Skip to content

Commit

Permalink
Add support for 8x8 image drawing in MAX7219 driver
Browse files Browse the repository at this point in the history
  • Loading branch information
trentrand committed Nov 27, 2020
1 parent 503e66a commit b0f8fbb
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 30 deletions.
60 changes: 30 additions & 30 deletions examples/max7219_7seg/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,39 +14,39 @@
#include <stdio.h>
#include <esp/hwrand.h>

#define CS_PIN 5
#include "../../../../src/digit_font.h"

/* #include "gdbstub.h" */

#define CS_PIN 15
#define DELAY 2000

// TODO: digits should be "columns" for 8x8 drawing, so update implementation to (digits * cascade)
static max7219_display_t disp = {
.cs_pin = CS_PIN,
.digits = 8,
.cascade_size = 1,
.mirrored = true
.cs_pin = CS_PIN,
.digits = 8 * 4,
.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);

char buf[9];
while (true)
{
max7219_clear(&disp);
max7219_draw_text(&disp, 0, "7219LEDS");
vTaskDelay(DELAY / portTICK_PERIOD_MS);

max7219_clear(&disp);
sprintf(buf, "%2.4f A", 34.6782);
max7219_draw_text(&disp, 0, buf);
vTaskDelay(DELAY / portTICK_PERIOD_MS);

max7219_clear(&disp);
sprintf(buf, "%08x", hwrand());
max7219_draw_text(&disp, 0, buf);
vTaskDelay(DELAY / portTICK_PERIOD_MS);
}
void user_init(void) {
uart_set_baud(0, 115200);
printf("SDK version:%s\n", sdk_system_get_sdk_version());

/* gdbstub_init(); */

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

while (true) {
max7219_clear(&disp);
uint8_t smile[8]= {0x3C, 0x42, 0xA5, 0x81, 0xA5, 0x99, 0x42, 0x3C};
uint8_t alien[8] = {0x99, 0xbd, 0x5a, 0x7e, 0x42, 0x3c, 0xdb, 0x81};

max7219_draw_image_8x8(&disp, 0, DIGITS[0]);
max7219_draw_image_8x8(&disp, 8, DIGITS[3]);
max7219_draw_image_8x8(&disp, 16, DIGITS[5]);
max7219_draw_image_8x8(&disp, 24, DIGITS[7]);
vTaskDelay(DELAY / portTICK_PERIOD_MS);
}
}
6 changes: 6 additions & 0 deletions extras/max7219/max7219.c
Original file line number Diff line number Diff line change
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, offset = 0; i < disp->digits && 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

0 comments on commit b0f8fbb

Please sign in to comment.