Skip to content

add CH422 support#42

Draft
omelia-iliffe wants to merge 2 commits intoRahix:mainfrom
omelia-iliffe:CH422
Draft

add CH422 support#42
omelia-iliffe wants to merge 2 commits intoRahix:mainfrom
omelia-iliffe:CH422

Conversation

@omelia-iliffe
Copy link
Copy Markdown
Contributor

Hi!

I've been working recently with a Waveshare ESP32-S3-Touch-LCD-7 which uses a CH422 IO chip (datasheet) for some of its core functions.
So I've had a go at adding support for it to the crate.

It's a bit a strange chip:

  • it has 12 pins:
    • a set of 4 output pins with 2 modes (push pull or open drain)
    • a set of 8 with 2 modes (inputs or push pull outputs)
  • the modes of the two sets control the entire set
  • no i2c address so the commands have to be bit shifted before being sent as an address

my work in progress implementation just supports the 8 io pins. It uses type state for switch between the two modes (input and output) but I'm not sure this is the right solution for a couple of reasons.

  • When created the library assumes it will be in input mode, it may not be
  • When changing modes the user has to specify the PortMutex generic, let mut io: port_expander::Ch422<RefCell<_>> = port_expander::Ch422::new(i2c).enable_output().unwrap();
  • the enable_output method is fallible and will drop the Port if it returns an Err

But using typestate means that when we call split, the Pins have the correct mode.

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.

1 participant