Microchip® Advanced Software Framework

i2c_samd20/i2c_slave.c File Reference

SAM D20 I2C Slave Driver.

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

#include "i2c_slave.h"
#include "i2c_slave_interrupt.h"

Functions

static enum status_code _i2c_slave_set_config (struct i2c_slave_module *const module, const struct i2c_slave_config *const config)
 
static enum status_code _i2c_slave_wait_for_bus (struct i2c_slave_module *const module)
 
void i2c_slave_clear_status (struct i2c_slave_module *const module, uint32_t status_flags)
 Clears a module status flag. 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...
 
uint32_t i2c_slave_get_status (struct i2c_slave_module *const module)
 Retrieves the current module status. 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...
 
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...
 
void i2c_slave_reset (struct i2c_slave_module *const module)
 Resets the hardware module. More...
 
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...
 

static enum status_code _i2c_slave_set_config ( struct i2c_slave_module *const  module,
const struct i2c_slave_config *const  config 
)
static

Sets configuration to module

Parameters
[out]modulePointer to software module structure
[in]configConfiguration structure with configurations to set
Returns
Status of setting configuration.
Return values
STATUS_OKModule was configured correctly
STATUS_ERR_ALREADY_INITIALIZEDIf setting other GCLK generator than previously set

References _sercom_get_default_pad(), i2c_slave_config::address, i2c_slave_config::address_mask, i2c_slave_config::address_mode, Assert, i2c_slave_config::buffer_timeout, system_pinmux_config::direction, i2c_slave_config::enable_general_call_address, system_pinmux_config::mux_position, 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::sda_hold_time, STATUS_OK, system_is_debugger_present(), system_pinmux_get_config_defaults(), SYSTEM_PINMUX_PIN_DIR_OUTPUT_WITH_READBACK, and system_pinmux_pin_set_config().

Referenced by i2c_slave_init().

static enum status_code _i2c_slave_wait_for_bus ( struct i2c_slave_module *const  module)
static

Waits for answer on bus

Parameters
[in]modulePointer to software module structure
Returns
Status of bus.
Return values
STATUS_OKIf given response from slave device
STATUS_ERR_TIMEOUTIf no response was given within specified timeout period

References Assert, STATUS_ERR_TIMEOUT, and STATUS_OK.

Referenced by i2c_slave_get_direction_wait(), i2c_slave_read_packet_wait(), and i2c_slave_write_packet_wait().