Skip to content

Fix Pin Modes #14

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

Merged
merged 19 commits into from
Jul 17, 2023
Merged

Fix Pin Modes #14

merged 19 commits into from
Jul 17, 2023

Conversation

vickash
Copy link
Contributor

@vickash vickash commented Jun 28, 2023

This fixes the following issues:

  • GPIO_MODE_INPUT_PULLDOWN could never be set. It was using the same bit in the mask as GPIO_MODE_INPUT_PULLUP, so either one would set the pullup resistor.
  • GPIO_FLOATING would not be set if GPIO::pin_mode is called first with GPIO_MODE_INPUT_PULLUP and then later with plain GPIO_MODE_INPUT. Instead, it would stay GPIO_MODE_INPUT_PULLUP.

This adds the following:

  • Open-drain modes were not exposed to mruby. They are now, with GPIO_MODE_OUTPUT_OD and GPIO_MODE_INPUT_OUTPUT_OD.
  • Adds GPIO_MODE_INPUT_PULLUP_PULLDOWN which enables both pull resistors.

Note: Again, this is based on my fork, and would integrate all my previous PRs. Relevant commits are: e57b1df and ce5917d.

vickash added 18 commits March 11, 2023 11:35
* commit 'c7ad6b17885043f18f25b3545453cec6d8c8eae2':
  Add shorthand constants back to GPIO module and fix example
  Constants under ESP32 instead of GPIO module
* commit '71d94b41a9f0e071b41356c47e3af78f78a7c5cc':
  Fix digital write instead of read
  Define both method styles in C. Alias methods aren't avaialble when top level including
  Define methods in C as snake case instead of camel case
Should catch original ESP32, S2, S3, C2, C3, C6 and H2 variants
Fixes the following:
  Pulldown resistor was not being enabled if requested
  Pull mode wasn't reset to floating if pullup was used and then mode was set again without pullup

Makes the following available in mruby:
  Combined pullup pulldown mode
  Output open-drain
  Input-output open-drain
Not all of the channels are connected to pins
* variants:
  Limit ADCs per chip even though they all define 0..9
Numbers that didn't originate in C (example: defining HIGH as 1 in mruby) can cause the function to do nothing
@vickash
Copy link
Contributor Author

vickash commented Jul 16, 2023

Can we merge this please?

Here's a summary of changes:

  • Uses current IDF drivers for DAC and ADC instead of deprecated ones
  • Fixes bugs where pulldown could not be set and pullup could not be unset once set
  • Handles GPIO, DAC and ADC pins available on S2 and S3 variants, so they work with this gem
  • Enables the following pin modes in mruby:
    • Pullup and pulldown both enabled
    • Open-drain output
    • Open-drain input-output

Then the 2 breaking changes:

  • Definition of both camel-case and snake-case mruby methods in C. See explanation here.
  • Moving all constants into the ESP32::Constants/ESP32 namespace, exactly matching their names to the ESP-IDF. Explanation here. In short: it's easier to read, and makes the existing IDF documentation more useful to a user if we use the same constant names and keep them all in one place.

EDIT: Added one more commit.

  • Added the new modes to ESP32::GPIO, with names equal to the C constants without GPIO_MODE_ prefix.
  • ESP32::GPIO::Pin::PIN_MODE uses the lowercase symbolized form for keys. Slightly different than before, where input was omitted sometimes, but more consistent.

EDIT2: Once merged, master branch should be merged into 0.5 branch too, so the main repo picks up the changes, since that is essentially the "release" branch.

Copy link
Contributor

@yuuu yuuu left a comment

Choose a reason for hiding this comment

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

OK 👍 Namespace constants have been reorganized and more constants can now be used. Thanks.

@yuuu yuuu merged commit 6c1e6da into mruby-esp32:master Jul 17, 2023
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.

2 participants