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 39 void EPD_Pin_init() 40 { 41 OUT(UBB_DAT2); 42 OUT(UBB_DAT3); 43 OUT(UBB_CMD); 44 OUT(UBB_CLK); 45 OUT(UBB_DAT0); 46 OUT(UBB_DAT1); 47 48 CLR(UBB_DAT2); 49 CLR(UBB_DAT3); 50 CLR(UBB_CMD); 51 CLR(UBB_CLK); 52 CLR(UBB_DAT0); 53 CLR(UBB_DAT1); 54 } 55 56 void EPD_Pin_EPD_CS(EPD_pinstate pin) 57 { 58 if (pin == HIGH) 59 SET(EPD_SSEL); 60 else 61 CLR(EPD_SSEL); 62 } 63 64 void EPD_Pin_RESET(EPD_pinstate pin) 65 { 66 if (pin == HIGH) 67 SET(EPD_RESET); 68 else 69 CLR(EPD_RESET); 70 printf("RESET = %d\n", pin); 71 } 72 73 void EPD_Pin_PANEL_ON(EPD_pinstate pin) 74 { 75 if (pin == HIGH) 76 ubb_power(1); 77 else 78 ubb_power(0); 79 printf("PANEL = %d\n", pin); 80 } 81 82 void EPD_Pin_DISCHARGE(EPD_pinstate pin) 83 { 84 if (pin == HIGH) 85 SET(EPD_DIS); 86 else 87 CLR(EPD_DIS); 88 printf("DIS = %d\n", pin); 89 } 90 91 void EPD_Pin_BORDER(EPD_pinstate pin) 92 { 93 } 94 95 void EPD_Pin_PWM(EPD_pinstate pin) 96 { 97 if (pin == HIGH) 98 SET(EPD_PWM); 99 else 100 CLR(EPD_PWM); 101 } 102 103 EPD_pinstate epd_get_busy() 104 { 105 bsp_delayUs(1); 106 return LOW; 107 } 108 109 void bsp_spiWrite(uint8_t *buffer, uint16_t length) 110 { 111 uint8_t mask, *ptr, *limit = buffer + length; 112 113 for (ptr = buffer; ptr < limit; ptr++) 114 { 115 for (mask = 0x80; mask; mask >>= 1) 116 { 117 if (*(ptr) & mask) 118 { 119 SET(EPD_MOSI); 120 } 121 else 122 { 123 CLR(EPD_MOSI); 124 } 125 126 SET(EPD_SCK); 127 CLR(EPD_SCK); 128 } 129 } 130 } 131 132 void bsp_delayMs(uint32_t ms) 133 { 134 bsp_delayUs(ms * 1000); 135 } 136 137 void bsp_delayUs(uint32_t us) 138 { 139 /* uint32_t now = bsp_getUsTicks(); */ 140 141 /* while (bsp_getUsTicks() - now < us); */ 142 143 uint32_t count = us * 24; 144 while (count--); 145 } 146 147 uint32_t bsp_getMsTicks() 148 { 149 struct timeval tv; 150 gettimeofday(&tv, NULL); 151 return tv.tv_sec * 1000 + tv.tv_usec / 1000; 152 } 153 154 uint32_t bsp_getUsTicks() 155 { 156 struct timeval tv; 157 gettimeofday(&tv, NULL); 158 return tv.tv_sec * 1000000 + tv.tv_usec; 159 } 160 161 int16_t bsp_getTemp() 162 { 163 return 20; 164 }