12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879 |
- #ifndef __HW_PWM_H__
- #define __HW_PWM_H__
- #define HW_PWM_1 0
- #define HW_PWM_2 1
- #define HW_PWM_3 2
- #define HW_PWM_4 3
- #define HW_PWM_5 4
- #define HW_PWM_6 5
- #define HW_PWM_7 6
- #define HW_PWM_8 7
- #define HW_PWM_9 8
- #define HW_PWM_10 9
- #define HW_PWM_11 10
- #define HW_PWM_12 11
- #define HW_PWM_NUMBER 2
- #define HW_ENCODER_NUMBER 1
- typedef struct
- {
- uint16_t * idr;
- uint16_t * odr;
- uint16_t pin;
- uint16_t level;
- } hw_pin_readwrite_t;
- extern uint32_t * hw_pwm_period_registers[];
- extern uint32_t * hw_pwm_dutycycle_registers[];
- extern uint16_t * hw_pwm_cr_registers[];
- extern uint16_t * hw_pwm_egr_registers[HW_PWM_NUMBER];
- //方向管脚读写表
- extern hw_pin_readwrite_t hw_pwm_dir_rw_map[];
- //使能管脚读写表
- extern hw_pin_readwrite_t hw_pwm_en_rw_map[];
- typedef void (* pwm_handle) (void *);
- //直接获取或者设置周期
- #define HW_PWM_PERIOD(no) *(hw_pwm_period_registers[no])
- //直接获取或者设置占空比
- #define HW_PWM_DUTYCYCLE(no) *(hw_pwm_dutycycle_registers[no])
- #define HW_PWM_SET_PERIOD(no,val) HW_PWM_PERIOD(no) = val;HW_PWM_DUTYCYCLE(no) = (val >> 1); *(hw_pwm_egr_registers[no]) |= 0x01
- #define HW_PWM_UPDATE_PERIOD(no,val) HW_PWM_PERIOD(no) = (val-1);HW_PWM_DUTYCYCLE(no) = (val >> 1)
- //#define HW_PWM_ON(no) *(hw_pwm_egr_registers[no]) |= 0x01;*(hw_pwm_cr_registers[no]) |= 0x01
- #define HW_PWM_ON(no) *(hw_pwm_cr_registers[no]) |= 0x01
- #define HW_PWM_OFF(no) *(hw_pwm_cr_registers[no]) &= ~0x01
- #define HW_PWM_IS_ON(no) (*(hw_pwm_cr_registers[no]) & 0x01)
- #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)
- #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
- #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)
- #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
- void hw_pwm_set_dir(unsigned char no, int dir);
- int hw_pwm_get_dir(unsigned char no);
- void hw_pwm_set_enable(unsigned char no, int en);
- int hw_pwm_get_enable(unsigned char no);
- void hw_pwm_start(unsigned char no);
- void hw_pwm_set_period(unsigned char no, int value);
- void hw_pwm_stop(unsigned char no);
- void hw_pwm_set_clock(unsigned char no, int clock);
- int hw_pwm_get_clk(unsigned char no);
- void hw_pwm_init(int clk);
- void hw_pwm_it_register(unsigned char no, pwm_handle handle, void * para);
- void hw_pwm_close_all(void);
- void hw_encoder_init(void);
- int hw_encoder_get(int index);
- void hw_encoder_set(int index, int count);
- #endif
|