#include <io.h>
#include <stdarg.h>
#include <stdbool.h>
#include <stddef.h>
#include <stdint.h>
#include <types.h>
#include <sys-clk.h>
#include <sys-gpio.h>
Go to the source code of this file.
◆ TWI_CLK_DIV_M
| #define TWI_CLK_DIV_M (0xf << 3) /* 6:3bit */ |
◆ TWI_CLK_DIV_N
| #define TWI_CLK_DIV_N (0x7 << 0) /* 2:0bit */ |
◆ TWI_CLK_DUTY
| #define TWI_CLK_DUTY (0x1 << 7) /* 7bit */ |
◆ TWI_CLK_DUTY_30_EN
| #define TWI_CLK_DUTY_30_EN (0x1 << 8) /* 8bit */ |
◆ TWI_CTL_ACK
| #define TWI_CTL_ACK (0x1 << 2) |
◆ TWI_CTL_BUSEN
| #define TWI_CTL_BUSEN (0x1 << 6) |
◆ TWI_CTL_INTEN
| #define TWI_CTL_INTEN (0x1 << 7) /* INT_EN */ |
◆ TWI_CTL_INTFLG
| #define TWI_CTL_INTFLG (0x1 << 3) |
◆ TWI_CTL_STA
| #define TWI_CTL_STA (0x1 << 5) /* M_STA,atutomatic clear 0 */ |
◆ TWI_CTL_STP
| #define TWI_CTL_STP (0x1 << 4) /* M_STP,Automatic clear 0 */ |
◆ TWI_DATA_MASK
| #define TWI_DATA_MASK (0xff) |
◆ TWI_DEFAULT_CLK_GATE_OFFSET
| #define TWI_DEFAULT_CLK_GATE_OFFSET |
( |
|
x | ) |
(x) |
◆ TWI_DEFAULT_CLK_RST_OFFSET
| #define TWI_DEFAULT_CLK_RST_OFFSET |
( |
|
x | ) |
(x + 16) |
◆ TWI_LCR_WMASK
◆ TWI_XADDR_MASK
| #define TWI_XADDR_MASK (0xff) |
◆ anonymous enum
Enumeration of I2C speeds.
This enumeration defines the supported I2C speeds for the device.
| Enumerator |
|---|
| SUNXI_I2C_SPEED_100K | 100 kHz I2C speed.
|
| SUNXI_I2C_SPEED_400K | 400 kHz I2C speed.
|
◆ anonymous enum
Enumeration of I2C device IDs.
This enumeration defines the IDs for available I2C devices on the Sunxi platform, including regular and reserved IDs.
| Enumerator |
|---|
| SUNXI_I2C0 | I2C device 0.
|
| SUNXI_I2C1 | I2C device 1.
|
| SUNXI_I2C2 | I2C device 2.
|
| SUNXI_I2C3 | I2C device 3.
|
| SUNXI_I2C4 | I2C device 4.
|
| SUNXI_I2C5 | I2C device 5.
|
| SUNXI_R_I2C0 | Reserved I2C device 0.
|
| SUNXI_R_I2C1 | Reserved I2C device 1.
|
| SUNXI_I2C_BUS_MAX | Maximum number of I2C buses.
|
◆ sunxi_i2c_init()
Initialize I2C controller and bus.
Initializes the I2C controller by configuring GPIO pins, enabling clocks, resetting the bus, setting clock frequency, and enabling the I2C controller.
- Parameters
-
| i2c_dev | Pointer to the I2C device structure containing configuration parameters |
◆ sunxi_i2c_read()
sunxi_i2c read function
- Parameters
-
| i2c_dev | Pointer to the sunxi_i2c controller device structure |
| addr | Device address |
| reg | Register to be read from in the device |
| buffer | Buffer to store the read data |
- Returns
- int Number of status
sunxi_i2c read function
Reads a single byte from a specified register on an I2C device.
- Parameters
-
| i2c_dev | Pointer to the I2C device structure |
| addr | I2C device address |
| reg | Register address to read from |
| data | Pointer to store the read byte |
- Returns
- I2C_OK on success, I2C_NOK if I2C controller is not initialized
◆ sunxi_i2c_write()
sunxi_i2c write function
- Parameters
-
| i2c_dev | Pointer to the sunxi_i2c controller device structure |
| addr | Device address |
| reg | Register to be read/written in the device |
| buffer | Data to be written/read |
- Returns
- int Number of status
sunxi_i2c write function
Writes a single byte to a specified register on an I2C device.
- Parameters
-
| i2c_dev | Pointer to the I2C device structure |
| addr | I2C device address |
| reg | Register address to write to |
| data | Byte value to write |
- Returns
- I2C_OK on success, I2C_NOK if I2C controller is not initialized