91 lines
2.7 KiB
C
91 lines
2.7 KiB
C
#include "main.h"
|
|
#include "display_gfx.h"
|
|
#include "st7565.h"
|
|
// #include "spi.h"
|
|
#include "string.h"
|
|
|
|
uint8_t st7565_buffor[ST7565_BUFFER_SIZE];
|
|
|
|
void ST7565_SendCommand(uint8_t data)
|
|
{
|
|
HAL_GPIO_WritePin(ST7565_A0_GPIO_Port, ST7565_A0_Pin, GPIO_PIN_RESET);
|
|
|
|
HAL_SPI_Transmit(&hspi3, &data, 1, HAL_MAX_DELAY);
|
|
}
|
|
|
|
void ST7565_SendData(uint8_t *data, uint16_t size)
|
|
{
|
|
HAL_GPIO_WritePin(ST7565_A0_GPIO_Port, ST7565_A0_Pin, GPIO_PIN_SET);
|
|
|
|
HAL_SPI_Transmit(&hspi3, data, size, HAL_MAX_DELAY);
|
|
}
|
|
|
|
void ST7565_Init(GFX_display_t *disp)
|
|
{
|
|
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(ST7565_CS_GPIO_Port, ST7565_CS_Pin, GPIO_PIN_RESET);
|
|
|
|
HAL_GPIO_WritePin(ST7565_RST_GPIO_Port, ST7565_RST_Pin, GPIO_PIN_RESET);
|
|
HAL_Delay(500);
|
|
HAL_GPIO_WritePin(ST7565_RST_GPIO_Port, ST7565_RST_Pin, GPIO_PIN_SET);
|
|
|
|
// LCD bias select
|
|
ST7565_SendCommand(CMD_SET_BIAS_7);
|
|
// ADC select
|
|
ST7565_SendCommand(CMD_SET_ADC_REVERSE);
|
|
// SHL select
|
|
ST7565_SendCommand(CMD_SET_COM_NORMAL);
|
|
// Initial display line
|
|
ST7565_SendCommand(CMD_SET_DISP_START_LINE);
|
|
|
|
// turn on voltage converter (VC=1, VR=0, VF=0)
|
|
ST7565_SendCommand(CMD_SET_POWER_CONTROL | 0x4);
|
|
// wait for 50% rising
|
|
HAL_Delay(50);
|
|
|
|
// turn on voltage regulator (VC=1, VR=1, VF=0)
|
|
ST7565_SendCommand(CMD_SET_POWER_CONTROL | 0x6);
|
|
// wait >=50ms
|
|
HAL_Delay(50);
|
|
|
|
// turn on voltage follower (VC=1, VR=1, VF=1)
|
|
ST7565_SendCommand(CMD_SET_POWER_CONTROL | 0x7);
|
|
// wait
|
|
HAL_Delay(10);
|
|
|
|
// set lcd operating voltage (regulator resistor, ref voltage resistor)
|
|
ST7565_SendCommand(CMD_SET_RESISTOR_RATIO | 0x6);
|
|
|
|
ST7565_SendCommand(CMD_DISPLAY_ON);
|
|
ST7565_SendCommand(CMD_SET_ALLPTS_NORMAL);
|
|
ST7565_SendCommand(CMD_SET_VOLUME_FIRST);
|
|
ST7565_SendCommand(CMD_SET_VOLUME_SECOND | (0x00 & 0x3f));
|
|
|
|
// initial display line
|
|
// set page address
|
|
// set column address
|
|
// write display data
|
|
|
|
// set up a bounding box for screen updates
|
|
|
|
// updateBoundingBox(0, 0, LCDWIDTH - 1, LCDHEIGHT - 1);
|
|
HAL_GPIO_WritePin(ST7565_CS_GPIO_Port, ST7565_CS_Pin, GPIO_PIN_SET);
|
|
}
|
|
|
|
void ST7565_DisplayAll(void)
|
|
{
|
|
HAL_GPIO_WritePin(ST7565_CS_GPIO_Port, ST7565_CS_Pin, GPIO_PIN_RESET);
|
|
for (uint8_t p = 0; p < 8; p++)
|
|
{
|
|
ST7565_SendCommand(CMD_SET_PAGE | p);
|
|
ST7565_SendCommand(CMD_SET_COLUMN_UPPER | 0);
|
|
ST7565_SendCommand(CMD_SET_COLUMN_LOWER | 0);
|
|
|
|
ST7565_SendData(&st7565_buffor[128 * p], 128);
|
|
}
|
|
HAL_GPIO_WritePin(ST7565_CS_GPIO_Port, ST7565_CS_Pin, GPIO_PIN_SET);
|
|
}
|