Come from standard seeed epaper, but adding SPI signal in construtor
Fork of seeedstudio-epaper by
EPD.h@2:c5bb7d34974d, 2015-11-13 (annotated)
- Committer:
- thierryc49
- Date:
- Fri Nov 13 20:46:53 2015 +0000
- Revision:
- 2:c5bb7d34974d
- Parent:
- 1:2f62e2b80305
lib from seedstudio-epaper, Add SPI in parameter's constructor
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 | 1:2f62e2b80305 | 15 | #ifndef __EPD_H__ |
sigveseb | 1:2f62e2b80305 | 16 | #define __EPD_H__ |
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 | typedef enum { |
sigveseb | 0:6ac5ba1343bf | 22 | EPD_1_44, // 128 x 96 |
sigveseb | 0:6ac5ba1343bf | 23 | EPD_2_0, // 200 x 96 |
sigveseb | 0:6ac5ba1343bf | 24 | EPD_2_7 // 264 x 176 |
sigveseb | 0:6ac5ba1343bf | 25 | } EPD_size; |
sigveseb | 0:6ac5ba1343bf | 26 | |
sigveseb | 0:6ac5ba1343bf | 27 | typedef enum { // Image pixel -> Display pixel |
sigveseb | 0:6ac5ba1343bf | 28 | EPD_compensate, // B -> W, W -> B (Current Image) |
sigveseb | 0:6ac5ba1343bf | 29 | EPD_white, // B -> N, W -> W (Current Image) |
sigveseb | 0:6ac5ba1343bf | 30 | EPD_inverse, // B -> N, W -> B (New Image) |
sigveseb | 0:6ac5ba1343bf | 31 | EPD_normal // B -> B, W -> W (New Image) |
sigveseb | 0:6ac5ba1343bf | 32 | } EPD_stage; |
sigveseb | 0:6ac5ba1343bf | 33 | |
sigveseb | 0:6ac5ba1343bf | 34 | typedef void EPD_reader(void *buffer, uint32_t address, uint16_t length); |
sigveseb | 0:6ac5ba1343bf | 35 | |
sigveseb | 0:6ac5ba1343bf | 36 | class EPD_Class |
sigveseb | 0:6ac5ba1343bf | 37 | { |
sigveseb | 0:6ac5ba1343bf | 38 | public: |
sigveseb | 0:6ac5ba1343bf | 39 | uint16_t lines_per_display; |
sigveseb | 0:6ac5ba1343bf | 40 | |
sigveseb | 0:6ac5ba1343bf | 41 | private: |
sigveseb | 0:6ac5ba1343bf | 42 | |
sigveseb | 0:6ac5ba1343bf | 43 | DigitalOut EPD_Pin_EPD_CS; |
sigveseb | 0:6ac5ba1343bf | 44 | DigitalOut EPD_Pin_PANEL_ON; |
sigveseb | 0:6ac5ba1343bf | 45 | DigitalOut EPD_Pin_BORDER; |
sigveseb | 0:6ac5ba1343bf | 46 | DigitalOut EPD_Pin_DISCHARGE; |
sigveseb | 0:6ac5ba1343bf | 47 | PwmOut EPD_Pin_PWM; |
sigveseb | 0:6ac5ba1343bf | 48 | DigitalOut EPD_Pin_RESET; |
sigveseb | 0:6ac5ba1343bf | 49 | DigitalIn EPD_Pin_BUSY; |
thierryc49 | 2:c5bb7d34974d | 50 | SPI spi; |
sigveseb | 0:6ac5ba1343bf | 51 | EPD_size size; |
sigveseb | 0:6ac5ba1343bf | 52 | uint16_t stage_time; |
sigveseb | 0:6ac5ba1343bf | 53 | |
sigveseb | 0:6ac5ba1343bf | 54 | uint16_t factored_stage_time; |
sigveseb | 0:6ac5ba1343bf | 55 | uint16_t dots_per_line; |
sigveseb | 0:6ac5ba1343bf | 56 | uint16_t bytes_per_line; |
sigveseb | 0:6ac5ba1343bf | 57 | uint16_t bytes_per_scan; |
sigveseb | 0:6ac5ba1343bf | 58 | const uint8_t *gate_source; |
sigveseb | 0:6ac5ba1343bf | 59 | uint16_t gate_source_length; |
sigveseb | 0:6ac5ba1343bf | 60 | const uint8_t *channel_select; |
sigveseb | 0:6ac5ba1343bf | 61 | uint16_t channel_select_length; |
sigveseb | 0:6ac5ba1343bf | 62 | |
sigveseb | 0:6ac5ba1343bf | 63 | bool filler; |
sigveseb | 0:6ac5ba1343bf | 64 | |
thierryc49 | 2:c5bb7d34974d | 65 | void SPI_put(uint8_t c); |
thierryc49 | 2:c5bb7d34974d | 66 | void SPI_put_wait(uint8_t c, DigitalIn busy_pin); |
thierryc49 | 2:c5bb7d34974d | 67 | void SPI_send(DigitalOut cs_pin, const uint8_t *buffer, uint16_t length); |
thierryc49 | 2:c5bb7d34974d | 68 | void SPI_on(); |
thierryc49 | 2:c5bb7d34974d | 69 | |
sigveseb | 0:6ac5ba1343bf | 70 | public: |
sigveseb | 0:6ac5ba1343bf | 71 | unsigned char lineDta[33]; |
sigveseb | 0:6ac5ba1343bf | 72 | |
sigveseb | 0:6ac5ba1343bf | 73 | public: |
sigveseb | 0:6ac5ba1343bf | 74 | 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); |
thierryc49 | 2:c5bb7d34974d | 75 | 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,PinName Pin_MOSI,PinName Pin_MISO,PinName Pin_CLK); |
sigveseb | 0:6ac5ba1343bf | 76 | // power up and power down the EPD panel |
sigveseb | 0:6ac5ba1343bf | 77 | void begin(EPD_size sz); |
sigveseb | 0:6ac5ba1343bf | 78 | void start(); |
sigveseb | 0:6ac5ba1343bf | 79 | void end(); |
sigveseb | 0:6ac5ba1343bf | 80 | |
sigveseb | 0:6ac5ba1343bf | 81 | void setFactor(int temperature = 25) { |
sigveseb | 0:6ac5ba1343bf | 82 | this->factored_stage_time = this->stage_time * this->temperature_to_factor_10x(temperature) / 10; |
sigveseb | 0:6ac5ba1343bf | 83 | } |
sigveseb | 0:6ac5ba1343bf | 84 | |
sigveseb | 0:6ac5ba1343bf | 85 | // clear display (anything -> white) |
sigveseb | 0:6ac5ba1343bf | 86 | void clear(int from_line = 0, int to_line = -1) |
sigveseb | 0:6ac5ba1343bf | 87 | { |
sigveseb | 0:6ac5ba1343bf | 88 | if(to_line == -1){ |
sigveseb | 0:6ac5ba1343bf | 89 | to_line = this->lines_per_display; |
sigveseb | 0:6ac5ba1343bf | 90 | } |
sigveseb | 0:6ac5ba1343bf | 91 | this->frame_fixed_repeat(0xff, EPD_compensate, from_line, to_line); |
sigveseb | 0:6ac5ba1343bf | 92 | this->frame_fixed_repeat(0xff, EPD_white, from_line, to_line); |
sigveseb | 0:6ac5ba1343bf | 93 | this->frame_fixed_repeat(0xaa, EPD_inverse, from_line, to_line); |
sigveseb | 0:6ac5ba1343bf | 94 | this->frame_fixed_repeat(0xaa, EPD_normal, from_line, to_line); |
sigveseb | 0:6ac5ba1343bf | 95 | } |
sigveseb | 0:6ac5ba1343bf | 96 | |
sigveseb | 1:2f62e2b80305 | 97 | // assuming a clear (white) screen output an image |
sigveseb | 0:6ac5ba1343bf | 98 | void image(const uint8_t *image, int from_line = 0, int to_line = -1) |
sigveseb | 0:6ac5ba1343bf | 99 | { |
sigveseb | 0:6ac5ba1343bf | 100 | if(to_line == -1){ |
sigveseb | 0:6ac5ba1343bf | 101 | to_line = this->lines_per_display; |
sigveseb | 0:6ac5ba1343bf | 102 | } |
sigveseb | 0:6ac5ba1343bf | 103 | this->frame_fixed_repeat(0xaa, EPD_compensate, from_line, to_line); |
sigveseb | 0:6ac5ba1343bf | 104 | this->frame_fixed_repeat(0xaa, EPD_white, from_line, to_line); |
sigveseb | 0:6ac5ba1343bf | 105 | this->frame_data_repeat(image, EPD_inverse, from_line, to_line); |
sigveseb | 0:6ac5ba1343bf | 106 | this->frame_data_repeat(image, EPD_normal, from_line, to_line); |
sigveseb | 0:6ac5ba1343bf | 107 | } |
sigveseb | 0:6ac5ba1343bf | 108 | |
sigveseb | 0:6ac5ba1343bf | 109 | |
sigveseb | 0:6ac5ba1343bf | 110 | |
sigveseb | 0:6ac5ba1343bf | 111 | // Low level API calls |
sigveseb | 0:6ac5ba1343bf | 112 | // =================== |
sigveseb | 0:6ac5ba1343bf | 113 | |
sigveseb | 0:6ac5ba1343bf | 114 | // single frame refresh |
sigveseb | 0:6ac5ba1343bf | 115 | void frame_fixed(uint8_t fixed_value, EPD_stage stage, int from_line, int to_line); |
sigveseb | 0:6ac5ba1343bf | 116 | void frame_data(const uint8_t *new_image, EPD_stage stage, int from_line, int to_line); |
sigveseb | 0:6ac5ba1343bf | 117 | |
sigveseb | 0:6ac5ba1343bf | 118 | // stage_time frame refresh |
sigveseb | 0:6ac5ba1343bf | 119 | void frame_fixed_repeat(uint8_t fixed_value, EPD_stage stage, int from_line, int to_line); |
sigveseb | 0:6ac5ba1343bf | 120 | void frame_data_repeat(const uint8_t *new_image, EPD_stage stage, int from_line, int to_line); |
sigveseb | 0:6ac5ba1343bf | 121 | |
sigveseb | 0:6ac5ba1343bf | 122 | // convert temperature to compensation factor |
sigveseb | 0:6ac5ba1343bf | 123 | int temperature_to_factor_10x(int temperature); |
sigveseb | 0:6ac5ba1343bf | 124 | |
sigveseb | 0:6ac5ba1343bf | 125 | // single line display - very low-level |
sigveseb | 0:6ac5ba1343bf | 126 | void line(uint16_t line, const uint8_t *data, uint8_t fixed_value, bool read_progmem, EPD_stage stage); |
sigveseb | 0:6ac5ba1343bf | 127 | }; |
sigveseb | 0:6ac5ba1343bf | 128 | |
sigveseb | 0:6ac5ba1343bf | 129 | extern EPD_Class EPD; |
sigveseb | 0:6ac5ba1343bf | 130 | |
sigveseb | 1:2f62e2b80305 | 131 | #endif |