This repository has been archived on 2025-01-02. You can view files and clone it, but cannot push or open issues or pull requests.
torsion/User/system/bsp/i2cs.h

39 lines
1.0 KiB
C

#ifndef __I2CS_H__
#define __I2CS_H__
#include "lib.h"
#include "gpios.h"
typedef struct I2CS i2c_t;
typedef struct
{
void (*start)(i2c_t *handle); // 启动
void (*stop)(i2c_t *handle); // 停止
BOOL(*wait_ack)
(i2c_t *handle); // 等待应答
void (*write_byte)(i2c_t *handle, uint8_t data); // 写入一个字节
uint8_t (*read_byte)(i2c_t *handle, BOOL ack); // 读取一个字节
void (*write_word)(i2c_t *handle, uint16_t data); // 写入二个字节
void (*write_12bit)(i2c_t *handle, uint16_t data); // 写入12bit
} i2c_interface_t;
typedef struct
{
struct GPIO *scl; // SCL
struct GPIO *sda; // SDA
} i2c_gpio_group_t;
struct I2CS
{
i2c_gpio_group_t gpios; // i2c引脚
uint16_t delay_ticks; // 延时多少个NOP
i2c_interface_t interface; // I2C接口
};
extern i2c_t *i2c_create(i2c_gpio_group_t gpios, uint16_t delay_ticks); // 创建I2C
extern void i2c_free(i2c_t *handle); // 释放I2C资源
#endif // __I2CS_H__