Kenji Arai
/
ePD_4R2inch_test_program_on_nRF52
test program for 4.2inch e-Paper
Embed:
(wiki syntax)
Show/hide line numbers
main.cpp
00001 /* 00002 * e-Paper control program 00003 * 00004 * Copyright (c) 2019 Kenji Arai / JH1PJL 00005 * http://www.page.sannet.ne.jp/kenjia/index.html 00006 * http://mbed.org/users/kenjiArai/ 00007 * Created: April 27th, 2019 00008 * Revised: August 29th, 2019 00009 * 00010 * Tested on nRF52-DK with mbed-os5.13.3 00011 * 00012 * Refrence software 00013 * https://github.com/waveshare/e-Paper 00014 * https://os.mbed.com/users/imachooon/code/epd1in54/ 00015 * Thanks imamura-san 00016 * 00017 * Technical documents 00018 * https://www.waveshare.com/wiki/2.13inch_e-Paper_HAT_(B) 00019 * 00020 * Product 00021 * http://akizukidenshi.com/catalog/g/gP-13757/ 00022 * https://www.waveshare.com/2.13inch-e-paper-hat-b.htm 00023 */ 00024 00025 // Include -------------------------------------------------------------------- 00026 #include "mbed.h" 00027 #include "epd4in2b.h" 00028 #include "epdpaint.h" 00029 00030 // Definition ----------------------------------------------------------------- 00031 #define COLORED 0 00032 #define UNCOLORED 1 00033 00034 #define DEBUG 0 00035 00036 #if DEBUG 00037 #define DBG(...) pc.printf(__VA_ARGS__) 00038 #else 00039 #define DBG(...) {;} 00040 #endif 00041 00042 // Constructor ---------------------------------------------------------------- 00043 #if defined(TARGET_NRF52832) 00044 // mosi,miso, sclk, cs, dc, rst, busy, pwr 00045 Epd epd = Epd(P0_23, NC, P0_25, P0_22, P0_19, P0_20, P0_2, P0_11); 00046 DigitalIn button1(P0_13); 00047 #elif defined(TARGET_NRF52840) 00048 // mosi,miso, sclk, cs, dc, rst, busy, pwr 00049 Epd epd = Epd(P1_13, NC, P1_15, P1_12, P1_10, P1_11, P0_2, P1_1); 00050 DigitalIn button1(P0_11); 00051 #else 00052 #error "Only for nRF52840 & nRF52832 CPU" 00053 #endif 00054 Serial pc(USBTX, USBRX); 00055 Timer t; 00056 00057 // RAM ------------------------------------------------------------------------ 00058 uint8_t image[EPD_HEIGHT*(EPD_WIDTH/8 + 1)]; 00059 00060 // ROM / Constant data -------------------------------------------------------- 00061 00062 // Function prototypes -------------------------------------------------------- 00063 extern void time_enter_mode(void); 00064 00065 //------------------------------------------------------------------------------ 00066 // Control Program 00067 //------------------------------------------------------------------------------ 00068 void set_p14_for_detect() 00069 { 00070 NRF_GPIO->PIN_CNF[14] = 3UL << 16; // BTN2 00071 } 00072 00073 int main() 00074 { 00075 time_t seconds; 00076 char buf[32]; 00077 00078 DBG("line:%d\r\n", __LINE__); 00079 t.reset(); 00080 t.start(); 00081 if (button1 == 0) { // USER BUTTON1 is on then go to time enter mode 00082 time_enter_mode(); 00083 } 00084 epd.PwrOn(); 00085 ThisThread::sleep_for(10); 00086 DBG("line:%d\r\n", __LINE__); 00087 seconds = time(NULL); // read current time 00088 if (epd.Init() != 0) { // initialize e-Paper control program 00089 printf("e-Paper init failed"); 00090 return -1; 00091 } 00092 DBG("line:%d\r\n", __LINE__); 00093 epd.ClearFrame(); 00094 ThisThread::sleep_for(200); 00095 Paint paint(image, EPD_WIDTH, EPD_HEIGHT); 00096 paint.Clear(UNCOLORED); 00097 //paint.SetRotate(ROTATE_90); 00098 DBG("line:%d\r\n", __LINE__); 00099 paint.DrawStringAt(0, 4, "123456789012345678901234567890123456789012345678901234567890", 00100 &Font12, COLORED); 00101 paint.DrawStringAt(0, 16, " Waveshare 4.2 e-Paper WBY", 00102 &Font12, COLORED); 00103 paint.DrawStringAt(0, 30, "Run on mbed-os5.13.4 Latest Revision", 00104 &Font16, COLORED); 00105 paint.DrawStringAt(0, 45, " tested on Nordic nRF52-DK & nRF52840-DK", 00106 &Font12, COLORED); 00107 paint.DrawStringAt(0, 58, " by JH1PJL Kenji Arai", 00108 &Font12, COLORED); 00109 DBG("line:%d\r\n", __LINE__); 00110 strftime(buf, 30, "'%y-%m-%d %H:%M", localtime(&seconds)); 00111 paint.DrawStringAt(0, 90, buf, &Font16, COLORED); 00112 strftime(buf, 30, " %B %d,'%y, %H:%M:%S", localtime(&seconds)); 00113 pc.puts(buf); 00114 paint.DrawStringAt(0, 110, " e-Paper 4.2inch", 00115 &Font8, COLORED); 00116 paint.DrawStringAt(0, 120, " e-Paper 4.2inch", 00117 &Font12, COLORED); 00118 paint.DrawStringAt(0, 135, " e-Paper 4.2inch", 00119 &Font16, COLORED); 00120 paint.DrawStringAt(0, 150, " e-Paper 4.2inch", 00121 &Font20, COLORED); 00122 paint.DrawStringAt(0, 175, " e-Paper 4.2inch", 00123 &Font24, COLORED); 00124 paint.DrawStringAt(0, 200, " e-Paper 4.2inch", 00125 &Font2829, COLORED); 00126 paint.DrawStringAt(0, 230, " e-Paper 4.2inch", 00127 &Font4040, COLORED); 00128 00129 epd.SetPartialWindowBlack(paint.GetImage(), 0, 8, 00130 paint.GetWidth(), paint.GetHeight()); 00131 paint.Clear(UNCOLORED); 00132 //paint.SetRotate(ROTATE_90); 00133 paint.DrawFilledRectangle(0, 28, 400, 29, COLORED); 00134 paint.DrawFilledRectangle(0, 43, 400, 44, COLORED); 00135 paint.DrawFilledRectangle(0, 74, 350, 80, COLORED); 00136 paint.DrawFilledCircle(350, 76, 30, COLORED); 00137 epd.SetPartialWindowRed(paint.GetImage(), 0, 8, 00138 paint.GetWidth(), paint.GetHeight()); 00139 epd.DisplayFrame(); 00140 epd.Sleep(); 00141 epd.PwrOff(); 00142 ThisThread::sleep_for(1000); 00143 pc.printf(" Display + Refresh time = %5.1f Sec\r\n", t.read()); 00144 ThisThread::sleep_for(10); 00145 set_p14_for_detect(); 00146 NRF_POWER->SYSTEMOFF = 1; 00147 while(true) { 00148 ; 00149 } 00150 system_reset(); // restart 00151 }
Generated on Thu Jul 14 2022 15:24:22 by 1.7.2