Files
uC_libs/oled/oled.c
bartool 2663ee6e2a oled initialization with ssd1306
oled-main with structure
ssd1306 initialization
2022-06-17 23:04:16 +02:00

59 lines
1.1 KiB
C

#include <stdlib.h>
#include "oled.h"
#include "ssd1306.h"
HAL_StatusTypeDef oled_Config(OLED_HandleTypeDef *hOled, uint8_t DevAddress, uint8_t Width, uint8_t Height, OLED_DisplayTypeDef OledType)
{
if (hOled == NULL || Width == 0 || Height == 0 || OledType == UNKNOWN)
{
return HAL_ERROR;
}
hOled->DevAddress = DevAddress;
hOled->Width = Width;
hOled->Height = Height;
hOled->OledType = OledType;
hOled->Buffer = (uint8_t *)malloc(Width * ((Height + 7) / 8));
if (hOled->Buffer == NULL)
{
return HAL_ERROR;
}
return HAL_OK;
}
void oled_init(OLED_HandleTypeDef *hOled, I2C_HandleTypeDef *hi2c)
{
if (hOled == NULL || hi2c == NULL)
{
return;
}
if (hOled->Buffer == NULL)
{
return;
}
hOled->hi2c = hi2c;
switch (hOled->OledType)
{
case SSD1306:
SSD1306_Init(hOled);
break;
case SH1106:
SH1106_Init(hOled);
break;
default:
break;
}
}
int main(void)
{
OLED_HandleTypeDef display;
oled_Config(&display, 0x3C, 128, 64, SH1106);
}