esp8266/machine_pwm: Enable real open drain output on pin driven by PWM.

The PWM module now detects if the pin is open drain and if so switches it
to hardware open drain before starting the PWM.

The code that was explicitly turning off the open drain output during PWM
is also removed.

Together these changes allow driving external transistor high-current
switches with PWM.

Signed-off-by: Trammell hudson <hudson@trmm.net>
This commit is contained in:
Trammell hudson
2020-02-25 22:53:46 +01:00
committed by Damien George
parent 5228f4067d
commit 96a2cc5e13
4 changed files with 20 additions and 10 deletions

View File

@@ -25,6 +25,7 @@
*/
#include "py/runtime.h"
#include "py/mphal.h"
#include "modmachine.h"
#include "esppwm.h"
@@ -74,6 +75,10 @@ STATIC void mp_machine_pwm_init_helper(machine_pwm_obj_t *self, size_t n_args, c
pwm_set_duty(args[ARG_duty].u_int, self->channel);
}
if (pin_mode[self->pin->phys_port] == GPIO_MODE_OPEN_DRAIN) {
mp_hal_pin_open_drain(self->pin->phys_port);
}
pwm_start();
}
@@ -120,6 +125,10 @@ STATIC mp_obj_t mp_machine_pwm_duty_get(machine_pwm_obj_t *self) {
if (!self->active) {
pwm_add(self->pin->phys_port, self->pin->periph, self->pin->func);
self->active = 1;
if (pin_mode[self->pin->phys_port] == GPIO_MODE_OPEN_DRAIN) {
mp_hal_pin_open_drain(self->pin->phys_port);
}
}
return MP_OBJ_NEW_SMALL_INT(pwm_get_duty(self->channel));
}