Library to control the EM027BS013 ePaper display from Pervasive Display.

Dependencies:   LM75B

Dependents:   app_epaper_EM027BS013_LPC1549 lpc4088_ebb_epaper EaEpaper_EM027BS013 app_epaper_EM027BS013 ... more

Committer:
embeddedartists
Date:
Tue Jul 22 11:59:06 2014 +0000
Revision:
0:9297e33f50cf
First version of library for the EM027BS013 ePaper display.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
embeddedartists 0:9297e33f50cf 1 /**
embeddedartists 0:9297e33f50cf 2 * \file
embeddedartists 0:9297e33f50cf 3 *
embeddedartists 0:9297e33f50cf 4 * \brief The initialization and configuration of COG hardware driver
embeddedartists 0:9297e33f50cf 5 *
embeddedartists 0:9297e33f50cf 6 * Copyright (c) 2012-2014 Pervasive Displays Inc. All rights reserved.
embeddedartists 0:9297e33f50cf 7 *
embeddedartists 0:9297e33f50cf 8 * Authors: Pervasive Displays Inc.
embeddedartists 0:9297e33f50cf 9 *
embeddedartists 0:9297e33f50cf 10 * Redistribution and use in source and binary forms, with or without
embeddedartists 0:9297e33f50cf 11 * modification, are permitted provided that the following conditions
embeddedartists 0:9297e33f50cf 12 * are met:
embeddedartists 0:9297e33f50cf 13 *
embeddedartists 0:9297e33f50cf 14 * 1. Redistributions of source code must retain the above copyright
embeddedartists 0:9297e33f50cf 15 * notice, this list of conditions and the following disclaimer.
embeddedartists 0:9297e33f50cf 16 * 2. Redistributions in binary form must reproduce the above copyright
embeddedartists 0:9297e33f50cf 17 * notice, this list of conditions and the following disclaimer in
embeddedartists 0:9297e33f50cf 18 * the documentation and/or other materials provided with the
embeddedartists 0:9297e33f50cf 19 * distribution.
embeddedartists 0:9297e33f50cf 20 *
embeddedartists 0:9297e33f50cf 21 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
embeddedartists 0:9297e33f50cf 22 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
embeddedartists 0:9297e33f50cf 23 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
embeddedartists 0:9297e33f50cf 24 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
embeddedartists 0:9297e33f50cf 25 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
embeddedartists 0:9297e33f50cf 26 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
embeddedartists 0:9297e33f50cf 27 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
embeddedartists 0:9297e33f50cf 28 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
embeddedartists 0:9297e33f50cf 29 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
embeddedartists 0:9297e33f50cf 30 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
embeddedartists 0:9297e33f50cf 31 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
embeddedartists 0:9297e33f50cf 32 */
embeddedartists 0:9297e33f50cf 33
embeddedartists 0:9297e33f50cf 34 //#include <math.h>
embeddedartists 0:9297e33f50cf 35 #include "EPD_hardware_driver.h"
embeddedartists 0:9297e33f50cf 36
embeddedartists 0:9297e33f50cf 37 static uint16_t EPD_Counter;
embeddedartists 0:9297e33f50cf 38 static uint8_t spi_flag = FALSE;
embeddedartists 0:9297e33f50cf 39
embeddedartists 0:9297e33f50cf 40 #include "mbed.h"
embeddedartists 0:9297e33f50cf 41 #include "LM75B.h"
embeddedartists 0:9297e33f50cf 42 static Ticker systemTicker;
embeddedartists 0:9297e33f50cf 43 static SPI* expSPI = NULL;
embeddedartists 0:9297e33f50cf 44 static LM75B* expLM75B = NULL;
embeddedartists 0:9297e33f50cf 45 void SysTick_Handler(void);
embeddedartists 0:9297e33f50cf 46
embeddedartists 0:9297e33f50cf 47 extern PinName SEC03;
embeddedartists 0:9297e33f50cf 48 extern PinName SEC04;
embeddedartists 0:9297e33f50cf 49 extern PinName SEC05;
embeddedartists 0:9297e33f50cf 50 extern PinName SEC09;
embeddedartists 0:9297e33f50cf 51 extern PinName SEC10;
embeddedartists 0:9297e33f50cf 52
embeddedartists 0:9297e33f50cf 53
embeddedartists 0:9297e33f50cf 54 /**
embeddedartists 0:9297e33f50cf 55 * \brief Set up EPD Timer for 1 mSec interrupts
embeddedartists 0:9297e33f50cf 56 *
embeddedartists 0:9297e33f50cf 57 * \note
embeddedartists 0:9297e33f50cf 58 * desired value: 1mSec
embeddedartists 0:9297e33f50cf 59 * actual value: 1.000mSec
embeddedartists 0:9297e33f50cf 60 */
embeddedartists 0:9297e33f50cf 61 static void initialize_EPD_timer(void) {
embeddedartists 0:9297e33f50cf 62 //------------------Timer A1----------------------------------------
embeddedartists 0:9297e33f50cf 63 //set up Timer_A CCR1 as master timer using ACLK
embeddedartists 0:9297e33f50cf 64 // TA0CCTL2 &= ~(CCIFG | CCIE); // reset CCIFG Interrupt Flag
embeddedartists 0:9297e33f50cf 65 // TA0CTL = TASSEL_2 + MC_0 + TACLR + ID_3;
embeddedartists 0:9297e33f50cf 66 // TA0CCTL2 = OUTMOD_4;
embeddedartists 0:9297e33f50cf 67 EPD_Counter = 0;
embeddedartists 0:9297e33f50cf 68 }
embeddedartists 0:9297e33f50cf 69
embeddedartists 0:9297e33f50cf 70 /**
embeddedartists 0:9297e33f50cf 71 * \brief Start Timer
embeddedartists 0:9297e33f50cf 72 */
embeddedartists 0:9297e33f50cf 73 void start_EPD_timer(void) {
embeddedartists 0:9297e33f50cf 74 initialize_EPD_timer();
embeddedartists 0:9297e33f50cf 75 // TA0R = 0;
embeddedartists 0:9297e33f50cf 76 // TA0CCR0 = 990 * 2; // 1ms
embeddedartists 0:9297e33f50cf 77 // TA0CCTL2 |= CCIE;
embeddedartists 0:9297e33f50cf 78 // TA0CTL |= MC_1;
embeddedartists 0:9297e33f50cf 79 EPD_Counter = 0;
embeddedartists 0:9297e33f50cf 80 systemTicker.attach_us(&SysTick_Handler, 1000);
embeddedartists 0:9297e33f50cf 81 }
embeddedartists 0:9297e33f50cf 82
embeddedartists 0:9297e33f50cf 83 /**
embeddedartists 0:9297e33f50cf 84 * \brief Stop Timer
embeddedartists 0:9297e33f50cf 85 */
embeddedartists 0:9297e33f50cf 86 void stop_EPD_timer(void) {
embeddedartists 0:9297e33f50cf 87 // TA0CCTL2 &= ~CCIE;
embeddedartists 0:9297e33f50cf 88 // TA0CTL &= ~MC_1;
embeddedartists 0:9297e33f50cf 89 systemTicker.detach();
embeddedartists 0:9297e33f50cf 90 }
embeddedartists 0:9297e33f50cf 91
embeddedartists 0:9297e33f50cf 92 /**
embeddedartists 0:9297e33f50cf 93 * \brief Get current Timer after starting a new one
embeddedartists 0:9297e33f50cf 94 */
embeddedartists 0:9297e33f50cf 95 uint32_t get_current_time_tick(void) {
embeddedartists 0:9297e33f50cf 96 return EPD_Counter;
embeddedartists 0:9297e33f50cf 97 }
embeddedartists 0:9297e33f50cf 98 /**
embeddedartists 0:9297e33f50cf 99 * \brief Set current Timer after starting a new one
embeddedartists 0:9297e33f50cf 100 */
embeddedartists 0:9297e33f50cf 101 void set_current_time_tick(uint32_t count) {
embeddedartists 0:9297e33f50cf 102 EPD_Counter=count;
embeddedartists 0:9297e33f50cf 103 }
embeddedartists 0:9297e33f50cf 104 /**
embeddedartists 0:9297e33f50cf 105 * \brief Interrupt Service Routine for system tick counter
embeddedartists 0:9297e33f50cf 106 */
embeddedartists 0:9297e33f50cf 107 void SysTick_Handler(void) {
embeddedartists 0:9297e33f50cf 108 EPD_Counter++;
embeddedartists 0:9297e33f50cf 109 }
embeddedartists 0:9297e33f50cf 110
embeddedartists 0:9297e33f50cf 111 ///**
embeddedartists 0:9297e33f50cf 112 // * \brief Interrupt Service Routine for Timer A0
embeddedartists 0:9297e33f50cf 113 // */
embeddedartists 0:9297e33f50cf 114 //#pragma vector=TIMER0_A1_VECTOR
embeddedartists 0:9297e33f50cf 115 //__interrupt void Timer_A0(void) {
embeddedartists 0:9297e33f50cf 116 // switch (__even_in_range(TA0IV, 10)) {
embeddedartists 0:9297e33f50cf 117 // case 2:
embeddedartists 0:9297e33f50cf 118 // //LPM3_EXIT;
embeddedartists 0:9297e33f50cf 119 // break;
embeddedartists 0:9297e33f50cf 120
embeddedartists 0:9297e33f50cf 121 // case 4:
embeddedartists 0:9297e33f50cf 122 // EPD_Counter++;
embeddedartists 0:9297e33f50cf 123 // LPM3_EXIT;
embeddedartists 0:9297e33f50cf 124 // break;
embeddedartists 0:9297e33f50cf 125 // }
embeddedartists 0:9297e33f50cf 126
embeddedartists 0:9297e33f50cf 127 //}
embeddedartists 0:9297e33f50cf 128
embeddedartists 0:9297e33f50cf 129 /**
embeddedartists 0:9297e33f50cf 130 * \brief Delay mini-seconds
embeddedartists 0:9297e33f50cf 131 * \param ms The number of mini-seconds
embeddedartists 0:9297e33f50cf 132 */
embeddedartists 0:9297e33f50cf 133 void delay_ms(unsigned int ms) {
embeddedartists 0:9297e33f50cf 134 // while (ms--) {
embeddedartists 0:9297e33f50cf 135 // __delay_cycles(SMCLK_FREQ / 1000);
embeddedartists 0:9297e33f50cf 136 // }
embeddedartists 0:9297e33f50cf 137 wait_ms(ms);
embeddedartists 0:9297e33f50cf 138 }
embeddedartists 0:9297e33f50cf 139
embeddedartists 0:9297e33f50cf 140 /**
embeddedartists 0:9297e33f50cf 141 * \brief Delay mini-seconds
embeddedartists 0:9297e33f50cf 142 * \param ms The number of mini-seconds
embeddedartists 0:9297e33f50cf 143 */
embeddedartists 0:9297e33f50cf 144 void sys_delay_ms(unsigned int ms) {
embeddedartists 0:9297e33f50cf 145 // delay_ms(ms);
embeddedartists 0:9297e33f50cf 146 wait_ms(ms);
embeddedartists 0:9297e33f50cf 147 }
embeddedartists 0:9297e33f50cf 148
embeddedartists 0:9297e33f50cf 149 static void Wait_10us(void) {
embeddedartists 0:9297e33f50cf 150 // __delay_cycles(SMCLK_FREQ / 100000);
embeddedartists 0:9297e33f50cf 151 wait_us(10);
embeddedartists 0:9297e33f50cf 152 }
embeddedartists 0:9297e33f50cf 153
embeddedartists 0:9297e33f50cf 154 //******************************************************************
embeddedartists 0:9297e33f50cf 155 //* PWM Configuration/Control //PWM output : PD3
embeddedartists 0:9297e33f50cf 156 //******************************************************************
embeddedartists 0:9297e33f50cf 157
embeddedartists 0:9297e33f50cf 158 /**
embeddedartists 0:9297e33f50cf 159 * \brief The PWM signal starts toggling
embeddedartists 0:9297e33f50cf 160 */
embeddedartists 0:9297e33f50cf 161 void PWM_start_toggle(void) {
embeddedartists 0:9297e33f50cf 162
embeddedartists 0:9297e33f50cf 163 }
embeddedartists 0:9297e33f50cf 164
embeddedartists 0:9297e33f50cf 165 /**
embeddedartists 0:9297e33f50cf 166 * \brief The PWM signal stops toggling.
embeddedartists 0:9297e33f50cf 167 */
embeddedartists 0:9297e33f50cf 168 void PWM_stop_toggle(void) {
embeddedartists 0:9297e33f50cf 169
embeddedartists 0:9297e33f50cf 170 }
embeddedartists 0:9297e33f50cf 171
embeddedartists 0:9297e33f50cf 172 /**
embeddedartists 0:9297e33f50cf 173 * \brief PWM toggling.
embeddedartists 0:9297e33f50cf 174 *
embeddedartists 0:9297e33f50cf 175 * \param ms The interval of PWM toggling (mini seconds)
embeddedartists 0:9297e33f50cf 176 */
embeddedartists 0:9297e33f50cf 177 void PWM_run(uint16_t ms) {
embeddedartists 0:9297e33f50cf 178 // start_EPD_timer();
embeddedartists 0:9297e33f50cf 179 // do {
embeddedartists 0:9297e33f50cf 180 // EPD_pwm_high();
embeddedartists 0:9297e33f50cf 181 // __delay_cycles(30);
embeddedartists 0:9297e33f50cf 182 // EPD_pwm_low();
embeddedartists 0:9297e33f50cf 183 // __delay_cycles(30);
embeddedartists 0:9297e33f50cf 184 // } while (get_current_time_tick() < ms); //wait Delay Time
embeddedartists 0:9297e33f50cf 185 // stop_EPD_timer();
embeddedartists 0:9297e33f50cf 186 mbed_die();
embeddedartists 0:9297e33f50cf 187 }
embeddedartists 0:9297e33f50cf 188
embeddedartists 0:9297e33f50cf 189 //******************************************************************
embeddedartists 0:9297e33f50cf 190 //* SPI Configuration
embeddedartists 0:9297e33f50cf 191 //******************************************************************
embeddedartists 0:9297e33f50cf 192
embeddedartists 0:9297e33f50cf 193 /**
embeddedartists 0:9297e33f50cf 194 * \brief Configure SPI
embeddedartists 0:9297e33f50cf 195 */
embeddedartists 0:9297e33f50cf 196 void epd_spi_init(void) {
embeddedartists 0:9297e33f50cf 197 if (spi_flag)
embeddedartists 0:9297e33f50cf 198 return;
embeddedartists 0:9297e33f50cf 199 spi_flag = TRUE;
embeddedartists 0:9297e33f50cf 200 // //config i/o
embeddedartists 0:9297e33f50cf 201 // config_gpio_dir_o(SPICLK_PORT, SPICLK_PIN);
embeddedartists 0:9297e33f50cf 202 // config_gpio_dir_o(SPIMOSI_PORT, SPIMOSI_PIN);
embeddedartists 0:9297e33f50cf 203 // config_gpio_dir_i(SPIMISO_PORT, SPIMISO_PIN);
embeddedartists 0:9297e33f50cf 204
embeddedartists 0:9297e33f50cf 205 // BITSET(SPISEL, SPICLK_PIN + SPIMOSI_PIN + SPIMISO_PIN);
embeddedartists 0:9297e33f50cf 206 // BITSET(SPISEL2, SPICLK_PIN + SPIMOSI_PIN + SPIMISO_PIN);
embeddedartists 0:9297e33f50cf 207 // //comfig SPI
embeddedartists 0:9297e33f50cf 208 // SPICTL0 = UCCKPH | UCMST | UCSYNC | UCMSB;
embeddedartists 0:9297e33f50cf 209 // SPICTL1 = UCSSEL_2 + UCSWRST;
embeddedartists 0:9297e33f50cf 210 // SPIBR0 = 2; //16MHz/2=8MHz
embeddedartists 0:9297e33f50cf 211 // SPIBR1 = 0;
embeddedartists 0:9297e33f50cf 212
embeddedartists 0:9297e33f50cf 213 // BITSET(REN (SPIMISO_PORT), SPIMISO_PIN);
embeddedartists 0:9297e33f50cf 214 // BITCLR(SPICTL1, UCSWRST);
embeddedartists 0:9297e33f50cf 215
embeddedartists 0:9297e33f50cf 216 expSPI = new SPI(SEC04, SEC05, SEC03); // mosi, miso, sclk
embeddedartists 0:9297e33f50cf 217 expSPI->frequency(COG_SPI_baudrate);
embeddedartists 0:9297e33f50cf 218 }
embeddedartists 0:9297e33f50cf 219
embeddedartists 0:9297e33f50cf 220 /**
embeddedartists 0:9297e33f50cf 221 * \brief Initialize SPI
embeddedartists 0:9297e33f50cf 222 */
embeddedartists 0:9297e33f50cf 223 void epd_spi_attach(void) {
embeddedartists 0:9297e33f50cf 224 EPD_flash_cs_high();
embeddedartists 0:9297e33f50cf 225 EPD_cs_high();
embeddedartists 0:9297e33f50cf 226 epd_spi_init();
embeddedartists 0:9297e33f50cf 227 }
embeddedartists 0:9297e33f50cf 228
embeddedartists 0:9297e33f50cf 229 /**
embeddedartists 0:9297e33f50cf 230 * \brief Disable SPI and change to GPIO
embeddedartists 0:9297e33f50cf 231 */
embeddedartists 0:9297e33f50cf 232 void epd_spi_detach(void) {
embeddedartists 0:9297e33f50cf 233 // BITCLR(SPISEL, SPICLK_PIN + SPIMOSI_PIN + SPIMISO_PIN);
embeddedartists 0:9297e33f50cf 234 // BITCLR(SPISEL2, SPICLK_PIN + SPIMOSI_PIN + SPIMISO_PIN);
embeddedartists 0:9297e33f50cf 235 // //config_gpio_dir_o(SPICLK_PORT,SPICLK_PIN);
embeddedartists 0:9297e33f50cf 236 // //config_gpio_dir_o(SPIMOSI_PORT,SPIMOSI_PIN);
embeddedartists 0:9297e33f50cf 237 // //config_gpio_dir_o(SPIMISO_PORT,SPIMISO_PIN);
embeddedartists 0:9297e33f50cf 238 // SPIMISO_low();
embeddedartists 0:9297e33f50cf 239 // SPIMOSI_low();
embeddedartists 0:9297e33f50cf 240 // SPICLK_low();
embeddedartists 0:9297e33f50cf 241 if (expSPI != NULL) {
embeddedartists 0:9297e33f50cf 242 delete expSPI;
embeddedartists 0:9297e33f50cf 243 expSPI = NULL;
embeddedartists 0:9297e33f50cf 244 }
embeddedartists 0:9297e33f50cf 245 spi_flag = FALSE;
embeddedartists 0:9297e33f50cf 246 }
embeddedartists 0:9297e33f50cf 247
embeddedartists 0:9297e33f50cf 248 /**
embeddedartists 0:9297e33f50cf 249 * \brief SPI synchronous write
embeddedartists 0:9297e33f50cf 250 */
embeddedartists 0:9297e33f50cf 251 void epd_spi_write(unsigned char Data) {
embeddedartists 0:9297e33f50cf 252 // SPITXBUF = Data;
embeddedartists 0:9297e33f50cf 253 // while (!(SPIIFG & SPITXIFG))
embeddedartists 0:9297e33f50cf 254 // ;
embeddedartists 0:9297e33f50cf 255 expSPI->write(Data);
embeddedartists 0:9297e33f50cf 256 }
embeddedartists 0:9297e33f50cf 257
embeddedartists 0:9297e33f50cf 258 /**
embeddedartists 0:9297e33f50cf 259 * \brief SPI synchronous read
embeddedartists 0:9297e33f50cf 260 */
embeddedartists 0:9297e33f50cf 261 uint8_t epd_spi_read(unsigned char RDATA) {
embeddedartists 0:9297e33f50cf 262 // SPITXBUF = RDATA;
embeddedartists 0:9297e33f50cf 263 // while ((SPISTAT & UCBUSY))
embeddedartists 0:9297e33f50cf 264 // ;
embeddedartists 0:9297e33f50cf 265 // RDATA = SPIRXBUF;
embeddedartists 0:9297e33f50cf 266 // return RDATA;
embeddedartists 0:9297e33f50cf 267 return expSPI->write(RDATA) & 0xff;
embeddedartists 0:9297e33f50cf 268 }
embeddedartists 0:9297e33f50cf 269
embeddedartists 0:9297e33f50cf 270 /**
embeddedartists 0:9297e33f50cf 271 * \brief Send data to SPI with time out feature
embeddedartists 0:9297e33f50cf 272 *
embeddedartists 0:9297e33f50cf 273 * \param data The data to be sent out
embeddedartists 0:9297e33f50cf 274 */
embeddedartists 0:9297e33f50cf 275 uint8_t epd_spi_write_ex(unsigned char Data) {
embeddedartists 0:9297e33f50cf 276 // uint8_t cnt = 200;
embeddedartists 0:9297e33f50cf 277 // uint8_t flag = 1;
embeddedartists 0:9297e33f50cf 278 // SPITXBUF = Data;
embeddedartists 0:9297e33f50cf 279 // while (!(SPIIFG & SPITXIFG)) {
embeddedartists 0:9297e33f50cf 280 // if ((cnt--) == 0) {
embeddedartists 0:9297e33f50cf 281 // flag = 0;
embeddedartists 0:9297e33f50cf 282 // break;
embeddedartists 0:9297e33f50cf 283 // }
embeddedartists 0:9297e33f50cf 284 // }
embeddedartists 0:9297e33f50cf 285 // return flag;
embeddedartists 0:9297e33f50cf 286
embeddedartists 0:9297e33f50cf 287 // Not used
embeddedartists 0:9297e33f50cf 288 mbed_die();
embeddedartists 0:9297e33f50cf 289 return 0;
embeddedartists 0:9297e33f50cf 290 }
embeddedartists 0:9297e33f50cf 291
embeddedartists 0:9297e33f50cf 292 #if (defined COG_V230_G2)
embeddedartists 0:9297e33f50cf 293 /**
embeddedartists 0:9297e33f50cf 294 * \brief SPI command
embeddedartists 0:9297e33f50cf 295 *
embeddedartists 0:9297e33f50cf 296 * \param register_index The Register Index as SPI Data to COG
embeddedartists 0:9297e33f50cf 297 * \param register_data The Register Data for sending command data to COG
embeddedartists 0:9297e33f50cf 298 * \return the SPI read value
embeddedartists 0:9297e33f50cf 299 */
embeddedartists 0:9297e33f50cf 300 uint8_t SPI_R(uint8_t Register, uint8_t Data) {
embeddedartists 0:9297e33f50cf 301 uint8_t result;
embeddedartists 0:9297e33f50cf 302 EPD_cs_low ();
embeddedartists 0:9297e33f50cf 303 epd_spi_write (0x70); // header of Register Index
embeddedartists 0:9297e33f50cf 304 epd_spi_write (Register);
embeddedartists 0:9297e33f50cf 305
embeddedartists 0:9297e33f50cf 306 EPD_cs_high ();
embeddedartists 0:9297e33f50cf 307 Wait_10us ();
embeddedartists 0:9297e33f50cf 308 EPD_cs_low ();
embeddedartists 0:9297e33f50cf 309
embeddedartists 0:9297e33f50cf 310 epd_spi_write (0x73); // header of Register Data of read command
embeddedartists 0:9297e33f50cf 311 result=epd_spi_read (Data);
embeddedartists 0:9297e33f50cf 312
embeddedartists 0:9297e33f50cf 313 EPD_cs_high ();
embeddedartists 0:9297e33f50cf 314
embeddedartists 0:9297e33f50cf 315 return result;
embeddedartists 0:9297e33f50cf 316 }
embeddedartists 0:9297e33f50cf 317 #endif
embeddedartists 0:9297e33f50cf 318
embeddedartists 0:9297e33f50cf 319 /**
embeddedartists 0:9297e33f50cf 320 * \brief SPI command if register data is larger than two bytes
embeddedartists 0:9297e33f50cf 321 *
embeddedartists 0:9297e33f50cf 322 * \param register_index The Register Index as SPI command to COG
embeddedartists 0:9297e33f50cf 323 * \param register_data The Register Data for sending command data to COG
embeddedartists 0:9297e33f50cf 324 * \param length The number of bytes of Register Data which depends on which
embeddedartists 0:9297e33f50cf 325 * Register Index is selected.
embeddedartists 0:9297e33f50cf 326 */
embeddedartists 0:9297e33f50cf 327 void epd_spi_send (unsigned char register_index, unsigned char *register_data,
embeddedartists 0:9297e33f50cf 328 unsigned length) {
embeddedartists 0:9297e33f50cf 329 EPD_cs_low ();
embeddedartists 0:9297e33f50cf 330 epd_spi_write (0x70); // header of Register Index
embeddedartists 0:9297e33f50cf 331 epd_spi_write (register_index);
embeddedartists 0:9297e33f50cf 332
embeddedartists 0:9297e33f50cf 333 EPD_cs_high ();
embeddedartists 0:9297e33f50cf 334 Wait_10us ();
embeddedartists 0:9297e33f50cf 335 EPD_cs_low ();
embeddedartists 0:9297e33f50cf 336
embeddedartists 0:9297e33f50cf 337 epd_spi_write (0x72); // header of Register Data of write command
embeddedartists 0:9297e33f50cf 338 while(length--) {
embeddedartists 0:9297e33f50cf 339 epd_spi_write (*register_data++);
embeddedartists 0:9297e33f50cf 340 }
embeddedartists 0:9297e33f50cf 341 EPD_cs_high ();
embeddedartists 0:9297e33f50cf 342 }
embeddedartists 0:9297e33f50cf 343
embeddedartists 0:9297e33f50cf 344 /**
embeddedartists 0:9297e33f50cf 345 * \brief SPI command
embeddedartists 0:9297e33f50cf 346 *
embeddedartists 0:9297e33f50cf 347 * \param register_index The Register Index as SPI command to COG
embeddedartists 0:9297e33f50cf 348 * \param register_data The Register Data for sending command data to COG
embeddedartists 0:9297e33f50cf 349 */
embeddedartists 0:9297e33f50cf 350 void epd_spi_send_byte (uint8_t register_index, uint8_t register_data) {
embeddedartists 0:9297e33f50cf 351 EPD_cs_low ();
embeddedartists 0:9297e33f50cf 352 epd_spi_write (0x70); // header of Register Index
embeddedartists 0:9297e33f50cf 353 epd_spi_write (register_index);
embeddedartists 0:9297e33f50cf 354
embeddedartists 0:9297e33f50cf 355 EPD_cs_high ();
embeddedartists 0:9297e33f50cf 356 Wait_10us ();
embeddedartists 0:9297e33f50cf 357 EPD_cs_low ();
embeddedartists 0:9297e33f50cf 358 epd_spi_write (0x72); // header of Register Data
embeddedartists 0:9297e33f50cf 359 epd_spi_write (register_data);
embeddedartists 0:9297e33f50cf 360 EPD_cs_high ();
embeddedartists 0:9297e33f50cf 361 }
embeddedartists 0:9297e33f50cf 362
embeddedartists 0:9297e33f50cf 363 //******************************************************************
embeddedartists 0:9297e33f50cf 364 //* Temperature sensor Configuration
embeddedartists 0:9297e33f50cf 365 //******************************************************************
embeddedartists 0:9297e33f50cf 366 #ifdef __Internal_Temperature_Sensor
embeddedartists 0:9297e33f50cf 367 // ADC10 interrupt service routine
embeddedartists 0:9297e33f50cf 368 #pragma vector=ADC10_VECTOR
embeddedartists 0:9297e33f50cf 369 __interrupt void ADC10_ISR(void) {
embeddedartists 0:9297e33f50cf 370 __bic_SR_register_on_exit(CPUOFF);
embeddedartists 0:9297e33f50cf 371 // Clear CPUOFF bit from 0(SR)
embeddedartists 0:9297e33f50cf 372 }
embeddedartists 0:9297e33f50cf 373 /**
embeddedartists 0:9297e33f50cf 374 * \brief Get temperature value from ADC
embeddedartists 0:9297e33f50cf 375 *
embeddedartists 0:9297e33f50cf 376 * \return the Celsius temperature
embeddedartists 0:9297e33f50cf 377 */
embeddedartists 0:9297e33f50cf 378 int16_t get_temperature(void) {
embeddedartists 0:9297e33f50cf 379 const uint8_t DegCOffset=0;
embeddedartists 0:9297e33f50cf 380 long temp;
embeddedartists 0:9297e33f50cf 381 float IntDegC;
embeddedartists 0:9297e33f50cf 382
embeddedartists 0:9297e33f50cf 383 ADC10CTL1 = INCH_10 + ADC10DIV_3; // Temp Sensor ADC10CLK/4
embeddedartists 0:9297e33f50cf 384 ADC10CTL0 = SREF_1 + ADC10SHT_3 + REFON + ADC10ON+ADC10IE;
embeddedartists 0:9297e33f50cf 385 ADC10CTL0 |= ENC + ADC10SC;// Sampling and conversion start
embeddedartists 0:9297e33f50cf 386 __bis_SR_register(CPUOFF + GIE);// LPM0, ADC10_ISR will force exit
embeddedartists 0:9297e33f50cf 387 // oC = ((A10/1024)*1500mV)-986mV)*1/3.55mV = A10*423/1024 - 278
embeddedartists 0:9297e33f50cf 388 temp = ADC10MEM;
embeddedartists 0:9297e33f50cf 389
embeddedartists 0:9297e33f50cf 390 ADC10CTL0 |= ENC + ADC10SC;// Sampling and conversion start
embeddedartists 0:9297e33f50cf 391 __bis_SR_register(CPUOFF + GIE);// LPM0, ADC10_ISR will force exit
embeddedartists 0:9297e33f50cf 392 temp = ADC10MEM;
embeddedartists 0:9297e33f50cf 393 ADC10CTL0 |= ENC + ADC10SC;// Sampling and conversion start
embeddedartists 0:9297e33f50cf 394 __bis_SR_register(CPUOFF + GIE);// LPM0, ADC10_ISR will force exit
embeddedartists 0:9297e33f50cf 395 temp += ADC10MEM;
embeddedartists 0:9297e33f50cf 396 temp=temp/2;
embeddedartists 0:9297e33f50cf 397
embeddedartists 0:9297e33f50cf 398 IntDegC =(long)((long)(temp*423)/1024)-(278+DegCOffset);//(long)((long)(temp - 673) * 423) / 1024;
embeddedartists 0:9297e33f50cf 399
embeddedartists 0:9297e33f50cf 400 __no_operation();// SET BREAKPOINT HERE
embeddedartists 0:9297e33f50cf 401
embeddedartists 0:9297e33f50cf 402 return (int8_t) IntDegC;
embeddedartists 0:9297e33f50cf 403 }
embeddedartists 0:9297e33f50cf 404 #elif defined __External_Temperature_Sensor
embeddedartists 0:9297e33f50cf 405
embeddedartists 0:9297e33f50cf 406 /**
embeddedartists 0:9297e33f50cf 407 * \brief Get temperature value from ADC
embeddedartists 0:9297e33f50cf 408 *
embeddedartists 0:9297e33f50cf 409 * \return the Celsius temperature
embeddedartists 0:9297e33f50cf 410 */
embeddedartists 0:9297e33f50cf 411 int16_t get_temperature(void) {
embeddedartists 0:9297e33f50cf 412 // float IntDegC;
embeddedartists 0:9297e33f50cf 413 // const uint8_t DegCOffset = 2;
embeddedartists 0:9297e33f50cf 414 // long temp;
embeddedartists 0:9297e33f50cf 415 // ADC10CTL0 |= ENC + ADC10SC; // Sampling and conversion start
embeddedartists 0:9297e33f50cf 416 // __bis_SR_register(CPUOFF + GIE);
embeddedartists 0:9297e33f50cf 417 // // LPM0, ADC10_ISR will force exit
embeddedartists 0:9297e33f50cf 418 // temp = ADC10MEM;
embeddedartists 0:9297e33f50cf 419
embeddedartists 0:9297e33f50cf 420 // ADC10CTL0 |= ENC + ADC10SC; // Sampling and conversion start
embeddedartists 0:9297e33f50cf 421 // __bis_SR_register(CPUOFF + GIE);
embeddedartists 0:9297e33f50cf 422 // // LPM0, ADC10_ISR will force exit
embeddedartists 0:9297e33f50cf 423 // temp = ADC10MEM;
embeddedartists 0:9297e33f50cf 424 // ADC10CTL0 |= ENC + ADC10SC; // Sampling and conversion start
embeddedartists 0:9297e33f50cf 425 // __bis_SR_register(CPUOFF + GIE);
embeddedartists 0:9297e33f50cf 426 // // LPM0, ADC10_ISR will force exit
embeddedartists 0:9297e33f50cf 427 // temp = ADC10MEM;
embeddedartists 0:9297e33f50cf 428 // ADC10CTL0 |= ENC + ADC10SC; // Sampling and conversion start
embeddedartists 0:9297e33f50cf 429 // __bis_SR_register(CPUOFF + GIE);
embeddedartists 0:9297e33f50cf 430 // // LPM0, ADC10_ISR will force exit
embeddedartists 0:9297e33f50cf 431 // temp = ADC10MEM;
embeddedartists 0:9297e33f50cf 432
embeddedartists 0:9297e33f50cf 433 // //org
embeddedartists 0:9297e33f50cf 434 // /*
embeddedartists 0:9297e33f50cf 435 // temp = (ADC10MEM*5)/2;
embeddedartists 0:9297e33f50cf 436 // voltage = (float)((float)temp*2.5)/1024.0; //(2.5/1024)*ADC=Mcu voltage,Temperature voltage=Mcu voltage*2
embeddedartists 0:9297e33f50cf 437 // IntDegC=100.0- (((voltage*1000)/10.77)-111.3); //100-((Temperature voltage-1.199)*1000)/10.77=IntDegC
embeddedartists 0:9297e33f50cf 438 // __no_operation(); // SET BREAKPOINT HERE
embeddedartists 0:9297e33f50cf 439 // */
embeddedartists 0:9297e33f50cf 440 // //adj
embeddedartists 0:9297e33f50cf 441 // // IntDegC=(203-DegCOffset)-((long)((7*temp)/128)+(temp/2));
embeddedartists 0:9297e33f50cf 442 // IntDegC = (201 - DegCOffset) - ((long) ((5 * temp) / 128) + (temp / 2));
embeddedartists 0:9297e33f50cf 443 // return (int16_t) IntDegC;
embeddedartists 0:9297e33f50cf 444
embeddedartists 0:9297e33f50cf 445 float f = *expLM75B;
embeddedartists 0:9297e33f50cf 446 return (int)f;
embeddedartists 0:9297e33f50cf 447 }
embeddedartists 0:9297e33f50cf 448
embeddedartists 0:9297e33f50cf 449 #endif
embeddedartists 0:9297e33f50cf 450
embeddedartists 0:9297e33f50cf 451 /**
embeddedartists 0:9297e33f50cf 452 * \brief Initialize the temperature sensor
embeddedartists 0:9297e33f50cf 453 */
embeddedartists 0:9297e33f50cf 454 void initialize_temperature(void) {
embeddedartists 0:9297e33f50cf 455 #ifdef __External_Temperature_Sensor
embeddedartists 0:9297e33f50cf 456
embeddedartists 0:9297e33f50cf 457 //Create an LM75B object at 0x92/0x93 (ADDRESS_1)
embeddedartists 0:9297e33f50cf 458 expLM75B = new LM75B(SEC10, SEC09, LM75B::ADDRESS_1); // Requires JP8 and JP9 in 1-2 position to avoid interference from LM75 on ARM University BB
embeddedartists 0:9297e33f50cf 459
embeddedartists 0:9297e33f50cf 460 //Try to open the LM75B
embeddedartists 0:9297e33f50cf 461 if (!expLM75B->open()) {
embeddedartists 0:9297e33f50cf 462 // mbed_die();
embeddedartists 0:9297e33f50cf 463 }
embeddedartists 0:9297e33f50cf 464 // ADC10CTL0 = SREF_1 + ADC10SHT_3 + ADC10ON + ADC10IE + REFON + REF2_5V; // ADC10ON, interrupt enabled
embeddedartists 0:9297e33f50cf 465 // ADC10CTL1 = INCH_4 + ADC10DIV_3; // input A1.4
embeddedartists 0:9297e33f50cf 466
embeddedartists 0:9297e33f50cf 467 #endif
embeddedartists 0:9297e33f50cf 468 }
embeddedartists 0:9297e33f50cf 469
embeddedartists 0:9297e33f50cf 470 /**
embeddedartists 0:9297e33f50cf 471 * \brief Initialize the EPD hardware setting
embeddedartists 0:9297e33f50cf 472 */
embeddedartists 0:9297e33f50cf 473 void EPD_display_hardware_init(void) {
embeddedartists 0:9297e33f50cf 474 EPD_initialize_gpio();
embeddedartists 0:9297e33f50cf 475 EPD_Vcc_turn_off();
embeddedartists 0:9297e33f50cf 476 epd_spi_init();
embeddedartists 0:9297e33f50cf 477 initialize_temperature();
embeddedartists 0:9297e33f50cf 478 EPD_cs_low();
embeddedartists 0:9297e33f50cf 479 EPD_pwm_low();
embeddedartists 0:9297e33f50cf 480 EPD_rst_low();
embeddedartists 0:9297e33f50cf 481 EPD_discharge_low();
embeddedartists 0:9297e33f50cf 482 EPD_border_low();
embeddedartists 0:9297e33f50cf 483 //initialize_EPD_timer();
embeddedartists 0:9297e33f50cf 484 }
embeddedartists 0:9297e33f50cf 485