diff --git a/CMakeLists.txt b/CMakeLists.txt index 4da3a2f..f31a6d4 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,6 @@ # The following lines of boilerplate have to be in your project's CMakeLists # in this exact order for cmake to work correctly -cmake_minimum_required(VERSION 3.5) +cmake_minimum_required(VERSION 3.16) set(SUPPORTED_TARGETS esp32) include($ENV{IDF_PATH}/tools/cmake/project.cmake) diff --git a/README.md b/README.md index 212eece..678aaf8 100644 --- a/README.md +++ b/README.md @@ -40,6 +40,16 @@ With `idf.py -p (PORT) flash` or `make flash` you can upload this build to an ES With `idf.py -p (PORT) monitor` or `make monitor` you can see the debug output (please use this output if you open an issue) or trigger basic test commands (mouse movement or a keyboard key press) on a connected target. + +### esp32miniBT vs. Arduino Nano Connect + +This firmware is used on 2 different devices in context of our assistive devices: +* __esp32miniBT module__: This board is located in this repository and is used as addon for v2 FLipMouse, FABI and FLipPad PCBs which use either a TeensyLC or a ProMicro controller. +* __Arduino Nano RP2040 Connect__: Version 3 of FLipMouse and FLipPad (maybe FABI as well) use this Arduino board, where we have a RP2040 controller AND the ESP32 on the same board (more RAM, more flash, cheaper than 2 boards). + +__Note:__ Please select the correct type of board in `idf.py menuconfig`! + +__Note:__ If you want to use this firmware on a custom board, you can select the external UART interface settings in menuconfig; for our boards the pinning, baudrate and UART config is pre-defined. # Usage via Console or second UART diff --git a/main/CMakeLists.txt b/main/CMakeLists.txt index e5ca208..31d5ae7 100644 --- a/main/CMakeLists.txt +++ b/main/CMakeLists.txt @@ -3,6 +3,6 @@ idf_component_register(SRCS "ble_hidd_demo_main.c" "hid_dev.c" "hid_device_le_prf.c" INCLUDE_DIRS "." - REQUIRES esp_hid PRIV_REQUIRES esp32 esp_wifi esp_websocket_client esp_https_server esp_eth mdns lwip fatfs openssl esp_https_ota esp_hid app_update) + REQUIRES esp_hid PRIV_REQUIRES esp_wifi esp_https_server esp_eth nvs_flash lwip fatfs esp_https_ota esp_hid app_update) target_compile_options(${COMPONENT_LIB} PRIVATE -Wno-unused-const-variable) diff --git a/main/Kconfig.projbuild b/main/Kconfig.projbuild index 41b5a05..34e84f0 100644 --- a/main/Kconfig.projbuild +++ b/main/Kconfig.projbuild @@ -1,25 +1,35 @@ -menu "esp32_mouse_keyboard - FLipMouse & FABI config" - - config MODULE_RX_PIN - int "RX pin for command/HID UART" - default 17 - range 1 39 - - config MODULE_TX_PIN - int "TX pin for command/HID UART" - default 16 - range 1 39 - - config MODULE_LED_PIN - int "LED connection indicator pin" - default 5 - range 1 39 - - config MODULE_UART_NR - int "UART interface number" - default 2 - range 1 2 +menu "esp32_mouse_keyboard / FLipMouse & FABI config" + config USE_AS_FLIPMOUSE_FABI + bool "Use project as FLipMouse/FABI Bluetooth module" + default n + help + If this option is enabled, a FLipMouse/FABI Bluetooth module + is built. If disabled, this project acts as demo code for Bluetooth + HID code. + + menu "Pinning for UART RX/TX & LED (if not a defined module)" + visible if !USE_AS_FLIPMOUSE_FABI + + config MODULE_RX_PIN + int "RX pin for command/HID UART" + default 17 + range 1 39 + + config MODULE_TX_PIN + int "TX pin for command/HID UART" + default 16 + range 1 39 + + config MODULE_LED_PIN + int "LED connection indicator pin" + default 5 + range 1 39 + config MODULE_UART_NR + int "UART interface number" + default 2 + range 1 2 + endmenu config MODULE_USEKEYBOARD bool "Enable BLE-HID keyboard (UNUSED)" default y @@ -56,50 +66,4 @@ menu "esp32_mouse_keyboard - FLipMouse & FABI config" If enabled, the module denies pairing requests by default. It is possible to enable the pairing by sending the pairing en-/disable command via the serial interface. - - - config USE_AS_FLIPMOUSE_FABI - bool "Use project as FLipMouse/FABI Bluetooth module" - default n - help - If this option is enabled, a FLipMouse/FABI Bluetooth module - is built. If disabled, this project acts as demo code for Bluetooth - HID code. - menu "FLipMouse / FABI configuration" - visible if USE_AS_FLIPMOUSE_FABI - - choice MODULE_TYPE - prompt "Module type (FLipMouse/FABI)" - depends on USE_AS_FLIPMOUSE_FABI - help - Specify the module type (FLipMouse or FABI). - - config MODULE_FLIPMOUSE - bool "FLipMouse" - - config MODULE_FABI - bool "FABI" - endchoice - - config FM_WEBGUI - bool "Enable WebGUI (UNUSED)" - default n - help - Enable the WebGUI for the FLipMouse in the ESP32. - - config FM_OTA - depends on MODULE_FLIPMOUSE - bool "Enable programming via Teensy (UNUSED)" - default n - help - Enable the update functionality via the Teensy module. - - config FABI_OTA - depends on MODULE_FABI - bool "Enable programming via ArduinoProMicro (UNUSED)" - default n - help - Enable the update functionality via the Arduino Pro Micro module. - - endmenu endmenu diff --git a/main/ble_hidd_demo_main.c b/main/ble_hidd_demo_main.c index 88146d4..f35c9ef 100644 --- a/main/ble_hidd_demo_main.c +++ b/main/ble_hidd_demo_main.c @@ -14,7 +14,9 @@ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, * MA 02110-1301, USA. * - * + * Copyright 2023: + * Benjamin Aigner , + * * Copyright 2020-2021: * Benjamin Aigner ,, * Junaid Khan @@ -62,6 +64,7 @@ #include "hid_dev.h" #include "config.h" #include "esp_ota_ops.h" +#include "esp_flash.h" /** * Brief: @@ -125,6 +128,32 @@ uint64_t timestampLastSent; * @see periodicHIDCallback */ uint8_t mouseButtons = 0; +/** Flag for hardware which this firmware is running on. + * If we are running this software on the Arudino RP2040 connect, + * we need to use different pins, also another UART (including pins). + * This flag is set immediately after startup in app_main and is set + * based on the flash size. All modules we used were with >=4MB flash, + * the uBlox NINA module on the Arduino RP2040 connect uses 2MB. */ +bool onArduinoRP2040 = false; + +/** 2nd UART unit number for RX/TX of commands + * Previously we used a define via KConfig to set the UART number. + * Because we need to detect on the fly if we are on an Arduino RP2040 Connect + * or on a Bluetooth addon, this value is set in a variable now. */ +int ext_uart_num = 0; + +/** 2nd UART unit RX pin */ +int ext_uart_rx = -1; + +/** 2nd UART unit TX pin */ +int ext_uart_tx = -1; + +/** pin number for indicator LED + * Was also a KConfig define for all available builds, now it is fixed + * for FABI/FM/FP builds depending on Arduino or addon board. + * For other modules or custom builds, it can be defined via idf.py menuconfig. */ +int indicator_led = -1; + /** "Keepalive" rate when in idle (no HID commands) * @note Microseconds! * @see timestampLastSent @@ -273,7 +302,7 @@ int get_int(const char * input, int index, int * value) /** Periodic sending of empty HID reports if no updates are sent via API */ static void periodicHIDCallback(void* arg) { - if(abs(esp_timer_get_time()-timestampLastSent) > HID_IDLE_UPDATE_RATE) + if((esp_timer_get_time()-timestampLastSent) > HID_IDLE_UPDATE_RATE) { //send empty report (but with last known button state) for(uint8_t i = 0; ible_security.auth_cmpl.addr_type); ESP_LOGI(HID_DEMO_TAG, "pair status = %s",param->ble_security.auth_cmpl.success ? "success" : "fail"); if(!param->ble_security.auth_cmpl.success) { - ESP_LOGE(HID_DEMO_TAG, "fail reason = 0x%x",param->ble_security.auth_cmpl.fail_reason); + ESP_LOGW(HID_DEMO_TAG, "fail reason = 0x%x",param->ble_security.auth_cmpl.fail_reason); } else { xEventGroupClearBits(eventgroup_system,SYSTEM_CURRENTLY_ADVERTISING); } @@ -505,7 +534,7 @@ static void gap_event_handler(esp_gap_ble_cb_event_t event, esp_ble_gap_cb_param case ESP_GAP_BLE_SCAN_START_COMPLETE_EVT: //scan start complete event to indicate scan start successfully or failed if (param->scan_start_cmpl.status != ESP_BT_STATUS_SUCCESS) { - ESP_LOGE(HID_DEMO_TAG, "scan start failed, error status = %x", param->scan_start_cmpl.status); + ESP_LOGW(HID_DEMO_TAG, "scan start failed, error status = %x", param->scan_start_cmpl.status); break; } ESP_LOGI(HID_DEMO_TAG, "Scan start success"); @@ -530,18 +559,50 @@ void processCommand(struct cmdBuf *cmdBuffer) // $GV get the value of the given key from NVS. Note: no spaces in ! max. key length: 15 // $SV set the value of the given key & store to NVS. Note: no spaces in ! // $CV clear all key/value pairs set with $SV - // $UG start flash update by searching for factory partition and rebooting there. + // $UG start flash update by searching for factory partition and rebooting there. Warning: not possible to boot back without flashing! + // $LGx (0,1,2): enable / disable logging system of ESP32.0 is level error, 1 is level info, 2 is level debug if(cmdBuffer->bufferLength < 2) return; //easier this way than typecast in each str* function const char *input = (const char *) cmdBuffer->buf; int len = cmdBuffer->bufferLength; - uint8_t keycode; const char *nl = "\r\n"; esp_ble_bond_dev_t * btdevlist; int counter; esp_err_t ret; - + + /**++++en-/disable logging++++*/ + if(strcmp(input,"LG0") == 0) + { + esp_log_level_set("*",ESP_LOG_ERROR); + if(cmdBuffer->sendToUART != 0) + { + uart_write_bytes(ext_uart_num, "LOG:0",strlen("LOG:0")); + uart_write_bytes(ext_uart_num,nl,sizeof(nl)); //newline + } + return; + } + if(strcmp(input,"LG1") == 0) + { + esp_log_level_set("*",ESP_LOG_INFO); + if(cmdBuffer->sendToUART != 0) + { + uart_write_bytes(ext_uart_num, "LOG:1",strlen("LOG:1")); + uart_write_bytes(ext_uart_num,nl,sizeof(nl)); //newline + } + return; + } + if(strcmp(input,"LG2") == 0) + { + esp_log_level_set("*",ESP_LOG_DEBUG); + if(cmdBuffer->sendToUART != 0) + { + uart_write_bytes(ext_uart_num, "LOG:2",strlen("LOG:2")); + uart_write_bytes(ext_uart_num,nl,sizeof(nl)); //newline + } + return; + } + /**++++ key/value storing ++++*/ if(strncmp(input,"CV ", 2) == 0) { @@ -554,8 +615,8 @@ void processCommand(struct cmdBuf *cmdBuffer) ESP_LOGI(EXT_UART_TAG,"cleared all NVS key/value pairs"); if(cmdBuffer->sendToUART != 0) { - uart_write_bytes(EX_UART_NUM, "NVS:OK",strlen("NVS:OK")); - uart_write_bytes(EX_UART_NUM,nl,sizeof(nl)); //newline + uart_write_bytes(ext_uart_num, "NVS:OK",strlen("NVS:OK")); + uart_write_bytes(ext_uart_num,nl,sizeof(nl)); //newline } return; } @@ -584,18 +645,18 @@ void processCommand(struct cmdBuf *cmdBuffer) if(ret != ESP_OK) { //send back error message - ESP_LOGE(EXT_UART_TAG,"error reading value: %s",esp_err_to_name(ret)); + ESP_LOGI(EXT_UART_TAG,"error reading value: %s",esp_err_to_name(ret)); if(cmdBuffer->sendToUART != 0) { - uart_write_bytes(EX_UART_NUM, "NVS:",strlen("NVS:")); - uart_write_bytes(EX_UART_NUM, esp_err_to_name(ret), strlen(esp_err_to_name(ret))); - uart_write_bytes(EX_UART_NUM,nl,sizeof(nl)); //newline + uart_write_bytes(ext_uart_num, "NVS:",strlen("NVS:")); + uart_write_bytes(ext_uart_num, esp_err_to_name(ret), strlen(esp_err_to_name(ret))); + uart_write_bytes(ext_uart_num,nl,sizeof(nl)); //newline } } else { ESP_LOGI(EXT_UART_TAG,"loaded - %s:%s",key,nvspayload); - uart_write_bytes(EX_UART_NUM, "NVS:",strlen("NVS:")); - uart_write_bytes(EX_UART_NUM, nvspayload, strlen(nvspayload)); - uart_write_bytes(EX_UART_NUM,nl,sizeof(nl)); //newline + uart_write_bytes(ext_uart_num, "NVS:",strlen("NVS:")); + uart_write_bytes(ext_uart_num, nvspayload, strlen(nvspayload)); + uart_write_bytes(ext_uart_num,nl,sizeof(nl)); //newline } //done with the payload @@ -615,11 +676,11 @@ void processCommand(struct cmdBuf *cmdBuffer) if(work == NULL) { - ESP_LOGE(EXT_UART_TAG,"error setting string: no value provided"); + ESP_LOGI(EXT_UART_TAG,"error setting string: no value provided"); if(cmdBuffer->sendToUART != 0) { - uart_write_bytes(EX_UART_NUM, "NVS:ESP_ERR_NVS_NO_VALUE",strlen("NVS:ESP_ERR_NVS_NO_VALUE")); - uart_write_bytes(EX_UART_NUM,nl,sizeof(nl)); //newline + uart_write_bytes(ext_uart_num, "NVS:ESP_ERR_NVS_NO_VALUE",strlen("NVS:ESP_ERR_NVS_NO_VALUE")); + uart_write_bytes(ext_uart_num,nl,sizeof(nl)); //newline } return; } @@ -636,12 +697,12 @@ void processCommand(struct cmdBuf *cmdBuffer) if(ret != ESP_OK) { //send back error message - ESP_LOGE(EXT_UART_TAG,"error setting string: %s",esp_err_to_name(ret)); + ESP_LOGI(EXT_UART_TAG,"error setting string: %s",esp_err_to_name(ret)); if(cmdBuffer->sendToUART != 0) { - uart_write_bytes(EX_UART_NUM, "NVS:",strlen("NVS:")); - uart_write_bytes(EX_UART_NUM, esp_err_to_name(ret), strlen(esp_err_to_name(ret))); - uart_write_bytes(EX_UART_NUM,nl,sizeof(nl)); //newline + uart_write_bytes(ext_uart_num, "NVS:",strlen("NVS:")); + uart_write_bytes(ext_uart_num, esp_err_to_name(ret), strlen(esp_err_to_name(ret))); + uart_write_bytes(ext_uart_num,nl,sizeof(nl)); //newline } } else { //send back OK & used/free entries @@ -650,11 +711,11 @@ void processCommand(struct cmdBuf *cmdBuffer) ESP_LOGI(EXT_UART_TAG,"set - %s:%s - used:%d,free:%d",key,nvspayload,nvs_stats.used_entries, nvs_stats.free_entries); if(cmdBuffer->sendToUART != 0) { - uart_write_bytes(EX_UART_NUM, "NVS:OK ", strlen("NVS:OK ")); + uart_write_bytes(ext_uart_num, "NVS:OK ", strlen("NVS:OK ")); char stats[64]; sprintf(stats,"%d/%d - used/free",nvs_stats.used_entries, nvs_stats.free_entries); - uart_write_bytes(EX_UART_NUM,stats,strnlen(stats,64)); - uart_write_bytes(EX_UART_NUM,nl,sizeof(nl)); //newline + uart_write_bytes(ext_uart_num,stats,strnlen(stats,64)); + uart_write_bytes(ext_uart_num,nl,sizeof(nl)); //newline } } return; @@ -675,13 +736,13 @@ void processCommand(struct cmdBuf *cmdBuffer) if(memcmp(active_connections[i],empty,sizeof(esp_bd_addr_t)) != 0) { //print on monitor & external uart - if(cmdBuffer->sendToUART != 0) uart_write_bytes(EX_UART_NUM, "CONNECTED:",strlen("CONNECTED:")); + if(cmdBuffer->sendToUART != 0) uart_write_bytes(ext_uart_num, "CONNECTED:",strlen("CONNECTED:")); esp_log_buffer_hex(EXT_UART_TAG, active_connections[i], sizeof(esp_bd_addr_t)); for (int t=0; tsendToUART != 0) uart_write_bytes(EX_UART_NUM, hexnum, 3); + if(cmdBuffer->sendToUART != 0) uart_write_bytes(ext_uart_num, hexnum, 3); } - if(cmdBuffer->sendToUART != 0) uart_write_bytes(EX_UART_NUM,nl,sizeof(nl)); //newline + if(cmdBuffer->sendToUART != 0) uart_write_bytes(ext_uart_num,nl,sizeof(nl)); //newline } } ESP_LOGI(EXT_UART_TAG,"---------------------------------------"); @@ -727,8 +788,8 @@ void processCommand(struct cmdBuf *cmdBuffer) { if(cmdBuffer->sendToUART != 0) { - uart_write_bytes(EX_UART_NUM, MODULE_ID, sizeof(MODULE_ID)); - uart_write_bytes(EX_UART_NUM, nl, sizeof(nl)); + uart_write_bytes(ext_uart_num, MODULE_ID, sizeof(MODULE_ID)); + uart_write_bytes(ext_uart_num, nl, sizeof(nl)); } ESP_LOGI(EXT_UART_TAG,"ID: %s",MODULE_ID); return; @@ -787,11 +848,11 @@ void processCommand(struct cmdBuf *cmdBuffer) for(uint8_t i = 0; isendToUART != 0) uart_write_bytes(EX_UART_NUM, "PAIRING:",strlen("PAIRING:")); + if(cmdBuffer->sendToUART != 0) uart_write_bytes(ext_uart_num, "PAIRING:",strlen("PAIRING:")); esp_log_buffer_hex(EXT_UART_TAG, btdevlist[i].bd_addr, sizeof(esp_bd_addr_t)); for (int t=0; tsendToUART != 0) uart_write_bytes(EX_UART_NUM, hexnum, 3); + if(cmdBuffer->sendToUART != 0) uart_write_bytes(ext_uart_num, hexnum, 3); } //print out name char btname[64]; @@ -803,19 +864,19 @@ void processCommand(struct cmdBuf *cmdBuffer) if(nvs_get_str(nvs_bt_name_h,key,btname,&name_len) == ESP_OK) { sprintf(hexnum," - "); - if(cmdBuffer->sendToUART != 0) uart_write_bytes(EX_UART_NUM, hexnum, 3); - if(cmdBuffer->sendToUART != 0) uart_write_bytes(EX_UART_NUM, btname, name_len); + if(cmdBuffer->sendToUART != 0) uart_write_bytes(ext_uart_num, hexnum, 3); + if(cmdBuffer->sendToUART != 0) uart_write_bytes(ext_uart_num, btname, name_len); ESP_LOGI(EXT_UART_TAG,"%s",btname); } else ESP_LOGW(EXT_UART_TAG,"cannot find name for addr."); - if(cmdBuffer->sendToUART != 0) uart_write_bytes(EX_UART_NUM,nl,sizeof(nl)); //newline + if(cmdBuffer->sendToUART != 0) uart_write_bytes(ext_uart_num,nl,sizeof(nl)); //newline } ESP_LOGI(EXT_UART_TAG,"---------------------------------------"); - } else ESP_LOGE(EXT_UART_TAG,"error getting device list"); + } else ESP_LOGW(EXT_UART_TAG,"error getting device list"); } else ESP_LOGE(EXT_UART_TAG,"error allocating memory for device list"); } else { - ESP_LOGE(EXT_UART_TAG,"error getting bonded devices count or no devices bonded"); - if(cmdBuffer->sendToUART != 0) uart_write_bytes(EX_UART_NUM, "END\r\n", 5); + ESP_LOGI(EXT_UART_TAG,"error getting bonded devices count or no devices bonded"); + if(cmdBuffer->sendToUART != 0) uart_write_bytes(ext_uart_num, "END\r\n", 5); } return; } @@ -833,13 +894,13 @@ void processCommand(struct cmdBuf *cmdBuffer) counter = esp_ble_get_bond_device_num(); if(counter == 0) { - ESP_LOGE(EXT_UART_TAG,"error deleting device, no paired devices"); + ESP_LOGI(EXT_UART_TAG,"error deleting device, no paired devices"); return; } if(index_to_remove >= counter) { - ESP_LOGE(EXT_UART_TAG,"error deleting device, number out of range"); + ESP_LOGW(EXT_UART_TAG,"error deleting device, number out of range"); return; } if(counter >= 0) @@ -863,14 +924,14 @@ void processCommand(struct cmdBuf *cmdBuffer) esp_ble_gap_update_whitelist(false,btdevlist[i].bd_addr,BLE_WL_ADDR_TYPE_RANDOM); } } - } else ESP_LOGE(EXT_UART_TAG,"error getting device list"); + } else ESP_LOGI(EXT_UART_TAG,"error getting device list"); free (btdevlist); //wait 20 ticks for everything to settle (write commits to NVS) vTaskDelay(20); //then restart to avoid re-bonding of the device(s). esp_restart(); - } else ESP_LOGE(EXT_UART_TAG,"error allocating memory for device list"); - } else ESP_LOGE(EXT_UART_TAG,"error getting bonded devices count"); + } else ESP_LOGW(EXT_UART_TAG,"error allocating memory for device list"); + } else ESP_LOGW(EXT_UART_TAG,"error getting bonded devices count"); return; } @@ -898,24 +959,26 @@ void processCommand(struct cmdBuf *cmdBuffer) const esp_partition_t* factory = esp_partition_get(pi); esp_partition_iterator_release(pi); if (esp_ota_set_boot_partition(factory) == ESP_OK) { - uart_write_bytes(EX_UART_NUM, "OTA:start", strlen("OTA:start")); - uart_write_bytes(EX_UART_NUM, nl, sizeof(nl)); - ESP_LOGI(EXT_UART_TAG, "Addon board in upgrade mode"); + uart_write_bytes(ext_uart_num, "OTA:start", strlen("OTA:start")); + uart_write_bytes(ext_uart_num, nl, sizeof(nl)); + ESP_LOGI(EXT_UART_TAG, "Addon board in upgrade mode"); + //LED off + if(onArduinoRP2040) gpio_set_level(indicator_led, 1); + else gpio_set_level(indicator_led, 0); esp_restart(); - } - else { + }else { ESP_LOGI(EXT_UART_TAG, "Booting factory partition not possible"); - uart_write_bytes(EX_UART_NUM, "OTA:not possible", strlen("OTA:not possible")); - uart_write_bytes(EX_UART_NUM, nl, sizeof(nl)); + uart_write_bytes(ext_uart_num, "OTA:not possible", strlen("OTA:not possible")); + uart_write_bytes(ext_uart_num, nl, sizeof(nl)); } } else { ESP_LOGI(EXT_UART_TAG, "Factory partition not found"); - uart_write_bytes(EX_UART_NUM, "OTA:not possible", strlen("OTA:not possible")); - uart_write_bytes(EX_UART_NUM, nl, sizeof(nl)); + uart_write_bytes(ext_uart_num, "OTA:not possible", strlen("OTA:not possible")); + uart_write_bytes(ext_uart_num, nl, sizeof(nl)); } return; } - ESP_LOGE(EXT_UART_TAG,"No command executed with: %s ; len= %d\n",input,len); + ESP_LOGW(EXT_UART_TAG,"No command executed with: %s ; len= %d\n",input,len); } void uart_parse_command (uint8_t character, struct cmdBuf * cmdBuffer) @@ -982,7 +1045,7 @@ void uart_parse_command (uint8_t character, struct cmdBuf * cmdBuffer) mouseButtons = cmdBuffer->buf[2]; //ESP_LOGI(EXT_UART_TAG,"m: %d/%d",cmdBuffer->buf[3],cmdBuffer->buf[4]); } - else ESP_LOGE(EXT_UART_TAG,"Unknown RAW HID packet"); + else ESP_LOGW(EXT_UART_TAG,"Unknown RAW HID packet"); } cmdBuffer->state=CMDSTATE_IDLE; } @@ -1013,59 +1076,70 @@ void uart_external_task(void *pvParameters) struct cmdBuf cmdBuffer; int changePinning = 0; - /* determine if we should switch RX/TX pins. */ - /* we enable the RX pin as GPIO with pull-down. - * if "1" is read, this is the "real" RX pin. If not, it - * should be the TX pin. */ - - gpio_config_t io_conf; - //disable interrupt - io_conf.intr_type = GPIO_INTR_DISABLE; - //set as output mode - io_conf.mode = GPIO_MODE_INPUT; - //bit mask, we want to set the RX pin as input - io_conf.pin_bit_mask = (1ULL<> 20; //now we have 2,4,8,.. + if(size_flash_chip > 2) + { + ESP_LOGW(HID_DEMO_TAG,"Not on Arduino RP2040 connect, using WROOM setup"); + } else onArduinoRP2040 = true; + esp_err_t ret; + //if we have this firmware on the Arduino, + //we should disable logging on startup. + if(onArduinoRP2040) esp_log_level_set("*",ESP_LOG_ERROR); + + //set external UART number according to setup + //and setup anything pin related. + #if CONFIG_USE_AS_FLIPMOUSE_FABI + if(onArduinoRP2040) + { + ext_uart_num = UART_NUM_0; + //GPIO26 is blue; 25 is green and 27 red + indicator_led = GPIO_NUM_26; + } else { + ext_uart_num = UART_NUM_2; + ext_uart_rx = GPIO_NUM_17; + ext_uart_tx = GPIO_NUM_16; + indicator_led = GPIO_NUM_5; + } + #else + ext_uart_num = CONFIG_MODULE_UART_NR; + ext_uart_rx = CONFIG_MODULE_RX_PIN; + ext_uart_tx = CONFIG_MODULE_TX_PIN; + indicator_led = CONFIG_MODULE_LED_PIN; + #endif // Initialize FreeRTOS elements eventgroup_system = xEventGroupCreate(); @@ -1359,8 +1494,8 @@ void app_main(void) //start active scan //if(esp_ble_gap_set_scan_params(&scan_params) != ESP_OK) ESP_LOGE("MAIN","Cannot set scan params"); - - xTaskCreate(&uart_console_task, "console", 4096, NULL, configMAX_PRIORITIES, NULL); + //a console for HID debugging (sending simple mouse/kbd commands) is not available on Arduino RP2040 Connect. + if(!onArduinoRP2040) xTaskCreate(&uart_console_task, "console", 4096, NULL, configMAX_PRIORITIES, NULL); xTaskCreate(&uart_external_task, "external", 4096, NULL, configMAX_PRIORITIES, NULL); ///@todo maybe reduce stack size for blink task? 4k words for blinky :-)? xTaskCreate(&blink_task, "blink", 4096, NULL, configMAX_PRIORITIES, NULL); @@ -1375,4 +1510,8 @@ void app_main(void) esp_timer_create(&periodic_timer_args, &periodic_timer); //call every 100ms esp_timer_start_periodic(periodic_timer, 100000); + + //avoid unused variable warnings here: + (void)hidd_adv_resp; + (void)scan_params; } diff --git a/main/config.h b/main/config.h index e41dbcf..98f98d4 100644 --- a/main/config.h +++ b/main/config.h @@ -2,31 +2,28 @@ #ifndef _CONFIG_H_ #define _CONFIG_H_ -#define MODULE_ID "ESP32miniBT_v0.3.2" - -#if CONFIG_MODULE_FLIPMOUSE - #define GATTS_TAG "FLipMouse" -#else - #if CONFIG_MODULE_FABI - #define GATTS_TAG "FABI" - #else - #define GATTS_TAG "esp32_mouse_keyboard" - #endif +#define MODULE_ID "ESP32miniBT_v0.3.4" + +#if CONFIG_USE_AS_FLIPMOUSE_FABI + //this will be overwritten by FABI/FLipMouse/FLipPad firmware to correct + //name, this is the BT device name for the first start + #define GATTS_TAG "AsTeRICS Foundation Module" +//non FM/FP/FABI boards +#else + #define EX_UART_NUM CONFIG_MODULE_UART_NR + #define GATTS_TAG "esp32_mouse_keyboard" + // indicator LED + #define INDICATOR_LED_PIN CONFIG_MODULE_LED_PIN + #define EX_SERIAL_TXPIN CONFIG_MODULE_TX_PIN + #define EX_SERIAL_RXPIN CONFIG_MODULE_RX_PIN #endif + #define MAX_BT_DEVICENAME_LENGTH 40 // serial port of monitor and for debugging (not in KConfig, won't be changed normally) #define CONSOLE_UART_NUM UART_NUM_0 -// serial port for connection to other controllers -#define EX_UART_NUM CONFIG_MODULE_UART_NR -#define EX_SERIAL_TXPIN CONFIG_MODULE_TX_PIN -#define EX_SERIAL_RXPIN CONFIG_MODULE_RX_PIN - -// indicator LED -#define INDICATOR_LED_PIN CONFIG_MODULE_LED_PIN - typedef struct config_data { char bt_device_name[MAX_BT_DEVICENAME_LENGTH]; uint8_t locale; diff --git a/sdkconfig.defaults b/sdkconfig.defaults index 453fcd6..25e5fc8 100644 --- a/sdkconfig.defaults +++ b/sdkconfig.defaults @@ -6,14 +6,14 @@ CONFIG_BTDM_CTRL_MODE_BR_EDR_ONLY=n CONFIG_BTDM_CTRL_MODE_BTDM=n # for testing with ESP32Think (Sparkfun), which has a different XTAl -CONFIG_ESP32_XTAL_FREQ_AUTO=y -CONFIG_ESP32_XTAL_FREQ=0 +CONFIG_XTAL_FREQ_AUTO=y +CONFIG_XTAL_FREQ=0 # ESP32-WROOM uses 4MB -CONFIG_ESPTOOLPY_FLASHSIZE_4MB=y -CONFIG_ESPTOOLPY_FLASHSIZE="4MB" -CONFIG_ESPTOOLPY_FLASHSIZE_DETECT=y +#CONFIG_ESPTOOLPY_FLASHSIZE_4MB=y +#CONFIG_ESPTOOLPY_FLASHSIZE="4MB" +# Arduino Nano connect Nina Module has 2MB +#CONFIG_ESPTOOLPY_FLASHSIZE_2MB=y +#CONFIG_ESPTOOLPY_FLASHSIZE="2MB" -# flash with 921k by default -CONFIG_ESPTOOLPY_BAUD_921600B=y -CONFIG_ESPTOOLPY_BAUD=921600 +CONFIG_ESPTOOLPY_HEADER_FLASHSIZE_UPDATE=y