hw_pwm.h 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. #ifndef __HW_PWM_H__
  2. #define __HW_PWM_H__
  3. #include "st_sys.h"
  4. #include "hw_pin.h"
  5. #define HW_PWM_1 0
  6. #define HW_PWM_2 1
  7. #define HW_PWM_3 2
  8. #define HW_PWM_4 3
  9. #define HW_PWM_NUMBER 2
  10. extern uint16_t * hw_pwm_period_registers[];
  11. extern uint16_t * hw_pwm_dutycycle_registers[];
  12. extern uint16_t * hw_pwm_cr_registers[];
  13. extern uint16_t * hw_pwm_egr_registers[HW_PWM_NUMBER];
  14. //方向管脚读写表
  15. extern hw_pin_readwrite_t hw_pwm_dir_rw_map[];
  16. //使能管脚读写表
  17. extern hw_pin_readwrite_t hw_pwm_en_rw_map[];
  18. typedef void (* pwm_handle) (void *);
  19. //直接获取或者设置周期
  20. #define HW_PWM_PERIOD(no) *(hw_pwm_period_registers[no])
  21. //直接获取或者设置占空比
  22. #define HW_PWM_DUTYCYCLE(no) *(hw_pwm_dutycycle_registers[no])
  23. #define HW_PWM_SET_PERIOD(no,val) HW_PWM_PERIOD(no) = val;HW_PWM_DUTYCYCLE(no) = (val >> 1); *(hw_pwm_egr_registers[no]) |= 0x01
  24. //#define HW_PWM_ON(no) *(hw_pwm_egr_registers[no]) |= 0x01;*(hw_pwm_cr_registers[no]) |= 0x01
  25. #define HW_PWM_ON(no) *(hw_pwm_cr_registers[no]) |= 0x01
  26. #define HW_PWM_OFF(no) *(hw_pwm_cr_registers[no]) &= ~0x01
  27. #define HW_PWM_IS_ON(no) (*(hw_pwm_cr_registers[no]) & 0x01)
  28. #define HW_PWM_GET_DIR(no) ((hw_pwm_dir_rw_map[no].idr & hw_pwm_dir_rw_map[no].pin) == hw_pwm_dir_rw_map[no].pin)
  29. #define HW_PWM_SET_DIR(no,sta) hw_pwm_dir_rw_map[no].odr[1 - sta] = hw_pwm_dir_rw_map[no].pin
  30. #define HW_PWM_GET_EN(no) ((hw_pwm_en_rw_map[no].idr & hw_pwm_en_rw_map[no].pin) == hw_pwm_dir_rw_map[no].pin)
  31. #define HW_PWM_SET_EN(no,sta) hw_pwm_en_rw_map[no].odr[1 - sta] = hw_pwm_en_rw_map[no].pin
  32. void hw_pwm_set_dir(unsigned char no, int dir);
  33. int hw_pwm_get_dir(unsigned char no);
  34. void hw_pwm_set_enable(unsigned char no, int en);
  35. int hw_pwm_get_enable(unsigned char no);
  36. void hw_pwm_start(unsigned char no);
  37. void hw_pwm_set_period(unsigned char no, int value);
  38. void hw_pwm_stop(unsigned char no);
  39. int hw_pwm_get_clk(unsigned char no);
  40. void hw_pwm_init(int clk);
  41. void hw_pwm_it_register(unsigned char no, pwm_handle handle, void * para);
  42. void hw_pwm_close_all(void);
  43. int hw_pwm_get_alr(unsigned char no);
  44. int hw_pwm_get_tarr(unsigned char no);
  45. void hw_pwm_set_clr(unsigned char no, int en);
  46. void hw_pwm_set_tmode(unsigned char no, int en);
  47. #endif