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

feat(drivers): Driver for MAX7318 GPIO expander #1295

Merged
merged 14 commits into from Sep 30, 2022

Conversation

zhiayang
Copy link
Contributor

@zhiayang zhiayang commented May 10, 2022

Adds a driver for the MAX7318 16-port I2C GPIO expander. Doesn't support the interrupt feature (yet?).

Has been tested on real hardware.

I've moved the existing mcp23017 driver to its own subfolder as well to keep things a little more organised.

Copy link
Contributor

@petejohanson petejohanson left a comment

Choose a reason for hiding this comment

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

Thanks for working on this!

I don't really agree w/ the need for separate dirs yet for this, IMHO, can you please not mix that in w/ the new driver here?

Other than that, a few suggestions, I imagine mostly stemming from you copying our current out of tree driver that's missing some upstream QOL improvements.

Comment on lines 6 to 9
menuconfig GPIO_MAX7318
bool "MAX7318 I2C-based GPIO chip"
depends on I2C
select HAS_DTS_GPIO
Copy link
Contributor

Choose a reason for hiding this comment

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

See the 595 gpio driver I just merged for an example of how to auto-enable this if found in the DT.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

yep, copied it over.


#define MAX7318_INIT(inst) \
static struct max7318_config max7318_##inst##_config = { \
.i2c_dev_name = DT_INST_BUS_LABEL(inst), \
Copy link
Contributor

Choose a reason for hiding this comment

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

The common stuff should be initialized here, see https://github.com/zmkfirmware/zmk/blob/main/app/drivers/gpio/gpio_595.c#L200 for an example.

Also, Zephyr has newer APIs for the bus stuff, which isn't incorporated into our local mcp23017 driver yet, but should be used for newer drivers. The I2C idea can be seen at https://github.com/zmkfirmware/zmk/blob/main/app/drivers/gpio/gpio_595.c#L205 but there is an equivalent macro and API for SPI.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I think you meant s/spi/i2c/. I hope I made the changes correctly (it compiles); will test with my board to make sure it works when I get the time (soon)

uint16_t data = sys_cpu_to_le16(value);
uint16_t dev_addr = ((struct max7318_config *)dev->config)->device_addr;

return i2c_burst_write(drv_data->i2c, dev_addr, reg, (uint8_t *)&data, sizeof(data));
Copy link
Contributor

Choose a reason for hiding this comment

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

Move to the _dt version of this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

uint16_t dev_addr = ((struct max7318_config *)dev->config)->device_addr;

uint16_t data = 0;
int ret = i2c_burst_read(drv_data->i2c, dev_addr, reg, (uint8_t *)&data, sizeof(data));
Copy link
Contributor

Choose a reason for hiding this comment

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

Ditto, move to the _dt version of this.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done.

@zhiayang
Copy link
Contributor Author

zhiayang commented Jun 4, 2022

Addressed the PR comments

@caksoylar caksoylar added enhancement New feature or request core Core functionality/behavior of ZMK labels Jul 4, 2022
@zhiayang
Copy link
Contributor Author

@petejohanson are there any more issues preventing this from being merged? let me know what else to change. thanks!

Copy link
Contributor

@petejohanson petejohanson left a comment

Choose a reason for hiding this comment

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

Just one minor nitpick, probably keeping this from automatically being enabled if the DTS contains a compatible node.

# Copyright (c) 2022 The ZMK Contributors
# SPDX-License-Identifier: MIT

DT_COMPAT_ZMK_GPIO_MAX7318 := zmk,gpio-max7318
Copy link
Contributor

Choose a reason for hiding this comment

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

This doesn't match the compatible defined in the yaml binding or used in the code. Accident or intentional?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah, my bad. The MCP23017 driver doesn't have gpio- in front, but the 595 does -- which one should I follow here?

Thanks!

Copy link
Contributor

Choose a reason for hiding this comment

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

Follow the mcp format is fine.

@zhiayang
Copy link
Contributor Author

should've fixed them now!

Copy link
Contributor

@petejohanson petejohanson left a comment

Choose a reason for hiding this comment

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

Just one other nitpick for the naming changes.

app/drivers/gpio/Kconfig.max7318 Outdated Show resolved Hide resolved
app/drivers/gpio/Kconfig.max7318 Outdated Show resolved Hide resolved
zhiayang and others added 2 commits September 28, 2022 14:25
Co-authored-by: Pete Johanson <peter@peterjohanson.com>
Co-authored-by: Pete Johanson <peter@peterjohanson.com>
@zhiayang
Copy link
Contributor Author

done!

Copy link
Contributor

@petejohanson petejohanson left a comment

Choose a reason for hiding this comment

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

Thanks!

@petejohanson petejohanson merged commit cc3d552 into zmkfirmware:main Sep 30, 2022
alinelena pushed a commit to alinelena/zmk that referenced this pull request Sep 30, 2022
Add driver for max7318 i2c gpio expander

Co-authored-by: Pete Johanson <peter@peterjohanson.com>
alinelena pushed a commit to alinelena/zmk that referenced this pull request Sep 30, 2022
Add driver for max7318 i2c gpio expander

Co-authored-by: Pete Johanson <peter@peterjohanson.com>
alinelena pushed a commit to alinelena/zmk that referenced this pull request Sep 30, 2022
Add driver for max7318 i2c gpio expander

Co-authored-by: Pete Johanson <peter@peterjohanson.com>
tyalie pushed a commit to tyalie/zmk that referenced this pull request Nov 15, 2022
Add driver for max7318 i2c gpio expander

Co-authored-by: Pete Johanson <peter@peterjohanson.com>
@zhiayang zhiayang deleted the gpio-driver-max7318 branch December 21, 2022 08:40
zhiayang added a commit to zhiayang/zmk that referenced this pull request Dec 21, 2022
Add driver for max7318 i2c gpio expander

Co-authored-by: Pete Johanson <peter@peterjohanson.com>
rafaelromao pushed a commit to rafaelromao/zmk that referenced this pull request Dec 22, 2022
Add driver for max7318 i2c gpio expander

Co-authored-by: Pete Johanson <peter@peterjohanson.com>
rafaelromao pushed a commit to rafaelromao/zmk that referenced this pull request Dec 23, 2022
Add driver for max7318 i2c gpio expander

Co-authored-by: Pete Johanson <peter@peterjohanson.com>
abondis pushed a commit to abondis/zmk that referenced this pull request Feb 12, 2023
Add driver for max7318 i2c gpio expander

Co-authored-by: Pete Johanson <peter@peterjohanson.com>
abondis pushed a commit to abondis/zmk that referenced this pull request Feb 12, 2023
Add driver for max7318 i2c gpio expander

Co-authored-by: Pete Johanson <peter@peterjohanson.com>
abondis pushed a commit to abondis/zmk that referenced this pull request Feb 14, 2023
Add driver for max7318 i2c gpio expander

Co-authored-by: Pete Johanson <peter@peterjohanson.com>
NikolaRavic pushed a commit to NikolaRavic/zmk-firmware that referenced this pull request Feb 27, 2023
Add driver for max7318 i2c gpio expander

Co-authored-by: Pete Johanson <peter@peterjohanson.com>
Lugoues pushed a commit to Lugoues/zmk that referenced this pull request Mar 9, 2023
Add driver for max7318 i2c gpio expander

Co-authored-by: Pete Johanson <peter@peterjohanson.com>
nickconway pushed a commit to nickconway/zmk that referenced this pull request Jun 2, 2023
Add driver for max7318 i2c gpio expander

Co-authored-by: Pete Johanson <peter@peterjohanson.com>
yuanbin pushed a commit to yuanbin/zmk that referenced this pull request Jun 14, 2023
Add driver for max7318 i2c gpio expander

Co-authored-by: Pete Johanson <peter@peterjohanson.com>
FearlessSpiff pushed a commit to FearlessSpiff/zmk that referenced this pull request Oct 31, 2023
Add driver for max7318 i2c gpio expander

Co-authored-by: Pete Johanson <peter@peterjohanson.com>
FearlessSpiff pushed a commit to FearlessSpiff/zmk that referenced this pull request Oct 31, 2023
Add driver for max7318 i2c gpio expander

Co-authored-by: Pete Johanson <peter@peterjohanson.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
core Core functionality/behavior of ZMK enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants