@@ -67,7 +67,9 @@ bool flash_changed = false;
6767
6868// the setup function runs once when you press reset or power the board
6969void setup () {
70+ #ifdef LED_BUILTIN
7071 pinMode (LED_BUILTIN, OUTPUT);
72+ #endif
7173 Serial.begin (115200 );
7274
7375 // MSC with 2 Logical Units: LUN0: External Flash, LUN1: SDCard
@@ -234,11 +236,12 @@ int32_t sdcard_read_cb (uint32_t lba, void* buffer, uint32_t bufsize)
234236// Callback invoked when received WRITE10 command.
235237// Process data in buffer to disk's storage and
236238// return number of written bytes (must be multiple of block size)
237- int32_t sdcard_write_cb (uint32_t lba, uint8_t * buffer, uint32_t bufsize)
238- {
239+ int32_t sdcard_write_cb (uint32_t lba, uint8_t * buffer, uint32_t bufsize) {
239240 bool rc;
240241
242+ #ifdef LED_BUILTIN
241243 digitalWrite (LED_BUILTIN, HIGH);
244+ #endif
242245
243246#if SD_FAT_VERSION >= 20000
244247 rc = sd.card ()->writeSectors (lba, buffer, bufsize/512 );
@@ -264,7 +267,9 @@ void sdcard_flush_cb (void)
264267
265268 sd_changed = true ;
266269
270+ #ifdef LED_BUILTIN
267271 digitalWrite (LED_BUILTIN, LOW);
272+ #endif
268273}
269274
270275#ifdef SDCARD_DETECT
@@ -299,8 +304,7 @@ bool sdcard_ready_callback(void)
299304// Callback invoked when received READ10 command.
300305// Copy disk's data to buffer (up to bufsize) and
301306// return number of copied bytes (must be multiple of block size)
302- int32_t external_flash_read_cb (uint32_t lba, void * buffer, uint32_t bufsize)
303- {
307+ int32_t external_flash_read_cb (uint32_t lba, void * buffer, uint32_t bufsize) {
304308 // Note: SPIFLash Bock API: readBlocks/writeBlocks/syncBlocks
305309 // already include 4K sector caching internally. We don't need to cache it, yahhhh!!
306310 return flash.readBlocks (lba, (uint8_t *) buffer, bufsize/512 ) ? bufsize : -1 ;
@@ -309,9 +313,10 @@ int32_t external_flash_read_cb (uint32_t lba, void* buffer, uint32_t bufsize)
309313// Callback invoked when received WRITE10 command.
310314// Process data in buffer to disk's storage and
311315// return number of written bytes (must be multiple of block size)
312- int32_t external_flash_write_cb (uint32_t lba, uint8_t * buffer, uint32_t bufsize)
313- {
316+ int32_t external_flash_write_cb (uint32_t lba, uint8_t * buffer, uint32_t bufsize) {
317+ # ifdef LED_BUILTIN
314318 digitalWrite (LED_BUILTIN, HIGH);
319+ #endif
315320
316321 // Note: SPIFLash Bock API: readBlocks/writeBlocks/syncBlocks
317322 // already include 4K sector caching internally. We don't need to cache it, yahhhh!!
@@ -320,14 +325,15 @@ int32_t external_flash_write_cb (uint32_t lba, uint8_t* buffer, uint32_t bufsize
320325
321326// Callback invoked when WRITE10 command is completed (status received and accepted by host).
322327// used to flush any pending cache.
323- void external_flash_flush_cb (void )
324- {
328+ void external_flash_flush_cb (void ) {
325329 flash.syncBlocks ();
326330
327331 // clear file system's cache to force refresh
328332 fatfs.cacheClear ();
329333
330334 flash_changed = true ;
331335
336+ #ifdef LED_BUILTIN
332337 digitalWrite (LED_BUILTIN, LOW);
338+ #endif
333339}
0 commit comments