|
@ -1,7 +1,5 @@
|
|||
# 2.9" Waveshare ePaper Driver Example
|
||||
|
||||
Source https://github.com/krzychb/esp-epaper-29-ws
|
||||
|
||||
Communicate with [2.9" Waveshare ePaper Module](https://www.waveshare.com/wiki/2.9inch_e-Paper_Module) using SPI interface of [ESP32](http://espressif.com/en/products/hardware/esp32/overview) and [ESP-IDF](https://github.com/espressif/esp-idf) or [Arduino](https://www.arduino.cc/).
|
||||
|
||||
* [2.9" Waveshare ePaper Module Datasheet](pictures/2.9inch_e-Paper_Datasheet.pdf)
|
Before Width: | Height: | Size: 407 KiB After Width: | Height: | Size: 407 KiB |
Before Width: | Height: | Size: 623 KiB After Width: | Height: | Size: 623 KiB |
Before Width: | Height: | Size: 455 KiB After Width: | Height: | Size: 455 KiB |
Before Width: | Height: | Size: 40 KiB After Width: | Height: | Size: 40 KiB |
|
@ -30,20 +30,32 @@
|
|||
Epd::~Epd() {
|
||||
};
|
||||
|
||||
|
||||
Epd::Epd() {
|
||||
reset_pin = RST_PIN;
|
||||
dc_pin = DC_PIN;
|
||||
//reset_pin = RST_PIN;
|
||||
//dc_pin = DC_PIN;
|
||||
cs_pin = CS_PIN;
|
||||
busy_pin = BUSY_PIN;
|
||||
mosi_pin = MOSI_PIN;
|
||||
sclk_pin = SCLK_PIN;
|
||||
//busy_pin = BUSY_PIN;
|
||||
width = EPD_WIDTH;
|
||||
height = EPD_HEIGHT;
|
||||
};
|
||||
|
||||
int Epd::Init(const unsigned char* lut) {
|
||||
/* this calls the peripheral hardware interface, see epdif */
|
||||
if (IfInit() != 0) {
|
||||
/*if (IfInit() != 0) {
|
||||
return -1;
|
||||
}
|
||||
}*/
|
||||
/*
|
||||
cs_pin=pin[GPIO_SSPI_CS];
|
||||
mosi_pin=pin[GPIO_SSPI_MOSI];
|
||||
sclk_pin=pin[GPIO_SSPI_SCLK];
|
||||
*/
|
||||
pinMode(cs_pin, OUTPUT);
|
||||
pinMode(mosi_pin, OUTPUT);
|
||||
pinMode(sclk_pin, OUTPUT);
|
||||
|
||||
/* EPD hardware init start */
|
||||
this->lut = lut;
|
||||
Reset();
|
||||
|
@ -72,22 +84,25 @@ int Epd::Init(const unsigned char* lut) {
|
|||
* @brief: basic function for sending commands
|
||||
*/
|
||||
void Epd::SendCommand(unsigned char command) {
|
||||
DigitalWrite(dc_pin, LOW);
|
||||
SpiTransfer(command);
|
||||
//DigitalWrite(dc_pin, LOW);
|
||||
//SpiTransfer(command);
|
||||
fastSPIwrite(command,0);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief: basic function for sending data
|
||||
*/
|
||||
void Epd::SendData(unsigned char data) {
|
||||
DigitalWrite(dc_pin, HIGH);
|
||||
SpiTransfer(data);
|
||||
fastSPIwrite(data,1);
|
||||
// DigitalWrite(dc_pin, HIGH);
|
||||
// SpiTransfer(data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief: Wait until the busy_pin goes LOW
|
||||
*/
|
||||
void Epd::WaitUntilIdle(void) {
|
||||
return;
|
||||
while(DigitalRead(busy_pin) == HIGH) { //LOW: idle, HIGH: busy
|
||||
DelayMs(100);
|
||||
}
|
||||
|
@ -99,9 +114,9 @@ void Epd::WaitUntilIdle(void) {
|
|||
* see Epd::Sleep();
|
||||
*/
|
||||
void Epd::Reset(void) {
|
||||
DigitalWrite(reset_pin, LOW); //module reset
|
||||
//DigitalWrite(reset_pin, LOW); //module reset
|
||||
DelayMs(200);
|
||||
DigitalWrite(reset_pin, HIGH);
|
||||
//DigitalWrite(reset_pin, HIGH);
|
||||
DelayMs(200);
|
||||
}
|
||||
|
||||
|
@ -123,13 +138,13 @@ void Epd::SetLut(const unsigned char* lut) {
|
|||
*/
|
||||
void Epd::SetFrameMemory(
|
||||
const unsigned char* image_buffer,
|
||||
int x,
|
||||
int y,
|
||||
int image_width,
|
||||
int image_height
|
||||
uint16_t x,
|
||||
uint16_t y,
|
||||
uint16_t image_width,
|
||||
uint16_t image_height
|
||||
) {
|
||||
int x_end;
|
||||
int y_end;
|
||||
uint16_t x_end;
|
||||
uint16_t y_end;
|
||||
|
||||
if (
|
||||
image_buffer == NULL ||
|
||||
|
@ -138,9 +153,10 @@ void Epd::SetFrameMemory(
|
|||
) {
|
||||
return;
|
||||
}
|
||||
|
||||
/* x point must be the multiple of 8 or the last 3 bits will be ignored */
|
||||
x &= 0xF8;
|
||||
image_width &= 0xF8;
|
||||
x &= 0xFFF8;
|
||||
image_width &= 0xFFF8;
|
||||
if (x + image_width >= this->width) {
|
||||
x_end = this->width - 1;
|
||||
} else {
|
||||
|
@ -151,12 +167,18 @@ void Epd::SetFrameMemory(
|
|||
} else {
|
||||
y_end = y + image_height - 1;
|
||||
}
|
||||
|
||||
if (!x && !y && image_width==this->width && image_height==this->height) {
|
||||
SetFrameMemory(image_buffer);
|
||||
return;
|
||||
}
|
||||
|
||||
SetMemoryArea(x, y, x_end, y_end);
|
||||
SetMemoryPointer(x, y);
|
||||
SendCommand(WRITE_RAM);
|
||||
/* send the image data */
|
||||
for (int j = 0; j < y_end - y + 1; j++) {
|
||||
for (int i = 0; i < (x_end - x + 1) / 8; i++) {
|
||||
for (uint16_t j = 0; j < y_end - y + 1; j++) {
|
||||
for (uint16_t i = 0; i < (x_end - x + 1) / 8; i++) {
|
||||
SendData(image_buffer[i + j * (image_width / 8)]);
|
||||
}
|
||||
}
|
||||
|
@ -273,7 +295,23 @@ const unsigned char lut_partial_update[] =
|
|||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00
|
||||
};
|
||||
|
||||
void Epd::fastSPIwrite(uint8_t d,uint8_t dc) {
|
||||
|
||||
digitalWrite(cs_pin, LOW);
|
||||
|
||||
// transfer dc
|
||||
digitalWrite(sclk_pin, LOW);
|
||||
if(dc) digitalWrite(mosi_pin, HIGH);
|
||||
else digitalWrite(mosi_pin, LOW);
|
||||
digitalWrite(sclk_pin, HIGH);
|
||||
|
||||
for(uint8_t bit = 0x80; bit; bit >>= 1) {
|
||||
digitalWrite(sclk_pin, LOW);
|
||||
if(d & bit) digitalWrite(mosi_pin, HIGH);
|
||||
else digitalWrite(mosi_pin, LOW);
|
||||
digitalWrite(sclk_pin, HIGH);
|
||||
}
|
||||
|
||||
digitalWrite(cs_pin, HIGH);
|
||||
}
|
||||
/* END OF FILE */
|
||||
|
||||
|
|
@ -73,26 +73,32 @@ public:
|
|||
void Reset(void);
|
||||
void SetFrameMemory(
|
||||
const unsigned char* image_buffer,
|
||||
int x,
|
||||
int y,
|
||||
int image_width,
|
||||
int image_height
|
||||
uint16_t x,
|
||||
uint16_t y,
|
||||
uint16_t image_width,
|
||||
uint16_t image_height
|
||||
);
|
||||
void SetFrameMemory(const unsigned char* image_buffer);
|
||||
void ClearFrameMemory(unsigned char color);
|
||||
void DisplayFrame(void);
|
||||
void Sleep(void);
|
||||
|
||||
unsigned int cs_pin;
|
||||
unsigned int mosi_pin;
|
||||
unsigned int sclk_pin;
|
||||
|
||||
private:
|
||||
unsigned int reset_pin;
|
||||
unsigned int dc_pin;
|
||||
unsigned int cs_pin;
|
||||
unsigned int busy_pin;
|
||||
const unsigned char* lut;
|
||||
|
||||
|
||||
|
||||
void SetLut(const unsigned char* lut);
|
||||
void SetMemoryArea(int x_start, int y_start, int x_end, int y_end);
|
||||
void SetMemoryPointer(int x, int y);
|
||||
void fastSPIwrite(uint8_t d,uint8_t dc);
|
||||
};
|
||||
|
||||
#endif /* EPD2IN9_H */
|
|
@ -34,31 +34,63 @@ EpdIf::EpdIf() {
|
|||
EpdIf::~EpdIf() {
|
||||
};
|
||||
|
||||
void EpdIf::DigitalWrite(int pin, int value) {
|
||||
digitalWrite(pin, value);
|
||||
void EpdIf::DelayMs(unsigned int delaytime) {
|
||||
delay(delaytime);
|
||||
}
|
||||
|
||||
int EpdIf::DigitalRead(int pin) {
|
||||
return digitalRead(pin);
|
||||
}
|
||||
|
||||
void EpdIf::DelayMs(unsigned int delaytime) {
|
||||
delay(delaytime);
|
||||
/*
|
||||
void EpdIf::DigitalWrite(int pin, int value) {
|
||||
digitalWrite(pin, value);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void EpdIf::SpiTransfer(unsigned char data) {
|
||||
digitalWrite(CS_PIN, LOW);
|
||||
SPI.transfer(data);
|
||||
digitalWrite(CS_PIN, HIGH);
|
||||
digitalWrite(cs_pin, LOW);
|
||||
//SPI.transfer(data);
|
||||
digitalWrite(cs_pin, HIGH);
|
||||
}
|
||||
|
||||
|
||||
|
||||
int EpdIf::IfInit(void) {
|
||||
pinMode(CS_PIN, OUTPUT);
|
||||
pinMode(RST_PIN, OUTPUT);
|
||||
pinMode(DC_PIN, OUTPUT);
|
||||
pinMode(BUSY_PIN, INPUT);
|
||||
SPI.beginTransaction(SPISettings(2000000, MSBFIRST, SPI_MODE0));
|
||||
SPI.begin(SCK_PIN, MISO_PIN, MOSI_PIN, SS_PIN);
|
||||
|
||||
|
||||
pinMode(cs_pin, OUTPUT);
|
||||
pinMode(mosi_pin, OUTPUT);
|
||||
pinMode(mosi_pin, OUTPUT);
|
||||
//pinMode(RST_PIN, OUTPUT);
|
||||
//pinMode(DC_PIN, OUTPUT);
|
||||
//pinMode(BUSY_PIN, INPUT);
|
||||
//SPI.beginTransaction(SPISettings(2000000, MSBFIRST, SPI_MODE0));
|
||||
//SPI.begin(SCK_PIN, MISO_PIN, MOSI_PIN, SS_PIN);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
void EpdIf::fastSPIwrite(uint8_t d,uint8_t dc) {
|
||||
|
||||
digitalWrite(cs_pin, LOW);
|
||||
|
||||
// transfer dc
|
||||
digitalWrite(sclk_pin, LOW);
|
||||
if(dc) digitalWrite(mosi_pin, HIGH);
|
||||
else digitalWrite(mosi_pin, LOW);
|
||||
digitalWrite(sclk_pin, HIGH);
|
||||
|
||||
for(uint8_t bit = 0x80; bit; bit >>= 1) {
|
||||
digitalWrite(sclk_pin, LOW);
|
||||
if(d & bit) digitalWrite(mosi_pin, HIGH);
|
||||
else digitalWrite(mosi_pin, LOW);
|
||||
digitalWrite(sclk_pin, HIGH);
|
||||
}
|
||||
|
||||
digitalWrite(cs_pin, HIGH);
|
||||
}
|
||||
*/
|
|
@ -39,6 +39,7 @@ Default pins:
|
|||
SS 5
|
||||
Use default pin -1
|
||||
*/
|
||||
/*
|
||||
#define SCK_PIN -1
|
||||
#define MISO_PIN 4
|
||||
#define MOSI_PIN 5
|
||||
|
@ -49,17 +50,27 @@ Default pins:
|
|||
#define DC_PIN 21
|
||||
#define CS_PIN 19
|
||||
#define BUSY_PIN 22
|
||||
*/
|
||||
|
||||
#define CS_PIN 5
|
||||
#define MOSI_PIN 0
|
||||
#define SCLK_PIN 4
|
||||
|
||||
|
||||
class EpdIf {
|
||||
public:
|
||||
EpdIf(void);
|
||||
~EpdIf(void);
|
||||
|
||||
static void DelayMs(unsigned int delaytime);
|
||||
static int DigitalRead(int pin);
|
||||
/*
|
||||
static int IfInit(void);
|
||||
static void DigitalWrite(int pin, int value);
|
||||
static int DigitalRead(int pin);
|
||||
static void DelayMs(unsigned int delaytime);
|
||||
|
||||
|
||||
static void SpiTransfer(unsigned char data);
|
||||
*/
|
||||
//static void fastSPIwrite(uint8_t d,uint8_t dc);
|
||||
};
|
||||
|
||||
#endif
|
|
@ -151,6 +151,9 @@ void Paint::DrawCharAt(int x, int y, char ascii_char, sFONT* font, int colored)
|
|||
for (i = 0; i < font->Width; i++) {
|
||||
if (pgm_read_byte(ptr) & (0x80 >> (i % 8))) {
|
||||
DrawPixel(x + i, y + j, colored);
|
||||
} else {
|
||||
// fill background
|
||||
DrawPixel(x + i, y + j, 1);
|
||||
}
|
||||
if (i % 8 == 7) {
|
||||
ptr++;
|
||||
|
@ -317,26 +320,3 @@ void Paint::DrawFilledCircle(int x, int y, int radius, int colored) {
|
|||
}
|
||||
|
||||
/* END OF FILE */
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
@ -64,12 +64,11 @@ public:
|
|||
|
||||
private:
|
||||
unsigned char* image;
|
||||
int width;
|
||||
int height;
|
||||
int rotate;
|
||||
uint16_t width;
|
||||
uint16_t height;
|
||||
uint8_t rotate;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
/* END OF FILE */
|
||||
|
|
@ -1,64 +0,0 @@
|
|||
/**
|
||||
* @filename : epdif.cpp
|
||||
* @brief : Implements EPD interface functions
|
||||
* Users have to implement all the functions in epdif.cpp
|
||||
* @author : Yehui from Waveshare
|
||||
*
|
||||
* Copyright (C) Waveshare August 10 2017
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documnetation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS OR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include "epdif.h"
|
||||
#include <SPI.h>
|
||||
|
||||
EpdIf::EpdIf() {
|
||||
};
|
||||
|
||||
EpdIf::~EpdIf() {
|
||||
};
|
||||
|
||||
void EpdIf::DigitalWrite(int pin, int value) {
|
||||
digitalWrite(pin, value);
|
||||
}
|
||||
|
||||
int EpdIf::DigitalRead(int pin) {
|
||||
return digitalRead(pin);
|
||||
}
|
||||
|
||||
void EpdIf::DelayMs(unsigned int delaytime) {
|
||||
delay(delaytime);
|
||||
}
|
||||
|
||||
void EpdIf::SpiTransfer(unsigned char data) {
|
||||
digitalWrite(CS_PIN, LOW);
|
||||
SPI.transfer(data);
|
||||
digitalWrite(CS_PIN, HIGH);
|
||||
}
|
||||
|
||||
int EpdIf::IfInit(void) {
|
||||
pinMode(CS_PIN, OUTPUT);
|
||||
pinMode(RST_PIN, OUTPUT);
|
||||
pinMode(DC_PIN, OUTPUT);
|
||||
pinMode(BUSY_PIN, INPUT);
|
||||
SPI.beginTransaction(SPISettings(2000000, MSBFIRST, SPI_MODE0));
|
||||
SPI.begin(SCK_PIN, MISO_PIN, MOSI_PIN, SS_PIN);
|
||||
return 0;
|
||||
}
|
||||
|
|
@ -1,65 +0,0 @@
|
|||
/**
|
||||
* @filename : epdif.h
|
||||
* @brief : Header file of epdif.cpp providing EPD interface functions
|
||||
* Users have to implement all the functions in epdif.cpp
|
||||
* @author : Yehui from Waveshare
|
||||
*
|
||||
* Copyright (C) Waveshare August 10 2017
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documnetation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS OR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef EPDIF_H
|
||||
#define EPDIF_H
|
||||
|
||||
#include <Arduino.h>
|
||||
|
||||
/*
|
||||
SPI Pin definition
|
||||
Default pins:
|
||||
SCK 18
|
||||
MISO 19
|
||||
MOSI 23
|
||||
SS 5
|
||||
Use default pin -1
|
||||
*/
|
||||
#define SCK_PIN -1
|
||||
#define MISO_PIN 4
|
||||
#define MOSI_PIN 5
|
||||
#define SS_PIN 2
|
||||
|
||||
// EPD Pin definition
|
||||
#define RST_PIN 23
|
||||
#define DC_PIN 21
|
||||
#define CS_PIN 19
|
||||
#define BUSY_PIN 22
|
||||
|
||||
class EpdIf {
|
||||
public:
|
||||
EpdIf(void);
|
||||
~EpdIf(void);
|
||||
|
||||
static int IfInit(void);
|
||||
static void DigitalWrite(int pin, int value);
|
||||
static int DigitalRead(int pin);
|
||||
static void DelayMs(unsigned int delaytime);
|
||||
static void SpiTransfer(unsigned char data);
|
||||
};
|
||||
|
||||
#endif
|
|
@ -1,279 +0,0 @@
|
|||
/**
|
||||
* @filename : epd2in9.cpp
|
||||
* @brief : Implements for e-paper library
|
||||
* @author : Yehui from Waveshare
|
||||
*
|
||||
* Copyright (C) Waveshare September 9 2017
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documnetation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS OR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <stdlib.h>
|
||||
#include "epd2in9.h"
|
||||
|
||||
Epd::~Epd() {
|
||||
};
|
||||
|
||||
Epd::Epd() {
|
||||
reset_pin = RST_PIN;
|
||||
dc_pin = DC_PIN;
|
||||
cs_pin = CS_PIN;
|
||||
busy_pin = BUSY_PIN;
|
||||
width = EPD_WIDTH;
|
||||
height = EPD_HEIGHT;
|
||||
};
|
||||
|
||||
int Epd::Init(const unsigned char* lut) {
|
||||
/* this calls the peripheral hardware interface, see epdif */
|
||||
if (IfInit() != 0) {
|
||||
return -1;
|
||||
}
|
||||
/* EPD hardware init start */
|
||||
this->lut = lut;
|
||||
Reset();
|
||||
SendCommand(DRIVER_OUTPUT_CONTROL);
|
||||
SendData((EPD_HEIGHT - 1) & 0xFF);
|
||||
SendData(((EPD_HEIGHT - 1) >> 8) & 0xFF);
|
||||
SendData(0x00); // GD = 0; SM = 0; TB = 0;
|
||||
SendCommand(BOOSTER_SOFT_START_CONTROL);
|
||||
SendData(0xD7);
|
||||
SendData(0xD6);
|
||||
SendData(0x9D);
|
||||
SendCommand(WRITE_VCOM_REGISTER);
|
||||
SendData(0xA8); // VCOM 7C
|
||||
SendCommand(SET_DUMMY_LINE_PERIOD);
|
||||
SendData(0x1A); // 4 dummy lines per gate
|
||||
SendCommand(SET_GATE_TIME);
|
||||
SendData(0x08); // 2us per line
|
||||
SendCommand(DATA_ENTRY_MODE_SETTING);
|
||||
SendData(0x03); // X increment; Y increment
|
||||
SetLut(this->lut);
|
||||
/* EPD hardware init end */
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief: basic function for sending commands
|
||||
*/
|
||||
void Epd::SendCommand(unsigned char command) {
|
||||
DigitalWrite(dc_pin, LOW);
|
||||
SpiTransfer(command);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief: basic function for sending data
|
||||
*/
|
||||
void Epd::SendData(unsigned char data) {
|
||||
DigitalWrite(dc_pin, HIGH);
|
||||
SpiTransfer(data);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief: Wait until the busy_pin goes LOW
|
||||
*/
|
||||
void Epd::WaitUntilIdle(void) {
|
||||
while(DigitalRead(busy_pin) == HIGH) { //LOW: idle, HIGH: busy
|
||||
DelayMs(100);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief: module reset.
|
||||
* often used to awaken the module in deep sleep,
|
||||
* see Epd::Sleep();
|
||||
*/
|
||||
void Epd::Reset(void) {
|
||||
DigitalWrite(reset_pin, LOW); //module reset
|
||||
DelayMs(200);
|
||||
DigitalWrite(reset_pin, HIGH);
|
||||
DelayMs(200);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief: set the look-up table register
|
||||
*/
|
||||
void Epd::SetLut(const unsigned char* lut) {
|
||||
this->lut = lut;
|
||||
SendCommand(WRITE_LUT_REGISTER);
|
||||
/* the length of look-up table is 30 bytes */
|
||||
for (int i = 0; i < 30; i++) {
|
||||
SendData(this->lut[i]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief: put an image buffer to the frame memory.
|
||||
* this won't update the display.
|
||||
*/
|
||||
void Epd::SetFrameMemory(
|
||||
const unsigned char* image_buffer,
|
||||
int x,
|
||||
int y,
|
||||
int image_width,
|
||||
int image_height
|
||||
) {
|
||||
int x_end;
|
||||
int y_end;
|
||||
|
||||
if (
|
||||
image_buffer == NULL ||
|
||||
x < 0 || image_width < 0 ||
|
||||
y < 0 || image_height < 0
|
||||
) {
|
||||
return;
|
||||
}
|
||||
/* x point must be the multiple of 8 or the last 3 bits will be ignored */
|
||||
x &= 0xF8;
|
||||
image_width &= 0xF8;
|
||||
if (x + image_width >= this->width) {
|
||||
x_end = this->width - 1;
|
||||
} else {
|
||||
x_end = x + image_width - 1;
|
||||
}
|
||||
if (y + image_height >= this->height) {
|
||||
y_end = this->height - 1;
|
||||
} else {
|
||||
y_end = y + image_height - 1;
|
||||
}
|
||||
SetMemoryArea(x, y, x_end, y_end);
|
||||
SetMemoryPointer(x, y);
|
||||
SendCommand(WRITE_RAM);
|
||||
/* send the image data */
|
||||
for (int j = 0; j < y_end - y + 1; j++) {
|
||||
for (int i = 0; i < (x_end - x + 1) / 8; i++) {
|
||||
SendData(image_buffer[i + j * (image_width / 8)]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief: put an image buffer to the frame memory.
|
||||
* this won't update the display.
|
||||
*
|
||||
* Question: When do you use this function instead of
|
||||
* void SetFrameMemory(
|
||||
* const unsigned char* image_buffer,
|
||||
* int x,
|
||||
* int y,
|
||||
* int image_width,
|
||||
* int image_height
|
||||
* );
|
||||
* Answer: SetFrameMemory with parameters only reads image data
|
||||
* from the RAM but not from the flash in AVR chips (for AVR chips,
|
||||
* you have to use the function pgm_read_byte to read buffers
|
||||
* from the flash).
|
||||
*/
|
||||
void Epd::SetFrameMemory(const unsigned char* image_buffer) {
|
||||
SetMemoryArea(0, 0, this->width - 1, this->height - 1);
|
||||
SetMemoryPointer(0, 0);
|
||||
SendCommand(WRITE_RAM);
|
||||
/* send the image data */
|
||||
for (int i = 0; i < this->width / 8 * this->height; i++) {
|
||||
SendData(pgm_read_byte(&image_buffer[i]));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief: clear the frame memory with the specified color.
|
||||
* this won't update the display.
|
||||
*/
|
||||
void Epd::ClearFrameMemory(unsigned char color) {
|
||||
SetMemoryArea(0, 0, this->width - 1, this->height - 1);
|
||||
SetMemoryPointer(0, 0);
|
||||
SendCommand(WRITE_RAM);
|
||||
/* send the color data */
|
||||
for (int i = 0; i < this->width / 8 * this->height; i++) {
|
||||
SendData(color);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief: update the display
|
||||
* there are 2 memory areas embedded in the e-paper display
|
||||
* but once this function is called,
|
||||
* the the next action of SetFrameMemory or ClearFrame will
|
||||
* set the other memory area.
|
||||
*/
|
||||
void Epd::DisplayFrame(void) {
|
||||
SendCommand(DISPLAY_UPDATE_CONTROL_2);
|
||||
SendData(0xC4);
|
||||
SendCommand(MASTER_ACTIVATION);
|
||||
SendCommand(TERMINATE_FRAME_READ_WRITE);
|
||||
WaitUntilIdle();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief: private function to specify the memory area for data R/W
|
||||
*/
|
||||
void Epd::SetMemoryArea(int x_start, int y_start, int x_end, int y_end) {
|
||||
SendCommand(SET_RAM_X_ADDRESS_START_END_POSITION);
|
||||
/* x point must be the multiple of 8 or the last 3 bits will be ignored */
|
||||
SendData((x_start >> 3) & 0xFF);
|
||||
SendData((x_end >> 3) & 0xFF);
|
||||
SendCommand(SET_RAM_Y_ADDRESS_START_END_POSITION);
|
||||
SendData(y_start & 0xFF);
|
||||
SendData((y_start >> 8) & 0xFF);
|
||||
SendData(y_end & 0xFF);
|
||||
SendData((y_end >> 8) & 0xFF);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief: private function to specify the start point for data R/W
|
||||
*/
|
||||
void Epd::SetMemoryPointer(int x, int y) {
|
||||
SendCommand(SET_RAM_X_ADDRESS_COUNTER);
|
||||
/* x point must be the multiple of 8 or the last 3 bits will be ignored */
|
||||
SendData((x >> 3) & 0xFF);
|
||||
SendCommand(SET_RAM_Y_ADDRESS_COUNTER);
|
||||
SendData(y & 0xFF);
|
||||
SendData((y >> 8) & 0xFF);
|
||||
WaitUntilIdle();
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief: After this command is transmitted, the chip would enter the
|
||||
* deep-sleep mode to save power.
|
||||
* The deep sleep mode would return to standby by hardware reset.
|
||||
* You can use Epd::Init() to awaken
|
||||
*/
|
||||
void Epd::Sleep() {
|
||||
SendCommand(DEEP_SLEEP_MODE);
|
||||
WaitUntilIdle();
|
||||
}
|
||||
|
||||
const unsigned char lut_full_update[] =
|
||||
{
|
||||
0x02, 0x02, 0x01, 0x11, 0x12, 0x12, 0x22, 0x22,
|
||||
0x66, 0x69, 0x69, 0x59, 0x58, 0x99, 0x99, 0x88,
|
||||
0x00, 0x00, 0x00, 0x00, 0xF8, 0xB4, 0x13, 0x51,
|
||||
0x35, 0x51, 0x51, 0x19, 0x01, 0x00
|
||||
};
|
||||
|
||||
const unsigned char lut_partial_update[] =
|
||||
{
|
||||
0x10, 0x18, 0x18, 0x08, 0x18, 0x18, 0x08, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
|
||||
0x00, 0x00, 0x00, 0x00, 0x13, 0x14, 0x44, 0x12,
|
||||
0x00, 0x00, 0x00, 0x00, 0x00, 0x00
|
||||
};
|
||||
|
||||
|
||||
/* END OF FILE */
|
||||
|
||||
|
|
@ -1,100 +0,0 @@
|
|||
/**
|
||||
* @filename : epd2in9.h
|
||||
* @brief : Header file for e-paper display library epd2in9.cpp
|
||||
* @author : Yehui from Waveshare
|
||||
*
|
||||
* Copyright (C) Waveshare September 5 2017
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documnetation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS OR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef EPD2IN9_H
|
||||
#define EPD2IN9_H
|
||||
|
||||
#include "epdif.h"
|
||||
|
||||
// Display resolution
|
||||
#define EPD_WIDTH 128
|
||||
#define EPD_HEIGHT 296
|
||||
|
||||
// EPD2IN9 commands
|
||||
#define DRIVER_OUTPUT_CONTROL 0x01
|
||||
#define BOOSTER_SOFT_START_CONTROL 0x0C
|
||||
#define GATE_SCAN_START_POSITION 0x0F
|
||||
#define DEEP_SLEEP_MODE 0x10
|
||||
#define DATA_ENTRY_MODE_SETTING 0x11
|
||||
#define SW_RESET 0x12
|
||||
#define TEMPERATURE_SENSOR_CONTROL 0x1A
|
||||
#define MASTER_ACTIVATION 0x20
|
||||
#define DISPLAY_UPDATE_CONTROL_1 0x21
|
||||
#define DISPLAY_UPDATE_CONTROL_2 0x22
|
||||
#define WRITE_RAM 0x24
|
||||
#define WRITE_VCOM_REGISTER 0x2C
|
||||
#define WRITE_LUT_REGISTER 0x32
|
||||
#define SET_DUMMY_LINE_PERIOD 0x3A
|
||||
#define SET_GATE_TIME 0x3B
|
||||
#define BORDER_WAVEFORM_CONTROL 0x3C
|
||||
#define SET_RAM_X_ADDRESS_START_END_POSITION 0x44
|
||||
#define SET_RAM_Y_ADDRESS_START_END_POSITION 0x45
|
||||
#define SET_RAM_X_ADDRESS_COUNTER 0x4E
|
||||
#define SET_RAM_Y_ADDRESS_COUNTER 0x4F
|
||||
#define TERMINATE_FRAME_READ_WRITE 0xFF
|
||||
|
||||
extern const unsigned char lut_full_update[];
|
||||
extern const unsigned char lut_partial_update[];
|
||||
|
||||
class Epd : EpdIf {
|
||||
public:
|
||||
unsigned long width;
|
||||
unsigned long height;
|
||||
|
||||
Epd();
|
||||
~Epd();
|
||||
int Init(const unsigned char* lut);
|
||||
void SendCommand(unsigned char command);
|
||||
void SendData(unsigned char data);
|
||||
void WaitUntilIdle(void);
|
||||
void Reset(void);
|
||||
void SetFrameMemory(
|
||||
const unsigned char* image_buffer,
|
||||
int x,
|
||||
int y,
|
||||
int image_width,
|
||||
int image_height
|
||||
);
|
||||
void SetFrameMemory(const unsigned char* image_buffer);
|
||||
void ClearFrameMemory(unsigned char color);
|
||||
void DisplayFrame(void);
|
||||
void Sleep(void);
|
||||
|
||||
private:
|
||||
unsigned int reset_pin;
|
||||
unsigned int dc_pin;
|
||||
unsigned int cs_pin;
|
||||
unsigned int busy_pin;
|
||||
const unsigned char* lut;
|
||||
|
||||
void SetLut(const unsigned char* lut);
|
||||
void SetMemoryArea(int x_start, int y_start, int x_end, int y_end);
|
||||
void SetMemoryPointer(int x, int y);
|
||||
};
|
||||
|
||||
#endif /* EPD2IN9_H */
|
||||
|
||||
/* END OF FILE */
|
|
@ -1,342 +0,0 @@
|
|||
/**
|
||||
* @filename : epdpaint.cpp
|
||||
* @brief : Paint tools
|
||||
* @author : Yehui from Waveshare
|
||||
*
|
||||
* Copyright (C) Waveshare September 9 2017
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documnetation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS OR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <pgmspace.h>
|
||||
#include "epdpaint.h"
|
||||
|
||||
Paint::Paint(unsigned char* image, int width, int height) {
|
||||
this->rotate = ROTATE_0;
|
||||
this->image = image;
|
||||
/* 1 byte = 8 pixels, so the width should be the multiple of 8 */
|
||||
this->width = width % 8 ? width + 8 - (width % 8) : width;
|
||||
this->height = height;
|
||||
}
|
||||
|
||||
Paint::~Paint() {
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief: clear the image
|
||||
*/
|
||||
void Paint::Clear(int colored) {
|
||||
for (int x = 0; x < this->width; x++) {
|
||||
for (int y = 0; y < this->height; y++) {
|
||||
DrawAbsolutePixel(x, y, colored);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief: this draws a pixel by absolute coordinates.
|
||||
* this function won't be affected by the rotate parameter.
|
||||
*/
|
||||
void Paint::DrawAbsolutePixel(int x, int y, int colored) {
|
||||
if (x < 0 || x >= this->width || y < 0 || y >= this->height) {
|
||||
return;
|
||||
}
|
||||
if (IF_INVERT_COLOR) {
|
||||
if (colored) {
|
||||
image[(x + y * this->width) / 8] |= 0x80 >> (x % 8);
|
||||
} else {
|
||||
image[(x + y * this->width) / 8] &= ~(0x80 >> (x % 8));
|
||||
}
|
||||
} else {
|
||||
if (colored) {
|
||||
image[(x + y * this->width) / 8] &= ~(0x80 >> (x % 8));
|
||||
} else {
|
||||
image[(x + y * this->width) / 8] |= 0x80 >> (x % 8);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief: Getters and Setters
|
||||
*/
|
||||
unsigned char* Paint::GetImage(void) {
|
||||
return this->image;
|
||||
}
|
||||
|
||||
int Paint::GetWidth(void) {
|
||||
return this->width;
|
||||
}
|
||||
|
||||
void Paint::SetWidth(int width) {
|
||||
this->width = width % 8 ? width + 8 - (width % 8) : width;
|
||||
}
|
||||
|
||||
int Paint::GetHeight(void) {
|
||||
return this->height;
|
||||
}
|
||||
|
||||
void Paint::SetHeight(int height) {
|
||||
this->height = height;
|
||||
}
|
||||
|
||||
int Paint::GetRotate(void) {
|
||||
return this->rotate;
|
||||
}
|
||||
|
||||
void Paint::SetRotate(int rotate){
|
||||
this->rotate = rotate;
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief: this draws a pixel by the coordinates
|
||||
*/
|
||||
void Paint::DrawPixel(int x, int y, int colored) {
|
||||
int point_temp;
|
||||
if (this->rotate == ROTATE_0) {
|
||||
if(x < 0 || x >= this->width || y < 0 || y >= this->height) {
|
||||
return;
|
||||
}
|
||||
DrawAbsolutePixel(x, y, colored);
|
||||
} else if (this->rotate == ROTATE_90) {
|
||||
if(x < 0 || x >= this->height || y < 0 || y >= this->width) {
|
||||
return;
|
||||
}
|
||||
point_temp = x;
|
||||
x = this->width - y;
|
||||
y = point_temp;
|
||||
DrawAbsolutePixel(x, y, colored);
|
||||
} else if (this->rotate == ROTATE_180) {
|
||||
if(x < 0 || x >= this->width || y < 0 || y >= this->height) {
|
||||
return;
|
||||
}
|
||||
x = this->width - x;
|
||||
y = this->height - y;
|
||||
DrawAbsolutePixel(x, y, colored);
|
||||
} else if (this->rotate == ROTATE_270) {
|
||||
if(x < 0 || x >= this->height || y < 0 || y >= this->width) {
|
||||
return;
|
||||
}
|
||||
point_temp = x;
|
||||
x = y;
|
||||
y = this->height - point_temp;
|
||||
DrawAbsolutePixel(x, y, colored);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief: this draws a charactor on the frame buffer but not refresh
|
||||
*/
|
||||
void Paint::DrawCharAt(int x, int y, char ascii_char, sFONT* font, int colored) {
|
||||
int i, j;
|
||||
unsigned int char_offset = (ascii_char - ' ') * font->Height * (font->Width / 8 + (font->Width % 8 ? 1 : 0));
|
||||
const unsigned char* ptr = &font->table[char_offset];
|
||||
|
||||
for (j = 0; j < font->Height; j++) {
|
||||
for (i = 0; i < font->Width; i++) {
|
||||
if (pgm_read_byte(ptr) & (0x80 >> (i % 8))) {
|
||||
DrawPixel(x + i, y + j, colored);
|
||||
}
|
||||
if (i % 8 == 7) {
|
||||
ptr++;
|
||||
}
|
||||
}
|
||||
if (font->Width % 8 != 0) {
|
||||
ptr++;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief: this displays a string on the frame buffer but not refresh
|
||||
*/
|
||||
void Paint::DrawStringAt(int x, int y, const char* text, sFONT* font, int colored) {
|
||||
const char* p_text = text;
|
||||
unsigned int counter = 0;
|
||||
int refcolumn = x;
|
||||
|
||||
/* Send the string character by character on EPD */
|
||||
while (*p_text != 0) {
|
||||
/* Display one character on EPD */
|
||||
DrawCharAt(refcolumn, y, *p_text, font, colored);
|
||||
/* Decrement the column position by 16 */
|
||||
refcolumn += font->Width;
|
||||
/* Point on the next character */
|
||||
p_text++;
|
||||
counter++;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief: this draws a line on the frame buffer
|
||||
*/
|
||||
void Paint::DrawLine(int x0, int y0, int x1, int y1, int colored) {
|
||||
/* Bresenham algorithm */
|
||||
int dx = x1 - x0 >= 0 ? x1 - x0 : x0 - x1;
|
||||
int sx = x0 < x1 ? 1 : -1;
|
||||
int dy = y1 - y0 <= 0 ? y1 - y0 : y0 - y1;
|
||||
int sy = y0 < y1 ? 1 : -1;
|
||||
int err = dx + dy;
|
||||
|
||||
while((x0 != x1) && (y0 != y1)) {
|
||||
DrawPixel(x0, y0 , colored);
|
||||
if (2 * err >= dy) {
|
||||
err += dy;
|
||||
x0 += sx;
|
||||
}
|
||||
if (2 * err <= dx) {
|
||||
err += dx;
|
||||
y0 += sy;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief: this draws a horizontal line on the frame buffer
|
||||
*/
|
||||
void Paint::DrawHorizontalLine(int x, int y, int line_width, int colored) {
|
||||
int i;
|
||||
for (i = x; i < x + line_width; i++) {
|
||||
DrawPixel(i, y, colored);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief: this draws a vertical line on the frame buffer
|
||||
*/
|
||||
void Paint::DrawVerticalLine(int x, int y, int line_height, int colored) {
|
||||
int i;
|
||||
for (i = y; i < y + line_height; i++) {
|
||||
DrawPixel(x, i, colored);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief: this draws a rectangle
|
||||
*/
|
||||
void Paint::DrawRectangle(int x0, int y0, int x1, int y1, int colored) {
|
||||
int min_x, min_y, max_x, max_y;
|
||||
min_x = x1 > x0 ? x0 : x1;
|
||||
max_x = x1 > x0 ? x1 : x0;
|
||||
min_y = y1 > y0 ? y0 : y1;
|
||||
max_y = y1 > y0 ? y1 : y0;
|
||||
|
||||
DrawHorizontalLine(min_x, min_y, max_x - min_x + 1, colored);
|
||||
DrawHorizontalLine(min_x, max_y, max_x - min_x + 1, colored);
|
||||
DrawVerticalLine(min_x, min_y, max_y - min_y + 1, colored);
|
||||
DrawVerticalLine(max_x, min_y, max_y - min_y + 1, colored);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief: this draws a filled rectangle
|
||||
*/
|
||||
void Paint::DrawFilledRectangle(int x0, int y0, int x1, int y1, int colored) {
|
||||
int min_x, min_y, max_x, max_y;
|
||||
int i;
|
||||
min_x = x1 > x0 ? x0 : x1;
|
||||
max_x = x1 > x0 ? x1 : x0;
|
||||
min_y = y1 > y0 ? y0 : y1;
|
||||
max_y = y1 > y0 ? y1 : y0;
|
||||
|
||||
for (i = min_x; i <= max_x; i++) {
|
||||
DrawVerticalLine(i, min_y, max_y - min_y + 1, colored);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief: this draws a circle
|
||||
*/
|
||||
void Paint::DrawCircle(int x, int y, int radius, int colored) {
|
||||
/* Bresenham algorithm */
|
||||
int x_pos = -radius;
|
||||
int y_pos = 0;
|
||||
int err = 2 - 2 * radius;
|
||||
int e2;
|
||||
|
||||
do {
|
||||
DrawPixel(x - x_pos, y + y_pos, colored);
|
||||
DrawPixel(x + x_pos, y + y_pos, colored);
|
||||
DrawPixel(x + x_pos, y - y_pos, colored);
|
||||
DrawPixel(x - x_pos, y - y_pos, colored);
|
||||
e2 = err;
|
||||
if (e2 <= y_pos) {
|
||||
err += ++y_pos * 2 + 1;
|
||||
if(-x_pos == y_pos && e2 <= x_pos) {
|
||||
e2 = 0;
|
||||
}
|
||||
}
|
||||
if (e2 > x_pos) {
|
||||
err += ++x_pos * 2 + 1;
|
||||
}
|
||||
} while (x_pos <= 0);
|
||||
}
|
||||
|
||||
/**
|
||||
* @brief: this draws a filled circle
|
||||
*/
|
||||
void Paint::DrawFilledCircle(int x, int y, int radius, int colored) {
|
||||
/* Bresenham algorithm */
|
||||
int x_pos = -radius;
|
||||
int y_pos = 0;
|
||||
int err = 2 - 2 * radius;
|
||||
int e2;
|
||||
|
||||
do {
|
||||
DrawPixel(x - x_pos, y + y_pos, colored);
|
||||
DrawPixel(x + x_pos, y + y_pos, colored);
|
||||
DrawPixel(x + x_pos, y - y_pos, colored);
|
||||
DrawPixel(x - x_pos, y - y_pos, colored);
|
||||
DrawHorizontalLine(x + x_pos, y + y_pos, 2 * (-x_pos) + 1, colored);
|
||||
DrawHorizontalLine(x + x_pos, y - y_pos, 2 * (-x_pos) + 1, colored);
|
||||
e2 = err;
|
||||
if (e2 <= y_pos) {
|
||||
err += ++y_pos * 2 + 1;
|
||||
if(-x_pos == y_pos && e2 <= x_pos) {
|
||||
e2 = 0;
|
||||
}
|
||||
}
|
||||
if(e2 > x_pos) {
|
||||
err += ++x_pos * 2 + 1;
|
||||
}
|
||||
} while(x_pos <= 0);
|
||||
}
|
||||
|
||||
/* END OF FILE */
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
@ -1,75 +0,0 @@
|
|||
/**
|
||||
* @filename : epdpaint.h
|
||||
* @brief : Header file for epdpaint.cpp
|
||||
* @author : Yehui from Waveshare
|
||||
*
|
||||
* Copyright (C) Waveshare July 28 2017
|
||||
*
|
||||
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
* of this software and associated documnetation files (the "Software"), to deal
|
||||
* in the Software without restriction, including without limitation the rights
|
||||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
* copies of the Software, and to permit persons to whom the Software is
|
||||
* furished to do so, subject to the following conditions:
|
||||
*
|
||||
* The above copyright notice and this permission notice shall be included in
|
||||
* all copies or substantial portions of the Software.
|
||||
*
|
||||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
* FITNESS OR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
* LIABILITY WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||
* THE SOFTWARE.
|
||||
*/
|
||||
|
||||
#ifndef EPDPAINT_H
|
||||
#define EPDPAINT_H
|
||||
|
||||
// Display orientation
|
||||
#define ROTATE_0 0
|
||||
#define ROTATE_90 1
|
||||
#define ROTATE_180 2
|
||||
#define ROTATE_270 3
|
||||
|
||||
// Color inverse. 1 or 0 = set or reset a bit if set a colored pixel
|
||||
#define IF_INVERT_COLOR 1
|
||||
|
||||
#include "fonts.h"
|
||||
|
||||
class Paint {
|
||||
public:
|
||||
Paint(unsigned char* image, int width, int height);
|
||||
~Paint();
|
||||
void Clear(int colored);
|
||||
int GetWidth(void);
|
||||
void SetWidth(int width);
|
||||
int GetHeight(void);
|
||||
void SetHeight(int height);
|
||||
int GetRotate(void);
|
||||
void SetRotate(int rotate);
|
||||
unsigned char* GetImage(void);
|
||||
void DrawAbsolutePixel(int x, int y, int colored);
|
||||
void DrawPixel(int x, int y, int colored);
|
||||
void DrawCharAt(int x, int y, char ascii_char, sFONT* font, int colored);
|
||||
void DrawStringAt(int x, int y, const char* text, sFONT* font, int colored);
|
||||
void DrawLine(int x0, int y0, int x1, int y1, int colored);
|
||||
void DrawHorizontalLine(int x, int y, int width, int colored);
|
||||
void DrawVerticalLine(int x, int y, int height, int colored);
|
||||
void DrawRectangle(int x0, int y0, int x1, int y1, int colored);
|
||||
void DrawFilledRectangle(int x0, int y0, int x1, int y1, int colored);
|
||||
void DrawCircle(int x, int y, int radius, int colored);
|
||||
void DrawFilledCircle(int x, int y, int radius, int colored);
|
||||
|
||||
private:
|
||||
unsigned char* image;
|
||||
int width;
|
||||
int height;
|
||||
int rotate;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
/* END OF FILE */
|
||||
|
|
@ -1,75 +0,0 @@
|
|||
/**
|
||||
******************************************************************************
|
||||
* @file fonts.h
|
||||
* @author MCD Application Team
|
||||
* @version V1.0.0
|
||||
* @date 18-February-2014
|
||||
* @brief Header for fonts.c file
|
||||
******************************************************************************
|
||||
* @attention
|
||||
*
|
||||
* <h2><center>© COPYRIGHT(c) 2014 STMicroelectronics</center></h2>
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* 3. Neither the name of STMicroelectronics nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*
|
||||
******************************************************************************
|
||||
*/
|
||||
|
||||
/* Define to prevent recursive inclusion -------------------------------------*/
|
||||
#ifndef __FONTS_H
|
||||
#define __FONTS_H
|
||||
|
||||
/* Max size of bitmap will based on a font24 (17x24) */
|
||||
#define MAX_HEIGHT_FONT 24
|
||||
#define MAX_WIDTH_FONT 17
|
||||
#define OFFSET_BITMAP 54
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
/* Includes ------------------------------------------------------------------*/
|
||||
#include <stdint.h>
|
||||
|
||||
typedef struct _tFont
|
||||
{
|
||||
const uint8_t *table;
|
||||
uint16_t Width;
|
||||
uint16_t Height;
|
||||
|
||||
} sFONT;
|
||||
|
||||
extern sFONT Font24;
|
||||
extern sFONT Font20;
|
||||
extern sFONT Font16;
|
||||
extern sFONT Font12;
|
||||
extern sFONT Font8;
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __FONTS_H */
|
||||
|
||||
|
||||
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
|