diff --git a/ChangeLog b/ChangeLog index 2017db058..a8937869f 100644 --- a/ChangeLog +++ b/ChangeLog @@ -12,6 +12,7 @@ Add `E.errorFlag` event to allow JS to respond to internal errors Use Esc[J VT100 code when cycling through command history (much faster REPL on low bandwidth connections) ESP8266: Remove debugger again as it will never work on 8266 + ESP8266: Add GPIO16 as D16 without watch (#1206) 1v94 : Allow Espruino boards to reset straight out of the DFU Bootloader Improvements in handling errors in code running in IRQs diff --git a/boards/ESP8266_4MB.py b/boards/ESP8266_4MB.py index 3444ddaf4..d82e5b57b 100644 --- a/boards/ESP8266_4MB.py +++ b/boards/ESP8266_4MB.py @@ -65,7 +65,7 @@ devices = { # left-right, or top-bottom order board_esp12 = { 'top' : ['D1', 'D3', 'D5', 'D4', 'D0', 'D2', 'D15', 'GND'], - 'bottom' : ['VCC', 'D13', 'D12', 'D14', 'B16', 'CH_EN', 'A0', 'RESET'], + 'bottom' : ['VCC', 'D13', 'D12', 'D14', 'D16', 'CH_EN', 'A0', 'RESET'], 'right' : ['D11', 'D8', 'D9', 'D10', 'D7', 'D6'], }; board_esp12["bottom"].reverse() @@ -111,10 +111,10 @@ board_esp01 = { boards = [ board_esp12 ]; def get_pins(): - pins = pinutils.generate_pins(0,15) + pins = pinutils.generate_pins(0,16) pinutils.findpin(pins, "PD0", True)["functions"]["LED_1"]=0; pinutils.findpin(pins, "PD1", True)["functions"]["USART0_TX"]=0; pinutils.findpin(pins, "PD2", True)["functions"]["USART1_TX"]=0; pinutils.findpin(pins, "PD3", True)["functions"]["USART0_RX"]=0; - # just fake pins D0 .. D15 + # just fake pins D0 .. D16 return pins diff --git a/boards/ESP8266_BOARD.py b/boards/ESP8266_BOARD.py index 3c5f88ae6..c5185d691 100644 --- a/boards/ESP8266_BOARD.py +++ b/boards/ESP8266_BOARD.py @@ -56,7 +56,7 @@ devices = { # left-right, or top-bottom order board_esp12 = { 'top' : ['D1', 'D3', 'D5', 'D4', 'D0', 'D2', 'D15', 'GND'], - 'bottom' : ['VCC', 'D13', 'D12', 'D14', 'B16', 'CH_EN', 'A0', 'RESET'], + 'bottom' : ['VCC', 'D13', 'D12', 'D14', 'D16', 'CH_EN', 'A0', 'RESET'], 'right' : ['D11', 'D8', 'D9', 'D10', 'D7', 'D6'], }; board_esp12["bottom"].reverse() @@ -132,10 +132,10 @@ board_esp01["_css"] = """ boards = [ board_esp12, board_esp01 ]; def get_pins(): - pins = pinutils.generate_pins(0,15) + pins = pinutils.generate_pins(0,16) pinutils.findpin(pins, "PD0", True)["functions"]["LED_1"]=0; pinutils.findpin(pins, "PD1", True)["functions"]["USART0_TX"]=0; pinutils.findpin(pins, "PD2", True)["functions"]["USART1_TX"]=0; pinutils.findpin(pins, "PD3", True)["functions"]["USART0_RX"]=0; - # just fake pins D0 .. D15 + # just fake pins D0 .. D16 return pins \ No newline at end of file diff --git a/src/jswrap_io.c b/src/jswrap_io.c index a72cd53be..cdb4a2a2e 100644 --- a/src/jswrap_io.c +++ b/src/jswrap_io.c @@ -613,7 +613,7 @@ JsVar *jswrap_interface_setWatch( } if (!jsiIsWatchingPin(pin) && !jshCanWatch(pin)) { - jsWarn("Unable to set watch. You may already have a watch on a pin with the same number (eg. A0 and B0)"); + jsWarn("Unable to set watch. You may already have a watch on a pin with the same number (eg. A0 and B0),\nor this pin cannot be used with watch"); return 0; } diff --git a/targets/esp8266/jshardware.c b/targets/esp8266/jshardware.c index 42002f305..8bd2d5f0a 100644 --- a/targets/esp8266/jshardware.c +++ b/targets/esp8266/jshardware.c @@ -363,6 +363,36 @@ void jshPinSetState( Pin pin, //!< The pin to have its state changed. JshPinState state //!< The new desired state of the pin. ) { + + os_printf("> ESP8266: jshPinSetState state: %s\n",pinStateToString(state)); + + /* handle D16 */ + if (pin == 16) { + switch(state){ + case JSHPINSTATE_GPIO_OUT: + // mux configuration for XPD_DCDC to output rtc_gpio0 + WRITE_PERI_REG(PAD_XPD_DCDC_CONF, (READ_PERI_REG(PAD_XPD_DCDC_CONF) & 0xffffffbc) | (uint32)0x1); + //mux configuration for out enable + WRITE_PERI_REG(RTC_GPIO_CONF,(READ_PERI_REG(RTC_GPIO_CONF) & (uint32)0xfffffffe) | (uint32)0x0); + //out enable + WRITE_PERI_REG(RTC_GPIO_ENABLE,(READ_PERI_REG(RTC_GPIO_ENABLE) & (uint32)0xfffffffe) | (uint32)0x1); + break; + case JSHPINSTATE_GPIO_IN: + // mux configuration for XPD_DCDC and rtc_gpio0 connection + WRITE_PERI_REG(PAD_XPD_DCDC_CONF,(READ_PERI_REG(PAD_XPD_DCDC_CONF) & 0xffffffbc) | (uint32)0x1); + //mux configuration for out enable + WRITE_PERI_REG(RTC_GPIO_CONF,(READ_PERI_REG(RTC_GPIO_CONF) & (uint32)0xfffffffe) | (uint32)0x0); + //out disable + WRITE_PERI_REG(RTC_GPIO_ENABLE,READ_PERI_REG(RTC_GPIO_ENABLE) & (uint32)0xfffffffe); + break; + default: + jsError("only output and input are valid for D16"); + return; + } + g_pinState[pin] = state; + return; + } + /* Make sure we kill software PWM if we set the pin state * after we've started it */ if (BITFIELD_GET(jshPinSoftPWM, pin)) { @@ -441,9 +471,17 @@ JshPinState jshPinGetState(Pin pin) { pin, g_pinState[pin], (GPIO_REG_READ(GPIO_OUT_W1TS_ADDRESS)>>pin)&1, (GPIO_REG_READ(GPIO_OUT_ADDRESS)>>pin)&1, GPIO_INPUT_GET(pin)); */ - if ( (GPIO_REG_READ(GPIO_OUT_ADDRESS)>>pin)&1 ) - return g_pinState[pin] | JSHPINSTATE_PIN_IS_ON; - return g_pinState[pin]; + int rc = g_pinState[pin]; + if (pin == 16) { + if ((uint8)(READ_PERI_REG(RTC_GPIO_IN_DATA) & 1) &1) { + rc = g_pinState[pin] | JSHPINSTATE_PIN_IS_ON; + } + } else { + if ( (GPIO_REG_READ(GPIO_OUT_ADDRESS)>>pin)&1 ) { + rc = g_pinState[pin] | JSHPINSTATE_PIN_IS_ON; + } + } + return rc; } //===== GPIO and PIN stuff ===== @@ -456,8 +494,17 @@ void jshPinSetValue( bool value //!< The new value of the pin. ) { //os_printf("> ESP8266: jshPinSetValue pin=%d, value=%d\n", pin, value); - if (value & 1) GPIO_REG_WRITE(GPIO_OUT_W1TS_ADDRESS, 1< ESP8266: jshPinGetValue pin=%d, value=%d\n", pin, GPIO_INPUT_GET(pin)); - return GPIO_INPUT_GET(pin); + /* handle D16 */ + if (pin == 16) { + return (READ_PERI_REG(RTC_GPIO_IN_DATA) & 1); + } else { + return GPIO_INPUT_GET(pin); + } } @@ -646,12 +697,18 @@ bool jshCanWatch( Pin pin //!< The pin that we are asking whether or not we can watch it. ) { // As of right now, let us assume that all pins on an ESP8266 are watchable. - os_printf("> jshCanWatch: pin=%d\n", pin); - os_printf("< jshCanWatch = true\n"); - return true; + bool rc; + //os_printf("> jshCanWatch: pin=%d\n", pin); + // exclude pin 16 + if ( pin == 16 ) { + rc = false; + } else { + rc = true; + } + //os_printf("< jshCanWatch = %d (0:false,1:true)\n",rc); + return rc; } - /** * Do what ever is necessary to watch a pin. * \return The event flag for this pin.