Microchip® Advanced Software Framework

twim.h File Reference
#include <avr32/io.h>
#include "compiler.h"

Data Structures

struct  twi_options_t
 Input parameters when initializing the twi module mode. More...
 
struct  twi_package_t
 Information concerning the data transmission. More...
 
struct  twim_transfer_t
 Information concerning the data transmission. More...
 

Macros

Error Codes for the Module
#define TWI_SUCCESS   0
 
#define TWI_INVALID_ARGUMENT   -1
 
#define TWI_ARBITRATION_LOST   -2
 
#define TWI_NO_CHIP_FOUND   -3
 
#define TWI_RECEIVE_OVERRUN   -4
 
#define TWI_RECEIVE_NACK   -5
 
#define TWI_SEND_OVERRUN   -6
 
#define TWI_SEND_NACK   -7
 
#define TWI_INVALID_CLOCK_DIV   -8
 

Functions

static void twi_master_disable (volatile avr32_twim_t *twi)
 Disable Master Mode of the TWI. More...
 
static void twi_master_enable (volatile avr32_twim_t *twi)
 Enable Master Mode of the TWI. More...
 
int twi_master_init (volatile avr32_twim_t *twi, const twi_options_t *opt)
 Initialize the twi master module. More...
 
int twi_master_read (volatile avr32_twim_t *twi, const twi_package_t *package)
 Read multiple bytes from a TWI compatible slave device. More...
 
static int twi_master_write (volatile avr32_twim_t *twi, const twi_package_t *package)
 Write multiple bytes to a TWI compatible slave device. More...
 
int twi_probe (volatile avr32_twim_t *twi, char chip_addr)
 Test if a chip answers for a given twi address. More...
 
int twi_set_speed (volatile avr32_twim_t *twi, unsigned int speed, unsigned long pba_hz)
 Set the twi bus speed in conjunction with the clock frequency. More...
 
int twim_chained_transfer (volatile avr32_twim_t *twi, volatile twim_transfer_t *first, volatile twim_transfer_t *second, bool tenbit)
 
int twim_read (volatile avr32_twim_t *twi, unsigned char *buffer, int nbytes, int saddr, bool tenbit)
 
int twim_read_packet (volatile avr32_twim_t *twi, const twi_package_t *package)
 Read multiple bytes from a TWI compatible slave device. More...
 
int twim_write (volatile avr32_twim_t *twi, unsigned const char *buffer, int nbytes, int saddr, bool tenbit)
 
int twim_write_packet (volatile avr32_twim_t *twi, const twi_package_t *package)
 Write multiple bytes to a TWI compatible slave device. More...
 

#define TWI_ARBITRATION_LOST   -2

Referenced by twim_chained_transfer().

#define TWI_INVALID_ARGUMENT   -1
#define TWI_INVALID_CLOCK_DIV   -8

Referenced by twi_master_init(), and twi_set_speed().

#define TWI_NO_CHIP_FOUND   -3
#define TWI_RECEIVE_NACK   -5
#define TWI_RECEIVE_OVERRUN   -4
#define TWI_SEND_NACK   -7
#define TWI_SEND_OVERRUN   -6

static void twi_master_disable ( volatile avr32_twim_t *  twi)
inlinestatic

Disable Master Mode of the TWI.

Parameters
twiBase address of the TWI instance.
static void twi_master_enable ( volatile avr32_twim_t *  twi)
inlinestatic

Enable Master Mode of the TWI.

Parameters
twiBase address of the TWI instance.
int twi_master_init ( volatile avr32_twim_t *  twi,
const twi_options_t opt 
)

Initialize the twi master module.

Parameters
twiBase address of the TWI (i.e. &AVR32_TWI).
*optOptions for initializing the twi module (see twim_options_t)

References BSP_INTC_IntReg(), Disable_global_interrupt, Enable_global_interrupt, Is_global_interrupt_enabled, twi_options_t::pba_hz, twi_options_t::smbus, twi_options_t::speed, TWI_INVALID_CLOCK_DIV, twi_master_interrupt_handler(), twi_set_speed(), TWI_SUCCESS, and UL.

Referenced by twi_init().

int twi_master_read ( volatile avr32_twim_t *  twi,
const twi_package_t package 
)

Read multiple bytes from a TWI compatible slave device.

Parameters
twiBase address of the TWI (i.e. &AVR32_TWI).
packagePackage information and data (see twi_package_t)
Returns
TWI_SUCCESS if all bytes were read, error code otherwhise

References twi_package_t::addr, twi_package_t::addr_length, twi_package_t::buffer, twi_package_t::chip, twi_package_t::length, Swap32, TWI_SUCCESS, twim_read(), and twim_write().

Referenced by at42qt1060_get_status(), and at42qt1060_read_reg().

static int twi_master_write ( volatile avr32_twim_t *  twi,
const twi_package_t package 
)
inlinestatic

Write multiple bytes to a TWI compatible slave device.

Parameters
twiBase address of the TWI (i.e. &AVR32_TWI).
*packagePackage information and data (see twi_package_t)
Returns
TWI_SUCCESS if all bytes were written, error code otherwhise

References twi_package_t::buffer, twi_package_t::chip, twi_package_t::length, and twim_write().

Referenced by at42qt1060_read_reg(), and at42qt1060_write_reg().

int twi_probe ( volatile avr32_twim_t *  twi,
char  chip_addr 
)

Test if a chip answers for a given twi address.

Parameters
twiBase address of the TWI (i.e. &AVR32_TWI).
chip_addrAddress of the chip which is searched for
Returns
TWI_SUCCESS if a chip was found, error code otherwhise

References twi_package_t::addr, twi_package_t::addr_length, twi_package_t::buffer, twi_package_t::chip, twi_package_t::length, and twim_write_packet().

int twi_set_speed ( volatile avr32_twim_t *  twi,
unsigned int  speed,
unsigned long  pba_hz 
)

Set the twi bus speed in conjunction with the clock frequency.

Parameters
twiBase address of the TWI (i.e. &AVR32_TWI).
speedThe desired twi bus speed
pba_hzThe current running PBA clock frequency
Returns
TWI_SUCCESS

References TWI_INVALID_CLOCK_DIV, and TWI_SUCCESS.

Referenced by twi_master_init().

int twim_chained_transfer ( volatile avr32_twim_t *  twi,
volatile twim_transfer_t first,
volatile twim_transfer_t second,
bool  tenbit 
)
int twim_read ( volatile avr32_twim_t *  twi,
unsigned char *  buffer,
int  nbytes,
int  saddr,
bool  tenbit 
)
int twim_read_packet ( volatile avr32_twim_t *  twi,
const twi_package_t package 
)

Read multiple bytes from a TWI compatible slave device.

Parameters
twiBase address of the TWI (i.e. &AVR32_TWI).
packagePackage information and data (see twi_package_t)
Returns
TWI_SUCCESS if all bytes were read, error code otherwhise

References twi_package_t::addr, twi_package_t::addr_length, twi_package_t::buffer, twi_package_t::chip, Enable_global_interrupt, twi_package_t::length, TWI_RECEIVE_NACK, TWI_SUCCESS, twim_disable_interrupt(), twim_inst, twim_it_mask, twim_nack, twim_rx_data, twim_rx_nb_bytes, twim_tx_data, and twim_tx_nb_bytes.

int twim_write ( volatile avr32_twim_t *  twi,
unsigned const char *  buffer,
int  nbytes,
int  saddr,
bool  tenbit 
)
int twim_write_packet ( volatile avr32_twim_t *  twi,
const twi_package_t package 
)

Write multiple bytes to a TWI compatible slave device.

Parameters
twiBase address of the TWI (i.e. &AVR32_TWI).
*packagePackage information and data (see twi_package_t)
Returns
TWI_SUCCESS if all bytes were written, error code otherwhise

References twi_package_t::addr, twi_package_t::addr_length, twi_package_t::buffer, twi_package_t::chip, twi_package_t::length, TWI_RECEIVE_NACK, TWI_SUCCESS, twim_tx_data, and twim_tx_nb_bytes.

Referenced by twi_probe().