EaPaper Library for EM027BS013
Dependencies: EM027BS013 TFT_fonts
Fork of EaEpaper by
Revision 4:672976335e80, committed 2015-04-02
- Comitter:
- tlisowski3
- Date:
- Thu Apr 02 16:27:46 2015 +0000
- Parent:
- 3:1371614703cd
- Commit message:
- EaPaper Library modified for EM027BS013
Changed in this revision
diff -r 1371614703cd -r 672976335e80 EM027BS013.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/EM027BS013.lib Thu Apr 02 16:27:46 2015 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/embeddedartists/code/EM027BS013/#9297e33f50cf
diff -r 1371614703cd -r 672976335e80 EPD.cpp --- a/EPD.cpp Wed Jun 25 17:43:32 2014 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,610 +0,0 @@ -// Copyright 2013 Pervasive Displays, Inc. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at: -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either -// express or implied. See the License for the specific language -// governing permissions and limitations under the License. - - - -#include <limits.h> - -#include "EPD.h" -#include "mbed.h" - -// delays - more consistent naming -#define Delay_ms(ms) wait_ms(ms) -#define Delay_us(us) wait_us(us) - -// inline arrays -#define ARRAY(type, ...) ((type[]){__VA_ARGS__}) -#define CU8(...) (ARRAY(const uint8_t, __VA_ARGS__)) - -#define LOW (0) -#define HIGH (1) -#define digitalWrite(pin, state) (pin) = (state) -#define digitalRead(pin) (pin) - -Timer _time; -#define millis() _time.read_ms() -#define millis_start() _time.start() - - -//static void PWM_start(int pin); -//static void PWM_stop(int pin); - -//static void SPI_put(uint8_t c); -//static void SPI_put_wait(uint8_t c, int busy_pin); -//static void SPI_send(uint8_t cs_pin, const uint8_t *buffer, uint16_t length); - - -EPD_Class::EPD_Class(EPD_size size, - PinName panel_on_pin, - PinName border_pin, - PinName discharge_pin, - PinName pwm_pin, - PinName reset_pin, - PinName busy_pin, - PinName chip_select_pin, - PinName mosi, - PinName miso, - PinName sck) : - EPD_Pin_PANEL_ON(panel_on_pin), - EPD_Pin_BORDER(border_pin), - EPD_Pin_DISCHARGE(discharge_pin), - EPD_Pin_PWM(pwm_pin), - EPD_Pin_RESET(reset_pin), - EPD_Pin_BUSY(busy_pin), - EPD_Pin_EPD_CS(chip_select_pin), - spi_(mosi,miso,sck) { - - this->size = size; - this->stage_time = 480; // milliseconds - this->lines_per_display = 96; - this->dots_per_line = 128; - this->bytes_per_line = 128 / 8; - this->bytes_per_scan = 96 / 4; - this->filler = false; - spi_.frequency(12000000); // 12 MHz SPI clock - - // display size dependant items - { - static uint8_t cs[] = {0x72, 0x00, 0x00, 0x00, 0x00, 0x00, 0x0f, 0xff, 0x00}; - static uint8_t gs[] = {0x72, 0x03}; - this->channel_select = cs; - this->channel_select_length = sizeof(cs); - this->gate_source = gs; - this->gate_source_length = sizeof(gs); - } - - // set up size structure - switch (size) { - default: - case EPD_1_44: // default so no change - break; - - case EPD_2_0: { - this->lines_per_display = 96; - this->dots_per_line = 200; - this->bytes_per_line = 200 / 8; - this->bytes_per_scan = 96 / 4; - this->filler = true; - static uint8_t cs[] = {0x72, 0x00, 0x00, 0x00, 0x00, 0x01, 0xff, 0xe0, 0x00}; - static uint8_t gs[] = {0x72, 0x03}; - this->channel_select = cs; - this->channel_select_length = sizeof(cs); - this->gate_source = gs; - this->gate_source_length = sizeof(gs); - break; - } - - case EPD_2_7: { - this->stage_time = 630; // milliseconds - this->lines_per_display = 176; - this->dots_per_line = 264; - this->bytes_per_line = 264 / 8; - this->bytes_per_scan = 176 / 4; - this->filler = true; - static uint8_t cs[] = {0x72, 0x00, 0x00, 0x00, 0x7f, 0xff, 0xfe, 0x00, 0x00}; - static uint8_t gs[] = {0x72, 0x00}; - this->channel_select = cs; - this->channel_select_length = sizeof(cs); - this->gate_source = gs; - this->gate_source_length = sizeof(gs); - break; - } - } - - this->factored_stage_time = this->stage_time; -} - - -void EPD_Class::begin() { - - // power up sequence - SPI_put(0x00); - - digitalWrite(this->EPD_Pin_RESET, LOW); - digitalWrite(this->EPD_Pin_PANEL_ON, LOW); - digitalWrite(this->EPD_Pin_DISCHARGE, LOW); - digitalWrite(this->EPD_Pin_BORDER, LOW); - digitalWrite(this->EPD_Pin_EPD_CS, LOW); - - //PWM_start(this->EPD_Pin_PWM); - EPD_Pin_PWM = 0.5; - Delay_ms(5); - digitalWrite(this->EPD_Pin_PANEL_ON, HIGH); - Delay_ms(10); - - digitalWrite(this->EPD_Pin_RESET, HIGH); - digitalWrite(this->EPD_Pin_BORDER, HIGH); - digitalWrite(this->EPD_Pin_EPD_CS, HIGH); - Delay_ms(5); - - digitalWrite(this->EPD_Pin_RESET, LOW); - Delay_ms(5); - - digitalWrite(this->EPD_Pin_RESET, HIGH); - Delay_ms(5); - - // wait for COG to become ready - while (HIGH == digitalRead(this->EPD_Pin_BUSY)) { - } - - // channel select - Delay_us(10); - SPI_send(this->EPD_Pin_EPD_CS, CU8(0x70, 0x01), 2); - Delay_us(10); - SPI_send(this->EPD_Pin_EPD_CS, this->channel_select, this->channel_select_length); - - // DC/DC frequency - Delay_us(10); - SPI_send(this->EPD_Pin_EPD_CS, CU8(0x70, 0x06), 2); - Delay_us(10); - SPI_send(this->EPD_Pin_EPD_CS, CU8(0x72, 0xff), 2); - - // high power mode osc - Delay_us(10); - SPI_send(this->EPD_Pin_EPD_CS, CU8(0x70, 0x07), 2); - Delay_us(10); - SPI_send(this->EPD_Pin_EPD_CS, CU8(0x72, 0x9d), 2); - - - // disable ADC - Delay_us(10); - SPI_send(this->EPD_Pin_EPD_CS, CU8(0x70, 0x08), 2); - Delay_us(10); - SPI_send(this->EPD_Pin_EPD_CS, CU8(0x72, 0x00), 2); - - // Vcom level - Delay_us(10); - SPI_send(this->EPD_Pin_EPD_CS, CU8(0x70, 0x09), 2); - Delay_us(10); - SPI_send(this->EPD_Pin_EPD_CS, CU8(0x72, 0xd0, 0x00), 3); - - // gate and source voltage levels - Delay_us(10); - SPI_send(this->EPD_Pin_EPD_CS, CU8(0x70, 0x04), 2); - Delay_us(10); - SPI_send(this->EPD_Pin_EPD_CS, this->gate_source, this->gate_source_length); - - Delay_ms(5); //??? - - // driver latch on - Delay_us(10); - SPI_send(this->EPD_Pin_EPD_CS, CU8(0x70, 0x03), 2); - Delay_us(10); - SPI_send(this->EPD_Pin_EPD_CS, CU8(0x72, 0x01), 2); - - // driver latch off - Delay_us(10); - SPI_send(this->EPD_Pin_EPD_CS, CU8(0x70, 0x03), 2); - Delay_us(10); - SPI_send(this->EPD_Pin_EPD_CS, CU8(0x72, 0x00), 2); - - Delay_ms(5); - - // charge pump positive voltage on - Delay_us(10); - SPI_send(this->EPD_Pin_EPD_CS, CU8(0x70, 0x05), 2); - Delay_us(10); - SPI_send(this->EPD_Pin_EPD_CS, CU8(0x72, 0x01), 2); - - // final delay before PWM off - Delay_ms(30); - //PWM_stop(this->EPD_Pin_PWM); - EPD_Pin_PWM = 0.0; - - // charge pump negative voltage on - Delay_us(10); - SPI_send(this->EPD_Pin_EPD_CS, CU8(0x70, 0x05), 2); - Delay_us(10); - SPI_send(this->EPD_Pin_EPD_CS, CU8(0x72, 0x03), 2); - - Delay_ms(30); - - // Vcom driver on - Delay_us(10); - SPI_send(this->EPD_Pin_EPD_CS, CU8(0x70, 0x05), 2); - Delay_us(10); - SPI_send(this->EPD_Pin_EPD_CS, CU8(0x72, 0x0f), 2); - - Delay_ms(30); - - // output enable to disable - Delay_us(10); - SPI_send(this->EPD_Pin_EPD_CS, CU8(0x70, 0x02), 2); - Delay_us(10); - SPI_send(this->EPD_Pin_EPD_CS, CU8(0x72, 0x24), 2); -} - - -void EPD_Class::end() { - - this->frame_fixed(0x55, EPD_normal); // dummy frame - this->line(0x7fffu, 0, 0x55, false, EPD_normal); // dummy_line - - Delay_ms(25); - - digitalWrite(this->EPD_Pin_BORDER, LOW); - Delay_ms(30); - - digitalWrite(this->EPD_Pin_BORDER, HIGH); - - // latch reset turn on - Delay_us(10); - SPI_send(this->EPD_Pin_EPD_CS, CU8(0x70, 0x03), 2); - Delay_us(10); - SPI_send(this->EPD_Pin_EPD_CS, CU8(0x72, 0x01), 2); - - // output enable off - Delay_us(10); - SPI_send(this->EPD_Pin_EPD_CS, CU8(0x70, 0x02), 2); - Delay_us(10); - SPI_send(this->EPD_Pin_EPD_CS, CU8(0x72, 0x05), 2); - - // Vcom power off - Delay_us(10); - SPI_send(this->EPD_Pin_EPD_CS, CU8(0x70, 0x05), 2); - Delay_us(10); - SPI_send(this->EPD_Pin_EPD_CS, CU8(0x72, 0x0e), 2); - - // power off negative charge pump - Delay_us(10); - SPI_send(this->EPD_Pin_EPD_CS, CU8(0x70, 0x05), 2); - Delay_us(10); - SPI_send(this->EPD_Pin_EPD_CS, CU8(0x72, 0x02), 2); - - // discharge - Delay_us(10); - SPI_send(this->EPD_Pin_EPD_CS, CU8(0x70, 0x04), 2); - Delay_us(10); - SPI_send(this->EPD_Pin_EPD_CS, CU8(0x72, 0x0c), 2); - - Delay_ms(120); - - // all charge pumps off - Delay_us(10); - SPI_send(this->EPD_Pin_EPD_CS, CU8(0x70, 0x05), 2); - Delay_us(10); - SPI_send(this->EPD_Pin_EPD_CS, CU8(0x72, 0x00), 2); - - // turn of osc - Delay_us(10); - SPI_send(this->EPD_Pin_EPD_CS, CU8(0x70, 0x07), 2); - Delay_us(10); - SPI_send(this->EPD_Pin_EPD_CS, CU8(0x72, 0x0d), 2); - - // discharge internal - 1 - Delay_us(10); - SPI_send(this->EPD_Pin_EPD_CS, CU8(0x70, 0x04), 2); - Delay_us(10); - SPI_send(this->EPD_Pin_EPD_CS, CU8(0x72, 0x50), 2); - - Delay_ms(40); - - // discharge internal - 2 - Delay_us(10); - SPI_send(this->EPD_Pin_EPD_CS, CU8(0x70, 0x04), 2); - Delay_us(10); - SPI_send(this->EPD_Pin_EPD_CS, CU8(0x72, 0xA0), 2); - - Delay_ms(40); - - // discharge internal - 3 - Delay_us(10); - SPI_send(this->EPD_Pin_EPD_CS, CU8(0x70, 0x04), 2); - Delay_us(10); - SPI_send(this->EPD_Pin_EPD_CS, CU8(0x72, 0x00), 2); - - // turn of power and all signals - digitalWrite(this->EPD_Pin_RESET, LOW); - digitalWrite(this->EPD_Pin_PANEL_ON, LOW); - digitalWrite(this->EPD_Pin_BORDER, LOW); - digitalWrite(this->EPD_Pin_EPD_CS, LOW); - - digitalWrite(this->EPD_Pin_DISCHARGE, HIGH); - - SPI_put(0x00); - - Delay_ms(150); - - digitalWrite(this->EPD_Pin_DISCHARGE, LOW); -} - - -// convert a temperature in Celcius to -// the scale factor for frame_*_repeat methods -int EPD_Class::temperature_to_factor_10x(int temperature) { - if (temperature <= -10) { - return 170; - } else if (temperature <= -5) { - return 120; - } else if (temperature <= 5) { - return 80; - } else if (temperature <= 10) { - return 40; - } else if (temperature <= 15) { - return 30; - } else if (temperature <= 20) { - return 20; - } else if (temperature <= 40) { - return 10; - } - return 7; -} - - -// One frame of data is the number of lines * rows. For example: -// The 1.44” frame of data is 96 lines * 128 dots. -// The 2” frame of data is 96 lines * 200 dots. -// The 2.7” frame of data is 176 lines * 264 dots. - -// the image is arranged by line which matches the display size -// so smallest would have 96 * 32 bytes - -void EPD_Class::frame_fixed(uint8_t fixed_value, EPD_stage stage) { - for (uint8_t line = 0; line < this->lines_per_display ; ++line) { - this->line(line, 0, fixed_value, false, stage); - } -} - - -void EPD_Class::frame_data(PROGMEM const uint8_t *image, EPD_stage stage){ - for (uint8_t line = 0; line < this->lines_per_display ; ++line) { - this->line(line, &image[line * this->bytes_per_line], 0, true, stage); - } -} - - -#if defined(EPD_ENABLE_EXTRA_SRAM) -void EPD_Class::frame_sram(const uint8_t *image, EPD_stage stage){ - for (uint8_t line = 0; line < this->lines_per_display ; ++line) { - this->line(line, &image[line * this->bytes_per_line], 0, false, stage); - } -} -#endif - - -void EPD_Class::frame_cb(uint32_t address, EPD_reader *reader, EPD_stage stage) { - static uint8_t buffer[264 / 8]; - for (uint8_t line = 0; line < this->lines_per_display; ++line) { - reader(buffer, address + line * this->bytes_per_line, this->bytes_per_line); - this->line(line, buffer, 0, false, stage); - } -} - -void EPD_Class::frame_fixed_repeat(uint8_t fixed_value, EPD_stage stage) { - long stage_time = this->factored_stage_time; - - do { - millis_start(); - unsigned long t_start = millis(); - this->frame_fixed(fixed_value, stage); - unsigned long t_end = millis(); - if (t_end > t_start) { - stage_time -= t_end - t_start; - } else { - stage_time -= t_start - t_end + 1 + ULONG_MAX; - } - } while (stage_time > 0); -} - - -void EPD_Class::frame_data_repeat(PROGMEM const uint8_t *image, EPD_stage stage) { - long stage_time = this->factored_stage_time; - do { - millis_start(); - unsigned long t_start = millis(); - this->frame_data(image, stage); - unsigned long t_end = millis(); - if (t_end > t_start) { - stage_time -= t_end - t_start; - } else { - stage_time -= t_start - t_end + 1 + ULONG_MAX; - } - } while (stage_time > 0); -} - - -#if defined(EPD_ENABLE_EXTRA_SRAM) -void EPD_Class::frame_sram_repeat(const uint8_t *image, EPD_stage stage) { - long stage_time = this->factored_stage_time; - do { - millis_start(); - unsigned long t_start = millis(); - this->frame_sram(image, stage); - unsigned long t_end = millis(); - if (t_end > t_start) { - stage_time -= t_end - t_start; - } else { - stage_time -= t_start - t_end + 1 + ULONG_MAX; - } - } while (stage_time > 0); -} -#endif - - -void EPD_Class::frame_cb_repeat(uint32_t address, EPD_reader *reader, EPD_stage stage) { - long stage_time = this->factored_stage_time; - do { - millis_start(); - unsigned long t_start = millis(); - this->frame_cb(address, reader, stage); - unsigned long t_end = millis(); - if (t_end > t_start) { - stage_time -= t_end - t_start; - } else { - stage_time -= t_start - t_end + 1 + ULONG_MAX; - } - } while (stage_time > 0); -} - - -void EPD_Class::line(uint16_t line, const uint8_t *data, uint8_t fixed_value, bool read_progmem, EPD_stage stage) { - // charge pump voltage levels - - Delay_us(10); - SPI_send(this->EPD_Pin_EPD_CS, CU8(0x70, 0x04), 2); - Delay_us(10); - SPI_send(this->EPD_Pin_EPD_CS, this->gate_source, this->gate_source_length); - - // send data - Delay_us(10); - SPI_send(this->EPD_Pin_EPD_CS, CU8(0x70, 0x0a), 2); - Delay_us(10); - - // CS low - digitalWrite(this->EPD_Pin_EPD_CS, LOW); - SPI_put_wait(0x72, this->EPD_Pin_BUSY); - - // even pixels - for (uint16_t b = this->bytes_per_line; b > 0; --b) { - if (0 != data) { - - uint8_t pixels = data[b - 1] & 0xaa; - - switch(stage) { - case EPD_compensate: // B -> W, W -> B (Current Image) - pixels = 0xaa | ((pixels ^ 0xaa) >> 1); - break; - case EPD_white: // B -> N, W -> W (Current Image) - pixels = 0x55 + ((pixels ^ 0xaa) >> 1); - break; - case EPD_inverse: // B -> N, W -> B (New Image) - pixels = 0x55 | (pixels ^ 0xaa); - break; - case EPD_normal: // B -> B, W -> W (New Image) - pixels = 0xaa | (pixels >> 1); - break; - } - SPI_put_wait(pixels, this->EPD_Pin_BUSY); - } else { - SPI_put_wait(fixed_value, this->EPD_Pin_BUSY); - } } - - // scan line - for (uint16_t b = 0; b < this->bytes_per_scan; ++b) { - if (line / 4 == b) { - SPI_put_wait(0xc0 >> (2 * (line & 0x03)), this->EPD_Pin_BUSY); - } else { - SPI_put_wait(0x00, this->EPD_Pin_BUSY); - } - } - - // odd pixels - for (uint16_t b = 0; b < this->bytes_per_line; ++b) { - if (0 != data) { - - uint8_t pixels = data[b] & 0x55; - - switch(stage) { - case EPD_compensate: // B -> W, W -> B (Current Image) - pixels = 0xaa | (pixels ^ 0x55); - break; - case EPD_white: // B -> N, W -> W (Current Image) - pixels = 0x55 + (pixels ^ 0x55); - break; - case EPD_inverse: // B -> N, W -> B (New Image) - pixels = 0x55 | ((pixels ^ 0x55) << 1); - break; - case EPD_normal: // B -> B, W -> W (New Image) - pixels = 0xaa | pixels; - break; - } - uint8_t p1 = (pixels >> 6) & 0x03; - uint8_t p2 = (pixels >> 4) & 0x03; - uint8_t p3 = (pixels >> 2) & 0x03; - uint8_t p4 = (pixels >> 0) & 0x03; - pixels = (p1 << 0) | (p2 << 2) | (p3 << 4) | (p4 << 6); - SPI_put_wait(pixels, this->EPD_Pin_BUSY); - } else { - SPI_put_wait(fixed_value, this->EPD_Pin_BUSY); - } - } - - if (this->filler) { - SPI_put_wait(0x00, this->EPD_Pin_BUSY); - } - - // CS high - digitalWrite(this->EPD_Pin_EPD_CS, HIGH); - - // output data to panel - Delay_us(10); - SPI_send(this->EPD_Pin_EPD_CS, CU8(0x70, 0x02), 2); - Delay_us(10); - SPI_send(this->EPD_Pin_EPD_CS, CU8(0x72, 0x2f), 2); -} - - -void EPD_Class::SPI_put(uint8_t c) { - - spi_.write(c); - //spi_.fastWrite(c); - - -} - - - -void EPD_Class::SPI_put_wait(uint8_t c, DigitalIn busy_pin) { - - SPI_put(c); - - // wait for COG ready - while (HIGH == digitalRead(busy_pin)) { - } -} - - -void EPD_Class::SPI_send(DigitalOut cs_pin, const uint8_t *buffer, uint16_t length) { - - // CS low - digitalWrite(cs_pin, LOW); - - // send all data - for (uint16_t i = 0; i < length; ++i) { - spi_.write(*buffer++); - } - - // CS high - digitalWrite(cs_pin, HIGH); -} - - -//static void PWM_start(int pin) { -// analogWrite(pin, 128); // 50% duty cycle -//} - - -//static void PWM_stop(int pin) { -// analogWrite(pin, 0); -//}
diff -r 1371614703cd -r 672976335e80 EPD.h --- a/EPD.h Wed Jun 25 17:43:32 2014 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,155 +0,0 @@ -// Copyright 2013 Pervasive Displays, Inc. -// -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at: -// -// http://www.apache.org/licenses/LICENSE-2.0 -// -// Unless required by applicable law or agreed to in writing, -// software distributed under the License is distributed on an -// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either -// express or implied. See the License for the specific language -// governing permissions and limitations under the License. - -#ifndef EPD_H -#define EPD_H - -#include "mbed.h" - -#define PROGMEM - - -typedef enum { - EPD_1_44, // 128 x 96 - EPD_2_0, // 200 x 96 - EPD_2_7 // 264 x 176 -} EPD_size; - -typedef enum { // Image pixel -> Display pixel - EPD_compensate, // B -> W, W -> B (Current Image) - EPD_white, // B -> N, W -> W (Current Image) - EPD_inverse, // B -> N, W -> B (New Image) - EPD_normal // B -> B, W -> W (New Image) -} EPD_stage; - -typedef void EPD_reader(void *buffer, uint32_t address, uint16_t length); - -class EPD_Class { -private: - DigitalOut EPD_Pin_PANEL_ON; - DigitalOut EPD_Pin_BORDER; - DigitalOut EPD_Pin_DISCHARGE; - PwmOut EPD_Pin_PWM; - DigitalOut EPD_Pin_RESET; - DigitalIn EPD_Pin_BUSY; - DigitalOut EPD_Pin_EPD_CS; - SPI spi_; - - EPD_size size; - uint16_t stage_time; - uint16_t factored_stage_time; - uint16_t lines_per_display; - uint16_t dots_per_line; - uint16_t bytes_per_line; - uint16_t bytes_per_scan; - PROGMEM const uint8_t *gate_source; - uint16_t gate_source_length; - PROGMEM const uint8_t *channel_select; - uint16_t channel_select_length; - - bool filler; - - void SPI_put(uint8_t c); - void SPI_put_wait(uint8_t c, DigitalIn busy_pin); - void SPI_send(DigitalOut cs_pin, const uint8_t *buffer, uint16_t length); - -public: - // power up and power down the EPD panel - void begin(); - void end(); - - void setFactor(int temperature = 25) { - this->factored_stage_time = this->stage_time * this->temperature_to_factor_10x(temperature) / 10; - } - - // clear display (anything -> white) - void clear() { - this->frame_fixed_repeat(0xff, EPD_compensate); - this->frame_fixed_repeat(0xff, EPD_white); - this->frame_fixed_repeat(0xaa, EPD_inverse); - this->frame_fixed_repeat(0xaa, EPD_normal); - } - - // assuming a clear (white) screen output an image (PROGMEM data) - void image(const uint8_t *image) { - this->frame_fixed_repeat(0xaa, EPD_compensate); - this->frame_fixed_repeat(0xaa, EPD_white); - this->frame_data_repeat(image, EPD_inverse); - this->frame_data_repeat(image, EPD_normal); - } - - // change from old image to new image (PROGMEM data) - void image(const uint8_t *old_image, const uint8_t *new_image) { - this->frame_data_repeat(old_image, EPD_compensate); - this->frame_data_repeat(old_image, EPD_white); - this->frame_data_repeat(new_image, EPD_inverse); - this->frame_data_repeat(new_image, EPD_normal); - } - -#if defined(EPD_ENABLE_EXTRA_SRAM) - - // change from old image to new image (SRAM version) - void image_sram(const uint8_t *old_image, const uint8_t *new_image) { - this->frame_sram_repeat(old_image, EPD_compensate); - this->frame_sram_repeat(old_image, EPD_white); - this->frame_sram_repeat(new_image, EPD_inverse); - this->frame_sram_repeat(new_image, EPD_normal); - } -#endif - - // Low level API calls - // =================== - - // single frame refresh - void frame_fixed(uint8_t fixed_value, EPD_stage stage); - void frame_data(const uint8_t *new_image, EPD_stage stage); -#if defined(EPD_ENABLE_EXTRA_SRAM) - void frame_sram(const uint8_t *new_image, EPD_stage stage); -#endif - void frame_cb(uint32_t address, EPD_reader *reader, EPD_stage stage); - - // stage_time frame refresh - void frame_fixed_repeat(uint8_t fixed_value, EPD_stage stage); - void frame_data_repeat(const uint8_t *new_image, EPD_stage stage); -#if defined(EPD_ENABLE_EXTRA_SRAM) - void frame_sram_repeat(const uint8_t *new_image, EPD_stage stage); -#endif - void frame_cb_repeat(uint32_t address, EPD_reader *reader, EPD_stage stage); - - // convert temperature to compensation factor - int temperature_to_factor_10x(int temperature); - - // single line display - very low-level - // also has to handle AVR progmem - void line(uint16_t line, const uint8_t *data, uint8_t fixed_value, bool read_progmem, EPD_stage stage); - - // inline static void attachInterrupt(); - // inline static void detachInterrupt(); - - EPD_Class(EPD_size size, - PinName panel_on_pin, - PinName border_pin, - PinName discharge_pin, - PinName pwm_pin, - PinName reset_pin, - PinName busy_pin, - PinName chip_select_pin, - PinName mosi, - PinName miso, - PinName sck); - -}; - -#endif -
diff -r 1371614703cd -r 672976335e80 EaEpaper.cpp --- a/EaEpaper.cpp Wed Jun 25 17:43:32 2014 +0000 +++ b/EaEpaper.cpp Thu Apr 02 16:27:46 2015 +0000 @@ -6,30 +6,36 @@ #define LM75A_ADDRESS (0x92) // 0x49 << 1 #define LM75A_CMD_TEMP 0x00 -static uint8_t _oldImage[EA_IMG_BUF_SZ]; static uint8_t _newImage[EA_IMG_BUF_SZ]; -EaEpaper::EaEpaper(PinName p_on, PinName border, PinName discharge, PinName reset, PinName busy, PinName cs, - PinName pwm, - PinName mosi, PinName miso, PinName sck, - PinName sda, PinName scl, +EaEpaper::EaEpaper(PinName sec03_SpiSCK, + PinName sec04_SpiMOSI, + PinName sec05_SpiMISO, + PinName sec06_EpdCS, + PinName sec07_EpdBusy, + PinName sec08_EpdBorder, + PinName sec09_I2cSCL, + PinName sec10_I2cSDA, + PinName sec11_FlashCS, + PinName sec12_EpdReset, + PinName sec13_EpdPanelOn, + PinName sec14_EpdDischarge, const char* name): - epd_(EPD_2_7, - p_on, // panel_on_pin - border, // border_pin - discharge, // discharge_pin - pwm, // pwm_pin - reset, // reset_pin - busy, // busy_pin - cs, // chip_select_pin - mosi, // mosi - miso, // miso - sck), // sck - i2c_(sda, scl), + em_(sec03_SpiSCK, + sec04_SpiMOSI, + sec05_SpiMISO, + sec06_EpdCS, + sec07_EpdBusy, + sec08_EpdBorder, + sec09_I2cSCL, + sec10_I2cSDA, + sec11_FlashCS, + sec12_EpdReset, + sec13_EpdPanelOn, + sec14_EpdDischarge), // sck GraphicsDisplay(name) { draw_mode = NORMAL; - memset(_oldImage, 0, EA_IMG_BUF_SZ); memset(_newImage, 0, EA_IMG_BUF_SZ); } @@ -48,40 +54,16 @@ // erase pixel after power up void EaEpaper::clear() { - epd_.begin(); - epd_.setFactor(readTemperature()/100); - epd_.clear(); - epd_.end(); - - memset(_oldImage, 0, EA_IMG_BUF_SZ); - memset(_newImage, 0, EA_IMG_BUF_SZ); + memset(_newImage, 0xFF, EA_IMG_BUF_SZ); } // update screen _newImage -> _oldImage void EaEpaper::write_disp(void) { - epd_.begin(); - epd_.setFactor(readTemperature()/100); - epd_.image(_oldImage, _newImage); - epd_.end(); - - memcpy(_oldImage, _newImage, EA_IMG_BUF_SZ); + em_.drawImage(_newImage); } // read LM75A sensor on board to calculate display speed -int32_t EaEpaper::readTemperature() -{ - char buf[2]; - int32_t t = 0; - char reg = LM75A_CMD_TEMP; - - i2c_.write(LM75A_ADDRESS, ®, 1); - i2c_.read(LM75A_ADDRESS, buf, 2); - - t = ((buf[0] << 8) | (buf[1])); - - return ((t * 100) >> 8); -} // set one pixel in buffer _newImage @@ -92,19 +74,19 @@ if(draw_mode == NORMAL) { if(color == 0) - _newImage[(x / 8) + ((y-1) * 33)] &= ~(1 << (x%8)); // erase pixel + _newImage[(x / 8) + ((y-1) * 33)] &= ~(1 << (7-(x%8))); // erase pixel else - _newImage[(x / 8) + ((y-1) * 33)] |= (1 << (x%8)); // set pixel + _newImage[(x / 8) + ((y-1) * 33)] |= (1 << (7-(x%8))); // set pixel } else { // XOR mode if(color == 1) - _newImage[(x / 8) + ((y-1) * 33)] ^= (1 << (x%8)); // xor pixel + _newImage[(x / 8) + ((y-1) * 33)] ^= (1 << (7-(x%8))); // xor pixel } } // clear screen void EaEpaper::cls(void) { - memset(_newImage, 0, EA_IMG_BUF_SZ); // clear display buffer + memset(_newImage, 0xFF, EA_IMG_BUF_SZ); // clear display buffer } // print line
diff -r 1371614703cd -r 672976335e80 EaEpaper.h --- a/EaEpaper.h Wed Jun 25 17:43:32 2014 +0000 +++ b/EaEpaper.h Thu Apr 02 16:27:46 2015 +0000 @@ -20,7 +20,7 @@ * Includes */ #include "mbed.h" -#include "EPD.h" +#include "EM027BS013.h" #include "GraphicsDisplay.h" // we have to double buffer the display @@ -93,10 +93,18 @@ /** * Constructor. */ - EaEpaper(PinName p_on, PinName border, PinName discharge, PinName reset, PinName busy, PinName cs, // IO-Pins - PinName pwm, // PWM Pin - PinName mosi, PinName miso, PinName sck, // SPI - PinName sda, PinName scl, // I2C + EaEpaper::EaEpaper(PinName sec03_SpiSCK, + PinName sec04_SpiMOSI, + PinName sec05_SpiMISO, + PinName sec06_EpdCS, + PinName sec07_EpdBusy, + PinName sec08_EpdBorder, + PinName sec09_I2cSCL, + PinName sec10_I2cSDA, + PinName sec11_FlashCS, + PinName sec12_EpdReset, + PinName sec13_EpdPanelOn, + PinName sec14_EpdDischarge, // I2C const char* name ="E_Paper"); /** Get the width of the screen in pixel @@ -249,11 +257,9 @@ private: - EPD_Class epd_; - I2C i2c_; + EM027BS013 em_; unsigned int char_x; unsigned int char_y; - int32_t readTemperature(); };
diff -r 1371614703cd -r 672976335e80 TFT_fonts.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/TFT_fonts.lib Thu Apr 02 16:27:46 2015 +0000 @@ -0,0 +1,1 @@ +http://developer.mbed.org/users/dreschpe/code/TFT_fonts/#76774250fcec