Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
人间散章
rt-thread
提交
1a7cd8b4
R
rt-thread
项目概览
人间散章
/
rt-thread
与 Fork 源项目一致
Fork自
RT-Thread / rt-thread
通知
1
Star
1
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
rt-thread
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
1a7cd8b4
编写于
3月 29, 2023
作者:
嵌入式路上的流浪
提交者:
Thomas_Fly
3月 29, 2023
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
[driver]添加ESP32_C3 I2C驱动
上级
19f311b4
变更
4
显示空白变更内容
内联
并排
Showing
4 changed file
with
187 addition
and
8 deletion
+187
-8
bsp/ESP32_C3/drivers/Kconfig
bsp/ESP32_C3/drivers/Kconfig
+9
-4
bsp/ESP32_C3/drivers/drv_hw_i2c.c
bsp/ESP32_C3/drivers/drv_hw_i2c.c
+133
-0
bsp/ESP32_C3/drivers/drv_hw_i2c.h
bsp/ESP32_C3/drivers/drv_hw_i2c.h
+32
-0
bsp/ESP32_C3/rtconfig.h
bsp/ESP32_C3/rtconfig.h
+13
-4
未找到文件。
bsp/ESP32_C3/drivers/Kconfig
浏览文件 @
1a7cd8b4
...
...
@@ -63,6 +63,11 @@ menu "On-chip Peripheral Drivers"
select RT_USING_SERIAL
select RT_USING_SERIAL_V1
default y
config BSP_USING_I2C0
bool "Enable I2C0"
select RT_USING_I2C
default n
endmenu
endmenu
...
...
bsp/ESP32_C3/drivers/drv_hw_i2c.c
0 → 100644
浏览文件 @
1a7cd8b4
/*
* Copyright (c) 2006-2023, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
*2023-03-28 Zxy first version
*/
#ifdef RT_USING_I2C
#include "drv_hw_i2c.h"
#include "driver/i2c.h"//bsp/ESP32_C3/packages/ESP-IDF-latest/components/driver/include/driver/i2c.h
#include "hal/i2c_types.h"//bsp/ESP32_C3/packages/ESP-IDF-latest/tools/mocks/hal/include/hal/i2c_types.h
#include "esp_err.h"
//#include "portmacro.h"//bsp/ESP32_C3/packages/FreeRTOS_Wrapper-latest/FreeRTOS/portable/rt-thread/portmacro.h
struct
esp32_i2c
{
struct
rt_i2c_bus_device
bus
;
i2c_config_t
*
base
;
char
*
device_name
;
};
// #if defined(BSP_USING_I2C0)
static
struct
esp32_i2c
i2c0
=
{
0
};
// #endif
static
rt_size_t
_master_xfer
(
struct
rt_i2c_bus_device
*
bus
,
struct
rt_i2c_msg
msgs
[],
rt_uint32_t
num
)
{
i2c_cmd_handle_t
cmd
;
//创建流程
rt_size_t
ret
=
(
0
);
rt_uint32_t
index
=
0
;
// struct esp32_i2c *esp32_i2c = RT_NULL;
struct
rt_i2c_msg
*
msg
=
RT_NULL
;
i2c_rw_t
direction
;
//w-0 r-1
esp_err_t
result
=
ESP_OK
;
RT_ASSERT
(
bus
!=
RT_NULL
);
// esp32_i2c = (struct esp32_i2c *)bus;
for
(
index
=
0
;
index
<
num
;
index
++
)
{
msg
=
&
msgs
[
index
];
direction
=
((
msg
->
flags
&
RT_I2C_RD
)
?
I2C_MASTER_READ
:
I2C_MASTER_WRITE
);
if
(
!
(
msg
->
flags
&
RT_I2C_NO_START
))
{
/* Start condition and slave address. */
cmd
=
i2c_cmd_link_create
();
//创建流程
i2c_master_start
(
cmd
);
//启动流程录入
result
=
i2c_master_write_byte
(
cmd
,
msg
->
addr
<<
1
|
WRITE_BIT
,
ACK_CHECK_EN
);
//发送起始信号和从设备地址
i2c_master_stop
(
cmd
);
//流程录入完毕
ret
=
i2c_master_cmd_begin
(
I2C_NUMBER
(
0
),
cmd
,
1000
/
portTICK_PERIOD_MS
);
//执行流程
i2c_cmd_link_delete
(
cmd
);
//删除流程任务
if
(
ret
!=
ESP_OK
)
return
ret
;
}
if
(
result
==
ESP_OK
)
{
if
(
direction
==
I2C_MASTER_WRITE
)
{
/* Transmit data. */
cmd
=
i2c_cmd_link_create
();
//创建流程
i2c_master_start
(
cmd
);
//启动流程录入
result
=
i2c_master_write_byte
(
cmd
,
msg
->
buf
,
ACK_CHECK_EN
);
i2c_master_stop
(
cmd
);
//流程录入完毕
ret
=
i2c_master_cmd_begin
(
I2C_MASTER_NUM
,
cmd
,
1000
/
portTICK_PERIOD_MS
);
//执行流程
i2c_cmd_link_delete
(
cmd
);
//删除流程任务
}
else
{
/* Receive Data. */
cmd
=
i2c_cmd_link_create
();
//创建流程
i2c_master_start
(
cmd
);
//启动流程录入
result
=
i2c_master_read_byte
(
cmd
,
msg
->
buf
,
ACK_VAL
);
i2c_master_stop
(
cmd
);
//流程录入完毕
ret
=
i2c_master_cmd_begin
(
I2C_MASTER_NUM
,
cmd
,
1000
/
portTICK_PERIOD_MS
);
//执行流程
i2c_cmd_link_delete
(
cmd
);
//删除流程任务
}
}
}
if
(
result
==
ESP_OK
)
{
ret
=
index
;
}
return
ret
;
}
static
rt_size_t
_slave_xfer
(
struct
rt_i2c_bus_device
*
bus
,
struct
rt_i2c_msg
msgs
[],
rt_uint32_t
num
)
{
return
-
RT_ENOSYS
;
}
static
rt_err_t
_i2c_bus_control
(
struct
rt_i2c_bus_device
*
bus
,
rt_uint32_t
cmd
,
rt_uint32_t
arg
)
{
return
-
RT_EINVAL
;
}
static
const
struct
rt_i2c_bus_device_ops
i2c_ops
=
{
_master_xfer
,
_slave_xfer
,
_i2c_bus_control
,
};
int
rt_hw_i2c_init
(
void
)
{
i2c0
.
base
=
&
i2c0
;
i2c0
.
device_name
=
"i2c0"
;
i2c0
.
bus
.
ops
=
&
i2c_ops
;
int
i2c_master_port
=
I2C_MASTER_NUM
;
//iic0
i2c_config_t
conf
=
{
.
mode
=
I2C_MODE_MASTER
,
.
sda_io_num
=
I2C_MASTER_SDA_IO
,
.
sda_pullup_en
=
GPIO_PULLUP_ENABLE
,
.
scl_io_num
=
I2C_MASTER_SCL_IO
,
.
scl_pullup_en
=
GPIO_PULLUP_ENABLE
,
.
master
.
clk_speed
=
100000
,
// .clk_flags = 0, /*!< Optional, you can use I2C_SCLK_SRC_FLAG_* flags to choose i2c source clock here. */
};
i2c_param_config
(
i2c_master_port
,
&
conf
);
//配置完成
i2c_driver_install
(
i2c_master_port
,
conf
.
mode
,
0
,
0
,
0
);
// I2C 设备的初始化
rt_i2c_bus_device_register
(
&
i2c0
.
bus
,
i2c0
.
device_name
);
return
RT_EOK
;
}
INIT_BOARD_EXPORT
(
rt_hw_i2c_init
);
#endif
/* RT_USING_I2C */
\ No newline at end of file
bsp/ESP32_C3/drivers/drv_hw_i2c.h
0 → 100644
浏览文件 @
1a7cd8b4
/*
* Copyright (c) 2006-2023, RT-Thread Development Team
*
* SPDX-License-Identifier: Apache-2.0
*
* Change Logs:
* Date Author Notes
*2023-03-28 Zxy first version
*/
#ifndef __DRV_HW_I2C_H__
#define __DRV_HW_I2C_H__
#include <rtthread.h>
#include <rtdevice.h>
#include "sdkconfig.h"
#define WRITE_BIT I2C_MASTER_WRITE
/*!< I2C master write */
#define READ_BIT I2C_MASTER_READ
/*!< I2C master read */
#define ACK_CHECK_EN 0x1
/*!< I2C master will check ack from slave*/
#define ACK_CHECK_DIS 0x0
/*!< I2C master will not check ack from slave */
#define ACK_VAL 0x0
/*!< I2C ack value */
#define NACK_VAL 0x1
/*!< I2C nack value */
#define _I2C_NUMBER(num) I2C_NUM_##num
#define I2C_NUMBER(num) _I2C_NUMBER(num)
#define I2C_MASTER_NUM I2C_NUMBER(0)
/*!< I2C port number for master dev */
#define I2C_MASTER_SCL_IO CONFIG_I2C_MASTER_SCL
/*!< gpio number for I2C master clock */
#define I2C_MASTER_SDA_IO CONFIG_I2C_MASTER_SDA
/*!< gpio number for I2C master data */
#define CONFIG_I2C_MASTER_SCL 6
#define CONFIG_I2C_MASTER_SDA 5
int
rt_hw_i2c_init
(
void
);
#endif
/* __DRV_HW_I2C_H__ */
bsp/ESP32_C3/rtconfig.h
浏览文件 @
1a7cd8b4
...
...
@@ -7,7 +7,7 @@
/* RT-Thread Kernel */
#define RT_NAME_MAX 8
#define RT_ALIGN_SIZE
8
#define RT_ALIGN_SIZE
4
#define RT_THREAD_PRIORITY_32
#define RT_THREAD_PRIORITY_MAX 32
#define RT_TICK_PER_SECOND 1000
...
...
@@ -65,6 +65,7 @@
/* Device Drivers */
#define RT_USING_DEVICE_IPC
#define RT_UNAMED_PIPE_NUMBER 64
#define RT_USING_SERIAL
#define RT_USING_SERIAL_V1
#define RT_SERIAL_RB_BUFSZ 64
...
...
@@ -130,9 +131,6 @@
/* u8g2: a monochrome graphic library */
/* PainterEngine: A cross-platform graphics application framework written in C language */
/* tools packages */
...
...
@@ -154,6 +152,11 @@
/* peripheral libraries and drivers */
/* sensors drivers */
/* touch drivers */
#define PKG_USING_ESP_IDF
#define PKG_USING_ESP_IDF_LATEST_VERSION
...
...
@@ -163,6 +166,9 @@
/* AI packages */
/* Signal Processing and Control Algorithm Packages */
/* miscellaneous packages */
/* project laboratory */
...
...
@@ -195,10 +201,13 @@
/* Communication */
/* Device Control */
/* Other */
/* Signal IO */
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录