1 #ifndef _BFLB_PWM_V1_H 2 #define _BFLB_PWM_V2_H 3 4 #include "bflb_core.h" 5 6 /** @addtogroup LHAL 7 * @{ 8 */ 9 10 /** @addtogroup PWM_V1 11 * @{ 12 */ 13 14 /** @defgroup PWM_CHANNEL pwm channel definition 15 * @{ 16 */ 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 /** 24 * @} 25 */ 26 27 /** @defgroup PWM_INTSTS pwm interrupt status definition 28 * @{ 29 */ 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 /** 36 * @} 37 */ 38 39 /** @defgroup PWM_INTCLR pwm interrupt clear definition 40 * @{ 41 */ 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 /** 48 * @} 49 */ 50 51 /** @defgroup PWM_CMD pwm feature control cmd definition 52 * @{ 53 */ 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 /** 60 * @} 61 */ 62 63 /** @defgroup PWM_STOP_MODE pwm stop mode definition 64 * @{ 65 */ 66 #define PWM_STOP_MODE_ABRUPT 0 67 #define PWM_STOP_MODE_GRACEFUL 1 68 /** 69 * @} 70 */ 71 72 /** 73 * @brief PWM configuration structure 74 * 75 * @param clk_source PWM clock source, use @ref BFLB_SYSTEM_CLOCK 76 * @param clk_div PWM clock dividor, should be in 1~65535 77 * @param period PWM period count, should be in 2~65535 78 */ 79 struct bflb_pwm_v1_channel_config_s { 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 89 /** 90 * @brief Initialize pwm channel. 91 * 92 * @param [in] dev device handle 93 * @param [in] ch channel number 94 * @param [in] config pointer to save pwm channel config 95 */ 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 98 /** 99 * @brief Deinitialize pwm channel. 100 * 101 * @param [in] dev device handle 102 * @param [in] ch channel number 103 */ 104 void bflb_pwm_v1_channel_deinit(struct bflb_device_s *dev, uint8_t ch); 105 106 /** 107 * @brief Start pwm channel output. 108 * 109 * @param [in] dev device handle 110 * @param [in] ch channel number 111 */ 112 void bflb_pwm_v1_start(struct bflb_device_s *dev, uint8_t ch); 113 114 /** 115 * @brief Stop pwm channel output. 116 * 117 * @param [in] dev device handle 118 * @param [in] ch channel number 119 */ 120 void bflb_pwm_v1_stop(struct bflb_device_s *dev, uint8_t ch); 121 122 /** 123 * @brief Set pwm channel period to change pwm frequence. Frequcence(hz) = pwm source clock /div/period. 124 * 125 * @param [in] dev device handle 126 * @param [in] ch channel number 127 * @param [in] period pwm period 128 */ 129 void bflb_pwm_v1_set_period(struct bflb_device_s *dev, uint8_t ch, uint16_t period); 130 131 /** 132 * @brief Set pwm dutycycle. Dutycycle(%) = (high_threhold - low_threhold)/period * 100%. 133 * 134 * @param [in] dev device handle 135 * @param [in] ch channel number 136 * @param [in] low_threhold pwm low threhold 137 * @param [in] high_threhold pwm high threhold 138 */ 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 141 /** 142 * @brief Enable pwm interrupt. 143 * 144 * @param [in] dev device handle 145 * @param [in] ch channel number 146 * @param [in] enable true means enable, otherwise disable. 147 */ 148 void bflb_pwm_v1_int_enable(struct bflb_device_s *dev, uint8_t ch, bool enable); 149 150 /** 151 * @brief Get pwm interrupt status. 152 * 153 * @param [in] dev device handle 154 * @return interrupt status, use @ref PWM_INTSTS 155 */ 156 uint32_t bflb_pwm_v1_get_intstatus(struct bflb_device_s *dev); 157 158 /** 159 * @brief Clear pwm interrupt status. 160 * 161 * @param [in] dev device handle 162 * @param [in] int_clear clear value, use @ref PWM_INTCLR 163 */ 164 void bflb_pwm_v1_int_clear(struct bflb_device_s *dev, uint32_t int_clear); 165 166 /** 167 * @brief 168 * 169 * @param [in] dev device handle 170 * @param [in] ch channel number 171 * @param [in] cmd feature command, use @ref PWM_CMD 172 * @param [in] arg user data 173 * @return A negated errno value on failure. 174 */ 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 181 /** 182 * @} 183 */ 184 185 /** 186 * @} 187 */ 188 189 #endif