Come from standard seeed epaper, but adding SPI signal in construtor

Fork of seeedstudio-epaper by Nordic Pucks

Committer:
sigveseb
Date:
Fri Jul 18 09:20:24 2014 +0000
Revision:
1:2f62e2b80305
Parent:
0:6ac5ba1343bf
Child:
2:c5bb7d34974d
clean up;

Who changed what in which revision?

UserRevisionLine numberNew 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;
sigveseb 0:6ac5ba1343bf 50
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
sigveseb 0:6ac5ba1343bf 65 public:
sigveseb 0:6ac5ba1343bf 66 unsigned char lineDta[33];
sigveseb 0:6ac5ba1343bf 67
sigveseb 0:6ac5ba1343bf 68 public:
sigveseb 0:6ac5ba1343bf 69 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 70 // power up and power down the EPD panel
sigveseb 0:6ac5ba1343bf 71 void begin(EPD_size sz);
sigveseb 0:6ac5ba1343bf 72 void start();
sigveseb 0:6ac5ba1343bf 73 void end();
sigveseb 0:6ac5ba1343bf 74
sigveseb 0:6ac5ba1343bf 75 void setFactor(int temperature = 25) {
sigveseb 0:6ac5ba1343bf 76 this->factored_stage_time = this->stage_time * this->temperature_to_factor_10x(temperature) / 10;
sigveseb 0:6ac5ba1343bf 77 }
sigveseb 0:6ac5ba1343bf 78
sigveseb 0:6ac5ba1343bf 79 // clear display (anything -> white)
sigveseb 0:6ac5ba1343bf 80 void clear(int from_line = 0, int to_line = -1)
sigveseb 0:6ac5ba1343bf 81 {
sigveseb 0:6ac5ba1343bf 82 if(to_line == -1){
sigveseb 0:6ac5ba1343bf 83 to_line = this->lines_per_display;
sigveseb 0:6ac5ba1343bf 84 }
sigveseb 0:6ac5ba1343bf 85 this->frame_fixed_repeat(0xff, EPD_compensate, from_line, to_line);
sigveseb 0:6ac5ba1343bf 86 this->frame_fixed_repeat(0xff, EPD_white, from_line, to_line);
sigveseb 0:6ac5ba1343bf 87 this->frame_fixed_repeat(0xaa, EPD_inverse, from_line, to_line);
sigveseb 0:6ac5ba1343bf 88 this->frame_fixed_repeat(0xaa, EPD_normal, from_line, to_line);
sigveseb 0:6ac5ba1343bf 89 }
sigveseb 0:6ac5ba1343bf 90
sigveseb 1:2f62e2b80305 91 // assuming a clear (white) screen output an image
sigveseb 0:6ac5ba1343bf 92 void image(const uint8_t *image, int from_line = 0, int to_line = -1)
sigveseb 0:6ac5ba1343bf 93 {
sigveseb 0:6ac5ba1343bf 94 if(to_line == -1){
sigveseb 0:6ac5ba1343bf 95 to_line = this->lines_per_display;
sigveseb 0:6ac5ba1343bf 96 }
sigveseb 0:6ac5ba1343bf 97 this->frame_fixed_repeat(0xaa, EPD_compensate, from_line, to_line);
sigveseb 0:6ac5ba1343bf 98 this->frame_fixed_repeat(0xaa, EPD_white, from_line, to_line);
sigveseb 0:6ac5ba1343bf 99 this->frame_data_repeat(image, EPD_inverse, from_line, to_line);
sigveseb 0:6ac5ba1343bf 100 this->frame_data_repeat(image, EPD_normal, from_line, to_line);
sigveseb 0:6ac5ba1343bf 101 }
sigveseb 0:6ac5ba1343bf 102
sigveseb 0:6ac5ba1343bf 103
sigveseb 0:6ac5ba1343bf 104
sigveseb 0:6ac5ba1343bf 105 // Low level API calls
sigveseb 0:6ac5ba1343bf 106 // ===================
sigveseb 0:6ac5ba1343bf 107
sigveseb 0:6ac5ba1343bf 108 // single frame refresh
sigveseb 0:6ac5ba1343bf 109 void frame_fixed(uint8_t fixed_value, EPD_stage stage, int from_line, int to_line);
sigveseb 0:6ac5ba1343bf 110 void frame_data(const uint8_t *new_image, EPD_stage stage, int from_line, int to_line);
sigveseb 0:6ac5ba1343bf 111
sigveseb 0:6ac5ba1343bf 112 // stage_time frame refresh
sigveseb 0:6ac5ba1343bf 113 void frame_fixed_repeat(uint8_t fixed_value, EPD_stage stage, int from_line, int to_line);
sigveseb 0:6ac5ba1343bf 114 void frame_data_repeat(const uint8_t *new_image, EPD_stage stage, int from_line, int to_line);
sigveseb 0:6ac5ba1343bf 115
sigveseb 0:6ac5ba1343bf 116 // convert temperature to compensation factor
sigveseb 0:6ac5ba1343bf 117 int temperature_to_factor_10x(int temperature);
sigveseb 0:6ac5ba1343bf 118
sigveseb 0:6ac5ba1343bf 119 // single line display - very low-level
sigveseb 0:6ac5ba1343bf 120 void line(uint16_t line, const uint8_t *data, uint8_t fixed_value, bool read_progmem, EPD_stage stage);
sigveseb 0:6ac5ba1343bf 121 };
sigveseb 0:6ac5ba1343bf 122
sigveseb 0:6ac5ba1343bf 123 extern EPD_Class EPD;
sigveseb 0:6ac5ba1343bf 124
sigveseb 1:2f62e2b80305 125 #endif