Microchip® Advanced Software Framework

i2c_slave.h File Reference

SAM SERCOM I2C Slave Driver.

Copyright (c) 2013-2020 Microchip Technology Inc. and its subsidiaries.

#include "i2c_common.h"
#include <sercom.h>
#include <pinmux.h>

Data Structures

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

Macros

#define PINMUX_DEFAULT   0
 
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...
 

Enumerations

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

Functions

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

#define PINMUX_DEFAULT   0