Skip to content

v1.6.8 - GPIO HAL Abstraction Layer (2025-11-20)

What Changed?

This release introduces a hardware abstraction layer (HAL) for GPIO reads using the ENABLE_GPIO_ABSTRACTION compile-time flag. The implementation supports two paths: a readable HAL path using gpio_get_level() for development, and a direct register path for production performance. This improves code maintainability and enables easy migration to other ESP32 variants (ESP32-S3, ESP32-C3) while maintaining backward compatibility.


What's New

Main Feature: GPIO HAL Abstraction with ENABLE_GPIO_ABSTRACTION Flag

What it does:

Provides two compile-time selectable GPIO read implementations:

  1. HAL Path (ENABLE_GPIO_ABSTRACTION=1): Uses ESP-IDF gpio_get_level() API for clear, readable code that doesn't require datasheet knowledge
  2. Direct Register Path (ENABLE_GPIO_ABSTRACTION=0): Uses direct GPIO register access for maximum performance (zero overhead)

How to use it:

The flag is configured in platformio.ini:

  • Development builds automatically use HAL path (ENABLE_GPIO_ABSTRACTION=1)
  • Production builds automatically use direct register path (ENABLE_GPIO_ABSTRACTION=0)
  • Override via command line: PLATFORMIO_BUILD_FLAGS="-DENABLE_GPIO_ABSTRACTION=0" pio run -e esp32dev-dev

Code example:

// In src/cosmic_detector.cpp - both paths available at compile time:
#if ENABLE_GPIO_ABSTRACTION == 1
  // HAL path: Clear, portable, maintainable
  detector_signal1 += gpio_get_level((gpio_num_t)DETECT_PIN1);
#else
  // Direct register path: High performance, ESP32-specific
  uint32_t gpio_in_reg = *((uint32_t*)GPIO_IN_REG_ADDRESS);
  detector_signal1 += ((gpio_in_reg & GPIO_IN_REG_MASK) >> 12) & 1;
#endif

Hardware Portability

The implementation completely isolates ESP32-specific code in the direct register path. When migrating to other ESP32 variants:

  • HAL path works unchanged (uses ESP-IDF driver/gpio.h)
  • Pin definitions in config.h remain variant-agnostic
  • Only the direct register path needs variant-specific updates

Example: To add ESP32-S3 support, update GPIO_IN_REG_ADDRESS for the direct path; HAL path continues working as-is.


Installation

Quick Start

# Get the release
git checkout v1.6.8

# Build development (uses HAL path)
task dev:build

# Or build production (uses direct register path)
task prod:build

# Upload
task upload

# Check it works
task monitor

What's Different from the Last Version?

โœ… Added

  • ENABLE_GPIO_ABSTRACTION compile-time flag in include/config.h
  • HAL path using gpio_get_level() in src/cosmic_detector.cpp
  • Direct register path isolation in #else blocks (no register code in HAL path)
  • GPIO abstraction architecture documentation in CLAUDE.md
  • Hardware portability guide with ESP32-S3 migration example

๐Ÿ”ง Changed

  • platformio.ini dev profile now enables HAL path by default
  • Production profile continues using direct register path for performance
  • REFACTORING_ROADMAP.md updated with v1.6.8 implementation results

๐Ÿ“š Documentation

  • Added comprehensive GPIO HAL Abstraction Layer section to CLAUDE.md
  • Updated REFACTORING_ROADMAP.md with build results and performance analysis
  • Created v1.6.8 progress log with implementation details

Is It Safe to Upgrade?

Backward Compatible: โœ… Yes

  • Zero breaking changes - existing firmware code remains unchanged
  • Direct register path preserved for production use
  • Both build profiles generate functionally equivalent detection
  • Memory usage identical to v1.6.7 (no regressions)

Impact on existing users:

  • No action required for production deployments (continue using task prod:build)
  • Development and code review workflows benefit from HAL path readability
  • Hardware migration testing easier with portable HAL path

Tests Passed

  • โœ… Dev build (HAL path): 0 warnings, 302069 bytes flash, 23904 bytes RAM
  • โœ… Prod build (direct register): 0 warnings, 297025 bytes flash, 22608 bytes RAM
  • โœ… Both builds succeed in <1 second
  • โœ… Both paths generate functionally equivalent detection logic
  • โœ… HAL overhead acceptable (<1% of detection cycle time)

Performance Notes

Aspect HAL Path Direct Register Difference
Flash 302069 bytes 297025 bytes +5KB (acceptable)
RAM 23904 bytes 22608 bytes +1.3KB (acceptable)
Detection Accuracy โœ… Identical โœ… Identical None
Overhead ~1-2ยตs per 100-poll cycle Zero <0.01% impact

Release Details

  • Date: 2025-11-20
  • Version: v1.6.8
  • Type: Enhancement (HAL abstraction layer)
  • Breaking Changes: None
  • Files Changed: 4 main files (config.h, cosmic_detector.cpp, CLAUDE.md, REFACTORING_ROADMAP.md)

Next Steps

  1. v1.7.0 (Q4 2025): Text command parsing optimization (reduce code duplication)
  2. Future Considerations:
  3. Complete GPIO HAL adoption if direct register path proves unnecessary
  4. Support for additional ESP32 variants (ESP32-S3, ESP32-C3)
  5. Performance optimization based on real-world usage patterns

See REFACTORING_ROADMAP.md for the full roadmap.