summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--ports/esp8266/esppwm.c1
-rw-r--r--ports/esp8266/machine_pin.c10
-rw-r--r--ports/esp8266/machine_pwm.c9
-rw-r--r--ports/esp8266/modmachine.h10
4 files changed, 20 insertions, 10 deletions
diff --git a/ports/esp8266/esppwm.c b/ports/esp8266/esppwm.c
index 6164e2fc8..3b705fb94 100644
--- a/ports/esp8266/esppwm.c
+++ b/ports/esp8266/esppwm.c
@@ -389,7 +389,6 @@ pwm_add(uint8_t pin_id, uint32_t pin_mux, uint32_t pin_func) {
pwm.duty[i] = 0;
pwm_gpio |= (1 << pin_num[channel]);
PIN_FUNC_SELECT(pin_mux, pin_func);
- GPIO_REG_WRITE(GPIO_PIN_ADDR(GPIO_ID_PIN(pin_num[channel])), GPIO_REG_READ(GPIO_PIN_ADDR(GPIO_ID_PIN(pin_num[channel]))) & (~GPIO_PIN_PAD_DRIVER_SET(GPIO_PAD_DRIVER_ENABLE))); // disable open drain;
pwm_channel_num++;
UNLOCK_PWM(critical); // leave critical
return channel;
diff --git a/ports/esp8266/machine_pin.c b/ports/esp8266/machine_pin.c
index ea17728e2..f5e17c7e1 100644
--- a/ports/esp8266/machine_pin.c
+++ b/ports/esp8266/machine_pin.c
@@ -46,14 +46,6 @@
(GPIO_REG_READ(GPIO_PIN_ADDR(phys_port)) & ~GPIO_PIN_INT_TYPE_MASK) \
| GPIO_PIN_INT_TYPE_SET(trig))) \
-#define GPIO_MODE_INPUT (0)
-#define GPIO_MODE_OUTPUT (1)
-#define GPIO_MODE_OPEN_DRAIN (2) // synthesised
-#define GPIO_PULL_NONE (0)
-#define GPIO_PULL_UP (1)
-// Removed in SDK 1.1.0
-// #define GPIO_PULL_DOWN (2)
-
typedef struct _pin_irq_obj_t {
mp_obj_base_t base;
uint16_t phys_port;
@@ -84,7 +76,7 @@ const pyb_pin_obj_t pyb_pin_obj[16 + 1] = {
{{&pyb_pin_type}, 16, -1, -1},
};
-STATIC uint8_t pin_mode[16 + 1];
+uint8_t pin_mode[16 + 1];
// forward declaration
STATIC const pin_irq_obj_t pin_irq_obj[16];
diff --git a/ports/esp8266/machine_pwm.c b/ports/esp8266/machine_pwm.c
index 00547195f..6b7728dea 100644
--- a/ports/esp8266/machine_pwm.c
+++ b/ports/esp8266/machine_pwm.c
@@ -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));
}
diff --git a/ports/esp8266/modmachine.h b/ports/esp8266/modmachine.h
index 4a73d3b8e..9b7a5e3cb 100644
--- a/ports/esp8266/modmachine.h
+++ b/ports/esp8266/modmachine.h
@@ -21,6 +21,16 @@ typedef struct _pyb_pin_obj_t {
const pyb_pin_obj_t pyb_pin_obj[16 + 1];
+#define GPIO_MODE_INPUT (0)
+#define GPIO_MODE_OUTPUT (1)
+#define GPIO_MODE_OPEN_DRAIN (2) // synthesised
+#define GPIO_PULL_NONE (0)
+#define GPIO_PULL_UP (1)
+// Removed in SDK 1.1.0
+// #define GPIO_PULL_DOWN (2)
+
+extern uint8_t pin_mode[16 + 1];
+
void pin_init0(void);
uint mp_obj_get_pin(mp_obj_t pin_in);