Загрузка данных


#include <zephyr/drivers/i2s.h>
#include <zephyr/audio/codec.h>
#include <errno.h>

typedef enum {
    AUDIO_PATH_0 = 0,  // SAI3 (i2s0) + WM8960
    AUDIO_PATH_1 = 1   // SAI2 (i2s1) + SGTL5000
} audio_path_t;

// Глобальная переменная текущего пути
static volatile uint8_t current_audio_path = AUDIO_PATH_0;

// Изменяемые runtime-указатели на устройства
static const struct device *i2s_dev_rx = NULL;
static const struct device *i2s_dev_tx = NULL;
static const struct device *codec_dev  = NULL;

// Внутренний хелпер для рантайм-получения девайсов из дерева устройств
static void update_device_pointers(uint8_t path)
{
    if (path == AUDIO_PATH_1) {
        i2s_dev_rx = DEVICE_DT_GET(DT_NODELABEL(i2s1_rx));
        i2s_dev_tx = DEVICE_DT_GET(DT_NODELABEL(i2s1_tx));
        codec_dev  = DEVICE_DT_GET(DT_NODELABEL(rx_audio_codec));
        current_audio_path = AUDIO_PATH_1;
    } else {
        i2s_dev_rx = DEVICE_DT_GET(DT_NODELABEL(i2s0_rx));
        i2s_dev_tx = DEVICE_DT_GET(DT_NODELABEL(i2s0_tx));
        codec_dev  = DEVICE_DT_GET(DT_NODELABEL(audio_codec));
        current_audio_path = AUDIO_PATH_0;
    }
}