1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/Display_COG_Process.c Sun Apr 07 18:35:52 2013 +0000
1.3 @@ -0,0 +1,650 @@
1.4 +// Copyright 2013 Pervasive Displays, Inc.
1.5 +//
1.6 +// Licensed under the Apache License, Version 2.0 (the "License");
1.7 +// you may not use this file except in compliance with the License.
1.8 +// You may obtain a copy of the License at:
1.9 +//
1.10 +// http://www.apache.org/licenses/LICENSE-2.0
1.11 +//
1.12 +// Unless required by applicable law or agreed to in writing,
1.13 +// software distributed under the License is distributed on an
1.14 +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
1.15 +// express or implied. See the License for the specific language
1.16 +// governing permissions and limitations under the License.
1.17 +
1.18 +/******************************************************************************
1.19 + * Includes
1.20 + *****************************************************************************/
1.21 +//#include "driver_config.h"
1.22 +//#include "target_config.h"
1.23 +//#include "type.h"
1.24 +//#include "gpio.h"
1.25 +#include "Display_COG_Process.h"
1.26 +#include "Display_Hardware_Driver.h"
1.27 +#include "Display_Controller.h"
1.28 +
1.29 +
1.30 +/******************************************************************************
1.31 + * Defines and typedefs
1.32 + *****************************************************************************/
1.33 +#define _GaugeFrameTimeMark 0
1.34 +
1.35 +const COG_Parameters_t COG_Parameters[3]= {
1.36 + { //for 1.44"
1.37 + {0x00,0x00,0x00,0x00,0x00,0x0f,0xff,0x00},
1.38 + 0x03,
1.39 + (128/8),
1.40 + 96,
1.41 + (((128+96)*2)/8),
1.42 + (43),
1.43 + 480
1.44 + },
1.45 + { //for 2.0"
1.46 + {0x00,0x00,0x00,0x00,0x01,0xFF,0xE0,0x00},
1.47 + 0x03,
1.48 + (200/8),
1.49 + 96,
1.50 + (((200+96)*2)/8)+1,
1.51 + (53),
1.52 + 480
1.53 + },
1.54 + { //for 2.7"
1.55 + {0x00,0x00,0x00,0x7F,0xFF,0xFE,0x00,0x00},
1.56 + 0x00,
1.57 + (264/8),
1.58 + 176,
1.59 + (((264+176)*2)/8)+1,
1.60 + 105,
1.61 + 630
1.62 + },
1.63 +};
1.64 +
1.65 +const uint8_t ScanTable[4] = {0xC0, 0x30, 0x0C, 0x03};
1.66 +
1.67 +
1.68 +/******************************************************************************
1.69 + * Local variables
1.70 + *****************************************************************************/
1.71 +static uint32_t StageTime = 480;
1.72 +static COG_LineDataPacket_t COG_Line;
1.73 +static uint16_t EPD_Type_Index = 0;
1.74 +static uint16_t cnt = 0;
1.75 +static uint32_t Currentframe;
1.76 +static uint8_t *DataLineEven;
1.77 +static uint8_t *DataLineOdd;
1.78 +static uint8_t *DataLineScan;
1.79 +static uint8_t *DisplayOrgPtr;
1.80 +
1.81 +
1.82 +/******************************************************************************
1.83 + * Local functions
1.84 + *****************************************************************************/
1.85 +static void SetTemperature_Factor(uint8_t EPD_Type_Index)
1.86 +{
1.87 + int16_t Temperature;
1.88 +
1.89 + //Get current temperature
1.90 + Temperature = epd_get_temperature();
1.91 +
1.92 + if (Temperature < -10)
1.93 + {
1.94 + StageTime = COG_Parameters[EPD_Type_Index].StageTime * 17;
1.95 + }
1.96 + else if (Temperature < -5)
1.97 + {
1.98 + StageTime = COG_Parameters[EPD_Type_Index].StageTime * 12;
1.99 + }
1.100 + else if (Temperature < 5)
1.101 + {
1.102 + StageTime = COG_Parameters[EPD_Type_Index].StageTime * 8;
1.103 + }
1.104 + else if (Temperature < 10)
1.105 + {
1.106 + StageTime = COG_Parameters[EPD_Type_Index].StageTime * 4;
1.107 + }
1.108 + else if (Temperature < 15)
1.109 + {
1.110 + StageTime = COG_Parameters[EPD_Type_Index].StageTime * 3;
1.111 + }
1.112 + else if (Temperature < 20)
1.113 + {
1.114 + StageTime = COG_Parameters[EPD_Type_Index].StageTime * 2;
1.115 + }
1.116 + else if (Temperature < 40)
1.117 + {
1.118 + StageTime = COG_Parameters[EPD_Type_Index].StageTime * 1;
1.119 + }
1.120 + else
1.121 + {
1.122 + StageTime = (COG_Parameters[EPD_Type_Index].StageTime * 7)/10;
1.123 + }
1.124 +}
1.125 +
1.126 +static void Driver_TypeSelect(uint8_t typeIndex)
1.127 +{
1.128 + switch(typeIndex)
1.129 + {
1.130 + case EPDType_144:
1.131 + DataLineEven=&COG_Line.LineDatas.COG_144LineData.Even[0];
1.132 + DataLineOdd=&COG_Line.LineDatas.COG_144LineData.Odd[0];
1.133 + DataLineScan=&COG_Line.LineDatas.COG_144LineData.Scan[0];
1.134 + break;
1.135 + case EPDType_200:
1.136 + DataLineEven=&COG_Line.LineDatas.COG_20LineData.Even[0];
1.137 + DataLineOdd=&COG_Line.LineDatas.COG_20LineData.Odd[0];
1.138 + DataLineScan=&COG_Line.LineDatas.COG_20LineData.Scan[0];
1.139 + break;
1.140 + case EPDType_270:
1.141 + DataLineEven=&COG_Line.LineDatas.COG_27LineData.Even[0];
1.142 + DataLineOdd=&COG_Line.LineDatas.COG_27LineData.Odd[0];
1.143 + DataLineScan=&COG_Line.LineDatas.COG_27LineData.Scan[0];
1.144 + break;
1.145 + }
1.146 +}
1.147 +
1.148 +//#pragma GCC optimize ("-O3")
1.149 +static void Display_Stage_1 (uint8_t *PreviousPicture)
1.150 +{
1.151 + uint16_t i,j,k; // general counters
1.152 + uint8_t TempByte; // Temporary storage for image data check
1.153 + uint16_t StartClock;
1.154 +#ifdef DISPLAY_180_DEGREE
1.155 + uint8_t *DataLinePrt;
1.156 + DisplayOrgPtr = (PreviousPicture+(uint32_t)((COG_Parameters[EPD_Type_Index].VERTICAL-1)*COG_Parameters[EPD_Type_Index].HORIZONTAL));
1.157 +#else
1.158 + DisplayOrgPtr = PreviousPicture;
1.159 +#endif
1.160 + Currentframe = (uint32_t)COG_Parameters[EPD_Type_Index].FrameTime;
1.161 +//TestPinTrigger();
1.162 + cnt = 0;
1.163 + StartClock = epd_GetCurrentTimeTick();
1.164 + do
1.165 + {
1.166 +// TestPin2Trigger();
1.167 + PreviousPicture = DisplayOrgPtr;
1.168 +#ifdef DISPLAY_180_DEGREE
1.169 + DataLinePrt = PreviousPicture;
1.170 +#endif
1.171 + for (i = 0; i < COG_Parameters[EPD_Type_Index].VERTICAL; i++) // for every line
1.172 + {
1.173 + // SPI (0x04, ...)
1.174 + epd_SPI_Send_Byte(0x04, COG_Parameters[EPD_Type_Index].VoltageLevel);
1.175 + k = COG_Parameters[EPD_Type_Index].HORIZONTAL-1;
1.176 + for (j = 0; j < COG_Parameters[EPD_Type_Index].HORIZONTAL; j++) // check every bit in the line
1.177 + {
1.178 + TempByte = (*PreviousPicture++);
1.179 +#ifdef DISPLAY_180_DEGREE
1.180 + DataLineEven[j] = ((TempByte & 0x80) ? BLACK3 : WHITE3)
1.181 + | ((TempByte & 0x20) ? BLACK2 : WHITE2)
1.182 + | ((TempByte & 0x08) ? BLACK1 : WHITE1)
1.183 + | ((TempByte & 0x02) ? BLACK0 : WHITE0);
1.184 +
1.185 + DataLineOdd[k--] = ((TempByte & 0x01) ? BLACK3 : WHITE3)
1.186 + | ((TempByte & 0x04) ? BLACK2 : WHITE2)
1.187 + | ((TempByte & 0x10) ? BLACK1 : WHITE1)
1.188 + | ((TempByte & 0x40) ? BLACK0 : WHITE0);
1.189 + DataLinePrt--;
1.190 +#else
1.191 + DataLineOdd[j] = ((TempByte & 0x80) ? BLACK3 : WHITE3)
1.192 + | ((TempByte & 0x20) ? BLACK2 : WHITE2)
1.193 + | ((TempByte & 0x08) ? BLACK1 : WHITE1)
1.194 + | ((TempByte & 0x02) ? BLACK0 : WHITE0);
1.195 +
1.196 + DataLineEven[k--] = ((TempByte & 0x01) ? BLACK3 : WHITE3)
1.197 + | ((TempByte & 0x04) ? BLACK2 : WHITE2)
1.198 + | ((TempByte & 0x10) ? BLACK1 : WHITE1)
1.199 + | ((TempByte & 0x40) ? BLACK0 : WHITE0);
1.200 +#endif
1.201 + }
1.202 +#ifdef DISPLAY_180_DEGREE
1.203 + PreviousPicture = DataLinePrt;
1.204 +#endif
1.205 + DataLineScan[(i>>2)] = ScanTable[(i%4)];
1.206 + // SPI (0x0a, line data....)
1.207 + epd_SPI_Send(0x0a, (uint8_t *)&COG_Line.uint8, COG_Parameters[EPD_Type_Index].DataLineSize);
1.208 +
1.209 + // SPI (0x02, 0x25)
1.210 + epd_SPI_Send_Byte(0x02, 0x2F);
1.211 +
1.212 + DataLineScan[(i>>2)] = 0;
1.213 + }
1.214 +#if(!_GaugeFrameTimeMark)
1.215 + if(COG_Parameters[EPD_Type_Index].FrameTime>0)
1.216 + {
1.217 + while(Currentframe>(epd_GetCurrentTimeTick() - StartClock));
1.218 + }
1.219 +#endif
1.220 + //TestPin2Trigger();
1.221 + Currentframe=(uint32_t)(epd_GetCurrentTimeTick() - StartClock)+COG_Parameters[EPD_Type_Index].FrameTime ;
1.222 + cnt++;
1.223 + }while (StageTime>Currentframe);
1.224 +// TestPin2Trigger();
1.225 + while(StageTime>(epd_GetCurrentTimeTick() - StartClock));
1.226 +// TestPin2Trigger();
1.227 +// TestPinTrigger();
1.228 +}
1.229 +
1.230 +//#pragma GCC optimize ("-O3")
1.231 +static void Display_Stage_2 (uint8_t *PreviousPicture)
1.232 +{
1.233 + uint16_t i, j, k; // general counters
1.234 + uint8_t TempByte; // Temporary storage for image data check
1.235 + uint16_t StartClock;
1.236 +#ifdef DISPLAY_180_DEGREE
1.237 + uint8_t *DataLinePrt;
1.238 + DisplayOrgPtr = (PreviousPicture+(uint32_t)((COG_Parameters[EPD_Type_Index].VERTICAL-1)*COG_Parameters[EPD_Type_Index].HORIZONTAL));
1.239 +#else
1.240 + DisplayOrgPtr = PreviousPicture;
1.241 +#endif
1.242 +
1.243 +// TestPinTrigger();
1.244 + cnt = 0;
1.245 + Currentframe = (uint32_t)COG_Parameters[EPD_Type_Index].FrameTime;
1.246 + StartClock = epd_GetCurrentTimeTick();
1.247 + do
1.248 + {
1.249 +// TestPin2Trigger();
1.250 + PreviousPicture = DisplayOrgPtr;
1.251 +#ifdef DISPLAY_180_DEGREE
1.252 + DataLinePrt = PreviousPicture;
1.253 +#endif
1.254 + for (i = 0; i < COG_Parameters[EPD_Type_Index].VERTICAL; i++) // for every line
1.255 + {
1.256 + // SPI (0x04, ...)
1.257 + epd_SPI_Send_Byte(0x04, COG_Parameters[EPD_Type_Index].VoltageLevel);
1.258 + k = COG_Parameters[EPD_Type_Index].HORIZONTAL-1;
1.259 + for (j = 0; j < COG_Parameters[EPD_Type_Index].HORIZONTAL; j++) // make every bit in the line black
1.260 + {
1.261 + TempByte =(*PreviousPicture++);
1.262 +#ifdef DISPLAY_180_DEGREE
1.263 + DataLineEven[j] = ((TempByte & 0x80) ? WHITE3 : NOTHING)
1.264 + | ((TempByte & 0x20) ? WHITE2 : NOTHING)
1.265 + | ((TempByte & 0x08) ? WHITE1 : NOTHING)
1.266 + | ((TempByte & 0x02) ? WHITE0 : NOTHING);
1.267 + DataLineOdd[k--] = ((TempByte & 0x01) ? WHITE3 : NOTHING)
1.268 + | ((TempByte & 0x04) ? WHITE2 : NOTHING)
1.269 + | ((TempByte & 0x10) ? WHITE1 : NOTHING)
1.270 + | ((TempByte & 0x40) ? WHITE0 : NOTHING);
1.271 + DataLinePrt--;
1.272 +#else
1.273 + DataLineOdd[j] = ((TempByte & 0x80) ? WHITE3 : NOTHING)
1.274 + | ((TempByte & 0x20) ? WHITE2 : NOTHING)
1.275 + | ((TempByte & 0x08) ? WHITE1 : NOTHING)
1.276 + | ((TempByte & 0x02) ? WHITE0 : NOTHING);
1.277 + DataLineEven[k--] = ((TempByte & 0x01) ? WHITE3 : NOTHING)
1.278 + | ((TempByte & 0x04) ? WHITE2 : NOTHING)
1.279 + | ((TempByte & 0x10) ? WHITE1 : NOTHING)
1.280 + | ((TempByte & 0x40) ? WHITE0 : NOTHING);
1.281 +#endif
1.282 + }
1.283 +
1.284 +#ifdef DISPLAY_180_DEGREE
1.285 + PreviousPicture = DataLinePrt;
1.286 +#endif
1.287 + DataLineScan[(i>>2)] = ScanTable[(i%4)];
1.288 + // SPI (0x0a, line data....)
1.289 + epd_SPI_Send(0x0a, (uint8_t *)&COG_Line.uint8, COG_Parameters[EPD_Type_Index].DataLineSize);
1.290 +
1.291 + epd_SPI_Send_Byte(0x02, 0x25);
1.292 +
1.293 + DataLineScan[(i>>2)] = 0;
1.294 + }
1.295 +#if(!_GaugeFrameTimeMark)
1.296 + if(COG_Parameters[EPD_Type_Index].FrameTime>0)
1.297 + {
1.298 + while(Currentframe>(epd_GetCurrentTimeTick() - StartClock));
1.299 + }
1.300 +#endif
1.301 + //TestPin2Trigger();
1.302 + Currentframe=(uint32_t)(epd_GetCurrentTimeTick() - StartClock)+COG_Parameters[EPD_Type_Index].FrameTime ;
1.303 + cnt++;
1.304 + }while (StageTime>Currentframe);
1.305 +// TestPin2Trigger();
1.306 + while(StageTime>(epd_GetCurrentTimeTick() - StartClock));
1.307 +// TestPin2Trigger();
1.308 +// TestPinTrigger();
1.309 +}
1.310 +
1.311 +
1.312 +//#pragma GCC optimize ("-O3")
1.313 +static void Display_Stage_3 (uint8_t *Picture)
1.314 +{
1.315 + uint16_t i, j,k; // general counters
1.316 + uint8_t TempByte; // Temporary storage for image data check
1.317 + uint16_t StartClock;
1.318 +#ifdef DISPLAY_180_DEGREE
1.319 + uint8_t *DataLinePrt;
1.320 + DisplayOrgPtr = (Picture+(uint32_t)((COG_Parameters[EPD_Type_Index].VERTICAL-1)*COG_Parameters[EPD_Type_Index].HORIZONTAL));
1.321 +#else
1.322 + DisplayOrgPtr = Picture;
1.323 +#endif
1.324 + Currentframe = (uint32_t)COG_Parameters[EPD_Type_Index].FrameTime;
1.325 + cnt = 0;
1.326 +// TestPinTrigger();
1.327 + StartClock = epd_GetCurrentTimeTick();
1.328 + do
1.329 + {
1.330 +// TestPin2Trigger();
1.331 + Picture = DisplayOrgPtr;
1.332 +#ifdef DISPLAY_180_DEGREE
1.333 + DataLinePrt = Picture;
1.334 +#endif
1.335 + for (i = 0; i < COG_Parameters[EPD_Type_Index].VERTICAL; i++) // for every line
1.336 + {
1.337 + // SPI (0x04, 0x03)
1.338 + epd_SPI_Send_Byte(0x04, COG_Parameters[EPD_Type_Index].VoltageLevel);
1.339 + k = COG_Parameters[EPD_Type_Index].HORIZONTAL-1;
1.340 + for (j = 0; j < COG_Parameters[EPD_Type_Index].HORIZONTAL; j++) // check every bit in the line
1.341 + {
1.342 + TempByte = (*Picture++);
1.343 +#ifdef DISPLAY_180_DEGREE
1.344 + DataLineEven[j] = ((TempByte & 0x80) ? BLACK3 : NOTHING)
1.345 + | ((TempByte & 0x20) ? BLACK2 : NOTHING )
1.346 + | ((TempByte & 0x08) ? BLACK1 : NOTHING )
1.347 + | ((TempByte & 0x02) ? BLACK0 : NOTHING );
1.348 +
1.349 + DataLineOdd[k--] = ((TempByte & 0x01) ? BLACK3 : NOTHING)
1.350 + | ((TempByte & 0x04) ? BLACK2 : NOTHING )
1.351 + | ((TempByte & 0x10) ? BLACK1 : NOTHING )
1.352 + | ((TempByte & 0x40) ? BLACK0 : NOTHING );
1.353 + DataLinePrt--;
1.354 +#else
1.355 + DataLineOdd[j] = ((TempByte & 0x80) ? BLACK3 : NOTHING)
1.356 + | ((TempByte & 0x20) ? BLACK2 : NOTHING )
1.357 + | ((TempByte & 0x08) ? BLACK1 : NOTHING )
1.358 + | ((TempByte & 0x02) ? BLACK0 : NOTHING );
1.359 +
1.360 + DataLineEven[k--] = ((TempByte & 0x01) ? BLACK3 : NOTHING)
1.361 + | ((TempByte & 0x04) ? BLACK2 : NOTHING )
1.362 + | ((TempByte & 0x10) ? BLACK1 : NOTHING )
1.363 + | ((TempByte & 0x40) ? BLACK0 : NOTHING );
1.364 +#endif
1.365 + }
1.366 +#ifdef DISPLAY_180_DEGREE
1.367 + Picture = DataLinePrt;
1.368 +#endif
1.369 + DataLineScan[(i>>2)] = ScanTable[(i%4)];
1.370 + // SPI (0x0a, line data....)
1.371 + epd_SPI_Send(0x0a, (uint8_t *)&COG_Line.uint8, COG_Parameters[EPD_Type_Index].DataLineSize);
1.372 +
1.373 + epd_SPI_Send_Byte(0x02, 0x2F);
1.374 +
1.375 + DataLineScan[(i>>2)] = 0;
1.376 + }
1.377 +#if(!_GaugeFrameTimeMark)
1.378 + if(COG_Parameters[EPD_Type_Index].FrameTime>0)
1.379 + {
1.380 + while(Currentframe>(epd_GetCurrentTimeTick() - StartClock));
1.381 + }
1.382 +#endif
1.383 + //TestPin2Trigger();
1.384 + Currentframe=(uint32_t)(epd_GetCurrentTimeTick() - StartClock)+COG_Parameters[EPD_Type_Index].FrameTime ;
1.385 + cnt++;
1.386 + }while (StageTime>Currentframe);
1.387 +// TestPin2Trigger();
1.388 + while(StageTime>(epd_GetCurrentTimeTick() - StartClock));
1.389 +// TestPin2Trigger();
1.390 +// TestPinTrigger();
1.391 +}
1.392 +
1.393 +//#pragma GCC optimize ("-O3")
1.394 +static void Display_Stage_4 (uint8_t *Picture)
1.395 +{
1.396 + uint16_t i, j,k; // general counters
1.397 + uint8_t TempByte; // Temporary storage for image data check
1.398 + uint16_t StartClock;
1.399 +#ifdef DISPLAY_180_DEGREE
1.400 + uint8_t *DataLinePrt;
1.401 + DisplayOrgPtr = (Picture+(uint32_t)((COG_Parameters[EPD_Type_Index].VERTICAL-1)*COG_Parameters[EPD_Type_Index].HORIZONTAL));
1.402 +#else
1.403 + DisplayOrgPtr = Picture;
1.404 +#endif
1.405 + Currentframe = (uint32_t)COG_Parameters[EPD_Type_Index].FrameTime;
1.406 + cnt = 0;
1.407 +// TestPinTrigger();
1.408 +
1.409 + StartClock = epd_GetCurrentTimeTick();
1.410 + do
1.411 + {
1.412 +// TestPin2Trigger();
1.413 + Picture = DisplayOrgPtr;
1.414 +#ifdef DISPLAY_180_DEGREE
1.415 + DataLinePrt = Picture;
1.416 +#endif
1.417 + for (i = 0; i < COG_Parameters[EPD_Type_Index].VERTICAL; i++) // for every line
1.418 + {
1.419 + // SPI (0x04, ...)
1.420 + epd_SPI_Send_Byte(0x04, COG_Parameters[EPD_Type_Index].VoltageLevel);
1.421 + k = COG_Parameters[EPD_Type_Index].HORIZONTAL-1;
1.422 + for (j = 0; j < COG_Parameters[EPD_Type_Index].HORIZONTAL; j++) // check every bit in the line
1.423 + {
1.424 + TempByte =(*Picture++);
1.425 +#ifdef DISPLAY_180_DEGREE
1.426 + DataLineEven[j] = ((TempByte & 0x80) ? WHITE3 : BLACK3 )
1.427 + | ((TempByte & 0x20) ? WHITE2 : BLACK2 )
1.428 + | ((TempByte & 0x08) ? WHITE1 : BLACK1 )
1.429 + | ((TempByte & 0x02) ? WHITE0 : BLACK0 );
1.430 +
1.431 + DataLineOdd[k--] = ((TempByte & 0x01) ? WHITE3 : BLACK3 )
1.432 + | ((TempByte & 0x04) ? WHITE2 : BLACK2 )
1.433 + | ((TempByte & 0x10) ? WHITE1 : BLACK1 )
1.434 + | ((TempByte & 0x40) ? WHITE0 : BLACK0 );
1.435 + DataLinePrt--;
1.436 +#else
1.437 + DataLineOdd[j] = ((TempByte & 0x80) ? WHITE3 : BLACK3 )
1.438 + | ((TempByte & 0x20) ? WHITE2 : BLACK2 )
1.439 + | ((TempByte & 0x08) ? WHITE1 : BLACK1 )
1.440 + | ((TempByte & 0x02) ? WHITE0 : BLACK0 );
1.441 +
1.442 + DataLineEven[k--] = ((TempByte & 0x01) ? WHITE3 : BLACK3 )
1.443 + | ((TempByte & 0x04) ? WHITE2 : BLACK2 )
1.444 + | ((TempByte & 0x10) ? WHITE1 : BLACK1 )
1.445 + | ((TempByte & 0x40) ? WHITE0 : BLACK0 );
1.446 +#endif
1.447 + }
1.448 +#ifdef DISPLAY_180_DEGREE
1.449 + Picture = DataLinePrt;
1.450 +#endif
1.451 + DataLineScan[(i>>2)] = ScanTable[(i%4)];
1.452 + // SPI (0x0a, line data....)
1.453 + epd_SPI_Send(0x0a, (uint8_t *)&COG_Line.uint8, COG_Parameters[EPD_Type_Index].DataLineSize);
1.454 +
1.455 + epd_SPI_Send_Byte(0x02, 0x2F);
1.456 +
1.457 + DataLineScan[(i>>2)] = 0;
1.458 + }
1.459 +#if(!_GaugeFrameTimeMark)
1.460 + if(COG_Parameters[EPD_Type_Index].FrameTime>0)
1.461 + {
1.462 + while(Currentframe>(epd_GetCurrentTimeTick() - StartClock));
1.463 + }
1.464 +#endif
1.465 + //TestPin2Trigger();
1.466 + Currentframe=(uint32_t)(epd_GetCurrentTimeTick() - StartClock)+COG_Parameters[EPD_Type_Index].FrameTime ;
1.467 + cnt++;
1.468 + }while (StageTime>Currentframe);
1.469 +
1.470 +// TestPin2Trigger();
1.471 + while(StageTime>(epd_GetCurrentTimeTick() - StartClock));
1.472 +// TestPin2Trigger();
1.473 +// TestPinTrigger();
1.474 +}
1.475 +
1.476 +static void Display_Nothing (void)
1.477 +{
1.478 + uint16_t i; // general counters
1.479 +
1.480 + for (i = 0; i < COG_Parameters[EPD_Type_Index].HORIZONTAL; i++) // make every bit in the line white
1.481 + {
1.482 + DataLineEven[i] = 0x00;
1.483 + DataLineOdd[i] = 0x00;
1.484 + }
1.485 +
1.486 + for (i = 0; i < COG_Parameters[EPD_Type_Index].VERTICAL; i++) // for every line
1.487 + {
1.488 + epd_SPI_Send_Byte(0x04, 0x03);
1.489 + DataLineScan[(i>>2)] = ScanTable[(i%4)];
1.490 + // SPI (0x0a, line data....)
1.491 + epd_SPI_Send(0x0a, (uint8_t *)&COG_Line.uint8, COG_Parameters[EPD_Type_Index].DataLineSize);
1.492 +
1.493 + epd_SPI_Send_Byte(0x02, 0x2F);
1.494 + }
1.495 +}
1.496 +
1.497 +static void Dummy_line(void)
1.498 +{
1.499 + uint16_t i;
1.500 +
1.501 + for (i = 0; i < COG_Parameters[EPD_Type_Index].DataLineSize; i++)
1.502 + {
1.503 + COG_Line.uint8[i] = 0x00;
1.504 + }
1.505 +
1.506 + epd_SPI_Send_Byte(0x04, 0x03);
1.507 +
1.508 + // SPI (0x0a, line data....)
1.509 + epd_SPI_Send(0x0a, (uint8_t *)&COG_Line.uint8, COG_Parameters[EPD_Type_Index].DataLineSize);
1.510 +
1.511 + epd_SPI_Send_Byte(0x02, 0x2F);
1.512 +}
1.513 +
1.514 +
1.515 +/******************************************************************************
1.516 + * Public functions
1.517 + *****************************************************************************/
1.518 +void epd_HwInit(void)
1.519 +{
1.520 + epd_InitDisplayHardware();
1.521 +}
1.522 +
1.523 +void epd_PowerOn(void)
1.524 +{
1.525 + epd_discharge_low();
1.526 + epd_rst_low();
1.527 + epd_cs_low();
1.528 + epd_spi_init();
1.529 +
1.530 + epd_pwm_active(5);
1.531 +
1.532 + epd_panelon_on();
1.533 +
1.534 + epd_pwm_active(10);
1.535 +
1.536 + epd_cs_high();
1.537 +
1.538 + //epd_border_high();
1.539 +
1.540 + epd_rst_high();
1.541 +
1.542 + epd_pwm_active(5);
1.543 +
1.544 + epd_rst_low();
1.545 +
1.546 + epd_pwm_active(5);
1.547 +
1.548 + epd_rst_high();
1.549 +
1.550 + epd_pwm_active(5);
1.551 +}
1.552 +
1.553 +void epd_InitializeDriver(uint8_t EPDIndex)
1.554 +{
1.555 + uint8_t SendBuffer[2];
1.556 + uint16_t k;
1.557 +
1.558 + EPD_Type_Index = EPDIndex;
1.559 +
1.560 + //Data Line Clear
1.561 + for (k = 0; k <= __LineDataSize; k ++)
1.562 + {
1.563 + COG_Line.uint8[k] = 0x00;
1.564 + }
1.565 + Driver_TypeSelect(EPDIndex);
1.566 + k = 0;
1.567 +
1.568 + SetTemperature_Factor(EPDIndex);
1.569 +
1.570 + /*while (DRIVERBUSY_Get())
1.571 + {
1.572 + delayT32B0Us(500);
1.573 + if((k++)>=1000) return;//wait 500 ms
1.574 + }
1.575 + */
1.576 +
1.577 + // SPI (0x01, 0x0000, 0x0000, 0x01ff, 0xe000)
1.578 + epd_SPI_Send(0x01, (uint8_t *)&COG_Parameters[EPDIndex].ChannelSelect, 8);
1.579 +
1.580 + epd_SPI_Send_Byte(0x06, 0xff);
1.581 + epd_SPI_Send_Byte(0x07, 0x9d);
1.582 + epd_SPI_Send_Byte(0x08, 0x00);
1.583 +
1.584 + // SPI (0x09, 0xd000)
1.585 + SendBuffer[0] = 0xd0;
1.586 + SendBuffer[1] = 0x00;
1.587 + epd_SPI_Send(0x09, SendBuffer, 2);
1.588 +
1.589 + epd_SPI_Send_Byte(0x04,COG_Parameters[EPDIndex].VoltageLevel);
1.590 +
1.591 + epd_SPI_Send_Byte(0x03, 0x01);
1.592 + epd_SPI_Send_Byte(0x03, 0x00);
1.593 +
1.594 + epd_pwm_active(5);
1.595 +
1.596 + epd_SPI_Send_Byte(0x05, 0x01);
1.597 +
1.598 + epd_pwm_active(30);
1.599 +
1.600 + epd_SPI_Send_Byte(0x05, 0x03);
1.601 + epd_delay_ms(30);
1.602 + epd_SPI_Send_Byte(0x05, 0x0f);
1.603 + epd_delay_ms(30);
1.604 + epd_SPI_Send_Byte(0x02, 0x24);
1.605 +}
1.606 +
1.607 +void epd_Display (uint8_t *pNewImg, uint8_t *pPrevImg)
1.608 +{
1.609 + //COG Process - update display in four steps
1.610 + Display_Stage_1(pPrevImg);
1.611 + Display_Stage_2(pPrevImg);
1.612 + Display_Stage_3(pNewImg);
1.613 + Display_Stage_4(pNewImg);
1.614 +}
1.615 +
1.616 +void epd_PowerOff (void)
1.617 +{
1.618 + Display_Nothing();
1.619 + Dummy_line();
1.620 + epd_delay_ms(25);
1.621 +
1.622 + //border_low();
1.623 + //epd_delay_ms(_30ms);
1.624 + //border_high();
1.625 +
1.626 + epd_SPI_Send_Byte(0x03, 0x01);
1.627 + epd_SPI_Send_Byte(0x02, 0x05);
1.628 + epd_SPI_Send_Byte(0x05, 0x0E);
1.629 + epd_SPI_Send_Byte(0x05, 0x02);
1.630 + epd_SPI_Send_Byte(0x04, 0x0C);
1.631 + epd_delay_ms(120);
1.632 + epd_SPI_Send_Byte(0x05, 0x00);
1.633 + epd_SPI_Send_Byte(0x07, 0x0D);
1.634 + epd_SPI_Send_Byte(0x04, 0x50);
1.635 + epd_delay_ms(40);
1.636 + epd_SPI_Send_Byte(0x04, 0xA0);
1.637 + epd_delay_ms(40);
1.638 + epd_SPI_Send_Byte(0x04, 0x00);
1.639 +
1.640 + epd_rst_low();
1.641 + epd_cs_low();
1.642 + epd_spi_detach();
1.643 + epd_panelon_off();
1.644 +
1.645 + //epd_border_low();
1.646 +
1.647 + epd_discharge_high();
1.648 + epd_delay_ms(150);
1.649 + epd_discharge_low();
1.650 +}
1.651 +
1.652 +
1.653 +
2.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
2.2 +++ b/Display_COG_Process.h Sun Apr 07 18:35:52 2013 +0000
2.3 @@ -0,0 +1,120 @@
2.4 +// Copyright 2013 Pervasive Displays, Inc.
2.5 +//
2.6 +// Licensed under the Apache License, Version 2.0 (the "License");
2.7 +// you may not use this file except in compliance with the License.
2.8 +// You may obtain a copy of the License at:
2.9 +//
2.10 +// http://www.apache.org/licenses/LICENSE-2.0
2.11 +//
2.12 +// Unless required by applicable law or agreed to in writing,
2.13 +// software distributed under the License is distributed on an
2.14 +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
2.15 +// express or implied. See the License for the specific language
2.16 +// governing permissions and limitations under the License.
2.17 +
2.18 +#ifndef __Display_COG_Process_H_
2.19 +#define __Display_COG_Process_H_
2.20 +
2.21 +/******************************************************************************
2.22 + * Includes
2.23 + *****************************************************************************/
2.24 +
2.25 + #include "bsp.h"
2.26 +
2.27 +/******************************************************************************
2.28 + * Defines and typedefs
2.29 + *****************************************************************************/
2.30 +#define BLACK0 (0x03)
2.31 +#define BLACK1 (0x0C)
2.32 +#define BLACK2 (0x30)
2.33 +#define BLACK3 (0xc0)
2.34 +#define WHITE0 (0x02)
2.35 +#define WHITE1 (0x08)
2.36 +#define WHITE2 (0x20)
2.37 +#define WHITE3 (0x80)
2.38 +
2.39 +#define NOTHING (0x00)
2.40 +#define SCANON (0xC0)
2.41 +#define __LineDataSize 111
2.42 +
2.43 +/*
2.44 +enum
2.45 +{
2.46 + _5ms,
2.47 + _10ms,
2.48 + _25ms,
2.49 + _30ms,
2.50 + _40ms,
2.51 + _120ms,
2.52 + _150ms,
2.53 + _300ms
2.54 +};
2.55 +*/
2.56 +
2.57 +typedef enum
2.58 +{
2.59 + EPDType_144 = 0, //1.44" display
2.60 + EPDType_200 = 1, //2.0" display
2.61 + EPDType_270 = 2 //2.7" display
2.62 +} EPDType_t;
2.63 +#define EPD_TYPE_144 0
2.64 +#define EPD_TYPE_200 1
2.65 +#define EPD_TYPE_270 2
2.66 +
2.67 +typedef struct
2.68 +{
2.69 + uint8_t Even[16];
2.70 + uint8_t Scan[24];
2.71 + uint8_t Odd [16];
2.72 +} COG_144_LineData_t;
2.73 +
2.74 +typedef struct
2.75 +{
2.76 + uint8_t Even[25];
2.77 + uint8_t Scan[24];
2.78 + uint8_t Odd [25];
2.79 + uint8_t DummyData;
2.80 +} COG_20_LineData_t;
2.81 +
2.82 +typedef struct
2.83 +{
2.84 + uint8_t Even[33];
2.85 + uint8_t Scan[44];
2.86 + uint8_t Odd [33];
2.87 + uint8_t DummyData;
2.88 +} COG_27_LineData_t;
2.89 +
2.90 +typedef union
2.91 +{
2.92 + union
2.93 + {
2.94 + COG_144_LineData_t COG_144LineData;
2.95 + COG_20_LineData_t COG_20LineData;
2.96 + COG_27_LineData_t COG_27LineData;
2.97 + } LineDatas;
2.98 + uint8_t uint8[__LineDataSize];
2.99 +} COG_LineDataPacket_t;
2.100 +
2.101 +typedef struct
2.102 +{
2.103 + uint8_t ChannelSelect[8];
2.104 + uint8_t VoltageLevel;
2.105 + uint16_t HORIZONTAL;
2.106 + uint16_t VERTICAL;
2.107 + uint8_t DataLineSize;
2.108 + uint16_t FrameTime;
2.109 + uint16_t StageTime;
2.110 +} COG_Parameters_t;
2.111 +
2.112 +extern const COG_Parameters_t COG_Parameters[3];
2.113 +
2.114 +/******************************************************************************
2.115 + * Prototypes
2.116 + *****************************************************************************/
2.117 +void epd_HwInit(void);
2.118 +void epd_PowerOn(void);
2.119 +void epd_InitializeDriver(uint8_t EPDIndex);
2.120 +void epd_Display(uint8_t *pNewImg, uint8_t *pPrevImg);
2.121 +void epd_PowerOff(void);
2.122 +
2.123 +#endif //__Display_COG_Process_H_
5.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
5.2 +++ b/Display_Hardware_Driver.c Sun Apr 07 18:35:52 2013 +0000
5.3 @@ -0,0 +1,258 @@
5.4 +// Copyright 2013 Pervasive Displays, Inc.
5.5 +//
5.6 +// Licensed under the Apache License, Version 2.0 (the "License");
5.7 +// you may not use this file except in compliance with the License.
5.8 +// You may obtain a copy of the License at:
5.9 +//
5.10 +// http://www.apache.org/licenses/LICENSE-2.0
5.11 +//
5.12 +// Unless required by applicable law or agreed to in writing,
5.13 +// software distributed under the License is distributed on an
5.14 +// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
5.15 +// express or implied. See the License for the specific language
5.16 +// governing permissions and limitations under the License.
5.17 +
5.18 +/******************************************************************************
5.19 + * Includes
5.20 + *****************************************************************************/
5.21 +#include "Display_Hardware_Driver.h"
5.22 +
5.23 +
5.24 +/******************************************************************************
5.25 + * Public functions
5.26 + *****************************************************************************/
5.27 +void epd_cs_high(void)
5.28 +{
5.29 + // CS_SET_HIGH;
5.30 + bsp_pinOut(BSP_PIN_6, 1);
5.31 +}
5.32 +
5.33 +void epd_cs_low(void)
5.34 +{
5.35 + // CS_SET_LOW;
5.36 + bsp_pinOut(BSP_PIN_6, 0);
5.37 +}
5.38 +
5.39 +void epd_rst_high(void)
5.40 +{
5.41 + // RST_SET_HIGH;
5.42 + bsp_pinOut(BSP_PIN_12, 1);
5.43 +}
5.44 +
5.45 +void epd_rst_low(void)
5.46 +{
5.47 + // RST_SET_LOW;
5.48 + bsp_pinOut(BSP_PIN_12, 0);
5.49 +}
5.50 +
5.51 +void epd_discharge_high(void)
5.52 +{
5.53 + // DISCHARGE_SET_HIGH;
5.54 + bsp_pinOut(BSP_PIN_14, 1);
5.55 +}
5.56 +
5.57 +void epd_discharge_low(void)
5.58 +{
5.59 + // DISCHARGE_SET_LOW;
5.60 + bsp_pinOut(BSP_PIN_14, 0);
5.61 +}
5.62 +
5.63 +void epd_panelon_off(void)
5.64 +{
5.65 + // PANELON_SET_LOW;
5.66 + bsp_pinOut(BSP_PIN_13, 0);
5.67 +}
5.68 +
5.69 +void epd_panelon_on(void)
5.70 +{
5.71 + // PANELON_SET_HIGH;
5.72 + bsp_pinOut(BSP_PIN_13, 1);
5.73 +}
5.74 +
5.75 +void epd_border_high(void)
5.76 +{
5.77 + // BORDER_SET_HIGH;
5.78 +}
5.79 +
5.80 +void epd_border_low(void)
5.81 +{
5.82 + // BORDER_SET_LOW;
5.83 +}
5.84 +
5.85 +void epd_delay_ms(uint32_t Time)
5.86 +{
5.87 + bsp_delayMs(Time);
5.88 +}
5.89 +
5.90 +int16_t epd_get_temperature(void)
5.91 +{
5.92 + return bsp_getTemp();
5.93 +}
5.94 +
5.95 +uint32_t epd_GetCurrentTimeTick(void)
5.96 +{
5.97 + return bsp_getMsTicks();
5.98 +}
5.99 +
5.100 +//******************************************************************
5.101 +//PWM Configuration/Control
5.102 +//******************************************************************
5.103 +#if 0
5.104 +volatile uint32_t period = 500; //96Khz PWM frequency
5.105 +
5.106 +void epd_pwm_disable(void)
5.107 +{
5.108 + disable_timer16(1);
5.109 + LPC_IOCON->PIO1_9 &= 0xFC;//Disable PWM,set general IO
5.110 + PWM_DIR_OUT();
5.111 + PWM_SET_LOW();
5.112 +}
5.113 +
5.114 +void epd_pwm_active(void)
5.115 +{
5.116 + PWM_SET_HIGH();
5.117 + /* Initialize the PWM in timer32_1 enabling match0 output */
5.118 + init_timer16PWM(1, period, MATCH0,0);
5.119 + setMatch_timer16PWM (1, 1, period/8);
5.120 + enable_timer16(1);
5.121 +}
5.122 +#endif
5.123 +void epd_pwm_active(uint16_t delayInMs)
5.124 +{
5.125 + uint16_t numOfIterations;
5.126 +
5.127 + numOfIterations = delayInMs * 100;
5.128 + // PWM_DIR_OUT;
5.129 + bsp_pinMode(BSP_PIN_11, BSP_PINMODE_OUTPUT);
5.130 + for(; numOfIterations > 0; numOfIterations--)
5.131 + {
5.132 + // PWM_SET_HIGH;
5.133 + bsp_pinOut(BSP_PIN_11, 1);
5.134 + bsp_delayUs(5); //100kHz (96kHz ideal)
5.135 + // PWM_SET_LOW;
5.136 + bsp_pinOut(BSP_PIN_11, 0);
5.137 + bsp_delayUs(5);
5.138 + }
5.139 +}
5.140 +
5.141 +
5.142 +//******************************************************************
5.143 +//SPI Configuration
5.144 +//******************************************************************
5.145 +void epd_spi_detach(void)
5.146 +{
5.147 +#if 0
5.148 + LPC_IOCON->PIO0_8 &= 0xFC;; /* SSP I/O config */
5.149 + SPIMISO_DIR_OUT();
5.150 + SPIMISO_Set(Low);
5.151 +
5.152 + LPC_IOCON->PIO0_9 &= 0xFC; /* SSP MOSI */
5.153 + SPIMOSI_DIR_OUT();
5.154 + SPIMOSI_Set(Low);
5.155 +
5.156 + LPC_IOCON->PIO2_11 &= 0xFC;
5.157 + SPICLK_DIR_OUT();
5.158 + SPICLK_Set(Low);
5.159 +#endif
5.160 +}
5.161 +void epd_spi_init (void)
5.162 +{
5.163 + bsp_spiInit();
5.164 +//SSP_IOConfig( SSP_PORT ); /* initialize SSP port */
5.165 +//SSP_Init( SSP_PORT );
5.166 +}
5.167 +
5.168 +void epd_SPI_Send (unsigned char Register, unsigned char *Data, unsigned Length)
5.169 +{
5.170 + uint8_t buf[2];
5.171 +
5.172 + epd_cs_low();
5.173 + buf[0] = 0x70;
5.174 + buf[1] = Register;
5.175 + bsp_writeToDisplay(buf, 2);
5.176 + epd_cs_high();
5.177 + bsp_delayUs(10);
5.178 +
5.179 + epd_cs_low();
5.180 + buf[0] = 0x72;
5.181 + bsp_writeToDisplay(buf, 1);
5.182 + bsp_writeToDisplay(Data, Length);
5.183 + epd_cs_high();
5.184 + bsp_delayUs(10);
5.185 +}
5.186 +
5.187 +
5.188 +
5.189 +void epd_SPI_Send_Byte (uint8_t Register, uint8_t Data)
5.190 +{
5.191 + uint8_t buf[2];
5.192 +
5.193 + epd_cs_low();
5.194 + buf[0] = 0x70;
5.195 + buf[1] = Register;
5.196 + bsp_writeToDisplay(buf, 2);
5.197 + epd_cs_high();
5.198 + bsp_delayUs(10);
5.199 +
5.200 + epd_cs_low();
5.201 + buf[0] = 0x72;
5.202 + buf[1] = Data;
5.203 + bsp_writeToDisplay(buf, 2);
5.204 + epd_cs_high();
5.205 + bsp_delayUs(10);
5.206 +}
5.207 +
5.208 +void epd_InitDisplayHardware(void)
5.209 +{
5.210 + // RST_DIR_OUT;
5.211 + bsp_pinMode(BSP_PIN_12, BSP_PINMODE_OUTPUT);
5.212 + // DISCHARGE_DIR_OUT;
5.213 + bsp_pinMode(BSP_PIN_14, BSP_PINMODE_OUTPUT);
5.214 + // CS_DIR_OUT;
5.215 + bsp_pinMode(BSP_PIN_6, BSP_PINMODE_OUTPUT);
5.216 + // PANELON_DIR_OUT;
5.217 + bsp_pinMode(BSP_PIN_13, BSP_PINMODE_OUTPUT);
5.218 + // DRIVERBUSY_DIR_IN;
5.219 + bsp_pinMode(BSP_PIN_7, BSP_PINMODE_INPUT);
5.220 + // BORDER_DIR_OUT;
5.221 +
5.222 +
5.223 + epd_panelon_off();
5.224 + epd_spi_init();
5.225 + epd_cs_low();
5.226 + // epd_pwm_low();
5.227 + epd_pwm_active(0); //set output low
5.228 + epd_rst_low();
5.229 + epd_discharge_low();
5.230 +
5.231 +// TESTPin_DIR_OUT();
5.232 +// TESTPin2_DIR_OUT();
5.233 +}
5.234 +
5.235 +//************************************************************************
5.236 +void TestPinLow(void)
5.237 +{
5.238 +// TESTPin_Set(0);
5.239 +}
5.240 +void TestPinHigh(void)
5.241 +{
5.242 +// TESTPin_Set(1);
5.243 +}
5.244 +void TestPinTrigger(void)
5.245 +{
5.246 +// if(TESTPin_Get())TestPinLow();
5.247 +// else TestPinHigh();
5.248 +}
5.249 +void TestPin2Low(void)
5.250 +{
5.251 +// TESTPin2_Set(0);
5.252 +}
5.253 +void TestPin2High(void)
5.254 +{
5.255 +// TESTPin2_Set(1);
5.256 +}
5.257 +void TestPin2Trigger(void)
5.258 +{
5.259 +// if(TESTPin2_Get())TestPin2Low();
5.260 +// else TestPin2High();
5.261 +}