Bouffalo SDK  1.0
Bouffalolab Software Development Kit
bflb_pwm_v1.h
Go to the documentation of this file.
1 #ifndef _BFLB_PWM_V1_H
2 #define _BFLB_PWM_V1_H
3 
4 #include "bflb_core.h"
5 
17 #define PWM_CH0 0
18 #define PWM_CH1 1
19 #define PWM_CH2 2
20 #define PWM_CH3 3
21 #define PWM_CH4 4
22 #define PWM_V1_CH_MAX 5
23 
30 #define PWM_INTSTS_REPT_CH0 (1 << 0)
31 #define PWM_INTSTS_REPT_CH1 (1 << 1)
32 #define PWM_INTSTS_REPT_CH2 (1 << 2)
33 #define PWM_INTSTS_REPT_CH3 (1 << 3)
34 #define PWM_INTSTS_REPT_CH4 (1 << 4)
35 
42 #define PWM_INTCLR_REPT_CH0 (1 << 8)
43 #define PWM_INTCLR_REPT_CH1 (1 << 9)
44 #define PWM_INTCLR_REPT_CH2 (1 << 10)
45 #define PWM_INTCLR_REPT_CH3 (1 << 11)
46 #define PWM_INTCLR_REPT_CH4 (1 << 12)
47 
54 #define PWM_CMD_SET_STOP_MODE (0x01)
55 #define PWM_CMD_SET_OUT_INVERT (0x02)
56 #define PWM_CMD_SET_SW_MODE (0x03)
57 #define PWM_CMD_SET_SW_FORCE_VALUE (0x04)
58 #define PWM_CMD_SET_REPT_COUNT (0x05)
59 
66 #define PWM_STOP_MODE_ABRUPT 0
67 #define PWM_STOP_MODE_GRACEFUL 1
68 
80  uint8_t clk_source;
81  uint16_t clk_div;
82  uint16_t period;
83 };
84 
85 #ifdef __cplusplus
86 extern "C" {
87 #endif
88 
96 void bflb_pwm_v1_channel_init(struct bflb_device_s *dev, uint8_t ch, const struct bflb_pwm_v1_channel_config_s *config);
97 
104 void bflb_pwm_v1_channel_deinit(struct bflb_device_s *dev, uint8_t ch);
105 
112 void bflb_pwm_v1_start(struct bflb_device_s *dev, uint8_t ch);
113 
120 void bflb_pwm_v1_stop(struct bflb_device_s *dev, uint8_t ch);
121 
129 void bflb_pwm_v1_set_period(struct bflb_device_s *dev, uint8_t ch, uint16_t period);
130 
139 void bflb_pwm_v1_channel_set_threshold(struct bflb_device_s *dev, uint8_t ch, uint16_t low_threhold, uint16_t high_threhold);
140 
148 void bflb_pwm_v1_int_enable(struct bflb_device_s *dev, uint8_t ch, bool enable);
149 
156 uint32_t bflb_pwm_v1_get_intstatus(struct bflb_device_s *dev);
157 
164 void bflb_pwm_v1_int_clear(struct bflb_device_s *dev, uint32_t int_clear);
165 
175 int bflb_pwm_v1_feature_control(struct bflb_device_s *dev, uint8_t ch, int cmd, size_t arg);
176 
177 #ifdef __cplusplus
178 }
179 #endif
180 
189 #endif
void bflb_pwm_v1_channel_set_threshold(struct bflb_device_s *dev, uint8_t ch, uint16_t low_threhold, uint16_t high_threhold)
Set pwm dutycycle. Dutycycle(%) = (high_threhold - low_threhold)/period * 100%.
void bflb_pwm_v1_int_clear(struct bflb_device_s *dev, uint32_t int_clear)
Clear pwm interrupt status.
void bflb_pwm_v1_channel_deinit(struct bflb_device_s *dev, uint8_t ch)
Deinitialize pwm channel.
void bflb_pwm_v1_set_period(struct bflb_device_s *dev, uint8_t ch, uint16_t period)
Set pwm channel period to change pwm frequence. Frequcence(hz) = pwm source clock /div/period...
void bflb_pwm_v1_stop(struct bflb_device_s *dev, uint8_t ch)
Stop pwm channel output.
void bflb_pwm_v1_start(struct bflb_device_s *dev, uint8_t ch)
Start pwm channel output.
PWM configuration structure.
Definition: bflb_pwm_v1.h:79
void bflb_pwm_v1_channel_init(struct bflb_device_s *dev, uint8_t ch, const struct bflb_pwm_v1_channel_config_s *config)
Initialize pwm channel.
uint32_t bflb_pwm_v1_get_intstatus(struct bflb_device_s *dev)
Get pwm interrupt status.
int bflb_pwm_v1_feature_control(struct bflb_device_s *dev, uint8_t ch, int cmd, size_t arg)
void bflb_pwm_v1_int_enable(struct bflb_device_s *dev, uint8_t ch, bool enable)
Enable pwm interrupt.