initial WIP

lots of code copied over, things filled in to hopefully get the LED matrix lighting up. untested.
This commit is contained in:
true
2026-05-08 11:54:12 -07:00
commit d95af918fa
77 changed files with 24395 additions and 0 deletions

View File

@@ -0,0 +1,81 @@
/*
* ledprog.c: led programs
*/
#include "matrix.h"
static uint32_t s[8] = {0};
//static uint32_t t[8] = {0};
//static uint32_t l[8] = {0};
void lp_ribbon_init()
{
uint8_t i;
for (i = 0; i < 8; i++) {
s[i] = 0;
}
}
void lp_ribbon_upward(uint16_t wait, uint16_t rate, uint8_t fade)
{
uint32_t i;
uint32_t x;
/*
0: state
1: timeout
2: index
*/
switch (s[0]) {
case 0: { // timeout
if (!s[1]) {
s[0]++;
s[2] = 0;
return;
}
s[1]--;
break;
}
case 1: { // upward trails
// rate delay
if (!s[1]) {
s[1] = rate;
} else {
s[1]--;
break;
}
x = s[2]++;
// are we done?
if (x > sizeof(led_set.ribbon)) {
s[0] = 0;
s[1] = wait;
break;
}
// fade in and up
led_set.ribbon[x] = 0x40;
if (x) led_set.ribbon[x - 1] = 0x70;
if (x > 1) led_set.ribbon[x - 2] = 0xff;
}
}
// fade out LEDs
for (i = 0; i < sizeof(led_set.ribbon); i++) {
if (led_set.ribbon[i] >= fade) {
led_set.ribbon[i] -= fade;
} else {
led_set.ribbon[i] = 0;
}
}
matrix_flag_update();
}

View File

@@ -0,0 +1,15 @@
/*
* ledprog.h
*/
#ifndef __APP_LED_LEDPROG_H
#define __APP_LED_LEDPROG_H
void lp_ribbon_init();
void lp_ribbon_upward(uint16_t wait, uint16_t rate, uint8_t fade);
#endif /* __APP_LED_LEDPROG_H */

View File

View File

128
firmware/app/led/matrix.c Normal file
View File

@@ -0,0 +1,128 @@
/*
*
*/
#include "ch32x035_conf.h"
#include <string.h>
#include "matrix.h"
#include "driver/aw20xxx.h"
// #include "user_config.h"
#define AW20X_DIM 31 // initial global current setting
#define AW20X_COLS 6
#define AW20X_ROWS 12
#define AW20X_FADE_COUNT (AW20X_ROWS * AW20X_COLS)
#define HWEN_PORT GPIOB
#define HWEN_PIN GPIO_Pin_7
AW20x awled;
static uint8_t awled_fade[AW20X_FADE_COUNT];
static uint8_t led_matrix_needs_update = 0;
uint16_t led_map_size;
const LedMap led_map = {
// map is 1-based to match part numbers on the board
{ // ribbon
1, 25, 13, 49,
37, 14,
28, 2, 38,
50, 3,
27, 15,
39, 51,
4, 16,
28, 40,
52, 5,
17, 29,
41, 53,
6, 18,
30, 42,
54,
0, 0, 0, 0, 0, 0,
7, 0,
19, 0,
31, 0,
43, 0,
55, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0,
8, 20, 32,
0, 0
},
{ // "A"
9, 21, 33, 0, 0, 0, 45, 57, 10,
22,
34, 46, 58, 11, 23, 35, 47, 59, 12
},
{ // "//" left one
61, 62, 63, 64, 44
},
{ // "//" right one
60, 48, 36, 24, 56
}
};
LedMap led_set;
void matrix_init()
{
volatile uint32_t x;
// make sure the hardware pin is on before calling.
HWEN_PORT->BSHR = HWEN_PIN;
// wait a little while to ensure controller is awake
x = 131072;
while (x--);
// clear fade
memset(awled_fade, 0x00, sizeof(awled_fade));
// set up RGBLED chip
awled.fade = awled_fade;
aw20x_init(&awled, AW20X_ADDR_VDD << 1, AW20X_COLS, AW20X_ROWS, AW20X_IMAX_20MA);
aw20x_set_dim_global(&awled, AW20X_DIM);
aw20x_set_fade(&awled);
aw20x_led_enable_range(&awled, 0, (AW20X_COLS * AW20X_MAX_ROWS) - 1);
led_map_size = sizeof(led_map.ribbon) + sizeof(led_map.a) + sizeof(led_map.ii_lf) + sizeof(led_map.ii_rt);
}
void matrix_flag_update()
{
led_matrix_needs_update = 1;
}
void matrix_send()
{
int8_t i;
uint8_t *fade = awled_fade;
uint8_t *map = (uint8_t *)&led_map;
uint8_t *set = (uint8_t *)&led_set;
if (led_matrix_needs_update) {
led_matrix_needs_update = 0;
// remap data for sending
for (i = 0; i < led_map_size; i++) {
if ((*map) & (*map <= AW20X_FADE_COUNT)) {
fade[*map - 1] = *set;
}
map++;
set++;
}
aw20x_set_fade(&awled);
}
}

35
firmware/app/led/matrix.h Normal file
View File

@@ -0,0 +1,35 @@
/*
*
*/
#ifndef __APP_LED_MATRIX_H
#define __APP_LED_MATRIX_H
#include <stdint.h>
// 0 index = bottom.
// 0 value = no LED here.
typedef struct LedMap {
uint8_t ribbon[80]; // a "linear" bottom to top map, with gaps for the spacing.
uint8_t a[20]; // left to right, bottom to apex to bottom.
uint8_t ii_lf[5]; // top to bottom.
uint8_t ii_rt[5]; // top to bottom.
} LedMap;
extern LedMap led_set;
void matrix_init();
void matrix_send();
void matrix_flag_update();
#endif /* __APP_LED_MATRIX_H */