3030 sck = 7
3131)
3232
33+ # Would be better to do this only when the LoRa app starts:
3334try :
3435 lora_spi_device = SPI .Device (spi_bus = spi_bus , freq = 500000 , cs = - 1 , polarity = 0 , phase = 0 , firstbit = SPI .Device .MSB , bits = 8 )
3536except Exception as e :
@@ -95,6 +96,10 @@ def progress(msg, pct):
9596 expander_i2c = I2C (sda = Pin (39 ), scl = Pin (42 ), freq = 400000 )
9697 expander = Expander (i2c_bus = expander_i2c )
9798
99+ # quick and dirty way to make accessible later:
100+ import mpos
101+ mpos .io_expander = expander
102+
98103# Quick and dirty patch of BatteryManager to use the CH32 battery level:
99104def get_voltage (force_refresh = False , raw_adc_value = None ):
100105 # First workaround Fri3dCamp/badge_2026_fw/issues/2 by disabling input polling
@@ -106,27 +111,23 @@ def get_voltage(force_refresh=False, raw_adc_value=None):
106111 import time
107112 time .sleep_ms (10 )
108113 # Do the read:
109- returnval = (0.001857993861607339 * mpos .io_expander .analog [2 ] - 0.9965856090206169 )
114+ returnval = (0.001857993861607339 * mpos .io_expander .analog () [2 ] - 0.9965856090206169 )
110115 # Wait again to ensure more than 5ms between input polls
111116 time .sleep_ms (10 )
112117 # Enable input polling again:
113118 e .enable (True )
114119 return returnval
120+
115121from mpos import BatteryManager
116- BatteryManager .read_raw_adc = lambda * args : mpos .io_expander .analog [2 ]
122+ BatteryManager .read_raw_adc = lambda * args : mpos .io_expander .analog () [2 ]
117123BatteryManager .has_battery = lambda * args : True
118124BatteryManager .read_battery_voltage = get_voltage
119125
120-
121- # quick and dirty way to make accessible later:
122- mpos .io_expander = expander
123-
124126# LCD reset using the CH32 microcontroller
125127expander .config = 0x01 # 3v3 aux on + LCD off
126128import time
127129time .sleep_ms (100 )
128130expander .config = 0x03 # 3v3 aux + LCD on
129- import mpos
130131
131132# see ./lvgl_micropython/api_drivers/py_api_drivers/frozen/display/display_driver_framework.py
132133mpos .ui .main_display = st7789 .ST7789 (
0 commit comments