Skip to content

Commit

Permalink
Fixed stopping PWM
Browse files Browse the repository at this point in the history
  • Loading branch information
szupi-ipuzs committed Dec 2, 2023
1 parent 9b8e00c commit ed42365
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 3 deletions.
4 changes: 3 additions & 1 deletion cores/beken-72xx/arduino/src/wiring.c
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,10 @@ void pinRemoveMode(PinInfo *pin, uint32_t mask) {
}
if ((mask & PIN_PWM) && (pin->enabled & PIN_PWM)) {
data->pwm->cfg.bits.en = PWM_DISABLE;
uint32_t channel_in_32bit = data->pwm->channel;
__wrap_bk_printf_disable();
sddev_control(PWM_DEV_NAME, CMD_PWM_DEINIT_PARAM, data->pwm);
sddev_control(PWM_DEV_NAME, CMD_PWM_INIT_LEVL_SET_LOW, &channel_in_32bit);
sddev_control(PWM_DEV_NAME, CMD_PWM_UNIT_DISABLE, &channel_in_32bit);
__wrap_bk_printf_enable();
pinDisable(pin, PIN_PWM);
}
Expand Down
6 changes: 4 additions & 2 deletions cores/beken-72xx/arduino/src/wiring_analog.c
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,7 @@ void analogWrite(pin_size_t pinNumber, int value) {
uint32_t frequency = 26 * _analogWritePeriod - 1;
uint32_t dutyCycle = percent * frequency;
pwm.channel = gpioToPwm(pin->gpio);
uint32_t channel_in_32bit = pwm.channel;
#if CFG_SOC_NAME != SOC_BK7231N
pwm.duty_cycle = dutyCycle;
#else
Expand All @@ -110,13 +111,14 @@ void analogWrite(pin_size_t pinNumber, int value) {
pwm.p_Int_Handler = NULL;
__wrap_bk_printf_disable();
sddev_control(PWM_DEV_NAME, CMD_PWM_INIT_PARAM, &pwm);
sddev_control(PWM_DEV_NAME, CMD_PWM_INIT_LEVL_SET_HIGH, &pwm.channel);
sddev_control(PWM_DEV_NAME, CMD_PWM_UNIT_ENABLE, &pwm.channel);
sddev_control(PWM_DEV_NAME, CMD_PWM_INIT_LEVL_SET_HIGH, &channel_in_32bit);
sddev_control(PWM_DEV_NAME, CMD_PWM_UNIT_ENABLE, &channel_in_32bit);
__wrap_bk_printf_enable();
// pass global PWM object pointer
data->pwm = &pwm;
pinEnable(pin, PIN_PWM);
} else {
sddev_control(PWM_DEV_NAME, CMD_PWM_INIT_LEVL_SET_HIGH, &channel_in_32bit);
// update duty cycle
sddev_control(PWM_DEV_NAME, CMD_PWM_SET_DUTY_CYCLE, &pwm);
}
Expand Down

0 comments on commit ed42365

Please sign in to comment.