74 lines
2.2 KiB
C
74 lines
2.2 KiB
C
#include "stm32f4xx_hal.h"
|
|
#include "main.h"
|
|
#include "ILI9341.h"
|
|
|
|
#include <inttypes.h>
|
|
#include <string.h>
|
|
#include <stdarg.h>
|
|
|
|
#define LCD_W 320
|
|
#define LCD_H 240
|
|
|
|
void ili9341_cmd_write(uint16_t cmd, uint16_t cnt, ...)
|
|
{
|
|
va_list argp;
|
|
va_start(argp, cnt);
|
|
|
|
LCD_REG = cmd;
|
|
for(uint16_t n = 0; n < cnt; ++n) {
|
|
LCD_RAM = (uint16_t) va_arg(argp, uint32_t);
|
|
}
|
|
va_end(argp);
|
|
}
|
|
|
|
void ili9341_cmd_read(uint16_t cmd, uint16_t cnt, uint16_t *results)
|
|
{
|
|
LCD_REG = cmd;
|
|
for(uint16_t n = 0; n < cnt; ++n) {
|
|
*results++ = LCD_RAM;
|
|
}
|
|
}
|
|
|
|
void ili9341_init(void)
|
|
{
|
|
// volatile uint16_t id[5];
|
|
|
|
LCD_REG = ILI9341_RESET;
|
|
HAL_Delay(10);
|
|
LCD_REG = ILI9341_DISPLAY_OFF;
|
|
ili9341_cmd_write(ILI9341_POWERA, 5, 0x39, 0x2C, 0x00, 0x34, 0x02);
|
|
ili9341_cmd_write(ILI9341_POWERB, 3, 0x00, 0xC1, 0x30);
|
|
ili9341_cmd_write(ILI9341_DTCA, 3, 0x85, 0x00, 0x78);
|
|
ili9341_cmd_write(ILI9341_DTCB, 2, 0x00, 0x00);
|
|
ili9341_cmd_write(ILI9341_POWER_SEQ, 4, 0x64, 0x03, 0x12, 0x81);
|
|
ili9341_cmd_write(ILI9341_PRC, 1, 0x20);
|
|
ili9341_cmd_write(ILI9341_POWER1, 1, 0x23);
|
|
ili9341_cmd_write(ILI9341_POWER2, 1, 0x10);
|
|
ili9341_cmd_write(ILI9341_VCOM1, 2, 0x3E, 0x28);
|
|
ili9341_cmd_write(ILI9341_VCOM2, 1, 0x86);
|
|
ili9341_cmd_write(ILI9341_MAC, 1, 0xe8);
|
|
ili9341_cmd_write(ILI9341_PIXEL_FORMAT, 1, 0x55);
|
|
ili9341_cmd_write(ILI9341_FRC, 2, 0x00, 0x18);
|
|
ili9341_cmd_write(ILI9341_DFC, 3, 0x08, 0x82, 0x27);
|
|
ili9341_cmd_write(ILI9341_3GAMMA_EN, 1, 0x00);
|
|
ili9341_cmd_write(ILI9341_COLUMN_ADDR, 4, 0x00, 0x00, 0x01, 0x3F);
|
|
ili9341_cmd_write(ILI9341_PAGE_ADDR, 4, 0x00, 0x00, 0x00, 0xEF);
|
|
ili9341_cmd_write(ILI9341_GAMMA, 1, 0x01);
|
|
ili9341_cmd_write(ILI9341_PGAMMA, 15, 0x0F, 0x31, 0x2B, 0x0C, 0x0E, 0x08, 0x4E, 0xF1, 0x37, 0x07, 0x10, 0x03, 0x0E, 0x09, 0x00);
|
|
ili9341_cmd_write(ILI9341_NGAMMA, 15, 0x00, 0x0E, 0x14, 0x03, 0x11, 0x07, 0x31, 0xC1, 0x48, 0x08, 0x0F, 0x0C, 0x31, 0x36, 0x0F);
|
|
LCD_REG = ILI9341_SLEEP_OUT;
|
|
HAL_Delay(100);
|
|
LCD_REG = ILI9341_DISPLAY_ON;
|
|
|
|
LCD_REG = ILI9341_GRAM;
|
|
uint16_t fillers[4] = { 0xf800, 0x7e0, 0x1f, 0xffff };
|
|
for(uint32_t y = 0; y < LCD_H; ++y) {
|
|
uint32_t x;
|
|
for(x = 0; x < LCD_W / 2; ++x) {
|
|
LCD_RAM = fillers[ (x&0x18) >> 3 ];
|
|
}
|
|
for( ; x < LCD_W; ++x) {
|
|
LCD_RAM = 0;
|
|
}
|
|
}
|
|
}
|