image/svg+xml
Brteve's API for EveApps
Version 0.0.1
The reference document for common folder of EveApps project.
 
Loading...
Searching...
No Matches
Reader Class Reference

#include <sdcard.h>

Public Member Functions

int openfile (const char *filename)
 
void begin (dirent &de)
 
void nextcluster ()
 
void skipcluster ()
 
void skipsector ()
 
void seek (uint32_t o)
 
void readsector ()
 
void readsector (byte *dst)
 

Data Fields

sdcard SD
 
uint32_t cluster
 
uint32_t offset
 
uint32_t size
 
byte sector
 

Detailed Description

Definition at line 302 of file sdcard.h.

Member Function Documentation

◆ begin()

void Reader::begin ( dirent de)
inline

Definition at line 323 of file sdcard.h.

323 {
324 size = de.size;
325 cluster = de.cluster;
326 if (SD.type == FAT32)
327 cluster |= ((long)de.cluster_hi << 16);
328 sector = 0;
329 offset = 0;
330 }
uint32_t cluster
Definition sdcard.h:392
byte sector
Definition sdcard.h:395
uint32_t offset
Definition sdcard.h:393
uint32_t size
Definition sdcard.h:394
sdcard SD
Definition sdcard.h:304
byte type
Definition sdcard.h:271
#define FAT32
Definition sdcard.h:55
uint16_t cluster
Definition sdcard.h:44
uint32_t size
Definition sdcard.h:45
uint16_t cluster_hi
Definition sdcard.h:41

◆ nextcluster()

void Reader::nextcluster ( )
inline

Definition at line 331 of file sdcard.h.

331 {
332 if (SD.type == FAT16)
333 cluster = SD.rd2(SD.o_fat + 2 * cluster);
334 else
335 cluster = SD.rd4(SD.o_fat + 4 * cluster);
336#if VERBOSE
337 Serial.print("nextcluster=");
338 Serial.println(cluster, DEC);
339#endif
340 }
uint32_t rd4(uint32_t off)
Definition sdcard.h:251
uint16_t rd2(uint32_t off)
Definition sdcard.h:257
uint32_t o_fat
Definition sdcard.h:281
#define FAT16
Definition sdcard.h:54

◆ openfile()

int Reader::openfile ( const char *  filename)
inline

Definition at line 305 of file sdcard.h.

305 {
306 int i = 0;
307 byte dosname[11];
308 dirent de;
309
310 dos83(dosname, filename);
311 do {
312 SD.rdn((byte*)&de, SD.o_root + i * 32, sizeof(de));
313 // Serial.println(de.name);
314 if (0 == memcmp(de.name, dosname, 11)) {
315 begin(de);
316 return 1;
317 }
318 i++;
319 } while (de.name[0]);
320 return 0;
321 }
void begin(dirent &de)
Definition sdcard.h:323
uint32_t o_root
Definition sdcard.h:282
void rdn(byte *d, uint32_t off, uint16_t n)
Definition sdcard.h:238
static void dos83(byte dst[11], const char *ps)
Definition sdcard.h:286

◆ readsector() [1/2]

void Reader::readsector ( )
inline

Definition at line 361 of file sdcard.h.

361 {
363 sector = 0;
364 nextcluster();
365 }
366 uint32_t off = SD.o_data + ((long)SD.cluster_size * cluster) + (512L * sector);
367#if VERBOSE
368 Serial.print("off=0x");
369 Serial.println(off, HEX);
370#endif
371 SD.cmd17(off & ~511L);
372// Serial.println(2 * (micros() - t0), DEC);
373 sector++;
374 offset += 512;
375 }
unsigned int uint32_t
void nextcluster()
Definition sdcard.h:331
void cmd17(uint32_t off)
Definition sdcard.h:228
uint16_t cluster_size
Definition sdcard.h:276
uint32_t o_data
Definition sdcard.h:283
uint16_t sectors_per_cluster
Definition sdcard.h:272

◆ readsector() [2/2]

void Reader::readsector ( byte *  dst)
inline

Definition at line 376 of file sdcard.h.

376 {
377 readsector();
378 for (int i = 0; i < 64; i++) {
379 *dst++ = SPI.transfer(0xff);
380 *dst++ = SPI.transfer(0xff);
381 *dst++ = SPI.transfer(0xff);
382 *dst++ = SPI.transfer(0xff);
383 *dst++ = SPI.transfer(0xff);
384 *dst++ = SPI.transfer(0xff);
385 *dst++ = SPI.transfer(0xff);
386 *dst++ = SPI.transfer(0xff);
387 }
388 SPI.transfer(0xff); // consume CRC
389 SPI.transfer(0xff);
390 SD.desel();
391 }
void readsector()
Definition sdcard.h:361
void desel()
Definition sdcard.h:60

◆ seek()

void Reader::seek ( uint32_t  o)
inline

Definition at line 353 of file sdcard.h.

353 {
354 while (offset < o) {
355 if ((sector == SD.sectors_per_cluster) && ((o - offset) > (long)SD.cluster_size))
356 skipcluster();
357 else
358 skipsector();
359 }
360 }
void skipcluster()
Definition sdcard.h:341
void skipsector()
Definition sdcard.h:345

◆ skipcluster()

void Reader::skipcluster ( )
inline

Definition at line 341 of file sdcard.h.

341 {
342 nextcluster();
344 }

◆ skipsector()

void Reader::skipsector ( )
inline

Definition at line 345 of file sdcard.h.

345 {
347 sector = 0;
348 nextcluster();
349 }
350 sector++;
351 offset += 512;
352 }

Field Documentation

◆ cluster

uint32_t Reader::cluster

Definition at line 392 of file sdcard.h.

◆ offset

uint32_t Reader::offset

Definition at line 393 of file sdcard.h.

◆ SD

sdcard Reader::SD

Definition at line 304 of file sdcard.h.

◆ sector

byte Reader::sector

Definition at line 395 of file sdcard.h.

◆ size

uint32_t Reader::size

Definition at line 394 of file sdcard.h.


The documentation for this class was generated from the following file: