diff --git a/Friend/firmware/firmware_v1.0/CMakeLists.txt b/Friend/firmware/firmware_v1.0/CMakeLists.txt index d96488956..81e8e146f 100644 --- a/Friend/firmware/firmware_v1.0/CMakeLists.txt +++ b/Friend/firmware/firmware_v1.0/CMakeLists.txt @@ -7,15 +7,15 @@ enable_language(C ASM) target_sources(app PRIVATE src/main.c - src/transport.c - src/mic.c + #src/transport.c + #src/mic.c src/led.c src/codec.c src/lib/battery/battery.c - src/button.c - src/speaker.c - src/sdcard.c - src/storage.c + #src/button.c + #src/speaker.c + #src/sdcard.c + #src/storage.c src/usb.c # src/nfc.c future release ) diff --git a/Friend/firmware/firmware_v1.0/CMakePresets.json b/Friend/firmware/firmware_v1.0/CMakePresets.json index 6df34505f..2cfb35de2 100644 --- a/Friend/firmware/firmware_v1.0/CMakePresets.json +++ b/Friend/firmware/firmware_v1.0/CMakePresets.json @@ -1,58 +1,78 @@ { "version": 2, - "cmakeMinimumRequired": { - "major": 3, - "minor": 20, - "patch": 0 - }, - "configurePresets": [ - { - "name": "build_xiao_ble_sense_devkitv1", - "displayName": "Devkit V1", - "configuration": "Debug", - "hidden": false, - "description": "Debug build for devkit v1 device with no external modules", - "generator": "Ninja", - "binaryDir": "${sourceDir}/build/build_xiao_ble_sense_devkitv1", - "cacheVariables": { - "CMAKE_EXPORT_COMPILE_COMMANDS": "YES", - "CMAKE_BUILD_TYPE": "Debug", - "PLATFORM": "nrf52840", - "BOARD": "xiao_ble_sense", - "CACHED_CONF_FILE": "${sourceDir}/prj_xiao_ble_sense_devkitv1.conf" + "cmakeMinimumRequired": { + "major": 3, + "minor": 20, + "patch": 0 + }, + "configurePresets": [ + { + "name": "build_xiao_ble_sense_devkitv1", + "displayName": "Devkit V1", + "configuration": "Debug", + "hidden": false, + "description": "Debug build for devkit v1 device with no external modules", + "generator": "Ninja", + "binaryDir": "${sourceDir}/build/build_xiao_ble_sense_devkitv1", + "cacheVariables": { + "CMAKE_EXPORT_COMPILE_COMMANDS": "YES", + "CMAKE_BUILD_TYPE": "Debug", + "PLATFORM": "nrf52840", + "BOARD": "xiao_ble_sense", + "CACHED_CONF_FILE": "${sourceDir}/prj_xiao_ble_sense_devkitv1.conf" } - },{ - "name": "build_xiao_ble_sense_devkitv1-spisd.", - "displayName": "Devkit V1 (with SPI SD)", - "configuration": "Debug", - "hidden": false, - "description": "Debug build for devkit v1 device with external SPI SD card module", - "generator": "Ninja", - "binaryDir": "${sourceDir}/build/build_xiao_ble_sense_devkitv1-spisd", - "cacheVariables": { - "CMAKE_EXPORT_COMPILE_COMMANDS": "YES", - "CMAKE_BUILD_TYPE": "Debug", - "PLATFORM": "nrf52840", - "BOARD": "xiao_ble_sense", - "CACHED_CONF_FILE": "${sourceDir}/prj_xiao_ble_sense_devkitv1-spisd.conf", - "DTC_OVERLAY_FILE": "${sourceDir}/overlay/xiao_ble_sense_devkitv1-spisd.overlay" + }, + { + "name": "build_xiao_ble_sense_devkitv1-spisd.", + "displayName": "Devkit V1 (with SPI SD)", + "configuration": "Debug", + "hidden": false, + "description": "Debug build for devkit v1 device with external SPI SD card module", + "generator": "Ninja", + "binaryDir": "${sourceDir}/build/build_xiao_ble_sense_devkitv1-spisd", + "cacheVariables": { + "CMAKE_EXPORT_COMPILE_COMMANDS": "YES", + "CMAKE_BUILD_TYPE": "Debug", + "PLATFORM": "nrf52840", + "BOARD": "xiao_ble_sense", + "CACHED_CONF_FILE": "${sourceDir}/prj_xiao_ble_sense_devkitv1-spisd.conf", + "DTC_OVERLAY_FILE": "${sourceDir}/overlay/xiao_ble_sense_devkitv1-spisd.overlay" } - },{ - "name": "build_xiao_ble_sense_devkitv2-adafruit.", - "displayName": "Devkit V2 (with Adafruit BFF Module)", - "configuration": "Debug", - "hidden": false, - "description": "Debug build for devkit v2 device with adafruit audio bff module", - "generator": "Ninja", - "binaryDir": "${sourceDir}/build/build_xiao_ble_sense_devkitv2-adafruit", - "cacheVariables": { - "CMAKE_EXPORT_COMPILE_COMMANDS": "YES", - "CMAKE_BUILD_TYPE": "Debug", - "PLATFORM": "nrf52840", - "BOARD": "xiao_ble_sense", - "CACHED_CONF_FILE": "${sourceDir}/prj_xiao_ble_sense_devkitv2-adafruit.conf", - "CONF_FILE": "${sourceDir}/prj_xiao_ble_sense_devkitv2-adafruit.conf", - "DTC_OVERLAY_FILE": "${sourceDir}/overlay/xiao_ble_sense_devkitv2-adafruit.overlay" + }, + { + "name": "build_xiao_ble_sense_devkitv2-adafruit.", + "displayName": "Devkit V2 (with Adafruit BFF Module)", + "configuration": "Debug", + "hidden": false, + "description": "Debug build for devkit v2 device with adafruit audio bff module", + "generator": "Ninja", + "binaryDir": "${sourceDir}/build/build_xiao_ble_sense_devkitv2-adafruit", + "cacheVariables": { + "CMAKE_EXPORT_COMPILE_COMMANDS": "YES", + "CMAKE_BUILD_TYPE": "Debug", + "PLATFORM": "nrf52840", + "BOARD": "xiao_ble_sense", + "CACHED_CONF_FILE": "${sourceDir}/prj_xiao_ble_sense_devkitv2-adafruit.conf", + "CONF_FILE": "${sourceDir}/prj_xiao_ble_sense_devkitv2-adafruit.conf", + "DTC_OVERLAY_FILE": "${sourceDir}/overlay/xiao_ble_sense_devkitv2-adafruit.overlay" + } + }, + { + "name": "build_xiao_ble_sense_devkitv2-5340.", + "displayName": "Devkit V2 (with nrf5340)", + "configuration": "Debug", + "hidden": false, + "description": "Debug build for devkit v2 device with nrf5340", + "generator": "Ninja", + "binaryDir": "${sourceDir}/build/build_xiao_ble_sense_devkitv2-5340", + "cacheVariables": { + "CMAKE_EXPORT_COMPILE_COMMANDS": "YES", + "CMAKE_BUILD_TYPE": "Debug", + "PLATFORM": "nrf5340", + "BOARD": "xiao_ble_sense", + "CACHED_CONF_FILE": "${sourceDir}/prj_xiao_ble_sense_devkitv2-5340.conf", + "CONF_FILE": "${sourceDir}/prj_xiao_ble_sense_devkitv2-5340.conf", + "DTC_OVERLAY_FILE": "${sourceDir}/overlay/xiao_ble_sense_devkitv2-5340.overlay" } } ] diff --git a/Friend/firmware/firmware_v1.0/Kconfig b/Friend/firmware/firmware_v1.0/Kconfig index e60ad2fe5..23943cbf9 100644 --- a/Friend/firmware/firmware_v1.0/Kconfig +++ b/Friend/firmware/firmware_v1.0/Kconfig @@ -17,4 +17,7 @@ config ENABLE_BUTTON config ENABLE_SPEAKER bool "Enable the speaker!!" default n +config ENABLE_LED + bool "Enable the led!!" + default y endmenu diff --git a/Friend/firmware/firmware_v1.0/overlay/xiao_ble_sense_devkitv2-5340.overlay b/Friend/firmware/firmware_v1.0/overlay/xiao_ble_sense_devkitv2-5340.overlay new file mode 100644 index 000000000..c2881ee88 --- /dev/null +++ b/Friend/firmware/firmware_v1.0/overlay/xiao_ble_sense_devkitv2-5340.overlay @@ -0,0 +1,94 @@ + +//&i2s0 { +// status = "okay"; +// pinctrl-0 = <&i2s0_default>; +// pinctrl-names = "default"; +// label = "I2S_0"; +//}; +// +//&pinctrl { +// i2s0_default: i2s0_default { +// group1 { +// psels = , // SCK pin (bit clock) A3 +// , // LRCK pin (word select clock) A2 +// ; // SDOUT pin (data out) A1 +// }; +// }; +//}; +// +//&spi2 { +// status = "okay"; +// pinctrl-0 = <&custom_spi>; +// pinctrl-1 = <&custom_spi>; +// pinctrl-names = "default", "sleep"; +// cs-gpios = <&gpio0 2 GPIO_ACTIVE_LOW>; // CS pin on P0.28 +// +// sdhc0: sdhc@0 { +// compatible = "zephyr,sdhc-spi-slot"; +// reg = <0>; +// status = "okay"; +// label = "SDHC_0"; +// mmc { +// compatible = "zephyr,sdmmc-disk"; +// status = "okay"; +// }; +// spi-max-frequency = <24000000>; // 24 MHz SPI speed for SD card +// }; +//}; +// +//&pinctrl { +// custom_spi: custom_spi { +// group1 { +// psels = , // SCK on P1.13 +// , // MOSI on P1.15 +// ; // MISO on P1.14 +// }; +// }; +//}; +// +//&uart0 { +// status = "disabled"; +//}; +// +//// &qspi { +//// status = "disabled"; +//// }; +// +//&i2c0 { +// lsm6ds3tr_c: lsm6ds3tr-c@6a { +// compatible = "st,lsm6dsl"; +// reg = <0x6a>; +// irq-gpios = <&gpio0 11 GPIO_ACTIVE_HIGH>; +// status = "okay"; +// label = "b"; +// // wakeup-source = true; +// }; +//}; +// +//&i2c1{ +// status = "disabled"; +//}; +// +//&temp { +// status = "disabled"; +//}; +// +// + + +//FOR 7002DK, ref: /opt/nordic/ncs/v2.8.0/zephyr/boards/nordic/nrf7002dk/nrf5340_cpuapp_common.dtsi +/ { + aliases { + led0 = &led0; + led1 = &led1; + led2 = &led1; + pwm-led0 = &pwm_led0; + sw0 = &button0; + sw1 = &button1; + bootloader-led0 = &led0; + mcuboot-button0 = &button0; + mcuboot-led0 = &led0; + watchdog0 = &wdt0; + }; +}; + diff --git a/Friend/firmware/firmware_v1.0/prj_xiao_ble_sense_devkitv2-5340.conf b/Friend/firmware/firmware_v1.0/prj_xiao_ble_sense_devkitv2-5340.conf new file mode 100644 index 000000000..5b0ef5d5b --- /dev/null +++ b/Friend/firmware/firmware_v1.0/prj_xiao_ble_sense_devkitv2-5340.conf @@ -0,0 +1,195 @@ +# +# Hardware settings +# + +CONFIG_GPIO=y +CONFIG_NRFX_PDM0=y +CONFIG_ADC=y + +# To flash via dev board +#CONFIG_BUILD_OUTPUT_UF2=n +#CONFIG_USE_DT_CODE_PARTITION=n + +# +# Bluetooth settings +# + +CONFIG_BT=y +CONFIG_BT_PERIPHERAL=y +CONFIG_BT_DEVICE_NAME="Omi DevKit 2" +CONFIG_BT_MAX_CONN=1 +# CONFIG_BT_EXT_ADV_MAX_ADV_SET=2 +CONFIG_BT_MAX_PAIRED=1 +CONFIG_BT_DEVICE_APPEARANCE=22 +CONFIG_BT_GATT_DYNAMIC_DB=y + +# +# Max transmit power supported by nRF52840 +# + +CONFIG_BT_CTLR_TX_PWR_ANTENNA=8 +CONFIG_BT_PHY_UPDATE=y + +# +# Battery and Device Information services +# + +CONFIG_BT_BAS=y +CONFIG_BT_DIS=y +CONFIG_BT_DIS_PNP=n +CONFIG_BT_DIS_MODEL="Omi DevKit 2" +CONFIG_BT_DIS_MANUF="Based Hardware" +CONFIG_BT_DIS_FW_REV=y +CONFIG_BT_DIS_HW_REV=y +CONFIG_BT_DIS_FW_REV_STR="2.0.7" +CONFIG_BT_DIS_HW_REV_STR="Seeed Xiao BLE Sense" + +# +# Large BLE packets / BLE Buffers +# +# CONFIG_BT_GATT_CLIENT=y +# CONFIG_BT_THROUGHPUT=y + +CONFIG_BT_L2CAP_TX_MTU=498 + +CONFIG_BT_CTLR_DATA_LENGTH_MAX=251 +CONFIG_BT_CTLR_PHY_2M=y +CONFIG_BT_CTLR_PHY_CODED=y +CONFIG_BT_CTLR_SDC_MAX_CONN_EVENT_LEN_DEFAULT=400000 +CONFIG_BT_CONN_TX_MAX=20 +CONFIG_BT_BUF_ACL_RX_SIZE=1024 +CONFIG_BT_L2CAP_TX_BUF_COUNT=10 +CONFIG_BT_BUF_ACL_TX_SIZE=2048 +# CONFIG_BT_ATT_TX_COUNT=10 +# CONFIG_BT_EXT_ADV=y +# CONFIG_BT_PER_ADV=y +# CONFIG_BT_OBSERVER=y +# CONFIG_BT_ATT_PREPARE_COUNT=2 +CONFIG_BT_USER_DATA_LEN_UPDATE=y +CONFIG_BT_AUTO_DATA_LEN_UPDATE=y +CONFIG_BT_USER_PHY_UPDATE=y +CONFIG_BT_AUTO_PHY_UPDATE=y + +CONFIG_FPU=y +CONFIG_NORDIC_QSPI_NOR=n +# CONFIG_BOARD_ENABLE_DCDC=y +# + +##TODO +# +# Console +# +# Disable the lines to enable console log +CONFIG_CONSOLE=n + +# +# Debug +# +# Enable the lines below to enable debug logs via UART/USB + +# CONFIG_DEBUG=y +# CONFIG_LOG=y +# CONFIG_LOG_PRINTK=y +# CONFIG_LOG_MODE_IMMEDIATE=y +# CONFIG_DEBUG_OPTIMIZATIONS=y +# CONFIG_SERIAL=y +# CONFIG_UART_CONSOLE=y +# CONFIG_LOG_BACKEND_UART=y +# CONFIG_LOG_BACKEND_UART_OUTPUT_TEXT=y +# CONFIG_LOG_DEFAULT_LEVEL=3 + +# +# Debug (This value breaks some builds) +# + +# CONFIG_ASSERT=y + +# +# Log Levels +# + +# CONFIG_BT_DEBUG_LOG=y +# CONFIG_BT_L2CAP_LOG_LEVEL_DBG=y +# CONFIG_BT_LOG_LEVEL_DBG=y + +# CONFIG_LOG_PROCESS_THREAD_STACK_SIZE=4096 +# CONFIG_BT_RX_STACK_SIZE=4096 +# CONFIG_BT_CTLR_RX_PRIO_STACK_SIZE=4096 +# CONFIG_BT_DEBUG_LOG=y +# CONFIG_LOG_BUFFER_SIZE=32000 +# CONFIG_LOG_OVERRIDE_LEVEL=4 +# CONFIG_LOG_PROCESS_THREAD_STACK_SIZE=4096 +# CONFIG_BT_RX_STACK_SIZE=4096 +# CONFIG_BT_CTLR_RX_PRIO_STACK_SIZE=4096 + +# +# Codecs +# +CONFIG_CODEC_OPUS=y + +# +# SD Card Support (all devices required) +# + +CONFIG_OFFLINE_STORAGE=y +CONFIG_DISK_ACCESS=y +CONFIG_FILE_SYSTEM=y +CONFIG_FAT_FILESYSTEM_ELM=y +CONFIG_FS_FATFS_MOUNT_MKFS=y +CONFIG_FS_FATFS_EXFAT=y +# CONFIG_PRINTK=y +#nessessary? +CONFIG_MAIN_STACK_SIZE=2048 +# CONFIG_DISK_DRIVER_SDMMC=y +# CONFIG_SPI=y +CONFIG_HEAP_MEM_POOL_SIZE=512 + +# +# Disable unused peripherals +# +CONFIG_I2C=n +# CONFIG_NRFX_TWIM0=n +# CONFIG_NRFX_TWIM1=n + +# +# LSM6DSL sensor (accelerometer and gyroscope) +# +CONFIG_LSM6DSL=y +CONFIG_LSM6DSL_ENABLE_TEMP=n +# CONFIG_LSM6DSL_TRIGGER_GLOBAL_THREAD=y +CONFIG_SENSOR=y + +# +# Speaker +# +CONFIG_I2S=y +CONFIG_I2S_NRFX=y +CONFIG_SPI_NRFX=y + +## +## NFC (in the future) +## +# +## CONFIG_NFC_T2T_NRFXLIB=y +## CONFIG_NFC_NDEF=y +## CONFIG_NFC_NDEF_MSG=y +## CONFIG_NFC_NDEF_RECORD=y +## CONFIG_NFC_NDEF_URI_MSG=y +## CONFIG_NFC_NDEF_URI_REC=y +## CONFIG_HWINFO=y + +# +#EVERYTHING ELSE +# + +CONFIG_RING_BUFFER=y + +CONFIG_ACCELEROMETER=n +CONFIG_ENABLE_BUTTON=n +CONFIG_ENABLE_SPEAKER=n +CONFIG_ENABLE_LED=y + +CONFIG_PM_DEVICE=y +# CONFIG_NRFX_USBD=y + +# CONFIG_FLASH=y diff --git a/Friend/firmware/firmware_v1.0/prj_xiao_ble_sense_devkitv2-adafruit.conf b/Friend/firmware/firmware_v1.0/prj_xiao_ble_sense_devkitv2-adafruit.conf index 936ec8e7d..6baec4e8d 100644 --- a/Friend/firmware/firmware_v1.0/prj_xiao_ble_sense_devkitv2-adafruit.conf +++ b/Friend/firmware/firmware_v1.0/prj_xiao_ble_sense_devkitv2-adafruit.conf @@ -186,6 +186,7 @@ CONFIG_RING_BUFFER=y CONFIG_ACCELEROMETER=y CONFIG_ENABLE_BUTTON=y CONFIG_ENABLE_SPEAKER=y +CONFIG_ENABLE_LED=n CONFIG_PM_DEVICE=y # CONFIG_NRFX_USBD=y diff --git a/Friend/firmware/firmware_v1.0/src/led.h b/Friend/firmware/firmware_v1.0/src/led.h index 68b1058cd..56ce526f9 100644 --- a/Friend/firmware/firmware_v1.0/src/led.h +++ b/Friend/firmware/firmware_v1.0/src/led.h @@ -20,4 +20,4 @@ void set_led_red(bool on); void set_led_green(bool on); void set_led_blue(bool on); -#endif \ No newline at end of file +#endif diff --git a/Friend/firmware/firmware_v1.0/src/main.c b/Friend/firmware/firmware_v1.0/src/main.c index 8876869c9..f043bbd5e 100644 --- a/Friend/firmware/firmware_v1.0/src/main.c +++ b/Friend/firmware/firmware_v1.0/src/main.c @@ -1,301 +1,11 @@ -#include +#include #include -#include "transport.h" -#include "mic.h" -#include "utils.h" -#include "led.h" -#include "config.h" -#include "codec.h" -#include "button.h" -// #include "nfc.h" -#include "sdcard.h" -#include "storage.h" -#include "speaker.h" -#include "usb.h" -#define BOOT_BLINK_DURATION_MS 600 -#define BOOT_PAUSE_DURATION_MS 200 -#define VBUS_DETECT (1U << 20) -#define WAKEUP_DETECT (1U << 16) -LOG_MODULE_REGISTER(main, CONFIG_LOG_DEFAULT_LEVEL); -static void codec_handler(uint8_t *data, size_t len) -{ - int err = broadcast_audio_packets(data, len); - if (err) - { - LOG_ERR("Failed to broadcast audio packets: %d", err); - } -} - -static void mic_handler(int16_t *buffer) -{ - int err = codec_receive_pcm(buffer, MIC_BUFFER_SAMPLES); - if (err) - { - LOG_ERR("Failed to process PCM data: %d", err); - } -} - -void bt_ctlr_assert_handle(char *name, int type) -{ - LOG_INF("Bluetooth assert: %s (type %d)", name ? name : "NULL", type); -} - - - -bool is_connected = false; -bool is_charging = false; -extern bool is_off; -extern bool usb_charge; -static void boot_led_sequence(void) -{ - // Red blink - set_led_red(true); - k_msleep(BOOT_BLINK_DURATION_MS); - set_led_red(false); - k_msleep(BOOT_PAUSE_DURATION_MS); - // Green blink - set_led_green(true); - k_msleep(BOOT_BLINK_DURATION_MS); - set_led_green(false); - k_msleep(BOOT_PAUSE_DURATION_MS); - // Blue blink - set_led_blue(true); - k_msleep(BOOT_BLINK_DURATION_MS); - set_led_blue(false); - k_msleep(BOOT_PAUSE_DURATION_MS); - // All LEDs on - set_led_red(true); - set_led_green(true); - set_led_blue(true); - k_msleep(BOOT_BLINK_DURATION_MS); - // All LEDs off - set_led_red(false); - set_led_green(false); - set_led_blue(false); -} -void activate_everything_no_lights() -{ - int err; - - err = led_start(); - err = transport_start(); - err = mount_sd_card(); - err = storage_init(); - err = init_haptic_pin(); - set_codec_callback(codec_handler); - err = codec_start(); - set_mic_callback(mic_handler); - err = mic_start(); - err = init_usb(); - -} - -void set_led_state() -{ - // Recording and connected state - BLUE - - if(usb_charge) - { - is_charging = !is_charging; - if(is_charging) - { - set_led_green(true); - } - else - { - set_led_green(false); - } - } - else - { - set_led_green(false); - } - if(is_off) - { - set_led_red(false); - set_led_blue(false); - return; - } - if (is_connected) - { - set_led_blue(true); - set_led_red(false); - return; - } - - // Recording but lost connection - RED - if (!is_connected) - { - set_led_red(true); - set_led_blue(false); - return; - } - -} -bool from_wakeup = false; - -// Main loop int main(void) { - int err; - // TODO: what does it mean ? disabled from_usb_event for now - // for system power off, we have no choice but to handle usb detect wakeup events. if off, and this was the reason, initialize, skip lightshow, start not recording - uint32_t reset_reas = NRF_POWER->RESETREAS; - NRF_POWER->DCDCEN=1; - NRF_POWER->DCDCEN0=1; - - NRF_POWER->RESETREAS=1; - // bool from_usb_event = (reset_reas & VBUS_DETECT); - bool from_wakeup = (reset_reas & WAKEUP_DETECT); - // if (from_usb_event) - // { - // k_msleep(100); - // printf("from reset \n"); - // is_off = true; - - // // usb_charge = true; - // activate_everything_no_lights(); - // // bt_disable(); - // bt_off(); - // } - //else if (from_wakeup) - if (from_wakeup) - { - - is_off = false; - usb_charge = false; - force_button_state(GRACE); - k_msleep(1000); - activate_everything_no_lights(); - bt_on(); - play_haptic_milli(100); - - } - else - { - - LOG_INF("Friend device firmware starting..."); - err = led_start(); - if (err) - { - LOG_ERR("Failed to initialize LEDs: %d", err); - return err; - } - // Run the boot LED sequence - boot_led_sequence(); - // Indicate transport initialization - set_led_green(true); - set_led_green(false); - - err = transport_start(); - if (err) - { - LOG_ERR("Failed to start transport: %d", err); - // Blink green LED to indicate error - for (int i = 0; i < 5; i++) - { - set_led_green(!gpio_pin_get_dt(&led_green)); - k_msleep(200); - } - set_led_green(false); - // return err; - } - play_boot_sound(); - err = mount_sd_card(); - if (err) - { - LOG_ERR("Failed to mount SD card: %d", err); - } - LOG_INF("result of mount:%d",err); - - k_msleep(500); - err = storage_init(); - if (err) - { - LOG_ERR("Failed to initialize storage: %d", err); - } - err = init_haptic_pin(); - if (err) - { - LOG_ERR("Failed to initialize haptic pin: %d", err); - } - - set_led_blue(true); - set_codec_callback(codec_handler); - err = codec_start(); - if (err) - { - LOG_ERR("Failed to start codec: %d", err); - // Blink blue LED to indicate error - for (int i = 0; i < 5; i++) - { - set_led_blue(!gpio_pin_get_dt(&led_blue)); - k_msleep(200); - } - set_led_blue(false); - return err; - } - play_haptic_milli(500); - set_led_blue(false); - - // Indicate microphone initialization - set_led_red(true); - set_led_green(true); - LOG_INF("Starting microphone initialization"); - set_mic_callback(mic_handler); - err = mic_start(); - if (err) - { - LOG_ERR("Failed to start microphone: %d", err); - // Blink red and green LEDs to indicate error - for (int i = 0; i < 5; i++) - { - set_led_red(!gpio_pin_get_dt(&led_red)); - set_led_green(!gpio_pin_get_dt(&led_green)); - k_msleep(200); - } - set_led_red(false); - set_led_green(false); - return err; - } - set_led_red(false); - set_led_green(false); - - // save_offset(200); - // // Initialize NFC first - // LOG_INF("Initializing NFC..."); - // err = nfc_init(); - // if (err != 0) { - // LOG_ERR("Failed to initialize NFC: %d", err); - // // Consider whether to continue or return based on the severity of the error - // } else { - // LOG_INF("NFC initialized successfully"); - // } - - // Indicate successful initialization - err = init_usb(); - if (err) - { - LOG_ERR("Failed to initialize power supply: %d", err); - } - - // button_init(); - // register_button_service(); - // activate_button_work(); - - - LOG_INF("Omi firmware initialized successfully\n"); - set_led_blue(true); - k_msleep(1000); - set_led_blue(false); - - } - - printf("reset reas:%d\n",reset_reas); while (1) { - set_led_state(); + printk("hello - 04\n"); k_msleep(500); } diff --git a/Friend/firmware/firmware_v1.0/src/mic.c b/Friend/firmware/firmware_v1.0/src/mic.c index 73ef80ccf..540d1c75a 100644 --- a/Friend/firmware/firmware_v1.0/src/mic.c +++ b/Friend/firmware/firmware_v1.0/src/mic.c @@ -34,16 +34,16 @@ static void pdm_irq_handler(nrfx_pdm_evt_t const *event) if (event->buffer_requested) { LOG_DBG("Audio buffer requested"); - if (_next_buffer_index == 0) - { - nrfx_pdm_buffer_set(_buffer_0, MIC_BUFFER_SAMPLES); - _next_buffer_index = 1; - } - else - { - nrfx_pdm_buffer_set(_buffer_1, MIC_BUFFER_SAMPLES); - _next_buffer_index = 0; - } + // if (_next_buffer_index == 0) + // { + // nrfx_pdm_buffer_set(_buffer_0, MIC_BUFFER_SAMPLES); + // _next_buffer_index = 1; + // } + // else + // { + // nrfx_pdm_buffer_set(_buffer_1, MIC_BUFFER_SAMPLES); + // _next_buffer_index = 0; + // } } // Release buffer @@ -75,23 +75,23 @@ int mic_start() pdm_config.mode = NRF_PDM_MODE_MONO; pdm_config.edge = NRF_PDM_EDGE_LEFTFALLING; pdm_config.ratio = NRF_PDM_RATIO_80X; - IRQ_DIRECT_CONNECT(PDM_IRQn, 5, nrfx_pdm_irq_handler, 0); // IMPORTANT! - if (nrfx_pdm_init(&pdm_config, pdm_irq_handler) != NRFX_SUCCESS) - { - LOG_ERR("Audio unable to initialize PDM"); - return -1; - } + //IRQ_DIRECT_CONNECT(PDM_IRQn, 5, nrfx_pdm_irq_handler, 0); // IMPORTANT! + //if (nrfx_pdm_init(&pdm_config, pdm_irq_handler) != NRFX_SUCCESS) + //{ + // LOG_ERR("Audio unable to initialize PDM"); + // return -1; + //} // Power on Mic nrfy_gpio_cfg_output(PDM_PWR_PIN); nrfy_gpio_pin_set(PDM_PWR_PIN); // Start PDM - if (nrfx_pdm_start() != NRFX_SUCCESS) - { - LOG_ERR("Audio unable to start PDM"); - return -1; - } + //if (nrfx_pdm_start() != NRFX_SUCCESS) + //{ + // LOG_ERR("Audio unable to start PDM"); + // return -1; + //} LOG_INF("Audio microphone started"); return 0; diff --git a/Friend/firmware/firmware_v1.0/src/transport.c b/Friend/firmware/firmware_v1.0/src/transport.c index 67291a3e5..3a9ea35f3 100644 --- a/Friend/firmware/firmware_v1.0/src/transport.c +++ b/Friend/firmware/firmware_v1.0/src/transport.c @@ -13,12 +13,11 @@ #include "transport.h" #include "config.h" #include "utils.h" -// #include "nfc.h" -#include "speaker.h" -#include "sdcard.h" -#include "storage.h" -#include "button.h" -#include "mic.h" +//#include "speaker.h" +//#include "sdcard.h" +//#include "storage.h" +//#include "button.h" +//#include "mic.h" #include "lib/battery/battery.h" // #include "friend.h" LOG_MODULE_REGISTER(transport, CONFIG_LOG_DEFAULT_LEVEL); @@ -159,6 +158,7 @@ static void accel_ccc_config_changed_handler(const struct bt_gatt_attr *attr, ui LOG_ERR("Invalid CCC value: %u", value); } } + int accel_start() { struct sensor_value odr_attr; @@ -177,8 +177,6 @@ int accel_start() odr_attr.val1 = 10; odr_attr.val2 = 0; - - if (gpio_is_ready_dt(&accel_gpio_pin)) { printk("Speaker Pin ready\n"); @@ -861,7 +859,6 @@ int broadcast_audio_packets(uint8_t *buffer, size_t size) return 0; } - void accel_off() { gpio_pin_set_dt(&accel_gpio_pin, 0);