Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[components][i2c]增加通用的软件模拟 I2C #7850

Merged
merged 19 commits into from
Oct 17, 2023
Merged

[components][i2c]增加通用的软件模拟 I2C #7850

merged 19 commits into from
Oct 17, 2023

Conversation

sp-cai
Copy link
Contributor

@sp-cai sp-cai commented Jul 23, 2023

实现无需直接操作任何底层硬件的通用软件 I2C ,并提级到设备框架层,用于替代所有 BSP 的软件模拟 I2C 。

拉取/合并请求描述:(PR description)

[

为什么提交这份PR (why to submit this PR)

使用 pin 设备和软延时就可以实现软件模拟 I2C ,没必要每一个BSP都要实现一次。
#7725

你的解决方案是什么 (what is your solution)

  1. 使用 pin 设备实现 SCL 线和 SDA 线电平。
  2. 使用 rt_hw_us_delay 实现时序延时。

在什么测试环境下测试通过 (what is the test environment)

使用 HK32F030 和 HC32F460 通过本软件模拟 I2C 读写 24C02 和 KT06XX 等。

]

当前拉取/合并请求的状态 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

实现无需直接操作任何底层硬件的通用软件 I2C ,并提级到设备框架层,用于替代所有 BSP 的软件模拟 I2C 。
@mysterywolf mysterywolf added the in progress PR/issue in progress. label Jul 23, 2023
components/drivers/Kconfig Outdated Show resolved Hide resolved
components/drivers/i2c/soft_i2c.c Outdated Show resolved Hide resolved
@supperthomas supperthomas added the discussion This PR/issue needs to be discussed later label Jul 26, 2023
@sp-cai sp-cai requested a review from supperthomas July 27, 2023 05:07
Copy link
Member

@supperthomas supperthomas left a comment

Choose a reason for hiding this comment

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

建议还是保留之前的分层结构,这样维护代码会方便一些~,也可以解一些耦合~也便于维护

@sp-cai
Copy link
Contributor Author

sp-cai commented Jul 30, 2023

建议还是保留之前的分层结构,这样维护代码会方便一些~,也可以解一些耦合~也便于维护

好的,我再改一下

@sp-cai
Copy link
Contributor Author

sp-cai commented Jul 31, 2023

建议还是保留之前的分层结构,这样维护代码会方便一些~,也可以解一些耦合~也便于维护

已改好

@sp-cai sp-cai requested a review from supperthomas July 31, 2023 14:23
components/drivers/i2c/soft_i2c.c Show resolved Hide resolved
@@ -55,9 +56,9 @@ struct rt_i2c_bus_device
struct rt_device parent;
const struct rt_i2c_bus_device_ops *ops;
rt_uint16_t flags;
rt_uint16_t retries;
Copy link
Member

Choose a reason for hiding this comment

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

i2c.h 修改理由?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

一个操作的重试次数没必要用32位数值,16位数值更有利于字节对齐。
这个修改探讨一下

Copy link
Member

Choose a reason for hiding this comment

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

你在哪里用到这个变量了?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

见 i2c-bit-ops.c 这个文件用到的

Copy link
Member

Choose a reason for hiding this comment

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

哦,你改了下位置。

Copy link
Contributor Author

Choose a reason for hiding this comment

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

是的

components/drivers/Kconfig Outdated Show resolved Hide resolved
components/drivers/Kconfig Outdated Show resolved Hide resolved
@@ -55,9 +56,9 @@ struct rt_i2c_bus_device
struct rt_device parent;
const struct rt_i2c_bus_device_ops *ops;
rt_uint16_t flags;
rt_uint16_t retries;
Copy link
Member

Choose a reason for hiding this comment

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

你在哪里用到这个变量了?

components/drivers/Kconfig Outdated Show resolved Hide resolved
components/drivers/i2c/soft_i2c.c Outdated Show resolved Hide resolved
components/drivers/Kconfig Outdated Show resolved Hide resolved
@supperthomas
Copy link
Member

i2c.h 不建议修改。

@sp-cai
Copy link
Contributor Author

sp-cai commented Aug 17, 2023

文件 i2c.h 的更改是很谨慎的,已检索过所有代码确认是完全兼容的且无不良影响才改的。
其实此修改与本 PR 主题无关,可以独立 PR,要不要撤销此文件的修改,然后重开一个 PR 讨论?
请回复我马上改
@supperthomas

@supperthomas
Copy link
Member

i2c.h可以另外提PR

@sp-cai
Copy link
Contributor Author

sp-cai commented Aug 17, 2023

i2c.h可以另外提PR

好的,已改好

@supperthomas supperthomas removed in progress PR/issue in progress. discussion This PR/issue needs to be discussed later labels Aug 17, 2023
@supperthomas
Copy link
Member

@Guozhanxin

@sp-cai
Copy link
Contributor Author

sp-cai commented Aug 24, 2023

@mysterywolf @Guozhanxin

@mysterywolf
Copy link
Member

请耐心等待一下 这个PR还在决策怎么合入比较好

@mysterywolf mysterywolf linked an issue Aug 25, 2023 that may be closed by this pull request
@mysterywolf mysterywolf merged commit 7f6f086 into RT-Thread:master Oct 17, 2023
33 checks passed
@meng-plus
Copy link
Contributor

kconfig 处使用问题反馈与建议
https://github.com/RT-Thread/rt-thread/blob/feature/air32f103cct6/components/drivers/Kconfig#L146-L163

config RT_SOFT_I2C1_SCL_PIN
                    int "SCL pin number"
                    range 0 32767
                    default 1
                config RT_SOFT_I2C1_SDA_PIN
                    int "SDA pin number"
                    range 0 32767
                    default 2

pin引脚配置项采用的 int 类型 这样不方便引脚标号写入,建议更换为hex 方式更加友好

config RT_SOFT_I2C1_SCL_PIN
                    hex "SCL pin number"
                    range 0x00 0xFF
                    default 1
                config RT_SOFT_I2C1_SDA_PIN
                    hex "SDA pin number"
                    range 0x00 0xFF
                    default 2

@sp-cai
Copy link
Contributor Author

sp-cai commented Oct 22, 2023

kconfig 处使用问题反馈与建议 https://github.com/RT-Thread/rt-thread/blob/feature/air32f103cct6/components/drivers/Kconfig#L146-L163

config RT_SOFT_I2C1_SCL_PIN
                    int "SCL pin number"
                    range 0 32767
                    default 1
                config RT_SOFT_I2C1_SDA_PIN
                    int "SDA pin number"
                    range 0 32767
                    default 2

pin引脚配置项采用的 int 类型 这样不方便引脚标号写入,建议更换为hex 方式更加友好

config RT_SOFT_I2C1_SCL_PIN
                    hex "SCL pin number"
                    range 0x00 0xFF
                    default 1
                config RT_SOFT_I2C1_SDA_PIN
                    hex "SDA pin number"
                    range 0x00 0xFF
                    default 2

这个问题已讨论过,见上面有关 components/drivers/Kconfig 的讨论记录。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

I2C相关PR整合
4 participants