1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/Display_Hardware_Driver.c Sun Apr 07 18:35:52 2013 +0000
1.3 @@ -0,0 +1,258 @@
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 "Display_Hardware_Driver.h"
1.22 +
1.23 +
1.24 +/******************************************************************************
1.25 + * Public functions
1.26 + *****************************************************************************/
1.27 +void epd_cs_high(void)
1.28 +{
1.29 + // CS_SET_HIGH;
1.30 + bsp_pinOut(BSP_PIN_6, 1);
1.31 +}
1.32 +
1.33 +void epd_cs_low(void)
1.34 +{
1.35 + // CS_SET_LOW;
1.36 + bsp_pinOut(BSP_PIN_6, 0);
1.37 +}
1.38 +
1.39 +void epd_rst_high(void)
1.40 +{
1.41 + // RST_SET_HIGH;
1.42 + bsp_pinOut(BSP_PIN_12, 1);
1.43 +}
1.44 +
1.45 +void epd_rst_low(void)
1.46 +{
1.47 + // RST_SET_LOW;
1.48 + bsp_pinOut(BSP_PIN_12, 0);
1.49 +}
1.50 +
1.51 +void epd_discharge_high(void)
1.52 +{
1.53 + // DISCHARGE_SET_HIGH;
1.54 + bsp_pinOut(BSP_PIN_14, 1);
1.55 +}
1.56 +
1.57 +void epd_discharge_low(void)
1.58 +{
1.59 + // DISCHARGE_SET_LOW;
1.60 + bsp_pinOut(BSP_PIN_14, 0);
1.61 +}
1.62 +
1.63 +void epd_panelon_off(void)
1.64 +{
1.65 + // PANELON_SET_LOW;
1.66 + bsp_pinOut(BSP_PIN_13, 0);
1.67 +}
1.68 +
1.69 +void epd_panelon_on(void)
1.70 +{
1.71 + // PANELON_SET_HIGH;
1.72 + bsp_pinOut(BSP_PIN_13, 1);
1.73 +}
1.74 +
1.75 +void epd_border_high(void)
1.76 +{
1.77 + // BORDER_SET_HIGH;
1.78 +}
1.79 +
1.80 +void epd_border_low(void)
1.81 +{
1.82 + // BORDER_SET_LOW;
1.83 +}
1.84 +
1.85 +void epd_delay_ms(uint32_t Time)
1.86 +{
1.87 + bsp_delayMs(Time);
1.88 +}
1.89 +
1.90 +int16_t epd_get_temperature(void)
1.91 +{
1.92 + return bsp_getTemp();
1.93 +}
1.94 +
1.95 +uint32_t epd_GetCurrentTimeTick(void)
1.96 +{
1.97 + return bsp_getMsTicks();
1.98 +}
1.99 +
1.100 +//******************************************************************
1.101 +//PWM Configuration/Control
1.102 +//******************************************************************
1.103 +#if 0
1.104 +volatile uint32_t period = 500; //96Khz PWM frequency
1.105 +
1.106 +void epd_pwm_disable(void)
1.107 +{
1.108 + disable_timer16(1);
1.109 + LPC_IOCON->PIO1_9 &= 0xFC;//Disable PWM,set general IO
1.110 + PWM_DIR_OUT();
1.111 + PWM_SET_LOW();
1.112 +}
1.113 +
1.114 +void epd_pwm_active(void)
1.115 +{
1.116 + PWM_SET_HIGH();
1.117 + /* Initialize the PWM in timer32_1 enabling match0 output */
1.118 + init_timer16PWM(1, period, MATCH0,0);
1.119 + setMatch_timer16PWM (1, 1, period/8);
1.120 + enable_timer16(1);
1.121 +}
1.122 +#endif
1.123 +void epd_pwm_active(uint16_t delayInMs)
1.124 +{
1.125 + uint16_t numOfIterations;
1.126 +
1.127 + numOfIterations = delayInMs * 100;
1.128 + // PWM_DIR_OUT;
1.129 + bsp_pinMode(BSP_PIN_11, BSP_PINMODE_OUTPUT);
1.130 + for(; numOfIterations > 0; numOfIterations--)
1.131 + {
1.132 + // PWM_SET_HIGH;
1.133 + bsp_pinOut(BSP_PIN_11, 1);
1.134 + bsp_delayUs(5); //100kHz (96kHz ideal)
1.135 + // PWM_SET_LOW;
1.136 + bsp_pinOut(BSP_PIN_11, 0);
1.137 + bsp_delayUs(5);
1.138 + }
1.139 +}
1.140 +
1.141 +
1.142 +//******************************************************************
1.143 +//SPI Configuration
1.144 +//******************************************************************
1.145 +void epd_spi_detach(void)
1.146 +{
1.147 +#if 0
1.148 + LPC_IOCON->PIO0_8 &= 0xFC;; /* SSP I/O config */
1.149 + SPIMISO_DIR_OUT();
1.150 + SPIMISO_Set(Low);
1.151 +
1.152 + LPC_IOCON->PIO0_9 &= 0xFC; /* SSP MOSI */
1.153 + SPIMOSI_DIR_OUT();
1.154 + SPIMOSI_Set(Low);
1.155 +
1.156 + LPC_IOCON->PIO2_11 &= 0xFC;
1.157 + SPICLK_DIR_OUT();
1.158 + SPICLK_Set(Low);
1.159 +#endif
1.160 +}
1.161 +void epd_spi_init (void)
1.162 +{
1.163 + bsp_spiInit();
1.164 +//SSP_IOConfig( SSP_PORT ); /* initialize SSP port */
1.165 +//SSP_Init( SSP_PORT );
1.166 +}
1.167 +
1.168 +void epd_SPI_Send (unsigned char Register, unsigned char *Data, unsigned Length)
1.169 +{
1.170 + uint8_t buf[2];
1.171 +
1.172 + epd_cs_low();
1.173 + buf[0] = 0x70;
1.174 + buf[1] = Register;
1.175 + bsp_writeToDisplay(buf, 2);
1.176 + epd_cs_high();
1.177 + bsp_delayUs(10);
1.178 +
1.179 + epd_cs_low();
1.180 + buf[0] = 0x72;
1.181 + bsp_writeToDisplay(buf, 1);
1.182 + bsp_writeToDisplay(Data, Length);
1.183 + epd_cs_high();
1.184 + bsp_delayUs(10);
1.185 +}
1.186 +
1.187 +
1.188 +
1.189 +void epd_SPI_Send_Byte (uint8_t Register, uint8_t Data)
1.190 +{
1.191 + uint8_t buf[2];
1.192 +
1.193 + epd_cs_low();
1.194 + buf[0] = 0x70;
1.195 + buf[1] = Register;
1.196 + bsp_writeToDisplay(buf, 2);
1.197 + epd_cs_high();
1.198 + bsp_delayUs(10);
1.199 +
1.200 + epd_cs_low();
1.201 + buf[0] = 0x72;
1.202 + buf[1] = Data;
1.203 + bsp_writeToDisplay(buf, 2);
1.204 + epd_cs_high();
1.205 + bsp_delayUs(10);
1.206 +}
1.207 +
1.208 +void epd_InitDisplayHardware(void)
1.209 +{
1.210 + // RST_DIR_OUT;
1.211 + bsp_pinMode(BSP_PIN_12, BSP_PINMODE_OUTPUT);
1.212 + // DISCHARGE_DIR_OUT;
1.213 + bsp_pinMode(BSP_PIN_14, BSP_PINMODE_OUTPUT);
1.214 + // CS_DIR_OUT;
1.215 + bsp_pinMode(BSP_PIN_6, BSP_PINMODE_OUTPUT);
1.216 + // PANELON_DIR_OUT;
1.217 + bsp_pinMode(BSP_PIN_13, BSP_PINMODE_OUTPUT);
1.218 + // DRIVERBUSY_DIR_IN;
1.219 + bsp_pinMode(BSP_PIN_7, BSP_PINMODE_INPUT);
1.220 + // BORDER_DIR_OUT;
1.221 +
1.222 +
1.223 + epd_panelon_off();
1.224 + epd_spi_init();
1.225 + epd_cs_low();
1.226 + // epd_pwm_low();
1.227 + epd_pwm_active(0); //set output low
1.228 + epd_rst_low();
1.229 + epd_discharge_low();
1.230 +
1.231 +// TESTPin_DIR_OUT();
1.232 +// TESTPin2_DIR_OUT();
1.233 +}
1.234 +
1.235 +//************************************************************************
1.236 +void TestPinLow(void)
1.237 +{
1.238 +// TESTPin_Set(0);
1.239 +}
1.240 +void TestPinHigh(void)
1.241 +{
1.242 +// TESTPin_Set(1);
1.243 +}
1.244 +void TestPinTrigger(void)
1.245 +{
1.246 +// if(TESTPin_Get())TestPinLow();
1.247 +// else TestPinHigh();
1.248 +}
1.249 +void TestPin2Low(void)
1.250 +{
1.251 +// TESTPin2_Set(0);
1.252 +}
1.253 +void TestPin2High(void)
1.254 +{
1.255 +// TESTPin2_Set(1);
1.256 +}
1.257 +void TestPin2Trigger(void)
1.258 +{
1.259 +// if(TESTPin2_Get())TestPin2Low();
1.260 +// else TestPin2High();
1.261 +}