From cdd1c2c05f8787ce1b59b665c0f4fd6a71e12d6f Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=C3=98yvind=20Kol=C3=A5s?= <pippin@gimp.org>
Date: Fri, 15 Sep 2023 13:38:01 +0200
Subject: [PATCH] st3m_gfx,mpy,py: call option for apps not overriding mode
 "lock"

---
 .../micropython/usermodule/mp_sys_display.c      |  2 +-
 components/st3m/st3m_gfx.c                       | 16 ++++++++--------
 components/st3m/st3m_gfx.h                       |  2 +-
 python_payload/apps/graphics_mode/__init__.py    |  4 ++--
 4 files changed, 12 insertions(+), 12 deletions(-)

diff --git a/components/micropython/usermodule/mp_sys_display.c b/components/micropython/usermodule/mp_sys_display.c
index 5bd1206eb8..3da5cc5d4e 100644
--- a/components/micropython/usermodule/mp_sys_display.c
+++ b/components/micropython/usermodule/mp_sys_display.c
@@ -135,7 +135,7 @@ STATIC const mp_rom_map_elem_t mp_module_sys_display_globals_table[] = {
     { MP_ROM_QSTR(MP_QSTR_low_latency), MP_ROM_INT((int)st3m_gfx_low_latency) },
     { MP_ROM_QSTR(MP_QSTR_direct_ctx), MP_ROM_INT((int)st3m_gfx_direct_ctx) },
     { MP_ROM_QSTR(MP_QSTR_unset), MP_ROM_INT((int)st3m_gfx_unset) },
-    { MP_ROM_QSTR(MP_QSTR_force), MP_ROM_INT((int)st3m_gfx_force) },
+    { MP_ROM_QSTR(MP_QSTR_lock), MP_ROM_INT((int)st3m_gfx_lock) },
     { MP_ROM_QSTR(MP_QSTR_x2), MP_ROM_INT((int)st3m_gfx_2x) },
     { MP_ROM_QSTR(MP_QSTR_x3), MP_ROM_INT((int)st3m_gfx_3x) },
     { MP_ROM_QSTR(MP_QSTR_x4), MP_ROM_INT((int)st3m_gfx_4x) },
diff --git a/components/st3m/st3m_gfx.c b/components/st3m/st3m_gfx.c
index 687cbbf748..c31d2f6a3f 100644
--- a/components/st3m/st3m_gfx.c
+++ b/components/st3m/st3m_gfx.c
@@ -213,8 +213,8 @@ void st3m_gfx_set_palette(uint8_t *pal_in, int count) {
 
 void st3m_gfx_set_default_mode(st3m_gfx_mode mode) {
     if (mode & st3m_gfx_unset) {
-        if (mode & st3m_gfx_force)
-            default_mode &= ~st3m_gfx_force;
+        if (mode & st3m_gfx_lock)
+            default_mode &= ~st3m_gfx_lock;
         else if (mode & st3m_gfx_4x)
             default_mode &= ~st3m_gfx_4x;
         else if (mode & st3m_gfx_osd)
@@ -245,18 +245,18 @@ void st3m_gfx_set_default_mode(st3m_gfx_mode mode) {
         default_mode |= st3m_gfx_osd;
     } else if (mode == st3m_gfx_low_latency) {
         default_mode |= st3m_gfx_low_latency;
-    } else if (mode == st3m_gfx_force) {
-        default_mode |= st3m_gfx_force;
+    } else if (mode == st3m_gfx_lock) {
+        default_mode |= st3m_gfx_lock;
     } else if (mode == st3m_gfx_direct_ctx) {
         default_mode |= st3m_gfx_direct_ctx;
     } else
         default_mode = mode;
 
-    if (default_mode & st3m_gfx_force) {
-        default_mode &= ~st3m_gfx_force;
+    if (default_mode & st3m_gfx_lock) {
+        default_mode &= ~st3m_gfx_lock;
         _st3m_gfx_mode = default_mode + 1;
         st3m_gfx_set_mode(st3m_gfx_default);
-        default_mode |= st3m_gfx_force;
+        default_mode |= st3m_gfx_lock;
     } else {
         _st3m_gfx_mode = default_mode + 1;
         st3m_gfx_set_mode(st3m_gfx_default);
@@ -311,7 +311,7 @@ static void st3m_gfx_init_palette(st3m_gfx_mode mode) {
 }
 
 st3m_gfx_mode st3m_gfx_set_mode(st3m_gfx_mode mode) {
-    if ((mode == _st3m_gfx_mode) || (0 != (default_mode & st3m_gfx_force))) {
+    if ((mode == _st3m_gfx_mode) || (0 != (default_mode & st3m_gfx_lock))) {
         st3m_gfx_init_palette(
             mode);  // we say it is a no-op but reset the palette
         return (mode ? mode : default_mode);
diff --git a/components/st3m/st3m_gfx.h b/components/st3m/st3m_gfx.h
index d2a744b83c..05b137eb05 100644
--- a/components/st3m/st3m_gfx.h
+++ b/components/st3m/st3m_gfx.h
@@ -17,7 +17,7 @@ typedef enum {
     // shallower pipeline, in the future might mean immediate mode
     st3m_gfx_low_latency = 512,
     st3m_gfx_unset = 1024,
-    st3m_gfx_force = 8192,
+    st3m_gfx_lock = 8192,
     st3m_gfx_2x = 2048,
     st3m_gfx_3x = 4096,
     st3m_gfx_4x = 6144,
diff --git a/python_payload/apps/graphics_mode/__init__.py b/python_payload/apps/graphics_mode/__init__.py
index 3740da9a62..5a4bd83b20 100644
--- a/python_payload/apps/graphics_mode/__init__.py
+++ b/python_payload/apps/graphics_mode/__init__.py
@@ -126,7 +126,7 @@ class App(Application):
         curmode = sys_display.get_mode()
         low_latency = (curmode & sys_display.low_latency) != 0
         direct_ctx = (curmode & sys_display.direct_ctx) != 0
-        lock = (curmode & sys_display.force) != 0
+        lock = (curmode & sys_display.lock) != 0
         osd = (curmode & sys_display.osd) != 0
         scale = 0
         if (curmode & sys_display.x4) == sys_display.x2:
@@ -194,7 +194,7 @@ class App(Application):
         mode += osd * sys_display.osd
         mode += low_latency * sys_display.low_latency
         mode += direct_ctx * sys_display.direct_ctx
-        mode += lock * sys_display.force
+        mode += lock * sys_display.lock
 
         if scale == 1:
             mode += sys_display.x2
-- 
GitLab