From e70ece4c413b8fa5dce99240bff04e4641edf3a8 Mon Sep 17 00:00:00 2001 From: sommersoft Date: Wed, 25 Apr 2018 03:57:09 +0000 Subject: [PATCH] now checks for proper pin in is_pin_free; initialize GPIO16 as input in reset_pins --- ports/esp8266/common-hal/microcontroller/Pin.c | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/ports/esp8266/common-hal/microcontroller/Pin.c b/ports/esp8266/common-hal/microcontroller/Pin.c index 5c90f4f1a0..4b6efb428d 100644 --- a/ports/esp8266/common-hal/microcontroller/Pin.c +++ b/ports/esp8266/common-hal/microcontroller/Pin.c @@ -33,14 +33,18 @@ #include "eagle_soc.h" extern volatile bool adc_in_use; +volatile bool gpio16_in_use __attribute__((aligned(4))) = false; bool common_hal_mcu_pin_is_free(const mcu_pin_obj_t* pin) { if (pin == &pin_TOUT) { return !adc_in_use; } - if (pin->gpio_number == NO_GPIO || pin->gpio_number == SPECIAL_CASE) { + if (pin->gpio_number == NO_GPIO) { return false; } + if (pin->gpio_number == 16) { + return !gpio16_in_use; + } return (READ_PERI_REG(pin->peripheral) & (PERIPHS_IO_MUX_FUNC<gpio_number)) == 0 && @@ -48,7 +52,7 @@ bool common_hal_mcu_pin_is_free(const mcu_pin_obj_t* pin) { } void reset_pins(void) { - for (int i = 0; i < 17; i++) { + for (int i = 0; i < 16; i++) { // 5 is RXD, 6 is TXD if ((i > 4 && i < 13) || i == 12) { continue; @@ -59,4 +63,9 @@ void reset_pins(void) { // Disable the pin. gpio_output_set(0x0, 0x0, 0x0, 1 << i); } + // Set GPIO16 as input + WRITE_PERI_REG(PAD_XPD_DCDC_CONF, (READ_PERI_REG(PAD_XPD_DCDC_CONF) & 0xffffffbc) | 1); // mux configuration for XPD_DCDC and rtc_gpio0 connection + WRITE_PERI_REG(RTC_GPIO_CONF, READ_PERI_REG(RTC_GPIO_CONF) & ~1); //mux configuration for out enable + WRITE_PERI_REG(RTC_GPIO_ENABLE, READ_PERI_REG(RTC_GPIO_ENABLE) & ~1); //out disable + gpio16_in_use = false; }