diff --git a/user/cgipins.c b/user/cgipins.c index ade7068..bf9b823 100644 --- a/user/cgipins.c +++ b/user/cgipins.c @@ -2,16 +2,20 @@ #include #include "cgi.h" #include "espfs.h" +#include "config.h" static char *map_names[] = { - "esp-bridge", "jn-esp-v2", "esp-01" + "esp-bridge", "jn-esp-v2", "esp-01(ARM)", "esp-01(AVR)", }; static char* map_func[] = { "reset", "isp", "conn_led", "ser_led" }; -static uint8_t map_asn[][4] = { +static int8_t map_asn[][4] = { { 12, 13, 0, 14 }, // esp-bridge { 12, 13, 0, 2 }, // jn-esp-v2 - { 0, 2, 12, 13 }, // esp-01 + { 0, 2, -1, -1 }, // esp-01(ARM) + { 0, -1, 2, -1 }, // esp-01(AVR) }; +static const int num_map_names = sizeof(map_names)/sizeof(char*); +static const int num_map_func = sizeof(map_func)/sizeof(char*); // Cgi to return choice of pin assignments int ICACHE_FLASH_ATTR cgiPinsGet(HttpdConnData *connData) { @@ -22,15 +26,25 @@ int ICACHE_FLASH_ATTR cgiPinsGet(HttpdConnData *connData) { return HTTPD_CGI_DONE; // Connection aborted } - len = os_sprintf(buff, "{ \"curr\":\"esp-bridge\", \"map\": [ "); - for (int i=0; igetArgs, "map", buff, sizeof(buff)); + if (len == 0) { + jsonHeader(connData, 400); + return HTTPD_CGI_DONE; + } + + int m = atoi(buff); + if (m < 0 || m >= num_map_names) { + jsonHeader(connData, 400); + return HTTPD_CGI_DONE; + } + + os_printf("Switching pin map to %s (%d)\n", map_names[m], m); + int8_t *map = map_asn[m]; + flashConfig.reset_pin = map[0]; + flashConfig.isp_pin = map[1]; + flashConfig.conn_led_pin = map[2]; + flashConfig.ser_led_pin = map[3]; + jsonHeader(connData, 200); return HTTPD_CGI_DONE; } diff --git a/user/cgipins.h b/user/cgipins.h index 53e46cb..cacd913 100644 --- a/user/cgipins.h +++ b/user/cgipins.h @@ -4,5 +4,6 @@ #include "httpd.h" int cgiPins(HttpdConnData *connData); +int8_t pin_reset, pin_isp, pin_conn, pin_ser; #endif diff --git a/user/config.c b/user/config.c new file mode 100644 index 0000000..e6eec90 --- /dev/null +++ b/user/config.c @@ -0,0 +1,20 @@ +/* Configuration stored in flash */ + +#include +#include +#include "config.h" +#include "espfs.h" + +FlashConfig flashConfig = { + MCU_RESET_PIN, MCU_ISP_PIN, LED_CONN_PIN, LED_SERIAL_PIN, + 115200, + "esp-link\0 ", +}; + +bool ICACHE_FLASH_ATTR configSave(void) { + return true; +} + +bool ICACHE_FLASH_ATTR configRestore(void) { + return true; +} diff --git a/user/config.h b/user/config.h new file mode 100644 index 0000000..513f0c9 --- /dev/null +++ b/user/config.h @@ -0,0 +1,14 @@ +#ifndef CONFIG_H +#define CONFIG_H + +typedef struct { + int8_t reset_pin, isp_pin, conn_led_pin, ser_led_pin; + int32_t baud_rate; + char hostname[32]; +} FlashConfig; +extern FlashConfig flashConfig; + +bool configSave(void); +bool configRestore(void); + +#endif