# HG changeset patch # User Paul Boddie # Date 1369148887 0 # Node ID 06697662b4d6315fb94f5ccc26831dd8bd7d4711 # Parent 488ce300977e8ce579cda213e61a767e9e0664d0 Switched to the newer code drop from Pervasive Displays. diff -r 488ce300977e -r 06697662b4d6 Display_COG_Process.c --- a/Display_COG_Process.c Sun May 19 22:06:40 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,616 +0,0 @@ -// Copyright 2013 Pervasive Displays, Inc. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at: -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either -// express or implied. See the License for the specific language -// governing permissions and limitations under the License. - -/****************************************************************************** - * Includes - *****************************************************************************/ -//#include "driver_config.h" -//#include "target_config.h" -//#include "type.h" -//#include "gpio.h" -#include "Display_COG_Process.h" -#include "Display_Hardware_Driver.h" -#include "Display_Controller.h" -#include - - -/****************************************************************************** - * Defines and typedefs - *****************************************************************************/ -#define _GaugeFrameTimeMark 0 - -const COG_Parameters_t COG_Parameters[3]= { - { //for 1.44" - {0x00,0x00,0x00,0x00,0x00,0x0f,0xff,0x00}, - 0x03, - (128/8), - 96, - (((128+96)*2)/8), - (43), - 480 - }, - { //for 2.0" - {0x00,0x00,0x00,0x00,0x01,0xFF,0xE0,0x00}, - 0x03, - (200/8), - 96, - (((200+96)*2)/8)+1, - (53), - 480 - }, - { //for 2.7" - {0x00,0x00,0x00,0x7F,0xFF,0xFE,0x00,0x00}, - 0x00, - (264/8), - 176, - (((264+176)*2)/8)+1, - 105, - 630 - }, -}; - -const uint8_t ScanTable[4] = {0xC0, 0x30, 0x0C, 0x03}; - - -/****************************************************************************** - * Local variables - *****************************************************************************/ -static uint32_t StageTime = 480; -static COG_LineDataPacket_t COG_Line; -static uint16_t EPD_Type_Index = 0; -static uint16_t cnt = 0; -static uint32_t Currentframe; -static uint8_t *DataLineEven; -static uint8_t *DataLineOdd; -static uint8_t *DataLineScan; -static uint8_t *DisplayOrgPtr; - - -/****************************************************************************** - * Local functions - *****************************************************************************/ -static void SetTemperature_Factor(uint8_t EPD_Type_Index) -{ - int16_t Temperature; - - //Get current temperature - Temperature = epd_get_temperature(); - - if (Temperature < -10) - { - StageTime = COG_Parameters[EPD_Type_Index].StageTime * 17; - } - else if (Temperature < -5) - { - StageTime = COG_Parameters[EPD_Type_Index].StageTime * 12; - } - else if (Temperature < 5) - { - StageTime = COG_Parameters[EPD_Type_Index].StageTime * 8; - } - else if (Temperature < 10) - { - StageTime = COG_Parameters[EPD_Type_Index].StageTime * 4; - } - else if (Temperature < 15) - { - StageTime = COG_Parameters[EPD_Type_Index].StageTime * 3; - } - else if (Temperature < 20) - { - StageTime = COG_Parameters[EPD_Type_Index].StageTime * 2; - } - else if (Temperature < 40) - { - StageTime = COG_Parameters[EPD_Type_Index].StageTime * 1; - } - else - { - StageTime = (COG_Parameters[EPD_Type_Index].StageTime * 7)/10; - } -} - -static void Driver_TypeSelect(uint8_t typeIndex) -{ - switch(typeIndex) - { - case EPDType_144: - DataLineEven=&COG_Line.LineDatas.COG_144LineData.Even[0]; - DataLineOdd=&COG_Line.LineDatas.COG_144LineData.Odd[0]; - DataLineScan=&COG_Line.LineDatas.COG_144LineData.Scan[0]; - break; - case EPDType_200: - DataLineEven=&COG_Line.LineDatas.COG_20LineData.Even[0]; - DataLineOdd=&COG_Line.LineDatas.COG_20LineData.Odd[0]; - DataLineScan=&COG_Line.LineDatas.COG_20LineData.Scan[0]; - break; - case EPDType_270: - DataLineEven=&COG_Line.LineDatas.COG_27LineData.Even[0]; - DataLineOdd=&COG_Line.LineDatas.COG_27LineData.Odd[0]; - DataLineScan=&COG_Line.LineDatas.COG_27LineData.Scan[0]; - break; - } -} - -//#pragma GCC optimize ("-O3") -static void Display_Stage_1 (uint8_t *PreviousPicture) -{ - uint16_t i,j,k; // general counters - uint8_t TempByte; // Temporary storage for image data check - uint16_t StartClock; -#ifdef DISPLAY_180_DEGREE - uint8_t *DataLinePrt; - DisplayOrgPtr = (PreviousPicture+(uint32_t)((COG_Parameters[EPD_Type_Index].VERTICAL-1)*COG_Parameters[EPD_Type_Index].HORIZONTAL)); -#else - DisplayOrgPtr = PreviousPicture; -#endif - Currentframe = (uint32_t)COG_Parameters[EPD_Type_Index].FrameTime; -//TestPinTrigger(); - cnt = 0; - StartClock = epd_GetCurrentTimeTick(); - do - { -// TestPin2Trigger(); - PreviousPicture = DisplayOrgPtr; -#ifdef DISPLAY_180_DEGREE - DataLinePrt = PreviousPicture; -#endif - for (i = 0; i < COG_Parameters[EPD_Type_Index].VERTICAL; i++) // for every line - { - // SPI (0x04, ...) - epd_SPI_Send_Byte(0x04, COG_Parameters[EPD_Type_Index].VoltageLevel); - k = COG_Parameters[EPD_Type_Index].HORIZONTAL-1; - for (j = 0; j < COG_Parameters[EPD_Type_Index].HORIZONTAL; j++) // check every bit in the line - { - TempByte = (*PreviousPicture++); -#ifdef DISPLAY_180_DEGREE - DataLineEven[j] = ((TempByte & 0x80) ? BLACK3 : WHITE3) - | ((TempByte & 0x20) ? BLACK2 : WHITE2) - | ((TempByte & 0x08) ? BLACK1 : WHITE1) - | ((TempByte & 0x02) ? BLACK0 : WHITE0); - - DataLineOdd[k--] = ((TempByte & 0x01) ? BLACK3 : WHITE3) - | ((TempByte & 0x04) ? BLACK2 : WHITE2) - | ((TempByte & 0x10) ? BLACK1 : WHITE1) - | ((TempByte & 0x40) ? BLACK0 : WHITE0); - DataLinePrt--; -#else - DataLineOdd[j] = ((TempByte & 0x80) ? BLACK3 : WHITE3) - | ((TempByte & 0x20) ? BLACK2 : WHITE2) - | ((TempByte & 0x08) ? BLACK1 : WHITE1) - | ((TempByte & 0x02) ? BLACK0 : WHITE0); - - DataLineEven[k--] = ((TempByte & 0x01) ? BLACK3 : WHITE3) - | ((TempByte & 0x04) ? BLACK2 : WHITE2) - | ((TempByte & 0x10) ? BLACK1 : WHITE1) - | ((TempByte & 0x40) ? BLACK0 : WHITE0); -#endif - } -#ifdef DISPLAY_180_DEGREE - PreviousPicture = DataLinePrt; -#endif - DataLineScan[(i>>2)] = ScanTable[(i%4)]; - // SPI (0x0a, line data....) - epd_SPI_Send(0x0a, (uint8_t *)&COG_Line.uint8, COG_Parameters[EPD_Type_Index].DataLineSize); - - // SPI (0x02, 0x25) - epd_SPI_Send_Byte(0x02, 0x2F); - - DataLineScan[(i>>2)] = 0; - } -#if(!_GaugeFrameTimeMark) - if(COG_Parameters[EPD_Type_Index].FrameTime>0) - { - while(Currentframe>(epd_GetCurrentTimeTick() - StartClock)); - } -#endif - //TestPin2Trigger(); - Currentframe=(uint32_t)(epd_GetCurrentTimeTick() - StartClock)+COG_Parameters[EPD_Type_Index].FrameTime ; - cnt++; - }while (StageTime>Currentframe); -// TestPin2Trigger(); - while(StageTime>(epd_GetCurrentTimeTick() - StartClock)); -// TestPin2Trigger(); -// TestPinTrigger(); -} - -//#pragma GCC optimize ("-O3") -static void Display_Stage_2 (uint8_t *PreviousPicture) -{ - uint16_t i, j, k; // general counters - uint8_t TempByte; // Temporary storage for image data check - uint16_t StartClock; -#ifdef DISPLAY_180_DEGREE - uint8_t *DataLinePrt; - DisplayOrgPtr = (PreviousPicture+(uint32_t)((COG_Parameters[EPD_Type_Index].VERTICAL-1)*COG_Parameters[EPD_Type_Index].HORIZONTAL)); -#else - DisplayOrgPtr = PreviousPicture; -#endif - -// TestPinTrigger(); - cnt = 0; - Currentframe = (uint32_t)COG_Parameters[EPD_Type_Index].FrameTime; - StartClock = epd_GetCurrentTimeTick(); - do - { -// TestPin2Trigger(); - PreviousPicture = DisplayOrgPtr; -#ifdef DISPLAY_180_DEGREE - DataLinePrt = PreviousPicture; -#endif - for (i = 0; i < COG_Parameters[EPD_Type_Index].VERTICAL; i++) // for every line - { - // SPI (0x04, ...) - epd_SPI_Send_Byte(0x04, COG_Parameters[EPD_Type_Index].VoltageLevel); - k = COG_Parameters[EPD_Type_Index].HORIZONTAL-1; - for (j = 0; j < COG_Parameters[EPD_Type_Index].HORIZONTAL; j++) // make every bit in the line black - { - TempByte =(*PreviousPicture++); -#ifdef DISPLAY_180_DEGREE - DataLineEven[j] = ((TempByte & 0x80) ? WHITE3 : NOTHING) - | ((TempByte & 0x20) ? WHITE2 : NOTHING) - | ((TempByte & 0x08) ? WHITE1 : NOTHING) - | ((TempByte & 0x02) ? WHITE0 : NOTHING); - DataLineOdd[k--] = ((TempByte & 0x01) ? WHITE3 : NOTHING) - | ((TempByte & 0x04) ? WHITE2 : NOTHING) - | ((TempByte & 0x10) ? WHITE1 : NOTHING) - | ((TempByte & 0x40) ? WHITE0 : NOTHING); - DataLinePrt--; -#else - DataLineOdd[j] = ((TempByte & 0x80) ? WHITE3 : NOTHING) - | ((TempByte & 0x20) ? WHITE2 : NOTHING) - | ((TempByte & 0x08) ? WHITE1 : NOTHING) - | ((TempByte & 0x02) ? WHITE0 : NOTHING); - DataLineEven[k--] = ((TempByte & 0x01) ? WHITE3 : NOTHING) - | ((TempByte & 0x04) ? WHITE2 : NOTHING) - | ((TempByte & 0x10) ? WHITE1 : NOTHING) - | ((TempByte & 0x40) ? WHITE0 : NOTHING); -#endif - } - -#ifdef DISPLAY_180_DEGREE - PreviousPicture = DataLinePrt; -#endif - DataLineScan[(i>>2)] = ScanTable[(i%4)]; - // SPI (0x0a, line data....) - epd_SPI_Send(0x0a, (uint8_t *)&COG_Line.uint8, COG_Parameters[EPD_Type_Index].DataLineSize); - - epd_SPI_Send_Byte(0x02, 0x25); - - DataLineScan[(i>>2)] = 0; - } -#if(!_GaugeFrameTimeMark) - if(COG_Parameters[EPD_Type_Index].FrameTime>0) - { - while(Currentframe>(epd_GetCurrentTimeTick() - StartClock)); - } -#endif - //TestPin2Trigger(); - Currentframe=(uint32_t)(epd_GetCurrentTimeTick() - StartClock)+COG_Parameters[EPD_Type_Index].FrameTime ; - cnt++; - }while (StageTime>Currentframe); -// TestPin2Trigger(); - while(StageTime>(epd_GetCurrentTimeTick() - StartClock)); -// TestPin2Trigger(); -// TestPinTrigger(); -} - - -//#pragma GCC optimize ("-O3") -static void Display_Stage_3 (uint8_t *Picture) -{ - uint16_t i, j,k; // general counters - uint8_t TempByte; // Temporary storage for image data check - uint16_t StartClock; -#ifdef DISPLAY_180_DEGREE - uint8_t *DataLinePrt; - DisplayOrgPtr = (Picture+(uint32_t)((COG_Parameters[EPD_Type_Index].VERTICAL-1)*COG_Parameters[EPD_Type_Index].HORIZONTAL)); -#else - DisplayOrgPtr = Picture; -#endif - Currentframe = (uint32_t)COG_Parameters[EPD_Type_Index].FrameTime; - cnt = 0; -// TestPinTrigger(); - StartClock = epd_GetCurrentTimeTick(); - do - { -// TestPin2Trigger(); - Picture = DisplayOrgPtr; -#ifdef DISPLAY_180_DEGREE - DataLinePrt = Picture; -#endif - for (i = 0; i < COG_Parameters[EPD_Type_Index].VERTICAL; i++) // for every line - { - // SPI (0x04, 0x03) - epd_SPI_Send_Byte(0x04, COG_Parameters[EPD_Type_Index].VoltageLevel); - k = COG_Parameters[EPD_Type_Index].HORIZONTAL-1; - for (j = 0; j < COG_Parameters[EPD_Type_Index].HORIZONTAL; j++) // check every bit in the line - { - TempByte = (*Picture++); -#ifdef DISPLAY_180_DEGREE - DataLineEven[j] = ((TempByte & 0x80) ? BLACK3 : NOTHING) - | ((TempByte & 0x20) ? BLACK2 : NOTHING ) - | ((TempByte & 0x08) ? BLACK1 : NOTHING ) - | ((TempByte & 0x02) ? BLACK0 : NOTHING ); - - DataLineOdd[k--] = ((TempByte & 0x01) ? BLACK3 : NOTHING) - | ((TempByte & 0x04) ? BLACK2 : NOTHING ) - | ((TempByte & 0x10) ? BLACK1 : NOTHING ) - | ((TempByte & 0x40) ? BLACK0 : NOTHING ); - DataLinePrt--; -#else - DataLineOdd[j] = ((TempByte & 0x80) ? BLACK3 : NOTHING) - | ((TempByte & 0x20) ? BLACK2 : NOTHING ) - | ((TempByte & 0x08) ? BLACK1 : NOTHING ) - | ((TempByte & 0x02) ? BLACK0 : NOTHING ); - - DataLineEven[k--] = ((TempByte & 0x01) ? BLACK3 : NOTHING) - | ((TempByte & 0x04) ? BLACK2 : NOTHING ) - | ((TempByte & 0x10) ? BLACK1 : NOTHING ) - | ((TempByte & 0x40) ? BLACK0 : NOTHING ); -#endif - } -#ifdef DISPLAY_180_DEGREE - Picture = DataLinePrt; -#endif - DataLineScan[(i>>2)] = ScanTable[(i%4)]; - // SPI (0x0a, line data....) - epd_SPI_Send(0x0a, (uint8_t *)&COG_Line.uint8, COG_Parameters[EPD_Type_Index].DataLineSize); - - epd_SPI_Send_Byte(0x02, 0x2F); - - DataLineScan[(i>>2)] = 0; - } -#if(!_GaugeFrameTimeMark) - if(COG_Parameters[EPD_Type_Index].FrameTime>0) - { - while(Currentframe>(epd_GetCurrentTimeTick() - StartClock)); - } -#endif - //TestPin2Trigger(); - Currentframe=(uint32_t)(epd_GetCurrentTimeTick() - StartClock)+COG_Parameters[EPD_Type_Index].FrameTime ; - cnt++; - }while (StageTime>Currentframe); -// TestPin2Trigger(); - while(StageTime>(epd_GetCurrentTimeTick() - StartClock)); -// TestPin2Trigger(); -// TestPinTrigger(); -} - -//#pragma GCC optimize ("-O3") -static void Display_Stage_4 (uint8_t *Picture) -{ - uint16_t i, j,k; // general counters - uint8_t TempByte; // Temporary storage for image data check - uint16_t StartClock; -#ifdef DISPLAY_180_DEGREE - uint8_t *DataLinePrt; - DisplayOrgPtr = (Picture+(uint32_t)((COG_Parameters[EPD_Type_Index].VERTICAL-1)*COG_Parameters[EPD_Type_Index].HORIZONTAL)); -#else - DisplayOrgPtr = Picture; -#endif - Currentframe = (uint32_t)COG_Parameters[EPD_Type_Index].FrameTime; - cnt = 0; -// TestPinTrigger(); - - StartClock = epd_GetCurrentTimeTick(); - do - { -// TestPin2Trigger(); - Picture = DisplayOrgPtr; -#ifdef DISPLAY_180_DEGREE - DataLinePrt = Picture; -#endif - for (i = 0; i < COG_Parameters[EPD_Type_Index].VERTICAL; i++) // for every line - { - // SPI (0x04, ...) - epd_SPI_Send_Byte(0x04, COG_Parameters[EPD_Type_Index].VoltageLevel); - k = COG_Parameters[EPD_Type_Index].HORIZONTAL-1; - for (j = 0; j < COG_Parameters[EPD_Type_Index].HORIZONTAL; j++) // check every bit in the line - { - TempByte =(*Picture++); -#ifdef DISPLAY_180_DEGREE - DataLineEven[j] = ((TempByte & 0x80) ? WHITE3 : BLACK3 ) - | ((TempByte & 0x20) ? WHITE2 : BLACK2 ) - | ((TempByte & 0x08) ? WHITE1 : BLACK1 ) - | ((TempByte & 0x02) ? WHITE0 : BLACK0 ); - - DataLineOdd[k--] = ((TempByte & 0x01) ? WHITE3 : BLACK3 ) - | ((TempByte & 0x04) ? WHITE2 : BLACK2 ) - | ((TempByte & 0x10) ? WHITE1 : BLACK1 ) - | ((TempByte & 0x40) ? WHITE0 : BLACK0 ); - DataLinePrt--; -#else - DataLineOdd[j] = ((TempByte & 0x80) ? WHITE3 : BLACK3 ) - | ((TempByte & 0x20) ? WHITE2 : BLACK2 ) - | ((TempByte & 0x08) ? WHITE1 : BLACK1 ) - | ((TempByte & 0x02) ? WHITE0 : BLACK0 ); - - DataLineEven[k--] = ((TempByte & 0x01) ? WHITE3 : BLACK3 ) - | ((TempByte & 0x04) ? WHITE2 : BLACK2 ) - | ((TempByte & 0x10) ? WHITE1 : BLACK1 ) - | ((TempByte & 0x40) ? WHITE0 : BLACK0 ); -#endif - } -#ifdef DISPLAY_180_DEGREE - Picture = DataLinePrt; -#endif - DataLineScan[(i>>2)] = ScanTable[(i%4)]; - // SPI (0x0a, line data....) - epd_SPI_Send(0x0a, (uint8_t *)&COG_Line.uint8, COG_Parameters[EPD_Type_Index].DataLineSize); - - epd_SPI_Send_Byte(0x02, 0x2F); - - DataLineScan[(i>>2)] = 0; - } -#if(!_GaugeFrameTimeMark) - if(COG_Parameters[EPD_Type_Index].FrameTime>0) - { - while(Currentframe>(epd_GetCurrentTimeTick() - StartClock)); - } -#endif - //TestPin2Trigger(); - Currentframe=(uint32_t)(epd_GetCurrentTimeTick() - StartClock)+COG_Parameters[EPD_Type_Index].FrameTime ; - cnt++; - }while (StageTime>Currentframe); - -// TestPin2Trigger(); - while(StageTime>(epd_GetCurrentTimeTick() - StartClock)); -// TestPin2Trigger(); -// TestPinTrigger(); -} - -static void Display_Nothing (void) -{ - uint16_t i; // general counters - - for (i = 0; i < COG_Parameters[EPD_Type_Index].HORIZONTAL; i++) // make every bit in the line white - { - DataLineEven[i] = 0x00; - DataLineOdd[i] = 0x00; - } - - for (i = 0; i < COG_Parameters[EPD_Type_Index].VERTICAL; i++) // for every line - { - epd_SPI_Send_Byte(0x04, 0x03); - DataLineScan[(i>>2)] = ScanTable[(i%4)]; - // SPI (0x0a, line data....) - epd_SPI_Send(0x0a, (uint8_t *)&COG_Line.uint8, COG_Parameters[EPD_Type_Index].DataLineSize); - - epd_SPI_Send_Byte(0x02, 0x2F); - } -} - -static void Dummy_line(void) -{ - uint16_t i; - - for (i = 0; i < COG_Parameters[EPD_Type_Index].DataLineSize; i++) - { - COG_Line.uint8[i] = 0x00; - } - - epd_SPI_Send_Byte(0x04, 0x03); - - // SPI (0x0a, line data....) - epd_SPI_Send(0x0a, (uint8_t *)&COG_Line.uint8, COG_Parameters[EPD_Type_Index].DataLineSize); - - epd_SPI_Send_Byte(0x02, 0x2F); -} - - -/****************************************************************************** - * Public functions - *****************************************************************************/ -void epd_HwInit(void) -{ - epd_InitDisplayHardware(); -} - -void epd_PowerOn(void) -{ - bsp_PowerOn(); -} - -void epd_InitializeDriver(uint8_t EPDIndex) -{ - uint8_t SendBuffer[2]; - uint16_t k; - - EPD_Type_Index = EPDIndex; - - //Data Line Clear - for (k = 0; k <= __LineDataSize; k ++) - { - COG_Line.uint8[k] = 0x00; - } - Driver_TypeSelect(EPDIndex); - k = 0; - - SetTemperature_Factor(EPDIndex); - - /*while (DRIVERBUSY_Get()) - { - delayT32B0Us(500); - if((k++)>=1000) return;//wait 500 ms - } - */ - - // SPI (0x01, 0x0000, 0x0000, 0x01ff, 0xe000) - epd_SPI_Send(0x01, (uint8_t *)&COG_Parameters[EPDIndex].ChannelSelect, 8); - - epd_SPI_Send_Byte(0x06, 0xff); - epd_SPI_Send_Byte(0x07, 0x9d); - epd_SPI_Send_Byte(0x08, 0x00); - - // SPI (0x09, 0xd000) - SendBuffer[0] = 0xd0; - SendBuffer[1] = 0x00; - epd_SPI_Send(0x09, SendBuffer, 2); - - epd_SPI_Send_Byte(0x04,COG_Parameters[EPDIndex].VoltageLevel); - - epd_SPI_Send_Byte(0x03, 0x01); - epd_SPI_Send_Byte(0x03, 0x00); - - epd_pwm_active(5); - - epd_SPI_Send_Byte(0x05, 0x01); - - epd_pwm_active(30); - - epd_SPI_Send_Byte(0x05, 0x03); - epd_delay_ms(30); - epd_SPI_Send_Byte(0x05, 0x0f); - epd_delay_ms(30); - epd_SPI_Send_Byte(0x02, 0x24); - printf("Done initialisation.\n"); -} - -void epd_Display (uint8_t *pNewImg, uint8_t *pPrevImg) -{ - //COG Process - update display in four steps - Display_Stage_1(pPrevImg); - Display_Stage_2(pPrevImg); - Display_Stage_3(pNewImg); - Display_Stage_4(pNewImg); -} - -void epd_PowerOff (void) -{ - Display_Nothing(); - Dummy_line(); - epd_delay_ms(25); - - //border_low(); - //epd_delay_ms(_30ms); - //border_high(); - - epd_SPI_Send_Byte(0x03, 0x01); - epd_SPI_Send_Byte(0x02, 0x05); - epd_SPI_Send_Byte(0x05, 0x0E); - epd_SPI_Send_Byte(0x05, 0x02); - epd_SPI_Send_Byte(0x04, 0x0C); - epd_delay_ms(120); - epd_SPI_Send_Byte(0x05, 0x00); - epd_SPI_Send_Byte(0x07, 0x0D); - epd_SPI_Send_Byte(0x04, 0x50); - epd_delay_ms(40); - epd_SPI_Send_Byte(0x04, 0xA0); - epd_delay_ms(40); - epd_SPI_Send_Byte(0x04, 0x00); - - printf("Shutdown...\n"); - bsp_Shutdown(); -} diff -r 488ce300977e -r 06697662b4d6 Display_COG_Process.h --- a/Display_COG_Process.h Sun May 19 22:06:40 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,120 +0,0 @@ -// Copyright 2013 Pervasive Displays, Inc. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at: -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either -// express or implied. See the License for the specific language -// governing permissions and limitations under the License. - -#ifndef __Display_COG_Process_H_ -#define __Display_COG_Process_H_ - -/****************************************************************************** - * Includes - *****************************************************************************/ - - #include "bsp.h" - -/****************************************************************************** - * Defines and typedefs - *****************************************************************************/ -#define BLACK0 (0x03) -#define BLACK1 (0x0C) -#define BLACK2 (0x30) -#define BLACK3 (0xc0) -#define WHITE0 (0x02) -#define WHITE1 (0x08) -#define WHITE2 (0x20) -#define WHITE3 (0x80) - -#define NOTHING (0x00) -#define SCANON (0xC0) -#define __LineDataSize 111 - -/* -enum -{ - _5ms, - _10ms, - _25ms, - _30ms, - _40ms, - _120ms, - _150ms, - _300ms -}; -*/ - -typedef enum -{ - EPDType_144 = 0, //1.44" display - EPDType_200 = 1, //2.0" display - EPDType_270 = 2 //2.7" display -} EPDType_t; -#define EPD_TYPE_144 0 -#define EPD_TYPE_200 1 -#define EPD_TYPE_270 2 - -typedef struct -{ - uint8_t Even[16]; - uint8_t Scan[24]; - uint8_t Odd [16]; -} COG_144_LineData_t; - -typedef struct -{ - uint8_t Even[25]; - uint8_t Scan[24]; - uint8_t Odd [25]; - uint8_t DummyData; -} COG_20_LineData_t; - -typedef struct -{ - uint8_t Even[33]; - uint8_t Scan[44]; - uint8_t Odd [33]; - uint8_t DummyData; -} COG_27_LineData_t; - -typedef union -{ - union - { - COG_144_LineData_t COG_144LineData; - COG_20_LineData_t COG_20LineData; - COG_27_LineData_t COG_27LineData; - } LineDatas; - uint8_t uint8[__LineDataSize]; -} COG_LineDataPacket_t; - -typedef struct -{ - uint8_t ChannelSelect[8]; - uint8_t VoltageLevel; - uint16_t HORIZONTAL; - uint16_t VERTICAL; - uint8_t DataLineSize; - uint16_t FrameTime; - uint16_t StageTime; -} COG_Parameters_t; - -extern const COG_Parameters_t COG_Parameters[3]; - -/****************************************************************************** - * Prototypes - *****************************************************************************/ -void epd_HwInit(void); -void epd_PowerOn(void); -void epd_InitializeDriver(uint8_t EPDIndex); -void epd_Display(uint8_t *pNewImg, uint8_t *pPrevImg); -void epd_PowerOff(void); - -#endif //__Display_COG_Process_H_ diff -r 488ce300977e -r 06697662b4d6 Display_Controller.c --- a/Display_Controller.c Sun May 19 22:06:40 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,40 +0,0 @@ -// Copyright 2013 Pervasive Displays, Inc. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at: -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either -// express or implied. See the License for the specific language -// governing permissions and limitations under the License. - -/****************************************************************************** - * Includes - *****************************************************************************/ -//#include "driver_config.h" -//#include "type.h" -//#include "gpio.h" -#include "Display_Controller.h" - -/****************************************************************************** - * Global Functions - *****************************************************************************/ - -void epd_DisplayImg(EPDType_t EPDType, uint8_t *pNewImg, uint8_t *pPrevImg) -{ - //always initialize display (has been powered off before) - epd_HwInit(); - epd_PowerOn(); - epd_InitializeDriver(EPDType); - - //display new picture, but first remove old one - epd_Display(pNewImg, pPrevImg); - - //power down display - picture still displayed - epd_PowerOff(); -} - diff -r 488ce300977e -r 06697662b4d6 Display_Controller.h --- a/Display_Controller.h Sun May 19 22:06:40 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,34 +0,0 @@ -// Copyright 2013 Pervasive Displays, Inc. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at: -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either -// express or implied. See the License for the specific language -// governing permissions and limitations under the License. - -#ifndef __Display_Controller_H_ -#define __Display_Controller_H_ - -/****************************************************************************** - * Includes - *****************************************************************************/ -#include "bsp.h" -#include "Display_COG_Process.h" - -/****************************************************************************** - * Defines and typedefs - *****************************************************************************/ -#define DISPLAY_IN_USE EPD_TYPE_270 - -/****************************************************************************** - * Prototypes - *****************************************************************************/ -void epd_DisplayImg(EPDType_t EPDType, uint8_t *pNewImg, uint8_t *pPrevImg); - -#endif //__Display_Controller_H_ diff -r 488ce300977e -r 06697662b4d6 Display_Hardware_Driver.c --- a/Display_Hardware_Driver.c Sun May 19 22:06:40 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,190 +0,0 @@ -// Copyright 2013 Pervasive Displays, Inc. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at: -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either -// express or implied. See the License for the specific language -// governing permissions and limitations under the License. - -/****************************************************************************** - * Includes - *****************************************************************************/ -#include "Display_Hardware_Driver.h" -#include - - -/****************************************************************************** - * Public functions - *****************************************************************************/ -void epd_cs_high(void) -{ - // CS_SET_HIGH; - SET(EPD_SSEL); -} - -void epd_cs_low(void) -{ - // CS_SET_LOW; - CLR(EPD_SSEL); -} - -void epd_rst_high(void) -{ - // RST_SET_HIGH; - SET(EPD_RESET); -} - -void epd_rst_low(void) -{ - // RST_SET_LOW; - CLR(EPD_RESET); -} - -void epd_delay_ms(uint32_t Time) -{ - bsp_delayMs(Time); -} - -int16_t epd_get_temperature(void) -{ - return bsp_getTemp(); -} - -uint32_t epd_GetCurrentTimeTick(void) -{ - return bsp_getMsTicks(); -} - -//****************************************************************** -//PWM Configuration/Control -//****************************************************************** -#if 0 -volatile uint32_t period = 500; //96Khz PWM frequency - -void epd_pwm_disable(void) -{ - disable_timer16(1); - LPC_IOCON->PIO1_9 &= 0xFC;//Disable PWM,set general IO - PWM_DIR_OUT(); - PWM_SET_LOW(); -} - -void epd_pwm_active(void) -{ - PWM_SET_HIGH(); - /* Initialize the PWM in timer32_1 enabling match0 output */ - init_timer16PWM(1, period, MATCH0,0); - setMatch_timer16PWM (1, 1, period/8); - enable_timer16(1); -} -#endif -void epd_pwm_active(uint16_t delayInMs) -{ - bsp_pwm_active(delayInMs); -} - - -//****************************************************************** -//SPI Configuration -//****************************************************************** -void epd_spi_detach(void) -{ -#if 0 - LPC_IOCON->PIO0_8 &= 0xFC;; /* SSP I/O config */ - SPIMISO_DIR_OUT(); - SPIMISO_Set(Low); - - LPC_IOCON->PIO0_9 &= 0xFC; /* SSP MOSI */ - SPIMOSI_DIR_OUT(); - SPIMOSI_Set(Low); - - LPC_IOCON->PIO2_11 &= 0xFC; - SPICLK_DIR_OUT(); - SPICLK_Set(Low); -#endif -} -void epd_spi_init (void) -{ - bsp_spiInit(); -//SSP_IOConfig( SSP_PORT ); /* initialize SSP port */ -//SSP_Init( SSP_PORT ); -} - -void epd_SPI_Send (unsigned char Register, unsigned char *Data, unsigned Length) -{ - uint8_t buf[2]; - - epd_cs_low(); - buf[0] = 0x70; - buf[1] = Register; - bsp_writeToDisplay(buf, 2); - epd_cs_high(); - bsp_delayUs(10); - - epd_cs_low(); - buf[0] = 0x72; - bsp_writeToDisplay(buf, 1); - bsp_writeToDisplay(Data, Length); - epd_cs_high(); - bsp_delayUs(10); -} - - - -void epd_SPI_Send_Byte (uint8_t Register, uint8_t Data) -{ - uint8_t buf[2]; - - epd_cs_low(); - buf[0] = 0x70; - buf[1] = Register; - bsp_writeToDisplay(buf, 2); - epd_cs_high(); - bsp_delayUs(10); - - epd_cs_low(); - buf[0] = 0x72; - buf[1] = Data; - bsp_writeToDisplay(buf, 2); - epd_cs_high(); - bsp_delayUs(10); -} - -void epd_InitDisplayHardware(void) -{ - bsp_InitDisplayHardware(); -} - -//************************************************************************ -void TestPinLow(void) -{ -// TESTPin_Set(0); -} -void TestPinHigh(void) -{ -// TESTPin_Set(1); -} -void TestPinTrigger(void) -{ -// if(TESTPin_Get())TestPinLow(); -// else TestPinHigh(); -} -void TestPin2Low(void) -{ -// TESTPin2_Set(0); -} -void TestPin2High(void) -{ -// TESTPin2_Set(1); -} -void TestPin2Trigger(void) -{ -// if(TESTPin2_Get())TestPin2Low(); -// else TestPin2High(); -} diff -r 488ce300977e -r 06697662b4d6 Display_Hardware_Driver.h --- a/Display_Hardware_Driver.h Sun May 19 22:06:40 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,95 +0,0 @@ -// Copyright 2013 Pervasive Displays, Inc. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at: -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either -// express or implied. See the License for the specific language -// governing permissions and limitations under the License. - -#ifndef __DISPLAY_HARDWARE_DRIVER_H_ -#define __DISPLAY_HARDWARE_DRIVER_H_ - -/****************************************************************************** - * Includes - *****************************************************************************/ - -#include "bsp.h" - - -/****************************************************************************** - * Defines and typedefs - *****************************************************************************/ - -//Pin 12 on Serial Expansion Connector -// #define RST_DIR_OUT SEC14_PIN12_SET_OUTP -// #define RST_SET_HIGH SEC14_PIN12_SET_HIGH -// #define RST_SET_LOW SEC14_PIN12_SET_LOW - -//Pin 14 on Serial Expansion Connector -// #define DISCHARGE_DIR_OUT SEC14_PIN14_SET_OUTP -// #define DISCHARGE_SET_HIGH SEC14_PIN14_SET_HIGH -// #define DISCHARGE_SET_LOW SEC14_PIN14_SET_LOW - -//Pin 6 on Serial Expansion Connector -// #define CS_DIR_OUT SEC14_PIN6_SET_OUTP -// #define CS_SET_HIGH SEC14_PIN6_SET_HIGH -// #define CS_SET_LOW SEC14_PIN6_SET_LOW - -//Pin 13 on Serial Expansion Connector -// #define PANELON_DIR_OUT SEC14_PIN13_SET_OUTP -// #define PANELON_SET_HIGH SEC14_PIN13_SET_HIGH -// #define PANELON_SET_LOW SEC14_PIN13_SET_LOW - -//Pin 7 on Serial Expansion Connector -// #define DRIVERBUSY_DIR_IN SEC14_PIN7_SET_INP -// #define DRIVERBUSY_GET SEC14_PIN7_INP - -//Not implemented -// #define BORDER_DIR_OUT -// #define BORDER_SET_HIGH -// #define BORDER_SET_LOW - -//Pin 11 on Serial Expansion Connector -// #define PWM_DIR_OUT SEC14_PIN11_SET_OUTP -// #define PWM_SET_HIGH SEC14_PIN11_SET_HIGH -// #define PWM_SET_LOW SEC14_PIN11_SET_LOW - - -/****************************************************************************** - * Prototypes - *****************************************************************************/ -void epd_cs_high(void); -void epd_cs_low(void); -void epd_rst_high(void); -void epd_rst_low(void); - -void epd_pwm_active(uint16_t delayInMs); - -void epd_TestPinLow(void); -void epd_TestPinHigh(void); -void epd_TestPinTrigger(void); - -void epd_TestPin2Low(void); -void epd_TestPin2High(void); -void epd_TestPin2Trigger(void); - -void epd_delay_ms(uint32_t Time); -int16_t epd_get_temperature(void); -uint32_t epd_GetCurrentTimeTick(void); - -/***************************************************************************/ -void epd_spi_detach(void); -void epd_spi_init (void); -void epd_SPI_Send (unsigned char Register, unsigned char *Data, unsigned Length); -void epd_SPI_Send_Byte (uint8_t Register, uint8_t Data); -void epd_InitDisplayHardware (void); - -/****************************************************************************/ - -#endif //__DISPLAY_HARDWARE_DRIVER_H_ diff -r 488ce300977e -r 06697662b4d6 EPD.c --- a/EPD.c Sun May 19 22:06:40 2013 +0000 +++ b/EPD.c Tue May 21 15:08:07 2013 +0000 @@ -14,25 +14,14 @@ #include "EPD.h" +#include "bsp.h" +#include -typedef enum { - LOW=0, - HIGH=1 -} EPD_pinstate; - -static void EPD_line(uint16_t line, const uint8_t *data, uint8_t fixed_value, uint8_t read_progmem, EPD_stage stage); +static void EPD_line(uint16_t line, const uint8_t *data, uint8_t fixed_value, EPD_stage stage); static void SPI_send(const uint8_t *buffer, uint16_t length); static void SPI_put(uint8_t c); static void SPI_put_wait(uint8_t c); -static void EPD_Pin_init(); -static void EPD_Pin_EPD_CS(EPD_pinstate pin); -static void EPD_Pin_RESET(EPD_pinstate pin); -static void EPD_Pin_PANEL_ON(EPD_pinstate pin); -static void EPD_Pin_DISCHARGE(EPD_pinstate pin); -static void EPD_Pin_BORDER(EPD_pinstate pin); -static EPD_pinstate epd_get_busy(void); - static void epd_pwm_active(uint16_t delayInMs); @@ -80,28 +69,18 @@ static void EPD_frame_fixed(uint8_t fixed_value, EPD_stage stage) { uint8_t line; for (line = 0; line < epd.lines_per_display ; ++line) { - EPD_line(line, 0, fixed_value, FALSE, stage); + EPD_line(line, 0, fixed_value, stage); } } -static void EPD_frame_data(PROGMEM const uint8_t *image, EPD_stage stage){ +static void EPD_frame_data(const uint8_t *image, EPD_stage stage){ uint8_t line; for (line = 0; line < epd.lines_per_display ; ++line) { - EPD_line(line, &image[line * epd.bytes_per_line], 0, TRUE, stage); + EPD_line(line, &image[line * epd.bytes_per_line], 0, stage); } } -#if defined(EPD_ENABLE_EXTRA_SRAM) -static void EPD_frame_sram(const uint8_t *image, EPD_stage stage){ - uint8_t line; - for (line = 0; line < epd.lines_per_display ; ++line) { - EPD_line(line, &image[line * epd.bytes_per_line], 0, FALSE, stage); - } -} -#endif - - static void EPD_frame_fixed_repeat(uint8_t fixed_value, EPD_stage stage) { int32_t stage_time = epd.factored_stage_time; do { @@ -117,7 +96,7 @@ } -static void EPD_frame_data_repeat(PROGMEM const uint8_t *image, EPD_stage stage) { +static void EPD_frame_data_repeat(const uint8_t *image, EPD_stage stage) { int32_t stage_time = epd.factored_stage_time; do { uint32_t t_start = bsp_getMsTicks(); @@ -131,51 +110,7 @@ } while (stage_time > 0); } -#include -#if defined(EPD_ENABLE_EXTRA_SRAM) -static void EPD_frame_sram_repeat(const uint8_t *image, EPD_stage stage) { - int32_t stage_time = epd.factored_stage_time; - do { - uint32_t t_start = bsp_getMsTicks(); - EPD_frame_sram(image, stage); - uint32_t t_end = bsp_getMsTicks(); - if (t_end > t_start) { - stage_time -= t_end - t_start; - } else { - stage_time -= t_start - t_end + 1 + 0xffffffffU; - } - } while (stage_time > 0); -} -#endif - -#if 0 -typedef void EPD_reader(void *buffer, uint32_t address, uint16_t length); - -static void EPD_frame_cb(uint32_t address, EPD_reader *reader, EPD_stage stage) { - static uint8_t buffer[264 / 8]; - uint8_t line; - for (line = 0; line < epd.lines_per_display; ++line) { - reader(buffer, address + line * epd.bytes_per_line, epd.bytes_per_line); - EPD_line(line, buffer, 0, FALSE, stage); - } -} - -static void EPD_frame_cb_repeat(uint32_t address, EPD_reader *reader, EPD_stage stage) { - int32_t stage_time = epd.factored_stage_time; - do { - uint32_t t_start = bsp_getMsTicks(); - EPD_frame_cb(address, reader, stage); - uint32_t t_end = bsp_getMsTicks(); - if (t_end > t_start) { - stage_time -= t_end - t_start; - } else { - stage_time -= t_start - t_end + 1 + 0xffffffffU; - } - } while (stage_time > 0); -} -#endif - -static void EPD_line(uint16_t line, const uint8_t *data, uint8_t fixed_value, uint8_t read_progmem, EPD_stage stage) { +static void EPD_line(uint16_t line, const uint8_t *data, uint8_t fixed_value, EPD_stage stage) { // charge pump voltage levels bsp_delayUs(10); SPI_send(CU8(0x70, 0x04), 2); @@ -473,7 +408,7 @@ void EPD_end(void) { EPD_frame_fixed(0x55, EPD_normal); // dummy frame - EPD_line(0x7fffu, 0, 0x55, FALSE, EPD_normal); // dummy_line + EPD_line(0x7fffu, 0, 0x55, EPD_normal); // dummy_line bsp_delayMs(25); @@ -576,32 +511,22 @@ EPD_frame_fixed_repeat(0xaa, EPD_normal); } -// assuming a clear (white) screen output an image (PROGMEM data) -void EPD_image(PROGMEM const uint8_t *image) { +// assuming a clear (white) screen output an image +void EPD_image(const uint8_t *image) { EPD_frame_fixed_repeat(0xaa, EPD_compensate); EPD_frame_fixed_repeat(0xaa, EPD_white); EPD_frame_data_repeat(image, EPD_inverse); EPD_frame_data_repeat(image, EPD_normal); } -// change from old image to new image (PROGMEM data) -void EPD_image_progmem(PROGMEM const uint8_t *old_image, PROGMEM const uint8_t *new_image) { +// change from old image to new image +void EPD_image_change(const uint8_t *old_image, const uint8_t *new_image) { EPD_frame_data_repeat(old_image, EPD_compensate); EPD_frame_data_repeat(old_image, EPD_white); EPD_frame_data_repeat(new_image, EPD_inverse); EPD_frame_data_repeat(new_image, EPD_normal); } -#if defined(EPD_ENABLE_EXTRA_SRAM) -// change from old image to new image (SRAM version) -void EPD_image_sram(const uint8_t *old_image, const uint8_t *new_image) { - EPD_frame_sram_repeat(old_image, EPD_compensate); - EPD_frame_sram_repeat(old_image, EPD_white); - EPD_frame_sram_repeat(new_image, EPD_inverse); - EPD_frame_sram_repeat(new_image, EPD_normal); -} -#endif - static void SPI_put(uint8_t c) { uint8_t placeholder = c; @@ -629,86 +554,20 @@ EPD_Pin_EPD_CS(HIGH); } -static void EPD_Pin_init() -{ - bsp_pinDir(6, 1); // CS - bsp_pinDir(7, 0); // Driver Busy - bsp_pinDir(8, 1); // Border - bsp_pinDir(11, 1); // Pwm - bsp_pinDir(12, 1); // Reset - bsp_pinDir(13, 1); // Panel On - bsp_pinDir(14, 1); // Discharge -} - -static void EPD_Pin_EPD_CS(EPD_pinstate pin) -{ - if (HIGH == pin) { - bsp_pinSet(6); - } - else { - bsp_pinClr(6); - } -} - -static void EPD_Pin_RESET(EPD_pinstate pin) -{ - if (HIGH == pin) { - bsp_pinSet(12); - } - else { - bsp_pinClr(12); - } -} - -static void EPD_Pin_PANEL_ON(EPD_pinstate pin) -{ - if (HIGH == pin) { - bsp_pinSet(13); - } - else { - bsp_pinClr(13); - } -} - -static void EPD_Pin_DISCHARGE(EPD_pinstate pin) -{ - if (HIGH == pin) { - bsp_pinSet(14); - } - else { - bsp_pinClr(14); - } -} - -static void EPD_Pin_BORDER(EPD_pinstate pin) -{ - if (HIGH == pin) { - bsp_pinSet(8); - } - else { - bsp_pinClr(8); - } -} - -static EPD_pinstate epd_get_busy(void) -{ - if (bsp_pinState(7)) - return HIGH; - else - return LOW; -} - static void epd_pwm_active(uint16_t delayInMs) { uint16_t numOfIterations; + uint32_t now = bsp_getMsTicks(); numOfIterations = delayInMs * 100; for(; numOfIterations > 0; numOfIterations--) { - bsp_pinSet(11); + EPD_Pin_PWM(HIGH); bsp_delayUs(5); //100kHz - bsp_pinClr(11); + EPD_Pin_PWM(LOW); bsp_delayUs(5); } + + printf("PWM done for %dms.\n", bsp_getMsTicks() - now); } diff -r 488ce300977e -r 06697662b4d6 EPD.h --- a/EPD.h Sun May 19 22:06:40 2013 +0000 +++ b/EPD.h Tue May 21 15:08:07 2013 +0000 @@ -16,18 +16,17 @@ #ifndef __EPD_H__ #define __EPD_H__ -#include "bsp.h" - -//TODO -#define PROGMEM /*const*/ +#include -// if more SRAM available (8 kBytes) -#define EPD_ENABLE_EXTRA_SRAM 1 +typedef enum { + FALSE=0, + TRUE=1 +} bool; -//typedef enum { -// LOW=0, -// HIGH=1 -//} EPD_pinstate; +typedef enum { + LOW=0, + HIGH=1 +} EPD_pinstate; typedef enum { EPD_1_44, // 128 x 96 @@ -51,9 +50,9 @@ uint16_t dots_per_line; uint16_t bytes_per_line; uint16_t bytes_per_scan; - PROGMEM const uint8_t *gate_source; + const uint8_t *gate_source; uint16_t gate_source_length; - PROGMEM const uint8_t *channel_select; + const uint8_t *channel_select; uint16_t channel_select_length; uint8_t filler; } COG_Parameters_t; @@ -69,16 +68,11 @@ // clear display (anything -> white) void EPD_clear(void); -// assuming a clear (white) screen output an image (PROGMEM data) -void EPD_image(PROGMEM const uint8_t *image); +// assuming a clear (white) screen output an image +void EPD_image(const uint8_t *image); -// change from old image to new image (PROGMEM data) -void EPD_image_progmem(PROGMEM const uint8_t *old_image, PROGMEM const uint8_t *new_image); - -#if defined(EPD_ENABLE_EXTRA_SRAM) -// change from old image to new image (SRAM version) -void EPD_image_sram(const uint8_t *old_image, const uint8_t *new_image); -#endif +// change from old image to new image +void EPD_image_change(const uint8_t *old_image, const uint8_t *new_image); #endif //__EPD_H__ diff -r 488ce300977e -r 06697662b4d6 Makefile --- a/Makefile Sun May 19 22:06:40 2013 +0000 +++ b/Makefile Tue May 21 15:08:07 2013 +0000 @@ -14,11 +14,11 @@ ARCH = mipsel-openwrt-linux CC = $(TOOLBIN)/$(ARCH)-gcc -CFLAGS = -g -Wall -fPIC -march=mips32 -I$(LIBUBB)/include -DNANONOTE # -DDISPLAY_IN_USE=EPD_TYPE_270 # -DDEBUG=1 +CFLAGS = -g -Wall -fPIC -march=mips32 -I$(LIBUBB)/include LDFLAGS = -lubb -L$(LIBUBB) #-static #-L$(SYSLIBS) TARGET = test -SRC = test.c bsp.c Display_COG_Process.c Display_Controller.c Display_Hardware_Driver.c logo.c +SRC = test.c bsp.c EPD.c logo.c OBJ = $(SRC:.c=.o) .PHONY: all clean distclean diff -r 488ce300977e -r 06697662b4d6 bsp.c --- a/bsp.c Sun May 19 22:06:40 2013 +0000 +++ b/bsp.c Tue May 21 15:08:07 2013 +0000 @@ -35,9 +35,8 @@ #include #include #include "bsp.h" -#include "Display_Hardware_Driver.h" -void bsp_init() +void EPD_Pin_init() { OUT(UBB_DAT2); OUT(UBB_DAT3); @@ -45,230 +44,77 @@ OUT(UBB_CLK); OUT(UBB_DAT0); OUT(UBB_DAT1); -} -/* NanoNote-specific functions. */ - -void shift_select() -{ - CLR(MUX_S0); -} - -void shift_update() -{ - SET(SHIFT_RCK); - CLR(SHIFT_RCK); -} - -void shift_init() -{ - /* Initiate a clear operation. */ - - CLR(SHIFT_SCLR); - - /* Set clocks to known state. */ - - CLR(SHIFT_SCK); - CLR(SHIFT_RCK); - - /* Propagate the clear operation. */ - - shift_update(); - - /* Finalise the initialisation. */ - - SET(SHIFT_SCLR); + CLR(UBB_DAT2); + CLR(UBB_DAT3); + CLR(UBB_CMD); + CLR(UBB_CLK); + CLR(UBB_DAT0); + CLR(UBB_DAT1); } -void shift_reinit() +void EPD_Pin_EPD_CS(EPD_pinstate pin) { - /* Set clocks to known state. */ - - CLR(SHIFT_SCK); - CLR(SHIFT_RCK); - - /* Avoid clear operation. */ - - SET(SHIFT_SCLR); -} - -void shift_in(uint8_t v) -{ - if (v) - SET(SHIFT_SI); + if (pin == HIGH) + SET(EPD_SSEL); else - CLR(SHIFT_SI); - - SET(SHIFT_SCK); - CLR(SHIFT_SCK); + CLR(EPD_SSEL); } -void epd_select() -{ - SET(MUX_S0); -} - -/* Callback functions. */ - -void bsp_InitDisplayHardware() +void EPD_Pin_RESET(EPD_pinstate pin) { - /* This should do the following: - - PANEL = 0 - CS/SSEL = 0 - PWM = 0 - RESET = 0 - DIS = 0 - - (Could shift 0, 0 -> PANEL, DIS - or 0, 0, 0 -> PANEL, BORDER, DIS.) - */ - - shift_select(); - shift_init(); /* PANEL = DIS = 0 */ - - epd_select(); - CLR(EPD_SSEL); - CLR(EPD_PWM); - CLR(EPD_RESET); - CLR(EPD_MOSI); - - printf("Hardware initialised.\n"); + if (pin == HIGH) + SET(EPD_RESET); + else + CLR(EPD_RESET); + printf("RESET = %d\n", pin); } -void bsp_PowerOn() +void EPD_Pin_PANEL_ON(EPD_pinstate pin) { - /* This should do the following: - - RESET = 0 - DIS = 0 - CS/SSEL = 0 - */ - - epd_select(); - epd_rst_low(); - - shift_select(); - shift_init(); /* PANEL = DIS = 0 */ - - printf("RESET = PANEL = DIS = 0\n"); - - /* Then, the following: - - PWM = 1/0 (5ms) - PANEL = 1 - PWM = 1/0 (10ms) - BORDER = 1? - RESET = 1 - PWM = 1/0 (5ms) - RESET = 0 - PWM = 1/0 (5ms) - RESET = 1 - PWM = 1/0 (5ms) + if (pin == HIGH) + ubb_power(1); + else + ubb_power(0); + printf("PANEL = %d\n", pin); +} - (Could shift 1 -> PANEL => PANEL=1, DIS=0 - or 1, 1 -> PANEL, BORDER => PANEL=1, BORDER=1, DIS=0) - */ - - epd_select(); - epd_spi_init(); - printf("PWM at 5ms starting: %u\n", bsp_getMsTicks()); - epd_pwm_active(5); - printf("PWM at 5ms done: %u\n", bsp_getMsTicks()); - - shift_select(); - shift_init(); /* PANEL = DIS = 0 (still) */ - shift_in(1); /* PANEL = 1 */ - shift_update(); - printf("PANEL = 1\n"); - - epd_select(); - printf("PWM at 10ms starting: %u\n", bsp_getMsTicks()); - epd_pwm_active(10); - printf("PWM at 10ms done: %u\n", bsp_getMsTicks()); - epd_cs_high(); - epd_rst_high(); - printf("PWM at 5ms starting: %u\n", bsp_getMsTicks()); - epd_pwm_active(5); - printf("PWM at 5ms done: %u\n", bsp_getMsTicks()); - epd_rst_low(); - printf("PWM at 5ms starting: %u\n", bsp_getMsTicks()); - epd_pwm_active(5); - printf("PWM at 5ms done: %u\n", bsp_getMsTicks()); - epd_rst_high(); - printf("PWM at 5ms starting: %u\n", bsp_getMsTicks()); - epd_pwm_active(5); - printf("PWM at 5ms done: %u\n", bsp_getMsTicks()); - - printf("Hardware powered.\n"); +void EPD_Pin_DISCHARGE(EPD_pinstate pin) +{ + if (pin == HIGH) + SET(EPD_DIS); + else + CLR(EPD_DIS); + printf("DIS = %d\n", pin); } -void bsp_pwm_active(uint16_t delayInMs) +void EPD_Pin_BORDER(EPD_pinstate pin) { - uint16_t numOfIterations; +} - numOfIterations = delayInMs * 100; - for (; numOfIterations > 0; numOfIterations--) - { - // PWM_SET_HIGH; +void EPD_Pin_PWM(EPD_pinstate pin) +{ + if (pin == HIGH) SET(EPD_PWM); - bsp_delayUs(5); //100kHz (96kHz ideal) - // PWM_SET_LOW; + else CLR(EPD_PWM); - bsp_delayUs(5); - } } -void bsp_Shutdown() +EPD_pinstate epd_get_busy() { - /* This should complete the power off operation as follows: - - RESET = 0 - CS/SSEL = 0 - PANEL = 0 - BORDER = 0? - DIS = 1 - DIS = 0 (after 150ms) - - (Could shift 0 -> PANEL => PANEL=0, DIS=1 - or 0, 0 -> PANEL, BORDER => PANEL=0, BORDER=0, DIS=1) - */ - - epd_select(); - epd_rst_low(); - epd_cs_low(); - epd_spi_detach(); - - shift_reinit(); - shift_select(); - shift_in(0); /* PANEL = 0; DIS = 1 */ - shift_update(); - printf("Wait for 150ms, starting: %u\n", bsp_getMsTicks()); - epd_delay_ms(150); - printf("Wait for 150ms, done: %u\n", bsp_getMsTicks()); - shift_in(0); /* PANEL = 0; DIS = 0 */ - shift_update(); - - printf("Hardware shut down.\n"); + bsp_delayUs(1); + return LOW; } -void bsp_spiInit() +void bsp_spiWrite(uint8_t *buffer, uint16_t length) { - CLR(EPD_SCK); -} + uint8_t mask, *ptr, *limit = buffer + length; -/** - * Send the given value via MOSI. - */ -void bsp_writeToDisplay(uint8_t *data, uint16_t len) -{ - uint8_t mask, *ptr, *limit = data + len; - - for (ptr = data; ptr < limit; ptr++) + for (ptr = buffer; ptr < limit; ptr++) { for (mask = 0x80; mask; mask >>= 1) { - if (*ptr & mask) + if (*(ptr) & mask) { SET(EPD_MOSI); } @@ -290,15 +136,12 @@ void bsp_delayUs(uint32_t us) { - #ifndef NANONOTE - struct timespec tv; - tv.tv_sec = 0; - tv.tv_nsec = us * 100; - nanosleep(&tv, NULL); - #else - uint64_t i = us * 16; - while (i-- > 0); - #endif + /* uint32_t now = bsp_getUsTicks(); */ + + /* while (bsp_getUsTicks() - now < us); */ + + uint32_t count = us * 24; + while (count--); } uint32_t bsp_getMsTicks() @@ -308,7 +151,12 @@ return tv.tv_sec * 1000 + tv.tv_usec / 1000; } -/* Unsupported. */ +uint32_t bsp_getUsTicks() +{ + struct timeval tv; + gettimeofday(&tv, NULL); + return tv.tv_sec * 1000000 + tv.tv_usec; +} int16_t bsp_getTemp() { diff -r 488ce300977e -r 06697662b4d6 bsp.h --- a/bsp.h Sun May 19 22:06:40 2013 +0000 +++ b/bsp.h Tue May 21 15:08:07 2013 +0000 @@ -2,111 +2,52 @@ #define __BSP_H__ #include +#include "EPD.h" -/* Pin assignments (74HC4052): - * - * Sniffer UBB 74HC4052 #1 74HC4052 #2 10K Resistor M74HC595B1R EM027AS012 - * ------- ---- ----------- ----------- ------------ ----------- ---------- - * DAT2 DAT2 13 (1Z) - * CD DAT3 3 (2Z) - * CMD CMD 10 (S0) 10 (S0) IN OUT 10 (SCLR#) - * VCC VDD 16 (VCC) 16 (VCC) 16 (VCC) 2 (3V3) - * CLK CLK 3 (SCK) - * GND GND 8 (GND) 8 (GND) 8 (GND) 1 (GND) - * DAT0 DAT0 13 (1Z) - * DAT1 DAT1 3 (2Z) - * - * Multiplexer pin selection: - * - * {Z}Y{S1/S0} - * - * 1Z with S1=0, S0=0 => 1Y0 (output 1, channel 0) - * 2Z with S1=0, S0=0 => 2Y0 (output 2, channel 0) - * - * 1Z with S1=0, S0=1 => 1Y1 (output 1, channel 1) - * 2Z with S1=0, S0=1 => 2Y1 (output 2, channel 1) - * - * Connections to the shift register (channel 0): +/* Pin assignments: * - * Sniffer UBB 74HC4052 #1 M74HC595B1R - * ------- --- ----------- ----------- - * DAT2 DAT2 12 (1Y0) 12 (RCK) - * CD DAT3 1 (2Y0) 14 (SI) - * - * 74HC4052 #2 - * ----------- - * DAT0 DAT0 12 (1Y0) 10 (SCLR#) - * DAT1 DAT1 1 (2Y0) 11 (SCK) - * - * Connections to the display board (channel 1): - * - * Sniffer UBB 74HC4052 #1 EM027AS012 - * ------- --- ----------- ---------- - * DAT2 DAT2 14 (1Y1) 4 (MOSI) - * CD DAT3 5 (2Y1) 6 (SSEL) - * - * 74HC4052 #2 - * ----------- - * DAT0 DAT0 14 (1Y1) 11 (PWM) - * DAT1 DAT1 5 (2Y1) 12 (RESET) - * - * Connections from the shift register (providing persistent outputs for - * channel 0): - * - * M74HC595B1R EM027AS012 - * ----------- ---------- - * 15 (QA) 13 (PANEL) - * 1 (QB) 14 (DIS) + * Sniffer UBB EM027AS012 + * ------- ---- ----------- + * DAT2 DAT2 4 (MOSI) + * CD DAT3 6 (SSEL) + * CMD CMD 11 (PWM) + * VCC VDD 13 (PANEL) + * CLK CLK 3 (SCK) + * GND GND + * DAT0 DAT0 12 (RESET) + * DAT1 DAT1 14 (DIS) * * General connections: * - * Sniffer UBB 74HC4052 M74HC595B1R - * ------- ---- -------- ----------- - * GND GND 6 (E#) 13 (G#) - * 7 (VEE) - * 9 (S1) + * EM027AS012 + * ---------- + * 1 (GND) + * 2 (3V3) */ -/* CMD/S0 = 0 */ - -#define SHIFT_SCLR UBB_DAT0 -#define SHIFT_SCK UBB_DAT1 -#define SHIFT_RCK UBB_DAT2 -#define SHIFT_SI UBB_DAT3 - -/* CMD/S1 = 1 */ - -#define EPD_PWM UBB_DAT0 -#define EPD_RESET UBB_DAT1 -#define EPD_MOSI UBB_DAT2 -#define EPD_SSEL UBB_DAT3 - -/* Channel-insensitive. */ - -#define MUX_S0 UBB_CMD -#define EPD_SCK UBB_CLK - -/* NanoNote-specific functions. */ - -void shift_select(); -void shift_update(); -void shift_init(); -void shift_reinit(); -void shift_in(uint8_t v); -void epd_select(); +#define EPD_MOSI UBB_DAT2 +#define EPD_SSEL UBB_DAT3 +#define EPD_PWM UBB_CMD +#define EPD_SCK UBB_CLK +#define EPD_RESET UBB_DAT0 +#define EPD_DIS UBB_DAT1 /* Board-specific interface functions. */ -void bsp_init(); -void bsp_InitDisplayHardware(); -void bsp_PowerOn(); -void bsp_pwm_active(uint16_t delayInMs); -void bsp_Shutdown(); -void bsp_spiInit(); -void bsp_writeToDisplay(uint8_t *data, uint16_t len); +void EPD_Pin_init(); +void EPD_Pin_EPD_CS(EPD_pinstate pin); +void EPD_Pin_RESET(EPD_pinstate pin); +void EPD_Pin_PANEL_ON(EPD_pinstate pin); +void EPD_Pin_DISCHARGE(EPD_pinstate pin); +void EPD_Pin_BORDER(EPD_pinstate pin); +void EPD_Pin_PWM(EPD_pinstate pin); +EPD_pinstate epd_get_busy(); + +void bsp_spiWrite(uint8_t *buffer, uint16_t length); void bsp_delayMs(uint32_t ms); void bsp_delayUs(uint32_t us); uint32_t bsp_getMsTicks(); +uint32_t bsp_getUsTicks(); int16_t bsp_getTemp(); #endif /* __BSP_H__ */ diff -r 488ce300977e -r 06697662b4d6 test.c --- a/test.c Sun May 19 22:06:40 2013 +0000 +++ b/test.c Tue May 21 15:08:07 2013 +0000 @@ -15,9 +15,12 @@ #include #include #include "logo.h" -#include "Display_Controller.h" +#include "EPD.h" #include "bsp.h" +static uint8_t old_image[264 * 176 / 8], + new_image[264 * 176 / 8]; + /** * Handle termination of the process. */ @@ -32,8 +35,6 @@ int main(int argc, char *argv[]) { - uint8_t *current_image, blank_image[176][33]; - signal(SIGINT, &shutdown); if (ubb_open(0) < 0) { @@ -41,28 +42,32 @@ return 1; } - ubb_power(1); - printf("Power on.\n"); - /* Need to initialise the board. */ - bsp_init(); + EPD_init(EPD_2_7); printf("Initialised.\n"); /* Initialise an array containing the current image. */ - memset((uint8_t*) &blank_image[0][0], 0xff, 176*33); - current_image = (uint8_t*) &blank_image[0][0]; - printf("Set blank image.\n"); + memset(old_image, 0, sizeof(old_image)); + /* memset(new_image, 0, sizeof(new_image)); */ + memcpy(new_image, (uint8_t *) image_data[0], sizeof(new_image)); - /* Call epd_DisplayImg with the new image and current image. */ + printf("Clear image.\n"); - epd_DisplayImg(DISPLAY_IN_USE, (uint8_t *) &image_data[0][0][0], current_image); - printf("Updated image.\n"); + EPD_begin(); + EPD_setFactor(bsp_getTemp()); + EPD_clear(); + EPD_end(); + + printf("Set image.\n"); - /* Set the current image to the new image. */ + EPD_begin(); + EPD_setFactor(bsp_getTemp()); + EPD_image_change(old_image, new_image); + EPD_end(); - current_image = &image_data[0][0][0]; + /* memcpy(old_image, new_image, sizeof(old_image)); */ printf("Closing...\n"); ubb_close(0);