lots of code copied over, things filled in to hopefully get the LED matrix lighting up. untested.
128 lines
2.6 KiB
C
128 lines
2.6 KiB
C
/*
|
|
*
|
|
*/
|
|
|
|
|
|
#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);
|
|
}
|
|
} |