diff --git a/esp-link/cgiflash.c b/esp-link/cgiflash.c index 0fe3feb..1ce8469 100644 --- a/esp-link/cgiflash.c +++ b/esp-link/cgiflash.c @@ -179,7 +179,7 @@ int ICACHE_FLASH_ATTR cgiRebootFirmware(HttpdConnData *connData) { system_upgrade_flag_set(UPGRADE_FLAG_FINISH); os_timer_disarm(&flash_reboot_timer); os_timer_setfn(&flash_reboot_timer, (os_timer_func_t *)system_upgrade_reboot, NULL); - os_timer_arm(&flash_reboot_timer, 2000, 1); + os_timer_arm_us(&flash_reboot_timer, 2 * 1000000, 1); return HTTPD_CGI_DONE; } @@ -193,6 +193,6 @@ int ICACHE_FLASH_ATTR cgiReset(HttpdConnData *connData) { // Schedule a reboot os_timer_disarm(&flash_reboot_timer); os_timer_setfn(&flash_reboot_timer, (os_timer_func_t *)system_restart, NULL); - os_timer_arm(&flash_reboot_timer, 2000, 1); + os_timer_arm_us(&flash_reboot_timer, 2 * 1000000, 1); return HTTPD_CGI_DONE; } diff --git a/esp-link/cgioptiboot.c b/esp-link/cgioptiboot.c index c3ca1ea..c94ac96 100644 --- a/esp-link/cgioptiboot.c +++ b/esp-link/cgioptiboot.c @@ -128,7 +128,7 @@ int ICACHE_FLASH_ATTR cgiOptibootSync(HttpdConnData *connData) { // start sync timer os_timer_disarm(&optibootTimer); os_timer_setfn(&optibootTimer, optibootTimerCB, NULL); - os_timer_arm(&optibootTimer, INIT_DELAY, 0); + os_timer_arm_us(&optibootTimer, INIT_DELAY * 1000, 0); // respond with optimistic OK noCacheHeaders(connData, 204); @@ -382,7 +382,7 @@ bool ICACHE_FLASH_ATTR optibootProgramPage(void) { static void ICACHE_FLASH_ATTR armTimer(uint32_t ms) { os_timer_disarm(&optibootTimer); - os_timer_arm(&optibootTimer, ms, 0); + os_timer_arm_us(&optibootTimer, ms * 1000, 0); } static int baudRates[] = { 0, 9600, 57600, 115200 }; diff --git a/esp-link/cgipins.c b/esp-link/cgipins.c index b763d12..bf4754d 100644 --- a/esp-link/cgipins.c +++ b/esp-link/cgipins.c @@ -32,9 +32,10 @@ int ICACHE_FLASH_ATTR cgiPinsGet(HttpdConnData *connData) { int len; len = os_sprintf(buff, - "{ \"reset\":%d, \"isp\":%d, \"conn\":%d, \"ser\":%d, \"swap\":%d, \"rxpup\":%d }", + "{ \"reset\":%d, \"isp\":%d, \"conn\":%d, \"ser\":%d, \"swap\":%d, \"rxpup\":%d, \"txen\":%d }", flashConfig.reset_pin, flashConfig.isp_pin, flashConfig.conn_led_pin, - flashConfig.ser_led_pin, !!flashConfig.swap_uart, !!flashConfig.rx_pullup); + flashConfig.ser_led_pin, !!flashConfig.swap_uart, !!flashConfig.rx_pullup, + flashConfig.tx_enable_pin); jsonHeader(connData, 200); httpdSend(connData, buff, len); @@ -48,7 +49,7 @@ int ICACHE_FLASH_ATTR cgiPinsSet(HttpdConnData *connData) { } int8_t ok = 0; - int8_t reset, isp, conn, ser; + int8_t reset, isp, conn, ser, tx_enable; uint8_t swap, rxpup; ok |= getInt8Arg(connData, "reset", &reset); ok |= getInt8Arg(connData, "isp", &isp); @@ -56,6 +57,7 @@ int ICACHE_FLASH_ATTR cgiPinsSet(HttpdConnData *connData) { ok |= getInt8Arg(connData, "ser", &ser); ok |= getBoolArg(connData, "swap", &swap); ok |= getBoolArg(connData, "rxpup", &rxpup); + ok |= getInt8Arg(connData, "txen", &tx_enable); if (ok < 0) return HTTPD_CGI_DONE; char *coll; @@ -75,6 +77,10 @@ int ICACHE_FLASH_ATTR cgiPinsSet(HttpdConnData *connData) { if (pins & (1<= 0) { + if (pins & (1<= cgiWifiAps.noAps) + return; + + if (ptr != 0) + strncpy(ptr, cgiWifiAps.apData[i]->ssid, 32); + + DBG("AP %s\n", cgiWifiAps.apData[i]->ssid); +} + +// Access functions for cgiWifiAps : returns the signal strength of network (i is index into array). Return current network strength for negative i. +ICACHE_FLASH_ATTR int wifiSignalStrength(int i) { + sint8 rssi; + + if (i < 0 || i == 255) + rssi = wifi_station_get_rssi(); // Current network's signal strength + else if (i >= cgiWifiAps.noAps) + rssi = 0; // FIX ME + else + rssi = cgiWifiAps.apData[i]->rssi; // Signal strength of any known network + + return rssi; } // Access functions for cgiWifiAps : query the number of entries in the table diff --git a/esp-link/config.c b/esp-link/config.c index e9ad453..be49c69 100644 --- a/esp-link/config.c +++ b/esp-link/config.c @@ -34,6 +34,7 @@ FlashConfig flashDefault = { .data_bits = EIGHT_BITS, .parity = NONE_BITS, .stop_bits = ONE_STOP_BIT, + .tx_enable_pin = -1, }; typedef union { @@ -174,6 +175,13 @@ bool ICACHE_FLASH_ATTR configRestore(void) { flashConfig.parity = flashDefault.parity; flashConfig.stop_bits = flashDefault.stop_bits; } + if (flashConfig.tx_enable_pin == 0 && + (flashConfig.conn_led_pin == 0 || flashConfig.reset_pin == 0 || + flashConfig.isp_pin == 0 || flashConfig.ser_led_pin == 0)) { + // just added tx_enable_pin and it got the default 0, which is not good, need to default to + // disabled. + flashConfig.tx_enable_pin = -1; + } return true; } diff --git a/esp-link/config.h b/esp-link/config.h index c6a4058..8b9c45f 100644 --- a/esp-link/config.h +++ b/esp-link/config.h @@ -43,6 +43,7 @@ typedef struct { int8_t stop_bits; char mqtt_password[70]; // MQTT password, was 32-char mqtt_old_password char mqtt_username[70]; // MQTT username, was 32-char mqtt_old_username + int8_t tx_enable_pin; } FlashConfig; extern FlashConfig flashConfig; diff --git a/esp-link/main.c b/esp-link/main.c index 31bcf6e..9914ec9 100644 --- a/esp-link/main.c +++ b/esp-link/main.c @@ -162,10 +162,13 @@ user_rf_cal_sector_set(void) { // Main routine to initialize esp-link. void ICACHE_FLASH_ATTR user_init(void) { + system_timer_reinit(); + // uncomment the following three lines to see flash config messages for troubleshooting //uart_init(115200, 115200); //logInit(); - //os_delay_us(100000L); + //os_delay_us(60000L); + // get the flash config so we know how to init things //configWipe(); // uncomment to reset the config for testing purposes bool restoreOk = configRestore(); @@ -202,7 +205,7 @@ user_init(void) { #ifdef SHOW_HEAP_USE os_timer_disarm(&prHeapTimer); os_timer_setfn(&prHeapTimer, prHeapTimerCb, NULL); - os_timer_arm(&prHeapTimer, 10 * 1000, 1); + os_timer_arm_us(&prHeapTimer, 10 * 1000000, 1); #endif struct rst_info *rst_info = system_get_rst_info(); diff --git a/esp-link/status.c b/esp-link/status.c index 6905850..70a96d0 100644 --- a/esp-link/status.c +++ b/esp-link/status.c @@ -92,7 +92,7 @@ static void ICACHE_FLASH_ATTR ledTimerCb(void *v) { } setLed(ledState); - os_timer_arm(&ledTimer, time, 0); + os_timer_arm_us(&ledTimer, time * 1000, 0); } // change the wifi state indication @@ -101,7 +101,7 @@ void ICACHE_FLASH_ATTR statusWifiUpdate(uint8_t state) { // schedule an update (don't want to run into concurrency issues) os_timer_disarm(&ledTimer); os_timer_setfn(&ledTimer, ledTimerCb, NULL); - os_timer_arm(&ledTimer, 500, 0); + os_timer_arm_us(&ledTimer, 500000, 0); } //===== Init status stuff @@ -117,12 +117,12 @@ void ICACHE_FLASH_ATTR statusInit(void) { os_timer_disarm(&ledTimer); os_timer_setfn(&ledTimer, ledTimerCb, NULL); - os_timer_arm(&ledTimer, 2000, 0); + os_timer_arm_us(&ledTimer, 2 * 1000000, 0); #ifdef MQTT os_timer_disarm(&mqttStatusTimer); os_timer_setfn(&mqttStatusTimer, mqttStatusCb, NULL); - os_timer_arm(&mqttStatusTimer, MQTT_STATUS_INTERVAL, 1); // recurring timer + os_timer_arm_us(&mqttStatusTimer, MQTT_STATUS_INTERVAL * 1000, 1); // recurring timer #endif // MQTT } diff --git a/html/home.html b/html/home.html index de9862f..59dc5fd 100644 --- a/html/home.html +++ b/html/home.html @@ -76,6 +76,12 @@ +
+ + + +
diff --git a/html/ui.js b/html/ui.js index 67361c9..eb50b4c 100644 --- a/html/ui.js +++ b/html/ui.js @@ -393,12 +393,12 @@ function showNotification(text) { //===== GPIO Pin mux card var pinPresets = { - // array: reset, isp, conn, ser, swap, rxpup - "esp-01": [ 0, -1, 2, -1, 0, 1 ], - "esp-12": [ 12, 14, 0, 2, 0, 1 ], - "esp-12 swap": [ 1, 3, 0, 2, 1, 1 ], - "esp-bridge": [ 12, 13, 0, 14, 0, 0 ], - "wifi-link-12": [ 1, 3, 0, 2, 1, 0 ], + // array: reset, isp, conn, ser, swap, rxpup, txen + "esp-01": [ 0, -1, 2, -1, 0, 1, -1 ], + "esp-12": [ 12, 14, 0, 2, 0, 1, -1 ], + "esp-12 swap": [ 1, 3, 0, 2, 1, 1, -1 ], + "esp-bridge": [ 12, 13, 0, 14, 0, 0, -1 ], + "wifi-link-12": [ 1, 3, 0, 2, 1, 0, -1 ], }; function createPresets(sel) { @@ -418,6 +418,7 @@ function createPresets(sel) { setPP("ser", pp[3]); setPP("swap", pp[4]); $("#pin-rxpup").checked = !!pp[5]; + setPP("txen", pp[6]); sel.value = 0; }; @@ -453,6 +454,7 @@ function displayPins(resp) { createSelectForPin("ser", resp["ser"]); $("#pin-swap").value = resp["swap"]; $("#pin-rxpup").checked = !!resp["rxpup"]; + createSelectForPin("txen", resp["txen"]); createPresets($("#pin-preset")); $("#pin-spinner").setAttribute("hidden", ""); @@ -469,7 +471,7 @@ function setPins(ev) { ev.preventDefault(); var url = "/pins"; var sep = "?"; - ["reset", "isp", "conn", "ser", "swap"].forEach(function(p) { + ["reset", "isp", "conn", "ser", "swap", "txen"].forEach(function(p) { url += sep + p + "=" + $("#pin-"+p).value; sep = "&"; }); diff --git a/include/esp8266.h b/include/esp8266.h index 9531dfe..3cb71cf 100644 --- a/include/esp8266.h +++ b/include/esp8266.h @@ -18,6 +18,7 @@ #include #include +#define USE_US_TIMER #include #include diff --git a/mqtt/mqtt.c b/mqtt/mqtt.c index cce3436..f6a557e 100644 --- a/mqtt/mqtt.c +++ b/mqtt/mqtt.c @@ -703,7 +703,7 @@ MQTT_Connect(MQTT_Client* client) { // start timer function to tick every second os_timer_disarm(&client->mqttTimer); os_timer_setfn(&client->mqttTimer, (os_timer_func_t *)mqtt_timer, client); - os_timer_arm(&client->mqttTimer, 1000, 1); + os_timer_arm_us(&client->mqttTimer, 1 * 1000000, 1); // initiate the TCP connection or DNS lookup os_printf("MQTT: Connect to %s:%d %p (client=%p)\n", diff --git a/serial/serbridge.c b/serial/serbridge.c index 88de652..4b71b1b 100644 --- a/serial/serbridge.c +++ b/serial/serbridge.c @@ -18,7 +18,7 @@ static struct espconn serbridgeConn1; // plain bridging port static struct espconn serbridgeConn2; // programming port static esp_tcp serbridgeTcp1, serbridgeTcp2; -static int8_t mcu_reset_pin, mcu_isp_pin; +static int8_t mcu_reset_pin, mcu_isp_pin, tx_enable_pin; uint8_t in_mcu_flashing; // for disabling slip during MCU flashing @@ -557,9 +557,10 @@ serbridgeInitPins() { mcu_reset_pin = flashConfig.reset_pin; mcu_isp_pin = flashConfig.isp_pin; + tx_enable_pin = flashConfig.tx_enable_pin; #ifdef SERBR_DBG - os_printf("Serbridge pins: reset=%d isp=%d swap=%d\n", - mcu_reset_pin, mcu_isp_pin, flashConfig.swap_uart); + os_printf("Serbridge pins: reset=%d isp=%d tx_enable=%d swap=%d\n", + mcu_reset_pin, mcu_isp_pin, tx_enable_pin, flashConfig.swap_uart); #endif if (flashConfig.swap_uart) { @@ -578,12 +579,25 @@ serbridgeInitPins() system_uart_de_swap(); } - // set both pins to 1 before turning them on so we don't cause a reset - if (mcu_isp_pin >= 0) GPIO_OUTPUT_SET(mcu_isp_pin, 1); - if (mcu_reset_pin >= 0) GPIO_DIS_OUTPUT(mcu_reset_pin); - // switch pin mux to make these pins GPIO pins - if (mcu_reset_pin >= 0) makeGpio(mcu_reset_pin); - if (mcu_isp_pin >= 0) makeGpio(mcu_isp_pin); + /* set both pins to 1 before turning them on (so we don't cause a reset) + * then switch pin mux to make these pins GPIO pins + */ + if (mcu_isp_pin >= 0) { + GPIO_OUTPUT_SET(mcu_isp_pin, 1); + makeGpio(mcu_isp_pin); + } + + if (mcu_reset_pin >= 0) { + GPIO_OUTPUT_SET(mcu_reset_pin, 1); + makeGpio(mcu_reset_pin); + } + + // set TX_ENABLE to 0 so we start up listening + if (tx_enable_pin >= 0) { + GPIO_OUTPUT_SET(tx_enable_pin, 0); + makeGpio(tx_enable_pin); + } + //uart0_set_tx_enable_pin(tx_enable_pin); // must set to -1 if that's its value } // Start transparent serial bridge TCP server on specified port (typ. 23) diff --git a/serial/serled.c b/serial/serled.c index 5bd66a2..8d533e1 100644 --- a/serial/serled.c +++ b/serial/serled.c @@ -25,7 +25,7 @@ void ICACHE_FLASH_ATTR serledFlash(int duration) { setSerled(1); os_timer_disarm(&serledTimer); os_timer_setfn(&serledTimer, serledTimerCb, NULL); - os_timer_arm(&serledTimer, duration, 0); + os_timer_arm_us(&serledTimer, duration * 1000, 0); } void ICACHE_FLASH_ATTR serledInit(void) { diff --git a/syslog/syslog.c b/syslog/syslog.c index 5c88901..3c8ae48 100644 --- a/syslog/syslog.c +++ b/syslog/syslog.c @@ -91,7 +91,7 @@ static void ICACHE_FLASH_ATTR syslog_timer_arm(int delay) { syslog_timer_armed = true; os_timer_disarm(&wifi_chk_timer); os_timer_setfn(&wifi_chk_timer, (os_timer_func_t *)syslog_chk_status, NULL); - os_timer_arm(&wifi_chk_timer, delay, 0); + os_timer_arm_us(&wifi_chk_timer, delay * 1000, 0); } /******************************************************************************