From b7b9d61f71ce9c661b541d3617195f461efe1f2d Mon Sep 17 00:00:00 2001 From: Rei Vilo Date: Thu, 18 Jul 2024 15:34:32 +0200 Subject: [PATCH] Release 8.0.4 Added power management --- library.properties | 2 +- src/Screen_EPD_EXT3.cpp | 106 +++++++++++++++++++++---------- 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 ++++- 13 files changed, 302 insertions(+), 130 deletions(-) diff --git a/library.properties b/library.properties index 1986a07..e519884 100755 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=PDLS_EXT3_Basic_Global -version=8.0.3 +version=8.0.4 author=Rei Vilo for Pervasive Displays maintainer=Rei Vilo sentence=Library for Pervasive Displays iTC monochrome and colour screens and EXT3-1 board diff --git a/src/Screen_EPD_EXT3.cpp b/src/Screen_EPD_EXT3.cpp index 609ecd2..352be2f 100755 --- a/src/Screen_EPD_EXT3.cpp +++ b/src/Screen_EPD_EXT3.cpp @@ -31,6 +31,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 @@ -133,7 +134,7 @@ void Screen_EPD_EXT3::COG_LargeCJ_getDataOTP() mySerial.println(); mySerial.println(formatString("hV * OTP failed for screen %i-%cS-0%c", u_codeSize, u_codeFilm, u_codeDriver)); - while(0x01); + while (0x01); break; } @@ -164,7 +165,7 @@ void Screen_EPD_EXT3::COG_LargeCJ_getDataOTP() else { mySerial.println(formatString("hV * OTP check failed - First 0x%02x, expected 0x%02x", COG_data[0], 0xa5)); - while(0x01); + while (0x01); } } @@ -191,7 +192,7 @@ void Screen_EPD_EXT3::COG_LargeCJ_sendImageData() { // 9.69 and 11.98 combine two half-screens, hence two frames with adjusted (u_pageColourSize >> 1) size uint32_t u_subPageColourSize = (u_pageColourSize >> 1); - + FRAMEBUFFER_TYPE blackBuffer = s_newImage; FRAMEBUFFER_TYPE redBuffer = s_newImage + u_pageColourSize; @@ -637,7 +638,7 @@ void Screen_EPD_EXT3::COG_MediumCJ_getDataOTP() mySerial.println(); mySerial.println(formatString("hV * OTP failed for screen %i-%cS-0%c", u_codeSize, u_codeFilm, u_codeDriver)); - while(0x01); + while (0x01); break; } @@ -669,7 +670,7 @@ void Screen_EPD_EXT3::COG_MediumCJ_getDataOTP() { mySerial.println(); mySerial.println(formatString("hV * OTP check failed - First 0x%02x, expected 0x%02x", COG_data[0], 0xa5)); - while(0x01); + while (0x01); } } @@ -1023,7 +1024,7 @@ void Screen_EPD_EXT3::COG_SmallCJ_getDataOTP() COG_data[1] = 0x8d; break; } - + u_flagOTP = true; } @@ -1137,13 +1138,27 @@ void Screen_EPD_EXT3::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)) { mySerial.println(); - mySerial.println(formatString("hV * Required pin panelCSS is NOT_CONNECTED")); - while(0x01); + mySerial.println("hV * Required pin panelCSS is NOT_CONNECTED"); + while (0x01); } + // + // === End of Large screen section + // // Configure board switch (u_codeSize) @@ -1300,6 +1315,10 @@ void Screen_EPD_EXT3::begin() memset(s_newImage, 0x00, u_pageColourSize * u_bufferDepth); + setTemperatureC(25); // 25 Celsius = 77 Fahrenheit + b_fsmPowerScreen = FSM_OFF; + setPowerProfile(MODE_AUTO, SCOPE_GPIO_ONLY); + // Turn SPI on, initialise GPIOs and set GPIO levels // Reset panel and get tables resume(); @@ -1319,10 +1338,13 @@ void Screen_EPD_EXT3::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::WhoAmI() @@ -1333,32 +1355,44 @@ STRING_TYPE Screen_EPD_EXT3::WhoAmI() return formatString("iTC %i.%02i\"%s", v_screenDiagonal / 100, v_screenDiagonal % 100, work); } -void Screen_EPD_EXT3::suspend() +void Screen_EPD_EXT3::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::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 + + s_reset(); // Reset - // Reset - s_reset(); + b_fsmPowerScreen |= FSM_GPIO_MASK; + } - // Start SPI - hV_HAL_SPI_begin(); // Standard 8 MHz + // Check type and get tables + if (u_flagOTP == false) + { + s_getDataOTP(); // 3-wire SPI read OTP memory + + s_reset(); // Reset + } + + // Start SPI + hV_HAL_SPI_begin(16000000); // Fast 16 MHz, with unicity check + } } uint8_t Screen_EPD_EXT3::flushMode(uint8_t updateMode) @@ -1410,6 +1444,11 @@ void Screen_EPD_EXT3::s_reset() void Screen_EPD_EXT3::s_getDataOTP() { + hV_HAL_SPI_end(); // With unicity check + + hV_HAL_SPI3_begin(); // Define 3-wire SPI pins + + // Get data OTP uint16_t _readBytes = 0; switch (b_family) { @@ -1436,8 +1475,11 @@ void Screen_EPD_EXT3::s_getDataOTP() void Screen_EPD_EXT3::s_flush(uint8_t updateMode) { - // Turn SPI on, initialise GPIOs and set GPIO levels - resume(); + // Resume + if (b_fsmPowerScreen != FSM_ON) + { + resume(); + } // Three groups: // + small: up to 4.37 included @@ -1636,7 +1678,7 @@ void Screen_EPD_EXT3::s_setOrientation(uint8_t orientation) bool Screen_EPD_EXT3::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 diff --git a/src/Screen_EPD_EXT3.h b/src/Screen_EPD_EXT3.h index 5d9ac08..e6d82d8 100755 --- a/src/Screen_EPD_EXT3.h +++ b/src/Screen_EPD_EXT3.h @@ -12,8 +12,8 @@ /// * Feature: none /// /// @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 @@ -75,7 +75,7 @@ /// /// @brief Library release number /// -#define SCREEN_EPD_EXT3_RELEASE 803 +#define SCREEN_EPD_EXT3_RELEASE 804 /// /// @brief Library variant @@ -132,9 +132,11 @@ class Screen_EPD_EXT3 final : public hV_Screen_Buffer, public hV_Utilities_PDLS /// /// @brief Suspend - /// @details Turn SPI off and set all GPIOs low + /// @param bus include SPI bus, 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 };