Two-Wire Interface Controller (TWI) HW driver source file.
More...
Two-Wire Interface Controller (TWI) HW driver source file.
- Note
- These functions should only be used if the TWI unit was synthesized (IO_TWI_EN = true).
- See also
- https://stnolting.github.io/neorv32/sw/files.html
◆ neorv32_twi_available()
int neorv32_twi_available |
( |
void | | ) |
|
Check if TWI unit was synthesized.
- Returns
- 0 if TWI was not synthesized, 1 if TWI is available.
◆ neorv32_twi_busy()
int neorv32_twi_busy |
( |
void | | ) |
|
Check if TWI controller is busy (TWI bus engine busy or TX FIFO not empty).
- Returns
- 0 if idle, 1 if busy
◆ neorv32_twi_disable()
void neorv32_twi_disable |
( |
void | | ) |
|
◆ neorv32_twi_enable()
void neorv32_twi_enable |
( |
void | | ) |
|
◆ neorv32_twi_generate_start()
void neorv32_twi_generate_start |
( |
void | | ) |
|
Generate START (or REPEATED-START) condition.
- Note
- Blocking function.
◆ neorv32_twi_generate_start_nonblocking()
void neorv32_twi_generate_start_nonblocking |
( |
void | | ) |
|
Generate START (or REPEATED-START) condition.
- Note
- Non-blocking function; does not check the TX FIFO.
◆ neorv32_twi_generate_stop()
void neorv32_twi_generate_stop |
( |
void | | ) |
|
Generate STOP condition.
- Note
- Blocking function.
◆ neorv32_twi_generate_stop_nonblocking()
void neorv32_twi_generate_stop_nonblocking |
( |
void | | ) |
|
Generate STOP condition.
- Note
- Non-blocking function; does not check the TX FIFO.
◆ neorv32_twi_get()
int neorv32_twi_get |
( |
uint8_t * | data | ) |
|
Get received data + ACK/NACH from RX FIFO.
- Parameters
-
[in,out] | data | Pointer for returned data (uint8_t). |
- Returns
- RX FIFO access status (-1 = no data available, 0 = ACK received, 1 = NACK received).
◆ neorv32_twi_get_fifo_depth()
int neorv32_twi_get_fifo_depth |
( |
void | | ) |
|
Get TWI FIFO depth.
- Returns
- FIFO depth (number of entries), zero if no FIFO implemented
◆ neorv32_twi_send_nonblocking()
void neorv32_twi_send_nonblocking |
( |
uint8_t | data, |
|
|
int | mack ) |
Send data byte (RX can be read via neorv32_twi_get()).
- Note
- Non-blocking function; does not check the TX FIFO.
- Parameters
-
[in] | data | Data byte to be send. |
[in] | mack | Generate ACK by host controller when set. |
◆ neorv32_twi_sense_scl()
int neorv32_twi_sense_scl |
( |
void | | ) |
|
Get current state of SCL bus line.
- Returns
- 1 if SCL is high, 0 if SCL is low.
◆ neorv32_twi_sense_sda()
int neorv32_twi_sense_sda |
( |
void | | ) |
|
Get current state of SDA bus line.
- Returns
- 1 if SDA is high, 0 if SDA is low.
◆ neorv32_twi_setup()
void neorv32_twi_setup |
( |
int | prsc, |
|
|
int | cdiv, |
|
|
int | clkstr ) |
Enable and configure TWI controller. The TWI control register bits are listed in NEORV32_TWI_CTRL_enum.
- Parameters
-
[in] | prsc | Clock prescaler select (0..7). See NEORV32_CLOCK_PRSC_enum. |
[in] | cdiv | Clock divider (0..15). |
[in] | clkstr | Enable (allow) clock stretching. |
◆ neorv32_twi_trans()
int neorv32_twi_trans |
( |
uint8_t * | data, |
|
|
int | mack ) |
TWI transfer: send data byte and also receive data byte.
- Note
- Blocking function.
- Parameters
-
[in,out] | data | Pointer for TX/RX data (uint8_t). |
[in] | mack | Generate ACK by host controller when set. |
- Returns
- 0: ACK received, 1: NACK received.