eGUI alias D4D  Release 3.0
Reference Manual
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
d4dlcdhw_kinetis_spi.c
Go to the documentation of this file.
1 /**************************************************************************
2 *
3 * Copyright 2014 by Petr Gargulak. eGUI Community.
4 * Copyright 2009-2013 by Petr Gargulak. Freescale Semiconductor, Inc.
5 *
6 ***************************************************************************
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU Lesser General Public License Version 3
9 * or later (the "LGPL").
10 *
11 * As a special exception, the copyright holders of the eGUI project give you
12 * permission to link the eGUI sources with independent modules to produce an
13 * executable, regardless of the license terms of these independent modules,
14 * and to copy and distribute the resulting executable under terms of your
15 * choice, provided that you also meet, for each linked independent module,
16 * the terms and conditions of the license of that module.
17 * An independent module is a module which is not derived from or based
18 * on this library.
19 * If you modify the eGUI sources, you may extend this exception
20 * to your version of the eGUI sources, but you are not obligated
21 * to do so. If you do not wish to do so, delete this
22 * exception statement from your version.
23 *
24 * This program is distributed in the hope that it will be useful,
25 * but WITHOUT ANY WARRANTY; without even the implied warranty of
26 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
27 *
28 * You should have received a copy of the GNU General Public License
29 * and the GNU Lesser General Public License along with this program.
30 * If not, see <http://www.gnu.org/licenses/>.
31 *
32 ***************************************************************************/
46 #include "d4d.h" // include of all public items (types, function etc) of D4D driver
47 #include "common_files/d4d_lldapi.h" // include non public low level driver interface header file (types, function prototypes, enums etc. )
48 #include "common_files/d4d_private.h" // include the private header file that contains perprocessor macros as D4D_MK_STR
49 
50 
51 // identification string of driver - must be same as name D4DTCH_FUNCTIONS structure + "_ID"
52 // it is used for enable the code for compilation
53 #define d4dlcdhw_kinetis_spi_ID 1
54 
55 
56 // copilation enable preprocessor condition
57 // the string d4dtch_kinetis_spi_ID must be replaced by define created one line up
58 #if (D4D_MK_STR(D4D_LLD_LCD_HW) == d4dlcdhw_kinetis_spi_ID)
59 
60  // include of low level driver heaser file
61  // it will be included into wole project only in case that this driver is selected in main D4D configuration file
63  /******************************************************************************
64  * Macros
65  ******************************************************************************/
66  #if D4D_COLOR_SYSTEM != D4D_COLOR_SYSTEM_RGB565
67  #error The eGUI low level driver "d4dlcdhw_kinetis_spi" not supported selected type of D4D_COLOR_SYSTEM. To run this driver just select D4D_COLOR_SYSTEM_RGB565.
68  #endif
69  /******************************************************************************
70  * Internal function prototypes
71  ******************************************************************************/
72 
73  static unsigned char D4DLCDHW_Init_Kinetis_Spi(void);
74  static unsigned char D4DLCDHW_DeInit_Kinetis_Spi(void);
75  static void D4DLCDHW_SendDataWord_Kinetis_Spi(unsigned short value);
76  static void D4DLCDHW_SendCmdWord_Kinetis_Spi(unsigned short cmd);
77  static unsigned short D4DLCDHW_ReadDataWord_Kinetis_Spi(void);
78  static unsigned short D4DLCDHW_ReadCmdWord_Kinetis_Spi(void);
79  static unsigned char D4DLCDHW_PinCtl_Kinetis_Spi(D4DLCDHW_PINS pinId, D4DHW_PIN_STATE setState);
80  static void D4DLCD_FlushBuffer_Kinetis_Spi(D4DLCD_FLUSH_MODE mode);
81 
82  /**************************************************************/
88  // the main structure that contains low level driver api functions
89  // the name fo this structure is used for recognizing of configured low level driver of whole D4D
90  // so this name has to be used in main configuration header file of D4D driver to enable this driver
91  const D4DLCDHW_FUNCTIONS d4dlcdhw_kinetis_spi =
92  {
93  D4DLCDHW_Init_Kinetis_Spi,
94  D4DLCDHW_SendDataWord_Kinetis_Spi,
95  D4DLCDHW_SendCmdWord_Kinetis_Spi,
96  D4DLCDHW_ReadDataWord_Kinetis_Spi,
97  D4DLCDHW_ReadCmdWord_Kinetis_Spi,
98  D4DLCDHW_PinCtl_Kinetis_Spi,
99  D4DLCD_FlushBuffer_Kinetis_Spi,
100  D4DLCDHW_DeInit_Kinetis_Spi
101  };
102  /**************************************************************/
108  /**************************************************************/
114  //-----------------------------------------------------------------------------
115  // FUNCTION: D4DLCDHW_Init_Kinetis_Spi
116  // SCOPE: Low Level Driver API function
117  // DESCRIPTION: The function is used for initialization of this low level driver
118  //
119  // PARAMETERS: none
120  //
121  // RETURNS: result: 1 - Success
122  // 0 - Failed
123  //-----------------------------------------------------------------------------
124  static unsigned char D4DLCDHW_Init_Kinetis_Spi(void)
125  {
126 
127  // defined in spi_cfg.h
128  #ifdef D4DLCD_DISPLAY_MCU_USER_INIT
129  D4DLCD_DISPLAY_MCU_USER_INIT
130  #endif
131 
133 
134  D4DLCD_ASSERT_DC;
135  D4DLCD_INIT_DC;
136 
137  // Enable and clear SPI
138  D4DLCD_SPI_MCR &= (~ SPI_MCR_MDIS_MASK);
139  D4DLCD_SPI_MCR = SPI_MCR_HALT_MASK | SPI_MCR_CLR_TXF_MASK | SPI_MCR_CLR_RXF_MASK;
140 
141  // 15+1 = 16-bit transfers, Fclk = Fsys/4
142  D4DLCD_SPI_CTAR0 = SPI_CTAR_FMSZ(15) | SPI_CTAR_BR(0);
143 
144  #ifdef D4DLCD_SPI_DBL_BRATE
145  D4DLCD_SPI_CTAR0 |= SPI_CTAR_DBR_MASK; // Dual Baudrate enable in config file
146  #endif
147 
148  // Set CS0-7 inactive high
149  D4DLCD_SPI_MCR |= (SPI_MCR_PCSIS(1 << (D4DLCD_SPI_PCS_ID))|SPI_MCR_MSTR_MASK);
150 
151  // Disable all IRQs
152  D4DLCD_SPI_RSER = 0;
153  // clear Flag
154  D4DLCD_SPI_SR = SPI_SR_TFFF_MASK;
155  D4DLCD_SPI_SR = SPI_SR_TCF_MASK;
156 
157  // Enable SPI
158  D4DLCD_SPI_MCR &= (~ SPI_MCR_HALT_MASK);
159  return 1;
160  }
161 
162 
163  //-----------------------------------------------------------------------------
164  // FUNCTION: D4DLCDHW_DeInit_Kinetis_Spi
165  // SCOPE: Low Level Driver API function
166  // DESCRIPTION: The function is used for deinitialization of this low level driver
167  //
168  // PARAMETERS: none
169  //
170  // RETURNS: result: 1 - Success
171  // 0 - Failed
172  //-----------------------------------------------------------------------------
173  static unsigned char D4DLCDHW_DeInit_Kinetis_Spi(void)
174  {
175  return 1;
176  }
177 
178  //-----------------------------------------------------------------------------
179  // FUNCTION: D4DLCDHW_SendDataWord_Kinetis_Spi
180  // SCOPE: Low Level Driver API function
181  // DESCRIPTION: The function send the one 16 bit variable into LCD
182  //
183  // PARAMETERS: unsigned short value variable to send
184  //
185  // RETURNS: none
186  //-----------------------------------------------------------------------------
187  static void D4DLCDHW_SendDataWord_Kinetis_Spi(unsigned short value)
188  {
189 
190  // wait write buffer not full flag
191  while (!(D4DLCD_SPI_SR & SPI_SR_TFFF_MASK)){};
192 
193  // Assert CS0, Use config 0
194  D4DLCD_SPI_PUSHR = SPI_PUSHR_PCS(1 << (D4DLCD_SPI_PCS_ID)) | SPI_PUSHR_CTAS(0) | SPI_PUSHR_TXDATA((unsigned short)value);
195 
196  while (!(D4DLCD_SPI_SR & SPI_SR_TCF_MASK)){};// while shift-out complete
197  D4DLCD_SPI_SR = SPI_SR_TCF_MASK; // clear flag
198  }
199 
200  //-----------------------------------------------------------------------------
201  // FUNCTION: D4DLCDHW_SendCmdWord_Kinetis_Spi
202  // SCOPE: Low Level Driver API function
203  // DESCRIPTION: The function send the one 16 bit command into LCD
204  //
205  // PARAMETERS: unsigned short cmd command to send
206  //
207  // RETURNS: none
208  //-----------------------------------------------------------------------------
209  static void D4DLCDHW_SendCmdWord_Kinetis_Spi(unsigned short cmd)
210  {
211  D4DLCD_ASSERT_DC; // DataCmd := 1
212  D4DLCDHW_SendDataWord_Kinetis_Spi(cmd);
213  D4DLCD_DEASSERT_DC; // DataCmd := 0
214  }
215 
216 
217  //-----------------------------------------------------------------------------
218  // FUNCTION: D4DLCDHW_ReadDataWord_Kinetis_Spi
219  // SCOPE: Low Level Driver API function
220  // DESCRIPTION: The function reads the one 16 bit variable from LCD (if this function is supported)
221  //
222  // PARAMETERS: none
223  //
224  // RETURNS: unsigned short - the readed value
225  //
226  //-----------------------------------------------------------------------------
227  static unsigned short D4DLCDHW_ReadDataWord_Kinetis_Spi(void)
228  {
229  return 0;
230  }
231 
232  //-----------------------------------------------------------------------------
233  // FUNCTION: D4DLCDHW_ReadCmdWord_Kinetis_Spi
234  // SCOPE: Low Level Driver API function
235  // DESCRIPTION: The function reads the one 16 bit command from LCD (if this function is supported)
236  //
237  // PARAMETERS: none
238  //
239  // RETURNS: unsigned short - the readed value
240  //
241  //-----------------------------------------------------------------------------
242  static unsigned short D4DLCDHW_ReadCmdWord_Kinetis_Spi(void)
243  {
244  return 0;
245  }
246 
247  //-----------------------------------------------------------------------------
248  // FUNCTION: D4DLCDHW_PinCtl_Kinetis_Spi
249  // SCOPE: Low Level Driver API function
250  // DESCRIPTION: allows control GPIO pins for LCD conrol purposes
251  //
252  // PARAMETERS: D4DLCDHW_PINS pinId - Pin identification
253  // D4DHW_PIN_STATE setState - Pin action
254  // RETURNS: for Get action retuns the pin value
255  //-----------------------------------------------------------------------------
256 
257  static unsigned char D4DLCDHW_PinCtl_Kinetis_Spi(D4DLCDHW_PINS pinId, D4DHW_PIN_STATE setState)
258  {
259  switch(pinId)
260  {
261  case D4DLCD_RESET_PIN:
262  switch(setState)
263  {
264  #ifdef D4DLCD_RESET
265 
266  case D4DHW_PIN_OUT:
267  OUTPUT(D4DLCD_RESET);
268  break;
269  case D4DHW_PIN_IN:
270  INPUT(D4DLCD_RESET);
271  break;
272  case D4DHW_PIN_SET_1:
273  D4DLCD_DEASSERT_RESET
274  break;
275  case D4DHW_PIN_SET_0:
276  D4DLCD_ASSERT_RESET;
277  break;
278 
279  #endif
280  }
281  break;
283  switch(setState)
284  {
285 
286  #ifdef D4DLCD_BACKLIGHT
287 
288  case D4DHW_PIN_OUT:
289  OUTPUT(D4DLCD_BACKLIGHT);
290  break;
291  case D4DHW_PIN_IN:
292  INPUT(D4DLCD_BACKLIGHT);
293  break;
294  case D4DHW_PIN_SET_1:
295  D4DLCD_DEASSERT_BACKLIGHT
296  break;
297  case D4DHW_PIN_SET_0:
298  D4DLCD_ASSERT_BACKLIGHT;
299  break;
300 
301  #endif
302 
303  }
304  break;
305  }
306  return 1;
307 
308  }
309 
310 
311  //-----------------------------------------------------------------------------
312  // FUNCTION: D4DLCD_FlushBuffer_Kinetis_Spi
313  // SCOPE: Low Level Driver API function
314  // DESCRIPTION: For buffered low level interfaces is used to inform
315  // driver the complete object is drawed and pending pixels should be flushed
316  //
317  // PARAMETERS: none
318  //
319  // RETURNS: none
320  //-----------------------------------------------------------------------------
321  static void D4DLCD_FlushBuffer_Kinetis_Spi(D4DLCD_FLUSH_MODE mode)
322  {
323  D4D_UNUSED(mode);
324  }
325 
326 #endif //(D4D_MK_STR(D4D_LLD_LCD_HW) == d4dlcdhw_kinetis_Spi_ID)
#define D4DLCD_SPI_RSER
D4D low level standard LCD Hardware interface API structure.
Definition: d4d_lldapi.h:163
#define INPUT(x)
D4D Driver main header file.
D4DHW_PIN_STATE
D4D low level MCU pin state enumeration type.
Definition: d4d_lldapi.h:73
D4DLCD_FLUSH_MODE
D4D low level eGUI flush screen types enumeration.
Definition: d4d_lldapi.h:136
D4D Driver private header file.
D4DLCDHW_PINS
D4D low level MCU types definition for general LCD screen control signals.
Definition: d4d_lldapi.h:96
#define D4DLCD_SPI_PUSHR
#define OUTPUT(x)
#define D4DLCD_SPI_PORT_INIT
Switch pin to input mode (equivalent to high-Z)
Definition: d4d_lldapi.h:78
Switch pin to output mode.
Definition: d4d_lldapi.h:77
Set pin output register to logic 1.
Definition: d4d_lldapi.h:80
#define D4DLCD_SPI_CTAR0
LCD device backlight enable signal.
Definition: d4d_lldapi.h:99
D4D driver - kinetis_spi hardware lcd driver function header file.
#define D4D_UNUSED(x)
Macro used just for notify compiler that the input parameter is not used.
Definition: d4d_base.h:504
#define D4DLCD_SPI_MCR
Set pin output register to logic 0.
Definition: d4d_lldapi.h:79
#define D4DLCD_SPI_SR
D4D driver - resistive touch screen driver function header file.
LCD device reset signal.
Definition: d4d_lldapi.h:98