awonak / EuroPiGo

Alternate firmware for the Allen Synthesis EuroPi written in Go
MIT License
4 stars 2 forks source link

Build flags for supporting alternate hardware configuration #1

Open awonak opened 2 years ago

awonak commented 2 years ago

When DIY EuroPi modules use different GPIO pin configurations, we want to be able to easily support those different configurations without requiring a separate fork. This can be solved using the Go feature build constraints along with separate gpio configuration files with build constraint headers.

For example, we can define two files 1) board.go for the official hardware configuration and 2) board_rmx.go for the smd remix by @luisgongod. The first line of the file will be // go:build europi and // go:build europi_rmx respectively.

With that in place, the EuroPiGo firmware can be build using the command:

tinygo build -tags europi --target pico examples/

or

tinygo build -tags europi_rmx --target pico examples/

In order to use this in VSCode, we will need to make a few adjustments to the VSCode settings.

Add "-tags europi" to tasks.json (or "-tags europi_rmx")

{
    "version": "2.0.0",
    "tasks": [
        {
            "label": "tinygo flash",
            "type": "shell",
            "command": "tinygo flash -tags europi --target pico -opt 1 ${workspaceRoot}/examples/clockwerk",
            "group": {
                "kind": "build",
                "isDefault": true
            },
            "problemMatcher": []
        }
    ]
}

Add the build constraint flag to settings.json (either "europi" or "europi_rmx"):

{
    "go.toolsEnvVars": {
        "GOROOT": "...",
        "GOFLAGS": "-tags=europi,cortexm,baremetal,linux,arm,rp2040,rp,pico,tinygo,math_big_pure_go,gc.conservative,scheduler.tasks,serial.usb"
    }
}

Now you can build and flash the firmware for either hardware configuration!

awonak commented 2 years ago

An alternate design consideration, for the default europi configuration, we could instead add a build flag constraint that will only build that file when no other EuroPi board is specified. Say for example we had the other board configurations europi_rmx and europi_xl. We could add the following build constraint to the default europi configuration: //go:build !(europi_rmx || europi_xl). With that added, we can build the firmware without specifying any build tags when building for the default hardware configuration.

Considering that we can easily automate build tasks in VSCode, I don't think this is necessary to do for the purpose of avoiding specifying -tags europi for default hardware.