#include "ssd1306.h" #include "ssd1306_driver.h" #include "esp_log.h" #include "stdlib.h" #include "string.h" #include "config.h" #include "fonts.h" #ifdef ENABLE_SSD1306 static uint8_t SSD1306_Buffer[SSD1306_WIDTH * SSD1306_HEIGHT / 8]; typedef struct { uint16_t CurrentX; uint16_t CurrentY; uint8_t Inverted; uint8_t Initialized; } SSD1306_t; /* Private variable */ static SSD1306_t SSD1306; void SSD1306_SetPosition(const int x, const int y) { SSD1306.CurrentX = x; SSD1306.CurrentY = y; } void SSD1306_Clear() { memset(SSD1306_Buffer,0,SSD1306_WIDTH * SSD1306_HEIGHT / 8); } void SSD1306_DrawPixel(uint16_t x, uint16_t y, SSD1306_COLOR_t color) { if ( x >= SSD1306_WIDTH || y >= SSD1306_HEIGHT ) { return; } if (color == SSD1306_COLOR_WHITE) { SSD1306_Buffer[x + (y / 8) * SSD1306_WIDTH] |= 1 << (y % 8); } else { SSD1306_Buffer[x + (y / 8) * SSD1306_WIDTH] &= ~(1 << (y % 8)); } } char SSD1306_Putc(char ch, const FontDef_t* Font, SSD1306_COLOR_t color) { uint32_t i, b, j; /* Check available space in LCD */ if ( SSD1306_WIDTH <= (SSD1306.CurrentX + Font->FontWidth) || SSD1306_HEIGHT <= (SSD1306.CurrentY + Font->FontHeight) ) { /* Error */ return 0; } /* Go through font */ for (i = 0; i < Font->FontHeight; i++) { b = Font->data[(ch - 32) * Font->FontHeight + i]; for (j = 0; j < Font->FontWidth; j++) { if ((b << j) & 0x8000) { SSD1306_DrawPixel(SSD1306.CurrentX + j, (SSD1306.CurrentY + i), (SSD1306_COLOR_t) color); } else { SSD1306_DrawPixel(SSD1306.CurrentX + j, (SSD1306.CurrentY + i), (SSD1306_COLOR_t)!color); } } } /* Increase pointer */ SSD1306.CurrentX += Font->FontWidth; /* Return character written */ return ch; } char SSD1306_Puts(char* str, FontDef_t* Font, SSD1306_COLOR_t color) { /* Write characters */ while (*str) { /* Write character by character */ if (SSD1306_Putc(*str, Font, color) != *str) { /* Return error */ return *str; } /* Increase string pointer */ str++; } /* Everything OK, zero should be returned */ return *str; } void SSD1306_DrawVertLine(const uint8_t y, const uint8_t x1, const uint8_t x2) { for(uint8_t x=x1; x