echo-lalia/MicroHydra

Major API Overhaul is required for MicroHydra to enable multiplatform support.

Closed this issue · 1 comments

In MicroHydra 1.0, the API for controlling the hardware is highly specific to the Cardputer. This means that, to create apps that work on multiple devices, you would need to completely rewrite large parts of the code for every single device.

In order for MicroHydra to support multiple platforms (such as the Cardputer II and the original Cardputer) simultaneously, the API for all of the built-in modules must be redesigned such that apps no longer need to specify exact Pins or other device-specific parameters in order to control things like the display, speaker, keyboard, etc.

For example, this:

# init object for accessing display
tft = st7789fbuf.ST7789(
    machine.SPI(
        1,baudrate=40000000,sck=machine.Pin(36),mosi=machine.Pin(35),miso=None),
    _DISPLAY_HEIGHT,
    _DISPLAY_WIDTH,
    reset=machine.Pin(33, machine.Pin.OUT),
    cs=machine.Pin(37, machine.Pin.OUT),
    dc=machine.Pin(34, machine.Pin.OUT),
    backlight=machine.Pin(38, machine.Pin.OUT),
    rotation=1,
    color_order=st7789fbuf.BGR
    )

Will not work on anything except the Cardputer.

MicroHydra can use device-specific modules to simplify this process, and make the display initialization code in each app would look like this:

tft = Display()

FYI, this change is already being implemented in the experimental-multiplatform branch.

Currently, I am using a few different techniques in an attempt to simplify multiplatform development, including:

  • Creating device-specific modules organized into separate folders that are designed to control a specific device's hardware
  • Using a script to create something similar to C's macros, which will allow lines of code to be included/excluded based on a conditional statement.
  • Using that same script to automatically replace "magic" MicroHydra constants with their platform-specific values.

And more to come, hopefully :)