Added LCD test code.
This commit is contained in:
parent
8c1c6a79e1
commit
891d7987a0
|
@ -0,0 +1,28 @@
|
|||
#ifndef __ST7302_LCD_H
|
||||
#define __ST7302_LCD_H
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
#define ST7302_PANEL_SELECTION st7302_gd_unknown_init_sequence
|
||||
|
||||
typedef enum {
|
||||
ST7302_OK,
|
||||
ST7302_ERROR
|
||||
} st7302_ret_t;
|
||||
|
||||
typedef struct {
|
||||
st7302_ret_t (*reset_cb)(void *handle);
|
||||
st7302_ret_t (*write_cmd_cb)(void *handle, uint8_t *cmd, uint8_t len);
|
||||
st7302_ret_t (*write_data_cb)(void *handle, uint8_t *data, uint16_t len);
|
||||
} st7302_cb_t;
|
||||
|
||||
typedef struct {
|
||||
void *user_data;
|
||||
st7302_cb_t cb;
|
||||
} st7302_t;
|
||||
|
||||
#define ST7302_ERROR_CHECK(x) if(x != ST7302_OK) return ST7302_ERROR
|
||||
|
||||
st7302_ret_t st7302_init(st7302_t *lcd);
|
||||
|
||||
#endif
|
|
@ -23,6 +23,8 @@
|
|||
/* Private includes ----------------------------------------------------------*/
|
||||
/* USER CODE BEGIN Includes */
|
||||
|
||||
#include "st7302_lcd.h"
|
||||
|
||||
/* USER CODE END Includes */
|
||||
|
||||
/* Private typedef -----------------------------------------------------------*/
|
||||
|
@ -65,6 +67,28 @@ static void MX_SPI1_Init(void);
|
|||
/* Private user code ---------------------------------------------------------*/
|
||||
/* USER CODE BEGIN 0 */
|
||||
|
||||
st7302_ret_t _lcd_write_cmd(void *handle, uint8_t *command, uint8_t len) {
|
||||
HAL_GPIO_WritePin(SPI1_A0_GPIO_Port, SPI1_A0_Pin, GPIO_PIN_RESET);
|
||||
if(HAL_SPI_Transmit(&hspi1, command, 0x01, 1000) != HAL_OK) {
|
||||
return ST7302_ERROR;
|
||||
}
|
||||
if(len > 1) {
|
||||
HAL_GPIO_WritePin(SPI1_A0_GPIO_Port, SPI1_A0_Pin, GPIO_PIN_SET);
|
||||
if(HAL_SPI_Transmit(&hspi1, &command[1], len - 1, 1000) != HAL_OK) {
|
||||
return ST7302_ERROR;
|
||||
}
|
||||
}
|
||||
return ST7302_OK;
|
||||
}
|
||||
|
||||
st7302_ret_t _lcd_write_data(void *handle, uint8_t *data, uint16_t len) {
|
||||
HAL_GPIO_WritePin(SPI1_A0_GPIO_Port, SPI1_A0_Pin, GPIO_PIN_SET);
|
||||
if(HAL_SPI_Transmit(&hspi1, data, len, 1000) != HAL_OK) {
|
||||
return ST7302_ERROR;
|
||||
}
|
||||
return ST7302_OK;
|
||||
}
|
||||
|
||||
/* USER CODE END 0 */
|
||||
|
||||
/**
|
||||
|
@ -112,6 +136,18 @@ int main(void)
|
|||
MX_SPI1_Init();
|
||||
/* USER CODE BEGIN 2 */
|
||||
|
||||
HAL_GPIO_WritePin(SPI1_RST_GPIO_Port, SPI1_RST_Pin, GPIO_PIN_SET);
|
||||
|
||||
st7302_t lcd = {
|
||||
.cb = {
|
||||
.write_cmd_cb = _lcd_write_cmd,
|
||||
.write_data_cb = _lcd_write_data
|
||||
},
|
||||
.user_data = &hspi1
|
||||
};
|
||||
|
||||
st7302_init(&lcd);
|
||||
|
||||
/* USER CODE END 2 */
|
||||
|
||||
/* Infinite loop */
|
||||
|
|
|
@ -0,0 +1,45 @@
|
|||
#include "st7302_lcd.h"
|
||||
|
||||
#include "stm32h7xx_hal.h"
|
||||
|
||||
uint8_t st7302_gd_unknown_init_sequence[] = {
|
||||
0x01, 0xEB, 0x02, // Enable OTP
|
||||
0x01, 0xD7, 0x68, // OTP Load Control
|
||||
0x01, 0xD1, 0x01, // Auto Power Control
|
||||
0x01, 0xC0, 0x40, // Gate Voltage setting
|
||||
0x06, 0xC1, 0x22, 0x22, 0x22, 0x22, 0x14, 0x00, // VSH Setting
|
||||
0x04, 0xC2, 0x00, 0x00, 0x00, 0x00, // VSL Setting
|
||||
0x01, 0xCB, 0x0E, // VCOMH Setting
|
||||
0x0A, 0xB4, 0xE5, 0x66, 0x85, 0xFF, 0xFF, 0x52, 0x85, 0xFF, 0xFF, 0x52, // Gate EQ
|
||||
0x02, 0xC7, 0xA6, 0xE9, // OSC Setting
|
||||
0x01, 0xB0, 0x3F, // Duty Setting
|
||||
0x01, 0x36, 0x00, // Memory Access Mode
|
||||
0x01, 0x3A, 0x11, // Data Format
|
||||
0x01, 0xB9, 0x23, // Source Setting
|
||||
0x01, 0xB8, 0x09, // Source Setting
|
||||
0x02, 0x2A, 0x19, 0x23, // Column Address Setting
|
||||
0x02, 0x2B, 0x00, 0x7C, // Row Address Setting
|
||||
};
|
||||
|
||||
st7302_ret_t _st7302_init_seq(st7302_t *lcd) {
|
||||
uint16_t i = 0;
|
||||
|
||||
while(i < sizeof(ST7302_PANEL_SELECTION)) {
|
||||
ST7302_ERROR_CHECK(lcd->cb.write_cmd_cb(lcd->user_data, &ST7302_PANEL_SELECTION[i + 1], ST7302_PANEL_SELECTION[i] + 1));
|
||||
i += ST7302_PANEL_SELECTION[i] + 2;
|
||||
}
|
||||
|
||||
return ST7302_OK;
|
||||
}
|
||||
|
||||
st7302_ret_t st7302_init(st7302_t *lcd) {
|
||||
ST7302_ERROR_CHECK(_st7302_init_seq(lcd));
|
||||
uint8_t command[3] = {0xB2, 0x01, 0x05};
|
||||
command[0] = 0x11;
|
||||
ST7302_ERROR_CHECK(lcd->cb.write_cmd_cb(lcd->user_data, command, 0x01)); // Sleep Out
|
||||
HAL_Delay(100);
|
||||
command[0] = 0x29;
|
||||
ST7302_ERROR_CHECK(lcd->cb.write_cmd_cb(lcd->user_data, command, 0x01)); // Display ON
|
||||
|
||||
return ST7302_OK;
|
||||
}
|
1
Makefile
1
Makefile
|
@ -39,6 +39,7 @@ C_SOURCES = \
|
|||
Core/Src/main.c \
|
||||
Core/Src/stm32h7xx_it.c \
|
||||
Core/Src/stm32h7xx_hal_msp.c \
|
||||
Core/Src/st7302_lcd.c \
|
||||
Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_cortex.c \
|
||||
Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_qspi.c \
|
||||
Drivers/STM32H7xx_HAL_Driver/Src/stm32h7xx_hal_rcc.c \
|
||||
|
|
Loading…
Reference in New Issue