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:
Thu Dec 22 22:16:34 2016 +0000
Revision:
5:07113abf18c0
Parent:
4:e6e1642724d4
Child:
6:2f4a272ab299
See description. all works

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 5:07113abf18c0 286 //printf("\n");
ThomasSonderDesign 0:17d169ac117c 287 int posIndex=0;
ThomasSonderDesign 0:17d169ac117c 288 for(int i = 0; i < 64; i++) {
ThomasSonderDesign 5:07113abf18c0 289
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 5:07113abf18c0 318 pc.printf("\nAddress: %i\n", Address);
ThomasSonderDesign 4:e6e1642724d4 319 int USBDataBuffer [64]; //Creat a buffer for recived data
ThomasSonderDesign 4:e6e1642724d4 320 char memoryBuffer [bufferSize]; //Create a memory buffer, to be sent to flash
ThomasSonderDesign 4:e6e1642724d4 321 int bufferIndex = 0; //points to the next available possition in memory
ThomasSonderDesign 4:e6e1642724d4 322 int startAddress = Address;
ThomasSonderDesign 4:e6e1642724d4 323 while (Address<startAddress+86272) {
ThomasSonderDesign 4:e6e1642724d4 324 //waitForData(USBDataBuffer); //Waits untill data is recieved on usb, puts it in USBDataBuffer
ThomasSonderDesign 4:e6e1642724d4 325 while(bufferIndex<bufferSize) {
ThomasSonderDesign 4:e6e1642724d4 326 waitForData(USBDataBuffer);
ThomasSonderDesign 4:e6e1642724d4 327 bufferIndex=appendBuffer(USBDataBuffer, memoryBuffer, bufferIndex); //Appends USBDataBuffer onto memoryBuffer
ThomasSonderDesign 4:e6e1642724d4 328 }
ThomasSonderDesign 4:e6e1642724d4 329 bufferIndex=0;
ThomasSonderDesign 4:e6e1642724d4 330
ThomasSonderDesign 4:e6e1642724d4 331 //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 332 //protected. this erases a block before writung to it if nessisary.
ThomasSonderDesign 4:e6e1642724d4 333 int currentSlot = Address/0x20000;
ThomasSonderDesign 4:e6e1642724d4 334 if (erasedSlots[currentSlot]) {
ThomasSonderDesign 4:e6e1642724d4 335 Address = mem.writeData(my_spi, memoryBuffer, Address, bufferSize);
ThomasSonderDesign 4:e6e1642724d4 336 } else {
ThomasSonderDesign 4:e6e1642724d4 337 pc.printf("\nCan not write to unerased slot.");
ThomasSonderDesign 5:07113abf18c0 338 Address = mem.writeData(my_spi, memoryBuffer, Address, bufferSize);
ThomasSonderDesign 4:e6e1642724d4 339 }
ThomasSonderDesign 4:e6e1642724d4 340 }
ThomasSonderDesign 4:e6e1642724d4 341 pc.printf("\n pinnished writing");
ThomasSonderDesign 4:e6e1642724d4 342 t.stop();
ThomasSonderDesign 4:e6e1642724d4 343 pc.printf("\nwrite image %i", t.read_ms());
ThomasSonderDesign 4:e6e1642724d4 344 t.reset();
ThomasSonderDesign 4:e6e1642724d4 345 return Address;
ThomasSonderDesign 4:e6e1642724d4 346 }
ThomasSonderDesign 4:e6e1642724d4 347
ThomasSonderDesign 0:17d169ac117c 348 /**
ThomasSonderDesign 5:07113abf18c0 349 * Writes a single memorybuffer to memory
ThomasSonderDesign 0:17d169ac117c 350 * receives 64 packets over usb and stores them in memooryBuffer. When memory Buffer is full it is
ThomasSonderDesign 0:17d169ac117c 351 * written to memory at address.
ThomasSonderDesign 0:17d169ac117c 352 * returns the next availible adsress;
ThomasSonderDesign 0:17d169ac117c 353 */
ThomasSonderDesign 0:17d169ac117c 354 int writeFrame(SPI my_spi,int Address)
ThomasSonderDesign 0:17d169ac117c 355 {
ThomasSonderDesign 0:17d169ac117c 356 int USBDataBuffer [64]; //Creat a buffer for recived data
ThomasSonderDesign 0:17d169ac117c 357 char memoryBuffer [bufferSize]; //Create a memory buffer, to be sent to flash
ThomasSonderDesign 0:17d169ac117c 358 int bufferIndex = 0; //points to the next available possition in memory
ThomasSonderDesign 3:d4e1892846fb 359 Timer t;
ThomasSonderDesign 3:d4e1892846fb 360 t.start(); //Start the timer
ThomasSonderDesign 0:17d169ac117c 361
ThomasSonderDesign 0:17d169ac117c 362 waitForData(USBDataBuffer); //Waits untill data is recieved on usb, puts it in USBDataBuffer
ThomasSonderDesign 3:d4e1892846fb 363 t.stop();
ThomasSonderDesign 4:e6e1642724d4 364
ThomasSonderDesign 0:17d169ac117c 365 while(bufferIndex<bufferSize) {
ThomasSonderDesign 0:17d169ac117c 366 bufferIndex=appendBuffer(USBDataBuffer, memoryBuffer, bufferIndex); //Appends USBDataBuffer onto memoryBuffer
ThomasSonderDesign 3:d4e1892846fb 367 t.start();
ThomasSonderDesign 0:17d169ac117c 368 waitForData(USBDataBuffer);
ThomasSonderDesign 3:d4e1892846fb 369 t.stop();
ThomasSonderDesign 0:17d169ac117c 370 }
ThomasSonderDesign 0:17d169ac117c 371
ThomasSonderDesign 0:17d169ac117c 372 //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 373 //protected. this erases a block before writung to it if nessisary.
ThomasSonderDesign 2:8b66a3f7e202 374 int currentSlot = Address/0x20000;
ThomasSonderDesign 2:8b66a3f7e202 375 pc.printf("\nCurrent slot: %i", currentSlot);
ThomasSonderDesign 2:8b66a3f7e202 376 if (erasedSlots[currentSlot]) {
ThomasSonderDesign 1:1ec8bcd31b27 377 pc.printf("\nNE");
ThomasSonderDesign 0:17d169ac117c 378 Address = mem.writeData(my_spi, memoryBuffer, Address, bufferSize);
ThomasSonderDesign 0:17d169ac117c 379 } else {
ThomasSonderDesign 2:8b66a3f7e202 380 pc.printf("\nCan not write to unerased slot.");
ThomasSonderDesign 4:e6e1642724d4 381 }
ThomasSonderDesign 3:d4e1892846fb 382 //t.stop();
ThomasSonderDesign 3:d4e1892846fb 383 pc.printf("\nWait1 Wate2-4 %i", t.read_ms());
ThomasSonderDesign 3:d4e1892846fb 384 t.reset();
ThomasSonderDesign 0:17d169ac117c 385 return Address;
ThomasSonderDesign 0:17d169ac117c 386 }
ThomasSonderDesign 0:17d169ac117c 387
ThomasSonderDesign 1:1ec8bcd31b27 388
ThomasSonderDesign 1:1ec8bcd31b27 389 /**
ThomasSonderDesign 1:1ec8bcd31b27 390 * Sends a report containing a the name of the layout stored at a given slot
ThomasSonderDesign 1:1ec8bcd31b27 391 */
ThomasSonderDesign 2:8b66a3f7e202 392 void getLayoutName(int slot)
ThomasSonderDesign 1:1ec8bcd31b27 393 {
ThomasSonderDesign 1:1ec8bcd31b27 394 int temp [] = {0x31,slot,nameList[slot][0],nameList[slot][1],nameList[slot][2],nameList[slot][3],nameList[slot][4],0};
ThomasSonderDesign 1:1ec8bcd31b27 395 sendUSB(temp);
ThomasSonderDesign 1:1ec8bcd31b27 396 }
ThomasSonderDesign 1:1ec8bcd31b27 397
ThomasSonderDesign 1:1ec8bcd31b27 398
ThomasSonderDesign 1:1ec8bcd31b27 399 /**
ThomasSonderDesign 1:1ec8bcd31b27 400 * Sends three reports containing the list of layout names stored in memory.
ThomasSonderDesign 1:1ec8bcd31b27 401 */
ThomasSonderDesign 1:1ec8bcd31b27 402 void getNameList()
ThomasSonderDesign 1:1ec8bcd31b27 403 {
ThomasSonderDesign 1:1ec8bcd31b27 404 for(int slot =0; slot< 16; slot++) {
ThomasSonderDesign 2:8b66a3f7e202 405 getLayoutName(slot);
ThomasSonderDesign 1:1ec8bcd31b27 406 }
ThomasSonderDesign 1:1ec8bcd31b27 407 }
ThomasSonderDesign 0:17d169ac117c 408
ThomasSonderDesign 0:17d169ac117c 409 /**
ThomasSonderDesign 0:17d169ac117c 410 * Sends the name of the Current layout
ThomasSonderDesign 0:17d169ac117c 411 */
ThomasSonderDesign 1:1ec8bcd31b27 412 void getCurrentLayout()
ThomasSonderDesign 0:17d169ac117c 413 {
ThomasSonderDesign 2:8b66a3f7e202 414 getLayoutName(currentName);
ThomasSonderDesign 0:17d169ac117c 415 }
ThomasSonderDesign 0:17d169ac117c 416
ThomasSonderDesign 0:17d169ac117c 417 /**
ThomasSonderDesign 0:17d169ac117c 418 * Writes the name of a given layout to the top memory address in its reserved block
ThomasSonderDesign 1:1ec8bcd31b27 419 * name[] is a 5 bytes char array with the most significant byte at name[0]
ThomasSonderDesign 0:17d169ac117c 420 */
ThomasSonderDesign 2:8b66a3f7e202 421 void nameBlock(SPI my_spi, char name[], int slot)
ThomasSonderDesign 0:17d169ac117c 422 {
ThomasSonderDesign 1:1ec8bcd31b27 423 //char temp[]= {name};
ThomasSonderDesign 2:8b66a3f7e202 424 mem.writeData(my_spi, name, slots[slot]+0x1fff9, 5);
ThomasSonderDesign 2:8b66a3f7e202 425 }
ThomasSonderDesign 2:8b66a3f7e202 426
ThomasSonderDesign 2:8b66a3f7e202 427 /**
ThomasSonderDesign 2:8b66a3f7e202 428 * Reads memory to find the names of the layouts stored. puts the names into nameList
ThomasSonderDesign 2:8b66a3f7e202 429 */
ThomasSonderDesign 2:8b66a3f7e202 430 void populateNameList(SPI my_spi)
ThomasSonderDesign 2:8b66a3f7e202 431 {
ThomasSonderDesign 4:e6e1642724d4 432 for(int slot=0; slot<16; slot++) {
ThomasSonderDesign 4:e6e1642724d4 433 char name[5];
ThomasSonderDesign 4:e6e1642724d4 434 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 435 for( int i = 0; i<5; i++) {
ThomasSonderDesign 4:e6e1642724d4 436 nameList[slot][i]=name[i];
ThomasSonderDesign 4:e6e1642724d4 437 }
ThomasSonderDesign 4:e6e1642724d4 438 }
ThomasSonderDesign 2:8b66a3f7e202 439 }
ThomasSonderDesign 2:8b66a3f7e202 440
ThomasSonderDesign 2:8b66a3f7e202 441 /**
ThomasSonderDesign 2:8b66a3f7e202 442 * Prepares the memory for a new Layout, writes the layout's name, and erases the blocks
ThomasSonderDesign 2:8b66a3f7e202 443 */
ThomasSonderDesign 4:e6e1642724d4 444 void prepImage(SPI my_spi, int slot, char name[])
ThomasSonderDesign 2:8b66a3f7e202 445 {
ThomasSonderDesign 5:07113abf18c0 446 pc.printf("\nSlot: %i", slots[slot]);
ThomasSonderDesign 4:e6e1642724d4 447 mem.blockErase(my_spi, slots[slot]); //erase the bottom block of the slot
ThomasSonderDesign 4:e6e1642724d4 448 mem.blockErase(my_spi, slots[slot]+0x10000); //erase the top block of the slot
ThomasSonderDesign 4:e6e1642724d4 449 //nameBlock(my_spi, name, slots[slot]+0x1FFF9); //Write the name of the layout to memory
ThomasSonderDesign 4:e6e1642724d4 450 erasedSlots[slot]=true; //Mark the erased slot as true
ThomasSonderDesign 0:17d169ac117c 451 }
ThomasSonderDesign 0:17d169ac117c 452
ThomasSonderDesign 1:1ec8bcd31b27 453
ThomasSonderDesign 1:1ec8bcd31b27 454 /******************************************************************************
ThomasSonderDesign 1:1ec8bcd31b27 455 * Display control funtions
ThomasSonderDesign 1:1ec8bcd31b27 456 */
ThomasSonderDesign 1:1ec8bcd31b27 457
ThomasSonderDesign 0:17d169ac117c 458 /*###### EPD Set Up ######*/
ThomasSonderDesign 0:17d169ac117c 459 //Sets up the EPD spi pins
ThomasSonderDesign 0:17d169ac117c 460 SPI setupEPD()
ThomasSonderDesign 0:17d169ac117c 461 {
ThomasSonderDesign 0:17d169ac117c 462 pc.printf("\nEpd setup");
ThomasSonderDesign 0:17d169ac117c 463 /////Setup the spi link with the EDP////
ThomasSonderDesign 0:17d169ac117c 464 SPI epd_spi(P0_21, P1_21, P1_20); //SPI setup: mosi, miso, sclk
ThomasSonderDesign 0:17d169ac117c 465 // Setup the spi for 8 bit data, high steady state clock,
ThomasSonderDesign 0:17d169ac117c 466 // second edge capture, with a 5MHz clock rate
ThomasSonderDesign 0:17d169ac117c 467 epd_spi.format(8,3);
ThomasSonderDesign 0:17d169ac117c 468 epd_spi.frequency(5000000);
ThomasSonderDesign 0:17d169ac117c 469 return epd_spi;
ThomasSonderDesign 0:17d169ac117c 470 }
ThomasSonderDesign 0:17d169ac117c 471
ThomasSonderDesign 0:17d169ac117c 472
ThomasSonderDesign 0:17d169ac117c 473 /*###### EPD Write ######*/
ThomasSonderDesign 5:07113abf18c0 474 //Update the whole display with data from memory, starting at the
ThomasSonderDesign 0:17d169ac117c 475 int EPD_Write(SPI mem_spi, int address)
ThomasSonderDesign 0:17d169ac117c 476 {
ThomasSonderDesign 5:07113abf18c0 477 pc.printf("\nAddress: %i", address);
ThomasSonderDesign 0:17d169ac117c 478 //Setup the SPIs
ThomasSonderDesign 0:17d169ac117c 479 SPI epd_spi = setupEPD(); //Creat a new SPI object to comunicate with the EPD
ThomasSonderDesign 0:17d169ac117c 480
ThomasSonderDesign 0:17d169ac117c 481 //Create local variables
ThomasSonderDesign 5:07113abf18c0 482 int lineLengh = 60; //the length of the display in bytes
ThomasSonderDesign 5:07113abf18c0 483 char sixtyBytes[lineLengh]; //Create a line buffer
ThomasSonderDesign 5:07113abf18c0 484
ThomasSonderDesign 0:17d169ac117c 485 //int line = 0; //counter to keep track of the current line
ThomasSonderDesign 0:17d169ac117c 486 //int frameLine = 0; //counter to keep track of the line in the current frame
ThomasSonderDesign 5:07113abf18c0 487
ThomasSonderDesign 0:17d169ac117c 488
ThomasSonderDesign 0:17d169ac117c 489 //led=!led;
ThomasSonderDesign 1:1ec8bcd31b27 490 //Timer t;
ThomasSonderDesign 1:1ec8bcd31b27 491 //t.start(); //Start the timer
ThomasSonderDesign 0:17d169ac117c 492
ThomasSonderDesign 0:17d169ac117c 493 //Begin SPI comunication
ThomasSonderDesign 0:17d169ac117c 494 cs_epd=1; //EPD chip deselected
ThomasSonderDesign 0:17d169ac117c 495 TconEn =1; //Tcon ON set High
ThomasSonderDesign 0:17d169ac117c 496 wait_ms(120); //delay 120ms
ThomasSonderDesign 0:17d169ac117c 497 cs_epd=0; //Select the Tcon chip
ThomasSonderDesign 0:17d169ac117c 498 wait_ms(1); //delay 1ms
ThomasSonderDesign 0:17d169ac117c 499 //Write Header
ThomasSonderDesign 0:17d169ac117c 500 epd_spi.write(0x06);
ThomasSonderDesign 0:17d169ac117c 501 epd_spi.write(0xa0);
ThomasSonderDesign 0:17d169ac117c 502 wait_ms(120); //delay 120ms
ThomasSonderDesign 0:17d169ac117c 503
ThomasSonderDesign 0:17d169ac117c 504 //loop throug 1440 lines
ThomasSonderDesign 0:17d169ac117c 505 for(int j=0; j<1440; j++) {
ThomasSonderDesign 5:07113abf18c0 506 //pc.printf("\n");
ThomasSonderDesign 0:17d169ac117c 507 mem.readData(mem_spi, sixtyBytes, address, lineLengh); //Read the line, putt them in buffer return the next address to read from
ThomasSonderDesign 5:07113abf18c0 508 for(int i =0; i<lineLengh; i++) { //Read one byte from the buffer
ThomasSonderDesign 0:17d169ac117c 509 epd_spi.write(sixtyBytes[i]); //and write it to the display
ThomasSonderDesign 5:07113abf18c0 510 //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);
ThomasSonderDesign 0:17d169ac117c 511 address++;
ThomasSonderDesign 0:17d169ac117c 512 //byteCounter++;
ThomasSonderDesign 0:17d169ac117c 513 }
ThomasSonderDesign 0:17d169ac117c 514 epd_spi.write(00); //Write a 0 at the end of each line
ThomasSonderDesign 0:17d169ac117c 515 //wait_us(10000);
ThomasSonderDesign 0:17d169ac117c 516 }
ThomasSonderDesign 0:17d169ac117c 517 wait_us(1000);
ThomasSonderDesign 0:17d169ac117c 518 DigitalOut sclk(P0_13); //serial clk
ThomasSonderDesign 0:17d169ac117c 519 sclk = 0;
ThomasSonderDesign 0:17d169ac117c 520 cs_epd=1; //Deselct the chip
ThomasSonderDesign 1:1ec8bcd31b27 521 //t.stop();
ThomasSonderDesign 0:17d169ac117c 522 wait(10); //Wait 5s for the EPD to update
ThomasSonderDesign 0:17d169ac117c 523 TconEn=0; //Deassert Tcon ON
ThomasSonderDesign 0:17d169ac117c 524 cs_epd=0; //Deassert chip select
ThomasSonderDesign 0:17d169ac117c 525
ThomasSonderDesign 1:1ec8bcd31b27 526 //printf("\ntime = %i ", t.read_ms());
ThomasSonderDesign 1:1ec8bcd31b27 527 //t.reset();
ThomasSonderDesign 0:17d169ac117c 528 return 1;
ThomasSonderDesign 0:17d169ac117c 529 }
ThomasSonderDesign 0:17d169ac117c 530
ThomasSonderDesign 2:8b66a3f7e202 531 /*###### EPD Write ######*/
ThomasSonderDesign 2:8b66a3f7e202 532 //Update the whole display with data from a reserved slot
ThomasSonderDesign 2:8b66a3f7e202 533 int EPD_Swap(SPI mem_spi, int slot)
ThomasSonderDesign 2:8b66a3f7e202 534 {
ThomasSonderDesign 2:8b66a3f7e202 535 return EPD_Write(mem_spi, slots[slot]);
ThomasSonderDesign 2:8b66a3f7e202 536 }
ThomasSonderDesign 0:17d169ac117c 537 /*******************************************************
ThomasSonderDesign 0:17d169ac117c 538 * Main Function
ThomasSonderDesign 0:17d169ac117c 539 */
ThomasSonderDesign 0:17d169ac117c 540 int main()
ThomasSonderDesign 0:17d169ac117c 541 {
ThomasSonderDesign 1:1ec8bcd31b27 542 Timer t;
ThomasSonderDesign 1:1ec8bcd31b27 543
ThomasSonderDesign 0:17d169ac117c 544 int USBDataBuffer[64];
ThomasSonderDesign 0:17d169ac117c 545 SPI my_spi = setupSPI(); //Creates an SPI object to comunicate with the external memory
ThomasSonderDesign 2:8b66a3f7e202 546 populateNameList(my_spi); //Reads the names of layouts stored in external memory into RAM
ThomasSonderDesign 4:e6e1642724d4 547
ThomasSonderDesign 0:17d169ac117c 548 while(1) {
ThomasSonderDesign 3:d4e1892846fb 549 pc.printf("Loop");
ThomasSonderDesign 1:1ec8bcd31b27 550
ThomasSonderDesign 0:17d169ac117c 551 sendUSB(readyForComand);
ThomasSonderDesign 0:17d169ac117c 552 if (keyScan()>0) { //check if keyScan returned key presss
ThomasSonderDesign 4:e6e1642724d4 553 pc.printf("\nKey scan|n");
ThomasSonderDesign 0:17d169ac117c 554 int countpos =0;
ThomasSonderDesign 0:17d169ac117c 555 while(keybuffer[countpos][1]>0) { //While there are keypresses in the buffer
ThomasSonderDesign 0:17d169ac117c 556 pc.printf("%i",keybuffer[countpos][1]);
ThomasSonderDesign 0:17d169ac117c 557 pc.printf(" ");
ThomasSonderDesign 0:17d169ac117c 558 sendKey(keybuffer[countpos][0],keybuffer[countpos][1]);//Send key press
ThomasSonderDesign 0:17d169ac117c 559 countpos++;
ThomasSonderDesign 0:17d169ac117c 560 myled=0;
ThomasSonderDesign 0:17d169ac117c 561 }
ThomasSonderDesign 0:17d169ac117c 562 }
ThomasSonderDesign 1:1ec8bcd31b27 563
ThomasSonderDesign 0:17d169ac117c 564 sendUSB(readyForComand);
ThomasSonderDesign 0:17d169ac117c 565 if (readUSB(USBDataBuffer)>0) {
ThomasSonderDesign 4:e6e1642724d4 566 pc.printf("\nSwitch %i",USBDataBuffer[1]);
ThomasSonderDesign 3:d4e1892846fb 567 char temp[] = {USBDataBuffer[3],USBDataBuffer[4],USBDataBuffer[5],USBDataBuffer[6],USBDataBuffer[7]};
ThomasSonderDesign 0:17d169ac117c 568 switch(USBDataBuffer[1]) {
ThomasSonderDesign 0:17d169ac117c 569 case 0x10: //If the recieved data is a write instruction
ThomasSonderDesign 3:d4e1892846fb 570 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 571 break;
ThomasSonderDesign 3:d4e1892846fb 572 case 0x11:
ThomasSonderDesign 5:07113abf18c0 573 pc.printf("\nPrep write");
ThomasSonderDesign 4:e6e1642724d4 574 prepImage(my_spi, USBDataBuffer[2], temp);//Prepare a slot in memory for an image
ThomasSonderDesign 4:e6e1642724d4 575 break;
ThomasSonderDesign 4:e6e1642724d4 576 case 0x12:
ThomasSonderDesign 5:07113abf18c0 577 pc.printf("\nImage write");
ThomasSonderDesign 4:e6e1642724d4 578 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 579 break;
ThomasSonderDesign 0:17d169ac117c 580 case 0x20: //If the recieved comand is a read instruction
ThomasSonderDesign 0:17d169ac117c 581 //mem.readData(my_spi, memoryBuffer, USBDataBuffer[2], USBDataBuffer[3]);//read(spi, destination[], address, length)
ThomasSonderDesign 1:1ec8bcd31b27 582 //pc.printf(" \n---EPD UPDATE--- %i",USBDataBuffer[2]*65536+USBDataBuffer[3]*256+USBDataBuffer[4]);
ThomasSonderDesign 0:17d169ac117c 583 EPD_Write(my_spi, USBDataBuffer[2]*65536+USBDataBuffer[3]*256+USBDataBuffer[4]);
ThomasSonderDesign 0:17d169ac117c 584 break;
ThomasSonderDesign 0:17d169ac117c 585 case 0x30: //If the recieved comand is a request for the cutrrent name
ThomasSonderDesign 0:17d169ac117c 586 getCurrentLayout();
ThomasSonderDesign 0:17d169ac117c 587 break;
ThomasSonderDesign 0:17d169ac117c 588 case 0x35: //If the recieved comand is a request for all the names
ThomasSonderDesign 0:17d169ac117c 589 getCurrentLayout();
ThomasSonderDesign 0:17d169ac117c 590 break;
ThomasSonderDesign 0:17d169ac117c 591 default:
ThomasSonderDesign 4:e6e1642724d4 592 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 593 }
ThomasSonderDesign 0:17d169ac117c 594 }
ThomasSonderDesign 1:1ec8bcd31b27 595
ThomasSonderDesign 3:d4e1892846fb 596 //pc.printf("\n%d", t.read_us());
ThomasSonderDesign 1:1ec8bcd31b27 597 t.reset();
ThomasSonderDesign 0:17d169ac117c 598 }
ThomasSonderDesign 0:17d169ac117c 599 }