Code sharing for m01 and m100 firmware

I’ve been using a m01 for 5 years. It took me a few months to settle with a layout that I like and when I got my m100 I ported it over. Right now I need to manage two .ino files, one for each keyboard, and it’s getting old pretty fast trying to keep them in sync (smaller changes mostly, like led colors etc.).

I’m looking for a way to move most of the code (layout, space cadet config, led config, most plugin inits) into a common location so I’ve only one place to have to keep updating.

Has anyone figured out the best way to do this?

I think your best bet is using one .ino file with #ifdefs, and symlinking it to two places, one with their own sketch.json for the Model01 and the Model100, respectively.

For stuff that is Model100-only, you can use ARDUINO_keyboardio_model_100, and for Model01 specific things, ARDUINO_keyboardio_model_100.

1 Like

I am not sure if this will be useful for anybody else, but I’ve checked in most of what I use here: GitHub - lgnakano/KeyboardioSketches: Keyboardio Sketch

I created a .ino based on the example code , and surrounded most features with #ifdef and things alike.
I then check the following:

#ifdef ARDUINO_keyboardio_model_100
#include “configurationModel100.h”
#endif

#ifdef ARDUINO_AVR_MODEL01
#include “configurationModel01.h”
#endif

The configurationModel01.h and configurationModel100.h have the defines that specify which features will be used. All you do is to set the board type on the IDE.

There are different parts on the .ino where the same define is checked: whether to include a .h file, where macros are created, where the code should be in setup, if different keys should be used on the layout (for instance, if one shot is used, some of the keys are using OSM and OSL, but when one shot is not used, the corresponding keys are replaced).

Two caveats: I use Functional Colors, which you have to install on your Arduino IDE if you want to use, and I have a modified version of OneShot that has a timeout for sticky keys. This is used because sometimes I would set a key to sticky and walk away from my desk, come back and completely forgot that a key was set to sticky. If you want this feature, my version is on GitHub - lgnakano/Kaleidoscope-OneShot: Plugin to add "tappable" sticky modifiers and layers for Kaleidoscope.

I want to eventually contribute the code to the plugin, but I need to figure out how to create test cases for it. In the meantime, if you do not want this feature, just don’t use `setStickyTimeOutSeconds(), or set it with a negative number (it defaults to not being used, which sets it to -1).

For functional colors, if you do not define USE_FUNCTIONAL_COLORS on either of the configuration files, it won’t even try to include the file.

The configuration for the model01 has less than 1% of the memory left, so you may want to disable some of the things I use if you want some things I do not.

Let me know if you find any issues.

2 Likes