Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: Memory25L16_fast USBDevice mbed
Fork of BlackBoard_Firmware_MVP by
BB_Basic.cpp@14:429841168368, 2018-07-18 (annotated)
- Committer:
- Xinda
- Date:
- Wed Jul 18 03:32:35 2018 +0000
- Revision:
- 14:429841168368
- Parent:
- 13:f7445faded6a
implement with xinda's fast read, not being tested with Eink display.
Who changed what in which revision?
User | Revision | Line number | New 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 | 13:f7445faded6a | 334 | sendKeyXinda(2,80,80,80,80,80,80); // Open Google Chrome or txt in local |
Xinda | 13:f7445faded6a | 335 | wait_ms(1000); |
Xinda | 12:fbb1dd0586e1 | 336 | sendKeyXinda(1,80,80,80,80,80,80); // Ctrl+V according to the Ctrl Center setting |
Xinda | 13:f7445faded6a | 337 | wait_ms(1000); |
Xinda | 13:f7445faded6a | 338 | sendKeyXinda(0,80,80,80,80,80,80); // Input Chinese: Francisco is Sonder's mascot |
Xinda | 13:f7445faded6a | 339 | wait_ms(1000); |
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; |
Xinda | 13:f7445faded6a | 429 | //int imageSize = 310200; //The number of bytes to write, 86272 for 9.8" |
Xinda | 13:f7445faded6a | 430 | int imageSize = 271600; // This image size is for testing the RAIL system |
ThomasSonderDesign | 9:7c0f42f090e8 | 431 | while (Address<startAddress+imageSize) { |
ThomasSonderDesign | 4:e6e1642724d4 | 432 | //waitForData(USBDataBuffer); //Waits untill data is recieved on usb, puts it in USBDataBuffer |
ThomasSonderDesign | 4:e6e1642724d4 | 433 | while(bufferIndex<bufferSize) { |
ThomasSonderDesign | 4:e6e1642724d4 | 434 | waitForData(USBDataBuffer); |
ThomasSonderDesign | 9:7c0f42f090e8 | 435 | bufferIndex=appendBuffer(USBDataBuffer, memoryBuffer, bufferIndex); //Appends USBDataBuffer onto memoryBuffer |
ThomasSonderDesign | 4:e6e1642724d4 | 436 | } |
ThomasSonderDesign | 9:7c0f42f090e8 | 437 | bufferIndex=0; |
ThomasSonderDesign | 4:e6e1642724d4 | 438 | //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 | 439 | //protected. this erases a block before writung to it if nessisary. |
ThomasSonderDesign | 9:7c0f42f090e8 | 440 | int currentSlot = Address/SLOTSIZE; |
ThomasSonderDesign | 4:e6e1642724d4 | 441 | if (erasedSlots[currentSlot]) { |
Xinda | 12:fbb1dd0586e1 | 442 | Address = mem.writeData(memoryBuffer, Address, bufferSize); |
ThomasSonderDesign | 4:e6e1642724d4 | 443 | } else { |
ThomasSonderDesign | 9:7c0f42f090e8 | 444 | pc.printf("\nCan not write to unerased slot. %X", Address); |
Xinda | 12:fbb1dd0586e1 | 445 | Address = mem.writeData(memoryBuffer, Address, bufferSize); |
ThomasSonderDesign | 9:7c0f42f090e8 | 446 | } |
ThomasSonderDesign | 9:7c0f42f090e8 | 447 | |
ThomasSonderDesign | 4:e6e1642724d4 | 448 | } |
ThomasSonderDesign | 4:e6e1642724d4 | 449 | pc.printf("\n pinnished writing"); |
ThomasSonderDesign | 4:e6e1642724d4 | 450 | t.stop(); |
ThomasSonderDesign | 4:e6e1642724d4 | 451 | pc.printf("\nwrite image %i", t.read_ms()); |
ThomasSonderDesign | 4:e6e1642724d4 | 452 | t.reset(); |
ThomasSonderDesign | 4:e6e1642724d4 | 453 | return Address; |
ThomasSonderDesign | 4:e6e1642724d4 | 454 | } |
ThomasSonderDesign | 4:e6e1642724d4 | 455 | |
ThomasSonderDesign | 0:17d169ac117c | 456 | /** |
ThomasSonderDesign | 5:07113abf18c0 | 457 | * Writes a single memorybuffer to memory |
ThomasSonderDesign | 0:17d169ac117c | 458 | * receives 64 packets over usb and stores them in memooryBuffer. When memory Buffer is full it is |
ThomasSonderDesign | 0:17d169ac117c | 459 | * written to memory at address. |
ThomasSonderDesign | 0:17d169ac117c | 460 | * returns the next availible adsress; |
ThomasSonderDesign | 0:17d169ac117c | 461 | */ |
ThomasSonderDesign | 0:17d169ac117c | 462 | int writeFrame(SPI my_spi,int Address) |
ThomasSonderDesign | 0:17d169ac117c | 463 | { |
ThomasSonderDesign | 0:17d169ac117c | 464 | int USBDataBuffer [64]; //Creat a buffer for recived data |
ThomasSonderDesign | 0:17d169ac117c | 465 | char memoryBuffer [bufferSize]; //Create a memory buffer, to be sent to flash |
ThomasSonderDesign | 0:17d169ac117c | 466 | int bufferIndex = 0; //points to the next available possition in memory |
ThomasSonderDesign | 3:d4e1892846fb | 467 | Timer t; |
ThomasSonderDesign | 3:d4e1892846fb | 468 | t.start(); //Start the timer |
ThomasSonderDesign | 0:17d169ac117c | 469 | |
ThomasSonderDesign | 0:17d169ac117c | 470 | waitForData(USBDataBuffer); //Waits untill data is recieved on usb, puts it in USBDataBuffer |
ThomasSonderDesign | 3:d4e1892846fb | 471 | t.stop(); |
ThomasSonderDesign | 4:e6e1642724d4 | 472 | |
ThomasSonderDesign | 0:17d169ac117c | 473 | while(bufferIndex<bufferSize) { |
ThomasSonderDesign | 0:17d169ac117c | 474 | bufferIndex=appendBuffer(USBDataBuffer, memoryBuffer, bufferIndex); //Appends USBDataBuffer onto memoryBuffer |
ThomasSonderDesign | 3:d4e1892846fb | 475 | t.start(); |
ThomasSonderDesign | 0:17d169ac117c | 476 | waitForData(USBDataBuffer); |
ThomasSonderDesign | 3:d4e1892846fb | 477 | t.stop(); |
ThomasSonderDesign | 0:17d169ac117c | 478 | } |
ThomasSonderDesign | 0:17d169ac117c | 479 | |
ThomasSonderDesign | 0:17d169ac117c | 480 | //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 | 481 | //protected. this erases a block before writung to it if nessisary. |
ThomasSonderDesign | 9:7c0f42f090e8 | 482 | int currentSlot = Address/SLOTSIZE; |
ThomasSonderDesign | 2:8b66a3f7e202 | 483 | pc.printf("\nCurrent slot: %i", currentSlot); |
ThomasSonderDesign | 2:8b66a3f7e202 | 484 | if (erasedSlots[currentSlot]) { |
ThomasSonderDesign | 1:1ec8bcd31b27 | 485 | pc.printf("\nNE"); |
Xinda | 12:fbb1dd0586e1 | 486 | Address = mem.writeData(memoryBuffer, Address, bufferSize); |
ThomasSonderDesign | 0:17d169ac117c | 487 | } else { |
ThomasSonderDesign | 2:8b66a3f7e202 | 488 | pc.printf("\nCan not write to unerased slot."); |
ThomasSonderDesign | 4:e6e1642724d4 | 489 | } |
ThomasSonderDesign | 3:d4e1892846fb | 490 | //t.stop(); |
ThomasSonderDesign | 3:d4e1892846fb | 491 | pc.printf("\nWait1 Wate2-4 %i", t.read_ms()); |
ThomasSonderDesign | 3:d4e1892846fb | 492 | t.reset(); |
ThomasSonderDesign | 0:17d169ac117c | 493 | return Address; |
ThomasSonderDesign | 0:17d169ac117c | 494 | } |
ThomasSonderDesign | 0:17d169ac117c | 495 | |
ThomasSonderDesign | 1:1ec8bcd31b27 | 496 | |
ThomasSonderDesign | 1:1ec8bcd31b27 | 497 | /** |
ThomasSonderDesign | 1:1ec8bcd31b27 | 498 | * Sends a report containing a the name of the layout stored at a given slot |
ThomasSonderDesign | 1:1ec8bcd31b27 | 499 | */ |
ThomasSonderDesign | 2:8b66a3f7e202 | 500 | void getLayoutName(int slot) |
ThomasSonderDesign | 1:1ec8bcd31b27 | 501 | { |
ThomasSonderDesign | 1:1ec8bcd31b27 | 502 | int temp [] = {0x31,slot,nameList[slot][0],nameList[slot][1],nameList[slot][2],nameList[slot][3],nameList[slot][4],0}; |
ThomasSonderDesign | 1:1ec8bcd31b27 | 503 | sendUSB(temp); |
ThomasSonderDesign | 8:3577b060d7af | 504 | 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 | 505 | } |
ThomasSonderDesign | 1:1ec8bcd31b27 | 506 | |
ThomasSonderDesign | 1:1ec8bcd31b27 | 507 | |
ThomasSonderDesign | 1:1ec8bcd31b27 | 508 | /** |
ThomasSonderDesign | 1:1ec8bcd31b27 | 509 | * Sends three reports containing the list of layout names stored in memory. |
ThomasSonderDesign | 1:1ec8bcd31b27 | 510 | */ |
ThomasSonderDesign | 1:1ec8bcd31b27 | 511 | void getNameList() |
ThomasSonderDesign | 1:1ec8bcd31b27 | 512 | { |
ThomasSonderDesign | 1:1ec8bcd31b27 | 513 | for(int slot =0; slot< 16; slot++) { |
ThomasSonderDesign | 2:8b66a3f7e202 | 514 | getLayoutName(slot); |
ThomasSonderDesign | 9:7c0f42f090e8 | 515 | } |
ThomasSonderDesign | 1:1ec8bcd31b27 | 516 | } |
ThomasSonderDesign | 0:17d169ac117c | 517 | |
ThomasSonderDesign | 0:17d169ac117c | 518 | /** |
ThomasSonderDesign | 0:17d169ac117c | 519 | * Sends the name of the Current layout |
ThomasSonderDesign | 0:17d169ac117c | 520 | */ |
ThomasSonderDesign | 1:1ec8bcd31b27 | 521 | void getCurrentLayout() |
ThomasSonderDesign | 0:17d169ac117c | 522 | { |
ThomasSonderDesign | 2:8b66a3f7e202 | 523 | getLayoutName(currentName); |
ThomasSonderDesign | 0:17d169ac117c | 524 | } |
ThomasSonderDesign | 0:17d169ac117c | 525 | |
ThomasSonderDesign | 0:17d169ac117c | 526 | /** |
ThomasSonderDesign | 0:17d169ac117c | 527 | * Writes the name of a given layout to the top memory address in its reserved block |
ThomasSonderDesign | 1:1ec8bcd31b27 | 528 | * name[] is a 5 bytes char array with the most significant byte at name[0] |
ThomasSonderDesign | 0:17d169ac117c | 529 | */ |
Xinda | 12:fbb1dd0586e1 | 530 | void nameBlock(char name[], int slot) |
ThomasSonderDesign | 0:17d169ac117c | 531 | { |
ThomasSonderDesign | 1:1ec8bcd31b27 | 532 | //char temp[]= {name}; |
ThomasSonderDesign | 10:1f96f0cce2a0 | 533 | pc.printf("write name"); |
Xinda | 12:fbb1dd0586e1 | 534 | mem.writeData(name, slots[slot]+0x1ff00, 5); |
ThomasSonderDesign | 10:1f96f0cce2a0 | 535 | pc.printf("\nName Done"); |
ThomasSonderDesign | 2:8b66a3f7e202 | 536 | } |
ThomasSonderDesign | 2:8b66a3f7e202 | 537 | |
ThomasSonderDesign | 2:8b66a3f7e202 | 538 | /** |
ThomasSonderDesign | 2:8b66a3f7e202 | 539 | * Reads memory to find the names of the layouts stored. puts the names into nameList |
ThomasSonderDesign | 2:8b66a3f7e202 | 540 | */ |
Xinda | 12:fbb1dd0586e1 | 541 | void populateNameList() |
ThomasSonderDesign | 2:8b66a3f7e202 | 542 | { |
ThomasSonderDesign | 4:e6e1642724d4 | 543 | for(int slot=0; slot<16; slot++) { |
ThomasSonderDesign | 9:7c0f42f090e8 | 544 | short name[5]; |
Xinda | 12:fbb1dd0586e1 | 545 | mem.readData(name, slots[slot]+0x1FF00, 5); //Read five bytes from the end of a slot into the name array |
ThomasSonderDesign | 4:e6e1642724d4 | 546 | for( int i = 0; i<5; i++) { |
ThomasSonderDesign | 4:e6e1642724d4 | 547 | nameList[slot][i]=name[i]; |
ThomasSonderDesign | 4:e6e1642724d4 | 548 | } |
ThomasSonderDesign | 4:e6e1642724d4 | 549 | } |
ThomasSonderDesign | 2:8b66a3f7e202 | 550 | } |
ThomasSonderDesign | 2:8b66a3f7e202 | 551 | |
ThomasSonderDesign | 2:8b66a3f7e202 | 552 | /** |
ThomasSonderDesign | 2:8b66a3f7e202 | 553 | * Prepares the memory for a new Layout, writes the layout's name, and erases the blocks |
ThomasSonderDesign | 2:8b66a3f7e202 | 554 | */ |
Xinda | 12:fbb1dd0586e1 | 555 | void prepImage(int slot, char name[]) |
ThomasSonderDesign | 2:8b66a3f7e202 | 556 | { |
ThomasSonderDesign | 10:1f96f0cce2a0 | 557 | pc.printf("\nSlot: %i, %i", slot, slots[slot]); |
Xinda | 12:fbb1dd0586e1 | 558 | mem.blockErase(slots[slot]); //erase the bottom block of the slot |
Xinda | 12:fbb1dd0586e1 | 559 | mem.blockErase(slots[slot]+0x10000); //erase the middle block of the slot |
Xinda | 12:fbb1dd0586e1 | 560 | mem.blockErase(slots[slot]+0x20000); //erase the top block of the slot |
Xinda | 12:fbb1dd0586e1 | 561 | mem.blockErase(slots[slot]+0x30000); //erase the top block of the slot |
Xinda | 12:fbb1dd0586e1 | 562 | mem.blockErase(slots[slot]+0x40000); //erase the top block of the slot |
ThomasSonderDesign | 8:3577b060d7af | 563 | pc.printf("\nWorking"); |
Xinda | 12:fbb1dd0586e1 | 564 | //nameBlock(name, slots[slot]/*+0x1FFF9*/); //Write the name of the layout to memory |
ThomasSonderDesign | 4:e6e1642724d4 | 565 | erasedSlots[slot]=true; //Mark the erased slot as true |
ThomasSonderDesign | 10:1f96f0cce2a0 | 566 | pc.printf("\nFin Working"); |
Xinda | 12:fbb1dd0586e1 | 567 | populateNameList(); |
ThomasSonderDesign | 10:1f96f0cce2a0 | 568 | |
ThomasSonderDesign | 0:17d169ac117c | 569 | } |
ThomasSonderDesign | 0:17d169ac117c | 570 | |
ThomasSonderDesign | 1:1ec8bcd31b27 | 571 | |
ThomasSonderDesign | 1:1ec8bcd31b27 | 572 | /****************************************************************************** |
ThomasSonderDesign | 1:1ec8bcd31b27 | 573 | * Display control funtions |
ThomasSonderDesign | 1:1ec8bcd31b27 | 574 | */ |
ThomasSonderDesign | 1:1ec8bcd31b27 | 575 | |
ThomasSonderDesign | 0:17d169ac117c | 576 | /*###### EPD Set Up ######*/ |
ThomasSonderDesign | 0:17d169ac117c | 577 | //Sets up the EPD spi pins |
ThomasSonderDesign | 0:17d169ac117c | 578 | SPI setupEPD() |
ThomasSonderDesign | 0:17d169ac117c | 579 | { |
ThomasSonderDesign | 0:17d169ac117c | 580 | pc.printf("\nEpd setup"); |
ThomasSonderDesign | 0:17d169ac117c | 581 | /////Setup the spi link with the EDP//// |
ThomasSonderDesign | 9:7c0f42f090e8 | 582 | SPI epd_spi(EPDSPI); //SPI setup: mosi, miso, sclk |
ThomasSonderDesign | 9:7c0f42f090e8 | 583 | // Setup the spi for 16 bit data, low steady state clock, |
ThomasSonderDesign | 0:17d169ac117c | 584 | // second edge capture, with a 5MHz clock rate |
ThomasSonderDesign | 9:7c0f42f090e8 | 585 | epd_spi.format(16,0); |
ThomasSonderDesign | 9:7c0f42f090e8 | 586 | epd_spi.frequency(10000000); |
ThomasSonderDesign | 0:17d169ac117c | 587 | return epd_spi; |
ThomasSonderDesign | 0:17d169ac117c | 588 | } |
ThomasSonderDesign | 0:17d169ac117c | 589 | |
ThomasSonderDesign | 9:7c0f42f090e8 | 590 | /****************************************************************************** |
ThomasSonderDesign | 9:7c0f42f090e8 | 591 | * ITE driver Functions |
ThomasSonderDesign | 9:7c0f42f090e8 | 592 | */ |
ThomasSonderDesign | 9:7c0f42f090e8 | 593 | |
ThomasSonderDesign | 9:7c0f42f090e8 | 594 | /*###### Wait for LCD ######*/ |
ThomasSonderDesign | 9:7c0f42f090e8 | 595 | //delay until the hardware ready pin on LCD is set |
ThomasSonderDesign | 9:7c0f42f090e8 | 596 | void waitForLCD() |
ThomasSonderDesign | 9:7c0f42f090e8 | 597 | { |
ThomasSonderDesign | 9:7c0f42f090e8 | 598 | myled=1; |
ThomasSonderDesign | 9:7c0f42f090e8 | 599 | |
ThomasSonderDesign | 9:7c0f42f090e8 | 600 | while(TCbusy==0) { |
ThomasSonderDesign | 9:7c0f42f090e8 | 601 | wait_us(1); |
ThomasSonderDesign | 9:7c0f42f090e8 | 602 | } |
ThomasSonderDesign | 9:7c0f42f090e8 | 603 | myled=0; |
ThomasSonderDesign | 9:7c0f42f090e8 | 604 | } |
ThomasSonderDesign | 9:7c0f42f090e8 | 605 | |
ThomasSonderDesign | 9:7c0f42f090e8 | 606 | /*###### Mirror the bits in a int ######*/ |
ThomasSonderDesign | 9:7c0f42f090e8 | 607 | int reverse(int in) |
ThomasSonderDesign | 9:7c0f42f090e8 | 608 | { |
ThomasSonderDesign | 9:7c0f42f090e8 | 609 | int out=0; |
ThomasSonderDesign | 9:7c0f42f090e8 | 610 | out|=in&128; |
ThomasSonderDesign | 9:7c0f42f090e8 | 611 | out|=in&64; |
ThomasSonderDesign | 9:7c0f42f090e8 | 612 | out|=in&32; |
ThomasSonderDesign | 9:7c0f42f090e8 | 613 | out|=in&16; |
ThomasSonderDesign | 9:7c0f42f090e8 | 614 | out|=in&8; |
ThomasSonderDesign | 9:7c0f42f090e8 | 615 | out|=in&4; |
ThomasSonderDesign | 9:7c0f42f090e8 | 616 | out|=in&2; |
ThomasSonderDesign | 9:7c0f42f090e8 | 617 | out|=in&1; |
ThomasSonderDesign | 9:7c0f42f090e8 | 618 | return out; |
ThomasSonderDesign | 9:7c0f42f090e8 | 619 | } |
ThomasSonderDesign | 9:7c0f42f090e8 | 620 | |
ThomasSonderDesign | 9:7c0f42f090e8 | 621 | /*###### Double the number of bits (up to 16)in an int eg: 1010 => 11001100 ######*/ |
ThomasSonderDesign | 9:7c0f42f090e8 | 622 | /*short bitDouble(int in) |
ThomasSonderDesign | 9:7c0f42f090e8 | 623 | { |
ThomasSonderDesign | 9:7c0f42f090e8 | 624 | short out=0; |
ThomasSonderDesign | 9:7c0f42f090e8 | 625 | int y = 0; |
ThomasSonderDesign | 9:7c0f42f090e8 | 626 | for(int i =0; i<8; i++) { |
ThomasSonderDesign | 9:7c0f42f090e8 | 627 | y = 1<<i; |
ThomasSonderDesign | 9:7c0f42f090e8 | 628 | if((in&y)>0) { |
ThomasSonderDesign | 9:7c0f42f090e8 | 629 | out=out|(3<<(2*i)); |
ThomasSonderDesign | 9:7c0f42f090e8 | 630 | } |
ThomasSonderDesign | 9:7c0f42f090e8 | 631 | } |
ThomasSonderDesign | 9:7c0f42f090e8 | 632 | return out; |
ThomasSonderDesign | 9:7c0f42f090e8 | 633 | }*/ |
ThomasSonderDesign | 9:7c0f42f090e8 | 634 | |
ThomasSonderDesign | 9:7c0f42f090e8 | 635 | short bitDouble(int in) |
ThomasSonderDesign | 9:7c0f42f090e8 | 636 | { |
ThomasSonderDesign | 9:7c0f42f090e8 | 637 | short out=0; |
ThomasSonderDesign | 9:7c0f42f090e8 | 638 | //1 |
ThomasSonderDesign | 9:7c0f42f090e8 | 639 | out=out|(3*(in&1)); |
ThomasSonderDesign | 9:7c0f42f090e8 | 640 | //2 |
ThomasSonderDesign | 9:7c0f42f090e8 | 641 | out=out|((in&2)*6); |
ThomasSonderDesign | 9:7c0f42f090e8 | 642 | //4 |
ThomasSonderDesign | 9:7c0f42f090e8 | 643 | out=out|((in&4)*12); |
ThomasSonderDesign | 9:7c0f42f090e8 | 644 | //8 |
ThomasSonderDesign | 9:7c0f42f090e8 | 645 | out=out|((in&8)*24); |
ThomasSonderDesign | 9:7c0f42f090e8 | 646 | //16 |
ThomasSonderDesign | 9:7c0f42f090e8 | 647 | out=out|((in&16)*48); |
ThomasSonderDesign | 9:7c0f42f090e8 | 648 | //32 |
ThomasSonderDesign | 9:7c0f42f090e8 | 649 | out=out|((in&32)*96); |
ThomasSonderDesign | 9:7c0f42f090e8 | 650 | //64 |
ThomasSonderDesign | 9:7c0f42f090e8 | 651 | out=out|((in&64)*192); |
ThomasSonderDesign | 9:7c0f42f090e8 | 652 | //128 |
ThomasSonderDesign | 9:7c0f42f090e8 | 653 | out=out|((in&128)*384); |
ThomasSonderDesign | 9:7c0f42f090e8 | 654 | |
ThomasSonderDesign | 9:7c0f42f090e8 | 655 | return out; |
ThomasSonderDesign | 9:7c0f42f090e8 | 656 | } |
ThomasSonderDesign | 9:7c0f42f090e8 | 657 | |
ThomasSonderDesign | 0:17d169ac117c | 658 | |
ThomasSonderDesign | 9:7c0f42f090e8 | 659 | /*###### Send Comands ######*/ |
ThomasSonderDesign | 9:7c0f42f090e8 | 660 | //send a comand to the LCD |
ThomasSonderDesign | 9:7c0f42f090e8 | 661 | void sendComand(SPI my_spi, int comand) |
ThomasSonderDesign | 9:7c0f42f090e8 | 662 | { |
ThomasSonderDesign | 9:7c0f42f090e8 | 663 | waitForLCD(); |
ThomasSonderDesign | 9:7c0f42f090e8 | 664 | cs_epd = 0; // Bring chip select low |
ThomasSonderDesign | 9:7c0f42f090e8 | 665 | //Send write commandpreamble 0x6000 |
ThomasSonderDesign | 9:7c0f42f090e8 | 666 | my_spi.write(0x6000); |
ThomasSonderDesign | 9:7c0f42f090e8 | 667 | //Send command |
ThomasSonderDesign | 9:7c0f42f090e8 | 668 | my_spi.write(comand); |
ThomasSonderDesign | 9:7c0f42f090e8 | 669 | cs_epd = 1; |
ThomasSonderDesign | 9:7c0f42f090e8 | 670 | } |
ThomasSonderDesign | 9:7c0f42f090e8 | 671 | |
ThomasSonderDesign | 9:7c0f42f090e8 | 672 | /*###### Send N Data ######*/ |
ThomasSonderDesign | 9:7c0f42f090e8 | 673 | //send some 16 bit words to the LCD |
ThomasSonderDesign | 9:7c0f42f090e8 | 674 | //data[] is an int array containg wordsN number of words |
ThomasSonderDesign | 9:7c0f42f090e8 | 675 | void sendNData(SPI my_spi,int data[], int wordsN) //for ints |
ThomasSonderDesign | 9:7c0f42f090e8 | 676 | { |
ThomasSonderDesign | 9:7c0f42f090e8 | 677 | waitForLCD(); |
ThomasSonderDesign | 9:7c0f42f090e8 | 678 | cs_epd = 0; // Bring chip select low |
ThomasSonderDesign | 9:7c0f42f090e8 | 679 | //Send write data preamble 0x0000 |
Xinda | 12:fbb1dd0586e1 | 680 | mywrite(0x0000); |
ThomasSonderDesign | 9:7c0f42f090e8 | 681 | //Send data |
ThomasSonderDesign | 9:7c0f42f090e8 | 682 | for (int i =0; i<wordsN; i++) { |
Xinda | 12:fbb1dd0586e1 | 683 | mywrite(data[i]); |
ThomasSonderDesign | 9:7c0f42f090e8 | 684 | //pc.printf("%x ",data[i]); |
ThomasSonderDesign | 9:7c0f42f090e8 | 685 | waitForLCD(); |
ThomasSonderDesign | 9:7c0f42f090e8 | 686 | } |
ThomasSonderDesign | 9:7c0f42f090e8 | 687 | cs_epd = 1; // Bring chip select high to stop writing |
ThomasSonderDesign | 9:7c0f42f090e8 | 688 | } |
ThomasSonderDesign | 9:7c0f42f090e8 | 689 | |
ThomasSonderDesign | 9:7c0f42f090e8 | 690 | /*###### Send N Data ######*/ |
ThomasSonderDesign | 9:7c0f42f090e8 | 691 | //send some 16 bit words to the LCD |
ThomasSonderDesign | 9:7c0f42f090e8 | 692 | //data[] is an short array containg wordsN number of 16 bit words |
Xinda | 12:fbb1dd0586e1 | 693 | void sendNData(short data[], int wordsN) //for shorts |
ThomasSonderDesign | 9:7c0f42f090e8 | 694 | { |
ThomasSonderDesign | 9:7c0f42f090e8 | 695 | waitForLCD(); |
ThomasSonderDesign | 9:7c0f42f090e8 | 696 | cs_epd = 0; // Bring chip select low |
ThomasSonderDesign | 9:7c0f42f090e8 | 697 | //Send write data preamble 0x0000 |
Xinda | 12:fbb1dd0586e1 | 698 | mywrite(0x0000); |
ThomasSonderDesign | 9:7c0f42f090e8 | 699 | //Send data |
ThomasSonderDesign | 9:7c0f42f090e8 | 700 | for (int i =0; i<wordsN; i++) { |
Xinda | 12:fbb1dd0586e1 | 701 | mywrite(data[i]); |
ThomasSonderDesign | 9:7c0f42f090e8 | 702 | //pc.printf("%x ",data[i]); |
ThomasSonderDesign | 9:7c0f42f090e8 | 703 | waitForLCD(); |
ThomasSonderDesign | 9:7c0f42f090e8 | 704 | } |
ThomasSonderDesign | 9:7c0f42f090e8 | 705 | cs_epd = 1; // Bring chip select high to stop writing |
ThomasSonderDesign | 9:7c0f42f090e8 | 706 | } |
ThomasSonderDesign | 9:7c0f42f090e8 | 707 | |
ThomasSonderDesign | 9:7c0f42f090e8 | 708 | /////////////////////////////////////////////////Register comands |
ThomasSonderDesign | 9:7c0f42f090e8 | 709 | |
ThomasSonderDesign | 9:7c0f42f090e8 | 710 | |
ThomasSonderDesign | 9:7c0f42f090e8 | 711 | //Read one register value |
ThomasSonderDesign | 9:7c0f42f090e8 | 712 | // reg_Add: address of the register you want to read. |
ThomasSonderDesign | 9:7c0f42f090e8 | 713 | // |
ThomasSonderDesign | 9:7c0f42f090e8 | 714 | int* readReg(SPI my_spi, int reg_Add) |
ThomasSonderDesign | 9:7c0f42f090e8 | 715 | { |
ThomasSonderDesign | 9:7c0f42f090e8 | 716 | int myval[3]; //Read data buffer |
ThomasSonderDesign | 9:7c0f42f090e8 | 717 | |
ThomasSonderDesign | 9:7c0f42f090e8 | 718 | cs_epd = 0; // Bring chip select low |
ThomasSonderDesign | 9:7c0f42f090e8 | 719 | //Send write commandpreamble 0x6000 |
ThomasSonderDesign | 9:7c0f42f090e8 | 720 | my_spi.write(0x6000); |
ThomasSonderDesign | 9:7c0f42f090e8 | 721 | //Send read reg command 0x0010 |
ThomasSonderDesign | 9:7c0f42f090e8 | 722 | my_spi.write(0x0010); |
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 address 0x1100 |
ThomasSonderDesign | 9:7c0f42f090e8 | 731 | my_spi.write(reg_Add); |
ThomasSonderDesign | 9:7c0f42f090e8 | 732 | cs_epd = 1; // Bring chip select high to stop writing |
ThomasSonderDesign | 9:7c0f42f090e8 | 733 | |
ThomasSonderDesign | 9:7c0f42f090e8 | 734 | waitForLCD(); |
ThomasSonderDesign | 9:7c0f42f090e8 | 735 | |
ThomasSonderDesign | 9:7c0f42f090e8 | 736 | cs_epd=0; |
ThomasSonderDesign | 9:7c0f42f090e8 | 737 | //Send read data preamble 0x0000 ?0x0010? |
ThomasSonderDesign | 9:7c0f42f090e8 | 738 | my_spi.write(0x1000);//endian swap |
ThomasSonderDesign | 9:7c0f42f090e8 | 739 | |
ThomasSonderDesign | 9:7c0f42f090e8 | 740 | myval[0]=my_spi.write(00); |
ThomasSonderDesign | 9:7c0f42f090e8 | 741 | myval[1]=my_spi.write(00); |
ThomasSonderDesign | 9:7c0f42f090e8 | 742 | myval[2]=my_spi.write(00); |
ThomasSonderDesign | 9:7c0f42f090e8 | 743 | |
ThomasSonderDesign | 9:7c0f42f090e8 | 744 | cs_epd = 1; // Bring chip select high to stop writing |
ThomasSonderDesign | 9:7c0f42f090e8 | 745 | |
ThomasSonderDesign | 9:7c0f42f090e8 | 746 | |
ThomasSonderDesign | 9:7c0f42f090e8 | 747 | pc.printf("\n\rRef:%x %x %x %x",reg_Add,myval[0],myval[1],myval[2]); |
ThomasSonderDesign | 9:7c0f42f090e8 | 748 | //=====Print data======= |
ThomasSonderDesign | 9:7c0f42f090e8 | 749 | return myval; |
ThomasSonderDesign | 9:7c0f42f090e8 | 750 | } |
ThomasSonderDesign | 9:7c0f42f090e8 | 751 | |
ThomasSonderDesign | 9:7c0f42f090e8 | 752 | /*###### Write Register ######*/ |
ThomasSonderDesign | 9:7c0f42f090e8 | 753 | //Writes to one register |
ThomasSonderDesign | 9:7c0f42f090e8 | 754 | //wirtes reg_data to the registor at adress reg_Add |
ThomasSonderDesign | 9:7c0f42f090e8 | 755 | void writeReg(SPI my_spi, int reg_Add, int reg_data) |
ThomasSonderDesign | 9:7c0f42f090e8 | 756 | { |
ThomasSonderDesign | 9:7c0f42f090e8 | 757 | cs_epd = 0; // Bring chip select low |
ThomasSonderDesign | 9:7c0f42f090e8 | 758 | //Send write commandpreamble 0x6000 |
ThomasSonderDesign | 9:7c0f42f090e8 | 759 | my_spi.write(0x6000); |
ThomasSonderDesign | 9:7c0f42f090e8 | 760 | //Send write reg command 0x0011 |
ThomasSonderDesign | 9:7c0f42f090e8 | 761 | my_spi.write(0x0011); |
ThomasSonderDesign | 9:7c0f42f090e8 | 762 | cs_epd = 1; // Bring chip select high to stop writing |
ThomasSonderDesign | 9:7c0f42f090e8 | 763 | |
ThomasSonderDesign | 9:7c0f42f090e8 | 764 | waitForLCD(); |
ThomasSonderDesign | 9:7c0f42f090e8 | 765 | |
ThomasSonderDesign | 9:7c0f42f090e8 | 766 | cs_epd = 0; // Bring chip select low |
ThomasSonderDesign | 9:7c0f42f090e8 | 767 | //Send write data preamble 0x0000 |
ThomasSonderDesign | 9:7c0f42f090e8 | 768 | my_spi.write(0x0000); |
ThomasSonderDesign | 9:7c0f42f090e8 | 769 | //Send register address |
ThomasSonderDesign | 9:7c0f42f090e8 | 770 | my_spi.write(reg_Add); |
ThomasSonderDesign | 9:7c0f42f090e8 | 771 | cs_epd = 1; // Bring chip select high to stop writing |
ThomasSonderDesign | 9:7c0f42f090e8 | 772 | |
ThomasSonderDesign | 9:7c0f42f090e8 | 773 | waitForLCD(); |
ThomasSonderDesign | 9:7c0f42f090e8 | 774 | |
ThomasSonderDesign | 9:7c0f42f090e8 | 775 | cs_epd = 0; // Bring chip select low |
ThomasSonderDesign | 9:7c0f42f090e8 | 776 | //Send write data preamble 0x0000 |
ThomasSonderDesign | 9:7c0f42f090e8 | 777 | my_spi.write(0x0000); |
ThomasSonderDesign | 9:7c0f42f090e8 | 778 | //Send register data |
ThomasSonderDesign | 9:7c0f42f090e8 | 779 | my_spi.write(reg_data); |
ThomasSonderDesign | 9:7c0f42f090e8 | 780 | cs_epd = 1; // Bring chip select high to stop writing |
ThomasSonderDesign | 9:7c0f42f090e8 | 781 | } |
ThomasSonderDesign | 9:7c0f42f090e8 | 782 | |
ThomasSonderDesign | 9:7c0f42f090e8 | 783 | /*###### Read Status ######*/ |
ThomasSonderDesign | 9:7c0f42f090e8 | 784 | //Reads the staus register of the LCD |
ThomasSonderDesign | 9:7c0f42f090e8 | 785 | //returns 20 16bit words stored in the myval array. |
ThomasSonderDesign | 9:7c0f42f090e8 | 786 | void readStatus(SPI my_spi, int* myval) |
ThomasSonderDesign | 9:7c0f42f090e8 | 787 | { |
ThomasSonderDesign | 9:7c0f42f090e8 | 788 | //my_spi.format(16,0); // Setup the spi for 16 bit data, low steady state clock, |
ThomasSonderDesign | 9:7c0f42f090e8 | 789 | //my_spi.frequency(1000000); // second edge capture, with a 5Hz clock rate |
ThomasSonderDesign | 9:7c0f42f090e8 | 790 | //int myval[20]; //Read data buffer |
ThomasSonderDesign | 9:7c0f42f090e8 | 791 | |
ThomasSonderDesign | 9:7c0f42f090e8 | 792 | cs_epd = 0; // Bring chip select low |
ThomasSonderDesign | 9:7c0f42f090e8 | 793 | pc.printf("chec "); |
ThomasSonderDesign | 9:7c0f42f090e8 | 794 | waitForLCD(); |
ThomasSonderDesign | 9:7c0f42f090e8 | 795 | pc.printf("check1 "); |
ThomasSonderDesign | 9:7c0f42f090e8 | 796 | //Send write commandpreamble 0x6000 |
ThomasSonderDesign | 9:7c0f42f090e8 | 797 | my_spi.write(0x6000); |
ThomasSonderDesign | 9:7c0f42f090e8 | 798 | pc.printf("check2 "); |
ThomasSonderDesign | 9:7c0f42f090e8 | 799 | waitForLCD(); |
ThomasSonderDesign | 9:7c0f42f090e8 | 800 | //Send read status comand 0x0302 Section 2.1 in programing guide |
ThomasSonderDesign | 9:7c0f42f090e8 | 801 | my_spi.write(0x0302); |
ThomasSonderDesign | 9:7c0f42f090e8 | 802 | cs_epd = 1; // Bring chip select high to stop writing |
ThomasSonderDesign | 9:7c0f42f090e8 | 803 | |
ThomasSonderDesign | 9:7c0f42f090e8 | 804 | waitForLCD(); |
ThomasSonderDesign | 9:7c0f42f090e8 | 805 | |
ThomasSonderDesign | 9:7c0f42f090e8 | 806 | cs_epd=0; |
ThomasSonderDesign | 9:7c0f42f090e8 | 807 | //Send read data preamble 0x0000 ?0x0010? |
ThomasSonderDesign | 9:7c0f42f090e8 | 808 | my_spi.write(0x1000);//endian swap |
ThomasSonderDesign | 9:7c0f42f090e8 | 809 | waitForLCD(); |
ThomasSonderDesign | 9:7c0f42f090e8 | 810 | //Read the result into the data buffer |
ThomasSonderDesign | 9:7c0f42f090e8 | 811 | for(int i = 0; i<20; i++) { |
ThomasSonderDesign | 9:7c0f42f090e8 | 812 | waitForLCD(); |
Xinda | 12:fbb1dd0586e1 | 813 | mywrite(00);//Send dummy byte to read out value ate Address |
Xinda | 12:fbb1dd0586e1 | 814 | while (LPC_SSP0->SR & RNE) |
Xinda | 12:fbb1dd0586e1 | 815 | myval[i]= LPC_SSP0->DR;//Read from data register |
ThomasSonderDesign | 9:7c0f42f090e8 | 816 | } |
ThomasSonderDesign | 9:7c0f42f090e8 | 817 | cs_epd = 1; // Bring chip select high to stop writing |
ThomasSonderDesign | 9:7c0f42f090e8 | 818 | |
ThomasSonderDesign | 9:7c0f42f090e8 | 819 | |
ThomasSonderDesign | 9:7c0f42f090e8 | 820 | //=====Print data to the terminal======= |
ThomasSonderDesign | 9:7c0f42f090e8 | 821 | |
ThomasSonderDesign | 9:7c0f42f090e8 | 822 | pc.printf("\n\rStatus: "); |
ThomasSonderDesign | 9:7c0f42f090e8 | 823 | for(int i = 0; i< 20; i++) { |
ThomasSonderDesign | 9:7c0f42f090e8 | 824 | pc.printf("\n\r %x", myval[i]); |
ThomasSonderDesign | 9:7c0f42f090e8 | 825 | } |
ThomasSonderDesign | 9:7c0f42f090e8 | 826 | int imHi = myval[3]; |
ThomasSonderDesign | 9:7c0f42f090e8 | 827 | imHi = imHi<<16; |
ThomasSonderDesign | 9:7c0f42f090e8 | 828 | int imaddress = myval[4]|imHi; |
ThomasSonderDesign | 9:7c0f42f090e8 | 829 | pc.printf("Panel(W,H) = (%d,%d)\r\nImage Buffer Address = %X\r\n",myval[1], myval[2],imaddress); |
ThomasSonderDesign | 9:7c0f42f090e8 | 830 | |
ThomasSonderDesign | 9:7c0f42f090e8 | 831 | //pc.printf("Image Buffer Address = %X\r\n",imaddress); |
ThomasSonderDesign | 9:7c0f42f090e8 | 832 | |
ThomasSonderDesign | 9:7c0f42f090e8 | 833 | |
ThomasSonderDesign | 9:7c0f42f090e8 | 834 | } |
ThomasSonderDesign | 9:7c0f42f090e8 | 835 | |
ThomasSonderDesign | 9:7c0f42f090e8 | 836 | /*###### Set Image buffer adress ######*/ |
ThomasSonderDesign | 9:7c0f42f090e8 | 837 | //sets the bottom adress where new image buffer will be written to and the display will be read from |
ThomasSonderDesign | 9:7c0f42f090e8 | 838 | //imBufAddress is a 16bit address |
ThomasSonderDesign | 9:7c0f42f090e8 | 839 | void setImBufAddress(SPI my_spi, int imBufAddress) |
ThomasSonderDesign | 9:7c0f42f090e8 | 840 | { |
ThomasSonderDesign | 9:7c0f42f090e8 | 841 | int ImBufAdReg = 0x208; //Image buffer maddress register |
ThomasSonderDesign | 9:7c0f42f090e8 | 842 | int addL = imBufAddress&0xffff; |
ThomasSonderDesign | 9:7c0f42f090e8 | 843 | writeReg(my_spi, ImBufAdReg, addL); //Write the low side of the address |
ThomasSonderDesign | 9:7c0f42f090e8 | 844 | int addH = (imBufAddress >> 16)&0xffff; |
ThomasSonderDesign | 9:7c0f42f090e8 | 845 | writeReg(my_spi, ImBufAdReg+2, addH); //Write the high side of the address |
ThomasSonderDesign | 9:7c0f42f090e8 | 846 | } |
ThomasSonderDesign | 9:7c0f42f090e8 | 847 | |
ThomasSonderDesign | 9:7c0f42f090e8 | 848 | /*###### Burst write Memory ######*/ |
ThomasSonderDesign | 9:7c0f42f090e8 | 849 | //Fast write comand to send data to the LCD buffer |
ThomasSonderDesign | 9:7c0f42f090e8 | 850 | //writeBuffer: short buffer contsaning data to write |
ThomasSonderDesign | 9:7c0f42f090e8 | 851 | //mem_Add: address on the TCON to save the datat to |
ThomasSonderDesign | 9:7c0f42f090e8 | 852 | //write_Size: size of the writeBuffer |
ThomasSonderDesign | 9:7c0f42f090e8 | 853 | void burst_write_Memory(SPI my_spi, short *writeBuffer, int mem_Add, int write_Size) |
ThomasSonderDesign | 9:7c0f42f090e8 | 854 | { |
Xinda | 12:fbb1dd0586e1 | 855 | sendComand(my_spi, 0x0014); //Send bst write |
ThomasSonderDesign | 9:7c0f42f090e8 | 856 | |
ThomasSonderDesign | 9:7c0f42f090e8 | 857 | //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 | 858 | //sendNData(params, 4); //Send paramerters |
ThomasSonderDesign | 9:7c0f42f090e8 | 859 | waitForLCD(); |
ThomasSonderDesign | 9:7c0f42f090e8 | 860 | cs_epd=0; |
Xinda | 12:fbb1dd0586e1 | 861 | mywrite(0x0000); |
ThomasSonderDesign | 9:7c0f42f090e8 | 862 | waitForLCD(); |
Xinda | 12:fbb1dd0586e1 | 863 | mywrite(mem_Add&0xFFFF); |
ThomasSonderDesign | 9:7c0f42f090e8 | 864 | cs_epd=1; |
ThomasSonderDesign | 9:7c0f42f090e8 | 865 | waitForLCD(); |
ThomasSonderDesign | 9:7c0f42f090e8 | 866 | cs_epd=0; |
Xinda | 12:fbb1dd0586e1 | 867 | mywrite(0x0000); |
ThomasSonderDesign | 9:7c0f42f090e8 | 868 | waitForLCD(); |
Xinda | 12:fbb1dd0586e1 | 869 | mywrite((mem_Add>>16)&0xFFFF); |
ThomasSonderDesign | 9:7c0f42f090e8 | 870 | cs_epd=1; |
ThomasSonderDesign | 9:7c0f42f090e8 | 871 | waitForLCD(); |
ThomasSonderDesign | 9:7c0f42f090e8 | 872 | cs_epd=0; |
Xinda | 12:fbb1dd0586e1 | 873 | mywrite(0x0000); |
ThomasSonderDesign | 9:7c0f42f090e8 | 874 | waitForLCD(); |
Xinda | 12:fbb1dd0586e1 | 875 | mywrite(write_Size&0xFFFF); |
ThomasSonderDesign | 9:7c0f42f090e8 | 876 | cs_epd=1; |
ThomasSonderDesign | 9:7c0f42f090e8 | 877 | waitForLCD(); |
ThomasSonderDesign | 9:7c0f42f090e8 | 878 | cs_epd=0; |
Xinda | 12:fbb1dd0586e1 | 879 | mywrite(0x0000); |
ThomasSonderDesign | 9:7c0f42f090e8 | 880 | waitForLCD(); |
Xinda | 12:fbb1dd0586e1 | 881 | mywrite((write_Size>>16)&0xFFFF); |
ThomasSonderDesign | 9:7c0f42f090e8 | 882 | cs_epd=1; |
ThomasSonderDesign | 9:7c0f42f090e8 | 883 | |
ThomasSonderDesign | 9:7c0f42f090e8 | 884 | |
ThomasSonderDesign | 9:7c0f42f090e8 | 885 | |
ThomasSonderDesign | 9:7c0f42f090e8 | 886 | |
ThomasSonderDesign | 9:7c0f42f090e8 | 887 | waitForLCD(); |
ThomasSonderDesign | 9:7c0f42f090e8 | 888 | cs_epd = 0; // Bring chip select low |
ThomasSonderDesign | 9:7c0f42f090e8 | 889 | |
ThomasSonderDesign | 9:7c0f42f090e8 | 890 | //Send write data preamble 0x0000 |
Xinda | 12:fbb1dd0586e1 | 891 | mywrite(0x0000); |
ThomasSonderDesign | 9:7c0f42f090e8 | 892 | //Send data |
ThomasSonderDesign | 9:7c0f42f090e8 | 893 | for(int i = 0; i< 100; i++) { |
ThomasSonderDesign | 9:7c0f42f090e8 | 894 | for(int h = 0; h< write_Size; h++) { |
ThomasSonderDesign | 9:7c0f42f090e8 | 895 | waitForLCD(); |
Xinda | 12:fbb1dd0586e1 | 896 | mywrite(writeBuffer[h]); |
ThomasSonderDesign | 9:7c0f42f090e8 | 897 | pc.printf("."); |
ThomasSonderDesign | 9:7c0f42f090e8 | 898 | } |
ThomasSonderDesign | 9:7c0f42f090e8 | 899 | } |
ThomasSonderDesign | 9:7c0f42f090e8 | 900 | sendComand(my_spi, 0x0015); //Send burst access stop comand |
ThomasSonderDesign | 9:7c0f42f090e8 | 901 | } |
ThomasSonderDesign | 9:7c0f42f090e8 | 902 | |
ThomasSonderDesign | 9:7c0f42f090e8 | 903 | /*###### Burst Read Memory ######*/ |
ThomasSonderDesign | 9:7c0f42f090e8 | 904 | //Fast write comand to read data from the TCON |
ThomasSonderDesign | 9:7c0f42f090e8 | 905 | //readBuffer: short buffer contsaning data that was read |
ThomasSonderDesign | 9:7c0f42f090e8 | 906 | //mem_Add: address on the TCON to read the data from |
ThomasSonderDesign | 9:7c0f42f090e8 | 907 | //read_Size: size of the readBuffer |
ThomasSonderDesign | 9:7c0f42f090e8 | 908 | void burst_read_Memory(SPI my_spi, int *readBuffer, int mem_Add, int read_Size) |
ThomasSonderDesign | 9:7c0f42f090e8 | 909 | { |
ThomasSonderDesign | 9:7c0f42f090e8 | 910 | pc.printf("check1"); |
ThomasSonderDesign | 9:7c0f42f090e8 | 911 | //Send burst reag trigger comand 0x0012 |
ThomasSonderDesign | 9:7c0f42f090e8 | 912 | sendComand(my_spi, 0x0012); // Bring chip select high to stop writing |
ThomasSonderDesign | 9:7c0f42f090e8 | 913 | |
ThomasSonderDesign | 9:7c0f42f090e8 | 914 | waitForLCD(); |
ThomasSonderDesign | 9:7c0f42f090e8 | 915 | pc.printf("Check4"); |
ThomasSonderDesign | 9:7c0f42f090e8 | 916 | |
ThomasSonderDesign | 9:7c0f42f090e8 | 917 | cs_epd = 0; // Bring chip select low |
ThomasSonderDesign | 9:7c0f42f090e8 | 918 | //Send write data preamble 0x0000 |
ThomasSonderDesign | 9:7c0f42f090e8 | 919 | my_spi.write(0x0000); |
ThomasSonderDesign | 9:7c0f42f090e8 | 920 | //Send memory address low side |
ThomasSonderDesign | 9:7c0f42f090e8 | 921 | my_spi.write(mem_Add); |
ThomasSonderDesign | 9:7c0f42f090e8 | 922 | //Send memory address high side |
ThomasSonderDesign | 9:7c0f42f090e8 | 923 | my_spi.write(mem_Add>>16); |
ThomasSonderDesign | 9:7c0f42f090e8 | 924 | cs_epd = 1; |
ThomasSonderDesign | 9:7c0f42f090e8 | 925 | |
ThomasSonderDesign | 9:7c0f42f090e8 | 926 | |
ThomasSonderDesign | 9:7c0f42f090e8 | 927 | waitForLCD(); |
ThomasSonderDesign | 9:7c0f42f090e8 | 928 | |
ThomasSonderDesign | 9:7c0f42f090e8 | 929 | cs_epd = 0; // Bring chip select low |
ThomasSonderDesign | 9:7c0f42f090e8 | 930 | //Send write data preamble 0x0000 |
ThomasSonderDesign | 9:7c0f42f090e8 | 931 | my_spi.write(0x0000); |
ThomasSonderDesign | 9:7c0f42f090e8 | 932 | //Send memory size low side |
ThomasSonderDesign | 9:7c0f42f090e8 | 933 | my_spi.write(read_Size); |
ThomasSonderDesign | 9:7c0f42f090e8 | 934 | //Send memory address high side |
ThomasSonderDesign | 9:7c0f42f090e8 | 935 | my_spi.write(read_Size>>16); |
ThomasSonderDesign | 9:7c0f42f090e8 | 936 | cs_epd = 1; |
ThomasSonderDesign | 9:7c0f42f090e8 | 937 | |
ThomasSonderDesign | 9:7c0f42f090e8 | 938 | waitForLCD(); |
ThomasSonderDesign | 9:7c0f42f090e8 | 939 | |
ThomasSonderDesign | 9:7c0f42f090e8 | 940 | cs_epd = 0; // Bring chip select low |
ThomasSonderDesign | 9:7c0f42f090e8 | 941 | //Send write commandpreamble 0x6000 |
ThomasSonderDesign | 9:7c0f42f090e8 | 942 | my_spi.write(0x6000); |
ThomasSonderDesign | 9:7c0f42f090e8 | 943 | waitForLCD(); |
ThomasSonderDesign | 9:7c0f42f090e8 | 944 | //Send burst read start comand 0x0013 |
ThomasSonderDesign | 9:7c0f42f090e8 | 945 | my_spi.write(0x0013); |
ThomasSonderDesign | 9:7c0f42f090e8 | 946 | cs_epd = 1; // Bring chip select high to stop writing |
ThomasSonderDesign | 9:7c0f42f090e8 | 947 | |
ThomasSonderDesign | 9:7c0f42f090e8 | 948 | waitForLCD(); |
ThomasSonderDesign | 9:7c0f42f090e8 | 949 | |
ThomasSonderDesign | 9:7c0f42f090e8 | 950 | cs_epd=0; |
ThomasSonderDesign | 9:7c0f42f090e8 | 951 | //Send read data preamble 0x0000 ?0x0010? |
ThomasSonderDesign | 9:7c0f42f090e8 | 952 | my_spi.write(0x1000);//endian swap |
ThomasSonderDesign | 9:7c0f42f090e8 | 953 | waitForLCD(); |
ThomasSonderDesign | 9:7c0f42f090e8 | 954 | //Read the result into the data buffer |
ThomasSonderDesign | 9:7c0f42f090e8 | 955 | for(int i = 0; i<read_Size; i++) { |
ThomasSonderDesign | 9:7c0f42f090e8 | 956 | waitForLCD(); |
ThomasSonderDesign | 9:7c0f42f090e8 | 957 | readBuffer[i]=my_spi.write(00); //send Dummy Byte to rede out data |
ThomasSonderDesign | 9:7c0f42f090e8 | 958 | } |
ThomasSonderDesign | 9:7c0f42f090e8 | 959 | cs_epd = 1; // Bring chip select high to stop writing |
ThomasSonderDesign | 9:7c0f42f090e8 | 960 | |
ThomasSonderDesign | 9:7c0f42f090e8 | 961 | sendComand(my_spi, 0x0015); //Send burst access stop comand |
ThomasSonderDesign | 9:7c0f42f090e8 | 962 | |
ThomasSonderDesign | 9:7c0f42f090e8 | 963 | } |
ThomasSonderDesign | 9:7c0f42f090e8 | 964 | |
ThomasSonderDesign | 9:7c0f42f090e8 | 965 | /////////////////////////////////////////////////////////image comands |
ThomasSonderDesign | 9:7c0f42f090e8 | 966 | // |
ThomasSonderDesign | 9:7c0f42f090e8 | 967 | /** |
ThomasSonderDesign | 9:7c0f42f090e8 | 968 | * loads image data into the tcon |
ThomasSonderDesign | 9:7c0f42f090e8 | 969 | * ediantype 0/1 xxxxxxx1 |
ThomasSonderDesign | 9:7c0f42f090e8 | 970 | * pixel format bits per pixel 00=2 11=8 xxxxxx01 |
ThomasSonderDesign | 9:7c0f42f090e8 | 971 | * rotate 0,90, 270 xxxxxx10 |
ThomasSonderDesign | 9:7c0f42f090e8 | 972 | * im_buffer start of the local image buffer. data to send to the display |
ThomasSonderDesign | 9:7c0f42f090e8 | 973 | * imbuffer size, lenght of the buffer |
ThomasSonderDesign | 9:7c0f42f090e8 | 974 | * imPosX, imPosY, the position on the display to place the image |
ThomasSonderDesign | 9:7c0f42f090e8 | 975 | * height, width, the size in pixels of the image. |
ThomasSonderDesign | 9:7c0f42f090e8 | 976 | */ |
ThomasSonderDesign | 9:7c0f42f090e8 | 977 | 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 | 978 | { |
ThomasSonderDesign | 9:7c0f42f090e8 | 979 | |
ThomasSonderDesign | 9:7c0f42f090e8 | 980 | //Write image buffer address |
ThomasSonderDesign | 9:7c0f42f090e8 | 981 | //setImBufAddress(0x3dbe90); //adress from readdata() dat[2] and data[3] |
ThomasSonderDesign | 9:7c0f42f090e8 | 982 | |
ThomasSonderDesign | 9:7c0f42f090e8 | 983 | //pc.printf("\nwidth: %d\nHeight: %d", width, height); |
ThomasSonderDesign | 9:7c0f42f090e8 | 984 | |
ThomasSonderDesign | 9:7c0f42f090e8 | 985 | //Write load image comand 0x0020 |
ThomasSonderDesign | 9:7c0f42f090e8 | 986 | sendComand(my_spi, 0x0020); |
ThomasSonderDesign | 9:7c0f42f090e8 | 987 | int param[] = {(endianType<<8)|(pixFormat<<4)|rotate}; |
Xinda | 12:fbb1dd0586e1 | 988 | sendNData(my_spi, param,1); |
ThomasSonderDesign | 9:7c0f42f090e8 | 989 | |
ThomasSonderDesign | 9:7c0f42f090e8 | 990 | |
ThomasSonderDesign | 9:7c0f42f090e8 | 991 | //Write load image AREA comand 0x0021 |
ThomasSonderDesign | 9:7c0f42f090e8 | 992 | //sendComand(0x0021); |
ThomasSonderDesign | 9:7c0f42f090e8 | 993 | //Send load parameters |
ThomasSonderDesign | 9:7c0f42f090e8 | 994 | //int img_param[] = {(endianType<<8)|(pixFormat<<4)|rotate, imPosX, imPosY, width, height}; |
ThomasSonderDesign | 9:7c0f42f090e8 | 995 | //sendNData(img_param,5); |
ThomasSonderDesign | 9:7c0f42f090e8 | 996 | |
ThomasSonderDesign | 9:7c0f42f090e8 | 997 | int count =0; |
ThomasSonderDesign | 9:7c0f42f090e8 | 998 | int line=0; |
ThomasSonderDesign | 9:7c0f42f090e8 | 999 | |
ThomasSonderDesign | 9:7c0f42f090e8 | 1000 | |
ThomasSonderDesign | 9:7c0f42f090e8 | 1001 | //send image data one word at a time |
ThomasSonderDesign | 9:7c0f42f090e8 | 1002 | waitForLCD(); |
ThomasSonderDesign | 9:7c0f42f090e8 | 1003 | //cs_epd = 0; // Bring chip select low |
ThomasSonderDesign | 9:7c0f42f090e8 | 1004 | |
ThomasSonderDesign | 9:7c0f42f090e8 | 1005 | //Send write data preamble 0x0000 |
Xinda | 12:fbb1dd0586e1 | 1006 | //mywrite(0x0000); |
ThomasSonderDesign | 9:7c0f42f090e8 | 1007 | //Send data |
Xinda | 12:fbb1dd0586e1 | 1008 | sendNData(im_buffer, imbufferSize); |
ThomasSonderDesign | 9:7c0f42f090e8 | 1009 | |
ThomasSonderDesign | 9:7c0f42f090e8 | 1010 | cs_epd=1; |
ThomasSonderDesign | 9:7c0f42f090e8 | 1011 | //pc.printf("\ncheck1"); |
ThomasSonderDesign | 9:7c0f42f090e8 | 1012 | //send load image end coand |
ThomasSonderDesign | 9:7c0f42f090e8 | 1013 | sendComand(my_spi, 0x0022); |
ThomasSonderDesign | 9:7c0f42f090e8 | 1014 | } |
ThomasSonderDesign | 9:7c0f42f090e8 | 1015 | |
ThomasSonderDesign | 9:7c0f42f090e8 | 1016 | //Display bitmap on EPD |
ThomasSonderDesign | 9:7c0f42f090e8 | 1017 | /** |
ThomasSonderDesign | 9:7c0f42f090e8 | 1018 | * * xstart, ystart, the position on the display to place the image |
ThomasSonderDesign | 9:7c0f42f090e8 | 1019 | * height, width, the size in pixels of the image. |
ThomasSonderDesign | 9:7c0f42f090e8 | 1020 | * mode: bits per pixel 0 =2bbp, 1=3bpp, 2=4bpp, 3=5-8bpp |
ThomasSonderDesign | 9:7c0f42f090e8 | 1021 | */ |
ThomasSonderDesign | 9:7c0f42f090e8 | 1022 | void displayIamge(SPI my_spi, int xstart, int ystart, int height, int width, int mode) |
ThomasSonderDesign | 9:7c0f42f090e8 | 1023 | { |
ThomasSonderDesign | 9:7c0f42f090e8 | 1024 | waitForLCD(); |
ThomasSonderDesign | 9:7c0f42f090e8 | 1025 | //Write display image comand 0x0034 |
ThomasSonderDesign | 9:7c0f42f090e8 | 1026 | sendComand(my_spi, 0x0034); |
ThomasSonderDesign | 9:7c0f42f090e8 | 1027 | //Send parameters |
ThomasSonderDesign | 9:7c0f42f090e8 | 1028 | //t.attach_us(&ledon,5000); |
ThomasSonderDesign | 9:7c0f42f090e8 | 1029 | |
ThomasSonderDesign | 9:7c0f42f090e8 | 1030 | int params[] = {xstart, ystart, width, height, mode}; |
ThomasSonderDesign | 9:7c0f42f090e8 | 1031 | trigger = 1; |
ThomasSonderDesign | 9:7c0f42f090e8 | 1032 | sendNData(my_spi, params,5); |
ThomasSonderDesign | 9:7c0f42f090e8 | 1033 | } |
ThomasSonderDesign | 9:7c0f42f090e8 | 1034 | |
ThomasSonderDesign | 9:7c0f42f090e8 | 1035 | /*###### Write Line ######*/ |
ThomasSonderDesign | 9:7c0f42f090e8 | 1036 | //Write a single line To the TCON buffer |
ThomasSonderDesign | 9:7c0f42f090e8 | 1037 | void writeLine(SPI my_spi, int lineNum, short lineBuffer[], int size)//Writes one line to the display memory. |
ThomasSonderDesign | 9:7c0f42f090e8 | 1038 | { |
ThomasSonderDesign | 9:7c0f42f090e8 | 1039 | int displayAddress = lineNum*0x960+0x3DBE90; //set the address that the line will be stored in |
ThomasSonderDesign | 9:7c0f42f090e8 | 1040 | //pc.printf("\n\rline: %X Line Nume: %d", displayAddress, lineNum); |
ThomasSonderDesign | 9:7c0f42f090e8 | 1041 | setImBufAddress(my_spi, displayAddress); //0x3DBE90 adress from readdata() dat[2] and data[3] |
ThomasSonderDesign | 9:7c0f42f090e8 | 1042 | load_full_image(my_spi, 0,0,0, lineBuffer, size, 0,0, size,1); |
ThomasSonderDesign | 9:7c0f42f090e8 | 1043 | //readReg(my_spi, 0x208); //read the image base adress |
ThomasSonderDesign | 9:7c0f42f090e8 | 1044 | } |
ThomasSonderDesign | 9:7c0f42f090e8 | 1045 | |
ThomasSonderDesign | 0:17d169ac117c | 1046 | /*###### EPD Write ######*/ |
ThomasSonderDesign | 9:7c0f42f090e8 | 1047 | //Update the whole display with data from memory, starting at the |
ThomasSonderDesign | 9:7c0f42f090e8 | 1048 | //address: the adress in eeprom to read from |
Xinda | 12:fbb1dd0586e1 | 1049 | int EPD_Write(int address) |
ThomasSonderDesign | 0:17d169ac117c | 1050 | { |
ThomasSonderDesign | 9:7c0f42f090e8 | 1051 | Timer t; |
ThomasSonderDesign | 5:07113abf18c0 | 1052 | pc.printf("\nAddress: %i", address); |
ThomasSonderDesign | 9:7c0f42f090e8 | 1053 | t.start(); //Start the timer |
ThomasSonderDesign | 0:17d169ac117c | 1054 | //Setup the SPIs |
ThomasSonderDesign | 0:17d169ac117c | 1055 | SPI epd_spi = setupEPD(); //Creat a new SPI object to comunicate with the EPD |
ThomasSonderDesign | 9:7c0f42f090e8 | 1056 | int vaule[20]; |
ThomasSonderDesign | 9:7c0f42f090e8 | 1057 | readStatus(epd_spi, vaule); |
ThomasSonderDesign | 0:17d169ac117c | 1058 | |
ThomasSonderDesign | 0:17d169ac117c | 1059 | //Create local variables |
ThomasSonderDesign | 9:7c0f42f090e8 | 1060 | int lineLengh = 300; //the length of the display in 16 bit wordswords, |
ThomasSonderDesign | 9:7c0f42f090e8 | 1061 | int imageLength = 1034; |
ThomasSonderDesign | 9:7c0f42f090e8 | 1062 | short sixtyBytes[lineLengh*2]; //Create a line buffer |
ThomasSonderDesign | 9:7c0f42f090e8 | 1063 | |
ThomasSonderDesign | 0:17d169ac117c | 1064 | //int line = 0; //counter to keep track of the current line |
ThomasSonderDesign | 0:17d169ac117c | 1065 | //int frameLine = 0; //counter to keep track of the line in the current frame |
ThomasSonderDesign | 9:7c0f42f090e8 | 1066 | |
ThomasSonderDesign | 0:17d169ac117c | 1067 | |
ThomasSonderDesign | 0:17d169ac117c | 1068 | //led=!led; |
ThomasSonderDesign | 9:7c0f42f090e8 | 1069 | |
ThomasSonderDesign | 0:17d169ac117c | 1070 | //Begin SPI comunication |
ThomasSonderDesign | 9:7c0f42f090e8 | 1071 | // for old Tcon |
ThomasSonderDesign | 9:7c0f42f090e8 | 1072 | /*cs_epd=1; //EPD chip deselected |
ThomasSonderDesign | 0:17d169ac117c | 1073 | TconEn =1; //Tcon ON set High |
ThomasSonderDesign | 0:17d169ac117c | 1074 | wait_ms(120); //delay 120ms |
ThomasSonderDesign | 0:17d169ac117c | 1075 | cs_epd=0; //Select the Tcon chip |
ThomasSonderDesign | 0:17d169ac117c | 1076 | wait_ms(1); //delay 1ms |
ThomasSonderDesign | 0:17d169ac117c | 1077 | //Write Header |
ThomasSonderDesign | 0:17d169ac117c | 1078 | epd_spi.write(0x06); |
ThomasSonderDesign | 0:17d169ac117c | 1079 | epd_spi.write(0xa0); |
ThomasSonderDesign | 9:7c0f42f090e8 | 1080 | wait_ms(120); //delay 120ms*/ |
ThomasSonderDesign | 0:17d169ac117c | 1081 | |
ThomasSonderDesign | 9:7c0f42f090e8 | 1082 | //loop throug all lines lines |
ThomasSonderDesign | 6:2f4a272ab299 | 1083 | for(int j=0; j<imageLength; j++) { |
ThomasSonderDesign | 9:7c0f42f090e8 | 1084 | |
ThomasSonderDesign | 5:07113abf18c0 | 1085 | //pc.printf("\n"); |
Xinda | 12:fbb1dd0586e1 | 1086 | 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 | 1087 | |
ThomasSonderDesign | 9:7c0f42f090e8 | 1088 | //Halve the resolution by doubling bit length |
ThomasSonderDesign | 9:7c0f42f090e8 | 1089 | /*for(int i=0; i<lineLengh; i++) { |
ThomasSonderDesign | 9:7c0f42f090e8 | 1090 | int low = sixtyBytes[i]; |
ThomasSonderDesign | 9:7c0f42f090e8 | 1091 | |
ThomasSonderDesign | 9:7c0f42f090e8 | 1092 | low = bitDouble(low); |
ThomasSonderDesign | 9:7c0f42f090e8 | 1093 | |
ThomasSonderDesign | 9:7c0f42f090e8 | 1094 | sixtyBytes[i]=(low); |
ThomasSonderDesign | 9:7c0f42f090e8 | 1095 | }*/ |
ThomasSonderDesign | 9:7c0f42f090e8 | 1096 | |
ThomasSonderDesign | 9:7c0f42f090e8 | 1097 | |
ThomasSonderDesign | 9:7c0f42f090e8 | 1098 | //pc.printf("ÿup"); |
ThomasSonderDesign | 9:7c0f42f090e8 | 1099 | writeLine(epd_spi,j,sixtyBytes,lineLengh); |
ThomasSonderDesign | 9:7c0f42f090e8 | 1100 | if(j%100==0) { |
ThomasSonderDesign | 7:b30c411a6d36 | 1101 | keyCheck(); |
ThomasSonderDesign | 9:7c0f42f090e8 | 1102 | } |
ThomasSonderDesign | 9:7c0f42f090e8 | 1103 | |
ThomasSonderDesign | 0:17d169ac117c | 1104 | } |
ThomasSonderDesign | 9:7c0f42f090e8 | 1105 | t.stop(); |
ThomasSonderDesign | 9:7c0f42f090e8 | 1106 | displayIamge(epd_spi,0,0,1034,2400,2); |
ThomasSonderDesign | 9:7c0f42f090e8 | 1107 | |
ThomasSonderDesign | 9:7c0f42f090e8 | 1108 | for(int i = 0; i<1034; i++) { |
Xinda | 12:fbb1dd0586e1 | 1109 | 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 | 1110 | |
ThomasSonderDesign | 9:7c0f42f090e8 | 1111 | //Halve the resolution by doubling bit length |
ThomasSonderDesign | 9:7c0f42f090e8 | 1112 | /*for(int i=0; i<lineLengh; i++) { |
ThomasSonderDesign | 9:7c0f42f090e8 | 1113 | int low = sixtyBytes[i]; |
ThomasSonderDesign | 9:7c0f42f090e8 | 1114 | low = bitDouble(low); |
ThomasSonderDesign | 9:7c0f42f090e8 | 1115 | sixtyBytes[i]=(low); |
ThomasSonderDesign | 9:7c0f42f090e8 | 1116 | }*/ |
ThomasSonderDesign | 9:7c0f42f090e8 | 1117 | writeLine(epd_spi,i,sixtyBytes,lineLengh-250); |
ThomasSonderDesign | 9:7c0f42f090e8 | 1118 | } |
ThomasSonderDesign | 9:7c0f42f090e8 | 1119 | displayIamge(epd_spi,0,0,1034,400,2); |
ThomasSonderDesign | 9:7c0f42f090e8 | 1120 | |
ThomasSonderDesign | 0:17d169ac117c | 1121 | |
ThomasSonderDesign | 7:b30c411a6d36 | 1122 | printf("\ntime = %i ", t.read_ms()); |
ThomasSonderDesign | 7:b30c411a6d36 | 1123 | t.reset(); |
ThomasSonderDesign | 9:7c0f42f090e8 | 1124 | printf("\ndone = "); |
ThomasSonderDesign | 0:17d169ac117c | 1125 | return 1; |
ThomasSonderDesign | 0:17d169ac117c | 1126 | } |
ThomasSonderDesign | 0:17d169ac117c | 1127 | |
ThomasSonderDesign | 2:8b66a3f7e202 | 1128 | /*###### EPD Write ######*/ |
ThomasSonderDesign | 2:8b66a3f7e202 | 1129 | //Update the whole display with data from a reserved slot |
Xinda | 12:fbb1dd0586e1 | 1130 | int EPD_Swap(int slot) |
ThomasSonderDesign | 2:8b66a3f7e202 | 1131 | { |
ThomasSonderDesign | 10:1f96f0cce2a0 | 1132 | pc.printf("\nslots: %i, %X", slot,slots[slot]); |
Xinda | 12:fbb1dd0586e1 | 1133 | return EPD_Write(slots[slot]); |
ThomasSonderDesign | 2:8b66a3f7e202 | 1134 | } |
ThomasSonderDesign | 0:17d169ac117c | 1135 | /******************************************************* |
ThomasSonderDesign | 0:17d169ac117c | 1136 | * Main Function |
ThomasSonderDesign | 0:17d169ac117c | 1137 | */ |
ThomasSonderDesign | 0:17d169ac117c | 1138 | int main() |
ThomasSonderDesign | 0:17d169ac117c | 1139 | { |
ThomasSonderDesign | 1:1ec8bcd31b27 | 1140 | Timer t; |
ThomasSonderDesign | 1:1ec8bcd31b27 | 1141 | |
ThomasSonderDesign | 9:7c0f42f090e8 | 1142 | |
ThomasSonderDesign | 9:7c0f42f090e8 | 1143 | pc.baud(115200); |
ThomasSonderDesign | 0:17d169ac117c | 1144 | int USBDataBuffer[64]; |
Xinda | 13:f7445faded6a | 1145 | short memoryBuffer[256]; //the XT test image size here is problem, the image size too large so the board is out fo memory |
ThomasSonderDesign | 9:7c0f42f090e8 | 1146 | SPI mem_spi = setupSPI(); //Creates an SPI object to comunicate with the external memory |
Xinda | 12:fbb1dd0586e1 | 1147 | populateNameList(); //Reads the names of layouts stored in external memory into RAM |
ThomasSonderDesign | 4:e6e1642724d4 | 1148 | |
ThomasSonderDesign | 0:17d169ac117c | 1149 | while(1) { |
ThomasSonderDesign | 8:3577b060d7af | 1150 | //pc.printf("Loop"); |
ThomasSonderDesign | 9:7c0f42f090e8 | 1151 | trigger=0; |
ThomasSonderDesign | 9:7c0f42f090e8 | 1152 | |
ThomasSonderDesign | 9:7c0f42f090e8 | 1153 | sendUSB(readyForComand); //Tell pc that read for data |
ThomasSonderDesign | 9:7c0f42f090e8 | 1154 | keyCheck(); //Scan the key matrix for key press and send to the pc |
ThomasSonderDesign | 10:1f96f0cce2a0 | 1155 | pc.printf("."); |
ThomasSonderDesign | 0:17d169ac117c | 1156 | sendUSB(readyForComand); |
ThomasSonderDesign | 9:7c0f42f090e8 | 1157 | if (readUSB(USBDataBuffer)>0) { //If a coamd received |
ThomasSonderDesign | 4:e6e1642724d4 | 1158 | pc.printf("\nSwitch %i",USBDataBuffer[1]); |
ThomasSonderDesign | 3:d4e1892846fb | 1159 | char temp[] = {USBDataBuffer[3],USBDataBuffer[4],USBDataBuffer[5],USBDataBuffer[6],USBDataBuffer[7]}; |
ThomasSonderDesign | 0:17d169ac117c | 1160 | switch(USBDataBuffer[1]) { |
ThomasSonderDesign | 0:17d169ac117c | 1161 | case 0x10: //If the recieved data is a write instruction |
ThomasSonderDesign | 9:7c0f42f090e8 | 1162 | 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 | 1163 | break; |
ThomasSonderDesign | 3:d4e1892846fb | 1164 | case 0x11: |
ThomasSonderDesign | 5:07113abf18c0 | 1165 | pc.printf("\nPrep write"); |
Xinda | 12:fbb1dd0586e1 | 1166 | prepImage(USBDataBuffer[2], temp);//Prepare a slot in memory for an image |
ThomasSonderDesign | 4:e6e1642724d4 | 1167 | break; |
ThomasSonderDesign | 4:e6e1642724d4 | 1168 | case 0x12: |
ThomasSonderDesign | 5:07113abf18c0 | 1169 | pc.printf("\nImage write"); |
ThomasSonderDesign | 9:7c0f42f090e8 | 1170 | 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 | 1171 | break; |
ThomasSonderDesign | 0:17d169ac117c | 1172 | case 0x20: //If the recieved comand is a read instruction |
ThomasSonderDesign | 9:7c0f42f090e8 | 1173 | //mem.readData(mem_spi, memoryBuffer, USBDataBuffer[2], USBDataBuffer[3]);//read(spi, destination[], address, length) |
ThomasSonderDesign | 1:1ec8bcd31b27 | 1174 | //pc.printf(" \n---EPD UPDATE--- %i",USBDataBuffer[2]*65536+USBDataBuffer[3]*256+USBDataBuffer[4]); |
Xinda | 12:fbb1dd0586e1 | 1175 | EPD_Write(USBDataBuffer[2]*65536+USBDataBuffer[3]*256+USBDataBuffer[4]); |
ThomasSonderDesign | 0:17d169ac117c | 1176 | break; |
ThomasSonderDesign | 8:3577b060d7af | 1177 | case 0x21: //If the recieved comand is a swap instruction |
Xinda | 12:fbb1dd0586e1 | 1178 | EPD_Swap(USBDataBuffer[2]); |
ThomasSonderDesign | 9:7c0f42f090e8 | 1179 | break; |
ThomasSonderDesign | 0:17d169ac117c | 1180 | case 0x30: //If the recieved comand is a request for the cutrrent name |
Xinda | 12:fbb1dd0586e1 | 1181 | populateNameList(); |
ThomasSonderDesign | 8:3577b060d7af | 1182 | getNameList(); |
ThomasSonderDesign | 0:17d169ac117c | 1183 | break; |
ThomasSonderDesign | 9:7c0f42f090e8 | 1184 | case 0x35: //If the recieved comand is a request for all the names |
ThomasSonderDesign | 0:17d169ac117c | 1185 | getCurrentLayout(); |
ThomasSonderDesign | 0:17d169ac117c | 1186 | break; |
Xinda | 12:fbb1dd0586e1 | 1187 | case 0xF0: |
Xinda | 12:fbb1dd0586e1 | 1188 | testKey(); // If received command is a request of keypress debugging. Xinda Debug version of keyCheck |
Xinda | 12:fbb1dd0586e1 | 1189 | break; |
Xinda | 13:f7445faded6a | 1190 | case 0xF1: |
Xinda | 13:f7445faded6a | 1191 | pc.printf("\nReading\n"); |
Xinda | 13:f7445faded6a | 1192 | readData(memoryBuffer, USBDataBuffer[2], USBDataBuffer[3],0);//Xinda Fast read test, read(spi, destination[], address, length) |
Xinda | 13:f7445faded6a | 1193 | for(int count = 0; count < 64; count++){ |
Xinda | 13:f7445faded6a | 1194 | int temp[] = {0x31,memoryBuffer[count+1],memoryBuffer[count+2],memoryBuffer[count+3],memoryBuffer[count+4],0,0,0}; |
Xinda | 13:f7445faded6a | 1195 | sendUSB(temp); |
Xinda | 13:f7445faded6a | 1196 | } |
Xinda | 13:f7445faded6a | 1197 | break; |
Xinda | 13:f7445faded6a | 1198 | /*case 0xF2: |
Xinda | 13:f7445faded6a | 1199 | for(int i = 0 ; i <200; i++) { |
Xinda | 13:f7445faded6a | 1200 | if(i%520==0){ |
Xinda | 13:f7445faded6a | 1201 | pc.printf("\n"); |
Xinda | 13:f7445faded6a | 1202 | } |
Xinda | 13:f7445faded6a | 1203 | pc.printf(" %i", memoryBuffer[i]);//Send dummy byte to read out value ate Address |
Xinda | 13:f7445faded6a | 1204 | } |
Xinda | 13:f7445faded6a | 1205 | break;*/ |
ThomasSonderDesign | 0:17d169ac117c | 1206 | default: |
ThomasSonderDesign | 4:e6e1642724d4 | 1207 | 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 | 1208 | } |
ThomasSonderDesign | 0:17d169ac117c | 1209 | } |
ThomasSonderDesign | 1:1ec8bcd31b27 | 1210 | |
ThomasSonderDesign | 3:d4e1892846fb | 1211 | //pc.printf("\n%d", t.read_us()); |
ThomasSonderDesign | 1:1ec8bcd31b27 | 1212 | t.reset(); |
ThomasSonderDesign | 0:17d169ac117c | 1213 | } |
ThomasSonderDesign | 0:17d169ac117c | 1214 | } |