Implement UI scaling and more (#501)
**New Features** * Runtime font accessors and new symbol fonts for text, launcher, statusbar, and shared icons. * Added font height base setting to device.properties * Text fonts now have 3 sizes: small, default, large **Improvements** * Renamed `UiScale` to `UiDensity` * Statusbar, toolbar and many UI components now compute heights and spacing from fonts/density. * SSD1306 initialization sequence refined for more stable startup. * Multiple image assets replaced by symbol-font rendering. * Many layout improvements related to density, font scaling and icon scaling * Updated folder name capitalization for newer style
This commit is contained in:
committed by
GitHub
parent
72c9b2b113
commit
9a11e6f47b
@@ -0,0 +1,73 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <tactility/device.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#define GPIO_FLAGS_MASK 0x1f
|
||||
|
||||
#define GPIO_PIN_NONE -1
|
||||
|
||||
#define GPIO_PIN_SPEC_NONE ((struct GpioPinSpec) { NULL, 0, GPIO_FLAG_NONE })
|
||||
|
||||
#define GPIO_FLAG_NONE 0
|
||||
#define GPIO_FLAG_ACTIVE_HIGH (0 << 0)
|
||||
#define GPIO_FLAG_ACTIVE_LOW (1 << 0)
|
||||
#define GPIO_FLAG_DIRECTION_INPUT (1 << 1)
|
||||
#define GPIO_FLAG_DIRECTION_OUTPUT (1 << 2)
|
||||
#define GPIO_FLAG_DIRECTION_INPUT_OUTPUT (GPIO_FLAG_DIRECTION_INPUT | GPIO_FLAG_DIRECTION_OUTPUT)
|
||||
#define GPIO_FLAG_PULL_UP (0 << 3)
|
||||
#define GPIO_FLAG_PULL_DOWN (1 << 4)
|
||||
#define GPIO_FLAG_INTERRUPT_BITMASK (0b111 << 5) // 3 bits to hold the values [0, 5]
|
||||
#define GPIO_FLAG_INTERRUPT_FROM_OPTIONS(options) (gpio_int_type_t)((options & GPIO_FLAG_INTERRUPT_BITMASK) >> 5)
|
||||
#define GPIO_FLAG_INTERRUPT_TO_OPTIONS(options, interrupt) (options | (interrupt << 5))
|
||||
|
||||
typedef enum {
|
||||
GPIO_INTERRUPT_DISABLE = 0,
|
||||
GPIO_INTERRUPT_POS_EDGE = 1,
|
||||
GPIO_INTERRUPT_NEG_EDGE = 2,
|
||||
GPIO_INTERRUPT_ANY_EDGE = 3,
|
||||
GPIO_INTERRUPT_LOW_LEVEL = 4,
|
||||
GPIO_INTERRUPT_HIGH_LEVEL = 5,
|
||||
GPIO_MAX,
|
||||
} GpioInterruptType;
|
||||
|
||||
enum GpioOwnerType {
|
||||
/** @brief Pin is unclaimed/free */
|
||||
GPIO_OWNER_NONE,
|
||||
/** @brief Pin is owned by a hog */
|
||||
GPIO_OWNER_HOG,
|
||||
/** @brief Pin is claimed by a regular consumer */
|
||||
GPIO_OWNER_GPIO,
|
||||
/** @brief Pin is owned by SPI. This is a special case because of CS pin transfer from hog to SPI controller. */
|
||||
GPIO_OWNER_SPI
|
||||
};
|
||||
|
||||
/** The index of a GPIO pin on a GPIO Controller */
|
||||
typedef uint8_t gpio_pin_t;
|
||||
|
||||
/** Specifies the configuration flags for a GPIO pin (or set of pins) */
|
||||
typedef uint16_t gpio_flags_t;
|
||||
|
||||
/**
|
||||
* Specifies a pin and its properties for a specific GPIO controller.
|
||||
* Used by the devicetree, drivers and application code to refer to GPIO pins and acquire them via the gpio_controller API.
|
||||
*/
|
||||
struct GpioPinSpec {
|
||||
/** GPIO device controlling the pin */
|
||||
struct Device* gpio_controller;
|
||||
/** The pin's number on the device */
|
||||
gpio_pin_t pin;
|
||||
/** The pin's configuration flags as specified in devicetree */
|
||||
gpio_flags_t flags;
|
||||
};
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,148 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include "gpio.h"
|
||||
#include <tactility/error.h>
|
||||
|
||||
struct Device;
|
||||
struct GpioDescriptor;
|
||||
|
||||
struct GpioControllerApi {
|
||||
/**
|
||||
* @brief Sets the logical level of a GPIO pin.
|
||||
* @param[in,out] descriptor the pin descriptor
|
||||
* @param[in] high true to set the pin high, false to set it low
|
||||
* @return ERROR_NONE if successful
|
||||
*/
|
||||
error_t (*set_level)(struct GpioDescriptor* descriptor, bool high);
|
||||
|
||||
/**
|
||||
* @brief Gets the logical level of a GPIO pin.
|
||||
* @param[in] descriptor the pin descriptor
|
||||
* @param[out] high pointer to store the pin level
|
||||
* @return ERROR_NONE if successful
|
||||
*/
|
||||
error_t (*get_level)(struct GpioDescriptor* descriptor, bool* high);
|
||||
|
||||
/**
|
||||
* @brief Configures the options for a GPIO pin.
|
||||
* @param[in,out] descriptor the pin descriptor
|
||||
* @param[in] flags configuration flags (direction, pull-up/down, etc.)
|
||||
* @return ERROR_NONE if successful
|
||||
*/
|
||||
error_t (*set_flags)(struct GpioDescriptor* descriptor, gpio_flags_t flags);
|
||||
|
||||
/**
|
||||
* @brief Gets the configuration options for a GPIO pin.
|
||||
* @param[in] descriptor the pin descriptor
|
||||
* @param[out] flags pointer to store the configuration flags
|
||||
* @return ERROR_NONE if successful
|
||||
*/
|
||||
error_t (*get_flags)(struct GpioDescriptor* descriptor, gpio_flags_t* flags);
|
||||
|
||||
/**
|
||||
* @brief Gets the native pin number associated with a descriptor.
|
||||
* @param[in] descriptor the pin descriptor
|
||||
* @param[out] pin_number pointer to store the pin number
|
||||
* @return ERROR_NONE if successful
|
||||
*/
|
||||
error_t (*get_native_pin_number)(struct GpioDescriptor* descriptor, void* pin_number);
|
||||
};
|
||||
|
||||
struct GpioDescriptor* gpio_descriptor_acquire(
|
||||
struct Device* controller,
|
||||
gpio_pin_t pin_number,
|
||||
enum GpioOwnerType owner
|
||||
);
|
||||
|
||||
error_t gpio_descriptor_release(struct GpioDescriptor* descriptor);
|
||||
|
||||
/**
|
||||
* @brief Gets the pin number associated with a descriptor.
|
||||
* @param[in] descriptor the pin descriptor
|
||||
* @param[out] pin pointer to store the pin number
|
||||
* @return ERROR_NONE if successful
|
||||
*/
|
||||
error_t gpio_descriptor_get_pin_number(struct GpioDescriptor* descriptor, gpio_pin_t* pin);
|
||||
|
||||
/**
|
||||
* @brief Gets the pin owner type associated with a descriptor.
|
||||
* @param[in] descriptor the pin descriptor
|
||||
* @param[out] owner_type pointer to output owner type
|
||||
* @return ERROR_NONE if successful
|
||||
*/
|
||||
error_t gpio_descriptor_get_owner_type(struct GpioDescriptor* descriptor, enum GpioOwnerType* owner_type);
|
||||
|
||||
/**
|
||||
* @brief Sets the logical level of a GPIO pin.
|
||||
* @param[in] descriptor the pin descriptor
|
||||
* @param[in] high true to set the pin high, false to set it low
|
||||
* @return ERROR_NONE if successful
|
||||
*/
|
||||
error_t gpio_descriptor_set_level(struct GpioDescriptor* descriptor, bool high);
|
||||
|
||||
/**
|
||||
* @brief Gets the logical level of a GPIO pin.
|
||||
* @param[in] descriptor the pin descriptor
|
||||
* @param[out] high pointer to store the pin level
|
||||
* @return ERROR_NONE if successful
|
||||
*/
|
||||
error_t gpio_descriptor_get_level(struct GpioDescriptor* descriptor, bool* high);
|
||||
|
||||
/**
|
||||
* @brief Configures the options for a GPIO pin.
|
||||
* @param[in] descriptor the pin descriptor
|
||||
* @param[in] flags configuration flags (direction, pull-up/down, etc.)
|
||||
* @return ERROR_NONE if successful
|
||||
*/
|
||||
error_t gpio_descriptor_set_flags(struct GpioDescriptor* descriptor, gpio_flags_t flags);
|
||||
|
||||
/**
|
||||
* @brief Gets the configuration options for a GPIO pin.
|
||||
* @param[in] descriptor the pin descriptor
|
||||
* @param[out] flags pointer to store the configuration flags
|
||||
* @return ERROR_NONE if successful
|
||||
*/
|
||||
error_t gpio_descriptor_get_flags(struct GpioDescriptor* descriptor, gpio_flags_t* flags);
|
||||
|
||||
/**
|
||||
* @brief Gets the native pin number associated with a descriptor.
|
||||
* @param[in] descriptor the pin descriptor
|
||||
* @param[out] pin_number pointer to store the pin number
|
||||
* @return ERROR_NONE if successful
|
||||
*/
|
||||
error_t gpio_descriptor_get_native_pin_number(struct GpioDescriptor* descriptor, void* pin_number);
|
||||
|
||||
/**
|
||||
* @brief Gets the number of pins supported by the controller.
|
||||
* @param[in] device the GPIO controller device
|
||||
* @param[out] count pointer to store the number of pins
|
||||
* @return ERROR_NONE if successful
|
||||
*/
|
||||
error_t gpio_controller_get_pin_count(struct Device* device, uint32_t* count);
|
||||
|
||||
/**
|
||||
* @brief Initializes GPIO descriptors for a controller.
|
||||
* @param[in,out] device the GPIO controller device
|
||||
* @param[in] controller_context pointer to store in the controller's internal data
|
||||
* @return ERROR_NONE if successful
|
||||
*/
|
||||
error_t gpio_controller_init_descriptors(struct Device* device, uint32_t pin_count, void* controller_context);
|
||||
|
||||
/**
|
||||
* @brief Deinitializes GPIO descriptors for a controller.
|
||||
* @param[in,out] device the GPIO controller device
|
||||
* @return ERROR_NONE if successful
|
||||
*/
|
||||
error_t gpio_controller_deinit_descriptors(struct Device* device);
|
||||
|
||||
extern const struct DeviceType GPIO_CONTROLLER_TYPE;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,16 @@
|
||||
#pragma once
|
||||
|
||||
#include "gpio.h"
|
||||
|
||||
struct Device;
|
||||
|
||||
struct GpioDescriptor {
|
||||
/** @brief The controller that owns this pin */
|
||||
struct Device* controller;
|
||||
/** @brief Physical pin number */
|
||||
gpio_pin_t pin;
|
||||
/** @brief Current owner */
|
||||
enum GpioOwnerType owner_type;
|
||||
/** @brief Implementation-specific context (e.g. from esp32 controller internally) */
|
||||
void* controller_context;
|
||||
};
|
||||
@@ -0,0 +1,170 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#include "gpio.h"
|
||||
|
||||
#include <tactility/freertos/freertos.h>
|
||||
#include <tactility/error.h>
|
||||
|
||||
struct Device;
|
||||
|
||||
/**
|
||||
* @brief API for I2C controller drivers.
|
||||
*/
|
||||
struct I2cControllerApi {
|
||||
/**
|
||||
* @brief Reads data from an I2C device.
|
||||
* @param[in] device the I2C controller device
|
||||
* @param[in] address the 7-bit I2C address of the slave device
|
||||
* @param[out] data the buffer to store the read data
|
||||
* @param[in] dataSize the number of bytes to 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, uint8_t address, uint8_t* data, size_t dataSize, TickType_t timeout);
|
||||
|
||||
/**
|
||||
* @brief Writes data to an I2C device.
|
||||
* @param[in] device the I2C controller device
|
||||
* @param[in] address the 7-bit I2C address of the slave device
|
||||
* @param[in] data the buffer containing the data to write
|
||||
* @param[in] dataSize the number of bytes to write
|
||||
* @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, uint8_t address, const uint8_t* data, uint16_t dataSize, TickType_t timeout);
|
||||
|
||||
/**
|
||||
* @brief Writes data to then reads data from an I2C device.
|
||||
* @param[in] device the I2C controller device
|
||||
* @param[in] address the 7-bit I2C address of the slave device
|
||||
* @param[in] writeData the buffer containing the data to write
|
||||
* @param[in] writeDataSize the number of bytes to write
|
||||
* @param[out] readData the buffer to store the read data
|
||||
* @param[in] readDataSize the number of bytes to read
|
||||
* @param[in] timeout the maximum time to wait for the operation to complete
|
||||
* @retval ERROR_NONE when the operation was successful
|
||||
* @retval ERROR_TIMEOUT when the operation timed out
|
||||
*/
|
||||
error_t (*write_read)(struct Device* device, uint8_t address, const uint8_t* writeData, size_t writeDataSize, uint8_t* readData, size_t readDataSize, TickType_t timeout);
|
||||
|
||||
/**
|
||||
* @brief Reads data from a register of an I2C device.
|
||||
* @param[in] device the I2C controller device
|
||||
* @param[in] address the 7-bit I2C address of the slave device
|
||||
* @param[in] reg the register address to read from
|
||||
* @param[out] data the buffer to store the read data
|
||||
* @param[in] dataSize the number of bytes to 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_register)(struct Device* device, uint8_t address, uint8_t reg, uint8_t* data, size_t dataSize, TickType_t timeout);
|
||||
|
||||
/**
|
||||
* @brief Writes data to a register of an I2C device.
|
||||
* @param[in] device the I2C controller device
|
||||
* @param[in] address the 7-bit I2C address of the slave device
|
||||
* @param[in] reg the register address to write to
|
||||
* @param[in] data the buffer containing the data to write
|
||||
* @param[in] dataSize the number of bytes to write
|
||||
* @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_register)(struct Device* device, uint8_t address, uint8_t reg, const uint8_t* data, uint16_t dataSize, TickType_t timeout);
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Reads data from an I2C device using the specified controller.
|
||||
* @param[in] device the I2C controller device
|
||||
* @param[in] address the 7-bit I2C address of the slave device
|
||||
* @param[out] data the buffer to store the read data
|
||||
* @param[in] dataSize the number of bytes to 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 i2c_controller_read(struct Device* device, uint8_t address, uint8_t* data, size_t dataSize, TickType_t timeout);
|
||||
|
||||
/**
|
||||
* @brief Writes data to an I2C device using the specified controller.
|
||||
* @param[in] device the I2C controller device
|
||||
* @param[in] address the 7-bit I2C address of the slave device
|
||||
* @param[in] data the buffer containing the data to write
|
||||
* @param[in] dataSize the number of bytes to write
|
||||
* @param[in] timeout the maximum time to wait for the operation to complete
|
||||
* @retval ERROR_NONE when the write operation was successful
|
||||
*/
|
||||
error_t i2c_controller_write(struct Device* device, uint8_t address, const uint8_t* data, uint16_t dataSize, TickType_t timeout);
|
||||
|
||||
/**
|
||||
* @brief Writes data to then reads data from an I2C device using the specified controller.
|
||||
* @param[in] device the I2C controller device
|
||||
* @param[in] address the 7-bit I2C address of the slave device
|
||||
* @param[in] writeData the buffer containing the data to write
|
||||
* @param[in] writeDataSize the number of bytes to write
|
||||
* @param[out] readData the buffer to store the read data
|
||||
* @param[in] readDataSize the number of bytes to read
|
||||
* @param[in] timeout the maximum time to wait for the operation to complete
|
||||
* @retval ERROR_NONE when the operation was successful
|
||||
*/
|
||||
error_t i2c_controller_write_read(struct Device* device, uint8_t address, const uint8_t* writeData, size_t writeDataSize, uint8_t* readData, size_t readDataSize, TickType_t timeout);
|
||||
|
||||
/**
|
||||
* @brief Reads data from a register of an I2C device using the specified controller.
|
||||
* @param[in] device the I2C controller device
|
||||
* @param[in] address the 7-bit I2C address of the slave device
|
||||
* @param[in] reg the register address to read from
|
||||
* @param[out] data the buffer to store the read data
|
||||
* @param[in] dataSize the number of bytes to 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 i2c_controller_read_register(struct Device* device, uint8_t address, uint8_t reg, uint8_t* data, size_t dataSize, TickType_t timeout);
|
||||
|
||||
/**
|
||||
* @brief Writes data to a register of an I2C device using the specified controller.
|
||||
* @param[in] device the I2C controller device
|
||||
* @param[in] address the 7-bit I2C address of the slave device
|
||||
* @param[in] reg the register address to write to
|
||||
* @param[in] data the buffer containing the data to write
|
||||
* @param[in] dataSize the number of bytes to write
|
||||
* @param[in] timeout the maximum time to wait for the operation to complete
|
||||
* @retval ERROR_NONE when the write operation was successful
|
||||
*/
|
||||
error_t i2c_controller_write_register(struct Device* device, uint8_t address, uint8_t reg, const uint8_t* data, uint16_t dataSize, TickType_t timeout);
|
||||
|
||||
/**
|
||||
* @brief Writes an array of register-value pairs to an I2C device.
|
||||
* @param[in] device the I2C controller device
|
||||
* @param[in] address the 7-bit I2C address of the slave device
|
||||
* @param[in] data an array of bytes where even indices are register addresses and odd indices are values
|
||||
* @param[in] dataSize the number of bytes in the data array (must be even)
|
||||
* @param[in] timeout the maximum time to wait for each operation to complete
|
||||
* @retval ERROR_NONE when all write operations were successful
|
||||
*/
|
||||
error_t i2c_controller_write_register_array(struct Device* device, uint8_t address, const uint8_t* data, uint16_t dataSize, TickType_t timeout);
|
||||
|
||||
/**
|
||||
* @brief Checks if an I2C device is present at the specified address.
|
||||
* @param[in] device the I2C controller device
|
||||
* @param[in] address the 7-bit I2C address to check
|
||||
* @param[in] timeout the maximum time to wait for the check to complete
|
||||
* @retval ERROR_NONE when a device responded at the address
|
||||
*/
|
||||
error_t i2c_controller_has_device_at_address(struct Device* device, uint8_t address, TickType_t timeout);
|
||||
|
||||
extern const struct DeviceType I2C_CONTROLLER_TYPE;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,143 @@
|
||||
// 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>
|
||||
|
||||
struct Device;
|
||||
|
||||
/**
|
||||
* @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
|
||||
@@ -0,0 +1,25 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <stdbool.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
struct RootConfig {
|
||||
const char* model;
|
||||
};
|
||||
|
||||
/**
|
||||
* Indicates whether the device's model matches the specified model.
|
||||
* @param[in] device the device to check (non-null)
|
||||
* @param[in] model the model to check against
|
||||
* @return true if the device's model matches the specified model
|
||||
*/
|
||||
bool root_is_model(const struct Device* device, const char* model);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,72 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
|
||||
#include <tactility/freertos/freertos.h>
|
||||
#include <tactility/error.h>
|
||||
|
||||
struct Device;
|
||||
|
||||
/**
|
||||
* @brief API for SPI controller drivers.
|
||||
*/
|
||||
struct SpiControllerApi {
|
||||
/**
|
||||
* @brief Locks the SPI controller.
|
||||
* @param[in] device the SPI controller device
|
||||
* @retval ERROR_NONE when the operation was successful
|
||||
*/
|
||||
error_t (*lock)(struct Device* device);
|
||||
|
||||
/**
|
||||
* @brief Tries to lock the SPI controller.
|
||||
* @param[in] device the SPI controller device
|
||||
* @param[in] timeout the maximum time to wait for the lock
|
||||
* @retval ERROR_NONE when the operation was successful
|
||||
* @retval ERROR_TIMEOUT when the operation timed out
|
||||
*/
|
||||
error_t (*try_lock)(struct Device* device, TickType_t timeout);
|
||||
|
||||
/**
|
||||
* @brief Unlocks the SPI controller.
|
||||
* @param[in] device the SPI controller device
|
||||
* @retval ERROR_NONE when the operation was successful
|
||||
*/
|
||||
error_t (*unlock)(struct Device* device);
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Locks the SPI controller using the specified controller.
|
||||
* @param[in] device the SPI controller device
|
||||
* @retval ERROR_NONE when the operation was successful
|
||||
*/
|
||||
error_t spi_controller_lock(struct Device* device);
|
||||
|
||||
/**
|
||||
* @brief Tries to lock the SPI controller using the specified controller.
|
||||
* @param[in] device the SPI controller device
|
||||
* @param[in] timeout the maximum ticks to wait for the lock
|
||||
* @retval ERROR_NONE when the operation was successful
|
||||
* @retval ERROR_TIMEOUT when the operation timed out
|
||||
*/
|
||||
error_t spi_controller_try_lock(struct Device* device, TickType_t timeout);
|
||||
|
||||
/**
|
||||
* @brief Unlocks the SPI controller using the specified controller.
|
||||
* @param[in] device the SPI controller device
|
||||
* @retval ERROR_NONE when the operation was successful
|
||||
*/
|
||||
error_t spi_controller_unlock(struct Device* device);
|
||||
|
||||
extern const struct DeviceType SPI_CONTROLLER_TYPE;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
@@ -0,0 +1,227 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
|
||||
#pragma once
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
#include <stdint.h>
|
||||
#include <stddef.h>
|
||||
|
||||
#include <tactility/freertos/freertos.h>
|
||||
#include <tactility/error.h>
|
||||
|
||||
struct Device;
|
||||
|
||||
/**
|
||||
* @brief UART parity modes
|
||||
*/
|
||||
enum UartParity {
|
||||
UART_CONTROLLER_PARITY_DISABLE = 0x0,
|
||||
UART_CONTROLLER_PARITY_EVEN = 0x1,
|
||||
UART_CONTROLLER_PARITY_ODD = 0x2,
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief UART data bits
|
||||
*/
|
||||
enum UartDataBits {
|
||||
UART_CONTROLLER_DATA_5_BITS = 0x0,
|
||||
UART_CONTROLLER_DATA_6_BITS = 0x1,
|
||||
UART_CONTROLLER_DATA_7_BITS = 0x2,
|
||||
UART_CONTROLLER_DATA_8_BITS = 0x3,
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief UART stop bits
|
||||
*/
|
||||
enum UartStopBits {
|
||||
UART_CONTROLLER_STOP_BITS_1 = 0x1,
|
||||
UART_CONTROLLER_STOP_BITS_1_5 = 0x2,
|
||||
UART_CONTROLLER_STOP_BITS_2 = 0x3,
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief UART Config
|
||||
*/
|
||||
struct UartConfig {
|
||||
uint32_t baud_rate;
|
||||
enum UartDataBits data_bits;
|
||||
enum UartParity parity;
|
||||
enum UartStopBits stop_bits;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief API for UART controller drivers.
|
||||
*/
|
||||
struct UartControllerApi {
|
||||
/**
|
||||
* @brief Reads a single byte from UART.
|
||||
* @param[in] device the UART controller device
|
||||
* @param[out] out the buffer to store the read byte
|
||||
* @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_byte)(struct Device* device, uint8_t* out, TickType_t timeout);
|
||||
|
||||
/**
|
||||
* @brief Writes a single byte to UART.
|
||||
* @param[in] device the UART controller device
|
||||
* @param[in] out the byte to write
|
||||
* @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_byte)(struct Device* device, uint8_t out, TickType_t timeout);
|
||||
|
||||
/**
|
||||
* @brief Writes multiple bytes to UART.
|
||||
* @param[in] device the UART controller device
|
||||
* @param[in] buffer the buffer containing the data to write
|
||||
* @param[in] buffer_size the number of bytes to write
|
||||
* @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_bytes)(struct Device* device, const uint8_t* buffer, size_t buffer_size, TickType_t timeout);
|
||||
|
||||
/**
|
||||
* @brief Reads multiple bytes from UART.
|
||||
* @param[in] device the UART controller device
|
||||
* @param[out] buffer the buffer to store the read data
|
||||
* @param[in] buffer_size the number of bytes to 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_bytes)(struct Device* device, uint8_t* buffer, size_t buffer_size, TickType_t timeout);
|
||||
|
||||
/**
|
||||
* @brief Returns the number of bytes available for reading.
|
||||
* @param[in] device the UART controller device
|
||||
* @param[out] available the number of bytes available
|
||||
* @return ERROR_NONE on success
|
||||
*/
|
||||
error_t (*get_available)(struct Device* device, size_t* available);
|
||||
|
||||
/**
|
||||
* @brief Sets the UART configuration.
|
||||
* @param[in] device the UART 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 UartConfig* config);
|
||||
|
||||
/**
|
||||
* @brief Gets the current UART configuration.
|
||||
* @param[in] device the UART 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 UartConfig* config);
|
||||
|
||||
/**
|
||||
* @brief Opens the UART controller.
|
||||
* @param[in] device the UART controller device
|
||||
* @retval ERROR_NONE when the operation was successful
|
||||
*/
|
||||
error_t (*open)(struct Device* device);
|
||||
|
||||
/**
|
||||
* @brief Closes the UART controller.
|
||||
* @param[in] device the UART controller device
|
||||
* @retval ERROR_NONE when the operation was successful
|
||||
*/
|
||||
error_t (*close)(struct Device* device);
|
||||
|
||||
/**
|
||||
* @brief Checks if the UART controller is open.
|
||||
* @param[in] device the UART controller device
|
||||
* @return true if open, false otherwise
|
||||
*/
|
||||
bool (*is_open)(struct Device* device);
|
||||
|
||||
/**
|
||||
* @brief Flushes the UART input buffer.
|
||||
* @param[in] device the UART controller device
|
||||
* @retval ERROR_NONE when the operation was successful
|
||||
*/
|
||||
error_t (*flush_input)(struct Device* device);
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Reads a single byte from UART using the specified controller.
|
||||
*/
|
||||
error_t uart_controller_read_byte(struct Device* device, uint8_t* out, TickType_t timeout);
|
||||
|
||||
/**
|
||||
* @brief Writes a single byte to UART using the specified controller.
|
||||
*/
|
||||
error_t uart_controller_write_byte(struct Device* device, uint8_t out, TickType_t timeout);
|
||||
|
||||
/**
|
||||
* @brief Writes multiple bytes to UART using the specified controller.
|
||||
*/
|
||||
error_t uart_controller_write_bytes(struct Device* device, const uint8_t* buffer, size_t buffer_size, TickType_t timeout);
|
||||
|
||||
/**
|
||||
* @brief Reads multiple bytes from UART using the specified controller.
|
||||
*/
|
||||
error_t uart_controller_read_bytes(struct Device* device, uint8_t* buffer, size_t buffer_size, TickType_t timeout);
|
||||
|
||||
/**
|
||||
* @brief Reads from UART until a specific byte is encountered.
|
||||
* @param[in] device the UART controller device
|
||||
* @param[out] buffer the buffer to store the read data
|
||||
* @param[in] buffer_size the size of the buffer
|
||||
* @param[in] until_byte the byte to look for
|
||||
* @param[in] timeout the maximum time to wait for the operation to complete
|
||||
* @param[in] add_null_terminator whether to add a null terminator after the until_byte
|
||||
* @param[out] bytes_read the number of bytes read (excluding null terminator if added)
|
||||
* @retval ERROR_NONE when the operation was successful
|
||||
* @retval ERROR_TIMEOUT when the operation timed out
|
||||
*/
|
||||
error_t uart_controller_read_until(struct Device* device, uint8_t* buffer, size_t buffer_size, uint8_t until_byte, bool add_null_terminator, size_t* bytes_read, TickType_t timeout);
|
||||
|
||||
/**
|
||||
* @brief Get the number of bytes available for reading using the specified controller.
|
||||
*/
|
||||
error_t uart_controller_get_available(struct Device* device, size_t* available);
|
||||
|
||||
/**
|
||||
* @brief Sets the UART configuration using the specified controller.
|
||||
*/
|
||||
error_t uart_controller_set_config(struct Device* device, const struct UartConfig* config);
|
||||
|
||||
/**
|
||||
* @brief Gets the current UART configuration using the specified controller.
|
||||
*/
|
||||
error_t uart_controller_get_config(struct Device* device, struct UartConfig* config);
|
||||
|
||||
/**
|
||||
* @brief Opens the UART controller using the specified controller.
|
||||
*/
|
||||
error_t uart_controller_open(struct Device* device);
|
||||
|
||||
/**
|
||||
* @brief Closes the UART controller using the specified controller.
|
||||
*/
|
||||
error_t uart_controller_close(struct Device* device);
|
||||
|
||||
/**
|
||||
* @brief Checks if the UART controller is open using the specified controller.
|
||||
*/
|
||||
bool uart_controller_is_open(struct Device* device);
|
||||
|
||||
/**
|
||||
* @brief Flushes the UART input buffer using the specified controller.
|
||||
*/
|
||||
error_t uart_controller_flush_input(struct Device* device);
|
||||
|
||||
extern const struct DeviceType UART_CONTROLLER_TYPE;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
Reference in New Issue
Block a user