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

Committer:
ThomasSonderDesign
Date:
Wed Jul 27 02:23:21 2016 +0000
Revision:
4:e6e1642724d4
Parent:
3:d4e1892846fb
Child:
5:07113abf18c0
loads imaged much faster, mostly because of PC side optimization. Still some problems with naming blocks and marking them as erased, this needs to be sorted.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
ThomasSonderDesign 0:17d169ac117c 1 /******************************************************************************
ThomasSonderDesign 0:17d169ac117c 2 * S O N D E R
ThomasSonderDesign 0:17d169ac117c 3 * Copyright 2016 (C) Sonder Design Pty Ltd - All Rights Reserved
ThomasSonderDesign 0:17d169ac117c 4 * Unauthorised copying of this file, via any medium is strictly prohibited
ThomasSonderDesign 0:17d169ac117c 5 * Proprietary and confidential
ThomasSonderDesign 0:17d169ac117c 6 *****************************************************************************/
ThomasSonderDesign 0:17d169ac117c 7 /*
ThomasSonderDesign 0:17d169ac117c 8 This is the first implementation of a functional firmware. It allows the user to change the Display layout and type. Improvements for later
ThomasSonderDesign 0:17d169ac117c 9 versions will include usb keyboard support
ThomasSonderDesign 0:17d169ac117c 10 */
ThomasSonderDesign 0:17d169ac117c 11 #include "mbed.h"
ThomasSonderDesign 0:17d169ac117c 12 #include "USBHID.h"
ThomasSonderDesign 0:17d169ac117c 13 #include "Memory.h"
ThomasSonderDesign 0:17d169ac117c 14 #include "VKCodes.h"
ThomasSonderDesign 0:17d169ac117c 15
ThomasSonderDesign 0:17d169ac117c 16 /******************************************************************************
ThomasSonderDesign 0:17d169ac117c 17 * Definitiontions
ThomasSonderDesign 0:17d169ac117c 18 */
ThomasSonderDesign 0:17d169ac117c 19 //Constants for black board
ThomasSonderDesign 0:17d169ac117c 20
ThomasSonderDesign 0:17d169ac117c 21 DigitalOut cs_mem(P0_2); //Set up memory's Chip Select pin
ThomasSonderDesign 0:17d169ac117c 22 DigitalOut cs_epd(P1_23); //Set up epd's Chip Select pin
ThomasSonderDesign 0:17d169ac117c 23 DigitalOut TconEn(P0_5); //Tcon Enable pin, open drain must invert
ThomasSonderDesign 0:17d169ac117c 24 DigitalOut start(P0_14);
ThomasSonderDesign 0:17d169ac117c 25
ThomasSonderDesign 0:17d169ac117c 26 DigitalOut myled(P0_9);
ThomasSonderDesign 0:17d169ac117c 27 DigitalOut SRclk(P0_15); //Shift register clk signal
ThomasSonderDesign 0:17d169ac117c 28 DigitalOut SRlat (P1_22); //Shift register output latch
ThomasSonderDesign 0:17d169ac117c 29 DigitalOut SRds(P1_14); //Shiftreg data pin
ThomasSonderDesign 0:17d169ac117c 30
ThomasSonderDesign 0:17d169ac117c 31 DigitalIn E(P1_13); //Definne row row A input pin
ThomasSonderDesign 0:17d169ac117c 32 DigitalIn D(P0_7); //Definne row row B input pin
ThomasSonderDesign 0:17d169ac117c 33 DigitalIn C(P1_28); //Definne row row C input pin
ThomasSonderDesign 0:17d169ac117c 34 DigitalIn B(P1_31); //Definne row row D input pin
ThomasSonderDesign 0:17d169ac117c 35 DigitalIn A(P1_29); //Definne row row E input pin
ThomasSonderDesign 0:17d169ac117c 36
ThomasSonderDesign 0:17d169ac117c 37 DigitalIn modC(P0_11); //Definne row mod C input pin
ThomasSonderDesign 0:17d169ac117c 38 DigitalIn modB(P0_12); //Definne row mod B input pin
ThomasSonderDesign 0:17d169ac117c 39 DigitalIn modA(P0_13); //Definne row mod A input pin
ThomasSonderDesign 0:17d169ac117c 40
ThomasSonderDesign 0:17d169ac117c 41 Serial pc (P0_19,P0_18); //Setup a real serial port
ThomasSonderDesign 0:17d169ac117c 42 Memory mem(P0_2); //Create a new memory manager with chip select on P0_2
ThomasSonderDesign 0:17d169ac117c 43
ThomasSonderDesign 0:17d169ac117c 44 USBHID hid(64, 8,0x1234,0x3241); //Create a HID conection with and 64 byte input and 8 byte output report, PID0x1234 VID 3241
ThomasSonderDesign 0:17d169ac117c 45
ThomasSonderDesign 0:17d169ac117c 46 volatile int *PIN39IOREG = (int *)0x4004403C;
ThomasSonderDesign 0:17d169ac117c 47 int reportLength = 64; //The length of the report recieved
ThomasSonderDesign 0:17d169ac117c 48
ThomasSonderDesign 0:17d169ac117c 49 //Codes to send to the pc
ThomasSonderDesign 0:17d169ac117c 50 int readyAndWaiting []= {2,0x25,0,0,0,0,0,0};
ThomasSonderDesign 0:17d169ac117c 51 int busy []= {2,0x50,0,0,0,0,0,0};
ThomasSonderDesign 0:17d169ac117c 52 int readyForComand []= {2,0x75,0,0,0,0,0,0};
ThomasSonderDesign 0:17d169ac117c 53
ThomasSonderDesign 0:17d169ac117c 54
ThomasSonderDesign 0:17d169ac117c 55 int GlobalAddress = 0; //The last adress written to plus one
ThomasSonderDesign 0:17d169ac117c 56 int lastErasedBlock =0; //The Adress of the last erases block
ThomasSonderDesign 0:17d169ac117c 57 int currentName = 0; //The position in the nameList of the curret layout
ThomasSonderDesign 1:1ec8bcd31b27 58 char nameList[16][5]; //A list of all the Layouts in memory, each name is 5 bytes long
ThomasSonderDesign 1:1ec8bcd31b27 59
ThomasSonderDesign 1:1ec8bcd31b27 60 //Locations in memory were the 16 layouts can be stored
ThomasSonderDesign 1:1ec8bcd31b27 61 const int slots [] = {0,0x20000, 0x40000,0x60000, 0x80000, 0xa0000, 0xc0000, 0xe0000, 0x100000, 0x120000,0x140000,0x160000,0x180000, 0x1a0000,0x1e0000};
ThomasSonderDesign 4:e6e1642724d4 62 bool erasedSlots[]= {true,false,false,false,false,false,false,false,false,false,false,false,false,false,false,false};
ThomasSonderDesign 0:17d169ac117c 63
ThomasSonderDesign 0:17d169ac117c 64 int keybuffer[10][2]; //A buffer for storing key presses (mod key plus key)
ThomasSonderDesign 0:17d169ac117c 65
ThomasSonderDesign 0:17d169ac117c 66 int scanCode [5][14]= { //This 2D array maps key scan codes to letter codes
ThomasSonderDesign 0:17d169ac117c 67 {VK_OEM_3, KEY_1, KEY_2, KEY_3, KEY_4, KEY_5, KEY_6, KEY_7, KEY_8, KEY_9, KEY_0, VK_OEM_MINUS, VK_OEM_PLUS, VK_BACK},
ThomasSonderDesign 0:17d169ac117c 68 {VK_TAB, KEY_Q, KEY_W, KEY_E, KEY_R, KEY_T, KEY_Y, KEY_U, KEY_I, KEY_O, KEY_P},
ThomasSonderDesign 0:17d169ac117c 69 {KEY_A, KEY_S, KEY_D, KEY_F, KEY_G, KEY_H, KEY_J, KEY_K, KEY_L, VK_OEM_1},
ThomasSonderDesign 0:17d169ac117c 70 {KEY_Z, KEY_X, KEY_C, KEY_V, KEY_B, KEY_N, KEY_M, VK_LSHIFT,VK_CONTROL,VK_LMENU},
ThomasSonderDesign 0:17d169ac117c 71 {VK_F1, VK_F2,VK_F3,VK_F4, VK_SPACE, VK_TAB, VK_BACK, VK_RSHIFT,VK_LWIN,VK_RMENU}
ThomasSonderDesign 0:17d169ac117c 72 };
ThomasSonderDesign 0:17d169ac117c 73
ThomasSonderDesign 0:17d169ac117c 74
ThomasSonderDesign 0:17d169ac117c 75 /******************************************************************************
ThomasSonderDesign 0:17d169ac117c 76 * Set up Functions
ThomasSonderDesign 0:17d169ac117c 77 */
ThomasSonderDesign 0:17d169ac117c 78 char check(int depth) //Check availible memory
ThomasSonderDesign 0:17d169ac117c 79 {
ThomasSonderDesign 0:17d169ac117c 80 char c;
ThomasSonderDesign 0:17d169ac117c 81 char *ptr = new char;
ThomasSonderDesign 0:17d169ac117c 82 //pc.printf("stack at %p, heap at %p\n", &c, ptr);
ThomasSonderDesign 0:17d169ac117c 83 //pc.printf("sh,%i,%i\n", &c, ptr);
ThomasSonderDesign 0:17d169ac117c 84 pc.printf("mem size = %p\n", &c-ptr);
ThomasSonderDesign 0:17d169ac117c 85 //if (depth <= 0) return;
ThomasSonderDesign 0:17d169ac117c 86 // check(depth-1);
ThomasSonderDesign 0:17d169ac117c 87 free(ptr);
ThomasSonderDesign 0:17d169ac117c 88 return 1;
ThomasSonderDesign 0:17d169ac117c 89 }
ThomasSonderDesign 0:17d169ac117c 90
ThomasSonderDesign 0:17d169ac117c 91 /**
ThomasSonderDesign 0:17d169ac117c 92 * Set up the memory SPI
ThomasSonderDesign 0:17d169ac117c 93 */
ThomasSonderDesign 0:17d169ac117c 94 SPI setupSPI()
ThomasSonderDesign 0:17d169ac117c 95 {
ThomasSonderDesign 0:17d169ac117c 96 SPI my_spi(P0_9,P0_8,P0_10); // mosi, miso, sclk
ThomasSonderDesign 0:17d169ac117c 97 //cs_mem = 1; // Chip must be deselected
ThomasSonderDesign 0:17d169ac117c 98 my_spi.format(8,3); // Setup the spi for 8 bit data, low steady state clock,
ThomasSonderDesign 1:1ec8bcd31b27 99 my_spi.frequency(1000000); // second edge capture, with a 1MHz clock rate, Will work up to 20MHz
ThomasSonderDesign 0:17d169ac117c 100 return my_spi;
ThomasSonderDesign 0:17d169ac117c 101 }
ThomasSonderDesign 0:17d169ac117c 102
ThomasSonderDesign 0:17d169ac117c 103
ThomasSonderDesign 0:17d169ac117c 104 /**
ThomasSonderDesign 0:17d169ac117c 105 * Setup USB HID, usefull for later not used in this iterarion
ThomasSonderDesign 0:17d169ac117c 106 */
ThomasSonderDesign 0:17d169ac117c 107 /*USBHID setupUSB()
ThomasSonderDesign 0:17d169ac117c 108 {
ThomasSonderDesign 0:17d169ac117c 109 USBHID hid(64, 8,0x1234,0x3241); //Create a HID conection with and 64 byte input and 8 byte output report, PID0x1234 VID 3241
ThomasSonderDesign 0:17d169ac117c 110 return hid;
ThomasSonderDesign 0:17d169ac117c 111 }*/
ThomasSonderDesign 0:17d169ac117c 112
ThomasSonderDesign 0:17d169ac117c 113
ThomasSonderDesign 0:17d169ac117c 114 /******************************************************************************
ThomasSonderDesign 0:17d169ac117c 115 * USB Functions
ThomasSonderDesign 0:17d169ac117c 116 */
ThomasSonderDesign 0:17d169ac117c 117
ThomasSonderDesign 0:17d169ac117c 118 /**
ThomasSonderDesign 0:17d169ac117c 119 * checks the usb recive buffer, if it contains data it is coppired to USBDataBuffer and returns 1
ThomasSonderDesign 0:17d169ac117c 120 * if the empty return -1;
ThomasSonderDesign 0:17d169ac117c 121 */
ThomasSonderDesign 0:17d169ac117c 122 int readUSB(int USBDataBuffer[])
ThomasSonderDesign 0:17d169ac117c 123 {
ThomasSonderDesign 0:17d169ac117c 124 HID_REPORT recv_report;
ThomasSonderDesign 0:17d169ac117c 125 if(hid.readNB(&recv_report)) { //Check if there is a received report
ThomasSonderDesign 0:17d169ac117c 126 //printf("\n");
ThomasSonderDesign 0:17d169ac117c 127 for(int i = 0; i<recv_report.length; i++) { //Store the report in a locat array
ThomasSonderDesign 0:17d169ac117c 128 //printf(" %x", recv_report.data[i]);
ThomasSonderDesign 0:17d169ac117c 129 USBDataBuffer[i] = recv_report.data[i];
ThomasSonderDesign 0:17d169ac117c 130 }
ThomasSonderDesign 0:17d169ac117c 131 return 1;
ThomasSonderDesign 0:17d169ac117c 132 } else {
ThomasSonderDesign 0:17d169ac117c 133 return -1;
ThomasSonderDesign 0:17d169ac117c 134 }
ThomasSonderDesign 0:17d169ac117c 135 }
ThomasSonderDesign 0:17d169ac117c 136
ThomasSonderDesign 0:17d169ac117c 137
ThomasSonderDesign 0:17d169ac117c 138 /**
ThomasSonderDesign 0:17d169ac117c 139 * usbSend, send an eight byte report over usb
ThomasSonderDesign 0:17d169ac117c 140 */
ThomasSonderDesign 0:17d169ac117c 141 void sendUSB(int usbReport[])
ThomasSonderDesign 0:17d169ac117c 142 {
ThomasSonderDesign 0:17d169ac117c 143 //pc.printf("\nS: %x",usbReport[1]);
ThomasSonderDesign 0:17d169ac117c 144 HID_REPORT send_report;
ThomasSonderDesign 0:17d169ac117c 145 send_report.length = 8;
ThomasSonderDesign 0:17d169ac117c 146
ThomasSonderDesign 0:17d169ac117c 147 send_report.data[0] = usbReport[0];
ThomasSonderDesign 0:17d169ac117c 148 send_report.data[1] = usbReport[1]; //comand byte
ThomasSonderDesign 0:17d169ac117c 149 send_report.data[2] = usbReport[2];
ThomasSonderDesign 0:17d169ac117c 150 send_report.data[3] = usbReport[3];
ThomasSonderDesign 0:17d169ac117c 151 send_report.data[4] = usbReport[4];
ThomasSonderDesign 0:17d169ac117c 152 send_report.data[5] = usbReport[5];
ThomasSonderDesign 0:17d169ac117c 153 send_report.data[6] = usbReport[6];
ThomasSonderDesign 0:17d169ac117c 154 send_report.data[7] = usbReport[7];
ThomasSonderDesign 0:17d169ac117c 155 hid.send(&send_report);
ThomasSonderDesign 0:17d169ac117c 156 }
ThomasSonderDesign 0:17d169ac117c 157
ThomasSonderDesign 0:17d169ac117c 158
ThomasSonderDesign 0:17d169ac117c 159
ThomasSonderDesign 0:17d169ac117c 160 /******************************************************************************
ThomasSonderDesign 0:17d169ac117c 161 * Keyboard Functions
ThomasSonderDesign 0:17d169ac117c 162 */
ThomasSonderDesign 0:17d169ac117c 163
ThomasSonderDesign 0:17d169ac117c 164 /**
ThomasSonderDesign 0:17d169ac117c 165 * keyScan(int keyBuffer[][]). Sacns the keyboard matrix and stores any keypresses in the 2D keyBuffer
ThomasSonderDesign 0:17d169ac117c 166 * If a key press was detected it returns the most recent key press, otherwise it returns 0
ThomasSonderDesign 0:17d169ac117c 167 */
ThomasSonderDesign 0:17d169ac117c 168 int keyScan()
ThomasSonderDesign 0:17d169ac117c 169 {
ThomasSonderDesign 0:17d169ac117c 170 //Initialise and set Up code
ThomasSonderDesign 0:17d169ac117c 171 int counter=0; //Keubuffer index counter
ThomasSonderDesign 0:17d169ac117c 172 int rowNum = 0;
ThomasSonderDesign 0:17d169ac117c 173 int code =0; //the return value, the last key pushed
ThomasSonderDesign 0:17d169ac117c 174
ThomasSonderDesign 0:17d169ac117c 175 /*Clear the keybuffer*/
ThomasSonderDesign 0:17d169ac117c 176 for(int i = 0; i<10; i++) {
ThomasSonderDesign 0:17d169ac117c 177 keybuffer[i][0]=0;
ThomasSonderDesign 0:17d169ac117c 178 keybuffer[i][1]=0;
ThomasSonderDesign 0:17d169ac117c 179 }
ThomasSonderDesign 0:17d169ac117c 180
ThomasSonderDesign 0:17d169ac117c 181 int noCols = 16; //number of bits to be shifted
ThomasSonderDesign 0:17d169ac117c 182 int t = 1000; //wait time in uS. This is the period in us of the shift register clock
ThomasSonderDesign 0:17d169ac117c 183 SRclk=0;
ThomasSonderDesign 0:17d169ac117c 184 SRlat = 0;
ThomasSonderDesign 0:17d169ac117c 185 SRds =1; //Set first bit high
ThomasSonderDesign 0:17d169ac117c 186
ThomasSonderDesign 0:17d169ac117c 187
ThomasSonderDesign 0:17d169ac117c 188 for (int col = 0; col<noCols; col++) { //Loop through one shifit reg
ThomasSonderDesign 0:17d169ac117c 189 SRclk = 1; //clock in current bit // __ __
ThomasSonderDesign 0:17d169ac117c 190 wait_us(t/2); //SRclk__| |_..._| |_
ThomasSonderDesign 0:17d169ac117c 191 SRds = 0; //set dext bit low // ___
ThomasSonderDesign 0:17d169ac117c 192 wait_us(t/2); //SRds | |___..._____
ThomasSonderDesign 0:17d169ac117c 193 SRclk=0; // _ _
ThomasSonderDesign 0:17d169ac117c 194 SRlat = 1; //latch all data out //SRlat____| |_...___| |_
ThomasSonderDesign 0:17d169ac117c 195 wait_us(t/2); //
ThomasSonderDesign 0:17d169ac117c 196 SRlat=0;
ThomasSonderDesign 0:17d169ac117c 197
ThomasSonderDesign 0:17d169ac117c 198 /*
ThomasSonderDesign 0:17d169ac117c 199 Check if a button has been pressed by scaning the rows
ThomasSonderDesign 0:17d169ac117c 200 Generates a unique code depending on which button has been pressed
ThomasSonderDesign 0:17d169ac117c 201 The code is looked up in the scanCode Array
ThomasSonderDesign 0:17d169ac117c 202 */
ThomasSonderDesign 0:17d169ac117c 203 if(A>0) {
ThomasSonderDesign 0:17d169ac117c 204 //pc.printf("A\n");
ThomasSonderDesign 0:17d169ac117c 205 rowNum = 0;
ThomasSonderDesign 0:17d169ac117c 206 code = scanCode[rowNum][col];
ThomasSonderDesign 0:17d169ac117c 207 keybuffer[counter][1]= code;
ThomasSonderDesign 0:17d169ac117c 208 counter++;
ThomasSonderDesign 0:17d169ac117c 209 }
ThomasSonderDesign 0:17d169ac117c 210 if(B>0) {
ThomasSonderDesign 0:17d169ac117c 211 //pc.printf("B\n");
ThomasSonderDesign 0:17d169ac117c 212 rowNum = 1;
ThomasSonderDesign 0:17d169ac117c 213 code = scanCode[rowNum][col];
ThomasSonderDesign 0:17d169ac117c 214 keybuffer[counter][1]= code;
ThomasSonderDesign 0:17d169ac117c 215 counter++;
ThomasSonderDesign 0:17d169ac117c 216 }
ThomasSonderDesign 0:17d169ac117c 217 if(C>0) {
ThomasSonderDesign 0:17d169ac117c 218 //pc.printf("C\n");
ThomasSonderDesign 0:17d169ac117c 219 rowNum = 2;
ThomasSonderDesign 0:17d169ac117c 220 code = scanCode[rowNum][col];
ThomasSonderDesign 0:17d169ac117c 221 keybuffer[counter][1]= code;
ThomasSonderDesign 0:17d169ac117c 222 counter++;
ThomasSonderDesign 0:17d169ac117c 223 }
ThomasSonderDesign 0:17d169ac117c 224 if(D>0) {
ThomasSonderDesign 0:17d169ac117c 225 //pc.printf("D\n");
ThomasSonderDesign 0:17d169ac117c 226 rowNum = 3;
ThomasSonderDesign 0:17d169ac117c 227 code = scanCode[rowNum][col];
ThomasSonderDesign 0:17d169ac117c 228 keybuffer[counter][1]= code;
ThomasSonderDesign 0:17d169ac117c 229 counter++;
ThomasSonderDesign 0:17d169ac117c 230 }
ThomasSonderDesign 0:17d169ac117c 231 if(E>0) {
ThomasSonderDesign 0:17d169ac117c 232 //pc.printf("E\n");
ThomasSonderDesign 0:17d169ac117c 233 rowNum = 4;
ThomasSonderDesign 0:17d169ac117c 234 code = scanCode[rowNum][col];
ThomasSonderDesign 0:17d169ac117c 235 keybuffer[counter][1]= code;
ThomasSonderDesign 0:17d169ac117c 236 counter++;
ThomasSonderDesign 0:17d169ac117c 237 }
ThomasSonderDesign 0:17d169ac117c 238
ThomasSonderDesign 0:17d169ac117c 239 /*Scan the mod keys and assign them to the mod column of key buffer in the from zero up*/
ThomasSonderDesign 0:17d169ac117c 240 if(col>0) {
ThomasSonderDesign 0:17d169ac117c 241 counter=0;
ThomasSonderDesign 0:17d169ac117c 242
ThomasSonderDesign 0:17d169ac117c 243 if(modC>0) {
ThomasSonderDesign 0:17d169ac117c 244 rowNum = 0;
ThomasSonderDesign 0:17d169ac117c 245 code = scanCode[rowNum][col];
ThomasSonderDesign 0:17d169ac117c 246 keybuffer[counter][0]= code;
ThomasSonderDesign 0:17d169ac117c 247 }
ThomasSonderDesign 0:17d169ac117c 248 if(modB>0) {
ThomasSonderDesign 0:17d169ac117c 249 rowNum = 0;
ThomasSonderDesign 0:17d169ac117c 250 code = scanCode[rowNum][col];
ThomasSonderDesign 0:17d169ac117c 251 keybuffer[counter][0]= code;
ThomasSonderDesign 0:17d169ac117c 252 }
ThomasSonderDesign 0:17d169ac117c 253 if(modA>0) {
ThomasSonderDesign 0:17d169ac117c 254 rowNum = 0;
ThomasSonderDesign 0:17d169ac117c 255 code = scanCode[rowNum][col];
ThomasSonderDesign 0:17d169ac117c 256 keybuffer[counter][0]= code;
ThomasSonderDesign 0:17d169ac117c 257 }
ThomasSonderDesign 0:17d169ac117c 258 }
ThomasSonderDesign 0:17d169ac117c 259 }
ThomasSonderDesign 0:17d169ac117c 260 return code;
ThomasSonderDesign 0:17d169ac117c 261 }
ThomasSonderDesign 0:17d169ac117c 262
ThomasSonderDesign 0:17d169ac117c 263
ThomasSonderDesign 0:17d169ac117c 264 /**
ThomasSonderDesign 0:17d169ac117c 265 * int sendKey(int mod, int key). Sends a keypress to the pc over usb
ThomasSonderDesign 0:17d169ac117c 266 */
ThomasSonderDesign 0:17d169ac117c 267 void sendKey(int mod, int key)
ThomasSonderDesign 0:17d169ac117c 268 {
ThomasSonderDesign 0:17d169ac117c 269 int temp[]= {0x01,mod,key,0,0,0,0,0};
ThomasSonderDesign 0:17d169ac117c 270 sendUSB(temp);
ThomasSonderDesign 0:17d169ac117c 271 }
ThomasSonderDesign 0:17d169ac117c 272
ThomasSonderDesign 0:17d169ac117c 273
ThomasSonderDesign 0:17d169ac117c 274
ThomasSonderDesign 0:17d169ac117c 275 /******************************************************************************
ThomasSonderDesign 1:1ec8bcd31b27 276 * Memory control funtions
ThomasSonderDesign 0:17d169ac117c 277 */
ThomasSonderDesign 0:17d169ac117c 278
ThomasSonderDesign 0:17d169ac117c 279
ThomasSonderDesign 0:17d169ac117c 280 /**
ThomasSonderDesign 0:17d169ac117c 281 * Writes the contense of USBDataBuffer to memoryBuffer, starting at bufferIndex
ThomasSonderDesign 0:17d169ac117c 282 * returns the index of the last written byte+1;
ThomasSonderDesign 0:17d169ac117c 283 */
ThomasSonderDesign 0:17d169ac117c 284 int appendBuffer(int USBDataBuffer[], char memoryBuffer[], int bufferIndex)
ThomasSonderDesign 0:17d169ac117c 285 {
ThomasSonderDesign 0:17d169ac117c 286 //pc.printf("\n");
ThomasSonderDesign 0:17d169ac117c 287 int posIndex=0;
ThomasSonderDesign 0:17d169ac117c 288 for(int i = 0; i < 64; i++) {
ThomasSonderDesign 4:e6e1642724d4 289 //pc.printf("%x ",USBDataBuffer[i]);
ThomasSonderDesign 0:17d169ac117c 290 memoryBuffer[bufferIndex+i]=USBDataBuffer[i];
ThomasSonderDesign 0:17d169ac117c 291 posIndex++;
ThomasSonderDesign 0:17d169ac117c 292 }
ThomasSonderDesign 0:17d169ac117c 293 return (bufferIndex+posIndex);
ThomasSonderDesign 0:17d169ac117c 294 }
ThomasSonderDesign 0:17d169ac117c 295
ThomasSonderDesign 0:17d169ac117c 296 /**
ThomasSonderDesign 0:17d169ac117c 297 *Sends the ready and waiting signall and loops untill data is recieved.
ThomasSonderDesign 0:17d169ac117c 298 *Recieved data is stored in the USBDataBuffer
ThomasSonderDesign 0:17d169ac117c 299 */
ThomasSonderDesign 0:17d169ac117c 300 void waitForData(int USBDataBuffer[])
ThomasSonderDesign 0:17d169ac117c 301 {
ThomasSonderDesign 0:17d169ac117c 302 sendUSB(readyAndWaiting);
ThomasSonderDesign 0:17d169ac117c 303 while (readUSB(USBDataBuffer)<1) {
ThomasSonderDesign 0:17d169ac117c 304 sendUSB(readyAndWaiting);
ThomasSonderDesign 0:17d169ac117c 305 }
ThomasSonderDesign 0:17d169ac117c 306 }
ThomasSonderDesign 0:17d169ac117c 307
ThomasSonderDesign 4:e6e1642724d4 308
ThomasSonderDesign 4:e6e1642724d4 309 /**
ThomasSonderDesign 4:e6e1642724d4 310 * receives 64 packets over usb and stores them in memooryBuffer. When memory Buffer is full it is
ThomasSonderDesign 4:e6e1642724d4 311 * written to memory at address. This is repeated 336 times to write a whole image to memory.
ThomasSonderDesign 4:e6e1642724d4 312 * returns the next availible adsress;
ThomasSonderDesign 4:e6e1642724d4 313 */
ThomasSonderDesign 4:e6e1642724d4 314 int writeImage(SPI my_spi,int Address)
ThomasSonderDesign 4:e6e1642724d4 315 {
ThomasSonderDesign 4:e6e1642724d4 316 Timer t;
ThomasSonderDesign 4:e6e1642724d4 317 t.start(); //Start the timer
ThomasSonderDesign 4:e6e1642724d4 318 int USBDataBuffer [64]; //Creat a buffer for recived data
ThomasSonderDesign 4:e6e1642724d4 319 char memoryBuffer [bufferSize]; //Create a memory buffer, to be sent to flash
ThomasSonderDesign 4:e6e1642724d4 320 int bufferIndex = 0; //points to the next available possition in memory
ThomasSonderDesign 4:e6e1642724d4 321 int startAddress = Address;
ThomasSonderDesign 4:e6e1642724d4 322 while (Address<startAddress+86272) {
ThomasSonderDesign 4:e6e1642724d4 323 //waitForData(USBDataBuffer); //Waits untill data is recieved on usb, puts it in USBDataBuffer
ThomasSonderDesign 4:e6e1642724d4 324 while(bufferIndex<bufferSize) {
ThomasSonderDesign 4:e6e1642724d4 325 waitForData(USBDataBuffer);
ThomasSonderDesign 4:e6e1642724d4 326 bufferIndex=appendBuffer(USBDataBuffer, memoryBuffer, bufferIndex); //Appends USBDataBuffer onto memoryBuffer
ThomasSonderDesign 4:e6e1642724d4 327 }
ThomasSonderDesign 4:e6e1642724d4 328 bufferIndex=0;
ThomasSonderDesign 4:e6e1642724d4 329
ThomasSonderDesign 4:e6e1642724d4 330 //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
ThomasSonderDesign 4:e6e1642724d4 331 //protected. this erases a block before writung to it if nessisary.
ThomasSonderDesign 4:e6e1642724d4 332 int currentSlot = Address/0x20000;
ThomasSonderDesign 4:e6e1642724d4 333 if (erasedSlots[currentSlot]) {
ThomasSonderDesign 4:e6e1642724d4 334 Address = mem.writeData(my_spi, memoryBuffer, Address, bufferSize);
ThomasSonderDesign 4:e6e1642724d4 335 } else {
ThomasSonderDesign 4:e6e1642724d4 336 pc.printf("\nCan not write to unerased slot.");
ThomasSonderDesign 4:e6e1642724d4 337 }
ThomasSonderDesign 4:e6e1642724d4 338 }
ThomasSonderDesign 4:e6e1642724d4 339 pc.printf("\n pinnished writing");
ThomasSonderDesign 4:e6e1642724d4 340 t.stop();
ThomasSonderDesign 4:e6e1642724d4 341 pc.printf("\nwrite image %i", t.read_ms());
ThomasSonderDesign 4:e6e1642724d4 342 t.reset();
ThomasSonderDesign 4:e6e1642724d4 343 return Address;
ThomasSonderDesign 4:e6e1642724d4 344 }
ThomasSonderDesign 4:e6e1642724d4 345
ThomasSonderDesign 0:17d169ac117c 346 /**
ThomasSonderDesign 0:17d169ac117c 347 * receives 64 packets over usb and stores them in memooryBuffer. When memory Buffer is full it is
ThomasSonderDesign 0:17d169ac117c 348 * written to memory at address.
ThomasSonderDesign 0:17d169ac117c 349 * returns the next availible adsress;
ThomasSonderDesign 0:17d169ac117c 350 */
ThomasSonderDesign 0:17d169ac117c 351 int writeFrame(SPI my_spi,int Address)
ThomasSonderDesign 0:17d169ac117c 352 {
ThomasSonderDesign 0:17d169ac117c 353 int USBDataBuffer [64]; //Creat a buffer for recived data
ThomasSonderDesign 0:17d169ac117c 354 char memoryBuffer [bufferSize]; //Create a memory buffer, to be sent to flash
ThomasSonderDesign 0:17d169ac117c 355 int bufferIndex = 0; //points to the next available possition in memory
ThomasSonderDesign 3:d4e1892846fb 356 Timer t;
ThomasSonderDesign 3:d4e1892846fb 357 t.start(); //Start the timer
ThomasSonderDesign 0:17d169ac117c 358
ThomasSonderDesign 0:17d169ac117c 359 waitForData(USBDataBuffer); //Waits untill data is recieved on usb, puts it in USBDataBuffer
ThomasSonderDesign 3:d4e1892846fb 360 t.stop();
ThomasSonderDesign 4:e6e1642724d4 361
ThomasSonderDesign 0:17d169ac117c 362 while(bufferIndex<bufferSize) {
ThomasSonderDesign 0:17d169ac117c 363 bufferIndex=appendBuffer(USBDataBuffer, memoryBuffer, bufferIndex); //Appends USBDataBuffer onto memoryBuffer
ThomasSonderDesign 3:d4e1892846fb 364 t.start();
ThomasSonderDesign 0:17d169ac117c 365 waitForData(USBDataBuffer);
ThomasSonderDesign 3:d4e1892846fb 366 t.stop();
ThomasSonderDesign 0:17d169ac117c 367 }
ThomasSonderDesign 0:17d169ac117c 368
ThomasSonderDesign 0:17d169ac117c 369 //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
ThomasSonderDesign 0:17d169ac117c 370 //protected. this erases a block before writung to it if nessisary.
ThomasSonderDesign 2:8b66a3f7e202 371 int currentSlot = Address/0x20000;
ThomasSonderDesign 2:8b66a3f7e202 372 pc.printf("\nCurrent slot: %i", currentSlot);
ThomasSonderDesign 2:8b66a3f7e202 373 if (erasedSlots[currentSlot]) {
ThomasSonderDesign 1:1ec8bcd31b27 374 pc.printf("\nNE");
ThomasSonderDesign 0:17d169ac117c 375 Address = mem.writeData(my_spi, memoryBuffer, Address, bufferSize);
ThomasSonderDesign 0:17d169ac117c 376 } else {
ThomasSonderDesign 2:8b66a3f7e202 377 pc.printf("\nCan not write to unerased slot.");
ThomasSonderDesign 4:e6e1642724d4 378 }
ThomasSonderDesign 3:d4e1892846fb 379 //t.stop();
ThomasSonderDesign 3:d4e1892846fb 380 pc.printf("\nWait1 Wate2-4 %i", t.read_ms());
ThomasSonderDesign 3:d4e1892846fb 381 t.reset();
ThomasSonderDesign 0:17d169ac117c 382 return Address;
ThomasSonderDesign 0:17d169ac117c 383 }
ThomasSonderDesign 0:17d169ac117c 384
ThomasSonderDesign 1:1ec8bcd31b27 385
ThomasSonderDesign 1:1ec8bcd31b27 386 /**
ThomasSonderDesign 1:1ec8bcd31b27 387 * Sends a report containing a the name of the layout stored at a given slot
ThomasSonderDesign 1:1ec8bcd31b27 388 */
ThomasSonderDesign 2:8b66a3f7e202 389 void getLayoutName(int slot)
ThomasSonderDesign 1:1ec8bcd31b27 390 {
ThomasSonderDesign 1:1ec8bcd31b27 391 int temp [] = {0x31,slot,nameList[slot][0],nameList[slot][1],nameList[slot][2],nameList[slot][3],nameList[slot][4],0};
ThomasSonderDesign 1:1ec8bcd31b27 392 sendUSB(temp);
ThomasSonderDesign 1:1ec8bcd31b27 393 }
ThomasSonderDesign 1:1ec8bcd31b27 394
ThomasSonderDesign 1:1ec8bcd31b27 395
ThomasSonderDesign 1:1ec8bcd31b27 396 /**
ThomasSonderDesign 1:1ec8bcd31b27 397 * Sends three reports containing the list of layout names stored in memory.
ThomasSonderDesign 1:1ec8bcd31b27 398 */
ThomasSonderDesign 1:1ec8bcd31b27 399 void getNameList()
ThomasSonderDesign 1:1ec8bcd31b27 400 {
ThomasSonderDesign 1:1ec8bcd31b27 401 for(int slot =0; slot< 16; slot++) {
ThomasSonderDesign 2:8b66a3f7e202 402 getLayoutName(slot);
ThomasSonderDesign 1:1ec8bcd31b27 403 }
ThomasSonderDesign 1:1ec8bcd31b27 404 }
ThomasSonderDesign 0:17d169ac117c 405
ThomasSonderDesign 0:17d169ac117c 406 /**
ThomasSonderDesign 0:17d169ac117c 407 * Sends the name of the Current layout
ThomasSonderDesign 0:17d169ac117c 408 */
ThomasSonderDesign 1:1ec8bcd31b27 409 void getCurrentLayout()
ThomasSonderDesign 0:17d169ac117c 410 {
ThomasSonderDesign 2:8b66a3f7e202 411 getLayoutName(currentName);
ThomasSonderDesign 0:17d169ac117c 412 }
ThomasSonderDesign 0:17d169ac117c 413
ThomasSonderDesign 0:17d169ac117c 414 /**
ThomasSonderDesign 0:17d169ac117c 415 * Writes the name of a given layout to the top memory address in its reserved block
ThomasSonderDesign 1:1ec8bcd31b27 416 * name[] is a 5 bytes char array with the most significant byte at name[0]
ThomasSonderDesign 0:17d169ac117c 417 */
ThomasSonderDesign 2:8b66a3f7e202 418 void nameBlock(SPI my_spi, char name[], int slot)
ThomasSonderDesign 0:17d169ac117c 419 {
ThomasSonderDesign 1:1ec8bcd31b27 420 //char temp[]= {name};
ThomasSonderDesign 2:8b66a3f7e202 421 mem.writeData(my_spi, name, slots[slot]+0x1fff9, 5);
ThomasSonderDesign 2:8b66a3f7e202 422 }
ThomasSonderDesign 2:8b66a3f7e202 423
ThomasSonderDesign 2:8b66a3f7e202 424 /**
ThomasSonderDesign 2:8b66a3f7e202 425 * Reads memory to find the names of the layouts stored. puts the names into nameList
ThomasSonderDesign 2:8b66a3f7e202 426 */
ThomasSonderDesign 2:8b66a3f7e202 427 void populateNameList(SPI my_spi)
ThomasSonderDesign 2:8b66a3f7e202 428 {
ThomasSonderDesign 4:e6e1642724d4 429 for(int slot=0; slot<16; slot++) {
ThomasSonderDesign 4:e6e1642724d4 430 char name[5];
ThomasSonderDesign 4:e6e1642724d4 431 mem.readData(my_spi, name, slots[slot]+0x1FFF9, 5); //Read five bytes from the end of a slot into the name array
ThomasSonderDesign 4:e6e1642724d4 432 for( int i = 0; i<5; i++) {
ThomasSonderDesign 4:e6e1642724d4 433 nameList[slot][i]=name[i];
ThomasSonderDesign 4:e6e1642724d4 434 }
ThomasSonderDesign 4:e6e1642724d4 435 }
ThomasSonderDesign 2:8b66a3f7e202 436 }
ThomasSonderDesign 2:8b66a3f7e202 437
ThomasSonderDesign 2:8b66a3f7e202 438 /**
ThomasSonderDesign 2:8b66a3f7e202 439 * Prepares the memory for a new Layout, writes the layout's name, and erases the blocks
ThomasSonderDesign 2:8b66a3f7e202 440 */
ThomasSonderDesign 4:e6e1642724d4 441 void prepImage(SPI my_spi, int slot, char name[])
ThomasSonderDesign 2:8b66a3f7e202 442 {
ThomasSonderDesign 4:e6e1642724d4 443 pc.printf("Slot: %i", slots[slot]);
ThomasSonderDesign 4:e6e1642724d4 444 mem.blockErase(my_spi, slots[slot]); //erase the bottom block of the slot
ThomasSonderDesign 4:e6e1642724d4 445 mem.blockErase(my_spi, slots[slot]+0x10000); //erase the top block of the slot
ThomasSonderDesign 4:e6e1642724d4 446 //nameBlock(my_spi, name, slots[slot]+0x1FFF9); //Write the name of the layout to memory
ThomasSonderDesign 4:e6e1642724d4 447 erasedSlots[slot]=true; //Mark the erased slot as true
ThomasSonderDesign 0:17d169ac117c 448 }
ThomasSonderDesign 0:17d169ac117c 449
ThomasSonderDesign 1:1ec8bcd31b27 450
ThomasSonderDesign 1:1ec8bcd31b27 451 /******************************************************************************
ThomasSonderDesign 1:1ec8bcd31b27 452 * Display control funtions
ThomasSonderDesign 1:1ec8bcd31b27 453 */
ThomasSonderDesign 1:1ec8bcd31b27 454
ThomasSonderDesign 0:17d169ac117c 455 /*###### EPD Set Up ######*/
ThomasSonderDesign 0:17d169ac117c 456 //Sets up the EPD spi pins
ThomasSonderDesign 0:17d169ac117c 457 SPI setupEPD()
ThomasSonderDesign 0:17d169ac117c 458 {
ThomasSonderDesign 0:17d169ac117c 459 pc.printf("\nEpd setup");
ThomasSonderDesign 0:17d169ac117c 460 /////Setup the spi link with the EDP////
ThomasSonderDesign 0:17d169ac117c 461 SPI epd_spi(P0_21, P1_21, P1_20); //SPI setup: mosi, miso, sclk
ThomasSonderDesign 0:17d169ac117c 462 // Setup the spi for 8 bit data, high steady state clock,
ThomasSonderDesign 0:17d169ac117c 463 // second edge capture, with a 5MHz clock rate
ThomasSonderDesign 0:17d169ac117c 464 epd_spi.format(8,3);
ThomasSonderDesign 0:17d169ac117c 465 epd_spi.frequency(5000000);
ThomasSonderDesign 0:17d169ac117c 466 return epd_spi;
ThomasSonderDesign 0:17d169ac117c 467 }
ThomasSonderDesign 0:17d169ac117c 468
ThomasSonderDesign 0:17d169ac117c 469
ThomasSonderDesign 0:17d169ac117c 470 /*###### EPD Write ######*/
ThomasSonderDesign 0:17d169ac117c 471 //Update the whole display with data from memory, starting at the address
ThomasSonderDesign 0:17d169ac117c 472 int EPD_Write(SPI mem_spi, int address)
ThomasSonderDesign 0:17d169ac117c 473 {
ThomasSonderDesign 4:e6e1642724d4 474 pc.printf("Address: %i", address);
ThomasSonderDesign 0:17d169ac117c 475 //Setup the SPIs
ThomasSonderDesign 0:17d169ac117c 476 SPI epd_spi = setupEPD(); //Creat a new SPI object to comunicate with the EPD
ThomasSonderDesign 0:17d169ac117c 477
ThomasSonderDesign 0:17d169ac117c 478 //Create local variables
ThomasSonderDesign 0:17d169ac117c 479 char sixtyBytes[60]; //Create a line buffer
ThomasSonderDesign 0:17d169ac117c 480 //int line = 0; //counter to keep track of the current line
ThomasSonderDesign 0:17d169ac117c 481 //int frameLine = 0; //counter to keep track of the line in the current frame
ThomasSonderDesign 0:17d169ac117c 482 int lineLengh = 60;
ThomasSonderDesign 0:17d169ac117c 483
ThomasSonderDesign 0:17d169ac117c 484 //led=!led;
ThomasSonderDesign 1:1ec8bcd31b27 485 //Timer t;
ThomasSonderDesign 1:1ec8bcd31b27 486 //t.start(); //Start the timer
ThomasSonderDesign 0:17d169ac117c 487
ThomasSonderDesign 0:17d169ac117c 488 //Begin SPI comunication
ThomasSonderDesign 0:17d169ac117c 489 cs_epd=1; //EPD chip deselected
ThomasSonderDesign 0:17d169ac117c 490 TconEn =1; //Tcon ON set High
ThomasSonderDesign 0:17d169ac117c 491 wait_ms(120); //delay 120ms
ThomasSonderDesign 0:17d169ac117c 492 cs_epd=0; //Select the Tcon chip
ThomasSonderDesign 0:17d169ac117c 493 wait_ms(1); //delay 1ms
ThomasSonderDesign 0:17d169ac117c 494 //Write Header
ThomasSonderDesign 0:17d169ac117c 495 epd_spi.write(0x06);
ThomasSonderDesign 0:17d169ac117c 496 epd_spi.write(0xa0);
ThomasSonderDesign 0:17d169ac117c 497 wait_ms(120); //delay 120ms
ThomasSonderDesign 0:17d169ac117c 498
ThomasSonderDesign 0:17d169ac117c 499 //loop throug 1440 lines
ThomasSonderDesign 0:17d169ac117c 500 for(int j=0; j<1440; j++) {
ThomasSonderDesign 0:17d169ac117c 501 mem.readData(mem_spi, sixtyBytes, address, lineLengh); //Read the line, putt them in buffer return the next address to read from
ThomasSonderDesign 0:17d169ac117c 502 for(int i =0; i<60; i++) { //Read one byte from the buffer
ThomasSonderDesign 0:17d169ac117c 503 epd_spi.write(sixtyBytes[i]); //and write it to the display
ThomasSonderDesign 4:e6e1642724d4 504 pc.printf("%i ",sixtyBytes[i]);
ThomasSonderDesign 0:17d169ac117c 505 address++;
ThomasSonderDesign 0:17d169ac117c 506 //byteCounter++;
ThomasSonderDesign 0:17d169ac117c 507 }
ThomasSonderDesign 4:e6e1642724d4 508 pc.printf("\n");
ThomasSonderDesign 0:17d169ac117c 509 epd_spi.write(00); //Write a 0 at the end of each line
ThomasSonderDesign 0:17d169ac117c 510 //wait_us(10000);
ThomasSonderDesign 0:17d169ac117c 511 }
ThomasSonderDesign 0:17d169ac117c 512 wait_us(1000);
ThomasSonderDesign 0:17d169ac117c 513 DigitalOut sclk(P0_13); //serial clk
ThomasSonderDesign 0:17d169ac117c 514 sclk = 0;
ThomasSonderDesign 0:17d169ac117c 515 cs_epd=1; //Deselct the chip
ThomasSonderDesign 1:1ec8bcd31b27 516 //t.stop();
ThomasSonderDesign 0:17d169ac117c 517 wait(10); //Wait 5s for the EPD to update
ThomasSonderDesign 0:17d169ac117c 518 TconEn=0; //Deassert Tcon ON
ThomasSonderDesign 0:17d169ac117c 519 cs_epd=0; //Deassert chip select
ThomasSonderDesign 0:17d169ac117c 520
ThomasSonderDesign 1:1ec8bcd31b27 521 //printf("\ntime = %i ", t.read_ms());
ThomasSonderDesign 1:1ec8bcd31b27 522 //t.reset();
ThomasSonderDesign 0:17d169ac117c 523 return 1;
ThomasSonderDesign 0:17d169ac117c 524 }
ThomasSonderDesign 0:17d169ac117c 525
ThomasSonderDesign 2:8b66a3f7e202 526 /*###### EPD Write ######*/
ThomasSonderDesign 2:8b66a3f7e202 527 //Update the whole display with data from a reserved slot
ThomasSonderDesign 2:8b66a3f7e202 528 int EPD_Swap(SPI mem_spi, int slot)
ThomasSonderDesign 2:8b66a3f7e202 529 {
ThomasSonderDesign 2:8b66a3f7e202 530 return EPD_Write(mem_spi, slots[slot]);
ThomasSonderDesign 2:8b66a3f7e202 531 }
ThomasSonderDesign 0:17d169ac117c 532 /*******************************************************
ThomasSonderDesign 0:17d169ac117c 533 * Main Function
ThomasSonderDesign 0:17d169ac117c 534 */
ThomasSonderDesign 0:17d169ac117c 535 int main()
ThomasSonderDesign 0:17d169ac117c 536 {
ThomasSonderDesign 1:1ec8bcd31b27 537 Timer t;
ThomasSonderDesign 1:1ec8bcd31b27 538
ThomasSonderDesign 0:17d169ac117c 539 int USBDataBuffer[64];
ThomasSonderDesign 0:17d169ac117c 540 SPI my_spi = setupSPI(); //Creates an SPI object to comunicate with the external memory
ThomasSonderDesign 2:8b66a3f7e202 541 populateNameList(my_spi); //Reads the names of layouts stored in external memory into RAM
ThomasSonderDesign 4:e6e1642724d4 542
ThomasSonderDesign 0:17d169ac117c 543 while(1) {
ThomasSonderDesign 3:d4e1892846fb 544 pc.printf("Loop");
ThomasSonderDesign 1:1ec8bcd31b27 545
ThomasSonderDesign 0:17d169ac117c 546 sendUSB(readyForComand);
ThomasSonderDesign 0:17d169ac117c 547 if (keyScan()>0) { //check if keyScan returned key presss
ThomasSonderDesign 4:e6e1642724d4 548 pc.printf("\nKey scan|n");
ThomasSonderDesign 0:17d169ac117c 549 int countpos =0;
ThomasSonderDesign 0:17d169ac117c 550 while(keybuffer[countpos][1]>0) { //While there are keypresses in the buffer
ThomasSonderDesign 0:17d169ac117c 551 pc.printf("%i",keybuffer[countpos][1]);
ThomasSonderDesign 0:17d169ac117c 552 pc.printf(" ");
ThomasSonderDesign 0:17d169ac117c 553 sendKey(keybuffer[countpos][0],keybuffer[countpos][1]);//Send key press
ThomasSonderDesign 0:17d169ac117c 554 countpos++;
ThomasSonderDesign 0:17d169ac117c 555 myled=0;
ThomasSonderDesign 0:17d169ac117c 556 }
ThomasSonderDesign 0:17d169ac117c 557 }
ThomasSonderDesign 1:1ec8bcd31b27 558
ThomasSonderDesign 0:17d169ac117c 559 sendUSB(readyForComand);
ThomasSonderDesign 0:17d169ac117c 560 if (readUSB(USBDataBuffer)>0) {
ThomasSonderDesign 4:e6e1642724d4 561 pc.printf("\nSwitch %i",USBDataBuffer[1]);
ThomasSonderDesign 3:d4e1892846fb 562 char temp[] = {USBDataBuffer[3],USBDataBuffer[4],USBDataBuffer[5],USBDataBuffer[6],USBDataBuffer[7]};
ThomasSonderDesign 0:17d169ac117c 563 switch(USBDataBuffer[1]) {
ThomasSonderDesign 0:17d169ac117c 564 case 0x10: //If the recieved data is a write instruction
ThomasSonderDesign 3:d4e1892846fb 565 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]
ThomasSonderDesign 0:17d169ac117c 566 break;
ThomasSonderDesign 3:d4e1892846fb 567 case 0x11:
ThomasSonderDesign 3:d4e1892846fb 568 pc.printf("\n memory write");
ThomasSonderDesign 4:e6e1642724d4 569 prepImage(my_spi, USBDataBuffer[2], temp);//Prepare a slot in memory for an image
ThomasSonderDesign 4:e6e1642724d4 570 break;
ThomasSonderDesign 4:e6e1642724d4 571 case 0x12:
ThomasSonderDesign 4:e6e1642724d4 572 pc.printf("\n Image write");
ThomasSonderDesign 4:e6e1642724d4 573 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]
ThomasSonderDesign 3:d4e1892846fb 574 break;
ThomasSonderDesign 0:17d169ac117c 575 case 0x20: //If the recieved comand is a read instruction
ThomasSonderDesign 0:17d169ac117c 576 //mem.readData(my_spi, memoryBuffer, USBDataBuffer[2], USBDataBuffer[3]);//read(spi, destination[], address, length)
ThomasSonderDesign 1:1ec8bcd31b27 577 //pc.printf(" \n---EPD UPDATE--- %i",USBDataBuffer[2]*65536+USBDataBuffer[3]*256+USBDataBuffer[4]);
ThomasSonderDesign 0:17d169ac117c 578 EPD_Write(my_spi, USBDataBuffer[2]*65536+USBDataBuffer[3]*256+USBDataBuffer[4]);
ThomasSonderDesign 0:17d169ac117c 579 break;
ThomasSonderDesign 0:17d169ac117c 580 case 0x30: //If the recieved comand is a request for the cutrrent name
ThomasSonderDesign 0:17d169ac117c 581 getCurrentLayout();
ThomasSonderDesign 0:17d169ac117c 582 break;
ThomasSonderDesign 0:17d169ac117c 583 case 0x35: //If the recieved comand is a request for all the names
ThomasSonderDesign 0:17d169ac117c 584 getCurrentLayout();
ThomasSonderDesign 0:17d169ac117c 585 break;
ThomasSonderDesign 0:17d169ac117c 586 default:
ThomasSonderDesign 4:e6e1642724d4 587 pc.printf("\nfail! [%x %x %x %x %x %x %x %x]",USBDataBuffer[0],USBDataBuffer[1],USBDataBuffer[2],USBDataBuffer[3],USBDataBuffer[4],USBDataBuffer[5],USBDataBuffer[6],USBDataBuffer[7]);
ThomasSonderDesign 0:17d169ac117c 588 }
ThomasSonderDesign 0:17d169ac117c 589 }
ThomasSonderDesign 1:1ec8bcd31b27 590
ThomasSonderDesign 3:d4e1892846fb 591 //pc.printf("\n%d", t.read_us());
ThomasSonderDesign 1:1ec8bcd31b27 592 t.reset();
ThomasSonderDesign 0:17d169ac117c 593 }
ThomasSonderDesign 0:17d169ac117c 594 }