initial commit of in-progress platformio/arduino code

This commit is contained in:
true
2025-04-02 21:37:50 -07:00
commit 5f0a0feed1
8 changed files with 340 additions and 0 deletions

View File

@@ -0,0 +1,82 @@
#include <Arduino.h>
#include "rgbled.h"
uint8_t rgbp_rainbow(uint8_t init);
uint8_t (*rgb_program[1])(uint8_t) = {
rgbp_rainbow
};
#define RGB_COUNT 5
uint8_t rgbled[3 * RGB_COUNT];
// configures and enables the 50Hz timer interrupt that is used for RGB program updates
void conf_rgb_timer()
{
// this timer will run at half speed.
// so 8MHz / 2 (prescale) / 1 (CLK_PER) = 4MHz
// this will allow a full cycle time of ~61Hz.
_PROTECTED_WRITE(CLKCTRL_MCLKCTRLB, 0); // disable CLK_PER divider
disable_rgb_timer();
TCB0.CTRLA = TCB_CLKSEL_CLKDIV2_gc; // prescale timer to run at half speed
TCB0.CCMP = 0xffff; // count to full
TCB0.CNT = 0;
}
ISR(TCB0_INT_vect)
{
// reset the INTFLAGS - necessary on this series
uint8_t intflags = TCB0.INTFLAGS;
TCB0.INTFLAGS = intflags;
// we don't care why we interrupted.
// we'll now return to executing loop()
}
// rgb program 0: rainbow puke
#define RAINBOW_HUE_INC 50
#define RAINBOW_OFFSET (1536/5)
#define RAINBOW_TIMEOUT 240
uint16_t rainbow_hue = 0;
uint16_t rainbow_timeout;
uint8_t rgbp_rainbow(uint8_t init)
{
uint8_t i;
uint16_t hue;
if (init) {
rainbow_timeout = RAINBOW_TIMEOUT;
}
if (--rainbow_timeout) {
hue = rainbow_hue;
for (i = 0; i < RGB_COUNT; i++) {
hue += RAINBOW_OFFSET;
if (hue >= 1536) hue -= 1536;
// apply color
// TODO
}
// move the hue wheel for the next cycle through the program
rainbow_hue += RAINBOW_HUE_INC;
if (rainbow_hue > 1536) rainbow_hue -= 1536;
return 1;
}
// done with program
return 0;
}