From fd9d5a5e3538f6ac3bc154a0f7a8bfc27e107dd2 Mon Sep 17 00:00:00 2001 From: Rei Vilo Date: Thu, 18 Jul 2024 15:34:45 +0200 Subject: [PATCH] Release 8.0.4 Added power management --- .../Example_Fast_Temperature.ino | 4 +- library.properties | 2 +- src/Screen_EPD_EXT3.cpp | 193 ++++++++++-------- src/Screen_EPD_EXT3.h | 12 +- src/hV_Board.cpp | 125 +++++++----- src/hV_Board.h | 13 +- src/hV_Configuration.h | 2 + src/hV_Documentation.h | 4 +- src/hV_HAL_Peripherals.cpp | 76 +++++-- src/hV_HAL_Peripherals.h | 19 +- src/hV_List_Constants.h | 30 ++- src/hV_List_Options.h | 16 +- src/hV_Utilities_PDLS.cpp | 12 ++ src/hV_Utilities_PDLS.h | 15 +- 14 files changed, 340 insertions(+), 183 deletions(-) diff --git a/examples/Example_Fast_Temperature/Example_Fast_Temperature.ino b/examples/Example_Fast_Temperature/Example_Fast_Temperature.ino index a9efea5..4937286 100644 --- a/examples/Example_Fast_Temperature/Example_Fast_Temperature.ino +++ b/examples/Example_Fast_Temperature/Example_Fast_Temperature.ino @@ -34,8 +34,8 @@ // Define structures and classes // Define variables and constants -Screen_EPD_EXT3_Fast myScreen(eScreen_EPD_271_PS_09_Fast, boardRaspberryPiPico_RP2040); -// Screen_EPD_EXT3_Fast myScreen(eScreen_EPD_271_PS_09_Wide, boardRaspberryPiPico_RP2040); +Screen_EPD_EXT3_Fast myScreen(eScreen_EPD_271_PS_09, boardRaspberryPiPico_RP2040); +// Screen_EPD_EXT3_Fast myScreen(eScreen_EPD_271_KS_09, boardRaspberryPiPico_RP2040); // Prototypes diff --git a/library.properties b/library.properties index 068da8f..70c7de6 100755 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=PDLS_EXT3_Basic_Fast -version=8.0.3 +version=8.0.4 author=Rei Vilo for Pervasive Displays maintainer=Rei Vilo sentence=Library for Pervasive Displays iTC monochrome screens with embedded fast update and EXT3-1 board diff --git a/src/Screen_EPD_EXT3.cpp b/src/Screen_EPD_EXT3.cpp index 52f4f4b..892cfc4 100755 --- a/src/Screen_EPD_EXT3.cpp +++ b/src/Screen_EPD_EXT3.cpp @@ -35,6 +35,7 @@ // Release 802: Added references to application notes // Release 802: Refactored CoG functions // Release 803: Added types for string and frame-buffer +// Release 804: Improved power management // // Library header @@ -464,7 +465,26 @@ void Screen_EPD_EXT3_Fast::COG_MediumKP_powerOff() void Screen_EPD_EXT3_Fast::COG_SmallKP_reset() { // Application note ยง 2. Power on COG driver - b_reset(5, 5, 10, 5, 5); // small + b_reset(5, 5, 10, 5, 5); // Small + + // Check after reset + switch (u_eScreen_EPD) + { + case eScreen_EPD_150_KS_0J: + case eScreen_EPD_152_KS_0J: + + if (digitalRead(b_pin.panelBusy) == HIGH) + { + mySerial.println(); + mySerial.println("hV * Incorrect type for 1.52-Wide"); + while (0x01); + } + break; + + default: + + break; + } } void Screen_EPD_EXT3_Fast::COG_SmallKP_getDataOTP() @@ -873,6 +893,17 @@ void Screen_EPD_EXT3_Fast::begin() break; } + // + // === Touch section + // + + // + // === End of touch section + // + + // + // === Large screen section + // // Check panelCSS for large screens if (((u_codeSize == SIZE_969) or (u_codeSize == SIZE_1198)) and (b_pin.panelCSS == NOT_CONNECTED)) { @@ -880,6 +911,9 @@ void Screen_EPD_EXT3_Fast::begin() mySerial.println("hV * Required pin panelCSS is NOT_CONNECTED"); while (0x01); } + // + // === End of Large screen section + // // Configure board switch (u_codeSize) @@ -903,6 +937,14 @@ void Screen_EPD_EXT3_Fast::begin() break; } + // + // === Touch section + // + + // + // === End of touch section + // + // Sizes switch (u_codeSize) { @@ -1061,6 +1103,10 @@ void Screen_EPD_EXT3_Fast::begin() memset(s_newImage, 0x00, u_pageColourSize * u_bufferDepth); + setTemperatureC(25); // 25 Celsius = 77 Fahrenheit + b_fsmPowerScreen = FSM_OFF; + setPowerProfile(MODE_MANUAL, SCOPE_GPIO_ONLY); + // Turn SPI on, initialise GPIOs and set GPIO levels // Reset panel and get tables resume(); @@ -1080,10 +1126,13 @@ void Screen_EPD_EXT3_Fast::begin() v_penSolid = false; u_invert = false; - setTemperatureC(25); // 25 Celsius = 77 Fahrenheit + // + // === Touch section + // - // Turn SPI off and pull GPIOs low - suspend(); + // + // === End of Touch section + // } STRING_TYPE Screen_EPD_EXT3_Fast::WhoAmI() @@ -1094,62 +1143,61 @@ STRING_TYPE Screen_EPD_EXT3_Fast::WhoAmI() return formatString("iTC %i.%02i\"%s", v_screenDiagonal / 100, v_screenDiagonal % 100, work); } -void Screen_EPD_EXT3_Fast::suspend() +void Screen_EPD_EXT3_Fast::suspend(uint8_t suspendScope) { - // Suspend GPIO - b_suspend(); - - // Suspend SPI - hV_HAL_SPI_end(); + if (((suspendScope & FSM_GPIO_MASK) == FSM_GPIO_MASK) and (b_pin.panelPower != NOT_CONNECTED)) + { + if ((b_fsmPowerScreen & FSM_GPIO_MASK) == FSM_GPIO_MASK) + { + b_suspend(); + } + } } void Screen_EPD_EXT3_Fast::resume() { - // Resume GPIO - b_resume(); - - // Check type and get tables - if (u_flagOTP == false) + // Target FSM_ON + // Source FSM_OFF + // FSM_SLEEP + if (b_fsmPowerScreen != FSM_ON) { - hV_HAL_SPI3_begin(); // Define 3-wire SPI pins - s_getDataOTP(); // 3-wire SPI read OTP memory - } + if ((b_fsmPowerScreen & FSM_GPIO_MASK) != FSM_GPIO_MASK) + { + b_resume(); // GPIO - // Reset - s_reset(); + s_reset(); // Reset - // Check after reset - switch (u_eScreen_EPD) - { - case eScreen_EPD_150_KS_0J: - case eScreen_EPD_152_KS_0J: + b_fsmPowerScreen |= FSM_GPIO_MASK; + } - if (digitalRead(b_pin.panelBusy) == HIGH) - { - mySerial.println(); - mySerial.println("hV * Incorrect type for 1.52-Wide"); - while (0x01); - } - break; + // Check type and get tables + if (u_flagOTP == false) + { + s_getDataOTP(); // 3-wire SPI read OTP memory - default: + s_reset(); // Reset + } - break; - } + // Start SPI + switch (u_eScreen_EPD) + { + case eScreen_EPD_150_KS_0J: + case eScreen_EPD_152_KS_0J: - // Start SPI - switch (u_eScreen_EPD) - { - case eScreen_EPD_150_KS_0J: - case eScreen_EPD_152_KS_0J: + hV_HAL_SPI_begin(16000000); // 1.52" tested with 4, 8, 16 and 32 MHz, with unicity check + break; - hV_HAL_SPI_begin(16000000); // 1.52" tested with 4, 8, 16 and 32 MHz - break; + case eScreen_EPD_206_KS_0E: + case eScreen_EPD_290_KS_0F: - default: + hV_HAL_SPI_begin(16000000); // 2.06" tested with 4, 8 and 16 MHz, with unicity check + break; - hV_HAL_SPI_begin(); // Standard 8 MHz - break; + default: + + hV_HAL_SPI_begin(); // Standard 8 MHz, with unicity check + break; + } } } @@ -1175,7 +1223,11 @@ void Screen_EPD_EXT3_Fast::s_reset() void Screen_EPD_EXT3_Fast::s_getDataOTP() { - uint16_t _readBytes = 0; + hV_HAL_SPI_end(); // With unicity check + + hV_HAL_SPI3_begin(); // Define 3-wire SPI pins + + // Get data OTP switch (b_family) { case FAMILY_MEDIUM: @@ -1196,8 +1248,11 @@ void Screen_EPD_EXT3_Fast::s_getDataOTP() void Screen_EPD_EXT3_Fast::s_flush(uint8_t updateMode) { - // Turn SPI on, initialise GPIOs and set GPIO levels - resume(); + // Resume + if (b_fsmPowerScreen != FSM_ON) + { + resume(); + } switch (b_family) { @@ -1222,8 +1277,11 @@ void Screen_EPD_EXT3_Fast::s_flush(uint8_t updateMode) break; } - // Turn SPI off and pull GPIOs low - suspend(); + // Suspend + if (u_suspendMode == MODE_AUTO) + { + suspend(u_suspendScope); + } } uint8_t Screen_EPD_EXT3_Fast::flushMode(uint8_t updateMode) @@ -1337,7 +1395,7 @@ void Screen_EPD_EXT3_Fast::s_setOrientation(uint8_t orientation) bool Screen_EPD_EXT3_Fast::s_orientCoordinates(uint16_t & x, uint16_t & y) { - bool _flagResult = RESULT_ERROR; // false = success, true = error + bool _flagResult = RESULT_ERROR; switch (v_orientation) { case 3: // checked, previously 1 @@ -1419,38 +1477,7 @@ uint16_t Screen_EPD_EXT3_Fast::s_getB(uint16_t x1, uint16_t y1) uint16_t Screen_EPD_EXT3_Fast::s_getPoint(uint16_t x1, uint16_t y1) { - // Orient and check coordinates are within screen - if (s_orientCoordinates(x1, y1) == RESULT_ERROR) - { - return 0x0000; - } - - uint16_t _result = 0; - uint8_t _value = 0; - - // Coordinates - uint32_t z1 = s_getZ(x1, y1); - uint16_t b1 = s_getB(x1, y1); - - _value = bitRead(s_newImage[z1], b1); - _value <<= 4; - _value &= 0b11110000; - - // red = 0-1, black = 1-0, white 0-0 - switch (_value) - { - case 0x10: - - _result = myColours.black; - break; - - default: - - _result = myColours.white; - break; - } - - return _result; + return 0x0000; } // // === End of Class section diff --git a/src/Screen_EPD_EXT3.h b/src/Screen_EPD_EXT3.h index 5544e3b..f39eedc 100755 --- a/src/Screen_EPD_EXT3.h +++ b/src/Screen_EPD_EXT3.h @@ -26,8 +26,8 @@ /// * 4.37 reference xE2437PS0Cx /// /// @author Rei Vilo -/// @date 21 May 2024 -/// @version 803 +/// @date 21 Jul 2024 +/// @version 804 /// /// @copyright (c) Rei Vilo, 2010-2024 /// @copyright All rights reserved @@ -89,7 +89,7 @@ /// /// @brief Library release number /// -#define SCREEN_EPD_EXT3_RELEASE 803 +#define SCREEN_EPD_EXT3_RELEASE 804 /// /// @brief Library variant @@ -136,9 +136,11 @@ class Screen_EPD_EXT3_Fast final : public hV_Screen_Buffer, public hV_Utilities_ /// /// @brief Suspend - /// @details Turn SPI off and set all GPIOs low + /// @param suspendScope default = SCOPE_GPIO_ONLY, otherwise SCOPE_NONE + /// @details Power off and set all GPIOs low + /// @note If panelPower is NOT_CONNECTED, SCOPE_GPIO_ONLY defaults to SCOPE_NONE /// - void suspend(); + void suspend(uint8_t suspendScope = SCOPE_GPIO_ONLY); /// /// @brief Resume after suspend() diff --git a/src/hV_Board.cpp b/src/hV_Board.cpp index 658d1a5..359f351 100755 --- a/src/hV_Board.cpp +++ b/src/hV_Board.cpp @@ -13,6 +13,7 @@ // // Release 700: Initial release // Release 801: Improved double-panel screen management +// Release 804: Improved power management // // Library header @@ -20,7 +21,7 @@ hV_Board::hV_Board() { - ; + b_fsmPowerScreen = FSM_OFF; } void hV_Board::b_begin(pins_t board, uint8_t family, uint16_t delayCS) @@ -28,6 +29,7 @@ void hV_Board::b_begin(pins_t board, uint8_t family, uint16_t delayCS) b_pin = board; b_family = family; b_delayCS = delayCS; + b_fsmPowerScreen = FSM_OFF; } void hV_Board::b_reset(uint32_t ms1, uint32_t ms2, uint32_t ms3, uint32_t ms4, uint32_t ms5) @@ -54,61 +56,74 @@ void hV_Board::b_waitBusy(bool state) void hV_Board::b_suspend() { - // Optional power circuit - if (b_pin.panelPower != NOT_CONNECTED) // generic + if ((b_fsmPowerScreen & FSM_GPIO_MASK) == FSM_GPIO_MASK) { - digitalWrite(b_pin.panelPower, LOW); + // Optional power circuit + if (b_pin.panelPower != NOT_CONNECTED) // generic + { + digitalWrite(b_pin.panelPower, LOW); + } + b_fsmPowerScreen &= ~FSM_GPIO_MASK; } } void hV_Board::b_resume() { - // Optional power circuit - if (b_pin.panelPower != NOT_CONNECTED) // generic + // Target FSM_ON + // Source FSM_SLEEP -> FSM_SLEEP + // FSM_OFF -> FSM_SLEEP + + if ((b_fsmPowerScreen & FSM_GPIO_MASK) != FSM_GPIO_MASK) { - pinMode(b_pin.panelPower, OUTPUT); - digitalWrite(b_pin.panelPower, HIGH); - } + // Optional power circuit + if (b_pin.panelPower != NOT_CONNECTED) // generic + { + pinMode(b_pin.panelPower, OUTPUT); + digitalWrite(b_pin.panelPower, HIGH); + } - // Configure GPIOs - pinMode(b_pin.panelBusy, INPUT); + // Configure GPIOs + pinMode(b_pin.panelBusy, INPUT); - pinMode(b_pin.panelDC, OUTPUT); - digitalWrite(b_pin.panelDC, HIGH); + pinMode(b_pin.panelDC, OUTPUT); + digitalWrite(b_pin.panelDC, HIGH); - pinMode(b_pin.panelReset, OUTPUT); - digitalWrite(b_pin.panelReset, HIGH); + pinMode(b_pin.panelReset, OUTPUT); + digitalWrite(b_pin.panelReset, HIGH); - pinMode(b_pin.panelCS, OUTPUT); - digitalWrite(b_pin.panelCS, HIGH); // CS# = 1 + pinMode(b_pin.panelCS, OUTPUT); + digitalWrite(b_pin.panelCS, HIGH); // CS# = 1 - if (b_pin.panelCSS != NOT_CONNECTED) // generic - { - pinMode(b_pin.panelCSS, OUTPUT); - digitalWrite(b_pin.panelCSS, HIGH); - } + if (b_pin.panelCSS != NOT_CONNECTED) // generic + { + pinMode(b_pin.panelCSS, OUTPUT); + digitalWrite(b_pin.panelCSS, HIGH); + } - // External SPI memory - if (b_pin.flashCS != NOT_CONNECTED) // generic - { - pinMode(b_pin.flashCS, OUTPUT); - digitalWrite(b_pin.flashCS, HIGH); - } - if (b_pin.flashCSS != NOT_CONNECTED) // generic - { - pinMode(b_pin.flashCSS, OUTPUT); - digitalWrite(b_pin.flashCSS, HIGH); - } + // External SPI memory + if (b_pin.flashCS != NOT_CONNECTED) // generic + { + pinMode(b_pin.flashCS, OUTPUT); + digitalWrite(b_pin.flashCS, HIGH); + } + if (b_pin.flashCSS != NOT_CONNECTED) // generic + { + pinMode(b_pin.flashCSS, OUTPUT); + digitalWrite(b_pin.flashCSS, HIGH); + } - // External SD card - if (b_pin.cardCS != NOT_CONNECTED) // generic - { - pinMode(b_pin.cardCS, OUTPUT); - digitalWrite(b_pin.cardCS, HIGH); - } - if (b_pin.cardDetect != NOT_CONNECTED) // generic - { - pinMode(b_pin.cardCS, INPUT); + // External SD card + if (b_pin.cardCS != NOT_CONNECTED) // generic + { + pinMode(b_pin.cardCS, OUTPUT); + digitalWrite(b_pin.cardCS, HIGH); + } + if (b_pin.cardDetect != NOT_CONNECTED) // generic + { + pinMode(b_pin.cardCS, INPUT); + } + + b_fsmPowerScreen |= FSM_GPIO_MASK; } } @@ -118,7 +133,7 @@ void hV_Board::b_sendIndexFixed(uint8_t index, uint8_t data, uint32_t size) digitalWrite(b_pin.panelCS, LOW); // CS High = Select Master delayMicroseconds(b_delayCS); - SPI.transfer(index); + hV_HAL_SPI_transfer(index); delayMicroseconds(b_delayCS); digitalWrite(b_pin.panelDC, HIGH); // DC High = Data @@ -126,7 +141,7 @@ void hV_Board::b_sendIndexFixed(uint8_t index, uint8_t data, uint32_t size) delayMicroseconds(b_delayCS); for (uint32_t i = 0; i < size; i++) { - SPI.transfer(data); // b_sendIndexFixed + hV_HAL_SPI_transfer(data); // b_sendIndexFixed } delayMicroseconds(b_delayCS); @@ -139,7 +154,7 @@ void hV_Board::b_sendIndexFixedSelect(uint8_t index, uint8_t data, uint32_t size b_select(select); // Select half of large screen delayMicroseconds(b_delayCS); // Longer delay for large screens - SPI.transfer(index); + hV_HAL_SPI_transfer(index); delayMicroseconds(b_delayCS); // Longer delay for large screens digitalWrite(b_pin.panelDC, HIGH); // DC High = Data @@ -147,7 +162,7 @@ void hV_Board::b_sendIndexFixedSelect(uint8_t index, uint8_t data, uint32_t size delayMicroseconds(b_delayCS); // Longer delay for large screens for (uint32_t i = 0; i < size; i++) { - SPI.transfer(data); // b_sendIndexFixed + hV_HAL_SPI_transfer(data); // b_sendIndexFixed } delayMicroseconds(b_delayCS); // Longer delay for large screens @@ -171,7 +186,7 @@ void hV_Board::b_sendIndexData(uint8_t index, const uint8_t * data, uint32_t siz delayMicroseconds(450); // 450 + 50 = 500 } delayMicroseconds(b_delayCS); - SPI.transfer(index); + hV_HAL_SPI_transfer(index); delayMicroseconds(b_delayCS); if (b_family == FAMILY_LARGE) { @@ -195,7 +210,7 @@ void hV_Board::b_sendIndexData(uint8_t index, const uint8_t * data, uint32_t siz delayMicroseconds(b_delayCS); for (uint32_t i = 0; i < size; i++) { - SPI.transfer(data[i]); + hV_HAL_SPI_transfer(data[i]); } delayMicroseconds(b_delayCS); digitalWrite(b_pin.panelCS, HIGH); // CS High @@ -217,7 +232,7 @@ void hV_Board::b_sendIndexDataSelect(uint8_t index, const uint8_t * data, uint32 b_select(select); // Select half of large screen delayMicroseconds(b_delayCS); // Longer delay for large screens - SPI.transfer(index); + hV_HAL_SPI_transfer(index); delayMicroseconds(b_delayCS); // Longer delay for large screens digitalWrite(b_pin.panelDC, HIGH); // DC High = Data @@ -225,7 +240,7 @@ void hV_Board::b_sendIndexDataSelect(uint8_t index, const uint8_t * data, uint32 delayMicroseconds(b_delayCS); // Longer delay for large screens for (uint32_t i = 0; i < size; i++) { - SPI.transfer(data[i]); + hV_HAL_SPI_transfer(data[i]); } delayMicroseconds(b_delayCS); // Longer delay for large screens @@ -280,10 +295,10 @@ void hV_Board::b_sendCommandDataSelect8(uint8_t command, uint8_t data, uint8_t s digitalWrite(b_pin.panelDC, LOW); // LOW = command b_select(select); // Select half of large screen - SPI.transfer(command); + hV_HAL_SPI_transfer(command); digitalWrite(b_pin.panelDC, HIGH); // HIGH = data - SPI.transfer(data); + hV_HAL_SPI_transfer(data); digitalWrite(b_pin.panelCS, HIGH); if (b_pin.panelCSS != NOT_CONNECTED) @@ -297,7 +312,7 @@ void hV_Board::b_sendCommand8(uint8_t command) digitalWrite(b_pin.panelDC, LOW); digitalWrite(b_pin.panelCS, LOW); - SPI.transfer(command); + hV_HAL_SPI_transfer(command); digitalWrite(b_pin.panelCS, HIGH); } @@ -307,10 +322,10 @@ void hV_Board::b_sendCommandData8(uint8_t command, uint8_t data) digitalWrite(b_pin.panelDC, LOW); // LOW = command digitalWrite(b_pin.panelCS, LOW); - SPI.transfer(command); + hV_HAL_SPI_transfer(command); digitalWrite(b_pin.panelDC, HIGH); // HIGH = data - SPI.transfer(data); + hV_HAL_SPI_transfer(data); digitalWrite(b_pin.panelCS, HIGH); } diff --git a/src/hV_Board.h b/src/hV_Board.h index 0a89267..7d7b001 100755 --- a/src/hV_Board.h +++ b/src/hV_Board.h @@ -8,8 +8,8 @@ /// * Edition: Advanced /// /// @author Rei Vilo -/// @date 21 Mar 2024 -/// @version 801 +/// @date 21 Jul 2024 +/// @version 804 /// /// @copyright (c) Rei Vilo, 2010-2024 /// @copyright All rights reserved @@ -44,7 +44,7 @@ /// /// @brief Library release number /// -#define hV_BOARD_RELEASE 801 +#define hV_BOARD_RELEASE 804 // Objects // @@ -165,18 +165,21 @@ class hV_Board void b_sendCommandDataSelect8(uint8_t command, uint8_t data, uint8_t select = PANEL_CS_BOTH); /// - /// @brief Suspend + /// @brief Suspend GPIOs + /// @details Turn off and set low all GPIOs /// void b_suspend(); /// - /// @brief Resume + /// @brief Resume GPIOs + /// @details Turn on and configure all GPIOs /// void b_resume(); pins_t b_pin; uint16_t b_delayCS = 50; // ms uint8_t b_family; + uint8_t b_fsmPowerScreen = FSM_OFF; private: /// @brief Select one half of large screens diff --git a/src/hV_Configuration.h b/src/hV_Configuration.h index b9d7ecf..029c101 100755 --- a/src/hV_Configuration.h +++ b/src/hV_Configuration.h @@ -17,6 +17,7 @@ /// * 9. Set GPIO expander mode, not implemented /// * 10. String object for basic edition /// * 11. Set storage mode, not implemented +/// * 12. Set debug options /// /// @author Rei Vilo /// @date 21 May 2024 @@ -103,6 +104,7 @@ /// @name 9. Set GPIO expander mode, not implemented /// @name 10. String object of char array options for string. /// @name 11. Set storage mode, serial console by default +/// @name 12. Set debug options /// /// @see hV_List_Options.h /// diff --git a/src/hV_Documentation.h b/src/hV_Documentation.h index 2b0fc88..bff3670 100755 --- a/src/hV_Documentation.h +++ b/src/hV_Documentation.h @@ -41,8 +41,8 @@ /// Additionally, the **[Wiki](https://docs.pervasivedisplays.com/)** provides a gradual introduction to the e-paper technology and how to use it. /// /// @author Rei Vilo -/// @date 21 May 2024 -/// @version 803 +/// @date 21 Jul 2024 +/// @version 804 /// /// @copyright (c) Rei Vilo, 2010-2024 /// @copyright All rights reserved diff --git a/src/hV_HAL_Peripherals.cpp b/src/hV_HAL_Peripherals.cpp index 38f624a..021c3a4 100644 --- a/src/hV_HAL_Peripherals.cpp +++ b/src/hV_HAL_Peripherals.cpp @@ -22,6 +22,7 @@ // Release 800: Added 3-wire SPI // Release 801: Added SPI configuration // Release 803: Improved stability +// Release 804: Improved power management // // Library header @@ -73,47 +74,80 @@ void hV_HAL_begin() // === End of General section // +// +// === GPIO section +// + +// +// === End of GPIO section +// + +// +// === Time section +// + +// +// === End of Time section +// + // // === SPI section // +bool flagSPI = false; // Some SPI implementations require unique initialisation + void hV_HAL_SPI_begin(uint32_t speed) { - _settingScreen = {speed, MSBFIRST, SPI_MODE0}; + if (flagSPI != true) + { + _settingScreen = {speed, MSBFIRST, SPI_MODE0}; #if defined(ENERGIA) - SPI.begin(); - SPI.setBitOrder(_settingScreen.bitOrder); - SPI.setDataMode(_settingScreen.dataMode); - SPI.setClockDivider(SPI_CLOCK_MAX / min(SPI_CLOCK_MAX, _settingScreen.clock)); + SPI.begin(); + SPI.setBitOrder(_settingScreen.bitOrder); + SPI.setDataMode(_settingScreen.dataMode); + SPI.setClockDivider(SPI_CLOCK_MAX / min(SPI_CLOCK_MAX, _settingScreen.clock)); #else #if defined(ARDUINO_XIAO_ESP32C3) - // Board Xiao ESP32-C3 crashes if pins are specified. - SPI.begin(8, 9, 10); // SCK MISO MOSI + // Board Xiao ESP32-C3 crashes if pins are specified. + SPI.begin(8, 9, 10); // SCK MISO MOSI #elif defined(ARDUINO_ESP32_PICO) - // Board ESP32-Pico-DevKitM-2 crashes if pins are not specified. - SPI.begin(14, 12, 13); // SCK MISO MOSI + // Board ESP32-Pico-DevKitM-2 crashes if pins are not specified. + SPI.begin(14, 12, 13); // SCK MISO MOSI #else // General case - SPI.begin(); + SPI.begin(); #endif // SPI specifics - SPI.beginTransaction(_settingScreen); + SPI.beginTransaction(_settingScreen); #endif // ENERGIA + + flagSPI = true; + } } void hV_HAL_SPI_end() { - SPI.end(); + if (flagSPI != false) + { + SPI.end(); + flagSPI = false; + } +} + +uint8_t hV_HAL_SPI_transfer(uint8_t data) +{ + return SPI.transfer(data); } + // // === End of SPI section // @@ -121,28 +155,38 @@ void hV_HAL_SPI_end() // // === Wire section // +bool flagWire = false; // Some Wire implementations require unique initialisation + void hV_HAL_Wire_begin() { - Wire.begin(); + if (flagWire == false) + { + Wire.begin(); #if defined(ENERGIA) #if defined(ENERGIA_ARCH_MSP430ELF) - Wire.setClock(100000UL); // 100 kHz for MSP430 + Wire.setClock(100000UL); // 100 kHz for MSP430 #endif // ENERGIA_ARCH_MSP430ELF #else // ARDUINO - Wire.setClock(400000L); // 400 kHz + Wire.setClock(400000L); // 400 kHz #endif // ENERGIA ARDUINO + flagWire = true; + } } void hV_HAL_Wire_end() { - Wire.end(); + if (flagWire == true) + { + Wire.end(); + flagWire = true; + } } void hV_HAL_Wire_transfer(uint8_t address, uint8_t * dataWrite, size_t sizeWrite, uint8_t * dataRead, size_t sizeRead) diff --git a/src/hV_HAL_Peripherals.h b/src/hV_HAL_Peripherals.h index e234ceb..05698fc 100755 --- a/src/hV_HAL_Peripherals.h +++ b/src/hV_HAL_Peripherals.h @@ -6,8 +6,8 @@ /// @n Based on highView technology /// /// @author Rei Vilo -/// @date 21 May 2024 -/// @version 803 +/// @date 21 Jul 2024 +/// @version 804 /// /// @copyright (c) Rei Vilo, 2010-2024 /// @copyright All rights reserved @@ -36,7 +36,7 @@ /// /// @brief Release /// -#define hV_HAL_PERIPHERALS_RELEASE 803 +#define hV_HAL_PERIPHERALS_RELEASE 804 /// /// @brief SDK library @@ -72,14 +72,24 @@ void hV_HAL_begin(); /// @note Other parameters are /// * Bit order: MSBFIRST /// * Data mode: SPI_MODE0 +/// @note With check for unique initialisation /// void hV_HAL_SPI_begin(uint32_t speed = 8000000); /// /// @brief End SPI +/// @note With check for unique deinitialisation /// void hV_HAL_SPI_end(); +/// +/// @brief Combined write and read of a single byte +/// @param data byte +/// @return read byte +/// @warning No check for previous initialisation +/// +uint8_t hV_HAL_SPI_transfer(uint8_t data); + /// /// @name 3-wire SPI bus /// @warning @@ -135,11 +145,13 @@ void hV_HAL_SPI3_write(uint8_t value); /// /// @brief Configure and start Wire bus /// @note Master mode only +/// @note With check for unique initialisation /// void hV_HAL_Wire_begin(); /// /// @brief End Wire bus +/// @note With check for unique deinitialisation /// void hV_HAL_Wire_end(); @@ -152,6 +164,7 @@ void hV_HAL_Wire_end(); /// @param[out] dataRead buffer to read /// @param[in] sizeRead number of bytes /// @note If sizeRead = 0, no read performed +/// @warning No check for previous initialisation /// void hV_HAL_Wire_transfer(uint8_t address, uint8_t * dataWrite, size_t sizeWrite, uint8_t * dataRead = 0, size_t sizeRead = 0); diff --git a/src/hV_List_Constants.h b/src/hV_List_Constants.h index de950c1..53299b9 100755 --- a/src/hV_List_Constants.h +++ b/src/hV_List_Constants.h @@ -6,8 +6,8 @@ /// @n Based on highView technology /// /// @author Rei Vilo -/// @date 21 Mar 2024 -/// @version 801 +/// @date 21 Jul 2024 +/// @version 804 /// /// @copyright (c) Rei Vilo, 2010-2024 /// @copyright All rights reserved @@ -89,12 +89,30 @@ /// @} /// -/// @brief Power state +/// @brief Scopes for power profile /// @note Numbers are sequential and exclusive /// @{ -#define FSM_POWER_UNKNOWN 0x00 ///< Unknown -#define FSM_POWER_ON 0x01 ///< On -#define FSM_POWER_SLEEP 0x02 ///< Off or sleep +#define SCOPE_NONE 0x00 ///< Nothing suspended +#define SCOPE_GPIO_ONLY 0x01 ///< GPIO only and if panelPower defined +/// @} + +/// +/// @brief Modes for power profile +/// @note Numbers are sequential and exclusive +/// @{ +#define MODE_AUTO 0x00 ///< Managed by the screen library +#define MODE_MANUAL 0x01 ///< Managed by the application code +/// @} + +/// +/// @brief Power and GPIO state +/// @note Numbers are sequential and exclusive, except MASK +/// @{ +#define FSM_OFF 0x00 ///< Bus off, GPIO off or undefined +#define FSM_ON 0x11 ///< Bus on, GPIO on or defined +#define FSM_SLEEP 0x10 ///< Bus on, GPIO and Power off or undefined +#define FSM_GPIO_MASK 0x01 ///< Mask for GPIO on or defined +#define FSM_BUS_MASK 0x10 ///< Mask for bus on /// @} /// diff --git a/src/hV_List_Options.h b/src/hV_List_Options.h index 2a7ad8f..cf91ed5 100755 --- a/src/hV_List_Options.h +++ b/src/hV_List_Options.h @@ -18,8 +18,8 @@ /// * 12. Set debug options /// /// @author Rei Vilo -/// @date 21 May 2024 -/// @version 803 +/// @date 21 Jul 2024 +/// @version 804 /// /// @copyright (c) Rei Vilo, 2010-2024 /// @copyright All rights reserved @@ -66,6 +66,8 @@ /// * Basic edition: Terminal font /// * Evaluation edition: DejaVu font as header /// * Commercial edition: DejaVu font as either header or external SPI Flash +/// * Viewer edition: DejaVu font as header +/// /// @note USE_FONT_HEADER requires addFont() /// @note Font Manager requires USE_FONT_HEADER /// @warning 8- and 16-bit MCUs may limit the size of the fonts. Use 32-bit MCUs for optimal performance. @@ -97,6 +99,7 @@ /// * Basic edition: MCU internal SRAM /// * Commercial edition: MCU internal SRAM /// * Evaluation edition: MCU internal or SPI external SRAM +/// * Viewer edition: MCU internal SRAM /// /// @{ #define USE_INTERNAL_MCU 1 ///< Use MCU internal @@ -112,6 +115,8 @@ /// * Basic edition: self option /// * Evaluation edition: virtual option /// * Commercial edition: self and virtual options +/// * Viewer edition: virtual option +/// /// @note Recommended: USE_hV_SCREEN_VIRTUAL /// @warning Issues with virtual function on arm-none-eabi-g++ 4.9.3: use USE_hV_SCREEN_SELF instead. /// @{ @@ -126,6 +131,8 @@ /// * Basic edition: iTC 2.71 BW and iTC 3.70 BW /// * Evaluation edition: iTC 2.71 BW and iTC 3.70 BW /// * Commercial edition: iTC 2.71 BW and iTC 3.70 BW +/// * Viewer edition: iTC 2.71 BW and iTC 3.70 BW +/// /// @note Touch uses I2C and polling over interrupt /// @{ #define USE_TOUCH_NONE 0 ///< Do not use touch @@ -139,6 +146,7 @@ /// * Basic edition: no haptic feedback /// * Evaluation edition: ERM or LRA /// * Commercial edition: ERM or LRA +/// * Viewer edition: no haptic feedback /// /// @{ #define USE_HAPTICS_NONE 0 ///< No motor @@ -151,6 +159,7 @@ /// * Basic edition: no expander /// * Evaluation edition: PCF8574 or PCA9536 /// * Commercial edition: PCF8574 or PCA9536 +/// * Viewer edition: no expander /// /// @{ #define USE_EXPANDER_NONE 0 ///< No I2C expander @@ -163,6 +172,7 @@ /// * Basic edition: String object /// * Evaluation edition: char array /// * Commercial edition: String object or char array +/// * Viewer edition: char array /// /// @{ #define USE_STRING_OBJECT 1 @@ -175,6 +185,7 @@ /// * Basic edition: none /// * Evaluation edition: none /// * Commercial edition: option +/// * Viewer edition: option /// /// @{ #define USE_NONE 0 ///< No storage @@ -189,5 +200,6 @@ /// * Basic edition: none /// * Evaluation edition: all /// * Commercial edition: option +/// * Viewer edition: option /// diff --git a/src/hV_Utilities_PDLS.cpp b/src/hV_Utilities_PDLS.cpp index 335e5ee..bf4513c 100755 --- a/src/hV_Utilities_PDLS.cpp +++ b/src/hV_Utilities_PDLS.cpp @@ -296,6 +296,18 @@ uint8_t hV_Utilities_PDLS::checkTemperatureMode(uint8_t updateMode) return updateMode; } +void hV_Utilities_PDLS::setPowerProfile(uint8_t mode, uint8_t scope) +{ + u_suspendMode = mode; + u_suspendScope = scope; + + if (b_pin.panelPower == NOT_CONNECTED) + { + u_suspendMode = MODE_MANUAL; + u_suspendScope = SCOPE_NONE; + } +} + void hV_Utilities_PDLS::debugVariant(uint8_t contextFilm) { mySerial.println(); diff --git a/src/hV_Utilities_PDLS.h b/src/hV_Utilities_PDLS.h index 2339878..40b7b4a 100755 --- a/src/hV_Utilities_PDLS.h +++ b/src/hV_Utilities_PDLS.h @@ -8,8 +8,8 @@ /// * Edition: Advanced /// /// @author Rei Vilo -/// @date 21 May 2024 -/// @version 803 +/// @date 21 Jul 2024 +/// @version 804 /// /// @copyright (c) Rei Vilo, 2010-2024 /// @copyright All rights reserved @@ -63,7 +63,7 @@ /// /// @brief Library release number /// -#define hV_UTILITIES_PDLS_RELEASE 803 +#define hV_UTILITIES_PDLS_RELEASE 804 // Objects // @@ -102,6 +102,13 @@ class hV_Utilities_PDLS : public hV_Board /// uint8_t checkTemperatureMode(uint8_t updateMode); + /// @brief Set the power profile + /// @param mode default = MODE_AUTO, otherwise MODE_MANUAL + /// @param scope default = SCOPE_GPIO_ONLY, otherwise SCOPE_NONE + /// @note If panelPower is NOT_CONNECTED, (MODE_AUTO, SCOPE_GPIO_ONLY) defaults to (MODE_MANUAL, SCOPE_NONE) + /// + void setPowerProfile(uint8_t mode = MODE_AUTO, uint8_t scope = SCOPE_GPIO_ONLY); + /// /// @brief Invert screen /// @details Invert black and white colours @@ -164,6 +171,8 @@ class hV_Utilities_PDLS : public hV_Board uint32_t u_pageColourSize; bool u_invert = false; bool u_flagOTP = false; + uint8_t u_suspendMode = MODE_AUTO; + uint8_t u_suspendScope = SCOPE_GPIO_ONLY; /// @endcond };