Skip to content

Constants under ESP32 instead of GPIO module #11

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 2 commits into from
Jul 17, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
18 changes: 12 additions & 6 deletions mrblib/gpio.rb
Original file line number Diff line number Diff line change
@@ -1,6 +1,12 @@
module ESP32
include Constants

module GPIO
include Constants
INPUT_PULLUP = ESP32::GPIO_MODE_INPUT_PULLUP
INPUT_PULLDOWN = ESP32::GPIO_MODE_INPUT_PULLDOWN
INPUT = ESP32::GPIO_MODE_INPUT
OUTPUT = ESP32::GPIO_MODE_OUTPUT
INPUT_OUTPUT = ESP32::GPIO_MODE_INPUT_OUTPUT

class << self
alias :digital_write :digitalWrite
Expand All @@ -12,11 +18,11 @@ class << self

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
pullup: ESP32::GPIO_MODE_INPUT_PULLUP,
pulldown: ESP32::GPIO_MODE_INPUT_PULLDOWN,
input: ESP32::GPIO_MODE_INPUT,
output: ESP32::GPIO_MODE_OUTPUT,
inout: ESP32::GPIO_MODE_INPUT_OUTPUT
}

attr_reader :pin
Expand Down
12 changes: 6 additions & 6 deletions src/gpio.c
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ mrb_mruby_esp32_gpio_gem_init(mrb_state* mrb)

adc1_config_width(ADC_BITWIDTH_12);

constants = mrb_define_module_under(mrb, gpio, "Constants");
constants = mrb_define_module_under(mrb, esp32, "Constants");

#define define_const(SYM) \
do { \
Expand Down Expand Up @@ -172,11 +172,11 @@ mrb_mruby_esp32_gpio_gem_init(mrb_state* mrb)
mrb_define_const(mrb, constants, "LOW", mrb_fixnum_value(0));
mrb_define_const(mrb, constants, "HIGH", mrb_fixnum_value(1));

mrb_define_const(mrb, constants, "INPUT", mrb_fixnum_value(GPIO_MODE_INPUT));
mrb_define_const(mrb, constants, "INPUT_OUTPUT", mrb_fixnum_value(GPIO_MODE_INPUT_OUTPUT));
mrb_define_const(mrb, constants, "OUTPUT", mrb_fixnum_value(GPIO_MODE_OUTPUT));
mrb_define_const(mrb, constants, "INPUT_PULLUP", mrb_fixnum_value(GPIO_MODE_INPUT_PULLUP));
mrb_define_const(mrb, constants, "INPUT_PULLDOWN", mrb_fixnum_value(GPIO_MODE_INPUT_PULLDOWN));
mrb_define_const(mrb, constants, "GPIO_MODE_INPUT", mrb_fixnum_value(GPIO_MODE_INPUT));
mrb_define_const(mrb, constants, "GPIO_MODE_INPUT_OUTPUT", mrb_fixnum_value(GPIO_MODE_INPUT_OUTPUT));
mrb_define_const(mrb, constants, "GPIO_MODE_OUTPUT", mrb_fixnum_value(GPIO_MODE_OUTPUT));
mrb_define_const(mrb, constants, "GPIO_MODE_INPUT_PULLUP", mrb_fixnum_value(GPIO_MODE_INPUT_PULLUP));
mrb_define_const(mrb, constants, "GPIO_MODE_INPUT_PULLDOWN", mrb_fixnum_value(GPIO_MODE_INPUT_PULLDOWN));

}

Expand Down