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:
Xinda
Date:
Sat Jul 07 11:45:17 2018 +0000
Revision:
12:fbb1dd0586e1
Parent:
10:1f96f0cce2a0
Child:
13:f7445faded6a
July 7th

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