From 53a43e9d36c07d7cee4a4f5d4a322f0fb687c6f1 Mon Sep 17 00:00:00 2001 From: "Yukihiro \"Matz\" Matsumoto" Date: Fri, 27 Mar 2026 22:47:54 +0900 Subject: [PATCH] hw-gpio: consolidate platform gems into ports/ directories Move hw-esp32-gpio and hw-rp2040-gpio into hw-gpio/ports/esp32/ and hw-gpio/ports/rp2040/ using the new ports build system. Co-authored-by: Claude --- mrbgems/hw-esp32-gpio/mrbgem.rake | 7 ---- mrbgems/hw-gpio/README.md | 34 ++++++++----------- .../src => hw-gpio/ports/esp32}/gpio.c | 5 --- .../src => hw-gpio/ports/rp2040}/gpio.c | 5 --- mrbgems/hw-rp2040-gpio/mrbgem.rake | 7 ---- 5 files changed, 15 insertions(+), 43 deletions(-) delete mode 100644 mrbgems/hw-esp32-gpio/mrbgem.rake rename mrbgems/{hw-esp32-gpio/src => hw-gpio/ports/esp32}/gpio.c (85%) rename mrbgems/{hw-rp2040-gpio/src => hw-gpio/ports/rp2040}/gpio.c (84%) delete mode 100644 mrbgems/hw-rp2040-gpio/mrbgem.rake diff --git a/mrbgems/hw-esp32-gpio/mrbgem.rake b/mrbgems/hw-esp32-gpio/mrbgem.rake deleted file mode 100644 index f9b80f055..000000000 --- a/mrbgems/hw-esp32-gpio/mrbgem.rake +++ /dev/null @@ -1,7 +0,0 @@ -MRuby::Gem::Specification.new('hw-esp32-gpio') do |spec| - spec.license = 'MIT' - spec.author = 'mruby developers' - spec.summary = 'GPIO HAL for ESP32' - - spec.add_dependency 'hw-gpio' -end diff --git a/mrbgems/hw-gpio/README.md b/mrbgems/hw-gpio/README.md index c780a353b..43b15a898 100644 --- a/mrbgems/hw-gpio/README.md +++ b/mrbgems/hw-gpio/README.md @@ -6,26 +6,27 @@ It is designed for embedded platforms such as ESP32 and RP2040. ## Architecture -- **hw-gpio** (this gem) - Ruby API, C bindings, and HAL function declarations -- **hw-esp32-gpio** - HAL implementation for ESP32 (using ESP-IDF GPIO driver) -- **hw-rp2040-gpio** - HAL implementation for RP2040 (using Pico SDK) +Platform-specific HAL implementations are in `ports/` directories: -The platform gems depend on hw-gpio, so you only need to specify the -platform gem in your build configuration. +- `ports/esp32/` - ESP32 using ESP-IDF GPIO driver +- `ports/rp2040/` - RP2040 using Pico SDK + +The build system automatically compiles matching port sources based +on `conf.ports` setting. ## Build Configuration ```ruby # For ESP32 MRuby::CrossBuild.new('esp32') do |conf| - # ... - conf.gem "#{root}/mrbgems/hw-esp32-gpio" + conf.ports :esp32 + conf.gem core: 'hw-gpio' end # For RP2040 MRuby::CrossBuild.new('rp2040') do |conf| - # ... - conf.gem "#{root}/mrbgems/hw-rp2040-gpio" + conf.ports :rp2040 + conf.gem core: 'hw-gpio' end ``` @@ -121,9 +122,9 @@ GPIO.open_drain_at(pin) # enable open-drain ## HAL Interface -To add support for a new platform, create a gem (e.g., `hw-myboard-gpio`) -that depends on `hw-gpio` and implements the following C functions -declared in ``: +To add support for a new platform, create a `ports//` +directory and implement the following C functions declared in +``: ```c void mrb_gpio_init(uint8_t pin); @@ -135,13 +136,8 @@ int mrb_gpio_read(uint8_t pin); void mrb_gpio_write(uint8_t pin, uint8_t val); ``` -The `flags` parameter for `mrb_gpio_set_dir()` uses the bitmask -constants defined in the header (`MRB_GPIO_IN`, `MRB_GPIO_OUT`, -`MRB_GPIO_HIGH_Z`). - -The gem must also provide empty `mrb__gem_init()` and -`mrb__gem_final()` functions (with hyphens replaced by -underscores). +The port sources are compiled automatically when the build +configuration includes a matching `conf.ports` tag. ## License diff --git a/mrbgems/hw-esp32-gpio/src/gpio.c b/mrbgems/hw-gpio/ports/esp32/gpio.c similarity index 85% rename from mrbgems/hw-esp32-gpio/src/gpio.c rename to mrbgems/hw-gpio/ports/esp32/gpio.c index fbebeaaed..e3980c277 100644 --- a/mrbgems/hw-esp32-gpio/src/gpio.c +++ b/mrbgems/hw-gpio/ports/esp32/gpio.c @@ -48,8 +48,3 @@ mrb_gpio_write(uint8_t pin, uint8_t val) { gpio_set_level(pin, val); } - -#include - -void mrb_hw_esp32_gpio_gem_init(mrb_state *mrb) {} -void mrb_hw_esp32_gpio_gem_final(mrb_state *mrb) {} diff --git a/mrbgems/hw-rp2040-gpio/src/gpio.c b/mrbgems/hw-gpio/ports/rp2040/gpio.c similarity index 84% rename from mrbgems/hw-rp2040-gpio/src/gpio.c rename to mrbgems/hw-gpio/ports/rp2040/gpio.c index a01cc4958..7b69fa41e 100644 --- a/mrbgems/hw-rp2040-gpio/src/gpio.c +++ b/mrbgems/hw-gpio/ports/rp2040/gpio.c @@ -49,8 +49,3 @@ mrb_gpio_write(uint8_t pin, uint8_t val) { gpio_put(pin, val == 1); } - -#include - -void mrb_hw_rp2040_gpio_gem_init(mrb_state *mrb) {} -void mrb_hw_rp2040_gpio_gem_final(mrb_state *mrb) {} diff --git a/mrbgems/hw-rp2040-gpio/mrbgem.rake b/mrbgems/hw-rp2040-gpio/mrbgem.rake deleted file mode 100644 index d27b6b25f..000000000 --- a/mrbgems/hw-rp2040-gpio/mrbgem.rake +++ /dev/null @@ -1,7 +0,0 @@ -MRuby::Gem::Specification.new('hw-rp2040-gpio') do |spec| - spec.license = 'MIT' - spec.author = 'mruby developers' - spec.summary = 'GPIO HAL for RP2040' - - spec.add_dependency 'hw-gpio' -end