Skip to content

Conversation

@Donny9
Copy link
Contributor

@Donny9 Donny9 commented Dec 30, 2025

Summary

This commit adds a new lower-half driver implementation for I2C bit-bang that uses IO expander pins as the GPIO backend, enabling I2C bit-bang functionality on systems where direct GPIO access is not available or when I2C needs to be implemented using IO expander pins.

Background:
The existing I2C bit-bang driver (i2c_bitbang.c) provides a generic upper-half implementation that requires a platform-specific lower-half to control the SDA and SCL GPIO lines. Previously, each platform had to implement its own lower-half using direct GPIO access.

Usage Example:

FAR struct ioexpander_dev_s *ioe = /* get IO expander */; FAR struct i2c_master_s *i2c;

/* Initialize I2C bit-bang using IO expander pins 10 (SCL) and 11 (SDA) */ i2c = i2c_bitbang_ioexpander_initialize(ioe, 10, 11, 0); if (i2c)
  {
    /* Use i2c master device normally */
  }

Impact

This commit introduces a reusable lower-half implementation that:

  • Uses the standard IO expander API (IOEXP_WRITEPIN, IOEXP_READPIN)
  • Configures pins as open-drain outputs for proper I2C operation
  • Provides a simple initialization function that takes:
    • Pointer to IO expander device
    • SCL pin number
    • SDA pin number
    • I2C bus number

Testing

test for tc4d9 evb,
image
image

@github-actions github-actions bot added Area: Drivers Drivers issues Size: M The size of the change in this PR is medium labels Dec 30, 2025
Copy link
Contributor

@acassis acassis left a comment

Choose a reason for hiding this comment

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

@Donny9 this is really cool feature!!!

Please provide some basic Documentation

(optional, but desired) Please provide some basic board profile example that use it, ideally using sim and some low cost I/O Expander like the CJMCU-2233HL module.

…it-bang

This commit adds a new lower-half driver implementation for I2C bit-bang
that uses IO expander pins as the GPIO backend, enabling I2C bit-bang
functionality on systems where direct GPIO access is not available or
when I2C needs to be implemented using IO expander pins.

Background:
The existing I2C bit-bang driver (i2c_bitbang.c) provides a generic
upper-half implementation that requires a platform-specific lower-half
to control the SDA and SCL GPIO lines. Previously, each platform had to
implement its own lower-half using direct GPIO access.

Usage Example:
FAR struct ioexpander_dev_s *ioe = /* get IO expander */;
FAR struct i2c_master_s *i2c;

/* Initialize I2C bit-bang using IO expander pins 10 (SCL) and 11 (SDA) */
i2c = i2c_bitbang_ioexpander_initialize(ioe, 10, 11, 0);
if (i2c)
  {
    /* Use i2c master device normally */
  }

Signed-off-by: dongjiuzhu1 <dongjiuzhu1@xiaomi.com>
This documentation helps users understand when and how to use IO expander
pins for implementing additional I2C buses in their applications.

Related commit: 06099d4 (drivers/i2c: Add IO expander-based I2C bit-bang)

Signed-off-by: dongjiuzhu1 <dongjiuzhu1@xiaomi.com>
@Donny9
Copy link
Contributor Author

Donny9 commented Dec 30, 2025

@Donny9 this is really cool feature!!!

Please provide some basic Documentation

(optional, but desired) Please provide some basic board profile example that use it, ideally using sim and some low cost I/O Expander like the CJMCU-2233HL module.

Done~ @acassis

@github-actions github-actions bot added the Area: Documentation Improvements or additions to documentation label Dec 30, 2025
@acassis
Copy link
Contributor

acassis commented Dec 30, 2025

@Donny9 excellent documentation! Kudos!!!

@acassis
Copy link
Contributor

acassis commented Dec 30, 2025

@Donny9 for some reason the size of this config increased too much and CI is failing:

Configuration/Tool: lm3s6432-s2e/nsh,CONFIG_ARM_TOOLCHAIN_GNU_EABI
2025-12-30 17:51:58

Cleaning...
Configuring...
Disabling CONFIG_ARM_TOOLCHAIN_GNU_EABI
Enabling CONFIG_ARM_TOOLCHAIN_GNU_EABI
Building NuttX...
lto-wrapper: warning: using serial compilation of 4 LTRANS jobs
lto-wrapper: note: see the '-flto' option documentation for more information
/tools/gcc-arm-none-eabi/bin/../lib/gcc/arm-none-eabi/13.2.1/../../../../arm-none-eabi/bin/ld: /github/workspace/sources/nuttx/nuttx section .data' will not fit in region flash'
/tools/gcc-arm-none-eabi/bin/../lib/gcc/arm-none-eabi/13.2.1/../../../../arm-none-eabi/bin/ld: region `flash' overflowed by 32 bytes
/tools/gcc-arm-none-eabi/bin/../lib/gcc/arm-none-eabi/13.2.1/../../../../arm-none-eabi/bin/ld: warning: /github/workspace/sources/nuttx/nuttx has a LOAD segment with RWX permissions
collect2: error: ld returned 1 exit status
make[1]: *** [Makefile:217: nuttx] Error 1
make: *** [tools/Unix.mk:552: nuttx] Error 2
make: Target 'all' not remade because of errors.
/github/workspace/sources/nuttx/tools/testbuild.sh: line 385: /github/workspace/sources/nuttx/../nuttx/nuttx.manifest: No such file or directory
[1/1] Normalize lm3s6432-s2e/nsh
HEAD detached at pull/17746/merge
Untracked files:
(use "git add ..." to include in what will be committed)
boards/arm/tiva/lm3s6432-s2e/scripts/lm3s6432-s2e.ld.tmp

@raiden00pl
Copy link
Member

@acassis master is broken. All PRs fail on this configuration. Some change that increased flash usage was merged and CI didn't detect it.

@acassis
Copy link
Contributor

acassis commented Dec 31, 2025

@raiden00pl see #17751 according to @Donny9 it was recent network patches.

The wapi also stopped to get DHCP correctly for WiFi: #17736

I didn't test Ethernet boards, but I suppose it could be broke as well.

We need more reliable testing on our CI to avoid regressions like this.

Espressif also has an internal CI using Robot framework, but it also failed to get this issue, probably because they are using static IP, please confirm @fdcavalcanti || @tmedicci || @eren-terzioglu

@acassis
Copy link
Contributor

acassis commented Dec 31, 2025

@Donny9 please rebase this PR as well

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Area: Documentation Improvements or additions to documentation Area: Drivers Drivers issues Size: M The size of the change in this PR is medium

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants