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 11 * it under the terms of the GNU General Public License as published by 12 * the Free Software Foundation; either version 2 of the License, or 13 * (at your option) any later version. 14 * 15 * Driver-related code originally provided under the following terms: 16 * 17 * Copyright 2013 Pervasive Displays, Inc. 18 * 19 * Licensed under the Apache License, Version 2.0 (the "License"); 20 * you may not use this file except in compliance with the License. 21 * You may obtain a copy of the License at: 22 * 23 * http://www.apache.org/licenses/LICENSE-2.0 24 * 25 * Unless required by applicable law or agreed to in writing, 26 * software distributed under the License is distributed on an 27 * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either 28 * express or implied. See the License for the specific language 29 * governing permissions and limitations under the License. 30 */ 31 32 #include <ubb/ubb.h> 33 #include <unistd.h> 34 #include <sys/time.h> 35 #include <time.h> 36 #include <stdio.h> 37 #include "bsp.h" 38 #include "Display_Hardware_Driver.h" 39 40 void bsp_init() 41 { 42 OUT(UBB_DAT2); 43 OUT(UBB_DAT3); 44 OUT(UBB_CMD); 45 OUT(UBB_CLK); 46 OUT(UBB_DAT0); 47 OUT(UBB_DAT1); 48 49 CLR(UBB_DAT2); 50 CLR(UBB_DAT3); 51 CLR(UBB_CMD); 52 CLR(UBB_CLK); 53 CLR(UBB_DAT0); 54 CLR(UBB_DAT1); 55 } 56 57 void bsp_spiInit() 58 { 59 } 60 61 /** 62 * Send the given value via MOSI. 63 */ 64 void bsp_writeToDisplay(uint8_t *data, uint16_t len) 65 { 66 uint8_t mask, *ptr, *limit = data + len; 67 68 for (ptr = data; ptr < limit; ptr++) 69 { 70 for (mask = 0x80; mask; mask >>= 1) 71 { 72 if (*ptr & mask) 73 { 74 SET(EPD_MOSI); 75 } 76 else 77 { 78 CLR(EPD_MOSI); 79 } 80 81 SET(EPD_SCK); 82 CLR(EPD_SCK); 83 } 84 } 85 } 86 87 void bsp_delayMs(uint32_t ms) 88 { 89 bsp_delayUs(ms * 1000); 90 } 91 92 void bsp_delayUs(uint32_t us) 93 { 94 #ifndef NANONOTE 95 struct timespec tv; 96 tv.tv_sec = 0; 97 tv.tv_nsec = us * 100; 98 nanosleep(&tv, NULL); 99 #else 100 uint64_t i = us * 24; 101 while (i--); 102 #endif 103 } 104 105 uint32_t bsp_getMsTicks() 106 { 107 struct timeval tv; 108 gettimeofday(&tv, NULL); 109 return tv.tv_sec * 1000 + tv.tv_usec / 1000; 110 } 111 112 /* Unsupported. */ 113 114 int16_t bsp_getTemp() 115 { 116 return 20; 117 }