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

Implement mpr121 touch sensor capability to GPIO Expanders #192

Merged
merged 1 commit into from
Oct 22, 2022

Conversation

caelor
Copy link

@caelor caelor commented Oct 20, 2022

This is an updated PR cleanly against the v4.3 branch, as #190 was raised against the wrong branch.

Commit 396e754 from #190 could be cherry picked for a REAME.md update (as the v4.3 README.md isn't a small update to match)

This pull request adds an I2C based MP121 chip as a GPIO Expander. This chip provides 12 capacitive touch sensing pins, which are implemented here as inputs suitable for buttons.

The chip also can alternatively provide 8 GPIOs if correctly configured - this pull request does not implement this functionality (there seem to be more cost effective i2c GPIO expanders).

To use, set the gpio_exp_config nvs parameter to model=mpr121,addr=90,count=12,intr=<n> (assuming on default i2c address). GPIOs 40-51 can then be used as BUTTON_HIGH buttons.

The chip init parameters have been taken from those used by https://github.com/BareConductive/mpr121 with touch and release thresholds used by the SimpleTouch example there. Those values work for me.

@sle118 sle118 merged commit 6c524cd into sle118:master-v4.3 Oct 22, 2022
Copy link
Collaborator

@philippe44 philippe44 left a comment

Choose a reason for hiding this comment

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

Can you put the initialization in a table instead so so many calls to I2c_write?

@caelor
Copy link
Author

caelor commented Nov 11, 2022

Can you put the initialization in a table instead so so many calls to I2c_write?

I agree that would likely be tidier, but also beyond my abilities these days - I've not routinely written C for over 20 years and I'm more than rusty at it.

I'd be happy to test a table based alternative to confirm correct initialisation though.

@philippe44
Copy link
Collaborator

philippe44 commented Nov 11, 2022

Something like

static const struct {
	uint8_t addr;
	uint8_t data;
} mpr121_init_table[] = { { 0x2b, 0x01 }, { 0x2c, 0x01 }, { 0x2d, 0x10 }, {0x2e, 0x20}, {0, 0} };

for (int i = 0; mpr121_init_table[i].addr; i++) {
	err |= i2c_write(self->phy.port, self->phy.addr, mpr121_init_table[i].addr, mpr121_init_table[i].data, 1);
}

@caelor
Copy link
Author

caelor commented Nov 12, 2022

Thanks, I'm currently away on business but I'll try that when I return.

@caelor
Copy link
Author

caelor commented Nov 20, 2022

I've attempted to implement a tabular initialisation approach (see gist https://gist.github.com/caelor/db098ec88741630ab662f3b8fc4cdcd8).

Unfortunately, I've not been able to test as my docker container now seems to fail with IDF errors. I've spent several hours trying to get to the bottom of it without any luck. I'll revisit if I get chance around other commitments.

@philippe44
Copy link
Collaborator

philippe44 commented Nov 20, 2022

Looks like the right implementation to me. I'll take it and push an update

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.

None yet

3 participants