#include // #include #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_DisplayType_t OledType) { // static_assert(hOled != NULL, "brak pointera"); if (hOled == NULL || Width == 0 || Height == 0 || OledType == UNKNOWN) { return HAL_ERROR; } hOled->hi2c = NULL; hOled->DevAddress = DevAddress; hOled->Width = Width; hOled->Height = Height; hOled->OledType = OledType; hOled->BufSize = Width * ((Height + 7) / 8); hOled->Buffer = (uint8_t *)malloc(hOled->BufSize); 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 || hOled->BufSize == 0) { return; } hOled->hi2c = hi2c; switch (hOled->OledType) { case SSD1306: SSD1306_Init(hOled); break; case SH1106: SH1106_Init(hOled); break; default: break; } } 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 ERROR; } 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; }