Modules | |
Related Project(s) | |
In this section you can find all the projects related to the Asfdoc_sam0_sercom_i2c_group. | |
Data Structures | |
struct | i2c_master_config |
Configuration structure for the I2C Master device. More... | |
struct | i2c_master_module |
SERCOM I2C Master driver software device instance structure. More... | |
struct | i2c_master_packet |
I2C master packet for read/write. More... | |
struct | i2c_slave_config |
Configuration structure for the I2C slave device. More... | |
struct | i2c_slave_module |
SERCOM I2C slave driver software device instance structure. More... | |
struct | i2c_slave_packet |
I2C slave packet for read/write. More... | |
Callbacks | |
void | i2c_master_register_callback (struct i2c_master_module *const module, i2c_master_callback_t callback, enum i2c_master_callback callback_type) |
void | i2c_master_unregister_callback (struct i2c_master_module *const module, enum i2c_master_callback callback_type) |
static void | i2c_master_enable_callback (struct i2c_master_module *const module, enum i2c_master_callback callback_type) |
Enables callback. More... | |
static void | i2c_master_disable_callback (struct i2c_master_module *const module, enum i2c_master_callback callback_type) |
Disables callback. More... | |
Lock/Unlock | |
static enum status_code | i2c_master_lock (struct i2c_master_module *const module) |
Attempt to get lock on driver instance. More... | |
static void | i2c_master_unlock (struct i2c_master_module *const module) |
Unlock driver instance. More... | |
Configuration and Initialization | |
static bool | i2c_master_is_syncing (const struct i2c_master_module *const module) |
Returns the synchronization status of the module. More... | |
static void | i2c_master_get_config_defaults (struct i2c_master_config *const config) |
Gets the I2C master default configurations. More... | |
enum status_code | i2c_master_init (struct i2c_master_module *const module, Sercom *const hw, const struct i2c_master_config *const config) |
static void | i2c_master_enable (const struct i2c_master_module *const module) |
Enables the I2C module. More... | |
static void | i2c_master_disable (const struct i2c_master_module *const module) |
Disable the I2C module. More... | |
void | i2c_master_reset (struct i2c_master_module *const module) |
Read and Write | |
enum status_code | i2c_master_read_packet_wait (struct i2c_master_module *const module, struct i2c_master_packet *const packet) |
enum status_code | i2c_master_read_packet_wait_no_stop (struct i2c_master_module *const module, struct i2c_master_packet *const packet) |
enum status_code | i2c_master_write_packet_wait (struct i2c_master_module *const module, struct i2c_master_packet *const packet) |
enum status_code | i2c_master_write_packet_wait_no_stop (struct i2c_master_module *const module, struct i2c_master_packet *const packet) |
void | i2c_master_send_stop (struct i2c_master_module *const module) |
void | i2c_master_send_nack (struct i2c_master_module *const module) |
enum status_code | i2c_master_read_byte (struct i2c_master_module *const module, uint8_t *byte) |
enum status_code | i2c_master_write_byte (struct i2c_master_module *const module, uint8_t byte) |
enum status_code | i2c_master_read_packet_wait_no_nack (struct i2c_master_module *const module, struct i2c_master_packet *const packet) |
SERCOM I2C Master with DMA Interfaces | |
static void | i2c_master_dma_set_transfer (struct i2c_master_module *const module, uint16_t addr, uint8_t length, enum i2c_transfer_direction direction) |
Set I2C for DMA transfer with slave address and transfer size. More... | |
I2C Slave Status Flags | |
I2C slave status flags, returned by i2c_slave_get_status() and cleared by i2c_slave_clear_status(). | |
#define | I2C_SLAVE_STATUS_ADDRESS_MATCH (1UL << 0) |
Address Match. More... | |
#define | I2C_SLAVE_STATUS_DATA_READY (1UL << 1) |
Data Ready. More... | |
#define | I2C_SLAVE_STATUS_STOP_RECEIVED (1UL << 2) |
Stop Received. More... | |
#define | I2C_SLAVE_STATUS_CLOCK_HOLD (1UL << 3) |
Clock Hold. More... | |
#define | I2C_SLAVE_STATUS_SCL_LOW_TIMEOUT (1UL << 4) |
SCL Low Timeout. More... | |
#define | I2C_SLAVE_STATUS_REPEATED_START (1UL << 5) |
Repeated Start. More... | |
#define | I2C_SLAVE_STATUS_RECEIVED_NACK (1UL << 6) |
Received not acknowledge. More... | |
#define | I2C_SLAVE_STATUS_COLLISION (1UL << 7) |
Transmit Collision. More... | |
#define | I2C_SLAVE_STATUS_BUS_ERROR (1UL << 8) |
Bus error. More... | |
Lock/Unlock | |
static enum status_code | i2c_slave_lock (struct i2c_slave_module *const module) |
Attempt to get lock on driver instance. More... | |
static void | i2c_slave_unlock (struct i2c_slave_module *const module) |
Unlock driver instance. More... | |
Configuration and Initialization | |
static bool | i2c_slave_is_syncing (const struct i2c_slave_module *const module) |
Returns the synchronization status of the module. More... | |
static void | i2c_slave_get_config_defaults (struct i2c_slave_config *const config) |
Gets the I2C slave default configurations. More... | |
enum status_code | i2c_slave_init (struct i2c_slave_module *const module, Sercom *const hw, const struct i2c_slave_config *const config) |
static void | i2c_slave_enable (const struct i2c_slave_module *const module) |
Enables the I2C module. More... | |
static void | i2c_slave_disable (const struct i2c_slave_module *const module) |
Disables the I2C module. More... | |
void | i2c_slave_reset (struct i2c_slave_module *const module) |
Read and Write | |
enum status_code | i2c_slave_write_packet_wait (struct i2c_slave_module *const module, struct i2c_slave_packet *const packet) |
enum status_code | i2c_slave_read_packet_wait (struct i2c_slave_module *const module, struct i2c_slave_packet *const packet) |
enum i2c_slave_direction | i2c_slave_get_direction_wait (struct i2c_slave_module *const module) |
Status Management | |
uint32_t | i2c_slave_get_status (struct i2c_slave_module *const module) |
void | i2c_slave_clear_status (struct i2c_slave_module *const module, uint32_t status_flags) |
SERCOM I2C slave with DMA Interfaces | |
static uint8_t | i2c_slave_dma_read_interrupt_status (struct i2c_slave_module *const module) |
Read SERCOM I2C interrupt status. More... | |
static void | i2c_slave_dma_write_interrupt_status (struct i2c_slave_module *const module, uint8_t flag) |
Write SERCOM I2C interrupt status. More... | |
Address Match Functionality | |
void | i2c_slave_enable_nack_on_address (struct i2c_slave_module *const module) |
void | i2c_slave_disable_nack_on_address (struct i2c_slave_module *const module) |
Callbacks | |
void | i2c_slave_register_callback (struct i2c_slave_module *const module, i2c_slave_callback_t callback, enum i2c_slave_callback callback_type) |
void | i2c_slave_unregister_callback (struct i2c_slave_module *const module, enum i2c_slave_callback callback_type) |
static void | i2c_slave_enable_callback (struct i2c_slave_module *const module, enum i2c_slave_callback callback_type) |
Enables callback. More... | |
static void | i2c_slave_disable_callback (struct i2c_slave_module *const module, enum i2c_slave_callback callback_type) |
Disables callback. More... | |
Read and Write, Interrupt-Driven | |
enum status_code | i2c_slave_read_packet_job (struct i2c_slave_module *const module, struct i2c_slave_packet *const packet) |
enum status_code | i2c_slave_write_packet_job (struct i2c_slave_module *const module, struct i2c_slave_packet *const packet) |
static void | i2c_slave_cancel_job (struct i2c_slave_module *const module) |
Cancels any currently ongoing operation. More... | |
static enum status_code | i2c_slave_get_job_status (struct i2c_slave_module *const module) |
Gets status of ongoing job. More... | |
#define I2C_SLAVE_STATUS_ADDRESS_MATCH (1UL << 0) |
Address Match.
#define I2C_SLAVE_STATUS_BUS_ERROR (1UL << 8) |
Bus error.
#define I2C_SLAVE_STATUS_CLOCK_HOLD (1UL << 3) |
Clock Hold.
#define I2C_SLAVE_STATUS_COLLISION (1UL << 7) |
Transmit Collision.
#define I2C_SLAVE_STATUS_DATA_READY (1UL << 1) |
Data Ready.
#define I2C_SLAVE_STATUS_RECEIVED_NACK (1UL << 6) |
Received not acknowledge.
#define I2C_SLAVE_STATUS_REPEATED_START (1UL << 5) |
Repeated Start.
#define I2C_SLAVE_STATUS_SCL_LOW_TIMEOUT (1UL << 4) |
SCL Low Timeout.
#define I2C_SLAVE_STATUS_STOP_RECEIVED (1UL << 2) |
Stop Received.
enum i2c_master_baud_rate |
I2C frequencies.
Values for I2C speeds supported by the module. The driver will also support setting any other value, in which case set the value in the i2c_master_config at desired value divided by 1000.
Example: If 10KHz operation is required, give baud_rate in the configuration structure the value 10.
enum i2c_master_callback |
Values for inactive bus time-out.
If the inactive bus time-out is enabled and the bus is inactive for longer than the time-out setting, the bus state logic will be set to idle.
Values for hold time after start bit.
Values for the possible I2C master mode SDA internal hold times after start bit has been sent.
Enum for the transfer speed.
Enum for the transfer speed.
Enum for the possible address modes.
Enum for the possible address modes.
enum i2c_slave_callback |
Callback types.
The available callback types for the I2C slave.
enum i2c_slave_direction |
Enum for the possible SDA hold times with respect to the negative edge of SCL.
Enum for the possible SDA hold times with respect to the negative edge of SCL.
|
inlinestatic |
Cancel any currently ongoing operation.
Terminates the running transfer operation.
[in,out] | module | Pointer to software module structure |
References Assert, and STATUS_ABORTED.
|
inlinestatic |
Disable the I2C module.
Disables the requested I2C module.
[in] | module | Pointer to the software module struct |
References _sercom_get_interrupt_vector(), Assert, and system_interrupt_disable().
Referenced by nm_bus_deinit(), and run_i2c_full_speed_test().
|
inlinestatic |
Disables callback.
Disables the callback specified by the callback_type.
[in,out] | module | Pointer to the software module struct |
[in] | callback_type | Callback type to disable |
References Assert.
|
inlinestatic |
Set I2C for DMA transfer with slave address and transfer size.
This function will set the slave address, transfer size and enable the auto transfer mode for DMA.
[in,out] | module | Pointer to the driver instance to lock |
[in] | addr | I2C slave address |
[in] | length | I2C transfer length with DMA |
[in] | direction | I2C transfer direction |
Referenced by main().
|
inlinestatic |
Enables the I2C module.
Enables the requested I2C module and set the bus state to IDLE after the specified timeout period if no stop bit is detected.
[in] | module | Pointer to the software module struct |
References _sercom_get_interrupt_vector(), Assert, and system_interrupt_enable().
Referenced by at30tse_init(), configure_i2c(), configure_i2c_master(), edbg_eui_read_eui64(), nm_bus_init(), run_i2c_full_speed_test(), and run_i2c_init_test().
|
inlinestatic |
Enables callback.
Enables the callback specified by the callback_type.
[in,out] | module | Pointer to the software module struct |
[in] | callback_type | Callback type to enable |
References Assert.
Referenced by configure_i2c_callbacks().
|
inlinestatic |
Gets the I2C master default configurations.
Use to initialize the configuration structure to known default values.
The default configuration is as follows:
Those default configuration only available if the device supports it:
[out] | config | Pointer to configuration structure to be initiated |
References Assert, i2c_master_config::baud_rate, i2c_master_config::baud_rate_high_speed, i2c_master_config::buffer_timeout, GCLK_GENERATOR_0, i2c_master_config::generator_source, I2C_MASTER_BAUD_RATE_100KHZ, I2C_MASTER_BAUD_RATE_3400KHZ, I2C_MASTER_INACTIVE_TIMEOUT_DISABLED, I2C_MASTER_SPEED_STANDARD_AND_FAST, I2C_MASTER_START_HOLD_TIME_300NS_600NS, i2c_master_config::inactive_timeout, i2c_master_config::master_scl_low_extend_timeout, PINMUX_DEFAULT, i2c_master_config::pinmux_pad0, i2c_master_config::pinmux_pad1, i2c_master_config::run_in_standby, i2c_master_config::scl_low_timeout, i2c_master_config::scl_stretch_only_after_ack_bit, i2c_master_config::sda_scl_rise_time_ns, i2c_master_config::slave_scl_low_extend_timeout, i2c_master_config::start_hold_time, i2c_master_config::transfer_speed, and i2c_master_config::unknown_bus_state_timeout.
Referenced by at30tse_init(), configure_i2c(), configure_i2c_master(), edbg_eui_read_eui64(), nm_bus_init(), run_i2c_full_speed_test(), and run_i2c_init_test().
|
inlinestatic |
Get status from ongoing job.
Will return the status of a transfer operation.
[in] | module | Pointer to software module structure |
STATUS_OK | No error has occurred |
STATUS_BUSY | If transfer is in progress |
STATUS_BUSY | If master module is busy |
STATUS_ERR_DENIED | If error on bus |
STATUS_ERR_PACKET_COLLISION | If arbitration is lost |
STATUS_ERR_BAD_ADDRESS | If slave is busy, or no slave acknowledged the address |
STATUS_ERR_TIMEOUT | If timeout occurred |
STATUS_ERR_OVERFLOW | If slave did not acknowledge last sent data, indicating that slave does not want more data and was not able to read |
References Assert.
enum status_code i2c_master_init | ( | struct i2c_master_module *const | module, |
Sercom *const | hw, | ||
const struct i2c_master_config *const | config | ||
) |
|
inlinestatic |
Returns the synchronization status of the module.
Returns the synchronization status of the module.
[in] | module | Pointer to software module structure |
true | Module is busy synchronizing |
false | Module is not synchronizing |
References Assert.
|
inlinestatic |
Attempt to get lock on driver instance.
This function checks the instance's lock, which indicates whether or not it is currently in use, and sets the lock if it was not already set.
The purpose of this is to enable exclusive access to driver instances, so that, e.g., transactions by different services will not interfere with each other.
[in,out] | module | Pointer to the driver instance to lock |
STATUS_OK | If the module was locked |
STATUS_BUSY | If the module was already locked |
References STATUS_BUSY, STATUS_OK, system_interrupt_enter_critical_section(), and system_interrupt_leave_critical_section().
enum status_code i2c_master_read_byte | ( | struct i2c_master_module *const | module, |
uint8_t * | byte | ||
) |
enum status_code i2c_master_read_bytes | ( | struct i2c_master_module *const | module, |
struct i2c_master_packet *const | packet | ||
) |
enum status_code i2c_master_read_packet_job | ( | struct i2c_master_module *const | module, |
struct i2c_master_packet *const | packet | ||
) |
Referenced by i2c_write_complete_callback().
enum status_code i2c_master_read_packet_job_no_nack | ( | struct i2c_master_module *const | module, |
struct i2c_master_packet *const | packet | ||
) |
enum status_code i2c_master_read_packet_job_no_stop | ( | struct i2c_master_module *const | module, |
struct i2c_master_packet *const | packet | ||
) |
enum status_code i2c_master_read_packet_wait | ( | struct i2c_master_module *const | module, |
struct i2c_master_packet *const | packet | ||
) |
enum status_code i2c_master_read_packet_wait_no_nack | ( | struct i2c_master_module *const | module, |
struct i2c_master_packet *const | packet | ||
) |
enum status_code i2c_master_read_packet_wait_no_stop | ( | struct i2c_master_module *const | module, |
struct i2c_master_packet *const | packet | ||
) |
Referenced by run_i2c_master_transfer_test().
void i2c_master_register_callback | ( | struct i2c_master_module *const | module, |
i2c_master_callback_t | callback, | ||
enum i2c_master_callback | callback_type | ||
) |
Referenced by configure_i2c_callbacks().
void i2c_master_reset | ( | struct i2c_master_module *const | module | ) |
Referenced by edbg_eui_read_eui64().
void i2c_master_send_nack | ( | struct i2c_master_module *const | module | ) |
void i2c_master_send_stop | ( | struct i2c_master_module *const | module | ) |
|
inlinestatic |
Unlock driver instance.
This function clears the instance lock, indicating that it is available for use.
[in,out] | module | Pointer to the driver instance to lock |
STATUS_OK | If the module was locked |
STATUS_BUSY | If the module was already locked |
void i2c_master_unregister_callback | ( | struct i2c_master_module *const | module, |
enum i2c_master_callback | callback_type | ||
) |
enum status_code i2c_master_write_byte | ( | struct i2c_master_module *const | module, |
uint8_t | byte | ||
) |
enum status_code i2c_master_write_bytes | ( | struct i2c_master_module *const | module, |
struct i2c_master_packet *const | packet | ||
) |
enum status_code i2c_master_write_packet_job | ( | struct i2c_master_module *const | module, |
struct i2c_master_packet *const | packet | ||
) |
Referenced by main().
enum status_code i2c_master_write_packet_job_no_stop | ( | struct i2c_master_module *const | module, |
struct i2c_master_packet *const | packet | ||
) |
enum status_code i2c_master_write_packet_wait | ( | struct i2c_master_module *const | module, |
struct i2c_master_packet *const | packet | ||
) |
enum status_code i2c_master_write_packet_wait_no_stop | ( | struct i2c_master_module *const | module, |
struct i2c_master_packet *const | packet | ||
) |
Referenced by at30tse_eeprom_read(), at30tse_read_register(), edbg_eui_read_eui64(), and run_i2c_master_transfer_test().
|
inlinestatic |
Cancels any currently ongoing operation.
Terminates the running transfer operation.
[in,out] | module | Pointer to software module structure |
References Assert.
void i2c_slave_clear_status | ( | struct i2c_slave_module *const | module, |
uint32_t | status_flags | ||
) |
|
inlinestatic |
Disables the I2C module.
This will disable the I2C module specified in the provided software module structure.
[in] | module | Pointer to the software module struct |
References _sercom_get_interrupt_vector(), Assert, and system_interrupt_disable().
|
inlinestatic |
Disables callback.
Disables the callback specified by the callback_type.
[in,out] | module | Pointer to the software module struct |
[in] | callback_type | Callback type to disable |
References Assert, I2C_SLAVE_CALLBACK_READ_REQUEST, I2C_SLAVE_CALLBACK_WRITE_REQUEST, and STATUS_BUSY.
void i2c_slave_disable_nack_on_address | ( | struct i2c_slave_module *const | module | ) |
|
inlinestatic |
Read SERCOM I2C interrupt status.
Read I2C interrupt status for DMA transfer.
[in,out] | module | Pointer to the driver instance to lock |
Referenced by main().
|
inlinestatic |
Write SERCOM I2C interrupt status.
Write I2C interrupt status for DMA transfer.
[in,out] | module | Pointer to the driver instance to lock |
[in] | flag | Interrupt flag status |
Referenced by main().
|
inlinestatic |
Enables the I2C module.
This will enable the requested I2C module.
[in] | module | Pointer to the software module struct |
References _sercom_get_interrupt_vector(), Assert, and system_interrupt_enable().
Referenced by configure_i2c_slave(), and run_i2c_init_test().
|
inlinestatic |
Enables callback.
Enables the callback specified by the callback_type.
[in,out] | module | Pointer to the software module struct |
[in] | callback_type | Callback type to enable |
References Assert, I2C_SLAVE_CALLBACK_READ_REQUEST, and I2C_SLAVE_CALLBACK_WRITE_REQUEST.
Referenced by configure_i2c_slave_callbacks().
void i2c_slave_enable_nack_on_address | ( | struct i2c_slave_module *const | module | ) |
|
inlinestatic |
Gets the I2C slave default configurations.
This will initialize the configuration structure to known default values.
The default configuration is as follows:
Those default configuration only available if the device supports it:
[out] | config | Pointer to configuration structure to be initialized |
References i2c_slave_config::address, i2c_slave_config::address_mask, i2c_slave_config::address_mode, Assert, i2c_slave_config::buffer_timeout, i2c_slave_config::enable_general_call_address, i2c_slave_config::enable_nack_on_address, i2c_slave_config::enable_scl_low_timeout, GCLK_GENERATOR_0, i2c_slave_config::generator_source, I2C_SLAVE_ADDRESS_MODE_MASK, I2C_SLAVE_SDA_HOLD_TIME_300NS_600NS, I2C_SLAVE_SPEED_STANDARD_AND_FAST, PINMUX_DEFAULT, i2c_slave_config::pinmux_pad0, i2c_slave_config::pinmux_pad1, i2c_slave_config::run_in_standby, i2c_slave_config::scl_low_timeout, i2c_slave_config::scl_stretch_only_after_ack_bit, i2c_slave_config::sda_hold_time, i2c_slave_config::slave_scl_low_extend_timeout, i2c_slave_config::ten_bit_address, and i2c_slave_config::transfer_speed.
Referenced by configure_i2c_slave(), and run_i2c_init_test().
enum i2c_slave_direction i2c_slave_get_direction_wait | ( | struct i2c_slave_module *const | module | ) |
Referenced by main().
|
inlinestatic |
Gets status of ongoing job.
Will return the status of the ongoing job, or the error that occurred in the last transfer operation. The status will be cleared when starting a new job.
[in,out] | module | Pointer to software module structure |
STATUS_OK | No error has occurred |
STATUS_BUSY | Transfer is in progress |
STATUS_ERR_IO | A collision, timeout or bus error happened in the last transfer |
STATUS_ERR_TIMEOUT | A timeout occurred |
STATUS_ERR_OVERFLOW | Data from master overflows receive buffer |
References Assert.
uint32_t i2c_slave_get_status | ( | struct i2c_slave_module *const | module | ) |
enum status_code i2c_slave_init | ( | struct i2c_slave_module *const | module, |
Sercom *const | hw, | ||
const struct i2c_slave_config *const | config | ||
) |
Referenced by configure_i2c_slave(), and run_i2c_init_test().
|
inlinestatic |
Returns the synchronization status of the module.
Returns the synchronization status of the module.
[out] | module | Pointer to software module structure |
true | Module is busy synchronizing |
false | Module is not synchronizing |
References Assert.
|
inlinestatic |
Attempt to get lock on driver instance.
This function checks the instance's lock, which indicates whether or not it is currently in use, and sets the lock if it was not already set.
The purpose of this is to enable exclusive access to driver instances, so that, e.g., transactions by different services will not interfere with each other.
[in,out] | module | Pointer to the driver instance to lock |
STATUS_OK | If the module was locked |
STATUS_BUSY | If the module was already locked |
References STATUS_BUSY, STATUS_OK, system_interrupt_enter_critical_section(), and system_interrupt_leave_critical_section().
enum status_code i2c_slave_read_packet_job | ( | struct i2c_slave_module *const | module, |
struct i2c_slave_packet *const | packet | ||
) |
Referenced by i2c_slave_write_request_callback(), and i2c_write_request_callback().
enum status_code i2c_slave_read_packet_wait | ( | struct i2c_slave_module *const | module, |
struct i2c_slave_packet *const | packet | ||
) |
Referenced by main().
void i2c_slave_register_callback | ( | struct i2c_slave_module *const | module, |
i2c_slave_callback_t | callback, | ||
enum i2c_slave_callback | callback_type | ||
) |
Referenced by configure_i2c_slave_callbacks().
void i2c_slave_reset | ( | struct i2c_slave_module *const | module | ) |
|
inlinestatic |
Unlock driver instance.
This function clears the instance lock, indicating that it is available for use.
[in,out] | module | Pointer to the driver instance to lock |
STATUS_OK | If the module was locked |
STATUS_BUSY | If the module was already locked |
void i2c_slave_unregister_callback | ( | struct i2c_slave_module *const | module, |
enum i2c_slave_callback | callback_type | ||
) |
enum status_code i2c_slave_write_packet_job | ( | struct i2c_slave_module *const | module, |
struct i2c_slave_packet *const | packet | ||
) |
Referenced by i2c_read_request_callback(), and i2c_slave_read_request_callback().
enum status_code i2c_slave_write_packet_wait | ( | struct i2c_slave_module *const | module, |
struct i2c_slave_packet *const | packet | ||
) |
Referenced by main().