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
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ In `CMakeLists.txt`, make sure the line `PRIV_REQUIRES` includes the `driver` co

## Example
```ruby
include ESP32::Constants
include ESP32::GPIO

led = GPIO_NUM_4
Expand Down
34 changes: 19 additions & 15 deletions mrblib/gpio.rb
Original file line number Diff line number Diff line change
@@ -1,22 +1,26 @@
module ESP32
module GPIO
include Constants

class << self
alias :digital_write :digitalWrite
alias :digital_read :digitalRead
alias :analog_write :analogWrite
alias :analog_read :analogRead
alias :pin_mode :pinMode
end
include Constants

module GPIO
INPUT = ESP32::GPIO_MODE_INPUT
OUTPUT = ESP32::GPIO_MODE_OUTPUT
INPUT_PULLUP = ESP32::GPIO_MODE_INPUT_PULLUP
INPUT_PULLDOWN = ESP32::GPIO_MODE_INPUT_PULLDOWN
INPUT_PULLUP_PULLDOWN = ESP32::GPIO_MODE_INPUT_PULLUP_PULLDOWN
INPUT_OUTPUT = ESP32::GPIO_MODE_INPUT_OUTPUT
INPUT_OUTPUT_OD = ESP32::GPIO_MODE_INPUT_OUTPUT_OD
OUTPUT_OD = ESP32::GPIO_MODE_OUTPUT_OD

class Pin
PIN_MODE = {
pullup: ESP32::GPIO::INPUT_PULLUP,
pulldown: ESP32::GPIO::INPUT_PULLDOWN,
input: ESP32::GPIO::INPUT,
output: ESP32::GPIO::OUTPUT,
inout: ESP32::GPIO::INPUT_OUTPUT
input: ESP32::GPIO_MODE_INPUT,
output: ESP32::GPIO_MODE_OUTPUT,
input_pullup: ESP32::GPIO_MODE_INPUT_PULLUP,
input_pulldown: ESP32::GPIO_MODE_INPUT_PULLDOWN,
input_pullup_pulldown: ESP32::GPIO_MODE_INPUT_PULLUP_PULLDOWN,
input_output: ESP32::GPIO_MODE_INPUT_OUTPUT,
input_output_od: ESP32::GPIO_MODE_INPUT_OUTPUT_OD,
output_od: ESP32::GPIO_MODE_OUTPUT_OD,
}

attr_reader :pin
Expand Down
Loading