Skip to content

Commit 714ed5d

Browse files
committed
Add support for 64-bit image drawing with MAX7219 8x8 LED Matrix
The MAX7219 driver has been extended to add support for bitmap drawing on an 8-by-8 LED matrix panel. Consumers can specify the targeted chip, which corresponds to a LED matrix panel, and provide a 64-bit image buffer specifying the pixels which should illuminate.
1 parent 503e66a commit 714ed5d

File tree

5 files changed

+163
-1
lines changed

5 files changed

+163
-1
lines changed

examples/max7219_8x8/Makefile

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
PROGRAM = max7219_8x8
2+
EXTRA_COMPONENTS = extras/max7219
3+
include ../../common.mk

examples/max7219_8x8/digit_font.h

Lines changed: 95 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
const uint8_t DIGITS[][8] = {
2+
{
3+
0x0,
4+
0x3c,
5+
0x66,
6+
0x6e,
7+
0x76,
8+
0x66,
9+
0x66,
10+
0x3c
11+
}, {
12+
0x0,
13+
0x18,
14+
0x18,
15+
0x38,
16+
0x18,
17+
0x18,
18+
0x18,
19+
0x7e
20+
}, {
21+
0x0,
22+
0x3c,
23+
0x66,
24+
0x6,
25+
0xc,
26+
0x30,
27+
0x60,
28+
0x7e
29+
}, {
30+
0x0,
31+
0x3c,
32+
0x66,
33+
0x6,
34+
0x1c,
35+
0x6,
36+
0x66,
37+
0x3c
38+
}, {
39+
0x0,
40+
0xc,
41+
0x1c,
42+
0x2c,
43+
0x4c,
44+
0x7e,
45+
0xc,
46+
0xc
47+
}, {
48+
0x0,
49+
0x7e,
50+
0x60,
51+
0x7c,
52+
0x6,
53+
0x6,
54+
0x66,
55+
0x3c
56+
}, {
57+
0x0,
58+
0x3c,
59+
0x66,
60+
0x60,
61+
0x7c,
62+
0x66,
63+
0x66,
64+
0x3c
65+
}, {
66+
0x0,
67+
0x7e,
68+
0x66,
69+
0xc,
70+
0xc,
71+
0x18,
72+
0x18,
73+
0x18
74+
}, {
75+
0x0,
76+
0x3c,
77+
0x66,
78+
0x66,
79+
0x3c,
80+
0x66,
81+
0x66,
82+
0x3c
83+
}, {
84+
0x0,
85+
0x3c,
86+
0x66,
87+
0x66,
88+
0x3e,
89+
0x6,
90+
0x66,
91+
0x3c
92+
}
93+
};
94+
95+
const int DIGITS_LEN = sizeof(DIGITS)/8;

examples/max7219_8x8/main.c

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/*
2+
* Example of using MAX7219 driver with 8x8 LED Matrix displays
3+
*
4+
* MAX7219 driver uses the hardware SPI bus, so connect with pinout:
5+
* DIN -> HSPID/HMOSI
6+
* CS -> HSPICS/HCS
7+
* CLK -> HSPICLK/HSCLK
8+
*/
9+
#include <esp/uart.h>
10+
#include <espressif/esp_common.h>
11+
#include <stdio.h>
12+
#include <max7219/max7219.h>
13+
#include <FreeRTOS.h>
14+
#include <task.h>
15+
#include <stdio.h>
16+
#include <esp/hwrand.h>
17+
18+
#include "./digit_font.h"
19+
20+
#define CS_PIN 15
21+
#define DELAY 1000
22+
23+
static max7219_display_t disp = {
24+
.cs_pin = CS_PIN,
25+
.digits = 8,
26+
.cascade_size = 4,
27+
.mirrored = false
28+
};
29+
30+
void user_init(void) {
31+
uart_set_baud(0, 115200);
32+
printf("SDK version:%s\n", sdk_system_get_sdk_version());
33+
34+
max7219_init(&disp);
35+
//max7219_set_decode_mode(&disp, true);
36+
37+
uint8_t counter = 0;
38+
while (true) {
39+
max7219_clear(&disp);
40+
41+
max7219_draw_image_8x8(&disp, 0, DIGITS[counter % 10]);
42+
max7219_draw_image_8x8(&disp, 1, DIGITS[(counter+1) % 10]);
43+
max7219_draw_image_8x8(&disp, 2, DIGITS[(counter+2) % 10]);
44+
max7219_draw_image_8x8(&disp, 3, DIGITS[(counter+3) % 10]);
45+
46+
vTaskDelay(DELAY / portTICK_PERIOD_MS);
47+
48+
counter++;
49+
}
50+
}

extras/max7219/max7219.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ void max7219_set_shutdown_mode(const max7219_display_t *disp, bool shutdown)
119119

120120
bool max7219_set_digit(const max7219_display_t *disp, uint8_t digit, uint8_t val)
121121
{
122-
if (digit >= disp->digits)
122+
if (digit >= (disp->digits * disp->cascade_size))
123123
{
124124
debug("Invalid digit: %d", digit);
125125
return false;
@@ -187,3 +187,9 @@ void max7219_draw_text(const max7219_display_t *disp, uint8_t pos, const char *s
187187
s++;
188188
}
189189
}
190+
191+
void max7219_draw_image_8x8(const max7219_display_t *disp, uint8_t pos, const void *image)
192+
{
193+
for (uint8_t i = (pos * disp->digits), offset = 0; i < (disp->digits * disp->cascade_size) && offset < 8; i++, offset++)
194+
max7219_set_digit(disp, i, *((uint8_t *)image + offset));
195+
}

extras/max7219/max7219.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,14 @@ void max7219_clear(const max7219_display_t *disp);
8888
*/
8989
void max7219_draw_text(const max7219_display_t *disp, uint8_t pos, const char *s);
9090

91+
/**
92+
* Draw 64-bit image on 8x8 matrix.
93+
* @param disp Pointer to display descriptor
94+
* @param pos Start digit
95+
* @param image 64-bit buffer with image data
96+
*/
97+
void max7219_draw_image_8x8(const max7219_display_t *disp, uint8_t pos, const void *image);
98+
9199
#ifdef __cplusplus
92100
}
93101
#endif

0 commit comments

Comments
 (0)