Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for 8x8 bitmap drawing with MAX7219 driver #765

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions examples/max7219_8x8/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
PROGRAM = max7219_8x8
EXTRA_COMPONENTS = extras/max7219
include ../../common.mk
95 changes: 95 additions & 0 deletions examples/max7219_8x8/digit_font.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
const uint8_t DIGITS[][8] = {
{
0x0,
0x3c,
0x66,
0x6e,
0x76,
0x66,
0x66,
0x3c
}, {
0x0,
0x18,
0x18,
0x38,
0x18,
0x18,
0x18,
0x7e
}, {
0x0,
0x3c,
0x66,
0x6,
0xc,
0x30,
0x60,
0x7e
}, {
0x0,
0x3c,
0x66,
0x6,
0x1c,
0x6,
0x66,
0x3c
}, {
0x0,
0xc,
0x1c,
0x2c,
0x4c,
0x7e,
0xc,
0xc
}, {
0x0,
0x7e,
0x60,
0x7c,
0x6,
0x6,
0x66,
0x3c
}, {
0x0,
0x3c,
0x66,
0x60,
0x7c,
0x66,
0x66,
0x3c
}, {
0x0,
0x7e,
0x66,
0xc,
0xc,
0x18,
0x18,
0x18
}, {
0x0,
0x3c,
0x66,
0x66,
0x3c,
0x66,
0x66,
0x3c
}, {
0x0,
0x3c,
0x66,
0x66,
0x3e,
0x6,
0x66,
0x3c
}
};

const int DIGITS_LEN = sizeof(DIGITS)/8;
48 changes: 48 additions & 0 deletions examples/max7219_8x8/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
* Example of using MAX7219 driver with 8x8 LED Matrix displays
*
* MAX7219 driver uses the hardware SPI bus, so connect with pinout:
* DIN -> HSPID/HMOSI
* CS -> HSPICS/HCS
* CLK -> HSPICLK/HSCLK
*/
#include <esp/uart.h>
#include <espressif/esp_common.h>
#include <stdio.h>
#include <max7219/max7219.h>
#include <FreeRTOS.h>
#include <task.h>

#include "./digit_font.h"

#define CS_PIN 15
#define DELAY 1000

static max7219_display_t disp = {
.cs_pin = CS_PIN,
.digits = 8,
.cascade_size = 4,
.mirrored = false
};

void user_init(void) {
uart_set_baud(0, 115200);
printf("SDK version:%s\n", sdk_system_get_sdk_version());

max7219_init(&disp);
//max7219_set_decode_mode(&disp, true);

uint8_t counter = 0;
while (true) {
max7219_clear(&disp);

max7219_draw_image_8x8(&disp, 0, DIGITS[counter % 10]);
max7219_draw_image_8x8(&disp, 1, DIGITS[(counter+1) % 10]);
max7219_draw_image_8x8(&disp, 2, DIGITS[(counter+2) % 10]);
max7219_draw_image_8x8(&disp, 3, DIGITS[(counter+3) % 10]);

vTaskDelay(DELAY / portTICK_PERIOD_MS);

counter++;
}
}
8 changes: 7 additions & 1 deletion extras/max7219/max7219.c
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ void max7219_set_shutdown_mode(const max7219_display_t *disp, bool shutdown)

bool max7219_set_digit(const max7219_display_t *disp, uint8_t digit, uint8_t val)
{
if (digit >= disp->digits)
if (digit >= (disp->digits * disp->cascade_size))
{
debug("Invalid digit: %d", digit);
return false;
Expand Down Expand Up @@ -187,3 +187,9 @@ void max7219_draw_text(const max7219_display_t *disp, uint8_t pos, const char *s
s++;
}
}

void max7219_draw_image_8x8(const max7219_display_t *disp, uint8_t pos, const void *image)
{
for (uint8_t i = (pos * disp->digits), offset = 0; i < (disp->digits * disp->cascade_size) && offset < 8; i++, offset++)
max7219_set_digit(disp, i, *((uint8_t *)image + offset));
}
8 changes: 8 additions & 0 deletions extras/max7219/max7219.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,14 @@ void max7219_clear(const max7219_display_t *disp);
*/
void max7219_draw_text(const max7219_display_t *disp, uint8_t pos, const char *s);

/**
* Draw 64-bit image on 8x8 matrix.
* @param disp Pointer to display descriptor
* @param pos Start digit
* @param image 64-bit buffer with image data
*/
void max7219_draw_image_8x8(const max7219_display_t *disp, uint8_t pos, const void *image);

#ifdef __cplusplus
}
#endif
Expand Down