1 /* 2 * Ben NanoNote and EM027AS012 E-Paper Display Adapter Board communication. 3 * 4 * Copyright (C) 2013 Paul Boddie 5 * 6 * SPI functions derived from those in lib/atben.c by Werner Almesberger: 7 * 8 * Copyright (C) 2010-2011 Werner Almesberger 9 * 10 * This program is free software; you can redistribute it and/or modify it under 11 * the terms of the GNU General Public License as published by the Free Software 12 * Foundation; either version 3 of the License, or (at your option) any later 13 * version. 14 * 15 * This program is distributed in the hope that it will be useful, but WITHOUT 16 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 17 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 18 * details. 19 * 20 * You should have received a copy of the GNU General Public License along with 21 * this program. If not, see <http://www.gnu.org/licenses/>. 22 */ 23 24 #include <ubb/ubb.h> 25 #include <unistd.h> 26 #include <sys/time.h> 27 #include <time.h> 28 #include <stdio.h> 29 #include "bsp.h" 30 #include "Display_Hardware_Driver.h" 31 32 void bsp_init() 33 { 34 OUT(UBB_DAT2); 35 OUT(UBB_DAT3); 36 OUT(UBB_CMD); 37 OUT(UBB_CLK); 38 OUT(UBB_DAT0); 39 OUT(UBB_DAT1); 40 41 CLR(UBB_DAT2); 42 CLR(UBB_DAT3); 43 CLR(UBB_CMD); 44 CLR(UBB_CLK); 45 CLR(UBB_DAT0); 46 CLR(UBB_DAT1); 47 } 48 49 void bsp_spiInit() 50 { 51 } 52 53 /** 54 * Send the given value via MOSI. 55 */ 56 void bsp_writeToDisplay(uint8_t *data, uint16_t len) 57 { 58 uint8_t mask, *ptr, *limit = data + len; 59 60 for (ptr = data; ptr < limit; ptr++) 61 { 62 for (mask = 0x80; mask; mask >>= 1) 63 { 64 if (*ptr & mask) 65 { 66 SET(EPD_MOSI); 67 } 68 else 69 { 70 CLR(EPD_MOSI); 71 } 72 73 SET(EPD_SCK); 74 CLR(EPD_SCK); 75 } 76 } 77 } 78 79 void bsp_delayMs(uint32_t ms) 80 { 81 bsp_delayUs(ms * 1000); 82 } 83 84 void bsp_delayUs(uint32_t us) 85 { 86 #ifndef NANONOTE 87 struct timespec tv; 88 tv.tv_sec = 0; 89 tv.tv_nsec = us * 100; 90 nanosleep(&tv, NULL); 91 #else 92 uint64_t i = us * 24; 93 while (i--); 94 #endif 95 } 96 97 uint32_t bsp_getMsTicks() 98 { 99 struct timeval tv; 100 gettimeofday(&tv, NULL); 101 return tv.tv_sec * 1000 + tv.tv_usec / 1000; 102 } 103 104 /* Unsupported. */ 105 106 int16_t bsp_getTemp() 107 { 108 return 20; 109 }