Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main'
Browse files Browse the repository at this point in the history
  • Loading branch information
josancamon19 committed Sep 4, 2024
2 parents cbd5d1d + 0751ad2 commit 5cc2c26
Show file tree
Hide file tree
Showing 20 changed files with 844 additions and 94 deletions.
2 changes: 2 additions & 0 deletions Friend/firmware/firmware_v1.0/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@ target_sources(app PRIVATE
src/lib/battery/battery.c
src/button.c
src/speaker.c
src/sdcard.c
src/storage.c
)

target_sources_ifdef(CONFIG_CODEC_OPUS app PRIVATE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,48 +8,40 @@
&pinctrl {
i2s0_default: i2s0_default {
group1 {
psels = <NRF_PSEL(I2S_SCK_M, 0, 3)>, // SCK pin (bit clock) A3
<NRF_PSEL(I2S_LRCK_M, 0, 2)>, // LRCK pin (word select clock) A2
<NRF_PSEL(I2S_SDOUT, 0, 1)>; // SDOUT pin (data out) A1
psels = <NRF_PSEL(I2S_SCK_M, 0, 29)>, // SCK pin (bit clock) A3
<NRF_PSEL(I2S_LRCK_M, 0, 28)>, // LRCK pin (word select clock) A2
<NRF_PSEL(I2S_SDOUT, 0, 3)>; // SDOUT pin (data out) A1
};
};
};

&spi2 {
status = "okay";
pinctrl-0 = <&spi2_default>;
pinctrl-1 = <&spi2_sleep>;
pinctrl-0 = <&custom_spi>;
pinctrl-1 = <&custom_spi>;
pinctrl-names = "default", "sleep";
cs-gpios = <&gpio0 13 GPIO_ACTIVE_LOW>; // SD chip select pin (P0.13)
cs-gpios = <&gpio0 2 GPIO_ACTIVE_LOW>; // CS pin on P0.28

sdhc0: sdhc@0 {
compatible = "zephyr,mmc-spi-slot";
compatible = "zephyr,sdhc-spi-slot";
reg = <0>;
status = "okay";
label = "SDHC_0";
spi-max-frequency = <24000000>;
mmc {
compatible = "zephyr,sdmmc-disk";
status = "okay";
};
spi-max-frequency = <24000000>; // 24 MHz SPI speed for SD card
};
};

&pinctrl {
spi2_default: spi2_default {
group1 {
psels = <NRF_PSEL(SPIM_SCK, 1, 15)>, // SCK connected to P1.15
<NRF_PSEL(SPIM_MOSI, 1, 13)>, // MOSI connected to P1.13
<NRF_PSEL(SPIM_MISO, 1, 14)>; // MISO connected to P1.14
};
};

spi2_sleep: spi2_sleep {
custom_spi: custom_spi {
group1 {
psels = <NRF_PSEL(SPIM_SCK, 1, 15)>,
<NRF_PSEL(SPIM_MOSI, 1, 13)>,
<NRF_PSEL(SPIM_MISO, 1, 14)>;
low-power-enable;
psels = <NRF_PSEL(SPIM_SCK, 1, 13)>, // SCK on P1.13
<NRF_PSEL(SPIM_MOSI, 1, 15)>, // MOSI on P1.15
<NRF_PSEL(SPIM_MISO, 1, 14)>; // MISO on P1.14
};
};
};

/ {
/delete-node/ lsm6dsl@0;
};
Original file line number Diff line number Diff line change
Expand Up @@ -99,16 +99,16 @@ 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_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
# CONFIG_MAIN_STACK_SIZE=5096
CONFIG_MAIN_STACK_SIZE=5096
# CONFIG_DISK_DRIVER_SDMMC=y
# CONFIG_SPI=y
# CONFIG_HEAP_MEM_POOL_SIZE=3048
CONFIG_HEAP_MEM_POOL_SIZE=3048

# # SD Card for Arduino Audio BFF (v2 device)
# CONFIG_MMC_STACK=y
Expand All @@ -127,12 +127,12 @@ CONFIG_OFFLINE_STORAGE=y
# CONFIG_SPI_SDHC=y

# File System
CONFIG_FILE_SYSTEM=y
CONFIG_FAT_FILESYSTEM_ELM=y
CONFIG_FS_FATFS_LFN=y
CONFIG_FS_FATFS_READ_ONLY=n
CONFIG_FS_FATFS_MOUNT_MKFS=y
CONFIG_FS_FATFS_EXFAT=y
# CONFIG_FILE_SYSTEM=y
# CONFIG_FAT_FILESYSTEM_ELM=y
# CONFIG_FS_FATFS_LFN=y
# CONFIG_FS_FATFS_READ_ONLY=n
# CONFIG_FS_FATFS_MOUNT_MKFS=y
# CONFIG_FS_FATFS_EXFAT=y

# Increase stack and heap sizes
CONFIG_MAIN_STACK_SIZE=8192
Expand All @@ -144,7 +144,7 @@ CONFIG_HEAP_MEM_POOL_SIZE=4096
# CONFIG_NRFX_TWIM1=n

# Disable LSM6DSL sensor (accelerometer and gyroscope)
CONFIG_LSM6DSL=y
CONFIG_LSM6DSL=n
CONFIG_LSM6DSL_ENABLE_TEMP=n
CONFIG_LSM6DSL_TRIGGER_GLOBAL_THREAD=y
CONFIG_SENSOR=y
Expand All @@ -154,8 +154,19 @@ CONFIG_I2S_NRFX=y
CONFIG_SPI_NRFX=y

#THE ACCELEROMETER
CONFIG_ACCELEROMETER=y
CONFIG_ACCELEROMETER=n
#ENABLE THE BUTTON!
CONFIG_ENABLE_BUTTON=y
CONFIG_ENABLE_BUTTON=n
#ENABLE THE SPEAKER
CONFIG_ENABLE_SPEAKER=y
CONFIG_ENABLE_SPEAKER=n

# CONFIG_SD_STACK=y
CONFIG_SD_INIT_TIMEOUT=1500
CONFIG_SD_RETRY_COUNT=10
CONFIG_SD_OCR_RETRY_COUNT=1000
CONFIG_SD_CMD_TIMEOUT=300
CONFIG_SD_DATA_TIMEOUT=10000
# CONFIG_SD_BUFFER_SIZE=64
CONFIG_SD_DATA_RETRIES=3
# CONFIG_SD_UHS_PROTOCOL is not set
# CONFIG_MMC_RCA=2
13 changes: 5 additions & 8 deletions Friend/firmware/firmware_v1.0/src/button.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#include <zephyr/bluetooth/l2cap.h>
#include <zephyr/bluetooth/services/bas.h>
#include "transport.h"

#include "button.h"
LOG_MODULE_REGISTER(button, CONFIG_LOG_DEFAULT_LEVEL);

static void button_ccc_config_changed_handler(const struct bt_gatt_attr *attr, uint16_t value);
Expand Down Expand Up @@ -75,13 +75,6 @@ void check_button_level(struct k_work *work_item);

K_WORK_DELAYABLE_DEFINE(button_work, check_button_level);

typedef enum {
IDLE,
ONE_PRESS,
TWO_PRESS,
GRACE
} FSM_STATE_T;


#define DEFAULT_STATE 0
#define SINGLE_TAP 1
Expand Down Expand Up @@ -308,4 +301,8 @@ void activate_button_work() {

void register_button_service() {
bt_gatt_service_register(&button_service);
}

FSM_STATE_T get_current_button_state() {
return current_button_state;
}
11 changes: 10 additions & 1 deletion Friend/firmware/firmware_v1.0/src/button.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
#pragma once

typedef enum {
IDLE,
ONE_PRESS,
TWO_PRESS,
GRACE
} FSM_STATE_T;

int button_init();
void activate_button_work();
void register_button_service();
void register_button_service();

FSM_STATE_T get_current_button_state();
17 changes: 11 additions & 6 deletions Friend/firmware/firmware_v1.0/src/codec.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@
#include "audio.h"
#include "config.h"
#include "utils.h"
#include "sdcard.h"
#ifdef CODEC_OPUS
#include "lib/opus-1.2.1/opus.h"
#endif

// #include "sdcard.c"
LOG_MODULE_REGISTER(codec, CONFIG_LOG_DEFAULT_LEVEL);

//
Expand All @@ -27,15 +28,18 @@ void set_codec_callback(codec_callback callback)

uint8_t codec_ring_buffer_data[AUDIO_BUFFER_SAMPLES * 2]; // 2 bytes per sample
struct ring_buf codec_ring_buf;

int codec_receive_pcm(int16_t *data, size_t len)
{
int codec_receive_pcm(int16_t *data, size_t len) //this gets called after mic data is finished
{
int written = ring_buf_put(&codec_ring_buf, (uint8_t *)data, len * 2);
if (written != len * 2)
{
printk("Failed to write %d bytes to codec ring buffer\n", len * 2);

// printk("Failed to write %d bytes to codec ring buffer\n", len * 2);
return -1;
}


return 0;
}

Expand Down Expand Up @@ -63,17 +67,18 @@ static OpusEncoder *const m_opus_state = (OpusEncoder *)m_opus_encoder;

void codec_entry()
{

uint16_t output_size;
while (1)
{

// Check if we have enough data
if (ring_buf_size_get(&codec_ring_buf) < CODEC_PACKAGE_SAMPLES * 2)
{
// printk("waiting on data....\n");
k_sleep(K_MSEC(10));
continue;
}

// Read package
ring_buf_get(&codec_ring_buf, (uint8_t *)codec_input_samples, CODEC_PACKAGE_SAMPLES * 2);

Expand Down
34 changes: 12 additions & 22 deletions Friend/firmware/firmware_v1.0/src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@
#include "config.h"
#include "audio.h"
#include "codec.h"

#include "sdcard.h"
#include "storage.h"
#define BOOT_BLINK_DURATION_MS 600
#define BOOT_PAUSE_DURATION_MS 200
LOG_MODULE_REGISTER(main, CONFIG_LOG_DEFAULT_LEVEL);
Expand Down Expand Up @@ -124,25 +125,6 @@ int main(void)
}
// Run the boot LED sequence
boot_led_sequence();

// // Indicate storage initialization
// set_led_red(true);
// LOG_INF("Initializing storage...");
// err = storage_init();
// if (err) {
// LOG_ERR("Failed to initialize storage: %d", err);
// // Blink red LED to indicate error
// for (int i = 0; i < 5; i++) {
// set_led_red(!gpio_pin_get_dt(&led_red));
// k_msleep(200);
// }
// set_led_red(false);
// return err;
// }
// LOG_INF("Storage initialized successfully");
// set_led_red(false);
// test_sd_card();

// Indicate transport initialization
set_led_green(true);
err = transport_start();
Expand All @@ -158,7 +140,15 @@ int main(void)
}
set_led_green(false);

// Indicate codec initialization
err = mount_sd_card();
printk("result of mount:%d\n",err);

k_msleep(500);
storage_init();




set_led_blue(true);
set_codec_callback(codec_handler);
err = codec_start();
Expand Down Expand Up @@ -196,7 +186,7 @@ int main(void)
set_led_green(false);

// Indicate successful initialization
LOG_INF("Omi firmware initialized successfully");
LOG_INF("Omi firmware initialized successfully\n");
set_led_blue(true);
k_msleep(1000);
set_led_blue(false);
Expand Down
Loading

0 comments on commit 5cc2c26

Please sign in to comment.