首次添加硬件I2C驱动层#11464
Conversation
|
|
|
👋 感谢您对 RT-Thread 的贡献!Thank you for your contribution to RT-Thread! 为确保代码符合 RT-Thread 的编码规范,请在你的仓库中执行以下步骤运行代码格式化工作流(如果格式化CI运行失败)。 🛠 操作步骤 | Steps
完成后,提交将自动更新至 如有问题欢迎联系我们,再次感谢您的贡献!💐 |
|
@dirtwillfly 麻烦签署一下CLA,谢谢! |
|
能否提供一个驱动正常执行的截图!麻烦把pr的标题修改一下,比较符合这次pr的内容,比如[bsp][NS800RT7P65]:......。另外rtconfig.h就不需要提交了,保持bsp最小化,然后麻烦加个i2c的ci检查,参考 |
There was a problem hiding this comment.
Pull request overview
Purpose: Add the first NS800 hardware I2C bus driver layer for the bsp/novosns/ns800/ns800rt7p65-nssinepad BSP, integrating it into RT-Thread’s rt_i2c_bus_device framework.
目的:为 bsp/novosns/ns800/ns800rt7p65-nssinepad BSP 首次引入 NS800 硬件 I2C 总线驱动层,并接入 RT-Thread 的 rt_i2c_bus_device 框架。
Changes / 变更:
- Add NS800 hardware I2C driver implementation (
drv_hard_i2c.c/.h) and register I2C buses at board init. / 新增 NS800 硬件 I2C 驱动实现并在板级初始化时注册 I2C 总线。 - Add BSP Kconfig options and SCons build integration for enabling I2C1/I2C2 and baudrate configuration. / 增加 BSP Kconfig 选项与 SCons 编译集成,用于启用 I2C1/I2C2 与配置波特率。
- Add NS800 RT7 I2C pin/instance configuration header and include it via
drv_config.h. / 增加 NS800 RT7 I2C 配置头文件,并通过drv_config.h引入。
PR Title check / PR 标题检查:
- English: Title is missing the required lowercase prefix like
[module][subsystem]. Suggested:[novosns][drivers] Add NS800 hardware I2C driver. - 中文:标题缺少要求的小写前缀格式
[模块][子系统]。建议:[novosns][drivers] 添加 NS800 硬件 I2C 驱动。
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 12 comments.
Show a summary per file
| File | Description |
|---|---|
| bsp/novosns/ns800/ns800rt7p65-nssinepad/rtconfig.h | Enables I2C-related macros for the BSP (but should be generated, not manually edited). |
| bsp/novosns/ns800/ns800rt7p65-nssinepad/board/Kconfig | Adds menuconfig options for BSP I2C and per-instance baudrate. |
| bsp/novosns/ns800/libraries/HAL_Drivers/drivers/SConscript | Adds drv_hard_i2c.c to the build when BSP_USING_I2C is enabled. |
| bsp/novosns/ns800/libraries/HAL_Drivers/drivers/drv_hard_i2c.h | Introduces NS800 I2C config/device structs for RT-Thread I2C bus integration. |
| bsp/novosns/ns800/libraries/HAL_Drivers/drivers/drv_hard_i2c.c | Implements NS800 I2C init + master_xfer + finsh scan command. |
| bsp/novosns/ns800/libraries/HAL_Drivers/drivers/drv_config.h | Includes RT7 I2C hardware config header for NS800. |
| bsp/novosns/ns800/libraries/HAL_Drivers/drivers/config/rt7/i2c_hard_config.h | Defines I2C1/I2C2 instance + GPIO + baudrate defaults for NS800 RT7. |
| #define RT_USING_I2C | ||
| #define RT_USING_I2C_BITOPS |
| #define BSP_USING_I2C | ||
| #define BSP_USING_HARD_I2C2 | ||
| #define BSP_I2C2_BAUDRATE 100000 |
|
|
||
| menuconfig BSP_USING_I2C | ||
| bool "Enable I2C" |
| if GetDepend('BSP_USING_SPI'): | ||
| src += ['drv_spi.c'] | ||
|
|
||
| if GetDepend('BSP_USING_I2C'): | ||
| src += ['drv_hard_i2c.c'] |
| /* Configure pin low timeouts after baudrate setting | ||
| The value is equal to PINLOW cycles of functional clock divided by prescaler | ||
| And set PINLOW to 0 disables the filter, so the min value is 1 */ | ||
| I2C_setMasterPinLowTimeout(i2c, I2C_MASTER_PINLOW_SCLSDA, 0U); | ||
|
|
| LOG_D("xfer msgs[%d] addr=0x%2x buf=0x%x len=0x%x flags=0x%x", | ||
| i, msg->addr, msg->buf, msg->len, msg->flags); |
| else | ||
| { | ||
| /* RT-Thread uses 7-bit address, SDK expects 8-bit address */ | ||
| uint8_t addr_8bit = msg->addr << 1; | ||
|
|
||
| if (msg->flags & RT_I2C_RD) | ||
| { | ||
| status = I2C_sendReStart(i2c, addr_8bit, I2C_DIRECTION_READ); | ||
| } | ||
| else | ||
| { | ||
| status = I2C_sendReStart(i2c, addr_8bit, I2C_DIRECTION_WRITE); | ||
| } | ||
|
|
||
| LOG_D("I2C[%s] SendReStart status=%d, MSR=0x%x", bus->parent.parent.name, status, I2C_getMasterStatusFlags(i2c)); | ||
|
|
||
| if (status != I2C_STATUS_SUCCESS) | ||
| { | ||
| LOG_E("I2C[%s] SendReStart error(%d)", bus->parent.parent.name, status); | ||
| ret = -RT_EIO; | ||
| goto out; | ||
| } | ||
| } |
| static I2C_Status I2C_checkMasterBusyTimeout(I2C_TypeDef *i2c, uint32_t timeout_ms) | ||
| { | ||
| uint32_t start_tick = rt_tick_get(); | ||
|
|
||
| while (rt_tick_get() - start_tick < rt_tick_from_millisecond(timeout_ms)) | ||
| { | ||
| __IO uint32_t status = I2C_getMasterStatusFlags(i2c); | ||
| if ((0U == (status & (uint32_t)I2C_MASTER_FLAG_BUSBUSY)) || | ||
| (0U != (status & (uint32_t)I2C_MASTER_FLAG_BUSY))) | ||
| { | ||
| return I2C_STATUS_SUCCESS; | ||
| } | ||
| rt_thread_mdelay(1); | ||
| } | ||
|
|
||
| return I2C_STATUS_BUSY; | ||
| } |
| { | ||
| #endif | ||
|
|
||
| #define BSP_I2C_CTRL_SET_TIMING 0x40 |
| enum | ||
| { | ||
| #ifdef BSP_USING_HARD_I2C1 | ||
| I2C1_INDEX, | ||
| #endif | ||
| #ifdef BSP_USING_HARD_I2C2 | ||
| I2C2_INDEX, | ||
| #endif | ||
| }; |
拉取/合并请求描述:(PR description)
[
为什么提交这份PR (why to submit this PR)
添加了硬件I2C驱动
你的解决方案是什么 (what is your solution)
支持了I2C1和I2C2
请提供验证的bsp和config (provide the config and bsp)
BSP: bsp\novosns\ns800\ns800rt7p65-nssinepad
.config: CONFIG_RT_USING_I2C=y
CONFIG_RT_USING_I2C_BITOPS=y
action:
]
当前拉取/合并请求的状态 Intent for your PR
必须选择一项 Choose one (Mandatory):
代码质量 Code Quality:
我在这个拉取/合并请求中已经考虑了 As part of this pull request, I've considered the following:
#if 0代码,不包含已经被注释了的代码 All redundant code is removed and cleaned up