From a8c82b506f5fe1bdaee00ae2798265a26fbc2823 Mon Sep 17 00:00:00 2001 From: "Yukihiro \"Matz\" Matsumoto" Date: Fri, 27 Mar 2026 22:48:53 +0900 Subject: [PATCH] hw-uart: consolidate platform gems into ports/ directories Move hw-esp32-uart and hw-rp2040-uart into hw-uart/ports/esp32/ and hw-uart/ports/rp2040/ using the new ports build system. Co-authored-by: Claude --- mrbgems/hw-esp32-uart/mrbgem.rake | 7 ------ mrbgems/hw-rp2040-uart/mrbgem.rake | 7 ------ mrbgems/hw-uart/README.md | 23 +++++++++---------- .../src => hw-uart/ports/esp32}/uart.c | 5 ---- .../src => hw-uart/ports/rp2040}/uart.c | 5 ---- 5 files changed, 11 insertions(+), 36 deletions(-) delete mode 100644 mrbgems/hw-esp32-uart/mrbgem.rake delete mode 100644 mrbgems/hw-rp2040-uart/mrbgem.rake rename mrbgems/{hw-esp32-uart/src => hw-uart/ports/esp32}/uart.c (96%) rename mrbgems/{hw-rp2040-uart/src => hw-uart/ports/rp2040}/uart.c (95%) diff --git a/mrbgems/hw-esp32-uart/mrbgem.rake b/mrbgems/hw-esp32-uart/mrbgem.rake deleted file mode 100644 index f96d5f083..000000000 --- a/mrbgems/hw-esp32-uart/mrbgem.rake +++ /dev/null @@ -1,7 +0,0 @@ -MRuby::Gem::Specification.new('hw-esp32-uart') do |spec| - spec.license = 'MIT' - spec.author = 'mruby developers' - spec.summary = 'UART HAL for ESP32' - - spec.add_dependency 'hw-uart' -end diff --git a/mrbgems/hw-rp2040-uart/mrbgem.rake b/mrbgems/hw-rp2040-uart/mrbgem.rake deleted file mode 100644 index 0e56e581f..000000000 --- a/mrbgems/hw-rp2040-uart/mrbgem.rake +++ /dev/null @@ -1,7 +0,0 @@ -MRuby::Gem::Specification.new('hw-rp2040-uart') do |spec| - spec.license = 'MIT' - spec.author = 'mruby developers' - spec.summary = 'UART HAL for RP2040' - - spec.add_dependency 'hw-uart' -end diff --git a/mrbgems/hw-uart/README.md b/mrbgems/hw-uart/README.md index d174bbd89..502aa5e5d 100644 --- a/mrbgems/hw-uart/README.md +++ b/mrbgems/hw-uart/README.md @@ -5,12 +5,11 @@ It is designed for embedded platforms such as ESP32 and RP2040. ## Architecture -- **hw-uart** (this gem) - Ruby API, C bindings, ring buffer, and HAL - function declarations -- **hw-esp32-uart** - HAL implementation for ESP32 (using ESP-IDF UART - driver with FreeRTOS task for RX) -- **hw-rp2040-uart** - HAL implementation for RP2040 (using Pico SDK - with IRQ-driven RX) +Platform-specific HAL implementations are in `ports/` directories: + +- `ports/esp32/` - ESP32 using ESP-IDF UART driver with FreeRTOS + task for RX +- `ports/rp2040/` - RP2040 using Pico SDK with IRQ-driven RX Received data is buffered in a ring buffer (allocated by the common gem) that the platform HAL populates via interrupt or task. The ring @@ -21,14 +20,14 @@ buffer size must be a power of two. ```ruby # For ESP32 MRuby::CrossBuild.new('esp32') do |conf| - # ... - conf.gem "#{root}/mrbgems/hw-esp32-uart" + conf.ports :esp32 + conf.gem core: 'hw-uart' end # For RP2040 MRuby::CrossBuild.new('rp2040') do |conf| - # ... - conf.gem "#{root}/mrbgems/hw-rp2040-uart" + conf.ports :rp2040 + conf.gem core: 'hw-uart' end ``` @@ -153,8 +152,8 @@ Set the line ending used by `puts`. Must be `"\n"`, `"\r"`, or ## HAL Interface -To add support for a new platform, create a gem that depends on -`hw-uart` 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 diff --git a/mrbgems/hw-esp32-uart/src/uart.c b/mrbgems/hw-uart/ports/esp32/uart.c similarity index 96% rename from mrbgems/hw-esp32-uart/src/uart.c rename to mrbgems/hw-uart/ports/esp32/uart.c index 7d63f1575..e751f8604 100644 --- a/mrbgems/hw-esp32-uart/src/uart.c +++ b/mrbgems/hw-uart/ports/esp32/uart.c @@ -145,8 +145,3 @@ mrb_uart_clear_tx(int unit) { /* not supported on ESP-IDF */ } - -#include - -void mrb_hw_esp32_uart_gem_init(mrb_state *mrb) {} -void mrb_hw_esp32_uart_gem_final(mrb_state *mrb) {} diff --git a/mrbgems/hw-rp2040-uart/src/uart.c b/mrbgems/hw-uart/ports/rp2040/uart.c similarity index 95% rename from mrbgems/hw-rp2040-uart/src/uart.c rename to mrbgems/hw-uart/ports/rp2040/uart.c index f8277d96a..8c2ba17ea 100644 --- a/mrbgems/hw-rp2040-uart/src/uart.c +++ b/mrbgems/hw-uart/ports/rp2040/uart.c @@ -134,8 +134,3 @@ mrb_uart_clear_tx(int unit) { /* not supported on RP2040 */ } - -#include - -void mrb_hw_rp2040_uart_gem_init(mrb_state *mrb) {} -void mrb_hw_rp2040_uart_gem_final(mrb_state *mrb) {}