finished drivers

ssd1306 and sh1106 are ready
This commit is contained in:
2022-06-18 19:10:48 +02:00
parent 55f54a2d4a
commit e01ec3e367
6 changed files with 143 additions and 24 deletions

View File

@@ -1,8 +1,9 @@
#include <stdlib.h> #include <stdlib.h>
#include "oled.h" #include "oled.h"
#include "ssd1306.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) 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->Width = Width;
hOled->Height = Height; hOled->Height = Height;
hOled->OledType = OledType; 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) if (hOled->Buffer == NULL)
{ {
@@ -30,7 +32,7 @@ void oled_init(OLED_HandleTypeDef *hOled, I2C_HandleTypeDef *hi2c)
return; return;
} }
if (hOled->Buffer == NULL) if (hOled->Buffer == NULL || hOled->BufSize == 0)
{ {
return; 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) int main(void)
{ {

View File

@@ -11,16 +11,22 @@ typedef enum
UNKNOWN, UNKNOWN,
SSD1306, SSD1306,
SH1106 SH1106
} OLED_DisplayTypeDef; } OLED_DisplayType_t;
typedef enum{
SENDPAGE,
SENDALL
} OLED_SendStatus_t;
typedef struct typedef struct
{ {
I2C_HandleTypeDef *hi2c; I2C_HandleTypeDef *hi2c;
OLED_DisplayTypeDef OledType; OLED_DisplayType_t OledType;
uint8_t DevAddress; uint8_t DevAddress;
uint8_t Width; uint8_t Width;
uint8_t Height; uint8_t Height;
uint8_t *Buffer; uint8_t *Buffer;
uint16_t BufSize;
} OLED_HandleTypeDef; } OLED_HandleTypeDef;

View File

@@ -1,3 +1,4 @@
#include "oled.h"
#include "sh1106.h" #include "sh1106.h"
#include "connection.h" #include "connection.h"
@@ -31,3 +32,31 @@ void SH1106_Init(OLED_HandleTypeDef *hOled)
oled_SendCommand(hOled, &display, 1); oled_SendCommand(hOled, &display, 1);
} }
void SH1106_display_all(OLED_HandleTypeDef *hOled)
{
while (SH1106_display_page(hOled) != SENDALL);
}
OLED_SendStatus_t SH1106_display_page(OLED_HandleTypeDef *hOled)
{
static uint8_t page = 0;
uint8_t config[] = {
SH1106_PAGEADDRESS | page,
SH1106_LOWCOLADDR | 0x00,
SH1106_HIGHCOLADDR | 0x00,
};
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;
}
}

View File

@@ -27,3 +27,7 @@
#define SH1106_COMPADSCONFVAL 0x12 // 0x12h (000X 0010) #define SH1106_COMPADSCONFVAL 0x12 // 0x12h (000X 0010)
#define SH1106_VCOMDESMODE 0xDD // (1101 1101) #define SH1106_VCOMDESMODE 0xDD // (1101 1101)
#define SH1106_VCOMDESVALUE 0x35 // 0x35h (XXXX XXXX) VCOM (Beta x Vref) #define SH1106_VCOMDESVALUE 0x35 // 0x35h (XXXX XXXX) VCOM (Beta x Vref)
void SH1106_Init(OLED_HandleTypeDef *hOled);
void SH1106_display_all(OLED_HandleTypeDef *hOled);
OLED_SendStatus_t SH1106_display_page(OLED_HandleTypeDef *hOled);

View File

@@ -43,6 +43,39 @@ void SSD1306_Init(OLED_HandleTypeDef *hOled)
display = SSD1306_DISPLAYOFF; display = SSD1306_DISPLAYOFF;
oled_SendCommand(hOled, &display, 1); 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));
SSD1306_SendData(hOled->Buffer + (page * hOled->Width), hOled->Width);
if (++page > 7)
{
page = 0;
return SENDALL;
}
else
{
return SENDPAGE;
}
} }

View File

@@ -38,5 +38,6 @@
#define SSD1306_ACTIVATE_SCROLL 0x2F ///< Start scroll #define SSD1306_ACTIVATE_SCROLL 0x2F ///< Start scroll
#define SSD1306_SET_VERTICAL_SCROLL_AREA 0xA3 ///< Set scroll range #define SSD1306_SET_VERTICAL_SCROLL_AREA 0xA3 ///< Set scroll range
void SSD1306_Init(OLED_HandleTypeDef *hOled); void SSD1306_Init(OLED_HandleTypeDef *hOled);
void SSD1306_display_all(OLED_HandleTypeDef *hOled);
OLED_SendStatus_t SSD1306_display_page(OLED_HandleTypeDef *hOled);