added drivers

This commit is contained in:
2023-09-25 21:32:15 +02:00
parent 0d74fea761
commit 4829b04024
28 changed files with 6621 additions and 3 deletions

View File

@@ -0,0 +1,84 @@
// #include "main.h"
#include "st7565.h"
static uint8_t st7565_buffor[ST7565_BUFFER_SIZE];
static void ST7565_SendCommand(st7565_handle_t *hdisp, uint8_t data)
{
HAL_GPIO_WritePin(hdisp->a0_port, hdisp->a0_pin, GPIO_PIN_RESET);
HAL_SPI_Transmit(hdisp->hspi, &data, 1, HAL_MAX_DELAY);
}
static void ST7565_SendData(st7565_handle_t *hdisp, uint8_t *data, uint16_t size)
{
HAL_GPIO_WritePin(hdisp->a0_port, hdisp->a0_pin, GPIO_PIN_SET);
HAL_SPI_Transmit(hdisp->hspi, data, size, HAL_MAX_DELAY);
}
void ST7565_Init(st7565_handle_t *hdisp, GFX_display_t *disp)
{
if (hdisp == NULL || hdisp->hspi == NULL || hdisp->a0_port == NULL || hdisp->cs_port == NULL || hdisp->rst_port == NULL)
{
Error_Handler();
}
disp->width = ST7565_WIDTH;
disp->height = ST7565_HEIGHT;
disp->buffor = st7565_buffor;
// toggle RST low to reset; CS low so it'll listen to us
HAL_GPIO_WritePin(hdisp->cs_port, hdisp->cs_pin, GPIO_PIN_RESET);
HAL_GPIO_WritePin(hdisp->rst_port, hdisp->rst_pin, GPIO_PIN_RESET);
HAL_Delay(500);
HAL_GPIO_WritePin(hdisp->rst_port, hdisp->rst_pin, GPIO_PIN_SET);
// LCD bias select
ST7565_SendCommand(hdisp, CMD_SET_BIAS_7);
// ADC select
ST7565_SendCommand(hdisp, CMD_SET_ADC_REVERSE);
// SHL select
ST7565_SendCommand(hdisp, CMD_SET_COM_NORMAL);
// Initial display line
ST7565_SendCommand(hdisp, CMD_SET_DISP_START_LINE);
// turn on voltage converter (VC=1, VR=0, VF=0)
ST7565_SendCommand(hdisp, CMD_SET_POWER_CONTROL | 0x4);
// wait for 50% rising
HAL_Delay(50);
// turn on voltage regulator (VC=1, VR=1, VF=0)
ST7565_SendCommand(hdisp, CMD_SET_POWER_CONTROL | 0x6);
// wait >=50ms
HAL_Delay(50);
// turn on voltage follower (VC=1, VR=1, VF=1)
ST7565_SendCommand(hdisp, CMD_SET_POWER_CONTROL | 0x7);
// wait
HAL_Delay(10);
// set lcd operating voltage (regulator resistor, ref voltage resistor)
ST7565_SendCommand(hdisp, CMD_SET_RESISTOR_RATIO | 0x6);
ST7565_SendCommand(hdisp, CMD_DISPLAY_ON);
ST7565_SendCommand(hdisp, CMD_SET_ALLPTS_NORMAL);
ST7565_SendCommand(hdisp, CMD_SET_VOLUME_FIRST);
ST7565_SendCommand(hdisp, CMD_SET_VOLUME_SECOND | (0x00 & 0x3f));
HAL_GPIO_WritePin(hdisp->cs_port, hdisp->cs_pin, GPIO_PIN_SET);
}
void ST7565_DisplayAll(st7565_handle_t *hdisp)
{
HAL_GPIO_WritePin(hdisp->cs_port, hdisp->cs_pin, GPIO_PIN_RESET);
for (uint8_t p = 0; p < 8; p++)
{
ST7565_SendCommand(hdisp, CMD_SET_PAGE | p);
ST7565_SendCommand(hdisp, CMD_SET_COLUMN_UPPER | 0);
ST7565_SendCommand(hdisp, CMD_SET_COLUMN_LOWER | 0);
ST7565_SendData(hdisp, &st7565_buffor[128 * p], 128);
}
HAL_GPIO_WritePin(hdisp->cs_port, hdisp->cs_pin, GPIO_PIN_SET);
}

View File

@@ -0,0 +1,61 @@
#pragma once
#include "spi.h"
#include "display_gfx.h"
#define ST7565_WIDTH 128
#define ST7565_HEIGHT 64
#define ST7565_BUFFER_SIZE ST7565_WIDTH *ST7565_HEIGHT / 8
#define CMD_DISPLAY_OFF 0xAE
#define CMD_DISPLAY_ON 0xAF
#define CMD_SET_DISP_START_LINE 0x40
#define CMD_SET_PAGE 0xB0
#define CMD_SET_COLUMN_UPPER 0x10
#define CMD_SET_COLUMN_LOWER 0x00
#define CMD_SET_ADC_NORMAL 0xA0
#define CMD_SET_ADC_REVERSE 0xA1
#define CMD_SET_DISP_NORMAL 0xA6
#define CMD_SET_DISP_REVERSE 0xA7
#define CMD_SET_ALLPTS_NORMAL 0xA4
#define CMD_SET_ALLPTS_ON 0xA5
#define CMD_SET_BIAS_9 0xA2
#define CMD_SET_BIAS_7 0xA3
#define CMD_RMW 0xE0
#define CMD_RMW_CLEAR 0xEE
#define CMD_INTERNAL_RESET 0xE2
#define CMD_SET_COM_NORMAL 0xC0
#define CMD_SET_COM_REVERSE 0xC8
#define CMD_SET_POWER_CONTROL 0x28
#define CMD_SET_RESISTOR_RATIO 0x20
#define CMD_SET_VOLUME_FIRST 0x81
#define CMD_SET_VOLUME_SECOND 0
#define CMD_SET_STATIC_OFF 0xAC
#define CMD_SET_STATIC_ON 0xAD
#define CMD_SET_STATIC_REG 0x0
#define CMD_SET_BOOSTER_FIRST 0xF8
#define CMD_SET_BOOSTER_234 0
#define CMD_SET_BOOSTER_5 1
#define CMD_SET_BOOSTER_6 3
#define CMD_NOP 0xE3
#define CMD_TEST 0xF0
typedef struct
{
SPI_HandleTypeDef *hspi;
GPIO_TypeDef *cs_port; // ST7565_CS_GPIO_Port
GPIO_TypeDef *a0_port; // ST7565_A0_GPIO_Port
GPIO_TypeDef *rst_port; // ST7565_RST_GPIO_Port
uint16_t cs_pin; // ST7565_CS_Pin
uint16_t a0_pin; // ST7565_A0_Pin
uint16_t rst_pin; // ST7565_RST_Pin
} st7565_handle_t;
void ST7565_Init(st7565_handle_t *hdisp, GFX_display_t *disp);
void ST7565_DisplayAll(st7565_handle_t *hdisp);