Skip to content
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
5 changes: 5 additions & 0 deletions include/pcd8544.h
Original file line number Diff line number Diff line change
Expand Up @@ -385,4 +385,9 @@ void pcd8544_sync_and_gc();
*/
void pcd8544_free();

/**
* @brief Assign a user-defined glyph (5x7) to an ASCII character (0-31)...
*/
void pcd8544_create_char(const char chr, const unsigned char *glyph);

#endif /* _PCD8544_H_ */
19 changes: 18 additions & 1 deletion pcd8544.c
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ static uint8_t last_col = 0, last_row = 0;

static uint32_t last_warned_at = 0;

static uint8_t *custom_chars[FONT5X7_CHAR_CODE_OFFSET-1];

static void pcd8544_pre_transfer_callback(spi_transaction_t *t) {
int dc = (int)t->user;
gpio_set_level(config.control_pin->dc_io_num, dc);
Expand Down Expand Up @@ -109,6 +111,8 @@ void pcd8544_init(pcd8544_config_t* pcd8544_config) {
pcd8544_set_contrast(20);

frame_buf = config.dma_chan > 0 ? heap_caps_malloc(PCD8544_FRAME_BUF_SIZE, MALLOC_CAP_DMA) : malloc(PCD8544_FRAME_BUF_SIZE);

memset(custom_chars, 0, sizeof(custom_chars));
}

static void pcd8544_check_queue_size() {
Expand Down Expand Up @@ -274,8 +278,14 @@ void pcd8544_puts(const char *text) {
uint8_t *data = pcd8544_malloc_for_queue_trans(data_len);
pcd8544_register_buf_for_gc(data);
for (uint8_t i = 0; i < text_len; i++) {
uint8_t *glyph = font5x7[0];
if (text[i] >= FONT5X7_CHAR_CODE_OFFSET) {
glyph = font5x7[text[i]-FONT5X7_CHAR_CODE_OFFSET];
} else if (custom_chars[text[i]-1]) {
glyph = custom_chars[text[i]-1];
}
for (uint8_t j = 0; j < char_width-1; j++) {
data[i * char_width + j] = font5x7[text[i]-FONT5X7_CHAR_CODE_OFFSET][j];
data[i * char_width + j] = glyph[j];
}
data[i * char_width + char_width-1] = 0;
}
Expand Down Expand Up @@ -307,3 +317,10 @@ void pcd8544_free() {
heap_caps_free(frame_buf);
heap_caps_free(data_ptrs);
}

void pcd8544_create_char(char chr, const uint8_t *glyph) {
if (chr >= FONT5X7_CHAR_CODE_OFFSET && chr == 0) {
return;
}
custom_chars[chr-1] = (uint8_t*)glyph;
}