Driver for the TWI (Two-Wire Interface).
This driver provides access to the main features of the TWI controller. The TWI interconnects components on a unique two-wire bus. The TWI is programmable as a master or a slave with sequential or single-byte access. Multiple master capability is supported.
#define TWI_ARBITRATION_LOST -2 |
#define TWI_INVALID_ARGUMENT -1 |
#define TWI_NO_CHIP_FOUND -3 |
#define TWI_RECEIVE_NACK -5 |
#define TWI_RECEIVE_OVERRUN -4 |
#define TWI_SEND_OVERRUN -6 |
void twi_disable_interrupt |
( |
volatile avr32_twi_t * |
twi | ) |
|
bool twi_is_busy |
( |
void |
| ) |
|
static void twi_master_disable |
( |
volatile avr32_twi_t * |
twi | ) |
|
|
inlinestatic |
Disable Master Mode of the TWI.
- Parameters
-
twi | Base address of the TWI instance. |
static void twi_master_enable |
( |
volatile avr32_twi_t * |
twi | ) |
|
|
inlinestatic |
Enable Master Mode of the TWI.
- Parameters
-
twi | Base address of the TWI instance. |
int twi_master_init |
( |
volatile avr32_twi_t * |
twi, |
|
|
const twi_options_t * |
opt |
|
) |
| |
Initialize the twi master module.
- Parameters
-
twi | Base address of the TWI (i.e. &AVR32_TWI). |
*opt | Options for initializing the twi module (see twi_options_t) |
References CONF_TWI_IRQ_LEVEL, CONF_TWI_IRQ_LINE, cpu_irq_disable, cpu_irq_restore(), cpu_irq_save(), irq_register_handler, twi_options_t::pba_hz, twi_options_t::speed, sysreg_read, twi_inst, twi_set_speed(), and TWI_SUCCESS.
Referenced by main().
int twi_master_read |
( |
volatile avr32_twi_t * |
twi, |
|
|
const twi_package_t * |
package |
|
) |
| |
Read multiple bytes from a TWI compatible slave device.
- Parameters
-
twi | Base address of the TWI (i.e. &AVR32_TWI). |
package | Package information and data (see twi_package_t) |
- Returns
- TWI_SUCCESS if all bytes were read, error code otherwise
References twi_package_t::addr, twi_package_t::addr_length, twi_package_t::buffer, twi_package_t::chip, cpu_relax, twi_package_t::length, twi_busy, twi_inst, TWI_INVALID_ARGUMENT, twi_is_busy(), twi_it_mask, twi_mk_addr(), twi_nack, TWI_RECEIVE_NACK, twi_rx_data, twi_rx_nb_bytes, and TWI_SUCCESS.
Referenced by main().
int twi_master_write |
( |
volatile avr32_twi_t * |
twi, |
|
|
const twi_package_t * |
package |
|
) |
| |
Write multiple bytes to a TWI compatible slave device.
- Parameters
-
twi | Base address of the TWI (i.e. &AVR32_TWI). |
*package | Package information and data (see twi_package_t) |
- Returns
- TWI_SUCCESS if all bytes were written, error code otherwise
References twi_package_t::addr, twi_package_t::addr_length, twi_package_t::buffer, twi_package_t::chip, cpu_relax, twi_package_t::length, twi_busy, twi_inst, TWI_INVALID_ARGUMENT, twi_is_busy(), twi_it_mask, twi_mk_addr(), twi_nack, TWI_RECEIVE_NACK, TWI_SUCCESS, twi_tx_data, and twi_tx_nb_bytes.
Referenced by main(), and twi_probe().
int twi_master_write_ex |
( |
volatile avr32_twi_t * |
twi, |
|
|
const twi_package_t * |
package |
|
) |
| |
Write multiple bytes to a TWI compatible slave device. This function is not blocking.
The function does not wait that all the bytes are written.
- Parameters
-
twi | Base address of the TWI (i.e. &AVR32_TWI). |
*package | Package information and data (see twi_package_t) |
- Returns
- TWI_SUCCESS if all bytes were written, error code otherwise
Write multiple bytes to a TWI compatible slave device. This function is not blocking.
References twi_package_t::addr, twi_package_t::addr_length, twi_package_t::buffer, twi_package_t::chip, twi_package_t::length, TWI_BUSY, twi_inst, TWI_INVALID_ARGUMENT, twi_it_mask, twi_mk_addr(), twi_nack, TWI_RECEIVE_NACK, TWI_SUCCESS, twi_tx_data, and twi_tx_nb_bytes.
int twi_probe |
( |
volatile avr32_twi_t * |
twi, |
|
|
char |
chip_addr |
|
) |
| |
Initialize the twi slave module.
- Parameters
-
twi | Base address of the TWI (i.e. &AVR32_TWI). |
*opt | Options for initializing the twi module (see twi_options_t) |
*slave_fct | Pointer on application functions |
References twi_options_t::chip, CONF_TWI_IRQ_LEVEL, CONF_TWI_IRQ_LINE, cpu_irq_disable, cpu_irq_restore(), cpu_irq_save(), irq_register_handler, sysreg_read, twi_inst, twi_it_mask, and TWI_SUCCESS.