1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
63
64
65
66
67
68
69
70
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
101
102
103
104
105
106
111
112
113
114
115
121
122
123
124
125
126
127
128
135
139
140
147
151
152
159
166
167
174
181
182
188
189
194
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
275
276
277
278
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
376
381
382
387
392
393
398
/* ... */
/* ... */
#include "GUI.h"
#include "GUIDRV_FlexColor.h"
#include "main.h"
#include "ili9325/ili9325.h"
/* ... */
#define XSIZE_PHYS 240
#define YSIZE_PHYS 320
/* ... */
#ifndef VXSIZE_PHYS
#define VXSIZE_PHYS XSIZE_PHYS
#endif
#ifndef VYSIZE_PHYS
#define VYSIZE_PHYS YSIZE_PHYS
#endif
#ifndef XSIZE_PHYS
#error Physical X size of display is not defined!
#endif
#ifndef YSIZE_PHYS
#error Physical Y size of display is not defined!
#endif
#ifndef GUICC_565
#error Color conversion not defined!
#endif
#ifndef GUIDRV_FLEXCOLOR
#error No display driver defined!
#endif
/* ... */
typedef struct
{
__IO uint16_t REG;
__IO uint16_t RAM;
...}LCD_CONTROLLER_TypeDef;
#define FMC_BANK3_BASE ((uint32_t)(0x60000000 | 0x08000000))
#define FMC_BANK3 ((LCD_CONTROLLER_TypeDef *) FMC_BANK3_BASE)
/* ... */
static void STM_FSMC_BANK3_WriteData(uint16_t Data);
static void STM_FSMC_BANK3_WriteReg(uint8_t Reg);
static uint16_t STM_FSMC_BANK3_ReadData(void);
static void STM_FSMC_BANK3_Init(void);
static void STM_FSMC_BANK3_MspInit(void);
/* ... */
static void LcdWriteReg(U16 Data)
{
STM_FSMC_BANK3_WriteReg(Data);
}{ ... }
/* ... */
static void LcdWriteData(U16 Data)
{
STM_FSMC_BANK3_WriteData (Data);
}{ ... }
/* ... */
static void LcdWriteDataMultiple(U16 * pData, int NumItems)
{
while (NumItems--)
{
STM_FSMC_BANK3_WriteData(*pData++);
}while (NumItems--) { ... }
}{ ... }
/* ... */
static void LcdReadDataMultiple(U16 * pData, int NumItems)
{
while (NumItems--)
{
*pData++ = STM_FSMC_BANK3_ReadData();
}while (NumItems--) { ... }
}{ ... }
/* ... */
/* ... */
void LCD_LL_Init(void)
{
STM_FSMC_BANK3_Init();
ili9325_Init();
}{ ... }
/* ... */
void LCD_X_Config(void)
{
GUI_DEVICE * pDevice;
CONFIG_FLEXCOLOR Config = {0};
GUI_PORT_API PortAPI = {0};
pDevice = GUI_DEVICE_CreateAndLink(GUIDRV_FLEXCOLOR, GUICC_565, 0, 0);
LCD_SetSizeEx (0, XSIZE_PHYS , YSIZE_PHYS);
LCD_SetVSizeEx(0, VXSIZE_PHYS, VYSIZE_PHYS);
Config.Orientation = GUI_SWAP_XY | GUI_MIRROR_Y;
GUIDRV_FlexColor_Config(pDevice, &Config);
PortAPI.pfWrite16_A0 = LcdWriteReg;
PortAPI.pfWrite16_A1 = LcdWriteData;
PortAPI.pfWriteM16_A1 = LcdWriteDataMultiple;
PortAPI.pfReadM16_A1 = LcdReadDataMultiple;
GUIDRV_FlexColor_SetFunc(pDevice, &PortAPI, GUIDRV_FLEXCOLOR_F66708, GUIDRV_FLEXCOLOR_M16C0B16);
}{ ... }
/* ... */
int LCD_X_DisplayDriver(unsigned LayerIndex, unsigned Cmd, void * pData) {
int r;
(void) LayerIndex;
(void) pData;
switch (Cmd) {
case LCD_X_INITCONTROLLER: {
LCD_LL_Init();
return 0;
...}case LCD_X_INITCONTROLLER:
default:
r = -1;default
}switch (Cmd) { ... }
return r;
}{ ... }
/* ... */
static void STM_FSMC_BANK3_MspInit(void)
{
GPIO_InitTypeDef GPIO_Init_Structure;
__HAL_RCC_FSMC_CLK_ENABLE();
__HAL_RCC_GPIOD_CLK_ENABLE();
__HAL_RCC_GPIOE_CLK_ENABLE();
__HAL_RCC_GPIOF_CLK_ENABLE();
__HAL_RCC_GPIOG_CLK_ENABLE();
GPIO_Init_Structure.Mode = GPIO_MODE_AF_PP;
GPIO_Init_Structure.Pull = GPIO_PULLUP;
GPIO_Init_Structure.Speed = GPIO_SPEED_HIGH;
GPIO_Init_Structure.Alternate = GPIO_AF12_FSMC;
GPIO_Init_Structure.Pin = GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_4 | GPIO_PIN_5 | GPIO_PIN_8 |\
GPIO_PIN_9 | GPIO_PIN_10 | GPIO_PIN_11 | GPIO_PIN_12 | GPIO_PIN_13 |\
GPIO_PIN_14 | GPIO_PIN_15;
HAL_GPIO_Init(GPIOD, &GPIO_Init_Structure);
GPIO_Init_Structure.Pin = GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_3| GPIO_PIN_4 | GPIO_PIN_7 |\
GPIO_PIN_8 | GPIO_PIN_9 | GPIO_PIN_10 | GPIO_PIN_11 | GPIO_PIN_12 |\
GPIO_PIN_13 | GPIO_PIN_14 | GPIO_PIN_15;
HAL_GPIO_Init(GPIOE, &GPIO_Init_Structure);
GPIO_Init_Structure.Pin = GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_2| GPIO_PIN_3 | GPIO_PIN_4 |\
GPIO_PIN_5 | GPIO_PIN_12 | GPIO_PIN_13 | GPIO_PIN_14 | GPIO_PIN_15;
HAL_GPIO_Init(GPIOF, &GPIO_Init_Structure);
GPIO_Init_Structure.Pin = GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_2| GPIO_PIN_3 | GPIO_PIN_4 |\
GPIO_PIN_5 | GPIO_PIN_10;
HAL_GPIO_Init(GPIOG, &GPIO_Init_Structure);
}{ ... }
/* ... */
static void STM_FSMC_BANK3_Init(void)
{
SRAM_HandleTypeDef hsram;
FSMC_NORSRAM_TimingTypeDef SRAM_Timing;
hsram.Instance = FMC_NORSRAM_DEVICE;
hsram.Extended = FMC_NORSRAM_EXTENDED_DEVICE;
SRAM_Timing.AddressSetupTime = 5;
SRAM_Timing.AddressHoldTime = 1;
SRAM_Timing.DataSetupTime = 9;
SRAM_Timing.BusTurnAroundDuration = 0;
SRAM_Timing.CLKDivision = 2;
SRAM_Timing.DataLatency = 2;
SRAM_Timing.AccessMode = FSMC_ACCESS_MODE_A;
hsram.Init.NSBank = FSMC_NORSRAM_BANK3;
hsram.Init.DataAddressMux = FSMC_DATA_ADDRESS_MUX_DISABLE;
hsram.Init.MemoryType = FSMC_MEMORY_TYPE_SRAM;
hsram.Init.MemoryDataWidth = FSMC_NORSRAM_MEM_BUS_WIDTH_16;
hsram.Init.BurstAccessMode = FSMC_BURST_ACCESS_MODE_DISABLE;
hsram.Init.WaitSignalPolarity = FSMC_WAIT_SIGNAL_POLARITY_LOW;
hsram.Init.WrapMode = FSMC_WRAP_MODE_DISABLE;
hsram.Init.WaitSignalActive = FSMC_WAIT_TIMING_BEFORE_WS;
hsram.Init.WriteOperation = FSMC_WRITE_OPERATION_ENABLE;
hsram.Init.WaitSignal = FSMC_WAIT_SIGNAL_DISABLE;
hsram.Init.ExtendedMode = FSMC_EXTENDED_MODE_DISABLE;
hsram.Init.AsynchronousWait = FSMC_ASYNCHRONOUS_WAIT_DISABLE;
hsram.Init.WriteBurst = FSMC_WRITE_BURST_DISABLE;
STM_FSMC_BANK3_MspInit();
HAL_SRAM_Init(&hsram, &SRAM_Timing, &SRAM_Timing);
}{ ... }
/* ... */
static void STM_FSMC_BANK3_WriteData(uint16_t Data)
{
FMC_BANK3->RAM = Data;
}{ ... }
/* ... */
static void STM_FSMC_BANK3_WriteReg(uint8_t Reg)
{
FMC_BANK3->REG = Reg;
}{ ... }
/* ... */
static uint16_t STM_FSMC_BANK3_ReadData(void)
{
return FMC_BANK3->RAM;
}{ ... }