Library for Waveshare epd1in54b (1.54 inch ePaper black/red)
e-Paper Module
Description
Waveshare 1.54 e-paper module imported from offiicial code https://www.waveshare.com/wiki/1.54inch_e-Paper_Module_(B) Codes are referenced from official Arduino code and Raspberry pi code.
SPI is used for communication between ePaper module and mbed.
Following shapes can be used:
- primitive shape (square, circle, line)
- font (variable sizes)
Pull request are appreciated (Note that the original code is copyrighted by (C) Waveshare )
Example Output
Display output with example code will be like following image:
Example Code
include the mbed library with this snippet
#include "mbed.h" #include "epd1in54b.h" // Control PinName rst; PinName dc; PinName busy; // SPI communication PinName mosi; PinName miso; PinName sclk; PinName cs; DigitalOut myled(LED1); unsigned char frame_black[EPD_HEIGHT*EPD_WIDTH/8]; unsigned char frame_red[EPD_HEIGHT*EPD_WIDTH/8]; int main() { mosi = p5; miso = p6; sclk = p7; cs = p8; rst = p9; dc = p10; busy = p11; memset(frame_black, 0xFF, sizeof(unsigned char)*EPD_HEIGHT*EPD_WIDTH/8); memset(frame_red, 0xFF, sizeof(unsigned char)*EPD_HEIGHT*EPD_WIDTH/8); Epd epd = Epd(mosi, miso, sclk, cs, dc, rst, busy); if (epd.Init() != 0){ return -1; } /* Draw something to the frame buffer */ // For simplicity, the arguments are explicit numerical coordinates epd.DrawRectangle(frame_black, 10, 60, 50, 110, COLORED); epd.DrawLine(frame_black, 10, 60, 50, 110, COLORED); epd.DrawLine(frame_black, 50, 60, 10, 110, COLORED); epd.DrawCircle(frame_black, 120, 80, 30, COLORED); epd.DrawFilledRectangle(frame_red, 10, 130, 50, 180, COLORED); epd.DrawFilledRectangle(frame_red, 0, 6, 200, 26, COLORED); epd.DrawFilledCircle(frame_red, 120, 150, 30, COLORED); /*Write strings to the buffer */ epd.DrawStringAt(frame_black, 30, 30, "e-Paper Demo", &Font16, COLORED); epd.DrawStringAt(frame_red, 28, 10, "Hello world!", &Font16, UNCOLORED); // display images epd.DisplayFrame(frame_black, frame_red); //epd.DisplayFrame(IMAGE_BLACK, IMAGE_RED); epd.Sleep(); while(1) { myled = 1; wait(0.5); myled = 0; wait(0.5); } }
epd1in54b.h@0:cba3c1061231, 2018-02-11 (annotated)
- Committer:
- imachooon
- Date:
- Sun Feb 11 01:34:23 2018 +0000
- Revision:
- 0:cba3c1061231
commimt as library
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
imachooon | 0:cba3c1061231 | 1 | /** |
imachooon | 0:cba3c1061231 | 2 | * @filename : epd1in54b.h |
imachooon | 0:cba3c1061231 | 3 | * @brief : Header file for e-paper display library epd1in54b.cpp |
imachooon | 0:cba3c1061231 | 4 | * @author : Yehui from Waveshare |
imachooon | 0:cba3c1061231 | 5 | * |
imachooon | 0:cba3c1061231 | 6 | * Copyright (C) Waveshare August 10 2017 |
imachooon | 0:cba3c1061231 | 7 | * |
imachooon | 0:cba3c1061231 | 8 | * Permission is hereby granted, free of charge, to any person obtaining a copy |
imachooon | 0:cba3c1061231 | 9 | * of this software and associated documnetation files (the "Software"), to deal |
imachooon | 0:cba3c1061231 | 10 | * in the Software without restriction, including without limitation the rights |
imachooon | 0:cba3c1061231 | 11 | * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
imachooon | 0:cba3c1061231 | 12 | * copies of the Software, and to permit persons to whom the Software is |
imachooon | 0:cba3c1061231 | 13 | * furished to do so, subject to the following conditions: |
imachooon | 0:cba3c1061231 | 14 | * |
imachooon | 0:cba3c1061231 | 15 | * The above copyright notice and this permission notice shall be included in |
imachooon | 0:cba3c1061231 | 16 | * all copies or substantial portions of the Software. |
imachooon | 0:cba3c1061231 | 17 | * |
imachooon | 0:cba3c1061231 | 18 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
imachooon | 0:cba3c1061231 | 19 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
imachooon | 0:cba3c1061231 | 20 | * FITNESS OR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
imachooon | 0:cba3c1061231 | 21 | * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
imachooon | 0:cba3c1061231 | 22 | * LIABILITY WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
imachooon | 0:cba3c1061231 | 23 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
imachooon | 0:cba3c1061231 | 24 | * THE SOFTWARE. |
imachooon | 0:cba3c1061231 | 25 | */ |
imachooon | 0:cba3c1061231 | 26 | |
imachooon | 0:cba3c1061231 | 27 | #ifndef EPD1IN54B_H |
imachooon | 0:cba3c1061231 | 28 | #define EPD1IN54B_H |
imachooon | 0:cba3c1061231 | 29 | |
imachooon | 0:cba3c1061231 | 30 | #include "epdif.h" |
imachooon | 0:cba3c1061231 | 31 | #include "fonts.h" |
imachooon | 0:cba3c1061231 | 32 | |
imachooon | 0:cba3c1061231 | 33 | #define LOW 0 |
imachooon | 0:cba3c1061231 | 34 | #define HIGH 1 |
imachooon | 0:cba3c1061231 | 35 | |
imachooon | 0:cba3c1061231 | 36 | // Display resolution |
imachooon | 0:cba3c1061231 | 37 | #define EPD_WIDTH 200 |
imachooon | 0:cba3c1061231 | 38 | #define EPD_HEIGHT 200 |
imachooon | 0:cba3c1061231 | 39 | |
imachooon | 0:cba3c1061231 | 40 | #define COLORED 1 |
imachooon | 0:cba3c1061231 | 41 | #define UNCOLORED 0 |
imachooon | 0:cba3c1061231 | 42 | |
imachooon | 0:cba3c1061231 | 43 | // EPD1IN54B commands |
imachooon | 0:cba3c1061231 | 44 | #define PANEL_SETTING 0x00 |
imachooon | 0:cba3c1061231 | 45 | #define POWER_SETTING 0x01 |
imachooon | 0:cba3c1061231 | 46 | #define POWER_OFF 0x02 |
imachooon | 0:cba3c1061231 | 47 | #define POWER_OFF_SEQUENCE_SETTING 0x03 |
imachooon | 0:cba3c1061231 | 48 | #define POWER_ON 0x04 |
imachooon | 0:cba3c1061231 | 49 | #define POWER_ON_MEASURE 0x05 |
imachooon | 0:cba3c1061231 | 50 | #define BOOSTER_SOFT_START 0x06 |
imachooon | 0:cba3c1061231 | 51 | #define DEEP_SLEEP 0x07 |
imachooon | 0:cba3c1061231 | 52 | #define DATA_START_TRANSMISSION_1 0x10 |
imachooon | 0:cba3c1061231 | 53 | #define DATA_STOP 0x11 |
imachooon | 0:cba3c1061231 | 54 | #define DISPLAY_REFRESH 0x12 |
imachooon | 0:cba3c1061231 | 55 | #define DATA_START_TRANSMISSION_2 0x13 |
imachooon | 0:cba3c1061231 | 56 | #define PLL_CONTROL 0x30 |
imachooon | 0:cba3c1061231 | 57 | #define TEMPERATURE_SENSOR_COMMAND 0x40 |
imachooon | 0:cba3c1061231 | 58 | #define TEMPERATURE_SENSOR_CALIBRATION 0x41 |
imachooon | 0:cba3c1061231 | 59 | #define TEMPERATURE_SENSOR_WRITE 0x42 |
imachooon | 0:cba3c1061231 | 60 | #define TEMPERATURE_SENSOR_READ 0x43 |
imachooon | 0:cba3c1061231 | 61 | #define VCOM_AND_DATA_INTERVAL_SETTING 0x50 |
imachooon | 0:cba3c1061231 | 62 | #define LOW_POWER_DETECTION 0x51 |
imachooon | 0:cba3c1061231 | 63 | #define TCON_SETTING 0x60 |
imachooon | 0:cba3c1061231 | 64 | #define TCON_RESOLUTION 0x61 |
imachooon | 0:cba3c1061231 | 65 | #define SOURCE_AND_GATE_START_SETTING 0x62 |
imachooon | 0:cba3c1061231 | 66 | #define GET_STATUS 0x71 |
imachooon | 0:cba3c1061231 | 67 | #define AUTO_MEASURE_VCOM 0x80 |
imachooon | 0:cba3c1061231 | 68 | #define VCOM_VALUE 0x81 |
imachooon | 0:cba3c1061231 | 69 | #define VCM_DC_SETTING_REGISTER 0x82 |
imachooon | 0:cba3c1061231 | 70 | #define PROGRAM_MODE 0xA0 |
imachooon | 0:cba3c1061231 | 71 | #define ACTIVE_PROGRAM 0xA1 |
imachooon | 0:cba3c1061231 | 72 | #define READ_OTP_DATA 0xA2 |
imachooon | 0:cba3c1061231 | 73 | |
imachooon | 0:cba3c1061231 | 74 | // Display orientation |
imachooon | 0:cba3c1061231 | 75 | #define ROTATE_0 0 |
imachooon | 0:cba3c1061231 | 76 | #define ROTATE_90 1 |
imachooon | 0:cba3c1061231 | 77 | #define ROTATE_180 2 |
imachooon | 0:cba3c1061231 | 78 | #define ROTATE_270 3 |
imachooon | 0:cba3c1061231 | 79 | |
imachooon | 0:cba3c1061231 | 80 | extern const unsigned char lut_vcom0[]; |
imachooon | 0:cba3c1061231 | 81 | extern const unsigned char lut_vcom1[]; |
imachooon | 0:cba3c1061231 | 82 | extern const unsigned char lut_w[]; |
imachooon | 0:cba3c1061231 | 83 | extern const unsigned char lut_b[]; |
imachooon | 0:cba3c1061231 | 84 | extern const unsigned char lut_g1[]; |
imachooon | 0:cba3c1061231 | 85 | extern const unsigned char lut_g2[]; |
imachooon | 0:cba3c1061231 | 86 | extern const unsigned char lut_red0[]; |
imachooon | 0:cba3c1061231 | 87 | extern const unsigned char lut_red1[]; |
imachooon | 0:cba3c1061231 | 88 | |
imachooon | 0:cba3c1061231 | 89 | class Epd : EpdIf { |
imachooon | 0:cba3c1061231 | 90 | public: |
imachooon | 0:cba3c1061231 | 91 | unsigned long width; |
imachooon | 0:cba3c1061231 | 92 | unsigned long height; |
imachooon | 0:cba3c1061231 | 93 | unsigned int rotate; |
imachooon | 0:cba3c1061231 | 94 | |
imachooon | 0:cba3c1061231 | 95 | Epd(PinName mosi, |
imachooon | 0:cba3c1061231 | 96 | PinName miso, |
imachooon | 0:cba3c1061231 | 97 | PinName sclk, |
imachooon | 0:cba3c1061231 | 98 | PinName cs, |
imachooon | 0:cba3c1061231 | 99 | PinName dc, |
imachooon | 0:cba3c1061231 | 100 | PinName rst, |
imachooon | 0:cba3c1061231 | 101 | PinName busy |
imachooon | 0:cba3c1061231 | 102 | ); |
imachooon | 0:cba3c1061231 | 103 | ~Epd(); |
imachooon | 0:cba3c1061231 | 104 | int Init(void); |
imachooon | 0:cba3c1061231 | 105 | void SendCommand(unsigned char command); |
imachooon | 0:cba3c1061231 | 106 | void SendData(unsigned char data); |
imachooon | 0:cba3c1061231 | 107 | void WaitUntilIdle(void); |
imachooon | 0:cba3c1061231 | 108 | void Reset(void); |
imachooon | 0:cba3c1061231 | 109 | void SetLutBw(void); |
imachooon | 0:cba3c1061231 | 110 | void SetLutRed(void); |
imachooon | 0:cba3c1061231 | 111 | void DisplayFrame(const unsigned char* frame_buffer_black, const unsigned char* frame_buffer_red); |
imachooon | 0:cba3c1061231 | 112 | void Sleep(void); |
imachooon | 0:cba3c1061231 | 113 | void SetRotate(int rotate); |
imachooon | 0:cba3c1061231 | 114 | void SetPixel(unsigned char *frame_buffer, int x, int y, int colored); |
imachooon | 0:cba3c1061231 | 115 | void SetAbsolutePixel(unsigned char *frame_buffer, int x, int y, int colored); |
imachooon | 0:cba3c1061231 | 116 | void DrawLine(unsigned char *frame_buffer, int x0, int y0, int x1, int y1, int colored); |
imachooon | 0:cba3c1061231 | 117 | void DrawHorizontalLine(unsigned char *frame_buffer, int x, int y, int width, int colored); |
imachooon | 0:cba3c1061231 | 118 | void DrawVerticalLine(unsigned char *frame_buffer, int x, int y, int height, int colored); |
imachooon | 0:cba3c1061231 | 119 | void DrawRectangle(unsigned char *frame_buffer, int x0, int y0, int x1, int y1, int colored); |
imachooon | 0:cba3c1061231 | 120 | void DrawFilledRectangle(unsigned char *frame_buffer, int x0, int y0, int x1, int y1, int colored); |
imachooon | 0:cba3c1061231 | 121 | void DrawCircle(unsigned char *frame_buffer, int x, int y, int radius, int colored); |
imachooon | 0:cba3c1061231 | 122 | void DrawFilledCircle(unsigned char *frame_buffer, int x, int y, int radius, int colored); |
imachooon | 0:cba3c1061231 | 123 | void DrawCharAt(unsigned char *frame_buffer, int x, int y, char ascii_char, sFONT* font, int colored); |
imachooon | 0:cba3c1061231 | 124 | void DrawStringAt(unsigned char *frame_buffer, int x, int y, const char* text, sFONT* font, int colored); |
imachooon | 0:cba3c1061231 | 125 | |
imachooon | 0:cba3c1061231 | 126 | |
imachooon | 0:cba3c1061231 | 127 | }; |
imachooon | 0:cba3c1061231 | 128 | |
imachooon | 0:cba3c1061231 | 129 | #endif /* EPD1IN54B_H */ |
imachooon | 0:cba3c1061231 | 130 | |
imachooon | 0:cba3c1061231 | 131 | /* END OF FILE */ |