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