Skip to content

首次添加硬件I2C驱动层#11464

Open
dirtwillfly wants to merge 1 commit into
RT-Thread:masterfrom
dirtwillfly:master
Open

首次添加硬件I2C驱动层#11464
dirtwillfly wants to merge 1 commit into
RT-Thread:masterfrom
dirtwillfly:master

Conversation

@dirtwillfly

Copy link
Copy Markdown

拉取/合并请求描述:(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):

  • 本拉取/合并请求是一个草稿版本 This PR is for a code-review and is intended to get feedback
  • [ *] 本拉取/合并请求是一个成熟版本 This PR is mature, and ready to be integrated into the repo

代码质量 Code Quality:

我在这个拉取/合并请求中已经考虑了 As part of this pull request, I've considered the following:

  • [* ] 已经仔细查看过代码改动的对比 Already check the difference between PR and old code
  • [* ] 代码风格正确,包括缩进空格,命名及其他风格 Style guide is adhered to, including spacing, naming and other styles
  • [* ] 没有垃圾代码,代码尽量精简,不包含#if 0代码,不包含已经被注释了的代码 All redundant code is removed and cleaned up
  • [*] 所有变更均有原因及合理的,并且不会影响到其他软件组件代码或BSP All modifications are justified and not affect other components or BSP
  • 对难懂代码均提供对应的注释 I've commented appropriately where code is tricky
  • 代码是高质量的 Code in this PR is of high quality
  • 已经使用formatting 等源码格式化工具确保格式符合RT-Thread代码规范 This PR complies with RT-Thread code specification
  • 如果是新增bsp, 已经添加ci检查到.github/ALL_BSP_COMPILE.json 详细请参考链接BSP自查

@CLAassistant

Copy link
Copy Markdown

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

@github-actions

Copy link
Copy Markdown

👋 感谢您对 RT-Thread 的贡献!Thank you for your contribution to RT-Thread!

为确保代码符合 RT-Thread 的编码规范,请在你的仓库中执行以下步骤运行代码格式化工作流(如果格式化CI运行失败)。
To ensure your code complies with RT-Thread's coding style, please run the code formatting workflow by following the steps below (If the formatting of CI fails to run).


🛠 操作步骤 | Steps

  1. 前往 Actions 页面 | Go to the Actions page
    点击进入工作流 → | Click to open workflow →

  2. 点击 Run workflow | Click Run workflow

  • 设置需排除的文件/目录(目录请以"/"结尾)
    Set files/directories to exclude (directories should end with "/")
  • 将目标分支设置为 \ Set the target branch to:master
  • 设置PR number为 \ Set the PR number to:11464
  1. 等待工作流完成 | Wait for the workflow to complete
    格式化后的代码将自动推送至你的分支。
    The formatted code will be automatically pushed to your branch.

完成后,提交将自动更新至 master 分支,关联的 Pull Request 也会同步更新。
Once completed, commits will be pushed to the master branch automatically, and the related Pull Request will be updated.

如有问题欢迎联系我们,再次感谢您的贡献!💐
If you have any questions, feel free to reach out. Thanks again for your contribution!

@github-actions github-actions Bot added BSP BSP: Novosns BSP related with novosns labels Jun 11, 2026
@CYFS3

CYFS3 commented Jun 11, 2026

Copy link
Copy Markdown
Contributor

@dirtwillfly 麻烦签署一下CLA,谢谢!

@CYFS3

CYFS3 commented Jun 11, 2026

Copy link
Copy Markdown
Contributor

能否提供一个驱动正常执行的截图!麻烦把pr的标题修改一下,比较符合这次pr的内容,比如[bsp][NS800RT7P65]:......。另外rtconfig.h就不需要提交了,保持bsp最小化,然后麻烦加个i2c的ci检查,参考
https://club.rt-thread.org/ask/article/d273bbcd1f8779bc.html
谢谢!

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines +152 to +153
#define RT_USING_I2C
#define RT_USING_I2C_BITOPS
Comment on lines +428 to +430
#define BSP_USING_I2C
#define BSP_USING_HARD_I2C2
#define BSP_I2C2_BAUDRATE 100000
Comment on lines +208 to +210

menuconfig BSP_USING_I2C
bool "Enable I2C"
Comment on lines 28 to +32
if GetDepend('BSP_USING_SPI'):
src += ['drv_spi.c']

if GetDepend('BSP_USING_I2C'):
src += ['drv_hard_i2c.c']
Comment on lines +269 to +273
/* 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);

Comment on lines +326 to +327
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);
Comment on lines +369 to +391
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;
}
}
Comment on lines +141 to +157
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
Comment on lines +22 to +30
enum
{
#ifdef BSP_USING_HARD_I2C1
I2C1_INDEX,
#endif
#ifdef BSP_USING_HARD_I2C2
I2C2_INDEX,
#endif
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

BSP: Novosns BSP related with novosns BSP

Projects

None yet

Development

Successfully merging this pull request may close these issues.

5 participants