oled initialization with ssd1306
oled-main with structure ssd1306 initialization
This commit is contained in:
46
oled/ssd1306/ssd1306.c
Normal file
46
oled/ssd1306/ssd1306.c
Normal file
@@ -0,0 +1,46 @@
|
||||
|
||||
#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;
|
||||
}
|
||||
|
||||
oled_SendCommand(hOled, SSD1306_DISPLAYOFF, 1);
|
||||
|
||||
const 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));
|
||||
|
||||
oled_SendCommand(hOled, SSD1306_DISPLAYON, 1);
|
||||
|
||||
|
||||
}
|
||||
40
oled/ssd1306/ssd1306.h
Normal file
40
oled/ssd1306/ssd1306.h
Normal file
@@ -0,0 +1,40 @@
|
||||
#pragma once
|
||||
|
||||
#define SSD1306_MEMORYMODE 0x20 ///< See datasheet
|
||||
#define SSD1306_COLUMNADDR 0x21 ///< See datasheet
|
||||
#define SSD1306_PAGEADDR 0x22 ///< See datasheet
|
||||
#define SSD1306_SETCONTRAST 0x81 ///< See datasheet
|
||||
#define SSD1306_CHARGEPUMP 0x8D ///< See datasheet
|
||||
#define SSD1306_SEGREMAP 0xA0 ///< See datasheet
|
||||
#define SSD1306_DISPLAYALLON_RESUME 0xA4 ///< See datasheet
|
||||
#define SSD1306_DISPLAYALLON 0xA5 ///< Not currently used
|
||||
#define SSD1306_NORMALDISPLAY 0xA6 ///< See datasheet
|
||||
#define SSD1306_INVERTDISPLAY 0xA7 ///< See datasheet
|
||||
#define SSD1306_SETMULTIPLEX 0xA8 ///< See datasheet
|
||||
#define SSD1306_DISPLAYOFF 0xAE ///< See datasheet
|
||||
#define SSD1306_DISPLAYON 0xAF ///< See datasheet
|
||||
#define SSD1306_COMSCANINC 0xC0 ///< Not currently used
|
||||
#define SSD1306_COMSCANDEC 0xC8 ///< See datasheet
|
||||
#define SSD1306_SETDISPLAYOFFSET 0xD3 ///< See datasheet
|
||||
#define SSD1306_SETDISPLAYCLOCKDIV 0xD5 ///< See datasheet
|
||||
#define SSD1306_SETPRECHARGE 0xD9 ///< See datasheet
|
||||
#define SSD1306_SETCOMPINS 0xDA ///< See datasheet
|
||||
#define SSD1306_SETVCOMDETECT 0xDB ///< See datasheet
|
||||
|
||||
#define SSD1306_SETLOWCOLUMN 0x00 ///< Not currently used
|
||||
#define SSD1306_SETHIGHCOLUMN 0x10 ///< Not currently used
|
||||
#define SSD1306_SETSTARTLINE 0x40 ///< See datasheet
|
||||
|
||||
#define SSD1306_EXTERNALVCC 0x01 ///< External display voltage source
|
||||
#define SSD1306_SWITCHCAPVCC 0x02 ///< Gen. display voltage from 3.3V
|
||||
|
||||
#define SSD1306_RIGHT_HORIZONTAL_SCROLL 0x26 ///< Init rt scroll
|
||||
#define SSD1306_LEFT_HORIZONTAL_SCROLL 0x27 ///< Init left scroll
|
||||
#define SSD1306_VERTICAL_AND_RIGHT_HORIZONTAL_SCROLL 0x29 ///< Init diag scroll
|
||||
#define SSD1306_VERTICAL_AND_LEFT_HORIZONTAL_SCROLL 0x2A ///< Init diag scroll
|
||||
#define SSD1306_DEACTIVATE_SCROLL 0x2E ///< Stop scroll
|
||||
#define SSD1306_ACTIVATE_SCROLL 0x2F ///< Start scroll
|
||||
#define SSD1306_SET_VERTICAL_SCROLL_AREA 0xA3 ///< Set scroll range
|
||||
|
||||
|
||||
void SSD1306_Init(OLED_HandleTypeDef *hOled);
|
||||
Reference in New Issue
Block a user