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