An example to display some text and graphics on a Waveshare 2.7" ePaper display tri-colour. From Kanjia 2.13" code.
Revision 0:fc1642aade4a, committed 2019-12-06
- Comitter:
- mdroberts1243
- Date:
- Fri Dec 06 23:31:49 2019 +0000
- Commit message:
- First commit. Adapted from Kanjia 2.13" example. May have an issue with an x offset (8 pixel border on Rotate 90 degrees mode)
Changed in this revision
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/EPD_2R7b.lib Fri Dec 06 23:31:49 2019 +0000 @@ -0,0 +1,1 @@ +https://os.mbed.com/users/mdroberts1243/code/EPD_2R7b/#9e6a8e3cd8de
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Fri Dec 06 23:31:49 2019 +0000 @@ -0,0 +1,128 @@ +/* + * e-Paper control program + * MODIFIED by Mark Roberts for the Waveshare 2.7inch Pi Hat + * Tested on Nucleo L432KC with pins as defined below... + * https://www.waveshare.com/wiki/2.7inch_e-Paper_HAT?spm=a2g0o.detail.1000023.17.1e014701V7d4HU&file=2.7inch_e-Paper_HAT + * + * Copyright (c) 2019 Kenji Arai / JH1PJL + * http://www.page.sannet.ne.jp/kenjia/index.html + * http://mbed.org/users/kenjiArai/ + * Created: April 27th, 2019 + * Revised: June 29th, 2019 + * + * Tested on Nucleo-F446RE with mbed-os5.12.2 + * + * Refrence software + * https://github.com/waveshare/e-Paper + * https://os.mbed.com/users/imachooon/code/epd1in54/ + * Thanks imamura-san + * + * Technical documents + * https://www.waveshare.com/wiki/2.13inch_e-Paper_HAT_(B) + * + * Product + * http://akizukidenshi.com/catalog/g/gP-13757/ + * https://www.waveshare.com/2.13inch-e-paper-hat-b.htm + */ + +// Include -------------------------------------------------------------------- +#include "mbed.h" +#include "epd2in7b.h" +#include "epdpaint.h" + +// Definition ----------------------------------------------------------------- +#define COLORED 0 +#define UNCOLORED 1 + +// Constructor ---------------------------------------------------------------- +// 3.3V, GND, DIN, , CLK, CS, DC, RST, BUSY, <- 2.13inch e-Paper pin +// mosi, miso, sclk, cs, dc, rst, busy, pwr +Epd epd = Epd( PB_5, NC, PB_3, PA_11, PA_0, PA_12, PA_1, NC); // modified for NUCLEO_L432KC + +Serial pc(USBTX, USBRX); +Timer t; +static int timeSet = 0; + +// RAM ------------------------------------------------------------------------ +uint8_t image[EPD_VERT*(EPD_HORIZ/8 + 1)]; + +// ROM / Constant data -------------------------------------------------------- + +// Function prototypes -------------------------------------------------------- +extern void time_enter_mode(void); + +//------------------------------------------------------------------------------ +// Control Program +//------------------------------------------------------------------------------ +int main() +{ + time_t seconds; + char buf[32]; + + t.reset(); + t.start(); +/* + if (timeSet == 0) { // if time not set then go to time enter mode + time_enter_mode(); + timeSet = 1; + } +*/ + seconds = time(NULL); // read current time + if (epd.Init() != 0) { // initialize e-Paper control program + printf("e-Paper init failed"); + return -1; + } + epd.ClearFrame(); + printf("Clear Frame completed\r\n"); + ThisThread::sleep_for(200); + Paint paint(image, EPD_HORIZ, EPD_VERT); + paint.Clear(UNCOLORED); + printf("Clear uncolored 1 complete\r\n"); + + paint.SetRotate(ROTATE_90); + paint.DrawStringAt(0, 4, "12345678901234567890123456789", + &Font8, COLORED); + paint.DrawStringAt(0, 16, "12345678901234567890123456789", + &Font12, COLORED); + paint.DrawStringAt(0, 32, "12345678901234567890123", + &Font16, COLORED); + paint.DrawStringAt(0, 54, "123456789012345678", + &Font20, COLORED); + paint.DrawStringAt(0, 80, "123456789012345", + &Font24, COLORED); + paint.DrawStringAt(0, 110, "Waveshare 2.7 e-Paper WBR", + &Font12, COLORED); + paint.DrawStringAt(0, 124, " tested on Nucleo-L432KC", + &Font12, COLORED); + paint.DrawStringAt(0, 138, " by mdroberts1243 ", + &Font12, COLORED); + strftime(buf, 30, "'%y-%m-%d %H:%M", localtime(&seconds)); + paint.DrawStringAt(0, 160, buf, &Font16, COLORED); + printf("Text paint buffer rendered\r\n"); + + epd.SetPartialWindowBlack(paint.GetImage(), 0, 8, + paint.GetWidth(), paint.GetHeight()); + printf("SetPartialWindowBlack\r\n"); + + paint.Clear(UNCOLORED); + printf("Clear uncolored 2 complete\r\n"); + paint.SetRotate(ROTATE_90); + paint.DrawFilledRectangle(0, 150, 250, 156, COLORED); + printf("Filled rectangle\r\n"); + paint.DrawFilledCircle(244, 150, 18, COLORED); + printf("Filled circle\r\n"); + epd.SetPartialWindowRed(paint.GetImage(), 0, 8, + paint.GetWidth(), paint.GetHeight()); + printf("SetPartialWindowRed\r\n"); + + epd.DisplayFrame(); + printf("DisplayFrame\r\n"); + + epd.Sleep(); + + strftime(buf, 30, " %B %d,'%y, %H:%M:%S", localtime(&seconds)); + pc.puts(buf); + pc.printf(" Display + Refresh time = %5.1f Sec\r\n", t.read()); + ThisThread::sleep_for((1000 * 60 * 1) - t.read_ms()); // sleep 1 minute + system_reset(); // restart +}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/set_RTC.cpp Fri Dec 06 23:31:49 2019 +0000 @@ -0,0 +1,159 @@ +/* + * Set time into RTC + * + * Copyright (c) 2019 Kenji Arai / JH1PJL + * http://www.page.sannet.ne.jp/kenjia/index.html + * http://mbed.org/users/kenjiArai/ + * Created: April 27th, 2019 + * Revised: June 29th, 2019 + */ + +#include "mbed.h" + +extern Serial pc; + +static void chk_and_set_time(char *ptr); +static int32_t xatoi (char **str, int32_t *res); +static void get_line (char *buff, int len); + +void time_enter_mode(void) +{ + char *ptr; + char linebuf[64]; + + pc.printf("\r\nSet time into RTC\r\n"); + pc.printf(" e.g. >19 6 29 10 11 12 -> June 29th,'19, 10:11:12\r\n"); + pc.printf(" If time is fine, just hit enter\r\n"); + pc.putc('>'); + ptr = linebuf; + get_line(ptr, sizeof(linebuf)); + pc.printf("\r"); + chk_and_set_time(ptr); +} + +static void get_line (char *buff, int len) +{ + char c; + uint32_t idx = 0; + + while(true) { + c = pc.getc(); + if (c == '\r') { + buff[idx++] = c; + break; + } + if ((c == '\b') && idx) { + idx--; + pc.putc(c); + pc.putc(' '); + pc.putc(c); + } + if (((uint8_t)c >= ' ') && (idx < len - 1)) { + buff[idx++] = c; + pc.putc(c); + } + } + buff[idx] = 0; + pc.puts("\r\n"); +} + +static void chk_and_set_time(char *ptr) +{ + int32_t p1; + struct tm t; + time_t seconds; + + if (xatoi(&ptr, &p1)) { + t.tm_year = (uint8_t)p1 + 100; + pc.printf("Year:%d ",p1); + xatoi( &ptr, &p1 ); + t.tm_mon = (uint8_t)p1 - 1; + pc.printf("Month:%d ",p1); + xatoi( &ptr, &p1 ); + t.tm_mday = (uint8_t)p1; + pc.printf("Day:%d ",p1); + xatoi( &ptr, &p1 ); + t.tm_hour = (uint8_t)p1; + pc.printf("Hour:%d ",p1); + xatoi( &ptr, &p1 ); + t.tm_min = (uint8_t)p1; + pc.printf("Min:%d ",p1); + xatoi( &ptr, &p1 ); + t.tm_sec = (uint8_t)p1; + pc.printf("Sec: %d \r\n",p1); + } else { + return; + } + seconds = mktime(&t); + set_time(seconds); + pc.printf( + "Date: %04d/%02d/%02d, %02d:%02d:%02d\r\n", + t.tm_year + 1900, t.tm_mon + 1, t.tm_mday, t.tm_hour, t.tm_min, t.tm_sec + ); +} + +static int32_t xatoi (char **str, int32_t *res) +{ + int32_t val; + uint8_t c, radix, s = 0; + + while ((c = **str) == ' ') { + (*str)++; + } + if (c == '-') { + s = 1; + c = *(++(*str)); + } + if (c == '0') { + c = *(++(*str)); + if (c <= ' ') { + *res = 0; + return 1; + } + if (c == 'x') { + radix = 16; + c = *(++(*str)); + } else { + if (c == 'b') { + radix = 2; + c = *(++(*str)); + } else { + if ((c >= '0')&&(c <= '9')) { + radix = 8; + } else { + return 0; + } + } + } + } else { + if ((c < '1')||(c > '9')) { + return 0; + } + radix = 10; + } + val = 0; + while (c > ' ') { + if (c >= 'a') { + c -= 0x20; + } + c -= '0'; + if (c >= 17) { + c -= 7; + if (c <= 9) { + return 0; + } + } + if (c >= radix) { + return 0; + } + val = val * radix + c; + c = *(++(*str)); + } + if (s) { + val = -val; + } + *res = val; + return 1; +} + +