I2S driver implementation (#480)

* **New Features**
  * ESP32 I2S controller support: runtime-configurable digital audio I/O with read/write/set/get operations and multiple formats.

* **Board Support**
  * LilyGO T-Deck device tree entry added to enable I2S peripheral pin configuration.

* **Documentation**
  * New/updated bindings and descriptors for I2S, I2C, GPIO, and root nodes.

* **Other**
  * Added GPIO "no pin" sentinel and exposed I2S controller API symbols.
This commit is contained in:
Ken Van Hoeylandt
2026-02-04 23:40:16 +01:00
committed by GitHub
parent 9a672a30ff
commit a1c835e073
18 changed files with 526 additions and 5 deletions
@@ -1,3 +1,4 @@
description: GPIO controller
properties:
gpio-count:
type: int
+1 -1
View File
@@ -1 +1 @@
bus: i2c
description: I2C controller
+1 -1
View File
@@ -1,4 +1,4 @@
on-bus: i2c
description: I2C device
properties:
register:
@@ -0,0 +1 @@
description: I2S controller
+2
View File
@@ -1,3 +1,5 @@
description: Represents root node of a device tree. It holds all other nodes.
compatible: "root"
properties:
@@ -26,6 +26,8 @@ extern "C" {
#define GPIO_INTERRUPT_FROM_OPTIONS(options) (gpio_int_type_t)((options & GPIO_INTERRUPT_BITMASK) >> 5)
#define GPIO_INTERRUPT_TO_OPTIONS(options, interrupt) (options | (interrupt << 5))
#define GPIO_PIN_NONE -1
typedef enum {
GPIO_INTERRUPT_DISABLE = 0,
GPIO_INTERRUPT_POS_EDGE = 1,
@@ -0,0 +1,141 @@
// SPDX-License-Identifier: Apache-2.0
#pragma once
#ifdef __cplusplus
extern "C" {
#endif
#include <stdint.h>
#include <stddef.h>
#include "gpio.h"
#include <tactility/freertos/freertos.h>
#include <tactility/error.h>
/**
* @brief I2S communication format
*/
enum I2sCommunicationFormat {
I2S_FORMAT_STAND_I2S = 0x01,
I2S_FORMAT_STAND_MSB = 0x02,
I2S_FORMAT_STAND_PCM_SHORT = 0x04,
I2S_FORMAT_STAND_PCM_LONG = 0x08,
};
#define I2S_CHANNEL_NONE -1
/**
* @brief I2S Config
*/
struct I2sConfig {
enum I2sCommunicationFormat communication_format;
uint32_t sample_rate;
uint8_t bits_per_sample; // 16, 24, 32
int8_t channel_left; // I2S_CHANNEL_NONE to disable
int8_t channel_right; // I2S_CHANNEL_NONE to disable
};
/**
* @brief API for I2S controller drivers.
*/
struct I2sControllerApi {
/**
* @brief Reads data from I2S.
* @param[in] device the I2S controller device
* @param[out] data the buffer to store the read data
* @param[in] data_size the number of bytes to read
* @param[out] bytes_read the number of bytes actually read
* @param[in] timeout the maximum time to wait for the operation to complete
* @retval ERROR_NONE when the read operation was successful
* @retval ERROR_TIMEOUT when the operation timed out
*/
error_t (*read)(struct Device* device, void* data, size_t data_size, size_t* bytes_read, TickType_t timeout);
/**
* @brief Writes data to I2S.
* @param[in] device the I2S controller device
* @param[in] data the buffer containing the data to write
* @param[in] data_size the number of bytes to write
* @param[out] bytes_written the number of bytes actually written
* @param[in] timeout the maximum time to wait for the operation to complete
* @retval ERROR_NONE when the write operation was successful
* @retval ERROR_TIMEOUT when the operation timed out
*/
error_t (*write)(struct Device* device, const void* data, size_t data_size, size_t* bytes_written, TickType_t timeout);
/**
* @brief Sets the I2S configuration.
* @param[in] device the I2S controller device
* @param[in] config the new configuration
* @retval ERROR_NONE when the operation was successful
*/
error_t (*set_config)(struct Device* device, const struct I2sConfig* config);
/**
* @brief Gets the current I2S configuration.
* @param[in] device the I2S controller device
* @param[out] config the buffer to store the current configuration
* @retval ERROR_NONE when the operation was successful
*/
error_t (*get_config)(struct Device* device, struct I2sConfig* config);
/**
* @brief Resets the I2S controller. Must configure it again before it can be used.
* @param[in] device the I2S controller device
* @retval ERROR_NONE when the operation was successful
*/
error_t (*reset)(struct Device* device);
};
/**
* @brief Reads data from I2S using the specified controller.
* @param[in] device the I2S controller device
* @param[out] data the buffer to store the read data
* @param[in] data_size the number of bytes to read
* @param[out] bytes_read the number of bytes actually read
* @param[in] timeout the maximum time to wait for the operation to complete
* @retval ERROR_NONE when the read operation was successful
*/
error_t i2s_controller_read(struct Device* device, void* data, size_t data_size, size_t* bytes_read, TickType_t timeout);
/**
* @brief Writes data to I2S using the specified controller.
* @param[in] device the I2S controller device
* @param[in] data the buffer containing the data to write
* @param[in] data_size the number of bytes to write
* @param[out] bytes_written the number of bytes actually written
* @param[in] timeout the maximum time to wait for the operation to complete
* @retval ERROR_NONE when the write operation was successful
*/
error_t i2s_controller_write(struct Device* device, const void* data, size_t data_size, size_t* bytes_written, TickType_t timeout);
/**
* @brief Sets the I2S configuration using the specified controller.
* @param[in] device the I2S controller device
* @param[in] config the new configuration
* @retval ERROR_NONE when the operation was successful
*/
error_t i2s_controller_set_config(struct Device* device, const struct I2sConfig* config);
/**
* @brief Gets the current I2S configuration using the specified controller.
* @param[in] device the I2S controller device
* @param[out] config the buffer to store the current configuration
* @retval ERROR_NONE when the operation was successful
*/
error_t i2s_controller_get_config(struct Device* device, struct I2sConfig* config);
/**
* @brief Resets the I2S controller. Must configure it again before it can be used.
* @param[in] device the I2S controller device
* @retval ERROR_NONE when the operation was successful
*/
error_t i2s_controller_reset(struct Device* device);
extern const struct DeviceType I2S_CONTROLLER_TYPE;
#ifdef __cplusplus
}
#endif
@@ -32,6 +32,6 @@ error_t gpio_controller_get_pin_count(struct Device* device, uint32_t* count) {
return GPIO_DRIVER_API(driver)->get_pin_count(device, count);
}
const struct DeviceType GPIO_CONTROLLER_TYPE { 0 };
extern const struct DeviceType GPIO_CONTROLLER_TYPE { 0 };
}
@@ -49,6 +49,6 @@ error_t i2c_controller_has_device_at_address(Device* device, uint8_t address, Ti
return I2C_DRIVER_API(driver)->write(device, address, message, 2, timeout);
}
const struct DeviceType I2C_CONTROLLER_TYPE { 0 };
extern const struct DeviceType I2C_CONTROLLER_TYPE { 0 };
}
@@ -0,0 +1,37 @@
// SPDX-License-Identifier: Apache-2.0
#include <tactility/drivers/i2s_controller.h>
#include <tactility/error.h>
#include <tactility/device.h>
#define I2S_DRIVER_API(driver) ((struct I2sControllerApi*)driver->api)
extern "C" {
error_t i2s_controller_read(Device* device, void* data, size_t dataSize, size_t* bytesRead, TickType_t timeout) {
const auto* driver = device_get_driver(device);
return I2S_DRIVER_API(driver)->read(device, data, dataSize, bytesRead, timeout);
}
error_t i2s_controller_write(Device* device, const void* data, size_t dataSize, size_t* bytesWritten, TickType_t timeout) {
const auto* driver = device_get_driver(device);
return I2S_DRIVER_API(driver)->write(device, data, dataSize, bytesWritten, timeout);
}
error_t i2s_controller_set_config(Device* device, const struct I2sConfig* config) {
const auto* driver = device_get_driver(device);
return I2S_DRIVER_API(driver)->set_config(device, config);
}
error_t i2s_controller_get_config(Device* device, struct I2sConfig* config) {
const auto* driver = device_get_driver(device);
return I2S_DRIVER_API(driver)->get_config(device, config);
}
error_t i2s_controller_reset(struct Device* device) {
const auto* driver = device_get_driver(device);
return I2S_DRIVER_API(driver)->reset(device);
}
extern const struct DeviceType I2S_CONTROLLER_TYPE { 0 };
}
+10
View File
@@ -1,6 +1,7 @@
#include <tactility/device.h>
#include <tactility/driver.h>
#include <tactility/drivers/i2c_controller.h>
#include <tactility/drivers/i2s_controller.h>
#include <tactility/drivers/gpio_controller.h>
#include <tactility/concurrent/dispatcher.h>
#include <tactility/concurrent/event_group.h>
@@ -58,6 +59,7 @@ const struct ModuleSymbol KERNEL_SYMBOLS[] = {
DEFINE_MODULE_SYMBOL(gpio_controller_set_options),
DEFINE_MODULE_SYMBOL(gpio_controller_get_options),
DEFINE_MODULE_SYMBOL(gpio_controller_get_pin_count),
DEFINE_MODULE_SYMBOL(GPIO_CONTROLLER_TYPE),
// drivers/i2c_controller
DEFINE_MODULE_SYMBOL(i2c_controller_read),
DEFINE_MODULE_SYMBOL(i2c_controller_write),
@@ -66,6 +68,14 @@ const struct ModuleSymbol KERNEL_SYMBOLS[] = {
DEFINE_MODULE_SYMBOL(i2c_controller_write_register),
DEFINE_MODULE_SYMBOL(i2c_controller_write_register_array),
DEFINE_MODULE_SYMBOL(i2c_controller_has_device_at_address),
DEFINE_MODULE_SYMBOL(I2C_CONTROLLER_TYPE),
// drivers/i2s_controller
DEFINE_MODULE_SYMBOL(i2s_controller_read),
DEFINE_MODULE_SYMBOL(i2s_controller_write),
DEFINE_MODULE_SYMBOL(i2s_controller_set_config),
DEFINE_MODULE_SYMBOL(i2s_controller_get_config),
DEFINE_MODULE_SYMBOL(i2s_controller_reset),
DEFINE_MODULE_SYMBOL(I2S_CONTROLLER_TYPE),
// concurrent/dispatcher
DEFINE_MODULE_SYMBOL(dispatcher_alloc),
DEFINE_MODULE_SYMBOL(dispatcher_free),