haven't verified against a scope but they "work for me" running at 24MHz at all times now for best energy use per watt before sleeping
153 lines
3.1 KiB
C
153 lines
3.1 KiB
C
/*
|
|
*
|
|
*/
|
|
|
|
|
|
#include "ch32x035_conf.h"
|
|
#include <string.h>
|
|
|
|
#include "matrix.h"
|
|
#include "driver/aw20xxx.h"
|
|
// #include "user_config.h"
|
|
|
|
|
|
|
|
|
|
#define AW20X_DIM 28 // 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;
|
|
uint8_t awled_fade[AW20X_FADE_COUNT];
|
|
|
|
static uint8_t led_matrix_needs_update = 0;
|
|
|
|
const LedMap led_map = {
|
|
// map is 1-based to match LED refdegs on the board
|
|
.ribbon = { // ribbon
|
|
13, 25, 1, 49,
|
|
37, 14,
|
|
26, 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, 0,
|
|
0, 0,
|
|
8, 0, 0, 20, 0, 0, 32,
|
|
0, 0
|
|
},
|
|
.a = { // "A"
|
|
9, 21, 33, 0, 0, 0, 45, 57, 10,
|
|
22,
|
|
34, 46, 58, 11, 23, 35, 47, 59, 12
|
|
},
|
|
.ii_lf = { // "//" left one
|
|
61, 62, 63, 64, 44
|
|
},
|
|
.ii_rt = { // "//" 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);
|
|
}
|
|
|
|
void matrix_flag_update()
|
|
{
|
|
led_matrix_needs_update = 1;
|
|
}
|
|
|
|
/*
|
|
static uint8_t delay = 0;
|
|
static uint8_t work = 0;
|
|
*/
|
|
|
|
void matrix_send()
|
|
{
|
|
uint32_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 < sizeof(led_map); i++) {
|
|
if ((*map) && ((*map) <= AW20X_FADE_COUNT)) {
|
|
fade[(*map) - 1] = *set;
|
|
}
|
|
map++; set++;
|
|
}
|
|
|
|
/* testing
|
|
if (delay) {
|
|
delay--;
|
|
} else {
|
|
delay = 20;
|
|
for (int i = 0; i < sizeof(led_map.ribbon); i++) {
|
|
if (led_map.ribbon[i]) {
|
|
awled_fade[led_map.ribbon[i] - 1] = 0;
|
|
}
|
|
}
|
|
|
|
if (led_map.ribbon[work]) {
|
|
awled_fade[led_map.ribbon[work] - 1] = 0xff;
|
|
}
|
|
work++;
|
|
|
|
if (work >= sizeof(led_map.ribbon)) work = 0;
|
|
|
|
matrix_flag_update();
|
|
}
|
|
*/
|
|
|
|
aw20x_set_fade(&awled);
|
|
}
|
|
} |