diff --git a/firmware/firmware_v1.0/src/main.c b/firmware/firmware_v1.0/src/main.c index 784a60175..d114ddf76 100644 --- a/firmware/firmware_v1.0/src/main.c +++ b/firmware/firmware_v1.0/src/main.c @@ -25,6 +25,44 @@ void bt_ctlr_assert_handle(char *name, int type) } } +bool is_connected = false; +bool is_charging = false; + +void set_led_state() +{ + // Recording and connected state - BLUE + if (is_connected) + { + set_led_red(false); + set_led_green(false); + set_led_blue(true); + return; + } + + // Recording but lost connection - RED + if (!is_connected) + { + set_led_red(true); + set_led_green(false); + set_led_blue(false); + return; + } + + // Not recording, but charging - WHITE + if (is_charging) + { + set_led_red(true); + set_led_green(true); + set_led_blue(true); + return; + } + + // Not recording - OFF + set_led_red(false); + set_led_green(false); + set_led_blue(false); +} + // Main loop int main(void) { @@ -43,16 +81,11 @@ int main(void) set_mic_callback(mic_handler); ASSERT_OK(mic_start()); - // Blink LED - bool is_on = true; - set_led_blue(false); - set_led_red(is_on); - // while (1) - // { - // is_on = !is_on; - // set_led_red(is_on); - // k_msleep(500); - // } + while (1) + { + set_led_state(); + k_msleep(500); + } // Unreachable return 0; diff --git a/firmware/firmware_v1.0/src/transport.c b/firmware/firmware_v1.0/src/transport.c index 6f2a8305c..2d9f16dac 100644 --- a/firmware/firmware_v1.0/src/transport.c +++ b/firmware/firmware_v1.0/src/transport.c @@ -14,6 +14,8 @@ #include "btutils.h" #include "lib/battery/battery.h" +extern bool is_connected; + // // Internal // @@ -207,10 +209,14 @@ static void _transport_connected(struct bt_conn *conn, uint8_t err) printk("LE data len updated: TX (len: %d time: %d) RX (len: %d time: %d)\n", info.le.data_len->tx_max_len, info.le.data_len->tx_max_time, info.le.data_len->rx_max_len, info.le.data_len->rx_max_time); k_work_schedule(&battery_work, K_MSEC(BATTERY_REFRESH_INTERVAL)); + + is_connected = true; } static void _transport_disconnected(struct bt_conn *conn, uint8_t err) { + is_connected = false; + printk("Disconnected\n"); bt_conn_unref(conn); current_connection = NULL; diff --git a/firmware/readme.md b/firmware/readme.md index 478bf1f67..16562bf5f 100644 --- a/firmware/readme.md +++ b/firmware/readme.md @@ -4,54 +4,25 @@ pip3 install --user adafruit-nrfutil ``` -### Upgrade bootloader using adafruit-nrfutil +### Create firmware OTA .zip using adafruit-nrfutil -Download a compatible version of the ```xiao_nrf52840_ble_sense_bootloader-``` bootloader -from [Adafurit bootloader releases](https://github.com/adafruit/Adafruit_nRF52_Bootloader/releases) -The minimum version required is 0.8.0. - -Put the board in bootloader mode by double pressing the reset button. -Check the serial port for the board and modify the command below accordingly. - -``` -adafruit-nrfutil dfu serial -p COM8 -pkg xiao_nrf52840_ble_sense_bootloader-0.8.0_s140_7.3.0.zip -``` - -### Upgrade firmware using adafruit-nrfutil - -Put the board in bootloader mode by double pressing the reset button. -Check the serial port for the board and modify the command below accordingly. - -``` +```bash adafruit-nrfutil dfu genpkg --dev-type 0x0052 --dev-revision 0xCE68 --application zephyr.hex zephyr.zip -adafruit-nrfutil dfu serial -p COM8 -pkg zephyr.zip ``` -You can also use the Nordic nRF Connect app to upgrade the bootloader and firmware. Make sure -to change the PRN option from the default of 12 to 8. - -### Create firmware UF2 file +### Upgrade firmware using UF2 file -You need the uf2conv.py script to convert the hex file to a uf2 file. You can find the script in the Adafruit -bootloader repository. The script is located in the ```lib/uf2/utils``` directory. -Alternatively, you can get the script from the Microsoft UF2 repository. - -```bash -git clone https://github.com/adafruit/Adafruit_nRF52_Bootloader -cd Adafruit_nRF52_Bootloader -git submodule update --init -cd lib\uf2\utils -``` +Download the latest version of the firmware ```xiao_nrf52840_ble_sense-XXXX.uf2``` +from [Friend firmware releases](https://github.com/BasedHardware/Friend/releases) -To create UF2 file with the application hex file, run the following command: +Put the board in bootloader mode by double pressing the reset button. The board should appear as a USB drive. -```bash -python c:\src\Adafruit_nRF52_Bootloader\lib\uf2\utils\uf2conv.py --convert --family 0xADA52840 --output friend-1.0.2.uf2 firmware_v1.0\build\zephyr\zephyr.hex -``` +Copy the new firmware file in the root directory of the board. The board will automatically update the firmware and reset back to application mode. +You can check the firmware version from the Friend companion app. ### Upgrade bootloader using UF2 file -Download a compatible version of the ```update-xiao_nrf52840_ble_sense_bootloader-``` bootloader +Download a compatible version of the ```update-xiao_nrf52840_ble_sense_bootloader-XXX.uf2``` bootloader from [Adafurit bootloader releases](https://github.com/adafruit/Adafruit_nRF52_Bootloader/releases) The latest tested version is 0.9.0. Newer versions should work as well.