14 static_assert(PWM_PARAM_N_OUTPUTS == 6,
15 "Expected six PWM channels. May need to update `dif_pwm.h`.");
16 static_assert(PWM_CFG_DC_RESN_MASK == 0xf,
17 "Expected duty cycle configuration register to be 4 bits.");
20 if (pwm == NULL || config.
clock_divisor > PWM_CFG_CLK_DIV_MASK ||
26 if (!mmio_region_read32(pwm->
base_addr, PWM_REGWEN_REG_OFFSET)) {
33 uint32_t config_reg = mmio_region_read32(pwm->
base_addr, PWM_CFG_REG_OFFSET);
50 mmio_region_write32(pwm->
base_addr, PWM_CFG_REG_OFFSET, 0);
51 mmio_region_write32(pwm->
base_addr, PWM_CFG_REG_OFFSET, config_reg);
64 if (!mmio_region_read32(pwm->
base_addr, PWM_REGWEN_REG_OFFSET)) {
73 mmio_region_read32(pwm->
base_addr, PWM_CFG_REG_OFFSET),
74 PWM_CFG_DC_RESN_FIELD);
75 uint32_t beats_per_pulse_cycle = 1U << (duty_cycle_resolution + 1);
86 uint16_t phase_cntr_ticks_per_beat =
87 (uint16_t)(1 << (16 - duty_cycle_resolution - 1));
88 uint32_t duty_cycle_reg =
111 uint32_t invert_reg =
112 mmio_region_read32(pwm->
base_addr, PWM_INVERT_REG_OFFSET);
115 uint32_t blink_param_reg = 0;
126 blink_param_reg, PWM_BLINK_PARAM_0_Y_0_FIELD,
137 #define DIF_PWM_CHANNEL_CONFIG_CASE_(channel_) \
138 case kDifPwmChannel##channel_: \
139 invert_reg = bitfield_bit32_write( \
140 invert_reg, PWM_INVERT_INVERT_##channel_##_BIT, config.polarity); \
141 mmio_region_write32(pwm->base_addr, \
142 PWM_DUTY_CYCLE_##channel_##_REG_OFFSET, \
144 mmio_region_write32(pwm->base_addr, PWM_PWM_PARAM_##channel_##_REG_OFFSET, \
146 if (config.mode == kDifPwmModeHeartbeat || \
147 config.mode == kDifPwmModeBlink) { \
148 mmio_region_write32(pwm->base_addr, \
149 PWM_BLINK_PARAM_##channel_##_REG_OFFSET, \
159 #undef DIF_PWM_CHANNEL_CONFIG_CASE_
161 mmio_region_write32(pwm->
base_addr, PWM_INVERT_REG_OFFSET, invert_reg);
172 if (!mmio_region_read32(pwm->
base_addr, PWM_REGWEN_REG_OFFSET)) {
176 uint32_t config_reg = mmio_region_read32(pwm->
base_addr, PWM_CFG_REG_OFFSET);
179 mmio_region_write32(pwm->
base_addr, PWM_CFG_REG_OFFSET, config_reg);
186 if (pwm == NULL || is_enabled == NULL) {
190 uint32_t config_reg = mmio_region_read32(pwm->
base_addr, PWM_CFG_REG_OFFSET);
200 if (pwm == NULL || channels >= (1U << PWM_PARAM_N_OUTPUTS) ||
205 if (!mmio_region_read32(pwm->
base_addr, PWM_REGWEN_REG_OFFSET)) {
209 uint32_t enable_reg =
210 mmio_region_read32(pwm->
base_addr, PWM_PWM_EN_REG_OFFSET);
213 enable_reg |= channels;
215 enable_reg &= ~channels;
218 mmio_region_write32(pwm->
base_addr, PWM_PWM_EN_REG_OFFSET, enable_reg);
226 if (pwm == NULL || is_enabled == NULL) {
232 if (channel_bit >= PWM_PARAM_N_OUTPUTS) {
236 uint32_t enable_reg =
237 mmio_region_read32(pwm->
base_addr, PWM_PWM_EN_REG_OFFSET);
249 mmio_region_write32(pwm->
base_addr, PWM_REGWEN_REG_OFFSET, 0);
255 if (pwm == NULL || is_locked == NULL) {
260 mmio_region_read32(pwm->
base_addr, PWM_REGWEN_REG_OFFSET) ? false :
true;