See Quickstart guide for SAM TWIS driver.
Driver for the TWIS (Two-Wire Slave Interface). This driver provides access to the main features of the TWIS controller. The TWIS interconnects components on a unique two-wire bus. The TWIS is programmable as a slave with sequential or single-byte access. High speed mode capability is supported.
Data Structures | |
struct | twis_callback |
struct | twis_config |
Input parameters when initializing the TWIS module mode. More... | |
struct | twis_dev_inst |
TWI slave driver software instance structure. More... | |
Macros | |
#define | TWIS_WAIT_TIMEOUT 1000 |
Typedefs | |
typedef struct twis_callback | twis_callback_t |
typedef enum twis_interrupt_source | twis_interrupt_source_t |
TWIS interrupt source type. More... | |
Enumerations | |
enum | twis_interrupt_source { TWIS_INTERRUPT_RX_BUFFER_READY = TWIS_IER_RXRDY, TWIS_INTERRUPT_TX_BUFFER_READY = TWIS_IER_TXRDY, TWIS_INTERRUPT_TRANS_COMP = TWIS_IER_TCOMP, TWIS_INTERRUPT_UNDER_RUN = TWIS_IER_URUN, TWIS_INTERRUPT_OVER_RUN = TWIS_IER_ORUN, TWIS_INTERRUPT_NAK_RECEIVED = TWIS_IER_NAK, TWIS_INTERRUPT_SMBUS_TIMEOUT = TWIS_IER_SMBTOUT, TWIS_INTERRUPT_SMBUS_PEC_ERROR = TWIS_IER_SMBPECERR, TWIS_INTERRUPT_BUS_ERROR = TWIS_IER_BUSERR, TWIS_INTERRUPT_SLAVEADR_MATCH = TWIS_IER_SAM, TWIS_INTERRUPT_GENCALL_MATCH = TWIS_IER_GCM, TWIS_INTERRUPT_SMBUS_HHADR_MATCH = TWIS_IER_SMBHHM, TWIS_INTERRUPT_SMBUS_DEFADR_MATCH = TWIS_IER_SMBDAM, TWIS_INTERRUPT_STOP_RECEIVED = TWIS_IER_STO, TWIS_INTERRUPT_RESTART_RECEIVED = TWIS_IER_REP, TWIS_INTERRUPT_BYTE_TRANS_FINISHED = TWIS_IER_BTF, TWIS_INTERRUPT_ERRORS, TWIS_INTERRUPT_ALL = ~0UL } |
TWIS interrupt source type. More... | |
Functions | |
static void | twis_clear_status (struct twis_dev_inst *const dev_inst, uint32_t clear_status) |
Clear the current status of the TWIS. More... | |
void | twis_disable (struct twis_dev_inst *const dev_inst) |
Disable TWIS Module. More... | |
static void | twis_disable_interrupt (struct twis_dev_inst *const dev_inst, twis_interrupt_source_t interrupt_source) |
Disable the TWIS interrupts. More... | |
void | twis_enable (struct twis_dev_inst *const dev_inst) |
Enable TWIS Module. More... | |
static void | twis_enable_interrupt (struct twis_dev_inst *const dev_inst, twis_interrupt_source_t interrupt_source) |
Enable the TWIS interrupts. More... | |
void | twis_get_config_defaults (struct twis_config *const cfg) |
Get the TWIS master default configurations. More... | |
static uint32_t | twis_get_interrupt_mask (struct twis_dev_inst *const dev_inst) |
Get the TWIS interrupt mask. More... | |
static uint8_t | twis_get_smbus_pec (struct twis_dev_inst *const dev_inst) |
Get the calculated PEC value. More... | |
static uint8_t | twis_get_smbus_transfer_nb (struct twis_dev_inst *const dev_inst) |
Get the progress of the transfer in SMBus mode. More... | |
static uint32_t | twis_get_status (struct twis_dev_inst *const dev_inst) |
Information about the current status of the TWIS. More... | |
enum status_code | twis_init (struct twis_dev_inst *const dev_inst, Twis *const twis, struct twis_config *config) |
Initialize the TWI Slave Module. More... | |
static enum status_code | twis_read (struct twis_dev_inst *const dev_inst, uint8_t *data) |
Get the last byte data received from TWI bus. More... | |
static void | twis_send_data_ack (struct twis_dev_inst *const dev_inst) |
Enable ACK transfer in Slave Receiver Mode. More... | |
static void | twis_send_data_nack (struct twis_dev_inst *const dev_inst) |
Enable NACK transfer in Slave Receiver Mode. More... | |
void | twis_set_callback (struct twis_dev_inst *const dev_inst, twis_interrupt_source_t source, twis_callback_t callback, uint8_t irq_level) |
Set callback for TWIS. More... | |
static void | twis_set_smbus_transfer_nb (struct twis_dev_inst *const dev_inst, uint8_t nb, bool increment) |
Set the total number of data bytes in the transmission. More... | |
static enum status_code | twis_write (struct twis_dev_inst *const dev_inst, uint8_t byte) |
Write one byte data to TWI bus. More... | |
#define TWIS_WAIT_TIMEOUT 1000 |
Referenced by twis_read(), and twis_write().
typedef struct twis_callback twis_callback_t |
typedef enum twis_interrupt_source twis_interrupt_source_t |
TWIS interrupt source type.
TWIS interrupt source type.
|
inlinestatic |
Clear the current status of the TWIS.
dev_inst | Device structure pointer |
clear_status | The TWIS status to be clear |
References Assert, and twis_dev_inst::hw_dev.
Referenced by twis_interrupt_handler().
void twis_disable | ( | struct twis_dev_inst *const | dev_inst | ) |
Disable TWIS Module.
dev_inst | Device structure pointer |
References Assert, twis_dev_inst::hw_dev, SLEEPMGR_SLEEP_1, and sleepmgr_unlock_mode().
|
inlinestatic |
Disable the TWIS interrupts.
dev_inst | Device structure pointer. |
interrupt_source | The TWIS interrupt to be disabled |
References Assert, and twis_dev_inst::hw_dev.
Referenced by twis_interrupt_handler().
void twis_enable | ( | struct twis_dev_inst *const | dev_inst | ) |
Enable TWIS Module.
dev_inst | Device structure pointer |
References Assert, twis_dev_inst::hw_dev, sleepmgr_lock_mode(), and SLEEPMGR_SLEEP_1.
Referenced by main().
|
inlinestatic |
Enable the TWIS interrupts.
dev_inst | Device structure pointer |
interrupt_source | The TWIS interrupt source to be enabled |
References Assert, and twis_dev_inst::hw_dev.
Referenced by twis_interrupt_handler(), and twis_set_callback().
void twis_get_config_defaults | ( | struct twis_config *const | cfg | ) |
Get the TWIS master default configurations.
Use to initialize the configuration structure to known default values. This function should be called at the start of any TWIS initiation.
The default configuration is as follows:
cfg | Pointer to configuration structure to be initiated. |
References twis_config::ack_general_call, twis_config::ack_slave_addr, twis_config::ack_smbus_default_addr, twis_config::ack_smbus_host_header, Assert, twis_config::chip, twis_config::enable_pec, twis_config::exp, twis_config::fs_dadrivel, twis_config::fs_daslew, twis_config::fs_filter, twis_config::hddat, twis_config::hs_dadrivel, twis_config::hs_daslew, twis_config::hs_filter, twis_config::smbus, twis_config::stretch_clk_addr, twis_config::stretch_clk_data, twis_config::stretch_clk_hr, twis_config::sudat, twis_config::ten_bit, twis_config::tlows, and twis_config::ttouts.
Referenced by main().
|
inlinestatic |
Get the TWIS interrupt mask.
dev_inst | Device structure pointer. |
TWIS | interrupt mask |
References Assert, and twis_dev_inst::hw_dev.
Referenced by twis_interrupt_handler().
|
inlinestatic |
Get the calculated PEC value.
Only for SMBus mode.
dev_inst | Device structure pointer. |
Calculated | PEC value |
References Assert, and twis_dev_inst::hw_dev.
|
inlinestatic |
Get the progress of the transfer in SMBus mode.
dev_inst | Device structure pointer. |
The | left number of data bytes in the transmission. |
References Assert, and twis_dev_inst::hw_dev.
|
inlinestatic |
Information about the current status of the TWIS.
dev_inst | Device structure pointer. |
References Assert, and twis_dev_inst::hw_dev.
Referenced by twis_interrupt_handler().
enum status_code twis_init | ( | struct twis_dev_inst *const | dev_inst, |
Twis *const | twis, | ||
struct twis_config * | config | ||
) |
Initialize the TWI Slave Module.
dev_inst | Device structure pointer |
twis | Base address of the TWIS |
config | Configuration for the TWIS |
STATUS_OK | The data is written correctly. |
STATUS_ERR_DENIED | Initialization failed due to the module was enable before. |
STATUS_ERR_BUSY | Initialization failed due to the module is busy with transfer. |
References Assert, twis_dev_inst::hw_dev, STATUS_ERR_BUSY, STATUS_ERR_DENIED, STATUS_OK, sysclk_enable_peripheral_clock(), twis_find_ch_num(), and twis_set_config().
Referenced by main().
|
inlinestatic |
Get the last byte data received from TWI bus.
dev_inst | Device structure pointer. |
*data | The read data. |
STATUS_OK | The data is read correctly. |
STATUS_ERR_TIMEOUT | The read operation aborted due to timeout. |
References Assert, twis_dev_inst::hw_dev, STATUS_ERR_TIMEOUT, STATUS_OK, and TWIS_WAIT_TIMEOUT.
|
inlinestatic |
Enable ACK transfer in Slave Receiver Mode.
dev_inst | Device structure pointer. |
References Assert, and twis_dev_inst::hw_dev.
|
inlinestatic |
Enable NACK transfer in Slave Receiver Mode.
dev_inst | Device structure pointer. |
References Assert, and twis_dev_inst::hw_dev.
void twis_set_callback | ( | struct twis_dev_inst *const | dev_inst, |
twis_interrupt_source_t | source, | ||
twis_callback_t | callback, | ||
uint8_t | irq_level | ||
) |
Set callback for TWIS.
dev_inst | Device structure pointer |
source | Interrupt source |
callback | Callback function pointer |
irq_level | Interrupt level |
References Assert, twis_dev_inst::hw_dev, irq_register_handler, twis_enable_interrupt(), twis_find_ch_num(), and TWIS_INTERRUPT_SLAVEADR_MATCH.
Referenced by main().
|
inlinestatic |
Set the total number of data bytes in the transmission.
Only for SMBus mode.
dev_inst | Device structure pointer |
nb | Total number of data bytes in the transmission |
increment | Count up per byte transferred if true, otherwise count down |
References Assert, and twis_dev_inst::hw_dev.
|
inlinestatic |
Write one byte data to TWI bus.
dev_inst | Device structure pointer. |
byte | The byte data to write. |
STATUS_OK | The data is written correctly. |
STATUS_ERR_TIMEOUT | The write operation aborted due to timeout. |
References Assert, twis_dev_inst::hw_dev, STATUS_ERR_TIMEOUT, STATUS_OK, and TWIS_WAIT_TIMEOUT.