mirror of
https://github.com/liberatedsystems/RNode_Firmware_CE.git
synced 2025-06-07 14:22:51 -04:00
Incorporate changes from upstream 1.82
This commit is contained in:
commit
fd5520d95f
12 changed files with 251 additions and 128 deletions
205
Bluetooth.h
205
Bluetooth.h
|
@ -165,31 +165,42 @@ char bt_devname[11];
|
||||||
}
|
}
|
||||||
|
|
||||||
#elif HAS_BLE == true
|
#elif HAS_BLE == true
|
||||||
|
bool bt_setup_hw(); void bt_security_setup();
|
||||||
BLESecurity *ble_security = new BLESecurity();
|
BLESecurity *ble_security = new BLESecurity();
|
||||||
bool ble_authenticated = false;
|
bool ble_authenticated = false;
|
||||||
uint32_t pairing_pin = 0;
|
uint32_t pairing_pin = 0;
|
||||||
|
|
||||||
void bt_flush() { if (bt_state == BT_STATE_CONNECTED) { SerialBT.flush(); } }
|
void bt_flush() { if (bt_state == BT_STATE_CONNECTED) { SerialBT.flush(); } }
|
||||||
|
|
||||||
void bt_disable_pairing() {
|
void bt_start() {
|
||||||
|
// Serial.println("BT start");
|
||||||
display_unblank();
|
display_unblank();
|
||||||
bt_allow_pairing = false;
|
if (bt_state == BT_STATE_OFF) {
|
||||||
bt_ssp_pin = 0;
|
|
||||||
bt_state = BT_STATE_ON;
|
bt_state = BT_STATE_ON;
|
||||||
|
SerialBT.begin(bt_devname);
|
||||||
|
SerialBT.setTimeout(10);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void bt_passkey_notify_callback(uint32_t passkey) {
|
void bt_stop() {
|
||||||
// Serial.printf("Got passkey notification: %d\n", passkey);
|
// Serial.println("BT stop");
|
||||||
bt_ssp_pin = passkey;
|
display_unblank();
|
||||||
bt_state = BT_STATE_PAIRING;
|
if (bt_state != BT_STATE_OFF) {
|
||||||
bt_allow_pairing = true;
|
bt_allow_pairing = false;
|
||||||
bt_pairing_started = millis();
|
bt_state = BT_STATE_OFF;
|
||||||
kiss_indicate_btpin();
|
SerialBT.end();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool bt_confirm_pin_callback(uint32_t pin) {
|
bool bt_init() {
|
||||||
// Serial.printf("Confirm PIN callback: %d\n", pin);
|
// Serial.println("BT init");
|
||||||
|
bt_state = BT_STATE_OFF;
|
||||||
|
if (bt_setup_hw()) {
|
||||||
|
if (bt_enabled && !console_active) bt_start();
|
||||||
return true;
|
return true;
|
||||||
|
} else {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void bt_debond_all() {
|
void bt_debond_all() {
|
||||||
|
@ -201,6 +212,44 @@ char bt_devname[11];
|
||||||
free(dev_list);
|
free(dev_list);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void bt_enable_pairing() {
|
||||||
|
// Serial.println("BT enable pairing");
|
||||||
|
display_unblank();
|
||||||
|
if (bt_state == BT_STATE_OFF) bt_start();
|
||||||
|
|
||||||
|
bt_security_setup();
|
||||||
|
|
||||||
|
bt_allow_pairing = true;
|
||||||
|
bt_pairing_started = millis();
|
||||||
|
bt_state = BT_STATE_PAIRING;
|
||||||
|
bt_ssp_pin = pairing_pin;
|
||||||
|
}
|
||||||
|
|
||||||
|
void bt_disable_pairing() {
|
||||||
|
// Serial.println("BT disable pairing");
|
||||||
|
display_unblank();
|
||||||
|
bt_allow_pairing = false;
|
||||||
|
bt_ssp_pin = 0;
|
||||||
|
bt_state = BT_STATE_ON;
|
||||||
|
}
|
||||||
|
|
||||||
|
void bt_passkey_notify_callback(uint32_t passkey) {
|
||||||
|
// Serial.printf("Got passkey notification: %d\n", passkey);
|
||||||
|
if (bt_allow_pairing) {
|
||||||
|
bt_ssp_pin = passkey;
|
||||||
|
bt_pairing_started = millis();
|
||||||
|
kiss_indicate_btpin();
|
||||||
|
} else {
|
||||||
|
// Serial.println("Pairing not allowed, re-init");
|
||||||
|
SerialBT.disconnect();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool bt_confirm_pin_callback(uint32_t pin) {
|
||||||
|
// Serial.printf("Confirm PIN callback: %d\n", pin);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
void bt_update_passkey() {
|
void bt_update_passkey() {
|
||||||
// Serial.println("Updating passkey");
|
// Serial.println("Updating passkey");
|
||||||
pairing_pin = random(899999)+100000;
|
pairing_pin = random(899999)+100000;
|
||||||
|
@ -217,31 +266,6 @@ char bt_devname[11];
|
||||||
return ble_authenticated;
|
return ble_authenticated;
|
||||||
}
|
}
|
||||||
|
|
||||||
void bt_security_setup() {
|
|
||||||
uint32_t passkey = bt_passkey_callback();
|
|
||||||
|
|
||||||
// Serial.printf("Executing BT security setup, passkey is %d\n", passkey);
|
|
||||||
|
|
||||||
uint8_t key_size = 16;
|
|
||||||
uint8_t init_key = ESP_BLE_ENC_KEY_MASK | ESP_BLE_ID_KEY_MASK;
|
|
||||||
uint8_t rsp_key = ESP_BLE_ENC_KEY_MASK | ESP_BLE_ID_KEY_MASK;
|
|
||||||
|
|
||||||
esp_ble_auth_req_t auth_req = ESP_LE_AUTH_REQ_SC_MITM_BOND;
|
|
||||||
uint8_t auth_option = ESP_BLE_ONLY_ACCEPT_SPECIFIED_AUTH_ENABLE;
|
|
||||||
uint8_t oob_support = ESP_BLE_OOB_DISABLE;
|
|
||||||
|
|
||||||
esp_ble_io_cap_t iocap = ESP_IO_CAP_OUT;
|
|
||||||
|
|
||||||
esp_ble_gap_set_security_param(ESP_BLE_SM_SET_STATIC_PASSKEY, &passkey, sizeof(uint32_t));
|
|
||||||
esp_ble_gap_set_security_param(ESP_BLE_SM_AUTHEN_REQ_MODE, &auth_req, sizeof(uint8_t));
|
|
||||||
esp_ble_gap_set_security_param(ESP_BLE_SM_IOCAP_MODE, &iocap, sizeof(uint8_t));
|
|
||||||
esp_ble_gap_set_security_param(ESP_BLE_SM_MAX_KEY_SIZE, &key_size, sizeof(uint8_t));
|
|
||||||
esp_ble_gap_set_security_param(ESP_BLE_SM_ONLY_ACCEPT_SPECIFIED_SEC_AUTH, &auth_option, sizeof(uint8_t));
|
|
||||||
esp_ble_gap_set_security_param(ESP_BLE_SM_OOB_SUPPORT, &oob_support, sizeof(uint8_t));
|
|
||||||
esp_ble_gap_set_security_param(ESP_BLE_SM_SET_INIT_KEY, &init_key, sizeof(uint8_t));
|
|
||||||
esp_ble_gap_set_security_param(ESP_BLE_SM_SET_RSP_KEY, &rsp_key, sizeof(uint8_t));
|
|
||||||
}
|
|
||||||
|
|
||||||
bool bt_security_request_callback() {
|
bool bt_security_request_callback() {
|
||||||
if (bt_allow_pairing) {
|
if (bt_allow_pairing) {
|
||||||
// Serial.println("Accepting security request");
|
// Serial.println("Accepting security request");
|
||||||
|
@ -256,11 +280,15 @@ char bt_devname[11];
|
||||||
if (auth_result.success == true) {
|
if (auth_result.success == true) {
|
||||||
// Serial.println("Authentication success");
|
// Serial.println("Authentication success");
|
||||||
ble_authenticated = true;
|
ble_authenticated = true;
|
||||||
bt_state = BT_STATE_CONNECTED;
|
if (bt_state == BT_STATE_PAIRING) {
|
||||||
|
// Serial.println("Pairing complete, disconnecting");
|
||||||
|
delay(2000); SerialBT.disconnect();
|
||||||
|
} else { bt_state = BT_STATE_CONNECTED; }
|
||||||
} else {
|
} else {
|
||||||
// Serial.println("Authentication fail");
|
// Serial.println("Authentication fail");
|
||||||
ble_authenticated = false;
|
ble_authenticated = false;
|
||||||
bt_state = BT_STATE_ON;
|
bt_state = BT_STATE_ON;
|
||||||
|
bt_update_passkey();
|
||||||
bt_security_setup();
|
bt_security_setup();
|
||||||
}
|
}
|
||||||
bt_allow_pairing = false;
|
bt_allow_pairing = false;
|
||||||
|
@ -268,16 +296,16 @@ char bt_devname[11];
|
||||||
}
|
}
|
||||||
|
|
||||||
void bt_connect_callback(BLEServer *server) {
|
void bt_connect_callback(BLEServer *server) {
|
||||||
// uint16_t conn_id = server->getConnId();
|
uint16_t conn_id = server->getConnId();
|
||||||
// Serial.printf("Connected: %d\n", conn_id);
|
// Serial.printf("Connected: %d\n", conn_id);
|
||||||
display_unblank();
|
display_unblank();
|
||||||
ble_authenticated = false;
|
ble_authenticated = false;
|
||||||
bt_state = BT_STATE_CONNECTED;
|
if (bt_state != BT_STATE_PAIRING) { bt_state = BT_STATE_CONNECTED; }
|
||||||
cable_state = CABLE_STATE_DISCONNECTED;
|
cable_state = CABLE_STATE_DISCONNECTED;
|
||||||
}
|
}
|
||||||
|
|
||||||
void bt_disconnect_callback(BLEServer *server) {
|
void bt_disconnect_callback(BLEServer *server) {
|
||||||
// uint16_t conn_id = server->getConnId();
|
uint16_t conn_id = server->getConnId();
|
||||||
// Serial.printf("Disconnected: %d\n", conn_id);
|
// Serial.printf("Disconnected: %d\n", conn_id);
|
||||||
display_unblank();
|
display_unblank();
|
||||||
ble_authenticated = false;
|
ble_authenticated = false;
|
||||||
|
@ -285,6 +313,7 @@ char bt_devname[11];
|
||||||
}
|
}
|
||||||
|
|
||||||
bool bt_setup_hw() {
|
bool bt_setup_hw() {
|
||||||
|
// Serial.println("BT setup hw");
|
||||||
if (!bt_ready) {
|
if (!bt_ready) {
|
||||||
if (EEPROM.read(eeprom_addr(ADDR_CONF_BT)) == BT_ENABLE_BYTE) {
|
if (EEPROM.read(eeprom_addr(ADDR_CONF_BT)) == BT_ENABLE_BYTE) {
|
||||||
bt_enabled = true;
|
bt_enabled = true;
|
||||||
|
@ -316,45 +345,30 @@ char bt_devname[11];
|
||||||
} else { return false; }
|
} else { return false; }
|
||||||
}
|
}
|
||||||
|
|
||||||
void bt_start() {
|
void bt_security_setup() {
|
||||||
display_unblank();
|
// Serial.println("Executing BT security setup");
|
||||||
if (bt_state == BT_STATE_OFF) {
|
if (pairing_pin == 0) { bt_update_passkey(); }
|
||||||
bt_state = BT_STATE_ON;
|
uint32_t passkey = pairing_pin;
|
||||||
SerialBT.begin(bt_devname);
|
// Serial.printf("Passkey is %d\n", passkey);
|
||||||
SerialBT.setTimeout(10);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void bt_stop() {
|
uint8_t key_size = 16;
|
||||||
display_unblank();
|
uint8_t init_key = ESP_BLE_ENC_KEY_MASK | ESP_BLE_ID_KEY_MASK;
|
||||||
if (bt_state != BT_STATE_OFF) {
|
uint8_t rsp_key = ESP_BLE_ENC_KEY_MASK | ESP_BLE_ID_KEY_MASK;
|
||||||
bt_allow_pairing = false;
|
|
||||||
bt_state = BT_STATE_OFF;
|
|
||||||
SerialBT.end();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
bool bt_init() {
|
esp_ble_auth_req_t auth_req = ESP_LE_AUTH_REQ_SC_MITM_BOND;
|
||||||
bt_state = BT_STATE_OFF;
|
uint8_t auth_option = ESP_BLE_ONLY_ACCEPT_SPECIFIED_AUTH_ENABLE;
|
||||||
if (bt_setup_hw()) {
|
uint8_t oob_support = ESP_BLE_OOB_DISABLE;
|
||||||
if (bt_enabled && !console_active) bt_start();
|
|
||||||
return true;
|
|
||||||
} else {
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void bt_enable_pairing() {
|
esp_ble_io_cap_t iocap = ESP_IO_CAP_OUT;
|
||||||
display_unblank();
|
|
||||||
if (bt_state == BT_STATE_OFF) bt_start();
|
|
||||||
|
|
||||||
bt_security_setup();
|
esp_ble_gap_set_security_param(ESP_BLE_SM_SET_STATIC_PASSKEY, &passkey, sizeof(uint32_t));
|
||||||
//bt_debond_all();
|
esp_ble_gap_set_security_param(ESP_BLE_SM_AUTHEN_REQ_MODE, &auth_req, sizeof(uint8_t));
|
||||||
//bt_update_passkey();
|
esp_ble_gap_set_security_param(ESP_BLE_SM_IOCAP_MODE, &iocap, sizeof(uint8_t));
|
||||||
|
esp_ble_gap_set_security_param(ESP_BLE_SM_MAX_KEY_SIZE, &key_size, sizeof(uint8_t));
|
||||||
bt_allow_pairing = true;
|
esp_ble_gap_set_security_param(ESP_BLE_SM_ONLY_ACCEPT_SPECIFIED_SEC_AUTH, &auth_option, sizeof(uint8_t));
|
||||||
bt_pairing_started = millis();
|
esp_ble_gap_set_security_param(ESP_BLE_SM_OOB_SUPPORT, &oob_support, sizeof(uint8_t));
|
||||||
bt_state = BT_STATE_PAIRING;
|
esp_ble_gap_set_security_param(ESP_BLE_SM_SET_INIT_KEY, &init_key, sizeof(uint8_t));
|
||||||
|
esp_ble_gap_set_security_param(ESP_BLE_SM_SET_RSP_KEY, &rsp_key, sizeof(uint8_t));
|
||||||
}
|
}
|
||||||
|
|
||||||
void update_bt() {
|
void update_bt() {
|
||||||
|
@ -375,6 +389,7 @@ char bt_devname[11];
|
||||||
uint8_t eeprom_read(uint32_t mapped_addr);
|
uint8_t eeprom_read(uint32_t mapped_addr);
|
||||||
|
|
||||||
void bt_stop() {
|
void bt_stop() {
|
||||||
|
// Serial.println("BT Stop");
|
||||||
if (bt_state != BT_STATE_OFF) {
|
if (bt_state != BT_STATE_OFF) {
|
||||||
bt_allow_pairing = false;
|
bt_allow_pairing = false;
|
||||||
bt_state = BT_STATE_OFF;
|
bt_state = BT_STATE_OFF;
|
||||||
|
@ -382,7 +397,9 @@ char bt_devname[11];
|
||||||
}
|
}
|
||||||
|
|
||||||
void bt_disable_pairing() {
|
void bt_disable_pairing() {
|
||||||
|
// Serial.println("BT Disable pairing");
|
||||||
bt_allow_pairing = false;
|
bt_allow_pairing = false;
|
||||||
|
pairing_pin = 0;
|
||||||
bt_ssp_pin = 0;
|
bt_ssp_pin = 0;
|
||||||
bt_state = BT_STATE_ON;
|
bt_state = BT_STATE_ON;
|
||||||
}
|
}
|
||||||
|
@ -390,10 +407,11 @@ char bt_devname[11];
|
||||||
void bt_flush() { if (bt_state == BT_STATE_CONNECTED) { SerialBT.flushTXD(); } }
|
void bt_flush() { if (bt_state == BT_STATE_CONNECTED) { SerialBT.flushTXD(); } }
|
||||||
|
|
||||||
void bt_pairing_complete(uint16_t conn_handle, uint8_t auth_status) {
|
void bt_pairing_complete(uint16_t conn_handle, uint8_t auth_status) {
|
||||||
if (auth_status == BLE_GAP_SEC_STATUS_SUCCESS) {
|
// Serial.println("BT pairing complete");
|
||||||
BLEConnection* connection = Bluefruit.Connection(conn_handle);
|
BLEConnection* connection = Bluefruit.Connection(conn_handle);
|
||||||
|
if (auth_status == BLE_GAP_SEC_STATUS_SUCCESS) {
|
||||||
ble_gap_conn_sec_mode_t security = connection->getSecureMode();
|
ble_gap_conn_sec_mode_t security = connection->getSecureMode();
|
||||||
|
// Serial.println("Bonding success");
|
||||||
|
|
||||||
// On the NRF52 it is not possible with the Arduino library to reject
|
// On the NRF52 it is not possible with the Arduino library to reject
|
||||||
// requests from devices with no IO capabilities, which would allow
|
// requests from devices with no IO capabilities, which would allow
|
||||||
|
@ -410,21 +428,26 @@ char bt_devname[11];
|
||||||
// Requires investigation.
|
// Requires investigation.
|
||||||
|
|
||||||
if (security.sm == 1 && security.lv >= 3) {
|
if (security.sm == 1 && security.lv >= 3) {
|
||||||
|
// Serial.println("Auth level success");
|
||||||
bt_state = BT_STATE_CONNECTED;
|
bt_state = BT_STATE_CONNECTED;
|
||||||
cable_state = CABLE_STATE_DISCONNECTED;
|
cable_state = CABLE_STATE_DISCONNECTED;
|
||||||
|
connection->disconnect();
|
||||||
bt_disable_pairing();
|
bt_disable_pairing();
|
||||||
} else {
|
} else {
|
||||||
if (connection->bonded()) {
|
// Serial.println("Auth level failure, debonding");
|
||||||
connection->removeBondKey();
|
if (connection->bonded()) { connection->removeBondKey(); }
|
||||||
}
|
|
||||||
connection->disconnect();
|
connection->disconnect();
|
||||||
|
bt_disable_pairing();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
bt_ssp_pin = 0;
|
// Serial.println("Bonding failure");
|
||||||
|
connection->disconnect();
|
||||||
|
bt_disable_pairing();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool bt_passkey_callback(uint16_t conn_handle, uint8_t const passkey[6], bool match_request) {
|
bool bt_passkey_callback(uint16_t conn_handle, uint8_t const passkey[6], bool match_request) {
|
||||||
|
// Serial.println("Passkey callback");
|
||||||
if (bt_allow_pairing) {
|
if (bt_allow_pairing) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -432,6 +455,7 @@ char bt_devname[11];
|
||||||
}
|
}
|
||||||
|
|
||||||
void bt_connect_callback(uint16_t conn_handle) {
|
void bt_connect_callback(uint16_t conn_handle) {
|
||||||
|
// Serial.println("Connect callback");
|
||||||
bt_state = BT_STATE_CONNECTED;
|
bt_state = BT_STATE_CONNECTED;
|
||||||
cable_state = CABLE_STATE_DISCONNECTED;
|
cable_state = CABLE_STATE_DISCONNECTED;
|
||||||
|
|
||||||
|
@ -442,12 +466,14 @@ char bt_devname[11];
|
||||||
}
|
}
|
||||||
|
|
||||||
void bt_disconnect_callback(uint16_t conn_handle, uint8_t reason) {
|
void bt_disconnect_callback(uint16_t conn_handle, uint8_t reason) {
|
||||||
|
// Serial.println("Disconnect callback");
|
||||||
if (reason != BLE_GAP_SEC_STATUS_SUCCESS) {
|
if (reason != BLE_GAP_SEC_STATUS_SUCCESS) {
|
||||||
bt_state = BT_STATE_ON;
|
bt_state = BT_STATE_ON;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void bt_update_passkey() {
|
void bt_update_passkey() {
|
||||||
|
// Serial.println("Update passkey");
|
||||||
pairing_pin = random(899999)+100000;
|
pairing_pin = random(899999)+100000;
|
||||||
bt_ssp_pin = pairing_pin;
|
bt_ssp_pin = pairing_pin;
|
||||||
}
|
}
|
||||||
|
@ -459,6 +485,7 @@ char bt_devname[11];
|
||||||
}
|
}
|
||||||
|
|
||||||
bool bt_setup_hw() {
|
bool bt_setup_hw() {
|
||||||
|
// Serial.println("Setup HW");
|
||||||
if (!bt_ready) {
|
if (!bt_ready) {
|
||||||
#if HAS_EEPROM
|
#if HAS_EEPROM
|
||||||
if (EEPROM.read(eeprom_addr(ADDR_CONF_BT)) == BT_ENABLE_BYTE) {
|
if (EEPROM.read(eeprom_addr(ADDR_CONF_BT)) == BT_ENABLE_BYTE) {
|
||||||
|
@ -513,12 +540,14 @@ char bt_devname[11];
|
||||||
}
|
}
|
||||||
|
|
||||||
void bt_start() {
|
void bt_start() {
|
||||||
|
// Serial.println("BT Start");
|
||||||
if (bt_state == BT_STATE_OFF) {
|
if (bt_state == BT_STATE_OFF) {
|
||||||
Bluefruit.setName(bt_devname);
|
Bluefruit.setName(bt_devname);
|
||||||
bledis.setManufacturer(BLE_MANUFACTURER);
|
bledis.setManufacturer(BLE_MANUFACTURER);
|
||||||
bledis.setModel(BLE_MODEL);
|
bledis.setModel(BLE_MODEL);
|
||||||
// start device information service
|
// start device information service
|
||||||
bledis.begin();
|
bledis.begin();
|
||||||
|
blebas.begin();
|
||||||
|
|
||||||
// Guard to ensure SerialBT service is not duplicated through BT being power cycled
|
// Guard to ensure SerialBT service is not duplicated through BT being power cycled
|
||||||
if (!SerialBT_init) {
|
if (!SerialBT_init) {
|
||||||
|
@ -529,8 +558,6 @@ char bt_devname[11];
|
||||||
SerialBT_init = true;
|
SerialBT_init = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
blebas.begin();
|
|
||||||
|
|
||||||
Bluefruit.Advertising.addFlags(BLE_GAP_ADV_FLAGS_LE_ONLY_GENERAL_DISC_MODE);
|
Bluefruit.Advertising.addFlags(BLE_GAP_ADV_FLAGS_LE_ONLY_GENERAL_DISC_MODE);
|
||||||
Bluefruit.Advertising.addTxPower();
|
Bluefruit.Advertising.addTxPower();
|
||||||
|
|
||||||
|
@ -548,6 +575,7 @@ char bt_devname[11];
|
||||||
}
|
}
|
||||||
|
|
||||||
bool bt_init() {
|
bool bt_init() {
|
||||||
|
// Serial.println("BT init");
|
||||||
bt_state = BT_STATE_OFF;
|
bt_state = BT_STATE_OFF;
|
||||||
if (bt_setup_hw()) {
|
if (bt_setup_hw()) {
|
||||||
if (bt_enabled && !console_active) bt_start();
|
if (bt_enabled && !console_active) bt_start();
|
||||||
|
@ -558,13 +586,22 @@ char bt_devname[11];
|
||||||
}
|
}
|
||||||
|
|
||||||
void bt_enable_pairing() {
|
void bt_enable_pairing() {
|
||||||
|
// Serial.println("BT enable pairing");
|
||||||
if (bt_state == BT_STATE_OFF) bt_start();
|
if (bt_state == BT_STATE_OFF) bt_start();
|
||||||
|
|
||||||
|
uint32_t pin = bt_get_passkey();
|
||||||
|
char pin_char[6];
|
||||||
|
sprintf(pin_char,"%lu", pin);
|
||||||
|
Bluefruit.Security.setPIN(pin_char);
|
||||||
|
|
||||||
bt_allow_pairing = true;
|
bt_allow_pairing = true;
|
||||||
bt_pairing_started = millis();
|
bt_pairing_started = millis();
|
||||||
bt_state = BT_STATE_PAIRING;
|
bt_state = BT_STATE_PAIRING;
|
||||||
kiss_indicate_btpin();
|
kiss_indicate_btpin();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void bt_debond_all() { }
|
||||||
|
|
||||||
void update_bt() {
|
void update_bt() {
|
||||||
if (bt_allow_pairing && millis()-bt_pairing_started >= BT_PAIRING_TIMEOUT) {
|
if (bt_allow_pairing && millis()-bt_pairing_started >= BT_PAIRING_TIMEOUT) {
|
||||||
bt_disable_pairing();
|
bt_disable_pairing();
|
||||||
|
|
15
Boards.h
15
Boards.h
|
@ -64,11 +64,12 @@
|
||||||
#define MODEL_DB 0xDB // LilyGO T-Beam Supreme, 433 MHz
|
#define MODEL_DB 0xDB // LilyGO T-Beam Supreme, 433 MHz
|
||||||
#define MODEL_DC 0xDC // LilyGO T-Beam Supreme, 868 MHz
|
#define MODEL_DC 0xDC // LilyGO T-Beam Supreme, 868 MHz
|
||||||
|
|
||||||
#define PRODUCT_XIAO_ESP32S3 0xEB // Xiao ESP32S3 - sold by Seeed Studio
|
#define PRODUCT_XIAO_S3 0xEB
|
||||||
#define BOARD_XIAO_ESP32S3 0x3E
|
#define BOARD_XIAO_S3 0x3E
|
||||||
#define MODEL_DD 0xDD // Xiao ESP32S3, 868 MHz
|
#define MODEL_DE 0xDE // Xiao ESP32S3 with Wio-SX1262 module, 433 MHz
|
||||||
|
#define MODEL_DD 0xDD // Xiao ESP32S3 with Wio-SX1262 module, 868 MHz
|
||||||
|
|
||||||
#define PRODUCT_T32_10 0xB2 // T3 v1.0 - sold by LilyGO
|
#define PRODUCT_T32_10 0xB2
|
||||||
#define BOARD_LORA32_V1_0 0x39
|
#define BOARD_LORA32_V1_0 0x39
|
||||||
#define MODEL_BA 0xBA // LilyGO T3 v1.0, 433 MHz
|
#define MODEL_BA 0xBA // LilyGO T3 v1.0, 433 MHz
|
||||||
#define MODEL_BB 0xBB // LilyGO T3 v1.0, 868 MHz
|
#define MODEL_BB 0xBB // LilyGO T3 v1.0, 868 MHz
|
||||||
|
@ -1030,7 +1031,7 @@
|
||||||
-1 // pin_tcxo_enable
|
-1 // pin_tcxo_enable
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
#elif BOARD_MODEL == BOARD_XIAO_ESP32S3
|
#elif BOARD_MODEL == BOARD_XIAO_S3
|
||||||
#define IS_ESP32S3 true
|
#define IS_ESP32S3 true
|
||||||
|
|
||||||
#define HAS_DISPLAY true
|
#define HAS_DISPLAY true
|
||||||
|
@ -1096,10 +1097,10 @@
|
||||||
// shared with button input.
|
// shared with button input.
|
||||||
#if HAS_NP == false
|
#if HAS_NP == false
|
||||||
#if defined(EXTERNAL_LEDS)
|
#if defined(EXTERNAL_LEDS)
|
||||||
const int pin_led_rx = -1;
|
const int pin_led_rx = 48;
|
||||||
const int pin_led_tx = 48; //47;
|
const int pin_led_tx = 48; //47;
|
||||||
#else
|
#else
|
||||||
const int pin_led_rx = -1;
|
const int pin_led_rx = 48;
|
||||||
const int pin_led_tx = 48; //47;
|
const int pin_led_tx = 48; //47;
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
|
|
10
Display.h
10
Display.h
|
@ -129,6 +129,12 @@ void busyCallback(const void* p) { display_callback(); }
|
||||||
#define DISP_W 250
|
#define DISP_W 250
|
||||||
#define DISP_H 122
|
#define DISP_H 122
|
||||||
#define DISP_ADDR -1
|
#define DISP_ADDR -1
|
||||||
|
#elif BOARD_MODEL == BOARD_XIAO_S3
|
||||||
|
#define DISP_RST -1
|
||||||
|
#define DISP_ADDR 0x3C
|
||||||
|
#define SCL_OLED 6
|
||||||
|
#define SDA_OLED 5
|
||||||
|
#define DISP_CUSTOM_ADDR true
|
||||||
#else
|
#else
|
||||||
#define DISP_RST -1
|
#define DISP_RST -1
|
||||||
#define DISP_ADDR 0x3C
|
#define DISP_ADDR 0x3C
|
||||||
|
@ -371,6 +377,8 @@ bool display_init() {
|
||||||
#endif
|
#endif
|
||||||
#elif BOARD_MODEL == BOARD_TBEAM_S_V1
|
#elif BOARD_MODEL == BOARD_TBEAM_S_V1
|
||||||
Wire.begin(SDA_OLED, SCL_OLED);
|
Wire.begin(SDA_OLED, SCL_OLED);
|
||||||
|
#elif BOARD_MODEL == BOARD_XIAO_S3
|
||||||
|
Wire.begin(SDA_OLED, SCL_OLED);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if HAS_EEPROM
|
#if HAS_EEPROM
|
||||||
|
@ -721,7 +729,7 @@ void draw_quality_bars(int px, int py) {
|
||||||
//}
|
//}
|
||||||
}
|
}
|
||||||
|
|
||||||
#if MODE == SX1280
|
#if MODEM == SX1280
|
||||||
#define S_RSSI_MIN -105.0
|
#define S_RSSI_MIN -105.0
|
||||||
#define S_RSSI_MAX -65.0
|
#define S_RSSI_MAX -65.0
|
||||||
#else
|
#else
|
||||||
|
|
|
@ -60,6 +60,7 @@
|
||||||
#define CMD_DISP_RCND 0x68
|
#define CMD_DISP_RCND 0x68
|
||||||
#define CMD_NP_INT 0x65
|
#define CMD_NP_INT 0x65
|
||||||
#define CMD_BT_CTRL 0x46
|
#define CMD_BT_CTRL 0x46
|
||||||
|
#define CMD_BT_UNPAIR 0x70
|
||||||
#define CMD_BT_PIN 0x62
|
#define CMD_BT_PIN 0x62
|
||||||
#define CMD_DIS_IA 0x69
|
#define CMD_DIS_IA 0x69
|
||||||
|
|
||||||
|
@ -86,6 +87,10 @@
|
||||||
#define CMD_DATA 0x00
|
#define CMD_DATA 0x00
|
||||||
|
|
||||||
#define CMD_SEL_INT 0x1F
|
#define CMD_SEL_INT 0x1F
|
||||||
|
#define CMD_LOG 0x80
|
||||||
|
#define CMD_TIME 0x81
|
||||||
|
#define CMD_MUX_CHAIN 0x82
|
||||||
|
#define CMD_MUX_DSCVR 0x83
|
||||||
|
|
||||||
#define DETECT_REQ 0x73
|
#define DETECT_REQ 0x73
|
||||||
#define DETECT_RESP 0x46
|
#define DETECT_RESP 0x46
|
||||||
|
|
8
Makefile
8
Makefile
|
@ -128,7 +128,7 @@ firmware-heltec32_v3:
|
||||||
firmware-heltec_w_paper:
|
firmware-heltec_w_paper:
|
||||||
arduino-cli compile --fqbn esp32:esp32:heltec_wifi_lora_32_V3 $(COMMON_BUILD_FLAGS) --build-property "compiler.cpp.extra_flags=\"-DBOARD_MODEL=0x3E\""
|
arduino-cli compile --fqbn esp32:esp32:heltec_wifi_lora_32_V3 $(COMMON_BUILD_FLAGS) --build-property "compiler.cpp.extra_flags=\"-DBOARD_MODEL=0x3E\""
|
||||||
|
|
||||||
firmware-xiao_esp32s3:
|
firmware-xiao_s3:
|
||||||
arduino-cli compile --fqbn esp32:esp32:XIAO_ESP32S3 $(COMMON_BUILD_FLAGS) --build-property "compiler.cpp.extra_flags=\"-DBOARD_MODEL=0x3E\""
|
arduino-cli compile --fqbn esp32:esp32:XIAO_ESP32S3 $(COMMON_BUILD_FLAGS) --build-property "compiler.cpp.extra_flags=\"-DBOARD_MODEL=0x3E\""
|
||||||
|
|
||||||
firmware-rnode_ng_20: check_bt_buffers
|
firmware-rnode_ng_20: check_bt_buffers
|
||||||
|
@ -207,14 +207,13 @@ upload-heltec_w_paper upload-heltec32_v3:
|
||||||
@sleep 3
|
@sleep 3
|
||||||
python3 ./Release/esptool/esptool.py --port $(or $(port), /dev/ttyUSB0) --chip esp32-s3 --baud 921600 --before default_reset --after hard_reset write_flash -z --flash_mode dio --flash_freq 80m --flash_size 4MB 0x210000 ./Release/console_image.bin
|
python3 ./Release/esptool/esptool.py --port $(or $(port), /dev/ttyUSB0) --chip esp32-s3 --baud 921600 --before default_reset --after hard_reset write_flash -z --flash_mode dio --flash_freq 80m --flash_size 4MB 0x210000 ./Release/console_image.bin
|
||||||
|
|
||||||
upload-xiao_esp32s3:
|
upload-xiao_s3:
|
||||||
arduino-cli upload -p $(or $(port), /dev/ttyACM0) --fqbn esp32:esp32:XIAO_ESP32S3
|
arduino-cli upload -p $(or $(port), /dev/ttyACM0) --fqbn esp32:esp32:XIAO_ESP32S3
|
||||||
@sleep 1
|
@sleep 1
|
||||||
rnodeconf $(or $(port), /dev/ttyACM0) --firmware-hash $$(./partition_hashes ./build/esp32.esp32.XIAO_ESP32S3/RNode_Firmware_CE.ino.bin)
|
rnodeconf $(or $(port), /dev/ttyACM0) --firmware-hash $$(./partition_hashes ./build/esp32.esp32.XIAO_ESP32S3/RNode_Firmware_CE.ino.bin)
|
||||||
@sleep 3
|
@sleep 3
|
||||||
python ./Release/esptool/esptool.py --port $(or $(port), /dev/ttyACM0) --chip esp32-s3 --baud 921600 --before default_reset --after hard_reset write_flash -z --flash_mode dio --flash_freq 80m --flash_size 8MB 0x210000 ./Release/console_image.bin
|
python ./Release/esptool/esptool.py --port $(or $(port), /dev/ttyACM0) --chip esp32-s3 --baud 921600 --before default_reset --after hard_reset write_flash -z --flash_mode dio --flash_freq 80m --flash_size 8MB 0x210000 ./Release/console_image.bin
|
||||||
|
|
||||||
|
|
||||||
upload-tdeck:
|
upload-tdeck:
|
||||||
arduino-cli upload -p $(or $(port), /dev/ttyACM0) --fqbn esp32:esp32:esp32s3
|
arduino-cli upload -p $(or $(port), /dev/ttyACM0) --fqbn esp32:esp32:esp32s3
|
||||||
@sleep 1
|
@sleep 1
|
||||||
|
@ -390,7 +389,7 @@ release-heltec_w_paper:
|
||||||
zip --junk-paths ./Release/rnode_firmware_heltecwpaper.zip ./Release/esptool/esptool.py ./Release/console_image.bin build/rnode_firmware_heltecwpaper.boot_app0 build/rnode_firmware_heltecwpaper.bin build/rnode_firmware_heltecwpaper.bootloader build/rnode_firmware_heltecwpaper.partitions
|
zip --junk-paths ./Release/rnode_firmware_heltecwpaper.zip ./Release/esptool/esptool.py ./Release/console_image.bin build/rnode_firmware_heltecwpaper.boot_app0 build/rnode_firmware_heltecwpaper.bin build/rnode_firmware_heltecwpaper.bootloader build/rnode_firmware_heltecwpaper.partitions
|
||||||
rm -r build
|
rm -r build
|
||||||
|
|
||||||
release-xiao_esp32s3:
|
release-xiao_s3:
|
||||||
arduino-cli compile --fqbn esp32:esp32:XIAO_ESP32S3 $(COMMON_BUILD_FLAGS) --build-property "compiler.cpp.extra_flags=\"-DBOARD_MODEL=0x3E\""
|
arduino-cli compile --fqbn esp32:esp32:XIAO_ESP32S3 $(COMMON_BUILD_FLAGS) --build-property "compiler.cpp.extra_flags=\"-DBOARD_MODEL=0x3E\""
|
||||||
cp ~/.arduino15/packages/esp32/hardware/esp32/$(ARDUINO_ESP_CORE_VER)/tools/partitions/boot_app0.bin build/rnode_firmware_xiao_esp32s3.boot_app0
|
cp ~/.arduino15/packages/esp32/hardware/esp32/$(ARDUINO_ESP_CORE_VER)/tools/partitions/boot_app0.bin build/rnode_firmware_xiao_esp32s3.boot_app0
|
||||||
cp build/esp32.esp32.XIAO_ESP32S3/RNode_Firmware_CE.ino.bin build/rnode_firmware_xiao_esp32s3.bin
|
cp build/esp32.esp32.XIAO_ESP32S3/RNode_Firmware_CE.ino.bin build/rnode_firmware_xiao_esp32s3.bin
|
||||||
|
@ -529,4 +528,3 @@ release-heltec_t114:
|
||||||
cp build/Heltec_nRF52.Heltec_nRF52.HT-n5262/RNode_Firmware_CE.ino.hex build/rnode_firmware_heltec_t114.hex
|
cp build/Heltec_nRF52.Heltec_nRF52.HT-n5262/RNode_Firmware_CE.ino.hex build/rnode_firmware_heltec_t114.hex
|
||||||
adafruit-nrfutil dfu genpkg --dev-type 0x0052 --application build/rnode_firmware_heltec_t114.hex Release/rnode_firmware_heltec_t114.zip
|
adafruit-nrfutil dfu genpkg --dev-type 0x0052 --application build/rnode_firmware_heltec_t114.hex Release/rnode_firmware_heltec_t114.zip
|
||||||
rm -r build
|
rm -r build
|
||||||
|
|
||||||
|
|
11
README.md
11
README.md
|
@ -102,7 +102,6 @@ The production of one particular RNode device is not an end, but the potential s
|
||||||
|
|
||||||
This tree fits into the larger biome of Free & Open Communications Systems, which I hope that you - by using communications tools like RNode - will help grow and prosper.
|
This tree fits into the larger biome of Free & Open Communications Systems, which I hope that you - by using communications tools like RNode - will help grow and prosper.
|
||||||
|
|
||||||
|
|
||||||
## Getting Started Fast
|
## Getting Started Fast
|
||||||
You can download and flash the firmware to all the supported boards using [rnodeconf](https://github.com/markqvist/Reticulum). All firmware releases are handled and installed directly through the `rnodeconf` utility, which is included in the `rns` package. It can be installed via `pip`:
|
You can download and flash the firmware to all the supported boards using [rnodeconf](https://github.com/markqvist/Reticulum). All firmware releases are handled and installed directly through the `rnodeconf` utility, which is included in the `rns` package. It can be installed via `pip`:
|
||||||
|
|
||||||
|
@ -143,13 +142,13 @@ You can help support the continued development of open, free and private communi
|
||||||
```
|
```
|
||||||
84FpY1QbxHcgdseePYNmhTHcrgMX4nFfBYtz2GKYToqHVVhJp8Eaw1Z1EedRnKD19b3B8NiLCGVxzKV17UMmmeEsCrPyA5w
|
84FpY1QbxHcgdseePYNmhTHcrgMX4nFfBYtz2GKYToqHVVhJp8Eaw1Z1EedRnKD19b3B8NiLCGVxzKV17UMmmeEsCrPyA5w
|
||||||
```
|
```
|
||||||
- Ethereum
|
|
||||||
```
|
|
||||||
0xFDabC71AC4c0C78C95aDDDe3B4FA19d6273c5E73
|
|
||||||
```
|
|
||||||
- Bitcoin
|
- Bitcoin
|
||||||
```
|
```
|
||||||
35G9uWVzrpJJibzUwpNUQGQNFzLirhrYAH
|
bc1p4a6axuvl7n9hpapfj8sv5reqj8kz6uxa67d5en70vzrttj0fmcusgxsfk5
|
||||||
|
```
|
||||||
|
- Ethereum
|
||||||
|
```
|
||||||
|
0xae89F3B94fC4AD6563F0864a55F9a697a90261ff
|
||||||
```
|
```
|
||||||
- Ko-Fi: https://ko-fi.com/markqvist
|
- Ko-Fi: https://ko-fi.com/markqvist
|
||||||
|
|
||||||
|
|
|
@ -144,14 +144,24 @@ void setup() {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// Seed the PRNG for CSMA R-value selection
|
// Seed the PRNG for CSMA R-value selection
|
||||||
# if MCU_VARIANT == MCU_ESP32
|
#if MCU_VARIANT == MCU_ESP32
|
||||||
// On ESP32, get the seed value from the
|
// On ESP32, get the seed value from the
|
||||||
// hardware RNG
|
// hardware RNG
|
||||||
int seed_val = (int)esp_random();
|
unsigned long seed_val = (unsigned long)esp_random();
|
||||||
|
#elif MCU_VARIANT == MCU_NRF52
|
||||||
|
// On nRF, get the seed value from the
|
||||||
|
// hardware RNG
|
||||||
|
unsigned long seed_val = get_rng_seed();
|
||||||
#else
|
#else
|
||||||
// Otherwise, get a pseudo-random seed
|
// Otherwise, get a pseudo-random seed
|
||||||
// value from an unconnected analog pin
|
// value from an unconnected analog pin
|
||||||
int seed_val = analogRead(0);
|
//
|
||||||
|
// CAUTION! If you are implementing the
|
||||||
|
// firmware on a platform that does not
|
||||||
|
// have a hardware RNG, you MUST take
|
||||||
|
// care to get a seed value with enough
|
||||||
|
// entropy at each device reset!
|
||||||
|
unsigned long seed_val = analogRead(0);
|
||||||
#endif
|
#endif
|
||||||
randomSeed(seed_val);
|
randomSeed(seed_val);
|
||||||
|
|
||||||
|
@ -165,6 +175,10 @@ void setup() {
|
||||||
led_init();
|
led_init();
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if MCU_VARIANT == MCU_NRF52 && HAS_NP == true
|
||||||
|
boot_seq();
|
||||||
|
#endif
|
||||||
|
|
||||||
#if BOARD_MODEL != BOARD_RAK4631 && BOARD_MODEL != BOARD_HELTEC_T114 && BOARD_MODEL != BOARD_TECHO && BOARD_MODEL != BOARD_T3S3 && BOARD_MODEL != BOARD_TBEAM_S_V1 && BOARD_MODEL != BOARD_OPENCOM_XL
|
#if BOARD_MODEL != BOARD_RAK4631 && BOARD_MODEL != BOARD_HELTEC_T114 && BOARD_MODEL != BOARD_TECHO && BOARD_MODEL != BOARD_T3S3 && BOARD_MODEL != BOARD_TBEAM_S_V1 && BOARD_MODEL != BOARD_OPENCOM_XL
|
||||||
// Some boards need to wait until the hardware UART is set up before booting
|
// Some boards need to wait until the hardware UART is set up before booting
|
||||||
// the full firmware. In the case of the RAK4631/TECHO, the line below will wait
|
// the full firmware. In the case of the RAK4631/TECHO, the line below will wait
|
||||||
|
@ -1225,6 +1239,10 @@ void serial_callback(uint8_t sbyte) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
} else if (command == CMD_BT_UNPAIR) {
|
||||||
|
#if HAS_BLE
|
||||||
|
if (sbyte == 0x01) { bt_debond_all(); }
|
||||||
|
#endif
|
||||||
} else if (command == CMD_DISP_INT) {
|
} else if (command == CMD_DISP_INT) {
|
||||||
#if HAS_DISPLAY
|
#if HAS_DISPLAY
|
||||||
if (sbyte == FESC) {
|
if (sbyte == FESC) {
|
||||||
|
@ -1622,8 +1640,11 @@ void process_serial() {
|
||||||
|
|
||||||
void sleep_now() {
|
void sleep_now() {
|
||||||
#if HAS_SLEEP == true
|
#if HAS_SLEEP == true
|
||||||
|
for (int i = 0; i < INTERFACE_COUNT; i++) {
|
||||||
|
stopRadio(interface_obj[i]); // TODO: Check this on all platforms
|
||||||
|
}
|
||||||
#if PLATFORM == PLATFORM_ESP32
|
#if PLATFORM == PLATFORM_ESP32
|
||||||
#if BOARD_MODEL == BOARD_T3S3 || BOARD_MODEL == BOARD_XIAO_ESP32C3
|
#if BOARD_MODEL == BOARD_T3S3 || BOARD_MODEL == BOARD_XIAO_S3
|
||||||
display_intensity = 0;
|
display_intensity = 0;
|
||||||
update_display(true);
|
update_display(true);
|
||||||
#endif
|
#endif
|
||||||
|
|
Binary file not shown.
39
Utilities.h
39
Utilities.h
|
@ -23,6 +23,7 @@
|
||||||
#if HAS_EEPROM
|
#if HAS_EEPROM
|
||||||
#include <EEPROM.h>
|
#include <EEPROM.h>
|
||||||
#elif PLATFORM == PLATFORM_NRF52
|
#elif PLATFORM == PLATFORM_NRF52
|
||||||
|
#include <hal/nrf_rng.h>
|
||||||
#include <Adafruit_LittleFS.h>
|
#include <Adafruit_LittleFS.h>
|
||||||
#include <InternalFileSystem.h>
|
#include <InternalFileSystem.h>
|
||||||
using namespace Adafruit_LittleFS_Namespace;
|
using namespace Adafruit_LittleFS_Namespace;
|
||||||
|
@ -90,6 +91,28 @@ uint8_t boot_vector = 0x00;
|
||||||
// TODO: Get NRF52 boot flags
|
// TODO: Get NRF52 boot flags
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#if MCU_VARIANT == MCU_NRF52
|
||||||
|
unsigned long get_rng_seed() {
|
||||||
|
nrf_rng_error_correction_enable(NRF_RNG);
|
||||||
|
nrf_rng_shorts_disable(NRF_RNG, NRF_RNG_SHORT_VALRDY_STOP_MASK);
|
||||||
|
nrf_rng_task_trigger(NRF_RNG, NRF_RNG_TASK_START);
|
||||||
|
while (!nrf_rng_event_check(NRF_RNG, NRF_RNG_EVENT_VALRDY));
|
||||||
|
uint8_t rb_a = nrf_rng_random_value_get(NRF_RNG);
|
||||||
|
nrf_rng_event_clear(NRF_RNG, NRF_RNG_EVENT_VALRDY);
|
||||||
|
while (!nrf_rng_event_check(NRF_RNG, NRF_RNG_EVENT_VALRDY));
|
||||||
|
uint8_t rb_b = nrf_rng_random_value_get(NRF_RNG);
|
||||||
|
nrf_rng_event_clear(NRF_RNG, NRF_RNG_EVENT_VALRDY);
|
||||||
|
while (!nrf_rng_event_check(NRF_RNG, NRF_RNG_EVENT_VALRDY));
|
||||||
|
uint8_t rb_c = nrf_rng_random_value_get(NRF_RNG);
|
||||||
|
nrf_rng_event_clear(NRF_RNG, NRF_RNG_EVENT_VALRDY);
|
||||||
|
while (!nrf_rng_event_check(NRF_RNG, NRF_RNG_EVENT_VALRDY));
|
||||||
|
uint8_t rb_d = nrf_rng_random_value_get(NRF_RNG);
|
||||||
|
nrf_rng_event_clear(NRF_RNG, NRF_RNG_EVENT_VALRDY);
|
||||||
|
nrf_rng_task_trigger(NRF_RNG, NRF_RNG_TASK_STOP);
|
||||||
|
return rb_a << 24 | rb_b << 16 | rb_c << 8 | rb_d;
|
||||||
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
#if HAS_NP == true
|
#if HAS_NP == true
|
||||||
#include <Adafruit_NeoPixel.h>
|
#include <Adafruit_NeoPixel.h>
|
||||||
#define NUMPIXELS 1
|
#define NUMPIXELS 1
|
||||||
|
@ -279,6 +302,13 @@ uint8_t boot_vector = 0x00;
|
||||||
void led_tx_off() { digitalWrite(pin_led_tx, LOW); }
|
void led_tx_off() { digitalWrite(pin_led_tx, LOW); }
|
||||||
void led_id_on() { }
|
void led_id_on() { }
|
||||||
void led_id_off() { }
|
void led_id_off() { }
|
||||||
|
#elif BOARD_MODEL == BOARD_XIAO_S3
|
||||||
|
void led_rx_on() { digitalWrite(pin_led_rx, LED_ON); }
|
||||||
|
void led_rx_off() { digitalWrite(pin_led_rx, LED_OFF); }
|
||||||
|
void led_tx_on() { digitalWrite(pin_led_tx, LED_ON); }
|
||||||
|
void led_tx_off() { digitalWrite(pin_led_tx, LED_OFF); }
|
||||||
|
void led_id_on() { }
|
||||||
|
void led_id_off() { }
|
||||||
#elif BOARD_MODEL == BOARD_HUZZAH32
|
#elif BOARD_MODEL == BOARD_HUZZAH32
|
||||||
void led_rx_on() { digitalWrite(pin_led_rx, HIGH); }
|
void led_rx_on() { digitalWrite(pin_led_rx, HIGH); }
|
||||||
void led_rx_off() { digitalWrite(pin_led_rx, LOW); }
|
void led_rx_off() { digitalWrite(pin_led_rx, LOW); }
|
||||||
|
@ -286,7 +316,7 @@ uint8_t boot_vector = 0x00;
|
||||||
void led_tx_off() { digitalWrite(pin_led_tx, LOW); }
|
void led_tx_off() { digitalWrite(pin_led_tx, LOW); }
|
||||||
void led_id_on() { }
|
void led_id_on() { }
|
||||||
void led_id_off() { }
|
void led_id_off() { }
|
||||||
#elif BOARD_MODEL == BOARD_XIAO_ESP32S3
|
#elif BOARD_MODEL == BOARD_XIAO_S3
|
||||||
void led_rx_on() {}
|
void led_rx_on() {}
|
||||||
void led_rx_off() {}
|
void led_rx_off() {}
|
||||||
void led_tx_on() { digitalWrite(pin_led_tx, LED_ON); }
|
void led_tx_on() { digitalWrite(pin_led_tx, LED_ON); }
|
||||||
|
@ -1251,6 +1281,7 @@ void setTXPower(RadioInterface* radio, int txp) {
|
||||||
if (model == MODEL_DC) radio->setTxPower(txp, PA_OUTPUT_PA_BOOST_PIN);
|
if (model == MODEL_DC) radio->setTxPower(txp, PA_OUTPUT_PA_BOOST_PIN);
|
||||||
|
|
||||||
if (model == MODEL_DD) radio->setTxPower(txp, PA_OUTPUT_PA_BOOST_PIN);
|
if (model == MODEL_DD) radio->setTxPower(txp, PA_OUTPUT_PA_BOOST_PIN);
|
||||||
|
if (model == MODEL_DE) radio->setTxPower(txp, PA_OUTPUT_PA_BOOST_PIN);
|
||||||
|
|
||||||
if (model == MODEL_E4) radio->setTxPower(txp, PA_OUTPUT_PA_BOOST_PIN);
|
if (model == MODEL_E4) radio->setTxPower(txp, PA_OUTPUT_PA_BOOST_PIN);
|
||||||
if (model == MODEL_E9) radio->setTxPower(txp, PA_OUTPUT_PA_BOOST_PIN);
|
if (model == MODEL_E9) radio->setTxPower(txp, PA_OUTPUT_PA_BOOST_PIN);
|
||||||
|
@ -1481,7 +1512,7 @@ bool eeprom_product_valid() {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if PLATFORM == PLATFORM_ESP32
|
#if PLATFORM == PLATFORM_ESP32
|
||||||
if (rval == PRODUCT_RNODE || rval == BOARD_RNODE_NG_20 || rval == BOARD_RNODE_NG_21 || rval == PRODUCT_HMBRW || rval == PRODUCT_TBEAM || rval == PRODUCT_T32_10 || rval == PRODUCT_T32_20 || rval == PRODUCT_T32_21 || rval == PRODUCT_H32_V2 || rval == PRODUCT_H32_V3 || rval == PRODUCT_TDECK_V1 || rval == PRODUCT_TBEAM_S_V1 || rval == PRODUCT_H_W_PAPER || rval == PRODUCT_XIAO_ESP32S3) {
|
if (rval == PRODUCT_RNODE || rval == BOARD_RNODE_NG_20 || rval == BOARD_RNODE_NG_21 || rval == PRODUCT_HMBRW || rval == PRODUCT_TBEAM || rval == PRODUCT_T32_10 || rval == PRODUCT_T32_20 || rval == PRODUCT_T32_21 || rval == PRODUCT_H32_V2 || rval == PRODUCT_H32_V3 || rval == PRODUCT_TDECK_V1 || rval == PRODUCT_TBEAM_S_V1 || rval == PRODUCT_H_W_PAPER || rval == PRODUCT_XIAO_S3) {
|
||||||
#elif PLATFORM == PLATFORM_NRF52
|
#elif PLATFORM == PLATFORM_NRF52
|
||||||
if (rval == PRODUCT_RAK4631 || rval == PRODUCT_HELTEC_T114 || rval == PRODUCT_OPENCOM_XL || rval == PRODUCT_TECHO || rval == PRODUCT_HMBRW) {
|
if (rval == PRODUCT_RAK4631 || rval == PRODUCT_HELTEC_T114 || rval == PRODUCT_OPENCOM_XL || rval == PRODUCT_TECHO || rval == PRODUCT_HMBRW) {
|
||||||
#else
|
#else
|
||||||
|
@ -1517,8 +1548,8 @@ bool eeprom_model_valid() {
|
||||||
if (model == MODEL_16 || model == MODEL_17) {
|
if (model == MODEL_16 || model == MODEL_17) {
|
||||||
#elif BOARD_MODEL == BOARD_TBEAM_S_V1
|
#elif BOARD_MODEL == BOARD_TBEAM_S_V1
|
||||||
if (model == MODEL_DB || model == MODEL_DC) {
|
if (model == MODEL_DB || model == MODEL_DC) {
|
||||||
#elif BOARD_MODEL == BOARD_XIAO_ESP32S3
|
#elif BOARD_MODEL == BOARD_XIAO_S3
|
||||||
if (model == MODEL_DD) {
|
if (model == MODEL_DD || model == MODEL_DE) {
|
||||||
#elif BOARD_MODEL == BOARD_LORA32_V1_0
|
#elif BOARD_MODEL == BOARD_LORA32_V1_0
|
||||||
if (model == MODEL_BA || model == MODEL_BB) {
|
if (model == MODEL_BA || model == MODEL_BB) {
|
||||||
#elif BOARD_MODEL == BOARD_LORA32_V2_0
|
#elif BOARD_MODEL == BOARD_LORA32_V2_0
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
#!/usr/bin/env python3
|
#!/usr/bin/env python3
|
||||||
import sys
|
import sys
|
||||||
|
import re
|
||||||
|
|
||||||
try:
|
try:
|
||||||
target_path = sys.argv[1]
|
target_path = sys.argv[1]
|
||||||
|
@ -12,7 +13,7 @@ try:
|
||||||
for line in sf:
|
for line in sf:
|
||||||
line_index += 1
|
line_index += 1
|
||||||
if line.startswith("#define RX_QUEUE_SIZE"):
|
if line.startswith("#define RX_QUEUE_SIZE"):
|
||||||
ents = line.split(" ")
|
ents = re.sub(" +", " ", line).split(" ")
|
||||||
try:
|
try:
|
||||||
rxbuf_size = int(ents[2])
|
rxbuf_size = int(ents[2])
|
||||||
rx_line_index = line_index
|
rx_line_index = line_index
|
||||||
|
@ -20,12 +21,12 @@ try:
|
||||||
print(f"Could not parse Bluetooth RX_QUEUE_SIZE: {e}")
|
print(f"Could not parse Bluetooth RX_QUEUE_SIZE: {e}")
|
||||||
|
|
||||||
if line.startswith("#define TX_QUEUE_SIZE"):
|
if line.startswith("#define TX_QUEUE_SIZE"):
|
||||||
ents = line.split(" ")
|
ents = re.sub(" +", " ", line).split(" ")
|
||||||
try:
|
try:
|
||||||
txbuf_size = int(ents[2])
|
txbuf_size = int(ents[2])
|
||||||
tx_line_index = line_index
|
tx_line_index = line_index
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(f"Could not parse Bluetooth RX_QUEUE_SIZE: {e}")
|
print(f"Could not parse Bluetooth TX_QUEUE_SIZE: {e}")
|
||||||
|
|
||||||
if rxbuf_size != 0 and txbuf_size != 0:
|
if rxbuf_size != 0 and txbuf_size != 0:
|
||||||
break
|
break
|
||||||
|
|
|
@ -97,6 +97,17 @@ void BLESerial::flush() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void BLESerial::disconnect() {
|
||||||
|
if (ble_server->getConnectedCount() > 0) {
|
||||||
|
uint16_t conn_id = ble_server->getConnId();
|
||||||
|
// Serial.printf("Have connected: %d\n", conn_id);
|
||||||
|
ble_server->disconnect(conn_id);
|
||||||
|
// Serial.println("Disconnected");
|
||||||
|
} else {
|
||||||
|
// Serial.println("No connected");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void BLESerial::begin(const char *name) {
|
void BLESerial::begin(const char *name) {
|
||||||
ConnectedDeviceCount = 0;
|
ConnectedDeviceCount = 0;
|
||||||
BLEDevice::init(name);
|
BLEDevice::init(name);
|
||||||
|
@ -111,7 +122,10 @@ void BLESerial::begin(const char *name) {
|
||||||
BLEDevice::setSecurityCallbacks(this);
|
BLEDevice::setSecurityCallbacks(this);
|
||||||
|
|
||||||
SetupSerialService();
|
SetupSerialService();
|
||||||
|
this->startAdvertising();
|
||||||
|
}
|
||||||
|
|
||||||
|
void BLESerial::startAdvertising() {
|
||||||
ble_adv = BLEDevice::getAdvertising();
|
ble_adv = BLEDevice::getAdvertising();
|
||||||
ble_adv->addServiceUUID(BLE_SERIAL_SERVICE_UUID);
|
ble_adv->addServiceUUID(BLE_SERIAL_SERVICE_UUID);
|
||||||
ble_adv->setMinPreferred(0x20);
|
ble_adv->setMinPreferred(0x20);
|
||||||
|
@ -120,6 +134,11 @@ void BLESerial::begin(const char *name) {
|
||||||
ble_adv->start();
|
ble_adv->start();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void BLESerial::stopAdvertising() {
|
||||||
|
ble_adv = BLEDevice::getAdvertising();
|
||||||
|
ble_adv->stop();
|
||||||
|
}
|
||||||
|
|
||||||
void BLESerial::end() { BLEDevice::deinit(); }
|
void BLESerial::end() { BLEDevice::deinit(); }
|
||||||
|
|
||||||
void BLESerial::onWrite(BLECharacteristic *characteristic) {
|
void BLESerial::onWrite(BLECharacteristic *characteristic) {
|
||||||
|
|
|
@ -78,6 +78,9 @@ public:
|
||||||
|
|
||||||
void begin(const char *name);
|
void begin(const char *name);
|
||||||
void end();
|
void end();
|
||||||
|
void disconnect();
|
||||||
|
void startAdvertising();
|
||||||
|
void stopAdvertising();
|
||||||
void onWrite(BLECharacteristic *characteristic);
|
void onWrite(BLECharacteristic *characteristic);
|
||||||
int available();
|
int available();
|
||||||
int peek();
|
int peek();
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue