Skip to content

Commit

Permalink
Firmware: KConfig feature control and cleanup (#1695)
Browse files Browse the repository at this point in the history
Better KConfig feature control. Also, enabling features in source code
based on .conf to restore support for DK1, and enable other hw
configurations. (@beastoin - stole some of the main.c code from
iamdk_o3_firmware branch)
  • Loading branch information
beastoin authored Jan 15, 2025
2 parents d67527b + 0153799 commit a5e7f80
Show file tree
Hide file tree
Showing 8 changed files with 185 additions and 58 deletions.
2 changes: 1 addition & 1 deletion Friend/firmware/firmware_v1.0/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ target_sources(app PRIVATE
# src/nfc.c future release
)

target_sources_ifdef(CONFIG_CODEC_OPUS app PRIVATE
target_sources_ifdef(CONFIG_OMI_CODEC_OPUS app PRIVATE
src/lib/opus-1.2.1/A2NLSF.c
src/lib/opus-1.2.1/CNG.c
src/lib/opus-1.2.1/HP_variable_cutoff.c
Expand Down
60 changes: 49 additions & 11 deletions Friend/firmware/firmware_v1.0/Kconfig
Original file line number Diff line number Diff line change
@@ -1,20 +1,58 @@
source "Kconfig.zephyr"

menu "Friend Configuration"
config CODEC_OPUS
bool "Opus Audio Codec Support"
menu "Omi Features Configuration"

config OMI_CODEC_OPUS
bool "Opus Audio Codec"
help
"Enable the Opus audio codec support."
default n

config OFFLINE_STORAGE
bool "Offline SD Card Storage Support"
config OMI_ENABLE_OFFLINE_STORAGE
bool "Offline SD Card Storage"
select DISK_ACCESS
select FILE_SYSTEM
select FAT_FILESYSTEM_ELM
select FS_FATFS_MOUNT_MKFS
select FS_FATFS_EXFAT
help
"Enable the offline storage support. Requires a SD Card."
default n
config ACCELEROMETER

config OMI_ENABLE_ACCELEROMETER
bool "Accelerometer Support"
help
"Enable the accelerometer support."
default n

config OMI_ENABLE_BUTTON
bool "Button support"
help
"Enable the software button support."
default n

config OMI_ENABLE_SPEAKER
bool "Enable the speaker"
help
"Enable the speaker support."
default n
config ENABLE_BUTTON
bool "Button support on Devkit2"

config OMI_ENABLE_BATTERY
bool "Enable the battery"
help
"Enable the battery support."
default n

config OMI_ENABLE_USB
bool "Enable the usb"
help
"Enable the USB power check support."
default n
config ENABLE_SPEAKER
bool "Enable the speaker!!"
default n

config OMI_ENABLE_HAPTIC
bool "Enable the haptic"
help
"Enable the haptic support."
default n

endmenu
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ CONFIG_LOG_DEFAULT_LEVEL=3
# CONFIG_SEGGER_RTT_BUFFER_SIZE_UP=2048
# CONFIG_RTT_CONSOLE=y
# CONFIG_LOG_BACKEND_RTT=y
CONFIG_CODEC_OPUS=y
CONFIG_OMI_CODEC_OPUS=y

# SD Card Support
CONFIG_OFFLINE_STORAGE=y
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,4 +104,4 @@ CONFIG_SENSOR=y
# CONFIG_SEGGER_RTT_BUFFER_SIZE_UP=2048
# CONFIG_RTT_CONSOLE=y
# CONFIG_LOG_BACKEND_RTT=y
CONFIG_CODEC_OPUS=y
CONFIG_OMI_CODEC_OPUS=y
Original file line number Diff line number Diff line change
Expand Up @@ -133,16 +133,10 @@ CONFIG_PRINTK=y
# 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
Expand Down Expand Up @@ -194,11 +188,20 @@ CONFIG_SPI_NRFX=y

CONFIG_RING_BUFFER=y

CONFIG_ACCELEROMETER=y
CONFIG_ENABLE_BUTTON=y
CONFIG_ENABLE_SPEAKER=y

CONFIG_PM_DEVICE=y
# CONFIG_NRFX_USBD=y

# CONFIG_FLASH=y

#
# Omi features configuration
#

CONFIG_OMI_CODEC_OPUS=y
CONFIG_OMI_ENABLE_OFFLINE_STORAGE=y
CONFIG_OMI_ENABLE_ACCELEROMETER=y
CONFIG_OMI_ENABLE_BUTTON=y
CONFIG_OMI_ENABLE_SPEAKER=y
CONFIG_OMI_ENABLE_BATTERY=y
CONFIG_OMI_ENABLE_USB=y
CONFIG_OMI_ENABLE_HAPTIC=y
4 changes: 4 additions & 0 deletions Friend/firmware/firmware_v1.0/src/config.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@
#define PDM_PWR_PIN NRF_GPIO_PIN_MAP(1, 10)

// Codecs
#ifdef CONFIG_OMI_CODEC_OPUS
#define CODEC_OPUS 1
#else
#error "Enable CONFIG_OMI_CODEC_OPUS in the project .conf file"
#endif

#if CODEC_OPUS
#define CODEC_PACKAGE_SAMPLES 160
Expand Down
145 changes: 112 additions & 33 deletions Friend/firmware/firmware_v1.0/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -140,48 +140,76 @@ int main(void)
err = led_start();
if (err)
{
LOG_ERR("Failed to initialize LEDs: %d", err);
LOG_ERR("Failed to initialize LEDs (err %d)", err);
return err;
}

// Run the boot LED sequence
boot_led_sequence();

// Indicate transport initialization
LOG_PRINTK("\n");
LOG_INF("Initializing transport...\n");
// Enable battery
#ifdef CONFIG_OMI_ENABLE_BATTERY
err = battery_init();
if (err)
{
LOG_ERR("Battery init failed (err %d)", err);
return err;
}

set_led_green(true);
set_led_green(false);
err == battery_charge_start();
if (err)
{
LOG_ERR("Battery failed to start (err %d)", err);
return err;
}
LOG_INF("Battery initialized");
#endif

err = transport_start();

// Enable button
#ifdef CONFIG_OMI_ENABLE_BUTTON
err = button_init();
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;
LOG_ERR("Failed to initialize Button (err %d)", err);
return err;
}
LOG_INF("Button initialized");
activate_button_work();
#endif

LOG_PRINTK("\n");
LOG_INF("Play boot sound...\n");
// Enable accelerometer
#ifdef CONFIG_OMI_ENABLE_ACCELEROMETER
err = accel_start();
if (err)
{
LOG_ERR("Accelerometer failed to activated (err %d)", err);
return err;
}
LOG_INF("Accelerometer initialized");
#endif

// This messes up the UART console, so commented out
// if console logs are enabled
play_boot_sound();
// Enable speaker
#ifdef CONFIG_OMI_ENABLE_SPEAKER
err = speaker_init();
if (err)
{
LOG_ERR("Speaker failed to start");
return err;
}
LOG_INF("Speaker initialized");
#endif

// Enable sdcard
#ifdef CONFIG_OMI_ENABLE_OFFLINE_STORAGE
LOG_PRINTK("\n");
LOG_INF("Mount SD card...\n");

err = mount_sd_card();
if (err)
{
LOG_ERR("Failed to mount SD card: %d", err);
LOG_ERR("Failed to mount SD card (err %d)", err);
return err;
}

k_msleep(500);
Expand All @@ -192,23 +220,81 @@ int main(void)
err = storage_init();
if (err)
{
LOG_ERR("Failed to initialize storage: %d", err);
LOG_ERR("Failed to initialize storage (err %d)", err);
}
#endif

// Enable haptic
#ifdef CONFIG_OMI_ENABLE_HAPTIC
LOG_PRINTK("\n");
LOG_INF("Initializing haptic...\n");

err = init_haptic_pin();
if (err)
{
LOG_ERR("Failed to initialize haptic pin: %d", err);
LOG_ERR("Failed to initialize haptic pin (err %d)", err);
return err;
}
LOG_INF("Haptic pin initialized");
#endif

// Enable usb
#ifdef CONFIG_ENABLE_USB
LOG_PRINTK("\n");
LOG_INF("Initializing power supply check...\n");

err = init_usb();
if (err)
{
LOG_ERR("Failed to initialize power supply (err %d)", err);
return err;
}
#endif

// Indicate transport initialization
LOG_PRINTK("\n");
LOG_INF("Initializing transport...\n");

set_led_green(true);
set_led_green(false);

// Start transport
int transportErr;
transportErr = transport_start();
if (transportErr)
{
LOG_ERR("Failed to start transport (err %d)", transportErr);
// TODO: Detect the current core is app core or net core
// // 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;
return transportErr;
}

#ifdef CONFIG_OMI_ENABLE_SPEAKER
#ifndef CONFIG_UART_CONSOLE
LOG_PRINTK("\n");
LOG_INF("Play boot sound...\n");

// This messes up the UART console, so comment out
// if console logs are enabled
play_boot_sound();
#else
LOG_INF("UART console enabled, not playing boot sound");
#endif
#endif

LOG_PRINTK("\n");
LOG_INF("Initializing codec...\n");

set_led_blue(true);

// Audio codec(opus) callback
set_codec_callback(codec_handler);
err = codec_start();
if (err)
Expand All @@ -224,7 +310,9 @@ int main(void)
return err;
}

#ifdef CONFIG_OMI_ENABLE_HAPTIC
play_haptic_milli(500);
#endif
set_led_blue(false);

// Indicate microphone initialization
Expand Down Expand Up @@ -254,15 +342,6 @@ int main(void)
set_led_red(false);
set_led_green(false);

LOG_PRINTK("\n");
LOG_INF("Initializing power supply check...\n");

err = init_usb();
if (err)
{
LOG_ERR("Failed to initialize power supply: %d", err);
}

// Indicate successful initialization
LOG_PRINTK("\n");
LOG_INF("Device initialized successfully\n");
Expand Down
5 changes: 4 additions & 1 deletion Friend/firmware/firmware_v1.0/src/usb.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,14 @@ usb_dc_status_callback udc_status_cb(enum usb_dc_status_code status,

int init_usb()
{
#ifndef CONFIG_UART_CONSOLE
usb_disable();
int ret = usb_enable(udc_status_cb);
LOG_INF("USB ret: %d\n", ret);
#else
// Use this instead of the disable/enable lines above
// as USB disabling messes up the UART logging
// usb_dc_set_status_callback(udc_status_cb);
usb_dc_set_status_callback(udc_status_cb);
#endif
return 0;
}

0 comments on commit a5e7f80

Please sign in to comment.