[fix] driver: st7565
added controller class instead of constants
This commit is contained in:
@@ -77,6 +77,8 @@ C_SOURCES += ../shared_libs/drivers/mcp41x/mcp41x.c
|
||||
C_SOURCES += ../shared_libs/drivers/st7565/st7565.c
|
||||
# hw_button
|
||||
C_SOURCES += ../shared_libs/drivers/hw_button/hw_button.c
|
||||
# display
|
||||
C_SOURCES += ../shared_libs/display/display_gfx.c
|
||||
|
||||
# ASM sources
|
||||
ASM_SOURCES = \
|
||||
@@ -149,6 +151,8 @@ C_INCLUDES += -I../shared_libs/drivers/mcp41x
|
||||
C_INCLUDES += -I../shared_libs/drivers/st7565
|
||||
# hw_button includes
|
||||
C_INCLUDES += -I../shared_libs/drivers/hw_button
|
||||
# display includes
|
||||
C_INCLUDES += -I../shared_libs/display
|
||||
|
||||
# compile gcc flags
|
||||
ASFLAGS = $(MCU) $(AS_DEFS) $(AS_INCLUDES) $(OPT) -Wall -fdata-sections -ffunction-sections
|
||||
|
||||
@@ -4,87 +4,84 @@
|
||||
// #include "spi.h"
|
||||
#include "string.h"
|
||||
|
||||
uint8_t st7565_buffor[ST7565_BUFFER_SIZE];
|
||||
static uint8_t st7565_buffor[ST7565_BUFFER_SIZE];
|
||||
|
||||
void ST7565_SendCommand(uint8_t data)
|
||||
static void ST7565_SendCommand(st7565_handle_t *hdisp, uint8_t data)
|
||||
{
|
||||
HAL_GPIO_WritePin(ST7565_A0_GPIO_Port, ST7565_A0_Pin, GPIO_PIN_RESET);
|
||||
HAL_GPIO_WritePin(hdisp->a0_port, hdisp->a0_pin, GPIO_PIN_RESET);
|
||||
|
||||
HAL_SPI_Transmit(&hspi3, &data, 1, HAL_MAX_DELAY);
|
||||
HAL_SPI_Transmit(hdisp->hspi, &data, 1, HAL_MAX_DELAY);
|
||||
}
|
||||
|
||||
void ST7565_SendData(uint8_t *data, uint16_t size)
|
||||
static void ST7565_SendData(st7565_handle_t *hdisp, uint8_t *data, uint16_t size)
|
||||
{
|
||||
HAL_GPIO_WritePin(ST7565_A0_GPIO_Port, ST7565_A0_Pin, GPIO_PIN_SET);
|
||||
HAL_GPIO_WritePin(hdisp->a0_port, hdisp->a0_pin, GPIO_PIN_SET);
|
||||
|
||||
HAL_SPI_Transmit(&hspi3, data, size, HAL_MAX_DELAY);
|
||||
HAL_SPI_Transmit(hdisp->hspi, data, size, HAL_MAX_DELAY);
|
||||
}
|
||||
|
||||
void ST7565_Init(GFX_display_t *disp)
|
||||
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(ST7565_CS_GPIO_Port, ST7565_CS_Pin, GPIO_PIN_RESET);
|
||||
HAL_GPIO_WritePin(hdisp->cs_port, hdisp->cs_pin, GPIO_PIN_RESET);
|
||||
|
||||
HAL_GPIO_WritePin(ST7565_RST_GPIO_Port, ST7565_RST_Pin, GPIO_PIN_RESET);
|
||||
HAL_GPIO_WritePin(hdisp->rst_port, hdisp->rst_pin, GPIO_PIN_RESET);
|
||||
HAL_Delay(500);
|
||||
HAL_GPIO_WritePin(ST7565_RST_GPIO_Port, ST7565_RST_Pin, GPIO_PIN_SET);
|
||||
HAL_GPIO_WritePin(hdisp->rst_port, hdisp->rst_pin, GPIO_PIN_SET);
|
||||
|
||||
// LCD bias select
|
||||
ST7565_SendCommand(CMD_SET_BIAS_7);
|
||||
ST7565_SendCommand(hdisp, CMD_SET_BIAS_7);
|
||||
// ADC select
|
||||
ST7565_SendCommand(CMD_SET_ADC_REVERSE);
|
||||
ST7565_SendCommand(hdisp, CMD_SET_ADC_REVERSE);
|
||||
// SHL select
|
||||
ST7565_SendCommand(CMD_SET_COM_NORMAL);
|
||||
ST7565_SendCommand(hdisp, CMD_SET_COM_NORMAL);
|
||||
// Initial display line
|
||||
ST7565_SendCommand(CMD_SET_DISP_START_LINE);
|
||||
ST7565_SendCommand(hdisp, CMD_SET_DISP_START_LINE);
|
||||
|
||||
// turn on voltage converter (VC=1, VR=0, VF=0)
|
||||
ST7565_SendCommand(CMD_SET_POWER_CONTROL | 0x4);
|
||||
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(CMD_SET_POWER_CONTROL | 0x6);
|
||||
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(CMD_SET_POWER_CONTROL | 0x7);
|
||||
ST7565_SendCommand(hdisp, 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(hdisp, 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));
|
||||
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));
|
||||
|
||||
// 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);
|
||||
HAL_GPIO_WritePin(hdisp->cs_port, hdisp->cs_pin, GPIO_PIN_SET);
|
||||
}
|
||||
|
||||
void ST7565_DisplayAll(void)
|
||||
void ST7565_DisplayAll(st7565_handle_t *hdisp)
|
||||
{
|
||||
HAL_GPIO_WritePin(ST7565_CS_GPIO_Port, ST7565_CS_Pin, GPIO_PIN_RESET);
|
||||
HAL_GPIO_WritePin(hdisp->cs_port, hdisp->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_SendCommand(hdisp, CMD_SET_PAGE | p);
|
||||
ST7565_SendCommand(hdisp, CMD_SET_COLUMN_UPPER | 0);
|
||||
ST7565_SendCommand(hdisp, CMD_SET_COLUMN_LOWER | 0);
|
||||
|
||||
ST7565_SendData(&st7565_buffor[128 * p], 128);
|
||||
ST7565_SendData(hdisp, &st7565_buffor[128 * p], 128);
|
||||
}
|
||||
HAL_GPIO_WritePin(ST7565_CS_GPIO_Port, ST7565_CS_Pin, GPIO_PIN_SET);
|
||||
HAL_GPIO_WritePin(hdisp->cs_port, hdisp->cs_pin, GPIO_PIN_SET);
|
||||
}
|
||||
|
||||
@@ -43,5 +43,16 @@
|
||||
#define CMD_NOP 0xE3
|
||||
#define CMD_TEST 0xF0
|
||||
|
||||
void ST7565_Init(GFX_display_t *disp);
|
||||
void ST7565_DisplayAll(void);
|
||||
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);
|
||||
|
||||
Reference in New Issue
Block a user