diff --git a/.cproject b/.cproject index c4c14c7..950dd39 100644 --- a/.cproject +++ b/.cproject @@ -16,34 +16,35 @@ - - - + + + @@ -114,33 +117,34 @@ - - - + + + @@ -200,7 +206,14 @@ - + + + + + + + + diff --git a/App/ILI9341.c b/App/ILI9341.c new file mode 100644 index 0000000..b7ce438 --- /dev/null +++ b/App/ILI9341.c @@ -0,0 +1,74 @@ +#include "stm32f4xx_hal.h" +#include "main.h" +#include "ILI9341.h" + +#include +#include +#include + +#define LCD_W 240 +#define LCD_H 320 + +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, 0x48); + 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, 0x00, 0xEF); + ili9341_cmd_write(ILI9341_PAGE_ADDR, 4, 0x00, 0x00, 0x01, 0x3F); + 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; + } + } +} diff --git a/App/ILI9341.h b/App/ILI9341.h new file mode 100644 index 0000000..052cfab --- /dev/null +++ b/App/ILI9341.h @@ -0,0 +1,120 @@ +#ifndef __ili9341_H +#define __ili9341_H +#ifdef __cplusplus + extern "C" { +#endif + +#define LCD_REG (*((volatile unsigned short *) 0x60000000)) /* DC = 0 */ +#define LCD_RAM (*((volatile unsigned short *) 0x60080000)) /* DC = 1 */ + +/* Includes ------------------------------------------------------------------*/ + +#define ILI9341_NOP 0x00 +#define ILI9341_RESET 0x01 +#define ILI9341_READ_DISPLAY_IDENTIFICATION_INFORMATION 0x04 +#define ILI9341_READ_DISPLAY_STATUS 0x09 +#define ILI9341_READ_DISPLAY_POWER_MODE 0x0A +#define ILI9341_READ_DISPLAY_MADCTL 0x0B +#define ILI9341_READ_DISPLAY_PIXEL_FORMAT 0x0C +#define ILI9341_READ_DISPLAY_IMAGE_FORMAT 0x0D +#define ILI9341_READ_DISPLAY_SIGNAL_MODE 0x0E +#define ILI9341_READ_DISPLAY_SELF_DIAGNOSTIC_RESULT 0x0F +#define ILI9341_ENTER_SLEEP_MODE 0x10 +#define ILI9341_SLEEP_OUT 0x11 +#define ILI9341_PARTIAL_MODE_ON 0x12 +#define ILI9341_NORMAL_DISPLAY_MODE_ON 0x13 +#define ILI9341_DISPLAY_INVERSION_OFF 0x20 +#define ILI9341_DISPLAY_INVERSION_ON 0x21 +#define ILI9341_GAMMA 0x26 +#define ILI9341_DISPLAY_OFF 0x28 +#define ILI9341_DISPLAY_ON 0x29 +#define ILI9341_COLUMN_ADDR 0x2A +#define ILI9341_PAGE_ADDR 0x2B +#define ILI9341_GRAM 0x2C +#define ILI9341_COLOR_SET 0x2D +#define ILI9341_MEMORY_READ 0x2E +#define ILI9341_PARTIAL_AREA 0x30 +#define ILI9341_VERTICAL_SCROLLING_DEFINITION 0x33 +#define ILI9341_TEARING_EFFECT_LINE_OFF 0x34 +#define ILI9341_TEARING_EFFECT_LINE_ON 0x35 +#define ILI9341_MAC 0x36 +#define ILI9341_VERTICAL_SCROLLING_START_ADDRESS 0x37 +#define ILI9341_IDLE_MODE_OFF 0x38 +#define ILI9341_IDLE_MODE_ON 0x39 +#define ILI9341_PIXEL_FORMAT 0x3A +#define ILI9341_WMC 0x3C +#define ILI9341_RMC 0x3E +#define ILI9341_SET_TEAR_SCANLINE 0x44 +#define ILI9341_WDB 0x51 +#define ILI9341_READ_DISPLAY_BRIGHTNESS 0x52 +#define ILI9341_WCD 0x53 +#define ILI9341_READ_CTRL_DISPLAY 0x54 +#define ILI9341_WCABC 0x55 +#define ILI9341_RCABC 0x56 +#define ILI9341_WCABCMB 0x5E +#define ILI9341_RCABCMB 0x5F +#define ILI9341_RGB_INTERFACE 0xB0 +#define ILI9341_FRC 0xB1 +#define ILI9341_FRAME_CTRL_NM 0xB2 +#define ILI9341_FRAME_CTRL_IM 0xB3 +#define ILI9341_FRAME_CTRL_PM 0xB4 +#define ILI9341_BPC 0xB5 +#define ILI9341_DFC 0xB6 +#define ILI9341_ENTRY_MODE_SET 0xB7 +#define ILI9341_BACKLIGHT_CONTROL_1 0xB8 +#define ILI9341_BACKLIGHT_CONTROL_2 0xB9 +#define ILI9341_BACKLIGHT_CONTROL_3 0xBA +#define ILI9341_BACKLIGHT_CONTROL_4 0xBB +#define ILI9341_BACKLIGHT_CONTROL_5 0xBC +#define ILI9341_BACKLIGHT_CONTROL_6 0xBD +#define ILI9341_BACKLIGHT_CONTROL_7 0xBE +#define ILI9341_BACKLIGHT_CONTROL_8 0xBF +#define ILI9341_POWER1 0xC0 +#define ILI9341_POWER2 0xC1 +#define ILI9341_VCOM1 0xC5 +#define ILI9341_VCOM2 0xC7 +#define ILI9341_POWERA 0xCB +#define ILI9341_POWERB 0xCF +#define ILI9341_READ_ID1 0xDA +#define ILI9341_READ_ID2 0xDB +#define ILI9341_READ_ID3 0xDC +#define ILI9341_PGAMMA 0xE0 +#define ILI9341_NGAMMA 0xE1 +#define ILI9341_DTCA 0xE8 +#define ILI9341_DTCB 0xEA +#define ILI9341_POWER_SEQ 0xED +#define ILI9341_3GAMMA_EN 0xF2 +#define ILI9341_INTERFACE 0xF6 +#define ILI9341_PRC 0xF7 + + +// Color definitions +#define ILI9341_BLACK 0x0000 /* 0, 0, 0 */ +#define ILI9341_NAVY 0x000F /* 0, 0, 128 */ +#define ILI9341_DARKGREEN 0x03E0 /* 0, 128, 0 */ +#define ILI9341_DARKCYAN 0x03EF /* 0, 128, 128 */ +#define ILI9341_MAROON 0x7800 /* 128, 0, 0 */ +#define ILI9341_PURPLE 0x780F /* 128, 0, 128 */ +#define ILI9341_OLIVE 0x7BE0 /* 128, 128, 0 */ +#define ILI9341_LIGHTGREY 0xC618 /* 192, 192, 192 */ +#define ILI9341_DARKGREY 0x7BEF /* 128, 128, 128 */ +#define ILI9341_BLUE 0x001F /* 0, 0, 255 */ +#define ILI9341_GREEN 0x07E0 /* 0, 255, 0 */ +#define ILI9341_CYAN 0x07FF /* 0, 255, 255 */ +#define ILI9341_RED 0xF800 /* 255, 0, 0 */ +#define ILI9341_MAGENTA 0xF81F /* 255, 0, 255 */ +#define ILI9341_YELLOW 0xFFE0 /* 255, 255, 0 */ +#define ILI9341_WHITE 0xFFFF /* 255, 255, 255 */ +#define ILI9341_ORANGE 0xFD20 /* 255, 165, 0 */ +#define ILI9341_GREENYELLOW 0xAFE5 /* 173, 255, 47 */ +#define ILI9341_PINK 0xF81F + +void ili9341_Reset(void); +void ili9341_writeData(char Data); +void ili9341_writeCommand(char Command); +void ili9341_init(void); + +#ifdef __cplusplus +} +#endif +#endif diff --git a/Src/main.c b/Src/main.c index 0dd4cf3..24d61d8 100644 --- a/Src/main.c +++ b/Src/main.c @@ -26,6 +26,7 @@ /* Private includes ----------------------------------------------------------*/ /* USER CODE BEGIN Includes */ +#include /* USER CODE END Includes */ @@ -93,6 +94,7 @@ int main(void) MX_USART1_UART_Init(); MX_FSMC_Init(); /* USER CODE BEGIN 2 */ + ili9341_init(); /* USER CODE END 2 */