Skip to content

Provide all configuration values at compile time #2

Description

@Eelviny

The issue

Currently, bbs-fw implements a similar method of configuration as is provided by the stock Bafang firmware. Once the firmware has been flashed, it is then possible to use the configuration tool to set all configuration parameters.

This makes setting up the controller a 2-step process - whenever a new firmware is flashed, the EEPROM (internal flash storage) is wiped (I think? Not sure here). The user then must load the configuration again.

The (potential) solution

As we have full access to the source, and can compile it ourselves, it would be possible to embed the configuration directly into the firmware. This has a number of key benefits:

  • It greatly decreases the complexity of the code, as it removes the need for the controller to provide a UART configuration interface
  • It decreases the load on the controller as the compiler can do a lot of the calculations upfront, hardcoding them into the firmware instead of having the controller constantly re-calculate them
  • It encourages a more "declarative" approach to setting configuration, where the user can be sure that when the firmware is flashed, that every value is set as expected (did I remember to press write after changing this config value?)
  • It frees up RAM on space-constrained controllers like the BBS02 for me to do cool stuff with it :)

In fact, for many less well supported features, bbs-fw does this already. Some features can only be enabled by modifying the fwconfig.h file.

The challenge comes with making this user-friendly. I propose using the same successful approach as ESPHome - provide the configuration in a YAML file, then build a tool that:

  1. Takes care of translating the YAML file to a headers file that C can understand
  2. Handles compilation in a bullet-proof method that requires little hands-on experience for the user
  3. Flashes the firmware directly to the controller

I intend to build this using Python. It can use the built-in YAML capabilities to write a .h file, make exec calls to sdcc, and then use stcgal as a library to flash the config (stcgal is also written in Python).

Metadata

Metadata

Assignees

Labels

enhancementNew feature or request

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions