Skip to content

Commit

Permalink
[EPD] POWER_OFF screen adjustment for 2:1 aspect ratio
Browse files Browse the repository at this point in the history
  • Loading branch information
lyusupov committed Jul 29, 2024
1 parent 3ace05d commit bac6de3
Show file tree
Hide file tree
Showing 16 changed files with 560 additions and 30 deletions.
48 changes: 38 additions & 10 deletions software/firmware/source/SoftRF/src/driver/EPD.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -546,19 +546,38 @@ void EPD_fini(int reason, bool screen_saver)
uint16_t tbw, tbh;
uint16_t x, y;

uint16_t display_width;
uint16_t display_height;
int16_t dy = 0;

SoC->ADB_ops && SoC->ADB_ops->fini();

const char *msg = (reason == SOFTRF_SHUTDOWN_LOWBAT ?
"LOW BATTERY" : "NORMAL OFF");

switch (hw_info.display)
{
#if defined(EPD_ASPECT_RATIO_1C1)
#if defined(EPD_ASPECT_RATIO_1C1) || defined(EPD_ASPECT_RATIO_2C1)
case DISPLAY_EPD_1_54:
case DISPLAY_EPD_2_13:
#if defined(USE_EPD_TASK)
while (EPD_update_in_progress != EPD_UPDATE_NONE) delay(100);
// while (!SoC->Display_lock()) { delay(10); }
#endif
display_width = display->width();
display_height = display->height();

#if defined(EPD_ASPECT_RATIO_2C1)

if (display->epd2.panel == GxEPD2::DEPG0213BN) {
if (display_width == 128) display_width = 122;
if (display_height == 128) {
display_height = 122;
if (display->getRotation() == ROTATE_90 ) { dy = 6; }
}
}
#endif /* EPD_ASPECT_RATIO_2C1 */

if (screen_saver) {
const char *msg_line;

Expand All @@ -568,16 +587,16 @@ void EPD_fini(int reason, bool screen_saver)
msg_line = "POWER OFF";

display->getTextBounds(msg_line, 0, 0, &tbx, &tby, &tbw, &tbh);
x = (display->width() - tbw) / 2;
y = display->height() / 3;
x = (display_width - tbw) / 2;
y = display_height / 3;
display->setCursor(x, y);
display->print(msg_line);

msg_line = "SCREEN SAVER";

display->getTextBounds(msg_line, 0, 0, &tbx, &tby, &tbw, &tbh);
x = (display->width() - tbw) / 2;
y = (2 * display->height()) / 3;
x = (display_width - tbw) / 2;
y = (2 * display_height) / 3;
display->setCursor(x, y);
display->print(msg_line);

Expand Down Expand Up @@ -608,19 +627,28 @@ void EPD_fini(int reason, bool screen_saver)

display->setFont(&FreeMonoBold12pt7b);
display->getTextBounds(msg, 0, 0, &tbx, &tby, &tbw, &tbh);
x = (display->width() - tbw) / 2;
x = (display_width - tbw) / 2;
y = tbh + tbh / 2;
display->setCursor(x, y);
display->print(msg);

x = (display->width() - 128) / 2;
y = (display->height() - 128) / 2 - tbh / 2;
#if defined(EPD_ASPECT_RATIO_1C1)
x = (display_width - 128) / 2;
y = (display_height - 128) / 2 - tbh / 2;
display->drawBitmap(x, y, sleep_icon_128x128, 128, 128, GxEPD_BLACK);
#endif /* EPD_ASPECT_RATIO_1C1 */

display->setFont(&Org_01);
display->getTextBounds(EPD_SoftRF_text4, 0, 0, &tbx, &tby, &tbw, &tbh);

#if defined(EPD_ASPECT_RATIO_1C1)
x = 5;
y += 128 + 17;
#endif /* EPD_ASPECT_RATIO_1C1 */
#if defined(EPD_ASPECT_RATIO_2C1)
x = 30;
y = (3 * display_height) / 4;
#endif /* EPD_ASPECT_RATIO_2C1 */
display->setCursor(x, y);
display->print(EPD_SoftRF_text4);

Expand All @@ -629,7 +657,7 @@ void EPD_fini(int reason, bool screen_saver)

display->setFont(&FreeSerif9pt7b);
display->getTextBounds(EPD_SoftRF_text6, 0, 0, &tbx, &tby, &tbw, &tbh);
x = (display->width() - tbw) / 2;
x = (display_width - tbw) / 2;
y += 21;
display->setCursor(x, y);
display->print(EPD_SoftRF_text6);
Expand All @@ -652,7 +680,7 @@ void EPD_fini(int reason, bool screen_saver)

// SoC->Display_unlock();
break;
#endif /* EPD_ASPECT_RATIO_1C1 */
#endif /* EPD_ASPECT_RATIO_1C1 || EPD_ASPECT_RATIO_2C1 */

case DISPLAY_NONE:
default:
Expand Down
7 changes: 7 additions & 0 deletions software/firmware/source/SoftRF/src/driver/EPD.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,13 @@
#if defined(USE_EPAPER)
#define ENABLE_GxEPD2_GFX 1
#include <GxEPD2_BW.h>

extern const GFXfont FreeMono9pt7b PROGMEM;
extern const GFXfont FreeMonoBold9pt7b PROGMEM;
extern const GFXfont FreeMonoBold12pt7b PROGMEM;
extern const GFXfont FreeMono18pt7b PROGMEM;
extern const GFXfont FreeMonoBold18pt7b PROGMEM;
extern const GFXfont FreeMonoBold24pt7b PROGMEM;
#endif /* USE_EPAPER */

#define EPD_EXPIRATION_TIME 5 /* seconds */
Expand Down
8 changes: 4 additions & 4 deletions software/firmware/source/SoftRF/src/platform/nRF52.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ GxEPD2_BW<GxEPD2_150_BN, GxEPD2_150_BN::HEIGHT> epd_bn (GxEPD2_150_BN(
SOC_GPIO_PIN_EPD_DC,
SOC_GPIO_PIN_EPD_RST,
SOC_GPIO_PIN_EPD_BUSY));
GxEPD2_BW<GxEPD2_371, GxEPD2_371::HEIGHT> epd_w7 (GxEPD2_371(
GxEPD2_BW<GxEPD2_371_T03, GxEPD2_371_T03::HEIGHT> epd_t3 (GxEPD2_371_T03(
SOC_GPIO_PIN_EPD_TULTIMA_SS,
SOC_GPIO_PIN_EPD_TULTIMA_DC,
SOC_GPIO_PIN_EPD_TULTIMA_RST,
Expand Down Expand Up @@ -2141,7 +2141,7 @@ static byte nRF52_Display_setup()
SPI1.setPins(SOC_GPIO_PIN_EPD_TULTIMA_MISO,
SOC_GPIO_PIN_EPD_TULTIMA_SCK,
SOC_GPIO_PIN_EPD_TULTIMA_MOSI);
nRF52_display = EP_GDEW0371W7;
nRF52_display = EP_GDEY037T03;
break;
case NRF52_LILYGO_TECHO_REV_0:
case NRF52_LILYGO_TECHO_REV_1:
Expand All @@ -2167,8 +2167,8 @@ static byte nRF52_Display_setup()
case EP_DEPG0150BN:
display = &epd_bn;
break;
case EP_GDEW0371W7:
display = &epd_w7;
case EP_GDEY037T03:
display = &epd_t3;
break;
case EP_GDEH0154D67:
default:
Expand Down
3 changes: 2 additions & 1 deletion software/firmware/source/SoftRF/src/platform/nRF52.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/

#if defined(ARDUINO_ARCH_NRF52) || defined(ARDUINO_ARCH_NRF52840)

#ifndef PLATFORM_NRF52_H
Expand Down Expand Up @@ -76,7 +77,7 @@ enum nRF52_display_id {
EP_GDEH0154D67,
EP_GDEP015OC1,
EP_DEPG0150BN,
EP_GDEW0371W7,
EP_GDEY037T03,
};

typedef struct {
Expand Down
2 changes: 0 additions & 2 deletions software/firmware/source/SoftRF/src/ui/Baro_EPD.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,7 @@
#include "../driver/EPD.h"
#include "../driver/Baro.h"

#include <Fonts/FreeMono9pt7b.h>
#include <Fonts/FreeMono12pt7b.h>
#include <Fonts/FreeMonoBold18pt7b.h>
#include <TinyGPS++.h>

const char Altitude_text[] = "ALTITUDE, ";
Expand Down
9 changes: 4 additions & 5 deletions software/firmware/source/SoftRF/src/ui/IMU_EPD.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,14 @@

#include "../system/SoC.h"

#if !defined(EXCLUDE_IMU)
float IMU_g = 0;
#endif /* EXCLUDE_IMU */

#if defined(USE_EPAPER)

#include "../driver/EPD.h"

#include <Fonts/FreeMonoBold24pt7b.h>
#include <Fonts/FreeMonoBold12pt7b.h>

float IMU_g = 0;

static const char G_load_text[] = "G-load";

void EPD_imu_setup()
Expand Down
2 changes: 0 additions & 2 deletions software/firmware/source/SoftRF/src/ui/Radar_EPD.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,7 @@
#include "../driver/LED.h"
#include "../driver/RF.h"

#include <Fonts/FreeMono9pt7b.h>
#include <Fonts/FreeMonoBold9pt7b.h>
#include <Fonts/FreeMonoBold12pt7b.h>
#include <Fonts/Picopixel.h>

static int EPD_zoom = ZOOM_MEDIUM;
Expand Down
1 change: 0 additions & 1 deletion software/firmware/source/SoftRF/src/ui/Status_EPD.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@

#include <Fonts/FreeMono9pt7b.h>
#include <Fonts/FreeSerifBold12pt7b.h>
#include <Fonts/FreeMonoBold18pt7b.h>

const char ID_text[] = "ID";
const char PROTOCOL_text[] = "PROTOCOL";
Expand Down
2 changes: 0 additions & 2 deletions software/firmware/source/SoftRF/src/ui/Text_EPD.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@
#include <protocol.h>
#include "../protocol/radio/Legacy.h"

#include <Fonts/FreeMonoBold12pt7b.h>

const char *EPD_Aircraft_Type[] = {
[AIRCRAFT_TYPE_UNKNOWN] = "Unknown",
[AIRCRAFT_TYPE_GLIDER] = "Glider",
Expand Down
3 changes: 0 additions & 3 deletions software/firmware/source/SoftRF/src/ui/Time_EPD.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,6 @@
extern RTC_Date fw_build_date_time;
#endif /* ARDUINO_ARCH_NRF52 */

#include <Fonts/FreeMonoBold24pt7b.h>
#include <Fonts/FreeMonoBold12pt7b.h>
#include <Fonts/FreeMono18pt7b.h>
#include "U8g2_for_Adafruit_GFX.h"

static const char TZ_text[] = "UTC";
Expand Down
1 change: 1 addition & 0 deletions software/firmware/source/libraries/GxEPD2/src/GxEPD2.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ class GxEPD2
GDEW027W3, Waveshare_2_7_bw = GDEW027W3,
GDEY027T91,
GDEW0371W7, Waveshare_3_7_bw = GDEW0371W7,
GDEY037T03,
GDEW042T2, Waveshare_4_2_bw = GDEW042T2,
GDEW0583T7, Waveshare_5_83_bw = GDEW0583T7,
GDEW075T8, Waveshare_7_5_bw = GDEW075T8,
Expand Down
1 change: 1 addition & 0 deletions software/firmware/source/libraries/GxEPD2/src/GxEPD2_BW.h
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#include "epd/GxEPD2_270.h"
#include "epd/GxEPD2_270_T91.h"
#include "epd/GxEPD2_371.h"
#include "epd/GxEPD2_371_T03.h"
#include "epd/GxEPD2_420.h"
#include "epd/GxEPD2_583.h"
#include "epd/GxEPD2_750.h"
Expand Down
19 changes: 19 additions & 0 deletions software/firmware/source/libraries/GxEPD2/src/GxEPD2_EPD.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ GxEPD2_EPD::GxEPD2_EPD(int8_t cs, int8_t dc, int8_t rst, int8_t busy, int8_t bus
_power_is_on = false;
_using_partial_mode = false;
_hibernating = false;
_init_display_done = false;
_timeout_expired = false;
_busy_callback = 0;
_busy_callback_parameter = 0;
Expand All @@ -51,6 +52,7 @@ void GxEPD2_EPD::init(uint32_t serial_diag_bitrate, bool initial, bool pulldown_
_power_is_on = false;
_using_partial_mode = false;
_hibernating = false;
_init_display_done = false;
_timeout_expired = false;
if (serial_diag_bitrate > 0)
{
Expand Down Expand Up @@ -269,3 +271,20 @@ void GxEPD2_EPD::_writeCommandDataPGM(const uint8_t* pCommandData, uint8_t datal
if (_cs >= 0) digitalWrite(_cs, HIGH);
_pSPIx->endTransaction();
}

void GxEPD2_EPD::_startTransfer()
{
_pSPIx->beginTransaction(_spi_settings);
if (_cs >= 0) digitalWrite(_cs, LOW);
}

void GxEPD2_EPD::_transfer(uint8_t value)
{
_pSPIx->transfer(value);
}

void GxEPD2_EPD::_endTransfer()
{
if (_cs >= 0) digitalWrite(_cs, HIGH);
_pSPIx->endTransaction();
}
4 changes: 4 additions & 0 deletions software/firmware/source/libraries/GxEPD2/src/GxEPD2_EPD.h
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,9 @@ class GxEPD2_EPD
void _writeDataPGM_sCS(const uint8_t* data, uint16_t n, int16_t fill_with_zeroes = 0);
void _writeCommandData(const uint8_t* pCommandData, uint8_t datalen);
void _writeCommandDataPGM(const uint8_t* pCommandData, uint8_t datalen);
void _startTransfer();
void _transfer(uint8_t value);
void _endTransfer();
protected:
int8_t _cs, _dc, _rst, _busy, _busy_level;
uint32_t _busy_timeout;
Expand All @@ -120,6 +123,7 @@ class GxEPD2_EPD
SPISettings _spi_settings;
bool _initial_write, _initial_refresh;
bool _power_is_on, _using_partial_mode, _hibernating;
bool _init_display_done;
bool _timeout_expired;
void (*_busy_callback)(const void*);
const void* _busy_callback_parameter;
Expand Down
Loading

0 comments on commit bac6de3

Please sign in to comment.