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 20 21 /****************************************************************************** 22 * Public functions 23 *****************************************************************************/ 24 void epd_cs_high(void) 25 { 26 // CS_SET_HIGH; 27 bsp_pinOut(BSP_PIN_6, 1); 28 } 29 30 void epd_cs_low(void) 31 { 32 // CS_SET_LOW; 33 bsp_pinOut(BSP_PIN_6, 0); 34 } 35 36 void epd_rst_high(void) 37 { 38 // RST_SET_HIGH; 39 bsp_pinOut(BSP_PIN_12, 1); 40 } 41 42 void epd_rst_low(void) 43 { 44 // RST_SET_LOW; 45 bsp_pinOut(BSP_PIN_12, 0); 46 } 47 48 void epd_discharge_high(void) 49 { 50 // DISCHARGE_SET_HIGH; 51 bsp_pinOut(BSP_PIN_14, 1); 52 } 53 54 void epd_discharge_low(void) 55 { 56 // DISCHARGE_SET_LOW; 57 bsp_pinOut(BSP_PIN_14, 0); 58 } 59 60 void epd_panelon_off(void) 61 { 62 // PANELON_SET_LOW; 63 bsp_pinOut(BSP_PIN_13, 0); 64 } 65 66 void epd_panelon_on(void) 67 { 68 // PANELON_SET_HIGH; 69 bsp_pinOut(BSP_PIN_13, 1); 70 } 71 72 void epd_border_high(void) 73 { 74 // BORDER_SET_HIGH; 75 } 76 77 void epd_border_low(void) 78 { 79 // BORDER_SET_LOW; 80 } 81 82 void epd_delay_ms(uint32_t Time) 83 { 84 bsp_delayMs(Time); 85 } 86 87 int16_t epd_get_temperature(void) 88 { 89 return bsp_getTemp(); 90 } 91 92 uint32_t epd_GetCurrentTimeTick(void) 93 { 94 return bsp_getMsTicks(); 95 } 96 97 //****************************************************************** 98 //PWM Configuration/Control 99 //****************************************************************** 100 #if 0 101 volatile uint32_t period = 500; //96Khz PWM frequency 102 103 void epd_pwm_disable(void) 104 { 105 disable_timer16(1); 106 LPC_IOCON->PIO1_9 &= 0xFC;//Disable PWM,set general IO 107 PWM_DIR_OUT(); 108 PWM_SET_LOW(); 109 } 110 111 void epd_pwm_active(void) 112 { 113 PWM_SET_HIGH(); 114 /* Initialize the PWM in timer32_1 enabling match0 output */ 115 init_timer16PWM(1, period, MATCH0,0); 116 setMatch_timer16PWM (1, 1, period/8); 117 enable_timer16(1); 118 } 119 #endif 120 void epd_pwm_active(uint16_t delayInMs) 121 { 122 uint16_t numOfIterations; 123 124 numOfIterations = delayInMs * 100; 125 // PWM_DIR_OUT; 126 bsp_pinMode(BSP_PIN_11, BSP_PINMODE_OUTPUT); 127 for(; numOfIterations > 0; numOfIterations--) 128 { 129 // PWM_SET_HIGH; 130 bsp_pinOut(BSP_PIN_11, 1); 131 bsp_delayUs(5); //100kHz (96kHz ideal) 132 // PWM_SET_LOW; 133 bsp_pinOut(BSP_PIN_11, 0); 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 // RST_DIR_OUT; 208 bsp_pinMode(BSP_PIN_12, BSP_PINMODE_OUTPUT); 209 // DISCHARGE_DIR_OUT; 210 bsp_pinMode(BSP_PIN_14, BSP_PINMODE_OUTPUT); 211 // CS_DIR_OUT; 212 bsp_pinMode(BSP_PIN_6, BSP_PINMODE_OUTPUT); 213 // PANELON_DIR_OUT; 214 bsp_pinMode(BSP_PIN_13, BSP_PINMODE_OUTPUT); 215 // DRIVERBUSY_DIR_IN; 216 bsp_pinMode(BSP_PIN_7, BSP_PINMODE_INPUT); 217 // BORDER_DIR_OUT; 218 219 220 epd_panelon_off(); 221 epd_spi_init(); 222 epd_cs_low(); 223 // epd_pwm_low(); 224 epd_pwm_active(0); //set output low 225 epd_rst_low(); 226 epd_discharge_low(); 227 228 // TESTPin_DIR_OUT(); 229 // TESTPin2_DIR_OUT(); 230 } 231 232 //************************************************************************ 233 void TestPinLow(void) 234 { 235 // TESTPin_Set(0); 236 } 237 void TestPinHigh(void) 238 { 239 // TESTPin_Set(1); 240 } 241 void TestPinTrigger(void) 242 { 243 // if(TESTPin_Get())TestPinLow(); 244 // else TestPinHigh(); 245 } 246 void TestPin2Low(void) 247 { 248 // TESTPin2_Set(0); 249 } 250 void TestPin2High(void) 251 { 252 // TESTPin2_Set(1); 253 } 254 void TestPin2Trigger(void) 255 { 256 // if(TESTPin2_Get())TestPin2Low(); 257 // else TestPin2High(); 258 }