i2c: introduce struct i2c_dt_spec
Introduces the `struct i2c_dt_spec` type, which contains the complete I2c bus information derived from devicetree. It serves the same purpose as `struct spi_dt_spec` in that it can be constructed automatically in `DEVICE_DT_INST_DEFINE` macros and provided as a single handle to I2C API calls. While I2C has much less instance configuration than SPI, this is still useful to enable the following pattern in device drivers that support both I2C and SPI comms: ``` struct config { union { struct spi_dt_spec spi; struct i2c_dt_spec i2c; }; }; ``` Signed-off-by: Jordan Yates <jordan.yates@data61.csiro.au>
This commit is contained in:
parent
2070c0997f
commit
6964fa8fbd
1 changed files with 39 additions and 0 deletions
|
@ -58,6 +58,45 @@ extern "C" {
|
|||
/** Controller to act as Master. */
|
||||
#define I2C_MODE_MASTER BIT(4)
|
||||
|
||||
/**
|
||||
* @brief Complete I2C DT information
|
||||
*
|
||||
* @param bus is the I2C bus
|
||||
* @param addr is the slave address
|
||||
*/
|
||||
struct i2c_dt_spec {
|
||||
const struct device *bus;
|
||||
uint16_t addr;
|
||||
};
|
||||
|
||||
/**
|
||||
* @brief Structure initializer for i2c_dt_spec from devicetree
|
||||
*
|
||||
* This helper macro expands to a static initializer for a <tt>struct
|
||||
* i2c_dt_spec</tt> by reading the relevant bus and address data from
|
||||
* the devicetree.
|
||||
*
|
||||
* @param node_id Devicetree node identifier for the I2C device whose
|
||||
* struct i2c_dt_spec to create an initializer for
|
||||
*/
|
||||
#define I2C_DT_SPEC_GET(node_id) \
|
||||
{ \
|
||||
.bus = DEVICE_DT_GET(DT_BUS(node_id)), \
|
||||
.addr = DT_REG_ADDR(node_id) \
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief Structure initializer for i2c_dt_spec from devicetree instance
|
||||
*
|
||||
* This is equivalent to
|
||||
* <tt>I2C_DT_SPEC_GET(DT_DRV_INST(inst))</tt>.
|
||||
*
|
||||
* @param inst Devicetree instance number
|
||||
*/
|
||||
#define I2C_DT_SPEC_INST_GET(inst) \
|
||||
I2C_DT_SPEC_GET(DT_DRV_INST(inst))
|
||||
|
||||
|
||||
/*
|
||||
* I2C_MSG_* are I2C Message flags.
|
||||
*/
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue