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:
Sun Apr 15 23:27:26 2018 +0000
Revision:
9:7c0f42f090e8
Parent:
8:3577b060d7af
Child:
10:1f96f0cce2a0
This works with the 11.3 in display and can update in about 6 seconds. Works on the QSB on bread board . Next step is to port it onto the black board.

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 9:7c0f42f090e8 16 //Spi port for epd. on black board P0_21, P1_21, P1_20. on QSB P0_21,P0_22,P1_15
ThomasSonderDesign 9:7c0f42f090e8 17 #define EPDSPI P0_21,P0_22,P1_15
ThomasSonderDesign 9:7c0f42f090e8 18 //Spi port for memory. on black board P0_9,P0_8,P0_10, P1_20. on QSB P0_9,P0_8,P0_10
ThomasSonderDesign 9:7c0f42f090e8 19 #define MEMSPI P0_9,P0_8,P0_10
ThomasSonderDesign 9:7c0f42f090e8 20 #define SLOTSIZE 0x50000
ThomasSonderDesign 0:17d169ac117c 21 /******************************************************************************
ThomasSonderDesign 0:17d169ac117c 22 * Definitiontions
ThomasSonderDesign 0:17d169ac117c 23 */
ThomasSonderDesign 0:17d169ac117c 24 //Constants for black board
ThomasSonderDesign 0:17d169ac117c 25
ThomasSonderDesign 9:7c0f42f090e8 26 DigitalOut cs_mem(P0_16); //Set up memory's Chip Select pin BB:P0_2 QSB:P0_16 spi0
ThomasSonderDesign 9:7c0f42f090e8 27 DigitalOut cs_epd(P0_11); //Set up epd's Chip Select pin BB:P1_23 QSB:P0_11 spi1
ThomasSonderDesign 0:17d169ac117c 28 DigitalOut TconEn(P0_5); //Tcon Enable pin, open drain must invert
ThomasSonderDesign 0:17d169ac117c 29 DigitalOut start(P0_14);
ThomasSonderDesign 9:7c0f42f090e8 30 DigitalIn TCbusy(P0_4); //Tcon busy line P0_4
ThomasSonderDesign 0:17d169ac117c 31
ThomasSonderDesign 9:7c0f42f090e8 32 DigitalOut trigger(P1_19);
ThomasSonderDesign 9:7c0f42f090e8 33 DigitalOut myled(P0_23);
ThomasSonderDesign 9:7c0f42f090e8 34
ThomasSonderDesign 0:17d169ac117c 35 DigitalOut SRclk(P0_15); //Shift register clk signal
ThomasSonderDesign 0:17d169ac117c 36 DigitalOut SRlat (P1_22); //Shift register output latch
ThomasSonderDesign 0:17d169ac117c 37 DigitalOut SRds(P1_14); //Shiftreg data pin
ThomasSonderDesign 0:17d169ac117c 38
ThomasSonderDesign 0:17d169ac117c 39 DigitalIn E(P1_13); //Definne row row A input pin
ThomasSonderDesign 0:17d169ac117c 40 DigitalIn D(P0_7); //Definne row row B input pin
ThomasSonderDesign 0:17d169ac117c 41 DigitalIn C(P1_28); //Definne row row C input pin
ThomasSonderDesign 0:17d169ac117c 42 DigitalIn B(P1_31); //Definne row row D input pin
ThomasSonderDesign 0:17d169ac117c 43 DigitalIn A(P1_29); //Definne row row E input pin
ThomasSonderDesign 0:17d169ac117c 44
ThomasSonderDesign 9:7c0f42f090e8 45 DigitalIn modC(P0_1); //Definne row mod C input pin BB:P0_11 QSB:P0_1
ThomasSonderDesign 0:17d169ac117c 46 DigitalIn modB(P0_12); //Definne row mod B input pin
ThomasSonderDesign 0:17d169ac117c 47 DigitalIn modA(P0_13); //Definne row mod A input pin
ThomasSonderDesign 0:17d169ac117c 48
ThomasSonderDesign 0:17d169ac117c 49 Serial pc (P0_19,P0_18); //Setup a real serial port
ThomasSonderDesign 9:7c0f42f090e8 50 Memory mem(P0_16); //Create a new memory manager with chip select on P0_2
ThomasSonderDesign 0:17d169ac117c 51
ThomasSonderDesign 0:17d169ac117c 52 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 53
ThomasSonderDesign 0:17d169ac117c 54 volatile int *PIN39IOREG = (int *)0x4004403C;
ThomasSonderDesign 0:17d169ac117c 55 int reportLength = 64; //The length of the report recieved
ThomasSonderDesign 0:17d169ac117c 56
ThomasSonderDesign 0:17d169ac117c 57 //Codes to send to the pc
ThomasSonderDesign 0:17d169ac117c 58 int readyAndWaiting []= {2,0x25,0,0,0,0,0,0};
ThomasSonderDesign 0:17d169ac117c 59 int busy []= {2,0x50,0,0,0,0,0,0};
ThomasSonderDesign 0:17d169ac117c 60 int readyForComand []= {2,0x75,0,0,0,0,0,0};
ThomasSonderDesign 0:17d169ac117c 61
ThomasSonderDesign 0:17d169ac117c 62
ThomasSonderDesign 0:17d169ac117c 63 int GlobalAddress = 0; //The last adress written to plus one
ThomasSonderDesign 0:17d169ac117c 64 int lastErasedBlock =0; //The Adress of the last erases block
ThomasSonderDesign 0:17d169ac117c 65 int currentName = 0; //The position in the nameList of the curret layout
ThomasSonderDesign 1:1ec8bcd31b27 66 char nameList[16][5]; //A list of all the Layouts in memory, each name is 5 bytes long
ThomasSonderDesign 1:1ec8bcd31b27 67
ThomasSonderDesign 1:1ec8bcd31b27 68 //Locations in memory were the 16 layouts can be stored
ThomasSonderDesign 9:7c0f42f090e8 69 const int slots [] = {0*SLOTSIZE,1*SLOTSIZE, 2*SLOTSIZE,3*SLOTSIZE, 4*SLOTSIZE, 5*SLOTSIZE, 6*SLOTSIZE, 7*SLOTSIZE, 8*SLOTSIZE, 9*SLOTSIZE,10*SLOTSIZE,11*SLOTSIZE,12*SLOTSIZE};
ThomasSonderDesign 9:7c0f42f090e8 70 bool erasedSlots[]= {true,true,false,false,false,false,false,false,false,false,false,false,false,false,false,false};
ThomasSonderDesign 0:17d169ac117c 71
ThomasSonderDesign 0:17d169ac117c 72 int keybuffer[10][2]; //A buffer for storing key presses (mod key plus key)
ThomasSonderDesign 0:17d169ac117c 73
ThomasSonderDesign 0:17d169ac117c 74 int scanCode [5][14]= { //This 2D array maps key scan codes to letter codes
ThomasSonderDesign 0:17d169ac117c 75 {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 76 {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 77 {KEY_A, KEY_S, KEY_D, KEY_F, KEY_G, KEY_H, KEY_J, KEY_K, KEY_L, VK_OEM_1},
ThomasSonderDesign 0:17d169ac117c 78 {KEY_Z, KEY_X, KEY_C, KEY_V, KEY_B, KEY_N, KEY_M, VK_LSHIFT,VK_CONTROL,VK_LMENU},
ThomasSonderDesign 0:17d169ac117c 79 {VK_F1, VK_F2,VK_F3,VK_F4, VK_SPACE, VK_TAB, VK_BACK, VK_RSHIFT,VK_LWIN,VK_RMENU}
ThomasSonderDesign 0:17d169ac117c 80 };
ThomasSonderDesign 0:17d169ac117c 81
ThomasSonderDesign 9:7c0f42f090e8 82 /******************************************************************************
ThomasSonderDesign 9:7c0f42f090e8 83 * prototype Functions
ThomasSonderDesign 9:7c0f42f090e8 84 */
ThomasSonderDesign 9:7c0f42f090e8 85 short bitDouble(int);
ThomasSonderDesign 0:17d169ac117c 86
ThomasSonderDesign 0:17d169ac117c 87 /******************************************************************************
ThomasSonderDesign 0:17d169ac117c 88 * Set up Functions
ThomasSonderDesign 0:17d169ac117c 89 */
ThomasSonderDesign 0:17d169ac117c 90 char check(int depth) //Check availible memory
ThomasSonderDesign 0:17d169ac117c 91 {
ThomasSonderDesign 0:17d169ac117c 92 char c;
ThomasSonderDesign 0:17d169ac117c 93 char *ptr = new char;
ThomasSonderDesign 0:17d169ac117c 94 //pc.printf("stack at %p, heap at %p\n", &c, ptr);
ThomasSonderDesign 0:17d169ac117c 95 //pc.printf("sh,%i,%i\n", &c, ptr);
ThomasSonderDesign 0:17d169ac117c 96 pc.printf("mem size = %p\n", &c-ptr);
ThomasSonderDesign 0:17d169ac117c 97 //if (depth <= 0) return;
ThomasSonderDesign 0:17d169ac117c 98 // check(depth-1);
ThomasSonderDesign 0:17d169ac117c 99 free(ptr);
ThomasSonderDesign 0:17d169ac117c 100 return 1;
ThomasSonderDesign 0:17d169ac117c 101 }
ThomasSonderDesign 0:17d169ac117c 102
ThomasSonderDesign 0:17d169ac117c 103 /**
ThomasSonderDesign 0:17d169ac117c 104 * Set up the memory SPI
ThomasSonderDesign 0:17d169ac117c 105 */
ThomasSonderDesign 0:17d169ac117c 106 SPI setupSPI()
ThomasSonderDesign 0:17d169ac117c 107 {
ThomasSonderDesign 9:7c0f42f090e8 108 SPI my_spi(MEMSPI); // mosi, miso, sclk
ThomasSonderDesign 0:17d169ac117c 109 //cs_mem = 1; // Chip must be deselected
ThomasSonderDesign 0:17d169ac117c 110 my_spi.format(8,3); // Setup the spi for 8 bit data, low steady state clock,
ThomasSonderDesign 9:7c0f42f090e8 111 my_spi.frequency(10000000); // second edge capture, with a 1MHz clock rate, Will work up to 20MHz
ThomasSonderDesign 0:17d169ac117c 112 return my_spi;
ThomasSonderDesign 0:17d169ac117c 113 }
ThomasSonderDesign 0:17d169ac117c 114
ThomasSonderDesign 0:17d169ac117c 115
ThomasSonderDesign 0:17d169ac117c 116 /**
ThomasSonderDesign 0:17d169ac117c 117 * Setup USB HID, usefull for later not used in this iterarion
ThomasSonderDesign 0:17d169ac117c 118 */
ThomasSonderDesign 0:17d169ac117c 119 /*USBHID setupUSB()
ThomasSonderDesign 0:17d169ac117c 120 {
ThomasSonderDesign 0:17d169ac117c 121 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 122 return hid;
ThomasSonderDesign 0:17d169ac117c 123 }*/
ThomasSonderDesign 0:17d169ac117c 124
ThomasSonderDesign 0:17d169ac117c 125
ThomasSonderDesign 0:17d169ac117c 126 /******************************************************************************
ThomasSonderDesign 0:17d169ac117c 127 * USB Functions
ThomasSonderDesign 0:17d169ac117c 128 */
ThomasSonderDesign 0:17d169ac117c 129
ThomasSonderDesign 0:17d169ac117c 130 /**
ThomasSonderDesign 0:17d169ac117c 131 * checks the usb recive buffer, if it contains data it is coppired to USBDataBuffer and returns 1
ThomasSonderDesign 0:17d169ac117c 132 * if the empty return -1;
ThomasSonderDesign 0:17d169ac117c 133 */
ThomasSonderDesign 0:17d169ac117c 134 int readUSB(int USBDataBuffer[])
ThomasSonderDesign 0:17d169ac117c 135 {
ThomasSonderDesign 0:17d169ac117c 136 HID_REPORT recv_report;
ThomasSonderDesign 0:17d169ac117c 137 if(hid.readNB(&recv_report)) { //Check if there is a received report
ThomasSonderDesign 0:17d169ac117c 138 //printf("\n");
ThomasSonderDesign 0:17d169ac117c 139 for(int i = 0; i<recv_report.length; i++) { //Store the report in a locat array
ThomasSonderDesign 0:17d169ac117c 140 //printf(" %x", recv_report.data[i]);
ThomasSonderDesign 0:17d169ac117c 141 USBDataBuffer[i] = recv_report.data[i];
ThomasSonderDesign 0:17d169ac117c 142 }
ThomasSonderDesign 0:17d169ac117c 143 return 1;
ThomasSonderDesign 0:17d169ac117c 144 } else {
ThomasSonderDesign 0:17d169ac117c 145 return -1;
ThomasSonderDesign 0:17d169ac117c 146 }
ThomasSonderDesign 0:17d169ac117c 147 }
ThomasSonderDesign 0:17d169ac117c 148
ThomasSonderDesign 0:17d169ac117c 149
ThomasSonderDesign 0:17d169ac117c 150 /**
ThomasSonderDesign 0:17d169ac117c 151 * usbSend, send an eight byte report over usb
ThomasSonderDesign 0:17d169ac117c 152 */
ThomasSonderDesign 0:17d169ac117c 153 void sendUSB(int usbReport[])
ThomasSonderDesign 0:17d169ac117c 154 {
ThomasSonderDesign 0:17d169ac117c 155 //pc.printf("\nS: %x",usbReport[1]);
ThomasSonderDesign 0:17d169ac117c 156 HID_REPORT send_report;
ThomasSonderDesign 0:17d169ac117c 157 send_report.length = 8;
ThomasSonderDesign 0:17d169ac117c 158
ThomasSonderDesign 0:17d169ac117c 159 send_report.data[0] = usbReport[0];
ThomasSonderDesign 0:17d169ac117c 160 send_report.data[1] = usbReport[1]; //comand byte
ThomasSonderDesign 0:17d169ac117c 161 send_report.data[2] = usbReport[2];
ThomasSonderDesign 0:17d169ac117c 162 send_report.data[3] = usbReport[3];
ThomasSonderDesign 0:17d169ac117c 163 send_report.data[4] = usbReport[4];
ThomasSonderDesign 0:17d169ac117c 164 send_report.data[5] = usbReport[5];
ThomasSonderDesign 0:17d169ac117c 165 send_report.data[6] = usbReport[6];
ThomasSonderDesign 0:17d169ac117c 166 send_report.data[7] = usbReport[7];
ThomasSonderDesign 0:17d169ac117c 167 hid.send(&send_report);
ThomasSonderDesign 0:17d169ac117c 168 }
ThomasSonderDesign 0:17d169ac117c 169
ThomasSonderDesign 0:17d169ac117c 170
ThomasSonderDesign 0:17d169ac117c 171
ThomasSonderDesign 7:b30c411a6d36 172
ThomasSonderDesign 0:17d169ac117c 173 /******************************************************************************
ThomasSonderDesign 0:17d169ac117c 174 * Keyboard Functions
ThomasSonderDesign 0:17d169ac117c 175 */
ThomasSonderDesign 0:17d169ac117c 176
ThomasSonderDesign 0:17d169ac117c 177 /**
ThomasSonderDesign 0:17d169ac117c 178 * keyScan(int keyBuffer[][]). Sacns the keyboard matrix and stores any keypresses in the 2D keyBuffer
ThomasSonderDesign 0:17d169ac117c 179 * If a key press was detected it returns the most recent key press, otherwise it returns 0
ThomasSonderDesign 0:17d169ac117c 180 */
ThomasSonderDesign 0:17d169ac117c 181 int keyScan()
ThomasSonderDesign 0:17d169ac117c 182 {
ThomasSonderDesign 0:17d169ac117c 183 //Initialise and set Up code
ThomasSonderDesign 0:17d169ac117c 184 int counter=0; //Keubuffer index counter
ThomasSonderDesign 0:17d169ac117c 185 int rowNum = 0;
ThomasSonderDesign 0:17d169ac117c 186 int code =0; //the return value, the last key pushed
ThomasSonderDesign 0:17d169ac117c 187
ThomasSonderDesign 0:17d169ac117c 188 /*Clear the keybuffer*/
ThomasSonderDesign 0:17d169ac117c 189 for(int i = 0; i<10; i++) {
ThomasSonderDesign 0:17d169ac117c 190 keybuffer[i][0]=0;
ThomasSonderDesign 0:17d169ac117c 191 keybuffer[i][1]=0;
ThomasSonderDesign 0:17d169ac117c 192 }
ThomasSonderDesign 0:17d169ac117c 193
ThomasSonderDesign 0:17d169ac117c 194 int noCols = 16; //number of bits to be shifted
ThomasSonderDesign 0:17d169ac117c 195 int t = 1000; //wait time in uS. This is the period in us of the shift register clock
ThomasSonderDesign 0:17d169ac117c 196 SRclk=0;
ThomasSonderDesign 0:17d169ac117c 197 SRlat = 0;
ThomasSonderDesign 0:17d169ac117c 198 SRds =1; //Set first bit high
ThomasSonderDesign 0:17d169ac117c 199
ThomasSonderDesign 0:17d169ac117c 200
ThomasSonderDesign 0:17d169ac117c 201 for (int col = 0; col<noCols; col++) { //Loop through one shifit reg
ThomasSonderDesign 0:17d169ac117c 202 SRclk = 1; //clock in current bit // __ __
ThomasSonderDesign 0:17d169ac117c 203 wait_us(t/2); //SRclk__| |_..._| |_
ThomasSonderDesign 0:17d169ac117c 204 SRds = 0; //set dext bit low // ___
ThomasSonderDesign 0:17d169ac117c 205 wait_us(t/2); //SRds | |___..._____
ThomasSonderDesign 0:17d169ac117c 206 SRclk=0; // _ _
ThomasSonderDesign 0:17d169ac117c 207 SRlat = 1; //latch all data out //SRlat____| |_...___| |_
ThomasSonderDesign 0:17d169ac117c 208 wait_us(t/2); //
ThomasSonderDesign 0:17d169ac117c 209 SRlat=0;
ThomasSonderDesign 0:17d169ac117c 210
ThomasSonderDesign 0:17d169ac117c 211 /*
ThomasSonderDesign 0:17d169ac117c 212 Check if a button has been pressed by scaning the rows
ThomasSonderDesign 0:17d169ac117c 213 Generates a unique code depending on which button has been pressed
ThomasSonderDesign 0:17d169ac117c 214 The code is looked up in the scanCode Array
ThomasSonderDesign 0:17d169ac117c 215 */
ThomasSonderDesign 0:17d169ac117c 216 if(A>0) {
ThomasSonderDesign 0:17d169ac117c 217 //pc.printf("A\n");
ThomasSonderDesign 0:17d169ac117c 218 rowNum = 0;
ThomasSonderDesign 0:17d169ac117c 219 code = scanCode[rowNum][col];
ThomasSonderDesign 0:17d169ac117c 220 keybuffer[counter][1]= code;
ThomasSonderDesign 0:17d169ac117c 221 counter++;
ThomasSonderDesign 0:17d169ac117c 222 }
ThomasSonderDesign 0:17d169ac117c 223 if(B>0) {
ThomasSonderDesign 0:17d169ac117c 224 //pc.printf("B\n");
ThomasSonderDesign 0:17d169ac117c 225 rowNum = 1;
ThomasSonderDesign 0:17d169ac117c 226 code = scanCode[rowNum][col];
ThomasSonderDesign 0:17d169ac117c 227 keybuffer[counter][1]= code;
ThomasSonderDesign 0:17d169ac117c 228 counter++;
ThomasSonderDesign 0:17d169ac117c 229 }
ThomasSonderDesign 0:17d169ac117c 230 if(C>0) {
ThomasSonderDesign 0:17d169ac117c 231 //pc.printf("C\n");
ThomasSonderDesign 0:17d169ac117c 232 rowNum = 2;
ThomasSonderDesign 0:17d169ac117c 233 code = scanCode[rowNum][col];
ThomasSonderDesign 0:17d169ac117c 234 keybuffer[counter][1]= code;
ThomasSonderDesign 0:17d169ac117c 235 counter++;
ThomasSonderDesign 0:17d169ac117c 236 }
ThomasSonderDesign 0:17d169ac117c 237 if(D>0) {
ThomasSonderDesign 0:17d169ac117c 238 //pc.printf("D\n");
ThomasSonderDesign 0:17d169ac117c 239 rowNum = 3;
ThomasSonderDesign 0:17d169ac117c 240 code = scanCode[rowNum][col];
ThomasSonderDesign 0:17d169ac117c 241 keybuffer[counter][1]= code;
ThomasSonderDesign 0:17d169ac117c 242 counter++;
ThomasSonderDesign 0:17d169ac117c 243 }
ThomasSonderDesign 0:17d169ac117c 244 if(E>0) {
ThomasSonderDesign 0:17d169ac117c 245 //pc.printf("E\n");
ThomasSonderDesign 0:17d169ac117c 246 rowNum = 4;
ThomasSonderDesign 0:17d169ac117c 247 code = scanCode[rowNum][col];
ThomasSonderDesign 0:17d169ac117c 248 keybuffer[counter][1]= code;
ThomasSonderDesign 0:17d169ac117c 249 counter++;
ThomasSonderDesign 0:17d169ac117c 250 }
ThomasSonderDesign 0:17d169ac117c 251
ThomasSonderDesign 0:17d169ac117c 252 /*Scan the mod keys and assign them to the mod column of key buffer in the from zero up*/
ThomasSonderDesign 0:17d169ac117c 253 if(col>0) {
ThomasSonderDesign 0:17d169ac117c 254 counter=0;
ThomasSonderDesign 0:17d169ac117c 255
ThomasSonderDesign 0:17d169ac117c 256 if(modC>0) {
ThomasSonderDesign 0:17d169ac117c 257 rowNum = 0;
ThomasSonderDesign 0:17d169ac117c 258 code = scanCode[rowNum][col];
ThomasSonderDesign 0:17d169ac117c 259 keybuffer[counter][0]= code;
ThomasSonderDesign 0:17d169ac117c 260 }
ThomasSonderDesign 0:17d169ac117c 261 if(modB>0) {
ThomasSonderDesign 0:17d169ac117c 262 rowNum = 0;
ThomasSonderDesign 0:17d169ac117c 263 code = scanCode[rowNum][col];
ThomasSonderDesign 0:17d169ac117c 264 keybuffer[counter][0]= code;
ThomasSonderDesign 0:17d169ac117c 265 }
ThomasSonderDesign 0:17d169ac117c 266 if(modA>0) {
ThomasSonderDesign 0:17d169ac117c 267 rowNum = 0;
ThomasSonderDesign 0:17d169ac117c 268 code = scanCode[rowNum][col];
ThomasSonderDesign 0:17d169ac117c 269 keybuffer[counter][0]= code;
ThomasSonderDesign 0:17d169ac117c 270 }
ThomasSonderDesign 0:17d169ac117c 271 }
ThomasSonderDesign 0:17d169ac117c 272 }
ThomasSonderDesign 0:17d169ac117c 273 return code;
ThomasSonderDesign 0:17d169ac117c 274 }
ThomasSonderDesign 0:17d169ac117c 275
ThomasSonderDesign 0:17d169ac117c 276
ThomasSonderDesign 0:17d169ac117c 277 /**
ThomasSonderDesign 0:17d169ac117c 278 * int sendKey(int mod, int key). Sends a keypress to the pc over usb
ThomasSonderDesign 0:17d169ac117c 279 */
ThomasSonderDesign 0:17d169ac117c 280 void sendKey(int mod, int key)
ThomasSonderDesign 0:17d169ac117c 281 {
ThomasSonderDesign 0:17d169ac117c 282 int temp[]= {0x01,mod,key,0,0,0,0,0};
ThomasSonderDesign 0:17d169ac117c 283 sendUSB(temp);
ThomasSonderDesign 0:17d169ac117c 284 }
ThomasSonderDesign 0:17d169ac117c 285
ThomasSonderDesign 7:b30c411a6d36 286 /**
ThomasSonderDesign 7:b30c411a6d36 287 * keyCheck(), scanss the keys and sends the keypress to the pc over usb
ThomasSonderDesign 7:b30c411a6d36 288 */
ThomasSonderDesign 9:7c0f42f090e8 289 void keyCheck()
ThomasSonderDesign 9:7c0f42f090e8 290 {
ThomasSonderDesign 8:3577b060d7af 291 //pc.printf("KeyCheck\n");
ThomasSonderDesign 7:b30c411a6d36 292 if (keyScan()>0) { //check if keyScan returned key presss
ThomasSonderDesign 9:7c0f42f090e8 293 //pc.printf("\nKey scan|n");
ThomasSonderDesign 9:7c0f42f090e8 294 int countpos =0;
ThomasSonderDesign 9:7c0f42f090e8 295 while(keybuffer[countpos][1]>0) { //While there are keypresses in the buffer
ThomasSonderDesign 9:7c0f42f090e8 296 pc.printf("%i",keybuffer[countpos][1]);
ThomasSonderDesign 9:7c0f42f090e8 297 pc.printf(" ");
ThomasSonderDesign 9:7c0f42f090e8 298 sendKey(keybuffer[countpos][0],keybuffer[countpos][1]);//Send key press
ThomasSonderDesign 9:7c0f42f090e8 299 countpos++;
ThomasSonderDesign 9:7c0f42f090e8 300 myled=0;
ThomasSonderDesign 7:b30c411a6d36 301 }
ThomasSonderDesign 9:7c0f42f090e8 302 }
ThomasSonderDesign 7:b30c411a6d36 303 }
ThomasSonderDesign 0:17d169ac117c 304
ThomasSonderDesign 0:17d169ac117c 305 /******************************************************************************
ThomasSonderDesign 1:1ec8bcd31b27 306 * Memory control funtions
ThomasSonderDesign 0:17d169ac117c 307 */
ThomasSonderDesign 0:17d169ac117c 308
ThomasSonderDesign 0:17d169ac117c 309
ThomasSonderDesign 0:17d169ac117c 310 /**
ThomasSonderDesign 0:17d169ac117c 311 * Writes the contense of USBDataBuffer to memoryBuffer, starting at bufferIndex
ThomasSonderDesign 0:17d169ac117c 312 * returns the index of the last written byte+1;
ThomasSonderDesign 0:17d169ac117c 313 */
ThomasSonderDesign 0:17d169ac117c 314 int appendBuffer(int USBDataBuffer[], char memoryBuffer[], int bufferIndex)
ThomasSonderDesign 0:17d169ac117c 315 {
ThomasSonderDesign 5:07113abf18c0 316 //printf("\n");
ThomasSonderDesign 0:17d169ac117c 317 int posIndex=0;
ThomasSonderDesign 0:17d169ac117c 318 for(int i = 0; i < 64; i++) {
ThomasSonderDesign 9:7c0f42f090e8 319
ThomasSonderDesign 0:17d169ac117c 320 memoryBuffer[bufferIndex+i]=USBDataBuffer[i];
ThomasSonderDesign 0:17d169ac117c 321 posIndex++;
ThomasSonderDesign 0:17d169ac117c 322 }
ThomasSonderDesign 0:17d169ac117c 323 return (bufferIndex+posIndex);
ThomasSonderDesign 0:17d169ac117c 324 }
ThomasSonderDesign 0:17d169ac117c 325
ThomasSonderDesign 0:17d169ac117c 326 /**
ThomasSonderDesign 0:17d169ac117c 327 *Sends the ready and waiting signall and loops untill data is recieved.
ThomasSonderDesign 0:17d169ac117c 328 *Recieved data is stored in the USBDataBuffer
ThomasSonderDesign 0:17d169ac117c 329 */
ThomasSonderDesign 0:17d169ac117c 330 void waitForData(int USBDataBuffer[])
ThomasSonderDesign 0:17d169ac117c 331 {
ThomasSonderDesign 0:17d169ac117c 332 sendUSB(readyAndWaiting);
ThomasSonderDesign 0:17d169ac117c 333 while (readUSB(USBDataBuffer)<1) {
ThomasSonderDesign 0:17d169ac117c 334 sendUSB(readyAndWaiting);
ThomasSonderDesign 0:17d169ac117c 335 }
ThomasSonderDesign 0:17d169ac117c 336 }
ThomasSonderDesign 0:17d169ac117c 337
ThomasSonderDesign 9:7c0f42f090e8 338 /**
ThomasSonderDesign 9:7c0f42f090e8 339 * Reads 'length' elements into a char array starting at the 24bit Address.
ThomasSonderDesign 9:7c0f42f090e8 340 *If length is greater than BufferSize (3840 bytes) the function will terminate
ThomasSonderDesign 9:7c0f42f090e8 341 *and return the start address.
ThomasSonderDesign 9:7c0f42f090e8 342 */
ThomasSonderDesign 9:7c0f42f090e8 343 int readData(SPI my_spi, short value [], int Address, int length, int doubleSelect)
ThomasSonderDesign 9:7c0f42f090e8 344 {
ThomasSonderDesign 9:7c0f42f090e8 345 //if(length>bufferSize) {
ThomasSonderDesign 9:7c0f42f090e8 346 //printf("\nLength %i exceeds Max Length\n",length);
ThomasSonderDesign 9:7c0f42f090e8 347 //return Address;
ThomasSonderDesign 9:7c0f42f090e8 348 //}
ThomasSonderDesign 9:7c0f42f090e8 349 int temp = 0;
ThomasSonderDesign 9:7c0f42f090e8 350 short temp1 = 0;
ThomasSonderDesign 9:7c0f42f090e8 351 cs_mem = 1; //Ensure cs is deselected
ThomasSonderDesign 9:7c0f42f090e8 352 //wait_us(10);
ThomasSonderDesign 9:7c0f42f090e8 353 cs_mem = 0; //memory is selected
ThomasSonderDesign 9:7c0f42f090e8 354 my_spi.write(0x03); //Send read command
ThomasSonderDesign 9:7c0f42f090e8 355 my_spi.write(Address>>16); //Send high address byte
ThomasSonderDesign 9:7c0f42f090e8 356 my_spi.write(Address>>8); //Send mid address byte
ThomasSonderDesign 9:7c0f42f090e8 357 my_spi.write(Address); //Send low address byte
ThomasSonderDesign 9:7c0f42f090e8 358
ThomasSonderDesign 9:7c0f42f090e8 359
ThomasSonderDesign 9:7c0f42f090e8 360 for(int i =0; i <length; i++) {
ThomasSonderDesign 9:7c0f42f090e8 361 temp = my_spi.write(dummy);//Send dummy byte to read out value ate Address
ThomasSonderDesign 9:7c0f42f090e8 362 temp1 = bitDouble(temp);
ThomasSonderDesign 9:7c0f42f090e8 363 value[i]= temp1;
ThomasSonderDesign 9:7c0f42f090e8 364 //printf(" %X",value[i]);
ThomasSonderDesign 9:7c0f42f090e8 365 Address++;
ThomasSonderDesign 9:7c0f42f090e8 366 }
ThomasSonderDesign 9:7c0f42f090e8 367 cs_mem = 1;
ThomasSonderDesign 9:7c0f42f090e8 368 return Address; //Return the address of the next unread byte
ThomasSonderDesign 9:7c0f42f090e8 369 }
ThomasSonderDesign 9:7c0f42f090e8 370
ThomasSonderDesign 4:e6e1642724d4 371
ThomasSonderDesign 4:e6e1642724d4 372 /**
ThomasSonderDesign 4:e6e1642724d4 373 * receives 64 packets over usb and stores them in memooryBuffer. When memory Buffer is full it is
ThomasSonderDesign 4:e6e1642724d4 374 * written to memory at address. This is repeated 336 times to write a whole image to memory.
ThomasSonderDesign 4:e6e1642724d4 375 * returns the next availible adsress;
ThomasSonderDesign 4:e6e1642724d4 376 */
ThomasSonderDesign 4:e6e1642724d4 377 int writeImage(SPI my_spi,int Address)
ThomasSonderDesign 4:e6e1642724d4 378 {
ThomasSonderDesign 4:e6e1642724d4 379 Timer t;
ThomasSonderDesign 4:e6e1642724d4 380 t.start(); //Start the timer
ThomasSonderDesign 5:07113abf18c0 381 pc.printf("\nAddress: %i\n", Address);
ThomasSonderDesign 4:e6e1642724d4 382 int USBDataBuffer [64]; //Creat a buffer for recived data
ThomasSonderDesign 4:e6e1642724d4 383 char memoryBuffer [bufferSize]; //Create a memory buffer, to be sent to flash
ThomasSonderDesign 4:e6e1642724d4 384 int bufferIndex = 0; //points to the next available possition in memory
ThomasSonderDesign 4:e6e1642724d4 385 int startAddress = Address;
ThomasSonderDesign 9:7c0f42f090e8 386 int imageSize = 310200; //The number of bytes to write, 86272 for 9.8"
ThomasSonderDesign 9:7c0f42f090e8 387 while (Address<startAddress+imageSize) {
ThomasSonderDesign 4:e6e1642724d4 388 //waitForData(USBDataBuffer); //Waits untill data is recieved on usb, puts it in USBDataBuffer
ThomasSonderDesign 4:e6e1642724d4 389 while(bufferIndex<bufferSize) {
ThomasSonderDesign 4:e6e1642724d4 390 waitForData(USBDataBuffer);
ThomasSonderDesign 9:7c0f42f090e8 391 bufferIndex=appendBuffer(USBDataBuffer, memoryBuffer, bufferIndex); //Appends USBDataBuffer onto memoryBuffer
ThomasSonderDesign 4:e6e1642724d4 392 }
ThomasSonderDesign 9:7c0f42f090e8 393 bufferIndex=0;
ThomasSonderDesign 4:e6e1642724d4 394 //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 395 //protected. this erases a block before writung to it if nessisary.
ThomasSonderDesign 9:7c0f42f090e8 396 int currentSlot = Address/SLOTSIZE;
ThomasSonderDesign 4:e6e1642724d4 397 if (erasedSlots[currentSlot]) {
ThomasSonderDesign 4:e6e1642724d4 398 Address = mem.writeData(my_spi, memoryBuffer, Address, bufferSize);
ThomasSonderDesign 4:e6e1642724d4 399 } else {
ThomasSonderDesign 9:7c0f42f090e8 400 pc.printf("\nCan not write to unerased slot. %X", Address);
ThomasSonderDesign 5:07113abf18c0 401 Address = mem.writeData(my_spi, memoryBuffer, Address, bufferSize);
ThomasSonderDesign 9:7c0f42f090e8 402 }
ThomasSonderDesign 9:7c0f42f090e8 403
ThomasSonderDesign 4:e6e1642724d4 404 }
ThomasSonderDesign 4:e6e1642724d4 405 pc.printf("\n pinnished writing");
ThomasSonderDesign 4:e6e1642724d4 406 t.stop();
ThomasSonderDesign 4:e6e1642724d4 407 pc.printf("\nwrite image %i", t.read_ms());
ThomasSonderDesign 4:e6e1642724d4 408 t.reset();
ThomasSonderDesign 4:e6e1642724d4 409 return Address;
ThomasSonderDesign 4:e6e1642724d4 410 }
ThomasSonderDesign 4:e6e1642724d4 411
ThomasSonderDesign 0:17d169ac117c 412 /**
ThomasSonderDesign 5:07113abf18c0 413 * Writes a single memorybuffer to memory
ThomasSonderDesign 0:17d169ac117c 414 * receives 64 packets over usb and stores them in memooryBuffer. When memory Buffer is full it is
ThomasSonderDesign 0:17d169ac117c 415 * written to memory at address.
ThomasSonderDesign 0:17d169ac117c 416 * returns the next availible adsress;
ThomasSonderDesign 0:17d169ac117c 417 */
ThomasSonderDesign 0:17d169ac117c 418 int writeFrame(SPI my_spi,int Address)
ThomasSonderDesign 0:17d169ac117c 419 {
ThomasSonderDesign 0:17d169ac117c 420 int USBDataBuffer [64]; //Creat a buffer for recived data
ThomasSonderDesign 0:17d169ac117c 421 char memoryBuffer [bufferSize]; //Create a memory buffer, to be sent to flash
ThomasSonderDesign 0:17d169ac117c 422 int bufferIndex = 0; //points to the next available possition in memory
ThomasSonderDesign 3:d4e1892846fb 423 Timer t;
ThomasSonderDesign 3:d4e1892846fb 424 t.start(); //Start the timer
ThomasSonderDesign 0:17d169ac117c 425
ThomasSonderDesign 0:17d169ac117c 426 waitForData(USBDataBuffer); //Waits untill data is recieved on usb, puts it in USBDataBuffer
ThomasSonderDesign 3:d4e1892846fb 427 t.stop();
ThomasSonderDesign 4:e6e1642724d4 428
ThomasSonderDesign 0:17d169ac117c 429 while(bufferIndex<bufferSize) {
ThomasSonderDesign 0:17d169ac117c 430 bufferIndex=appendBuffer(USBDataBuffer, memoryBuffer, bufferIndex); //Appends USBDataBuffer onto memoryBuffer
ThomasSonderDesign 3:d4e1892846fb 431 t.start();
ThomasSonderDesign 0:17d169ac117c 432 waitForData(USBDataBuffer);
ThomasSonderDesign 3:d4e1892846fb 433 t.stop();
ThomasSonderDesign 0:17d169ac117c 434 }
ThomasSonderDesign 0:17d169ac117c 435
ThomasSonderDesign 0:17d169ac117c 436 //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 437 //protected. this erases a block before writung to it if nessisary.
ThomasSonderDesign 9:7c0f42f090e8 438 int currentSlot = Address/SLOTSIZE;
ThomasSonderDesign 2:8b66a3f7e202 439 pc.printf("\nCurrent slot: %i", currentSlot);
ThomasSonderDesign 2:8b66a3f7e202 440 if (erasedSlots[currentSlot]) {
ThomasSonderDesign 1:1ec8bcd31b27 441 pc.printf("\nNE");
ThomasSonderDesign 0:17d169ac117c 442 Address = mem.writeData(my_spi, memoryBuffer, Address, bufferSize);
ThomasSonderDesign 0:17d169ac117c 443 } else {
ThomasSonderDesign 2:8b66a3f7e202 444 pc.printf("\nCan not write to unerased slot.");
ThomasSonderDesign 4:e6e1642724d4 445 }
ThomasSonderDesign 3:d4e1892846fb 446 //t.stop();
ThomasSonderDesign 3:d4e1892846fb 447 pc.printf("\nWait1 Wate2-4 %i", t.read_ms());
ThomasSonderDesign 3:d4e1892846fb 448 t.reset();
ThomasSonderDesign 0:17d169ac117c 449 return Address;
ThomasSonderDesign 0:17d169ac117c 450 }
ThomasSonderDesign 0:17d169ac117c 451
ThomasSonderDesign 1:1ec8bcd31b27 452
ThomasSonderDesign 1:1ec8bcd31b27 453 /**
ThomasSonderDesign 1:1ec8bcd31b27 454 * Sends a report containing a the name of the layout stored at a given slot
ThomasSonderDesign 1:1ec8bcd31b27 455 */
ThomasSonderDesign 2:8b66a3f7e202 456 void getLayoutName(int slot)
ThomasSonderDesign 1:1ec8bcd31b27 457 {
ThomasSonderDesign 1:1ec8bcd31b27 458 int temp [] = {0x31,slot,nameList[slot][0],nameList[slot][1],nameList[slot][2],nameList[slot][3],nameList[slot][4],0};
ThomasSonderDesign 1:1ec8bcd31b27 459 sendUSB(temp);
ThomasSonderDesign 8:3577b060d7af 460 pc.printf("\nSlot %d = %c%c%c%c%c",slot, nameList[slot][0],nameList[slot][1],nameList[slot][2],nameList[slot][3],nameList[slot][4]);
ThomasSonderDesign 1:1ec8bcd31b27 461 }
ThomasSonderDesign 1:1ec8bcd31b27 462
ThomasSonderDesign 1:1ec8bcd31b27 463
ThomasSonderDesign 1:1ec8bcd31b27 464 /**
ThomasSonderDesign 1:1ec8bcd31b27 465 * Sends three reports containing the list of layout names stored in memory.
ThomasSonderDesign 1:1ec8bcd31b27 466 */
ThomasSonderDesign 1:1ec8bcd31b27 467 void getNameList()
ThomasSonderDesign 1:1ec8bcd31b27 468 {
ThomasSonderDesign 1:1ec8bcd31b27 469 for(int slot =0; slot< 16; slot++) {
ThomasSonderDesign 2:8b66a3f7e202 470 getLayoutName(slot);
ThomasSonderDesign 9:7c0f42f090e8 471 }
ThomasSonderDesign 1:1ec8bcd31b27 472 }
ThomasSonderDesign 0:17d169ac117c 473
ThomasSonderDesign 0:17d169ac117c 474 /**
ThomasSonderDesign 0:17d169ac117c 475 * Sends the name of the Current layout
ThomasSonderDesign 0:17d169ac117c 476 */
ThomasSonderDesign 1:1ec8bcd31b27 477 void getCurrentLayout()
ThomasSonderDesign 0:17d169ac117c 478 {
ThomasSonderDesign 2:8b66a3f7e202 479 getLayoutName(currentName);
ThomasSonderDesign 0:17d169ac117c 480 }
ThomasSonderDesign 0:17d169ac117c 481
ThomasSonderDesign 0:17d169ac117c 482 /**
ThomasSonderDesign 0:17d169ac117c 483 * Writes the name of a given layout to the top memory address in its reserved block
ThomasSonderDesign 1:1ec8bcd31b27 484 * name[] is a 5 bytes char array with the most significant byte at name[0]
ThomasSonderDesign 0:17d169ac117c 485 */
ThomasSonderDesign 2:8b66a3f7e202 486 void nameBlock(SPI my_spi, char name[], int slot)
ThomasSonderDesign 0:17d169ac117c 487 {
ThomasSonderDesign 1:1ec8bcd31b27 488 //char temp[]= {name};
ThomasSonderDesign 8:3577b060d7af 489 mem.writeData(my_spi, name, slots[slot]+0x1ff00, 5);
ThomasSonderDesign 2:8b66a3f7e202 490 }
ThomasSonderDesign 2:8b66a3f7e202 491
ThomasSonderDesign 2:8b66a3f7e202 492 /**
ThomasSonderDesign 2:8b66a3f7e202 493 * Reads memory to find the names of the layouts stored. puts the names into nameList
ThomasSonderDesign 2:8b66a3f7e202 494 */
ThomasSonderDesign 2:8b66a3f7e202 495 void populateNameList(SPI my_spi)
ThomasSonderDesign 2:8b66a3f7e202 496 {
ThomasSonderDesign 4:e6e1642724d4 497 for(int slot=0; slot<16; slot++) {
ThomasSonderDesign 9:7c0f42f090e8 498 short name[5];
ThomasSonderDesign 8:3577b060d7af 499 mem.readData(my_spi, name, slots[slot]+0x1FF00, 5); //Read five bytes from the end of a slot into the name array
ThomasSonderDesign 4:e6e1642724d4 500 for( int i = 0; i<5; i++) {
ThomasSonderDesign 4:e6e1642724d4 501 nameList[slot][i]=name[i];
ThomasSonderDesign 4:e6e1642724d4 502 }
ThomasSonderDesign 4:e6e1642724d4 503 }
ThomasSonderDesign 2:8b66a3f7e202 504 }
ThomasSonderDesign 2:8b66a3f7e202 505
ThomasSonderDesign 2:8b66a3f7e202 506 /**
ThomasSonderDesign 2:8b66a3f7e202 507 * Prepares the memory for a new Layout, writes the layout's name, and erases the blocks
ThomasSonderDesign 2:8b66a3f7e202 508 */
ThomasSonderDesign 4:e6e1642724d4 509 void prepImage(SPI my_spi, int slot, char name[])
ThomasSonderDesign 2:8b66a3f7e202 510 {
ThomasSonderDesign 5:07113abf18c0 511 pc.printf("\nSlot: %i", slots[slot]);
ThomasSonderDesign 4:e6e1642724d4 512 mem.blockErase(my_spi, slots[slot]); //erase the bottom block of the slot
ThomasSonderDesign 9:7c0f42f090e8 513 mem.blockErase(my_spi, slots[slot]+0x10000); //erase the middle block of the slot
ThomasSonderDesign 9:7c0f42f090e8 514 mem.blockErase(my_spi, slots[slot]+0x20000); //erase the top block of the slot
ThomasSonderDesign 9:7c0f42f090e8 515 mem.blockErase(my_spi, slots[slot]+0x30000); //erase the top block of the slot
ThomasSonderDesign 9:7c0f42f090e8 516 mem.blockErase(my_spi, slots[slot]+0x40000); //erase the top block of the slot
ThomasSonderDesign 8:3577b060d7af 517 pc.printf("\nWorking");
ThomasSonderDesign 7:b30c411a6d36 518 nameBlock(my_spi, name, slots[slot]/*+0x1FFF9*/); //Write the name of the layout to memory
ThomasSonderDesign 4:e6e1642724d4 519 erasedSlots[slot]=true; //Mark the erased slot as true
ThomasSonderDesign 8:3577b060d7af 520 populateNameList(my_spi);
ThomasSonderDesign 0:17d169ac117c 521 }
ThomasSonderDesign 0:17d169ac117c 522
ThomasSonderDesign 1:1ec8bcd31b27 523
ThomasSonderDesign 1:1ec8bcd31b27 524 /******************************************************************************
ThomasSonderDesign 1:1ec8bcd31b27 525 * Display control funtions
ThomasSonderDesign 1:1ec8bcd31b27 526 */
ThomasSonderDesign 1:1ec8bcd31b27 527
ThomasSonderDesign 0:17d169ac117c 528 /*###### EPD Set Up ######*/
ThomasSonderDesign 0:17d169ac117c 529 //Sets up the EPD spi pins
ThomasSonderDesign 0:17d169ac117c 530 SPI setupEPD()
ThomasSonderDesign 0:17d169ac117c 531 {
ThomasSonderDesign 0:17d169ac117c 532 pc.printf("\nEpd setup");
ThomasSonderDesign 0:17d169ac117c 533 /////Setup the spi link with the EDP////
ThomasSonderDesign 9:7c0f42f090e8 534 SPI epd_spi(EPDSPI); //SPI setup: mosi, miso, sclk
ThomasSonderDesign 9:7c0f42f090e8 535 // Setup the spi for 16 bit data, low steady state clock,
ThomasSonderDesign 0:17d169ac117c 536 // second edge capture, with a 5MHz clock rate
ThomasSonderDesign 9:7c0f42f090e8 537 epd_spi.format(16,0);
ThomasSonderDesign 9:7c0f42f090e8 538 epd_spi.frequency(10000000);
ThomasSonderDesign 0:17d169ac117c 539 return epd_spi;
ThomasSonderDesign 0:17d169ac117c 540 }
ThomasSonderDesign 0:17d169ac117c 541
ThomasSonderDesign 9:7c0f42f090e8 542 /******************************************************************************
ThomasSonderDesign 9:7c0f42f090e8 543 * ITE driver Functions
ThomasSonderDesign 9:7c0f42f090e8 544 */
ThomasSonderDesign 9:7c0f42f090e8 545
ThomasSonderDesign 9:7c0f42f090e8 546 /*###### Wait for LCD ######*/
ThomasSonderDesign 9:7c0f42f090e8 547 //delay until the hardware ready pin on LCD is set
ThomasSonderDesign 9:7c0f42f090e8 548 void waitForLCD()
ThomasSonderDesign 9:7c0f42f090e8 549 {
ThomasSonderDesign 9:7c0f42f090e8 550 myled=1;
ThomasSonderDesign 9:7c0f42f090e8 551
ThomasSonderDesign 9:7c0f42f090e8 552 while(TCbusy==0) {
ThomasSonderDesign 9:7c0f42f090e8 553 wait_us(1);
ThomasSonderDesign 9:7c0f42f090e8 554 }
ThomasSonderDesign 9:7c0f42f090e8 555 myled=0;
ThomasSonderDesign 9:7c0f42f090e8 556 }
ThomasSonderDesign 9:7c0f42f090e8 557
ThomasSonderDesign 9:7c0f42f090e8 558 /*###### Mirror the bits in a int ######*/
ThomasSonderDesign 9:7c0f42f090e8 559 int reverse(int in)
ThomasSonderDesign 9:7c0f42f090e8 560 {
ThomasSonderDesign 9:7c0f42f090e8 561 int out=0;
ThomasSonderDesign 9:7c0f42f090e8 562 out|=in&128;
ThomasSonderDesign 9:7c0f42f090e8 563 out|=in&64;
ThomasSonderDesign 9:7c0f42f090e8 564 out|=in&32;
ThomasSonderDesign 9:7c0f42f090e8 565 out|=in&16;
ThomasSonderDesign 9:7c0f42f090e8 566 out|=in&8;
ThomasSonderDesign 9:7c0f42f090e8 567 out|=in&4;
ThomasSonderDesign 9:7c0f42f090e8 568 out|=in&2;
ThomasSonderDesign 9:7c0f42f090e8 569 out|=in&1;
ThomasSonderDesign 9:7c0f42f090e8 570 return out;
ThomasSonderDesign 9:7c0f42f090e8 571 }
ThomasSonderDesign 9:7c0f42f090e8 572
ThomasSonderDesign 9:7c0f42f090e8 573 /*###### Double the number of bits (up to 16)in an int eg: 1010 => 11001100 ######*/
ThomasSonderDesign 9:7c0f42f090e8 574 /*short bitDouble(int in)
ThomasSonderDesign 9:7c0f42f090e8 575 {
ThomasSonderDesign 9:7c0f42f090e8 576 short out=0;
ThomasSonderDesign 9:7c0f42f090e8 577 int y = 0;
ThomasSonderDesign 9:7c0f42f090e8 578 for(int i =0; i<8; i++) {
ThomasSonderDesign 9:7c0f42f090e8 579 y = 1<<i;
ThomasSonderDesign 9:7c0f42f090e8 580 if((in&y)>0) {
ThomasSonderDesign 9:7c0f42f090e8 581 out=out|(3<<(2*i));
ThomasSonderDesign 9:7c0f42f090e8 582 }
ThomasSonderDesign 9:7c0f42f090e8 583 }
ThomasSonderDesign 9:7c0f42f090e8 584 return out;
ThomasSonderDesign 9:7c0f42f090e8 585 }*/
ThomasSonderDesign 9:7c0f42f090e8 586
ThomasSonderDesign 9:7c0f42f090e8 587 short bitDouble(int in)
ThomasSonderDesign 9:7c0f42f090e8 588 {
ThomasSonderDesign 9:7c0f42f090e8 589 short out=0;
ThomasSonderDesign 9:7c0f42f090e8 590 //1
ThomasSonderDesign 9:7c0f42f090e8 591 out=out|(3*(in&1));
ThomasSonderDesign 9:7c0f42f090e8 592 //2
ThomasSonderDesign 9:7c0f42f090e8 593 out=out|((in&2)*6);
ThomasSonderDesign 9:7c0f42f090e8 594 //4
ThomasSonderDesign 9:7c0f42f090e8 595 out=out|((in&4)*12);
ThomasSonderDesign 9:7c0f42f090e8 596 //8
ThomasSonderDesign 9:7c0f42f090e8 597 out=out|((in&8)*24);
ThomasSonderDesign 9:7c0f42f090e8 598 //16
ThomasSonderDesign 9:7c0f42f090e8 599 out=out|((in&16)*48);
ThomasSonderDesign 9:7c0f42f090e8 600 //32
ThomasSonderDesign 9:7c0f42f090e8 601 out=out|((in&32)*96);
ThomasSonderDesign 9:7c0f42f090e8 602 //64
ThomasSonderDesign 9:7c0f42f090e8 603 out=out|((in&64)*192);
ThomasSonderDesign 9:7c0f42f090e8 604 //128
ThomasSonderDesign 9:7c0f42f090e8 605 out=out|((in&128)*384);
ThomasSonderDesign 9:7c0f42f090e8 606
ThomasSonderDesign 9:7c0f42f090e8 607 return out;
ThomasSonderDesign 9:7c0f42f090e8 608 }
ThomasSonderDesign 9:7c0f42f090e8 609
ThomasSonderDesign 0:17d169ac117c 610
ThomasSonderDesign 9:7c0f42f090e8 611 /*###### Send Comands ######*/
ThomasSonderDesign 9:7c0f42f090e8 612 //send a comand to the LCD
ThomasSonderDesign 9:7c0f42f090e8 613 void sendComand(SPI my_spi, int comand)
ThomasSonderDesign 9:7c0f42f090e8 614 {
ThomasSonderDesign 9:7c0f42f090e8 615 waitForLCD();
ThomasSonderDesign 9:7c0f42f090e8 616 cs_epd = 0; // Bring chip select low
ThomasSonderDesign 9:7c0f42f090e8 617 //Send write commandpreamble 0x6000
ThomasSonderDesign 9:7c0f42f090e8 618 my_spi.write(0x6000);
ThomasSonderDesign 9:7c0f42f090e8 619 //Send command
ThomasSonderDesign 9:7c0f42f090e8 620 my_spi.write(comand);
ThomasSonderDesign 9:7c0f42f090e8 621 cs_epd = 1;
ThomasSonderDesign 9:7c0f42f090e8 622 }
ThomasSonderDesign 9:7c0f42f090e8 623
ThomasSonderDesign 9:7c0f42f090e8 624 /*###### Send N Data ######*/
ThomasSonderDesign 9:7c0f42f090e8 625 //send some 16 bit words to the LCD
ThomasSonderDesign 9:7c0f42f090e8 626 //data[] is an int array containg wordsN number of words
ThomasSonderDesign 9:7c0f42f090e8 627 void sendNData(SPI my_spi,int data[], int wordsN) //for ints
ThomasSonderDesign 9:7c0f42f090e8 628 {
ThomasSonderDesign 9:7c0f42f090e8 629 waitForLCD();
ThomasSonderDesign 9:7c0f42f090e8 630 cs_epd = 0; // Bring chip select low
ThomasSonderDesign 9:7c0f42f090e8 631 //Send write data preamble 0x0000
ThomasSonderDesign 9:7c0f42f090e8 632 my_spi.write(0x0000);
ThomasSonderDesign 9:7c0f42f090e8 633 //Send data
ThomasSonderDesign 9:7c0f42f090e8 634 for (int i =0; i<wordsN; i++) {
ThomasSonderDesign 9:7c0f42f090e8 635 my_spi.write(data[i]);
ThomasSonderDesign 9:7c0f42f090e8 636 //pc.printf("%x ",data[i]);
ThomasSonderDesign 9:7c0f42f090e8 637 waitForLCD();
ThomasSonderDesign 9:7c0f42f090e8 638 }
ThomasSonderDesign 9:7c0f42f090e8 639 cs_epd = 1; // Bring chip select high to stop writing
ThomasSonderDesign 9:7c0f42f090e8 640 }
ThomasSonderDesign 9:7c0f42f090e8 641
ThomasSonderDesign 9:7c0f42f090e8 642 /*###### Send N Data ######*/
ThomasSonderDesign 9:7c0f42f090e8 643 //send some 16 bit words to the LCD
ThomasSonderDesign 9:7c0f42f090e8 644 //data[] is an short array containg wordsN number of 16 bit words
ThomasSonderDesign 9:7c0f42f090e8 645 void sendNData(SPI my_spi, short data[], int wordsN) //for shorts
ThomasSonderDesign 9:7c0f42f090e8 646 {
ThomasSonderDesign 9:7c0f42f090e8 647 waitForLCD();
ThomasSonderDesign 9:7c0f42f090e8 648 cs_epd = 0; // Bring chip select low
ThomasSonderDesign 9:7c0f42f090e8 649 //Send write data preamble 0x0000
ThomasSonderDesign 9:7c0f42f090e8 650 my_spi.write(0x0000);
ThomasSonderDesign 9:7c0f42f090e8 651 //Send data
ThomasSonderDesign 9:7c0f42f090e8 652 for (int i =0; i<wordsN; i++) {
ThomasSonderDesign 9:7c0f42f090e8 653 my_spi.write(data[i]);
ThomasSonderDesign 9:7c0f42f090e8 654 //pc.printf("%x ",data[i]);
ThomasSonderDesign 9:7c0f42f090e8 655 waitForLCD();
ThomasSonderDesign 9:7c0f42f090e8 656 }
ThomasSonderDesign 9:7c0f42f090e8 657 cs_epd = 1; // Bring chip select high to stop writing
ThomasSonderDesign 9:7c0f42f090e8 658 }
ThomasSonderDesign 9:7c0f42f090e8 659
ThomasSonderDesign 9:7c0f42f090e8 660 /////////////////////////////////////////////////Register comands
ThomasSonderDesign 9:7c0f42f090e8 661
ThomasSonderDesign 9:7c0f42f090e8 662
ThomasSonderDesign 9:7c0f42f090e8 663 //Read one register value
ThomasSonderDesign 9:7c0f42f090e8 664 // reg_Add: address of the register you want to read.
ThomasSonderDesign 9:7c0f42f090e8 665 //
ThomasSonderDesign 9:7c0f42f090e8 666 int* readReg(SPI my_spi, int reg_Add)
ThomasSonderDesign 9:7c0f42f090e8 667 {
ThomasSonderDesign 9:7c0f42f090e8 668 int myval[3]; //Read data buffer
ThomasSonderDesign 9:7c0f42f090e8 669
ThomasSonderDesign 9:7c0f42f090e8 670 cs_epd = 0; // Bring chip select low
ThomasSonderDesign 9:7c0f42f090e8 671 //Send write commandpreamble 0x6000
ThomasSonderDesign 9:7c0f42f090e8 672 my_spi.write(0x6000);
ThomasSonderDesign 9:7c0f42f090e8 673 //Send read reg command 0x0010
ThomasSonderDesign 9:7c0f42f090e8 674 my_spi.write(0x0010);
ThomasSonderDesign 9:7c0f42f090e8 675 cs_epd = 1; // Bring chip select high to stop writing
ThomasSonderDesign 9:7c0f42f090e8 676
ThomasSonderDesign 9:7c0f42f090e8 677 waitForLCD();
ThomasSonderDesign 9:7c0f42f090e8 678
ThomasSonderDesign 9:7c0f42f090e8 679 cs_epd = 0; // Bring chip select low
ThomasSonderDesign 9:7c0f42f090e8 680 //Send write data preamble 0x0000
ThomasSonderDesign 9:7c0f42f090e8 681 my_spi.write(0x0000);
ThomasSonderDesign 9:7c0f42f090e8 682 //Send register address 0x1100
ThomasSonderDesign 9:7c0f42f090e8 683 my_spi.write(reg_Add);
ThomasSonderDesign 9:7c0f42f090e8 684 cs_epd = 1; // Bring chip select high to stop writing
ThomasSonderDesign 9:7c0f42f090e8 685
ThomasSonderDesign 9:7c0f42f090e8 686 waitForLCD();
ThomasSonderDesign 9:7c0f42f090e8 687
ThomasSonderDesign 9:7c0f42f090e8 688 cs_epd=0;
ThomasSonderDesign 9:7c0f42f090e8 689 //Send read data preamble 0x0000 ?0x0010?
ThomasSonderDesign 9:7c0f42f090e8 690 my_spi.write(0x1000);//endian swap
ThomasSonderDesign 9:7c0f42f090e8 691
ThomasSonderDesign 9:7c0f42f090e8 692 myval[0]=my_spi.write(00);
ThomasSonderDesign 9:7c0f42f090e8 693 myval[1]=my_spi.write(00);
ThomasSonderDesign 9:7c0f42f090e8 694 myval[2]=my_spi.write(00);
ThomasSonderDesign 9:7c0f42f090e8 695
ThomasSonderDesign 9:7c0f42f090e8 696 cs_epd = 1; // Bring chip select high to stop writing
ThomasSonderDesign 9:7c0f42f090e8 697
ThomasSonderDesign 9:7c0f42f090e8 698
ThomasSonderDesign 9:7c0f42f090e8 699 pc.printf("\n\rRef:%x %x %x %x",reg_Add,myval[0],myval[1],myval[2]);
ThomasSonderDesign 9:7c0f42f090e8 700 //=====Print data=======
ThomasSonderDesign 9:7c0f42f090e8 701 return myval;
ThomasSonderDesign 9:7c0f42f090e8 702 }
ThomasSonderDesign 9:7c0f42f090e8 703
ThomasSonderDesign 9:7c0f42f090e8 704 /*###### Write Register ######*/
ThomasSonderDesign 9:7c0f42f090e8 705 //Writes to one register
ThomasSonderDesign 9:7c0f42f090e8 706 //wirtes reg_data to the registor at adress reg_Add
ThomasSonderDesign 9:7c0f42f090e8 707 void writeReg(SPI my_spi, int reg_Add, int reg_data)
ThomasSonderDesign 9:7c0f42f090e8 708 {
ThomasSonderDesign 9:7c0f42f090e8 709 cs_epd = 0; // Bring chip select low
ThomasSonderDesign 9:7c0f42f090e8 710 //Send write commandpreamble 0x6000
ThomasSonderDesign 9:7c0f42f090e8 711 my_spi.write(0x6000);
ThomasSonderDesign 9:7c0f42f090e8 712 //Send write reg command 0x0011
ThomasSonderDesign 9:7c0f42f090e8 713 my_spi.write(0x0011);
ThomasSonderDesign 9:7c0f42f090e8 714 cs_epd = 1; // Bring chip select high to stop writing
ThomasSonderDesign 9:7c0f42f090e8 715
ThomasSonderDesign 9:7c0f42f090e8 716 waitForLCD();
ThomasSonderDesign 9:7c0f42f090e8 717
ThomasSonderDesign 9:7c0f42f090e8 718 cs_epd = 0; // Bring chip select low
ThomasSonderDesign 9:7c0f42f090e8 719 //Send write data preamble 0x0000
ThomasSonderDesign 9:7c0f42f090e8 720 my_spi.write(0x0000);
ThomasSonderDesign 9:7c0f42f090e8 721 //Send register address
ThomasSonderDesign 9:7c0f42f090e8 722 my_spi.write(reg_Add);
ThomasSonderDesign 9:7c0f42f090e8 723 cs_epd = 1; // Bring chip select high to stop writing
ThomasSonderDesign 9:7c0f42f090e8 724
ThomasSonderDesign 9:7c0f42f090e8 725 waitForLCD();
ThomasSonderDesign 9:7c0f42f090e8 726
ThomasSonderDesign 9:7c0f42f090e8 727 cs_epd = 0; // Bring chip select low
ThomasSonderDesign 9:7c0f42f090e8 728 //Send write data preamble 0x0000
ThomasSonderDesign 9:7c0f42f090e8 729 my_spi.write(0x0000);
ThomasSonderDesign 9:7c0f42f090e8 730 //Send register data
ThomasSonderDesign 9:7c0f42f090e8 731 my_spi.write(reg_data);
ThomasSonderDesign 9:7c0f42f090e8 732 cs_epd = 1; // Bring chip select high to stop writing
ThomasSonderDesign 9:7c0f42f090e8 733 }
ThomasSonderDesign 9:7c0f42f090e8 734
ThomasSonderDesign 9:7c0f42f090e8 735 /*###### Read Status ######*/
ThomasSonderDesign 9:7c0f42f090e8 736 //Reads the staus register of the LCD
ThomasSonderDesign 9:7c0f42f090e8 737 //returns 20 16bit words stored in the myval array.
ThomasSonderDesign 9:7c0f42f090e8 738 void readStatus(SPI my_spi, int* myval)
ThomasSonderDesign 9:7c0f42f090e8 739 {
ThomasSonderDesign 9:7c0f42f090e8 740 //my_spi.format(16,0); // Setup the spi for 16 bit data, low steady state clock,
ThomasSonderDesign 9:7c0f42f090e8 741 //my_spi.frequency(1000000); // second edge capture, with a 5Hz clock rate
ThomasSonderDesign 9:7c0f42f090e8 742 //int myval[20]; //Read data buffer
ThomasSonderDesign 9:7c0f42f090e8 743
ThomasSonderDesign 9:7c0f42f090e8 744 cs_epd = 0; // Bring chip select low
ThomasSonderDesign 9:7c0f42f090e8 745 pc.printf("chec ");
ThomasSonderDesign 9:7c0f42f090e8 746 waitForLCD();
ThomasSonderDesign 9:7c0f42f090e8 747 pc.printf("check1 ");
ThomasSonderDesign 9:7c0f42f090e8 748 //Send write commandpreamble 0x6000
ThomasSonderDesign 9:7c0f42f090e8 749 my_spi.write(0x6000);
ThomasSonderDesign 9:7c0f42f090e8 750 pc.printf("check2 ");
ThomasSonderDesign 9:7c0f42f090e8 751 waitForLCD();
ThomasSonderDesign 9:7c0f42f090e8 752 //Send read status comand 0x0302 Section 2.1 in programing guide
ThomasSonderDesign 9:7c0f42f090e8 753 my_spi.write(0x0302);
ThomasSonderDesign 9:7c0f42f090e8 754 cs_epd = 1; // Bring chip select high to stop writing
ThomasSonderDesign 9:7c0f42f090e8 755
ThomasSonderDesign 9:7c0f42f090e8 756 waitForLCD();
ThomasSonderDesign 9:7c0f42f090e8 757
ThomasSonderDesign 9:7c0f42f090e8 758 cs_epd=0;
ThomasSonderDesign 9:7c0f42f090e8 759 //Send read data preamble 0x0000 ?0x0010?
ThomasSonderDesign 9:7c0f42f090e8 760 my_spi.write(0x1000);//endian swap
ThomasSonderDesign 9:7c0f42f090e8 761 waitForLCD();
ThomasSonderDesign 9:7c0f42f090e8 762 //Read the result into the data buffer
ThomasSonderDesign 9:7c0f42f090e8 763 for(int i = 0; i<20; i++) {
ThomasSonderDesign 9:7c0f42f090e8 764 waitForLCD();
ThomasSonderDesign 9:7c0f42f090e8 765 myval[i]=my_spi.write(00); //send Dummy Byte to rede out data
ThomasSonderDesign 9:7c0f42f090e8 766 }
ThomasSonderDesign 9:7c0f42f090e8 767 cs_epd = 1; // Bring chip select high to stop writing
ThomasSonderDesign 9:7c0f42f090e8 768
ThomasSonderDesign 9:7c0f42f090e8 769
ThomasSonderDesign 9:7c0f42f090e8 770 //=====Print data to the terminal=======
ThomasSonderDesign 9:7c0f42f090e8 771
ThomasSonderDesign 9:7c0f42f090e8 772 pc.printf("\n\rStatus: ");
ThomasSonderDesign 9:7c0f42f090e8 773 for(int i = 0; i< 20; i++) {
ThomasSonderDesign 9:7c0f42f090e8 774 pc.printf("\n\r %x", myval[i]);
ThomasSonderDesign 9:7c0f42f090e8 775 }
ThomasSonderDesign 9:7c0f42f090e8 776 int imHi = myval[3];
ThomasSonderDesign 9:7c0f42f090e8 777 imHi = imHi<<16;
ThomasSonderDesign 9:7c0f42f090e8 778 int imaddress = myval[4]|imHi;
ThomasSonderDesign 9:7c0f42f090e8 779 pc.printf("Panel(W,H) = (%d,%d)\r\nImage Buffer Address = %X\r\n",myval[1], myval[2],imaddress);
ThomasSonderDesign 9:7c0f42f090e8 780
ThomasSonderDesign 9:7c0f42f090e8 781 //pc.printf("Image Buffer Address = %X\r\n",imaddress);
ThomasSonderDesign 9:7c0f42f090e8 782
ThomasSonderDesign 9:7c0f42f090e8 783
ThomasSonderDesign 9:7c0f42f090e8 784 }
ThomasSonderDesign 9:7c0f42f090e8 785
ThomasSonderDesign 9:7c0f42f090e8 786 /*###### Set Image buffer adress ######*/
ThomasSonderDesign 9:7c0f42f090e8 787 //sets the bottom adress where new image buffer will be written to and the display will be read from
ThomasSonderDesign 9:7c0f42f090e8 788 //imBufAddress is a 16bit address
ThomasSonderDesign 9:7c0f42f090e8 789 void setImBufAddress(SPI my_spi, int imBufAddress)
ThomasSonderDesign 9:7c0f42f090e8 790 {
ThomasSonderDesign 9:7c0f42f090e8 791 int ImBufAdReg = 0x208; //Image buffer maddress register
ThomasSonderDesign 9:7c0f42f090e8 792 int addL = imBufAddress&0xffff;
ThomasSonderDesign 9:7c0f42f090e8 793 writeReg(my_spi, ImBufAdReg, addL); //Write the low side of the address
ThomasSonderDesign 9:7c0f42f090e8 794 int addH = (imBufAddress >> 16)&0xffff;
ThomasSonderDesign 9:7c0f42f090e8 795 writeReg(my_spi, ImBufAdReg+2, addH); //Write the high side of the address
ThomasSonderDesign 9:7c0f42f090e8 796 }
ThomasSonderDesign 9:7c0f42f090e8 797
ThomasSonderDesign 9:7c0f42f090e8 798 /*###### Burst write Memory ######*/
ThomasSonderDesign 9:7c0f42f090e8 799 //Fast write comand to send data to the LCD buffer
ThomasSonderDesign 9:7c0f42f090e8 800 //writeBuffer: short buffer contsaning data to write
ThomasSonderDesign 9:7c0f42f090e8 801 //mem_Add: address on the TCON to save the datat to
ThomasSonderDesign 9:7c0f42f090e8 802 //write_Size: size of the writeBuffer
ThomasSonderDesign 9:7c0f42f090e8 803 void burst_write_Memory(SPI my_spi, short *writeBuffer, int mem_Add, int write_Size)
ThomasSonderDesign 9:7c0f42f090e8 804 {
ThomasSonderDesign 9:7c0f42f090e8 805 sendComand(my_spi,0x0014); //Send bst write
ThomasSonderDesign 9:7c0f42f090e8 806
ThomasSonderDesign 9:7c0f42f090e8 807 //int params []= {mem_Add&0xFFFF,(mem_Add>>16)&0xFFFF,write_Size&0xFFFF,(write_Size>>16)&0xFFFF,}; //Split the parameters into 16bit words
ThomasSonderDesign 9:7c0f42f090e8 808 //sendNData(params, 4); //Send paramerters
ThomasSonderDesign 9:7c0f42f090e8 809 waitForLCD();
ThomasSonderDesign 9:7c0f42f090e8 810 cs_epd=0;
ThomasSonderDesign 9:7c0f42f090e8 811 my_spi.write(0x0000);
ThomasSonderDesign 9:7c0f42f090e8 812 waitForLCD();
ThomasSonderDesign 9:7c0f42f090e8 813 my_spi.write(mem_Add&0xFFFF);
ThomasSonderDesign 9:7c0f42f090e8 814 cs_epd=1;
ThomasSonderDesign 9:7c0f42f090e8 815 waitForLCD();
ThomasSonderDesign 9:7c0f42f090e8 816 cs_epd=0;
ThomasSonderDesign 9:7c0f42f090e8 817 my_spi.write(0x0000);
ThomasSonderDesign 9:7c0f42f090e8 818 waitForLCD();
ThomasSonderDesign 9:7c0f42f090e8 819 my_spi.write((mem_Add>>16)&0xFFFF);
ThomasSonderDesign 9:7c0f42f090e8 820 cs_epd=1;
ThomasSonderDesign 9:7c0f42f090e8 821 waitForLCD();
ThomasSonderDesign 9:7c0f42f090e8 822 cs_epd=0;
ThomasSonderDesign 9:7c0f42f090e8 823 my_spi.write(0x0000);
ThomasSonderDesign 9:7c0f42f090e8 824 waitForLCD();
ThomasSonderDesign 9:7c0f42f090e8 825 my_spi.write(write_Size&0xFFFF);
ThomasSonderDesign 9:7c0f42f090e8 826 cs_epd=1;
ThomasSonderDesign 9:7c0f42f090e8 827 waitForLCD();
ThomasSonderDesign 9:7c0f42f090e8 828 cs_epd=0;
ThomasSonderDesign 9:7c0f42f090e8 829 my_spi.write(0x0000);
ThomasSonderDesign 9:7c0f42f090e8 830 waitForLCD();
ThomasSonderDesign 9:7c0f42f090e8 831 my_spi.write((write_Size>>16)&0xFFFF);
ThomasSonderDesign 9:7c0f42f090e8 832 cs_epd=1;
ThomasSonderDesign 9:7c0f42f090e8 833
ThomasSonderDesign 9:7c0f42f090e8 834
ThomasSonderDesign 9:7c0f42f090e8 835
ThomasSonderDesign 9:7c0f42f090e8 836
ThomasSonderDesign 9:7c0f42f090e8 837 waitForLCD();
ThomasSonderDesign 9:7c0f42f090e8 838 cs_epd = 0; // Bring chip select low
ThomasSonderDesign 9:7c0f42f090e8 839
ThomasSonderDesign 9:7c0f42f090e8 840 //Send write data preamble 0x0000
ThomasSonderDesign 9:7c0f42f090e8 841 my_spi.write(0x0000);
ThomasSonderDesign 9:7c0f42f090e8 842 //Send data
ThomasSonderDesign 9:7c0f42f090e8 843 for(int i = 0; i< 100; i++) {
ThomasSonderDesign 9:7c0f42f090e8 844 for(int h = 0; h< write_Size; h++) {
ThomasSonderDesign 9:7c0f42f090e8 845 waitForLCD();
ThomasSonderDesign 9:7c0f42f090e8 846 my_spi.write(writeBuffer[h]);
ThomasSonderDesign 9:7c0f42f090e8 847 pc.printf(".");
ThomasSonderDesign 9:7c0f42f090e8 848 }
ThomasSonderDesign 9:7c0f42f090e8 849 }
ThomasSonderDesign 9:7c0f42f090e8 850 sendComand(my_spi, 0x0015); //Send burst access stop comand
ThomasSonderDesign 9:7c0f42f090e8 851 }
ThomasSonderDesign 9:7c0f42f090e8 852
ThomasSonderDesign 9:7c0f42f090e8 853 /*###### Burst Read Memory ######*/
ThomasSonderDesign 9:7c0f42f090e8 854 //Fast write comand to read data from the TCON
ThomasSonderDesign 9:7c0f42f090e8 855 //readBuffer: short buffer contsaning data that was read
ThomasSonderDesign 9:7c0f42f090e8 856 //mem_Add: address on the TCON to read the data from
ThomasSonderDesign 9:7c0f42f090e8 857 //read_Size: size of the readBuffer
ThomasSonderDesign 9:7c0f42f090e8 858 void burst_read_Memory(SPI my_spi, int *readBuffer, int mem_Add, int read_Size)
ThomasSonderDesign 9:7c0f42f090e8 859 {
ThomasSonderDesign 9:7c0f42f090e8 860 pc.printf("check1");
ThomasSonderDesign 9:7c0f42f090e8 861 //Send burst reag trigger comand 0x0012
ThomasSonderDesign 9:7c0f42f090e8 862 sendComand(my_spi, 0x0012); // Bring chip select high to stop writing
ThomasSonderDesign 9:7c0f42f090e8 863
ThomasSonderDesign 9:7c0f42f090e8 864 waitForLCD();
ThomasSonderDesign 9:7c0f42f090e8 865 pc.printf("Check4");
ThomasSonderDesign 9:7c0f42f090e8 866
ThomasSonderDesign 9:7c0f42f090e8 867 cs_epd = 0; // Bring chip select low
ThomasSonderDesign 9:7c0f42f090e8 868 //Send write data preamble 0x0000
ThomasSonderDesign 9:7c0f42f090e8 869 my_spi.write(0x0000);
ThomasSonderDesign 9:7c0f42f090e8 870 //Send memory address low side
ThomasSonderDesign 9:7c0f42f090e8 871 my_spi.write(mem_Add);
ThomasSonderDesign 9:7c0f42f090e8 872 //Send memory address high side
ThomasSonderDesign 9:7c0f42f090e8 873 my_spi.write(mem_Add>>16);
ThomasSonderDesign 9:7c0f42f090e8 874 cs_epd = 1;
ThomasSonderDesign 9:7c0f42f090e8 875
ThomasSonderDesign 9:7c0f42f090e8 876
ThomasSonderDesign 9:7c0f42f090e8 877 waitForLCD();
ThomasSonderDesign 9:7c0f42f090e8 878
ThomasSonderDesign 9:7c0f42f090e8 879 cs_epd = 0; // Bring chip select low
ThomasSonderDesign 9:7c0f42f090e8 880 //Send write data preamble 0x0000
ThomasSonderDesign 9:7c0f42f090e8 881 my_spi.write(0x0000);
ThomasSonderDesign 9:7c0f42f090e8 882 //Send memory size low side
ThomasSonderDesign 9:7c0f42f090e8 883 my_spi.write(read_Size);
ThomasSonderDesign 9:7c0f42f090e8 884 //Send memory address high side
ThomasSonderDesign 9:7c0f42f090e8 885 my_spi.write(read_Size>>16);
ThomasSonderDesign 9:7c0f42f090e8 886 cs_epd = 1;
ThomasSonderDesign 9:7c0f42f090e8 887
ThomasSonderDesign 9:7c0f42f090e8 888 waitForLCD();
ThomasSonderDesign 9:7c0f42f090e8 889
ThomasSonderDesign 9:7c0f42f090e8 890 cs_epd = 0; // Bring chip select low
ThomasSonderDesign 9:7c0f42f090e8 891 //Send write commandpreamble 0x6000
ThomasSonderDesign 9:7c0f42f090e8 892 my_spi.write(0x6000);
ThomasSonderDesign 9:7c0f42f090e8 893 waitForLCD();
ThomasSonderDesign 9:7c0f42f090e8 894 //Send burst read start comand 0x0013
ThomasSonderDesign 9:7c0f42f090e8 895 my_spi.write(0x0013);
ThomasSonderDesign 9:7c0f42f090e8 896 cs_epd = 1; // Bring chip select high to stop writing
ThomasSonderDesign 9:7c0f42f090e8 897
ThomasSonderDesign 9:7c0f42f090e8 898 waitForLCD();
ThomasSonderDesign 9:7c0f42f090e8 899
ThomasSonderDesign 9:7c0f42f090e8 900 cs_epd=0;
ThomasSonderDesign 9:7c0f42f090e8 901 //Send read data preamble 0x0000 ?0x0010?
ThomasSonderDesign 9:7c0f42f090e8 902 my_spi.write(0x1000);//endian swap
ThomasSonderDesign 9:7c0f42f090e8 903 waitForLCD();
ThomasSonderDesign 9:7c0f42f090e8 904 //Read the result into the data buffer
ThomasSonderDesign 9:7c0f42f090e8 905 for(int i = 0; i<read_Size; i++) {
ThomasSonderDesign 9:7c0f42f090e8 906 waitForLCD();
ThomasSonderDesign 9:7c0f42f090e8 907 readBuffer[i]=my_spi.write(00); //send Dummy Byte to rede out data
ThomasSonderDesign 9:7c0f42f090e8 908 }
ThomasSonderDesign 9:7c0f42f090e8 909 cs_epd = 1; // Bring chip select high to stop writing
ThomasSonderDesign 9:7c0f42f090e8 910
ThomasSonderDesign 9:7c0f42f090e8 911 sendComand(my_spi, 0x0015); //Send burst access stop comand
ThomasSonderDesign 9:7c0f42f090e8 912
ThomasSonderDesign 9:7c0f42f090e8 913 }
ThomasSonderDesign 9:7c0f42f090e8 914
ThomasSonderDesign 9:7c0f42f090e8 915 /////////////////////////////////////////////////////////image comands
ThomasSonderDesign 9:7c0f42f090e8 916 //
ThomasSonderDesign 9:7c0f42f090e8 917 /**
ThomasSonderDesign 9:7c0f42f090e8 918 * loads image data into the tcon
ThomasSonderDesign 9:7c0f42f090e8 919 * ediantype 0/1 xxxxxxx1
ThomasSonderDesign 9:7c0f42f090e8 920 * pixel format bits per pixel 00=2 11=8 xxxxxx01
ThomasSonderDesign 9:7c0f42f090e8 921 * rotate 0,90, 270 xxxxxx10
ThomasSonderDesign 9:7c0f42f090e8 922 * im_buffer start of the local image buffer. data to send to the display
ThomasSonderDesign 9:7c0f42f090e8 923 * imbuffer size, lenght of the buffer
ThomasSonderDesign 9:7c0f42f090e8 924 * imPosX, imPosY, the position on the display to place the image
ThomasSonderDesign 9:7c0f42f090e8 925 * height, width, the size in pixels of the image.
ThomasSonderDesign 9:7c0f42f090e8 926 */
ThomasSonderDesign 9:7c0f42f090e8 927 void load_full_image(SPI my_spi, int endianType, int pixFormat, int rotate, short im_buffer[], int imbufferSize, int imPosX, int imPosY, int width, int height)
ThomasSonderDesign 9:7c0f42f090e8 928 {
ThomasSonderDesign 9:7c0f42f090e8 929
ThomasSonderDesign 9:7c0f42f090e8 930 //Write image buffer address
ThomasSonderDesign 9:7c0f42f090e8 931 //setImBufAddress(0x3dbe90); //adress from readdata() dat[2] and data[3]
ThomasSonderDesign 9:7c0f42f090e8 932
ThomasSonderDesign 9:7c0f42f090e8 933 //pc.printf("\nwidth: %d\nHeight: %d", width, height);
ThomasSonderDesign 9:7c0f42f090e8 934
ThomasSonderDesign 9:7c0f42f090e8 935 //Write load image comand 0x0020
ThomasSonderDesign 9:7c0f42f090e8 936 sendComand(my_spi, 0x0020);
ThomasSonderDesign 9:7c0f42f090e8 937 int param[] = {(endianType<<8)|(pixFormat<<4)|rotate};
ThomasSonderDesign 9:7c0f42f090e8 938 sendNData(my_spi,param,1);
ThomasSonderDesign 9:7c0f42f090e8 939
ThomasSonderDesign 9:7c0f42f090e8 940
ThomasSonderDesign 9:7c0f42f090e8 941 //Write load image AREA comand 0x0021
ThomasSonderDesign 9:7c0f42f090e8 942 //sendComand(0x0021);
ThomasSonderDesign 9:7c0f42f090e8 943 //Send load parameters
ThomasSonderDesign 9:7c0f42f090e8 944 //int img_param[] = {(endianType<<8)|(pixFormat<<4)|rotate, imPosX, imPosY, width, height};
ThomasSonderDesign 9:7c0f42f090e8 945 //sendNData(img_param,5);
ThomasSonderDesign 9:7c0f42f090e8 946
ThomasSonderDesign 9:7c0f42f090e8 947 int count =0;
ThomasSonderDesign 9:7c0f42f090e8 948 int line=0;
ThomasSonderDesign 9:7c0f42f090e8 949
ThomasSonderDesign 9:7c0f42f090e8 950
ThomasSonderDesign 9:7c0f42f090e8 951 //send image data one word at a time
ThomasSonderDesign 9:7c0f42f090e8 952 waitForLCD();
ThomasSonderDesign 9:7c0f42f090e8 953 //cs_epd = 0; // Bring chip select low
ThomasSonderDesign 9:7c0f42f090e8 954
ThomasSonderDesign 9:7c0f42f090e8 955 //Send write data preamble 0x0000
ThomasSonderDesign 9:7c0f42f090e8 956 //my_spi.write(0x0000);
ThomasSonderDesign 9:7c0f42f090e8 957 //Send data
ThomasSonderDesign 9:7c0f42f090e8 958 sendNData(my_spi,im_buffer, imbufferSize);
ThomasSonderDesign 9:7c0f42f090e8 959
ThomasSonderDesign 9:7c0f42f090e8 960 cs_epd=1;
ThomasSonderDesign 9:7c0f42f090e8 961 //pc.printf("\ncheck1");
ThomasSonderDesign 9:7c0f42f090e8 962 //send load image end coand
ThomasSonderDesign 9:7c0f42f090e8 963 sendComand(my_spi, 0x0022);
ThomasSonderDesign 9:7c0f42f090e8 964 }
ThomasSonderDesign 9:7c0f42f090e8 965
ThomasSonderDesign 9:7c0f42f090e8 966 //Display bitmap on EPD
ThomasSonderDesign 9:7c0f42f090e8 967 /**
ThomasSonderDesign 9:7c0f42f090e8 968 * * xstart, ystart, the position on the display to place the image
ThomasSonderDesign 9:7c0f42f090e8 969 * height, width, the size in pixels of the image.
ThomasSonderDesign 9:7c0f42f090e8 970 * mode: bits per pixel 0 =2bbp, 1=3bpp, 2=4bpp, 3=5-8bpp
ThomasSonderDesign 9:7c0f42f090e8 971 */
ThomasSonderDesign 9:7c0f42f090e8 972 void displayIamge(SPI my_spi, int xstart, int ystart, int height, int width, int mode)
ThomasSonderDesign 9:7c0f42f090e8 973 {
ThomasSonderDesign 9:7c0f42f090e8 974 waitForLCD();
ThomasSonderDesign 9:7c0f42f090e8 975 //Write display image comand 0x0034
ThomasSonderDesign 9:7c0f42f090e8 976 sendComand(my_spi, 0x0034);
ThomasSonderDesign 9:7c0f42f090e8 977 //Send parameters
ThomasSonderDesign 9:7c0f42f090e8 978 //t.attach_us(&ledon,5000);
ThomasSonderDesign 9:7c0f42f090e8 979
ThomasSonderDesign 9:7c0f42f090e8 980 int params[] = {xstart, ystart, width, height, mode};
ThomasSonderDesign 9:7c0f42f090e8 981 trigger = 1;
ThomasSonderDesign 9:7c0f42f090e8 982 sendNData(my_spi, params,5);
ThomasSonderDesign 9:7c0f42f090e8 983 }
ThomasSonderDesign 9:7c0f42f090e8 984
ThomasSonderDesign 9:7c0f42f090e8 985 /*###### Write Line ######*/
ThomasSonderDesign 9:7c0f42f090e8 986 //Write a single line To the TCON buffer
ThomasSonderDesign 9:7c0f42f090e8 987 void writeLine(SPI my_spi, int lineNum, short lineBuffer[], int size)//Writes one line to the display memory.
ThomasSonderDesign 9:7c0f42f090e8 988 {
ThomasSonderDesign 9:7c0f42f090e8 989 int displayAddress = lineNum*0x960+0x3DBE90; //set the address that the line will be stored in
ThomasSonderDesign 9:7c0f42f090e8 990 //pc.printf("\n\rline: %X Line Nume: %d", displayAddress, lineNum);
ThomasSonderDesign 9:7c0f42f090e8 991 setImBufAddress(my_spi, displayAddress); //0x3DBE90 adress from readdata() dat[2] and data[3]
ThomasSonderDesign 9:7c0f42f090e8 992 load_full_image(my_spi, 0,0,0, lineBuffer, size, 0,0, size,1);
ThomasSonderDesign 9:7c0f42f090e8 993 //readReg(my_spi, 0x208); //read the image base adress
ThomasSonderDesign 9:7c0f42f090e8 994 }
ThomasSonderDesign 9:7c0f42f090e8 995
ThomasSonderDesign 0:17d169ac117c 996 /*###### EPD Write ######*/
ThomasSonderDesign 9:7c0f42f090e8 997 //Update the whole display with data from memory, starting at the
ThomasSonderDesign 9:7c0f42f090e8 998 //address: the adress in eeprom to read from
ThomasSonderDesign 0:17d169ac117c 999 int EPD_Write(SPI mem_spi, int address)
ThomasSonderDesign 0:17d169ac117c 1000 {
ThomasSonderDesign 9:7c0f42f090e8 1001 Timer t;
ThomasSonderDesign 5:07113abf18c0 1002 pc.printf("\nAddress: %i", address);
ThomasSonderDesign 9:7c0f42f090e8 1003 t.start(); //Start the timer
ThomasSonderDesign 0:17d169ac117c 1004 //Setup the SPIs
ThomasSonderDesign 0:17d169ac117c 1005 SPI epd_spi = setupEPD(); //Creat a new SPI object to comunicate with the EPD
ThomasSonderDesign 9:7c0f42f090e8 1006 int vaule[20];
ThomasSonderDesign 9:7c0f42f090e8 1007 readStatus(epd_spi, vaule);
ThomasSonderDesign 0:17d169ac117c 1008
ThomasSonderDesign 0:17d169ac117c 1009 //Create local variables
ThomasSonderDesign 9:7c0f42f090e8 1010 int lineLengh = 300; //the length of the display in 16 bit wordswords,
ThomasSonderDesign 9:7c0f42f090e8 1011 int imageLength = 1034;
ThomasSonderDesign 9:7c0f42f090e8 1012 short sixtyBytes[lineLengh*2]; //Create a line buffer
ThomasSonderDesign 9:7c0f42f090e8 1013
ThomasSonderDesign 0:17d169ac117c 1014 //int line = 0; //counter to keep track of the current line
ThomasSonderDesign 0:17d169ac117c 1015 //int frameLine = 0; //counter to keep track of the line in the current frame
ThomasSonderDesign 9:7c0f42f090e8 1016
ThomasSonderDesign 0:17d169ac117c 1017
ThomasSonderDesign 0:17d169ac117c 1018 //led=!led;
ThomasSonderDesign 9:7c0f42f090e8 1019
ThomasSonderDesign 0:17d169ac117c 1020 //Begin SPI comunication
ThomasSonderDesign 9:7c0f42f090e8 1021 // for old Tcon
ThomasSonderDesign 9:7c0f42f090e8 1022 /*cs_epd=1; //EPD chip deselected
ThomasSonderDesign 0:17d169ac117c 1023 TconEn =1; //Tcon ON set High
ThomasSonderDesign 0:17d169ac117c 1024 wait_ms(120); //delay 120ms
ThomasSonderDesign 0:17d169ac117c 1025 cs_epd=0; //Select the Tcon chip
ThomasSonderDesign 0:17d169ac117c 1026 wait_ms(1); //delay 1ms
ThomasSonderDesign 0:17d169ac117c 1027 //Write Header
ThomasSonderDesign 0:17d169ac117c 1028 epd_spi.write(0x06);
ThomasSonderDesign 0:17d169ac117c 1029 epd_spi.write(0xa0);
ThomasSonderDesign 9:7c0f42f090e8 1030 wait_ms(120); //delay 120ms*/
ThomasSonderDesign 0:17d169ac117c 1031
ThomasSonderDesign 9:7c0f42f090e8 1032 //loop throug all lines lines
ThomasSonderDesign 6:2f4a272ab299 1033 for(int j=0; j<imageLength; j++) {
ThomasSonderDesign 9:7c0f42f090e8 1034
ThomasSonderDesign 5:07113abf18c0 1035 //pc.printf("\n");
ThomasSonderDesign 9:7c0f42f090e8 1036 readData(mem_spi, sixtyBytes, address+(j*lineLengh), lineLengh,0); //Read the line, putt them in buffer return the next address to read from. Since mem reads 8bit data, we need double line length for 16bit display
ThomasSonderDesign 9:7c0f42f090e8 1037
ThomasSonderDesign 9:7c0f42f090e8 1038 //Halve the resolution by doubling bit length
ThomasSonderDesign 9:7c0f42f090e8 1039 /*for(int i=0; i<lineLengh; i++) {
ThomasSonderDesign 9:7c0f42f090e8 1040 int low = sixtyBytes[i];
ThomasSonderDesign 9:7c0f42f090e8 1041
ThomasSonderDesign 9:7c0f42f090e8 1042 low = bitDouble(low);
ThomasSonderDesign 9:7c0f42f090e8 1043
ThomasSonderDesign 9:7c0f42f090e8 1044 sixtyBytes[i]=(low);
ThomasSonderDesign 9:7c0f42f090e8 1045 }*/
ThomasSonderDesign 9:7c0f42f090e8 1046
ThomasSonderDesign 9:7c0f42f090e8 1047
ThomasSonderDesign 9:7c0f42f090e8 1048 //pc.printf("ÿup");
ThomasSonderDesign 9:7c0f42f090e8 1049 writeLine(epd_spi,j,sixtyBytes,lineLengh);
ThomasSonderDesign 9:7c0f42f090e8 1050 if(j%100==0) {
ThomasSonderDesign 7:b30c411a6d36 1051 keyCheck();
ThomasSonderDesign 9:7c0f42f090e8 1052 }
ThomasSonderDesign 9:7c0f42f090e8 1053
ThomasSonderDesign 0:17d169ac117c 1054 }
ThomasSonderDesign 9:7c0f42f090e8 1055 t.stop();
ThomasSonderDesign 9:7c0f42f090e8 1056 displayIamge(epd_spi,0,0,1034,2400,2);
ThomasSonderDesign 9:7c0f42f090e8 1057
ThomasSonderDesign 9:7c0f42f090e8 1058 for(int i = 0; i<1034; i++) {
ThomasSonderDesign 9:7c0f42f090e8 1059 readData(mem_spi, sixtyBytes, address+(i*lineLengh), lineLengh-250,0); //Read the line, putt them in buffer return the next address to read from. Since mem reads 8bit data, we need double line length for 16bit display
ThomasSonderDesign 9:7c0f42f090e8 1060
ThomasSonderDesign 9:7c0f42f090e8 1061 //Halve the resolution by doubling bit length
ThomasSonderDesign 9:7c0f42f090e8 1062 /*for(int i=0; i<lineLengh; i++) {
ThomasSonderDesign 9:7c0f42f090e8 1063 int low = sixtyBytes[i];
ThomasSonderDesign 9:7c0f42f090e8 1064 low = bitDouble(low);
ThomasSonderDesign 9:7c0f42f090e8 1065 sixtyBytes[i]=(low);
ThomasSonderDesign 9:7c0f42f090e8 1066 }*/
ThomasSonderDesign 9:7c0f42f090e8 1067 writeLine(epd_spi,i,sixtyBytes,lineLengh-250);
ThomasSonderDesign 9:7c0f42f090e8 1068 }
ThomasSonderDesign 9:7c0f42f090e8 1069 displayIamge(epd_spi,0,0,1034,400,2);
ThomasSonderDesign 9:7c0f42f090e8 1070
ThomasSonderDesign 0:17d169ac117c 1071
ThomasSonderDesign 7:b30c411a6d36 1072 printf("\ntime = %i ", t.read_ms());
ThomasSonderDesign 7:b30c411a6d36 1073 t.reset();
ThomasSonderDesign 9:7c0f42f090e8 1074 printf("\ndone = ");
ThomasSonderDesign 0:17d169ac117c 1075 return 1;
ThomasSonderDesign 0:17d169ac117c 1076 }
ThomasSonderDesign 0:17d169ac117c 1077
ThomasSonderDesign 2:8b66a3f7e202 1078 /*###### EPD Write ######*/
ThomasSonderDesign 2:8b66a3f7e202 1079 //Update the whole display with data from a reserved slot
ThomasSonderDesign 2:8b66a3f7e202 1080 int EPD_Swap(SPI mem_spi, int slot)
ThomasSonderDesign 2:8b66a3f7e202 1081 {
ThomasSonderDesign 2:8b66a3f7e202 1082 return EPD_Write(mem_spi, slots[slot]);
ThomasSonderDesign 2:8b66a3f7e202 1083 }
ThomasSonderDesign 0:17d169ac117c 1084 /*******************************************************
ThomasSonderDesign 0:17d169ac117c 1085 * Main Function
ThomasSonderDesign 0:17d169ac117c 1086 */
ThomasSonderDesign 0:17d169ac117c 1087 int main()
ThomasSonderDesign 0:17d169ac117c 1088 {
ThomasSonderDesign 1:1ec8bcd31b27 1089 Timer t;
ThomasSonderDesign 1:1ec8bcd31b27 1090
ThomasSonderDesign 9:7c0f42f090e8 1091
ThomasSonderDesign 9:7c0f42f090e8 1092 pc.baud(115200);
ThomasSonderDesign 0:17d169ac117c 1093 int USBDataBuffer[64];
ThomasSonderDesign 9:7c0f42f090e8 1094 SPI mem_spi = setupSPI(); //Creates an SPI object to comunicate with the external memory
ThomasSonderDesign 9:7c0f42f090e8 1095 populateNameList(mem_spi); //Reads the names of layouts stored in external memory into RAM
ThomasSonderDesign 4:e6e1642724d4 1096
ThomasSonderDesign 0:17d169ac117c 1097 while(1) {
ThomasSonderDesign 8:3577b060d7af 1098 //pc.printf("Loop");
ThomasSonderDesign 9:7c0f42f090e8 1099 trigger=0;
ThomasSonderDesign 9:7c0f42f090e8 1100
ThomasSonderDesign 9:7c0f42f090e8 1101 sendUSB(readyForComand); //Tell pc that read for data
ThomasSonderDesign 9:7c0f42f090e8 1102 keyCheck(); //Scan the key matrix for key press and send to the pc
ThomasSonderDesign 1:1ec8bcd31b27 1103
ThomasSonderDesign 0:17d169ac117c 1104 sendUSB(readyForComand);
ThomasSonderDesign 9:7c0f42f090e8 1105 if (readUSB(USBDataBuffer)>0) { //If a coamd received
ThomasSonderDesign 4:e6e1642724d4 1106 pc.printf("\nSwitch %i",USBDataBuffer[1]);
ThomasSonderDesign 3:d4e1892846fb 1107 char temp[] = {USBDataBuffer[3],USBDataBuffer[4],USBDataBuffer[5],USBDataBuffer[6],USBDataBuffer[7]};
ThomasSonderDesign 0:17d169ac117c 1108 switch(USBDataBuffer[1]) {
ThomasSonderDesign 0:17d169ac117c 1109 case 0x10: //If the recieved data is a write instruction
ThomasSonderDesign 9:7c0f42f090e8 1110 GlobalAddress = writeFrame(mem_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 1111 break;
ThomasSonderDesign 3:d4e1892846fb 1112 case 0x11:
ThomasSonderDesign 5:07113abf18c0 1113 pc.printf("\nPrep write");
ThomasSonderDesign 9:7c0f42f090e8 1114 prepImage(mem_spi, USBDataBuffer[2], temp);//Prepare a slot in memory for an image
ThomasSonderDesign 4:e6e1642724d4 1115 break;
ThomasSonderDesign 4:e6e1642724d4 1116 case 0x12:
ThomasSonderDesign 5:07113abf18c0 1117 pc.printf("\nImage write");
ThomasSonderDesign 9:7c0f42f090e8 1118 writeImage(mem_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 1119 break;
ThomasSonderDesign 0:17d169ac117c 1120 case 0x20: //If the recieved comand is a read instruction
ThomasSonderDesign 9:7c0f42f090e8 1121 //mem.readData(mem_spi, memoryBuffer, USBDataBuffer[2], USBDataBuffer[3]);//read(spi, destination[], address, length)
ThomasSonderDesign 1:1ec8bcd31b27 1122 //pc.printf(" \n---EPD UPDATE--- %i",USBDataBuffer[2]*65536+USBDataBuffer[3]*256+USBDataBuffer[4]);
ThomasSonderDesign 9:7c0f42f090e8 1123 EPD_Write(mem_spi, USBDataBuffer[2]*65536+USBDataBuffer[3]*256+USBDataBuffer[4]);
ThomasSonderDesign 0:17d169ac117c 1124 break;
ThomasSonderDesign 8:3577b060d7af 1125 case 0x21: //If the recieved comand is a swap instruction
ThomasSonderDesign 9:7c0f42f090e8 1126 EPD_Swap(mem_spi, USBDataBuffer[2]);
ThomasSonderDesign 9:7c0f42f090e8 1127 break;
ThomasSonderDesign 0:17d169ac117c 1128 case 0x30: //If the recieved comand is a request for the cutrrent name
ThomasSonderDesign 9:7c0f42f090e8 1129 populateNameList(mem_spi);
ThomasSonderDesign 8:3577b060d7af 1130 getNameList();
ThomasSonderDesign 0:17d169ac117c 1131 break;
ThomasSonderDesign 9:7c0f42f090e8 1132 case 0x35: //If the recieved comand is a request for all the names
ThomasSonderDesign 0:17d169ac117c 1133 getCurrentLayout();
ThomasSonderDesign 0:17d169ac117c 1134 break;
ThomasSonderDesign 0:17d169ac117c 1135 default:
ThomasSonderDesign 4:e6e1642724d4 1136 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 1137 }
ThomasSonderDesign 0:17d169ac117c 1138 }
ThomasSonderDesign 1:1ec8bcd31b27 1139
ThomasSonderDesign 3:d4e1892846fb 1140 //pc.printf("\n%d", t.read_us());
ThomasSonderDesign 1:1ec8bcd31b27 1141 t.reset();
ThomasSonderDesign 0:17d169ac117c 1142 }
ThomasSonderDesign 0:17d169ac117c 1143 }