1 // Copyright 2013 Pervasive Displays, Inc. 2 // 3 // Licensed under the Apache License, Version 2.0 (the "License"); 4 // you may not use this file except in compliance with the License. 5 // You may obtain a copy of the License at: 6 // 7 // http://www.apache.org/licenses/LICENSE-2.0 8 // 9 // Unless required by applicable law or agreed to in writing, 10 // software distributed under the License is distributed on an 11 // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 12 // express or implied. See the License for the specific language 13 // governing permissions and limitations under the License. 14 15 /****************************************************************************** 16 * Includes 17 *****************************************************************************/ 18 #include "Display_Hardware_Driver.h" 19 #include <ubb/ubb.h> 20 21 22 /****************************************************************************** 23 * Public functions 24 *****************************************************************************/ 25 void epd_cs_high(void) 26 { 27 // CS_SET_HIGH; 28 SET(EPD_SSEL); 29 } 30 31 void epd_cs_low(void) 32 { 33 // CS_SET_LOW; 34 CLR(EPD_SSEL); 35 } 36 37 void epd_rst_high(void) 38 { 39 // RST_SET_HIGH; 40 SET(EPD_RESET); 41 } 42 43 void epd_rst_low(void) 44 { 45 // RST_SET_LOW; 46 CLR(EPD_RESET); 47 } 48 49 void epd_discharge_high(void) 50 { 51 // DISCHARGE_SET_HIGH; 52 SET(EPD_DIS); 53 } 54 55 void epd_discharge_low(void) 56 { 57 // DISCHARGE_SET_LOW; 58 CLR(EPD_DIS); 59 } 60 61 void epd_panelon_off(void) 62 { 63 // PANELON_SET_LOW; 64 ubb_power(1); 65 } 66 67 void epd_panelon_on(void) 68 { 69 // PANELON_SET_HIGH; 70 ubb_power(0); 71 } 72 73 void epd_border_high(void) 74 { 75 // BORDER_SET_HIGH; 76 } 77 78 void epd_border_low(void) 79 { 80 // BORDER_SET_LOW; 81 } 82 83 void epd_delay_ms(uint32_t Time) 84 { 85 bsp_delayMs(Time); 86 } 87 88 int16_t epd_get_temperature(void) 89 { 90 return bsp_getTemp(); 91 } 92 93 uint32_t epd_GetCurrentTimeTick(void) 94 { 95 return bsp_getMsTicks(); 96 } 97 98 //****************************************************************** 99 //PWM Configuration/Control 100 //****************************************************************** 101 #if 0 102 volatile uint32_t period = 500; //96Khz PWM frequency 103 104 void epd_pwm_disable(void) 105 { 106 disable_timer16(1); 107 LPC_IOCON->PIO1_9 &= 0xFC;//Disable PWM,set general IO 108 PWM_DIR_OUT(); 109 PWM_SET_LOW(); 110 } 111 112 void epd_pwm_active(void) 113 { 114 PWM_SET_HIGH(); 115 /* Initialize the PWM in timer32_1 enabling match0 output */ 116 init_timer16PWM(1, period, MATCH0,0); 117 setMatch_timer16PWM (1, 1, period/8); 118 enable_timer16(1); 119 } 120 #endif 121 void epd_pwm_active(uint16_t delayInMs) 122 { 123 uint16_t numOfIterations; 124 125 numOfIterations = delayInMs * 100; 126 // PWM_DIR_OUT; 127 for(; numOfIterations > 0; numOfIterations--) 128 { 129 // PWM_SET_HIGH; 130 SET(EPD_PWM); 131 bsp_delayUs(5); //100kHz (96kHz ideal) 132 // PWM_SET_LOW; 133 CLR(EPD_PWM); 134 bsp_delayUs(5); 135 } 136 } 137 138 139 //****************************************************************** 140 //SPI Configuration 141 //****************************************************************** 142 void epd_spi_detach(void) 143 { 144 #if 0 145 LPC_IOCON->PIO0_8 &= 0xFC;; /* SSP I/O config */ 146 SPIMISO_DIR_OUT(); 147 SPIMISO_Set(Low); 148 149 LPC_IOCON->PIO0_9 &= 0xFC; /* SSP MOSI */ 150 SPIMOSI_DIR_OUT(); 151 SPIMOSI_Set(Low); 152 153 LPC_IOCON->PIO2_11 &= 0xFC; 154 SPICLK_DIR_OUT(); 155 SPICLK_Set(Low); 156 #endif 157 } 158 void epd_spi_init (void) 159 { 160 bsp_spiInit(); 161 //SSP_IOConfig( SSP_PORT ); /* initialize SSP port */ 162 //SSP_Init( SSP_PORT ); 163 } 164 165 void epd_SPI_Send (unsigned char Register, unsigned char *Data, unsigned Length) 166 { 167 uint8_t buf[2]; 168 169 epd_cs_low(); 170 buf[0] = 0x70; 171 buf[1] = Register; 172 bsp_writeToDisplay(buf, 2); 173 epd_cs_high(); 174 bsp_delayUs(10); 175 176 epd_cs_low(); 177 buf[0] = 0x72; 178 bsp_writeToDisplay(buf, 1); 179 bsp_writeToDisplay(Data, Length); 180 epd_cs_high(); 181 bsp_delayUs(10); 182 } 183 184 185 186 void epd_SPI_Send_Byte (uint8_t Register, uint8_t Data) 187 { 188 uint8_t buf[2]; 189 190 epd_cs_low(); 191 buf[0] = 0x70; 192 buf[1] = Register; 193 bsp_writeToDisplay(buf, 2); 194 epd_cs_high(); 195 bsp_delayUs(10); 196 197 epd_cs_low(); 198 buf[0] = 0x72; 199 buf[1] = Data; 200 bsp_writeToDisplay(buf, 2); 201 epd_cs_high(); 202 bsp_delayUs(10); 203 } 204 205 void epd_InitDisplayHardware(void) 206 { 207 epd_panelon_off(); 208 epd_spi_init(); 209 epd_cs_low(); 210 // epd_pwm_low(); 211 epd_pwm_active(0); //set output low 212 epd_rst_low(); 213 epd_discharge_low(); 214 } 215 216 //************************************************************************ 217 void TestPinLow(void) 218 { 219 // TESTPin_Set(0); 220 } 221 void TestPinHigh(void) 222 { 223 // TESTPin_Set(1); 224 } 225 void TestPinTrigger(void) 226 { 227 // if(TESTPin_Get())TestPinLow(); 228 // else TestPinHigh(); 229 } 230 void TestPin2Low(void) 231 { 232 // TESTPin2_Set(0); 233 } 234 void TestPin2High(void) 235 { 236 // TESTPin2_Set(1); 237 } 238 void TestPin2Trigger(void) 239 { 240 // if(TESTPin2_Get())TestPin2Low(); 241 // else TestPin2High(); 242 }