Demo Team / Renard_UI_Only

Dependencies:   DebouncedInterrupt SharpLCD_LucidaFont mbed-src

Fork of Renard_UI_Only by Eric Gowland

Committer:
erigow01
Date:
Wed Jul 02 13:19:34 2014 +0000
Revision:
0:9bea6067730f
Basic UI working - needs some additional work on Icons, Layout

Who changed what in which revision?

UserRevisionLine numberNew contents of line
erigow01 0:9bea6067730f 1 // Copyright 2013 Pervasive Displays, Inc.
erigow01 0:9bea6067730f 2 //
erigow01 0:9bea6067730f 3 // Licensed under the Apache License, Version 2.0 (the "License");
erigow01 0:9bea6067730f 4 // you may not use this file except in compliance with the License.
erigow01 0:9bea6067730f 5 // You may obtain a copy of the License at:
erigow01 0:9bea6067730f 6 //
erigow01 0:9bea6067730f 7 // http://www.apache.org/licenses/LICENSE-2.0
erigow01 0:9bea6067730f 8 //
erigow01 0:9bea6067730f 9 // Unless required by applicable law or agreed to in writing,
erigow01 0:9bea6067730f 10 // software distributed under the License is distributed on an
erigow01 0:9bea6067730f 11 // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
erigow01 0:9bea6067730f 12 // express or implied. See the License for the specific language
erigow01 0:9bea6067730f 13 // governing permissions and limitations under the License.
erigow01 0:9bea6067730f 14
erigow01 0:9bea6067730f 15 #ifndef EPD_H
erigow01 0:9bea6067730f 16 #define EPD_H
erigow01 0:9bea6067730f 17
erigow01 0:9bea6067730f 18 #include "mbed.h"
erigow01 0:9bea6067730f 19
erigow01 0:9bea6067730f 20 #define PROGMEM
erigow01 0:9bea6067730f 21
erigow01 0:9bea6067730f 22
erigow01 0:9bea6067730f 23 typedef enum {
erigow01 0:9bea6067730f 24 EPD_1_44, // 128 x 96
erigow01 0:9bea6067730f 25 EPD_2_0, // 200 x 96
erigow01 0:9bea6067730f 26 EPD_2_7 // 264 x 176
erigow01 0:9bea6067730f 27 } EPD_size;
erigow01 0:9bea6067730f 28
erigow01 0:9bea6067730f 29 typedef enum { // Image pixel -> Display pixel
erigow01 0:9bea6067730f 30 EPD_compensate, // B -> W, W -> B (Current Image)
erigow01 0:9bea6067730f 31 EPD_white, // B -> N, W -> W (Current Image)
erigow01 0:9bea6067730f 32 EPD_inverse, // B -> N, W -> B (New Image)
erigow01 0:9bea6067730f 33 EPD_normal // B -> B, W -> W (New Image)
erigow01 0:9bea6067730f 34 } EPD_stage;
erigow01 0:9bea6067730f 35
erigow01 0:9bea6067730f 36 typedef void EPD_reader(void *buffer, uint32_t address, uint16_t length);
erigow01 0:9bea6067730f 37
erigow01 0:9bea6067730f 38 class EPD_Class {
erigow01 0:9bea6067730f 39 private:
erigow01 0:9bea6067730f 40 DigitalOut EPD_Pin_PANEL_ON;
erigow01 0:9bea6067730f 41 DigitalOut EPD_Pin_BORDER;
erigow01 0:9bea6067730f 42 DigitalOut EPD_Pin_DISCHARGE;
erigow01 0:9bea6067730f 43 PwmOut EPD_Pin_PWM;
erigow01 0:9bea6067730f 44 DigitalOut EPD_Pin_RESET;
erigow01 0:9bea6067730f 45 DigitalIn EPD_Pin_BUSY;
erigow01 0:9bea6067730f 46 DigitalOut EPD_Pin_EPD_CS;
erigow01 0:9bea6067730f 47 SPI spi_;
erigow01 0:9bea6067730f 48
erigow01 0:9bea6067730f 49 EPD_size size;
erigow01 0:9bea6067730f 50 uint16_t stage_time;
erigow01 0:9bea6067730f 51 uint16_t factored_stage_time;
erigow01 0:9bea6067730f 52 uint16_t lines_per_display;
erigow01 0:9bea6067730f 53 uint16_t dots_per_line;
erigow01 0:9bea6067730f 54 uint16_t bytes_per_line;
erigow01 0:9bea6067730f 55 uint16_t bytes_per_scan;
erigow01 0:9bea6067730f 56 PROGMEM const uint8_t *gate_source;
erigow01 0:9bea6067730f 57 uint16_t gate_source_length;
erigow01 0:9bea6067730f 58 PROGMEM const uint8_t *channel_select;
erigow01 0:9bea6067730f 59 uint16_t channel_select_length;
erigow01 0:9bea6067730f 60
erigow01 0:9bea6067730f 61 bool filler;
erigow01 0:9bea6067730f 62
erigow01 0:9bea6067730f 63 void SPI_put(uint8_t c);
erigow01 0:9bea6067730f 64 void SPI_put_wait(uint8_t c, DigitalIn busy_pin);
erigow01 0:9bea6067730f 65 void SPI_send(DigitalOut cs_pin, const uint8_t *buffer, uint16_t length);
erigow01 0:9bea6067730f 66
erigow01 0:9bea6067730f 67 public:
erigow01 0:9bea6067730f 68 // power up and power down the EPD panel
erigow01 0:9bea6067730f 69 void begin();
erigow01 0:9bea6067730f 70 void end();
erigow01 0:9bea6067730f 71
erigow01 0:9bea6067730f 72 void setFactor(int temperature = 25) {
erigow01 0:9bea6067730f 73 this->factored_stage_time = this->stage_time * this->temperature_to_factor_10x(temperature) / 10;
erigow01 0:9bea6067730f 74 }
erigow01 0:9bea6067730f 75
erigow01 0:9bea6067730f 76 // clear display (anything -> white)
erigow01 0:9bea6067730f 77 void clear() {
erigow01 0:9bea6067730f 78 this->frame_fixed_repeat(0xff, EPD_compensate);
erigow01 0:9bea6067730f 79 this->frame_fixed_repeat(0xff, EPD_white);
erigow01 0:9bea6067730f 80 this->frame_fixed_repeat(0xaa, EPD_inverse);
erigow01 0:9bea6067730f 81 this->frame_fixed_repeat(0xaa, EPD_normal);
erigow01 0:9bea6067730f 82 }
erigow01 0:9bea6067730f 83
erigow01 0:9bea6067730f 84 // assuming a clear (white) screen output an image (PROGMEM data)
erigow01 0:9bea6067730f 85 void image(const uint8_t *image) {
erigow01 0:9bea6067730f 86 this->frame_fixed_repeat(0xaa, EPD_compensate);
erigow01 0:9bea6067730f 87 this->frame_fixed_repeat(0xaa, EPD_white);
erigow01 0:9bea6067730f 88 this->frame_data_repeat(image, EPD_inverse);
erigow01 0:9bea6067730f 89 this->frame_data_repeat(image, EPD_normal);
erigow01 0:9bea6067730f 90 }
erigow01 0:9bea6067730f 91
erigow01 0:9bea6067730f 92 // change from old image to new image (PROGMEM data)
erigow01 0:9bea6067730f 93 void image(const uint8_t *old_image, const uint8_t *new_image) {
erigow01 0:9bea6067730f 94 this->frame_data_repeat(old_image, EPD_compensate);
erigow01 0:9bea6067730f 95 this->frame_data_repeat(old_image, EPD_white);
erigow01 0:9bea6067730f 96 this->frame_data_repeat(new_image, EPD_inverse);
erigow01 0:9bea6067730f 97 this->frame_data_repeat(new_image, EPD_normal);
erigow01 0:9bea6067730f 98 }
erigow01 0:9bea6067730f 99
erigow01 0:9bea6067730f 100 #if defined(EPD_ENABLE_EXTRA_SRAM)
erigow01 0:9bea6067730f 101
erigow01 0:9bea6067730f 102 // change from old image to new image (SRAM version)
erigow01 0:9bea6067730f 103 void image_sram(const uint8_t *old_image, const uint8_t *new_image) {
erigow01 0:9bea6067730f 104 this->frame_sram_repeat(old_image, EPD_compensate);
erigow01 0:9bea6067730f 105 this->frame_sram_repeat(old_image, EPD_white);
erigow01 0:9bea6067730f 106 this->frame_sram_repeat(new_image, EPD_inverse);
erigow01 0:9bea6067730f 107 this->frame_sram_repeat(new_image, EPD_normal);
erigow01 0:9bea6067730f 108 }
erigow01 0:9bea6067730f 109 #endif
erigow01 0:9bea6067730f 110
erigow01 0:9bea6067730f 111 // Low level API calls
erigow01 0:9bea6067730f 112 // ===================
erigow01 0:9bea6067730f 113
erigow01 0:9bea6067730f 114 // single frame refresh
erigow01 0:9bea6067730f 115 void frame_fixed(uint8_t fixed_value, EPD_stage stage);
erigow01 0:9bea6067730f 116 void frame_data(const uint8_t *new_image, EPD_stage stage);
erigow01 0:9bea6067730f 117 #if defined(EPD_ENABLE_EXTRA_SRAM)
erigow01 0:9bea6067730f 118 void frame_sram(const uint8_t *new_image, EPD_stage stage);
erigow01 0:9bea6067730f 119 #endif
erigow01 0:9bea6067730f 120 void frame_cb(uint32_t address, EPD_reader *reader, EPD_stage stage);
erigow01 0:9bea6067730f 121
erigow01 0:9bea6067730f 122 // stage_time frame refresh
erigow01 0:9bea6067730f 123 void frame_fixed_repeat(uint8_t fixed_value, EPD_stage stage);
erigow01 0:9bea6067730f 124 void frame_data_repeat(const uint8_t *new_image, EPD_stage stage);
erigow01 0:9bea6067730f 125 #if defined(EPD_ENABLE_EXTRA_SRAM)
erigow01 0:9bea6067730f 126 void frame_sram_repeat(const uint8_t *new_image, EPD_stage stage);
erigow01 0:9bea6067730f 127 #endif
erigow01 0:9bea6067730f 128 void frame_cb_repeat(uint32_t address, EPD_reader *reader, EPD_stage stage);
erigow01 0:9bea6067730f 129
erigow01 0:9bea6067730f 130 // convert temperature to compensation factor
erigow01 0:9bea6067730f 131 int temperature_to_factor_10x(int temperature);
erigow01 0:9bea6067730f 132
erigow01 0:9bea6067730f 133 // single line display - very low-level
erigow01 0:9bea6067730f 134 // also has to handle AVR progmem
erigow01 0:9bea6067730f 135 void line(uint16_t line, const uint8_t *data, uint8_t fixed_value, bool read_progmem, EPD_stage stage);
erigow01 0:9bea6067730f 136
erigow01 0:9bea6067730f 137 // inline static void attachInterrupt();
erigow01 0:9bea6067730f 138 // inline static void detachInterrupt();
erigow01 0:9bea6067730f 139
erigow01 0:9bea6067730f 140 EPD_Class(EPD_size size,
erigow01 0:9bea6067730f 141 PinName panel_on_pin,
erigow01 0:9bea6067730f 142 PinName border_pin,
erigow01 0:9bea6067730f 143 PinName discharge_pin,
erigow01 0:9bea6067730f 144 PinName pwm_pin,
erigow01 0:9bea6067730f 145 PinName reset_pin,
erigow01 0:9bea6067730f 146 PinName busy_pin,
erigow01 0:9bea6067730f 147 PinName chip_select_pin,
erigow01 0:9bea6067730f 148 PinName mosi,
erigow01 0:9bea6067730f 149 PinName miso,
erigow01 0:9bea6067730f 150 PinName sck);
erigow01 0:9bea6067730f 151
erigow01 0:9bea6067730f 152 };
erigow01 0:9bea6067730f 153
erigow01 0:9bea6067730f 154 #endif
erigow01 0:9bea6067730f 155