@@ -0,0 +1,18 | |||
|
1 | TEMPLATE = lib | |
|
2 | ||
|
3 | TARGET=bsp | |
|
4 | OBJECTS_DIR = obj | |
|
5 | ||
|
6 | BSP = OPLAYER | |
|
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,423 | |||
|
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@gmail.com | |
|
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 <stm32f4xx_gpio.h> | |
|
29 | #include <stm32f4xx_fsmc.h> | |
|
30 | #include <i2c.h> | |
|
31 | #include <core.h> | |
|
32 | #include <terminal.h> | |
|
33 | #include <sdcard-spi.h> | |
|
34 | #include <sdcard.h> | |
|
35 | #include <mbr.h> | |
|
36 | #include <VS10XX.h> | |
|
37 | ||
|
38 | uint32_t OSC0 =8000000; | |
|
39 | uint32_t INTOSC =16000000; | |
|
40 | uint32_t RTCOSC =32768; | |
|
41 | uint32_t currentCpuFreq=0; | |
|
42 | extern streamdevice* __opnfiles__[__MAX_OPENED_FILES__]; | |
|
43 | ||
|
44 | LCD_IF_t lcdIF0={ | |
|
45 | .init = &bsp_FSMC_init, | |
|
46 | .writereg = &bsp_lcd0_write_reg, | |
|
47 | .readreg = &bsp_lcd0_read_reg, | |
|
48 | .writeGRAM = &bsp_lcd0_writeGRAM, | |
|
49 | .readGRAM = &bsp_lcd0_readGRAM | |
|
50 | }; | |
|
51 | ||
|
52 | LCD_t lcd0={ | |
|
53 | .interface = &lcdIF0, | |
|
54 | .init = &ili9328init, | |
|
55 | .paint = &ili9328paint, | |
|
56 | .paintText = &ili9328paintText, | |
|
57 | .paintFilRect = &ili9328paintFilRect, | |
|
58 | .refreshenable = &ili9328refreshenable, | |
|
59 | .width= 240, | |
|
60 | .height = 320 | |
|
61 | }; | |
|
62 | ||
|
63 | terminal_t terminal0; | |
|
64 | ||
|
65 | volatile int8_t* lcd0_CMD=(volatile int8_t*) 0x60000000; | |
|
66 | volatile int8_t* lcd0_DATA=(volatile int8_t*)(0x61FFFFF0); | |
|
67 | ||
|
68 | float VREF0 =(float)3.3; | |
|
69 | volatile vs10XXDev audioCodec0; | |
|
70 | ||
|
71 | int bsp_init() | |
|
72 | { | |
|
73 | int i=0; | |
|
74 | for(i=0;i<__MAX_OPENED_FILES__;i++) | |
|
75 | { | |
|
76 | __opnfiles__[i] = NULL; | |
|
77 | } | |
|
78 | bsp_GPIO_init(); | |
|
79 | bsp_uart_init(); | |
|
80 | bsp_iic_init(); | |
|
81 | bsp_FSMC_init(); | |
|
82 | bsp_GTerm_init(); | |
|
83 | bsp_spi_init(); | |
|
84 | bsp_SD_init(); | |
|
85 | bsp_Audio_init(); | |
|
86 | printf("\r=====================\n\r"); | |
|
87 | printf( "=====================\n\r"); | |
|
88 | printf(BSP); | |
|
89 | printf(" initialised\n\r"); | |
|
90 | printf( "=====================\n\r"); | |
|
91 | return 1; | |
|
92 | } | |
|
93 | ||
|
94 | void bsp_GPIO_init() | |
|
95 | { | |
|
96 | gpio_t GPIO_Out_init_List[]={LED1,LED2,LCD_RESET,LCD_BACKL,VS1053xCS,VS1053xDCS,VS1053xRESET,SDCARD2CS}; | |
|
97 | for(int i=0;i<8;i++) | |
|
98 | { | |
|
99 | gpio_t GPIO_init = gpioopen(GPIO_Out_init_List[i]); | |
|
100 | GPIO_init |= gpiohighspeed | gpiooutdir | gpiopushpulltype; | |
|
101 | gpiosetconfig(&GPIO_init); | |
|
102 | } | |
|
103 | gpio_t GPIO_In_init_List[]={VS1053DREQ,SDCARD2CD}; | |
|
104 | for(int i=0;i<2;i++) | |
|
105 | { | |
|
106 | gpio_t GPIO_init = gpioopen(GPIO_In_init_List[i]); | |
|
107 | GPIO_init |= gpiohighspeed | gpioindir; | |
|
108 | gpiosetconfig(&GPIO_init); | |
|
109 | } | |
|
110 | gpioclr(VS1053xRESET); | |
|
111 | gpioset(VS1053xCS); | |
|
112 | gpioset(VS1053xDCS); | |
|
113 | gpioset(SDCARD2CS); | |
|
114 | gpioclr(LCD_RESET); | |
|
115 | gpioclr(LCD_BACKL); | |
|
116 | } | |
|
117 | ||
|
118 | void bsp_uart_init() | |
|
119 | { | |
|
120 | ||
|
121 | } | |
|
122 | ||
|
123 | /* | |
|
124 | D0 PD14 D1 PD15 D2 PD0 D3 PD1 D4 PE7 | |
|
125 | D5 PE8 D6 PE9 D7 PE10 | |
|
126 | A20 PE4 = RS FSMC_NE1 PD7 CS FSMC_NWE PD5 W/S | |
|
127 | FSMC_NOE PD4 RD | |
|
128 | */ | |
|
129 | ||
|
130 | int bsp_FSMC_init() | |
|
131 | { | |
|
132 | #define GPIOGETPORT(gpio) ((GPIO_TypeDef*)(((((uint32_t)gpio) & (uint32_t)0x0000FF00)*(uint32_t)4) + (uint32_t)GPIOA)) | |
|
133 | #define GPIOPORTNUM(gpio) (((uint32_t)(gpio) & (uint32_t)0x0000FF00)>>(uint32_t)8) | |
|
134 | ||
|
135 | gpio_t LCD_DBxList[]={PD14,PD15,PD0,PD1,PE7,PE8,PE9,PE10\ | |
|
136 | ,PD4,PD5,PD7,PE4}; | |
|
137 | for(int i=0;i<12;i++) | |
|
138 | { | |
|
139 | gpio_t LCD_DBx = gpioopen(LCD_DBxList[i]); | |
|
140 | LCD_DBx |= gpiohighspeed | gpioaf | gpiopushpulltype | gpionopulltype; | |
|
141 | gpiosetconfig(&LCD_DBx); | |
|
142 | GPIO_PinAFConfig(GPIOGETPORT(LCD_DBx), (uint8_t)(LCD_DBx & 0xF), GPIO_AF_FSMC); | |
|
143 | } | |
|
144 | ||
|
145 | FSMC_NORSRAMInitTypeDef FSMC_NORSRAMInitStructure; | |
|
146 | FSMC_NORSRAMTimingInitTypeDef p; | |
|
147 | ||
|
148 | /* Enable FSMC clock */ | |
|
149 | RCC_AHB3PeriphClockCmd(RCC_AHB3Periph_FSMC, ENABLE); | |
|
150 | ||
|
151 | /*-- FSMC Configuration ------------------------------------------------------*/ | |
|
152 | /*----------------------- SRAM Bank 3 ----------------------------------------*/ | |
|
153 | /* FSMC_Bank1_NORSRAM4 configuration */ | |
|
154 | //p.FSMC_AddressSetupTime = 5; | |
|
155 | //p.FSMC_AddressSetupTime = 1; | |
|
156 | p.FSMC_AddressSetupTime = 3; | |
|
157 | p.FSMC_AddressHoldTime = 3; | |
|
158 | //p.FSMC_DataSetupTime = 9; | |
|
159 | //ili9328 -> data setup time > 10ns | |
|
160 | p.FSMC_DataSetupTime = 1; | |
|
161 | if(getCpuFreq()>100*1000*1000) | |
|
162 | p.FSMC_DataSetupTime = 2;// 11; | |
|
163 | p.FSMC_BusTurnAroundDuration = 0; | |
|
164 | p.FSMC_CLKDivision = 0; | |
|
165 | p.FSMC_DataLatency = 0; | |
|
166 | //ili9328 -> data hold time > 15ns | |
|
167 | if(getCpuFreq()>66*1000*1000) | |
|
168 | p.FSMC_DataLatency = 0; | |
|
169 | p.FSMC_AccessMode = FSMC_AccessMode_A; | |
|
170 | ||
|
171 | FSMC_NORSRAMInitStructure.FSMC_Bank = FSMC_Bank1_NORSRAM1; | |
|
172 | FSMC_NORSRAMInitStructure.FSMC_DataAddressMux = FSMC_DataAddressMux_Disable; | |
|
173 | FSMC_NORSRAMInitStructure.FSMC_MemoryType = FSMC_MemoryType_SRAM; | |
|
174 | FSMC_NORSRAMInitStructure.FSMC_MemoryDataWidth = FSMC_MemoryDataWidth_8b; | |
|
175 | FSMC_NORSRAMInitStructure.FSMC_BurstAccessMode = FSMC_BurstAccessMode_Disable; | |
|
176 | FSMC_NORSRAMInitStructure.FSMC_AsynchronousWait = FSMC_AsynchronousWait_Disable; | |
|
177 | FSMC_NORSRAMInitStructure.FSMC_WaitSignalPolarity = FSMC_WaitSignalPolarity_Low; | |
|
178 | FSMC_NORSRAMInitStructure.FSMC_WrapMode = FSMC_WrapMode_Disable; | |
|
179 | FSMC_NORSRAMInitStructure.FSMC_WaitSignalActive = FSMC_WaitSignalActive_BeforeWaitState; | |
|
180 | FSMC_NORSRAMInitStructure.FSMC_WriteOperation = FSMC_WriteOperation_Enable; | |
|
181 | FSMC_NORSRAMInitStructure.FSMC_WaitSignal = FSMC_WaitSignal_Disable; | |
|
182 | FSMC_NORSRAMInitStructure.FSMC_ExtendedMode = FSMC_ExtendedMode_Disable; | |
|
183 | FSMC_NORSRAMInitStructure.FSMC_WriteBurst = FSMC_WriteBurst_Disable; | |
|
184 | FSMC_NORSRAMInitStructure.FSMC_ReadWriteTimingStruct = &p; | |
|
185 | FSMC_NORSRAMInitStructure.FSMC_WriteTimingStruct = &p; | |
|
186 | ||
|
187 | FSMC_NORSRAMInit(&FSMC_NORSRAMInitStructure); | |
|
188 | ||
|
189 | FSMC_NORSRAMCmd(FSMC_Bank1_NORSRAM1, ENABLE); | |
|
190 | gpioset(LCD_RESET); | |
|
191 | gpioclr(LCD_RESET); | |
|
192 | delay_100us(500); | |
|
193 | gpioset(LCD_RESET); | |
|
194 | delay_100us(500); | |
|
195 | lcd0.init(&lcd0); | |
|
196 | gpioset(LCD_BACKL); | |
|
197 | return 1; | |
|
198 | } | |
|
199 | ||
|
200 | void bsp_spi_init() | |
|
201 | { | |
|
202 | gpio_t VSSPI_DBxList[]={VS1053SCK,VS1053MOSI,VS1053MISO}; | |
|
203 | for(int i=0;i<3;i++) | |
|
204 | { | |
|
205 | gpio_t SPI_DBx = gpioopen(VSSPI_DBxList[i]); | |
|
206 | SPI_DBx |= gpiohighspeed | gpioaf | gpiopushpulltype | gpionopulltype; | |
|
207 | gpiosetconfig(&SPI_DBx); | |
|
208 | GPIO_PinAFConfig(GPIOGETPORT(SPI_DBx), (uint8_t)(SPI_DBx & 0xF), GPIO_AF_SPI1); | |
|
209 | } | |
|
210 | spiopenandconfig(VS1053SPI,spi8bits|spimaster|spimsbfirst,2*1000*1000,VS1053MOSI,VS1053MISO,VS1053SCK,-1); | |
|
211 | ||
|
212 | gpio_t SDSPI_DBxList[]={SDCARD2SCK,SDCARD2MOSI,SDCARD2MISO}; | |
|
213 | for(int i=0;i<3;i++) | |
|
214 | { | |
|
215 | gpio_t SPI_DBx = gpioopen(SDSPI_DBxList[i]); | |
|
216 | SPI_DBx |= gpiohighspeed | gpioaf | gpiopushpulltype | gpionopulltype; | |
|
217 | gpiosetconfig(&SPI_DBx); | |
|
218 | GPIO_PinAFConfig(GPIOGETPORT(SPI_DBx), (uint8_t)(SPI_DBx & 0xF), GPIO_AF_SPI3); | |
|
219 | } | |
|
220 | spiopenandconfig(SDCARD2SPI,spi8bits|spimaster|spimsbfirst,400*1000,SDCARD2MOSI,SDCARD2MISO,SDCARD2SCK,-1); | |
|
221 | ||
|
222 | } | |
|
223 | ||
|
224 | ||
|
225 | void bsp_iic_init() | |
|
226 | { | |
|
227 | // i2copenandconfig(i2c2,0,10000,PF0,PF1); | |
|
228 | } | |
|
229 | ||
|
230 | ||
|
231 | void bsp_Audio_init() | |
|
232 | { | |
|
233 | vs10XXopen(&audioCodec0,VS1053SPI,vs1052setXCS,vs1052setRST,vs1052setXDCS,vs10XXDREQ); | |
|
234 | } | |
|
235 | ||
|
236 | void bsp_SD_init() | |
|
237 | { | |
|
238 | sdcardDev sdcard2; | |
|
239 | blkdevice sdcard2blkdev; | |
|
240 | dikpartition sdcard2Part1; | |
|
241 | sdcardspimake(&sdcard2,(UHANDLE)SDCARD2SPI,spigetnc,spiputnc,spisetspeed,spigetspeed); | |
|
242 | sdcardspimakeblkdev(&sdcard2blkdev,&sdcard2,bspsdcardselect,bsppowersdcard,bspsdcardpresent,bspsdcardwriteprotected); | |
|
243 | sdcard2blkdev.initialize(&sdcard2blkdev); | |
|
244 | mbropen(&sdcard2blkdev,&sdcard2Part1,1); | |
|
245 | } | |
|
246 | ||
|
247 | void vs1052setXCS(char val) | |
|
248 | { | |
|
249 | gpiosetval(VS1053xCS,(int)val); | |
|
250 | } | |
|
251 | ||
|
252 | void vs1052setXDCS(char val) | |
|
253 | { | |
|
254 | gpiosetval(VS1053xDCS,(int)val); | |
|
255 | } | |
|
256 | ||
|
257 | void vs1052setRST(char val) | |
|
258 | { | |
|
259 | if(val) | |
|
260 | gpioset(VS1053xRESET); | |
|
261 | else | |
|
262 | gpioclr(VS1053xRESET); | |
|
263 | } | |
|
264 | ||
|
265 | int vs10XXDREQ() | |
|
266 | { | |
|
267 | return gpiogetval(VS1053DREQ); | |
|
268 | } | |
|
269 | ||
|
270 | ||
|
271 | void bsppowersdcard(char onoff) //always ON | |
|
272 | { | |
|
273 | ||
|
274 | } | |
|
275 | ||
|
276 | char bspsdcardpresent() | |
|
277 | { | |
|
278 | return gpiogetval(SDCARD2CD); | |
|
279 | } | |
|
280 | ||
|
281 | char bspsdcardwriteprotected() | |
|
282 | { | |
|
283 | return 0; | |
|
284 | } | |
|
285 | ||
|
286 | void bspsdcardselect(char YESNO) | |
|
287 | { | |
|
288 | if(YESNO) | |
|
289 | gpioclr(SDCARD2CS); | |
|
290 | else | |
|
291 | gpioset(SDCARD2CS); | |
|
292 | } | |
|
293 | ||
|
294 | ||
|
295 | void bsp_lcd0_write_reg(uint32_t reg,uint32_t data) | |
|
296 | { | |
|
297 | uint8_t* pt8 = (uint8_t*)(void*)® | |
|
298 | #if __BYTE_ORDER__==__ORDER_BIG_ENDIAN__ | |
|
299 | *lcd0_CMD=pt8[3]; | |
|
300 | *lcd0_CMD=pt8[2]; | |
|
301 | pt8 = (uint8_t*)(void*)&data; | |
|
302 | *lcd0_DATA=pt8[3]; | |
|
303 | *lcd0_DATA=pt8[2]; | |
|
304 | #else | |
|
305 | *lcd0_CMD=pt8[1]; | |
|
306 | *lcd0_CMD=pt8[0]; | |
|
307 | pt8 = (uint8_t*)(void*)&data; | |
|
308 | *lcd0_DATA=pt8[1]; | |
|
309 | *lcd0_DATA=pt8[0]; | |
|
310 | #endif | |
|
311 | ||
|
312 | } | |
|
313 | ||
|
314 | uint32_t bsp_lcd0_read_reg(uint32_t reg) | |
|
315 | { | |
|
316 | uint8_t* pt8 = (uint8_t*)(void*)® | |
|
317 | uint32_t DATA=0; | |
|
318 | #if __BYTE_ORDER__==__ORDER_BIG_ENDIAN__ | |
|
319 | *lcd0_CMD=pt8[3]; | |
|
320 | *lcd0_CMD=pt8[2]; | |
|
321 | pt8 = (uint8_t*)(void*)&DATA; | |
|
322 | pt8[3]=*lcd0_DATA; | |
|
323 | pt8[2]=*lcd0_DATA; | |
|
324 | #else | |
|
325 | ||
|
326 | *lcd0_CMD=pt8[1]; | |
|
327 | *lcd0_CMD=pt8[0]; | |
|
328 | pt8 = (uint8_t*)(void*)&DATA; | |
|
329 | pt8[1]=*lcd0_DATA; | |
|
330 | pt8[0]=*lcd0_DATA; | |
|
331 | #endif | |
|
332 | ||
|
333 | return DATA; | |
|
334 | } | |
|
335 | ||
|
336 | void bsp_lcd0_writeGRAM(void* buffer,uint32_t count) | |
|
337 | { | |
|
338 | uint32_t reg =ILI9328_REGISTER_WRITEDATATOGRAM; | |
|
339 | uint8_t* pt8 = (uint8_t*)(void*)® | |
|
340 | #if __BYTE_ORDER__==__ORDER_BIG_ENDIAN__ | |
|
341 | *lcd0_CMD=pt8[3]; | |
|
342 | *lcd0_CMD=pt8[2]; | |
|
343 | pt8 = (uint8_t*)(void*)buffer; | |
|
344 | for(int i=0;i<(int)count;i++) | |
|
345 | { | |
|
346 | *lcd0_DATA=pt8[(2*i) +1]; | |
|
347 | *lcd0_DATA=pt8[2*i]; | |
|
348 | } | |
|
349 | #else | |
|
350 | ||
|
351 | *lcd0_CMD=pt8[1]; | |
|
352 | *lcd0_CMD=pt8[0]; | |
|
353 | pt8 = (uint8_t*)(void*)buffer; | |
|
354 | for(int i=0;i<(int)count;i++) | |
|
355 | { | |
|
356 | ||
|
357 | *lcd0_DATA=pt8[(2*i) +1]; | |
|
358 | *lcd0_DATA=pt8[2*i]; | |
|
359 | } | |
|
360 | #endif | |
|
361 | } | |
|
362 | ||
|
363 | void bsp_lcd0_readGRAM(void* buffer,uint32_t count) | |
|
364 | { | |
|
365 | uint32_t reg =ILI9328_REGISTER_WRITEDATATOGRAM; | |
|
366 | uint8_t* pt8 = (uint8_t*)(void*)® | |
|
367 | #if __BYTE_ORDER__==__ORDER_BIG_ENDIAN__ | |
|
368 | *lcd0_CMD=pt8[3]; | |
|
369 | *lcd0_CMD=pt8[2]; | |
|
370 | pt8 = (uint8_t*)(void*)buffer; | |
|
371 | pt8[0] = *lcd0_DATA; | |
|
372 | pt8[0] = *lcd0_DATA; | |
|
373 | for(int i=0;i<(int)count;i++) | |
|
374 | { | |
|
375 | pt8[(2*i) +1]=*lcd0_DATA; | |
|
376 | pt8[2*i]=*lcd0_DATA; | |
|
377 | } | |
|
378 | #else | |
|
379 | ||
|
380 | *lcd0_CMD=pt8[1]; | |
|
381 | *lcd0_CMD=pt8[0]; | |
|
382 | pt8 = (uint8_t*)(void*)buffer; | |
|
383 | pt8[0] = *lcd0_DATA; | |
|
384 | pt8[0] = *lcd0_DATA; | |
|
385 | for(int i=0;i<(int)count;i++) | |
|
386 | { | |
|
387 | pt8[(2*i) +1]=*lcd0_DATA; | |
|
388 | pt8[2*i]=*lcd0_DATA; | |
|
389 | } | |
|
390 | #endif | |
|
391 | } | |
|
392 | ||
|
393 | void bsp_GTerm_init() | |
|
394 | { | |
|
395 | if(__opnfiles__[1]==NULL) | |
|
396 | { | |
|
397 | //uart_t* uart1 = (uart_t*)malloc(sizeof(uart_t)); | |
|
398 | streamdevice* fd1 = (streamdevice*)malloc(sizeof(streamdevice)); | |
|
399 | terminal_init(&terminal0 ,&lcd0,&ComicSansMS_8,fd1); | |
|
400 | __opnfiles__[1] = fd1; | |
|
401 | } | |
|
402 | else | |
|
403 | { | |
|
404 | ||
|
405 | } | |
|
406 | } | |
|
407 | ||
|
408 | ||
|
409 | ||
|
410 | ||
|
411 | ||
|
412 | ||
|
413 | ||
|
414 | ||
|
415 | ||
|
416 | ||
|
417 | ||
|
418 | ||
|
419 | ||
|
420 | ||
|
421 | ||
|
422 | ||
|
423 |
@@ -0,0 +1,116 | |||
|
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@gmail.com | |
|
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 <VS10XX.h> | |
|
32 | ||
|
33 | #define __MAX_OPENED_FILES__ 4 | |
|
34 | #define __FS_ROOT_SIZE__ 4 | |
|
35 | ||
|
36 | ||
|
37 | #define LED1 PC15 | |
|
38 | #define LED2 PC14 | |
|
39 | ||
|
40 | #define LCD_RESET PD10 | |
|
41 | #define LCD_BACKL PE11 | |
|
42 | ||
|
43 | #define VS1053SPI spi1 | |
|
44 | #define VS1053xCS PA3 | |
|
45 | #define VS1053xRESET PA2 | |
|
46 | #define VS1053xDCS PA4 | |
|
47 | #define VS1053DREQ PA1 | |
|
48 | #define VS1053MISO PA6 | |
|
49 | #define VS1053MOSI PA7 | |
|
50 | #define VS1053SCK PA5 | |
|
51 | ||
|
52 | ||
|
53 | ||
|
54 | #define SDCARD2SPI spi3 | |
|
55 | #define SDCARD2CS PB8 | |
|
56 | #define SDCARD2CD PB9 | |
|
57 | #define SDCARD2MISO PB4 | |
|
58 | #define SDCARD2MOSI PB5 | |
|
59 | #define SDCARD2SCK PB3 | |
|
60 | ||
|
61 | extern float VREF0; | |
|
62 | ||
|
63 | extern uint32_t currentCpuFreq; | |
|
64 | extern LCD_t lcd0; | |
|
65 | ||
|
66 | extern volatile vs10XXDev audioCodec0; | |
|
67 | ||
|
68 | extern int bsp_init(); | |
|
69 | ||
|
70 | extern void bsp_GPIO_init(); | |
|
71 | extern void bsp_uart_init(); | |
|
72 | extern void bsp_iic_init(); | |
|
73 | extern void bsp_spi_init(); | |
|
74 | extern void bsp_SD_init(); | |
|
75 | extern void bsp_Audio_init(); | |
|
76 | extern void bsp_GTerm_init(); | |
|
77 | extern int bsp_FSMC_init(); | |
|
78 | ||
|
79 | /* VS1053 */ | |
|
80 | extern void vs1052setXCS(char val); | |
|
81 | extern void vs1052setXDCS(char val); | |
|
82 | extern void vs1052setRST(char val); | |
|
83 | extern int vs10XXDREQ(); | |
|
84 | ||
|
85 | /* SD CARD */ | |
|
86 | void bsppowersdcard(char onoff); | |
|
87 | char bspsdcardpresent(); | |
|
88 | void bspsdcardselect(char YESNO); | |
|
89 | char bspsdcardwriteprotected(); | |
|
90 | ||
|
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 | #endif | |
|
98 | ||
|
99 | ||
|
100 | ||
|
101 | ||
|
102 | ||
|
103 | ||
|
104 | ||
|
105 | ||
|
106 | ||
|
107 | ||
|
108 | ||
|
109 | ||
|
110 | ||
|
111 | ||
|
112 | ||
|
113 | ||
|
114 | ||
|
115 | ||
|
116 |
@@ -6,7 +6,8 SUBDIRS += STM32F4Discovery \ | |||
|
6 | 6 | SOLAR_LFR_PSU \ |
|
7 | 7 | BEAGLESYNTH \ |
|
8 | 8 | STM32F4Eval \ |
|
9 | STM32F4Discovery-EXT | |
|
9 | STM32F4Discovery-EXT \ | |
|
10 | OPLAYER | |
|
10 | 11 | |
|
11 | 12 | |
|
12 | 13 |
@@ -3,7 +3,9 CONFIG += cpu | |||
|
3 | 3 | |
|
4 | 4 | |
|
5 | 5 | UCMODEL=stm32f4 |
|
6 | BSP = BEAGLESYNTH | |
|
6 | BSP = OPLAYER | |
|
7 | ||
|
8 | DEFINES += CPUFREQ=160000000 | |
|
7 | 9 | |
|
8 | 10 | SOURCES += \ |
|
9 | 11 | main.c |
@@ -5,17 +5,43 | |||
|
5 | 5 | #include <stm32f4xx.h> |
|
6 | 6 | #include <bsp.h> |
|
7 | 7 | #include <core.h> |
|
8 | #include <VS10XX.h> | |
|
9 | #include <bsp.h> | |
|
8 | 10 | |
|
9 | 11 | extern streamdevice* __opnfiles__[]; |
|
10 | 12 | |
|
13 | void randBoxesDemo() | |
|
14 | { | |
|
15 | int16_t x,y,w,h,t,r; | |
|
16 | x=rand()%240; | |
|
17 | y=rand()%320; | |
|
18 | w=rand()%(240-x); | |
|
19 | if(x>y) | |
|
20 | r=(rand()%(y))%(320-y); | |
|
21 | else | |
|
22 | r=(rand()%(x))%(240-x); | |
|
23 | h=rand()%(320-y); | |
|
24 | t=rand()%(10); | |
|
25 | ili9328paintFilRect(&lcd0,x,y,w,h,rand(),t,rand()); | |
|
26 | //ili9328paintFilCirc(&lcd0,x,y,r,rand(),t,rand()); | |
|
27 | //delay_100us(10); | |
|
28 | //for(volatile int i=0;i<(1024*2);i++); | |
|
29 | } | |
|
30 | ||
|
11 | 31 | int main() |
|
12 | 32 | { |
|
13 | while(1) | |
|
33 | while(1) | |
|
14 | 34 | { |
|
15 | gpioset(LED3); | |
|
35 | // printf("Audio Codec reg0=0x%x\n",vs10XXcmdread(&audioCodec0,0)); | |
|
36 | // printf("hello "); | |
|
37 | // bsp_lcd0_write_reg(1,0x1234); | |
|
38 | // delay_100us(10000); | |
|
39 | // randBoxesDemo(); | |
|
40 | gpioset(LED1); | |
|
16 | 41 | delay_100us(10000); |
|
17 |
gpioclr(LED |
|
|
42 | gpioclr(LED1); | |
|
18 | 43 | delay_100us(10000); |
|
44 | ||
|
19 | 45 | } |
|
20 | 46 | printf("hello world\n\r"); |
|
21 | 47 | return 0; |
@@ -23,20 +49,6 int main() | |||
|
23 | 49 | |
|
24 | 50 | |
|
25 | 51 | |
|
26 | void USART3_IRQHandler(void) | |
|
27 | { | |
|
28 | while(1) | |
|
29 | { | |
|
30 | for(volatile int i=0;i<1024*2048;i++); | |
|
31 | gpioset(PD12); | |
|
32 | gpioclr(PD14); | |
|
33 | for(volatile int i=0;i<1024*2048;i++); | |
|
34 | gpioclr(PD12); | |
|
35 | gpioset(PD14); | |
|
36 | } | |
|
37 | } | |
|
38 | 52 | |
|
39 | 53 | |
|
40 | 54 | |
|
41 | ||
|
42 |
@@ -19,13 +19,23 | |||
|
19 | 19 | #-- Author : Alexis Jeandet |
|
20 | 20 | #-- Mail : alexis.jeandet@gmail.com |
|
21 | 21 | #-------------------------------------------------------------------------------*/ |
|
22 |
#include |
|
|
23 |
#include |
|
|
22 | #include <spi.h> | |
|
23 | #include <VS10XX.h> | |
|
24 | #include <core.h> | |
|
24 | 25 | //#include <bsp.h> |
|
25 | 26 | |
|
26 | void vs10XXopen(vs10XXDev* codec,spi_t dev){ | |
|
27 | void vs10XXopen(vs10XXDev *codec, spi_t dev, void (*setxCS)(char), void (*setxRST)(char), void (*setxDCS)(char), int (*getDREQ)()) | |
|
28 | { | |
|
27 | 29 | codec->SPIdev = dev; |
|
28 | ||
|
30 | codec->setxCS = setxCS; | |
|
31 | codec->setxDCS = setxDCS; | |
|
32 | codec->setxRST = setxRST; | |
|
33 | codec->getDREQ = getDREQ; | |
|
34 | codec->setxDCS(1); | |
|
35 | codec->setxCS(1); | |
|
36 | codec->setxRST(0); | |
|
37 | delay_100us(2); | |
|
38 | codec->setxRST(1); | |
|
29 | 39 | } |
|
30 | 40 | |
|
31 | 41 | void vs10XXsoftreset(vs10XXDev* dev) |
@@ -35,22 +45,28 void vs10XXsoftreset(vs10XXDev* dev) | |||
|
35 | 45 | |
|
36 | 46 | int vs10XXcmdread(vs10XXDev* dev,char address) |
|
37 | 47 | { |
|
38 |
|
|
|
39 |
|
|
|
40 | vs10XXclearXCS(); | |
|
41 |
spiputw(dev->SPIdev, |
|
|
42 |
|
|
|
43 | vs10XXsetXCS(); | |
|
48 | int result; | |
|
49 | while(!dev->getDREQ()); | |
|
50 | dev->setxCS(0); | |
|
51 | spiputw(dev->SPIdev,3); | |
|
52 | spiputw(dev->SPIdev,address); | |
|
53 | result = (0xFF00 & (spigetw(dev->SPIdev)<<8)) + (0xFF & spigetw(dev->SPIdev)); | |
|
54 | dev->setxCS(1); | |
|
44 | 55 | return result; |
|
45 | 56 | } |
|
46 | 57 | |
|
47 | 58 | |
|
48 | 59 | void vs10XXcmdwrite(vs10XXDev* dev,char address,int value) |
|
49 | 60 | { |
|
50 |
|
|
|
51 | vs10XXclearXCS(); | |
|
52 |
spiputw(dev->SPIdev, |
|
|
61 | while(!dev->getDREQ()); | |
|
62 | dev->setxCS(0); | |
|
63 | spiputw(dev->SPIdev,2<<8); | |
|
64 | spiputw(dev->SPIdev,address); | |
|
65 | spiputw(dev->SPIdev,value>>8); | |
|
53 | 66 | spiputw(dev->SPIdev,value); |
|
54 | vs10XXsetXCS(); | |
|
67 | dev->setxCS(1); | |
|
55 | 68 | } |
|
56 | 69 | |
|
70 | ||
|
71 | ||
|
72 |
@@ -6,6 +6,7 SOURCES += VS10XX.c | |||
|
6 | 6 | |
|
7 | 7 | |
|
8 | 8 | HEADERS += ../../../includes/VS10XX.h |
|
9 | INCLUDEPATH += ../../../includes | |
|
9 | 10 | |
|
10 | 11 | UCMODEL=stm32f4 |
|
11 | 12 |
@@ -21,6 +21,8 | |||
|
21 | 21 | -------------------------------------------------------------------------------*/ |
|
22 | 22 | #include <sdcard.h> |
|
23 | 23 | #include <sdcard-spi.h> |
|
24 | #include <stdio.h> | |
|
25 | #include <core.h> | |
|
24 | 26 | |
|
25 | 27 | int sdcardselect (blkdeviceptr _this); |
|
26 | 28 | void sdcarddeselect (blkdeviceptr _this); |
@@ -58,17 +60,17 int sdcardselect (blkdeviceptr _this) /* | |||
|
58 | 60 | |
|
59 | 61 | int sdcardwait_ready (sdcardDev* sdcard) /* 1:OK, 0:Timeout */ |
|
60 | 62 | { |
|
61 |
|
|
|
63 | char d=0; | |
|
62 | 64 | unsigned int tmr; |
|
63 | 65 | volatile unsigned int i=0; |
|
64 | 66 | |
|
65 |
|
|
|
67 | for (tmr = 1000; tmr>0; tmr--) { /* Wait for ready in timeout of 500ms */ | |
|
66 | 68 | sdcard->rcvr_mmc(sdcard->phy,&d, 1); |
|
67 | 69 | if (d == 0xFF) break; |
|
68 | for(i=0;i<128;i++); | |
|
70 | delay_100us(10); | |
|
69 | 71 | } |
|
70 | 72 | |
|
71 |
|
|
|
73 | return tmr != 0; | |
|
72 | 74 | } |
|
73 | 75 | |
|
74 | 76 | int sdcardrcvr_datablock (sdcardDev* sdcard,char *buff,uint32_t btr) |
@@ -123,7 +125,7 char sdcardsend_cmd (blkdeviceptr _this, | |||
|
123 | 125 | } |
|
124 | 126 | /* Select the card and wait for ready */ |
|
125 | 127 | sdcarddeselect(_this); |
|
126 |
|
|
|
128 | if (!sdcardselect(_this)) {printf("Can't select SDCARD\n");return 0xFF;} | |
|
127 | 129 | /* Send a command packet */ |
|
128 | 130 | buf[0] = 0x40 | cmd; /* Start + Command index */ |
|
129 | 131 | buf[1] = (char)(arg >> 24); /* Argument[31..24] */ |
@@ -190,12 +192,18 DSTATUS sdcarddisk_initialize (blkdevice | |||
|
190 | 192 | |
|
191 | 193 | ((sdcardDev*)_this->phy)->setspeed(((sdcardDev*)_this->phy)->phy,350000); |
|
192 | 194 | if (_this==0) return STA_NOINIT; /* Supports only drive 0 */ |
|
193 | if (((sdcardDev*)_this->phy)->Stat & STA_NODISK) return ((sdcardDev*)_this->phy)->Stat; /* Is card existing in the soket? */ | |
|
194 | ||
|
195 | /* Is card existing in the soket? */ | |
|
196 | if (((sdcardDev*)_this->phy)->Stat & STA_NODISK) | |
|
197 | { | |
|
198 | printf("No SDCARD\n"); | |
|
199 | return ((sdcardDev*)_this->phy)->Stat; | |
|
200 | } | |
|
201 | printf("SDCARD Detected\n"); | |
|
195 | 202 | for (n = 10; n; n--) ((sdcardDev*)_this->phy)->xmit_mmc(((sdcardDev*)_this->phy)->phy,&dummy, 1); /* Send 80 dummy clocks */ |
|
196 | 203 | |
|
197 | 204 | ty = 0; |
|
198 | 205 | if (sdcardsend_cmd(_this,CMD0, 0) == 1) { /* Put the card SPI/Idle state */ |
|
206 | printf("SDCARD in Idle mode\n"); | |
|
199 | 207 | Timer1 = 1000; /* Initialization timeout = 1 sec */ |
|
200 | 208 | if (sdcardsend_cmd(_this,CMD8, 0x1AA) == 1) { /* SDv2? */ |
|
201 | 209 | ((sdcardDev*)_this->phy)->rcvr_mmc(((sdcardDev*)_this->phy)->phy,ocr, 4); |
@@ -454,7 +462,7 DRESULT sdcarddisk_ioctl (blkdeviceptr _ | |||
|
454 | 462 | |
|
455 | 463 | |
|
456 | 464 | |
|
457 | void sdcardmake(sdcardDev* sdcard,UHANDLE phy,void (*rcvr_mmc) (UHANDLE,char *,uint32_t),void (*xmit_mmc) (UHANDLE,const char *,uint32_t ),void (*setspeed) (UHANDLE phy,uint32_t speed),uint32_t (*getspeed) (UHANDLE phy)) | |
|
465 | void sdcardspimake(sdcardDev* sdcard,UHANDLE phy,void (*rcvr_mmc) (UHANDLE,char *,uint32_t),void (*xmit_mmc) (UHANDLE,const char *,uint32_t ),void (*setspeed) (UHANDLE phy,uint32_t speed),uint32_t (*getspeed) (UHANDLE phy)) | |
|
458 | 466 | { |
|
459 | 467 | sdcard->phy = phy; |
|
460 | 468 | sdcard->rcvr_mmc = rcvr_mmc; |
@@ -463,7 +471,7 void sdcardmake(sdcardDev* sdcard,UHANDL | |||
|
463 | 471 | sdcard->getspeed = getspeed; |
|
464 | 472 | } |
|
465 | 473 | |
|
466 | void sdcardmakeblkdev(blkdevice* dev,sdcardDev* sdcard, blkdevselect_t select,blkdevpower_t power,blkdevdetect_t detect,blkdevwriteprotected_t writeprotected) | |
|
474 | void sdcardspimakeblkdev(blkdevice* dev,sdcardDev* sdcard, blkdevselect_t select,blkdevpower_t power,blkdevdetect_t detect,blkdevwriteprotected_t writeprotected) | |
|
467 | 475 | { |
|
468 | 476 | dev->phy=sdcard; |
|
469 | 477 | dev->select=select; |
@@ -15,3 +15,6 UCMODEL=stm32f4 | |||
|
15 | 15 | target.path = $$[QT_INSTALL_LIBS]/$$UCMODEL |
|
16 | 16 | INSTALLS += target |
|
17 | 17 | |
|
18 | HEADERS += \ | |
|
19 | ../../../includes/sdcard.h | |
|
20 |
@@ -33,115 +33,115 | |||
|
33 | 33 | |
|
34 | 34 | #define ilipaintLine(LCD,X,Y,W,buffer,buffsize) \ |
|
35 | 35 | for(int l=0;l<1;l++)\ |
|
36 | {\ | |
|
37 |
|
|
|
38 |
|
|
|
39 |
|
|
|
40 |
|
|
|
41 | {\ | |
|
42 |
|
|
|
43 |
|
|
|
36 | {\ | |
|
37 | ili9328setFrame(LCD,X,Y,W,1);\ | |
|
38 | int rem=(W)%buffsize;\ | |
|
39 | if(rem)LCD->interface->writeGRAM(buffer,rem);\ | |
|
40 | for(int i=rem;i<(W);i+=buffsize)\ | |
|
41 | {\ | |
|
42 | LCD->interface->writeGRAM(buffer,buffsize);\ | |
|
43 | }\ | |
|
44 | 44 | } |
|
45 | 45 | |
|
46 | 46 | #define ilipaintHLineWithCont(LCD,X,Y,W,ContSz,bufferInt,buffIntsize,bufferCont,buffContsize) \ |
|
47 | 47 | for(int l=0;l<1;l++)\ |
|
48 | {\ | |
|
49 |
|
|
|
50 |
|
|
|
51 |
|
|
|
52 |
|
|
|
53 | {\ | |
|
54 |
|
|
|
55 |
|
|
|
48 | {\ | |
|
49 | ili9328setFrame(LCD,X,Y,W,1);\ | |
|
50 | int rem=(ContSz)%buffContsize;\ | |
|
51 | if(rem)LCD->interface->writeGRAM(bufferCont,rem);\ | |
|
52 | for(int i=rem;i<(ContSz);i+=buffContsize)\ | |
|
53 | {\ | |
|
54 | LCD->interface->writeGRAM(bufferCont,buffContsize);\ | |
|
55 | }\ | |
|
56 | 56 | if((2*ContSz)<W) \ |
|
57 | {\ | |
|
58 |
|
|
|
59 |
|
|
|
60 |
|
|
|
61 | {\ | |
|
62 |
|
|
|
63 |
|
|
|
57 | {\ | |
|
58 | rem=(W-(2*ContSz))%buffIntsize;\ | |
|
59 | if(rem)LCD->interface->writeGRAM(bufferInt,rem);\ | |
|
60 | for(int i=rem;i<(W-(2*ContSz));i+=buffIntsize)\ | |
|
61 | {\ | |
|
62 | LCD->interface->writeGRAM(bufferInt,buffIntsize);\ | |
|
63 | }\ | |
|
64 | 64 | }\ |
|
65 | 65 | rem=(ContSz)%buffContsize;\ |
|
66 | 66 | if(rem)LCD->interface->writeGRAM(bufferCont,rem);\ |
|
67 | 67 | for(int i=rem;i<(ContSz);i+=buffContsize)\ |
|
68 | {\ | |
|
69 |
|
|
|
68 | {\ | |
|
69 | LCD->interface->writeGRAM(bufferCont,buffContsize);\ | |
|
70 | 70 | }\ |
|
71 | }\ | |
|
71 | }\ | |
|
72 | 72 | |
|
73 | 73 | |
|
74 | 74 | #define ilipaintVLineWithCont(LCD,X,Y,H,ContSz,bufferInt,buffIntsize,bufferCont,buffContsize) \ |
|
75 | 75 | for(int l=0;l<1;l++)\ |
|
76 | {\ | |
|
77 |
|
|
|
78 |
|
|
|
79 |
|
|
|
80 |
|
|
|
81 | {\ | |
|
82 |
|
|
|
83 |
|
|
|
76 | {\ | |
|
77 | ili9328setFrame(LCD,X,Y,1,H);\ | |
|
78 | int rem=(ContSz)%buffContsize;\ | |
|
79 | if(rem)LCD->interface->writeGRAM(bufferCont,rem);\ | |
|
80 | for(int i=rem;i<(ContSz);i+=buffContsize)\ | |
|
81 | {\ | |
|
82 | LCD->interface->writeGRAM(bufferCont,buffContsize);\ | |
|
83 | }\ | |
|
84 | 84 | if((2*ContSz)<H) \ |
|
85 | {\ | |
|
86 |
|
|
|
87 |
|
|
|
88 |
|
|
|
89 | {\ | |
|
90 |
|
|
|
91 |
|
|
|
85 | {\ | |
|
86 | rem=(H-(2*ContSz))%buffIntsize;\ | |
|
87 | if(rem)LCD->interface->writeGRAM(bufferInt,rem);\ | |
|
88 | for(int i=rem;i<(H-(2*ContSz));i+=buffIntsize)\ | |
|
89 | {\ | |
|
90 | LCD->interface->writeGRAM(bufferInt,buffIntsize);\ | |
|
91 | }\ | |
|
92 | 92 | }\ |
|
93 | 93 | rem=(ContSz)%buffContsize;\ |
|
94 | 94 | if(rem)LCD->interface->writeGRAM(bufferCont,rem);\ |
|
95 | 95 | for(int i=rem;i<(ContSz);i+=buffContsize)\ |
|
96 | {\ | |
|
97 |
|
|
|
96 | {\ | |
|
97 | LCD->interface->writeGRAM(bufferCont,buffContsize);\ | |
|
98 | 98 | }\ |
|
99 | }\ | |
|
99 | }\ | |
|
100 | 100 | |
|
101 | 101 | |
|
102 | 102 | #define ilipaintHalfTopVLineWithCont(LCD,X,Y,H,ContSz,bufferInt,buffIntsize,bufferCont,buffContsize) \ |
|
103 | 103 | for(int l=0;l<1;l++)\ |
|
104 | {\ | |
|
105 |
|
|
|
106 |
|
|
|
107 |
|
|
|
108 |
|
|
|
109 | {\ | |
|
110 |
|
|
|
111 |
|
|
|
104 | {\ | |
|
105 | ili9328setFrame(LCD,X,Y,1,H);\ | |
|
106 | int rem=(ContSz)%buffContsize;\ | |
|
107 | if(rem)LCD->interface->writeGRAM(bufferCont,rem);\ | |
|
108 | for(int i=rem;i<(ContSz);i+=buffContsize)\ | |
|
109 | {\ | |
|
110 | LCD->interface->writeGRAM(bufferCont,buffContsize);\ | |
|
111 | }\ | |
|
112 | 112 | if(ContSz<H) \ |
|
113 | {\ | |
|
114 |
|
|
|
115 |
|
|
|
116 |
|
|
|
117 | {\ | |
|
118 |
|
|
|
119 | }\ | |
|
113 | {\ | |
|
114 | rem=(H-ContSz)%buffIntsize;\ | |
|
115 | if(rem)LCD->interface->writeGRAM(bufferInt,rem);\ | |
|
116 | for(int i=rem;i<(H-ContSz);i+=buffIntsize)\ | |
|
117 | {\ | |
|
118 | LCD->interface->writeGRAM(bufferInt,buffIntsize);\ | |
|
120 | 119 | }\ |
|
121 | }\ | |
|
120 | }\ | |
|
121 | }\ | |
|
122 | 122 | |
|
123 | 123 | |
|
124 | 124 | #define ilipaintHalfBottomVLineWithCont(LCD,X,Y,H,ContSz,bufferInt,buffIntsize,bufferCont,buffContsize) \ |
|
125 | 125 | for(int l=0;l<1;l++)\ |
|
126 | {\ | |
|
127 |
|
|
|
126 | {\ | |
|
127 | ili9328setFrame(LCD,X,Y,1,H);\ | |
|
128 | 128 | int rem;\ |
|
129 | 129 | if(ContSz<H) \ |
|
130 | {\ | |
|
131 |
|
|
|
132 |
|
|
|
133 |
|
|
|
134 | {\ | |
|
135 |
|
|
|
136 |
|
|
|
130 | {\ | |
|
131 | rem=(H-ContSz)%buffIntsize;\ | |
|
132 | if(rem)LCD->interface->writeGRAM(bufferInt,rem);\ | |
|
133 | for(int i=rem;i<(H-ContSz);i+=buffIntsize)\ | |
|
134 | {\ | |
|
135 | LCD->interface->writeGRAM(bufferInt,buffIntsize);\ | |
|
136 | }\ | |
|
137 | 137 | }\ |
|
138 | 138 | rem=(ContSz)%buffContsize;\ |
|
139 | 139 | if(rem)LCD->interface->writeGRAM(bufferCont,rem);\ |
|
140 | 140 | for(int i=rem;i<(ContSz);i+=buffContsize)\ |
|
141 | {\ | |
|
142 |
|
|
|
141 | {\ | |
|
142 | LCD->interface->writeGRAM(bufferCont,buffContsize);\ | |
|
143 | 143 | }\ |
|
144 | }\ | |
|
144 | }\ | |
|
145 | 145 | |
|
146 | 146 | |
|
147 | 147 | void ili9328setGRAMaddress(LCD_t* LCD,uint16_t Haddress,uint16_t Vaddress) |
@@ -376,18 +376,18 int ili9328init(struct LCD_t* LCD) | |||
|
376 | 376 | LCD->interface->writereg(ILI9328_REGISTER_DRIVEROUTPUTCONTROL1, 0x0100); // Driver Output Control Register (R01h) |
|
377 | 377 | LCD->interface->writereg(ILI9328_REGISTER_LCDDRIVINGCONTROL, 0x0700); // LCD Driving Waveform Control (R02h) |
|
378 | 378 | LCD->interface->writereg(ILI9328_REGISTER_ENTRYMODE, 0x1030); // Entry Mode (R03h) |
|
379 |
LCD->interface->writereg(ILI9328_REGISTER_DISPLAYCONTROL2, 0x0 |
|
|
379 | LCD->interface->writereg(ILI9328_REGISTER_DISPLAYCONTROL2, 0x0302); | |
|
380 | 380 | LCD->interface->writereg(ILI9328_REGISTER_DISPLAYCONTROL3, 0x0000); |
|
381 | 381 | LCD->interface->writereg(ILI9328_REGISTER_DISPLAYCONTROL4, 0x0000); // Fmark On |
|
382 | 382 | LCD->interface->writereg(ILI9328_REGISTER_POWERCONTROL1, 0x0000); // Power Control 1 (R10h) |
|
383 | 383 | LCD->interface->writereg(ILI9328_REGISTER_POWERCONTROL2, 0x0007); // Power Control 2 (R11h) |
|
384 | 384 | LCD->interface->writereg(ILI9328_REGISTER_POWERCONTROL3, 0x0000); // Power Control 3 (R12h) |
|
385 | 385 | LCD->interface->writereg(ILI9328_REGISTER_POWERCONTROL4, 0x0000); // Power Control 4 (R13h) |
|
386 | delay_100us(10); | |
|
386 | delay_100us(1000); | |
|
387 | 387 | LCD->interface->writereg(ILI9328_REGISTER_POWERCONTROL1, 0x14B0); // Power Control 1 (R10h) |
|
388 |
delay_100us( |
|
|
388 | delay_100us(500); | |
|
389 | 389 | LCD->interface->writereg(ILI9328_REGISTER_POWERCONTROL2, 0x0007); // Power Control 2 (R11h) |
|
390 |
delay_100us( |
|
|
390 | delay_100us(500); | |
|
391 | 391 | LCD->interface->writereg(ILI9328_REGISTER_POWERCONTROL3, 0x008E); // Power Control 3 (R12h) |
|
392 | 392 | LCD->interface->writereg(ILI9328_REGISTER_POWERCONTROL4, 0x0C00); // Power Control 4 (R13h) |
|
393 | 393 | LCD->interface->writereg(ILI9328_REGISTER_POWERCONTROL7, 0x0015); // NVM read data 2 (R29h) |
@@ -403,16 +403,16 int ili9328init(struct LCD_t* LCD) | |||
|
403 | 403 | LCD->interface->writereg(ILI9328_REGISTER_GAMMACONTROL9, 0x0203); // Gamma Control 9 |
|
404 | 404 | LCD->interface->writereg(ILI9328_REGISTER_GAMMACONTROL10, 0x0403); // Gamma Control 10 |
|
405 | 405 | LCD->interface->writereg(ILI9328_REGISTER_HORIZONTALADDRESSSTARTPOSITION, 0x0000); // Window Horizontal RAM Address Start (R50h) |
|
406 |
LCD->interface->writereg(ILI9328_REGISTER_HORIZONTALADDRESSENDPOSITION, |
|
|
406 | LCD->interface->writereg(ILI9328_REGISTER_HORIZONTALADDRESSENDPOSITION, LCD->width - 1); // Window Horizontal RAM Address End (R51h) | |
|
407 | 407 | LCD->interface->writereg(ILI9328_REGISTER_VERTICALADDRESSSTARTPOSITION, 0X0000); // Window Vertical RAM Address Start (R52h) |
|
408 |
LCD->interface->writereg(ILI9328_REGISTER_VERTICALADDRESSENDPOSITION, |
|
|
408 | LCD->interface->writereg(ILI9328_REGISTER_VERTICALADDRESSENDPOSITION, LCD->height - 1); // Window Vertical RAM Address End (R53h) | |
|
409 | 409 | LCD->interface->writereg(ILI9328_REGISTER_DRIVEROUTPUTCONTROL2, 0xa700); // Driver Output Control (R60h) |
|
410 | 410 | LCD->interface->writereg(ILI9328_REGISTER_BASEIMAGEDISPLAYCONTROL, 0x0003); // Driver Output Control (R61h) - enable VLE |
|
411 | 411 | LCD->interface->writereg(ILI9328_REGISTER_PANELINTERFACECONTROL1, 0X0010); // Panel Interface Control 1 (R90h) |
|
412 | 412 | // Display On |
|
413 | 413 | LCD->interface->writereg(ILI9328_REGISTER_DISPLAYCONTROL1, 0x0133); // Display Control (R07h) |
|
414 | 414 | delay_100us(500); |
|
415 | LCD->interface->writereg(ILI9328_REGISTER_ENTRYMODE, 0x0038); | |
|
415 | LCD->paintFilRect(LCD,0,0,LCD->width,LCD->height,0,0,0xFFFF); | |
|
416 | 416 | } |
|
417 | 417 | return 0; |
|
418 | 418 | } |
@@ -44,11 +44,15 | |||
|
44 | 44 | typedef struct vs10XXDev |
|
45 | 45 | { |
|
46 | 46 | spi_t SPIdev; |
|
47 | void (*setxCS)(char); | |
|
48 | void (*setxRST)(char); | |
|
49 | void (*setxDCS)(char); | |
|
50 | int (*getDREQ)(); | |
|
47 | 51 | int a; |
|
48 | 52 | }vs10XXDev; |
|
49 | 53 | |
|
50 | 54 | |
|
51 | void vs10XXopen(vs10XXDev* codec,spi_t dev); | |
|
55 | void vs10XXopen(vs10XXDev* codec,spi_t dev, void (*setxCS)(char),void (*setxRST)(char),void (*setxDCS)(char),int (*getDREQ)()); | |
|
52 | 56 | void vs10XXsoftreset(vs10XXDev* dev); |
|
53 | 57 | int vs10XXcmdread(vs10XXDev* dev,char address); |
|
54 | 58 | void vs10XXcmdwrite(vs10XXDev* dev,char address,int value); |
@@ -57,9 +57,9 | |||
|
57 | 57 | struct sdcard_str |
|
58 | 58 | { |
|
59 | 59 | UHANDLE phy; |
|
60 |
|
|
|
61 |
|
|
|
62 |
|
|
|
60 | int (*rcvr_mmc) (UHANDLE phy,char *buff,uint32_t bc); | |
|
61 | int (*xmit_mmc) (UHANDLE phy,const char *buff,uint32_t bc); | |
|
62 | int (*setspeed) (UHANDLE phy,uint32_t speed); | |
|
63 | 63 | uint32_t (*getspeed) (UHANDLE phy); |
|
64 | 64 | DSTATUS Stat; |
|
65 | 65 | char CardType; |
@@ -117,6 +117,7 extern int spidisable(spi_t spidev); | |||
|
117 | 117 | extern int spitransactionfinished(spi_t spidev); |
|
118 | 118 | extern int spisetconfig(spi_t spidev,uint32_t config,uint32_t speed); |
|
119 | 119 | extern int spisetspeed(spi_t spidev, uint32_t speed); |
|
120 | extern uint32_t spigetspeed(spi_t spidev); | |
|
120 | 121 | extern int spisetbitorder(spi_t spidev,spibitorder_t order); |
|
121 | 122 | extern int spisetdatabits(spi_t spidev,spibits_t bitscnt); |
|
122 | 123 | extern int spisetclkinhlevel(spi_t spidev,spiclkinhlvl_t level); |
@@ -347,7 +347,10 void gpiosetval(gpio_t gpio,int val) | |||
|
347 | 347 | } |
|
348 | 348 | else |
|
349 | 349 | { |
|
350 | GPIOx->ODR = (val & 1)<<(gpio & 0xFF); | |
|
350 | if(val) | |
|
351 | GPIOx->BSRRL = 1<<(gpio & 0xFF); | |
|
352 | else | |
|
353 | GPIOx->BSRRH = 1<<(gpio & 0xFF); | |
|
351 | 354 | } |
|
352 | 355 | } |
|
353 | 356 |
@@ -239,6 +239,27 int spisetspeed(spi_t spidev, uint32_t s | |||
|
239 | 239 | return -1; |
|
240 | 240 | } |
|
241 | 241 | |
|
242 | uint32_t spigetspeed(spi_t spidev) | |
|
243 | { | |
|
244 | if((spidev<3)&&(spidev>=0)) | |
|
245 | { | |
|
246 | SPI_TypeDef* _dev_ = _spi_dev_table[(int)spidev]; | |
|
247 | uint32_t apbclock = 0x00; | |
|
248 | RCC_ClocksTypeDef RCC_ClocksStatus; | |
|
249 | RCC_GetClocksFreq(&RCC_ClocksStatus); | |
|
250 | if (_dev_ == SPI1) | |
|
251 | { | |
|
252 | apbclock = RCC_ClocksStatus.PCLK2_Frequency; | |
|
253 | } | |
|
254 | else | |
|
255 | { | |
|
256 | apbclock = RCC_ClocksStatus.PCLK1_Frequency; | |
|
257 | } | |
|
258 | int BR= (_dev_->CR1>>3)&0x7; | |
|
259 | return apbclock>>(BR+1); | |
|
260 | } | |
|
261 | return -1; | |
|
262 | } | |
|
242 | 263 | |
|
243 | 264 | int spisetdatabits(spi_t spidev,spibits_t bitscnt) |
|
244 | 265 | { |
@@ -7,7 +7,7 INCLUDEPATH += $$[QT_INSTALL_HEADERS] \ | |||
|
7 | 7 | $$[QT_INSTALL_HEADERS]/$$ARCH |
|
8 | 8 | |
|
9 | 9 | |
|
10 | LIBS += -L$$[QT_INSTALL_LIBS]/$$ARCH -lterminal -lCS43L22 -lina226 -lili9328 -lssd2119 -lSTMPE811 -lfonts -lsdcard -lfat32 -lmbr -luart -li2c -lgpio -lspi -lcpu -lcore -lm | |
|
10 | LIBS += -L$$[QT_INSTALL_LIBS]/$$ARCH -lterminal -lCS43L22 -lina226 -lili9328 -lssd2119 -lSTMPE811 -lvs10XX -lfonts -lsdcard -lfat32 -lmbr -luart -li2c -lgpio -lspi -lcpu -lcore -lm | |
|
11 | 11 | |
|
12 | 12 | |
|
13 | 13 |
General Comments 0
You need to be logged in to leave comments.
Login now