hw_pwm.h 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  1. #ifndef __HW_PWM_H__
  2. #define __HW_PWM_H__
  3. #define HW_PWM_1 0
  4. #define HW_PWM_2 1
  5. #define HW_PWM_3 2
  6. #define HW_PWM_4 3
  7. #define HW_PWM_5 4
  8. #define HW_PWM_6 5
  9. #define HW_PWM_7 6
  10. #define HW_PWM_8 7
  11. #define HW_PWM_9 8
  12. #define HW_PWM_10 9
  13. #define HW_PWM_11 10
  14. #define HW_PWM_12 11
  15. #define HW_PWM_NUMBER 2
  16. #define HW_ENCODER_NUMBER 1
  17. typedef struct
  18. {
  19. uint16_t * idr;
  20. uint16_t * odr;
  21. uint16_t pin;
  22. uint16_t level;
  23. } hw_pin_readwrite_t;
  24. extern uint32_t * hw_pwm_period_registers[];
  25. extern uint32_t * hw_pwm_dutycycle_registers[];
  26. extern uint16_t * hw_pwm_cr_registers[];
  27. extern uint16_t * hw_pwm_egr_registers[HW_PWM_NUMBER];
  28. //方向管脚读写表
  29. extern hw_pin_readwrite_t hw_pwm_dir_rw_map[];
  30. //使能管脚读写表
  31. extern hw_pin_readwrite_t hw_pwm_en_rw_map[];
  32. typedef void (* pwm_handle) (void *);
  33. //直接获取或者设置周期
  34. #define HW_PWM_PERIOD(no) *(hw_pwm_period_registers[no])
  35. //直接获取或者设置占空比
  36. #define HW_PWM_DUTYCYCLE(no) *(hw_pwm_dutycycle_registers[no])
  37. #define HW_PWM_SET_PERIOD(no,val) HW_PWM_PERIOD(no) = val;HW_PWM_DUTYCYCLE(no) = (val >> 1); *(hw_pwm_egr_registers[no]) |= 0x01
  38. #define HW_PWM_UPDATE_PERIOD(no,val) HW_PWM_PERIOD(no) = (val-1);HW_PWM_DUTYCYCLE(no) = (val >> 1)
  39. //#define HW_PWM_ON(no) *(hw_pwm_egr_registers[no]) |= 0x01;*(hw_pwm_cr_registers[no]) |= 0x01
  40. #define HW_PWM_ON(no) *(hw_pwm_cr_registers[no]) |= 0x01
  41. #define HW_PWM_OFF(no) *(hw_pwm_cr_registers[no]) &= ~0x01
  42. #define HW_PWM_IS_ON(no) (*(hw_pwm_cr_registers[no]) & 0x01)
  43. #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)
  44. #define HW_PWM_SET_DIR(no,sta) hw_pwm_dir_rw_map[no].odr[sta ^ hw_pwm_dir_rw_map[no].level] = hw_pwm_dir_rw_map[no].pin
  45. #define HW_PWM_GET_EN(no) ((hw_pwm_en_rw_map[no].idr & hw_pwm_en_rw_map[no].pin) == hw_pwm_en_rw_map[no].pin)
  46. #define HW_PWM_SET_EN(no,sta) hw_pwm_en_rw_map[no].odr[sta ^ hw_pwm_en_rw_map[no].level] = hw_pwm_en_rw_map[no].pin
  47. void hw_pwm_set_dir(unsigned char no, int dir);
  48. int hw_pwm_get_dir(unsigned char no);
  49. void hw_pwm_set_enable(unsigned char no, int en);
  50. int hw_pwm_get_enable(unsigned char no);
  51. void hw_pwm_start(unsigned char no);
  52. void hw_pwm_set_period(unsigned char no, int value);
  53. void hw_pwm_stop(unsigned char no);
  54. void hw_pwm_set_clock(unsigned char no, int clock);
  55. int hw_pwm_get_clk(unsigned char no);
  56. void hw_pwm_init(int clk);
  57. void hw_pwm_it_register(unsigned char no, pwm_handle handle, void * para);
  58. void hw_pwm_close_all(void);
  59. void hw_encoder_init(void);
  60. int hw_encoder_get(int index);
  61. void hw_encoder_set(int index, int count);
  62. #endif