Sonder Design Team / Mbed 2 deprecated BlackBoard_Firmware_Fast_read_not_test

Dependencies:   Memory25L16_fast USBDevice mbed

Fork of BlackBoard_Firmware_MVP by Sonder Design Team

Revision:
5:07113abf18c0
Parent:
4:e6e1642724d4
Child:
6:2f4a272ab299
--- a/BB_Basic.cpp	Wed Jul 27 02:23:21 2016 +0000
+++ b/BB_Basic.cpp	Thu Dec 22 22:16:34 2016 +0000
@@ -283,10 +283,10 @@
  */
 int appendBuffer(int USBDataBuffer[], char memoryBuffer[], int bufferIndex)
 {
-    //pc.printf("\n");
+    //printf("\n");
     int posIndex=0;
     for(int i = 0; i < 64; i++) {
-            //pc.printf("%x ",USBDataBuffer[i]);
+            
         memoryBuffer[bufferIndex+i]=USBDataBuffer[i];
         posIndex++;
     }
@@ -315,6 +315,7 @@
 {
     Timer t;
     t.start();          //Start the timer
+    pc.printf("\nAddress: %i\n", Address);
     int USBDataBuffer [64];             //Creat a buffer for recived data
     char memoryBuffer [bufferSize];     //Create a memory buffer, to be sent to flash
     int bufferIndex = 0;                //points to the next available possition in memory
@@ -334,6 +335,7 @@
             Address = mem.writeData(my_spi, memoryBuffer, Address, bufferSize);
         } else {
             pc.printf("\nCan not write to unerased slot.");
+            Address = mem.writeData(my_spi, memoryBuffer, Address, bufferSize);
         }        
     }
     pc.printf("\n pinnished writing");
@@ -344,6 +346,7 @@
 }
 
 /**
+ * Writes a single memorybuffer to memory
  * receives 64 packets over usb and stores them in memooryBuffer. When memory Buffer is full it is
  * written to memory at address.
  * returns the next availible adsress;
@@ -440,7 +443,7 @@
  */
 void prepImage(SPI my_spi, int slot, char name[])
 {
-    pc.printf("Slot: %i", slots[slot]);
+    pc.printf("\nSlot: %i", slots[slot]);
     mem.blockErase(my_spi, slots[slot]);           //erase the bottom block of the slot
     mem.blockErase(my_spi, slots[slot]+0x10000);   //erase the top block of the slot
     //nameBlock(my_spi, name,  slots[slot]+0x1FFF9); //Write the name of the layout to memory
@@ -468,18 +471,20 @@
 
 
 /*###### EPD Write ######*/
-//Update the whole display with data from memory, starting at the address
+//Update the whole display with data from memory, starting at the 
 int EPD_Write(SPI mem_spi, int address)
 {
-    pc.printf("Address: %i", address);
+    pc.printf("\nAddress: %i", address);
     //Setup the SPIs
     SPI epd_spi = setupEPD();       //Creat a new SPI object to comunicate with the EPD
 
     //Create local variables
-    char sixtyBytes[60];        //Create a line buffer
+    int lineLengh = 60;            //the length of the display in bytes
+    char sixtyBytes[lineLengh];        //Create a line buffer
+    
     //int line = 0;               //counter to keep track of the current line
     //int frameLine = 0;          //counter to keep track of the line in the current frame
-    int lineLengh = 60;
+    
 
     //led=!led;
     //Timer t;
@@ -498,14 +503,14 @@
 
     //loop throug 1440 lines
     for(int j=0; j<1440; j++) {
+        //pc.printf("\n");
         mem.readData(mem_spi, sixtyBytes, address, lineLengh);    //Read the line, putt them in buffer return the next address to read from
-        for(int i =0; i<60; i++) {             //Read one byte from the buffer
+        for(int i =0; i<lineLengh; i++) {             //Read one byte from the buffer
             epd_spi.write(sixtyBytes[i]);      //and write it to the display
-            pc.printf("%i ",sixtyBytes[i]);
+            //pc.printf("%i%i%i%i%i%i%i%i",sixtyBytes[i]>>7&&1,sixtyBytes[i]>>6&&1,sixtyBytes[i]>>5&&1,sixtyBytes[i]>>4&&1,sixtyBytes[i]>>3&&1,sixtyBytes[i]>>2&&1,sixtyBytes[i]>>1&&1,sixtyBytes[i]&&1);
             address++;
             //byteCounter++;
         }
-        pc.printf("\n");
         epd_spi.write(00);      //Write a 0 at the end of each line
         //wait_us(10000);
     }
@@ -565,11 +570,11 @@
                     GlobalAddress = writeFrame(my_spi, USBDataBuffer[2]*65536+USBDataBuffer[3]*256+USBDataBuffer[4]);       //Write the following data to the memory at 24 bit address usbDatabuffer[2-4]
                     break;
                 case 0x11:
-                    pc.printf("\n memory write");
+                    pc.printf("\nPrep write");
                     prepImage(my_spi, USBDataBuffer[2], temp);//Prepare a slot in memory for an image
                     break;
                 case 0x12:
-                    pc.printf("\n Image write");
+                    pc.printf("\nImage write");
                     writeImage(my_spi, USBDataBuffer[2]*65536+USBDataBuffer[3]*256+USBDataBuffer[4]);//Write the next 86400 bytes of data to the memory starting at 24 bit address usbDatabuffer[2-4]
                     break;
                 case 0x20:          //If the recieved comand is a read instruction