Come from standard seeed epaper, but adding SPI signal in construtor
Fork of seeedstudio-epaper by
EPD.h@0:6ac5ba1343bf, 2014-07-17 (annotated)
- Committer:
- sigveseb
- Date:
- Thu Jul 17 14:15:53 2014 +0000
- Revision:
- 0:6ac5ba1343bf
- Child:
- 1:2f62e2b80305
-
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
sigveseb | 0:6ac5ba1343bf | 1 | // Copyright 2013 Pervasive Displays, Inc. |
sigveseb | 0:6ac5ba1343bf | 2 | // |
sigveseb | 0:6ac5ba1343bf | 3 | // Licensed under the Apache License, Version 2.0 (the "License"); |
sigveseb | 0:6ac5ba1343bf | 4 | // you may not use this file except in compliance with the License. |
sigveseb | 0:6ac5ba1343bf | 5 | // You may obtain a copy of the License at: |
sigveseb | 0:6ac5ba1343bf | 6 | // |
sigveseb | 0:6ac5ba1343bf | 7 | // http://www.apache.org/licenses/LICENSE-2.0 |
sigveseb | 0:6ac5ba1343bf | 8 | // |
sigveseb | 0:6ac5ba1343bf | 9 | // Unless required by applicable law or agreed to in writing, |
sigveseb | 0:6ac5ba1343bf | 10 | // software distributed under the License is distributed on an |
sigveseb | 0:6ac5ba1343bf | 11 | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either |
sigveseb | 0:6ac5ba1343bf | 12 | // express or implied. See the License for the specific language |
sigveseb | 0:6ac5ba1343bf | 13 | // governing permissions and limitations under the License. |
sigveseb | 0:6ac5ba1343bf | 14 | |
sigveseb | 0:6ac5ba1343bf | 15 | #if !defined(EPD_H) |
sigveseb | 0:6ac5ba1343bf | 16 | #define EPD_H 1 |
sigveseb | 0:6ac5ba1343bf | 17 | |
sigveseb | 0:6ac5ba1343bf | 18 | #include <SPI.h> |
sigveseb | 0:6ac5ba1343bf | 19 | #include <mbed.h> |
sigveseb | 0:6ac5ba1343bf | 20 | |
sigveseb | 0:6ac5ba1343bf | 21 | |
sigveseb | 0:6ac5ba1343bf | 22 | // if more SRAM available (8 kBytes) |
sigveseb | 0:6ac5ba1343bf | 23 | #define EPD_ENABLE_EXTRA_SRAM 1 |
sigveseb | 0:6ac5ba1343bf | 24 | |
sigveseb | 0:6ac5ba1343bf | 25 | typedef enum { |
sigveseb | 0:6ac5ba1343bf | 26 | EPD_1_44, // 128 x 96 |
sigveseb | 0:6ac5ba1343bf | 27 | EPD_2_0, // 200 x 96 |
sigveseb | 0:6ac5ba1343bf | 28 | EPD_2_7 // 264 x 176 |
sigveseb | 0:6ac5ba1343bf | 29 | } EPD_size; |
sigveseb | 0:6ac5ba1343bf | 30 | |
sigveseb | 0:6ac5ba1343bf | 31 | typedef enum { // Image pixel -> Display pixel |
sigveseb | 0:6ac5ba1343bf | 32 | EPD_compensate, // B -> W, W -> B (Current Image) |
sigveseb | 0:6ac5ba1343bf | 33 | EPD_white, // B -> N, W -> W (Current Image) |
sigveseb | 0:6ac5ba1343bf | 34 | EPD_inverse, // B -> N, W -> B (New Image) |
sigveseb | 0:6ac5ba1343bf | 35 | EPD_normal // B -> B, W -> W (New Image) |
sigveseb | 0:6ac5ba1343bf | 36 | } EPD_stage; |
sigveseb | 0:6ac5ba1343bf | 37 | |
sigveseb | 0:6ac5ba1343bf | 38 | typedef void EPD_reader(void *buffer, uint32_t address, uint16_t length); |
sigveseb | 0:6ac5ba1343bf | 39 | |
sigveseb | 0:6ac5ba1343bf | 40 | class EPD_Class |
sigveseb | 0:6ac5ba1343bf | 41 | { |
sigveseb | 0:6ac5ba1343bf | 42 | public: |
sigveseb | 0:6ac5ba1343bf | 43 | uint16_t lines_per_display; |
sigveseb | 0:6ac5ba1343bf | 44 | |
sigveseb | 0:6ac5ba1343bf | 45 | private: |
sigveseb | 0:6ac5ba1343bf | 46 | |
sigveseb | 0:6ac5ba1343bf | 47 | DigitalOut EPD_Pin_EPD_CS; |
sigveseb | 0:6ac5ba1343bf | 48 | DigitalOut EPD_Pin_PANEL_ON; |
sigveseb | 0:6ac5ba1343bf | 49 | DigitalOut EPD_Pin_BORDER; |
sigveseb | 0:6ac5ba1343bf | 50 | DigitalOut EPD_Pin_DISCHARGE; |
sigveseb | 0:6ac5ba1343bf | 51 | PwmOut EPD_Pin_PWM; |
sigveseb | 0:6ac5ba1343bf | 52 | DigitalOut EPD_Pin_RESET; |
sigveseb | 0:6ac5ba1343bf | 53 | DigitalIn EPD_Pin_BUSY; |
sigveseb | 0:6ac5ba1343bf | 54 | |
sigveseb | 0:6ac5ba1343bf | 55 | EPD_size size; |
sigveseb | 0:6ac5ba1343bf | 56 | uint16_t stage_time; |
sigveseb | 0:6ac5ba1343bf | 57 | |
sigveseb | 0:6ac5ba1343bf | 58 | uint16_t factored_stage_time; |
sigveseb | 0:6ac5ba1343bf | 59 | uint16_t dots_per_line; |
sigveseb | 0:6ac5ba1343bf | 60 | uint16_t bytes_per_line; |
sigveseb | 0:6ac5ba1343bf | 61 | uint16_t bytes_per_scan; |
sigveseb | 0:6ac5ba1343bf | 62 | const uint8_t *gate_source; |
sigveseb | 0:6ac5ba1343bf | 63 | uint16_t gate_source_length; |
sigveseb | 0:6ac5ba1343bf | 64 | const uint8_t *channel_select; |
sigveseb | 0:6ac5ba1343bf | 65 | uint16_t channel_select_length; |
sigveseb | 0:6ac5ba1343bf | 66 | |
sigveseb | 0:6ac5ba1343bf | 67 | bool filler; |
sigveseb | 0:6ac5ba1343bf | 68 | |
sigveseb | 0:6ac5ba1343bf | 69 | public: |
sigveseb | 0:6ac5ba1343bf | 70 | unsigned char lineDta[33]; |
sigveseb | 0:6ac5ba1343bf | 71 | |
sigveseb | 0:6ac5ba1343bf | 72 | public: |
sigveseb | 0:6ac5ba1343bf | 73 | EPD_Class(PinName Pin_EPD_CS, PinName Pin_PANEL_ON, PinName Pin_BORDER, PinName Pin_DISCHARGE, PinName Pin_PWM, PinName Pin_RESET, PinName Pin_BUSY); |
sigveseb | 0:6ac5ba1343bf | 74 | // power up and power down the EPD panel |
sigveseb | 0:6ac5ba1343bf | 75 | void begin(EPD_size sz); |
sigveseb | 0:6ac5ba1343bf | 76 | void start(); |
sigveseb | 0:6ac5ba1343bf | 77 | void end(); |
sigveseb | 0:6ac5ba1343bf | 78 | |
sigveseb | 0:6ac5ba1343bf | 79 | void setFactor(int temperature = 25) { |
sigveseb | 0:6ac5ba1343bf | 80 | this->factored_stage_time = this->stage_time * this->temperature_to_factor_10x(temperature) / 10; |
sigveseb | 0:6ac5ba1343bf | 81 | } |
sigveseb | 0:6ac5ba1343bf | 82 | |
sigveseb | 0:6ac5ba1343bf | 83 | // clear display (anything -> white) |
sigveseb | 0:6ac5ba1343bf | 84 | void clear(int from_line = 0, int to_line = -1) |
sigveseb | 0:6ac5ba1343bf | 85 | { |
sigveseb | 0:6ac5ba1343bf | 86 | if(to_line == -1){ |
sigveseb | 0:6ac5ba1343bf | 87 | to_line = this->lines_per_display; |
sigveseb | 0:6ac5ba1343bf | 88 | } |
sigveseb | 0:6ac5ba1343bf | 89 | this->frame_fixed_repeat(0xff, EPD_compensate, from_line, to_line); |
sigveseb | 0:6ac5ba1343bf | 90 | this->frame_fixed_repeat(0xff, EPD_white, from_line, to_line); |
sigveseb | 0:6ac5ba1343bf | 91 | this->frame_fixed_repeat(0xaa, EPD_inverse, from_line, to_line); |
sigveseb | 0:6ac5ba1343bf | 92 | this->frame_fixed_repeat(0xaa, EPD_normal, from_line, to_line); |
sigveseb | 0:6ac5ba1343bf | 93 | } |
sigveseb | 0:6ac5ba1343bf | 94 | |
sigveseb | 0:6ac5ba1343bf | 95 | // assuming a clear (white) screen output an image (PROGMEM data) |
sigveseb | 0:6ac5ba1343bf | 96 | void image(const uint8_t *image, int from_line = 0, int to_line = -1) |
sigveseb | 0:6ac5ba1343bf | 97 | { |
sigveseb | 0:6ac5ba1343bf | 98 | if(to_line == -1){ |
sigveseb | 0:6ac5ba1343bf | 99 | to_line = this->lines_per_display; |
sigveseb | 0:6ac5ba1343bf | 100 | } |
sigveseb | 0:6ac5ba1343bf | 101 | this->frame_fixed_repeat(0xaa, EPD_compensate, from_line, to_line); |
sigveseb | 0:6ac5ba1343bf | 102 | this->frame_fixed_repeat(0xaa, EPD_white, from_line, to_line); |
sigveseb | 0:6ac5ba1343bf | 103 | this->frame_data_repeat(image, EPD_inverse, from_line, to_line); |
sigveseb | 0:6ac5ba1343bf | 104 | this->frame_data_repeat(image, EPD_normal, from_line, to_line); |
sigveseb | 0:6ac5ba1343bf | 105 | } |
sigveseb | 0:6ac5ba1343bf | 106 | |
sigveseb | 0:6ac5ba1343bf | 107 | #if defined(__AVR_ATmega32U4__) || defined(__AVR_ATmega328P__) |
sigveseb | 0:6ac5ba1343bf | 108 | void image_sd() |
sigveseb | 0:6ac5ba1343bf | 109 | { |
sigveseb | 0:6ac5ba1343bf | 110 | this->frame_fixed_repeat(0xaa, EPD_compensate); |
sigveseb | 0:6ac5ba1343bf | 111 | this->frame_fixed_repeat(0xaa, EPD_white); |
sigveseb | 0:6ac5ba1343bf | 112 | this->frame_data_repeat_sd(EPD_inverse); |
sigveseb | 0:6ac5ba1343bf | 113 | this->frame_data_repeat_sd(EPD_normal); |
sigveseb | 0:6ac5ba1343bf | 114 | } |
sigveseb | 0:6ac5ba1343bf | 115 | #endif |
sigveseb | 0:6ac5ba1343bf | 116 | // change from old image to new image (PROGMEM data) |
sigveseb | 0:6ac5ba1343bf | 117 | /* |
sigveseb | 0:6ac5ba1343bf | 118 | void image(const uint8_t *old_image, const uint8_t *new_image) |
sigveseb | 0:6ac5ba1343bf | 119 | { |
sigveseb | 0:6ac5ba1343bf | 120 | this->frame_data_repeat(old_image, EPD_compensate); |
sigveseb | 0:6ac5ba1343bf | 121 | this->frame_data_repeat(old_image, EPD_white); |
sigveseb | 0:6ac5ba1343bf | 122 | this->frame_data_repeat(new_image, EPD_inverse); |
sigveseb | 0:6ac5ba1343bf | 123 | this->frame_data_repeat(new_image, EPD_normal); |
sigveseb | 0:6ac5ba1343bf | 124 | } |
sigveseb | 0:6ac5ba1343bf | 125 | */ |
sigveseb | 0:6ac5ba1343bf | 126 | |
sigveseb | 0:6ac5ba1343bf | 127 | |
sigveseb | 0:6ac5ba1343bf | 128 | // Low level API calls |
sigveseb | 0:6ac5ba1343bf | 129 | // =================== |
sigveseb | 0:6ac5ba1343bf | 130 | |
sigveseb | 0:6ac5ba1343bf | 131 | // single frame refresh |
sigveseb | 0:6ac5ba1343bf | 132 | void frame_fixed(uint8_t fixed_value, EPD_stage stage, int from_line, int to_line); |
sigveseb | 0:6ac5ba1343bf | 133 | void frame_data(const uint8_t *new_image, EPD_stage stage, int from_line, int to_line); |
sigveseb | 0:6ac5ba1343bf | 134 | #if defined(__AVR_ATmega32U4__) || defined(__AVR_ATmega328P__) |
sigveseb | 0:6ac5ba1343bf | 135 | void frame_data_sd(EPD_stage stage); |
sigveseb | 0:6ac5ba1343bf | 136 | #endif |
sigveseb | 0:6ac5ba1343bf | 137 | |
sigveseb | 0:6ac5ba1343bf | 138 | #if defined(EPD_ENABLE_EXTRA_SRAM) |
sigveseb | 0:6ac5ba1343bf | 139 | void frame_sram(const uint8_t *new_image, EPD_stage stage); |
sigveseb | 0:6ac5ba1343bf | 140 | #endif |
sigveseb | 0:6ac5ba1343bf | 141 | void frame_cb(uint32_t address, EPD_reader *reader, EPD_stage stage); |
sigveseb | 0:6ac5ba1343bf | 142 | |
sigveseb | 0:6ac5ba1343bf | 143 | // stage_time frame refresh |
sigveseb | 0:6ac5ba1343bf | 144 | void frame_fixed_repeat(uint8_t fixed_value, EPD_stage stage, int from_line, int to_line); |
sigveseb | 0:6ac5ba1343bf | 145 | void frame_data_repeat(const uint8_t *new_image, EPD_stage stage, int from_line, int to_line); |
sigveseb | 0:6ac5ba1343bf | 146 | #if defined(__AVR_ATmega32U4__) || defined(__AVR_ATmega328P__) |
sigveseb | 0:6ac5ba1343bf | 147 | void frame_data_repeat_sd(EPD_stage stage); |
sigveseb | 0:6ac5ba1343bf | 148 | #endif |
sigveseb | 0:6ac5ba1343bf | 149 | |
sigveseb | 0:6ac5ba1343bf | 150 | #if defined(EPD_ENABLE_EXTRA_SRAM) |
sigveseb | 0:6ac5ba1343bf | 151 | void frame_sram_repeat(const uint8_t *new_image, EPD_stage stage); |
sigveseb | 0:6ac5ba1343bf | 152 | #endif |
sigveseb | 0:6ac5ba1343bf | 153 | void frame_cb_repeat(uint32_t address, EPD_reader *reader, EPD_stage stage); |
sigveseb | 0:6ac5ba1343bf | 154 | |
sigveseb | 0:6ac5ba1343bf | 155 | // convert temperature to compensation factor |
sigveseb | 0:6ac5ba1343bf | 156 | int temperature_to_factor_10x(int temperature); |
sigveseb | 0:6ac5ba1343bf | 157 | |
sigveseb | 0:6ac5ba1343bf | 158 | // single line display - very low-level |
sigveseb | 0:6ac5ba1343bf | 159 | // also has to handle AVR progmem |
sigveseb | 0:6ac5ba1343bf | 160 | void line(uint16_t line, const uint8_t *data, uint8_t fixed_value, bool read_progmem, EPD_stage stage); |
sigveseb | 0:6ac5ba1343bf | 161 | #if defined(__AVR_ATmega32U4__) || defined(__AVR_ATmega328P__) |
sigveseb | 0:6ac5ba1343bf | 162 | void line_sd(uint16_t line, const uint8_t *data, uint8_t fixed_value, bool read_progmem, EPD_stage stage); |
sigveseb | 0:6ac5ba1343bf | 163 | #endif |
sigveseb | 0:6ac5ba1343bf | 164 | }; |
sigveseb | 0:6ac5ba1343bf | 165 | |
sigveseb | 0:6ac5ba1343bf | 166 | extern EPD_Class EPD; |
sigveseb | 0:6ac5ba1343bf | 167 | |
sigveseb | 0:6ac5ba1343bf | 168 | #endif |