Implement new I2C driver (#531)
This commit is contained in:
committed by
GitHub
parent
8dd9bee8d0
commit
8dabda2b5b
@@ -21,7 +21,7 @@ extern "C" {
|
||||
#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_UP (1 << 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)
|
||||
|
||||
@@ -82,6 +82,17 @@ struct I2cControllerApi {
|
||||
* @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 Checks if a device responds at the given address, without performing a data transfer.
|
||||
* Optional: set to NULL if the driver does not support a dedicated probe operation, in which case
|
||||
* @ref i2c_controller_has_device_at_address falls back to a generic write-based probe.
|
||||
* @param[in] device the I2C controller device
|
||||
* @param[in] address the 7-bit I2C address to probe
|
||||
* @param[in] timeout the maximum time to wait for the operation to complete
|
||||
* @retval ERROR_NONE when a device acknowledged the address
|
||||
*/
|
||||
error_t (*probe)(struct Device* device, uint8_t address, TickType_t timeout);
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
@@ -73,8 +73,12 @@ error_t i2c_controller_write_register_array(Device* device, uint8_t address, con
|
||||
|
||||
error_t i2c_controller_has_device_at_address(Device* device, uint8_t address, TickType_t timeout) {
|
||||
const auto* driver = device_get_driver(device);
|
||||
auto* api = I2C_DRIVER_API(driver);
|
||||
if (api->probe != nullptr) {
|
||||
return api->probe(device, address, timeout);
|
||||
}
|
||||
uint8_t message[2] = { 0, 0 };
|
||||
return I2C_DRIVER_API(driver)->write(device, address, message, 2, timeout);
|
||||
return api->write(device, address, message, 2, timeout);
|
||||
}
|
||||
|
||||
error_t i2c_controller_register16le_get(Device* device, uint8_t address, uint8_t reg, uint16_t* value, TickType_t timeout) {
|
||||
|
||||
Reference in New Issue
Block a user