You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
83 lines
2.6 KiB
83 lines
2.6 KiB
2 years ago
|
/**
|
||
|
* TODO file description
|
||
|
*/
|
||
|
|
||
|
#ifndef HD44780UTF_LCDBUF_H
|
||
|
#define HD44780UTF_LCDBUF_H
|
||
|
|
||
|
#include <stdint.h>
|
||
|
#include "utf8.h"
|
||
|
#include "cgram.h"
|
||
|
#include "cgrom.h"
|
||
|
|
||
|
#define LINE_NUM 4
|
||
|
#define LINE_LEN 20
|
||
|
|
||
|
#define BUFLEN_DIRTY_LIST 8
|
||
|
|
||
|
_Static_assert(LINE_NUM * LINE_LEN < 256, "LINE_NUM * LINE_LEN must fit in u8");
|
||
|
|
||
|
/** Indicates a range of screen cells that were changed and must be written to HW */
|
||
|
struct DirtyExtent {
|
||
|
uint8_t row;
|
||
|
uint8_t col;
|
||
|
uint8_t count;
|
||
|
};
|
||
|
|
||
|
/** Struct for one CGRAM slot */
|
||
|
struct CgramState {
|
||
|
/** UTF8 uint shown in this slot */
|
||
|
uint32_t uint;
|
||
|
/** Array index in the custom symbols table, use for look-up when writing the font data to HW */
|
||
|
uint32_t symbol_index;
|
||
|
/** Number of occurrences of this symbol in the screen array */
|
||
|
uint8_t refcount;
|
||
|
/** This CGRAM slot needs to be written to HW */
|
||
|
bool dirty;
|
||
|
};
|
||
|
|
||
|
struct LcdBuffer {
|
||
|
/** The raw screen buffer. Custom symbols are 0x00-0x07 */
|
||
|
uint8_t screen[LINE_NUM][LINE_LEN];
|
||
|
/** CGRAM state array */
|
||
|
struct CgramState cgram[8];
|
||
|
/** Hardware CGROM lookup table, used to map UTF8 to existing ROM symbols */
|
||
|
const struct cgrom_entry *cgrom;
|
||
|
/** Defined custom display pattern of utf8 symbols */
|
||
|
const struct cgram_pattern *custom_symbols;
|
||
|
|
||
|
/** Array of dirty extents - ranges in the display that need to be flushed to HW */
|
||
|
struct DirtyExtent dirty_extents[BUFLEN_DIRTY_LIST];
|
||
|
/** If the dirty extents array was not sufficient to hold all changes, this flag is set,
|
||
|
* indicating the dirty_extents array should be disregarded. */
|
||
|
bool full_repaint_required;
|
||
|
};
|
||
|
|
||
|
/** Initialize the struct */
|
||
|
void LcdBuffer_Init(struct LcdBuffer *self, const struct cgrom_entry *cgrom, const struct cgram_pattern *custom_symbols);
|
||
|
|
||
|
/** Clear the screen */
|
||
|
void LcdBuffer_Clear(struct LcdBuffer *self);
|
||
|
|
||
|
/** Write what needs to be written to the HW, clear all dirty marks */
|
||
|
void LcdBuffer_Flush(struct LcdBuffer *self);
|
||
|
|
||
|
/** Fully write everything to the display */
|
||
|
void LcdBuffer_FlushAll(struct LcdBuffer *self);
|
||
|
|
||
|
/** Set one utf8 character at a position */
|
||
|
void LcdBuffer_Set(struct LcdBuffer *self, uint8_t row, uint8_t col, struct Utf8Char ch);
|
||
|
|
||
|
/** Write a UTF8 string at a position */
|
||
|
void LcdBuffer_Write(struct LcdBuffer *self, uint8_t row, uint8_t col, char *utf_string);
|
||
|
|
||
|
/* Callbacks - need to be implemented by the application! */
|
||
|
|
||
|
/** Write character data at position */
|
||
|
void LcdBuffer_IO_WriteAt(uint8_t row, uint8_t col, const uint8_t *buf, uint8_t len);
|
||
|
|
||
|
/** Write CGRAM data. Data is always 8 bytes long. */
|
||
|
void LcdBuffer_IO_WriteCGRAM(uint8_t position, const uint8_t* data);
|
||
|
|
||
|
#endif //HD44780UTF_LCDBUF_H
|