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 +