##// END OF EJS Templates
Removed error on fat32 library, seems now to be able navigate among sectors in...
jeandet -
r68:104125d87b89 dev_alexis
parent child
Show More
@@ -0,0 +1,19
1
2 #include <stdio.h>
3 #include <fat32.h>
4 #include <ucdirent.h>
5
6 void printRootClustersChain(FAT32fs* sdcard2FAT32part)
7 {
8 ucdirent root;
9 uint32_t sector_lba,res,tmp=sdcard2FAT32part->cluster_begin_lba;
10 sector_lba=tmp;
11 do
12 {
13 printf("Sector @0x%x\n",tmp);
14 //sector_lba=tmp+sdcard2FAT32part->BPB_SecPerClus-1;
15 sector_lba=tmp;
16 res=fat32nextsectorlba(sdcard2FAT32part,sector_lba,&tmp);
17 }while((res==DIRENT_noErr)&&(res!=DIRENT_LastSect));
18
19 }
@@ -1,543 +1,541
1 1 /*------------------------------------------------------------------------------
2 2 -- This file is a part of the libuc, microcontroler library
3 3 -- Copyright (C) 2011, Alexis Jeandet
4 4 --
5 5 -- This program is free software; you can redistribute it and/or modify
6 6 -- it under the terms of the GNU General Public License as published by
7 7 -- the Free Software Foundation; either version 3 of the License, or
8 8 -- (at your option) any later version.
9 9 --
10 10 -- This program is distributed in the hope that it will be useful,
11 11 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
12 12 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 13 -- GNU General Public License for more details.
14 14 --
15 15 -- You should have received a copy of the GNU General Public License
16 16 -- along with this program; if not, write to the Free Software
17 17 -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 18 -------------------------------------------------------------------------------
19 19 -- Author : Alexis Jeandet
20 20 -- Mail : alexis.jeandet@member.fsf.org
21 21 -------------------------------------------------------------------------------*/
22 22 #include "bsp.h"
23 23 #include <streamdevices.h>
24 24 #include <malloc.h>
25 25 #include <gpio.h>
26 26 #include <uart.h>
27 27 #include <stdio.h>
28 28 #include <stm32f4xx_gpio.h>
29 29 #include <stm32f4xx_fsmc.h>
30 30 #include <i2c.h>
31 31 #include <core.h>
32 32 #include <terminal.h>
33 33
34 34 uint32_t OSC0 =8000000;
35 35 uint32_t INTOSC =16000000;
36 36 uint32_t RTCOSC =32768;
37 37 uint32_t currentCpuFreq=0;
38 38 extern streamdevice* __opnfiles__[__MAX_OPENED_FILES__];
39 39
40 40 LCD_IF_t lcdIF0={
41 41 .init = &bsp_FSMC_init,
42 42 .writereg = &bsp_lcd0_write_reg,
43 43 .readreg = &bsp_lcd0_read_reg,
44 44 .writeGRAM = &bsp_lcd0_writeGRAM,
45 45 .readGRAM = &bsp_lcd0_readGRAM
46 46 };
47 47
48 48 LCD_t lcd0={
49 49 .interface = &lcdIF0,
50 50 .init = &ili9328init,
51 51 .paint = &ili9328paint,
52 52 .paintText = &ili9328paintText,
53 53 .paintFilRect = &ili9328paintFilRect,
54 54 .getPix = &ili9328getPix,
55 55 .refreshenable = &ili9328refreshenable,
56 56 .width= 240,
57 57 .height = 320
58 58 };
59 59
60 60 terminal_t terminal0;
61 61
62 62 volatile int8_t* lcd0_CMD=(volatile int8_t*)0x60000000;
63 volatile int16_t* lcd0_CMD16=(volatile int16_t*)0x60000000;
63 64 volatile int8_t* lcd0_DATA=(volatile int8_t*)0x61FFFFF0;
65 volatile int16_t* lcd0_DATA16=(volatile int16_t*)0x61FFFFF0;
64 66
65 67 float VREF0 =(float)3.3;
66 68 volatile vs10XXDev audioCodec0;
67 69
68 70 sdcardDev sdcard2;
69 71 blkdevice sdcard2blkdev;
70 72 dikpartition sdcard2Part1;
71 73 FAT32fs sdcard2FAT32part1;
72 74 dikpartition sdcard2Part2;
73 75 FAT32fs sdcard2FAT32part2;
74 76 dikpartition sdcard2Part3;
75 77 FAT32fs sdcard2FAT32part3;
76 78 dikpartition sdcard2Part4;
77 79 FAT32fs sdcard2FAT32part4;
78 80
79 81 int bsp_init()
80 82 {
81 83 int i=0;
82 84 for(i=0;i<__MAX_OPENED_FILES__;i++)
83 85 {
84 86 __opnfiles__[i] = NULL;
85 87 }
86 88 bsp_GPIO_init();
87 89 bsp_uart_init();
88 90 bsp_iic_init();
89 91 bsp_FSMC_init();
90 92 bsp_GTerm_init();
91 93 bsp_spi_init();
92 94 bsp_SD_init();
93 95 bsp_Audio_init();
94 96 printf("\r=====================\n\r");
95 97 printf( "=====================\n\r");
96 98 printf(BSP);
97 99 printf(" initialised\n\r");
98 100 printf( "=====================\n\r");
99 101 #if __BYTE_ORDER__==__ORDER_BIG_ENDIAN__
100 102 printf( "BIG ENDIAN MACHINE\n\r");
101 103 #else
102 104 printf( "LITLE ENDIAN MACHINE\n\r");
103 105 #endif
104 106 return 1;
105 107 }
106 108
107 109 void bsp_GPIO_init()
108 110 {
109 111 gpio_t GPIO_Out_init_List[]={LED1,LED2,LCD_RESET,LCD_BACKL,VS1053xCS,VS1053xDCS,VS1053xRESET,SDCARD2CS};
110 112 for(int i=0;i<8;i++)
111 113 {
112 114 gpio_t GPIO_init = gpioopen(GPIO_Out_init_List[i]);
113 115 GPIO_init |= gpiohighspeed | gpiooutdir | gpiopushpulltype;
114 116 gpiosetconfig(&GPIO_init);
115 117 }
116 118 gpio_t GPIO_In_init_List[]={VS1053DREQ,SDCARD2CD,BP3};
117 119 for(int i=0;i<3;i++)
118 120 {
119 121 gpio_t GPIO_init = gpioopen(GPIO_In_init_List[i]);
120 122 GPIO_init |= gpiohighspeed | gpioindir;
121 123 gpiosetconfig(&GPIO_init);
122 124 }
123 125 gpioclr(VS1053xRESET);
124 126 gpioset(VS1053xCS);
125 127 gpioset(VS1053xDCS);
126 128 gpioset(SDCARD2CS);
127 129 gpioclr(LCD_RESET);
128 130 gpioclr(LCD_BACKL);
129 131 }
130 132
131 133 void bsp_uart_init()
132 134 {
133 135 // if(__opnfiles__[1]==NULL)
134 136 // {
135 137 // //uart_t* uart1 = (uart_t*)malloc(sizeof(uart_t));
136 138 // streamdevice* fd1 = (streamdevice*)malloc(sizeof(streamdevice));
137 139 // uart_t uart = uartopenandconfig(uart3,uartparitynone | uart8bits | uartonestop,115200,PD8,PD9,-1,-1);
138 140 // uartmkstreamdev(uart,fd1);
139 141 // __opnfiles__[1] = fd1;
140 142 // }
141 143 // else
142 144 // {
143 145 // uartopenandconfig(uart3,uartparitynone | uart8bits | uartonestop,115200,PD8,PD9,-1,-1);
144 146 // }
145 147 }
146 148
147 149 /*
148 150 D0 PD14 D1 PD15 D2 PD0 D3 PD1 D4 PE7
149 151 D5 PE8 D6 PE9 D7 PE10
150 152 A20 PE4 = RS FSMC_NE1 PD7 CS FSMC_NWE PD5 W/S
151 153 FSMC_NOE PD4 RD
152 154 */
153 155
154 156 int bsp_FSMC_init()
155 157 {
156 158 #define GPIOGETPORT(gpio) ((GPIO_TypeDef*)(((((uint32_t)gpio) & (uint32_t)0x0000FF00)*(uint32_t)4) + (uint32_t)GPIOA))
157 159 #define GPIOPORTNUM(gpio) (((uint32_t)(gpio) & (uint32_t)0x0000FF00)>>(uint32_t)8)
158 160
159 gpio_t LCD_DBxList[]={PD14,PD15,PD0,PD1,PE7,PE8,PE9,PE10\
160 ,PD4,PD5,PD7,PE4};
161 gpio_t LCD_DBxList[]={PD14,PD15,PD0,PD1,PE7,PE8,PE9,PE10\
162 ,PD4,PD5,PD7,PE4};
161 163 for(int i=0;i<12;i++)
162 164 {
163 165 gpio_t LCD_DBx = gpioopen(LCD_DBxList[i]);
164 166 LCD_DBx |= gpiohighspeed | gpioaf | gpiopushpulltype | gpionopulltype;
165 167 gpiosetconfig(&LCD_DBx);
166 168 GPIO_PinAFConfig(GPIOGETPORT(LCD_DBx), (uint8_t)(LCD_DBx & 0xF), GPIO_AF_FSMC);
167 169 }
168 170
169 171 FSMC_NORSRAMInitTypeDef FSMC_NORSRAMInitStructure;
170 FSMC_NORSRAMTimingInitTypeDef p,readtim;
172 FSMC_NORSRAMTimingInitTypeDef p;
171 173
172 174 /* Enable FSMC clock */
173 175 RCC_AHB3PeriphClockCmd(RCC_AHB3Periph_FSMC, ENABLE);
174 176
175 177 /*-- FSMC Configuration ------------------------------------------------------*/
176 178 /*----------------------- SRAM Bank 3 ----------------------------------------*/
177 179 /* FSMC_Bank1_NORSRAM4 configuration */
178 180 p.FSMC_AddressSetupTime = 3;
179 181 p.FSMC_AddressHoldTime = 3;
180 182 //ili9328 -> data setup time > 10ns
181 183 p.FSMC_DataSetupTime = 1;
182 184 if(getCpuFreq()>100*1000*1000)
183 185 p.FSMC_DataSetupTime = 2;// 11;
184 186 p.FSMC_BusTurnAroundDuration = 0;
185 187 p.FSMC_CLKDivision = 0;
186 188 p.FSMC_DataLatency = 0;
187 189 //ili9328 -> data hold time > 15ns
188 190 if(getCpuFreq()>66*1000*1000)
189 191 p.FSMC_DataLatency = 0;
190 192 p.FSMC_AccessMode = FSMC_AccessMode_A;
191 193
192 194
193 195 FSMC_NORSRAMInitStructure.FSMC_Bank = FSMC_Bank1_NORSRAM1;
194 196 FSMC_NORSRAMInitStructure.FSMC_DataAddressMux = FSMC_DataAddressMux_Disable;
195 197 FSMC_NORSRAMInitStructure.FSMC_MemoryType = FSMC_MemoryType_SRAM;
196 198 FSMC_NORSRAMInitStructure.FSMC_MemoryDataWidth = FSMC_MemoryDataWidth_8b;
197 199 FSMC_NORSRAMInitStructure.FSMC_BurstAccessMode = FSMC_BurstAccessMode_Disable;
198 200 FSMC_NORSRAMInitStructure.FSMC_AsynchronousWait = FSMC_AsynchronousWait_Disable;
199 201 FSMC_NORSRAMInitStructure.FSMC_WaitSignalPolarity = FSMC_WaitSignalPolarity_Low;
200 202 FSMC_NORSRAMInitStructure.FSMC_WrapMode = FSMC_WrapMode_Disable;
201 203 FSMC_NORSRAMInitStructure.FSMC_WaitSignalActive = FSMC_WaitSignalActive_BeforeWaitState;
202 204 FSMC_NORSRAMInitStructure.FSMC_WriteOperation = FSMC_WriteOperation_Enable;
203 205 FSMC_NORSRAMInitStructure.FSMC_WaitSignal = FSMC_WaitSignal_Disable;
204 206 FSMC_NORSRAMInitStructure.FSMC_ExtendedMode = FSMC_ExtendedMode_Disable;
205 207 FSMC_NORSRAMInitStructure.FSMC_WriteBurst = FSMC_WriteBurst_Disable;
206 208 FSMC_NORSRAMInitStructure.FSMC_ReadWriteTimingStruct = &p;
207 209 FSMC_NORSRAMInitStructure.FSMC_WriteTimingStruct = &p;
208 210
209 211 FSMC_NORSRAMInit(&FSMC_NORSRAMInitStructure);
210 212
211 213 FSMC_NORSRAMCmd(FSMC_Bank1_NORSRAM1, ENABLE);
212 214 gpioset(LCD_RESET);
213 215 gpioclr(LCD_RESET);
214 216 delay_100us(500);
215 217 gpioset(LCD_RESET);
216 218 delay_100us(500);
217 219 lcd0.init(&lcd0);
218 220 gpioset(LCD_BACKL);
219 221 return 1;
220 222 }
221 223
222 224 void bsp_spi_init()
223 225 {
224 226 gpio_t VSSPI_DBxList[]={VS1053SCK,VS1053MOSI,VS1053MISO};
225 227 for(int i=0;i<3;i++)
226 228 {
227 229 gpio_t SPI_DBx = gpioopen(VSSPI_DBxList[i]);
228 230 SPI_DBx |= gpiohighspeed | gpioaf | gpiopushpulltype | gpionopulltype;
229 231 gpiosetconfig(&SPI_DBx);
230 232 GPIO_PinAFConfig(GPIOGETPORT(SPI_DBx), (uint8_t)(SPI_DBx & 0xF), GPIO_AF_SPI1);
231 233 }
232 234 spiopenandconfig(VS1053SPI,spi8bits|spimaster|spimsbfirst,2*1000*1000,VS1053MOSI,VS1053MISO,VS1053SCK,-1);
233 235
234 236 gpio_t SDSPI_DBxList[]={SDCARD2SCK,SDCARD2MOSI,SDCARD2MISO};
235 237 for(int i=0;i<3;i++)
236 238 {
237 239 gpio_t SPI_DBx = gpioopen(SDSPI_DBxList[i]);
238 240 SPI_DBx |= gpiohighspeed | gpioaf | gpiopushpulltype | gpionopulltype;
239 241 gpiosetconfig(&SPI_DBx);
240 242 GPIO_PinAFConfig(GPIOGETPORT(SPI_DBx), (uint8_t)(SPI_DBx & 0xF), GPIO_AF_SPI3);
241 243 }
242 244 spiopenandconfig(SDCARD2SPI,spi8bits|spimaster|spimsbfirst,400*1000,SDCARD2MOSI,SDCARD2MISO,SDCARD2SCK,-1);
243 245
244 246 }
245 247
246 248
247 249 void bsp_iic_init()
248 250 {
249 251 // i2copenandconfig(i2c2,0,10000,PF0,PF1);
250 252 }
251 253
252 254
253 255 void bsp_Audio_init()
254 256 {
255 257 vs10XXopen(&audioCodec0,VS1053SPI,vs1052setXCS,vs1052setRST,vs1052setXDCS,vs10XXDREQ);
256 258 if(audioCodec0.VERSION!=UNKNOWN)
257 259 {
258 260 printf("detected Audio codec ");
259 261 switch (audioCodec0.VERSION) {
260 262 case VS1001:
261 263 printf("VS1001\n");
262 264 break;
263 265 case VS1011:
264 266 printf("VS1011\n");
265 267 break;
266 268 case VS1002:
267 269 printf("VS1002\n");
268 270 break;
269 271 case VS1003:
270 272 printf("VS1003\n");
271 273 break;
272 274 case VS1053:
273 275 printf("VS1053\n");
274 276 break;
275 277 case VS1033:
276 278 printf("VS1033\n");
277 279 break;
278 280 case VS1103:
279 281 printf("VS1103\n");
280 282 break;
281 283 default:
282 284 printf("Unknown device\n");
283 285 break;
284 286 }
285 287 }
286 288 }
287 289
288 290 void bsp_SD_init()
289 291 {
290 292 if(bspsdcardpresent())
291 293 {
292 294 sdcardspimake(&sdcard2,(UHANDLE)SDCARD2SPI,spigetnc,spiputnc,spisetspeed,spigetspeed);
293 295 sdcardspimakeblkdev(&sdcard2blkdev,&sdcard2,bspsdcardselect,bsppowersdcard,bspsdcardpresent,bspsdcardwriteprotected);
294 296 if(sdcard2blkdev.initialize(&sdcard2blkdev)!=STA_NOINIT)
295 297 {
296 298 if(mbropen(&sdcard2blkdev,&sdcard2Part1,1)==MBRnoErr)
297 299 {
298 300 if(FATnoErr!=fat32open(&sdcard2FAT32part1,&sdcard2Part1))
299 301 printf("Can't open fat32 partition 1\n");
300 302 }
301 303 else
302 304 {
303 305 printf("Can't open or read MBR\n");
304 306 }
305 delay_100us(1000);
307 delay_100us(10000);
306 308 if(mbropen(&sdcard2blkdev,&sdcard2Part2,2)==MBRnoErr)
307 309 {
308 310 if(FATnoErr!=fat32open(&sdcard2FAT32part2,&sdcard2Part2))
309 311 printf("Can't open fat32 partition 2\n");
310 312 }
311 313 else
312 314 {
313 315 printf("Can't open or read MBR\n");
314 316 }
315 delay_100us(1000);
317 delay_100us(10000);
316 318 if(mbropen(&sdcard2blkdev,&sdcard2Part3,3)==MBRnoErr)
317 319 {
318 320 if(FATnoErr!=fat32open(&sdcard2FAT32part3,&sdcard2Part3))
319 321 printf("Can't open fat32 partition 3\n");
320 322 }
321 323 else
322 324 {
323 325 printf("Can't open or read MBR\n");
324 326 }
325 delay_100us(1000);
327 delay_100us(10000);
326 328 if(mbropen(&sdcard2blkdev,&sdcard2Part4,4)==MBRnoErr)
327 329 {
328 330 if(FATnoErr!=fat32open(&sdcard2FAT32part4,&sdcard2Part4))
329 331 printf("Can't open fat32 partition 4\n");
330 332 }
331 333 else
332 334 {
333 335 printf("Can't open or read MBR\n");
334 336 }
335 337 }
336 338 else
337 339 {
338 340 printf("Can't initialize SDCARD\n");
339 341 }
340 342 }
341 delay_100us(2000);
343 delay_100us(20000);
342 344 }
343 345
344 346 void vs1052setXCS(char val)
345 347 {
346 348 gpiosetval(VS1053xCS,(int)val);
347 349 }
348 350
349 351 void vs1052setXDCS(char val)
350 352 {
351 353 //gpiosetval(LED1,(int)val);
352 354 gpiosetval(VS1053xDCS,(int)val);
353 355 }
354 356
355 357 void vs1052setRST(char val)
356 358 {
357 359 if(val)
358 360 gpioset(VS1053xRESET);
359 361 else
360 362 gpioclr(VS1053xRESET);
361 363 }
362 364
363 365 int vs10XXDREQ()
364 366 {
365 367 return gpiogetval(VS1053DREQ);
366 368 }
367 369
368 370
369 371 void bsppowersdcard(char onoff) //always ON
370 372 {
371 373
372 374 }
373 375
374 376 char bspsdcardpresent()
375 377 {
376 378 return gpiogetval(SDCARD2CD);
377 379 }
378 380
379 381 char bspsdcardwriteprotected()
380 382 {
381 383 return 0;
382 384 }
383 385
384 386 void bspsdcardselect(char YESNO)
385 387 {
386 388 // gpiosetval(LED1,(int)YESNO);
387 389 if(YESNO)
388 390 gpioclr(SDCARD2CS);
389 391 else
390 392 gpioset(SDCARD2CS);
391 393 }
392 394
393 395
394 396 void bsp_lcd0_write_reg(uint32_t reg,uint32_t data)
395 397 {
396 398 uint8_t* pt8 = (uint8_t*)(void*)(&reg);
397 399 #if __BYTE_ORDER__==__ORDER_BIG_ENDIAN__
398 400 *lcd0_CMD=pt8[3];
399 401 *lcd0_CMD=pt8[2];
400 402 pt8 = (uint8_t*)(void*)&data;
401 403 *lcd0_DATA=pt8[3];
402 404 *lcd0_DATA=pt8[2];
403 405 #else
404
405 406 *lcd0_CMD=pt8[1];
406 407 *lcd0_CMD=pt8[0];
407 408 pt8 = (uint8_t*)(void*)&data;
408 409 *lcd0_DATA=pt8[1];
409 410 *lcd0_DATA=pt8[0];
410 411 #endif
411 412
412 413 }
413 414
414 415 uint32_t bsp_lcd0_read_reg(uint32_t reg)
415 416 {
416 417 uint8_t* pt8 = (uint8_t*)(void*)(&reg);
417 418 uint32_t DATA=0;
418 419
419 420 #if __BYTE_ORDER__==__ORDER_BIG_ENDIAN__
420 421 *lcd0_CMD=pt8[3];
421 422 *lcd0_CMD=pt8[2];
422 423 pt8 = (uint8_t*)(void*)&DATA;
423 424 pt8[3]=*lcd0_DATA;
424 425 pt8[2]=*lcd0_DATA;
425 426 #else
426
427 427 *lcd0_CMD=pt8[1];
428 428 *lcd0_CMD=pt8[0];
429 429 pt8 = (uint8_t*)(void*)&DATA;
430 430 pt8[1]=*lcd0_DATA;
431 431 pt8[0]=*lcd0_DATA;
432 432 #endif
433 433
434 434 return DATA;
435 435 }
436 436
437 437 void bsp_lcd0_writeGRAM(void* buffer,uint32_t count)
438 438 {
439 439 uint32_t reg =ILI9328_REGISTER_WRITEDATATOGRAM;
440 440 uint8_t* pt8 = (uint8_t*)(void*)(&reg);
441 441 #if __BYTE_ORDER__==__ORDER_BIG_ENDIAN__
442 442 *lcd0_CMD=pt8[3];
443 443 *lcd0_CMD=pt8[2];
444 444 pt8 = (uint8_t*)(void*)buffer;
445 445 for(int i=0;i<(int)count;i++)
446 446 {
447 447 *lcd0_DATA=pt8[(2*i) +1];
448 448 *lcd0_DATA=pt8[2*i];
449 449 }
450 450 #else
451
452 451 *lcd0_CMD=pt8[1];
453 452 *lcd0_CMD=pt8[0];
454 453 pt8 = (uint8_t*)(void*)buffer;
455 454 for(int i=0;i<(int)count;i++)
456 455 {
457 456
458 457 *lcd0_DATA=pt8[(2*i) +1];
459 458 *lcd0_DATA=pt8[2*i];
460 459 }
461 460 #endif
462 461 }
463 462
464 463 void bsp_lcd0_readGRAM(void* buffer,uint32_t count)
465 464 {
466 //uint32_t reg =ILI9328_REGISTER_WRITEDATATOGRAM;
467 volatile uint8_t* pt8 ;// = (uint8_t*)(void*)&reg;
468 /* #if __BYTE_ORDER__==__ORDER_BIG_ENDIAN__
465 //uint32_t reg =ILI9328_REGISTER_WRITEDATATOGRAM;
466 volatile uint8_t* pt8;// = (uint8_t*)(void*)&reg;
467 /* #if __BYTE_ORDER__==__ORDER_BIG_ENDIAN__
469 468 *lcd0_CMD=pt8[3];
470 469 *lcd0_CMD=pt8[2];
471 470 pt8 = (uint8_t*)(void*)buffer;
472 471 for(int i=0;i<(int)count;i++)
473 472 {
474 473 pt8[(2*i) +1]=*lcd0_DATA;
475 474 pt8[2*i]=*lcd0_DATA;
476 475 }
477 476 #else
478 477 *lcd0_CMD=(uint8_t)0;
479 478 *lcd0_CMD=(uint8_t)0;
480 479 *lcd0_CMD=(uint8_t)0;
481 480 *lcd0_CMD=(uint8_t)0;
482 481 *lcd0_CMD=pt8[1];
483 482 *lcd0_CMD=pt8[0];
484 483 pt8 = (uint8_t*)buffer;*/
485 484 /*
486 485 * x dummy reads Cf ili9328 datasheet p79!
487 486 */
488 /* pt8[0]=*lcd0_DATA;
487 /* pt8[0]=*lcd0_DATA;
489 488 pt8[1]=*lcd0_DATA;
490 489
491 490 for(int i=0;i<(int)count;i++)
492 491 {
493 492 pt8[(2*i) +1]=*lcd0_DATA;
494 493 pt8[2*i]=*lcd0_DATA;
495 494 pt8[(2*i) +1]=*lcd0_DATA;
496 495 pt8[2*i]=*lcd0_DATA;
497 496 }
498 497 #endif*/
499 498
500 *lcd0_CMD=(uint8_t)0;
501 *lcd0_CMD=(uint8_t)0x22;
499 *lcd0_CMD=(int8_t)0;
500 // *lcd0_CMD=(int8_t)0x22;
501 *lcd0_CMD=(int8_t)0x00;
502 502 pt8 = (uint8_t*)buffer;
503 503 pt8[1]=*lcd0_DATA;
504 504 pt8[0]=*lcd0_DATA;
505 505 for(int i=0;i<(int)count;i++)
506 506 {
507 //pt8[(2*i) +1]=0;
508 //pt8[2*i]=0;
509 507 pt8[(2*i)+1]= *lcd0_DATA;
510 508 pt8[2*i]= *lcd0_DATA;
511 509 }
512 510 }
513 511
514 512 void bsp_GTerm_init()
515 513 {
516 514 if(__opnfiles__[1]==NULL)
517 515 {
518 516 streamdevice* fd1 = (streamdevice*)malloc(sizeof(streamdevice));
519 terminal_init(&terminal0 ,&lcd0,&ComicSansMS_18,fd1);
517 terminal_init(&terminal0 ,&lcd0,&ComicSansMS_8,fd1);
520 518 __opnfiles__[1] = fd1;
521 519 }
522 520 else
523 521 {
524 522
525 523 }
526 524 }
527 525
528 526
529 527
530 528
531 529
532 530
533 531
534 532
535 533
536 534
537 535
538 536
539 537
540 538
541 539
542 540
543 541
@@ -1,133 +1,134
1 1 /*------------------------------------------------------------------------------
2 2 -- This file is a part of the libuc, microcontroler library
3 3 -- Copyright (C) 2011, Alexis Jeandet
4 4 --
5 5 -- This program is free software; you can redistribute it and/or modify
6 6 -- it under the terms of the GNU General Public License as published by
7 7 -- the Free Software Foundation; either version 3 of the License, or
8 8 -- (at your option) any later version.
9 9 --
10 10 -- This program is distributed in the hope that it will be useful,
11 11 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
12 12 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 13 -- GNU General Public License for more details.
14 14 --
15 15 -- You should have received a copy of the GNU General Public License
16 16 -- along with this program; if not, write to the Free Software
17 17 -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 18 -------------------------------------------------------------------------------
19 19 -- Author : Alexis Jeandet
20 20 -- Mail : alexis.jeandet@member.fsf.org
21 21 -------------------------------------------------------------------------------*/
22 22 #ifndef BSP_H
23 23 #define BSP_H
24 24 #include <stm32f4xx.h>
25 25 #include <stm32f4xx_gpio.h>
26 26 #include <stm32f4xx_rcc.h>
27 27 #include <gpio.h>
28 28 #include <spi.h>
29 29 #include <ili9328.h>
30 30 #include <genericLCD_Controler.h>
31 31 #include <sdcard-spi.h>
32 32 #include <sdcard.h>
33 33 #include <mbr.h>
34 34 #include <VS10XX.h>
35 35 #include <fat32.h>
36 36
37 37 #define __MAX_OPENED_FILES__ 4
38 38 #define __FS_ROOT_SIZE__ 4
39 39
40 40
41 41 #define LED1 PC15
42 42 #define LED2 PC14
43 43
44 44 #define BP3 PA0
45 45
46 46 #define LCD_RESET PD10
47 47 #define LCD_BACKL PE11
48 #define LCD_RS PE4
48 49
49 50 #define VS1053SPI spi1
50 51 #define VS1053xCS PA3
51 52 #define VS1053xRESET PA2
52 53 #define VS1053xDCS PA4
53 54 #define VS1053DREQ PA1
54 55 #define VS1053MISO PA6
55 56 #define VS1053MOSI PA7
56 57 #define VS1053SCK PA5
57 58
58 59
59 60
60 61 #define SDCARD2SPI spi3
61 62 #define SDCARD2CS PB8
62 63 #define SDCARD2CD PB9
63 64 #define SDCARD2MISO PB4
64 65 #define SDCARD2MOSI PB5
65 66 #define SDCARD2SCK PB3
66 67
67 68 extern float VREF0;
68 69
69 70 extern uint32_t currentCpuFreq;
70 71 extern LCD_t lcd0;
71 72
72 73 extern volatile vs10XXDev audioCodec0;
73 74
74 75 extern sdcardDev sdcard2;
75 76 extern blkdevice sdcard2blkdev;
76 77 extern dikpartition sdcard2Part1;
77 78 extern FAT32fs sdcard2FAT32part1;
78 79 extern dikpartition sdcard2Part2;
79 80 extern FAT32fs sdcard2FAT32part2;
80 81 extern dikpartition sdcard2Part3;
81 82 extern FAT32fs sdcard2FAT32part3;
82 83 extern dikpartition sdcard2Part4;
83 84 extern FAT32fs sdcard2FAT32part4;
84 85
85 86 extern int bsp_init();
86 87
87 88 extern void bsp_GPIO_init();
88 89 extern void bsp_uart_init();
89 90 extern void bsp_iic_init();
90 91 extern void bsp_spi_init();
91 92 extern void bsp_SD_init();
92 93 extern void bsp_Audio_init();
93 94 extern void bsp_GTerm_init();
94 95 extern int bsp_FSMC_init();
95 96
96 97 /* VS1053 */
97 98 extern void vs1052setXCS(char val);
98 99 extern void vs1052setXDCS(char val);
99 100 extern void vs1052setRST(char val);
100 101 extern int vs10XXDREQ();
101 102
102 103 /* SD CARD */
103 104 void bsppowersdcard(char onoff);
104 105 char bspsdcardpresent();
105 106 void bspsdcardselect(char YESNO);
106 107 char bspsdcardwriteprotected();
107 108
108 109
109 110 void bsp_lcd0_write_reg(uint32_t reg,uint32_t data);
110 111 uint32_t bsp_lcd0_read_reg(uint32_t reg);
111 112 void bsp_lcd0_writeGRAM(void *buffer, uint32_t count);
112 113 void bsp_lcd0_readGRAM(void *buffer, uint32_t count);
113 114
114 115 #endif
115 116
116 117
117 118
118 119
119 120
120 121
121 122
122 123
123 124
124 125
125 126
126 127
127 128
128 129
129 130
130 131
131 132
132 133
133 134
@@ -1,284 +1,332
1 1 /*------------------------------------------------------------------------------
2 2 -- This file is a part of the libuc, microcontroler library
3 3 -- Copyright (C) 2011, Alexis Jeandet
4 4 --
5 5 -- This program is free software; you can redistribute it and/or modify
6 6 -- it under the terms of the GNU General Public License as published by
7 7 -- the Free Software Foundation; either version 3 of the License, or
8 8 -- (at your option) any later version.
9 9 --
10 10 -- This program is distributed in the hope that it will be useful,
11 11 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
12 12 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 13 -- GNU General Public License for more details.
14 14 --
15 15 -- You should have received a copy of the GNU General Public License
16 16 -- along with this program; if not, write to the Free Software
17 17 -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 18 -------------------------------------------------------------------------------
19 19 -- Author : Alexis Jeandet
20 20 -- Mail : alexis.jeandet@member.fsf.org
21 21 -------------------------------------------------------------------------------*/
22 22 #include "bsp.h"
23 23 #include <streamdevices.h>
24 24 #include <malloc.h>
25 25 #include <stdio.h>
26 26
27 27
28 28 uint32_t OSC0 =8000000;
29 29 uint32_t INTOSC =16000000;
30 30 uint32_t RTCOSC =32768;
31 31 uint32_t currentCpuFreq=0;
32 32 extern streamdevice* __opnfiles__[__MAX_OPENED_FILES__];
33 33
34 34
35 35 LCD_IF_t lcdIF0={
36 36 .init = &SDLCD_init,
37 37 .writereg = &SDLCD_writereg,
38 38 .readreg = &SDLCD_readreg,
39 39 .writeGRAM = &SDLCD_writeGRAM_16bpp,
40 40 .readGRAM = &SDLCD_readGRAM_16bpp
41 41 };
42 42
43 43 LCD_t lcd0={
44 44 .interface = &lcdIF0,
45 45 .init = &ili9328init,
46 46 .paint = &ili9328paint,
47 47 .paintText = &ili9328paintText,
48 48 .paintFilRect = &ili9328paintFilRect,
49 49 .getPix = &ili9328getPix,
50 50 .refreshenable = &ili9328refreshenable,
51 51 .width= 240,
52 52 .height = 320
53 53 };
54 54
55 55 terminal_t terminal0;
56 56
57 57 volatile int8_t* lcd0_CMD=(volatile int8_t*) 0x60000000;
58 58 volatile int8_t* lcd0_DATA=(volatile int8_t*)(0x61FFFFF0);
59 59
60 60 float VREF0 =(float)3.3;
61 61 volatile vs10XXDev audioCodec0;
62 62
63 63 sdcardDev sdcard2;
64 64 blkdevice sdcard2blkdev;
65 65 dikpartition sdcard2Part1;
66 66 FAT32fs sdcard2FAT32part1;
67 67 dikpartition sdcard2Part2;
68 68 FAT32fs sdcard2FAT32part2;
69 69 dikpartition sdcard2Part3;
70 70 FAT32fs sdcard2FAT32part3;
71 71 dikpartition sdcard2Part4;
72 72 FAT32fs sdcard2FAT32part4;
73 73
74 74 int bsp_init()
75 75 {
76 76 int i=0;
77 77 for(i=0;i<__MAX_OPENED_FILES__;i++)
78 78 {
79 79 __opnfiles__[i] = NULL;
80 80 }
81 81 bsp_GPIO_init();
82 82 bsp_uart_init();
83 83 bsp_iic_init();
84 84 bsp_FSMC_init();
85 85 bsp_GTerm_init();
86 86 bsp_spi_init();
87 87 bsp_SD_init();
88 88 bsp_Audio_init();
89 89 printf("\r=====================\n\r");
90 90 printf( "=====================\n\r");
91 91 printf(BSP);
92 92 printf(" initialised\n\r");
93 93 printf( "=====================\n\r");
94 94 return 1;
95 95 }
96 96
97 97 void bsp_GPIO_init()
98 98 {
99 99
100 100 }
101 101
102 102 void bsp_uart_init()
103 103 {
104 104
105 105 }
106 106
107 107 /*
108 108 D0 PD14 D1 PD15 D2 PD0 D3 PD1 D4 PE7
109 109 D5 PE8 D6 PE9 D7 PE10
110 110 A20 PE4 = RS FSMC_NE1 PD7 CS FSMC_NWE PD5 W/S
111 111 FSMC_NOE PD4 RD
112 112 */
113 113
114 114 int bsp_FSMC_init()
115 115 {
116 116
117 117 return 1;
118 118 }
119 119
120 120 void bsp_spi_init()
121 121 {
122 122
123 123 }
124 124
125 125
126 126 void bsp_iic_init()
127 127 {
128 128
129 129 }
130 130
131 131
132 132 void bsp_Audio_init()
133 133 {
134 134
135 135 }
136 136
137 137 void bsp_SD_init()
138 138 {
139
139 sdcardspimakeblkdev(&sdcard2blkdev,&sdcard2, bspsdcardselect,bsppowersdcard,bspsdcardpresent,bspsdcardwriteprotected);
140 if(sdcard2blkdev.initialize(&sdcard2blkdev)!=STA_NOINIT)
141 {
142 if(mbropen(&sdcard2blkdev,&sdcard2Part1,1)==MBRnoErr)
143 {
144 if(FATnoErr!=fat32open(&sdcard2FAT32part1,&sdcard2Part1))
145 printf("Can't open fat32 partition 1\n");
146 }
147 else
148 {
149 printf("Can't open or read MBR\n");
150 }
151 delay_100us(1000);
152 if(mbropen(&sdcard2blkdev,&sdcard2Part2,2)==MBRnoErr)
153 {
154 if(FATnoErr!=fat32open(&sdcard2FAT32part2,&sdcard2Part2))
155 printf("Can't open fat32 partition 2\n");
156 }
157 else
158 {
159 printf("Can't open or read MBR\n");
160 }
161 delay_100us(1000);
162 if(mbropen(&sdcard2blkdev,&sdcard2Part3,3)==MBRnoErr)
163 {
164 if(FATnoErr!=fat32open(&sdcard2FAT32part3,&sdcard2Part3))
165 printf("Can't open fat32 partition 3\n");
166 }
167 else
168 {
169 printf("Can't open or read MBR\n");
170 }
171 delay_100us(1000);
172 if(mbropen(&sdcard2blkdev,&sdcard2Part4,4)==MBRnoErr)
173 {
174 if(FATnoErr!=fat32open(&sdcard2FAT32part4,&sdcard2Part4))
175 printf("Can't open fat32 partition 4\n");
176 }
177 else
178 {
179 printf("Can't open or read MBR\n");
180 }
181 }
182 else
183 {
184 printf("Can't initialize SDCARD\n");
185 }
186
187 delay_100us(2000);
140 188 }
141 189
142 190 void vs1052setXCS(char val)
143 191 {
144 192 }
145 193
146 194 void vs1052setXDCS(char val)
147 195 {
148 196 }
149 197
150 198 void vs1052setRST(char val)
151 199 {
152 200 }
153 201
154 202 int vs10XXDREQ()
155 203 {
156 204 return 1;
157 205 }
158 206
159 207
160 208 void bsppowersdcard(char onoff) //always ON
161 209 {
162 210
163 211 }
164 212
165 213 char bspsdcardpresent()
166 214 {
167 215 return 1;
168 216 }
169 217
170 218 char bspsdcardwriteprotected()
171 219 {
172 220 return 0;
173 221 }
174 222
175 223 void bspsdcardselect(char YESNO)
176 224 {
177 225
178 226 }
179 227
180 228
181 229 void bsp_lcd0_write_reg(uint32_t reg,uint32_t data)
182 230 {
183 231
184 232 }
185 233
186 234 uint32_t bsp_lcd0_read_reg(uint32_t reg)
187 235 {
188 236 return 0;
189 237 }
190 238
191 239 void bsp_lcd0_writeGRAM(void* buffer,uint32_t count)
192 240 {
193 241
194 242 }
195 243
196 244 void bsp_lcd0_readGRAM(void* buffer,uint32_t count)
197 245 {
198 246
199 247 }
200 248
201 249 void bsp_GTerm_init()
202 250 {
203 251 SDLCD_mkscreen(240,320,16,LCDILI9328);
204 252
205 253 if(__opnfiles__[1]==NULL)
206 254 {
207 255 streamdevice* fd1 = (streamdevice*)malloc(sizeof(streamdevice));
208 256 terminal_init(&terminal0 ,&lcd0,&ComicSansMS_18,fd1);
209 257 lcd0.paintFilRect(&lcd0,0,0,240,320,0,0,0x0f0f);
210 258 __opnfiles__[1] = fd1;
211 259 }
212 260 else
213 261 {
214 262
215 263 }
216 264 }
217 265
218 266
219 267
220 268
221 269
222 270
223 271
224 272 void putpixel(SDL_Surface *surface, int x, int y, Uint32 pixel)
225 273 {
226 274 int bpp = surface->format->BytesPerPixel;
227 275 /* Here p is the address to the pixel we want to set */
228 276 Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp;
229 277 switch(bpp) {
230 278 case 1:
231 279 *p = pixel;
232 280 break;
233 281 case 2:
234 282 *(Uint16 *)p = pixel;
235 283 break;
236 284 case 3:
237 285 if(SDL_BYTEORDER == SDL_BIG_ENDIAN) {
238 286 p[0] = (pixel >> 16) & 0xff;
239 287 p[1] = (pixel >> 8) & 0xff;
240 288 p[2] = pixel & 0xff;
241 289 } else {
242 290 p[0] = pixel & 0xff;
243 291 p[1] = (pixel >> 8) & 0xff;
244 292 p[2] = (pixel >> 16) & 0xff;
245 293 }
246 294 break;
247 295 case 4:
248 296 *(Uint32 *)p = pixel;
249 297 break;
250 298 }
251 299 }
252 300
253 301 Uint32 getpixel(SDL_Surface *surface, int x, int y)
254 302 {
255 303 int bpp = surface->format->BytesPerPixel;
256 304 /* Here p is the address to the pixel we want to retrieve */
257 305 Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp;
258 306 switch(bpp) {
259 307 case 1:
260 308 return *p;
261 309 case 2:
262 310 return *(Uint16 *)p;
263 311 case 3:
264 312 if(SDL_BYTEORDER == SDL_BIG_ENDIAN)
265 313 return p[0] << 16 | p[1] << 8 | p[2];
266 314 else
267 315 return p[0] | p[1] << 8 | p[2] << 16;
268 316 case 4:
269 317 return *(Uint32 *)p;
270 318 default:
271 319 return 0;
272 320 }
273 321 /* shouldn’t happen, but avoids warnings */
274 322 }
275 323
276 324
277 325
278 326
279 327
280 328
281 329
282 330
283 331
284 332
@@ -1,229 +1,229
1 1 #include <stdio.h>
2 2 #include <fat32.h>
3 3 #include <gpio.h>
4 4 #include <uart.h>
5 5 #include <stm32f4xx.h>
6 6 #include <bsp.h>
7 7 #include <core.h>
8 8 #include <VS10XX.h>
9 9 #include <bsp.h>
10 10 #include <spi.h>
11 11 #include <sdcard.h>
12 12 #include <sdcard-spi.h>
13 13 #include <fat32.h>
14 14 #include <ucdirent.h>
15 15 #include <string.h>
16 16 #include <terminal.h>
17 17 #include <ili9328.h>
18 18
19 19
20 20 extern streamdevice* __opnfiles__[];
21 21 extern void test_Block_Move(LCD_t* LCD,int x,int y,int w,int h,int color);
22 22 extern void test_all_colors(LCD_t* LCD);
23 23 extern void test_small_lines(LCD_t* LCD);
24 24 extern void test_lines(LCD_t* LCD);
25 25 extern void test_address(LCD_t* LCD);
26 26 void test_uniform_rw(LCD_t* LCD);
27 27 char buffer[512];
28 28
29 29 void randBoxesDemo()
30 30 {
31 31 int16_t x,y,w,h,t,r;
32 32 x=rand()%240;
33 33 y=rand()%320;
34 34 w=rand()%(240-x);
35 35 if(x>y)
36 36 r=(rand()%(y))%(320-y);
37 37 else
38 38 r=(rand()%(x))%(240-x);
39 39 h=rand()%(320-y);
40 40 t=rand()%(10);
41 41 ili9328paintFilRect(&lcd0,x,y,w,h,rand(),t,rand());
42 42 //ili9328paintFilCirc(&lcd0,x,y,r,rand(),t,rand());
43 43 //delay_100us(10);
44 44 //for(volatile int i=0;i<(1024*2);i++);
45 45 }
46 46
47 47 void randTextDemo()
48 48 {
49 49 int16_t x,y,w,h,t,r;
50 50 char buf[2];
51 51 buf[1]='\0';
52 52 x=rand()%240;
53 53 y=rand()%320;
54 54 if(x>y)
55 55 r=(rand()%(y))%(320-y);
56 56 else
57 57 r=(rand()%(x))%(240-x);
58 58 h=rand()%(320-y);
59 59 buf[0]=rand()%(255);
60 60 //ili9328paintFilRect(&lcd0,x,y,w,h,rand(),t,rand());
61 61 ili9328paintText(&lcd0,buf,x,y,&ComicSansMS_18,rand());
62 62 //ili9328paintFilCirc(&lcd0,x,y,r,rand(),t,rand());
63 63 delay_100us(5000);
64 64 //for(volatile int i=0;i<(1024*2);i++);
65 65 }
66 66
67 67 void tryToplay2()
68 68 {
69 69
70 70 extern blkdevice sdcard2blkdev;
71 71 int i=0,l=0;
72 72
73 73 spisetspeed(audioCodec0.SPIdev,4000000);
74 74 printf("Streaming File\n");
75 75
76 76 //printf("New LBA=0x%X\n",nextLba);
77 77
78 78 while(sdcard2blkdev.read(&sdcard2blkdev,buffer,l++,1)==RES_OK)
79 79 {
80 80
81 81 for(i=0;i<512;i+=32)
82 82 {
83 83 vs10XXstream32bytes(&audioCodec0,buffer+i);
84 84 }
85 85 }
86 86 }
87 87
88 88 void playFile(ucdirent* file,FAT32fs* part)
89 89 {
90 90 extern volatile vs10XXDev audioCodec0;
91 char direntName[]=" \n";
91 char direntName[]=" \n";
92 92 uint32_t fileLba,nextLba;
93 93 int i=0;
94 94 fat32getdirentname(file,direntName);
95 95 //gpioset(LCD_BACKL);
96 96 printf("%s\n",direntName);
97 97 nextLba=fat32getdirentlba(file);
98 98 //printf("Streaming File\n");
99 99 //gpioclr(LCD_BACKL);
100 100 do
101 101 {
102 102 fileLba = nextLba;
103 103 if(sdcard2FAT32part1.part->phy->read(part->part->phy,buffer,fileLba,1)==RES_OK)
104 104 {
105 105 for(i=0;i<512;i+=32)
106 106 {
107 107 vs10XXstream32bytes(&audioCodec0,buffer+i);
108 108 }
109 109 }
110 110 }while ((fat32nextsectorlba(part,fileLba,&nextLba)==DIRENT_noErr) && (!gpiogetval(BP3)));
111 111 vs10XXsoftReset(&audioCodec0);
112 112 while (gpiogetval(BP3))delay_100us(1000);
113 113 }
114 114
115 115 void playAllparts()
116 116 {
117 117 extern FAT32fs sdcard2FAT32part1,sdcard2FAT32part2,sdcard2FAT32part3,sdcard2FAT32part4;
118 118 ucdirent root;
119 119 if(DIRENT_noErr==fat32mkdirent(&sdcard2FAT32part1,&root))
120 120 {
121 121 printf("Reading on SDCARD2 part1\n");
122 122 if(DIRENT_noErr==fat32getrootfirstent(&root))
123 123 {
124 124 do{
125 125 playFile(&root,&sdcard2FAT32part1);
126 126 }while (DIRENT_noErr==fat32nextdirent(&root));
127 127 }
128 128 }
129 129 gpioset(LED2);
130 130 if(DIRENT_noErr==fat32mkdirent(&sdcard2FAT32part2,&root))
131 131 {
132 132 printf("Reading on SDCARD2 part2\n");
133 133 if(DIRENT_noErr==fat32getrootfirstent(&root))
134 134 {
135 135 do{
136 136 playFile(&root,&sdcard2FAT32part2);
137 137 }while (DIRENT_noErr==fat32nextdirent(&root));
138 138 }
139 139 }
140 140 }
141 141
142 int main()
142 int main2()
143 143 {
144 144 delay_100us(30000);
145 145 int i=0;
146 146 int color=0;
147 147 // test_all_colors(&lcd0);
148 148 // test_small_lines(&lcd0);
149 149 // test_uniform_rw(&lcd0);
150 150
151 151 printf("LCD ID REG = 0x%X\n\r",lcd0.interface->readreg(ILI9328_REGISTER_DRIVERCODEREAD));
152 152 printf("LCD ENTRY MODE REG = 0x%X\n\r",lcd0.interface->readreg(ILI9328_REGISTER_ENTRYMODE));
153 153 uint16_t test[16];
154 154 for(int i=0;i<16;i++)
155 155 {
156 156 test[i]=0xF00F;
157 157 }
158 158 lcd0.paint(&lcd0,test,10,100,4,4);
159 159 lcd0.getPix(&lcd0,test,10,100,4,4);
160 160 for(int i=0;i<16;i++)
161 161 {
162 162 printf("@%d=0x%X\n",i,test[i]);
163 163 }
164 164 // test_lines(&lcd0);
165 165
166 166 while(1)test_address(&lcd0);
167 167 for(i=0;i<240;i++)
168 168 {
169 169 if(i>(240/3))
170 170 {
171 171 color= (i<<5) + 0x1F;
172 172 }
173 173 else
174 174 {
175 175 color = i;
176 176 }
177 177 if(i>(2*240/3))
178 178 {
179 179 color= (i<<10) + 0x3FF;
180 180 }
181 181 lcd0.paintFilRect(&lcd0,i,0,1,100,0,0,color);
182 182 }
183 183 while(1)printf("test ");
184 184 // for(i=0;i<240;i++)
185 185 // {
186 186 // if(i>(240/3))
187 187 // {
188 188 // color= (i<<5) + 0x1F;
189 189 // }
190 190 // else
191 191 // {
192 192 // color = i;
193 193 // }
194 194 // if(i>(2*240/3))
195 195 // {
196 196 // color= (i<<10) + 0x3FF;
197 197 // }
198 198 // lcd0.paintFilRect(&lcd0,i,220,1,100,0,0,color);
199 199 // }
200 200 for(i=0;i<240;i++)
201 201 {
202 202 ili9328setFrame(&lcd0,i,0,1,100);
203 203 lcd0.interface->readGRAM(buffer,100);
204 204 lcd0.paint(&lcd0,buffer,i,200,1,100);
205 205 }
206 206 while(1);
207 207 }
208 208
209 int main2()
209 int main()
210 210 {
211 211 extern terminal_t terminal0;
212 212 extern volatile vs10XXDev audioCodec0;
213 213 printf("Volume=0x%x\n",vs10XXcmdread(&audioCodec0,VSVOL));
214 214 vs10XXcmdwrite(&audioCodec0,VSCLOCKF,0x2000);
215 215 delay_100us(1000);
216 216 vs10XXcmdwrite(&audioCodec0,VSVOL,0x2020);
217 217 printf("VSCLOCKF=0x%x\n",vs10XXcmdread(&audioCodec0,VSCLOCKF));
218 218 printf("VSMODE=0x%x\n",vs10XXcmdread(&audioCodec0,VSMODE));
219 219 //terminal_clear(&terminal0);
220 220 // gpioclr(LCD_BACKL);
221 221 playAllparts();
222 222 return 0;
223 223 }
224 224
225 225
226 226
227 227
228 228
229 229
@@ -1,13 +1,14
1 1 TEMPLATE = app
2 2 CONFIG += cpu
3 3
4 4
5 5 UCMODEL=simulator
6 6 BSP = SIMULATOR
7 7
8 8 DEFINES += CPUFREQ=100000000
9 9
10 10 SOURCES += \
11 11 main.c \
12 test_lcd.c
12 test_lcd.c \
13 test_SDCARD.c
13 14
@@ -1,71 +1,138
1 1 #include <stdio.h>
2 2 #include <fat32.h>
3 3 #include <gpio.h>
4 4 #include <uart.h>
5 5 #include <bsp.h>
6 6 #include <core.h>
7 7 #include <bsp.h>
8 8 #include <spi.h>
9 9 #include <fat32.h>
10 10 #include <ucdirent.h>
11 11 #include <string.h>
12 12 #include <unistd.h>
13 13 #include <terminal.h>
14 14 #include <stdarg.h>
15 15 #include <malloc.h>
16 16
17 17 extern streamdevice* __opnfiles__[];
18 18 extern void test_Block_Move(LCD_t* LCD,int x,int y,int w,int h,int color);
19 extern void test_address(LCD_t* LCD);
20 extern void printRootClustersChain(FAT32fs* sdcard2FAT32part);
19 21 char buffer[512];
20 22
21 23
22 void streamdevicePrint(streamdevice* dev, const char* format,...)
23 {
24 char** str_buffer;
25 int i;
26 va_list ap;
27 va_start(ap,format);
28 vasprintf(str_buffer,format,ap);
29 va_end(ap);
30 i=strlen(*str_buffer);
31 dev->ops->write(dev,(void*)*str_buffer,1,i);
32 free(*str_buffer);
33 }
34
35 //int printf(const char *format,...)
24 //void streamdevicePrint(streamdevice* dev, const char* format,...)
36 25 //{
37 // char** str_buffer;
26 // char str_buffer[512]="";
38 27 // int i;
39 28 // va_list ap;
40 29 // va_start(ap,format);
41 30 // vasprintf(str_buffer,format,ap);
42 31 // va_end(ap);
43 // i=strlen(*str_buffer);
44 // __opnfiles__[1]->ops->write(__opnfiles__[1],(void*)*str_buffer,1,i);
45 // free(*str_buffer);
32 // i=strlen(str_buffer);
33 // dev->ops->write(dev,(void*)str_buffer,1,i);
34 //}
35
36 int _write(int file, char *ptr, int len)
37 {
38 if(file<__MAX_OPENED_FILES__ && __opnfiles__[file]!=NULL)
39 {
40 if(__opnfiles__[file]->ops->write(__opnfiles__[file],ptr,1,len)) return len;
41 }
42 return len;
43 }
46 44
45 int _write_r (struct _reent *r, int file, char * ptr, int len)
46 {
47 return _write(file, ptr, len);
48 }
49
50 //int printf(const char *format,...)
51 //{
52 // char str_buffer[512]="";
53 // for(int i =0;i<512;i++)str_buffer[i]='\0';
54 // int i;
55 // va_list ap;
56 // va_start(ap,format);
57 // vasprintf(str_buffer,format,ap);
58 // va_end(ap);
59 // i=strlen(str_buffer);
60 // __opnfiles__[1]->ops->write(__opnfiles__[1],(void*)str_buffer,1,i);
47 61 //}
48 62
49 63 void lcd_print()
50 64 {
51 65 lcd0.paintFilRect(&lcd0,10,10,100,100,0,0,0x0F0F);
52 66 // __opnfiles__[1]->ops->write(__opnfiles__[1],(void*)"hello",1,5);
53 67 }
54 68
69
70 void playFile(ucdirent* file,FAT32fs* part)
71 {
72 extern volatile vs10XXDev audioCodec0;
73 char direntName[]=" \n";
74 uint32_t fileLba,nextLba;
75 int i=0;
76 fat32getdirentname(file,direntName);
77 //gpioset(LCD_BACKL);
78 printf("%s\n",direntName);
79 nextLba=fat32getdirentlba(file);
80 //printf("Streaming File\n");
81 //gpioclr(LCD_BACKL);
82 }
83
84 void listFiles()
85 {
86 extern FAT32fs sdcard2FAT32part1,sdcard2FAT32part2,sdcard2FAT32part3,sdcard2FAT32part4;
87 ucdirent root;
88 if(DIRENT_noErr==fat32mkdirent(&sdcard2FAT32part1,&root))
89 {
90 printf("Reading on SDCARD2 part1\n");
91 if(DIRENT_noErr==fat32getrootfirstent(&root))
92 {
93 do{
94 playFile(&root,&sdcard2FAT32part1);
95 }while (DIRENT_noErr==fat32nextdirent(&root));
96 }
97 }
98 gpioset(LED2);
99 if(DIRENT_noErr==fat32mkdirent(&sdcard2FAT32part2,&root))
100 {
101 printf("Reading on SDCARD2 part2\n");
102 if(DIRENT_noErr==fat32getrootfirstent(&root))
103 {
104 do{
105 playFile(&root,&sdcard2FAT32part2);
106 }while (DIRENT_noErr==fat32nextdirent(&root));
107 }
108 }
109 }
110
111
112 int libuc_main2()
113 {
114 printRootClustersChain(&sdcard2FAT32part1);
115
116 }
117
55 118 int libuc_main()
56 119 {
57 120 char in[255];
58 lcd_print();
121 //lcd_print();
59 122 printf("hello world\n");
60 streamdevicePrint(__opnfiles__[1],"test Hello %d %f \n",1234567,8.96);
123 delay_100us(10000);
124 // streamdevicePrint(__opnfiles__[1],"test Hello %d %f \n",1234567,8.96);
61 125 lcd0.paintText(&lcd0,"A",10,100,&ComicSansMS_18,0x0);
126 //while(1)test_address(&lcd0);
127 listFiles();
62 128 // while (scanf("%c",in))
63 129 // {
64 130 sleep(5);
65 131 // }
132
66 133 }
67 134
68 135
69 136
70 137
71 138
@@ -1,21 +1,43
1 1 #include <stdio.h>
2 2 #include <fat32.h>
3 3 #include <gpio.h>
4 4 #include <uart.h>
5 5 #include <bsp.h>
6 6 #include <core.h>
7 7 #include <VS10XX.h>
8 8 #include <bsp.h>
9 9 #include <spi.h>
10 10 #include <sdcard.h>
11 11 #include <sdcard-spi.h>
12 12 #include <fat32.h>
13 13 #include <ucdirent.h>
14 14 #include <string.h>
15 15 #include <ili9328.h>
16 16
17 uint16_t buff[50*50];
17 18
18 19 void test_Block_Move(LCD_t* LCD,int x,int y,int w,int h,int color)
19 20 {
20 21 // LCD->paintFilRect(LCD,x,y,w,h,0,0,color);
21 22 }
23 int coef=1;
24
25 void test_address(LCD_t* LCD)
26 {
27 LCD->paintFilRect(LCD,0,0,LCD->width,LCD->height,0,0,0xFFFF);
28 uint16_t color[1];
29 for(int y=0;y<320;y++)
30 {
31 for(int x=0;x<240;x++)
32 {
33 color[0]=((x/10*y*x)/((y+x+1)))+coef;
34 coef = color[0];
35 LCD->paint(LCD,color,x,y,1,1);
36 //delay_100us(100);
37 }
38 }
39 LCD->getPix(LCD,buff,50,50,50,50);
40 // delay_100us(5000);
41 LCD->paint(LCD,buff,50,50,50,50);
42 delay_100us(500);
43 }
@@ -1,383 +1,336
1 1 /*------------------------------------------------------------------------------
2 2 -- This file is a part of the libuc, microcontroler library
3 3 -- Copyright (C) 2012, Alexis Jeandet
4 4 --
5 5 -- This program is free software; you can redistribute it and/or modify
6 6 -- it under the terms of the GNU General Public License as published by
7 7 -- the Free Software Foundation; either version 3 of the License, or
8 8 -- (at your option) any later version.
9 9 --
10 10 -- This program is distributed in the hope that it will be useful,
11 11 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
12 12 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 13 -- GNU General Public License for more details.
14 14 --
15 15 -- You should have received a copy of the GNU General Public License
16 16 -- along with this program; if not, write to the Free Software
17 -- 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 19 -- Author : Alexis Jeandet
20 20 -- Mail : alexis.jeandet@member.fsf.org
21 21 -------------------------------------------------------------------------------*/
22 22 #define FAT32_PRIVATE
23 23 #include <fat32.h>
24 24 #include <stdio.h>
25 25 #include <stdint.h>
26 26 #include <hexviewer.h>
27 27
28 char fat32buff[512]__attribute__ ((aligned (4)));
28 char fat32buff[512];
29 29 uint32_t lastSecAddrs=-1;
30 30 FAT32fs* lastFATFS=0;
31 31
32 32 int fat32open(FAT32fs* fs,dikpartition* part)
33 33 {
34 fs->valide = 0;
35 if(part->valide==0)return FATBadpart;
36 char sector[512];
34 //char sector[512];
37 35 fs->part = part;
38 36 if(!isFat32(fs->part->TypeCode))return FATBadpart;
39 if(fs->part->phy->read(fs->part->phy,sector,fs->part->LBABegin,1)!=RES_OK)return FATReadErr;
40 fs->BPB_BytsPerSec = fat32Ui8_2_Ui16(sector,BPB_BytsPerSecoff);
41 fs->BPB_RsvdSecCnt = fat32Ui8_2_Ui16(sector,BPB_RsvdSecCntoff);
42 fs->BPB_FATSz32 = fat32Ui8_2_Ui32(sector,BPB_FATSz32off);
43 fs->BPB_RootClus = fat32Ui8_2_Ui32(sector,BPB_RootClusoff);
44 fs->BPB_SecPerClus = sector[BPB_SecPerClusoff];
45 fs->BPB_NumFATs = sector[BPB_NumFATsoff];
37 //if(fs->part->phy->read(fs->part->phy,sector,fs->part->LBABegin,1)!=RES_OK)return FATReadErr;
38 fat32sectorreadout(fs,fs->part->LBABegin);
39 fs->BPB_BytsPerSec = fat32Ui8_2_Ui16(fat32buff,BPB_BytsPerSecoff);
40 fs->BPB_RsvdSecCnt = fat32Ui8_2_Ui16(fat32buff,BPB_RsvdSecCntoff);
41 fs->BPB_FATSz32 = fat32Ui8_2_Ui32(fat32buff,BPB_FATSz32off);
42 fs->BPB_RootClus = fat32Ui8_2_Ui32(fat32buff,BPB_RootClusoff);
43 fs->BPB_SecPerClus = fat32buff[BPB_SecPerClusoff];
44 fs->BPB_NumFATs = fat32buff[BPB_NumFATsoff];
46 45 fs->fat_begin_lba = (unsigned int)fs->part->LBABegin + (unsigned int)(unsigned short)fs->BPB_RsvdSecCnt;
47 46 fs->cluster_begin_lba = (unsigned int)fs->fat_begin_lba + ((unsigned int)fs->BPB_NumFATs * (unsigned int)fs->BPB_FATSz32 );
48 fs->valide=1;
49 47 return FATnoErr;
50 48 }
51 49
52 50
53 51 int fat32mkdirent(FAT32fs* fs,ucdirent* dirent)
54 52 {
55 if((fs==0) || (fs->valide==0)) return DIRENT_BabArg;
53 if(fs==0) return DIRENT_BabArg;
56 54 if(dirent==0) return DIRENT_BabArg;
57 55 dirent->fs = (UHANDLE)fs;
58 56 dirent->getrootfirstent = &fat32getrootfirstent;
59 57 dirent->nextdirent = &fat32nextdirent;
60 58 return DIRENT_noErr;
61 59 }
62 60
63 61
64 62 int fat32getrootfirstent(ucdirent* entry)
65 {
63 {
66 64 if(entry==0) return DIRENT_BabArg;
67 65 entry->CurrentSec = ((FAT32fs*)entry->fs)->cluster_begin_lba;
68 66 entry->Currententry = 0;
69 67 return fat32nextdirent(entry);
70 68 }
71 69
72 70
73 71 int fat32getVolName(FAT32fs* fs,char* Name)
74 72 {
75 if((fs==0) || (fs->valide==0)) return DIRENT_BabArg;
73 if(fs==0) return DIRENT_BabArg;
76 74 if(Name==0) return DIRENT_BabArg;
77 75 int i=0;
78 76 ucdirent entry;
79 77 if(DIRENT_noErr==fat32mkdirent(fs,&entry))
80 78 {
81 79 entry.CurrentSec = ((FAT32fs*)entry.fs)->cluster_begin_lba;
82 80 entry.Currententry = -1;
83 81 if(DIRENT_noErr!=fat32nextdirent(&entry))return DIRENT_ReadErr;
84 82 for(i=0;i<16;i++)
85 83 {
86 84 Name[i] = entry.DIR_Name[i];
87 85 }
88 86 return DIRENT_noErr;
89 87 }
90 88 return DIRENT_ReadErr;
91 89 }
92 90
93 91
94 92 int fat32enterdirent(ucdirent* currententry,ucdirent* firstentry)
95 93 {
96 94 if(firstentry==0) return DIRENT_BabArg;
97 95 if(currententry==0) return DIRENT_BabArg;
98 96 fat32mkdirent(((FAT32fs*)currententry->fs),firstentry);
99 97 firstentry->CurrentSec = fat32getdirentlba(currententry);
100 98 firstentry->Currententry = -1;
101 99 return fat32nextdirent(firstentry);
102 100 }
103 101
104 102
105 103 int fat32nextdirent(ucdirent* entry)
106 104 {
107 105 uint32_t n=0,res=DIRENT_noErr,k,j;
108 106 k=(0xFF&((signed char)entry->Currententry)+1)*32; /*Restart at last dir entry*/
109 107 j=entry->CurrentSec;// /*Restart at last sector*/
110 108 do
111 109 {
112 //printf("reading new secotr\n",k);
113 110 fat32sectorreadout(((FAT32fs*)entry->fs),j);
114 //printf("done\n",k);
115 /*512 Bytes per sector and 32 bytes per entry*/
116 for(k=k;k<(512);k+=32)
111 for(k=k;k<(512);k+=32) /*512 Bytes per sector and 32 bytes per entry*/
117 112 {
118 113 if((fat32buff[DIR_Nameoff+k]!=(char)0xE5)) /*0xE5 = free entry*/
119 114 {
120 //printf("Fount dir entry = %d, 0x%X\n",0xff & ((int)fat32buff[DIR_Nameoff+k]),0xff & ((int)fat32buff[DIR_Attroff+k]));
121 115 if(fat32buff[DIR_Nameoff+k]==(char)0)
122 {
123 //printf("end of directory reached\n",k);
124 116 return DIRENT_EndOfDir; /*0x00 = end of dir*/
125 }
126 117 else
127 {
128 uint8_t attribute=fat32buff[DIR_Attroff + k];
129 if( (attribute==ATTR_DIRECTORY)
130 ||(attribute==ATTR_ARCHIVE)
131 ||(attribute==ATTR_READ_ONLY)
132 ||(attribute==ATTR_READ_ONLY))
118 if((fat32buff[DIR_Attroff + k]==(char)ATTR_DIRECTORY)||(fat32buff[DIR_Attroff + k]==(char)ATTR_ARCHIVE)||(fat32buff[DIR_Attroff + k]==(char)(ATTR_READ_ONLY)))
133 119 {
134 120 for(n=0;n<16;n++)entry->DIR_Name[n] = '\0';
135 121 for(n=0;n<11;n++)entry->DIR_Name[n] = fat32buff[n+DIR_Nameoff + k];
136 entry->DIR_Attr = attribute;
122 entry->DIR_Attr = (uint8_t)fat32buff[DIR_Attroff + k];
137 123 entry->DIR_CrtTimeTenth = (uint8_t)fat32buff[DIR_CrtTimeTenthoff + k];
138 124 entry->DIR_CrtTime = fat32extract16b(fat32buff,(DIR_CrtTimeoff + k));
139 125 entry->DIR_CrtDate = fat32extract16b(fat32buff,(DIR_CrtDateoff + k));
140 126 entry->DIR_LstAccDate = fat32extract16b(fat32buff,(DIR_LstAccDateoff + k));
141 127 entry->DIR_FstClusHI = fat32extract16b(fat32buff, (DIR_FstClusHIoff + k));
142 128 entry->DIR_WrtTime = fat32extract16b(fat32buff,(DIR_WrtTimeoff + k));
143 129 entry->DIR_FstClustLO = fat32extract16b(fat32buff, (DIR_FstClusLOoff + k));
144 130 entry->DIR_FileSize = fat32extract32b(fat32buff,(DIR_FileSizeoff + k));
145 131 entry->CurrentSec = j;
146 entry->Currententry = (uint8_t)(0xFF&(k>>5));
132 entry->Currententry = (unsigned char)(k/32);
147 133 return DIRENT_noErr;
148 134 }
149 }
150 135 }
136
151 137 }
152 //printf("asking for next sector\n");
153 //printf("current = 0x%X\n",j);
154 138 j=fat32nextsectorlba(((FAT32fs*)entry->fs),j,&k);
155 //printf("got it 0x%x\n",k);
156 139 if(j!=DIRENT_noErr)
157 140 {
158 141 if(j==DIRENT_LastSect) return DIRENT_EndOfDir; /*Not clean but can avoid some bugs*/
159 142 return j;
160 143 }
161 144 j=k;
162 145 k=0;
163 146 }while(res==DIRENT_noErr);
164 147 return res;
165 148 }
166 149
167 150
168 151 int fat32getdirentname(ucdirent* entry,char* nameBuffer)
169 152 {
170 153 uint32_t j;
171 154 int k,n,i;
172 155 int res=DIRENT_noErr;
173 156 char longName=0;
174 157 k=(((signed char)entry->Currententry))*32;
175 158 j=entry->CurrentSec;
176 159 fat32sectorreadout(((FAT32fs*)entry->fs),j);
177 160 longName |= fat32buff[DIR_Nameoff + 6 + k]=='~';
178 161 if(k>=32)
179 162 {
180 163 longName |= ((fat32buff[DIR_Nameoff + k-32]&0x40)==0x40)&((fat32buff[DIR_Nameoff + k-32 +11])==ATTR_LONGNAME);
181 164 }
182 165 else
183 166 {
184 167 uint32_t j_old=j;
185 168 if(fat32prevsectorlba((FAT32fs*)entry->fs, j,&j)!=DIRENT_noErr)return DIRENT_ReadErr;
186 169 fat32sectorreadout(((FAT32fs*)entry->fs),j);
187 170 k=512;
188 171 longName |= ((fat32buff[DIR_Nameoff + k-32]&0x40)==0x40)&((fat32buff[DIR_Nameoff + k-32 +11])==ATTR_LONGNAME);
189 172 if(!longName)
190 173 {
191 174 k=0;
192 175 j=j_old;
193 176 fat32sectorreadout(((FAT32fs*)entry->fs),j);
194 177 k=0;
195 178 }
196 179 }
197 180 if(longName) //long Name? or lower case name
198 181 {
199 182 i=0;
200 183 do{
201 184 if(k==0)
202 185 {
203 186 //get previous sector
204 if(fat32prevsectorlba2((FAT32fs*)entry->fs,entry, j,&j)!=DIRENT_noErr)return DIRENT_ReadErr;
187 if(fat32prevsectorlba((FAT32fs*)entry->fs, j,&j)!=DIRENT_noErr)return DIRENT_ReadErr;
205 188 fat32sectorreadout(((FAT32fs*)entry->fs),j);
206 189 k=512-32;
207 190 for(n=0;n<5;n++)nameBuffer[i++] = fat32buff[((n<<1)|1) + k];
208 191 for(n=14;n<26;n+=2)nameBuffer[i++] = fat32buff[n + k];
209 192 for(n=28;n<32;n+=2)nameBuffer[i++] = fat32buff[n + k];
210 193 }
211 194 else
212 195 {
213 196 k-=32;
214 197 for(n=0;n<5;n++)nameBuffer[i++] = fat32buff[((n<<1)|1) + k];
215 198 for(n=14;n<26;n+=2)nameBuffer[i++] = fat32buff[n + k];
216 199 for(n=28;n<32;n+=2)nameBuffer[i++] = fat32buff[n + k];
217 200 }
218 201 }while((fat32buff[k]&0x40)!=0x40);
219 202 nameBuffer[i]='\0';
220 203 }
221 204 else
222 205 {
223 206 i=0;
224 207 for(n=0;n<8;n++)
225 208 {
226 209 nameBuffer[i] = 0x20 | fat32buff[n+DIR_Nameoff + k];
227 210 if(nameBuffer[i]!=0x20)i++;
228 211 }
229 212 if((((fat32buff[DIR_Nameoff + k +11])&ATTR_DIRECTORY)!=ATTR_DIRECTORY)&&(fat32buff[8+DIR_Nameoff + k]!=0x20))
230 213 nameBuffer[i++]='.';
231 214 for(n=8;n<11;n++)
232 215 {
233 216 nameBuffer[i] = 0x20 | fat32buff[n+DIR_Nameoff + k];
234 217 if(nameBuffer[i]!=0x20)i++;
235 218 }
236 219
237 220 nameBuffer[i]='\0';
238 221 }
239 222 return res;
240 223 }
241 224
242 225
243 226 uint32_t fat32getdirentlba(ucdirent* entry)
244 227 {
245 228 uint32_t clusterNum = (uint32_t)((uint16_t)entry->DIR_FstClustLO) + ((uint32_t)((uint16_t)entry->DIR_FstClusHI) <<16);
246 229 uint32_t lba=clusterlba(((FAT32fs*)entry->fs),clusterNum);
247 230 return lba;
248 231 }
249 232
250 233
251 234 int fat32nextsectorlba(FAT32fs* fs,uint32_t lastsector_lba,uint32_t *nextsector_lba)
252 235 {
253 236
254 237 if(((lastsector_lba + 1 - fs->cluster_begin_lba) & ((uint32_t)(fs->BPB_SecPerClus)-1))!=0) /*Is it the last sector of the cluster?*/
255 238 {
256 239 *nextsector_lba = lastsector_lba+1; /*if not just increment lba*/
257 240 return DIRENT_noErr;
258 241 }
259 242
260 243 uint32_t clusternum=fat32sectorlbatoclusternum(fs,lastsector_lba); /*Get cluster Number from sector number*/
261 244 uint32_t fatsec=fat32clusterinfatsect(fs,clusternum); /*Get FAT sector number*/
262 245 fat32sectorreadout(fs,fatsec);
263 246 int i= fat32clusterinfatoff(clusternum);
264 247 *nextsector_lba=fat32Ui8_2_Ui32(fat32buff,i);
265 248 if(*nextsector_lba==0xFFFFFFF7)
266 249 {
250
251 printf("DIRENT_BadSect\n");
267 252 return DIRENT_BadSect;
268 253 }
269 254 if((uint32_t)(*nextsector_lba)>=(uint32_t)0xFFFFFFF6)
270 255 {
256 printf("DIRENT_LastSect\n");
271 257 return DIRENT_LastSect;
272 258 }
273 259 *nextsector_lba = clusterlba(fs,*nextsector_lba);
274 260 return DIRENT_noErr;
275 261 }
276 262
277 263
278 264 int fat32prevsectorlba(FAT32fs* fs,uint32_t lastsector_lba,uint32_t *nextsector_lba)
279 265 {
280 266 uint32_t i=0,fatsec=0;
281 if(((lastsector_lba - 1 - fs->cluster_begin_lba) & (fs->BPB_SecPerClus-1))!=0) /*Is it the first sector of the cluster?*/
267 if(((lastsector_lba - fs->cluster_begin_lba) % (fs->BPB_SecPerClus-1))!=0) /*Is it the first sector of the cluster?*/
282 268 {
283 269 *nextsector_lba = lastsector_lba-1; /*if not just decrement lba*/
284 270 return DIRENT_noErr;
285 271 }
286
287 uint32_t clusternum = fat32sectorlbatoclusternum(fs,lastsector_lba); /*Get cluster Number from sector number*/
272 uint32_t clusternum=fat32sectorlbatoclusternum(fs,lastsector_lba); /*Get cluster Number from sector number*/
288 273 fatsec=fat32clusterinfatsect(fs,clusternum); /*Get FAT sector number*/
289 while(fatsec>=fs->fat_begin_lba)
274 do
290 275 {
276
291 277 fat32sectorreadout(fs,fatsec);
292 278 fatsec--;
293 for(i=508;i>2;i-=4)
279 for(i=511;i>3;i-=4)
294 280 {
295 *nextsector_lba = fat32Ui8_2_Ui32(fat32buff,i);
281 *nextsector_lba = fat32Ui8_2_Ui32(fat32buff,i-3);
296 282 if (*nextsector_lba ==clusternum)
297 283 {
298 284 *nextsector_lba = clusterlba(fs,*nextsector_lba);
299 285 return DIRENT_noErr;
300 286 }
287
301 288 }
302 }
289
290 }while(fatsec>=fs->fat_begin_lba);
303 291
304 292 clusternum=fat32sectorlbatoclusternum(fs,lastsector_lba); /*Get cluster Number from sector number*/
305 293 fatsec=fat32clusterinfatsect(fs,clusternum); /*Get FAT sector number*/
306 294 do
307 295 {
308 296
309 297 fat32sectorreadout(fs,fatsec);
310 298 fatsec++;
311 299 for(i=0;i<512;i+=4)
312 300 {
313 301 *nextsector_lba = fat32Ui8_2_Ui32(fat32buff,i);
314 302 if (*nextsector_lba ==clusternum)
315 303 {
316 304 *nextsector_lba = clusterlba(fs,*nextsector_lba);
317 305 return DIRENT_noErr;
318 306 }
319 307
320 308 }
309
321 310 }while(fatsec<=(fs->fat_begin_lba+fs->BPB_FATSz32));
322 311 return DIRENT_ReadErr;
323 312 }
324 313
325 314
326 int fat32prevsectorlba2(FAT32fs* fs,ucdirent* entry,uint32_t lastsector_lba,uint32_t *nextsector_lba)
327 {
328 uint32_t i=0,fatsec=0;
329 if(((lastsector_lba - 1 - fs->cluster_begin_lba) & (fs->BPB_SecPerClus-1))!=0) /*Is it the first sector of the cluster?*/
330 {
331 *nextsector_lba = lastsector_lba-1; /*if not just decrement lba*/
332 return DIRENT_noErr;
333 }
334
335 uint32_t clusternum = fat32sectorlbatoclusternum(fs,lastsector_lba); /*Get cluster Number from sector number*/
336 uint32_t currentClusternum = fat32sectorlbatoclusternum(fs,(fat32getdirentlba(entry)));
337 fatsec=fat32clusterinfatsect(fs,currentClusternum); /*Get FAT sector number*/
338 *nextsector_lba = fat32getdirentlba(entry);
339 while(fatsec<=(fs->fat_begin_lba+fs->BPB_FATSz32))
340 {
341 uint32_t currentClusternum = fat32sectorlbatoclusternum(fs,(*nextsector_lba));
342 fatsec=fat32clusterinfatsect(fs,currentClusternum); /*Get FAT sector number*/
343 fat32sectorreadout(fs,fatsec);
344 i= fat32clusterinfatoff(currentClusternum);
345 if(i==clusternum)
346 {
347 return DIRENT_noErr;
348 }
349 *nextsector_lba=fat32Ui8_2_Ui32(fat32buff,i);
350 if(*nextsector_lba==0xFFFFFFF7)
351 {
352 return DIRENT_BadSect;
353 }
354 if((uint32_t)(*nextsector_lba)>=(uint32_t)0xFFFFFFF6)
355 {
356 return DIRENT_LastSect;
357 }
358 }
359 return DIRENT_ReadErr;
360 }
361
362
363 315
364 316
365 317
366 318
367 319
368 320
369 321
370 322
371 323
372 324
373 325
374 326
375 327
376 328
377 329
378 330
379 331
380 332
381 333
382 334
383 335
336
@@ -1,86 +1,86
1 1 /*------------------------------------------------------------------------------
2 2 -- This file is a part of the libuc, microcontroler library
3 3 -- Copyright (C) 2012, Alexis Jeandet
4 4 --
5 5 -- This program is free software; you can redistribute it and/or modify
6 6 -- it under the terms of the GNU General Public License as published by
7 7 -- the Free Software Foundation; either version 3 of the License, or
8 8 -- (at your option) any later version.
9 9 --
10 10 -- This program is distributed in the hope that it will be useful,
11 11 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
12 12 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 13 -- GNU General Public License for more details.
14 14 --
15 15 -- You should have received a copy of the GNU General Public License
16 16 -- along with this program; if not, write to the Free Software
17 17 -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 18 -------------------------------------------------------------------------------
19 19 -- Author : Alexis Jeandet
20 20 -- Mail : alexis.jeandet@member.fsf.org
21 21 -------------------------------------------------------------------------------*/
22 22 #include <mbr.h>
23 23 #include <stdio.h>
24 24
25 25
26 26 int mbropen(blkdevice* phy,dikpartition* part,char partNum)
27 27 {
28 28 printf("enter MBR open function\n");
29 29 char mbr[512];
30 30 if((part==0) || (phy ==0) || (partNum>4) || (partNum==0) ) return MBRBabArg;
31 31 part->phy = phy;
32 32 if(phy->read(phy,mbr,0,1)!=RES_OK)
33 33 {
34 34 printf("can't read MBR!\n");
35 35 printf("%x %x %x %x %x %x %x %x\n",mbr[0],mbr[1],mbr[2],mbr[3],mbr[4],mbr[5],mbr[6],mbr[7]);
36 36 part->valide = 0;
37 37 return MBRReadErr;
38 38 }
39 39 if(((mbr[510]) == (char)0x55) && ((mbr[511]) == (char)0xAA))
40 40 {
41 part->TypeCode = mbr[(512-82+TypeCodeoffset)+partNum*16];
42 part->LBABegin = (unsigned int)mbr[(512-82+LBABeginoffset)+partNum*16] + ((unsigned int)mbr[(512-82+LBABeginoffset+1)+partNum*16]<<8)+ ((unsigned int)mbr[(512-82+LBABeginoffset+2)+partNum*16]<<16)+ ((unsigned int)mbr[(512-82+LBABeginoffset+3)+partNum*16]<<24);
43 part->NumOfSec = (unsigned int)mbr[(512-82+NumOfSecoffset)+partNum*16] + ((unsigned int)mbr[(512-82+NumOfSecoffset+1)+partNum*16]<<8)+ ((unsigned int)mbr[(512-82+NumOfSecoffset+2)+partNum*16]<<16)+ ((unsigned int)mbr[(512-82+NumOfSecoffset+3)+partNum*16]<<24);
41 part->TypeCode = mbr[(512-82+TypeCodeoffset)+(partNum*16)];
42 part->LBABegin = (unsigned int)mbr[(512-82+LBABeginoffset)+(partNum*16)] + ((unsigned int)mbr[(512-82+LBABeginoffset+1)+(partNum*16)]<<8)+ ((unsigned int)mbr[(512-82+LBABeginoffset+2)+(partNum*16)]<<16)+ ((unsigned int)mbr[(512-82+LBABeginoffset+3)+(partNum*16)]<<24);
43 part->NumOfSec = (unsigned int)mbr[(512-82+NumOfSecoffset)+(partNum*16)] + ((unsigned int)mbr[(512-82+NumOfSecoffset+1)+(partNum*16)]<<8)+ ((unsigned int)mbr[(512-82+NumOfSecoffset+2)+(partNum*16)]<<16)+ ((unsigned int)mbr[(512-82+NumOfSecoffset+3)+(partNum*16)]<<24);
44 44 printf("MBR Ok\n");
45 45 part->valide = 1;
46 46 return MBRnoErr;
47 47 }
48 48 printf("Bad MBR MBR[510]=0x%.2X MBR[511]=0x%.2X!\n",0xff&mbr[510],0xff&mbr[511]);
49 49 part->valide = 0;
50 50 return MBRBadMbr;
51 51
52 52 }
53 53
54 54
55 55
56 56
57 57
58 58
59 59
60 60
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
78 78
79 79
80 80
81 81
82 82
83 83
84 84
85 85
86 86
@@ -1,239 +1,239
1 1 /*------------------------------------------------------------------------------
2 2 -- This file is a part of the libuc, microcontroler library
3 3 -- Copyright (C) 2013, Alexis Jeandet
4 4 --
5 5 -- This program is free software; you can redistribute it and/or modify
6 6 -- it under the terms of the GNU General Public License as published by
7 7 -- the Free Software Foundation; either version 3 of the License, or
8 8 -- (at your option) any later version.
9 9 --
10 10 -- This program is distributed in the hope that it will be useful,
11 11 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
12 12 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 13 -- GNU General Public License for more details.
14 14 --
15 15 -- You should have received a copy of the GNU General Public License
16 16 -- along with this program; if not, write to the Free Software
17 17 -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 18 -------------------------------------------------------------------------------
19 19 -- Author : Alexis Jeandet
20 20 -- Mail : alexis.jeandet@member.fsf.org
21 21 -------------------------------------------------------------------------------*/
22 22 #include <widget.h>
23 23 #include <terminal.h>
24 24 #include <stdint.h>
25 25 #include <stdio.h>
26 26 #include <gpio.h>
27 27 #include <core.h>
28 28 #include <malloc.h>
29 29
30 30 #define CHARXPOS(terminal,charwidth) (((terminal)->column * charwidth) + (terminal)->Xpos)
31 31 #define CHARYPOS(terminal,charheight) ((terminal)->line * charheight + (terminal)->Ypos+charheight)
32 32
33 33 streamdevice_ops TERMINAL_OPS=
34 34 {
35 35 .write = &terminal_write,
36 36 .read = &terminal_read,
37 37 .setpos= &terminal_setpos,
38 38 .close = NULL
39 39 };
40 40
41 41 int terminal_init(terminal_t* terminal,LCD_t* LCD,sFONT* font,streamdevice* strdev)
42 42 {
43 43 if((LCD!=NULL) && (font!=NULL) && (strdev!=NULL) && (terminal!=NULL))
44 44 {
45 45 terminal->LCD=LCD;
46 46 terminal->font=font;
47 47 terminal->line = 0;
48 48 terminal->column = 0;
49 49 terminal->horizontalSpace = 0;
50 50 terminal->verticalSpace = 0;
51 51 int charw=terminal->font->Width + terminal->horizontalSpace;
52 52 int charh=terminal->font->Height + terminal->verticalSpace;
53 53 terminal->textColor=0xFFFF;
54 54 terminal->backgroundColor=0xF00F;
55 55 terminal_setgeometry(terminal,5,5,terminal->LCD->width-(10),terminal->LCD->height-(10));
56 56 strdev->_stream = (UHANDLE)terminal;
57 57 strdev->ops = &TERMINAL_OPS;
58 58 strdev->streamPt = 0;
59 59 terminal_clear(terminal);
60 60 terminal->LCD->paintFilRect(terminal->LCD,CHARXPOS(terminal, charw),CHARYPOS(terminal, charh)-charh,charw,charh,terminal->backgroundColor,0,terminal->backgroundColor);
61 61 terminal->buffer = (char*)malloc(terminal->lineCount*(terminal->columnCount + 1));
62 62 terminal->firstLine = 0;
63 63 terminal->lastLine = 0;
64 64 terminal->empty = 1;
65 65 for(int i=1;i<=terminal->lineCount;i++)
66 66 {
67 67 terminal->buffer[i * terminal->columnCount]='\n';
68 68 }
69 69 return 1;
70 70 }
71 71 return 0;
72 72 }
73 73
74 74 void terminal_setgeometry(terminal_t* terminal,uint16_t Xpos,uint16_t Ypos,uint16_t width,uint16_t height)
75 75 {
76 76 int charw=terminal->font->Width + terminal->horizontalSpace;
77 77 int charh=terminal->font->Height + terminal->verticalSpace;
78 78 if(terminal->LCD->height<(Ypos+height))
79 79 return;
80 80 if(terminal->LCD->width<(Xpos+width))
81 81 return;
82 82 terminal->Xpos = Xpos;
83 83 terminal->Ypos = Ypos;
84 84 terminal->height = height;
85 85 terminal->width = width;
86 86 terminal->lineCount = terminal->height/charh;
87 87 terminal->columnCount = (terminal->width/charw)-1;
88 88 terminal_clear(terminal);
89 89 }
90 90
91 91
92 92 void terminal_clear(terminal_t* terminal)
93 93 {
94 94 terminal->firstLine = 0;
95 95 terminal->lastLine = 0;
96 96 terminal->empty = 1;
97 97 terminal->line =0;
98 98 terminal->column=0;
99 99 terminal->LCD->paintFilRect(terminal->LCD,terminal->Xpos,terminal->Ypos,terminal->width,terminal->height,terminal->backgroundColor,0,terminal->backgroundColor);
100 100 }
101 101
102 102 void terminal_setbackgroundColor(terminal_t* terminal, uint32_t backgrooundColor)
103 103 {
104 104 terminal->backgroundColor = backgrooundColor;
105 105 }
106 106
107 107 void terminal_settextColor(terminal_t* terminal, uint32_t textColor)
108 108 {
109 109 terminal->textColor = textColor;
110 110 }
111 111
112 112
113 113 void terminal_movecursor(terminal_t* terminal,int n)
114 114 {
115 115 terminal->column += n;
116 116 if(terminal->column>(terminal->columnCount))
117 117 {
118 118 terminal->line += (terminal->column)/terminal->columnCount;
119 119 terminal->line = terminal->line % terminal->lineCount;
120 120 terminal->column = (terminal->column % terminal->columnCount)-1;
121 121 }
122 122 }
123 123
124 124 void terminal_clearCurentLine(terminal_t* terminal)
125 125 {
126 126 int charw=terminal->font->Width + terminal->horizontalSpace;
127 127 int charh=terminal->font->Height + terminal->verticalSpace;
128 128 terminal->LCD->paintFilRect(terminal->LCD,terminal->Xpos,CHARYPOS(terminal, charh)-charh,terminal->width,charh,terminal->backgroundColor,0,terminal->backgroundColor);
129 129 }
130 130
131 131 int terminal_writenc(terminal_t* terminal,char* data, int n)
132 132 {
133 133 int charw=terminal->font->Width + terminal->horizontalSpace;
134 134 int charh=terminal->font->Height + terminal->verticalSpace;
135 135 int l=0;
136 136 char buffer[2]=" ";
137 137 while(l<n)
138 138 {
139 139
140 140 buffer[0]=data[l];
141 141 if(buffer[0]=='\n')
142 142 {
143 143 terminal->line= (terminal->line+1) % terminal->lineCount;
144 144 terminal->column = 0;
145 145 if(terminal->line==0)
146 146 terminal_clear(terminal);
147 147 else
148 148 terminal_clearCurentLine(terminal);
149 149 }else {
150 150 if(buffer[0]=='\t')
151 151 {
152 152 for(int i=0;i<1;i++)terminal_movecursor(terminal,1);
153 153 }else
154 154 if(terminal->column==0)terminal_clearCurentLine(terminal);
155 155 if(buffer[0]!='\r'){
156 156 // terminal->LCD->paintFilRect(terminal->LCD,CHARXPOS(terminal,charw),CHARYPOS(terminal, charh)-charh,charw,charh,terminal->backgroundColor,0,terminal->backgroundColor);
157 // terminal->LCD->paintText(terminal->LCD,buffer,CHARXPOS(terminal,charw),(CHARYPOS(terminal, charh))-(terminal->verticalSpace/2),terminal->font,terminal->textColor);
158 #include <ili9328.h>
159 ili9328paintChar(terminal->LCD,buffer[0],CHARXPOS(terminal,charw),(CHARYPOS(terminal, charh))-(terminal->verticalSpace/2),terminal->font,terminal->textColor);
157 terminal->LCD->paintText(terminal->LCD,buffer,CHARXPOS(terminal,charw),(CHARYPOS(terminal, charh))-(terminal->verticalSpace/2),terminal->font,terminal->textColor);
158 //#include <ili9328.h>
159 // ili9328paintChar(terminal->LCD,buffer[0],CHARXPOS(terminal,charw),(CHARYPOS(terminal, charh))-(terminal->verticalSpace/2),terminal->font,terminal->textColor);
160 160 terminal_movecursor(terminal,1);
161 161 }
162 162 }
163 163 l++;
164 164 }
165 165 return n;
166 166 }
167 167
168 168 void terminal_print_line(terminal_t* terminal,int line)
169 169 {
170 170 int charw=terminal->font->Width + terminal->horizontalSpace;
171 171 int charh=terminal->font->Height + terminal->verticalSpace;
172 172 terminal_clearCurentLine(terminal);
173 173 terminal->LCD->paintText(terminal->LCD,terminal->buffer+(line*(terminal->columnCount + 1)),CHARXPOS(terminal,charw),CHARYPOS(terminal, charh),terminal->font,terminal->textColor);
174 174 }
175 175
176 176 int terminal_writenc2(terminal_t* terminal,char* data, int n)
177 177 {
178 178 int charw=terminal->font->Width + terminal->horizontalSpace;
179 179 int charh=terminal->font->Height + terminal->verticalSpace;
180 180 /* First copy to buffer*/
181 181 int offset = (terminal->lastLine*(terminal->columnCount + 1)) + terminal->column;
182 182 for(int i=0;i<n;i++)
183 183 {
184 184 terminal->empty=0;
185 185 terminal->buffer[offset] = data[i];
186 186 if(data[i]=='\n')
187 187 {
188 188 offset = ((offset/(terminal->columnCount + 1) + 1) * (terminal->columnCount + 1));
189 189 }
190 190 else
191 191 {
192 192 offset++;
193 193 }
194 194 }
195 195 if(!terminal->empty)
196 196 {
197 197 for(int i=terminal->firstLine;i<=terminal->lastLine;i++)
198 198 {
199 199 terminal_print_line(terminal,i);
200 200 }
201 201 }
202 202 return n;
203 203 }
204 204
205 205
206 206
207 207 int terminal_write(streamdevice* device,void* data,int size, int n)
208 208 {
209 209 return terminal_writenc((terminal_t*)device->_stream,(char*) data,size*n);
210 210 }
211 211
212 212 int terminal_read(streamdevice* device,void* data,int size, int n)
213 213 {
214 214 return n*size;
215 215 }
216 216
217 217 int terminal_setpos(streamdevice* device,int pos)
218 218 {
219 219 return 1;
220 220 }
221 221
222 222 int terminal_close( streamdevice* device)
223 223 {
224 224 return 1;
225 225 }
226 226
227 227
228 228
229 229
230 230
231 231
232 232
233 233
234 234
235 235
236 236
237 237
238 238
239 239
@@ -1,196 +1,195
1 1 /*------------------------------------------------------------------------------
2 2 -- This file is a part of the libuc, microcontroler library
3 3 -- Copyright (C) 2012, Alexis Jeandet
4 4 --
5 5 -- This program is free software; you can redistribute it and/or modify
6 6 -- it under the terms of the GNU General Public License as published by
7 7 -- the Free Software Foundation; either version 3 of the License, or
8 8 -- (at your option) any later version.
9 9 --
10 10 -- This program is distributed in the hope that it will be useful,
11 11 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
12 12 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 13 -- GNU General Public License for more details.
14 14 --
15 15 -- You should have received a copy of the GNU General Public License
16 16 -- along with this program; if not, write to the Free Software
17 -- 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 19 -- Author : Alexis Jeandet
20 20 -- Mail : alexis.jeandet@member.fsf.org
21 21 -------------------------------------------------------------------------------*/
22 22 #ifndef FAT32_H
23 23 #define FAT32_H
24 24 #include <mbr.h>
25 25 #include <libucfs.h>
26 26 #include <ucdirent.h>
27 27 #include <stdint.h>
28 28 #include <stdint-gcc.h>
29 29 /*BPB (Boot Sector) Offsets */
30 30
31 31 #define BS_jmpBootoff 0
32 32 #define BS_OEMNameoff 3
33 33 #define BPB_BytsPerSecoff 11
34 34 #define BPB_SecPerClusoff 13
35 35 #define BPB_RsvdSecCntoff 14
36 36 #define BPB_NumFATsoff 16
37 37 #define BPB_RootEntCntoff 17
38 38 #define BPB_TotSec16off 19
39 39 #define BPB_Mediaoff 21
40 40 #define BPB_FATSz16off 22
41 41 #define BPB_SecPerTrkoff 24
42 42 #define BPB_NumHeadsoff 26
43 43 #define BPB_HiddSecoff 28
44 44 #define BPB_TotSec32off 32
45 45 /*FAT16*/
46 46 #define BS_DrvNumFAT16off 36
47 47 #define BS_Reserved1FAT16off 37
48 48 #define BS_BootSigFAT16off 38
49 49 #define BS_VolIDFAT16off 39
50 50 #define BS_VolLabFAT16off 43
51 51 #define BS_FilSysTypeFAT16off 54
52 52 /*FAT32*/
53 53 #define BPB_FATSz32off 36
54 54 #define BPB_ExtFlagsoff 40
55 55 #define BPB_FSVeroff 42
56 56 #define BPB_RootClusoff 44
57 57 #define BPB_FSInfooff 48
58 58 #define BPB_BkBootSecoff 50
59 59 #define BPB_Reservedoff 52
60 60 #define BS_DrvNumFAT32off 64
61 61 #define BS_Reserved1FAT32off 65
62 62 #define BS_BootSigFAT32off 66
63 63 #define BS_VolIDFAT32off 67
64 64 #define BS_VolLabFAT32off 71
65 65 #define BS_FilSysTypeFAT32off 82
66 66
67 67
68 68 #define DIR_Nameoff 0
69 69 #define DIR_Attroff 0xb
70 70 #define DIR_FstClusHIoff 0x14
71 71 #define DIR_FstClusLOoff 0x1A
72 72 #define DIR_FileSizeoff 0x1c
73 73 #define DIR_CrtTimeTenthoff 13
74 74 #define DIR_CrtTimeoff 14
75 75 #define DIR_CrtDateoff 16
76 76 #define DIR_LstAccDateoff 18
77 77 #define DIR_WrtTimeoff 22
78 78 #define DIR_WrtDateoff 24
79 79
80 80
81 81
82 82 #define FATBadpart 1
83 83 #define FATBabArg 2
84 84 #define FATReadErr 3
85 85 #define FATnoErr 0
86 86
87 87 /*
88 88 TODO :
89 89 intergrate a per BLKDEV or per partition buffer.
90 90 */
91 91 typedef struct FAT32fs
92 92 {
93 93 uint16_t BPB_BytsPerSec;
94 94 uint16_t BPB_RsvdSecCnt;
95 95 uint32_t BPB_FATSz32;
96 96 uint32_t BPB_RootClus;
97 97 uint32_t fat_begin_lba;
98 98 uint32_t cluster_begin_lba;
99 99 uint8_t BPB_SecPerClus;
100 100 uint8_t BPB_NumFATs;
101 101 char valide;
102 dikpartition* part;
102 dikpartition* part;
103 103 }FAT32fs;
104 104
105 105
106 106 #define castUI64(val) ((uint64_t)(val))
107 107 #define castUI32(val) ((uint32_t)(val))
108 108 #define castUI16(val) ((uint16_t)(val))
109 109 #define castUI8(val) ((uint8_t)(val))
110 110
111 111 #define castI64(val) ((int64_t)(val))
112 112 #define castI32(val) ((int32_t)(val))
113 113 #define castI16(val) ((int16_t)(val))
114 114 #define castI8(val) ((int8_t)(val))
115 115
116 116 /*
117 117 TODO :
118 118 Should add global function for casting with endianness care.
119 119 have a look at REV, REV16, REVSH, and RBIT ARMV7m asm
120 120 */
121 121
122 122 #if __BYTE_ORDER__==__ORDER_BIG_ENDIAN__
123 123 #define fat32Ui8_2_Ui32(table,lsBindex) ((uint32_t)((0xFF&(table[lsBindex]))+(0xFF00&(((uint32_t)table[lsBindex+1])<<8))+(0xFF0000&(((uint32_t)table[lsBindex+2])<<16))+(0xFF000000&(((uint32_t)table[lsBindex+3])<<24))))
124 124 #define fat32Ui8_2_Ui16(table,lsBindex) ((uint16_t)((0xFF&(table[lsBindex]))+(0xFF00&(((uint16_t)table[lsBindex+1])<<8))))
125 125 #define fat32extract16b(table, LSBOffset) (uint16_t)(( (uint16_t) ((uint8_t)table[(LSBOffset)]) ) + (uint16_t)( ((uint8_t)table[(LSBOffset)+1]) << 8 ))
126 126 #define fat32extract32b(table, LSBOffset) (uint32_t)(( (uint32_t) ((uint8_t)table[(LSBOffset)]) ) + (uint32_t)( ((uint8_t)table[(LSBOffset)+1]) << 8 )+ (uint32_t)( ((uint8_t)table[(LSBOffset)+2]) << 16 )+ (uint32_t)( ((uint8_t)table[(LSBOffset)+3]) << 24 ))
127 127 #else
128 128 #define fat32Ui8_2_Ui32(table,lsBindex) ((uint32_t)((0xFF&(table[lsBindex]))+(0xFF00&(((uint32_t)table[lsBindex+1])<<8))+(0xFF0000&(((uint32_t)table[lsBindex+2])<<16))+(0xFF000000&(((uint32_t)table[lsBindex+3])<<24))))
129 129 #define fat32Ui8_2_Ui16(table,lsBindex) ((uint16_t)((0xFF&(table[lsBindex]))+(0xFF00&(((uint16_t)table[lsBindex+1])<<8))))
130 130 #define fat32extract16b(table, LSBOffset) (uint16_t)(( (uint16_t) ((uint8_t)table[(LSBOffset)]) ) + (uint16_t)( ((uint8_t)table[(LSBOffset)+1]) << 8 ))
131 131 #define fat32extract32b(table, LSBOffset) (uint32_t)(( (uint32_t) ((uint8_t)table[(LSBOffset)]) ) + (uint32_t)( ((uint8_t)table[(LSBOffset)+1]) << 8 )+ (uint32_t)( ((uint8_t)table[(LSBOffset)+2]) << 16 )+ (uint32_t)( ((uint8_t)table[(LSBOffset)+3]) << 24 ))
132 132 #endif
133 133
134 134
135 135 /* Get the first sector lba of given cluster number*/
136 136 #define clusterlba(fs,cluster_number) ((uint32_t)fs->cluster_begin_lba + (((uint32_t)cluster_number) - (2)) * (uint32_t)fs->BPB_SecPerClus)
137 137
138 138 //#define fat32clusterinfatsect(fs,cluster_number) ((((uint32_t)(cluster_number))>>6) + fs->fat_begin_lba)
139 139 #define fat32clusterinfatsect(fs,cluster_number) ((((uint32_t)(cluster_number))>>7) + fs->fat_begin_lba)
140 140 #define fat32clusterinfatoff(cluster_number) (((cluster_number)&0x7F)*4)
141 141
142 142 /*Get cluster index in FAT Table from sector address*/
143 143 #define fat32masksectorlba(sectorlba,fs) (sectorlba)//(sectorlba & (castUI32(-1)^castUI32(fs->BPB_SecPerClus-1)))
144 144 #define fat32sectorlbatoclusternum(fs,sectorlba) (((fat32masksectorlba(castUI32(sectorlba),fs) -(castUI32(fs->cluster_begin_lba)))/castUI32(fs->BPB_SecPerClus))+castUI32(2))
145 145
146 146
147 147 #ifdef FAT32_PRIVATE
148 148 #define fat32sectorreadout(fs,fatsec) \
149 149 if((lastSecAddrs!=(fatsec)) || (lastFATFS!=(fs))) /*Check if sector already buffered*/ \
150 150 {\
151 151 if((fs)->part->phy->read((fs)->part->phy,fat32buff,(fatsec),1)!=RES_OK) \
152 152 {\
153 153 return DIRENT_ReadErr;\
154 154 }\
155 155 }\
156 156 lastSecAddrs=(fatsec);\
157 157 lastFATFS=(fs);
158 158 #endif
159 159
160 160 extern int fat32open(FAT32fs* fs,dikpartition* part);
161 161 extern int fat32mkdirent(FAT32fs* fs,ucdirent* dirent);
162 162 extern int fat32getVolName(FAT32fs* fs,char* Name);
163 163 extern int fat32getrootfirstent(ucdirent* entry);
164 164 extern int fat32nextdirent(ucdirent* entry);
165 165 extern int fat32nextsectorlba(FAT32fs* fs,uint32_t lastsector_lba,uint32_t* nextsector_lba);
166 166 extern int fat32prevsectorlba(FAT32fs* fs,uint32_t lastsector_lba,uint32_t *nextsector_lba);
167 167 extern int fat32prevsectorlba2(FAT32fs* fs,ucdirent* entry,uint32_t lastsector_lba,uint32_t *nextsector_lba);
168 168 extern uint32_t fat32getdirentlba(ucdirent* entry);
169 169 extern int fat32getdirentname(ucdirent* entry,char* nameBuffer);
170 170
171 171 #endif
172 172
173 173
174 174
175 175
176 176
177 177
178 178
179 179
180 180
181 181
182 182
183 183
184 184
185 185
186 186
187 187
188 188
189 189
190 190
191 191
192 192
193 193
194 194
195 195
196
@@ -1,115 +1,116
1 1 #include <stdio.h>
2 2 #include <sdcard.h>
3 3 #include <sdcard-spi.h>
4 4
5 FILE* sdcardimg;
5 FILE* sdcardimg=NULL;
6 6
7 7
8 8 void sdcardmake(sdcardDev* sdcard,UHANDLE phy,void (*rcvr_mmc) (UHANDLE,char *,unsigned int ),void (*xmit_mmc) (UHANDLE,const char *,unsigned int ),void (*setspeed) (UHANDLE phy,unsigned int speed),unsigned int (*getspeed) (UHANDLE phy))
9 9 {
10 10
11 11 }
12 12
13 13
14 14 int sdcardselect (blkdevice* _this)
15 15 {
16 16 return 1;
17 17 }
18 18
19 19
20 20 void sdcarddeselect (blkdevice* _this)
21 21 {
22 22
23 23 }
24 24
25 25 int sdcardwait_ready (sdcardDev* sdcard)
26 26 {
27 27 return 1;
28 28 }
29 29
30 30 void sdcardpower (blkdevice* _this)
31 31 {
32 32
33 33 }
34 34
35 35 char sdcarddetect (blkdevice* _this)
36 36 {
37 37 return 1;
38 38 }
39 39
40 40 char sdcardwriteprotected (blkdevice* _this)
41 41 {
42 42 return 0;
43 43 }
44 44
45 45
46 46
47 47 int sdcardxmit_datablock (sdcardDev* sdcard,const char *buff,char token)
48 48 {
49 49 return 1;
50 50 }
51 51
52 52 int sdcardrcvr_datablock (sdcardDev* sdcard,char *buff,unsigned int btr)
53 53 {
54 54 return 1;
55 55 }
56 56
57 57 char sdcardsend_cmd (blkdevice* _this,char cmd,unsigned int arg)
58 58 {
59 59 return 1;
60 60 }
61 61
62 62 DSTATUS sdcarddisk_status (blkdevice* _this)
63 63 {}
64 64
65 65 DSTATUS sdcarddisk_initialize (blkdevice* _this)
66 66 {}
67 67
68 68 DRESULT sdcarddisk_read (blkdevice* _this,char *buff,unsigned long sector,char count)
69 69 {
70 if(sdcardimg==NULL)return RES_ERROR;
70 71 int res = fseek(sdcardimg, sector*(unsigned long)512, SEEK_SET);
71 72 if(count*512== fread(buff,1,count*512,sdcardimg))
72 73 return RES_OK;
73 74 return RES_ERROR;
74 75 }
75 76
76 77 DRESULT sdcarddisk_write (blkdevice* _this,const char *buff,unsigned long sector,char count)
77 78 {
79 if(sdcardimg==NULL)return RES_ERROR;
78 80 fseek(sdcardimg, sector*(unsigned long)512, SEEK_SET);
79 81 fwrite(buff,1,count*512,sdcardimg);
80 82 return RES_OK;
81 83 }
82 84
83 85 DRESULT sdcarddisk_ioctl (blkdevice* _this,char ctrl,void *buff)
84 86 {}
85 87
86 88
87 89 void sdcardspimakeblkdev(blkdevice* dev,sdcardDev* sdcard, blkdevselect_t select,blkdevpower_t power,blkdevdetect_t detect,blkdevwriteprotected_t writeprotected)
88 90 {
89 sdcardimg=fopen("sdcard.bin","rb");
91 sdcardimg=fopen("/dev/sdc","rb");
90 92 // sdcardimg=fopen("usbkey.bin","rb");
91 93 if(sdcardimg!=NULL)printf("ok sdcard openned\n");
92 94 else printf("Nok sdcard not openned\n");
93 95 dev->phy=NULL;
94 96 dev->select= (blkdevselect_t)select;
95 97 dev->power = (blkdevpower_t)power;
96 98 dev->detect = (blkdevdetect_t)detect;
97 99 dev->writeprotected = (blkdevwriteprotected_t)writeprotected;
98 100 dev->write = sdcarddisk_write;
99 101 dev->read = sdcarddisk_read;
100 102 dev->ioctl = sdcarddisk_ioctl;
101 103 dev->initialize = sdcarddisk_initialize;
102 104 dev->status = sdcarddisk_status;
103 printf("sdcard opened\n");
104 105 }
105 106
106 107
107 108
108 109
109 110
110 111
111 112
112 113
113 114
114 115
115 116
@@ -1,316 +1,333
1 1 /*------------------------------------------------------------------------------
2 2 -- This file is a part of the libuc, microcontroler library
3 3 -- Copyright (C) 2013, Alexis Jeandet
4 4 --
5 5 -- This program is free software; you can redistribute it and/or modify
6 6 -- it under the terms of the GNU General Public License as published by
7 7 -- the Free Software Foundation; either version 3 of the License, or
8 8 -- (at your option) any later version.
9 9 --
10 10 -- This program is distributed in the hope that it will be useful,
11 11 -- but WITHOUT ANY WARRANTY; without even the implied warranty of
12 12 -- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 13 -- GNU General Public License for more details.
14 14 --
15 15 -- You should have received a copy of the GNU General Public License
16 16 -- along with this program; if not, write to the Free Software
17 17 -- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 18 -------------------------------------------------------------------------------
19 19 -- Author : Alexis Jeandet
20 20 -- Mail : alexis.jeandet@member.fsf.org
21 21 -------------------------------------------------------------------------------*/
22 22
23 23 #include <SDL.h>
24 24 #include <malloc.h>
25 25 #include "SDLCD.h"
26 26
27 27 SDL_Surface *screen;
28 28 SDL_Overlay *bmp;
29 29
30 30 int SDLCD_Xpos=0;
31 31 int SDLCD_Ypos=0;
32 32 int SDLCD_XWinStrt=0;
33 33 int SDLCD_YWinStrt=0;
34 34 int SDLCD_XWinEnd=0;
35 35 int SDLCD_YWinEnd=0;
36 36
37 37 void* SDLCD_buffer;
38 38 int SDLCD_bpp;
39 39 void SDLCD_putpixel(SDL_Surface *surface, int x, int y, Uint32 pixel);
40 40
41 static Uint32 sdl_refresh_timer(Uint32 interval, void *opaque) {
42
43 if ( SDL_MUSTLOCK(screen) ) {
44 if ( SDL_LockSurface(screen) < 0 ) {
45 fprintf(stderr, "Can’t lock screen: %s\n", SDL_GetError());
46 return interval;
47 }
48 }
49 //SDL_UpdateRect(screen, 0, 0, screen->w, screen->h);
50 SDL_Flip(screen);
51 if ( SDL_MUSTLOCK(screen) ) {
52 SDL_UnlockSurface(screen);
53 }
54 return interval; /* 0 means stop timer */
55 }
56
41 57 void SDLCD_mkscreen(int resx,int resy,int bpp,int lcdtype)
42 58 {
43 59 int i=0;
44 60 if(SDL_Init(SDL_INIT_VIDEO | SDL_INIT_TIMER)) {
45 61 fprintf(stderr, "Could not initialize SDL - %s\n", SDL_GetError());
46 62 exit(1);
47 63 }
48 screen = SDL_SetVideoMode(resx, resy, bpp, 0);
64 screen = SDL_SetVideoMode(resx, resy, bpp, SDL_DOUBLEBUF);
49 65 if(!screen) {
50 66 fprintf(stderr, "SDL: could not set video mode - exiting\n");
51 67 exit(1);
52 68 }
53 69 if ( SDL_MUSTLOCK(screen) ) {
54 70 if ( SDL_LockSurface(screen) < 0 ) {
55 71 fprintf(stderr, "Can’t lock screen: %s\n", SDL_GetError());
56 72 return;
57 73 }
58 74 }
75 SDL_UpdateRect(screen, 0, 0, resx, resy);
59 76 if ( SDL_MUSTLOCK(screen) ) {
60 77 SDL_UnlockSurface(screen);
61 78 }
62 SDL_UpdateRect(screen, 0, 0, resx, resy);
63 79 SDLCD_buffer = malloc(resx*resy*bpp/8);
64 80 SDLCD_bpp = bpp;
65 81 for(i=0;i<(resx*resy);i++)
66 82 {
67 83 SDLCD_putpixel(screen, i%resx, (i/resx), 0xFFFF);
68 84 }
85 SDL_AddTimer(10, sdl_refresh_timer, NULL);
69 86 }
70 87
71 88
72 89
73 90 int SDLCD_init()
74 91 {
75 92
76 93 }
77 94
78 95 void SDLCD_writereg(uint32_t reg,uint32_t data)
79 96 {
80 97 switch (reg) {
81 98 case ILI9328_REGISTER_HORIZONTALGRAMADDRESSSET:
82 99 if((data>=screen->w) || (data<0))
83 100 printf("Warning printing out of bounds HORIZONTALGRAMADDRESSSET=%d",data);
84 101 SDLCD_Xpos = data;
85 102 break;
86 103 case ILI9328_REGISTER_VERTICALGRAMADDRESSSET:
87 104 if((data>=screen->h) || (data<0))
88 105 printf("Warning printing out of bounds ILI9328_REGISTER_VERTICALGRAMADDRESSSET=%d",data);
89 106 SDLCD_Ypos = data;
90 107 break;
91 108 case ILI9328_REGISTER_HORIZONTALADDRESSSTARTPOSITION:
92 109 if((data>=screen->w) || (data<0))
93 110 printf("Warning printing out of bounds ILI9328_REGISTER_HORIZONTALADDRESSSTARTPOSITION=%d",data);
94 111 SDLCD_XWinStrt = data;
95 112 break;
96 113 case ILI9328_REGISTER_HORIZONTALADDRESSENDPOSITION:
97 114 if((data>=screen->w) || (data<0))
98 115 printf("Warning printing out of bounds ILI9328_REGISTER_HORIZONTALADDRESSENDPOSITION=%d",data);
99 116 SDLCD_XWinEnd = data;
100 117 break;
101 118 case ILI9328_REGISTER_VERTICALADDRESSSTARTPOSITION:
102 119 if((data>=screen->h) || (data<0))
103 120 printf("Warning printing out of bounds ILI9328_REGISTER_VERTICALADDRESSSTARTPOSITION=%d",data);
104 121 SDLCD_YWinStrt = data;
105 122 break;
106 123 case ILI9328_REGISTER_VERTICALADDRESSENDPOSITION:
107 124 if((data>=screen->h) || (data<0))
108 125 printf("Warning printing out of bounds ILI9328_REGISTER_VERTICALADDRESSENDPOSITION=%d",data);
109 126 SDLCD_YWinEnd = data;
110 127 break;
111 128 default:
112 129 break;
113 130 }
114 131 }
115 132
116 133 uint32_t SDLCD_readreg(uint32_t reg)
117 134 {
118 135 return 0;
119 136 }
120 137
121 138
122 139 void SDLCD_putpixel(SDL_Surface *surface, int x, int y, Uint32 pixel)
123 140 {
124 141 int bpp = surface->format->BytesPerPixel;
125 142 /* Here p is the address to the pixel we want to set */
126 143 Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp;
127 144 switch(bpp) {
128 145 case 1:
129 146 *p = pixel;
130 147 break;
131 148 case 2:
132 149 *(Uint16 *)p = pixel;
133 150 break;
134 151 case 3:
135 152 if(SDL_BYTEORDER == SDL_BIG_ENDIAN) {
136 153 p[0] = (pixel >> 16) & 0xff;
137 154 p[1] = (pixel >> 8) & 0xff;
138 155 p[2] = pixel & 0xff;
139 156 } else {
140 157 p[0] = pixel & 0xff;
141 158 p[1] = (pixel >> 8) & 0xff;
142 159 p[2] = (pixel >> 16) & 0xff;
143 160 }
144 161 break;
145 162 case 4:
146 163 *(Uint32 *)p = pixel;
147 164 break;
148 165 }
149 166 }
150 167
151 168 void SDLCD_putpixel_16bpp(SDL_Surface *surface, int x, int y, Uint32 pixel)
152 169 {
153 170 Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * surface->format->BytesPerPixel;
154 171 *(Uint16 *)p = pixel;
155 172 }
156 173
157 174 Uint32 SDLCD_getpixel_16bpp(SDL_Surface *surface, int x, int y)
158 175 {
159 176 Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * surface->format->BytesPerPixel;
160 177 return *(Uint16 *)p;
161 178 }
162 179
163 180 Uint32 SDLCD_getpixel(SDL_Surface *surface, int x, int y)
164 181 {
165 182 int bpp = surface->format->BytesPerPixel;
166 183 /* Here p is the address to the pixel we want to retrieve */
167 184 Uint8 *p = (Uint8 *)surface->pixels + y * surface->pitch + x * bpp;
168 185 switch(bpp) {
169 186 case 1:
170 187 return *p;
171 188 case 2:
172 189 return *(Uint16 *)p;
173 190 case 3:
174 191 if(SDL_BYTEORDER == SDL_BIG_ENDIAN)
175 192 return p[0] << 16 | p[1] << 8 | p[2];
176 193 else
177 194 return p[0] | p[1] << 8 | p[2] << 16;
178 195 case 4:
179 196 return *(Uint32 *)p;
180 197 default:
181 198 return 0;
182 199 }
183 200 /* shouldn’t happen, but avoids warnings */
184 201 }
185 202
186 203 void SDLCD_writeGRAM(void* buffer,uint32_t count)
187 204 {
188 205 int i=0;
189 206 u_int16_t* ptr=(u_int16_t*)SDLCD_buffer;
190 207 u_int16_t* inptr=(u_int16_t*)buffer;
191 208 if ( SDL_MUSTLOCK(screen) ) {
192 209 if ( SDL_LockSurface(screen) < 0 ) {
193 210 fprintf(stderr, "Can’t lock screen: %s\n", SDL_GetError());
194 211 return;
195 212 }
196 213 }
197 214 for(i=0;i<count;i++)
198 215 {
199 216 SDLCD_putpixel_16bpp(screen,SDLCD_Xpos,SDLCD_Ypos,inptr[i]);
200 217 SDLCD_Xpos+=1;
201 218 ptr[i]=inptr[i];
202 219 if(SDLCD_Xpos>=SDLCD_XWinEnd)
203 220 {
204 221 SDLCD_Xpos=SDLCD_XWinStrt;
205 222 SDLCD_Ypos+=1;
206 223 }
207 224 if(SDLCD_Ypos>=SDLCD_YWinEnd)
208 225 {
209 226 SDLCD_Ypos=SDLCD_YWinStrt;
210 227 }
211 228 }
212 229 if ( SDL_MUSTLOCK(screen) ) {
213 230 SDL_UnlockSurface(screen);
214 231 }
215 232 // SDL_UpdateRect(screen, SDLCD_XWinStrt, SDLCD_YWinStrt, SDLCD_XWinEnd-SDLCD_XWinStrt, SDLCD_YWinEnd-SDLCD_YWinStrt);
216 SDL_UpdateRect(screen, 0, 0, screen->w, screen->h);
233 //SDL_UpdateRect(screen, 0, 0, screen->w, screen->h);
217 234 }
218 235
219 236 void SDLCD_writeGRAM_16bpp(void* buffer,uint32_t count)
220 237 {
221 238 int i=0;
222 239 u_int16_t* inptr=(u_int16_t*)buffer;
223 240 if ( SDL_MUSTLOCK(screen) ) {
224 241 if ( SDL_LockSurface(screen) < 0 ) {
225 242 fprintf(stderr, "Can’t lock screen: %s\n", SDL_GetError());
226 243 return;
227 244 }
228 245 }
229 246 for(i=0;i<count;i++)
230 247 {
231 248 *(( Uint16 * ) screen->pixels + SDLCD_Ypos * screen->pitch / 2 + SDLCD_Xpos)=inptr[i];
232 249 SDLCD_Xpos+=1;
233 250 if(SDLCD_Xpos>=SDLCD_XWinEnd)
234 251 {
235 252 SDLCD_Xpos=SDLCD_XWinStrt;
236 253 SDLCD_Ypos+=1;
237 254 }
238 255 if(SDLCD_Ypos>=SDLCD_YWinEnd)
239 256 {
240 257 SDLCD_Ypos=SDLCD_YWinStrt;
241 258 }
242 259 }
243 260 if ( SDL_MUSTLOCK(screen) ) {
244 261 SDL_UnlockSurface(screen);
245 262 }
246 263 // SDL_UpdateRect(screen, SDLCD_XWinStrt, SDLCD_YWinStrt, SDLCD_XWinEnd-SDLCD_XWinStrt, SDLCD_YWinEnd-SDLCD_YWinStrt);
247 SDL_UpdateRect(screen, 0, 0, screen->w, screen->h);
264 //SDL_UpdateRect(screen, 0, 0, screen->w, screen->h);
248 265 }
249 266
250 267 void SDLCD_readGRAM_16bpp(void* buffer,uint32_t count)
251 268 {
252 269 int i=0;
253 270 u_int16_t* ptr=(u_int16_t*)SDLCD_buffer;
254 271 u_int16_t* inptr=(u_int16_t*)buffer;
255 272 for(i=0;i<count;i++)
256 273 {
257 274 inptr[i]=*(( Uint16 * ) screen->pixels + SDLCD_Ypos * screen->pitch / 2 + SDLCD_Xpos);
258 275 SDLCD_Xpos+=1;
259 276 ptr[i]=inptr[i];
260 277 if(SDLCD_Xpos>=SDLCD_XWinEnd)
261 278 {
262 279 SDLCD_Xpos=SDLCD_XWinStrt;
263 280 SDLCD_Ypos+=1;
264 281 }
265 282 if(SDLCD_Ypos>=SDLCD_YWinEnd)
266 283 {
267 284 SDLCD_Ypos=SDLCD_YWinStrt;
268 285 }
269 286 }
270 287
271 288 }
272 289
273 290 void SDLCD_readGRAM(void* buffer,uint32_t count)
274 291 {
275 292 int i=0;
276 293 u_int16_t* ptr=(u_int16_t*)SDLCD_buffer;
277 294 u_int16_t* inptr=(u_int16_t*)buffer;
278 295 for(i=0;i<count;i++)
279 296 {
280 297 inptr[i]=SDLCD_getpixel_16bpp(screen,SDLCD_Xpos,SDLCD_Ypos);
281 298 SDLCD_Xpos+=1;
282 299 ptr[i]=inptr[i];
283 300 if(SDLCD_Xpos>=SDLCD_XWinEnd)
284 301 {
285 302 SDLCD_Xpos=SDLCD_XWinStrt;
286 303 SDLCD_Ypos+=1;
287 304 }
288 305 if(SDLCD_Ypos>=SDLCD_YWinEnd)
289 306 {
290 307 SDLCD_Ypos=SDLCD_YWinStrt;
291 308 }
292 309 }
293 310
294 311 }
295 312
296 313
297 314
298 315
299 316
300 317
301 318
302 319
303 320
304 321
305 322
306 323
307 324
308 325
309 326
310 327
311 328
312 329
313 330
314 331
315 332
316 333
General Comments 0
You need to be logged in to leave comments. Login now