@@ -334,6 +334,113 @@ static spi_command_t cmd_data_read = {
334334 .operation = SPI_RECV ,
335335};
336336
337+ // REVISIT: We are not supposed to include these. These are here just to have
338+ // some placeholder data to play with until read/write are implemented
339+ #include "genhdr/mpversion.h"
340+ #include <pbsys/storage.h>
341+
342+ static pbio_error_t delete_me_load_placeholder_data (uint32_t offset , uint8_t * buffer , uint32_t size ) {
343+
344+ // This is a compiled version of the following. It:
345+ // - blinks the LED
346+ // - increments a persistent counter each time you run it
347+ //
348+ // For now, it increases the count each time you press the center button.
349+ // For now, it resets to 0 on shutdown and restart. If read and write are
350+ // implemented, the value is persistent!
351+ /*
352+
353+ from pybricks.hubs import EV3Brick
354+ from pybricks.parameters import Color
355+ from pybricks.tools import wait
356+
357+ hub = EV3Brick()
358+
359+ count = hub.system.storage(0, read=1)[0]
360+ hub.system.storage(0, write=bytes([(count + 1) % 256]))
361+
362+ print("Persistent count:", count)
363+
364+ while True:
365+ hub.light.on(Color.RED)
366+ wait(500)
367+ hub.light.on(Color.GREEN)
368+ wait(500)
369+ */
370+
371+
372+ static const uint8_t _program_data [] = {
373+ 0x43 , 0x01 , 0x00 , 0x00 , 0x5F , 0x5F , 0x6D , 0x61 ,
374+ 0x69 , 0x6E , 0x5F , 0x5F , 0x00 , 0x4D , 0x06 , 0x00 ,
375+ 0x1F , 0x14 , 0x01 , 0x0E , 0x74 , 0x65 , 0x73 , 0x74 ,
376+ 0x2E , 0x70 , 0x79 , 0x00 , 0x0F , 0x10 , 0x45 , 0x56 ,
377+ 0x33 , 0x42 , 0x72 , 0x69 , 0x63 , 0x6B , 0x00 , 0x1A ,
378+ 0x70 , 0x79 , 0x62 , 0x72 , 0x69 , 0x63 , 0x6B , 0x73 ,
379+ 0x2E , 0x68 , 0x75 , 0x62 , 0x73 , 0x00 , 0x0A , 0x43 ,
380+ 0x6F , 0x6C , 0x6F , 0x72 , 0x00 , 0x26 , 0x70 , 0x79 ,
381+ 0x62 , 0x72 , 0x69 , 0x63 , 0x6B , 0x73 , 0x2E , 0x70 ,
382+ 0x61 , 0x72 , 0x61 , 0x6D , 0x65 , 0x74 , 0x65 , 0x72 ,
383+ 0x73 , 0x00 , 0x08 , 0x77 , 0x61 , 0x69 , 0x74 , 0x00 ,
384+ 0x1C , 0x70 , 0x79 , 0x62 , 0x72 , 0x69 , 0x63 , 0x6B ,
385+ 0x73 , 0x2E , 0x74 , 0x6F , 0x6F , 0x6C , 0x73 , 0x00 ,
386+ 0x0C , 0x73 , 0x79 , 0x73 , 0x74 , 0x65 , 0x6D , 0x00 ,
387+ 0x0E , 0x73 , 0x74 , 0x6F , 0x72 , 0x61 , 0x67 , 0x65 ,
388+ 0x00 , 0x81 , 0x7B , 0x82 , 0x49 , 0x0A , 0x6C , 0x69 ,
389+ 0x67 , 0x68 , 0x74 , 0x00 , 0x04 , 0x6F , 0x6E , 0x00 ,
390+ 0x06 , 0x52 , 0x45 , 0x44 , 0x00 , 0x0A , 0x47 , 0x52 ,
391+ 0x45 , 0x45 , 0x4E , 0x00 , 0x06 , 0x68 , 0x75 , 0x62 ,
392+ 0x00 , 0x81 , 0x15 , 0x81 , 0x05 , 0x81 , 0x77 , 0x05 ,
393+ 0x11 , 0x50 , 0x65 , 0x72 , 0x73 , 0x69 , 0x73 , 0x74 ,
394+ 0x65 , 0x6E , 0x74 , 0x20 , 0x63 , 0x6F , 0x75 , 0x6E ,
395+ 0x74 , 0x3A , 0x00 , 0x89 , 0x58 , 0x30 , 0x18 , 0x01 ,
396+ 0x2C , 0x2C , 0x4C , 0x46 , 0x31 , 0x5B , 0x49 , 0x20 ,
397+ 0x2D , 0x28 , 0x2D , 0x80 , 0x10 , 0x02 , 0x2A , 0x01 ,
398+ 0x1B , 0x03 , 0x1C , 0x02 , 0x16 , 0x02 , 0x59 , 0x80 ,
399+ 0x10 , 0x04 , 0x2A , 0x01 , 0x1B , 0x05 , 0x1C , 0x04 ,
400+ 0x16 , 0x04 , 0x59 , 0x80 , 0x10 , 0x06 , 0x2A , 0x01 ,
401+ 0x1B , 0x07 , 0x1C , 0x06 , 0x16 , 0x06 , 0x59 , 0x11 ,
402+ 0x02 , 0x34 , 0x00 , 0x16 , 0x10 , 0x11 , 0x10 , 0x13 ,
403+ 0x08 , 0x14 , 0x09 , 0x80 , 0x10 , 0x0A , 0x81 , 0x36 ,
404+ 0x82 , 0x01 , 0x80 , 0x55 , 0x16 , 0x11 , 0x11 , 0x10 ,
405+ 0x13 , 0x08 , 0x14 , 0x09 , 0x80 , 0x10 , 0x0B , 0x11 ,
406+ 0x12 , 0x11 , 0x11 , 0x81 , 0xF2 , 0x22 , 0x82 , 0x00 ,
407+ 0xF8 , 0x2B , 0x01 , 0x34 , 0x01 , 0x36 , 0x82 , 0x01 ,
408+ 0x59 , 0x11 , 0x13 , 0x23 , 0x00 , 0x11 , 0x11 , 0x34 ,
409+ 0x02 , 0x59 , 0x11 , 0x10 , 0x13 , 0x0C , 0x14 , 0x0D ,
410+ 0x11 , 0x04 , 0x13 , 0x0E , 0x36 , 0x01 , 0x59 , 0x11 ,
411+ 0x06 , 0x22 , 0x83 , 0x74 , 0x34 , 0x01 , 0x59 , 0x11 ,
412+ 0x10 , 0x13 , 0x0C , 0x14 , 0x0D , 0x11 , 0x04 , 0x13 ,
413+ 0x0F , 0x36 , 0x01 , 0x59 , 0x11 , 0x06 , 0x22 , 0x83 ,
414+ 0x74 , 0x34 , 0x01 , 0x59 , 0x42 , 0x14 , 0x51 , 0x63 ,
415+ };
416+
417+ // The block device normally doesn't need to be aware of this higher level
418+ // data structure, but we use it here to mimic some working data into memory
419+ // so we have something to test against.
420+ static struct {
421+ uint32_t write_size ;
422+ uint8_t user_data [PBSYS_CONFIG_STORAGE_USER_DATA_SIZE ];
423+ char stored_firmware_hash [8 ];
424+ pbsys_storage_settings_t settings ;
425+ uint32_t program_offset ;
426+ uint32_t program_size ;
427+ uint8_t program_data [sizeof (_program_data )];
428+ } disk = { 0 };
429+
430+ // Prepare fake disk data
431+ disk .write_size = sizeof (disk ) + sizeof (_program_data );
432+ disk .program_size = sizeof (_program_data );
433+ memcpy (& disk .stored_firmware_hash [0 ], MICROPY_GIT_HASH , sizeof (disk .stored_firmware_hash ));
434+ memcpy (& disk .program_data [0 ], _program_data , sizeof (_program_data ));
435+
436+ // Initial value of that one user byte:
437+ disk .user_data [0 ] = 123 ;
438+
439+ // Copy requested data to RAM.
440+ memcpy (buffer , (uint8_t * )& disk + offset , size );
441+ return PBIO_SUCCESS ;
442+ }
443+
337444pbio_error_t pbdrv_block_device_read (pbio_os_state_t * state , uint32_t offset , uint8_t * buffer , uint32_t size ) {
338445
339446 static pbio_os_state_t sub ;
@@ -343,6 +450,9 @@ pbio_error_t pbdrv_block_device_read(pbio_os_state_t *state, uint32_t offset, ui
343450
344451 PBIO_OS_ASYNC_BEGIN (state );
345452
453+ // REVSISIT: DELETE ME!
454+ return delete_me_load_placeholder_data (offset , buffer , size );
455+
346456 // Exit on invalid size.
347457 if (size == 0 || offset + size > PBDRV_CONFIG_BLOCK_DEVICE_EV3_SIZE ) {
348458 return PBIO_ERROR_INVALID_ARG ;
0 commit comments