Files
uC_libs/oled/ssd1306/ssd1306.c

81 lines
2.0 KiB
C

#include "ssd1306.h"
#include "connection.h"
void SSD1306_Init(OLED_HandleTypeDef *hOled)
{
uint8_t comPins = 0x02;
uint8_t contrast = 0x8F;
if ((hOled->Width == 128) && (hOled->Height == 32)) {
comPins = 0x02;
contrast = 0x0F;
} else if ((hOled->Width == 128) && (hOled->Height == 64)) {
comPins = 0x12;
contrast = 0xCF;
} else if ((hOled->Width == 96) && (hOled->Height == 16)) {
comPins = 0x02; // ada x12
contrast = 0xAF;
}
uint8_t display = SSD1306_DISPLAYOFF;
oled_SendCommand(hOled, &display, 1);
uint8_t config[] = {
SSD1306_SETMULTIPLEX, hOled->Height -1,
SSD1306_SETDISPLAYOFFSET, 0x00,
SSD1306_SETSTARTLINE | 0x00,
SSD1306_SEGREMAP | 0x01,
SSD1306_COMSCANDEC,
SSD1306_SETCOMPINS, comPins,
SSD1306_SETCONTRAST, contrast,
SSD1306_DISPLAYALLON_RESUME,
SSD1306_NORMALDISPLAY,
SSD1306_SETDISPLAYCLOCKDIV, 0x80,
SSD1306_CHARGEPUMP, 0x14,
SSD1306_MEMORYMODE, 0x00,
SSD1306_DEACTIVATE_SCROLL,
SSD1306_SETPRECHARGE, 0xF1,
SSD1306_SETVCOMDETECT, 0x40
};
oled_SendCommand(hOled, config, sizeof(config));
display = SSD1306_DISPLAYOFF;
oled_SendCommand(hOled, &display, 1);
}
void SSD1306_display_all(OLED_HandleTypeDef *hOled)
{
uint8_t config[] = {
SSD1306_PAGEADDR, 0x00, 0x07, //cmd, start_page, end_page
SSD1306_COLUMNADDR, 0x00, hOled->Width - 1 //cmd, start_col, end_col
};
oled_SendCommand(hOled, config, sizeof(config));
oled_SendData(hOled, hOled->Buffer, hOled->BufSize);
}
OLED_SendStatus_t SSD1306_display_page(OLED_HandleTypeDef *hOled)
{
static uint8_t page = 0;
uint8_t config[] = {
SSD1306_PAGEADDR, page, page,
SSD1306_COLUMNADDR, 0x00, hOled->Width - 1
};
oled_SendCommand(hOled, config, sizeof(config));
oled_SendData(hOled, hOled->Buffer + (page * hOled->Width), hOled->Width);
if (++page > 7)
{
page = 0;
return SENDALL;
}
else
{
return SENDPAGE;
}
}