finished drivers
ssd1306 and sh1106 are ready
This commit is contained in:
52
oled/oled.c
52
oled/oled.c
@@ -1,8 +1,9 @@
|
||||
#include <stdlib.h>
|
||||
#include "oled.h"
|
||||
#include "ssd1306.h"
|
||||
#include "sh1106.h"
|
||||
|
||||
HAL_StatusTypeDef oled_Config(OLED_HandleTypeDef *hOled, uint8_t DevAddress, uint8_t Width, uint8_t Height, OLED_DisplayTypeDef OledType)
|
||||
HAL_StatusTypeDef oled_Config(OLED_HandleTypeDef *hOled, uint8_t DevAddress, uint8_t Width, uint8_t Height, OLED_DisplayType_t OledType)
|
||||
{
|
||||
if (hOled == NULL || Width == 0 || Height == 0 || OledType == UNKNOWN)
|
||||
{
|
||||
@@ -13,7 +14,8 @@ HAL_StatusTypeDef oled_Config(OLED_HandleTypeDef *hOled, uint8_t DevAddress, uin
|
||||
hOled->Width = Width;
|
||||
hOled->Height = Height;
|
||||
hOled->OledType = OledType;
|
||||
hOled->Buffer = (uint8_t *)malloc(Width * ((Height + 7) / 8));
|
||||
hOled->BufSize = Width * ((Height + 7) / 8);
|
||||
hOled->Buffer = (uint8_t *)malloc(hOled->BufSize);
|
||||
|
||||
if (hOled->Buffer == NULL)
|
||||
{
|
||||
@@ -30,7 +32,7 @@ void oled_init(OLED_HandleTypeDef *hOled, I2C_HandleTypeDef *hi2c)
|
||||
return;
|
||||
}
|
||||
|
||||
if (hOled->Buffer == NULL)
|
||||
if (hOled->Buffer == NULL || hOled->BufSize == 0)
|
||||
{
|
||||
return;
|
||||
}
|
||||
@@ -51,6 +53,50 @@ void oled_init(OLED_HandleTypeDef *hOled, I2C_HandleTypeDef *hi2c)
|
||||
}
|
||||
}
|
||||
|
||||
void oled_display_all(OLED_HandleTypeDef *hOled)
|
||||
{
|
||||
if (hOled == NULL)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
switch (hOled->OledType)
|
||||
{
|
||||
case SSD1306:
|
||||
SSD1306_display_all(hOled);
|
||||
break;
|
||||
case SH1106:
|
||||
SH1106_display_all(hOled);
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
OLED_SendStatus_t oled_display_page(OLED_HandleTypeDef *hOled)
|
||||
{
|
||||
if (hOled == NULL)
|
||||
{
|
||||
return;
|
||||
}
|
||||
OLED_SendStatus_t sendStatus;
|
||||
switch (hOled->OledType)
|
||||
{
|
||||
case SSD1306:
|
||||
sendStatus = SSD1306_display_page(hOled);
|
||||
break;
|
||||
case SH1106:
|
||||
sendStatus = SH1106_display_page(hOled);
|
||||
break;
|
||||
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
return sendStatus;
|
||||
}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
|
||||
|
||||
Reference in New Issue
Block a user