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