From 3f670fa9f78b69327ce6b37abf4c8d2ae76267d7 Mon Sep 17 00:00:00 2001 From: Adam Wonak Date: Wed, 13 Aug 2025 07:42:02 -0700 Subject: [PATCH] Update docs and example firmware --- README.md | 19 +++++++++++++++---- .../calibrate_analog/calibrate_analog.ino | 4 ++-- .../calibrate_analog2/calibrate_analog2.ino | 4 ++-- examples/hardware_test/hardware_test.ino | 16 ++++++++-------- 4 files changed, 27 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index 569aeed..7afaabf 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,8 @@ # Sitka Instruments Gravity Firmware Abstraction -This library helps make writing firmware easier by abstracting away the initialization and peripheral interactions. Now your firmware code can just focus on the logic and behavior of the app, and keep the low level code neatly tucked away in this library. +This library helps make writing firmware for the [Sitka Instruments Gravity](https://sitkainstruments.com/gravity/) eurorack module easier by abstracting away the initialization and peripheral interactions. Now your firmware code can just focus on the logic and behavior of the app, and keep the low level code neatly tucked away in this library. + +The latest releases of all Sitka Instruments Gravity firmware builds can be found on the [Updater](https://sitkainstruments.com/gravity/updater/) page. You can use this page to flash the latest build directly to the Arduino Nano on the back of your module. ## Installation @@ -17,13 +19,14 @@ Common directory locations: * [uClock](https://github.com/midilab/uClock) [MIT] - (Included with this repo) Handle clock tempo, external clock input, and internal clock timer handler. * [RotateEncoder](https://github.com/mathertel/RotaryEncoder) [BSD] - Library for reading and interpreting encoder rotation. * [U8g2](https://github.com/olikraus/u8g2/) [MIT] - Graphics helper library. +* [NeoHWSerial](https://github.com/SlashDevin/NeoHWSerial) [GPL] - Hardware serial library with attachInterrupt. ## Example Here's a trivial example showing some of the ways to interact with the library. This script rotates the active clock channel according to the set tempo. The encoder can change the temo or rotation direction. The play/pause button will toggle the clock activity on or off. The shift button will freeze the clock from advancing the channel rotation. ```cpp -#include "gravity.h" +#include "libGravity.h" byte idx = 0; bool reversed = false; @@ -75,11 +78,11 @@ void HandlePlayPressed() { } } -void HandleRotate(Direction dir, int val) { +void HandleRotate(int val) { if (selected_param == 0) { gravity.clock.SetTempo(gravity.clock.Tempo() + val); } else if (selected_param == 1) { - reversed = (dir == DIRECTION_DECREMENT); + reversed = (val < 0); } } @@ -111,6 +114,14 @@ void UpdateDisplay() { } ``` +**Builing New Firmware Using libGravity** + +When starting a new firmware sketch you can use the [skeleton](examples/skeleton/skeleton.ino) app as a place to start. + +**Building New Firmware from scratch** + +If you do not want to use the libGravity hardware abstraction library and want to roll your own vanilla firmware, take a look at the [peripherials.h](src/peripherials.h) file for the pinout definitions used by the module. + ### Build for release ``` diff --git a/examples/calibrate_analog/calibrate_analog.ino b/examples/calibrate_analog/calibrate_analog.ino index c3e6a5f..388494f 100644 --- a/examples/calibrate_analog/calibrate_analog.ino +++ b/examples/calibrate_analog/calibrate_analog.ino @@ -17,7 +17,7 @@ * TODO: Store the calibration value in EEPROM. */ -#include "gravity.h" +#include "libGravity.h" #define TEXT_FONT u8g2_font_profont11_tf #define INDICATOR_FONT u8g2_font_open_iconic_arrow_1x_t @@ -43,7 +43,7 @@ void NextCalibrationPoint() { selected_param = (selected_param + 1) % 6; } -void CalibrateCV(Direction dir, int val) { +void CalibrateCV(int val) { AnalogInput* cv = (selected_param > 2) ? &gravity.cv2 : &gravity.cv1; switch (selected_param % 3) { case 0: diff --git a/examples/calibrate_analog2/calibrate_analog2.ino b/examples/calibrate_analog2/calibrate_analog2.ino index ac5d772..48958d2 100644 --- a/examples/calibrate_analog2/calibrate_analog2.ino +++ b/examples/calibrate_analog2/calibrate_analog2.ino @@ -14,7 +14,7 @@ * */ -#include "gravity.h" +#include "libGravity.h" #define TEXT_FONT u8g2_font_profont11_tf @@ -39,7 +39,7 @@ void NextCalibrationPoint() { selected_param = (selected_param + 1) % 2; } -void CalibrateCV(Direction dir, int val) { +void CalibrateCV(int val) { // AnalogInput* cv = (selected_param > 2) ? &gravity.cv2 : &gravity.cv1; AnalogInput* cv = &gravity.cv1; switch (selected_param % 2) { diff --git a/examples/hardware_test/hardware_test.ino b/examples/hardware_test/hardware_test.ino index 5f3d345..9ba6b90 100644 --- a/examples/hardware_test/hardware_test.ino +++ b/examples/hardware_test/hardware_test.ino @@ -1,4 +1,4 @@ -#include "gravity.h" +#include "libGravity.h" byte idx = 0; bool reversed = false; @@ -33,28 +33,28 @@ void IntClock(uint32_t tick) { if (tick % 12 == 0 && ! freeze) { gravity.outputs[idx].Low(); if (reversed) { - idx = (idx == 0) ? OUTPUT_COUNT - 1 : idx - 1; + idx = (idx == 0) ? Gravity::OUTPUT_COUNT - 1 : idx - 1; } else { - idx = (idx + 1) % OUTPUT_COUNT; + idx = (idx + 1) % Gravity::OUTPUT_COUNT; } gravity.outputs[idx].High(); } } void HandlePlayPressed() { - gravity.clock.Pause(); + gravity.clock.Stop(); if (gravity.clock.IsPaused()) { - for (int i = 0; i < OUTPUT_COUNT; i++) { + for (int i = 0; i < Gravity::OUTPUT_COUNT; i++) { gravity.outputs[i].Low(); } } } -void HandleRotate(Direction dir, int val) { +void HandleRotate(int val) { if (selected_param == 0) { gravity.clock.SetTempo(gravity.clock.Tempo() + val); } else if (selected_param == 1) { - reversed = (dir == DIRECTION_DECREMENT); + reversed = (val < 0); } } @@ -80,7 +80,7 @@ void UpdateDisplay() { gravity.display.print("Direction: "); gravity.display.print((reversed) ? "Backward" : "Forward"); - gravity.display.drawChar(0, selected_param * 10, 0x10, 1, 0, 1); + gravity.display.drawStr(0, selected_param * 10, "x"); gravity.display.display(); } \ No newline at end of file