1 #ifndef __ILI9341_H__ 2 #define __ILI9341_H__ 3 4 #include <stdbool.h> 5 #include <stdio.h> 6 7 #define ILI9341_HEIGHT 240 8 #define ILI9341_WIDTH 320 9 10 typedef struct _ili9341_dev_t { 11 int spi_port; 12 int spi_freq; 13 int gpio_dc_id; 14 int gpio_reset_id; 15 int gpio_bgl_id; 16 17 int spi_fd; 18 int gpio_fd; 19 } ili9341_dev_t; 20 21 // Set of commands described in ILI9341 datasheet. 22 #define ILI9341_NOP 0x00 23 #define ILI9341_SWRESET 0x01 24 #define ILI9341_RDDID 0x04 25 #define ILI9341_RDDST 0x09 26 27 #define ILI9341_SLPIN 0x10 28 #define ILI9341_SLPOUT 0x11 29 #define ILI9341_PTLON 0x12 30 #define ILI9341_NORON 0x13 31 32 #define ILI9341_RDMODE 0x0A 33 #define ILI9341_RDMADCTL 0x0B 34 #define ILI9341_RDPIXFMT 0x0C 35 #define ILI9341_RDIMGFMT 0x0D 36 #define ILI9341_RDSELFDIAG 0x0F 37 38 #define ILI9341_INVOFF 0x20 39 #define ILI9341_INVON 0x21 40 #define ILI9341_GAMMASET 0x26 41 #define ILI9341_DISPOFF 0x28 42 #define ILI9341_DISPON 0x29 43 44 #define ILI9341_CASET 0x2A 45 #define ILI9341_PASET 0x2B 46 #define ILI9341_RAMWR 0x2C 47 #define ILI9341_RAMRD 0x2E 48 49 #define ILI9341_PTLAR 0x30 50 #define ILI9341_MADCTL 0x36 51 #define ILI9341_PIXFMT 0x3A 52 53 #define ILI9341_FRMCTR1 0xB1 54 #define ILI9341_FRMCTR2 0xB2 55 #define ILI9341_FRMCTR3 0xB3 56 #define ILI9341_INVCTR 0xB4 57 #define ILI9341_DFUNCTR 0xB6 58 59 #define ILI9341_PWCTR1 0xC0 60 #define ILI9341_PWCTR2 0xC1 61 #define ILI9341_PWCTR3 0xC2 62 #define ILI9341_PWCTR4 0xC3 63 #define ILI9341_PWCTR5 0xC4 64 #define ILI9341_VMCTR1 0xC5 65 #define ILI9341_VMCTR2 0xC7 66 #define ILI9341_PWCTRSEQ 0xCB 67 #define ILI9341_PWCTRA 0xCD 68 #define ILI9341_PWCTRB 0xCF 69 70 #define ILI9341_RDID1 0xDA 71 #define ILI9341_RDID2 0xDB 72 #define ILI9341_RDID3 0xDC 73 #define ILI9341_RDID4 0xDD 74 75 #define ILI9341_GMCTRP1 0xE0 76 #define ILI9341_GMCTRN1 0xE1 77 #define ILI9341_DGMCTR1 0xE2 78 #define ILI9341_DGMCTR2 0xE3 79 #define ILI9341_TIMCTRA 0xE8 80 #define ILI9341_TIMCTRB 0xEA 81 82 #define ILI9341_ENGMCTR 0xF2 83 #define ILI9341_INCTR 0xF6 84 #define ILI9341_PUMP 0xF7 85 86 #define ILI9341_MADCTL_MY 0x80 87 #define ILI9341_MADCTL_MX 0x40 88 #define ILI9341_MADCTL_MV 0x20 89 #define ILI9341_MADCTL_ML 0x10 90 #define ILI9341_MADCTL_RGB 0x00 91 #define ILI9341_MADCTL_BGR 0x08 92 #define ILI9341_MADCTL_MH 0x04 93 94 int ili9341_hw_init(ili9341_dev_t *ili9341_dev); 95 static void ili9341_init_command(ili9341_dev_t ili9341_dev); 96 int ili9341_hw_uninit(ili9341_dev_t *ili9341_dev); 97 void ili9341_draw_pixel(ili9341_dev_t ili9341_dev, 98 uint16_t x, 99 uint16_t y, 100 uint16_t color); 101 void ili9341_draw_area(ili9341_dev_t ili9341_dev, 102 uint16_t x, 103 uint16_t y, 104 uint16_t width, 105 uint16_t height, 106 uint8_t *frame); 107 void ili9341_draw_rect(ili9341_dev_t ili9341_dev, 108 uint16_t x, 109 uint16_t y, 110 uint16_t width, 111 uint16_t height, 112 uint32_t color); 113 void ili9341_draw_frame(ili9341_dev_t ili9341_dev, uint8_t *frame); 114 void ili9341_set_rotation(ili9341_dev_t ili9341_dev, uint16_t rotation); 115 void ili9341_set_invert(ili9341_dev_t ili9341_dev, uint8_t invert); 116 void ili9341_enter_sleep(ili9341_dev_t ili9341_dev); 117 void ili9341_exit_sleep(ili9341_dev_t ili9341_dev); 118 119 #endif 120