This driver for Atmel® | SMART ARM®-based microcontrollers provides an interface for the configuration and management of the device's SERCOM I2C module, for the transfer of data via an I2C bus.
The following driver API modes are covered by this manual:
The following peripheral is used by this module:
The following devices can use this module:
The outline of this documentation is as follows:
There are no prerequisites.
The outline of this section is as follows:
Driver Feature Macro | Supported devices |
---|---|
FEATURE_I2C_FAST_MODE_PLUS_AND_HIGH_SPEED | SAM D21/R21/D10/D11/L21/L22/DA1/C20/C21/HA1/R34/R35 |
FEATURE_I2C_10_BIT_ADDRESS | SAM D21/R21/D10/D11/L21/L22/DA1/C20/C21/HA1/R34/R35 |
FEATURE_I2C_SCL_STRETCH_MODE | SAM D21/R21/D10/D11/L21/L22/DA1/C20/C21/HA1/R34/R35 |
FEATURE_I2C_SCL_EXTEND_TIMEOUT | SAM D21/R21/D10/D11/L21/L22/DA1/C20/C21/HA1/R34/R35 |
The I2C provides a simple two-wire bidirectional bus consisting of a wired-AND type serial clock line (SCL) and a wired-AND type serial data line (SDA).
The I2C bus provides a simple, but efficient method of interconnecting multiple master and slave devices. An arbitration mechanism is provided for resolving bus ownership between masters, as only one master device may own the bus at any given time. The arbitration mechanism relies on the wired-AND connections to avoid bus drivers short-circuiting.
A unique address is assigned to all slave devices connected to the bus. A device can contain both master and slave logic, and can emulate multiple slave devices by responding to more than one address.
The I2C bus topology is illustrated in the figure below. The pull-up resistors (Rs) will provide a high level on the bus lines when none of the I2C devices are driving the bus. These are optional, and can be replaced with a constant current source.
The I2C standard defines three fundamental transaction formats:
A data transfer starts with the master issuing a Start condition on the bus, followed by the address of the slave together with a bit to indicate whether the master wants to read from or write to the slave. The addressed slave must respond to this by sending an ACK back to the master.
After this, data packets are sent from the master or slave, according to the read/write bit. Each packet must be acknowledged (ACK) or not acknowledged (NACK) by the receiver.
If a slave responds with a NACK, the master must assume that the slave cannot receive any more data and cancel the write operation.
The master completes a transaction by issuing a Stop condition.
A master can issue multiple Start conditions during a transaction; this is then called a Repeated Start condition.
The slave address consists of seven bits. The 8th bit in the transfer determines the data direction (read or write). An address packet always succeeds a Start or Repeated Start condition. The 8th bit is handled in the driver, and the user will only have to provide the 7-bit address.
Data packets are nine bits long, consisting of one 8-bit data byte, and an acknowledgement bit. Data packets follow either an address packet or another data packet on the bus.
The gray bits in the following examples are sent from master to slave, and the white bits are sent from slave to master. Example of a read transaction is shown in the figure below. Here, the master first issues a Start condition and gets ownership of the bus. An address packet with the direction flag set to read is then sent and acknowledged by the slave. Then the slave sends one data packet which is acknowledged by the master. The slave sends another packet, which is not acknowledged by the master and indicates that the master will terminate the transaction. In the end, the transaction is terminated by the master issuing a Stop condition.
Example of a write transaction is shown in the figure below. Here, the master first issues a Start condition and gets ownership of the bus. An address packet with the dir flag set to write is then sent and acknowledged by the slave. Then the master sends two data packets, each acknowledged by the slave. In the end, the transaction is terminated by the master issuing a Stop condition.
When a master sends an I2C packet, there is no way of being sure that a slave will acknowledge the packet. To avoid stalling the device forever while waiting for an acknowledge, a user selectable timeout is provided in the i2c_master_config struct which lets the driver exit a read or write operation after the specified time. The function will then return the STATUS_ERR_TIMEOUT flag.
This is also the case for the slave when using the functions postfixed _wait
.
The time before the timeout occurs, will be the same as for unknown bus state timeout.
To issue a Repeated Start, the functions postfixed _no_stop
must be used. These functions will not send a Stop condition when the transfer is done, thus the next transfer will start with a Repeated Start. To end the transaction, the functions without the _no_stop
postfix must be used for the last read/write.
In a multi master environment, arbitration of the bus is important, as only one master can own the bus at any point.
In situations where more than one master is trying to control the bus clock line at the same time, a clock synchronization algorithm based on the same principles used for clock stretching is necessary.
As the I2C bus is limited to one transaction at the time, a master that wants to perform a bus transaction must wait until the bus is free. Because of this, it is necessary for all masters in a multi-master system to know the current status of the bus to be able to avoid conflicts and to ensure data integrity.
The bus state diagram can be seen in the figure below.
Inactive bus timeout for the master and SDA hold time is configurable in the drivers.
When a master is enabled or connected to the bus, the bus state will be unknown until either a given timeout or a stop command has occurred. The timeout is configurable in the i2c_master_config struct. The timeout time will depend on toolchain and optimization level used, as the timeout is a loop incrementing a value until it reaches the specified timeout value.
When using the I2C in slave mode, it will be important to set a SDA hold time which assures that the master will be able to pick up the bit sent from the slave. The SDA hold time makes sure that this is the case by holding the data line low for a given period after the negative edge on the clock.
The SDA hold time is also available for the master driver, but is not a necessity.
The I2C module can operate in all sleep modes by setting the run_in_standby Boolean in the i2c_master_config or i2c_slave_config struct. The operation in slave and master mode is shown in the table below.
Run in standby | Slave | Master |
---|---|---|
false | Disabled, all reception is dropped | Generic Clock (GCLK) disabled when master is idle |
true | Wake on address match when enabled | GCLK enabled while in sleep modes |
While an interrupt-driven operation is in progress, subsequent calls to a write or read operation will return the STATUS_BUSY flag, indicating that only one operation is allowed at any given time.
To check if another transmission can be initiated, the user can either call another transfer operation, or use the i2c_master_get_job_status/i2c_slave_get_job_status functions depending on mode.
If the user would like to get callback from operations while using the interrupt-driven driver, the callback must be registered and then enabled using the "register_callback" and "enable_callback" functions.
For extra information, see Extra Information for SERCOM I2C Driver. This includes:
For a list of examples related to this driver, see Examples for SERCOM I2C Driver.
Modules | |
Related Project(s) | |
In this section you can find all the projects related to the SAM I2C (SERCOM I2C) Driver. | |
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... | |
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) |
Initializes the requested I2C hardware module. More... | |
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) |
Resets the hardware module. More... | |
Read and Write | |
enum status_code | i2c_slave_write_packet_wait (struct i2c_slave_module *const module, struct i2c_slave_packet *const packet) |
Writes a packet to the master. More... | |
enum status_code | i2c_slave_read_packet_wait (struct i2c_slave_module *const module, struct i2c_slave_packet *const packet) |
Reads a packet from the master. More... | |
enum i2c_slave_direction | i2c_slave_get_direction_wait (struct i2c_slave_module *const module) |
Waits for a start condition on the bus. More... | |
Status Management | |
uint32_t | i2c_slave_get_status (struct i2c_slave_module *const module) |
Retrieves the current module status. More... | |
void | i2c_slave_clear_status (struct i2c_slave_module *const module, uint32_t status_flags) |
Clears a module status flag. More... | |
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... | |
Driver Feature Definition | |
Define SERCOM I2C driver features set according to different device family. | |
#define | FEATURE_I2C_FAST_MODE_PLUS_AND_HIGH_SPEED |
Fast mode plus and high speed support. More... | |
#define | FEATURE_I2C_10_BIT_ADDRESS |
10-bit address support More... | |
#define | FEATURE_I2C_SCL_STRETCH_MODE |
SCL stretch mode support. More... | |
#define | FEATURE_I2C_SCL_EXTEND_TIMEOUT |
SCL extend timeout support. More... | |
#define | FEATURE_I2C_DMA_SUPPORT |
Address Match Functionality | |
void | i2c_slave_enable_nack_on_address (struct i2c_slave_module *const module) |
Enables sending of NACK on address match. More... | |
void | i2c_slave_disable_nack_on_address (struct i2c_slave_module *const module) |
Disables sending NACK on address match. More... | |
Callbacks | |
void | i2c_slave_register_callback (struct i2c_slave_module *const module, i2c_slave_callback_t callback, enum i2c_slave_callback callback_type) |
Registers callback for the specified callback type. More... | |
void | i2c_slave_unregister_callback (struct i2c_slave_module *const module, enum i2c_slave_callback callback_type) |
Unregisters callback for the specified callback type. More... | |
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) |
Initiates a reads packet operation. More... | |
enum status_code | i2c_slave_write_packet_job (struct i2c_slave_module *const module, struct i2c_slave_packet *const packet) |
Initiates a write packet operation. More... | |
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... | |
Callbacks | |
void | i2c_master_register_callback (struct i2c_master_module *const module, i2c_master_callback_t callback, enum i2c_master_callback callback_type) |
Registers callback for the specified callback type. More... | |
void | i2c_master_unregister_callback (struct i2c_master_module *const module, enum i2c_master_callback callback_type) |
Unregisters callback for the specified callback type. More... | |
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... | |
Read and Write, Interrupt-driven | |
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) |
Initiates a read packet operation. More... | |
enum status_code | i2c_master_read_packet_job_no_stop (struct i2c_master_module *const module, struct i2c_master_packet *const packet) |
Initiates a read packet operation without sending a STOP condition when done. More... | |
enum status_code | i2c_master_read_packet_job_no_nack (struct i2c_master_module *const module, struct i2c_master_packet *const packet) |
Initiates a read packet operation without sending a NACK signal and a STOP condition when done. More... | |
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) |
Initiates a write packet operation. More... | |
enum status_code | i2c_master_write_packet_job_no_stop (struct i2c_master_module *const module, struct i2c_master_packet *const packet) |
Initiates a write packet operation without sending a STOP condition when done. More... | |
static void | i2c_master_cancel_job (struct i2c_master_module *const module) |
Cancel any currently ongoing operation. More... | |
static enum status_code | i2c_master_get_job_status (struct i2c_master_module *const module) |
Get status from ongoing job. 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) |
Initializes the requested I2C hardware module. More... | |
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) |
Resets the hardware module. More... | |
Read and Write | |
enum status_code | i2c_master_read_packet_wait (struct i2c_master_module *const module, struct i2c_master_packet *const packet) |
Reads data packet from slave. More... | |
enum status_code | i2c_master_read_packet_wait_no_stop (struct i2c_master_module *const module, struct i2c_master_packet *const packet) |
Reads data packet from slave without sending a stop condition when done. More... | |
enum status_code | i2c_master_write_packet_wait (struct i2c_master_module *const module, struct i2c_master_packet *const packet) |
Writes data packet to slave. More... | |
enum status_code | i2c_master_write_packet_wait_no_stop (struct i2c_master_module *const module, struct i2c_master_packet *const packet) |
Writes data packet to slave without sending a stop condition when done. More... | |
void | i2c_master_send_stop (struct i2c_master_module *const module) |
Sends stop condition on bus. More... | |
void | i2c_master_send_nack (struct i2c_master_module *const module) |
Sends nack signal on bus. More... | |
enum status_code | i2c_master_read_byte (struct i2c_master_module *const module, uint8_t *byte) |
Reads one byte data from slave. More... | |
enum status_code | i2c_master_write_byte (struct i2c_master_module *const module, uint8_t byte) |
Write one byte data to slave. More... | |
enum status_code | i2c_master_read_packet_wait_no_nack (struct i2c_master_module *const module, struct i2c_master_packet *const packet) |
Reads data packet from slave without sending a nack signal and a stop condition when done. More... | |
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... | |
#define FEATURE_I2C_10_BIT_ADDRESS |
10-bit address support
#define FEATURE_I2C_DMA_SUPPORT |
#define FEATURE_I2C_FAST_MODE_PLUS_AND_HIGH_SPEED |
Fast mode plus and high speed support.
#define FEATURE_I2C_SCL_EXTEND_TIMEOUT |
SCL extend timeout support.
#define FEATURE_I2C_SCL_STRETCH_MODE |
SCL stretch mode support.
#define I2C_SLAVE_STATUS_ADDRESS_MATCH (1UL << 0) |
Address Match.
Referenced by i2c_slave_clear_status(), and i2c_slave_get_status().
#define I2C_SLAVE_STATUS_BUS_ERROR (1UL << 8) |
Bus error.
Referenced by i2c_slave_clear_status(), and i2c_slave_get_status().
#define I2C_SLAVE_STATUS_CLOCK_HOLD (1UL << 3) |
Clock Hold.
Referenced by i2c_slave_get_status().
#define I2C_SLAVE_STATUS_COLLISION (1UL << 7) |
Transmit Collision.
Referenced by i2c_slave_clear_status(), and i2c_slave_get_status().
#define I2C_SLAVE_STATUS_DATA_READY (1UL << 1) |
Data Ready.
Referenced by i2c_slave_clear_status(), and i2c_slave_get_status().
#define I2C_SLAVE_STATUS_RECEIVED_NACK (1UL << 6) |
#define I2C_SLAVE_STATUS_REPEATED_START (1UL << 5) |
Repeated Start.
Referenced by i2c_slave_get_status().
#define I2C_SLAVE_STATUS_SCL_LOW_TIMEOUT (1UL << 4) |
SCL Low Timeout.
Referenced by i2c_slave_clear_status(), and i2c_slave_get_status().
#define I2C_SLAVE_STATUS_STOP_RECEIVED (1UL << 2) |
Stop Received.
Referenced by i2c_slave_clear_status(), and i2c_slave_get_status().
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 i2c_master_reset(), main_cdc_disable(), 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 adp_interface_init(), 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 adp_interface_init(), 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 | ||
) |
Initializes the requested I2C hardware module.
Initializes the SERCOM I2C master device requested and sets the provided software module struct. Run this function before any further use of the driver.
[out] | module | Pointer to software module struct |
[in] | hw | Pointer to the hardware instance |
[in] | config | Pointer to the configuration struct |
STATUS_OK | Module initiated correctly |
STATUS_ERR_DENIED | If module is enabled |
STATUS_BUSY | If module is busy resetting |
STATUS_ERR_ALREADY_INITIALIZED | If setting other GCLK generator than previously set |
STATUS_ERR_BAUDRATE_UNAVAILABLE | If given baudrate is not compatible with set GCLK frequency |
References _i2c_master_interrupt_handler(), _sercom_get_sercom_inst_index(), _sercom_instances, _sercom_set_handler(), Assert, i2c_master_config::generator_source, NULL, sercom_set_gclk_generator(), system_gclk_chan_config::source_generator, STATUS_BUSY, STATUS_ERR_DENIED, STATUS_OK, system_apb_clock_set_mask(), SYSTEM_CLOCK_APB_APBC, system_gclk_chan_enable(), system_gclk_chan_get_config_defaults(), and system_gclk_chan_set_config().
Referenced by adp_interface_init(), 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 |
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, 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 | ||
) |
Reads one byte data from slave.
[in,out] | module | Pointer to software module struct |
[out] | byte | Read one byte data to slave |
STATUS_OK | One byte was read successfully |
STATUS_ERR_TIMEOUT | If no response was given within specified timeout period |
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 |
References _i2c_master_wait_for_bus().
enum status_code i2c_master_read_bytes | ( | struct i2c_master_module *const | module, |
struct i2c_master_packet *const | packet | ||
) |
Starts a read bytes operation.
[in,out] | module | Pointer to software module struct |
[in,out] | packet | Pointer to I2C packet to transfer |
STATUS_OK | If reading was started successfully |
STATUS_BUSY | If module is currently busy with another transfer |
References Assert, i2c_master_packet::data, i2c_master_packet::data_length, I2C_TRANSFER_READ, STATUS_BUSY, and STATUS_OK.
enum status_code i2c_master_read_packet_job | ( | struct i2c_master_module *const | module, |
struct i2c_master_packet *const | packet | ||
) |
Initiates a read packet operation.
Reads a data packet from the specified slave address on the I2C bus. This is the non-blocking equivalent of i2c_master_read_packet_wait.
[in,out] | module | Pointer to software module struct |
[in,out] | packet | Pointer to I2C packet to transfer |
STATUS_OK | If reading was started successfully |
STATUS_BUSY | If module is currently busy with another transfer |
References _i2c_master_read_packet(), Assert, and STATUS_BUSY.
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 | ||
) |
Initiates a read packet operation without sending a NACK signal and a STOP condition when done.
Reads a data packet from the specified slave address on the I2C bus without sending a nack and a stop condition, thus retaining ownership of the bus when done. To end the transaction, a read or write with stop condition must be performed.
This is the non-blocking equivalent of i2c_master_read_packet_wait_no_stop.
[in,out] | module | Pointer to software module struct |
[in,out] | packet | Pointer to I2C packet to transfer |
STATUS_OK | If reading was started successfully |
STATUS_BUSY | If module is currently busy with another operation |
References _i2c_master_read_packet(), Assert, and STATUS_BUSY.
enum status_code i2c_master_read_packet_job_no_stop | ( | struct i2c_master_module *const | module, |
struct i2c_master_packet *const | packet | ||
) |
Initiates a read packet operation without sending a STOP condition when done.
Reads a data packet from the specified slave address on the I2C bus without sending a stop condition, thus retaining ownership of the bus when done. To end the transaction, a read or write with stop condition must be performed.
This is the non-blocking equivalent of i2c_master_read_packet_wait_no_stop.
[in,out] | module | Pointer to software module struct |
[in,out] | packet | Pointer to I2C packet to transfer |
STATUS_OK | If reading was started successfully |
STATUS_BUSY | If module is currently busy with another operation |
References _i2c_master_read_packet(), Assert, and STATUS_BUSY.
enum status_code i2c_master_read_packet_wait | ( | struct i2c_master_module *const | module, |
struct i2c_master_packet *const | packet | ||
) |
Reads data packet from slave.
Reads a data packet from the specified slave address on the I2C bus and sends a stop condition when finished.
[in,out] | module | Pointer to software module struct |
[in,out] | packet | Pointer to I2C packet to transfer |
STATUS_OK | The packet was read successfully |
STATUS_ERR_TIMEOUT | If no response was given within specified timeout period |
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 |
References _i2c_master_read_packet(), Assert, and STATUS_BUSY.
Referenced by adp_interface_read_response(), at30tse_eeprom_read(), at30tse_read_register(), edbg_eui_read_eui64(), io1_board_get_info(), main(), run_i2c_full_speed_test(), run_i2c_master_transfer_test(), and show_extension_boards_information().
enum status_code i2c_master_read_packet_wait_no_nack | ( | struct i2c_master_module *const | module, |
struct i2c_master_packet *const | packet | ||
) |
Reads data packet from slave without sending a nack signal and a stop condition when done.
Starts blocking read operation. Reads a data packet from the specified slave address on the I2C bus without sending a nack signal and a stop condition when done, thus retaining ownership of the bus when done. To end the transaction, a read or write with stop condition must be performed.
[in,out] | module | Pointer to software module struct |
[in,out] | packet | Pointer to I2C packet to transfer |
STATUS_OK | The packet was read successfully |
STATUS_ERR_TIMEOUT | If no response was given within specified timeout period |
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 |
References _i2c_master_read_packet(), Assert, and STATUS_BUSY.
enum status_code i2c_master_read_packet_wait_no_stop | ( | struct i2c_master_module *const | module, |
struct i2c_master_packet *const | packet | ||
) |
Reads data packet from slave without sending a stop condition when done.
Reads a data packet from the specified slave address on the I2C bus without sending a stop condition when done, thus retaining ownership of the bus when done. To end the transaction, a read or write with stop condition must be performed.
[in,out] | module | Pointer to software module struct |
[in,out] | packet | Pointer to I2C packet to transfer |
STATUS_OK | The packet was read successfully |
STATUS_ERR_TIMEOUT | If no response was given within specified timeout period |
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 |
References _i2c_master_read_packet(), Assert, and STATUS_BUSY.
Referenced by run_i2c_master_transfer_test().
void i2c_master_register_callback | ( | struct i2c_master_module *const | module, |
const i2c_master_callback_t | callback, | ||
enum i2c_master_callback | callback_type | ||
) |
Registers callback for the specified callback type.
Associates the given callback function with the specified callback type.
To enable the callback, the i2c_master_enable_callback function must be used.
[in,out] | module | Pointer to the software module struct |
[in] | callback | Pointer to the function desired for the specified callback |
[in] | callback_type | Callback type to register |
References Assert, and callback.
Referenced by configure_i2c_callbacks().
void i2c_master_reset | ( | struct i2c_master_module *const | module | ) |
Resets the hardware module.
Reset the module to hardware defaults.
[in,out] | module | Pointer to software module structure |
References _sercom_get_interrupt_vector(), Assert, i2c_master_disable(), system_interrupt_clear_pending(), system_interrupt_enter_critical_section(), and system_interrupt_leave_critical_section().
Referenced by edbg_eui_read_eui64().
void i2c_master_send_nack | ( | struct i2c_master_module *const | module | ) |
Sends nack signal on bus.
Sends a nack signal on bus.
[in,out] | module | Pointer to the software instance struct |
References Assert.
void i2c_master_send_stop | ( | struct i2c_master_module *const | module | ) |
Sends stop condition on bus.
Sends a stop condition on bus.
[in,out] | module | Pointer to the software instance struct |
References Assert.
|
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 | ||
) |
Write one byte data to slave.
[in,out] | module | Pointer to software module struct |
[in] | byte | Send one byte data to slave |
STATUS_OK | One byte was write successfully |
STATUS_ERR_TIMEOUT | If no response was given within specified timeout period |
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 |
References _i2c_master_wait_for_bus().
enum status_code i2c_master_write_bytes | ( | struct i2c_master_module *const | module, |
struct i2c_master_packet *const | packet | ||
) |
Starts a write bytes operation.
[in,out] | module | Pointer to software module struct |
[in,out] | packet | Pointer to I2C packet to transfer |
STATUS_OK | If writing was started successfully |
STATUS_BUSY | If module is currently busy with another transfer |
References Assert, i2c_master_packet::data, i2c_master_packet::data_length, I2C_TRANSFER_WRITE, STATUS_BUSY, and STATUS_OK.
enum status_code i2c_master_write_packet_job | ( | struct i2c_master_module *const | module, |
struct i2c_master_packet *const | packet | ||
) |
Initiates a write packet operation.
Writes a data packet to the specified slave address on the I2C bus. This is the non-blocking equivalent of i2c_master_write_packet_wait.
[in,out] | module | Pointer to software module struct |
[in,out] | packet | Pointer to I2C packet to transfer |
STATUS_OK | If writing was started successfully |
STATUS_BUSY | If module is currently busy with another transfer |
References _i2c_master_write_packet(), Assert, and STATUS_BUSY.
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 | ||
) |
Initiates a write packet operation without sending a STOP condition when done.
Writes a data packet to the specified slave address on the I2C bus without sending a stop condition, thus retaining ownership of the bus when done. To end the transaction, a read or write with stop condition or sending a stop with the i2c_master_send_stop function must be performed.
This is the non-blocking equivalent of i2c_master_write_packet_wait_no_stop.
[in,out] | module | Pointer to software module struct |
[in,out] | packet | Pointer to I2C packet to transfer |
STATUS_OK | If writing was started successfully |
STATUS_BUSY | If module is currently busy with another |
References _i2c_master_write_packet(), Assert, and STATUS_BUSY.
enum status_code i2c_master_write_packet_wait | ( | struct i2c_master_module *const | module, |
struct i2c_master_packet *const | packet | ||
) |
Writes data packet to slave.
Writes a data packet to the specified slave address on the I2C bus and sends a stop condition when finished.
[in,out] | module | Pointer to software module struct |
[in,out] | packet | Pointer to I2C packet to transfer |
STATUS_OK | If packet was write successfully |
STATUS_BUSY | If master module is busy with a job |
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 last data sent |
References _i2c_master_write_packet(), Assert, and STATUS_BUSY.
Referenced by adp_interface_send(), at30tse_eeprom_write(), at30tse_set_register_pointer(), at30tse_write_register(), main(), run_i2c_full_speed_test(), and run_i2c_master_transfer_test().
enum status_code i2c_master_write_packet_wait_no_stop | ( | struct i2c_master_module *const | module, |
struct i2c_master_packet *const | packet | ||
) |
Writes data packet to slave without sending a stop condition when done.
Writes a data packet to the specified slave address on the I2C bus without sending a stop condition, thus retaining ownership of the bus when done. To end the transaction, a read or write with stop condition or sending a stop with the i2c_master_send_stop function must be performed.
[in,out] | module | Pointer to software module struct |
[in,out] | packet | Pointer to I2C packet to transfer |
STATUS_OK | If packet was write successfully |
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 do not want more data |
References _i2c_master_write_packet(), Assert, and STATUS_BUSY.
Referenced by at30tse_eeprom_read(), at30tse_read_register(), edbg_eui_read_eui64(), io1_board_get_info(), run_i2c_master_transfer_test(), and show_extension_boards_information().
|
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 | ||
) |
Clears a module status flag.
Clears the given status flag of the module.
[in] | module | Pointer to the I2C software device struct |
[in] | status_flags | Bit mask of status flags to clear |
References Assert, I2C_SLAVE_STATUS_ADDRESS_MATCH, I2C_SLAVE_STATUS_BUS_ERROR, I2C_SLAVE_STATUS_COLLISION, I2C_SLAVE_STATUS_DATA_READY, I2C_SLAVE_STATUS_SCL_LOW_TIMEOUT, and I2C_SLAVE_STATUS_STOP_RECEIVED.
|
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().
Referenced by i2c_slave_reset().
|
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 | ) |
Disables sending NACK on address match.
Disables sending of NACK on address match, thus acknowledging incoming transactions.
[in,out] | module | Pointer to software module structure |
References Assert.
|
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 |
|
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 check_boot_mode(), 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 | ) |
Enables sending of NACK on address match.
Enables sending of NACK on address match, thus discarding any incoming transaction.
[in,out] | module | Pointer to software module structure |
References Assert.
|
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 check_boot_mode(), configure_i2c_slave(), and run_i2c_init_test().
enum i2c_slave_direction i2c_slave_get_direction_wait | ( | struct i2c_slave_module *const | module | ) |
Waits for a start condition on the bus.
Waits for the master to issue a start condition on the bus.
[in] | module | Pointer to software module structure |
I2C_SLAVE_DIRECTION_NONE | No request from master within timeout period |
I2C_SLAVE_DIRECTION_READ | Write request from master |
I2C_SLAVE_DIRECTION_WRITE | Read request from master |
References _i2c_slave_wait_for_bus(), Assert, I2C_SLAVE_DIRECTION_NONE, I2C_SLAVE_DIRECTION_READ, I2C_SLAVE_DIRECTION_WRITE, status, and STATUS_OK.
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 | ) |
Retrieves the current module status.
Checks the status of the module and returns it as a bitmask of status flags.
[in] | module | Pointer to the I2C slave software device struct |
I2C_SLAVE_STATUS_ADDRESS_MATCH | A valid address has been received |
I2C_SLAVE_STATUS_DATA_READY | A I2C slave byte transmission is successfully completed |
I2C_SLAVE_STATUS_STOP_RECEIVED | A stop condition is detected for a transaction being processed |
I2C_SLAVE_STATUS_CLOCK_HOLD | The slave is holding the SCL line low |
I2C_SLAVE_STATUS_SCL_LOW_TIMEOUT | An SCL low time-out has occurred |
I2C_SLAVE_STATUS_REPEATED_START | Indicates a repeated start, only valid if I2C_SLAVE_STATUS_ADDRESS_MATCH is set |
I2C_SLAVE_STATUS_RECEIVED_NACK | The last data packet sent was not acknowledged |
I2C_SLAVE_STATUS_COLLISION | The I2C slave was not able to transmit a high data or NACK bit |
I2C_SLAVE_STATUS_BUS_ERROR | An illegal bus condition has occurred on the bus |
References Assert, I2C_SLAVE_STATUS_ADDRESS_MATCH, I2C_SLAVE_STATUS_BUS_ERROR, I2C_SLAVE_STATUS_CLOCK_HOLD, I2C_SLAVE_STATUS_COLLISION, I2C_SLAVE_STATUS_DATA_READY, I2C_SLAVE_STATUS_RECEIVED_NACK, I2C_SLAVE_STATUS_REPEATED_START, I2C_SLAVE_STATUS_SCL_LOW_TIMEOUT, I2C_SLAVE_STATUS_STOP_RECEIVED, and status.
enum status_code i2c_slave_init | ( | struct i2c_slave_module *const | module, |
Sercom *const | hw, | ||
const struct i2c_slave_config *const | config | ||
) |
Initializes the requested I2C hardware module.
Initializes the SERCOM I2C slave device requested and sets the provided software module struct. Run this function before any further use of the driver.
[out] | module | Pointer to software module struct |
[in] | hw | Pointer to the hardware instance |
[in] | config | Pointer to the configuration struct |
STATUS_OK | Module initiated correctly |
STATUS_ERR_DENIED | If module is enabled |
STATUS_BUSY | If module is busy resetting |
STATUS_ERR_ALREADY_INITIALIZED | If setting other GCLK generator than previously set |
References _i2c_slave_interrupt_handler(), _i2c_slave_set_config(), _sercom_get_sercom_inst_index(), _sercom_instances, _sercom_set_handler(), Assert, i2c_slave_config::enable_nack_on_address, i2c_slave_config::generator_source, sercom_set_gclk_generator(), system_gclk_chan_config::source_generator, STATUS_BUSY, STATUS_ERR_DENIED, system_apb_clock_set_mask(), SYSTEM_CLOCK_APB_APBC, system_gclk_chan_enable(), system_gclk_chan_get_config_defaults(), and system_gclk_chan_set_config().
Referenced by check_boot_mode(), 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, 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 | ||
) |
Initiates a reads packet operation.
Reads a data packet from the master. A write request must be initiated by the master before the packet can be read.
The I2C_SLAVE_CALLBACK_WRITE_REQUEST callback can be used to call this function.
[in,out] | module | Pointer to software module struct |
[in,out] | packet | Pointer to I2C packet to transfer |
STATUS_OK | If reading was started successfully |
STATUS_BUSY | If module is currently busy with another transfer |
References Assert, i2c_slave_packet::data, i2c_slave_packet::data_length, STATUS_BUSY, and STATUS_OK.
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 | ||
) |
Reads a packet from the master.
Reads a packet from the master. This will wait for the master to issue a request.
[in] | module | Pointer to software module structure |
[out] | packet | Packet to read from master |
STATUS_OK | Packet was read successfully |
STATUS_ABORTED | Master sent stop condition or repeated start before specified length of bytes was received |
STATUS_ERR_IO | There was an error in the previous transfer |
STATUS_ERR_DENIED | Start condition not received, another interrupt flag is set |
STATUS_ERR_INVALID_ARG | Invalid argument(s) was provided |
STATUS_ERR_BUSY | The I2C module is busy with a job |
STATUS_ERR_BAD_FORMAT | Master wants to read data |
STATUS_ERR_ERR_OVERFLOW | Last byte received overflows buffer |
References _i2c_slave_wait_for_bus(), Assert, i2c_slave_packet::data, i2c_slave_packet::data_length, i, length, status, STATUS_ABORTED, STATUS_BUSY, STATUS_ERR_BAD_FORMAT, STATUS_ERR_DENIED, STATUS_ERR_INVALID_ARG, STATUS_ERR_IO, and STATUS_OK.
Referenced by fetch_data(), get_length(), and main().
void i2c_slave_register_callback | ( | struct i2c_slave_module *const | module, |
i2c_slave_callback_t | callback, | ||
enum i2c_slave_callback | callback_type | ||
) |
Registers callback for the specified callback type.
Associates the given callback function with the specified callback type. To enable the callback, the i2c_slave_enable_callback function must be used.
[in,out] | module | Pointer to the software module struct |
[in] | callback | Pointer to the function desired for the specified callback |
[in] | callback_type | Callback type to register |
References Assert, and callback.
Referenced by configure_i2c_slave_callbacks().
void i2c_slave_reset | ( | struct i2c_slave_module *const | module | ) |
Resets the hardware module.
This will reset the module to hardware defaults.
[in,out] | module | Pointer to software module structure |
References _sercom_get_interrupt_vector(), Assert, i2c_slave_disable(), NULL, system_interrupt_clear_pending(), system_interrupt_enter_critical_section(), and system_interrupt_leave_critical_section().
|
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 | ||
) |
Initiates a write packet operation.
Writes a data packet to the master. A read request must be initiated by the master before the packet can be written.
The I2C_SLAVE_CALLBACK_READ_REQUEST callback can be used to call this function.
[in,out] | module | Pointer to software module struct |
[in,out] | packet | Pointer to I2C packet to transfer |
STATUS_OK | If writing was started successfully |
STATUS_BUSY | If module is currently busy with another transfer |
References Assert, i2c_slave_packet::data, i2c_slave_packet::data_length, STATUS_BUSY, and STATUS_OK.
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 | ||
) |
Writes a packet to the master.
Writes a packet to the master. This will wait for the master to issue a request.
[in] | module | Pointer to software module structure |
[in] | packet | Packet to write to master |
STATUS_OK | Packet was written successfully |
STATUS_ERR_DENIED | Start condition not received, another interrupt flag is set |
STATUS_ERR_IO | There was an error in the previous transfer |
STATUS_ERR_BAD_FORMAT | Master wants to write data |
STATUS_ERR_INVALID_ARG | Invalid argument(s) was provided |
STATUS_ERR_BUSY | The I2C module is busy with a job |
STATUS_ERR_ERR_OVERFLOW | Master NACKed before entire packet was transferred |
STATUS_ERR_TIMEOUT | No response was given within the timeout period |
References _i2c_slave_wait_for_bus(), Assert, i2c_slave_packet::data, i2c_slave_packet::data_length, i, length, status, STATUS_BUSY, STATUS_ERR_BAD_FORMAT, STATUS_ERR_DENIED, STATUS_ERR_INVALID_ARG, STATUS_ERR_IO, STATUS_ERR_OVERFLOW, STATUS_ERR_TIMEOUT, and STATUS_OK.
Referenced by main(), and send_ack().