Microchip® Advanced Software Framework

twihs.h File Reference

Two-Wire Interface High Speed (TWIHS) driver for SAM.

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

#include "compiler.h"

Data Structures

struct  twihs_options
 Input parameters when initializing the TWIHS module mode. More...
 
struct  twihs_packet
 Information concerning the data transmission. More...
 

Macros

#define TWIHS_TIMEOUT   30000
 Time-out value (number of attempts). More...
 
#define TWIHS_SUCCESS   0
 Return codes for TWIHS APIs. More...
 
#define TWIHS_INVALID_ARGUMENT   1
 
#define TWIHS_ARBITRATION_LOST   2
 
#define TWIHS_NO_CHIP_FOUND   3
 
#define TWIHS_RECEIVE_OVERRUN   4
 
#define TWIHS_RECEIVE_NACK   5
 
#define TWIHS_SEND_OVERRUN   6
 
#define TWIHS_SEND_NACK   7
 
#define TWIHS_BUSY   8
 
#define TWIHS_ERROR_TIMEOUT   9
 

Typedefs

typedef struct twihs_options twihs_options_t
 Input parameters when initializing the TWIHS module mode. More...
 
typedef struct twihs_packet twihs_packet_t
 Information concerning the data transmission. More...
 

Functions

static void twihs_clear_disable_clock_wait_state (Twihs *p_twihs)
 Clear clock wait state disable mode. More...
 
static void twihs_disable_alternative_command (Twihs *p_twihs)
 Enable alternative command mode. More...
 
static void twihs_disable_clock_wait_state (Twihs *p_twihs)
 Clock stretching disabled in slave mode, OVRE and UNRE will indicate overrun and underrun. More...
 
static void twihs_disable_highspeed (Twihs *p_twihs)
 Disable high speed mode. More...
 
void twihs_disable_interrupt (Twihs *p_twihs, uint32_t ul_sources)
 Disable TWIHS interrupts. More...
 
void twihs_disable_master_mode (Twihs *p_twihs)
 Disable TWIHS master mode. More...
 
static void twihs_disable_pec (Twihs *p_twihs)
 Disable packet error checking. More...
 
static void twihs_disable_slave_default_addr (Twihs *p_twihs)
 Acknowledge of the SMBus Default Address disabled. More...
 
void twihs_disable_slave_mode (Twihs *p_twihs)
 Disable TWIHS slave mode. More...
 
static void twihs_disable_slave_nack (Twihs *p_twihs)
 Normal value to be returned in the ACK cycle of the data phase in slave receiver mode. More...
 
static void twihs_disable_smbus (Twihs *p_twihs)
 Disable SMBus mode. More...
 
static void twihs_disable_smbus_host_header (Twihs *p_twihs)
 Acknowledge of the SMBus Host Header disabled. More...
 
static void twihs_enable_alternative_command (Twihs *p_twihs)
 Enable alternative command mode. More...
 
static void twihs_enable_highspeed (Twihs *p_twihs)
 Enable high speed mode. More...
 
void twihs_enable_interrupt (Twihs *p_twihs, uint32_t ul_sources)
 Enable TWIHS interrupts. More...
 
void twihs_enable_master_mode (Twihs *p_twihs)
 Enable TWIHS master mode. More...
 
static void twihs_enable_pec (Twihs *p_twihs)
 Enable packet error checking. More...
 
static void twihs_enable_slave_default_addr (Twihs *p_twihs)
 Acknowledge of the SMBus Default Address enabled. More...
 
void twihs_enable_slave_mode (Twihs *p_twihs)
 Enable TWIHS slave mode. More...
 
static void twihs_enable_slave_nack (Twihs *p_twihs)
 NACK value to be returned in the ACK cycle of the data phase in slave receiver mode. More...
 
static void twihs_enable_smbus (Twihs *p_twihs)
 Enable SMBus mode. More...
 
static void twihs_enable_smbus_host_header (Twihs *p_twihs)
 Acknowledge of the SMBus Host Header enabled. More...
 
static void twihs_enable_smbus_quick_command (Twihs *p_twihs)
 If Master mode is enabled, a SMBUS Quick Command is sent. More...
 
uint32_t twihs_get_interrupt_mask (Twihs *p_twihs)
 Read TWIHS interrupt mask. More...
 
uint32_t twihs_get_interrupt_status (Twihs *p_twihs)
 Get TWIHS interrupt status. More...
 
Pdc * twihs_get_pdc_base (Twihs *p_twihs)
 Get TWIHS PDC base address. More...
 
void twihs_mask_slave_addr (Twihs *p_twihs, uint32_t ul_mask)
 A mask can be applied on the slave device address in slave mode in order to allow multiple address answer. More...
 
uint32_t twihs_master_init (Twihs *p_twihs, const twihs_options_t *p_opt)
 Initialize TWIHS master mode. More...
 
uint32_t twihs_master_read (Twihs *p_twihs, twihs_packet_t *p_packet)
 Read multiple bytes from a TWIHS compatible slave device. More...
 
uint32_t twihs_master_write (Twihs *p_twihs, twihs_packet_t *p_packet)
 Write multiple bytes to a TWIHS compatible slave device. More...
 
uint32_t twihs_probe (Twihs *p_twihs, uint8_t uc_slave_addr)
 Test if a chip answers a given I2C address. More...
 
uint8_t twihs_read_byte (Twihs *p_twihs)
 Reads a byte from the TWIHS bus. More...
 
void twihs_read_write_protection_status (Twihs *p_twihs, uint32_t *p_status)
 Read the write protection status. More...
 
static void twihs_request_pec (Twihs *p_twihs)
 Request a packet error checking. More...
 
void twihs_reset (Twihs *p_twihs)
 Reset TWIHS. More...
 
static void twihs_send_clear (Twihs *p_twihs)
 If master mode is enabled, send a bus clear command. More...
 
void twihs_set_alternative_command (Twihs *p_twihs, uint32_t ul_alt_cmd)
 Set length/direction/PEC for alternative command mode. More...
 
void twihs_set_filter (Twihs *p_twihs, uint32_t ul_filter)
 Set the filter for TWIHS. More...
 
void twihs_set_slave_addr (Twihs *p_twihs, uint32_t ul_device_addr)
 Set TWIHS slave address. More...
 
uint32_t twihs_set_speed (Twihs *p_twihs, uint32_t ul_speed, uint32_t ul_mck)
 Set the I2C bus speed in conjunction with the clock frequency. More...
 
void twihs_set_write_protection (Twihs *p_twihs, bool flag)
 Enables/Disables write protection mode. More...
 
void twihs_slave_init (Twihs *p_twihs, uint32_t ul_device_addr)
 Initialize TWIHS slave mode. More...
 
uint32_t twihs_slave_read (Twihs *p_twihs, uint8_t *p_data)
 Read data from master. More...
 
uint32_t twihs_slave_write (Twihs *p_twihs, uint8_t *p_data)
 Write data to TWIHS bus. More...
 
void twihs_smbus_set_timing (Twihs *p_twihs, uint32_t ul_timing)
 Set the prescaler, TLOW:SEXT, TLOW:MEXT and clock high max cycles for SMBUS mode. More...
 
void twihs_write_byte (Twihs *p_twihs, uint8_t uc_byte)
 Sends a byte of data to one of the TWIHS slaves on the bus. More...
 

#define TWIHS_ARBITRATION_LOST   2
#define TWIHS_BUSY   8

Referenced by ov_write_regs().

#define TWIHS_ERROR_TIMEOUT   9

Referenced by twihs_master_read().

#define TWIHS_INVALID_ARGUMENT   1
#define TWIHS_NO_CHIP_FOUND   3
#define TWIHS_RECEIVE_NACK   5
#define TWIHS_RECEIVE_OVERRUN   4
#define TWIHS_SEND_NACK   7
#define TWIHS_SEND_OVERRUN   6
#define TWIHS_TIMEOUT   30000

Time-out value (number of attempts).

Referenced by twihs_master_read().

Input parameters when initializing the TWIHS module mode.

typedef struct twihs_packet twihs_packet_t

Information concerning the data transmission.

static void twihs_clear_disable_clock_wait_state ( Twihs *  p_twihs)
inlinestatic

Clear clock wait state disable mode.

Parameters
p_twihsBase address of the TWIHS instance.
static void twihs_disable_alternative_command ( Twihs *  p_twihs)
inlinestatic

Enable alternative command mode.

Parameters
p_twihsBase address of the TWIHS instance.
static void twihs_disable_clock_wait_state ( Twihs *  p_twihs)
inlinestatic

Clock stretching disabled in slave mode, OVRE and UNRE will indicate overrun and underrun.

Parameters
p_twihsBase address of the TWIHS instance.
static void twihs_disable_highspeed ( Twihs *  p_twihs)
inlinestatic

Disable high speed mode.

Parameters
p_twihsBase address of the TWIHS instance.
static void twihs_disable_pec ( Twihs *  p_twihs)
inlinestatic

Disable packet error checking.

Parameters
p_twihsBase address of the TWIHS instance.
static void twihs_disable_slave_default_addr ( Twihs *  p_twihs)
inlinestatic

Acknowledge of the SMBus Default Address disabled.

Parameters
p_twihsBase address of the TWIHS instance.
static void twihs_disable_slave_nack ( Twihs *  p_twihs)
inlinestatic

Normal value to be returned in the ACK cycle of the data phase in slave receiver mode.

Parameters
p_twihsBase address of the TWIHS instance.
static void twihs_disable_smbus ( Twihs *  p_twihs)
inlinestatic

Disable SMBus mode.

Parameters
p_twihsBase address of the TWIHS instance.
static void twihs_disable_smbus_host_header ( Twihs *  p_twihs)
inlinestatic

Acknowledge of the SMBus Host Header disabled.

Parameters
p_twihsBase address of the TWIHS instance.
static void twihs_enable_alternative_command ( Twihs *  p_twihs)
inlinestatic

Enable alternative command mode.

Parameters
p_twihsBase address of the TWIHS instance.
static void twihs_enable_highspeed ( Twihs *  p_twihs)
inlinestatic

Enable high speed mode.

Parameters
p_twihsBase address of the TWIHS instance.
static void twihs_enable_pec ( Twihs *  p_twihs)
inlinestatic

Enable packet error checking.

Parameters
p_twihsBase address of the TWIHS instance.
static void twihs_enable_slave_default_addr ( Twihs *  p_twihs)
inlinestatic

Acknowledge of the SMBus Default Address enabled.

Parameters
p_twihsBase address of the TWIHS instance.
static void twihs_enable_slave_nack ( Twihs *  p_twihs)
inlinestatic

NACK value to be returned in the ACK cycle of the data phase in slave receiver mode.

Parameters
p_twihsBase address of the TWIHS instance.
static void twihs_enable_smbus ( Twihs *  p_twihs)
inlinestatic

Enable SMBus mode.

Parameters
p_twihsBase address of the TWIHS instance.
static void twihs_enable_smbus_host_header ( Twihs *  p_twihs)
inlinestatic

Acknowledge of the SMBus Host Header enabled.

Parameters
p_twihsBase address of the TWIHS instance.
static void twihs_enable_smbus_quick_command ( Twihs *  p_twihs)
inlinestatic

If Master mode is enabled, a SMBUS Quick Command is sent.

Parameters
p_twihsBase address of the TWIHS instance.
static void twihs_request_pec ( Twihs *  p_twihs)
inlinestatic

Request a packet error checking.

Parameters
p_twihsBase address of the TWIHS instance.
static void twihs_send_clear ( Twihs *  p_twihs)
inlinestatic

If master mode is enabled, send a bus clear command.

Parameters
p_twihsBase address of the TWIHS instance.