2022-10-20 09:40:14 +08:00
|
|
|
/*
|
|
|
|
* Copyright (c) 2006-2022, RT-Thread Development Team
|
2022-07-13 19:56:14 +08:00
|
|
|
*
|
2022-10-20 09:40:14 +08:00
|
|
|
* SPDX-License-Identifier: Apache-2.0
|
2022-07-13 19:56:14 +08:00
|
|
|
*
|
2022-10-20 09:40:14 +08:00
|
|
|
* Change Logs:
|
|
|
|
* Date Author Notes
|
|
|
|
* 2022-10-19 Nations first version
|
2022-07-13 19:56:14 +08:00
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef __DRV_I2C__
|
|
|
|
#define __DRV_I2C__
|
|
|
|
|
2022-07-15 13:36:32 +08:00
|
|
|
#include <rtthread.h>
|
|
|
|
#include <rthw.h>
|
|
|
|
#include <rtdevice.h>
|
2022-10-20 09:40:14 +08:00
|
|
|
#include "board.h"
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
2022-07-15 13:36:32 +08:00
|
|
|
|
|
|
|
/* n32 config class */
|
|
|
|
struct n32_soft_i2c_config
|
|
|
|
{
|
|
|
|
rt_uint8_t scl;
|
|
|
|
rt_uint8_t sda;
|
|
|
|
const char *bus_name;
|
|
|
|
};
|
|
|
|
|
|
|
|
/* n32 i2c dirver class */
|
|
|
|
struct n32_i2c
|
|
|
|
{
|
|
|
|
struct rt_i2c_bit_ops ops;
|
2023-12-28 16:57:28 +08:00
|
|
|
struct rt_i2c_bus_device i2c_bus;
|
2022-07-15 13:36:32 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
#ifdef BSP_USING_I2C1
|
|
|
|
#define I2C1_BUS_CONFIG \
|
|
|
|
{ \
|
|
|
|
.scl = BSP_I2C1_SCL_PIN, \
|
|
|
|
.sda = BSP_I2C1_SDA_PIN, \
|
|
|
|
.bus_name = "i2c1", \
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef BSP_USING_I2C2
|
|
|
|
#define I2C2_BUS_CONFIG \
|
|
|
|
{ \
|
|
|
|
.scl = BSP_I2C2_SCL_PIN, \
|
|
|
|
.sda = BSP_I2C2_SDA_PIN, \
|
|
|
|
.bus_name = "i2c2", \
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef BSP_USING_I2C3
|
|
|
|
#define I2C3_BUS_CONFIG \
|
|
|
|
{ \
|
|
|
|
.scl = BSP_I2C3_SCL_PIN, \
|
|
|
|
.sda = BSP_I2C3_SDA_PIN, \
|
|
|
|
.bus_name = "i2c3", \
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef BSP_USING_I2C4
|
|
|
|
#define I2C4_BUS_CONFIG \
|
|
|
|
{ \
|
|
|
|
.scl = BSP_I2C4_SCL_PIN, \
|
|
|
|
.sda = BSP_I2C4_SDA_PIN, \
|
|
|
|
.bus_name = "i2c4", \
|
|
|
|
}
|
|
|
|
#endif
|
2022-07-13 19:56:14 +08:00
|
|
|
|
|
|
|
struct rt_i2c_bus
|
|
|
|
{
|
|
|
|
struct rt_i2c_bus_device parent;
|
|
|
|
rt_uint32_t i2c_periph;
|
|
|
|
};
|
|
|
|
|
|
|
|
int rt_hw_i2c_init(void);
|
|
|
|
|
2022-10-20 09:40:14 +08:00
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2022-07-15 13:36:32 +08:00
|
|
|
#endif /* __DRV_I2C__ */
|