Microchip® Advanced Software Framework

 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
Asfdoc_sam0_sercom_i2c_group

Modules

 

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...
 

Enumerations

enum  i2c_master_baud_rate {
  I2C_MASTER_BAUD_RATE_100KHZ = 100,
  I2C_MASTER_BAUD_RATE_400KHZ = 400,
  I2C_MASTER_BAUD_RATE_1000KHZ = 1000,
  I2C_MASTER_BAUD_RATE_3400KHZ = 3400
}
 I2C frequencies. More...
 
enum  i2c_master_callback {
  I2C_MASTER_CALLBACK_WRITE_COMPLETE = 0,
  I2C_MASTER_CALLBACK_READ_COMPLETE = 1,
  I2C_MASTER_CALLBACK_ERROR = 2
}
 Callback types. More...
 
enum  i2c_master_inactive_timeout {
  I2C_MASTER_INACTIVE_TIMEOUT_DISABLED = SERCOM_I2CM_CTRLA_INACTOUT(0),
  I2C_MASTER_INACTIVE_TIMEOUT_55US = SERCOM_I2CM_CTRLA_INACTOUT(1),
  I2C_MASTER_INACTIVE_TIMEOUT_105US = SERCOM_I2CM_CTRLA_INACTOUT(2),
  I2C_MASTER_INACTIVE_TIMEOUT_205US = SERCOM_I2CM_CTRLA_INACTOUT(3)
}
 Values for inactive bus time-out. More...
 
enum  i2c_master_interrupt_flag {
  I2C_MASTER_INTERRUPT_WRITE = 0,
  I2C_MASTER_INTERRUPT_READ = 1
}
 Interrupt flags. More...
 
enum  i2c_master_start_hold_time {
  I2C_MASTER_START_HOLD_TIME_DISABLED = SERCOM_I2CM_CTRLA_SDAHOLD(0),
  I2C_MASTER_START_HOLD_TIME_50NS_100NS = SERCOM_I2CM_CTRLA_SDAHOLD(1),
  I2C_MASTER_START_HOLD_TIME_300NS_600NS = SERCOM_I2CM_CTRLA_SDAHOLD(2),
  I2C_MASTER_START_HOLD_TIME_400NS_800NS = SERCOM_I2CM_CTRLA_SDAHOLD(3)
}
 Values for hold time after start bit. More...
 
enum  i2c_master_transfer_speed {
  I2C_MASTER_SPEED_STANDARD_AND_FAST = SERCOM_I2CM_CTRLA_SPEED(0),
  I2C_MASTER_SPEED_FAST_MODE_PLUS = SERCOM_I2CM_CTRLA_SPEED(1),
  I2C_MASTER_SPEED_HIGH_SPEED = SERCOM_I2CM_CTRLA_SPEED(2)
}
 Enum for the transfer speed. More...
 
enum  i2c_slave_address_mode {
  I2C_SLAVE_ADDRESS_MODE_MASK = SERCOM_I2CS_CTRLB_AMODE(0),
  I2C_SLAVE_ADDRESS_MODE_TWO_ADDRESSES = SERCOM_I2CS_CTRLB_AMODE(1),
  I2C_SLAVE_ADDRESS_MODE_RANGE = SERCOM_I2CS_CTRLB_AMODE(2)
}
 Enum for the possible address modes. More...
 
enum  i2c_slave_callback {
  I2C_SLAVE_CALLBACK_WRITE_COMPLETE,
  I2C_SLAVE_CALLBACK_READ_COMPLETE,
  I2C_SLAVE_CALLBACK_READ_REQUEST,
  I2C_SLAVE_CALLBACK_WRITE_REQUEST,
  I2C_SLAVE_CALLBACK_ERROR,
  I2C_SLAVE_CALLBACK_ERROR_LAST_TRANSFER
}
 Callback types. More...
 
enum  i2c_slave_direction {
  I2C_SLAVE_DIRECTION_READ,
  I2C_SLAVE_DIRECTION_WRITE,
  I2C_SLAVE_DIRECTION_NONE
}
 Enum for the direction of a request. More...
 
enum  i2c_slave_sda_hold_time {
  I2C_SLAVE_SDA_HOLD_TIME_DISABLED,
  I2C_SLAVE_SDA_HOLD_TIME_50NS_100NS,
  I2C_SLAVE_SDA_HOLD_TIME_300NS_600NS,
  I2C_SLAVE_SDA_HOLD_TIME_400NS_800NS
}
 Enum for the possible SDA hold times with respect to the negative edge of SCL. More...
 
enum  i2c_slave_transfer_speed {
  I2C_SLAVE_SPEED_STANDARD_AND_FAST = SERCOM_I2CS_CTRLA_SPEED(0),
  I2C_SLAVE_SPEED_FAST_MODE_PLUS = SERCOM_I2CS_CTRLA_SPEED(1),
  I2C_SLAVE_SPEED_HIGH_SPEED = SERCOM_I2CS_CTRLA_SPEED(2)
}
 Enum for the transfer speed. 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...
 

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)
 
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_job_no_nack (struct i2c_master_module *const module, struct i2c_master_packet *const packet)
 
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)
 
enum status_code i2c_master_write_packet_job_no_stop (struct i2c_master_module *const module, struct i2c_master_packet *const packet)
 
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)
 
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.

Note
Should only be cleared internally by driver.
#define I2C_SLAVE_STATUS_BUS_ERROR   (1UL << 8)

Bus error.

#define I2C_SLAVE_STATUS_CLOCK_HOLD   (1UL << 3)

Clock Hold.

Note
Cannot be cleared, only valid when I2C_SLAVE_STATUS_ADDRESS_MATCH is set.
#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.

Note
Cannot be cleared.
#define I2C_SLAVE_STATUS_REPEATED_START   (1UL << 5)

Repeated Start.

Note
Cannot be cleared, only valid when I2C_SLAVE_STATUS_ADDRESS_MATCH is set.
#define I2C_SLAVE_STATUS_SCL_LOW_TIMEOUT   (1UL << 4)

SCL Low Timeout.

#define I2C_SLAVE_STATUS_STOP_RECEIVED   (1UL << 2)

Stop Received.

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.

Enumerator
I2C_MASTER_BAUD_RATE_100KHZ 

Baud rate at 100KHz (Standard-mode)

I2C_MASTER_BAUD_RATE_400KHZ 

Baud rate at 400KHz (Fast-mode)

I2C_MASTER_BAUD_RATE_1000KHZ 

Baud rate at 1MHz (Fast-mode Plus)

I2C_MASTER_BAUD_RATE_3400KHZ 

Baud rate at 3.4MHz (High-speed mode)

Callback types.

The available callback types for the I2C master module.

Enumerator
I2C_MASTER_CALLBACK_WRITE_COMPLETE 

Callback for packet write complete.

I2C_MASTER_CALLBACK_READ_COMPLETE 

Callback for packet read complete.

I2C_MASTER_CALLBACK_ERROR 

Callback for error.

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.

Enumerator
I2C_MASTER_INACTIVE_TIMEOUT_DISABLED 

Inactive bus time-out disabled.

I2C_MASTER_INACTIVE_TIMEOUT_55US 

Inactive bus time-out 5-6 SCL cycle time-out.

I2C_MASTER_INACTIVE_TIMEOUT_105US 

Inactive bus time-out 10-11 SCL cycle time-out.

I2C_MASTER_INACTIVE_TIMEOUT_205US 

Inactive bus time-out 20-21 SCL cycle time-out.

Interrupt flags.

Flags used when reading or setting interrupt flags.

Enumerator
I2C_MASTER_INTERRUPT_WRITE 

Interrupt flag used for write.

I2C_MASTER_INTERRUPT_READ 

Interrupt flag used for read.

Values for hold time after start bit.

Values for the possible I2C master mode SDA internal hold times after start bit has been sent.

Enumerator
I2C_MASTER_START_HOLD_TIME_DISABLED 

Internal SDA hold time disabled.

I2C_MASTER_START_HOLD_TIME_50NS_100NS 

Internal SDA hold time 50ns - 100ns.

I2C_MASTER_START_HOLD_TIME_300NS_600NS 

Internal SDA hold time 300ns - 600ns.

I2C_MASTER_START_HOLD_TIME_400NS_800NS 

Internal SDA hold time 400ns - 800ns.

Enum for the transfer speed.

Enum for the transfer speed.

Enumerator
I2C_MASTER_SPEED_STANDARD_AND_FAST 

Standard-mode (Sm) up to 100KHz and Fast-mode (Fm) up to 400KHz.

I2C_MASTER_SPEED_FAST_MODE_PLUS 

Fast-mode Plus (Fm+) up to 1MHz.

I2C_MASTER_SPEED_HIGH_SPEED 

High-speed mode (Hs-mode) up to 3.4MHz.

Enum for the possible address modes.

Enum for the possible address modes.

Enumerator
I2C_SLAVE_ADDRESS_MODE_MASK 

Address match on address_mask used as a mask to address.

I2C_SLAVE_ADDRESS_MODE_TWO_ADDRESSES 

Address math on both address and address_mask.

I2C_SLAVE_ADDRESS_MODE_RANGE 

Address match on range of addresses between and including address and address_mask.

Callback types.

The available callback types for the I2C slave.

Enumerator
I2C_SLAVE_CALLBACK_WRITE_COMPLETE 

Callback for packet write complete.

I2C_SLAVE_CALLBACK_READ_COMPLETE 

Callback for packet read complete.

I2C_SLAVE_CALLBACK_READ_REQUEST 

Callback for read request from master - can be used to issue a write.

I2C_SLAVE_CALLBACK_WRITE_REQUEST 

Callback for write request from master - can be used to issue a read.

I2C_SLAVE_CALLBACK_ERROR 

Callback for error.

I2C_SLAVE_CALLBACK_ERROR_LAST_TRANSFER 

Callback for error in last transfer.

Discovered on a new address interrupt.

Enum for the direction of a request.

Enum for the direction of a request.

Enumerator
I2C_SLAVE_DIRECTION_READ 

Read.

I2C_SLAVE_DIRECTION_WRITE 

Write.

I2C_SLAVE_DIRECTION_NONE 

No 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.

Enumerator
I2C_SLAVE_SDA_HOLD_TIME_DISABLED 

SDA hold time disabled.

I2C_SLAVE_SDA_HOLD_TIME_50NS_100NS 

SDA hold time 50ns - 100ns.

I2C_SLAVE_SDA_HOLD_TIME_300NS_600NS 

SDA hold time 300ns - 600ns.

I2C_SLAVE_SDA_HOLD_TIME_400NS_800NS 

SDA hold time 400ns - 800ns.

Enum for the transfer speed.

Enum for the transfer speed.

Enumerator
I2C_SLAVE_SPEED_STANDARD_AND_FAST 

Standard-mode (Sm) up to 100KHz and Fast-mode (Fm) up to 400KHz.

I2C_SLAVE_SPEED_FAST_MODE_PLUS 

Fast-mode Plus (Fm+) up to 1MHz.

I2C_SLAVE_SPEED_HIGH_SPEED 

High-speed mode (Hs-mode) up to 3.4MHz.

static void i2c_master_cancel_job ( struct i2c_master_module *const  module)
inlinestatic

Cancel any currently ongoing operation.

Terminates the running transfer operation.

Parameters
[in,out]modulePointer to software module structure

References Assert, and STATUS_ABORTED.

static void i2c_master_disable ( const struct i2c_master_module *const  module)
inlinestatic

Disable the I2C module.

Disables the requested I2C module.

Parameters
[in]modulePointer 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().

static void i2c_master_disable_callback ( struct i2c_master_module *const  module,
enum i2c_master_callback  callback_type 
)
inlinestatic

Disables callback.

Disables the callback specified by the callback_type.

Parameters
[in,out]modulePointer to the software module struct
[in]callback_typeCallback type to disable

References Assert.

static void i2c_master_dma_set_transfer ( struct i2c_master_module *const  module,
uint16_t  addr,
uint8_t  length,
enum i2c_transfer_direction  direction 
)
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.

Parameters
[in,out]modulePointer to the driver instance to lock
[in]addrI2C slave address
[in]lengthI2C transfer length with DMA
[in]directionI2C transfer direction

Referenced by main().

static void i2c_master_enable ( const struct i2c_master_module *const  module)
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.

Parameters
[in]modulePointer 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().

static void i2c_master_enable_callback ( struct i2c_master_module *const  module,
enum i2c_master_callback  callback_type 
)
inlinestatic

Enables callback.

Enables the callback specified by the callback_type.

Parameters
[in,out]modulePointer to the software module struct
[in]callback_typeCallback type to enable

References Assert.

Referenced by configure_i2c_callbacks().

static void i2c_master_get_config_defaults ( struct i2c_master_config *const  config)
inlinestatic

Gets the I2C master default configurations.

Use to initialize the configuration structure to known default values.

The default configuration is as follows:

  • Baudrate 100KHz
  • GCLK generator 0
  • Do not run in standby
  • Start bit hold time 300ns - 600ns
  • Buffer timeout = 65535
  • Unknown bus status timeout = 65535
  • Do not run in standby
  • PINMUX_DEFAULT for SERCOM pads

Those default configuration only available if the device supports it:

  • High speed baudrate 3.4MHz
  • Standard-mode and Fast-mode transfer speed
  • SCL stretch disabled
  • Slave SCL low extend time-out disabled
  • Master SCL low extend time-out disabled
Parameters
[out]configPointer 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().

static enum status_code i2c_master_get_job_status ( struct i2c_master_module *const  module)
inlinestatic

Get status from ongoing job.

Will return the status of a transfer operation.

Parameters
[in]modulePointer to software module structure
Returns
Last status code from transfer operation.
Return values
STATUS_OKNo error has occurred
STATUS_BUSYIf transfer is in progress
STATUS_BUSYIf master module is busy
STATUS_ERR_DENIEDIf error on bus
STATUS_ERR_PACKET_COLLISIONIf arbitration is lost
STATUS_ERR_BAD_ADDRESSIf slave is busy, or no slave acknowledged the address
STATUS_ERR_TIMEOUTIf timeout occurred
STATUS_ERR_OVERFLOWIf 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 
)
static bool i2c_master_is_syncing ( const struct i2c_master_module *const  module)
inlinestatic

Returns the synchronization status of the module.

Returns the synchronization status of the module.

Parameters
[in]modulePointer to software module structure
Returns
Status of the synchronization.
Return values
trueModule is busy synchronizing
falseModule is not synchronizing

References Assert.

static enum status_code i2c_master_lock ( struct i2c_master_module *const  module)
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.

Parameters
[in,out]modulePointer to the driver instance to lock
Return values
STATUS_OKIf the module was locked
STATUS_BUSYIf 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 
)
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 
)
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)
static void i2c_master_unlock ( struct i2c_master_module *const  module)
inlinestatic

Unlock driver instance.

This function clears the instance lock, indicating that it is available for use.

Parameters
[in,out]modulePointer to the driver instance to lock
Return values
STATUS_OKIf the module was locked
STATUS_BUSYIf 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_no_stop ( struct i2c_master_module *const  module,
struct i2c_master_packet *const  packet 
)
static void i2c_slave_cancel_job ( struct i2c_slave_module *const  module)
inlinestatic

Cancels any currently ongoing operation.

Terminates the running transfer operation.

Parameters
[in,out]modulePointer to software module structure

References Assert.

void i2c_slave_clear_status ( struct i2c_slave_module *const  module,
uint32_t  status_flags 
)
static void i2c_slave_disable ( const struct i2c_slave_module *const  module)
inlinestatic

Disables the I2C module.

This will disable the I2C module specified in the provided software module structure.

Parameters
[in]modulePointer to the software module struct

References _sercom_get_interrupt_vector(), Assert, and system_interrupt_disable().

static void i2c_slave_disable_callback ( struct i2c_slave_module *const  module,
enum i2c_slave_callback  callback_type 
)
inlinestatic

Disables callback.

Disables the callback specified by the callback_type.

Parameters
[in,out]modulePointer to the software module struct
[in]callback_typeCallback 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)
static uint8_t i2c_slave_dma_read_interrupt_status ( struct i2c_slave_module *const  module)
inlinestatic

Read SERCOM I2C interrupt status.

Read I2C interrupt status for DMA transfer.

Parameters
[in,out]modulePointer to the driver instance to lock

Referenced by main().

static void i2c_slave_dma_write_interrupt_status ( struct i2c_slave_module *const  module,
uint8_t  flag 
)
inlinestatic

Write SERCOM I2C interrupt status.

Write I2C interrupt status for DMA transfer.

Parameters
[in,out]modulePointer to the driver instance to lock
[in]flagInterrupt flag status

Referenced by main().

static void i2c_slave_enable ( const struct i2c_slave_module *const  module)
inlinestatic

Enables the I2C module.

This will enable the requested I2C module.

Parameters
[in]modulePointer 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().

static void i2c_slave_enable_callback ( struct i2c_slave_module *const  module,
enum i2c_slave_callback  callback_type 
)
inlinestatic

Enables callback.

Enables the callback specified by the callback_type.

Parameters
[in,out]modulePointer to the software module struct
[in]callback_typeCallback 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)
static void i2c_slave_get_config_defaults ( struct i2c_slave_config *const  config)
inlinestatic

Gets the I2C slave default configurations.

This will initialize the configuration structure to known default values.

The default configuration is as follows:

  • Disable SCL low timeout
  • 300ns - 600ns SDA hold time
  • Buffer timeout = 65535
  • Address with mask
  • Address = 0
  • Address mask = 0 (one single address)
  • General call address disabled
  • Address nack disabled if the interrupt driver is used
  • GCLK generator 0
  • Do not run in standby
  • PINMUX_DEFAULT for SERCOM pads

Those default configuration only available if the device supports it:

  • Not using 10-bit addressing
  • Standard-mode and Fast-mode transfer speed
  • SCL stretch disabled
  • Slave SCL low extend time-out disabled
Parameters
[out]configPointer 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().

static enum status_code i2c_slave_get_job_status ( struct i2c_slave_module *const  module)
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.

Parameters
[in,out]modulePointer to software module structure
Returns
Status of job.
Return values
STATUS_OKNo error has occurred
STATUS_BUSYTransfer is in progress
STATUS_ERR_IOA collision, timeout or bus error happened in the last transfer
STATUS_ERR_TIMEOUTA timeout occurred
STATUS_ERR_OVERFLOWData 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 
)
static bool i2c_slave_is_syncing ( const struct i2c_slave_module *const  module)
inlinestatic

Returns the synchronization status of the module.

Returns the synchronization status of the module.

Parameters
[out]modulePointer to software module structure
Returns
Status of the synchronization.
Return values
trueModule is busy synchronizing
falseModule is not synchronizing

References Assert.

static enum status_code i2c_slave_lock ( struct i2c_slave_module *const  module)
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.

Parameters
[in,out]modulePointer to the driver instance to lock
Return values
STATUS_OKIf the module was locked
STATUS_BUSYIf 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 
)
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 
)
void i2c_slave_reset ( struct i2c_slave_module *const  module)
static void i2c_slave_unlock ( struct i2c_slave_module *const  module)
inlinestatic

Unlock driver instance.

This function clears the instance lock, indicating that it is available for use.

Parameters
[in,out]modulePointer to the driver instance to lock
Return values
STATUS_OKIf the module was locked
STATUS_BUSYIf 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 
)
enum status_code i2c_slave_write_packet_wait ( struct i2c_slave_module *const  module,
struct i2c_slave_packet *const  packet 
)

Referenced by main().