Compare commits
7 Commits
v0.0.1-dc3
...
master
Author | SHA1 | Date |
---|---|---|
true | 56fed44f7a | |
true | 218819f75f | |
true | 3eb211fb54 | |
true | d32442da9a | |
true | 3a48cd8f06 | |
true | 340cdcad89 | |
true | 4dc61abc40 |
|
@ -3,7 +3,8 @@
|
||||||
* GAT Addon Firmware
|
* GAT Addon Firmware
|
||||||
* by true
|
* by true
|
||||||
*
|
*
|
||||||
* version 0.0.1
|
* version 0.0.3
|
||||||
|
* Last Update 20240808
|
||||||
*
|
*
|
||||||
* code was made for different random addons I designed for dc32,
|
* code was made for different random addons I designed for dc32,
|
||||||
* then adapted to each one. so things might be a mess.
|
* then adapted to each one. so things might be a mess.
|
||||||
|
@ -26,6 +27,7 @@
|
||||||
#include "src/config.h"
|
#include "src/config.h"
|
||||||
#include "src/i2c.h"
|
#include "src/i2c.h"
|
||||||
#include "src/led.h"
|
#include "src/led.h"
|
||||||
|
#include "src/led_rgbprog.h"
|
||||||
#include "src/rand.h"
|
#include "src/rand.h"
|
||||||
#include "src/ui.h"
|
#include "src/ui.h"
|
||||||
|
|
||||||
|
@ -57,10 +59,12 @@ void gpio_init()
|
||||||
// lightsense LED cathode
|
// lightsense LED cathode
|
||||||
gpio.GPIO_Mode = GPIO_Mode_Out_PP;
|
gpio.GPIO_Mode = GPIO_Mode_Out_PP;
|
||||||
gpio.GPIO_Pin = GPIO_Pin_2;
|
gpio.GPIO_Pin = GPIO_Pin_2;
|
||||||
|
GPIOA->OUTDR = ~GPIO_Pin_2;
|
||||||
GPIO_Init(GPIOA, &gpio);
|
GPIO_Init(GPIOA, &gpio);
|
||||||
|
|
||||||
// lightsense LED anode
|
// lightsense LED anode
|
||||||
gpio.GPIO_Pin = GPIO_Pin_0;
|
gpio.GPIO_Pin = GPIO_Pin_0;
|
||||||
|
GPIOD->OUTDR = ~GPIO_Pin_0;
|
||||||
GPIO_Init(GPIOD, &gpio);
|
GPIO_Init(GPIOD, &gpio);
|
||||||
|
|
||||||
// unused pins
|
// unused pins
|
||||||
|
@ -84,7 +88,14 @@ void gpio_init()
|
||||||
gpio.GPIO_Pin = GPIO_Pin_3 | GPIO_Pin_6;
|
gpio.GPIO_Pin = GPIO_Pin_3 | GPIO_Pin_6;
|
||||||
GPIO_Init(GPIOC, &gpio);
|
GPIO_Init(GPIOC, &gpio);
|
||||||
|
|
||||||
// BTN1, BTN2 will be handled by button handler
|
// BTN1 (PC5) pull up, BTN2 (PC4) pull down
|
||||||
|
gpio.GPIO_Pin = GPIO_Pin_4;
|
||||||
|
gpio.GPIO_Mode = GPIO_Mode_IPD;
|
||||||
|
GPIO_Init(GPIOC, &gpio);
|
||||||
|
|
||||||
|
gpio.GPIO_Pin = GPIO_Pin_5;
|
||||||
|
gpio.GPIO_Mode = GPIO_Mode_IPU;
|
||||||
|
GPIO_Init(GPIOC, &gpio);
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(void)
|
int main(void)
|
||||||
|
@ -101,7 +112,6 @@ int main(void)
|
||||||
|
|
||||||
// configure gpio pins, hard buttons (used for settings reset)
|
// configure gpio pins, hard buttons (used for settings reset)
|
||||||
gpio_init();
|
gpio_init();
|
||||||
btn_init();
|
|
||||||
|
|
||||||
// get saved settings, or reset if BTN1 is pushed
|
// get saved settings, or reset if BTN1 is pushed
|
||||||
i2c_init();
|
i2c_init();
|
||||||
|
@ -109,6 +119,7 @@ int main(void)
|
||||||
|
|
||||||
// configure hardware
|
// configure hardware
|
||||||
adc_init();
|
adc_init();
|
||||||
|
btn_init();
|
||||||
led_init();
|
led_init();
|
||||||
|
|
||||||
// configure random
|
// configure random
|
||||||
|
@ -120,6 +131,9 @@ int main(void)
|
||||||
// configure systick interrupt
|
// configure systick interrupt
|
||||||
systick_init();
|
systick_init();
|
||||||
|
|
||||||
|
// set up LEDs initially
|
||||||
|
led_rgb_firstrun();
|
||||||
|
|
||||||
// do system shit
|
// do system shit
|
||||||
while(1) {
|
while(1) {
|
||||||
__WFI();
|
__WFI();
|
||||||
|
|
|
@ -5,6 +5,7 @@
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <ch32v00x.h>
|
#include <ch32v00x.h>
|
||||||
|
|
||||||
#include "btn.h"
|
#include "btn.h"
|
||||||
|
|
||||||
|
|
||||||
|
@ -16,12 +17,11 @@ struct Btn btn[BTN_COUNT] = {0};
|
||||||
void btn_init()
|
void btn_init()
|
||||||
{
|
{
|
||||||
uint8_t i;
|
uint8_t i;
|
||||||
uint8_t r;
|
|
||||||
|
|
||||||
// configure GPIO
|
// configure GPIO (now handled as part of main GPIO init function)
|
||||||
BTN_PORT->BSHR = (BTN1_PUPD << BTN1_PIN) | (BTN2_PUPD << BTN2_PIN);
|
// BTN_PORT->BSHR = (BTN1_PUPD << BTN1_PIN) | (BTN2_PUPD << BTN2_PIN);
|
||||||
BTN_PORT->CFGLR &= ~((0xf << (BTN1_PIN*4)) | ((0xf << (BTN2_PIN*4))));
|
// BTN_PORT->CFGLR &= ~((0xf << (BTN1_PIN*4)) | ((0xf << (BTN2_PIN*4))));
|
||||||
BTN_PORT->CFGLR |= (0x8 << (BTN1_PIN*4)) | (0x8 << (BTN2_PIN*4));
|
// BTN_PORT->CFGLR |= (0x8 << (BTN1_PIN*4)) | (0x8 << (BTN2_PIN*4));
|
||||||
|
|
||||||
// configure default setup
|
// configure default setup
|
||||||
for (i = 0; i < BTN_COUNT; i++) {
|
for (i = 0; i < BTN_COUNT; i++) {
|
||||||
|
@ -60,7 +60,7 @@ void btn_poll()
|
||||||
// hold counter
|
// hold counter
|
||||||
if (btn[i]._count < 0xffff) btn[i]._count++;
|
if (btn[i]._count < 0xffff) btn[i]._count++;
|
||||||
|
|
||||||
// pushed long ennough?
|
// pushed long enough?
|
||||||
if (btn[i]._count < BTN_DEBOUNCE) continue;
|
if (btn[i]._count < BTN_DEBOUNCE) continue;
|
||||||
|
|
||||||
// first push?
|
// first push?
|
||||||
|
|
|
@ -80,11 +80,9 @@ int8_t i2c_read_addr1b(uint8_t addr, uint8_t reg, uint8_t *data, uint8_t len)
|
||||||
|
|
||||||
*data++ = I2C_ReceiveData(I2C1);
|
*data++ = I2C_ReceiveData(I2C1);
|
||||||
len--;
|
len--;
|
||||||
|
}
|
||||||
|
|
||||||
if (!len) {
|
|
||||||
I2C_GenerateSTOP(I2C1, ENABLE);
|
I2C_GenerateSTOP(I2C1, ENABLE);
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
@ -145,7 +143,7 @@ void i2c_write_reg_8b(uint8_t addr, uint8_t reg, const uint8_t dat)
|
||||||
i2c_write_addr1b(addr, reg, &dat, 1);
|
i2c_write_addr1b(addr, reg, &dat, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t i2c_addr_scan(uint8_t addr)
|
int8_t i2c_addr_scan(uint8_t addr)
|
||||||
{
|
{
|
||||||
uint8_t found = 1;
|
uint8_t found = 1;
|
||||||
uint32_t event;
|
uint32_t event;
|
||||||
|
@ -164,30 +162,28 @@ uint8_t i2c_addr_scan(uint8_t addr)
|
||||||
while(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_MODE_SELECT) && timeout--);
|
while(!I2C_CheckEvent(I2C1, I2C_EVENT_MASTER_MODE_SELECT) && timeout--);
|
||||||
if (!timeout) return -2;
|
if (!timeout) return -2;
|
||||||
|
|
||||||
I2C_Send7bitAddress(I2C1, addr, (addr & 1));
|
I2C_Send7bitAddress(I2C1, (addr & 0xfe), (addr & 0x01));
|
||||||
timeout = I2C_TIMEOUT_ACK_POLL;
|
timeout = I2C_TIMEOUT_ACK_POLL;
|
||||||
if (addr & 1) event = I2C_EVENT_MASTER_RECEIVER_MODE_SELECTED;
|
if (addr & 1) event = I2C_EVENT_MASTER_RECEIVER_MODE_SELECTED;
|
||||||
else event = I2C_EVENT_MASTER_TRANSMITTER_MODE_SELECTED;
|
else event = I2C_EVENT_MASTER_TRANSMITTER_MODE_SELECTED;
|
||||||
|
|
||||||
while (I2C_CheckEvent(I2C1, event) && timeout--) {
|
while ((I2C_CheckEvent(I2C1, event) == NoREADY) && timeout--) {
|
||||||
if (I2C_GetFlagStatus(I2C1, I2C_FLAG_AF)) {
|
if (I2C_GetFlagStatus(I2C1, I2C_FLAG_AF)) {
|
||||||
found = 0;
|
found = 0;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!timeout) {
|
if (!timeout) {
|
||||||
found = 0;
|
found = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
// reset flags; it might be in a fucked state
|
|
||||||
I2C1->STAR1 = 0;
|
|
||||||
|
|
||||||
// send a stop to make sure anything listening knows to stfu
|
// send a stop to make sure anything listening knows to stfu
|
||||||
I2C_GenerateSTOP(I2C1, ENABLE);
|
I2C_GenerateSTOP(I2C1, ENABLE);
|
||||||
|
|
||||||
|
// reset flags; it might be in a fucked state
|
||||||
if (!found) {
|
if (!found) {
|
||||||
|
I2C1->STAR1 = 0;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -19,7 +19,7 @@ int8_t i2c_write_addr1b(uint8_t addr, uint8_t reg, const uint8_t *data, uint8_t
|
||||||
uint8_t i2c_read_reg_8b(uint8_t addr, uint8_t reg);
|
uint8_t i2c_read_reg_8b(uint8_t addr, uint8_t reg);
|
||||||
void i2c_write_reg_8b(uint8_t addr, uint8_t reg, const uint8_t dat);
|
void i2c_write_reg_8b(uint8_t addr, uint8_t reg, const uint8_t dat);
|
||||||
|
|
||||||
uint8_t i2c_addr_scan(uint8_t addr);
|
int8_t i2c_addr_scan(uint8_t addr);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -520,23 +520,23 @@ void led_rgb_4_typing(uint8_t preview, uint8_t tick)
|
||||||
if (typing_fadeout >= 3) typing_fadeout--;
|
if (typing_fadeout >= 3) typing_fadeout--;
|
||||||
else typing_fadeout = 0;
|
else typing_fadeout = 0;
|
||||||
|
|
||||||
if (!preview || (i == 4) || (((preview & 0xf) == 4) && i >= 5)) {
|
// always do O character
|
||||||
for (j = 0; j < 3; j++) {
|
for (j = 0; j < 3; j++) {
|
||||||
s = rgb[8][j];
|
s = rgb[4][j];
|
||||||
s *= typing_fadeout;
|
s *= typing_fadeout;
|
||||||
rgb[8][j] = s >> 8;
|
rgb[8][j] = s >> 8;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
w = ((preview & 0xf) == 4) ? 5 : 0;
|
|
||||||
|
|
||||||
for (i = w; i < 8; i++) {
|
|
||||||
rgb[i][0] = rgb[8][0];
|
|
||||||
rgb[i][1] = rgb[8][1];
|
|
||||||
rgb[i][2] = rgb[8][2];
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!preview) {
|
if (!preview) {
|
||||||
|
w = ((preview & 0xf) == 4) ? 5 : 0;
|
||||||
|
|
||||||
|
for (i = w; i < 9; i++) {
|
||||||
|
rgb[i][0] = rgb[4][0];
|
||||||
|
rgb[i][1] = rgb[4][1];
|
||||||
|
rgb[i][2] = rgb[4][2];
|
||||||
|
}
|
||||||
|
|
||||||
|
// cursor
|
||||||
s = cursor[color];
|
s = cursor[color];
|
||||||
s *= typing_fadeout;
|
s *= typing_fadeout;
|
||||||
cursor[color] = s >> 8;
|
cursor[color] = s >> 8;
|
||||||
|
|
|
@ -13,6 +13,8 @@
|
||||||
#define LED_RGBPROG_NORMAL 0
|
#define LED_RGBPROG_NORMAL 0
|
||||||
#define LED_RGBPROG_PREVIEW 0x80
|
#define LED_RGBPROG_PREVIEW 0x80
|
||||||
|
|
||||||
|
#define LED_RGBPROG_COUNT 5
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
extern void ((*led_rgbprog[5])(uint8_t, uint8_t));
|
extern void ((*led_rgbprog[5])(uint8_t, uint8_t));
|
||||||
|
|
|
@ -25,8 +25,8 @@
|
||||||
|
|
||||||
#define UI_CONF_SAVE_TIMEOUT 192
|
#define UI_CONF_SAVE_TIMEOUT 192
|
||||||
|
|
||||||
#define UI_PROG_RUNTIME_MIN (128*15) // 15 seconds
|
#define UI_PROG_RUNTIME_MIN (15) // 15 seconds
|
||||||
#define UI_PROG_RUNTIME_MAX (128*120) // 120 seconds
|
#define UI_PROG_RUNTIME_MAX (120) // 120 seconds
|
||||||
|
|
||||||
|
|
||||||
static uint8_t mode = MODE_RUN;
|
static uint8_t mode = MODE_RUN;
|
||||||
|
@ -49,7 +49,7 @@ const uint16_t cursor_flash_rates[8] = { // off-to-on flash rates in 1/256
|
||||||
29, // PC VGA text mode (4.38 on-off/second)
|
29, // PC VGA text mode (4.38 on-off/second)
|
||||||
};
|
};
|
||||||
|
|
||||||
static uint8_t rgb_prog_idx = 0; // currently running rgbled program index
|
static uint8_t rgb_prog_idx = 0xff; // currently running rgbled program index
|
||||||
static uint16_t rgb_prog_timer = 9; // timeout until this program is done and switches
|
static uint16_t rgb_prog_timer = 9; // timeout until this program is done and switches
|
||||||
static uint8_t rgb_prog_is_editing = 0; // currently editing a program's parameters
|
static uint8_t rgb_prog_is_editing = 0; // currently editing a program's parameters
|
||||||
static uint8_t preview_idx = 0; // currently selected program preview index
|
static uint8_t preview_idx = 0; // currently selected program preview index
|
||||||
|
@ -121,59 +121,11 @@ void ui_btn_push_cb(uint8_t idx)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// do normal button actions
|
// there are no on-push events.
|
||||||
switch (mode) {
|
switch (mode) {
|
||||||
/* button logic flow:
|
case MODE_RUN: {
|
||||||
*
|
|
||||||
*
|
|
||||||
* mode changes happen by pressing both buttons.
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* NORMAL MODE: cursor is flashing.
|
|
||||||
*
|
|
||||||
* cursor changes are committed to EEPROM a couple of seconds after changing is done.
|
|
||||||
*
|
|
||||||
* if cursor is off, programming mode cannot be entered.
|
|
||||||
*
|
|
||||||
* - top button: changes cursor color (white, green, orange, off)
|
|
||||||
* - bot button: changes cursor flash rate. press and hold while not off to
|
|
||||||
* enter program change mode.
|
|
||||||
*/
|
|
||||||
|
|
||||||
|
}
|
||||||
/*
|
|
||||||
* PROGRAM CHANGE MODE: cursor is off.
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* letters in RETRO show enabled programs. by default, none are enabled.
|
|
||||||
* enabled programs are bright. disabled ones are dim.
|
|
||||||
* selected program will flash. if on, will flash brightly. if off, it will flash dimly.
|
|
||||||
*
|
|
||||||
* any program which is enabled can run. the active program randomly changes after random delays.
|
|
||||||
*
|
|
||||||
* letters in TECH preview the currently selected program.
|
|
||||||
* letters in RETRO will each preview their own program (any flash / twinkle will always have idle light)
|
|
||||||
*
|
|
||||||
* - top button: tap enables or disables the program. push and hold does nothing.
|
|
||||||
* - bot button: tap selects the next program index. push and hold enters parameter change mode.
|
|
||||||
*
|
|
||||||
*
|
|
||||||
* PARAMETER CHANGE MODE: cursor is on.
|
|
||||||
*
|
|
||||||
* letters in RETRO flash to show currently selected program.
|
|
||||||
* selected program will flash. if a program has been disabled, nothing will light for that letter.
|
|
||||||
*
|
|
||||||
* letters in TECH preview the current program, at some fixed brightness.
|
|
||||||
*
|
|
||||||
* - top button: increment some parameter, with loop (speed, etc)
|
|
||||||
* - bot button: selects the next program
|
|
||||||
* - knob: changes some parameter (color/hue, etc)
|
|
||||||
*
|
|
||||||
* settings are saved when the cursor returns to flashing from any other mode.
|
|
||||||
*
|
|
||||||
* settings are restored to default if the top button is held while powering on.
|
|
||||||
* restored settings are not committed until entering programming mode
|
|
||||||
*/
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -199,9 +151,11 @@ void ui_btn_release_cb(uint8_t idx)
|
||||||
|
|
||||||
switch (mode) {
|
switch (mode) {
|
||||||
/* button logic flow:
|
/* button logic flow:
|
||||||
*
|
|
||||||
*
|
*
|
||||||
* mode changes happen by pressing both buttons.
|
* mode changes happen by pressing both buttons.
|
||||||
|
* this is handled in the push event handler.
|
||||||
|
*
|
||||||
|
* if cursor is off, mode changing cannot occur.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/*
|
/*
|
||||||
|
@ -209,8 +163,6 @@ void ui_btn_release_cb(uint8_t idx)
|
||||||
*
|
*
|
||||||
* cursor changes are committed to EEPROM about a second after changing is done.
|
* cursor changes are committed to EEPROM about a second after changing is done.
|
||||||
*
|
*
|
||||||
* if cursor is off, programming mode cannot be entered.
|
|
||||||
*
|
|
||||||
* any program which is enabled will run. the active program randomly changes after random delays.
|
* any program which is enabled will run. the active program randomly changes after random delays.
|
||||||
*/
|
*/
|
||||||
case MODE_RUN: {
|
case MODE_RUN: {
|
||||||
|
@ -245,8 +197,8 @@ void ui_btn_release_cb(uint8_t idx)
|
||||||
/*
|
/*
|
||||||
* PROGRAM CHANGE MODE: cursor is on.
|
* PROGRAM CHANGE MODE: cursor is on.
|
||||||
*
|
*
|
||||||
* letters in RETRO show programs. by default, all are disabled.
|
* by default, all are disabled. selected program will flash.
|
||||||
* selected program will flash.
|
* cursor will light on the selected program if it is enabled.
|
||||||
*
|
*
|
||||||
* letters in TECH preview the currently selected program.
|
* letters in TECH preview the currently selected program.
|
||||||
* letters in RETRO will each preview their own program (any flash / twinkle will always have idle light)
|
* letters in RETRO will each preview their own program (any flash / twinkle will always have idle light)
|
||||||
|
@ -282,9 +234,8 @@ void ui_btn_release_cb(uint8_t idx)
|
||||||
*
|
*
|
||||||
* letters in TECH preview the current program, at some fixed brightness.
|
* letters in TECH preview the current program, at some fixed brightness.
|
||||||
*
|
*
|
||||||
*
|
* - top button: change some parameter
|
||||||
*
|
* - knob: change some parameter (color/hue, etc)
|
||||||
* - knob: changes some parameter (color/hue, etc)
|
|
||||||
*/
|
*/
|
||||||
case MODE_PARAMETER: {
|
case MODE_PARAMETER: {
|
||||||
switch (idx) {
|
switch (idx) {
|
||||||
|
@ -373,12 +324,16 @@ static void ui_cursor_flash()
|
||||||
case MODE_PROGRAM: {
|
case MODE_PROGRAM: {
|
||||||
// cursor is on if this program is flagged as on
|
// cursor is on if this program is flagged as on
|
||||||
cursor[0] = (userconf.ledprog_ena_mask & (1 << preview_idx)) ? 127 : 0;
|
cursor[0] = (userconf.ledprog_ena_mask & (1 << preview_idx)) ? 127 : 0;
|
||||||
|
cursor[1] = 0;
|
||||||
|
cursor[2] = 0;
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
case MODE_PARAMETER: {
|
case MODE_PARAMETER: {
|
||||||
// cursor is on when program is being edited
|
// cursor is on when program is being edited
|
||||||
cursor[0] = rgb_prog_is_editing ? 127 : 0;
|
cursor[0] = rgb_prog_is_editing ? 127 : 0;
|
||||||
|
cursor[1] = 0;
|
||||||
|
cursor[2] = 0;
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -387,27 +342,53 @@ static void ui_cursor_flash()
|
||||||
|
|
||||||
void ui_init()
|
void ui_init()
|
||||||
{
|
{
|
||||||
btn[0].hold = 330 >> 1;
|
btn[0].hold = 420 >> 1;
|
||||||
btn[0].repeat = (1000 / 20) >> 1;
|
btn[0].repeat = (1000 / 20) >> 1;
|
||||||
btn[0].cb_push = ui_btn_push_cb;
|
btn[0].cb_push = ui_btn_push_cb;
|
||||||
btn[0].cb_hold = ui_btn_hold_cb;
|
btn[0].cb_hold = ui_btn_hold_cb;
|
||||||
btn[0].cb_release = ui_btn_release_cb;
|
btn[0].cb_release = ui_btn_release_cb;
|
||||||
|
|
||||||
btn[1].hold = 330 >> 1;
|
btn[1].hold = 420 >> 1;
|
||||||
btn[1].repeat = 0;
|
btn[1].repeat = 0;
|
||||||
btn[1].cb_push = ui_btn_push_cb;
|
btn[1].cb_push = ui_btn_push_cb;
|
||||||
btn[1].cb_hold = ui_btn_hold_cb;
|
btn[1].cb_hold = ui_btn_hold_cb;
|
||||||
btn[1].cb_release = ui_btn_release_cb;
|
btn[1].cb_release = ui_btn_release_cb;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void rgb_prog_timer_generate() {
|
static void rgb_prog_random_timer_generate() {
|
||||||
uint32_t t;
|
uint32_t t;
|
||||||
|
|
||||||
t = prng_get16();
|
t = prng_get16();
|
||||||
t *= (UI_PROG_RUNTIME_MAX - UI_PROG_RUNTIME_MIN);
|
t *= (UI_PROG_RUNTIME_MAX - UI_PROG_RUNTIME_MIN) * 32;
|
||||||
t >>= 16;
|
t >>= 16;
|
||||||
|
t += UI_PROG_RUNTIME_MIN * 32;
|
||||||
|
|
||||||
rgb_prog_timer = t + UI_PROG_RUNTIME_MIN;
|
rgb_prog_timer = t;
|
||||||
|
}
|
||||||
|
|
||||||
|
static uint8_t rgb_prog_random_select()
|
||||||
|
{
|
||||||
|
uint8_t i;
|
||||||
|
uint8_t w;
|
||||||
|
|
||||||
|
uint8_t new;
|
||||||
|
|
||||||
|
w = prng_get8();
|
||||||
|
w &= 0x7;
|
||||||
|
for (i = 0; i < 8; i++) {
|
||||||
|
new = (w + i) & 0x7;
|
||||||
|
if (userconf.ledprog_ena_mask & (1 << new)) {
|
||||||
|
// bias selecting a new program
|
||||||
|
if (rgb_prog_idx != new) {
|
||||||
|
rgb_prog_idx = new;
|
||||||
|
led_rgb_firstrun();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (i == 8) return 0;
|
||||||
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ui_render()
|
void ui_render()
|
||||||
|
@ -417,7 +398,8 @@ void ui_render()
|
||||||
uint16_t w;
|
uint16_t w;
|
||||||
|
|
||||||
uint8_t flash;
|
uint8_t flash;
|
||||||
uint8_t new;
|
|
||||||
|
uint8_t out[16];
|
||||||
|
|
||||||
|
|
||||||
// deal with eeprom
|
// deal with eeprom
|
||||||
|
@ -473,73 +455,71 @@ void ui_render()
|
||||||
|
|
||||||
if (userconf.ledprog_ena_mask) {
|
if (userconf.ledprog_ena_mask) {
|
||||||
// fade and change programs depending on the timer
|
// fade and change programs depending on the timer
|
||||||
rgb_prog_timer--;
|
|
||||||
|
|
||||||
if (rgb_prog_timer) {
|
|
||||||
// actually run the program
|
// actually run the program
|
||||||
|
if (rgb_prog_timer) {
|
||||||
|
if (led_rgbprog[rgb_prog_idx] && (rgb_prog_idx < LED_RGBPROG_COUNT)) {
|
||||||
led_rgbprog[rgb_prog_idx](LED_RGBPROG_NORMAL, tick);
|
led_rgbprog[rgb_prog_idx](LED_RGBPROG_NORMAL, tick);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((tick & 0x3) == 0) {
|
||||||
|
rgb_prog_timer--;
|
||||||
|
|
||||||
// todo: the fade goes way too fast and looks bad
|
|
||||||
// make it look nicer
|
|
||||||
if (rgb_prog_timer <= 17) {
|
if (rgb_prog_timer <= 17) {
|
||||||
led_is_updated();
|
led_is_updated();
|
||||||
|
|
||||||
if (rgb_prog_timer == 17) {
|
if (rgb_prog_timer == 17) {
|
||||||
w = prng_get8();
|
// if no new program was selected (likely only one program selected?)
|
||||||
w &= 0x7;
|
// just reset the timer
|
||||||
for (i = 0; i < 8; i++) {
|
if (!rgb_prog_random_select()) {
|
||||||
new = (w + i) & 0x7;
|
rgb_prog_random_timer_generate();
|
||||||
if (userconf.ledprog_ena_mask & (1 << new)) {
|
|
||||||
// bias selecting a new program
|
|
||||||
if (rgb_prog_idx != new) {
|
|
||||||
rgb_prog_idx = new;
|
|
||||||
led_rgb_firstrun();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
// no new program was selected (likely only one program selected?)
|
|
||||||
// so just reset the timer
|
|
||||||
if (i == 8) {
|
|
||||||
rgb_prog_timer_generate();
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (rgb_prog_timer > 9) {
|
else if (rgb_prog_timer >= 9) {
|
||||||
// fade out current program
|
// fade out current program
|
||||||
w = 7 - (rgb_prog_timer - 10);
|
w = 7 - (rgb_prog_timer - 9);
|
||||||
for (i = 0; i < 9; i++) {
|
for (i = 0; i < 16; i++) {
|
||||||
rgb[i][0] >>= w;
|
out[i] = 0xff >> w;
|
||||||
rgb[i][1] >>= w;
|
|
||||||
rgb[i][2] >>= w;
|
|
||||||
}
|
}
|
||||||
} else if (rgb_prog_timer > 7) {
|
is31fl3729_set_scaling_current_multi(FL3729_ADDR, out, 15);
|
||||||
|
}
|
||||||
|
|
||||||
|
else if (rgb_prog_timer > 7) {
|
||||||
// clear out for now, since new program hasn't actually been run
|
// clear out for now, since new program hasn't actually been run
|
||||||
for (i = 0; i < 9; i++) {
|
for (i = 0; i < 9; i++) {
|
||||||
rgb[i][0] = 0;
|
rgb[i][0] = 0;
|
||||||
rgb[i][1] = 0;
|
rgb[i][1] = 0;
|
||||||
rgb[i][2] = 0;
|
rgb[i][2] = 0;
|
||||||
}
|
}
|
||||||
} else if (rgb_prog_timer >= 1) {
|
// try to select a new program if we haven't set one before
|
||||||
// fade in new program
|
if (rgb_prog_idx == 0xff) {
|
||||||
w = (rgb_prog_timer & 0x7);
|
rgb_prog_random_select();
|
||||||
for (i = 0; i < 9; i++) {
|
|
||||||
rgb[i][0] >>= w;
|
|
||||||
rgb[i][1] >>= w;
|
|
||||||
rgb[i][2] >>= w;
|
|
||||||
}
|
|
||||||
} else { // 0
|
|
||||||
// randomize next program timing
|
|
||||||
rgb_prog_timer_generate();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// temp: remove me once buttons are tested and working
|
else if (rgb_prog_timer > 0) {
|
||||||
//rgb_prog_idx = 0;
|
// fade in new program
|
||||||
//led_rgbprog[rgb_prog_idx](LED_RGBPROG_NORMAL, tick);
|
w = (rgb_prog_timer & 0x7);
|
||||||
|
for (i = 0; i < 16; i++) {
|
||||||
|
out[i] = 0xff >> w;
|
||||||
|
}
|
||||||
|
is31fl3729_set_scaling_current_multi(FL3729_ADDR, out, 15);
|
||||||
|
}
|
||||||
|
|
||||||
|
else { // 0
|
||||||
|
// randomize next program timing
|
||||||
|
for (i = 0; i < 16; i++) {
|
||||||
|
out[i] = 0xff;
|
||||||
|
}
|
||||||
|
is31fl3729_set_scaling_current_multi(FL3729_ADDR, out, 15);
|
||||||
|
|
||||||
|
rgb_prog_random_timer_generate();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -549,7 +529,7 @@ void ui_render()
|
||||||
config_save_timer = UI_CONF_SAVE_TIMEOUT;
|
config_save_timer = UI_CONF_SAVE_TIMEOUT;
|
||||||
|
|
||||||
// rapidly flash lsens
|
// rapidly flash lsens
|
||||||
if ((tick >> 3) & 1) {
|
if ((tick & 0x7) == 0) {
|
||||||
GPIOD->OUTDR ^= GPIO_Pin_0;
|
GPIOD->OUTDR ^= GPIO_Pin_0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -593,7 +573,7 @@ void ui_render()
|
||||||
config_save_timer = UI_CONF_SAVE_TIMEOUT;
|
config_save_timer = UI_CONF_SAVE_TIMEOUT;
|
||||||
|
|
||||||
// slowly flash lsnes
|
// slowly flash lsnes
|
||||||
if ((tick >> 5) & 1) {
|
if ((tick & 0x20) == 0) {
|
||||||
GPIOD->OUTDR ^= GPIO_Pin_0;
|
GPIOD->OUTDR ^= GPIO_Pin_0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue