/* * (c) danielinux 2019 * GPLv.2 * * See LICENSE for details */ #include #include #include "display.h" #include "systick.h" #include "system.h" static uint8_t contrast = 0xcf; void display_scroll(void *priv, uint8_t line) { display_send_cmd1(priv, SSD1306_SETSTARTLINE, (line % 0x40) + 0x40); } void display_setcontrast(void *priv, uint8_t c) { contrast = c; display_send_cmd1(priv, SSD1306_SETCONTRAST, contrast); } uint8_t display_getcontrast(void *priv) { return contrast; } void display_clear(void *priv) { int i,j; uint8_t zeros[8] = {0, 0, 0, 0, 0, 0, 0, 0 }; display_send_cmd(NULL, 0x00); display_send_cmd(NULL, 0x10); for (i = 0; i < 8; i++) { display_send_cmd2(NULL, SSD1306_PAGEADDR, i, 0x00); display_send_cmd2(NULL, SSD1306_COLUMNADDR, 0, WIDTH - 1); for (j = 0; j < 16; j++) display_send_data(NULL, zeros, 8); } WFI(); } void display_text(int row, const char *text) { int k; uint8_t zeros[8] = {0, 0, 0, 0, 0, 0, 0, 0 }; int len = strlen(text); if (len > 15) len = 15; display_send_cmd(NULL, 0x00); display_send_cmd(NULL, 0x10); WFI(); display_send_cmd2(NULL, SSD1306_PAGEADDR, 7 - row, 0x00); display_send_cmd2(NULL, SSD1306_COLUMNADDR, 0, WIDTH - 1); for(k = 0; k < len; k++) display_send_data(NULL, fb_font[text[k]], 8); for(; k < 16; k++) display_send_data(NULL, zeros, 8); } void display_text_inverse(int row, const char *text) { int k, j; uint8_t inv_buf[8]; uint8_t ones[8] = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF }; int len = strlen(text); if (len > 15) len = 15; display_send_cmd(NULL, 0x00); display_send_cmd(NULL, 0x10); WFI(); display_send_cmd2(NULL, SSD1306_PAGEADDR, 7 - row, 0x00); display_send_cmd2(NULL, SSD1306_COLUMNADDR, 0, WIDTH - 1); for(k = 0; k < len; k++) { for (j = 0; j < 8; j++) inv_buf[j] = ~fb_font[text[k]][j]; display_send_data(NULL, inv_buf, 8); } for(; k < 16; k++) display_send_data(NULL, ones, 8); } int display_init(void *priv) { int i; int k = 0; int row = 0; volatile int j; uint8_t dbuf2[64] = {}; int page = 0; int seg = 0; volatile uint32_t now; for (i = 1; i < 65; i++) { dbuf2[i] = 0; } display_send_cmd(priv, SSD1306_DISPLAYOFF); display_send_cmd1(priv, 0xD6, 0x01); display_send_cmd(priv, 0xA1); display_setcontrast(priv, contrast); display_send_cmd1(priv, SSD1306_CHARGEPUMP, 0x14); display_send_cmd1(priv, SSD1306_MEMORYMODE, 0x00); display_send_cmd1(priv, SSD1306_SETCOMPINS, 0x12); display_send_cmd1(priv, SSD1306_SETDISPLAYOFFSET, 0x00); display_send_cmd1(priv, SSD1306_SETVCOMDETECT, 0x00); display_send_cmd1(priv, SSD1306_SETMULTIPLEX, 63); display_send_cmd(priv, SSD1306_COMSCANINC); display_send_cmd(priv, SSD1306_DISPLAYALLON_RESUME); display_send_cmd(priv, SSD1306_DISPLAYON); display_send_cmd(priv, 0x2E); display_send_cmd2(priv, SSD1306_PAGEADDR, 0, 0xFF); display_send_cmd2(priv, SSD1306_COLUMNADDR, 0, WIDTH - 1); display_send_cmd1(priv, SSD1306_SETSTARTLINE, 0); display_send_cmd(priv, 0x00); display_send_cmd(priv, 0x10); for (page = 0; page < 8; page++) { display_send_cmd2(priv, SSD1306_PAGEADDR, page, 0xFF); for (seg= 0; seg < 32; seg++) { display_send_data(priv, dbuf2, 8); } display_send_cmd1(priv, SSD1306_SETSTARTLINE, row); } return 0; }