mirror of
https://github.com/ByteWelder/Tactility.git
synced 2026-02-18 19:03:16 +00:00
- Add kernel support for SPI driver - Add kernel support for UART driver - Implemented ESP32 UART kernel driver - Update existing UART-related code in Tactility to use new kernel driver - Remove UART from tt::hal::Configuration - Remove tt_hal_uart functionality but keep functions for now - Update devicetrees for UART changes - Kernel mutex and recursive mutex: improved locking API design - Other kernel improvements - Added device_exists_of_type() and device_find_by_name()
57 lines
2.5 KiB
C++
57 lines
2.5 KiB
C++
// SPDX-License-Identifier: Apache-2.0
|
|
#include <tactility/drivers/i2c_controller.h>
|
|
#include <tactility/error.h>
|
|
|
|
#define I2C_DRIVER_API(driver) ((struct I2cControllerApi*)driver->api)
|
|
|
|
extern "C" {
|
|
|
|
error_t i2c_controller_read(Device* device, uint8_t address, uint8_t* data, size_t dataSize, TickType_t timeout) {
|
|
const auto* driver = device_get_driver(device);
|
|
return I2C_DRIVER_API(driver)->read(device, address, data, dataSize, timeout);
|
|
}
|
|
|
|
error_t i2c_controller_write(Device* device, uint8_t address, const uint8_t* data, uint16_t dataSize, TickType_t timeout) {
|
|
const auto* driver = device_get_driver(device);
|
|
return I2C_DRIVER_API(driver)->write(device, address, data, dataSize, timeout);
|
|
}
|
|
|
|
error_t i2c_controller_write_read(Device* device, uint8_t address, const uint8_t* writeData, size_t writeDataSize, uint8_t* readData, size_t readDataSize, TickType_t timeout) {
|
|
const auto* driver = device_get_driver(device);
|
|
return I2C_DRIVER_API(driver)->write_read(device, address, writeData, writeDataSize, readData, readDataSize, timeout);
|
|
}
|
|
|
|
error_t i2c_controller_read_register(Device* device, uint8_t address, uint8_t reg, uint8_t* data, size_t dataSize, TickType_t timeout) {
|
|
const auto* driver = device_get_driver(device);
|
|
return I2C_DRIVER_API(driver)->read_register(device, address, reg, data, dataSize, timeout);
|
|
}
|
|
|
|
error_t i2c_controller_write_register(Device* device, uint8_t address, uint8_t reg, const uint8_t* data, uint16_t dataSize, TickType_t timeout) {
|
|
const auto* driver = device_get_driver(device);
|
|
return I2C_DRIVER_API(driver)->write_register(device, address, reg, data, dataSize, timeout);
|
|
}
|
|
|
|
error_t i2c_controller_write_register_array(Device* device, uint8_t address, const uint8_t* data, uint16_t dataSize, TickType_t timeout) {
|
|
const auto* driver = device_get_driver(device);
|
|
if (dataSize % 2 != 0) {
|
|
return ERROR_INVALID_ARGUMENT;
|
|
}
|
|
for (int i = 0; i < dataSize; i += 2) {
|
|
error_t error = I2C_DRIVER_API(driver)->write_register(device, address, data[i], &data[i + 1], 1, timeout);
|
|
if (error != ERROR_NONE) return error;
|
|
}
|
|
return ERROR_NONE;
|
|
}
|
|
|
|
error_t i2c_controller_has_device_at_address(Device* device, uint8_t address, TickType_t timeout) {
|
|
const auto* driver = device_get_driver(device);
|
|
uint8_t message[2] = { 0, 0 };
|
|
return I2C_DRIVER_API(driver)->write(device, address, message, 2, timeout);
|
|
}
|
|
|
|
const struct DeviceType I2C_CONTROLLER_TYPE {
|
|
.name = "i2c-controller"
|
|
};
|
|
|
|
}
|