@@ -0,0 +1,18 | |||
|
1 | TEMPLATE = lib | |
|
2 | ||
|
3 | TARGET=bsp | |
|
4 | OBJECTS_DIR = obj | |
|
5 | ||
|
6 | BSP=STM32F4Discovery-ILI9328-8bits | |
|
7 | ||
|
8 | UCMODEL=stm32f4 | |
|
9 | ||
|
10 | SOURCES += bsp.c | |
|
11 | ||
|
12 | HEADERS += bsp.h | |
|
13 | ||
|
14 | ||
|
15 | BSPFILE = bsp.pri | |
|
16 | ||
|
17 | ||
|
18 |
@@ -0,0 +1,378 | |||
|
1 | /*------------------------------------------------------------------------------ | |
|
2 | -- This file is a part of the libuc, microcontroler library | |
|
3 | -- Copyright (C) 2011, Alexis Jeandet | |
|
4 | -- | |
|
5 | -- This program is free software; you can redistribute it and/or modify | |
|
6 | -- it under the terms of the GNU General Public License as published by | |
|
7 | -- the Free Software Foundation; either version 3 of the License, or | |
|
8 | -- (at your option) any later version. | |
|
9 | -- | |
|
10 | -- This program is distributed in the hope that it will be useful, | |
|
11 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of | |
|
12 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
|
13 | -- GNU General Public License for more details. | |
|
14 | -- | |
|
15 | -- You should have received a copy of the GNU General Public License | |
|
16 | -- along with this program; if not, write to the Free Software | |
|
17 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
|
18 | ------------------------------------------------------------------------------- | |
|
19 | -- Author : Alexis Jeandet | |
|
20 | -- Mail : alexis.jeandet@member.fsf.org | |
|
21 | -------------------------------------------------------------------------------*/ | |
|
22 | #include "bsp.h" | |
|
23 | #include <streamdevices.h> | |
|
24 | #include <malloc.h> | |
|
25 | #include <gpio.h> | |
|
26 | #include <uart.h> | |
|
27 | #include <stdio.h> | |
|
28 | #include <ili9328.h> | |
|
29 | #include <genericLCD_Controler.h> | |
|
30 | #include <stm32f4xx.h> | |
|
31 | #include <stm32f4xx_gpio.h> | |
|
32 | #include <stm32f4xx_rcc.h> | |
|
33 | #include <stm32f4xx_gpio.h> | |
|
34 | #include <stm32f4xx_fsmc.h> | |
|
35 | #include <terminal.h> | |
|
36 | uint32_t OSC0 =8000000; | |
|
37 | uint32_t INTOSC =16000000; | |
|
38 | uint32_t RTCOSC =32768; | |
|
39 | uint32_t currentCpuFreq=0; | |
|
40 | extern streamdevice* __opnfiles__[__MAX_OPENED_FILES__]; | |
|
41 | ||
|
42 | volatile uint8_t* lcd0_CMD=(volatile uint8_t*)0x60000000; | |
|
43 | volatile uint8_t* lcd0_DATA=(volatile uint8_t*)0x61FFFFF0; | |
|
44 | terminal_t terminal0; | |
|
45 | volatile vs10XXDev audioCodec0; | |
|
46 | sdcardDev sdcard2; | |
|
47 | blkdevice sdcard2blkdev; | |
|
48 | dikpartition sdcard2Part1; | |
|
49 | FAT32fs sdcard2FAT32part1; | |
|
50 | dikpartition sdcard2Part2; | |
|
51 | FAT32fs sdcard2FAT32part2; | |
|
52 | dikpartition sdcard2Part3; | |
|
53 | FAT32fs sdcard2FAT32part3; | |
|
54 | dikpartition sdcard2Part4; | |
|
55 | FAT32fs sdcard2FAT32part4; | |
|
56 | ||
|
57 | LCD_IF_t lcdIF0={ | |
|
58 | .init = &bsp_FSMC_init, | |
|
59 | .writereg = &bsp_lcd0_write_reg, | |
|
60 | .readreg = &bsp_lcd0_read_reg, | |
|
61 | .writeGRAM = &bsp_lcd0_writeGRAM, | |
|
62 | .readGRAM = &bsp_lcd0_readGRAM | |
|
63 | }; | |
|
64 | ||
|
65 | LCD_t lcd0={ | |
|
66 | .interface = &lcdIF0, | |
|
67 | .init = &ili9328init, | |
|
68 | .paint = &ili9328paint, | |
|
69 | .paintText = &ili9328paintText, | |
|
70 | .paintFilRect = &ili9328paintFilRect, | |
|
71 | .refreshenable = &ili9328refreshenable, | |
|
72 | .width= 240, | |
|
73 | .height = 320 | |
|
74 | }; | |
|
75 | ||
|
76 | ||
|
77 | float VREF0 =(float)3.3; | |
|
78 | ||
|
79 | int bsp_init() | |
|
80 | { | |
|
81 | int i=0; | |
|
82 | for(i=0;i<32;i++) | |
|
83 | { | |
|
84 | __opnfiles__[i] = NULL; | |
|
85 | } | |
|
86 | bsp_GPIO_init(); | |
|
87 | bsp_uart_init(); | |
|
88 | bsp_FSMC_init(); | |
|
89 | bsp_GTerm_init(); | |
|
90 | printf("\r================================================================\n\r"); | |
|
91 | printf("================================================================\n\r"); | |
|
92 | printf(BSP); | |
|
93 | printf(" initialised\n\r"); | |
|
94 | printf("================================================================\n\r"); | |
|
95 | return 1; | |
|
96 | } | |
|
97 | ||
|
98 | void bsp_GPIO_init() | |
|
99 | { | |
|
100 | gpio_t gpio1 = gpioopen(PD12);//gpioopen(LED1); //PD9 D=> 0x0300 9 => 0x0009 | |
|
101 | gpio_t gpio2 = gpioopen(PD13);//gpioopen(LED2); | |
|
102 | gpio_t gpio3 = gpioopen(PD14);//gpioopen(LED2); | |
|
103 | gpio_t gpio4 = gpioopen(PD15);//gpioopen(LED2); | |
|
104 | gpiosetspeed(&gpio1,gpiohighspeed); | |
|
105 | gpiosetspeed(&gpio2,gpiohighspeed); | |
|
106 | gpiosetspeed(&gpio3,gpiohighspeed); | |
|
107 | gpiosetspeed(&gpio4,gpiohighspeed); | |
|
108 | gpiosetdir(&gpio1,gpiooutdir); | |
|
109 | gpiosetdir(&gpio3,gpiooutdir); | |
|
110 | gpiosetdir(&gpio2,gpiooutdir); | |
|
111 | gpiosetdir(&gpio4,gpiooutdir); | |
|
112 | } | |
|
113 | ||
|
114 | void bsp_uart_init() | |
|
115 | { | |
|
116 | // if(__opnfiles__[1]==NULL) | |
|
117 | // { | |
|
118 | // //uart_t* uart1 = (uart_t*)malloc(sizeof(uart_t)); | |
|
119 | // streamdevice* fd1 = (streamdevice*)malloc(sizeof(streamdevice)); | |
|
120 | // uart_t uart = uartopenandconfig(uart3,uartparitynone | uart8bits | uartonestop,19200,PB10,PB11,-1,-1); | |
|
121 | // uartmkstreamdev(uart,fd1); | |
|
122 | // __opnfiles__[1] = fd1; //stdo | |
|
123 | // __opnfiles__[0] = fd1; //stdi | |
|
124 | // } | |
|
125 | // else | |
|
126 | // { | |
|
127 | // uartopenandconfig(2,uartparitynone | uart8bits | uartonestop,115200,PB10,PB11,-1,-1); | |
|
128 | // } | |
|
129 | } | |
|
130 | ||
|
131 | void bsp_spi_init() | |
|
132 | { | |
|
133 | ||
|
134 | } | |
|
135 | ||
|
136 | ||
|
137 | int bsp_FSMC_init() | |
|
138 | { | |
|
139 | #define GPIOGETPORT(gpio) ((GPIO_TypeDef*)(((((uint32_t)gpio) & (uint32_t)0x0000FF00)*(uint32_t)4) + (uint32_t)GPIOA)) | |
|
140 | #define GPIOPORTNUM(gpio) (((uint32_t)(gpio) & (uint32_t)0x0000FF00)>>(uint32_t)8) | |
|
141 | ||
|
142 | gpio_t LCD_DBxList[]={PD14,PD15,PD0,PD1,PE7,PE8,PE9,PE10\ | |
|
143 | ,PD4,PD5,PD7,PE4}; | |
|
144 | for(int i=0;i<12;i++) | |
|
145 | { | |
|
146 | gpio_t LCD_DBx = gpioopen(LCD_DBxList[i]); | |
|
147 | LCD_DBx |= gpiohighspeed | gpioaf | gpiopushpulltype | gpionopulltype; | |
|
148 | gpiosetconfig(&LCD_DBx); | |
|
149 | GPIO_PinAFConfig(GPIOGETPORT(LCD_DBx), (uint8_t)(LCD_DBx & 0xF), GPIO_AF_FSMC); | |
|
150 | } | |
|
151 | ||
|
152 | FSMC_NORSRAMInitTypeDef FSMC_NORSRAMInitStructure; | |
|
153 | FSMC_NORSRAMTimingInitTypeDef p,readtim; | |
|
154 | ||
|
155 | /* Enable FSMC clock */ | |
|
156 | RCC_AHB3PeriphClockCmd(RCC_AHB3Periph_FSMC, ENABLE); | |
|
157 | ||
|
158 | /*-- FSMC Configuration ------------------------------------------------------*/ | |
|
159 | /*----------------------- SRAM Bank 3 ----------------------------------------*/ | |
|
160 | /* FSMC_Bank1_NORSRAM4 configuration */ | |
|
161 | p.FSMC_AddressSetupTime = 3; | |
|
162 | p.FSMC_AddressHoldTime = 3; | |
|
163 | //ili9328 -> data setup time > 10ns | |
|
164 | p.FSMC_DataSetupTime = 1; | |
|
165 | if(getCpuFreq()>100*1000*1000) | |
|
166 | p.FSMC_DataSetupTime = 2;// 11; | |
|
167 | p.FSMC_BusTurnAroundDuration = 0; | |
|
168 | p.FSMC_CLKDivision = 0; | |
|
169 | p.FSMC_DataLatency = 0; | |
|
170 | //ili9328 -> data hold time > 15ns | |
|
171 | if(getCpuFreq()>66*1000*1000) | |
|
172 | p.FSMC_DataLatency = 1; | |
|
173 | p.FSMC_AccessMode = FSMC_AccessMode_A; | |
|
174 | ||
|
175 | readtim.FSMC_AddressSetupTime = 0xF; | |
|
176 | readtim.FSMC_AddressHoldTime = 0xF; | |
|
177 | //p.FSMC_DataSetupTime = 9; | |
|
178 | readtim.FSMC_DataSetupTime = 0xF ;// 11; | |
|
179 | if(getCpuFreq()>100*1000*1000) | |
|
180 | readtim.FSMC_DataSetupTime = 0xF;// 11; | |
|
181 | readtim.FSMC_BusTurnAroundDuration = 0xf; | |
|
182 | readtim.FSMC_CLKDivision = 0; | |
|
183 | readtim.FSMC_DataLatency = 0xF; | |
|
184 | if(getCpuFreq()>66*1000*1000) | |
|
185 | readtim.FSMC_DataLatency = 0xF; | |
|
186 | readtim.FSMC_AccessMode = FSMC_AccessMode_A; | |
|
187 | ||
|
188 | ||
|
189 | FSMC_NORSRAMInitStructure.FSMC_Bank = FSMC_Bank1_NORSRAM1; | |
|
190 | FSMC_NORSRAMInitStructure.FSMC_DataAddressMux = FSMC_DataAddressMux_Disable; | |
|
191 | FSMC_NORSRAMInitStructure.FSMC_MemoryType = FSMC_MemoryType_SRAM; | |
|
192 | FSMC_NORSRAMInitStructure.FSMC_MemoryDataWidth = FSMC_MemoryDataWidth_8b; | |
|
193 | FSMC_NORSRAMInitStructure.FSMC_BurstAccessMode = FSMC_BurstAccessMode_Disable; | |
|
194 | FSMC_NORSRAMInitStructure.FSMC_AsynchronousWait = FSMC_AsynchronousWait_Disable; | |
|
195 | FSMC_NORSRAMInitStructure.FSMC_WaitSignalPolarity = FSMC_WaitSignalPolarity_Low; | |
|
196 | FSMC_NORSRAMInitStructure.FSMC_WrapMode = FSMC_WrapMode_Disable; | |
|
197 | FSMC_NORSRAMInitStructure.FSMC_WaitSignalActive = FSMC_WaitSignalActive_BeforeWaitState; | |
|
198 | FSMC_NORSRAMInitStructure.FSMC_WriteOperation = FSMC_WriteOperation_Enable; | |
|
199 | FSMC_NORSRAMInitStructure.FSMC_WaitSignal = FSMC_WaitSignal_Disable; | |
|
200 | FSMC_NORSRAMInitStructure.FSMC_ExtendedMode = FSMC_ExtendedMode_Disable; | |
|
201 | FSMC_NORSRAMInitStructure.FSMC_WriteBurst = FSMC_WriteBurst_Disable; | |
|
202 | FSMC_NORSRAMInitStructure.FSMC_ReadWriteTimingStruct = &readtim; | |
|
203 | FSMC_NORSRAMInitStructure.FSMC_WriteTimingStruct = &p; | |
|
204 | ||
|
205 | FSMC_NORSRAMInit(&FSMC_NORSRAMInitStructure); | |
|
206 | ||
|
207 | FSMC_NORSRAMCmd(FSMC_Bank1_NORSRAM1, ENABLE); | |
|
208 | gpioset(LCD_RESET); | |
|
209 | gpioclr(LCD_RESET); | |
|
210 | delay_100us(500); | |
|
211 | gpioset(LCD_RESET); | |
|
212 | delay_100us(500); | |
|
213 | lcd0.init(&lcd0); | |
|
214 | gpioset(LCD_BACKL); | |
|
215 | return 1; | |
|
216 | } | |
|
217 | ||
|
218 | ||
|
219 | void bsp_iic_init() | |
|
220 | { | |
|
221 | ||
|
222 | } | |
|
223 | ||
|
224 | void bsp_SD_init() | |
|
225 | { | |
|
226 | ||
|
227 | } | |
|
228 | ||
|
229 | ||
|
230 | void vs10XXclearXCS(){} | |
|
231 | void vs10XXsetXCS(){} | |
|
232 | int vs10XXDREQ() | |
|
233 | { | |
|
234 | return 1; | |
|
235 | } | |
|
236 | ||
|
237 | ||
|
238 | void bsppowersdcard(char onoff) //always ON | |
|
239 | { | |
|
240 | ||
|
241 | } | |
|
242 | ||
|
243 | char bspsdcardpresent() | |
|
244 | { | |
|
245 | return 0; | |
|
246 | } | |
|
247 | ||
|
248 | char bspsdcardwriteprotected() | |
|
249 | { | |
|
250 | return 0; | |
|
251 | } | |
|
252 | ||
|
253 | void bspsdcardselect(char YESNO) | |
|
254 | { | |
|
255 | ||
|
256 | } | |
|
257 | ||
|
258 | ||
|
259 | ||
|
260 | void bsp_lcd0_write_reg(uint32_t reg,uint32_t data) | |
|
261 | { | |
|
262 | uint8_t* pt8 = (uint8_t*)(void*)® | |
|
263 | #if __BYTE_ORDER__==__ORDER_BIG_ENDIAN__ | |
|
264 | *lcd0_CMD=pt8[3]; | |
|
265 | *lcd0_CMD=pt8[2]; | |
|
266 | pt8 = (uint8_t*)(void*)&data; | |
|
267 | *lcd0_DATA=pt8[3]; | |
|
268 | *lcd0_DATA=pt8[2]; | |
|
269 | #else | |
|
270 | *lcd0_CMD=pt8[1]; | |
|
271 | *lcd0_CMD=pt8[0]; | |
|
272 | pt8 = (uint8_t*)(void*)&data; | |
|
273 | *lcd0_DATA=pt8[1]; | |
|
274 | *lcd0_DATA=pt8[0]; | |
|
275 | #endif | |
|
276 | ||
|
277 | } | |
|
278 | ||
|
279 | uint32_t bsp_lcd0_read_reg(uint32_t reg) | |
|
280 | { | |
|
281 | uint8_t* pt8 = (uint8_t*)(void*)® | |
|
282 | uint32_t DATA=0; | |
|
283 | #if __BYTE_ORDER__==__ORDER_BIG_ENDIAN__ | |
|
284 | *lcd0_CMD=pt8[3]; | |
|
285 | *lcd0_CMD=pt8[2]; | |
|
286 | pt8 = (uint8_t*)(void*)&DATA; | |
|
287 | pt8[3]=*lcd0_DATA; | |
|
288 | pt8[2]=*lcd0_DATA; | |
|
289 | #else | |
|
290 | ||
|
291 | *lcd0_CMD=pt8[1]; | |
|
292 | *lcd0_CMD=pt8[0]; | |
|
293 | pt8 = (uint8_t*)(void*)&DATA; | |
|
294 | pt8[1]=*lcd0_DATA; | |
|
295 | pt8[0]=*lcd0_DATA; | |
|
296 | #endif | |
|
297 | ||
|
298 | return DATA; | |
|
299 | } | |
|
300 | ||
|
301 | void bsp_lcd0_writeGRAM(void* buffer,uint32_t count) | |
|
302 | { | |
|
303 | uint32_t reg =ILI9328_REGISTER_WRITEDATATOGRAM; | |
|
304 | uint8_t* pt8 = (uint8_t*)(void*)(®); | |
|
305 | #if __BYTE_ORDER__==__ORDER_BIG_ENDIAN__ | |
|
306 | *lcd0_CMD=pt8[3]; | |
|
307 | *lcd0_CMD=pt8[2]; | |
|
308 | pt8 = (uint8_t*)(void*)buffer; | |
|
309 | for(int i=0;i<(int)count;i++) | |
|
310 | { | |
|
311 | *lcd0_DATA=pt8[(2*i) +1]; | |
|
312 | *lcd0_DATA=pt8[2*i]; | |
|
313 | } | |
|
314 | #else | |
|
315 | ||
|
316 | *lcd0_CMD=pt8[1]; | |
|
317 | *lcd0_CMD=pt8[0]; | |
|
318 | pt8 = (uint8_t*)(void*)buffer; | |
|
319 | for(int i=0;i<(int)count;i++) | |
|
320 | { | |
|
321 | ||
|
322 | *lcd0_DATA=pt8[(2*i) +1]; | |
|
323 | *lcd0_DATA=pt8[2*i]; | |
|
324 | } | |
|
325 | #endif | |
|
326 | } | |
|
327 | ||
|
328 | void bsp_lcd0_readGRAM(void* buffer,uint32_t count) | |
|
329 | { | |
|
330 | uint32_t reg =ILI9328_REGISTER_WRITEDATATOGRAM; | |
|
331 | uint8_t* pt8 = (uint8_t*)(void*)® | |
|
332 | #if __BYTE_ORDER__==__ORDER_BIG_ENDIAN__ | |
|
333 | *lcd0_CMD=pt8[3]; | |
|
334 | *lcd0_CMD=pt8[2]; | |
|
335 | pt8 = (uint8_t*)(void*)buffer; | |
|
336 | for(int i=0;i<(int)count;i++) | |
|
337 | { | |
|
338 | pt8[(2*i) +1]=*lcd0_DATA; | |
|
339 | pt8[2*i]=*lcd0_DATA; | |
|
340 | } | |
|
341 | #else | |
|
342 | *lcd0_CMD=pt8[1]; | |
|
343 | *lcd0_CMD=pt8[0]; | |
|
344 | pt8 = (uint8_t*)(void*)buffer; | |
|
345 | /* | |
|
346 | * x dummy reads Cf ili9328 datasheet p79! | |
|
347 | */ | |
|
348 | pt8[0]=*lcd0_DATA; | |
|
349 | pt8[0]=*lcd0_DATA; | |
|
350 | ||
|
351 | for(int i=0;i<(int)count;i++) | |
|
352 | { | |
|
353 | pt8[(2*i) +1]=*lcd0_DATA; | |
|
354 | pt8[2*i]=*lcd0_DATA; | |
|
355 | // pt8[(2*i) +1]=(uint8_t)0; | |
|
356 | // pt8[(2*i)]=(uint8_t)0; | |
|
357 | } | |
|
358 | #endif | |
|
359 | } | |
|
360 | ||
|
361 | void bsp_GTerm_init() | |
|
362 | { | |
|
363 | if(__opnfiles__[1]==NULL) | |
|
364 | { | |
|
365 | streamdevice* fd1 = (streamdevice*)malloc(sizeof(streamdevice)); | |
|
366 | terminal_init(&terminal0 ,&lcd0,&ComicSansMS_8,fd1); | |
|
367 | __opnfiles__[1] = fd1; | |
|
368 | } | |
|
369 | else | |
|
370 | { | |
|
371 | ||
|
372 | } | |
|
373 | } | |
|
374 | ||
|
375 | ||
|
376 | ||
|
377 | ||
|
378 |
@@ -0,0 +1,127 | |||
|
1 | /*------------------------------------------------------------------------------ | |
|
2 | -- This file is a part of the libuc, microcontroler library | |
|
3 | -- Copyright (C) 2011, Alexis Jeandet | |
|
4 | -- | |
|
5 | -- This program is free software; you can redistribute it and/or modify | |
|
6 | -- it under the terms of the GNU General Public License as published by | |
|
7 | -- the Free Software Foundation; either version 3 of the License, or | |
|
8 | -- (at your option) any later version. | |
|
9 | -- | |
|
10 | -- This program is distributed in the hope that it will be useful, | |
|
11 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of | |
|
12 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
|
13 | -- GNU General Public License for more details. | |
|
14 | -- | |
|
15 | -- You should have received a copy of the GNU General Public License | |
|
16 | -- along with this program; if not, write to the Free Software | |
|
17 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
|
18 | ------------------------------------------------------------------------------- | |
|
19 | -- Author : Alexis Jeandet | |
|
20 | -- Mail : alexis.jeandet@member.fsf.org | |
|
21 | -------------------------------------------------------------------------------*/ | |
|
22 | #ifndef BSP_H | |
|
23 | #define BSP_H | |
|
24 | #include <stm32f4xx.h> | |
|
25 | #include <stm32f4xx_gpio.h> | |
|
26 | #include <stm32f4xx_rcc.h> | |
|
27 | #include <gpio.h> | |
|
28 | #include <spi.h> | |
|
29 | #include <ili9328.h> | |
|
30 | #include <genericLCD_Controler.h> | |
|
31 | #include <sdcard-spi.h> | |
|
32 | #include <sdcard.h> | |
|
33 | #include <mbr.h> | |
|
34 | #include <VS10XX.h> | |
|
35 | #include <fat32.h> | |
|
36 | ||
|
37 | /* | |
|
38 | #ifndef PD12 | |
|
39 | #define PD12 | |
|
40 | #endif | |
|
41 | #ifndef PD13 | |
|
42 | #define PD13 | |
|
43 | #endif | |
|
44 | */ | |
|
45 | #define __MAX_OPENED_FILES__ 32 | |
|
46 | #define __FS_ROOT_SIZE__ 32 | |
|
47 | ||
|
48 | #define LED1 PD12 | |
|
49 | #define LED2 PD13 | |
|
50 | #define BP3 PA0 | |
|
51 | ||
|
52 | #define LCD_RESET PD10 | |
|
53 | #define LCD_BACKL PE11 | |
|
54 | ||
|
55 | #define GREENLEDON (GPIOD->BSRRL = 1<<12) | |
|
56 | #define ORANGELEDON (GPIOD->BSRRL = 1<<13) | |
|
57 | #define REDLEDON (GPIOD->BSRRL = 1<<14) | |
|
58 | #define BLUELEDON (GPIOD->BSRRL = 1<<15) | |
|
59 | ||
|
60 | #define GREENLEDOFF (GPIOD->BSRRH = 1<<12) | |
|
61 | #define ORANGELEDOFF (GPIOD->BSRRH = 1<<13) | |
|
62 | #define REDLEDOFF (GPIOD->BSRRH = 1<<14) | |
|
63 | #define BLUELEDOFF (GPIOD->BSRRH = 1<<15) | |
|
64 | ||
|
65 | extern float VREF0; | |
|
66 | extern LCD_t lcd0; | |
|
67 | extern uint32_t OSC0; | |
|
68 | extern uint32_t currentCpuFreq; | |
|
69 | extern volatile vs10XXDev audioCodec0; | |
|
70 | extern sdcardDev sdcard2; | |
|
71 | extern blkdevice sdcard2blkdev; | |
|
72 | extern dikpartition sdcard2Part1; | |
|
73 | extern FAT32fs sdcard2FAT32part1; | |
|
74 | extern dikpartition sdcard2Part2; | |
|
75 | extern FAT32fs sdcard2FAT32part2; | |
|
76 | extern dikpartition sdcard2Part3; | |
|
77 | extern FAT32fs sdcard2FAT32part3; | |
|
78 | extern dikpartition sdcard2Part4; | |
|
79 | extern FAT32fs sdcard2FAT32part4; | |
|
80 | ||
|
81 | ||
|
82 | extern int bsp_init(); | |
|
83 | ||
|
84 | extern void bsp_GPIO_init(); | |
|
85 | extern void bsp_uart_init(); | |
|
86 | extern void bsp_iic_init(); | |
|
87 | extern void bsp_spi_init(); | |
|
88 | extern void bsp_SD_init(); | |
|
89 | extern void bsp_GTerm_init(); | |
|
90 | extern int bsp_FSMC_init(); | |
|
91 | ||
|
92 | void bsp_lcd0_write_reg(uint32_t reg,uint32_t data); | |
|
93 | uint32_t bsp_lcd0_read_reg(uint32_t reg); | |
|
94 | void bsp_lcd0_writeGRAM(void *buffer, uint32_t count); | |
|
95 | void bsp_lcd0_readGRAM(void *buffer, uint32_t count); | |
|
96 | ||
|
97 | /* VS1053 */ | |
|
98 | extern void clearXCS(); | |
|
99 | extern void setXCS(); | |
|
100 | extern int vs10XXDREQ(); | |
|
101 | ||
|
102 | /* SD CARD */ | |
|
103 | void bsppowersdcard(char onoff); | |
|
104 | char bspsdcardpresent(); | |
|
105 | void bspsdcardselect(char YESNO); | |
|
106 | char bspsdcardwriteprotected(); | |
|
107 | ||
|
108 | #endif | |
|
109 | ||
|
110 | ||
|
111 | ||
|
112 | ||
|
113 | ||
|
114 | ||
|
115 | ||
|
116 | ||
|
117 | ||
|
118 | ||
|
119 | ||
|
120 | ||
|
121 | ||
|
122 | ||
|
123 | ||
|
124 | ||
|
125 | ||
|
126 | ||
|
127 |
@@ -0,0 +1,3 | |||
|
1 | CPU=stm32f4xxxG | |
|
2 | DEFINES+=BSP=\\\"STM32F4Discovery-ILI9328-8bits\\\" | |
|
3 | UCMODEL=stm32f4 |
@@ -1,312 +1,313 | |||
|
1 | 1 | /*------------------------------------------------------------------------------ |
|
2 | 2 | -- This file is a part of the libuc, microcontroler library |
|
3 | 3 | -- Copyright (C) 2011, Alexis Jeandet |
|
4 | 4 | -- |
|
5 | 5 | -- This program is free software; you can redistribute it and/or modify |
|
6 | 6 | -- it under the terms of the GNU General Public License as published by |
|
7 | 7 | -- the Free Software Foundation; either version 3 of the License, or |
|
8 | 8 | -- (at your option) any later version. |
|
9 | 9 | -- |
|
10 | 10 | -- This program is distributed in the hope that it will be useful, |
|
11 | 11 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 | 12 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
13 | 13 | -- GNU General Public License for more details. |
|
14 | 14 | -- |
|
15 | 15 | -- You should have received a copy of the GNU General Public License |
|
16 | 16 | -- along with this program; if not, write to the Free Software |
|
17 | 17 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
18 | 18 | ------------------------------------------------------------------------------- |
|
19 | 19 | -- Author : Alexis Jeandet |
|
20 | 20 | -- Mail : alexis.jeandet@member.fsf.org |
|
21 | 21 | -------------------------------------------------------------------------------*/ |
|
22 | 22 | #include "bsp.h" |
|
23 | 23 | #include <streamdevices.h> |
|
24 | 24 | #include <malloc.h> |
|
25 | 25 | #include <gpio.h> |
|
26 | 26 | #include <uart.h> |
|
27 | 27 | #include <stdio.h> |
|
28 | 28 | #include <stm32f4xx_gpio.h> |
|
29 | 29 | #include <stm32f4xx_fsmc.h> |
|
30 | 30 | #include <i2c.h> |
|
31 | 31 | #include <core.h> |
|
32 | 32 | #include <terminal.h> |
|
33 | 33 | |
|
34 | 34 | uint32_t OSC0 =8000000; |
|
35 | 35 | uint32_t INTOSC =16000000; |
|
36 | 36 | uint32_t RTCOSC =32768; |
|
37 | 37 | uint32_t currentCpuFreq=0; |
|
38 | 38 | extern streamdevice* __opnfiles__[__MAX_OPENED_FILES__]; |
|
39 | 39 | |
|
40 | 40 | LCD_IF_t lcdIF0={ |
|
41 | 41 | .init = &bsp_FSMC_init, |
|
42 | 42 | .writereg = &bsp_lcd0_write_reg, |
|
43 | 43 | .readreg = &bsp_lcd0_read_reg, |
|
44 | 44 | .writeGRAM = &bsp_lcd0_writeGRAM, |
|
45 | 45 | .readGRAM = &bsp_lcd0_readGRAM |
|
46 | 46 | }; |
|
47 | 47 | |
|
48 | 48 | LCD_t lcd0={ |
|
49 | 49 | .interface = &lcdIF0, |
|
50 | 50 | .init = &ili9328init, |
|
51 | 51 | .paint = &ili9328paint, |
|
52 | 52 | .paintText = &ili9328paintText, |
|
53 | 53 | .paintFilRect = &ili9328paintFilRect, |
|
54 | .getPix = &ili9328getPix, | |
|
54 | 55 | .refreshenable = &ili9328refreshenable, |
|
55 | 56 | .width= 240, |
|
56 | 57 | .height = 320 |
|
57 | 58 | }; |
|
58 | 59 | |
|
59 | 60 | terminal_t terminal0; |
|
60 | 61 | |
|
61 |
volatile int16_t* lcd0_CMD=(volatile int16_t*) |
|
|
62 |
volatile int16_t* lcd0_DATA=(volatile int16_t*) |
|
|
62 | volatile int16_t* lcd0_CMD=(volatile int16_t*)0x60000000; | |
|
63 | volatile int16_t* lcd0_DATA=(volatile int16_t*)0x61FFFFF0; | |
|
63 | 64 | |
|
64 | 65 | float VREF0 =(float)3.3; |
|
65 | 66 | |
|
66 | 67 | int bsp_init() |
|
67 | 68 | { |
|
68 | 69 | int i=0; |
|
69 | 70 | for(i=0;i<32;i++) |
|
70 | 71 | { |
|
71 | 72 | __opnfiles__[i] = NULL; |
|
72 | 73 | } |
|
73 | 74 | bsp_GPIO_init(); |
|
74 | 75 | bsp_uart_init(); |
|
75 | 76 | bsp_iic_init(); |
|
76 | 77 | bsp_FSMC_init(); |
|
77 | 78 | bsp_GTerm_init(); |
|
78 | 79 | printf("\r=====================\n\r"); |
|
79 | 80 | printf( "=====================\n\r"); |
|
80 | 81 | printf(BSP); |
|
81 | 82 | printf(" initialised\n\r"); |
|
82 | 83 | printf( "=====================\n\r"); |
|
83 | 84 | return 1; |
|
84 | 85 | } |
|
85 | 86 | |
|
86 | 87 | void bsp_GPIO_init() |
|
87 | 88 | { |
|
88 | 89 | gpio_t gpio1 = gpioopen(LED1); |
|
89 | 90 | gpio_t gpio2 = gpioopen(LED2); |
|
90 | 91 | gpio_t gpio3 = gpioopen(LED3); |
|
91 | 92 | gpio_t gpio4 = gpioopen(PSU_DISABLE); |
|
92 | 93 | gpio_t gpio5 = gpioopen(PSU_ALERT_5V); |
|
93 | 94 | gpio_t gpio6 = gpioopen(PSU_ALERT_1_5V); |
|
94 | 95 | gpio_t gpio7 = gpioopen(PSU_ALERT_3_3V); |
|
95 | 96 | gpiosetspeed(&gpio1,gpiohighspeed); |
|
96 | 97 | gpiosetspeed(&gpio2,gpiohighspeed); |
|
97 | 98 | gpiosetspeed(&gpio3,gpiohighspeed); |
|
98 | 99 | gpiosetspeed(&gpio4,gpiohighspeed); |
|
99 | 100 | gpiosetspeed(&gpio5,gpiohighspeed); |
|
100 | 101 | gpiosetspeed(&gpio6,gpiohighspeed); |
|
101 | 102 | gpiosetspeed(&gpio7,gpiohighspeed); |
|
102 | 103 | gpioclr(PSU_DISABLE); |
|
103 | 104 | gpiosetdir(&gpio1,gpiooutdir); |
|
104 | 105 | gpiosetdir(&gpio3,gpiooutdir); |
|
105 | 106 | gpiosetdir(&gpio2,gpiooutdir); |
|
106 | 107 | gpiosetdir(&gpio4,gpiooutdir); |
|
107 | 108 | gpiosetdir(&gpio5,gpioindir); |
|
108 | 109 | gpiosetdir(&gpio6,gpioindir); |
|
109 | 110 | gpiosetdir(&gpio7,gpioindir); |
|
110 | 111 | gpioclr(PSU_DISABLE); |
|
111 | 112 | } |
|
112 | 113 | |
|
113 | 114 | void bsp_uart_init() |
|
114 | 115 | { |
|
115 | 116 | //if(__opnfiles__[1]==NULL) |
|
116 | 117 | //{ |
|
117 | 118 | //uart_t* uart1 = (uart_t*)malloc(sizeof(uart_t)); |
|
118 | 119 | // streamdevice* fd1 = (streamdevice*)malloc(sizeof(streamdevice)); |
|
119 | 120 | // uart_t uart = uartopenandconfig(uart1,uartparitynone | uart8bits | uartonestop,115200,PA9,PA10,-1,-1); |
|
120 | 121 | //uartmkstreamdev(uart,fd1); |
|
121 | 122 | //__opnfiles__[1] = fd1; |
|
122 | 123 | //} |
|
123 | 124 | //else |
|
124 | 125 | //{ |
|
125 | 126 | uartopenandconfig(0,uartparitynone | uart8bits | uartonestop,115200,PA9,PA10,-1,-1); |
|
126 | 127 | //} |
|
127 | 128 | } |
|
128 | 129 | |
|
129 | 130 | |
|
130 | 131 | |
|
131 | 132 | int bsp_FSMC_init() |
|
132 | 133 | { |
|
133 | 134 | #define GPIOGETPORT(gpio) ((GPIO_TypeDef*)(((((uint32_t)gpio) & (uint32_t)0x0000FF00)*(uint32_t)4) + (uint32_t)GPIOA)) |
|
134 | 135 | #define GPIOPORTNUM(gpio) (((uint32_t)(gpio) & (uint32_t)0x0000FF00)>>(uint32_t)8) |
|
135 | 136 | |
|
136 | 137 | gpio_t gpio1 = gpioopen(LCD_RESET); |
|
137 | 138 | gpiosetspeed(&gpio1,gpiohighspeed); |
|
138 | 139 | gpiosetdir(&gpio1,gpiooutdir); |
|
139 | 140 | gpioclr(LCD_RESET); |
|
140 | 141 | |
|
141 | 142 | gpio_t LCD_DBxList[]={PD14,PD15,PD0,PD1,PE7,PE8,PE9,PE10,PE11,PE12,PE13,PE14,PE15\ |
|
142 | 143 | ,PD8,PD9,PD10,PD4,PD5,PD7,PE4}; |
|
143 | 144 | for(int i=0;i<20;i++) |
|
144 | 145 | { |
|
145 | 146 | gpio_t LCD_DBx = gpioopen(LCD_DBxList[i]); |
|
146 | 147 | LCD_DBx |= gpiohighspeed | gpioaf | gpiopushpulltype | gpionopulltype; |
|
147 | 148 | gpiosetconfig(&LCD_DBx); |
|
148 | 149 | GPIO_PinAFConfig(GPIOGETPORT(LCD_DBx), (uint8_t)(LCD_DBx & 0xF), GPIO_AF_FSMC); |
|
149 | 150 | } |
|
150 | 151 | |
|
151 | 152 | FSMC_NORSRAMInitTypeDef FSMC_NORSRAMInitStructure; |
|
152 | 153 | FSMC_NORSRAMTimingInitTypeDef p; |
|
153 | 154 | |
|
154 | 155 | /* Enable FSMC clock */ |
|
155 | 156 | RCC_AHB3PeriphClockCmd(RCC_AHB3Periph_FSMC, ENABLE); |
|
156 | 157 | |
|
157 | 158 | /*-- FSMC Configuration ------------------------------------------------------*/ |
|
158 | 159 | /*----------------------- SRAM Bank 3 ----------------------------------------*/ |
|
159 | 160 | /* FSMC_Bank1_NORSRAM4 configuration */ |
|
160 | 161 | //p.FSMC_AddressSetupTime = 5; |
|
161 | 162 | p.FSMC_AddressSetupTime = 1; |
|
162 | 163 | p.FSMC_AddressHoldTime = 0; |
|
163 | 164 | //p.FSMC_DataSetupTime = 9; |
|
164 | 165 | p.FSMC_DataSetupTime = getCpuFreq()/14545450 ;// 11; |
|
165 | 166 | p.FSMC_BusTurnAroundDuration = 0; |
|
166 | 167 | p.FSMC_CLKDivision = 0; |
|
167 | 168 | p.FSMC_DataLatency = 0; |
|
168 | 169 | p.FSMC_AccessMode = FSMC_AccessMode_A; |
|
169 | 170 | /* Color LCD configuration ------------------------------------ |
|
170 | 171 | LCD configured as follow: |
|
171 | 172 | - Data/Address MUX = Disable |
|
172 | 173 | - Memory Type = SRAM |
|
173 | 174 | - Data Width = 16bit |
|
174 | 175 | - Write Operation = Enable |
|
175 | 176 | - Extended Mode = Enable |
|
176 | 177 | - Asynchronous Wait = Disable */ |
|
177 | 178 | |
|
178 | 179 | FSMC_NORSRAMInitStructure.FSMC_Bank = FSMC_Bank1_NORSRAM1; |
|
179 | 180 | FSMC_NORSRAMInitStructure.FSMC_DataAddressMux = FSMC_DataAddressMux_Disable; |
|
180 | 181 | FSMC_NORSRAMInitStructure.FSMC_MemoryType = FSMC_MemoryType_SRAM; |
|
181 | 182 | FSMC_NORSRAMInitStructure.FSMC_MemoryDataWidth = FSMC_MemoryDataWidth_16b; |
|
182 | 183 | FSMC_NORSRAMInitStructure.FSMC_BurstAccessMode = FSMC_BurstAccessMode_Disable; |
|
183 | 184 | FSMC_NORSRAMInitStructure.FSMC_AsynchronousWait = FSMC_AsynchronousWait_Disable; |
|
184 | 185 | FSMC_NORSRAMInitStructure.FSMC_WaitSignalPolarity = FSMC_WaitSignalPolarity_Low; |
|
185 | 186 | FSMC_NORSRAMInitStructure.FSMC_WrapMode = FSMC_WrapMode_Disable; |
|
186 | 187 | FSMC_NORSRAMInitStructure.FSMC_WaitSignalActive = FSMC_WaitSignalActive_BeforeWaitState; |
|
187 | 188 | FSMC_NORSRAMInitStructure.FSMC_WriteOperation = FSMC_WriteOperation_Enable; |
|
188 | 189 | FSMC_NORSRAMInitStructure.FSMC_WaitSignal = FSMC_WaitSignal_Disable; |
|
189 | 190 | FSMC_NORSRAMInitStructure.FSMC_ExtendedMode = FSMC_ExtendedMode_Disable; |
|
190 | 191 | FSMC_NORSRAMInitStructure.FSMC_WriteBurst = FSMC_WriteBurst_Disable; |
|
191 | 192 | FSMC_NORSRAMInitStructure.FSMC_ReadWriteTimingStruct = &p; |
|
192 | 193 | FSMC_NORSRAMInitStructure.FSMC_WriteTimingStruct = &p; |
|
193 | 194 | |
|
194 | 195 | FSMC_NORSRAMInit(&FSMC_NORSRAMInitStructure); |
|
195 | 196 | |
|
196 | 197 | /* Enable FSMC NOR/SRAM Bank1 */ |
|
197 | 198 | FSMC_NORSRAMCmd(FSMC_Bank1_NORSRAM1, ENABLE); |
|
198 | 199 | gpioset(LCD_RESET); |
|
199 | 200 | lcd0.init(&lcd0); |
|
200 | 201 | return 1; |
|
201 | 202 | } |
|
202 | 203 | |
|
203 | 204 | void bsp_spi_init() |
|
204 | 205 | { |
|
205 | 206 | |
|
206 | 207 | } |
|
207 | 208 | |
|
208 | 209 | |
|
209 | 210 | void bsp_iic_init() |
|
210 | 211 | { |
|
211 | 212 | i2copenandconfig(i2c2,0,10000,PF0,PF1); |
|
212 | 213 | } |
|
213 | 214 | |
|
214 | 215 | void bsp_SD_init() |
|
215 | 216 | { |
|
216 | 217 | |
|
217 | 218 | } |
|
218 | 219 | |
|
219 | 220 | void vs10XXclearXCS(){} |
|
220 | 221 | void vs10XXsetXCS(){} |
|
221 | 222 | int vs10XXDREQ() |
|
222 | 223 | { |
|
223 | 224 | return 1; |
|
224 | 225 | } |
|
225 | 226 | |
|
226 | 227 | |
|
227 | 228 | void bsppowersdcard(char onoff) //always ON |
|
228 | 229 | { |
|
229 | 230 | |
|
230 | 231 | } |
|
231 | 232 | |
|
232 | 233 | char bspsdcardpresent() |
|
233 | 234 | { |
|
234 | 235 | return 0; |
|
235 | 236 | } |
|
236 | 237 | |
|
237 | 238 | char bspsdcardwriteprotected() |
|
238 | 239 | { |
|
239 | 240 | return 0; |
|
240 | 241 | } |
|
241 | 242 | |
|
242 | 243 | void bspsdcardselect(char YESNO) |
|
243 | 244 | { |
|
244 | 245 | |
|
245 | 246 | } |
|
246 | 247 | |
|
247 | 248 | |
|
248 | 249 | void bsp_lcd0_write_reg(uint32_t reg,uint32_t data) |
|
249 | 250 | { |
|
250 | 251 | *lcd0_CMD=(uint16_t)reg; |
|
251 | 252 | *lcd0_DATA=(uint16_t)data; |
|
252 | 253 | } |
|
253 | 254 | |
|
254 | 255 | uint32_t bsp_lcd0_read_reg(uint32_t reg) |
|
255 | 256 | { |
|
256 | 257 | *lcd0_CMD=(uint16_t)reg; |
|
257 | 258 | return (uint16_t)*lcd0_DATA; |
|
258 | 259 | } |
|
259 | 260 | |
|
260 | 261 | void bsp_lcd0_writeGRAM(void* buffer,uint32_t count) |
|
261 | 262 | { |
|
262 | 263 | *lcd0_CMD=(uint16_t)ILI9328_REGISTER_WRITEDATATOGRAM; |
|
263 | 264 | uint16_t* castedBuff=(uint16_t*)buffer; |
|
264 | 265 | for(int i=0;i<(int)count;i++) |
|
265 | 266 | { |
|
266 | 267 | *lcd0_DATA=castedBuff[i]; |
|
267 | 268 | } |
|
268 | 269 | } |
|
269 | 270 | |
|
270 | 271 | void bsp_lcd0_readGRAM(void* buffer,uint32_t count) |
|
271 | 272 | { |
|
272 | 273 | *lcd0_CMD=(uint16_t)ILI9328_REGISTER_WRITEDATATOGRAM; |
|
273 | 274 | uint16_t* castedBuff=(uint16_t*)buffer; |
|
274 | 275 | castedBuff[0]=*lcd0_DATA; |
|
275 | 276 | for(int i=0;i<(int)count;i++) |
|
276 | 277 | { |
|
277 | 278 | castedBuff[i]=*lcd0_DATA; |
|
278 | 279 | } |
|
279 | 280 | } |
|
280 | 281 | |
|
281 | 282 | |
|
282 | 283 | void bsp_GTerm_init() |
|
283 | 284 | { |
|
284 | 285 | if(__opnfiles__[1]==NULL) |
|
285 | 286 | { |
|
286 | 287 | //uart_t* uart1 = (uart_t*)malloc(sizeof(uart_t)); |
|
287 | 288 | streamdevice* fd1 = (streamdevice*)malloc(sizeof(streamdevice)); |
|
288 | 289 | terminal_init(&terminal0 ,&lcd0,&ComicSansMS_8,fd1); |
|
289 | 290 | __opnfiles__[1] = fd1; |
|
290 | 291 | } |
|
291 | 292 | else |
|
292 | 293 | { |
|
293 | 294 | |
|
294 | 295 | } |
|
295 | 296 | } |
|
296 | 297 | |
|
297 | 298 | |
|
298 | 299 | |
|
299 | 300 | |
|
300 | 301 | |
|
301 | 302 | |
|
302 | 303 | |
|
303 | 304 | |
|
304 | 305 | |
|
305 | 306 | |
|
306 | 307 | |
|
307 | 308 | |
|
308 | 309 | |
|
309 | 310 | |
|
310 | 311 | |
|
311 | 312 | |
|
312 | 313 |
@@ -1,534 +1,555 | |||
|
1 | 1 | /*------------------------------------------------------------------------------ |
|
2 | 2 | -- This file is a part of the libuc, microcontroler library |
|
3 | 3 | -- Copyright (C) 2011, Alexis Jeandet |
|
4 | 4 | -- |
|
5 | 5 | -- This program is free software; you can redistribute it and/or modify |
|
6 | 6 | -- it under the terms of the GNU General Public License as published by |
|
7 | 7 | -- the Free Software Foundation; either version 3 of the License, or |
|
8 | 8 | -- (at your option) any later version. |
|
9 | 9 | -- |
|
10 | 10 | -- This program is distributed in the hope that it will be useful, |
|
11 | 11 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 | 12 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
13 | 13 | -- GNU General Public License for more details. |
|
14 | 14 | -- |
|
15 | 15 | -- You should have received a copy of the GNU General Public License |
|
16 | 16 | -- along with this program; if not, write to the Free Software |
|
17 | 17 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
18 | 18 | ------------------------------------------------------------------------------- |
|
19 | 19 | -- Author : Alexis Jeandet |
|
20 | 20 | -- Mail : alexis.jeandet@member.fsf.org |
|
21 | 21 | -------------------------------------------------------------------------------*/ |
|
22 | 22 | #include "bsp.h" |
|
23 | 23 | #include <streamdevices.h> |
|
24 | 24 | #include <malloc.h> |
|
25 | 25 | #include <gpio.h> |
|
26 | 26 | #include <uart.h> |
|
27 | 27 | #include <stdio.h> |
|
28 | 28 | #include <stm32f4xx_gpio.h> |
|
29 | 29 | #include <stm32f4xx_fsmc.h> |
|
30 | 30 | #include <i2c.h> |
|
31 | 31 | #include <core.h> |
|
32 | 32 | #include <terminal.h> |
|
33 | 33 | |
|
34 | 34 | uint32_t OSC0 =8000000; |
|
35 | 35 | uint32_t INTOSC =16000000; |
|
36 | 36 | uint32_t RTCOSC =32768; |
|
37 | 37 | uint32_t currentCpuFreq=0; |
|
38 | 38 | extern streamdevice* __opnfiles__[__MAX_OPENED_FILES__]; |
|
39 | 39 | |
|
40 | 40 | LCD_IF_t lcdIF0={ |
|
41 | 41 | .init = &bsp_FSMC_init, |
|
42 | 42 | .writereg = &bsp_lcd0_write_reg, |
|
43 | 43 | .readreg = &bsp_lcd0_read_reg, |
|
44 | 44 | .writeGRAM = &bsp_lcd0_writeGRAM, |
|
45 | 45 | .readGRAM = &bsp_lcd0_readGRAM |
|
46 | 46 | }; |
|
47 | 47 | |
|
48 | 48 | LCD_t lcd0={ |
|
49 | 49 | .interface = &lcdIF0, |
|
50 | 50 | .init = &ili9328init, |
|
51 | 51 | .paint = &ili9328paint, |
|
52 | 52 | .paintText = &ili9328paintText, |
|
53 | 53 | .paintFilRect = &ili9328paintFilRect, |
|
54 | .getPix = &ili9328getPix, | |
|
54 | 55 | .refreshenable = &ili9328refreshenable, |
|
55 | 56 | .width= 240, |
|
56 | 57 | .height = 320 |
|
57 | 58 | }; |
|
58 | 59 | |
|
59 | 60 | terminal_t terminal0; |
|
60 | 61 | |
|
61 |
volatile uint8_t* lcd0_CMD=(volatile uint8_t*) |
|
|
62 |
volatile uint8_t* lcd0_DATA=(volatile uint8_t*) |
|
|
62 | volatile uint8_t* lcd0_CMD=(volatile uint8_t*)0x60000000; | |
|
63 | volatile uint8_t* lcd0_DATA=(volatile uint8_t*)0x61FFFFF0; | |
|
63 | 64 | |
|
64 | 65 | float VREF0 =(float)3.3; |
|
65 | 66 | volatile vs10XXDev audioCodec0; |
|
66 | 67 | |
|
67 | 68 | sdcardDev sdcard2; |
|
68 | 69 | blkdevice sdcard2blkdev; |
|
69 | 70 | dikpartition sdcard2Part1; |
|
70 | 71 | FAT32fs sdcard2FAT32part1; |
|
71 | 72 | dikpartition sdcard2Part2; |
|
72 | 73 | FAT32fs sdcard2FAT32part2; |
|
73 | 74 | dikpartition sdcard2Part3; |
|
74 | 75 | FAT32fs sdcard2FAT32part3; |
|
75 | 76 | dikpartition sdcard2Part4; |
|
76 | 77 | FAT32fs sdcard2FAT32part4; |
|
77 | 78 | |
|
78 | 79 | int bsp_init() |
|
79 | 80 | { |
|
80 | 81 | int i=0; |
|
81 | 82 | for(i=0;i<__MAX_OPENED_FILES__;i++) |
|
82 | 83 | { |
|
83 | 84 | __opnfiles__[i] = NULL; |
|
84 | 85 | } |
|
85 | 86 | bsp_GPIO_init(); |
|
86 | 87 | bsp_uart_init(); |
|
87 | 88 | bsp_iic_init(); |
|
88 | 89 | bsp_FSMC_init(); |
|
89 | 90 | bsp_GTerm_init(); |
|
90 | 91 | bsp_spi_init(); |
|
91 | 92 | bsp_SD_init(); |
|
92 | 93 | bsp_Audio_init(); |
|
93 | 94 | printf("\r=====================\n\r"); |
|
94 | 95 | printf( "=====================\n\r"); |
|
95 | 96 | printf(BSP); |
|
96 | 97 | printf(" initialised\n\r"); |
|
97 | 98 | printf( "=====================\n\r"); |
|
99 | #if __BYTE_ORDER__==__ORDER_BIG_ENDIAN__ | |
|
100 | printf( "BIG ENDIAN MACHINE\n\r"); | |
|
101 | #else | |
|
102 | printf( "LITLE ENDIAN MACHINE\n\r"); | |
|
103 | #endif | |
|
98 | 104 | return 1; |
|
99 | 105 | } |
|
100 | 106 | |
|
101 | 107 | void bsp_GPIO_init() |
|
102 | 108 | { |
|
103 | 109 | gpio_t GPIO_Out_init_List[]={LED1,LED2,LCD_RESET,LCD_BACKL,VS1053xCS,VS1053xDCS,VS1053xRESET,SDCARD2CS}; |
|
104 | 110 | for(int i=0;i<8;i++) |
|
105 | 111 | { |
|
106 | 112 | gpio_t GPIO_init = gpioopen(GPIO_Out_init_List[i]); |
|
107 | 113 | GPIO_init |= gpiohighspeed | gpiooutdir | gpiopushpulltype; |
|
108 | 114 | gpiosetconfig(&GPIO_init); |
|
109 | 115 | } |
|
110 | 116 | gpio_t GPIO_In_init_List[]={VS1053DREQ,SDCARD2CD,BP3}; |
|
111 | 117 | for(int i=0;i<3;i++) |
|
112 | 118 | { |
|
113 | 119 | gpio_t GPIO_init = gpioopen(GPIO_In_init_List[i]); |
|
114 | 120 | GPIO_init |= gpiohighspeed | gpioindir; |
|
115 | 121 | gpiosetconfig(&GPIO_init); |
|
116 | 122 | } |
|
117 | 123 | gpioclr(VS1053xRESET); |
|
118 | 124 | gpioset(VS1053xCS); |
|
119 | 125 | gpioset(VS1053xDCS); |
|
120 | 126 | gpioset(SDCARD2CS); |
|
121 | 127 | gpioclr(LCD_RESET); |
|
122 | 128 | gpioclr(LCD_BACKL); |
|
123 | 129 | } |
|
124 | 130 | |
|
125 | 131 | void bsp_uart_init() |
|
126 | 132 | { |
|
127 | // if(__opnfiles__[1]==NULL) | |
|
128 | // { | |
|
129 | // //uart_t* uart1 = (uart_t*)malloc(sizeof(uart_t)); | |
|
130 | // streamdevice* fd1 = (streamdevice*)malloc(sizeof(streamdevice)); | |
|
131 | // uart_t uart = uartopenandconfig(uart3,uartparitynone | uart8bits | uartonestop,115200,PD8,PD9,-1,-1); | |
|
132 | // uartmkstreamdev(uart,fd1); | |
|
133 | // __opnfiles__[1] = fd1; | |
|
134 | // } | |
|
135 | // else | |
|
136 | // { | |
|
137 | // uartopenandconfig(uart3,uartparitynone | uart8bits | uartonestop,115200,PD8,PD9,-1,-1); | |
|
138 | // } | |
|
133 | // if(__opnfiles__[1]==NULL) | |
|
134 | // { | |
|
135 | // //uart_t* uart1 = (uart_t*)malloc(sizeof(uart_t)); | |
|
136 | // streamdevice* fd1 = (streamdevice*)malloc(sizeof(streamdevice)); | |
|
137 | // uart_t uart = uartopenandconfig(uart3,uartparitynone | uart8bits | uartonestop,115200,PD8,PD9,-1,-1); | |
|
138 | // uartmkstreamdev(uart,fd1); | |
|
139 | // __opnfiles__[1] = fd1; | |
|
140 | // } | |
|
141 | // else | |
|
142 | // { | |
|
143 | // uartopenandconfig(uart3,uartparitynone | uart8bits | uartonestop,115200,PD8,PD9,-1,-1); | |
|
144 | // } | |
|
139 | 145 | } |
|
140 | 146 | |
|
141 | 147 | /* |
|
142 | 148 | D0 PD14 D1 PD15 D2 PD0 D3 PD1 D4 PE7 |
|
143 | 149 | D5 PE8 D6 PE9 D7 PE10 |
|
144 | 150 | A20 PE4 = RS FSMC_NE1 PD7 CS FSMC_NWE PD5 W/S |
|
145 | 151 | FSMC_NOE PD4 RD |
|
146 | 152 | */ |
|
147 | 153 | |
|
148 | 154 | int bsp_FSMC_init() |
|
149 | 155 | { |
|
150 | 156 | #define GPIOGETPORT(gpio) ((GPIO_TypeDef*)(((((uint32_t)gpio) & (uint32_t)0x0000FF00)*(uint32_t)4) + (uint32_t)GPIOA)) |
|
151 | 157 | #define GPIOPORTNUM(gpio) (((uint32_t)(gpio) & (uint32_t)0x0000FF00)>>(uint32_t)8) |
|
152 | 158 | |
|
153 | 159 | gpio_t LCD_DBxList[]={PD14,PD15,PD0,PD1,PE7,PE8,PE9,PE10\ |
|
154 | 160 | ,PD4,PD5,PD7,PE4}; |
|
155 | 161 | for(int i=0;i<12;i++) |
|
156 | 162 | { |
|
157 | 163 | gpio_t LCD_DBx = gpioopen(LCD_DBxList[i]); |
|
158 | 164 | LCD_DBx |= gpiohighspeed | gpioaf | gpiopushpulltype | gpionopulltype; |
|
159 | 165 | gpiosetconfig(&LCD_DBx); |
|
160 | 166 | GPIO_PinAFConfig(GPIOGETPORT(LCD_DBx), (uint8_t)(LCD_DBx & 0xF), GPIO_AF_FSMC); |
|
161 | 167 | } |
|
162 | 168 | |
|
163 | 169 | FSMC_NORSRAMInitTypeDef FSMC_NORSRAMInitStructure; |
|
164 | FSMC_NORSRAMTimingInitTypeDef p; | |
|
170 | FSMC_NORSRAMTimingInitTypeDef p,readtim; | |
|
165 | 171 | |
|
166 | 172 | /* Enable FSMC clock */ |
|
167 | 173 | RCC_AHB3PeriphClockCmd(RCC_AHB3Periph_FSMC, ENABLE); |
|
168 | 174 | |
|
169 | 175 | /*-- FSMC Configuration ------------------------------------------------------*/ |
|
170 | 176 | /*----------------------- SRAM Bank 3 ----------------------------------------*/ |
|
171 | 177 | /* FSMC_Bank1_NORSRAM4 configuration */ |
|
172 |
|
|
|
173 |
|
|
|
174 | p.FSMC_AddressSetupTime = 3; | |
|
175 | p.FSMC_AddressHoldTime = 3; | |
|
176 | //p.FSMC_DataSetupTime = 9; | |
|
178 | p.FSMC_AddressSetupTime = 0xf; | |
|
179 | p.FSMC_AddressHoldTime = 0xf; | |
|
177 | 180 | //ili9328 -> data setup time > 10ns |
|
178 |
p.FSMC_DataSetupTime = |
|
|
181 | p.FSMC_DataSetupTime = 0xf; | |
|
179 | 182 | if(getCpuFreq()>100*1000*1000) |
|
180 |
p.FSMC_DataSetupTime = |
|
|
181 | p.FSMC_BusTurnAroundDuration = 0; | |
|
183 | p.FSMC_DataSetupTime = 0xf;// 11; | |
|
184 | p.FSMC_BusTurnAroundDuration = 0xf; | |
|
182 | 185 | p.FSMC_CLKDivision = 0; |
|
183 | p.FSMC_DataLatency = 0; | |
|
186 | p.FSMC_DataLatency = 0xf; | |
|
184 | 187 | //ili9328 -> data hold time > 15ns |
|
185 | 188 | if(getCpuFreq()>66*1000*1000) |
|
186 |
p.FSMC_DataLatency = |
|
|
189 | p.FSMC_DataLatency = 0xf; | |
|
187 | 190 | p.FSMC_AccessMode = FSMC_AccessMode_A; |
|
188 | 191 | |
|
192 | readtim.FSMC_AddressSetupTime = 0xf; | |
|
193 | readtim.FSMC_AddressHoldTime = 0xf; | |
|
194 | //p.FSMC_DataSetupTime = 9; | |
|
195 | readtim.FSMC_DataSetupTime = 0xf ;// 11; | |
|
196 | if(getCpuFreq()>100*1000*1000) | |
|
197 | readtim.FSMC_DataSetupTime = 0xf;// 11; | |
|
198 | readtim.FSMC_BusTurnAroundDuration = 0xf; | |
|
199 | readtim.FSMC_CLKDivision = 0; | |
|
200 | readtim.FSMC_DataLatency = 0xf; | |
|
201 | if(getCpuFreq()>66*1000*1000) | |
|
202 | readtim.FSMC_DataLatency = 0xf; | |
|
203 | readtim.FSMC_AccessMode = FSMC_AccessMode_A; | |
|
204 | ||
|
205 | ||
|
189 | 206 | FSMC_NORSRAMInitStructure.FSMC_Bank = FSMC_Bank1_NORSRAM1; |
|
190 | 207 | FSMC_NORSRAMInitStructure.FSMC_DataAddressMux = FSMC_DataAddressMux_Disable; |
|
191 | 208 | FSMC_NORSRAMInitStructure.FSMC_MemoryType = FSMC_MemoryType_SRAM; |
|
192 | 209 | FSMC_NORSRAMInitStructure.FSMC_MemoryDataWidth = FSMC_MemoryDataWidth_8b; |
|
193 | 210 | FSMC_NORSRAMInitStructure.FSMC_BurstAccessMode = FSMC_BurstAccessMode_Disable; |
|
194 | 211 | FSMC_NORSRAMInitStructure.FSMC_AsynchronousWait = FSMC_AsynchronousWait_Disable; |
|
195 | 212 | FSMC_NORSRAMInitStructure.FSMC_WaitSignalPolarity = FSMC_WaitSignalPolarity_Low; |
|
196 | 213 | FSMC_NORSRAMInitStructure.FSMC_WrapMode = FSMC_WrapMode_Disable; |
|
197 | 214 | FSMC_NORSRAMInitStructure.FSMC_WaitSignalActive = FSMC_WaitSignalActive_BeforeWaitState; |
|
198 | 215 | FSMC_NORSRAMInitStructure.FSMC_WriteOperation = FSMC_WriteOperation_Enable; |
|
199 | 216 | FSMC_NORSRAMInitStructure.FSMC_WaitSignal = FSMC_WaitSignal_Disable; |
|
200 | 217 | FSMC_NORSRAMInitStructure.FSMC_ExtendedMode = FSMC_ExtendedMode_Disable; |
|
201 | 218 | FSMC_NORSRAMInitStructure.FSMC_WriteBurst = FSMC_WriteBurst_Disable; |
|
202 |
FSMC_NORSRAMInitStructure.FSMC_ReadWriteTimingStruct = & |
|
|
219 | FSMC_NORSRAMInitStructure.FSMC_ReadWriteTimingStruct = &readtim; | |
|
203 | 220 | FSMC_NORSRAMInitStructure.FSMC_WriteTimingStruct = &p; |
|
204 | 221 | |
|
205 | 222 | FSMC_NORSRAMInit(&FSMC_NORSRAMInitStructure); |
|
206 | 223 | |
|
207 | 224 | FSMC_NORSRAMCmd(FSMC_Bank1_NORSRAM1, ENABLE); |
|
208 | 225 | gpioset(LCD_RESET); |
|
209 | 226 | gpioclr(LCD_RESET); |
|
210 | 227 | delay_100us(500); |
|
211 | 228 | gpioset(LCD_RESET); |
|
212 | 229 | delay_100us(500); |
|
213 | 230 | lcd0.init(&lcd0); |
|
214 | 231 | gpioset(LCD_BACKL); |
|
215 | 232 | return 1; |
|
216 | 233 | } |
|
217 | 234 | |
|
218 | 235 | void bsp_spi_init() |
|
219 | 236 | { |
|
220 | 237 | gpio_t VSSPI_DBxList[]={VS1053SCK,VS1053MOSI,VS1053MISO}; |
|
221 | 238 | for(int i=0;i<3;i++) |
|
222 | 239 | { |
|
223 | 240 | gpio_t SPI_DBx = gpioopen(VSSPI_DBxList[i]); |
|
224 | 241 | SPI_DBx |= gpiohighspeed | gpioaf | gpiopushpulltype | gpionopulltype; |
|
225 | 242 | gpiosetconfig(&SPI_DBx); |
|
226 | 243 | GPIO_PinAFConfig(GPIOGETPORT(SPI_DBx), (uint8_t)(SPI_DBx & 0xF), GPIO_AF_SPI1); |
|
227 | 244 | } |
|
228 | 245 | spiopenandconfig(VS1053SPI,spi8bits|spimaster|spimsbfirst,2*1000*1000,VS1053MOSI,VS1053MISO,VS1053SCK,-1); |
|
229 | 246 | |
|
230 | 247 | gpio_t SDSPI_DBxList[]={SDCARD2SCK,SDCARD2MOSI,SDCARD2MISO}; |
|
231 | 248 | for(int i=0;i<3;i++) |
|
232 | 249 | { |
|
233 | 250 | gpio_t SPI_DBx = gpioopen(SDSPI_DBxList[i]); |
|
234 | 251 | SPI_DBx |= gpiohighspeed | gpioaf | gpiopushpulltype | gpionopulltype; |
|
235 | 252 | gpiosetconfig(&SPI_DBx); |
|
236 | 253 | GPIO_PinAFConfig(GPIOGETPORT(SPI_DBx), (uint8_t)(SPI_DBx & 0xF), GPIO_AF_SPI3); |
|
237 | 254 | } |
|
238 | 255 | spiopenandconfig(SDCARD2SPI,spi8bits|spimaster|spimsbfirst,400*1000,SDCARD2MOSI,SDCARD2MISO,SDCARD2SCK,-1); |
|
239 | 256 | |
|
240 | 257 | } |
|
241 | 258 | |
|
242 | 259 | |
|
243 | 260 | void bsp_iic_init() |
|
244 | 261 | { |
|
245 | 262 | // i2copenandconfig(i2c2,0,10000,PF0,PF1); |
|
246 | 263 | } |
|
247 | 264 | |
|
248 | 265 | |
|
249 | 266 | void bsp_Audio_init() |
|
250 | 267 | { |
|
251 | 268 | vs10XXopen(&audioCodec0,VS1053SPI,vs1052setXCS,vs1052setRST,vs1052setXDCS,vs10XXDREQ); |
|
252 | 269 | if(audioCodec0.VERSION!=UNKNOWN) |
|
253 | 270 | { |
|
254 | 271 | printf("detected Audio codec "); |
|
255 | 272 | switch (audioCodec0.VERSION) { |
|
256 | 273 | case VS1001: |
|
257 | 274 | printf("VS1001\n"); |
|
258 | 275 | break; |
|
259 | 276 | case VS1011: |
|
260 | 277 | printf("VS1011\n"); |
|
261 | 278 | break; |
|
262 | 279 | case VS1002: |
|
263 | 280 | printf("VS1002\n"); |
|
264 | 281 | break; |
|
265 | 282 | case VS1003: |
|
266 | 283 | printf("VS1003\n"); |
|
267 | 284 | break; |
|
268 | 285 | case VS1053: |
|
269 | 286 | printf("VS1053\n"); |
|
270 | 287 | break; |
|
271 | 288 | case VS1033: |
|
272 | 289 | printf("VS1033\n"); |
|
273 | 290 | break; |
|
274 | 291 | case VS1103: |
|
275 | 292 | printf("VS1103\n"); |
|
276 | 293 | break; |
|
277 | 294 | default: |
|
278 | 295 | printf("Unknown device\n"); |
|
279 | 296 | break; |
|
280 | 297 | } |
|
281 | 298 | } |
|
282 | 299 | } |
|
283 | 300 | |
|
284 | 301 | void bsp_SD_init() |
|
285 | 302 | { |
|
286 | 303 | if(bspsdcardpresent()) |
|
287 | 304 | { |
|
288 | 305 | sdcardspimake(&sdcard2,(UHANDLE)SDCARD2SPI,spigetnc,spiputnc,spisetspeed,spigetspeed); |
|
289 | 306 | sdcardspimakeblkdev(&sdcard2blkdev,&sdcard2,bspsdcardselect,bsppowersdcard,bspsdcardpresent,bspsdcardwriteprotected); |
|
290 | 307 | if(sdcard2blkdev.initialize(&sdcard2blkdev)!=STA_NOINIT) |
|
291 | 308 | { |
|
292 | 309 | if(mbropen(&sdcard2blkdev,&sdcard2Part1,1)==MBRnoErr) |
|
293 | 310 | { |
|
294 | 311 | if(FATnoErr!=fat32open(&sdcard2FAT32part1,&sdcard2Part1)) |
|
295 | 312 | printf("Can't open fat32 partition 1\n"); |
|
296 | 313 | } |
|
297 | 314 | else |
|
298 | 315 | { |
|
299 | 316 | printf("Can't open or read MBR\n"); |
|
300 | 317 | } |
|
301 |
delay_100us(1000 |
|
|
318 | delay_100us(1000); | |
|
302 | 319 | if(mbropen(&sdcard2blkdev,&sdcard2Part2,2)==MBRnoErr) |
|
303 | 320 | { |
|
304 | 321 | if(FATnoErr!=fat32open(&sdcard2FAT32part2,&sdcard2Part2)) |
|
305 | 322 | printf("Can't open fat32 partition 2\n"); |
|
306 | 323 | } |
|
307 | 324 | else |
|
308 | 325 | { |
|
309 | 326 | printf("Can't open or read MBR\n"); |
|
310 | 327 | } |
|
311 |
delay_100us(1000 |
|
|
328 | delay_100us(1000); | |
|
312 | 329 | if(mbropen(&sdcard2blkdev,&sdcard2Part3,3)==MBRnoErr) |
|
313 | 330 | { |
|
314 | 331 | if(FATnoErr!=fat32open(&sdcard2FAT32part3,&sdcard2Part3)) |
|
315 | 332 | printf("Can't open fat32 partition 3\n"); |
|
316 | 333 | } |
|
317 | 334 | else |
|
318 | 335 | { |
|
319 | 336 | printf("Can't open or read MBR\n"); |
|
320 | 337 | } |
|
321 |
delay_100us(1000 |
|
|
338 | delay_100us(1000); | |
|
322 | 339 | if(mbropen(&sdcard2blkdev,&sdcard2Part4,4)==MBRnoErr) |
|
323 | 340 | { |
|
324 | 341 | if(FATnoErr!=fat32open(&sdcard2FAT32part4,&sdcard2Part4)) |
|
325 | 342 | printf("Can't open fat32 partition 4\n"); |
|
326 | 343 | } |
|
327 | 344 | else |
|
328 | 345 | { |
|
329 | 346 | printf("Can't open or read MBR\n"); |
|
330 | 347 | } |
|
331 | 348 | } |
|
332 | 349 | else |
|
333 | 350 | { |
|
334 | 351 | printf("Can't initialize SDCARD\n"); |
|
335 | 352 | } |
|
336 | 353 | } |
|
337 |
delay_100us(2000 |
|
|
354 | delay_100us(2000); | |
|
338 | 355 | } |
|
339 | 356 | |
|
340 | 357 | void vs1052setXCS(char val) |
|
341 | 358 | { |
|
342 | 359 | gpiosetval(VS1053xCS,(int)val); |
|
343 | 360 | } |
|
344 | 361 | |
|
345 | 362 | void vs1052setXDCS(char val) |
|
346 | 363 | { |
|
347 | 364 | //gpiosetval(LED1,(int)val); |
|
348 | 365 | gpiosetval(VS1053xDCS,(int)val); |
|
349 | 366 | } |
|
350 | 367 | |
|
351 | 368 | void vs1052setRST(char val) |
|
352 | 369 | { |
|
353 | 370 | if(val) |
|
354 | 371 | gpioset(VS1053xRESET); |
|
355 | 372 | else |
|
356 | 373 | gpioclr(VS1053xRESET); |
|
357 | 374 | } |
|
358 | 375 | |
|
359 | 376 | int vs10XXDREQ() |
|
360 | 377 | { |
|
361 | 378 | return gpiogetval(VS1053DREQ); |
|
362 | 379 | } |
|
363 | 380 | |
|
364 | 381 | |
|
365 | 382 | void bsppowersdcard(char onoff) //always ON |
|
366 | 383 | { |
|
367 | 384 | |
|
368 | 385 | } |
|
369 | 386 | |
|
370 | 387 | char bspsdcardpresent() |
|
371 | 388 | { |
|
372 | 389 | return gpiogetval(SDCARD2CD); |
|
373 | 390 | } |
|
374 | 391 | |
|
375 | 392 | char bspsdcardwriteprotected() |
|
376 | 393 | { |
|
377 | 394 | return 0; |
|
378 | 395 | } |
|
379 | 396 | |
|
380 | 397 | void bspsdcardselect(char YESNO) |
|
381 | 398 | { |
|
382 | // gpiosetval(LED1,(int)YESNO); | |
|
399 | // gpiosetval(LED1,(int)YESNO); | |
|
383 | 400 | if(YESNO) |
|
384 | 401 | gpioclr(SDCARD2CS); |
|
385 | 402 | else |
|
386 | 403 | gpioset(SDCARD2CS); |
|
387 | 404 | } |
|
388 | 405 | |
|
389 | 406 | |
|
390 | 407 | void bsp_lcd0_write_reg(uint32_t reg,uint32_t data) |
|
391 | 408 | { |
|
392 | uint8_t* pt8 = (uint8_t*)(void*)® | |
|
409 | uint8_t* pt8 = (uint8_t*)(void*)(®); | |
|
410 | *lcd0_CMD=(uint8_t)0; | |
|
411 | *lcd0_CMD=(uint8_t)0; | |
|
412 | *lcd0_CMD=(uint8_t)0; | |
|
413 | *lcd0_CMD=(uint8_t)0; | |
|
393 | 414 | #if __BYTE_ORDER__==__ORDER_BIG_ENDIAN__ |
|
394 | 415 | *lcd0_CMD=pt8[3]; |
|
395 | 416 | *lcd0_CMD=pt8[2]; |
|
396 | 417 | pt8 = (uint8_t*)(void*)&data; |
|
397 | 418 | *lcd0_DATA=pt8[3]; |
|
398 | 419 | *lcd0_DATA=pt8[2]; |
|
399 | 420 | #else |
|
400 | 421 | *lcd0_CMD=pt8[1]; |
|
401 | 422 | *lcd0_CMD=pt8[0]; |
|
402 | 423 | pt8 = (uint8_t*)(void*)&data; |
|
403 | 424 | *lcd0_DATA=pt8[1]; |
|
404 | 425 | *lcd0_DATA=pt8[0]; |
|
405 | 426 | #endif |
|
406 | 427 | |
|
407 | 428 | } |
|
408 | 429 | |
|
409 | 430 | uint32_t bsp_lcd0_read_reg(uint32_t reg) |
|
410 | 431 | { |
|
411 | uint8_t* pt8 = (uint8_t*)(void*)® | |
|
432 | uint8_t* pt8 = (uint8_t*)(void*)(®); | |
|
412 | 433 | uint32_t DATA=0; |
|
434 | *lcd0_CMD=(uint8_t)0; | |
|
435 | *lcd0_CMD=(uint8_t)0; | |
|
436 | *lcd0_CMD=(uint8_t)0; | |
|
437 | *lcd0_CMD=(uint8_t)0; | |
|
413 | 438 | #if __BYTE_ORDER__==__ORDER_BIG_ENDIAN__ |
|
414 | 439 | *lcd0_CMD=pt8[3]; |
|
415 | 440 | *lcd0_CMD=pt8[2]; |
|
416 | 441 | pt8 = (uint8_t*)(void*)&DATA; |
|
417 | 442 | pt8[3]=*lcd0_DATA; |
|
418 | 443 | pt8[2]=*lcd0_DATA; |
|
419 | 444 | #else |
|
420 | 445 | |
|
421 | 446 | *lcd0_CMD=pt8[1]; |
|
422 | 447 | *lcd0_CMD=pt8[0]; |
|
423 | 448 | pt8 = (uint8_t*)(void*)&DATA; |
|
424 | 449 | pt8[1]=*lcd0_DATA; |
|
425 | 450 | pt8[0]=*lcd0_DATA; |
|
426 | 451 | #endif |
|
427 | 452 | |
|
428 | 453 | return DATA; |
|
429 | 454 | } |
|
430 | 455 | |
|
431 | 456 | void bsp_lcd0_writeGRAM(void* buffer,uint32_t count) |
|
432 | 457 | { |
|
433 | 458 | uint32_t reg =ILI9328_REGISTER_WRITEDATATOGRAM; |
|
434 | uint8_t* pt8 = (uint8_t*)(void*)® | |
|
459 | uint8_t* pt8 = (uint8_t*)(void*)(®); | |
|
460 | *lcd0_CMD=(uint8_t)0; | |
|
461 | *lcd0_CMD=(uint8_t)0; | |
|
462 | *lcd0_CMD=(uint8_t)0; | |
|
463 | *lcd0_CMD=(uint8_t)0; | |
|
435 | 464 | #if __BYTE_ORDER__==__ORDER_BIG_ENDIAN__ |
|
436 | 465 | *lcd0_CMD=pt8[3]; |
|
437 | 466 | *lcd0_CMD=pt8[2]; |
|
438 | 467 | pt8 = (uint8_t*)(void*)buffer; |
|
439 | 468 | for(int i=0;i<(int)count;i++) |
|
440 | 469 | { |
|
441 | 470 | *lcd0_DATA=pt8[(2*i) +1]; |
|
442 | 471 | *lcd0_DATA=pt8[2*i]; |
|
443 | 472 | } |
|
444 | 473 | #else |
|
445 | 474 | |
|
446 | 475 | *lcd0_CMD=pt8[1]; |
|
447 | 476 | *lcd0_CMD=pt8[0]; |
|
448 | 477 | pt8 = (uint8_t*)(void*)buffer; |
|
449 | 478 | for(int i=0;i<(int)count;i++) |
|
450 | 479 | { |
|
451 | 480 | |
|
452 | 481 | *lcd0_DATA=pt8[(2*i) +1]; |
|
453 | 482 | *lcd0_DATA=pt8[2*i]; |
|
454 | 483 | } |
|
455 | 484 | #endif |
|
456 | 485 | } |
|
457 | 486 | |
|
458 | 487 | void bsp_lcd0_readGRAM(void* buffer,uint32_t count) |
|
459 | 488 | { |
|
460 | 489 | uint32_t reg =ILI9328_REGISTER_WRITEDATATOGRAM; |
|
461 | uint8_t* pt8 = (uint8_t*)(void*)® | |
|
490 | volatile uint8_t* pt8 = (uint8_t*)(void*)® | |
|
491 | *lcd0_CMD=(uint8_t)0; | |
|
492 | *lcd0_CMD=(uint8_t)0; | |
|
493 | *lcd0_CMD=(uint8_t)0; | |
|
494 | *lcd0_CMD=(uint8_t)0; | |
|
462 | 495 | #if __BYTE_ORDER__==__ORDER_BIG_ENDIAN__ |
|
463 | 496 | *lcd0_CMD=pt8[3]; |
|
464 | 497 | *lcd0_CMD=pt8[2]; |
|
465 | 498 | pt8 = (uint8_t*)(void*)buffer; |
|
466 | 499 | for(int i=0;i<(int)count;i++) |
|
467 | 500 | { |
|
468 | 501 | pt8[(2*i) +1]=*lcd0_DATA; |
|
469 | __asm__("nop"); | |
|
470 | __asm__("nop"); | |
|
471 | __asm__("nop"); | |
|
472 | __asm__("nop"); | |
|
473 | __asm__("nop"); | |
|
474 | 502 | pt8[2*i]=*lcd0_DATA; |
|
475 | 503 | } |
|
476 | 504 | #else |
|
477 | 505 | *lcd0_CMD=pt8[1]; |
|
478 | 506 | *lcd0_CMD=pt8[0]; |
|
479 |
|
|
|
507 | pt8 = (uint8_t*)buffer; | |
|
508 | /* | |
|
509 | * x dummy reads Cf ili9328 datasheet p79! | |
|
510 | */ | |
|
511 | pt8[0]=*lcd0_DATA; | |
|
512 | pt8[1]=*lcd0_DATA; | |
|
513 | ||
|
480 | 514 | for(int i=0;i<(int)count;i++) |
|
481 | 515 | { |
|
482 | 516 | pt8[(2*i) +1]=*lcd0_DATA; |
|
483 | __asm__("nop"); | |
|
484 | __asm__("nop"); | |
|
485 | __asm__("nop"); | |
|
486 | __asm__("nop"); | |
|
487 | __asm__("nop"); | |
|
488 | __asm__("nop"); | |
|
489 | __asm__("nop"); | |
|
490 | __asm__("nop"); | |
|
491 | __asm__("nop"); | |
|
492 | __asm__("nop"); | |
|
517 | pt8[2*i]=*lcd0_DATA; | |
|
518 | pt8[(2*i) +1]=*lcd0_DATA; | |
|
493 | 519 | pt8[2*i]=*lcd0_DATA; |
|
494 | __asm__("nop"); | |
|
495 | __asm__("nop"); | |
|
496 | __asm__("nop"); | |
|
497 | __asm__("nop"); | |
|
498 | __asm__("nop"); | |
|
499 | pt8[(2*i) +1]=(uint8_t)0; | |
|
500 | pt8[(2*i)]=(uint8_t)0; | |
|
520 | // pt8[(2*i) +1]=(uint8_t)0; | |
|
521 | // pt8[(2*i)]=(uint8_t)0; | |
|
501 | 522 | } |
|
502 | 523 | #endif |
|
503 | 524 | } |
|
504 | 525 | |
|
505 | 526 | void bsp_GTerm_init() |
|
506 | 527 | { |
|
507 | 528 | if(__opnfiles__[1]==NULL) |
|
508 | 529 | { |
|
509 | 530 | streamdevice* fd1 = (streamdevice*)malloc(sizeof(streamdevice)); |
|
510 | 531 | terminal_init(&terminal0 ,&lcd0,&ComicSansMS_8,fd1); |
|
511 | 532 | __opnfiles__[1] = fd1; |
|
512 | 533 | } |
|
513 | 534 | else |
|
514 | 535 | { |
|
515 | 536 | |
|
516 | 537 | } |
|
517 | 538 | } |
|
518 | 539 | |
|
519 | 540 | |
|
520 | 541 | |
|
521 | 542 | |
|
522 | 543 | |
|
523 | 544 | |
|
524 | 545 | |
|
525 | 546 | |
|
526 | 547 | |
|
527 | 548 | |
|
528 | 549 | |
|
529 | 550 | |
|
530 | 551 | |
|
531 | 552 | |
|
532 | 553 | |
|
533 | 554 | |
|
534 | 555 |
@@ -1,283 +1,284 | |||
|
1 | 1 | /*------------------------------------------------------------------------------ |
|
2 | 2 | -- This file is a part of the libuc, microcontroler library |
|
3 | 3 | -- Copyright (C) 2011, Alexis Jeandet |
|
4 | 4 | -- |
|
5 | 5 | -- This program is free software; you can redistribute it and/or modify |
|
6 | 6 | -- it under the terms of the GNU General Public License as published by |
|
7 | 7 | -- the Free Software Foundation; either version 3 of the License, or |
|
8 | 8 | -- (at your option) any later version. |
|
9 | 9 | -- |
|
10 | 10 | -- This program is distributed in the hope that it will be useful, |
|
11 | 11 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 | 12 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
13 | 13 | -- GNU General Public License for more details. |
|
14 | 14 | -- |
|
15 | 15 | -- You should have received a copy of the GNU General Public License |
|
16 | 16 | -- along with this program; if not, write to the Free Software |
|
17 | 17 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
18 | 18 | ------------------------------------------------------------------------------- |
|
19 | 19 | -- Author : Alexis Jeandet |
|
20 | 20 | -- Mail : alexis.jeandet@member.fsf.org |
|
21 | 21 | -------------------------------------------------------------------------------*/ |
|
22 | 22 | #include "bsp.h" |
|
23 | 23 | #include <streamdevices.h> |
|
24 | 24 | #include <malloc.h> |
|
25 | 25 | #include <stdio.h> |
|
26 | 26 | |
|
27 | 27 | |
|
28 | 28 | uint32_t OSC0 =8000000; |
|
29 | 29 | uint32_t INTOSC =16000000; |
|
30 | 30 | uint32_t RTCOSC =32768; |
|
31 | 31 | uint32_t currentCpuFreq=0; |
|
32 | 32 | extern streamdevice* __opnfiles__[__MAX_OPENED_FILES__]; |
|
33 | 33 | |
|
34 | 34 | |
|
35 | 35 | LCD_IF_t lcdIF0={ |
|
36 | 36 | .init = &SDLCD_init, |
|
37 | 37 | .writereg = &SDLCD_writereg, |
|
38 | 38 | .readreg = &SDLCD_readreg, |
|
39 | 39 | .writeGRAM = &SDLCD_writeGRAM_16bpp, |
|
40 | 40 | .readGRAM = &SDLCD_readGRAM_16bpp |
|
41 | 41 | }; |
|
42 | 42 | |
|
43 | 43 | LCD_t lcd0={ |
|
44 | 44 | .interface = &lcdIF0, |
|
45 | 45 | .init = &ili9328init, |
|
46 | 46 | .paint = &ili9328paint, |
|
47 | 47 | .paintText = &ili9328paintText, |
|
48 | 48 | .paintFilRect = &ili9328paintFilRect, |
|
49 | .getPix = &ili9328getPix, | |
|
49 | 50 | .refreshenable = &ili9328refreshenable, |
|
50 | 51 | .width= 240, |
|
51 | 52 | .height = 320 |
|
52 | 53 | }; |
|
53 | 54 | |
|
54 | 55 | terminal_t terminal0; |
|
55 | 56 | |
|
56 | 57 | volatile int8_t* lcd0_CMD=(volatile int8_t*) 0x60000000; |
|
57 | 58 | volatile int8_t* lcd0_DATA=(volatile int8_t*)(0x61FFFFF0); |
|
58 | 59 | |
|
59 | 60 | float VREF0 =(float)3.3; |
|
60 | 61 | volatile vs10XXDev audioCodec0; |
|
61 | 62 | |
|
62 | 63 | sdcardDev sdcard2; |
|
63 | 64 | blkdevice sdcard2blkdev; |
|
64 | 65 | dikpartition sdcard2Part1; |
|
65 | 66 | FAT32fs sdcard2FAT32part1; |
|
66 | 67 | dikpartition sdcard2Part2; |
|
67 | 68 | FAT32fs sdcard2FAT32part2; |
|
68 | 69 | dikpartition sdcard2Part3; |
|
69 | 70 | FAT32fs sdcard2FAT32part3; |
|
70 | 71 | dikpartition sdcard2Part4; |
|
71 | 72 | FAT32fs sdcard2FAT32part4; |
|
72 | 73 | |
|
73 | 74 | int bsp_init() |
|
74 | 75 | { |
|
75 | 76 | int i=0; |
|
76 | 77 | for(i=0;i<__MAX_OPENED_FILES__;i++) |
|
77 | 78 | { |
|
78 | 79 | __opnfiles__[i] = NULL; |
|
79 | 80 | } |
|
80 | 81 | bsp_GPIO_init(); |
|
81 | 82 | bsp_uart_init(); |
|
82 | 83 | bsp_iic_init(); |
|
83 | 84 | bsp_FSMC_init(); |
|
84 | 85 | bsp_GTerm_init(); |
|
85 | 86 | bsp_spi_init(); |
|
86 | 87 | bsp_SD_init(); |
|
87 | 88 | bsp_Audio_init(); |
|
88 | 89 | printf("\r=====================\n\r"); |
|
89 | 90 | printf( "=====================\n\r"); |
|
90 | 91 | printf(BSP); |
|
91 | 92 | printf(" initialised\n\r"); |
|
92 | 93 | printf( "=====================\n\r"); |
|
93 | 94 | return 1; |
|
94 | 95 | } |
|
95 | 96 | |
|
96 | 97 | void bsp_GPIO_init() |
|
97 | 98 | { |
|
98 | 99 | |
|
99 | 100 | } |
|
100 | 101 | |
|
101 | 102 | void bsp_uart_init() |
|
102 | 103 | { |
|
103 | 104 | |
|
104 | 105 | } |
|
105 | 106 | |
|
106 | 107 | /* |
|
107 | 108 | D0 PD14 D1 PD15 D2 PD0 D3 PD1 D4 PE7 |
|
108 | 109 | D5 PE8 D6 PE9 D7 PE10 |
|
109 | 110 | A20 PE4 = RS FSMC_NE1 PD7 CS FSMC_NWE PD5 W/S |
|
110 | 111 | FSMC_NOE PD4 RD |
|
111 | 112 | */ |
|
112 | 113 | |
|
113 | 114 | int bsp_FSMC_init() |
|
114 | 115 | { |
|
115 | 116 | |
|
116 | 117 | return 1; |
|
117 | 118 | } |
|
118 | 119 | |
|
119 | 120 | void bsp_spi_init() |
|
120 | 121 | { |
|
121 | 122 | |
|
122 | 123 | } |
|
123 | 124 | |
|
124 | 125 | |
|
125 | 126 | void bsp_iic_init() |
|
126 | 127 | { |
|
127 | 128 | |
|
128 | 129 | } |
|
129 | 130 | |
|
130 | 131 | |
|
131 | 132 | void bsp_Audio_init() |
|
132 | 133 | { |
|
133 | 134 | |
|
134 | 135 | } |
|
135 | 136 | |
|
136 | 137 | void bsp_SD_init() |
|
137 | 138 | { |
|
138 | 139 | |
|
139 | 140 | } |
|
140 | 141 | |
|
141 | 142 | void vs1052setXCS(char val) |
|
142 | 143 | { |
|
143 | 144 | } |
|
144 | 145 | |
|
145 | 146 | void vs1052setXDCS(char val) |
|
146 | 147 | { |
|
147 | 148 | } |
|
148 | 149 | |
|
149 | 150 | void vs1052setRST(char val) |
|
150 | 151 | { |
|
151 | 152 | } |
|
152 | 153 | |
|
153 | 154 | int vs10XXDREQ() |
|
154 | 155 | { |
|
155 | 156 | return 1; |
|
156 | 157 | } |
|
157 | 158 | |
|
158 | 159 | |
|
159 | 160 | void bsppowersdcard(char onoff) //always ON |
|
160 | 161 | { |
|
161 | 162 | |
|
162 | 163 | } |
|
163 | 164 | |
|
164 | 165 | char bspsdcardpresent() |
|
165 | 166 | { |
|
166 | 167 | return 1; |
|
167 | 168 | } |
|
168 | 169 | |
|
169 | 170 | char bspsdcardwriteprotected() |
|
170 | 171 | { |
|
171 | 172 | return 0; |
|
172 | 173 | } |
|
173 | 174 | |
|
174 | 175 | void bspsdcardselect(char YESNO) |
|
175 | 176 | { |
|
176 | 177 | |
|
177 | 178 | } |
|
178 | 179 | |
|
179 | 180 | |
|
180 | 181 | void bsp_lcd0_write_reg(uint32_t reg,uint32_t data) |
|
181 | 182 | { |
|
182 | 183 | |
|
183 | 184 | } |
|
184 | 185 | |
|
185 | 186 | uint32_t bsp_lcd0_read_reg(uint32_t reg) |
|
186 | 187 | { |
|
187 | 188 | return 0; |
|
188 | 189 | } |
|
189 | 190 | |
|
190 | 191 | void bsp_lcd0_writeGRAM(void* buffer,uint32_t count) |
|
191 | 192 | { |
|
192 | 193 | |
|
193 | 194 | } |
|
194 | 195 | |
|
195 | 196 | void bsp_lcd0_readGRAM(void* buffer,uint32_t count) |
|
196 | 197 | { |
|
197 | 198 | |
|
198 | 199 | } |
|
199 | 200 | |
|
200 | 201 | void bsp_GTerm_init() |
|
201 | 202 | { |
|
202 | 203 | SDLCD_mkscreen(240,320,16,LCDILI9328); |
|
203 | 204 | |
|
204 | 205 | if(__opnfiles__[1]==NULL) |
|
205 | 206 | { |
|
206 | 207 | streamdevice* fd1 = (streamdevice*)malloc(sizeof(streamdevice)); |
|
207 | 208 | terminal_init(&terminal0 ,&lcd0,&ComicSansMS_18,fd1); |
|
208 | 209 | lcd0.paintFilRect(&lcd0,0,0,240,320,0,0,0x0f0f); |
|
209 | 210 | __opnfiles__[1] = fd1; |
|
210 | 211 | } |
|
211 | 212 | else |
|
212 | 213 | { |
|
213 | 214 | |
|
214 | 215 | } |
|
215 | 216 | } |
|
216 | 217 | |
|
217 | 218 | |
|
218 | 219 | |
|
219 | 220 | |
|
220 | 221 | |
|
221 | 222 | |
|
222 | 223 | |
|
223 | 224 | void putpixel(SDL_Surface *surface, int x, int y, Uint32 pixel) |
|
224 | 225 | { |
|
225 | 226 | int bpp = surface->format->BytesPerPixel; |
|
226 | 227 | /* Here p is the address to the pixel we want to set */ |
|
227 | 228 | Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; |
|
228 | 229 | switch(bpp) { |
|
229 | 230 | case 1: |
|
230 | 231 | *p = pixel; |
|
231 | 232 | break; |
|
232 | 233 | case 2: |
|
233 | 234 | *(Uint16 *)p = pixel; |
|
234 | 235 | break; |
|
235 | 236 | case 3: |
|
236 | 237 | if(SDL_BYTEORDER == SDL_BIG_ENDIAN) { |
|
237 | 238 | p[0] = (pixel >> 16) & 0xff; |
|
238 | 239 | p[1] = (pixel >> 8) & 0xff; |
|
239 | 240 | p[2] = pixel & 0xff; |
|
240 | 241 | } else { |
|
241 | 242 | p[0] = pixel & 0xff; |
|
242 | 243 | p[1] = (pixel >> 8) & 0xff; |
|
243 | 244 | p[2] = (pixel >> 16) & 0xff; |
|
244 | 245 | } |
|
245 | 246 | break; |
|
246 | 247 | case 4: |
|
247 | 248 | *(Uint32 *)p = pixel; |
|
248 | 249 | break; |
|
249 | 250 | } |
|
250 | 251 | } |
|
251 | 252 | |
|
252 | 253 | Uint32 getpixel(SDL_Surface *surface, int x, int y) |
|
253 | 254 | { |
|
254 | 255 | int bpp = surface->format->BytesPerPixel; |
|
255 | 256 | /* Here p is the address to the pixel we want to retrieve */ |
|
256 | 257 | Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; |
|
257 | 258 | switch(bpp) { |
|
258 | 259 | case 1: |
|
259 | 260 | return *p; |
|
260 | 261 | case 2: |
|
261 | 262 | return *(Uint16 *)p; |
|
262 | 263 | case 3: |
|
263 | 264 | if(SDL_BYTEORDER == SDL_BIG_ENDIAN) |
|
264 | 265 | return p[0] << 16 | p[1] << 8 | p[2]; |
|
265 | 266 | else |
|
266 | 267 | return p[0] | p[1] << 8 | p[2] << 16; |
|
267 | 268 | case 4: |
|
268 | 269 | return *(Uint32 *)p; |
|
269 | 270 | default: |
|
270 | 271 | return 0; |
|
271 | 272 | } |
|
272 | 273 | /* shouldnβt happen, but avoids warnings */ |
|
273 | 274 | } |
|
274 | 275 | |
|
275 | 276 | |
|
276 | 277 | |
|
277 | 278 | |
|
278 | 279 | |
|
279 | 280 | |
|
280 | 281 | |
|
281 | 282 | |
|
282 | 283 | |
|
283 | 284 |
@@ -1,345 +1,365 | |||
|
1 | 1 | /*------------------------------------------------------------------------------ |
|
2 | 2 | -- This file is a part of the libuc, microcontroler library |
|
3 | 3 | -- Copyright (C) 2011, Alexis Jeandet |
|
4 | 4 | -- |
|
5 | 5 | -- This program is free software; you can redistribute it and/or modify |
|
6 | 6 | -- it under the terms of the GNU General Public License as published by |
|
7 | 7 | -- the Free Software Foundation; either version 3 of the License, or |
|
8 | 8 | -- (at your option) any later version. |
|
9 | 9 | -- |
|
10 | 10 | -- This program is distributed in the hope that it will be useful, |
|
11 | 11 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 | 12 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
13 | 13 | -- GNU General Public License for more details. |
|
14 | 14 | -- |
|
15 | 15 | -- You should have received a copy of the GNU General Public License |
|
16 | 16 | -- along with this program; if not, write to the Free Software |
|
17 | 17 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
18 | 18 | ------------------------------------------------------------------------------- |
|
19 | 19 | -- Author : Alexis Jeandet |
|
20 | 20 | -- Mail : alexis.jeandet@member.fsf.org |
|
21 | 21 | -------------------------------------------------------------------------------*/ |
|
22 | 22 | #include "bsp.h" |
|
23 | 23 | #include <streamdevices.h> |
|
24 | 24 | #include <malloc.h> |
|
25 | 25 | #include <gpio.h> |
|
26 | 26 | #include <uart.h> |
|
27 | 27 | #include <stdio.h> |
|
28 | 28 | #include <stm32f4xx_gpio.h> |
|
29 | 29 | #include <stm32f4xx_fsmc.h> |
|
30 | 30 | #include <i2c.h> |
|
31 | 31 | #include <core.h> |
|
32 | 32 | #include <terminal.h> |
|
33 | 33 | uint32_t OSC0 =8000000; |
|
34 | 34 | uint32_t INTOSC =16000000; |
|
35 | 35 | uint32_t RTCOSC =32768; |
|
36 | 36 | uint32_t currentCpuFreq=0; |
|
37 | 37 | extern streamdevice* __opnfiles__[__MAX_OPENED_FILES__]; |
|
38 | 38 | |
|
39 | 39 | LCD_IF_t lcdIF0={ |
|
40 | 40 | .init = &bsp_FSMC_init, |
|
41 | 41 | .writereg = &bsp_lcd0_write_reg, |
|
42 | 42 | .readreg = &bsp_lcd0_read_reg, |
|
43 | 43 | .writeGRAM = &bsp_lcd0_writeGRAM, |
|
44 | 44 | .readGRAM = &bsp_lcd0_readGRAM |
|
45 | 45 | }; |
|
46 | 46 | |
|
47 | 47 | LCD_t lcd0={ |
|
48 | 48 | .interface = &lcdIF0, |
|
49 | 49 | .init = &ili9328init, |
|
50 | 50 | .paint = &ili9328paint, |
|
51 | 51 | .paintText = &ili9328paintText, |
|
52 | 52 | .paintFilRect = &ili9328paintFilRect, |
|
53 | .getPix = &ili9328getPix, | |
|
53 | 54 | .refreshenable = &ili9328refreshenable, |
|
54 | 55 | .width= 240, |
|
55 | 56 | .height = 320 |
|
56 | 57 | }; |
|
57 | 58 | |
|
58 | 59 | terminal_t terminal0; |
|
59 | 60 | |
|
60 | 61 | |
|
61 | 62 | volatile int16_t* lcd0_CMD=(volatile int16_t*) (0x60000000 | 0x08000000); |
|
62 | 63 | volatile int16_t* lcd0_DATA=((volatile int16_t*)(0x60000000 | 0x08000002)); |
|
63 | 64 | |
|
64 | 65 | float VREF0 =(float)3.3; |
|
65 | 66 | |
|
66 | 67 | int bsp_init() |
|
67 | 68 | { |
|
68 | 69 | int i=0; |
|
69 | 70 | for(i=0;i<32;i++) |
|
70 | 71 | { |
|
71 | 72 | __opnfiles__[i] = NULL; |
|
72 | 73 | } |
|
73 | 74 | bsp_GPIO_init(); |
|
74 | 75 | bsp_uart_init(); |
|
75 | 76 | bsp_iic_init(); |
|
76 | 77 | bsp_FSMC_init(); |
|
77 | 78 | bsp_GTerm_init(); |
|
78 | 79 | printf("\r=====================\n\r"); |
|
79 | 80 | printf( "=====================\n\r"); |
|
80 | 81 | printf(BSP); |
|
81 | 82 | printf(" initialised\n\r"); |
|
82 | 83 | printf( "=====================\n\r"); |
|
83 | 84 | return 1; |
|
84 | 85 | } |
|
85 | 86 | |
|
86 | 87 | void bsp_GPIO_init() |
|
87 | 88 | { |
|
88 | 89 | gpio_t gpio1 = gpioopen(LED1); |
|
89 | 90 | gpio_t gpio2 = gpioopen(LED2); |
|
90 | 91 | gpio_t gpio3 = gpioopen(LED3); |
|
91 | 92 | gpiosetspeed(&gpio1,gpiohighspeed); |
|
92 | 93 | gpiosetspeed(&gpio2,gpiohighspeed); |
|
93 | 94 | gpiosetspeed(&gpio3,gpiohighspeed); |
|
94 | 95 | gpiosetdir(&gpio1,gpiooutdir); |
|
95 | 96 | gpiosetdir(&gpio2,gpiooutdir); |
|
96 | 97 | gpiosetdir(&gpio3,gpiooutdir); |
|
97 | 98 | } |
|
98 | 99 | |
|
99 | 100 | void bsp_uart_init() |
|
100 | 101 | { |
|
101 | 102 | //if(__opnfiles__[1]==NULL) |
|
102 | 103 | //{ |
|
103 | 104 | //uart_t* uart1 = (uart_t*)malloc(sizeof(uart_t)); |
|
104 | 105 | // streamdevice* fd1 = (streamdevice*)malloc(sizeof(streamdevice)); |
|
105 | 106 | // uart_t uart = uartopenandconfig(uart1,uartparitynone | uart8bits | uartonestop,115200,PA9,PA10,-1,-1); |
|
106 | 107 | //uartmkstreamdev(uart,fd1); |
|
107 | 108 | //__opnfiles__[1] = fd1; |
|
108 | 109 | //} |
|
109 | 110 | //else |
|
110 | 111 | //{ |
|
111 | 112 | uartopenandconfig(0,uartparitynone | uart8bits | uartonestop,115200,PA9,PA10,-1,-1); |
|
112 | 113 | //} |
|
113 | 114 | } |
|
114 | 115 | |
|
115 | 116 | /* |
|
116 | 117 | D0 PD14 D1 PD15 D2 PD0 D3 PD1 D4 PE7 |
|
117 | 118 | D5 PE8 D6 PE9 D7 PE10 D8 PE11 D9 PE12 |
|
118 | 119 | D10 PE13 D11 PE14 D12 PE15 D13 PD8 D14 PD9 |
|
119 | 120 | D15 PD10 |
|
120 | 121 | A0 PF0 = RS FSMC_NE3 PG10 CS FSMC_NWE PD5 W/S |
|
121 | 122 | FSMC_NOE PD4 RD |
|
122 | 123 | */ |
|
123 | 124 | /*-- GPIOs Configuration -----------------------------------------------------*/ |
|
124 | 125 | /* |
|
125 | 126 | +-------------------+--------------------+------------------+------------------+ |
|
126 | 127 | + SRAM pins assignment + |
|
127 | 128 | +-------------------+--------------------+------------------+------------------+ |
|
128 | 129 | | PD0 <-> FSMC_D2 | PE0 <-> FSMC_NBL0 | PF0 <-> FSMC_A0 | PG0 <-> FSMC_A10 | |
|
129 | 130 | | PD1 <-> FSMC_D3 | PE1 <-> FSMC_NBL1 | PF1 <-> FSMC_A1 | PG1 <-> FSMC_A11 | |
|
130 | 131 | | PD4 <-> FSMC_NOE | PE3 <-> FSMC_A19 | PF2 <-> FSMC_A2 | PG2 <-> FSMC_A12 | |
|
131 | 132 | | PD5 <-> FSMC_NWE | PE4 <-> FSMC_A20 | PF3 <-> FSMC_A3 | PG3 <-> FSMC_A13 | |
|
132 | 133 | | PD8 <-> FSMC_D13 | PE7 <-> FSMC_D4 | PF4 <-> FSMC_A4 | PG4 <-> FSMC_A14 | |
|
133 | 134 | | PD9 <-> FSMC_D14 | PE8 <-> FSMC_D5 | PF5 <-> FSMC_A5 | PG5 <-> FSMC_A15 | |
|
134 | 135 | | PD10 <-> FSMC_D15 | PE9 <-> FSMC_D6 | PF12 <-> FSMC_A6 | PG9 <-> FSMC_NE2 | |
|
135 | 136 | | PD11 <-> FSMC_A16 | PE10 <-> FSMC_D7 | PF13 <-> FSMC_A7 |------------------+ |
|
136 | 137 | | PD12 <-> FSMC_A17 | PE11 <-> FSMC_D8 | PF14 <-> FSMC_A8 | |
|
137 | 138 | | PD13 <-> FSMC_A18 | PE12 <-> FSMC_D9 | PF15 <-> FSMC_A9 | |
|
138 | 139 | | PD14 <-> FSMC_D0 | PE13 <-> FSMC_D10 |------------------+ |
|
139 | 140 | | PD15 <-> FSMC_D1 | PE14 <-> FSMC_D11 | |
|
140 | 141 | | | PE15 <-> FSMC_D12 | |
|
141 | 142 | +-------------------+--------------------+ |
|
142 | 143 | */ |
|
143 | 144 | int bsp_FSMC_init() |
|
144 | 145 | { |
|
145 | 146 | #define GPIOGETPORT(gpio) ((GPIO_TypeDef*)(((((uint32_t)gpio) & (uint32_t)0x0000FF00)*(uint32_t)4) + (uint32_t)GPIOA)) |
|
146 | 147 | #define GPIOPORTNUM(gpio) (((uint32_t)(gpio) & (uint32_t)0x0000FF00)>>(uint32_t)8) |
|
147 | 148 | |
|
148 | 149 | gpio_t LCD_DBxList[]={ |
|
149 | 150 | PD0 ,PD1 ,PD4 ,PD5 ,PD8 ,PD9 ,PD10,PD11,PD12,PD13,PD14,PD15, |
|
150 | 151 | PE0 ,PE1 ,PE3 ,PE4 ,PE7 ,PE8 ,PE9 ,PE10,PE11,PE12,PE13,PE14, |
|
151 | 152 | PE15,PF0 ,PF1 ,PF2 ,PF3 ,PF4 ,PF5 ,PF12,PF13,PF14,PF15,PG0 , |
|
152 | 153 | PG1 ,PG2 ,PG3 ,PG4 ,PG5 ,PG9 ,PG10 |
|
153 | 154 | }; |
|
154 | 155 | |
|
155 | 156 | for(int i=0;i<43;i++) |
|
156 | 157 | { |
|
157 | 158 | gpio_t LCD_DBx = gpioopen(LCD_DBxList[i]); |
|
158 | 159 | LCD_DBx |= gpiohighspeed | gpioaf | gpiopushpulltype | gpionopulltype; |
|
159 | 160 | gpiosetconfig(&LCD_DBx); |
|
160 | 161 | GPIO_PinAFConfig(GPIOGETPORT(LCD_DBx), (uint8_t)(LCD_DBx & 0xF), GPIO_AF_FSMC); |
|
161 | 162 | } |
|
162 | 163 | |
|
163 | 164 | FSMC_NORSRAMInitTypeDef FSMC_NORSRAMInitStructure; |
|
164 | FSMC_NORSRAMTimingInitTypeDef p; | |
|
165 | FSMC_NORSRAMTimingInitTypeDef p,readtim; | |
|
165 | 166 | |
|
166 | 167 | /* Enable FSMC clock */ |
|
167 | 168 | RCC_AHB3PeriphClockCmd(RCC_AHB3Periph_FSMC, ENABLE); |
|
168 | 169 | |
|
169 | 170 | /*-- FSMC Configuration ------------------------------------------------------*/ |
|
170 | 171 | /*----------------------- SRAM Bank 3 ----------------------------------------*/ |
|
171 | 172 | /* FSMC_Bank1_NORSRAM3 configuration */ |
|
172 |
p.FSMC_AddressSetupTime = |
|
|
173 | p.FSMC_AddressHoldTime = 0; | |
|
174 | p.FSMC_DataSetupTime = getCpuFreq()/14545450 ;// 11; | |
|
175 | p.FSMC_BusTurnAroundDuration = 0; | |
|
173 | p.FSMC_AddressSetupTime = 0xf; | |
|
174 | p.FSMC_AddressHoldTime = 0xf; | |
|
175 | //ili9328 -> data setup time > 10ns | |
|
176 | p.FSMC_DataSetupTime = 0xf; | |
|
177 | if(getCpuFreq()>100*1000*1000) | |
|
178 | p.FSMC_DataSetupTime = 0xf;// 11; | |
|
179 | p.FSMC_BusTurnAroundDuration = 0xf; | |
|
176 | 180 | p.FSMC_CLKDivision = 0; |
|
177 | p.FSMC_DataLatency = 0; | |
|
181 | p.FSMC_DataLatency = 0xf; | |
|
182 | //ili9328 -> data hold time > 15ns | |
|
183 | if(getCpuFreq()>66*1000*1000) | |
|
184 | p.FSMC_DataLatency = 0xf; | |
|
178 | 185 | p.FSMC_AccessMode = FSMC_AccessMode_A; |
|
186 | ||
|
187 | readtim.FSMC_AddressSetupTime = 0xf; | |
|
188 | readtim.FSMC_AddressHoldTime = 0xf; | |
|
189 | //p.FSMC_DataSetupTime = 9; | |
|
190 | readtim.FSMC_DataSetupTime = 0xf ;// 11; | |
|
191 | if(getCpuFreq()>100*1000*1000) | |
|
192 | readtim.FSMC_DataSetupTime = 0xf;// 11; | |
|
193 | readtim.FSMC_BusTurnAroundDuration = 0xf; | |
|
194 | readtim.FSMC_CLKDivision = 0; | |
|
195 | readtim.FSMC_DataLatency = 0xf; | |
|
196 | if(getCpuFreq()>66*1000*1000) | |
|
197 | readtim.FSMC_DataLatency = 0xf; | |
|
198 | readtim.FSMC_AccessMode = FSMC_AccessMode_A; | |
|
179 | 199 | /* Color LCD configuration ------------------------------------ |
|
180 | 200 | LCD configured as follow: |
|
181 | 201 | - Data/Address MUX = Disable |
|
182 | 202 | - Memory Type = SRAM |
|
183 | 203 | - Data Width = 16bit |
|
184 | 204 | - Write Operation = Enable |
|
185 | 205 | - Extended Mode = Enable |
|
186 | 206 | - Asynchronous Wait = Disable */ |
|
187 | 207 | |
|
188 | 208 | FSMC_NORSRAMInitStructure.FSMC_Bank = FSMC_Bank1_NORSRAM3; |
|
189 | 209 | FSMC_NORSRAMInitStructure.FSMC_DataAddressMux = FSMC_DataAddressMux_Disable; |
|
190 | 210 | FSMC_NORSRAMInitStructure.FSMC_MemoryType = FSMC_MemoryType_SRAM; |
|
191 | 211 | FSMC_NORSRAMInitStructure.FSMC_MemoryDataWidth = FSMC_MemoryDataWidth_16b; |
|
192 | 212 | FSMC_NORSRAMInitStructure.FSMC_BurstAccessMode = FSMC_BurstAccessMode_Disable; |
|
193 | 213 | FSMC_NORSRAMInitStructure.FSMC_AsynchronousWait = FSMC_AsynchronousWait_Disable; |
|
194 | 214 | FSMC_NORSRAMInitStructure.FSMC_WaitSignalPolarity = FSMC_WaitSignalPolarity_Low; |
|
195 | 215 | FSMC_NORSRAMInitStructure.FSMC_WrapMode = FSMC_WrapMode_Disable; |
|
196 | 216 | FSMC_NORSRAMInitStructure.FSMC_WaitSignalActive = FSMC_WaitSignalActive_BeforeWaitState; |
|
197 | 217 | FSMC_NORSRAMInitStructure.FSMC_WriteOperation = FSMC_WriteOperation_Enable; |
|
198 | 218 | FSMC_NORSRAMInitStructure.FSMC_WaitSignal = FSMC_WaitSignal_Disable; |
|
199 | 219 | FSMC_NORSRAMInitStructure.FSMC_ExtendedMode = FSMC_ExtendedMode_Disable; |
|
200 | 220 | FSMC_NORSRAMInitStructure.FSMC_WriteBurst = FSMC_WriteBurst_Disable; |
|
201 |
FSMC_NORSRAMInitStructure.FSMC_ReadWriteTimingStruct = & |
|
|
221 | FSMC_NORSRAMInitStructure.FSMC_ReadWriteTimingStruct = &readtim; | |
|
202 | 222 | FSMC_NORSRAMInitStructure.FSMC_WriteTimingStruct = &p; |
|
203 | 223 | |
|
204 | 224 | FSMC_NORSRAMInit(&FSMC_NORSRAMInitStructure); |
|
205 | 225 | |
|
206 | 226 | /* Enable FSMC NOR/SRAM Bank1 */ |
|
207 | 227 | FSMC_NORSRAMCmd(FSMC_Bank1_NORSRAM3, ENABLE); |
|
208 | 228 | |
|
209 | 229 | |
|
210 | 230 | p.FSMC_AddressSetupTime = getCpuFreq()/50000000; |
|
211 | 231 | p.FSMC_AddressHoldTime = 0; |
|
212 | 232 | p.FSMC_DataSetupTime = getCpuFreq()/25000000; |
|
213 | 233 | p.FSMC_BusTurnAroundDuration = 1; |
|
214 | 234 | p.FSMC_CLKDivision = 0; |
|
215 | 235 | p.FSMC_DataLatency = 0; |
|
216 | 236 | p.FSMC_AccessMode = FSMC_AccessMode_A; |
|
217 | 237 | |
|
218 | 238 | FSMC_NORSRAMInitStructure.FSMC_Bank = FSMC_Bank1_NORSRAM2; |
|
219 | 239 | FSMC_NORSRAMInitStructure.FSMC_DataAddressMux = FSMC_DataAddressMux_Disable; |
|
220 | 240 | FSMC_NORSRAMInitStructure.FSMC_MemoryType = FSMC_MemoryType_PSRAM; |
|
221 | 241 | FSMC_NORSRAMInitStructure.FSMC_MemoryDataWidth = FSMC_MemoryDataWidth_16b; |
|
222 | 242 | FSMC_NORSRAMInitStructure.FSMC_BurstAccessMode = FSMC_BurstAccessMode_Disable; |
|
223 | 243 | FSMC_NORSRAMInitStructure.FSMC_AsynchronousWait = FSMC_AsynchronousWait_Disable; |
|
224 | 244 | FSMC_NORSRAMInitStructure.FSMC_WaitSignalPolarity = FSMC_WaitSignalPolarity_Low; |
|
225 | 245 | FSMC_NORSRAMInitStructure.FSMC_WrapMode = FSMC_WrapMode_Disable; |
|
226 | 246 | FSMC_NORSRAMInitStructure.FSMC_WaitSignalActive = FSMC_WaitSignalActive_BeforeWaitState; |
|
227 | 247 | FSMC_NORSRAMInitStructure.FSMC_WriteOperation = FSMC_WriteOperation_Enable; |
|
228 | 248 | FSMC_NORSRAMInitStructure.FSMC_WaitSignal = FSMC_WaitSignal_Disable; |
|
229 | 249 | FSMC_NORSRAMInitStructure.FSMC_ExtendedMode = FSMC_ExtendedMode_Disable; |
|
230 | 250 | FSMC_NORSRAMInitStructure.FSMC_WriteBurst = FSMC_WriteBurst_Disable; |
|
231 | 251 | FSMC_NORSRAMInitStructure.FSMC_ReadWriteTimingStruct = &p; |
|
232 | 252 | FSMC_NORSRAMInitStructure.FSMC_WriteTimingStruct = &p; |
|
233 | 253 | |
|
234 | 254 | FSMC_NORSRAMInit(&FSMC_NORSRAMInitStructure); |
|
235 | 255 | |
|
236 | 256 | /*!< Enable FSMC Bank1_SRAM2 Bank */ |
|
237 | 257 | FSMC_NORSRAMCmd(FSMC_Bank1_NORSRAM2, ENABLE); |
|
238 | 258 | lcd0.init(&lcd0); |
|
239 | 259 | return 1; |
|
240 | 260 | } |
|
241 | 261 | |
|
242 | 262 | void bsp_spi_init() |
|
243 | 263 | { |
|
244 | 264 | |
|
245 | 265 | } |
|
246 | 266 | |
|
247 | 267 | |
|
248 | 268 | void bsp_iic_init() |
|
249 | 269 | { |
|
250 | 270 | i2copenandconfig(i2c1,0,10000,PB9,PB6); |
|
251 | 271 | } |
|
252 | 272 | |
|
253 | 273 | void bsp_SD_init() |
|
254 | 274 | { |
|
255 | 275 | gpio_t SDIO_DBxList[]={PC8 ,PC9 ,PC10 ,PC11 ,PC12,PD2}; |
|
256 | 276 | for(int i=0;i<6;i++) |
|
257 | 277 | { |
|
258 | 278 | gpio_t SDIO_DBx = gpioopen(SDIO_DBxList[i]); |
|
259 | 279 | SDIO_DBx |= gpiohighspeed | gpioaf | gpiopushpulltype | gpionopulltype; |
|
260 | 280 | gpiosetconfig(&SDIO_DBx); |
|
261 | 281 | GPIO_PinAFConfig(GPIOGETPORT(SDIO_DBx), (uint8_t)(SDIO_DBx & 0xF), GPIO_AF_SDIO); |
|
262 | 282 | } |
|
263 | 283 | } |
|
264 | 284 | |
|
265 | 285 | void vs10XXclearXCS(){} |
|
266 | 286 | void vs10XXsetXCS(){} |
|
267 | 287 | int vs10XXDREQ() |
|
268 | 288 | { |
|
269 | 289 | return 1; |
|
270 | 290 | } |
|
271 | 291 | |
|
272 | 292 | |
|
273 | 293 | void bsppowersdcard(char onoff) //always ON |
|
274 | 294 | { |
|
275 | 295 | |
|
276 | 296 | } |
|
277 | 297 | |
|
278 | 298 | char bspsdcardpresent() |
|
279 | 299 | { |
|
280 | 300 | return 0; |
|
281 | 301 | } |
|
282 | 302 | |
|
283 | 303 | char bspsdcardwriteprotected() |
|
284 | 304 | { |
|
285 | 305 | return 0; |
|
286 | 306 | } |
|
287 | 307 | |
|
288 | 308 | void bspsdcardselect(char YESNO) |
|
289 | 309 | { |
|
290 | 310 | |
|
291 | 311 | } |
|
292 | 312 | |
|
293 | 313 | |
|
294 | 314 | void bsp_lcd0_write_reg(uint32_t reg,uint32_t data) |
|
295 | 315 | { |
|
296 | 316 | *lcd0_CMD=(uint16_t)reg; |
|
297 | 317 | *lcd0_DATA=(uint16_t)data; |
|
298 | 318 | } |
|
299 | 319 | |
|
300 | 320 | uint32_t bsp_lcd0_read_reg(uint32_t reg) |
|
301 | 321 | { |
|
302 | 322 | *lcd0_CMD=(uint16_t)reg; |
|
303 | 323 | return (uint16_t)*lcd0_DATA; |
|
304 | 324 | } |
|
305 | 325 | |
|
306 | 326 | void bsp_lcd0_writeGRAM(void* buffer,uint32_t count) |
|
307 | 327 | { |
|
308 | 328 | *lcd0_CMD=(uint16_t)ILI9328_REGISTER_WRITEDATATOGRAM; |
|
309 | 329 | uint16_t* castedBuff=(uint16_t*)buffer; |
|
310 | 330 | for(int i=0;i<(int)count;i++) |
|
311 | 331 | { |
|
312 | 332 | *lcd0_DATA=castedBuff[i]; |
|
313 | 333 | } |
|
314 | 334 | } |
|
315 | 335 | |
|
316 | 336 | void bsp_lcd0_readGRAM(void* buffer,uint32_t count) |
|
317 | 337 | { |
|
318 | 338 | *lcd0_CMD=(uint16_t)ILI9328_REGISTER_WRITEDATATOGRAM; |
|
319 | 339 | uint16_t* castedBuff=(uint16_t*)buffer; |
|
320 | 340 | castedBuff[0]=*lcd0_DATA; |
|
321 | 341 | for(int i=0;i<(int)count;i++) |
|
322 | 342 | { |
|
323 | 343 | castedBuff[i]=*lcd0_DATA; |
|
324 | 344 | } |
|
325 | 345 | } |
|
326 | 346 | |
|
327 | 347 | void bsp_GTerm_init() |
|
328 | 348 | { |
|
329 | 349 | if(__opnfiles__[1]==NULL) |
|
330 | 350 | { |
|
331 | 351 | //uart_t* uart1 = (uart_t*)malloc(sizeof(uart_t)); |
|
332 | 352 | streamdevice* fd1 = (streamdevice*)malloc(sizeof(streamdevice)); |
|
333 | 353 | |
|
334 | 354 | ili9328paintFilRect(&lcd0,0,0,240,320,0x7FFF,5,0); |
|
335 | 355 | terminal_init(&terminal0,&lcd0,&ComicSansMS_8,fd1); |
|
336 | 356 | __opnfiles__[1] = fd1; |
|
337 | 357 | } |
|
338 | 358 | else |
|
339 | 359 | { |
|
340 | 360 | |
|
341 | 361 | } |
|
342 | 362 | } |
|
343 | 363 | |
|
344 | 364 | |
|
345 | 365 |
@@ -1,18 +1,19 | |||
|
1 | 1 | TEMPLATE = subdirs |
|
2 | 2 | CONFIG += ordered |
|
3 | 3 | SUBDIRS += STM32F4Discovery \ |
|
4 | 4 | M4Stick \ |
|
5 | 5 | M4StickV2 \ |
|
6 | 6 | SOLAR_LFR_PSU \ |
|
7 | 7 | BEAGLESYNTH \ |
|
8 | 8 | STM32F4Eval \ |
|
9 | 9 | STM32F4Discovery-EXT \ |
|
10 | STM32F4Discovery-ILI9328-8bits \ | |
|
10 | 11 | OPLAYER \ |
|
11 | 12 | SIMULATOR |
|
12 | 13 | |
|
13 | 14 | |
|
14 | 15 | |
|
15 | 16 | |
|
16 | 17 | |
|
17 | 18 | |
|
18 | 19 |
@@ -1,14 +1,15 | |||
|
1 | 1 | TEMPLATE = app |
|
2 | 2 | CONFIG += cpu |
|
3 | 3 | |
|
4 | 4 | |
|
5 | 5 | UCMODEL=stm32f4 |
|
6 | 6 | BSP = OPLAYER |
|
7 | #BSP = STM32F4Discovery-ILI9328-8bits | |
|
7 | 8 | |
|
8 |
DEFINES += CPUFREQ= |
|
|
9 | DEFINES += CPUFREQ=50000000 | |
|
9 | 10 | |
|
10 | 11 | |
|
11 | 12 | SOURCES += \ |
|
12 | 13 | main.c \ |
|
13 | 14 | test_lcd.c |
|
14 | 15 |
@@ -1,204 +1,213 | |||
|
1 | 1 | #include <stdio.h> |
|
2 | 2 | #include <fat32.h> |
|
3 | 3 | #include <gpio.h> |
|
4 | 4 | #include <uart.h> |
|
5 | 5 | #include <stm32f4xx.h> |
|
6 | 6 | #include <bsp.h> |
|
7 | 7 | #include <core.h> |
|
8 | 8 | #include <VS10XX.h> |
|
9 | 9 | #include <bsp.h> |
|
10 | 10 | #include <spi.h> |
|
11 | 11 | #include <sdcard.h> |
|
12 | 12 | #include <sdcard-spi.h> |
|
13 | 13 | #include <fat32.h> |
|
14 | 14 | #include <ucdirent.h> |
|
15 | 15 | #include <string.h> |
|
16 | 16 | #include <terminal.h> |
|
17 | 17 | #include <ili9328.h> |
|
18 | 18 | |
|
19 | 19 | |
|
20 | 20 | extern streamdevice* __opnfiles__[]; |
|
21 | 21 | extern void test_Block_Move(LCD_t* LCD,int x,int y,int w,int h,int color); |
|
22 | extern void test_all_colors(LCD_t* LCD); | |
|
23 | extern void test_small_lines(LCD_t* LCD); | |
|
24 | void test_uniform_rw(LCD_t* LCD); | |
|
22 | 25 | char buffer[512]; |
|
23 | 26 | |
|
24 | 27 | void randBoxesDemo() |
|
25 | 28 | { |
|
26 | 29 | int16_t x,y,w,h,t,r; |
|
27 | 30 | x=rand()%240; |
|
28 | 31 | y=rand()%320; |
|
29 | 32 | w=rand()%(240-x); |
|
30 | 33 | if(x>y) |
|
31 | 34 | r=(rand()%(y))%(320-y); |
|
32 | 35 | else |
|
33 | 36 | r=(rand()%(x))%(240-x); |
|
34 | 37 | h=rand()%(320-y); |
|
35 | 38 | t=rand()%(10); |
|
36 | 39 | ili9328paintFilRect(&lcd0,x,y,w,h,rand(),t,rand()); |
|
37 | 40 | //ili9328paintFilCirc(&lcd0,x,y,r,rand(),t,rand()); |
|
38 | 41 | //delay_100us(10); |
|
39 | 42 | //for(volatile int i=0;i<(1024*2);i++); |
|
40 | 43 | } |
|
41 | 44 | |
|
42 | 45 | void randTextDemo() |
|
43 | 46 | { |
|
44 | 47 | int16_t x,y,w,h,t,r; |
|
45 | 48 | char buf[2]; |
|
46 | 49 | buf[1]='\0'; |
|
47 | 50 | x=rand()%240; |
|
48 | 51 | y=rand()%320; |
|
49 | 52 | if(x>y) |
|
50 | 53 | r=(rand()%(y))%(320-y); |
|
51 | 54 | else |
|
52 | 55 | r=(rand()%(x))%(240-x); |
|
53 | 56 | h=rand()%(320-y); |
|
54 | 57 | buf[0]=rand()%(255); |
|
55 | 58 | //ili9328paintFilRect(&lcd0,x,y,w,h,rand(),t,rand()); |
|
56 | 59 | ili9328paintText(&lcd0,buf,x,y,&ComicSansMS_18,rand()); |
|
57 | 60 | //ili9328paintFilCirc(&lcd0,x,y,r,rand(),t,rand()); |
|
58 | 61 | delay_100us(5000); |
|
59 | 62 | //for(volatile int i=0;i<(1024*2);i++); |
|
60 | 63 | } |
|
61 | 64 | |
|
62 | 65 | void tryToplay2() |
|
63 | 66 | { |
|
64 | 67 | |
|
65 | 68 | extern blkdevice sdcard2blkdev; |
|
66 | 69 | int i=0,l=0; |
|
67 | 70 | |
|
68 | 71 | spisetspeed(audioCodec0.SPIdev,4000000); |
|
69 | 72 | printf("Streaming File\n"); |
|
70 | 73 | |
|
71 | 74 | //printf("New LBA=0x%X\n",nextLba); |
|
72 | 75 | |
|
73 | 76 | while(sdcard2blkdev.read(&sdcard2blkdev,buffer,l++,1)==RES_OK) |
|
74 | 77 | { |
|
75 | 78 | |
|
76 | 79 | for(i=0;i<512;i+=32) |
|
77 | 80 | { |
|
78 | 81 | vs10XXstream32bytes(&audioCodec0,buffer+i); |
|
79 | 82 | } |
|
80 | 83 | } |
|
81 | 84 | } |
|
82 | 85 | |
|
83 | 86 | void playFile(ucdirent* file,FAT32fs* part) |
|
84 | 87 | { |
|
85 | 88 | extern volatile vs10XXDev audioCodec0; |
|
86 | 89 | char direntName[]=" \n"; |
|
87 | 90 | uint32_t fileLba,nextLba; |
|
88 | 91 | int i=0; |
|
89 | 92 | fat32getdirentname(file,direntName); |
|
90 | 93 | //gpioset(LCD_BACKL); |
|
91 | 94 | printf("%s\n",direntName); |
|
92 | 95 | nextLba=fat32getdirentlba(file); |
|
93 | 96 | //printf("Streaming File\n"); |
|
94 | 97 | //gpioclr(LCD_BACKL); |
|
95 | 98 | do |
|
96 | 99 | { |
|
97 | 100 | fileLba = nextLba; |
|
98 | 101 | if(sdcard2FAT32part1.part->phy->read(part->part->phy,buffer,fileLba,1)==RES_OK) |
|
99 | 102 | { |
|
100 | 103 | for(i=0;i<512;i+=32) |
|
101 | 104 | { |
|
102 | 105 | vs10XXstream32bytes(&audioCodec0,buffer+i); |
|
103 | 106 | } |
|
104 | 107 | } |
|
105 | 108 | }while ((fat32nextsectorlba(part,fileLba,&nextLba)==DIRENT_noErr) && (!gpiogetval(BP3))); |
|
106 | 109 | vs10XXsoftReset(&audioCodec0); |
|
107 | 110 | while (gpiogetval(BP3))delay_100us(1000); |
|
108 | 111 | } |
|
109 | 112 | |
|
110 | 113 | void playAllparts() |
|
111 | 114 | { |
|
112 | 115 | extern FAT32fs sdcard2FAT32part1,sdcard2FAT32part2,sdcard2FAT32part3,sdcard2FAT32part4; |
|
113 | 116 | ucdirent root; |
|
114 | 117 | if(DIRENT_noErr==fat32mkdirent(&sdcard2FAT32part1,&root)) |
|
115 | 118 | { |
|
116 | 119 | printf("Reading on SDCARD2 part1\n"); |
|
117 | 120 | if(DIRENT_noErr==fat32getrootfirstent(&root)) |
|
118 | 121 | { |
|
119 | 122 | do{ |
|
120 | 123 | playFile(&root,&sdcard2FAT32part1); |
|
121 | 124 | }while (DIRENT_noErr==fat32nextdirent(&root)); |
|
122 | 125 | } |
|
123 | 126 | } |
|
124 | 127 | gpioset(LED2); |
|
125 | 128 | if(DIRENT_noErr==fat32mkdirent(&sdcard2FAT32part2,&root)) |
|
126 | 129 | { |
|
127 | 130 | printf("Reading on SDCARD2 part2\n"); |
|
128 | 131 | if(DIRENT_noErr==fat32getrootfirstent(&root)) |
|
129 | 132 | { |
|
130 | 133 | do{ |
|
131 | 134 | playFile(&root,&sdcard2FAT32part2); |
|
132 | 135 | }while (DIRENT_noErr==fat32nextdirent(&root)); |
|
133 | 136 | } |
|
134 | 137 | } |
|
135 | 138 | } |
|
136 | 139 | |
|
137 |
int main |
|
|
140 | int main() | |
|
138 | 141 | { |
|
139 | 142 | delay_100us(30000); |
|
140 | 143 | int i=0; |
|
141 | 144 | int color=0; |
|
145 | // test_all_colors(&lcd0); | |
|
146 | test_small_lines(&lcd0); | |
|
147 | test_uniform_rw(&lcd0); | |
|
148 | ||
|
149 | printf("LCD ID REG = 0x%X\n\r",lcd0.interface->readreg(ILI9328_REGISTER_DRIVERCODEREAD)); | |
|
150 | while(1); | |
|
142 | 151 | for(i=0;i<240;i++) |
|
143 | 152 | { |
|
144 | 153 | if(i>(240/3)) |
|
145 | 154 | { |
|
146 | 155 | color= (i<<5) + 0x1F; |
|
147 | 156 | } |
|
148 | 157 | else |
|
149 | 158 | { |
|
150 | 159 | color = i; |
|
151 | 160 | } |
|
152 | 161 | if(i>(2*240/3)) |
|
153 | 162 | { |
|
154 | 163 | color= (i<<10) + 0x3FF; |
|
155 | 164 | } |
|
156 | 165 | lcd0.paintFilRect(&lcd0,i,0,1,100,0,0,color); |
|
157 | 166 | } |
|
158 | 167 | while(1)printf("test "); |
|
159 | 168 | // for(i=0;i<240;i++) |
|
160 | 169 | // { |
|
161 | 170 | // if(i>(240/3)) |
|
162 | 171 | // { |
|
163 | 172 | // color= (i<<5) + 0x1F; |
|
164 | 173 | // } |
|
165 | 174 | // else |
|
166 | 175 | // { |
|
167 | 176 | // color = i; |
|
168 | 177 | // } |
|
169 | 178 | // if(i>(2*240/3)) |
|
170 | 179 | // { |
|
171 | 180 | // color= (i<<10) + 0x3FF; |
|
172 | 181 | // } |
|
173 | 182 | // lcd0.paintFilRect(&lcd0,i,220,1,100,0,0,color); |
|
174 | 183 | // } |
|
175 | 184 | for(i=0;i<240;i++) |
|
176 | 185 | { |
|
177 | 186 | ili9328setFrame(&lcd0,i,0,1,100); |
|
178 | 187 | lcd0.interface->readGRAM(buffer,100); |
|
179 | 188 | lcd0.paint(&lcd0,buffer,i,200,1,100); |
|
180 | 189 | } |
|
181 | 190 | while(1); |
|
182 | 191 | } |
|
183 | 192 | |
|
184 | int main() | |
|
193 | int main2() | |
|
185 | 194 | { |
|
186 | 195 | extern terminal_t terminal0; |
|
187 | 196 | extern volatile vs10XXDev audioCodec0; |
|
188 | 197 | printf("Volume=0x%x\n",vs10XXcmdread(&audioCodec0,VSVOL)); |
|
189 | 198 | vs10XXcmdwrite(&audioCodec0,VSCLOCKF,0x2000); |
|
190 | 199 | delay_100us(1000); |
|
191 | 200 | vs10XXcmdwrite(&audioCodec0,VSVOL,0x2020); |
|
192 | 201 | printf("VSCLOCKF=0x%x\n",vs10XXcmdread(&audioCodec0,VSCLOCKF)); |
|
193 | 202 | printf("VSMODE=0x%x\n",vs10XXcmdread(&audioCodec0,VSMODE)); |
|
194 | 203 | //terminal_clear(&terminal0); |
|
195 | 204 | // gpioclr(LCD_BACKL); |
|
196 | 205 | playAllparts(); |
|
197 | 206 | return 0; |
|
198 | 207 | } |
|
199 | 208 | |
|
200 | 209 | |
|
201 | 210 | |
|
202 | 211 | |
|
203 | 212 | |
|
204 | 213 |
@@ -1,23 +1,70 | |||
|
1 | 1 | #include <stdio.h> |
|
2 | 2 | #include <fat32.h> |
|
3 | 3 | #include <gpio.h> |
|
4 | 4 | #include <uart.h> |
|
5 | 5 | #include <stm32f4xx.h> |
|
6 | 6 | #include <bsp.h> |
|
7 | 7 | #include <core.h> |
|
8 | 8 | #include <VS10XX.h> |
|
9 | 9 | #include <bsp.h> |
|
10 | 10 | #include <spi.h> |
|
11 | 11 | #include <sdcard.h> |
|
12 | 12 | #include <sdcard-spi.h> |
|
13 | 13 | #include <fat32.h> |
|
14 | 14 | #include <ucdirent.h> |
|
15 | 15 | #include <string.h> |
|
16 | 16 | #include <terminal.h> |
|
17 | 17 | #include <ili9328.h> |
|
18 | 18 | |
|
19 | 19 | |
|
20 | 20 | void test_Block_Move(LCD_t* LCD,int x,int y,int w,int h,int color) |
|
21 | 21 | { |
|
22 | 22 | LCD->paintFilRect(LCD,x,y,w,h,0,0,color); |
|
23 | 23 | } |
|
24 | ||
|
25 | void test_small_lines(LCD_t* LCD) | |
|
26 | { | |
|
27 | int i=0; | |
|
28 | for(i=0;i<LCD->height;i+=2) | |
|
29 | { | |
|
30 | LCD->paintFilRect(LCD,0,i,LCD->width,1,0,0,0xaa00); | |
|
31 | } | |
|
32 | for(i=1;i<LCD->height;i+=2) | |
|
33 | { | |
|
34 | LCD->paintFilRect(LCD,0,i,LCD->width,1,0,0,0x5500); | |
|
35 | } | |
|
36 | ||
|
37 | } | |
|
38 | ||
|
39 | void test_uniform_rw(LCD_t* LCD) | |
|
40 | { | |
|
41 | uint16_t buffer[50*50]; | |
|
42 | LCD->paintFilRect(LCD,0,0,LCD->width,LCD->height/2,0,0,0xfaa0); | |
|
43 | delay_100us(10000); | |
|
44 | LCD->paintFilRect(LCD,0,0,LCD->width,LCD->height,0,0,0xfaa0); | |
|
45 | ili9328setFrame(LCD,10,100,50,50); | |
|
46 | while(1) | |
|
47 | { | |
|
48 | // LCD->interface->readGRAM((void*)buffer,50*50); | |
|
49 | LCD->getPix(LCD,buffer,10,100,50,50); | |
|
50 | LCD->paint(LCD,buffer,10,100,50,50); | |
|
51 | delay_100us(10000); | |
|
52 | //ili9328setFrame(LCD,10,100,50,50); | |
|
53 | //LCD->interface->writeGRAM((void*)buffer,50*50); | |
|
54 | } | |
|
55 | ||
|
56 | } | |
|
57 | ||
|
58 | void test_all_colors(LCD_t* LCD) | |
|
59 | { | |
|
60 | uint16_t color=0; | |
|
61 | char colorch[]=" "; | |
|
62 | while(1) | |
|
63 | { | |
|
64 | LCD->paintFilRect(LCD,0,0,LCD->width,LCD->height,0,0,color); | |
|
65 | sprintf(colorch,"0x%x",0xFFFF & ((int)color)); | |
|
66 | LCD->paintText(LCD,colorch,10,100,&ComicSansMS_18,color^-1); | |
|
67 | //delay_100us(10); | |
|
68 | color+=1; | |
|
69 | } | |
|
70 | } |
@@ -1,56 +1,71 | |||
|
1 | 1 | #include <stdio.h> |
|
2 | 2 | #include <fat32.h> |
|
3 | 3 | #include <gpio.h> |
|
4 | 4 | #include <uart.h> |
|
5 | 5 | #include <bsp.h> |
|
6 | 6 | #include <core.h> |
|
7 | 7 | #include <bsp.h> |
|
8 | 8 | #include <spi.h> |
|
9 | 9 | #include <fat32.h> |
|
10 | 10 | #include <ucdirent.h> |
|
11 | 11 | #include <string.h> |
|
12 | 12 | #include <unistd.h> |
|
13 | 13 | #include <terminal.h> |
|
14 | 14 | #include <stdarg.h> |
|
15 | 15 | #include <malloc.h> |
|
16 | 16 | |
|
17 | 17 | extern streamdevice* __opnfiles__[]; |
|
18 | 18 | extern void test_Block_Move(LCD_t* LCD,int x,int y,int w,int h,int color); |
|
19 | 19 | char buffer[512]; |
|
20 | 20 | |
|
21 | ||
|
21 | 22 | void streamdevicePrint(streamdevice* dev, const char* format,...) |
|
22 | 23 | { |
|
23 | 24 | char** str_buffer; |
|
24 | 25 | int i; |
|
25 | 26 | va_list ap; |
|
26 | 27 | va_start(ap,format); |
|
27 | 28 | vasprintf(str_buffer,format,ap); |
|
28 | 29 | va_end(ap); |
|
29 | 30 | i=strlen(*str_buffer); |
|
30 | 31 | dev->ops->write(dev,(void*)*str_buffer,1,i); |
|
31 | 32 | free(*str_buffer); |
|
32 | 33 | } |
|
33 | 34 | |
|
35 | //int printf(const char *format,...) | |
|
36 | //{ | |
|
37 | // char** str_buffer; | |
|
38 | // int i; | |
|
39 | // va_list ap; | |
|
40 | // va_start(ap,format); | |
|
41 | // vasprintf(str_buffer,format,ap); | |
|
42 | // va_end(ap); | |
|
43 | // i=strlen(*str_buffer); | |
|
44 | // __opnfiles__[1]->ops->write(__opnfiles__[1],(void*)*str_buffer,1,i); | |
|
45 | // free(*str_buffer); | |
|
46 | ||
|
47 | //} | |
|
48 | ||
|
34 | 49 | void lcd_print() |
|
35 | 50 | { |
|
36 | 51 | lcd0.paintFilRect(&lcd0,10,10,100,100,0,0,0x0F0F); |
|
37 | 52 | // __opnfiles__[1]->ops->write(__opnfiles__[1],(void*)"hello",1,5); |
|
38 | 53 | } |
|
39 | 54 | |
|
40 | 55 | int libuc_main() |
|
41 | 56 | { |
|
42 | 57 | char in[255]; |
|
43 | 58 | lcd_print(); |
|
44 | 59 | printf("hello world\n"); |
|
45 | 60 | streamdevicePrint(__opnfiles__[1],"test Hello %d %f \n",1234567,8.96); |
|
46 | 61 | lcd0.paintText(&lcd0,"A",10,100,&ComicSansMS_18,0x0); |
|
47 | 62 | // while (scanf("%c",in)) |
|
48 | 63 | // { |
|
49 | 64 | sleep(5); |
|
50 | 65 | // } |
|
51 | 66 | } |
|
52 | 67 | |
|
53 | 68 | |
|
54 | 69 | |
|
55 | 70 | |
|
56 | 71 |
@@ -1,13 +1,13 | |||
|
1 | 1 | TEMPLATE = app |
|
2 | 2 | CONFIG += cpu |
|
3 | 3 | |
|
4 | 4 | |
|
5 | 5 | UCMODEL=stm32f4 |
|
6 | 6 | |
|
7 | 7 | BSP = STM32F4Eval |
|
8 | 8 | |
|
9 |
DEFINES += CPUFREQ= |
|
|
9 | DEFINES += CPUFREQ=168000000 | |
|
10 | 10 | |
|
11 | 11 | SOURCES += \ |
|
12 | 12 | main.c |
|
13 | 13 |
@@ -1,94 +1,127 | |||
|
1 | 1 | #include <stdio.h> |
|
2 | 2 | #include <fat32.h> |
|
3 | 3 | #include <gpio.h> |
|
4 | 4 | #include <uart.h> |
|
5 | 5 | #include <stm32f4xx.h> |
|
6 | 6 | #include <math.h> |
|
7 | 7 | #include <bsp.h> |
|
8 | 8 | #include <i2c.h> |
|
9 | 9 | #include <CS43L22.h> |
|
10 | 10 | #include <STMPE811.h> |
|
11 | 11 | #include <ina226.h> |
|
12 | 12 | #include <fonts.h> |
|
13 | 13 | #include <stdlib.h> |
|
14 | 14 | #include <core.h> |
|
15 | 15 | #include <terminal.h> |
|
16 | 16 | |
|
17 | 17 | extern streamdevice* __opnfiles__[__MAX_OPENED_FILES__]; |
|
18 | 18 | |
|
19 | 19 | #define LCD_COLOR_WHITE 0xFFFF |
|
20 | 20 | #define LCD_COLOR_BLACK 0x0000 |
|
21 | 21 | #define LCD_COLOR_GREY 0xF7DE |
|
22 | 22 | #define LCD_COLOR_BLUE 0x001F |
|
23 | 23 | #define LCD_COLOR_BLUE2 0x051F |
|
24 | 24 | #define LCD_COLOR_RED 0xF800 |
|
25 | 25 | #define LCD_COLOR_MAGENTA 0xF81F |
|
26 | 26 | #define LCD_COLOR_GREEN 0x07E0 |
|
27 | 27 | #define LCD_COLOR_CYAN 0x7FFF |
|
28 | 28 | #define LCD_COLOR_YELLOW 0xFFE0 |
|
29 | 29 | |
|
30 | 30 | void testAudioDAC() |
|
31 | 31 | { |
|
32 | 32 | CS43L22_t dac; |
|
33 | 33 | cs43l22open(&dac,i2c1,0); |
|
34 | 34 | uint8_t ID= cs43l22getID(&dac); |
|
35 | 35 | printf("dac ID = %d\n\r",ID); |
|
36 | 36 | } |
|
37 | 37 | |
|
38 | 38 | void testIOEXPender() |
|
39 | 39 | { |
|
40 | 40 | STMPE811_t ioexp1,ioexp2; |
|
41 | 41 | char data[2]={0,0}; |
|
42 | 42 | i2cwrite(i2c1,0x50,data,1); |
|
43 | 43 | |
|
44 | 44 | //i2cread(i2c1,0x88,data,2); |
|
45 | 45 | // stmpe811init(&ioexp1,i2c1,0); |
|
46 | 46 | // stmpe811init(&ioexp2,i2c1,1); |
|
47 | 47 | // printf("Scan for IOEXPANDER:\n\r ID1=%d\n\rID2=%d",stmpe811getID(&ioexp1),stmpe811getID(&ioexp2)); |
|
48 | 48 | } |
|
49 | 49 | |
|
50 | int _terminal_writenc(terminal_t* terminal,char* data, int n) | |
|
51 | { | |
|
52 | #define CHARXPOS(terminal,charwidth) (((terminal)->column * charwidth) + (terminal)->Xpos) | |
|
53 | #define CHARYPOS(terminal,charheight) ((terminal)->line * charheight + (terminal)->Ypos+charheight) | |
|
54 | int charw=terminal->font->Width + terminal->horizontalSpace; | |
|
55 | int charh=terminal->font->Height + terminal->verticalSpace; | |
|
56 | int l=0; | |
|
57 | char buffer[2]=" "; | |
|
58 | while(l<n) | |
|
59 | { | |
|
60 | ||
|
61 | buffer[0]=data[l]; | |
|
62 | if(buffer[0]=='\n') | |
|
63 | { | |
|
64 | terminal->line= (terminal->line+1) % terminal->lineCount; | |
|
65 | terminal->column = 0; | |
|
66 | // if(terminal->line==0) | |
|
67 | // terminal_clear(terminal); | |
|
68 | // else | |
|
69 | // terminal_clearCurentLine(terminal); | |
|
70 | }else { | |
|
71 | if(buffer[0]=='\t') | |
|
72 | { | |
|
73 | for(int i=0;i<1;i++)terminal_movecursor(terminal,1); | |
|
74 | } | |
|
75 | // else | |
|
76 | // if(terminal->column==0)terminal_clearCurentLine(terminal); | |
|
77 | if(buffer[0]!='\r'){ | |
|
78 | // terminal->LCD->paintFilRect(terminal->LCD,CHARXPOS(terminal,charw),CHARYPOS(terminal, charh)-charh,charw,charh,terminal->backgroundColor,0,terminal->backgroundColor); | |
|
79 | terminal->LCD->paintText(terminal->LCD,buffer,CHARXPOS(terminal,charw),(CHARYPOS(terminal, charh))-(terminal->verticalSpace/2),terminal->font,terminal->textColor); | |
|
80 | terminal_movecursor(terminal,1); | |
|
81 | } | |
|
82 | } | |
|
83 | l++; | |
|
84 | } | |
|
85 | return n; | |
|
86 | } | |
|
87 | ||
|
50 | 88 | int main() |
|
51 | 89 | { |
|
52 | 90 | delay_100us(10000); |
|
53 | 91 | uint16_t innerbuffer[16]; |
|
54 | 92 | uint16_t outterbuffer[16]; |
|
55 | 93 | for(int i=0;i<16;i++)innerbuffer[i]=LCD_COLOR_BLUE; |
|
56 | 94 | for(int i=0;i<16;i++)outterbuffer[i]=LCD_COLOR_RED; |
|
57 | 95 | ili9328paintFilRect(&lcd0,0,0,240,320,LCD_COLOR_CYAN,5,LCD_COLOR_BLACK); |
|
58 | 96 | |
|
59 | 97 | streamdevice* fd1=__opnfiles__[1]; |
|
60 | 98 | streamdevice fd2; |
|
61 | 99 | int i=0; |
|
62 | 100 | terminal_t terminal0,terminal1; |
|
63 | 101 | terminal_init(&terminal0,&lcd0,&ComicSansMS_18,fd1); |
|
64 | 102 | //terminal_init(&terminal1,&lcd0,&ComicSansMS_18,&fd2); |
|
65 | 103 | terminal_setgeometry(&terminal0,5,5,terminal0.LCD->width-10,(terminal0.LCD->height)-10); |
|
66 | 104 | //terminal_setbackgroundColor(&terminal1,0xFFFF); |
|
67 | 105 | //terminal_settextColor(&terminal1,0x0000); |
|
68 | 106 | //terminal_setgeometry(&terminal1,5,(terminal0.LCD->height/2)+5,terminal0.LCD->width-10,(terminal0.LCD->height/2)-10); |
|
69 | 107 | printf("Line cnt :\n \t%d\n",terminal0.lineCount); |
|
70 | 108 | printf("Column cnt :\n \t%d\n",terminal0.columnCount); |
|
71 | 109 | printf("CPU Freq :\n \t%dMHz\n",getCpuFreq()/1000000); |
|
72 | 110 | //testAudioDAC(); |
|
73 | testIOEXPender(); | |
|
74 | while(1) | |
|
111 | for(int i=0;i<240;i++) | |
|
75 | 112 | { |
|
76 | i%=1000; | |
|
77 | //terminal->write(&terminal," Hi",1, 2); | |
|
78 | //delay_100us(1000); | |
|
79 | gpioset(LED1); | |
|
80 | //delay_100us(1000); | |
|
81 | gpioclr(LED1); | |
|
113 | lcd0.paintFilRect(&lcd0,i,0,1,320,0,0,i); | |
|
82 | 114 | } |
|
83 | printf("hello world\n\r"); | |
|
115 | lcd0.paintText(&lcd0,"A",100,100,&ComicSansMS_24,0); | |
|
116 | while(1)_terminal_writenc(&terminal0,"test ",5); | |
|
84 | 117 | return 0; |
|
85 | 118 | } |
|
86 | 119 | |
|
87 | 120 | |
|
88 | 121 | |
|
89 | 122 | |
|
90 | 123 | |
|
91 | 124 | |
|
92 | 125 | |
|
93 | 126 | |
|
94 | 127 |
@@ -1,422 +1,482 | |||
|
1 | 1 | /*------------------------------------------------------------------------------ |
|
2 | 2 | -- This file is a part of the libuc, microcontroler library |
|
3 | 3 | -- Copyright (C) 2012, Alexis Jeandet |
|
4 | 4 | -- |
|
5 | 5 | -- This program is free software; you can redistribute it and/or modify |
|
6 | 6 | -- it under the terms of the GNU General Public License as published by |
|
7 | 7 | -- the Free Software Foundation; either version 3 of the License, or |
|
8 | 8 | -- (at your option) any later version. |
|
9 | 9 | -- |
|
10 | 10 | -- This program is distributed in the hope that it will be useful, |
|
11 | 11 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 | 12 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
13 | 13 | -- GNU General Public License for more details. |
|
14 | 14 | -- |
|
15 | 15 | -- You should have received a copy of the GNU General Public License |
|
16 | 16 | -- along with this program; if not, write to the Free Software |
|
17 | 17 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
18 | 18 | ------------------------------------------------------------------------------- |
|
19 | 19 | -- Author : Alexis Jeandet |
|
20 | 20 | -- Mail : alexis.jeandet@member.fsf.org |
|
21 | 21 | -------------------------------------------------------------------------------*/ |
|
22 | #define _PRVATE_ILI9328_ | |
|
22 | 23 | #include <ili9328.h> |
|
23 | 24 | #include <stdio.h> |
|
24 | 25 | #include <stddef.h> |
|
25 | 26 | #include <core.h> |
|
26 | 27 | #include <math.h> |
|
28 | #include <stdint.h> | |
|
27 | 29 | |
|
28 | 30 | #ifdef __OPTIMIZED_MATH |
|
29 | 31 | #include <optimised_math.h> |
|
30 | 32 | #endif |
|
31 | 33 | |
|
32 | 34 | |
|
33 | 35 | #define ilipaintLine(LCD,X,Y,W,buffer,buffsize) \ |
|
34 | 36 | for(int l=0;l<1;l++)\ |
|
35 | 37 | {\ |
|
36 | 38 | ili9328setFrame(LCD,X,Y,W,1);\ |
|
37 | 39 | int rem=(W)%buffsize;\ |
|
38 | 40 | if(rem)LCD->interface->writeGRAM(buffer,rem);\ |
|
39 | 41 | for(int i=rem;i<(W);i+=buffsize)\ |
|
40 | 42 | {\ |
|
41 | 43 | LCD->interface->writeGRAM(buffer,buffsize);\ |
|
42 | 44 | }\ |
|
43 | 45 | } |
|
44 | 46 | |
|
45 | 47 | #define ilipaintHLineWithCont(LCD,X,Y,W,ContSz,bufferInt,buffIntsize,bufferCont,buffContsize) \ |
|
46 | 48 | for(int l=0;l<1;l++)\ |
|
47 | 49 | {\ |
|
48 | 50 | ili9328setFrame(LCD,X,Y,W,1);\ |
|
49 | 51 | int rem=(ContSz)%buffContsize;\ |
|
50 | 52 | if(rem)LCD->interface->writeGRAM(bufferCont,rem);\ |
|
51 | 53 | for(int i=rem;i<(ContSz);i+=buffContsize)\ |
|
52 | 54 | {\ |
|
53 | 55 | LCD->interface->writeGRAM(bufferCont,buffContsize);\ |
|
54 | 56 | }\ |
|
55 | 57 | if((2*ContSz)<W) \ |
|
56 | 58 | {\ |
|
57 | 59 | rem=(W-(2*ContSz))%buffIntsize;\ |
|
58 | 60 | if(rem)LCD->interface->writeGRAM(bufferInt,rem);\ |
|
59 | 61 | for(int i=rem;i<(W-(2*ContSz));i+=buffIntsize)\ |
|
60 | 62 | {\ |
|
61 | 63 | LCD->interface->writeGRAM(bufferInt,buffIntsize);\ |
|
62 | 64 | }\ |
|
63 | 65 | }\ |
|
64 | 66 | rem=(ContSz)%buffContsize;\ |
|
65 | 67 | if(rem)LCD->interface->writeGRAM(bufferCont,rem);\ |
|
66 | 68 | for(int i=rem;i<(ContSz);i+=buffContsize)\ |
|
67 | 69 | {\ |
|
68 | 70 | LCD->interface->writeGRAM(bufferCont,buffContsize);\ |
|
69 | 71 | }\ |
|
70 | 72 | }\ |
|
71 | 73 | |
|
72 | 74 | |
|
73 | 75 | #define ilipaintVLineWithCont(LCD,X,Y,H,ContSz,bufferInt,buffIntsize,bufferCont,buffContsize) \ |
|
74 | 76 | for(int l=0;l<1;l++)\ |
|
75 | 77 | {\ |
|
76 | 78 | ili9328setFrame(LCD,X,Y,1,H);\ |
|
77 | 79 | int rem=(ContSz)%buffContsize;\ |
|
78 | 80 | if(rem)LCD->interface->writeGRAM(bufferCont,rem);\ |
|
79 | 81 | for(int i=rem;i<(ContSz);i+=buffContsize)\ |
|
80 | 82 | {\ |
|
81 | 83 | LCD->interface->writeGRAM(bufferCont,buffContsize);\ |
|
82 | 84 | }\ |
|
83 | 85 | if((2*ContSz)<H) \ |
|
84 | 86 | {\ |
|
85 | 87 | rem=(H-(2*ContSz))%buffIntsize;\ |
|
86 | 88 | if(rem)LCD->interface->writeGRAM(bufferInt,rem);\ |
|
87 | 89 | for(int i=rem;i<(H-(2*ContSz));i+=buffIntsize)\ |
|
88 | 90 | {\ |
|
89 | 91 | LCD->interface->writeGRAM(bufferInt,buffIntsize);\ |
|
90 | 92 | }\ |
|
91 | 93 | }\ |
|
92 | 94 | rem=(ContSz)%buffContsize;\ |
|
93 | 95 | if(rem)LCD->interface->writeGRAM(bufferCont,rem);\ |
|
94 | 96 | for(int i=rem;i<(ContSz);i+=buffContsize)\ |
|
95 | 97 | {\ |
|
96 | 98 | LCD->interface->writeGRAM(bufferCont,buffContsize);\ |
|
97 | 99 | }\ |
|
98 | 100 | }\ |
|
99 | 101 | |
|
100 | 102 | |
|
101 | 103 | #define ilipaintHalfTopVLineWithCont(LCD,X,Y,H,ContSz,bufferInt,buffIntsize,bufferCont,buffContsize) \ |
|
102 | 104 | for(int l=0;l<1;l++)\ |
|
103 | 105 | {\ |
|
104 | 106 | ili9328setFrame(LCD,X,Y,1,H);\ |
|
105 | 107 | int rem=(ContSz)%buffContsize;\ |
|
106 | 108 | if(rem)LCD->interface->writeGRAM(bufferCont,rem);\ |
|
107 | 109 | for(int i=rem;i<(ContSz);i+=buffContsize)\ |
|
108 | 110 | {\ |
|
109 | 111 | LCD->interface->writeGRAM(bufferCont,buffContsize);\ |
|
110 | 112 | }\ |
|
111 | 113 | if(ContSz<H) \ |
|
112 | 114 | {\ |
|
113 | 115 | rem=(H-ContSz)%buffIntsize;\ |
|
114 | 116 | if(rem)LCD->interface->writeGRAM(bufferInt,rem);\ |
|
115 | 117 | for(int i=rem;i<(H-ContSz);i+=buffIntsize)\ |
|
116 | 118 | {\ |
|
117 | 119 | LCD->interface->writeGRAM(bufferInt,buffIntsize);\ |
|
118 | 120 | }\ |
|
119 | 121 | }\ |
|
120 | 122 | }\ |
|
121 | 123 | |
|
122 | 124 | |
|
123 | 125 | #define ilipaintHalfBottomVLineWithCont(LCD,X,Y,H,ContSz,bufferInt,buffIntsize,bufferCont,buffContsize) \ |
|
124 | 126 | for(int l=0;l<1;l++)\ |
|
125 | 127 | {\ |
|
126 | 128 | ili9328setFrame(LCD,X,Y,1,H);\ |
|
127 | 129 | int rem;\ |
|
128 | 130 | if(ContSz<H) \ |
|
129 | 131 | {\ |
|
130 | 132 | rem=(H-ContSz)%buffIntsize;\ |
|
131 | 133 | if(rem)LCD->interface->writeGRAM(bufferInt,rem);\ |
|
132 | 134 | for(int i=rem;i<(H-ContSz);i+=buffIntsize)\ |
|
133 | 135 | {\ |
|
134 | 136 | LCD->interface->writeGRAM(bufferInt,buffIntsize);\ |
|
135 | 137 | }\ |
|
136 | 138 | }\ |
|
137 | 139 | rem=(ContSz)%buffContsize;\ |
|
138 | 140 | if(rem)LCD->interface->writeGRAM(bufferCont,rem);\ |
|
139 | 141 | for(int i=rem;i<(ContSz);i+=buffContsize)\ |
|
140 | 142 | {\ |
|
141 | 143 | LCD->interface->writeGRAM(bufferCont,buffContsize);\ |
|
142 | 144 | }\ |
|
143 | 145 | }\ |
|
144 | 146 | |
|
145 | 147 | |
|
146 | 148 | void ili9328setGRAMaddress(LCD_t* LCD,uint16_t Haddress,uint16_t Vaddress) |
|
147 | 149 | { |
|
148 | 150 | LCD->interface->writereg(ILI9328_REGISTER_HORIZONTALGRAMADDRESSSET,Haddress); |
|
149 | 151 | LCD->interface->writereg(ILI9328_REGISTER_VERTICALGRAMADDRESSSET,Vaddress); |
|
150 | 152 | } |
|
151 | 153 | |
|
152 | 154 | void ili9328refreshenable(struct LCD_t* LCD,int enable) |
|
153 | 155 | { |
|
154 | 156 | if(enable) |
|
155 | 157 | { |
|
156 | 158 | //LCD->interface->writereg(ILI9328_REGISTER_ENTRYMODE,0x1018); |
|
157 | 159 | } |
|
158 | 160 | else |
|
159 | 161 | { |
|
160 | 162 | //LCD->interface->writereg(ILI9328_REGISTER_ENTRYMODE,0x1008); |
|
161 | 163 | |
|
162 | 164 | } |
|
163 | 165 | } |
|
164 | 166 | |
|
165 | 167 | void ili9328setFrame(LCD_t* LCD,uint16_t X,uint16_t Y,uint16_t W,uint16_t H) |
|
166 | 168 | { |
|
167 | 169 | LCD->interface->writereg(ILI9328_REGISTER_HORIZONTALGRAMADDRESSSET,(uint32_t)X); |
|
168 | 170 | LCD->interface->writereg(ILI9328_REGISTER_VERTICALGRAMADDRESSSET,(uint32_t)Y); |
|
169 | 171 | LCD->interface->writereg(ILI9328_REGISTER_HORIZONTALADDRESSSTARTPOSITION,(uint32_t)X); |
|
170 | 172 | LCD->interface->writereg(ILI9328_REGISTER_HORIZONTALADDRESSENDPOSITION,(uint32_t)(W+X-1)); |
|
171 | 173 | LCD->interface->writereg(ILI9328_REGISTER_VERTICALADDRESSSTARTPOSITION,(uint32_t)Y); |
|
172 | 174 | LCD->interface->writereg(ILI9328_REGISTER_VERTICALADDRESSENDPOSITION,(uint32_t)(Y+H-1)); |
|
173 | 175 | } |
|
174 | 176 | |
|
175 | 177 | void ili9328paint(LCD_t* LCD,void* buffer,uint16_t Xpos,uint16_t Ypos,uint16_t Width,uint16_t Height) |
|
176 | 178 | { |
|
177 | 179 | if((LCD!=NULL) && (LCD->interface!=NULL) && (LCD->interface->writeGRAM!=NULL) && (LCD->width>(Xpos+Width)) && (LCD->height>(Ypos+Height))) |
|
178 | 180 | { |
|
179 | 181 | ili9328setFrame(LCD,Xpos,Ypos,Width,Height); |
|
180 | 182 | LCD->interface->writeGRAM(buffer,Width*Height); |
|
181 | 183 | } |
|
182 | 184 | } |
|
183 | 185 | |
|
184 | 186 | void ili9328paintFilCirc(LCD_t* LCD,uint16_t Xpos,uint16_t Ypos,uint16_t r,uint32_t contColor,uint16_t contSz,uint32_t fillColor) |
|
185 | 187 | { |
|
186 | 188 | //Based on the mid point circle algorithm from Wikipedia |
|
187 | 189 | //http://en.wikipedia.org/wiki/Midpoint_circle_algorithm |
|
188 | 190 | uint16_t innerbuffer[16]; |
|
189 | 191 | uint16_t outterbuffer[16]; |
|
190 | 192 | for(int i=0;i<16;i++)innerbuffer[i]=fillColor; |
|
191 | 193 | for(int i=0;i<16;i++)outterbuffer[i]=contColor; |
|
192 | 194 | if(contSz<r) |
|
193 | 195 | { |
|
194 | 196 | int error = -r,error_int = -r+contSz; |
|
195 | 197 | int x = r,x_int=r-contSz; |
|
196 | 198 | int y = 0,y_int=0; |
|
197 | 199 | while (x >= y) |
|
198 | 200 | { |
|
199 | 201 | ilipaintHLineWithCont(LCD,(Xpos-x),(Ypos+y),(2*x),(x-x_int),innerbuffer,16,outterbuffer,16); |
|
200 | 202 | ilipaintHLineWithCont(LCD,(Xpos-x),(Ypos-y),(2*x),(x-x_int),innerbuffer,16,outterbuffer,16); |
|
201 | 203 | ilipaintHalfTopVLineWithCont(LCD,(Xpos+y),(Ypos-x),(x),(x-x_int),innerbuffer,16,outterbuffer,16); |
|
202 | 204 | ilipaintHalfTopVLineWithCont(LCD,(Xpos-y),(Ypos-x),(x),(x-x_int),innerbuffer,16,outterbuffer,16); |
|
203 | 205 | ilipaintHalfBottomVLineWithCont(LCD,(Xpos-y),(Ypos),(x),(x-x_int),innerbuffer,16,outterbuffer,16); |
|
204 | 206 | ilipaintHalfBottomVLineWithCont(LCD,(Xpos+y),(Ypos),(x),(x-x_int),innerbuffer,16,outterbuffer,16); |
|
205 | 207 | error += y; |
|
206 | 208 | ++y; |
|
207 | 209 | error += y; |
|
208 | 210 | error_int += y_int; |
|
209 | 211 | ++y_int; |
|
210 | 212 | error_int += y_int; |
|
211 | 213 | if(error >= 0) |
|
212 | 214 | { |
|
213 | 215 | error -= x; |
|
214 | 216 | --x; |
|
215 | 217 | error -= x; |
|
216 | 218 | } |
|
217 | 219 | if(error_int >= 0) |
|
218 | 220 | { |
|
219 | 221 | error_int -= x_int; |
|
220 | 222 | --x_int; |
|
221 | 223 | error_int -= x_int; |
|
222 | 224 | } |
|
223 | 225 | } |
|
224 | 226 | |
|
225 | 227 | |
|
226 | 228 | |
|
227 | 229 | } |
|
228 | 230 | |
|
229 | 231 | } |
|
230 | 232 | |
|
231 | 233 | void ili9328paintFilCirc_old(LCD_t* LCD,uint16_t Xpos,uint16_t Ypos,uint16_t r,uint32_t contColor,uint16_t contSz,uint32_t fillColor) |
|
232 | 234 | { |
|
233 | 235 | if(contSz<r) |
|
234 | 236 | { |
|
235 | 237 | uint16_t innerbuffer[16]; |
|
236 | 238 | uint16_t outterbuffer[16]; |
|
237 | 239 | int32_t rr=(r*r),rr2=((r-contSz)*(r-contSz)),contSz2,Val1,Val2,X1,W,rem; |
|
238 | 240 | for(int i=0;i<16;i++)innerbuffer[i]=fillColor; |
|
239 | 241 | for(int i=0;i<16;i++)outterbuffer[i]=contColor; |
|
240 | 242 | /* Y = b +/- sqrt[r^2 - (x - a)^2] */ |
|
241 | 243 | for(int32_t line=-r;line<r;line++) |
|
242 | 244 | { |
|
243 | 245 | #ifdef __OPTIMIZED_MATH |
|
244 | 246 | Val1 = (uint32_t)optimised_sqrt((float32_t)(rr - (line*line)) ); |
|
245 | 247 | Val2 = (uint32_t)optimised_sqrt((float32_t)(rr2 - (line*line)) ); |
|
246 | 248 | #else |
|
247 | 249 | Val1 = sqrt( (double)(rr - ((line)*(line))) ); |
|
248 | 250 | Val2 = sqrt( (double)(rr2 - ((line)*(line))) ); |
|
249 | 251 | #endif |
|
250 | 252 | X1=Xpos - Val1; |
|
251 | 253 | contSz2= Val1-Val2; |
|
252 | 254 | ili9328setFrame(LCD,X1,line+Ypos,2*Val1,1); |
|
253 | 255 | rem=(contSz2)%16; |
|
254 | 256 | if(rem)LCD->interface->writeGRAM(outterbuffer,rem); |
|
255 | 257 | for(int i=rem;i<(contSz2);i+=16) |
|
256 | 258 | { |
|
257 | 259 | LCD->interface->writeGRAM(outterbuffer,16); |
|
258 | 260 | } |
|
259 | 261 | |
|
260 | 262 | W=2*Val1; |
|
261 | 263 | if(W>(2*contSz2)) |
|
262 | 264 | { |
|
263 | 265 | W-=2*contSz2; |
|
264 | 266 | rem=(W)%16; |
|
265 | 267 | if(rem)LCD->interface->writeGRAM(innerbuffer,rem); |
|
266 | 268 | for(int i=rem;i<(W);i+=16) |
|
267 | 269 | { |
|
268 | 270 | LCD->interface->writeGRAM(innerbuffer,16); |
|
269 | 271 | } |
|
270 | 272 | } |
|
271 | 273 | |
|
272 | 274 | rem=(contSz2)%16; |
|
273 | 275 | if(rem)LCD->interface->writeGRAM(outterbuffer,rem); |
|
274 | 276 | for(int i=rem;i<(contSz2);i+=16) |
|
275 | 277 | { |
|
276 | 278 | LCD->interface->writeGRAM(outterbuffer,16); |
|
277 | 279 | } |
|
278 | 280 | } |
|
279 | 281 | } |
|
280 | 282 | } |
|
281 | 283 | |
|
282 | 284 | |
|
283 | 285 | |
|
284 | 286 | |
|
285 | 287 | void ili9328paintFilRect(LCD_t* LCD,uint16_t Xpos,uint16_t Ypos,uint16_t w,uint16_t h,uint32_t contColor,uint16_t contSz,uint32_t fillColor) |
|
286 | 288 | { |
|
287 | 289 | ili9328setFrame(LCD,Xpos,Ypos,w,h); |
|
288 | 290 | uint16_t tmp[32]; |
|
289 | 291 | for(int i=0;i<32;i++)tmp[i]=fillColor; |
|
290 | 292 | for(int i=0;i<(h*w);i+=32) |
|
291 | 293 | { |
|
292 | 294 | LCD->interface->writeGRAM(tmp,32); |
|
293 | 295 | } |
|
294 | 296 | int rem=(w*h)%32; |
|
295 | 297 | if(rem)LCD->interface->writeGRAM(tmp,rem); |
|
296 | 298 | if(contSz) |
|
297 | 299 | { |
|
298 | 300 | ili9328setFrame(LCD,Xpos,Ypos,w,contSz); |
|
299 | 301 | for(int i=0;i<32;i++)tmp[i]=contColor; |
|
300 | 302 | rem=(w*contSz)%32; |
|
301 | 303 | if(rem)LCD->interface->writeGRAM(tmp,rem); |
|
302 | 304 | for(int i=rem;i<(w*contSz);i+=32) |
|
303 | 305 | { |
|
304 | 306 | LCD->interface->writeGRAM(tmp,32); |
|
305 | 307 | } |
|
306 | 308 | |
|
307 | 309 | ili9328setFrame(LCD,Xpos,Ypos+h-contSz,w,contSz); |
|
308 | 310 | rem=(w*contSz)%32; |
|
309 | 311 | if(rem)LCD->interface->writeGRAM(tmp,rem); |
|
310 | 312 | for(int i=rem;i<(w*contSz);i+=32) |
|
311 | 313 | { |
|
312 | 314 | LCD->interface->writeGRAM(tmp,32); |
|
313 | 315 | } |
|
314 | 316 | |
|
315 | 317 | ili9328setFrame(LCD,Xpos,Ypos,contSz,h); |
|
316 | 318 | rem=(h*contSz)%32; |
|
317 | 319 | if(rem)LCD->interface->writeGRAM(tmp,rem); |
|
318 | 320 | for(int i=rem;i<(h*contSz);i+=32) |
|
319 | 321 | { |
|
320 | 322 | LCD->interface->writeGRAM(tmp,32); |
|
321 | 323 | } |
|
322 | 324 | |
|
323 | 325 | ili9328setFrame(LCD,Xpos+w-contSz,Ypos,contSz,h); |
|
324 | 326 | rem=(h*contSz)%32; |
|
325 | 327 | if(rem)LCD->interface->writeGRAM(tmp,rem); |
|
326 | 328 | for(int i=rem;i<(h*contSz);i+=32) |
|
327 | 329 | { |
|
328 | 330 | LCD->interface->writeGRAM(tmp,32); |
|
329 | 331 | } |
|
330 | 332 | } |
|
331 | 333 | } |
|
332 | 334 | |
|
333 | 335 | void ili9328paintText(LCD_t* LCD,char* buffer,uint16_t Xpos,uint16_t Ypos,sFONT* font,uint32_t color) |
|
334 | 336 | { |
|
335 | 337 | int w=font->Width,h=font->Height,bpl=font->bytesPerLine,pix=0,tableoffset=0; |
|
336 | 338 | uint16_t tmp[w]; |
|
337 | 339 | uint16_t linenum=0,charnum=0; |
|
338 | 340 | uint8_t line=0; |
|
339 | 341 | while(*buffer!='\0') |
|
340 | 342 | { |
|
341 | 343 | if(*buffer<32)*buffer=32; |
|
342 | 344 | if(*buffer>127)*buffer=32; |
|
343 | 345 | ili9328setFrame(LCD,Xpos+(charnum*w),Ypos-h,w,1); |
|
344 | LCD->interface->readGRAM(tmp,w); | |
|
346 | // LCD->interface->readGRAM(tmp,w); | |
|
347 | ili9328getPix(LCD,tmp,Xpos+(charnum*w),Ypos-h,w,1); | |
|
345 | 348 | for(int i=0;i<(h*w);i++) |
|
346 | 349 | { |
|
347 | 350 | if( ((i%w)==0) ) //read current line to apply text pixmap |
|
348 | 351 | { |
|
349 | 352 | if(linenum++>0) |
|
350 | 353 | { |
|
351 | 354 | ili9328setFrame(LCD,Xpos+(charnum*w),Ypos + linenum -h,w,1); |
|
352 | 355 | LCD->interface->writeGRAM(tmp,w); |
|
353 | 356 | ili9328setFrame(LCD,Xpos+(charnum*w),Ypos + linenum + 1-h,w,1); |
|
354 | LCD->interface->readGRAM(tmp,w); | |
|
357 | // LCD->interface->readGRAM(tmp,w); | |
|
358 | ili9328getPix(LCD,tmp,Xpos+(charnum*w),Ypos + linenum + 1-h,w,1); | |
|
355 | 359 | pix=0; |
|
356 | 360 | } |
|
357 | 361 | } |
|
358 | 362 | if((pix%8) == 0) |
|
359 | 363 | { |
|
360 | 364 | line=font->table[(((*buffer)-32)*h*bpl)+tableoffset++]; |
|
361 | 365 | } |
|
362 | 366 | //tmp[pix]=0; |
|
363 | 367 | if((line & (uint8_t)0x01)==(uint8_t)1)tmp[pix]=(uint16_t)color; |
|
364 | 368 | pix++; |
|
365 | 369 | line>>=1; |
|
366 | 370 | } |
|
367 | 371 | linenum=0; |
|
368 | 372 | tableoffset=0; |
|
369 | 373 | charnum++; |
|
370 | 374 | buffer++; |
|
371 | 375 | } |
|
372 | 376 | } |
|
373 | 377 | |
|
374 | 378 | int ili9328init(struct LCD_t* LCD) |
|
375 | 379 | { |
|
376 | 380 | if((LCD!=NULL) && (LCD->interface!=NULL) && (LCD->interface->writereg!=NULL)) |
|
377 | 381 | { |
|
378 | 382 | LCD->interface->writereg(ILI9328_REGISTER_DRIVEROUTPUTCONTROL1, 0x0100); // Driver Output Control Register (R01h) |
|
379 | 383 | LCD->interface->writereg(ILI9328_REGISTER_LCDDRIVINGCONTROL, 0x0700); // LCD Driving Waveform Control (R02h) |
|
380 | 384 | LCD->interface->writereg(ILI9328_REGISTER_ENTRYMODE, 0x1030); // Entry Mode (R03h) |
|
381 | 385 | LCD->interface->writereg(ILI9328_REGISTER_DISPLAYCONTROL2, 0x0302); |
|
382 | 386 | LCD->interface->writereg(ILI9328_REGISTER_DISPLAYCONTROL3, 0x0000); |
|
383 | 387 | LCD->interface->writereg(ILI9328_REGISTER_DISPLAYCONTROL4, 0x0000); // Fmark On |
|
384 | 388 | LCD->interface->writereg(ILI9328_REGISTER_POWERCONTROL1, 0x0000); // Power Control 1 (R10h) |
|
385 | 389 | LCD->interface->writereg(ILI9328_REGISTER_POWERCONTROL2, 0x0007); // Power Control 2 (R11h) |
|
386 | 390 | LCD->interface->writereg(ILI9328_REGISTER_POWERCONTROL3, 0x0000); // Power Control 3 (R12h) |
|
387 | 391 | LCD->interface->writereg(ILI9328_REGISTER_POWERCONTROL4, 0x0000); // Power Control 4 (R13h) |
|
388 | 392 | delay_100us(1000); |
|
389 | 393 | LCD->interface->writereg(ILI9328_REGISTER_POWERCONTROL1, 0x14B0); // Power Control 1 (R10h) |
|
390 | 394 | delay_100us(500); |
|
391 | 395 | LCD->interface->writereg(ILI9328_REGISTER_POWERCONTROL2, 0x0007); // Power Control 2 (R11h) |
|
392 | 396 | delay_100us(500); |
|
393 | 397 | LCD->interface->writereg(ILI9328_REGISTER_POWERCONTROL3, 0x008E); // Power Control 3 (R12h) |
|
394 | 398 | LCD->interface->writereg(ILI9328_REGISTER_POWERCONTROL4, 0x0C00); // Power Control 4 (R13h) |
|
395 | 399 | LCD->interface->writereg(ILI9328_REGISTER_POWERCONTROL7, 0x0015); // NVM read data 2 (R29h) |
|
396 | 400 | delay_100us(500); |
|
397 | 401 | LCD->interface->writereg(ILI9328_REGISTER_GAMMACONTROL1, 0x0000); // Gamma Control 1 |
|
398 | 402 | LCD->interface->writereg(ILI9328_REGISTER_GAMMACONTROL2, 0x0107); // Gamma Control 2 |
|
399 | 403 | LCD->interface->writereg(ILI9328_REGISTER_GAMMACONTROL3, 0x0000); // Gamma Control 3 |
|
400 | 404 | LCD->interface->writereg(ILI9328_REGISTER_GAMMACONTROL4, 0x0203); // Gamma Control 4 |
|
401 | 405 | LCD->interface->writereg(ILI9328_REGISTER_GAMMACONTROL5, 0x0402); // Gamma Control 5 |
|
402 | 406 | LCD->interface->writereg(ILI9328_REGISTER_GAMMACONTROL6, 0x0000); // Gamma Control 6 |
|
403 | 407 | LCD->interface->writereg(ILI9328_REGISTER_GAMMACONTROL7, 0x0207); // Gamma Control 7 |
|
404 | 408 | LCD->interface->writereg(ILI9328_REGISTER_GAMMACONTROL8, 0x0000); // Gamma Control 8 |
|
405 | 409 | LCD->interface->writereg(ILI9328_REGISTER_GAMMACONTROL9, 0x0203); // Gamma Control 9 |
|
406 | 410 | LCD->interface->writereg(ILI9328_REGISTER_GAMMACONTROL10, 0x0403); // Gamma Control 10 |
|
407 | 411 | LCD->interface->writereg(ILI9328_REGISTER_HORIZONTALADDRESSSTARTPOSITION, 0x0000); // Window Horizontal RAM Address Start (R50h) |
|
408 | 412 | LCD->interface->writereg(ILI9328_REGISTER_HORIZONTALADDRESSENDPOSITION, LCD->width - 1); // Window Horizontal RAM Address End (R51h) |
|
409 | 413 | LCD->interface->writereg(ILI9328_REGISTER_VERTICALADDRESSSTARTPOSITION, 0X0000); // Window Vertical RAM Address Start (R52h) |
|
410 | 414 | LCD->interface->writereg(ILI9328_REGISTER_VERTICALADDRESSENDPOSITION, LCD->height - 1); // Window Vertical RAM Address End (R53h) |
|
411 | 415 | LCD->interface->writereg(ILI9328_REGISTER_DRIVEROUTPUTCONTROL2, 0xa700); // Driver Output Control (R60h) |
|
412 | 416 | LCD->interface->writereg(ILI9328_REGISTER_BASEIMAGEDISPLAYCONTROL, 0x0003); // Driver Output Control (R61h) - enable VLE |
|
413 | 417 | LCD->interface->writereg(ILI9328_REGISTER_PANELINTERFACECONTROL1, 0X0010); // Panel Interface Control 1 (R90h) |
|
414 | 418 | // Display On |
|
415 | 419 | LCD->interface->writereg(ILI9328_REGISTER_DISPLAYCONTROL1, 0x0133); // Display Control (R07h) |
|
416 | 420 | delay_100us(500); |
|
417 | 421 | LCD->paintFilRect(LCD,0,0,LCD->width,LCD->height,0,0,0xFFFF); |
|
418 | 422 | } |
|
419 | 423 | return 0; |
|
420 | 424 | } |
|
421 | 425 | |
|
426 | void ili9328cpFrame(LCD_t* LCD,void* buffer,int x,int y,int w, int h) | |
|
427 | { | |
|
428 | #define __set__Address__(_x_,_y_) LCD->interface->writereg(ILI9328_REGISTER_HORIZONTALGRAMADDRESSSET,_x_); \ | |
|
429 | LCD->interface->writereg(ILI9328_REGISTER_VERTICALGRAMADDRESSSET,_y_) | |
|
422 | 430 | |
|
431 | uint16_t* castedBuff = (uint16_t*)buffer; | |
|
432 | int cx=x,cy=y; | |
|
433 | for(int i=0;i<(w*h);i++) | |
|
434 | { | |
|
435 | __set__Address__(cx,cy); | |
|
436 | LCD->interface->readGRAM((void*)(&castedBuff[i]),1); | |
|
437 | cx+=1; | |
|
438 | if(cx>=(w+x)) | |
|
439 | { | |
|
440 | cx=x; | |
|
441 | cy+=1; | |
|
442 | } | |
|
443 | } | |
|
444 | } | |
|
445 | ||
|
446 | ||
|
447 | ||
|
448 | void ili9328getPix(struct LCD_t* LCD,uint16_t* buffer,uint16_t Xpos,uint16_t Ypos,uint16_t w,uint16_t h) | |
|
449 | { | |
|
450 | #define __set__Address__(_x_,_y_) LCD->interface->writereg(ILI9328_REGISTER_HORIZONTALGRAMADDRESSSET,_x_); \ | |
|
451 | LCD->interface->writereg(ILI9328_REGISTER_VERTICALGRAMADDRESSSET,_y_) | |
|
452 | ||
|
453 | uint16_t* castedBuff = (uint16_t*)buffer; | |
|
454 | int cx=Xpos,cy=Ypos; | |
|
455 | for(int i=0;i<(w*h);i++) | |
|
456 | { | |
|
457 | __set__Address__(cx,cy); | |
|
458 | LCD->interface->readGRAM((void*)(&castedBuff[i]),1); | |
|
459 | cx+=1; | |
|
460 | if(cx>=(w+Xpos)) | |
|
461 | { | |
|
462 | cx=Xpos; | |
|
463 | cy+=1; | |
|
464 | } | |
|
465 | } | |
|
466 | ||
|
467 | } | |
|
468 | ||
|
469 | ||
|
470 | ||
|
471 | ||
|
472 | ||
|
473 | ||
|
474 | ||
|
475 | ||
|
476 | ||
|
477 | ||
|
478 | ||
|
479 | ||
|
480 | ||
|
481 | ||
|
482 |
@@ -1,18 +1,22 | |||
|
1 | 1 | TEMPLATE = lib |
|
2 | 2 | TARGET = ili9328 |
|
3 | 3 | |
|
4 | 4 | SOURCES += \ |
|
5 | 5 | ili9328.c |
|
6 | 6 | |
|
7 | 7 | |
|
8 | 8 | INCLUDEPATH += ../../../../includes \ |
|
9 | 9 | ../../../../includes/GRAPHIC/CONTROLERS \ |
|
10 | 10 | ../../../../includes/GRAPHIC/GUI/FONTS \ |
|
11 | 11 | ../../../../includes/GRAPHIC/GUI/Widgets |
|
12 | 12 | |
|
13 | 13 | |
|
14 | 14 | UCMODEL=simulator |
|
15 | 15 | |
|
16 | 16 | target.path = $$[QT_INSTALL_LIBS]/$$UCMODEL |
|
17 | 17 | INSTALLS += target |
|
18 | 18 | |
|
19 | HEADERS += \ | |
|
20 | ../../../../includes/GRAPHIC/CONTROLERS/ili9328.h \ | |
|
21 | ../../../../includes/GRAPHIC/CONTROLERS/genericLCD_Controler.h | |
|
22 |
@@ -1,22 +1,25 | |||
|
1 | 1 | TEMPLATE = lib |
|
2 | 2 | OBJECTS_DIR = obj |
|
3 | 3 | TARGET = ili9328 |
|
4 | 4 | |
|
5 | 5 | SOURCES += \ |
|
6 | 6 | ili9328.c |
|
7 | 7 | |
|
8 | 8 | DEFINES -= __OPTIMIZED_MATH |
|
9 | 9 | |
|
10 | 10 | INCLUDEPATH += ../../../../includes \ |
|
11 | 11 | ../../../CPU/STM32F4xx_StdPeriph_Driver/inc \ |
|
12 | 12 | ../../../CPU/CMSIS/Include \ |
|
13 | 13 | ../../../../includes/GRAPHIC/CONTROLERS \ |
|
14 | 14 | ../../../../includes/GRAPHIC/GUI/FONTS \ |
|
15 | 15 | ../../../../includes/GRAPHIC/GUI/Widgets |
|
16 | 16 | |
|
17 | 17 | |
|
18 | 18 | UCMODEL=stm32f4 |
|
19 | 19 | |
|
20 | 20 | target.path = $$[QT_INSTALL_LIBS]/$$UCMODEL |
|
21 | 21 | INSTALLS += target |
|
22 | 22 | |
|
23 | HEADERS += \ | |
|
24 | ../../../../includes/GRAPHIC/CONTROLERS/ili9328.h | |
|
25 |
@@ -1,57 +1,58 | |||
|
1 | 1 | /*------------------------------------------------------------------------------ |
|
2 | 2 | -- This file is a part of the libuc, microcontroler library |
|
3 | 3 | -- Copyright (C) 2012, Alexis Jeandet |
|
4 | 4 | -- |
|
5 | 5 | -- This program is free software; you can redistribute it and/or modify |
|
6 | 6 | -- it under the terms of the GNU General Public License as published by |
|
7 | 7 | -- the Free Software Foundation; either version 3 of the License, or |
|
8 | 8 | -- (at your option) any later version. |
|
9 | 9 | -- |
|
10 | 10 | -- This program is distributed in the hope that it will be useful, |
|
11 | 11 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 | 12 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
13 | 13 | -- GNU General Public License for more details. |
|
14 | 14 | -- |
|
15 | 15 | -- You should have received a copy of the GNU General Public License |
|
16 | 16 | -- along with this program; if not, write to the Free Software |
|
17 | 17 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
18 | 18 | ------------------------------------------------------------------------------- |
|
19 | 19 | -- Author : Alexis Jeandet |
|
20 | 20 | -- Mail : alexis.jeandet@gmail.com |
|
21 | 21 | -------------------------------------------------------------------------------*/ |
|
22 | 22 | #ifndef GENERICLCD_CONTROLER_H |
|
23 | 23 | #define GENERICLCD_CONTROLER_H |
|
24 | 24 | |
|
25 | 25 | #include <uhandle.h> |
|
26 | 26 | #include <stdint.h> |
|
27 | 27 | #include <fonts.h> |
|
28 | 28 | |
|
29 | 29 | |
|
30 | 30 | typedef struct LCD_IF_t |
|
31 | 31 | { |
|
32 | 32 | int (*init)(); |
|
33 | 33 | void (*writereg)(uint32_t reg,uint32_t data); |
|
34 | 34 | uint32_t (*readreg)(uint32_t reg); |
|
35 | 35 | void (*writeGRAM)(void* buffer,uint32_t count); |
|
36 | 36 | void (*readGRAM)(void* buffer,uint32_t count); |
|
37 | 37 | }LCD_IF_t; |
|
38 | 38 | |
|
39 | 39 | typedef struct LCD_t |
|
40 | 40 | { |
|
41 | 41 | LCD_IF_t* interface; |
|
42 | 42 | int (*init)(struct LCD_t* LCD); |
|
43 | 43 | void (*paint)(struct LCD_t* LCD,void* buffer,uint16_t Xpos,uint16_t Ypos,uint16_t Width,uint16_t Height); |
|
44 | 44 | void (*paintText)(struct LCD_t* LCD,char* buffer,uint16_t Xpos,uint16_t Ypos,sFONT *font,uint32_t color); |
|
45 | 45 | void (*paintFilRect)(struct LCD_t* LCD,uint16_t Xpos,uint16_t Ypos,uint16_t w,uint16_t h,uint32_t contColor,uint16_t contSz,uint32_t fillColor); |
|
46 | void (*getPix)(struct LCD_t* LCD,uint16_t* buffer,uint16_t Xpos,uint16_t Ypos,uint16_t w,uint16_t h); | |
|
46 | 47 | void (*refreshenable)(struct LCD_t* LCD,int enable); |
|
47 | 48 | uint16_t width; |
|
48 | 49 | uint16_t height; |
|
49 | 50 | }LCD_t; |
|
50 | 51 | |
|
51 | 52 | |
|
52 | 53 | #endif /*GENERICLCD_CONTROLER_H*/ |
|
53 | 54 | |
|
54 | 55 | |
|
55 | 56 | |
|
56 | 57 | |
|
57 | 58 |
@@ -1,97 +1,101 | |||
|
1 | 1 | /*------------------------------------------------------------------------------ |
|
2 | 2 | -- This file is a part of the libuc, microcontroler library |
|
3 | 3 | -- Copyright (C) 2012, Alexis Jeandet |
|
4 | 4 | -- |
|
5 | 5 | -- This program is free software; you can redistribute it and/or modify |
|
6 | 6 | -- it under the terms of the GNU General Public License as published by |
|
7 | 7 | -- the Free Software Foundation; either version 3 of the License, or |
|
8 | 8 | -- (at your option) any later version. |
|
9 | 9 | -- |
|
10 | 10 | -- This program is distributed in the hope that it will be useful, |
|
11 | 11 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 | 12 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
13 | 13 | -- GNU General Public License for more details. |
|
14 | 14 | -- |
|
15 | 15 | -- You should have received a copy of the GNU General Public License |
|
16 | 16 | -- along with this program; if not, write to the Free Software |
|
17 | 17 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
18 | 18 | ------------------------------------------------------------------------------- |
|
19 | 19 | -- Author : Alexis Jeandet |
|
20 | 20 | -- Mail : alexis.jeandet@gmail.com |
|
21 | 21 | -------------------------------------------------------------------------------*/ |
|
22 | 22 | #ifndef ILI9328_H |
|
23 | 23 | #define ILI9328_H |
|
24 | 24 | |
|
25 | 25 | #include <uhandle.h> |
|
26 | 26 | #include <genericLCD_Controler.h> |
|
27 | 27 | #include <stdint.h> |
|
28 | 28 | #include <fonts.h> |
|
29 | 29 | |
|
30 | extern int ili9328init(struct LCD_t* LCD); | |
|
30 | extern int ili9328init(struct LCD_t* LCD); | |
|
31 | 31 | extern void ili9328setFrame(LCD_t* LCD,uint16_t X,uint16_t Y,uint16_t W,uint16_t H); |
|
32 | 32 | extern void ili9328setGRAMaddress(LCD_t* LCD,uint16_t Haddress,uint16_t Vaddress); |
|
33 | 33 | extern void ili9328paint(LCD_t* LCD,void* buffer,uint16_t Xpos,uint16_t Ypos,uint16_t Width,uint16_t Height); |
|
34 | 34 | extern void ili9328paintText(LCD_t* LCD,char* buffer,uint16_t Xpos,uint16_t Ypos,sFONT *font,uint32_t color); |
|
35 | 35 | extern void ili9328paintFilRect(LCD_t* LCD,uint16_t Xpos,uint16_t Ypos,uint16_t w,uint16_t h,uint32_t contColor,uint16_t contSz,uint32_t fillColor); |
|
36 | 36 | extern void ili9328paintFilCirc(LCD_t* LCD,uint16_t Xpos,uint16_t Ypos,uint16_t r,uint32_t contColor,uint16_t contSz,uint32_t fillColor); |
|
37 | 37 | extern void ili9328paintFilCircMidPoint(LCD_t* LCD,uint16_t Xpos,uint16_t Ypos,uint16_t r,uint32_t contColor,uint16_t contSz,uint32_t fillColor); |
|
38 | extern void ili9328getPix(struct LCD_t* LCD,uint16_t* buffer,uint16_t Xpos,uint16_t Ypos,uint16_t w,uint16_t h); | |
|
38 | 39 | extern void ili9328refreshenable(struct LCD_t* LCD,int enable); |
|
39 | 40 | |
|
40 |
#define ILI9328_REGISTER_DRIVERCODEREAD |
|
|
41 |
#define ILI9328_REGISTER_DRIVEROUTPUTCONTROL1 |
|
|
42 |
#define ILI9328_REGISTER_LCDDRIVINGCONTROL |
|
|
43 |
#define ILI9328_REGISTER_ENTRYMODE |
|
|
44 |
#define ILI9328_REGISTER_RESIZECONTROL |
|
|
45 |
#define ILI9328_REGISTER_DISPLAYCONTROL1 |
|
|
46 |
#define ILI9328_REGISTER_DISPLAYCONTROL2 |
|
|
47 |
#define ILI9328_REGISTER_DISPLAYCONTROL3 |
|
|
48 |
#define ILI9328_REGISTER_DISPLAYCONTROL4 |
|
|
49 |
#define ILI9328_REGISTER_RGBDISPLAYINTERFACECONTROL1 |
|
|
50 |
#define ILI9328_REGISTER_FRAMEMAKERPOSITION |
|
|
51 |
#define ILI9328_REGISTER_RGBDISPLAYINTERFACECONTROL2 |
|
|
52 |
#define ILI9328_REGISTER_POWERCONTROL1 |
|
|
53 |
#define ILI9328_REGISTER_POWERCONTROL2 |
|
|
54 |
#define ILI9328_REGISTER_POWERCONTROL3 |
|
|
55 |
#define ILI9328_REGISTER_POWERCONTROL4 |
|
|
56 |
#define ILI9328_REGISTER_HORIZONTALGRAMADDRESSSET |
|
|
57 |
#define ILI9328_REGISTER_VERTICALGRAMADDRESSSET |
|
|
58 |
#define ILI9328_REGISTER_WRITEDATATOGRAM |
|
|
59 |
#define ILI9328_REGISTER_POWERCONTROL7 |
|
|
60 |
#define ILI9328_REGISTER_FRAMERATEANDCOLORCONTROL |
|
|
61 |
#define ILI9328_REGISTER_GAMMACONTROL1 |
|
|
62 |
#define ILI9328_REGISTER_GAMMACONTROL2 |
|
|
63 |
#define ILI9328_REGISTER_GAMMACONTROL3 |
|
|
64 |
#define ILI9328_REGISTER_GAMMACONTROL4 |
|
|
65 |
#define ILI9328_REGISTER_GAMMACONTROL5 |
|
|
66 |
#define ILI9328_REGISTER_GAMMACONTROL6 |
|
|
67 |
#define ILI9328_REGISTER_GAMMACONTROL7 |
|
|
68 |
#define ILI9328_REGISTER_GAMMACONTROL8 |
|
|
69 |
#define ILI9328_REGISTER_GAMMACONTROL9 |
|
|
70 |
#define ILI9328_REGISTER_GAMMACONTROL10 |
|
|
71 |
#define ILI9328_REGISTER_HORIZONTALADDRESSSTARTPOSITION ((uint32_t) 0x0050 |
|
|
72 |
#define ILI9328_REGISTER_HORIZONTALADDRESSENDPOSITION ((uint32_t) |
|
|
73 |
#define ILI9328_REGISTER_VERTICALADDRESSSTARTPOSITION ((uint32_t) |
|
|
74 |
#define ILI9328_REGISTER_VERTICALADDRESSENDPOSITION |
|
|
75 |
#define ILI9328_REGISTER_DRIVEROUTPUTCONTROL2 |
|
|
76 |
#define ILI9328_REGISTER_BASEIMAGEDISPLAYCONTROL |
|
|
77 |
#define ILI9328_REGISTER_VERTICALSCROLLCONTROL |
|
|
78 |
#define ILI9328_REGISTER_PARTIALIMAGE1DISPLAYPOSITION |
|
|
79 |
#define ILI9328_REGISTER_PARTIALIMAGE1AREASTARTLINE |
|
|
80 |
#define ILI9328_REGISTER_PARTIALIMAGE1AREAENDLINE |
|
|
81 |
#define ILI9328_REGISTER_PARTIALIMAGE2DISPLAYPOSITION |
|
|
82 |
#define ILI9328_REGISTER_PARTIALIMAGE2AREASTARTLINE |
|
|
83 |
#define ILI9328_REGISTER_PARTIALIMAGE2AREAENDLINE |
|
|
84 |
#define ILI9328_REGISTER_PANELINTERFACECONTROL1 |
|
|
85 |
#define ILI9328_REGISTER_PANELINTERFACECONTROL2 |
|
|
86 |
#define ILI9328_REGISTER_PANELINTERFACECONTROL4 |
|
|
87 |
#define ILI9328_REGISTER_OTPVCMPROGRAMMINGCONTROL |
|
|
88 |
#define ILI9328_REGISTER_OTPVCMSTATUSANDENABLE |
|
|
89 |
#define ILI9328_REGISTER_OTPPROGRAMMINGIDKEY |
|
|
41 | #define ILI9328_REGISTER_DRIVERCODEREAD ((uint32_t) 0x0000 ) | |
|
42 | #define ILI9328_REGISTER_DRIVEROUTPUTCONTROL1 ((uint32_t) 0x0001 ) | |
|
43 | #define ILI9328_REGISTER_LCDDRIVINGCONTROL ((uint32_t) 0x0002 ) | |
|
44 | #define ILI9328_REGISTER_ENTRYMODE ((uint32_t) 0x0003 ) | |
|
45 | #define ILI9328_REGISTER_RESIZECONTROL ((uint32_t) 0x0004 ) | |
|
46 | #define ILI9328_REGISTER_DISPLAYCONTROL1 ((uint32_t) 0x0007 ) | |
|
47 | #define ILI9328_REGISTER_DISPLAYCONTROL2 ((uint32_t) 0x0008 ) | |
|
48 | #define ILI9328_REGISTER_DISPLAYCONTROL3 ((uint32_t) 0x0009 ) | |
|
49 | #define ILI9328_REGISTER_DISPLAYCONTROL4 ((uint32_t) 0x000A ) | |
|
50 | #define ILI9328_REGISTER_RGBDISPLAYINTERFACECONTROL1 ((uint32_t) 0x000C ) | |
|
51 | #define ILI9328_REGISTER_FRAMEMAKERPOSITION ((uint32_t) 0x000D ) | |
|
52 | #define ILI9328_REGISTER_RGBDISPLAYINTERFACECONTROL2 ((uint32_t) 0x000F ) | |
|
53 | #define ILI9328_REGISTER_POWERCONTROL1 ((uint32_t) 0x0010 ) | |
|
54 | #define ILI9328_REGISTER_POWERCONTROL2 ((uint32_t) 0x0011 ) | |
|
55 | #define ILI9328_REGISTER_POWERCONTROL3 ((uint32_t) 0x0012 ) | |
|
56 | #define ILI9328_REGISTER_POWERCONTROL4 ((uint32_t) 0x0013 ) | |
|
57 | #define ILI9328_REGISTER_HORIZONTALGRAMADDRESSSET ((uint32_t) 0x0020 ) | |
|
58 | #define ILI9328_REGISTER_VERTICALGRAMADDRESSSET ((uint32_t) 0x0021 ) | |
|
59 | #define ILI9328_REGISTER_WRITEDATATOGRAM ((uint32_t) 0x0022 ) | |
|
60 | #define ILI9328_REGISTER_POWERCONTROL7 ((uint32_t) 0x0029 ) | |
|
61 | #define ILI9328_REGISTER_FRAMERATEANDCOLORCONTROL ((uint32_t) 0x002B ) | |
|
62 | #define ILI9328_REGISTER_GAMMACONTROL1 ((uint32_t) 0x0030 ) | |
|
63 | #define ILI9328_REGISTER_GAMMACONTROL2 ((uint32_t) 0x0031 ) | |
|
64 | #define ILI9328_REGISTER_GAMMACONTROL3 ((uint32_t) 0x0032 ) | |
|
65 | #define ILI9328_REGISTER_GAMMACONTROL4 ((uint32_t) 0x0035 ) | |
|
66 | #define ILI9328_REGISTER_GAMMACONTROL5 ((uint32_t) 0x0036 ) | |
|
67 | #define ILI9328_REGISTER_GAMMACONTROL6 ((uint32_t) 0x0037 ) | |
|
68 | #define ILI9328_REGISTER_GAMMACONTROL7 ((uint32_t) 0x0038 ) | |
|
69 | #define ILI9328_REGISTER_GAMMACONTROL8 ((uint32_t) 0x0039 ) | |
|
70 | #define ILI9328_REGISTER_GAMMACONTROL9 ((uint32_t) 0x003C ) | |
|
71 | #define ILI9328_REGISTER_GAMMACONTROL10 ((uint32_t) 0x003D ) | |
|
72 | #define ILI9328_REGISTER_HORIZONTALADDRESSSTARTPOSITION ((uint32_t) 0x0050 ) | |
|
73 | #define ILI9328_REGISTER_HORIZONTALADDRESSENDPOSITION ((uint32_t) 0x0051 ) | |
|
74 | #define ILI9328_REGISTER_VERTICALADDRESSSTARTPOSITION ((uint32_t) 0x0052 ) | |
|
75 | #define ILI9328_REGISTER_VERTICALADDRESSENDPOSITION ((uint32_t) 0x0053 ) | |
|
76 | #define ILI9328_REGISTER_DRIVEROUTPUTCONTROL2 ((uint32_t) 0x0060 ) | |
|
77 | #define ILI9328_REGISTER_BASEIMAGEDISPLAYCONTROL ((uint32_t) 0x0061 ) | |
|
78 | #define ILI9328_REGISTER_VERTICALSCROLLCONTROL ((uint32_t) 0x006A ) | |
|
79 | #define ILI9328_REGISTER_PARTIALIMAGE1DISPLAYPOSITION ((uint32_t) 0x0080 ) | |
|
80 | #define ILI9328_REGISTER_PARTIALIMAGE1AREASTARTLINE ((uint32_t) 0x0081 ) | |
|
81 | #define ILI9328_REGISTER_PARTIALIMAGE1AREAENDLINE ((uint32_t) 0x0082 ) | |
|
82 | #define ILI9328_REGISTER_PARTIALIMAGE2DISPLAYPOSITION ((uint32_t) 0x0083 ) | |
|
83 | #define ILI9328_REGISTER_PARTIALIMAGE2AREASTARTLINE ((uint32_t) 0x0084 ) | |
|
84 | #define ILI9328_REGISTER_PARTIALIMAGE2AREAENDLINE ((uint32_t) 0x0085 ) | |
|
85 | #define ILI9328_REGISTER_PANELINTERFACECONTROL1 ((uint32_t) 0x0090 ) | |
|
86 | #define ILI9328_REGISTER_PANELINTERFACECONTROL2 ((uint32_t) 0x0092 ) | |
|
87 | #define ILI9328_REGISTER_PANELINTERFACECONTROL4 ((uint32_t) 0x0095 ) | |
|
88 | #define ILI9328_REGISTER_OTPVCMPROGRAMMINGCONTROL ((uint32_t) 0x00A1 ) | |
|
89 | #define ILI9328_REGISTER_OTPVCMSTATUSANDENABLE ((uint32_t) 0x00A2 ) | |
|
90 | #define ILI9328_REGISTER_OTPPROGRAMMINGIDKEY ((uint32_t) 0x00A5 ) | |
|
90 | 91 | |
|
92 | #ifdef _PRVATE_ILI9328_ | |
|
93 | void ili9328cpFrame(LCD_t* LCD,void* buffer,int x,int y,int w, int h); | |
|
94 | #endif | |
|
91 | 95 | |
|
92 | 96 | #endif |
|
93 | 97 | |
|
94 | 98 | |
|
95 | 99 | |
|
96 | 100 | |
|
97 | 101 |
@@ -1,304 +1,310 | |||
|
1 | 1 | /*------------------------------------------------------------------------------ |
|
2 | 2 | -- This file is a part of the libuc, microcontroler library |
|
3 | 3 | -- Copyright (C) 2013, Alexis Jeandet |
|
4 | 4 | -- |
|
5 | 5 | -- This program is free software; you can redistribute it and/or modify |
|
6 | 6 | -- it under the terms of the GNU General Public License as published by |
|
7 | 7 | -- the Free Software Foundation; either version 3 of the License, or |
|
8 | 8 | -- (at your option) any later version. |
|
9 | 9 | -- |
|
10 | 10 | -- This program is distributed in the hope that it will be useful, |
|
11 | 11 | -- but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 | 12 | -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
13 | 13 | -- GNU General Public License for more details. |
|
14 | 14 | -- |
|
15 | 15 | -- You should have received a copy of the GNU General Public License |
|
16 | 16 | -- along with this program; if not, write to the Free Software |
|
17 | 17 | -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
|
18 | 18 | ------------------------------------------------------------------------------- |
|
19 | 19 | -- Author : Alexis Jeandet |
|
20 | 20 | -- Mail : alexis.jeandet@member.fsf.org |
|
21 | 21 | -------------------------------------------------------------------------------*/ |
|
22 | 22 | |
|
23 | 23 | #include <SDL.h> |
|
24 | 24 | #include <malloc.h> |
|
25 | 25 | #include "SDLCD.h" |
|
26 | 26 | |
|
27 | 27 | SDL_Surface *screen; |
|
28 | 28 | SDL_Overlay *bmp; |
|
29 | 29 | |
|
30 | 30 | int SDLCD_Xpos=0; |
|
31 | 31 | int SDLCD_Ypos=0; |
|
32 | 32 | int SDLCD_XWinStrt=0; |
|
33 | 33 | int SDLCD_YWinStrt=0; |
|
34 | 34 | int SDLCD_XWinEnd=0; |
|
35 | 35 | int SDLCD_YWinEnd=0; |
|
36 | 36 | |
|
37 | 37 | void* SDLCD_buffer; |
|
38 | 38 | int SDLCD_bpp; |
|
39 | 39 | void SDLCD_putpixel(SDL_Surface *surface, int x, int y, Uint32 pixel); |
|
40 | 40 | |
|
41 | 41 | void SDLCD_mkscreen(int resx,int resy,int bpp,int lcdtype) |
|
42 | 42 | { |
|
43 | 43 | int i=0; |
|
44 | 44 | if(SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER)) { |
|
45 | 45 | fprintf(stderr, "Could not initialize SDL - %s\n", SDL_GetError()); |
|
46 | 46 | exit(1); |
|
47 | 47 | } |
|
48 | 48 | screen = SDL_SetVideoMode(resx, resy, bpp, 0); |
|
49 | 49 | if(!screen) { |
|
50 | 50 | fprintf(stderr, "SDL: could not set video mode - exiting\n"); |
|
51 | 51 | exit(1); |
|
52 | 52 | } |
|
53 | 53 | if ( SDL_MUSTLOCK(screen) ) { |
|
54 | 54 | if ( SDL_LockSurface(screen) < 0 ) { |
|
55 | 55 | fprintf(stderr, "Canβt lock screen: %s\n", SDL_GetError()); |
|
56 | 56 | return; |
|
57 | 57 | } |
|
58 | 58 | } |
|
59 | 59 | if ( SDL_MUSTLOCK(screen) ) { |
|
60 | 60 | SDL_UnlockSurface(screen); |
|
61 | 61 | } |
|
62 | 62 | SDL_UpdateRect(screen, 0, 0, resx, resy); |
|
63 | 63 | SDLCD_buffer = malloc(resx*resy*bpp/8); |
|
64 | 64 | SDLCD_bpp = bpp; |
|
65 | 65 | for(i=0;i<(resx*resy);i++) |
|
66 | 66 | { |
|
67 | 67 | SDLCD_putpixel(screen, i%resx, (i/resx), 0xFFFF); |
|
68 | 68 | } |
|
69 | 69 | } |
|
70 | 70 | |
|
71 | 71 | |
|
72 | 72 | |
|
73 | 73 | int SDLCD_init() |
|
74 | 74 | { |
|
75 | 75 | |
|
76 | 76 | } |
|
77 | 77 | |
|
78 | 78 | void SDLCD_writereg(uint32_t reg,uint32_t data) |
|
79 | 79 | { |
|
80 | 80 | switch (reg) { |
|
81 | 81 | case ILI9328_REGISTER_HORIZONTALGRAMADDRESSSET: |
|
82 | if((data>=screen->w) || (data<0))printf("Warning printing out of bounds HORIZONTALGRAMADDRESSSET=%d",data); | |
|
82 | 83 | SDLCD_Xpos = data; |
|
83 | 84 | break; |
|
84 | 85 | case ILI9328_REGISTER_VERTICALGRAMADDRESSSET: |
|
86 | if((data>=screen->h) || (data<0))printf("Warning printing out of bounds ILI9328_REGISTER_VERTICALGRAMADDRESSSET=%d",data); | |
|
85 | 87 | SDLCD_Ypos = data; |
|
86 | 88 | break; |
|
87 | 89 | case ILI9328_REGISTER_HORIZONTALADDRESSSTARTPOSITION: |
|
90 | if((data>=screen->w) || (data<0))printf("Warning printing out of bounds ILI9328_REGISTER_HORIZONTALADDRESSSTARTPOSITION=%d",data); | |
|
88 | 91 | SDLCD_XWinStrt = data; |
|
89 | 92 | break; |
|
90 | 93 | case ILI9328_REGISTER_HORIZONTALADDRESSENDPOSITION: |
|
94 | if((data>=screen->w) || (data<0))printf("Warning printing out of bounds ILI9328_REGISTER_HORIZONTALADDRESSENDPOSITION=%d",data); | |
|
91 | 95 | SDLCD_XWinEnd = data; |
|
92 | 96 | break; |
|
93 | 97 | case ILI9328_REGISTER_VERTICALADDRESSSTARTPOSITION: |
|
98 | if((data>=screen->h) || (data<0))printf("Warning printing out of bounds ILI9328_REGISTER_VERTICALADDRESSSTARTPOSITION=%d",data); | |
|
94 | 99 | SDLCD_YWinStrt = data; |
|
95 | 100 | break; |
|
96 | 101 | case ILI9328_REGISTER_VERTICALADDRESSENDPOSITION: |
|
102 | if((data>=screen->h) || (data<0))printf("Warning printing out of bounds ILI9328_REGISTER_VERTICALADDRESSENDPOSITION=%d",data); | |
|
97 | 103 | SDLCD_YWinEnd = data; |
|
98 | 104 | break; |
|
99 | 105 | default: |
|
100 | 106 | break; |
|
101 | 107 | } |
|
102 | 108 | } |
|
103 | 109 | |
|
104 | 110 | uint32_t SDLCD_readreg(uint32_t reg) |
|
105 | 111 | { |
|
106 | 112 | return 0; |
|
107 | 113 | } |
|
108 | 114 | |
|
109 | 115 | |
|
110 | 116 | void SDLCD_putpixel(SDL_Surface *surface, int x, int y, Uint32 pixel) |
|
111 | 117 | { |
|
112 | 118 | int bpp = surface->format->BytesPerPixel; |
|
113 | 119 | /* Here p is the address to the pixel we want to set */ |
|
114 | 120 | Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; |
|
115 | 121 | switch(bpp) { |
|
116 | 122 | case 1: |
|
117 | 123 | *p = pixel; |
|
118 | 124 | break; |
|
119 | 125 | case 2: |
|
120 | 126 | *(Uint16 *)p = pixel; |
|
121 | 127 | break; |
|
122 | 128 | case 3: |
|
123 | 129 | if(SDL_BYTEORDER == SDL_BIG_ENDIAN) { |
|
124 | 130 | p[0] = (pixel >> 16) & 0xff; |
|
125 | 131 | p[1] = (pixel >> 8) & 0xff; |
|
126 | 132 | p[2] = pixel & 0xff; |
|
127 | 133 | } else { |
|
128 | 134 | p[0] = pixel & 0xff; |
|
129 | 135 | p[1] = (pixel >> 8) & 0xff; |
|
130 | 136 | p[2] = (pixel >> 16) & 0xff; |
|
131 | 137 | } |
|
132 | 138 | break; |
|
133 | 139 | case 4: |
|
134 | 140 | *(Uint32 *)p = pixel; |
|
135 | 141 | break; |
|
136 | 142 | } |
|
137 | 143 | } |
|
138 | 144 | |
|
139 | 145 | void SDLCD_putpixel_16bpp(SDL_Surface *surface, int x, int y, Uint32 pixel) |
|
140 | 146 | { |
|
141 | 147 | Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * surface->format->BytesPerPixel; |
|
142 | 148 | *(Uint16 *)p = pixel; |
|
143 | 149 | } |
|
144 | 150 | |
|
145 | 151 | Uint32 SDLCD_getpixel_16bpp(SDL_Surface *surface, int x, int y) |
|
146 | 152 | { |
|
147 | 153 | Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * surface->format->BytesPerPixel; |
|
148 | 154 | return *(Uint16 *)p; |
|
149 | 155 | } |
|
150 | 156 | |
|
151 | 157 | Uint32 SDLCD_getpixel(SDL_Surface *surface, int x, int y) |
|
152 | 158 | { |
|
153 | 159 | int bpp = surface->format->BytesPerPixel; |
|
154 | 160 | /* Here p is the address to the pixel we want to retrieve */ |
|
155 | 161 | Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp; |
|
156 | 162 | switch(bpp) { |
|
157 | 163 | case 1: |
|
158 | 164 | return *p; |
|
159 | 165 | case 2: |
|
160 | 166 | return *(Uint16 *)p; |
|
161 | 167 | case 3: |
|
162 | 168 | if(SDL_BYTEORDER == SDL_BIG_ENDIAN) |
|
163 | 169 | return p[0] << 16 | p[1] << 8 | p[2]; |
|
164 | 170 | else |
|
165 | 171 | return p[0] | p[1] << 8 | p[2] << 16; |
|
166 | 172 | case 4: |
|
167 | 173 | return *(Uint32 *)p; |
|
168 | 174 | default: |
|
169 | 175 | return 0; |
|
170 | 176 | } |
|
171 | 177 | /* shouldnβt happen, but avoids warnings */ |
|
172 | 178 | } |
|
173 | 179 | |
|
174 | 180 | void SDLCD_writeGRAM(void* buffer,uint32_t count) |
|
175 | 181 | { |
|
176 | 182 | int i=0; |
|
177 | 183 | u_int16_t* ptr=(u_int16_t*)SDLCD_buffer; |
|
178 | 184 | u_int16_t* inptr=(u_int16_t*)buffer; |
|
179 | 185 | if ( SDL_MUSTLOCK(screen) ) { |
|
180 | 186 | if ( SDL_LockSurface(screen) < 0 ) { |
|
181 | 187 | fprintf(stderr, "Canβt lock screen: %s\n", SDL_GetError()); |
|
182 | 188 | return; |
|
183 | 189 | } |
|
184 | 190 | } |
|
185 | 191 | for(i=0;i<count;i++) |
|
186 | 192 | { |
|
187 | 193 | SDLCD_putpixel_16bpp(screen,SDLCD_Xpos,SDLCD_Ypos,inptr[i]); |
|
188 | 194 | SDLCD_Xpos+=1; |
|
189 | 195 | ptr[i]=inptr[i]; |
|
190 | 196 | if(SDLCD_Xpos>=SDLCD_XWinEnd) |
|
191 | 197 | { |
|
192 | 198 | SDLCD_Xpos=SDLCD_XWinStrt; |
|
193 | 199 | SDLCD_Ypos+=1; |
|
194 | 200 | } |
|
195 | 201 | if(SDLCD_Ypos>=SDLCD_YWinEnd) |
|
196 | 202 | { |
|
197 | 203 | SDLCD_Ypos=SDLCD_YWinStrt; |
|
198 | 204 | } |
|
199 | 205 | } |
|
200 | 206 | if ( SDL_MUSTLOCK(screen) ) { |
|
201 | 207 | SDL_UnlockSurface(screen); |
|
202 | 208 | } |
|
203 | 209 | // SDL_UpdateRect(screen, SDLCD_XWinStrt, SDLCD_YWinStrt, SDLCD_XWinEnd-SDLCD_XWinStrt, SDLCD_YWinEnd-SDLCD_YWinStrt); |
|
204 | 210 | SDL_UpdateRect(screen, 0, 0, screen->w, screen->h); |
|
205 | 211 | } |
|
206 | 212 | |
|
207 | 213 | void SDLCD_writeGRAM_16bpp(void* buffer,uint32_t count) |
|
208 | 214 | { |
|
209 | 215 | int i=0; |
|
210 | 216 | u_int16_t* inptr=(u_int16_t*)buffer; |
|
211 | 217 | if ( SDL_MUSTLOCK(screen) ) { |
|
212 | 218 | if ( SDL_LockSurface(screen) < 0 ) { |
|
213 | 219 | fprintf(stderr, "Canβt lock screen: %s\n", SDL_GetError()); |
|
214 | 220 | return; |
|
215 | 221 | } |
|
216 | 222 | } |
|
217 | 223 | for(i=0;i<count;i++) |
|
218 | 224 | { |
|
219 | 225 | *(( Uint16 * ) screen->pixels + SDLCD_Ypos * screen->pitch / 2 + SDLCD_Xpos)=inptr[i]; |
|
220 | 226 | SDLCD_Xpos+=1; |
|
221 | 227 | if(SDLCD_Xpos>=SDLCD_XWinEnd) |
|
222 | 228 | { |
|
223 | 229 | SDLCD_Xpos=SDLCD_XWinStrt; |
|
224 | 230 | SDLCD_Ypos+=1; |
|
225 | 231 | } |
|
226 | 232 | if(SDLCD_Ypos>=SDLCD_YWinEnd) |
|
227 | 233 | { |
|
228 | 234 | SDLCD_Ypos=SDLCD_YWinStrt; |
|
229 | 235 | } |
|
230 | 236 | } |
|
231 | 237 | if ( SDL_MUSTLOCK(screen) ) { |
|
232 | 238 | SDL_UnlockSurface(screen); |
|
233 | 239 | } |
|
234 | 240 | // SDL_UpdateRect(screen, SDLCD_XWinStrt, SDLCD_YWinStrt, SDLCD_XWinEnd-SDLCD_XWinStrt, SDLCD_YWinEnd-SDLCD_YWinStrt); |
|
235 | 241 | SDL_UpdateRect(screen, 0, 0, screen->w, screen->h); |
|
236 | 242 | } |
|
237 | 243 | |
|
238 | 244 | void SDLCD_readGRAM_16bpp(void* buffer,uint32_t count) |
|
239 | 245 | { |
|
240 | 246 | int i=0; |
|
241 | 247 | u_int16_t* ptr=(u_int16_t*)SDLCD_buffer; |
|
242 | 248 | u_int16_t* inptr=(u_int16_t*)buffer; |
|
243 | 249 | for(i=0;i<count;i++) |
|
244 | 250 | { |
|
245 | 251 | inptr[i]=*(( Uint16 * ) screen->pixels + SDLCD_Ypos * screen->pitch / 2 + SDLCD_Xpos); |
|
246 | 252 | SDLCD_Xpos+=1; |
|
247 | 253 | ptr[i]=inptr[i]; |
|
248 | 254 | if(SDLCD_Xpos>=SDLCD_XWinEnd) |
|
249 | 255 | { |
|
250 | 256 | SDLCD_Xpos=SDLCD_XWinStrt; |
|
251 | 257 | SDLCD_Ypos+=1; |
|
252 | 258 | } |
|
253 | 259 | if(SDLCD_Ypos>=SDLCD_YWinEnd) |
|
254 | 260 | { |
|
255 | 261 | SDLCD_Ypos=SDLCD_YWinStrt; |
|
256 | 262 | } |
|
257 | 263 | } |
|
258 | 264 | |
|
259 | 265 | } |
|
260 | 266 | |
|
261 | 267 | void SDLCD_readGRAM(void* buffer,uint32_t count) |
|
262 | 268 | { |
|
263 | 269 | int i=0; |
|
264 | 270 | u_int16_t* ptr=(u_int16_t*)SDLCD_buffer; |
|
265 | 271 | u_int16_t* inptr=(u_int16_t*)buffer; |
|
266 | 272 | for(i=0;i<count;i++) |
|
267 | 273 | { |
|
268 | 274 | inptr[i]=SDLCD_getpixel_16bpp(screen,SDLCD_Xpos,SDLCD_Ypos); |
|
269 | 275 | SDLCD_Xpos+=1; |
|
270 | 276 | ptr[i]=inptr[i]; |
|
271 | 277 | if(SDLCD_Xpos>=SDLCD_XWinEnd) |
|
272 | 278 | { |
|
273 | 279 | SDLCD_Xpos=SDLCD_XWinStrt; |
|
274 | 280 | SDLCD_Ypos+=1; |
|
275 | 281 | } |
|
276 | 282 | if(SDLCD_Ypos>=SDLCD_YWinEnd) |
|
277 | 283 | { |
|
278 | 284 | SDLCD_Ypos=SDLCD_YWinStrt; |
|
279 | 285 | } |
|
280 | 286 | } |
|
281 | 287 | |
|
282 | 288 | } |
|
283 | 289 | |
|
284 | 290 | |
|
285 | 291 | |
|
286 | 292 | |
|
287 | 293 | |
|
288 | 294 | |
|
289 | 295 | |
|
290 | 296 | |
|
291 | 297 | |
|
292 | 298 | |
|
293 | 299 | |
|
294 | 300 | |
|
295 | 301 | |
|
296 | 302 | |
|
297 | 303 | |
|
298 | 304 | |
|
299 | 305 | |
|
300 | 306 | |
|
301 | 307 | |
|
302 | 308 | |
|
303 | 309 | |
|
304 | 310 |
@@ -1,77 +1,77 | |||
|
1 | 1 | # |
|
2 | 2 | # qmake configuration for stm32f4 |
|
3 | 3 | # |
|
4 | 4 | # |
|
5 | 5 | |
|
6 | 6 | |
|
7 | 7 | isEmpty(_stm32f4_conf){ |
|
8 | 8 | _stm32f4_conf="oneshot" |
|
9 | 9 | |
|
10 | 10 | QMAKE_CFLAGS=-mlittle-endian -mthumb -mcpu=cortex-m4 -mfloat-abi=hard -mfpu=fpv4-sp-d16 -std=c99 |
|
11 | 11 | |
|
12 | 12 | include(../../common/arm-none-eabi.conf) |
|
13 | 13 | |
|
14 | 14 | DEFINES += __OPTIMIZED_MATH |
|
15 | 15 | DEFINES += \"assert_param(expr)=((void)0)\" |
|
16 | 16 | INCLUDEPATH += $$PWD |
|
17 | 17 | |
|
18 | 18 | DEFINES += __FPU_PRESENT=1 |
|
19 | 19 | DEFINES += ARM_MATH_CM4 |
|
20 | 20 | |
|
21 | 21 | DEFINES += BSP="\"\\\"$$BSP"\\\"\" |
|
22 | 22 | |
|
23 | 23 | CONFIG += cpu |
|
24 | 24 | |
|
25 | 25 | contains( TEMPLATE, app ) { |
|
26 | 26 | OBJECTS_DIR=obj-$$UCMODEL |
|
27 | 27 | DESTDIR=bin-$$UCMODEL |
|
28 | 28 | unix:QMAKE_POST_LINK += arm-none-eabi-objcopy -O ihex "$(TARGET)" $$DESTDIR/"$(QMAKE_TARGET).hex" && arm-none-eabi-objcopy -O binary "$(TARGET)" $$DESTDIR/"$(QMAKE_TARGET).bin && python $$[QT_INSTALL_BINS]/dfu.py -b 0x08000000:"$$DESTDIR/"$(QMAKE_TARGET).bin " $$DESTDIR/"$(QMAKE_TARGET).dfu" |
|
29 | 29 | win32:QMAKE_POST_LINK += arm-none-eabi-objcopy -O ihex "$(DESTDIR_TARGET)" $$DESTDIR/"$(QMAKE_TARGET).hex" && arm-none-eabi-objcopy -O binary "$(DESTDIR_TARGET)" $$DESTDIR/"$(QMAKE_TARGET).bin" |
|
30 | 30 | |
|
31 | 31 | LIBS += -L$$[QT_INSTALL_PREFIX]/bsp/lib/$$BSP |
|
32 | 32 | LIBS += -lbsp |
|
33 | 33 | |
|
34 | 34 | |
|
35 | 35 | QMAKE_LFLAGS= -mlittle-endian -mthumb -mcpu=cortex-m4 -mfloat-abi=hard -mfpu=fpv4-sp-d16 -std=c99 -T $$[QT_INSTALL_PREFIX]/mkspecs/features/stm32f4/stm32_flash.ld |
|
36 | 36 | |
|
37 | 37 | INCLUDEPATH+= $$[QT_INSTALL_PREFIX]/bsp/includes/$$BSP |
|
38 | 38 | |
|
39 | 39 | SOURCES +=$$[QT_INSTALL_PREFIX]/mkspecs/features/stm32f4/syscalls.c |
|
40 | 40 | SOURCES +=$$[QT_INSTALL_PREFIX]/mkspecs/features/stm32f4/fs.c |
|
41 | 41 | SOURCES +=$$[QT_INSTALL_PREFIX]/mkspecs/features/stm32f4/startup.s |
|
42 | 42 | SOURCES +=$$[QT_INSTALL_PREFIX]/mkspecs/features/stm32f4/cpuinit.c |
|
43 | 43 | |
|
44 | 44 | # OTHER_FILES += $$[QT_INSTALL_PREFIX]/ucfiles/stm32f4/$$CPU/stm32_flash.ld |
|
45 | 45 | |
|
46 | 46 | stflash.target = stflash |
|
47 |
stflash.commands = cd $$DESTDIR && |
|
|
47 | stflash.commands = cd $$DESTDIR && st-flash write $(QMAKE_TARGET).bin 0x08000000 | |
|
48 | 48 | dfu.target = dfu |
|
49 | 49 | dfu.commands = cd $$DESTDIR && dfu-util d 0483:df11 -c 1 -i 0 -a 0 -s 0x08000000 -D $(QMAKE_TARGET).bin 0x08000000 |
|
50 | 50 | QMAKE_EXTRA_TARGETS += stflash dfu |
|
51 | 51 | } |
|
52 | 52 | |
|
53 | 53 | contains( TEMPLATE, lib ) { |
|
54 | 54 | CONFIG+=staticlib |
|
55 | 55 | OBJECTS_DIR=obj-$$UCMODEL |
|
56 | 56 | DESTDIR=bin-$$UCMODEL |
|
57 | 57 | message( "You can only build static library for stm32f4" ) |
|
58 | 58 | } |
|
59 | 59 | |
|
60 | 60 | include(../../common/libuc2libs.conf) |
|
61 | 61 | |
|
62 | 62 | } |
|
63 | 63 | |
|
64 | 64 | |
|
65 | 65 | |
|
66 | 66 | |
|
67 | 67 | |
|
68 | 68 | |
|
69 | 69 | |
|
70 | 70 | |
|
71 | 71 | |
|
72 | 72 | |
|
73 | 73 | |
|
74 | 74 | |
|
75 | 75 | |
|
76 | 76 | |
|
77 | 77 |
General Comments 0
You need to be logged in to leave comments.
Login now