3535// Release 802: Added references to application notes
3636// Release 802: Refactored CoG functions
3737// Release 803: Added types for string and frame-buffer
38+ // Release 804: Improved power management
3839//
3940
4041// Library header
@@ -464,7 +465,26 @@ void Screen_EPD_EXT3_Fast::COG_MediumKP_powerOff()
464465void Screen_EPD_EXT3_Fast::COG_SmallKP_reset ()
465466{
466467 // Application note § 2. Power on COG driver
467- b_reset (5 , 5 , 10 , 5 , 5 ); // small
468+ b_reset (5 , 5 , 10 , 5 , 5 ); // Small
469+
470+ // Check after reset
471+ switch (u_eScreen_EPD)
472+ {
473+ case eScreen_EPD_150_KS_0J:
474+ case eScreen_EPD_152_KS_0J:
475+
476+ if (digitalRead (b_pin.panelBusy ) == HIGH)
477+ {
478+ mySerial.println ();
479+ mySerial.println (" hV * Incorrect type for 1.52-Wide" );
480+ while (0x01 );
481+ }
482+ break ;
483+
484+ default :
485+
486+ break ;
487+ }
468488}
469489
470490void Screen_EPD_EXT3_Fast::COG_SmallKP_getDataOTP ()
@@ -873,13 +893,27 @@ void Screen_EPD_EXT3_Fast::begin()
873893 break ;
874894 }
875895
896+ //
897+ // === Touch section
898+ //
899+
900+ //
901+ // === End of touch section
902+ //
903+
904+ //
905+ // === Large screen section
906+ //
876907 // Check panelCSS for large screens
877908 if (((u_codeSize == SIZE_969) or (u_codeSize == SIZE_1198)) and (b_pin.panelCSS == NOT_CONNECTED))
878909 {
879910 mySerial.println ();
880911 mySerial.println (" hV * Required pin panelCSS is NOT_CONNECTED" );
881912 while (0x01 );
882913 }
914+ //
915+ // === End of Large screen section
916+ //
883917
884918 // Configure board
885919 switch (u_codeSize)
@@ -903,6 +937,14 @@ void Screen_EPD_EXT3_Fast::begin()
903937 break ;
904938 }
905939
940+ //
941+ // === Touch section
942+ //
943+
944+ //
945+ // === End of touch section
946+ //
947+
906948 // Sizes
907949 switch (u_codeSize)
908950 {
@@ -1061,6 +1103,10 @@ void Screen_EPD_EXT3_Fast::begin()
10611103
10621104 memset (s_newImage, 0x00 , u_pageColourSize * u_bufferDepth);
10631105
1106+ setTemperatureC (25 ); // 25 Celsius = 77 Fahrenheit
1107+ b_fsmPowerScreen = FSM_OFF;
1108+ setPowerProfile (MODE_MANUAL, SCOPE_GPIO_ONLY);
1109+
10641110 // Turn SPI on, initialise GPIOs and set GPIO levels
10651111 // Reset panel and get tables
10661112 resume ();
@@ -1080,10 +1126,13 @@ void Screen_EPD_EXT3_Fast::begin()
10801126 v_penSolid = false ;
10811127 u_invert = false ;
10821128
1083- setTemperatureC (25 ); // 25 Celsius = 77 Fahrenheit
1129+ //
1130+ // === Touch section
1131+ //
10841132
1085- // Turn SPI off and pull GPIOs low
1086- suspend ();
1133+ //
1134+ // === End of Touch section
1135+ //
10871136}
10881137
10891138STRING_TYPE Screen_EPD_EXT3_Fast::WhoAmI ()
@@ -1094,62 +1143,61 @@ STRING_TYPE Screen_EPD_EXT3_Fast::WhoAmI()
10941143 return formatString (" iTC %i.%02i\" %s" , v_screenDiagonal / 100 , v_screenDiagonal % 100 , work);
10951144}
10961145
1097- void Screen_EPD_EXT3_Fast::suspend ()
1146+ void Screen_EPD_EXT3_Fast::suspend (uint8_t suspendScope )
10981147{
1099- // Suspend GPIO
1100- b_suspend ();
1101-
1102- // Suspend SPI
1103- hV_HAL_SPI_end ();
1148+ if (((suspendScope & FSM_GPIO_MASK) == FSM_GPIO_MASK) and (b_pin.panelPower != NOT_CONNECTED))
1149+ {
1150+ if ((b_fsmPowerScreen & FSM_GPIO_MASK) == FSM_GPIO_MASK)
1151+ {
1152+ b_suspend ();
1153+ }
1154+ }
11041155}
11051156
11061157void Screen_EPD_EXT3_Fast::resume ()
11071158{
1108- // Resume GPIO
1109- b_resume ();
1110-
1111- // Check type and get tables
1112- if (u_flagOTP == false )
1159+ // Target FSM_ON
1160+ // Source FSM_OFF
1161+ // FSM_SLEEP
1162+ if (b_fsmPowerScreen != FSM_ON)
11131163 {
1114- hV_HAL_SPI3_begin (); // Define 3-wire SPI pins
1115- s_getDataOTP (); // 3-wire SPI read OTP memory
1116- }
1164+ if ((b_fsmPowerScreen & FSM_GPIO_MASK) != FSM_GPIO_MASK)
1165+ {
1166+ b_resume (); // GPIO
11171167
1118- // Reset
1119- s_reset ();
1168+ s_reset (); // Reset
11201169
1121- // Check after reset
1122- switch (u_eScreen_EPD)
1123- {
1124- case eScreen_EPD_150_KS_0J:
1125- case eScreen_EPD_152_KS_0J:
1170+ b_fsmPowerScreen |= FSM_GPIO_MASK;
1171+ }
11261172
1127- if (digitalRead (b_pin.panelBusy ) == HIGH)
1128- {
1129- mySerial.println ();
1130- mySerial.println (" hV * Incorrect type for 1.52-Wide" );
1131- while (0x01 );
1132- }
1133- break ;
1173+ // Check type and get tables
1174+ if (u_flagOTP == false )
1175+ {
1176+ s_getDataOTP (); // 3-wire SPI read OTP memory
11341177
1135- default :
1178+ s_reset (); // Reset
1179+ }
11361180
1137- break ;
1138- }
1181+ // Start SPI
1182+ switch (u_eScreen_EPD)
1183+ {
1184+ case eScreen_EPD_150_KS_0J:
1185+ case eScreen_EPD_152_KS_0J:
11391186
1140- // Start SPI
1141- switch (u_eScreen_EPD)
1142- {
1143- case eScreen_EPD_150_KS_0J:
1144- case eScreen_EPD_152_KS_0J:
1187+ hV_HAL_SPI_begin (16000000 ); // 1.52" tested with 4, 8, 16 and 32 MHz, with unicity check
1188+ break ;
11451189
1146- hV_HAL_SPI_begin ( 16000000 ); // 1.52" tested with 4, 8, 16 and 32 MHz
1147- break ;
1190+ case eScreen_EPD_206_KS_0E:
1191+ case eScreen_EPD_290_KS_0F:
11481192
1149- default :
1193+ hV_HAL_SPI_begin (16000000 ); // 2.06" tested with 4, 8 and 16 MHz, with unicity check
1194+ break ;
11501195
1151- hV_HAL_SPI_begin (); // Standard 8 MHz
1152- break ;
1196+ default :
1197+
1198+ hV_HAL_SPI_begin (); // Standard 8 MHz, with unicity check
1199+ break ;
1200+ }
11531201 }
11541202}
11551203
@@ -1175,7 +1223,11 @@ void Screen_EPD_EXT3_Fast::s_reset()
11751223
11761224void Screen_EPD_EXT3_Fast::s_getDataOTP ()
11771225{
1178- uint16_t _readBytes = 0 ;
1226+ hV_HAL_SPI_end (); // With unicity check
1227+
1228+ hV_HAL_SPI3_begin (); // Define 3-wire SPI pins
1229+
1230+ // Get data OTP
11791231 switch (b_family)
11801232 {
11811233 case FAMILY_MEDIUM:
@@ -1196,8 +1248,11 @@ void Screen_EPD_EXT3_Fast::s_getDataOTP()
11961248
11971249void Screen_EPD_EXT3_Fast::s_flush (uint8_t updateMode)
11981250{
1199- // Turn SPI on, initialise GPIOs and set GPIO levels
1200- resume ();
1251+ // Resume
1252+ if (b_fsmPowerScreen != FSM_ON)
1253+ {
1254+ resume ();
1255+ }
12011256
12021257 switch (b_family)
12031258 {
@@ -1222,8 +1277,11 @@ void Screen_EPD_EXT3_Fast::s_flush(uint8_t updateMode)
12221277 break ;
12231278 }
12241279
1225- // Turn SPI off and pull GPIOs low
1226- suspend ();
1280+ // Suspend
1281+ if (u_suspendMode == MODE_AUTO)
1282+ {
1283+ suspend (u_suspendScope);
1284+ }
12271285}
12281286
12291287uint8_t Screen_EPD_EXT3_Fast::flushMode (uint8_t updateMode)
@@ -1337,7 +1395,7 @@ void Screen_EPD_EXT3_Fast::s_setOrientation(uint8_t orientation)
13371395
13381396bool Screen_EPD_EXT3_Fast::s_orientCoordinates (uint16_t & x, uint16_t & y)
13391397{
1340- bool _flagResult = RESULT_ERROR; // false = success, true = error
1398+ bool _flagResult = RESULT_ERROR;
13411399 switch (v_orientation)
13421400 {
13431401 case 3 : // checked, previously 1
@@ -1419,38 +1477,7 @@ uint16_t Screen_EPD_EXT3_Fast::s_getB(uint16_t x1, uint16_t y1)
14191477
14201478uint16_t Screen_EPD_EXT3_Fast::s_getPoint (uint16_t x1, uint16_t y1)
14211479{
1422- // Orient and check coordinates are within screen
1423- if (s_orientCoordinates (x1, y1) == RESULT_ERROR)
1424- {
1425- return 0x0000 ;
1426- }
1427-
1428- uint16_t _result = 0 ;
1429- uint8_t _value = 0 ;
1430-
1431- // Coordinates
1432- uint32_t z1 = s_getZ (x1, y1);
1433- uint16_t b1 = s_getB (x1, y1);
1434-
1435- _value = bitRead (s_newImage[z1], b1);
1436- _value <<= 4 ;
1437- _value &= 0b11110000 ;
1438-
1439- // red = 0-1, black = 1-0, white 0-0
1440- switch (_value)
1441- {
1442- case 0x10 :
1443-
1444- _result = myColours.black ;
1445- break ;
1446-
1447- default :
1448-
1449- _result = myColours.white ;
1450- break ;
1451- }
1452-
1453- return _result;
1480+ return 0x0000 ;
14541481}
14551482//
14561483// === End of Class section
0 commit comments