Modules | |
I2C hal tests | |
The I2C HAL tests ensure driver conformance to defined behaviour. | |
Functions | |
void | i2c_get_capabilities (i2c_capabilities_t *capabilities) |
Fills structure indicating supported features and frequencies on the current platform. More... | |
void | i2c_init (i2c_t *obj, PinName sda, PinName scl, bool is_slave) |
Initialize the I2C peripheral. More... | |
void | i2c_free (i2c_t *obj) |
Release the I2C object. More... | |
uint32_t | i2c_frequency (i2c_t *obj, uint32_t frequency) |
Configure the frequency in Hz at which the I2C peripheral should operate. More... | |
void | i2c_set_clock_stretching (i2c_t *obj, bool enabled) |
Enable or disable clock stretching for the I2C peripheral. More... | |
void | i2c_timeout (i2c_t *obj, uint32_t timeout) |
Configure the timeout duration in microseconds for blocking transmission. More... | |
void | i2c_start (i2c_t *obj) |
Send START command. More... | |
void | i2c_stop (i2c_t *obj) |
Send STOP command. More... | |
int32_t | i2c_write (i2c_t *obj, uint16_t address, const uint8_t *data, uint32_t length, bool stop) |
Blocking sending data. More... | |
int32_t | i2c_read (i2c_t *obj, uint16_t address, uint8_t *data, uint32_t length, bool stop) |
Blocking reading data. More... | |
const PinMap * | i2c_master_sda_pinmap (void) |
Get the pins that support I2C SDA. More... | |
const PinMap * | i2c_master_scl_pinmap (void) |
Get the pins that support I2C SCL. More... | |
const PinMap * | i2c_slave_sda_pinmap (void) |
Get the pins that support I2C SDA. More... | |
const PinMap * | i2c_slave_scl_pinmap (void) |
Get the pins that support I2C SCL. More... | |
length
bytes from the I2C slave specified by address
to the data
bufferstop
parameter is non-zerolength
bytes to the I2C slave specified by address
from the data
bufferstop
parameter is non-zerolast
parameter to inform the slave that all bytes have been readlength
bytes from the I2C master to the data
bufferlength
bytes to the I2C master from the data
buffertx_length
bytes to the I2C slave specified by address
from the tx
bufferrx_length
bytes from the I2C slave specified by address
to the rx
bufferstop
parameter is non-zeroDMAUsage
hint to select the appropriate async algorithmi2c_t
i2c_t
I2C
peripheral with invalid SDA
and SCL
pins.obj
to any functionnull
pointer as an argument to any function.I2C
reserved valueread
or write
functionshandler
void i2c_free | ( | i2c_t * | obj | ) |
Release the I2C object.
obj | The I2C object to deinitialize |
uint32_t i2c_frequency | ( | i2c_t * | obj, |
uint32_t | frequency | ||
) |
Configure the frequency in Hz at which the I2C peripheral should operate.
obj | The I2C object |
frequency | Frequency in Hz |
void i2c_get_capabilities | ( | i2c_capabilities_t * | capabilities | ) |
Fills structure indicating supported features and frequencies on the current platform.
[out] | capabilities | Capabilities structure filled with supported configurations. |
void i2c_init | ( | i2c_t * | obj, |
PinName | sda, | ||
PinName | scl, | ||
bool | is_slave | ||
) |
Initialize the I2C peripheral.
It sets the default parameters for the I2C peripheral and configures its pins.
obj | The I2C object |
sda | The sda pin |
scl | The scl pin |
is_slave | Choose whether the peripheral is initialized as master or slave. |
const PinMap* i2c_master_scl_pinmap | ( | void | ) |
const PinMap* i2c_master_sda_pinmap | ( | void | ) |
int32_t i2c_read | ( | i2c_t * | obj, |
uint16_t | address, | ||
uint8_t * | data, | ||
uint32_t | length, | ||
bool | stop | ||
) |
Blocking reading data.
This function receives data when the peripheral is configured as Master from the selected slave and when configured as Slave from the Master.
This function is blocking; it returns when the transfer is complete or a timeout event is triggered. The number of bytes received is returned by the function after the operation is completed. Receive operation cannot be canceled or aborted.
When in master mode, the operation consists of:
stop
field is true.obj | The I2C object |
address | 7/10-bit address (last bit is 1) |
data | The buffer for receiving |
length | Number of bytes to read |
stop | If true, stop is generated after the transfer is done |
Additional time for arbitration or clock stretching should by count by setting appropriate timeout value.
When no transmision timeout is set by the user, the default timeout value is used. It counts one additional byte for addressing stage: default_timeout = (length + 1) * byte_timeout.
void i2c_set_clock_stretching | ( | i2c_t * | obj, |
bool | enabled | ||
) |
Enable or disable clock stretching for the I2C peripheral.
obj | The I2C object |
enabled | If 'true', enable clock stretching on the given I2C peripheral; otherwise, disable it. |
const PinMap* i2c_slave_scl_pinmap | ( | void | ) |
const PinMap* i2c_slave_sda_pinmap | ( | void | ) |
void i2c_start | ( | i2c_t * | obj | ) |
Send START command.
obj | The I2C object. |
void i2c_stop | ( | i2c_t * | obj | ) |
Send STOP command.
obj | The I2C object |
void i2c_timeout | ( | i2c_t * | obj, |
uint32_t | timeout | ||
) |
Configure the timeout duration in microseconds for blocking transmission.
obj | The I2C object |
timeout | Transmission timeout in microseconds. |
int32_t i2c_write | ( | i2c_t * | obj, |
uint16_t | address, | ||
const uint8_t * | data, | ||
uint32_t | length, | ||
bool | stop | ||
) |
Blocking sending data.
This function transmits data when the peripheral is configured as Master to the selected slave and when configured as Slave transmits data to the Master.
This function is blocking; it returns when the transfer is complete or a timeout event is triggered. The number of bytes transmitted is returned by the function after the operation is completed. Transmit operation cannot be canceled or aborted.
The data buffer must stay allocated during the duration of the transfer, and the contents must not be modified. The value of the specified address
is ignored when configured in slave mode. In master mode, it contains the address of the target peripheral. This is a 7-bit value unless 10-bit addressing is configured, and the target supports it.
When in master mode, the operation consists of:
stop
field is true.obj | The I2C object |
address | 7/10-bit address (last bit is 0) |
data | The buffer for sending |
length | Number of bytes to write |
stop | If true, stop is generated after the transfer is done |
Additional time for arbitration or clock stretching should by count by setting appropriate timeout value.
When no transmision timeout is set by the user, the default timeout value is used. It counts one additional byte for addressing stage: default_timeout = (length + 1) * byte_timeout.