Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: Memory25L16_fast USBDevice mbed
Fork of BlackBoard_Firmware_MVP by
Diff: BB_Basic.cpp
- Revision:
- 1:1ec8bcd31b27
- Parent:
- 0:17d169ac117c
- Child:
- 2:8b66a3f7e202
diff -r 17d169ac117c -r 1ec8bcd31b27 BB_Basic.cpp --- a/BB_Basic.cpp Thu Jun 23 22:33:40 2016 +0000 +++ b/BB_Basic.cpp Sun Jun 26 23:01:49 2016 +0000 @@ -55,7 +55,11 @@ int GlobalAddress = 0; //The last adress written to plus one int lastErasedBlock =0; //The Adress of the last erases block int currentName = 0; //The position in the nameList of the curret layout -char nameList[16]; //A list of all the Layouts in memory +char nameList[16][5]; //A list of all the Layouts in memory, each name is 5 bytes long + +//Locations in memory were the 16 layouts can be stored +const int slots [] = {0,0x20000, 0x40000,0x60000, 0x80000, 0xa0000, 0xc0000, 0xe0000, 0x100000, 0x120000,0x140000,0x160000,0x180000, 0x1a0000,0x1e0000}; +bool erasedSlots[]= {false,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false}; int keybuffer[10][2]; //A buffer for storing key presses (mod key plus key) @@ -92,7 +96,7 @@ SPI my_spi(P0_9,P0_8,P0_10); // mosi, miso, sclk //cs_mem = 1; // Chip must be deselected my_spi.format(8,3); // Setup the spi for 8 bit data, low steady state clock, - my_spi.frequency(1000000); // second edge capture, with a 20MHz clock rate + my_spi.frequency(1000000); // second edge capture, with a 1MHz clock rate, Will work up to 20MHz return my_spi; } @@ -269,7 +273,7 @@ /****************************************************************************** - * Display control funtions + * Memory control funtions */ @@ -312,6 +316,8 @@ 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 + /*Timer t; + t.start(); //Start the timer*/ waitForData(USBDataBuffer); //Waits untill data is recieved on usb, puts it in USBDataBuffer while(bufferIndex<bufferSize) { @@ -322,19 +328,24 @@ //Checks if the block has been erased. only virgin bytes can be written to, so if a block has not been errased it is write //protected. this erases a block before writung to it if nessisary. if (Address<lastErasedBlock) { + pc.printf("\nNE"); Address = mem.writeData(my_spi, memoryBuffer, Address, bufferSize); } else { + pc.printf("\nFUUL"); mem.blockErase(my_spi, Address); - lastErasedBlock=Address; + lastErasedBlock=Address+0x10000; Address = mem.writeData(my_spi, memoryBuffer, Address, bufferSize); } + /*t.stop(); + printf("\n%i ", t.read_ms()); + t.reset();*/ return Address; } /** * Sends three reports containing the list of layout names stored in memory. */ -char getNameList() +/*char getNameList() { int temp1[]= {0x31, nameList[0], nameList[1], nameList[2], nameList[3], nameList[4], nameList[5], nameList[6]}; sendUSB(temp1); @@ -344,26 +355,51 @@ sendUSB(temp3); return (char)temp1[1]; } +*/ + +/** + * Sends a report containing a the name of the layout stored at a given slot + */ +void getSlotName(int slot) +{ + int temp [] = {0x31,slot,nameList[slot][0],nameList[slot][1],nameList[slot][2],nameList[slot][3],nameList[slot][4],0}; + sendUSB(temp); +} + + +/** + * Sends three reports containing the list of layout names stored in memory. + */ +void getNameList() +{ + for(int slot =0; slot< 16; slot++) { + getSlotName(slot); + } +} /** * Sends the name of the Current layout */ -char getCurrentLayout() +void getCurrentLayout() { - int temp [] = {0,nameList[currentName],0,0,0,0,0,0}; - sendUSB(temp); - return nameList[currentName]; + getSlotName(currentName); } /** * Writes the name of a given layout to the top memory address in its reserved block + * name[] is a 5 bytes char array with the most significant byte at name[0] */ -void nameBlock(SPI my_spi, char name, int address) +void nameBlock(SPI my_spi, char name[], int address) { - char temp[]= {name}; - mem.writeData(my_spi, temp, address, 1); + //char temp[]= {name}; + mem.writeData(my_spi, name, address, 5); } + +/****************************************************************************** + * Display control funtions + */ + /*###### EPD Set Up ######*/ //Sets up the EPD spi pins SPI setupEPD() @@ -393,8 +429,8 @@ int lineLengh = 60; //led=!led; - Timer t; - t.start(); //Start the timer + //Timer t; + //t.start(); //Start the timer //Begin SPI comunication cs_epd=1; //EPD chip deselected @@ -422,13 +458,13 @@ DigitalOut sclk(P0_13); //serial clk sclk = 0; cs_epd=1; //Deselct the chip - t.stop(); + //t.stop(); wait(10); //Wait 5s for the EPD to update TconEn=0; //Deassert Tcon ON cs_epd=0; //Deassert chip select - printf("\ntime = %i ", t.read_ms()); - t.reset(); + //printf("\ntime = %i ", t.read_ms()); + //t.reset(); return 1; } @@ -438,10 +474,13 @@ */ int main() { + Timer t; + int USBDataBuffer[64]; SPI my_spi = setupSPI(); //Creates an SPI object to comunicate with the external memory while(1) { //pc.printf("Loop"); + sendUSB(readyForComand); if (keyScan()>0) { //check if keyScan returned key presss int countpos =0; @@ -453,17 +492,20 @@ myled=0; } } + sendUSB(readyForComand); if (readUSB(USBDataBuffer)>0) { switch(USBDataBuffer[1]) { - //pc.printf("Switch %i",USBDataBuffer[1]); + //pc.printf("Switch %i",USBDataBuffer[1]); case 0x10: //If the recieved data is a write instruction //check(0); + t.start(); GlobalAddress = writeFrame(my_spi, USBDataBuffer[2]*65536+USBDataBuffer[3]*256+USBDataBuffer[4]); //Write the following data to the memory + t.stop(); break; case 0x20: //If the recieved comand is a read instruction //mem.readData(my_spi, memoryBuffer, USBDataBuffer[2], USBDataBuffer[3]);//read(spi, destination[], address, length) - pc.printf(" \n---EPD UPDATE--- %i",USBDataBuffer[2]*65536+USBDataBuffer[3]*256+USBDataBuffer[4]); + //pc.printf(" \n---EPD UPDATE--- %i",USBDataBuffer[2]*65536+USBDataBuffer[3]*256+USBDataBuffer[4]); EPD_Write(my_spi, USBDataBuffer[2]*65536+USBDataBuffer[3]*256+USBDataBuffer[4]); break; case 0x30: //If the recieved comand is a request for the cutrrent name @@ -476,5 +518,8 @@ pc.printf("fail! %x",USBDataBuffer[1]); } } + + pc.printf("\n%d", t.read_us()); + t.reset(); } }