From 21e040eb97793ed2ec856e8635db97c8e5281495 Mon Sep 17 00:00:00 2001 From: Mark Qvist Date: Wed, 2 Nov 2022 19:02:22 +0100 Subject: [PATCH] Updated start sequence, added boot graphics --- Bluetooth.h | 65 ++++++++------------ Device.h | 2 +- Display.h | 144 +++++++++++++++++++++++---------------------- Graphics.h | 17 ++++++ RNode_Firmware.ino | 37 +++++++----- Utilities.h | 14 +++++ 6 files changed, 155 insertions(+), 124 deletions(-) diff --git a/Bluetooth.h b/Bluetooth.h index 01c3576..099a442 100644 --- a/Bluetooth.h +++ b/Bluetooth.h @@ -71,52 +71,37 @@ char bt_devname[11]; } } - bool bt_early_init_done = false; - bool bt_early_init() { - if (!bt_early_init_done) { + bool bt_setup_hw() { + if (!bt_ready) { + if (EEPROM.read(eeprom_addr(ADDR_CONF_BT)) == BT_ENABLE_BYTE) { + bt_enabled = true; + } else { + bt_enabled = false; + } if (btStart()) { if (esp_bluedroid_init() == ESP_OK) { if (esp_bluedroid_enable() == ESP_OK) { const uint8_t* bda_ptr = esp_bt_dev_get_address(); - memcpy(dev_bt_mac, bda_ptr, BT_DEV_HASH_LEN); + char *data = (char*)malloc(BT_DEV_ADDR_LEN+1); + for (int i = 0; i < BT_DEV_ADDR_LEN; i++) { + data[i] = bda_ptr[i]; + } + data[BT_DEV_ADDR_LEN] = EEPROM.read(eeprom_addr(ADDR_SIGNATURE)); + unsigned char *hash = MD5::make_hash(data, BT_DEV_ADDR_LEN); + memcpy(bt_dh, hash, BT_DEV_HASH_LEN); + sprintf(bt_devname, "RNode %02X%02X", bt_dh[14], bt_dh[15]); + free(data); + + SerialBT.enableSSP(); + SerialBT.onConfirmRequest(bt_confirm_pairing); + SerialBT.onAuthComplete(bt_pairing_complete); + SerialBT.register_callback(bt_connection_callback); + + bt_ready = true; return true; - } else { - return false; - } - } else { - return false; - } - } else { - return false; - } - } else { - return true; - } - } - - bool bt_setup_hw() { - if (!bt_ready) { - if (EEPROM.read(eeprom_addr(ADDR_CONF_BT)) == BT_ENABLE_BYTE) { bt_enabled = true; } else { bt_enabled = false; } - if (bt_early_init()) { - const uint8_t* bda_ptr = esp_bt_dev_get_address(); - char *data = (char*)malloc(BT_DEV_ADDR_LEN+1); - for (int i = 0; i < BT_DEV_ADDR_LEN; i++) { - data[i] = bda_ptr[i]; - } - data[BT_DEV_ADDR_LEN] = EEPROM.read(eeprom_addr(ADDR_SIGNATURE)); - unsigned char *hash = MD5::make_hash(data, BT_DEV_ADDR_LEN); - memcpy(bt_dh, hash, BT_DEV_HASH_LEN); - sprintf(bt_devname, "RNode %02X%02X", bt_dh[14], bt_dh[15]); - free(data); - - SerialBT.enableSSP(); - SerialBT.onConfirmRequest(bt_confirm_pairing); - SerialBT.onAuthComplete(bt_pairing_complete); - SerialBT.register_callback(bt_connection_callback); - - bt_ready = true; - return true; + } else { return false; } + } else { return false; } } else { return false; } } } diff --git a/Device.h b/Device.h index f62ffc8..d18179a 100644 --- a/Device.h +++ b/Device.h @@ -113,7 +113,7 @@ bool device_firmware_ok() { } bool device_init() { - if (bt_early_init()) { + if (bt_ready) { for (uint8_t i=0; i= page_interval) { - disp_page = (++disp_page%pages); - last_page_flip = millis(); - if (not community_fw and disp_page == 0) disp_page = 1; - } + } else { + if (millis()-last_page_flip >= page_interval) { + disp_page = (++disp_page%pages); + last_page_flip = millis(); + if (not community_fw and disp_page == 0) disp_page = 1; + } - if (disp_page == 0) { - if (device_signatures_ok()) { + if (disp_page == 0) { + if (device_signatures_ok()) { + if (radio_online) { + disp_area.drawBitmap(0, 37, bm_online, disp_area.width(), 27, SSD1306_WHITE, SSD1306_BLACK); + } else { + disp_area.drawBitmap(0, 37, bm_checks, disp_area.width(), 27, SSD1306_WHITE, SSD1306_BLACK); + } + } else { + disp_area.drawBitmap(0, 37, bm_nfr, disp_area.width(), 27, SSD1306_WHITE, SSD1306_BLACK); + } + } else if (disp_page == 1) { if (radio_online) { disp_area.drawBitmap(0, 37, bm_online, disp_area.width(), 27, SSD1306_WHITE, SSD1306_BLACK); - } else { - disp_area.drawBitmap(0, 37, bm_checks, disp_area.width(), 27, SSD1306_WHITE, SSD1306_BLACK); + } else{ + disp_area.drawBitmap(0, 37, bm_hwok, disp_area.width(), 27, SSD1306_WHITE, SSD1306_BLACK); } - } else { - disp_area.drawBitmap(0, 37, bm_nfr, disp_area.width(), 27, SSD1306_WHITE, SSD1306_BLACK); - } - } else if (disp_page == 1) { - if (radio_online) { - disp_area.drawBitmap(0, 37, bm_online, disp_area.width(), 27, SSD1306_WHITE, SSD1306_BLACK); - } else{ - disp_area.drawBitmap(0, 37, bm_hwok, disp_area.width(), 27, SSD1306_WHITE, SSD1306_BLACK); - } - } else if (disp_page == 2) { - if (radio_online) { - disp_area.drawBitmap(0, 37, bm_online, disp_area.width(), 27, SSD1306_WHITE, SSD1306_BLACK); - } else{ - disp_area.drawBitmap(0, 37, bm_version, disp_area.width(), 27, SSD1306_WHITE, SSD1306_BLACK); - char *v_str = (char*)malloc(3+1); - sprintf(v_str, "%01d%02d", MAJ_VERS, MIN_VERS); - for (int i = 0; i < 3; i++) { - uint8_t numeric = v_str[i]-48; uint8_t bm_offset = numeric*5; - uint8_t dxp = 20; - if (i == 1) dxp += 9*1+4; - if (i == 2) dxp += 9*2+4; - disp_area.drawBitmap(dxp, 37+16, bm_n_uh+bm_offset, 8, 5, SSD1306_WHITE, SSD1306_BLACK); + } else if (disp_page == 2) { + if (radio_online) { + disp_area.drawBitmap(0, 37, bm_online, disp_area.width(), 27, SSD1306_WHITE, SSD1306_BLACK); + } else{ + disp_area.drawBitmap(0, 37, bm_version, disp_area.width(), 27, SSD1306_WHITE, SSD1306_BLACK); + char *v_str = (char*)malloc(3+1); + sprintf(v_str, "%01d%02d", MAJ_VERS, MIN_VERS); + for (int i = 0; i < 3; i++) { + uint8_t numeric = v_str[i]-48; uint8_t bm_offset = numeric*5; + uint8_t dxp = 20; + if (i == 1) dxp += 9*1+4; + if (i == 2) dxp += 9*2+4; + disp_area.drawBitmap(dxp, 37+16, bm_n_uh+bm_offset, 8, 5, SSD1306_WHITE, SSD1306_BLACK); + } + disp_area.drawLine(27, 37+19, 28, 37+19, SSD1306_BLACK); + disp_area.drawLine(27, 37+20, 28, 37+20, SSD1306_BLACK); } - disp_area.drawLine(27, 37+19, 28, 37+19, SSD1306_BLACK); - disp_area.drawLine(27, 37+20, 28, 37+20, SSD1306_BLACK); } } + } else { + disp_area.drawBitmap(0, 0, fb, disp_area.width(), disp_area.height(), SSD1306_WHITE, SSD1306_BLACK); } - } else { - disp_area.drawBitmap(0, 0, fb, disp_area.width(), disp_area.height(), SSD1306_WHITE, SSD1306_BLACK); } } diff --git a/Graphics.h b/Graphics.h index a432177..776ad34 100644 --- a/Graphics.h +++ b/Graphics.h @@ -27,6 +27,23 @@ const unsigned char bm_bt [] PROGMEM = { 0x29, 0x94, 0x11, 0x48, 0x03, 0x20, 0x05, 0x10, 0x09, 0x20, 0x01, 0x40, 0x01, 0x80, 0x01, 0x00 }; +const unsigned char bm_boot [] PROGMEM = { + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xfc, 0x38, 0x66, 0x67, 0x1c, 0x3f, 0xff, 0xff, 0xfc, 0x99, 0xe6, 0x66, 0x4c, 0xff, 0xff, + 0xff, 0xfc, 0x98, 0x70, 0xe6, 0x7c, 0x3f, 0xff, 0xff, 0xfc, 0x99, 0xf0, 0xe6, 0x4c, 0xff, 0xff, + 0xff, 0xfc, 0x38, 0x79, 0xe7, 0x1c, 0x3f, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0x0c, 0x38, 0xe1, 0xc3, 0x33, 0x38, 0x7f, 0xfe, 0x7e, 0x72, 0x64, 0xe7, 0x31, 0x33, 0xff, + 0xff, 0x1e, 0x70, 0x61, 0xe7, 0x30, 0x32, 0x7f, 0xff, 0xce, 0x72, 0x61, 0xe7, 0x32, 0x32, 0x7f, + 0xfe, 0x1e, 0x72, 0x64, 0xe7, 0x33, 0x38, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, + 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff +}; + const unsigned char bm_version [] PROGMEM = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, diff --git a/RNode_Firmware.ino b/RNode_Firmware.ino index 0a441ba..de12b5f 100644 --- a/RNode_Firmware.ino +++ b/RNode_Firmware.ino @@ -52,8 +52,7 @@ char sbuf[128]; void setup() { #if MCU_VARIANT == MCU_ESP32 - // TODO: Reset? - // delay(500); + boot_seq(); EEPROM.begin(EEPROM_SIZE); Serial.setRxBufferSize(CONFIG_UART_BUFFER_SIZE); #endif @@ -90,16 +89,22 @@ void setup() { // pins for the LoRa module LoRa.setPins(pin_cs, pin_reset, pin_dio); + #if HAS_DISPLAY + disp_ready = display_init(); + update_display(); + #endif + #if MCU_VARIANT == MCU_ESP32 #if HAS_PMU == true pmu_ready = init_pmu(); #endif - kiss_indicate_reset(); - #endif + #if HAS_BLUETOOTH + bt_init(); + bt_init_ran = true; + #endif - #if HAS_DISPLAY - disp_ready = display_init(); + kiss_indicate_reset(); #endif // Validate board health, EEPROM and config @@ -832,7 +837,10 @@ void validate_status() { hw_ready = false; Serial.write("Error, invalid hardware check state\r\n"); #if HAS_DISPLAY - if (disp_ready) update_display(); + if (disp_ready) { + device_init_done = true; + update_display(); + } #endif led_indicate_boot_error(); } @@ -846,7 +854,10 @@ void validate_status() { } else { Serial.write("Error, indeterminate boot vector\r\n"); #if HAS_DISPLAY - if (disp_ready) update_display(); + if (disp_ready) { + device_init_done = true; + update_display(); + } #endif led_indicate_boot_error(); } @@ -881,7 +892,10 @@ void validate_status() { hw_ready = false; Serial.write("Error, incorrect boot vector\r\n"); #if HAS_DISPLAY - if (disp_ready) update_display(); + if (disp_ready) { + device_init_done = true; + update_display(); + } #endif led_indicate_boot_error(); } @@ -947,11 +961,6 @@ void loop() { #endif #if HAS_BLUETOOTH - if (!bt_init_ran && millis() > 1000) { - bt_init(); - bt_init_ran = true; - } - if (bt_ready) update_bt(); #endif } diff --git a/Utilities.h b/Utilities.h index 49f89a1..8e5f407 100644 --- a/Utilities.h +++ b/Utilities.h @@ -66,6 +66,20 @@ uint8_t boot_vector = 0x00; pixels.show(); } } + + void boot_seq() { + uint8_t rs[] = { 0x00, 0x00, 0x00 }; + uint8_t gs[] = { 0x10, 0x08, 0x00 }; + uint8_t bs[] = { 0x00, 0x08, 0x10 }; + for (int i = 0; i < 1*sizeof(rs); i++) { + npset(rs[i%sizeof(rs)], gs[i%sizeof(gs)], bs[i%sizeof(bs)]); + delay(33); + npset(0x00, 0x00, 0x00); + delay(66); + } + } +#else + void boot_seq() { } #endif #if MCU_VARIANT == MCU_1284P || MCU_VARIANT == MCU_2560