Update docs and example firmware

This commit is contained in:
2025-08-13 07:42:02 -07:00
parent b5029bde88
commit 3f670fa9f7
4 changed files with 27 additions and 16 deletions

View File

@ -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
```

View File

@ -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:

View File

@ -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) {

View File

@ -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();
}