diff options
| Commit | 26d05638f13ab41591a5a82012e895c64a3564ec (patch) | |
|---|---|---|
| Author | 2024-05-23 16:34:58 +0300 | |
| Committer | 2024-05-23 16:34:58 +0300 | |
| Files | ec4bbcbde7d500e10afdf61668d650447cf78afa | |
| uni-projects-26d05638f13ab41591a5a82012e895c64a3564ec.tar uni-projects-26d05638f13ab41591a5a82012e895c64a3564ec.tar.gz uni-projects-26d05638f13ab41591a5a82012e895c64a3564ec.zip | ||
| Parent | 3f1bdb7ef2253d4e1a6cecdb8ff50a1415950a29 (diff) | |
(iot/goam) Cleaned up and generalized display interface
2 files changed, 46 insertions, 67 deletions
| -rw-r--r-- | Year 3/Internet of things/goam/main/display.c | 109 | ||||
| -rw-r--r-- | Year 3/Internet of things/goam/main/display.h | 4 |
diff --git a/Year 3/Internet of things/goam/main/display.c b/Year 3/Internet of things/goam/main/display.c index e3eb96b..5e66984 100644 --- a/Year 3/Internet of things/goam/main/display.c +++ b/Year 3/Internet of things/goam/main/display.c @@ -7,6 +7,9 @@ static const char* TAG = "display"; +#define LAST_PAGE 7 +#define LAST_COL 127 + /* * I2C settings */ @@ -57,27 +60,43 @@ static void send(enum DATA_TYPE type, const unsigned char* data, size_t size) { } /* + * Static interface + */ + +unsigned char current_page = 0; +#define PAGE_INC ((current_page + 1) % (LAST_PAGE + 1)) + +static void display_output_borders(unsigned char column_start, unsigned char column_end, unsigned char page_start, unsigned char page_end) { + current_page = page_start; + unsigned char command[] = { 0x21, column_start, column_end, 0x22, page_start, page_end }; + send(CMD_STREAM, command, sizeof(command)); +} + +static void display_output_beginning() { + display_output_borders(0, LAST_COL, 0, LAST_PAGE); +} + +static void display_output_newpage() { + display_output_borders(0, LAST_COL, PAGE_INC, LAST_PAGE); +} + +/* * Public interface */ static const unsigned char startup[] = { - 0x8D, 0x14, 0xAF, - - 0x20, // vertical address mode - 0b00, - 0x21, // set column start/end - 0, 127, - 0x22, //set page start/end - 0, 7, + 0x8D, 0x14, 0xAF, // pump charge and enable + 0x20, 0b00, // vertical address mode }; -unsigned char current_page = 0; -#define PAGE_INC ((current_page + 1) % 8) - void display_init() { i2c_init(); send(CMD_STREAM, startup, sizeof(startup)); ESP_LOGI(TAG, "Initialized display"); + display_println(" "); + display_println(" "); + display_println(" "); + display_println(" "); } void display_invertion(enum Inversion inv_byte) { @@ -90,73 +109,33 @@ extern const unsigned bitpixel_char_height; extern const unsigned bitpixel_char_width; extern const uint8_t* bitpixel_chars[256]; -/* static const size_t line_width = 16; */ -/* static const size_t lines = 64 / bitpixel_char_height; */ - -unsigned char out_page_row[128]; - -void display_output_borders(unsigned char column_start, unsigned char column_end, unsigned char page_start, unsigned char page_end) { - unsigned char command[] = { 0x21, column_start, column_end, 0x22, page_start, page_end }; - send(CMD_STREAM, command, sizeof(command)); -} - -void display_output_beginning() { - display_output_borders(0, 127, 0, 7); -} - -void display_newpage() { - display_output_borders(0, 127, PAGE_INC, 7); -} +unsigned char out_page_row[LAST_COL + 1]; -void display_print(const char* str) { +void display_println(const char* str) { for (int linepage = 0; linepage <= 1; linepage++) { int column; - for (column = 0; column < 128; column++) { + for (column = 0; column <= LAST_COL; column++) { if (str[column / bitpixel_char_width] == '\0') { column--; break; } - out_page_row[column] = bitpixel_chars[(int)str[column / bitpixel_char_width]][(column * 2 + linepage) % 16]; + out_page_row[column] = bitpixel_chars[(int)str[column / bitpixel_char_width]] + [(column * 2 + linepage) % bitpixel_char_height]; } + send(DATA_STREAM, out_page_row, column); if (column < sizeof(out_page_row)) { - display_newpage(); + display_output_newpage(); } + current_page = PAGE_INC; } } -const unsigned char off = 0xAE, on = 0xAF; - -void display_example() { - // MUST be separated, for some reason - /* send(CMD_STREAM, &off, 1); */ - /* display_print(""); */ - display_print("A0 "); - /* display_print(""); */ - /* for (int i = 0; i < 16; i++) { */ - /* out_page_row[i] = bitpixel_chars[1][(i * 2) % 16]; */ - /* } */ - /* send(DATA_STREAM, out_page_row, 16); */ - /* send(DATA_STREAM, out_page_row, 16); */ - /* send(DATA_STREAM, out_page_row, 16); */ - /* send(DATA_STREAM, out_page_row, 16); */ - /* send(DATA_STREAM, out_page_row, 16); */ - /* send(DATA_STREAM, out_page_row, 16); */ - /* send(DATA_STREAM, out_page_row, 16); */ - /* send(DATA_STREAM, out_page_row, 16); */ - /* for (int i = 0; i < 16; i++) { */ - /* out_page_row[i] = bitpixel_chars[1][(i * 2+1) % 16]; */ - /* } */ - /* send(DATA_STREAM, out_page_row, 16); */ - /* send(DATA_STREAM, out_page_row, 16); */ - /* send(DATA_STREAM, out_page_row, 16); */ - /* send(DATA_STREAM, out_page_row, 16); */ - /* send(DATA_STREAM, out_page_row, 16); */ - /* send(DATA_STREAM, out_page_row, 16); */ - /* send(DATA_STREAM, out_page_row, 16); */ - /* send(DATA_STREAM, out_page_row, 16); */ - /* send(out_page_row, sizeof(out_page_row)); */ - /* send(pattern + 8, 3); */ - /* send(CMD_STREAM, &on, 1); */ +void display_printon(const char* str, unsigned char line) { + if (line < 1) line = 1; + if (line > 7) line = 7; + display_output_borders(0, 127, (line - 1) * 2, 7); + display_println(str); + display_output_beginning(); } diff --git a/Year 3/Internet of things/goam/main/display.h b/Year 3/Internet of things/goam/main/display.h index 0fcae86..db7159f 100644 --- a/Year 3/Internet of things/goam/main/display.h +++ b/Year 3/Internet of things/goam/main/display.h @@ -12,5 +12,5 @@ void display_invertion(enum Inversion inv_byte); /* clang-format on */ -void display_example(); -void display_print(const char* str); +void display_println(const char* str); +void display_printon(const char* str, unsigned char line); |
