ESP8266 ILI9341 display support code with printf sources, wire-frame viewer and custom fonts  1.0
ESP8266ILI9341DisplayProject
ili9341_hal.c
Go to the documentation of this file.
1 
23 #include "user_config.h"
24 
25 #include <stdint.h>
26 #include <stdarg.h>
27 #include <string.h>
28 #include <math.h>
29 
30 #include "display/ili9341.h"
31 
32 // TFT master window definition
33 extern window tftwin;
34 extern window *tft;
35 
40 
43 
45 
46 #ifdef ESP8266
47 #ifndef ILI9341_CS
48 #error ILI9341_CS is undefined
49 #endif
50 #define tft_delay_us(a) os_delay_us(a)
51 
52 #ifndef ADDR_0
53 #error ADDR_0 is undefined
54 #endif
55 
56 #define TFT_DATA chip_addr(1)
57 #define TFT_COMMAND chip_addr(0)
58 
59 #endif
60 
65 {
66  tft_clock = 2;
67  chip_select_init(ILI9341_CS);
68 }
69 
73 {
74  tft_clock = 1;
75  chip_select_init(ILI9341_CS);
76 }
77 
81 {
82  spi_begin(tft_clock, ILI9341_CS);
83 }
84 
88 {
89  spi_end(ILI9341_CS);
90 }
91 
95 {
96 #ifdef ILI9341_RESET
97  chip_select_init(ILI9341_RESET);
98 #endif
99 }
100 
104 {
105 #ifdef ILI9341_RESET
106  chip_enable(ILI9341_RESET);
107 #endif
108 }
109 
113 {
114  chip_addr_init();
115 }
116 
117 
121 {
122 #ifdef ILI9341_RESET
123  chip_disable(ILI9341_RESET);
124 #endif
125 }
126 
127 
128 
134 void tft_spi_TX(uint8_t *data, int bytes, uint8_t command)
135 {
136  spi_waitReady();
137  if(command)
138  TFT_COMMAND;
139  else
140  TFT_DATA;
141  spi_TX_buffer(data,bytes);
142 }
143 
149 void tft_spi_TXRX(uint8_t * data, int bytes, uint8_t command)
150 {
151  spi_waitReady();
152  if(command)
153  TFT_COMMAND;
154  else
155  TFT_DATA;
156  spi_TXRX_buffer(data,bytes);
157 }
158 
159 
165 void tft_spi_RX(uint8_t *data, int bytes, uint8_t command)
166 {
167  spi_waitReady();
168  if(command)
169  TFT_COMMAND;
170  else
171  TFT_DATA;
172  spi_RX_buffer(data,bytes);
173 }
174 
177 MEMSPACE
179 {
180  // Start with slow clock so tft_readId works
181  // This is the only function that fails at less then 1.
182  // tft_readId is the ONLY SPI bus command that needs this.
183  // Nomal reads work fine.
184  tft_addr_init();
186 
187  // reset display
188  tft_reset_init();
190  tft_delay_us(10000);
192  tft_delay_us(1000);
193 
194  /* Adafruit 9341 TFT Display Initialization */
196 
197  /* Read the TFT ID value */
198  tft_ID = tft_readId();
199 
200  // fast SPI
202 
203  /* Setup the master window */
205  tft_setRotation(0);
206  tft_fillWin(tft, tft->bg);
207 
208  return (tft);
209 }
210 
MEMSPACE void tft_setRotation(uint8_t m)
Set Display rotation, applies to the master window only Set hardware display rotation and memory fill...
Definition: ili9341.c:982
#define TFT_YOFF
Definition: ili9341.h:86
void tft_reset_disable()
disnable ILI9341 reset return: void
Definition: ili9341_hal.c:120
unsigned short uint16_t
Definition: send.c:18
void spi_begin(uint32_t clock, int pin)
SPI chip enable function Function waits for current tranaction to finish before proceeding.
Definition: hal.c:355
Master include file for project Includes all project includes and defines here.
uint16_t bg
Definition: ili9341.h:45
void tft_spi_TX(uint8_t *data, int bytes, uint8_t command)
Transmit 8 bit data array.
Definition: ili9341_hal.c:134
MEMSPACE void tft_configRegister(void)
Initialize ILI9341 display.
unsigned int uint32_t
Definition: send.c:19
void spi_waitReady()
SPI bus wrapper functions for multiple device support.
Definition: hal.c:306
void tft_addr_init()
Initialize ILI9341 command/data GPIO return: void.
Definition: ili9341_hal.c:112
uint16_t tft_ID
Definition: ili9341_hal.c:44
void tft_reset_enable()
enable ILI9341 reset return: void
Definition: ili9341_hal.c:103
void spi_end(uint8_t pin)
SPI chip disable function wait for current tranaction to finish!
Definition: hal.c:388
void chip_select_init(uint8_t pin)
CHIP select HAL.
Definition: hal.c:198
#define TFT_XOFF
Definition: ili9341.h:85
window tftwin
Definition: ili9341.c:44
void tft_spi_begin()
Obtain SPI bus for TFT display, assert chip select return: void.
Definition: ili9341_hal.c:80
void spi_TXRX_buffer(const uint8_t *data, int count)
SPI write/read buffer.
Definition: hal.c:442
void spi_RX_buffer(const uint8_t *data, int count)
SPI read buffer.
Definition: hal.c:428
void tft_spi_init_slow()
Initialize TFT SPI clock speed and pin for slow speed Only used to read the CHIP ID return: void...
Definition: ili9341_hal.c:64
void tft_spi_end()
Release SPI bus from TFT display, deassert chip select return: void.
Definition: ili9341_hal.c:87
#define MEMSPACE
Definition: cpu.h:25
window * tft
Definition: ili9341.c:45
void tft_fillWin(window *win, uint16_t color)
Fill functions
Definition: ili9341.c:334
uint32_t tft_clock
cahce of SPI clock devisor
Definition: ili9341_hal.c:42
Definition: ili9341.h:34
MEMSPACE uint32_t tft_readId(void)
Read ILI9341 device ID should be 9341 This does not work for really high SPI clock speeds Make sure t...
Definition: ili9341.c:206
ili9341 driver inspired by Adafruit ili9341 code All code in this file has been rewritten by Mike Gor...
void chip_addr_init()
ADDRESS select HAL.
Definition: hal.c:242
void spi_TX_buffer(const uint8_t *data, int count)
SPI write buffer.
Definition: hal.c:414
unsigned char uint8_t
Definition: send.c:17
#define TFT_W
Definition: ili9341.h:83
void tft_spi_TXRX(uint8_t *data, int bytes, uint8_t command)
Transmit and read 8 bit data array.
Definition: ili9341_hal.c:149
#define TFT_H
Definition: ili9341.h:84
void tft_spi_RX(uint8_t *data, int bytes, uint8_t command)
read 8 bit data array
Definition: ili9341_hal.c:165
MEMSPACE window * tft_init(void)
Initialize TFT.
Definition: ili9341_hal.c:178
MEMSPACE void tft_window_init(window *win, int16_t x, int16_t y, int16_t w, int16_t h)
Initialize window structure we default values FIXME check x+w, y+h absolute limits against TFT limuts...
Definition: ili9341.c:1198
void tft_reset_init()
Initialize ILI9341 reset GPIO return: void.
Definition: ili9341_hal.c:94
void tft_spi_init_fast()
Initialize TFT SPI clock speed and pin for normal speed return: void.
Definition: ili9341_hal.c:72