52 PWM_ERR_INVALID_PARAM = -1,
53 PWM_ERR_BAD_STATE = -2,
60 static INLINE
void pwm_enable(
int id)
62 uint32_t reg = RD_WORD(PWM_REGS_MISC_CTRL);
64 WR_WORD(PWM_REGS_MISC_CTRL, reg);
67 static INLINE
void pwm_disable(
int id)
69 uint32_t reg = RD_WORD(PWM_REGS_MISC_CTRL);
71 WR_WORD(PWM_REGS_MISC_CTRL, reg);
74 static INLINE
void pwm_pause(
int id,
int pause)
76 uint32_t reg = RD_WORD(PWM_REGS_MISC_CTRL);
78 reg |= (1 << (PWM_REGS_MISC_CTRL_CTL_PWM_PAUSE_SHIFT + id));
80 reg &= ~(1 << (PWM_REGS_MISC_CTRL_CTL_PWM_PAUSE_SHIFT + id));
82 WR_WORD(PWM_REGS_MISC_CTRL, reg);
85 static INLINE
void pwm_polarity(
int id,
int invert)
87 uint32_t reg = RD_WORD(PWM_REGS_MISC_CTRL);
89 reg |= (1 << (PWM_REGS_MISC_CTRL_CTL_PWM_POLARITY_SHIFT + id));
91 reg &= ~(1 << (PWM_REGS_MISC_CTRL_CTL_PWM_POLARITY_SHIFT + id));
93 WR_WORD(PWM_REGS_MISC_CTRL, reg);
96 static INLINE
void pwm_config(
int id, uint32_t duration, uint32_t high_duration)
98 uint32_t addr1, addr2;
101 addr1 = PWM_REGS_PWM_DURATION_0;
102 addr2 = PWM_REGS_PWM_HIGH_DURATION_0;
103 }
else if (
id == PWM1_ID) {
104 addr1 = PWM_REGS_PWM_DURATION_1;
105 addr2 = PWM_REGS_PWM_HIGH_DURATION_1;
106 }
else if (
id == PWM2_ID) {
107 addr1 = PWM_REGS_PWM_DURATION_2;
108 addr2 = PWM_REGS_PWM_HIGH_DURATION_2;
109 }
else if (
id == PWM3_ID) {
110 addr1 = PWM_REGS_PWM_DURATION_3;
111 addr2 = PWM_REGS_PWM_HIGH_DURATION_3;
112 }
else if (
id == PWM4_ID) {
113 addr1 = PWM_REGS_PWM_DURATION_4;
114 addr2 = PWM_REGS_PWM_HIGH_DURATION_4;
115 }
else if (
id == PWM5_ID) {
116 addr1 = PWM_REGS_PWM_DURATION_5;
117 addr2 = PWM_REGS_PWM_HIGH_DURATION_5;
118 }
else if (
id == PWM6_ID) {
119 addr1 = PWM_REGS_PWM_DURATION_6;
120 addr2 = PWM_REGS_PWM_HIGH_DURATION_6;
122 addr1 = PWM_REGS_PWM_DURATION_7;
123 addr2 = PWM_REGS_PWM_HIGH_DURATION_7;
126 WR_WORD(addr1, duration);
127 WR_WORD(addr2, high_duration);
130 static INLINE
void pwm_high_duration(
int id, uint32_t high_duration)
135 addr = PWM_REGS_PWM_HIGH_DURATION_0;
136 }
else if (
id == PWM1_ID) {
137 addr = PWM_REGS_PWM_HIGH_DURATION_1;
138 }
else if (
id == PWM2_ID) {
139 addr = PWM_REGS_PWM_HIGH_DURATION_2;
140 }
else if (
id == PWM3_ID) {
141 addr = PWM_REGS_PWM_HIGH_DURATION_3;
142 }
else if (
id == PWM4_ID) {
143 addr = PWM_REGS_PWM_HIGH_DURATION_4;
144 }
else if (
id == PWM5_ID) {
145 addr = PWM_REGS_PWM_HIGH_DURATION_5;
146 }
else if (
id == PWM6_ID) {
147 addr = PWM_REGS_PWM_HIGH_DURATION_6;
149 addr = PWM_REGS_PWM_HIGH_DURATION_7;
152 WR_WORD(addr, high_duration);
155 static INLINE
int pwm_output(
int id)
160 addr = PWM_REGS_PWM_OUTPUT_0;
161 }
else if (
id == PWM1_ID) {
162 addr = PWM_REGS_PWM_OUTPUT_1;
163 }
else if (
id == PWM2_ID) {
164 addr = PWM_REGS_PWM_OUTPUT_2;
165 }
else if (
id == PWM3_ID) {
166 addr = PWM_REGS_PWM_OUTPUT_3;
167 }
else if (
id == PWM4_ID) {
168 addr = PWM_REGS_PWM_OUTPUT_4;
169 }
else if (
id == PWM5_ID) {
170 addr = PWM_REGS_PWM_OUTPUT_5;
171 }
else if (
id == PWM6_ID) {
172 addr = PWM_REGS_PWM_OUTPUT_6;
174 addr = PWM_REGS_PWM_OUTPUT_7;
177 return (RD_WORD(addr) & 1);
180 static INLINE uint32_t pwm_int_status(
void)
182 return (RD_WORD(PWM_REGS_INTR_STATUS) & 0xFF);
185 static INLINE uint32_t pwm_int_mask_status(
void)
187 return (RD_WORD(PWM_REGS_INTR_MASK_STATUS) & 0xFF);
190 static INLINE
void pwm_int_clr_all(
void)
192 WR_WORD(PWM_REGS_INTR_CLEAR, 0xFF);
195 static INLINE
void pwm_int_clr(
int id)
197 WR_WORD(PWM_REGS_INTR_CLEAR, (1 <<
id));
200 static INLINE
void pwm_int_mask_all(
void)
202 WR_WORD(PWM_REGS_INTR_MASK_SET, 0xFF);
205 static INLINE
void pwm_int_mask(
int id)
207 WR_WORD(PWM_REGS_INTR_MASK_SET, (1 <<
id));
210 static INLINE
void pwm_int_unmask(
int id)
212 WR_WORD(PWM_REGS_INTR_MASK_CLEAR, (1 <<
id));
215 static INLINE
void pwm_int_reset(
void)
217 WR_WORD(PWM_REGS_RESET_INTR, PWM_REGS_RESET_INTR_CTL_PWM_INTR_SRESET);
220 static INLINE
void pwm_duration_load(uint32_t pwm_load)
222 WR_WORD(PWM_REGS_PWM_HIGH_DURATION_0, pwm_load&PWM_REGS_PWM_HIGH_DURATION_0_DURATION_MASK);
230 int hal_pwm_open_status(
void);
231 int hal_pwm_isr_status(
void);
232 void hal_crc_register_cb(
void * arg,
void (*cb)(
void* arg));
251 void *
hal_pwm_open(
int id,
int prio,
void *arg,
void (*callback)(
void *));
289 int hal_pwm_start(
void *hdl, uint32_t period_ticks, uint32_t high_ticks);
339 int hal_pwm_update(
void *hdl, uint32_t period_ticks, uint32_t high_ticks);
int hal_pwm_update_high_duration(void *hdl, uint32_t high_ticks)
Update PWM high time.
uint32_t hal_pwm_us_to_ticks(uint32_t us)
Convert us to PWM ticks.
int hal_pwm_close(void *hdl)
Close PWM driver.
int hal_pwm_resume(void *hdl)
Resume PWM.
int hal_pwm_update(void *hdl, uint32_t period_ticks, uint32_t high_ticks)
Update PWM period and high time.
int hal_pwm_stop(void *hdl)
Stop PWM.
int hal_pwm_pause(void *hdl)
Pause PWM. When PWM is paused, can't go to deep sleep.
void * hal_pwm_open(int id, int prio, void *arg, void(*callback)(void *))
Open PWM driver.
int hal_pwm_start(void *hdl, uint32_t period_ticks, uint32_t high_ticks)
Start PWM