SyterKit 0.4.0.x
SyterKit is a bare-metal framework
Loading...
Searching...
No Matches
Classes | Macros | Enumerations | Functions
sys-i2c.h File Reference
#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>
Include dependency graph for sys-i2c.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  sunxi_i2c_gpio_t
 Structure representing the GPIO configuration for I2C. More...
 
struct  sunxi_i2c_t
 Structure representing an I2C device configuration. More...
 
struct  sunxi_twi_reg
 Structure representing the registers of the Sunxi TWI (Two Wire Interface). More...
 

Macros

#define TWI_XADDR_MASK   (0xff)
 
#define TWI_DATA_MASK   (0xff)
 
#define TWI_CTL_ACK   (0x1 << 2)
 
#define TWI_CTL_INTFLG   (0x1 << 3)
 
#define TWI_CTL_STP   (0x1 << 4) /* M_STP,Automatic clear 0 */
 
#define TWI_CTL_STA   (0x1 << 5) /* M_STA,atutomatic clear 0 */
 
#define TWI_CTL_BUSEN   (0x1 << 6)
 
#define TWI_CTL_INTEN   (0x1 << 7) /* INT_EN */
 
#define TWI_CLK_DUTY_30_EN   (0x1 << 8) /* 8bit */
 
#define TWI_CLK_DUTY   (0x1 << 7) /* 7bit */
 
#define TWI_CLK_DIV_M   (0xf << 3) /* 6:3bit */
 
#define TWI_CLK_DIV_N   (0x7 << 0) /* 2:0bit */
 
#define TWI_LCR_WMASK   (TWI_CTL_STA | TWI_CTL_STP | TWI_CTL_INTFLG)
 
#define TWI_DEFAULT_CLK_RST_OFFSET(x)   (x + 16)
 
#define TWI_DEFAULT_CLK_GATE_OFFSET(x)   (x)
 

Enumerations

enum  { SUNXI_I2C_SPEED_100K = 100000 , SUNXI_I2C_SPEED_400K = 400000 }
 Enumeration of I2C speeds. More...
 
enum  {
  SUNXI_I2C0 = 0 , SUNXI_I2C1 , SUNXI_I2C2 , SUNXI_I2C3 ,
  SUNXI_I2C4 , SUNXI_I2C5 , SUNXI_R_I2C0 , SUNXI_R_I2C1 ,
  SUNXI_I2C_BUS_MAX
}
 Enumeration of I2C device IDs. More...
 

Functions

void sunxi_i2c_init (sunxi_i2c_t *i2c_dev)
 Initialize I2C controller and bus.
 
int sunxi_i2c_write (sunxi_i2c_t *i2c_dev, uint8_t addr, uint32_t reg, uint8_t data)
 sunxi_i2c write function
 
int sunxi_i2c_read (sunxi_i2c_t *i2c_dev, uint8_t addr, uint32_t reg, uint8_t *data)
 sunxi_i2c read function
 

Macro Definition Documentation

◆ 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

#define TWI_LCR_WMASK   (TWI_CTL_STA | TWI_CTL_STP | TWI_CTL_INTFLG)

◆ TWI_XADDR_MASK

#define TWI_XADDR_MASK   (0xff)

Enumeration Type Documentation

◆ anonymous enum

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

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.

Function Documentation

◆ sunxi_i2c_init()

void sunxi_i2c_init ( sunxi_i2c_t i2c_dev)

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_devPointer to the I2C device structure containing configuration parameters

◆ sunxi_i2c_read()

int sunxi_i2c_read ( sunxi_i2c_t i2c_dev,
uint8_t  addr,
uint32_t  reg,
uint8_t data 
)

sunxi_i2c read function

Parameters
i2c_devPointer to the sunxi_i2c controller device structure
addrDevice address
regRegister to be read from in the device
bufferBuffer 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_devPointer to the I2C device structure
addrI2C device address
regRegister address to read from
dataPointer to store the read byte
Returns
I2C_OK on success, I2C_NOK if I2C controller is not initialized

◆ sunxi_i2c_write()

int sunxi_i2c_write ( sunxi_i2c_t i2c_dev,
uint8_t  addr,
uint32_t  reg,
uint8_t  data 
)

sunxi_i2c write function

Parameters
i2c_devPointer to the sunxi_i2c controller device structure
addrDevice address
regRegister to be read/written in the device
bufferData 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_devPointer to the I2C device structure
addrI2C device address
regRegister address to write to
dataByte value to write
Returns
I2C_OK on success, I2C_NOK if I2C controller is not initialized