mirror of
https://github.com/espruino/Espruino.git
synced 2025-12-08 19:06:15 +00:00
ESP8266: Add GPIO16 as D16 without watch (#1206)
This commit is contained in:
parent
c951f277ca
commit
b6e11a0d0f
@ -12,6 +12,7 @@
|
|||||||
Add `E.errorFlag` event to allow JS to respond to internal errors
|
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)
|
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: 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
|
1v94 : Allow Espruino boards to reset straight out of the DFU Bootloader
|
||||||
Improvements in handling errors in code running in IRQs
|
Improvements in handling errors in code running in IRQs
|
||||||
|
|||||||
@ -65,7 +65,7 @@ devices = {
|
|||||||
# left-right, or top-bottom order
|
# left-right, or top-bottom order
|
||||||
board_esp12 = {
|
board_esp12 = {
|
||||||
'top' : ['D1', 'D3', 'D5', 'D4', 'D0', 'D2', 'D15', 'GND'],
|
'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'],
|
'right' : ['D11', 'D8', 'D9', 'D10', 'D7', 'D6'],
|
||||||
};
|
};
|
||||||
board_esp12["bottom"].reverse()
|
board_esp12["bottom"].reverse()
|
||||||
@ -111,10 +111,10 @@ board_esp01 = {
|
|||||||
boards = [ board_esp12 ];
|
boards = [ board_esp12 ];
|
||||||
|
|
||||||
def get_pins():
|
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, "PD0", True)["functions"]["LED_1"]=0;
|
||||||
pinutils.findpin(pins, "PD1", True)["functions"]["USART0_TX"]=0;
|
pinutils.findpin(pins, "PD1", True)["functions"]["USART0_TX"]=0;
|
||||||
pinutils.findpin(pins, "PD2", True)["functions"]["USART1_TX"]=0;
|
pinutils.findpin(pins, "PD2", True)["functions"]["USART1_TX"]=0;
|
||||||
pinutils.findpin(pins, "PD3", True)["functions"]["USART0_RX"]=0;
|
pinutils.findpin(pins, "PD3", True)["functions"]["USART0_RX"]=0;
|
||||||
# just fake pins D0 .. D15
|
# just fake pins D0 .. D16
|
||||||
return pins
|
return pins
|
||||||
|
|||||||
@ -56,7 +56,7 @@ devices = {
|
|||||||
# left-right, or top-bottom order
|
# left-right, or top-bottom order
|
||||||
board_esp12 = {
|
board_esp12 = {
|
||||||
'top' : ['D1', 'D3', 'D5', 'D4', 'D0', 'D2', 'D15', 'GND'],
|
'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'],
|
'right' : ['D11', 'D8', 'D9', 'D10', 'D7', 'D6'],
|
||||||
};
|
};
|
||||||
board_esp12["bottom"].reverse()
|
board_esp12["bottom"].reverse()
|
||||||
@ -132,10 +132,10 @@ board_esp01["_css"] = """
|
|||||||
boards = [ board_esp12, board_esp01 ];
|
boards = [ board_esp12, board_esp01 ];
|
||||||
|
|
||||||
def get_pins():
|
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, "PD0", True)["functions"]["LED_1"]=0;
|
||||||
pinutils.findpin(pins, "PD1", True)["functions"]["USART0_TX"]=0;
|
pinutils.findpin(pins, "PD1", True)["functions"]["USART0_TX"]=0;
|
||||||
pinutils.findpin(pins, "PD2", True)["functions"]["USART1_TX"]=0;
|
pinutils.findpin(pins, "PD2", True)["functions"]["USART1_TX"]=0;
|
||||||
pinutils.findpin(pins, "PD3", True)["functions"]["USART0_RX"]=0;
|
pinutils.findpin(pins, "PD3", True)["functions"]["USART0_RX"]=0;
|
||||||
# just fake pins D0 .. D15
|
# just fake pins D0 .. D16
|
||||||
return pins
|
return pins
|
||||||
@ -613,7 +613,7 @@ JsVar *jswrap_interface_setWatch(
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!jsiIsWatchingPin(pin) && !jshCanWatch(pin)) {
|
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;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -363,6 +363,36 @@ void jshPinSetState(
|
|||||||
Pin pin, //!< The pin to have its state changed.
|
Pin pin, //!< The pin to have its state changed.
|
||||||
JshPinState state //!< The new desired state of the pin.
|
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
|
/* Make sure we kill software PWM if we set the pin state
|
||||||
* after we've started it */
|
* after we've started it */
|
||||||
if (BITFIELD_GET(jshPinSoftPWM, pin)) {
|
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,
|
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));
|
(GPIO_REG_READ(GPIO_OUT_ADDRESS)>>pin)&1, GPIO_INPUT_GET(pin));
|
||||||
*/
|
*/
|
||||||
if ( (GPIO_REG_READ(GPIO_OUT_ADDRESS)>>pin)&1 )
|
int rc = g_pinState[pin];
|
||||||
return g_pinState[pin] | JSHPINSTATE_PIN_IS_ON;
|
if (pin == 16) {
|
||||||
return g_pinState[pin];
|
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 =====
|
//===== GPIO and PIN stuff =====
|
||||||
@ -456,8 +494,17 @@ void jshPinSetValue(
|
|||||||
bool value //!< The new value of the pin.
|
bool value //!< The new value of the pin.
|
||||||
) {
|
) {
|
||||||
//os_printf("> ESP8266: jshPinSetValue pin=%d, value=%d\n", pin, value);
|
//os_printf("> ESP8266: jshPinSetValue pin=%d, value=%d\n", pin, value);
|
||||||
if (value & 1) GPIO_REG_WRITE(GPIO_OUT_W1TS_ADDRESS, 1<<pin);
|
/* handle GPIO16 */
|
||||||
else GPIO_REG_WRITE(GPIO_OUT_W1TC_ADDRESS, 1<<pin);
|
if (pin == 16) {
|
||||||
|
WRITE_PERI_REG(RTC_GPIO_OUT,(READ_PERI_REG(RTC_GPIO_OUT) & (uint32)0xfffffffe) | (uint32)(value & 1));
|
||||||
|
} else {
|
||||||
|
if (value & 1) {
|
||||||
|
GPIO_REG_WRITE(GPIO_OUT_W1TS_ADDRESS, 1<<pin);
|
||||||
|
} else {
|
||||||
|
GPIO_REG_WRITE(GPIO_OUT_W1TC_ADDRESS, 1<<pin);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return;
|
||||||
//jshDebugPin(pin);
|
//jshDebugPin(pin);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -469,8 +516,12 @@ void jshPinSetValue(
|
|||||||
bool CALLED_FROM_INTERRUPT jshPinGetValue( // can be called at interrupt time
|
bool CALLED_FROM_INTERRUPT jshPinGetValue( // can be called at interrupt time
|
||||||
Pin pin //!< The pin to have its value read.
|
Pin pin //!< The pin to have its value read.
|
||||||
) {
|
) {
|
||||||
//os_printf("> ESP8266: jshPinGetValue pin=%d, value=%d\n", pin, GPIO_INPUT_GET(pin));
|
/* handle D16 */
|
||||||
return GPIO_INPUT_GET(pin);
|
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.
|
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.
|
// As of right now, let us assume that all pins on an ESP8266 are watchable.
|
||||||
os_printf("> jshCanWatch: pin=%d\n", pin);
|
bool rc;
|
||||||
os_printf("< jshCanWatch = true\n");
|
//os_printf("> jshCanWatch: pin=%d\n", pin);
|
||||||
return true;
|
// 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.
|
* Do what ever is necessary to watch a pin.
|
||||||
* \return The event flag for this pin.
|
* \return The event flag for this pin.
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user