diff --git a/esp8266/esp_mphal.c b/esp8266/esp_mphal.c index 0573f3d56cba6547e0d5bdb32e020042c2463f0b..686f54bc3155dbad6ae915e3da1a35a711d4bced 100644 --- a/esp8266/esp_mphal.c +++ b/esp8266/esp_mphal.c @@ -212,3 +212,15 @@ void dupterm_task_init() { void mp_hal_signal_dupterm_input(void) { system_os_post(DUPTERM_TASK_ID, 0, 0); } + +void mp_hal_pin_config_od(mp_hal_pin_obj_t pin_id) { + const pyb_pin_obj_t *pin = &pyb_pin_obj[pin_id]; + ETS_GPIO_INTR_DISABLE(); + PIN_FUNC_SELECT(pin->periph, pin->func); + GPIO_REG_WRITE(GPIO_PIN_ADDR(GPIO_ID_PIN(pin->phys_port)), + GPIO_REG_READ(GPIO_PIN_ADDR(GPIO_ID_PIN(pin->phys_port))) + | GPIO_PIN_PAD_DRIVER_SET(GPIO_PAD_DRIVER_ENABLE)); // open drain + GPIO_REG_WRITE(GPIO_ENABLE_ADDRESS, + GPIO_REG_READ(GPIO_ENABLE_ADDRESS) | (1 << pin->phys_port)); + ETS_GPIO_INTR_ENABLE(); +} diff --git a/esp8266/esp_mphal.h b/esp8266/esp_mphal.h index 39cf60ab16dbe4c9cdb628c75d895fa7b8a34204..4dca17d0a4175c0b628d7b903846236b95b5db13 100644 --- a/esp8266/esp_mphal.h +++ b/esp8266/esp_mphal.h @@ -63,20 +63,11 @@ void ets_event_poll(void); #include "etshal.h" #include "gpio.h" #include "esp8266/modpyb.h" -#define mp_hal_pin_obj_t pyb_pin_obj_t* -#define mp_hal_get_pin_obj(o) mp_obj_get_pin_obj(o) -#define mp_hal_pin_config_od(p) do { \ - ETS_GPIO_INTR_DISABLE(); \ - PIN_FUNC_SELECT((p)->periph, (p)->func); \ - GPIO_REG_WRITE(GPIO_PIN_ADDR(GPIO_ID_PIN((p)->phys_port)), \ - GPIO_REG_READ(GPIO_PIN_ADDR(GPIO_ID_PIN((p)->phys_port))) \ - | GPIO_PIN_PAD_DRIVER_SET(GPIO_PAD_DRIVER_ENABLE)); /* open drain */ \ - GPIO_REG_WRITE(GPIO_ENABLE_ADDRESS, \ - GPIO_REG_READ(GPIO_ENABLE_ADDRESS) | (1 << (p)->phys_port)); \ - ETS_GPIO_INTR_ENABLE(); \ - } while (0) -#define mp_hal_pin_low(p) gpio_output_set(0, 1 << (p)->phys_port, 1 << (p)->phys_port, 0) -#define mp_hal_pin_od_high(p) gpio_output_set(1 << (p)->phys_port, 0, 1 << (p)->phys_port, 0) -#define mp_hal_pin_read(p) GPIO_INPUT_GET(GPIO_ID_PIN((p)->phys_port)) +#define mp_hal_pin_obj_t uint32_t +#define mp_hal_get_pin_obj(o) mp_obj_get_pin(o) +void mp_hal_pin_config_od(mp_hal_pin_obj_t pin); +#define mp_hal_pin_low(p) gpio_output_set(0, 1 << (p), 1 << (p), 0) +#define mp_hal_pin_od_high(p) gpio_output_set(1 << (p), 0, 1 << (p), 0) +#define mp_hal_pin_read(p) GPIO_INPUT_GET(GPIO_ID_PIN((p))) #endif // _INCLUDED_MPHAL_H_ diff --git a/esp8266/modpyb.h b/esp8266/modpyb.h index 8d27ebed72c40e0a971b6da9e36cdc37d090ac35..c1a0413f04b89af4fcac6d0473a3481b949c27b4 100644 --- a/esp8266/modpyb.h +++ b/esp8266/modpyb.h @@ -18,6 +18,8 @@ typedef struct _pyb_pin_obj_t { uint32_t periph; } pyb_pin_obj_t; +const pyb_pin_obj_t pyb_pin_obj[16 + 1]; + void pin_init0(void); void pin_intr_handler_iram(void *arg); void pin_intr_handler(uint32_t); diff --git a/esp8266/modpybpin.c b/esp8266/modpybpin.c index 2049d4bf34a07323ff308c885e32c2e03df53d4a..a65911cbd117bf0fd1a730bcc645b4c6a9f0bd28 100644 --- a/esp8266/modpybpin.c +++ b/esp8266/modpybpin.c @@ -59,7 +59,7 @@ typedef struct _pin_irq_obj_t { uint16_t phys_port; } pin_irq_obj_t; -STATIC const pyb_pin_obj_t pyb_pin_obj[16 + 1] = { +const pyb_pin_obj_t pyb_pin_obj[16 + 1] = { {{&pyb_pin_type}, 0, FUNC_GPIO0, PERIPHS_IO_MUX_GPIO0_U}, {{&pyb_pin_type}, 1, FUNC_GPIO1, PERIPHS_IO_MUX_U0TXD_U}, {{&pyb_pin_type}, 2, FUNC_GPIO2, PERIPHS_IO_MUX_GPIO2_U},