summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.gitmodules3
-rw-r--r--Makefile1
m---------micropython0
-rw-r--r--res/battery.pngbin0 -> 3471 bytes
-rw-r--r--wasp/boards/pinetime/manifest.py9
-rw-r--r--wasp/boards/pinetime/watch.py63
-rw-r--r--wasp/boards/simulator/micropython.py19
-rw-r--r--wasp/boot.py2
m---------wasp/drivers/flash0
-rw-r--r--wasp/drivers/st7789.py20
-rw-r--r--wasp/main.py2
11 files changed, 85 insertions, 34 deletions
diff --git a/.gitmodules b/.gitmodules
index 4471178..be828d9 100644
--- a/.gitmodules
+++ b/.gitmodules
@@ -10,3 +10,6 @@
[submodule "tools/nrfutil"]
path = tools/nrfutil
url = https://github.com/adafruit/Adafruit_nRF52_nrfutil.git
+[submodule "wasp/drivers/flash"]
+ path = wasp/drivers/flash
+ url = https://github.com/daniel-thompson/micropython-eeprom
diff --git a/Makefile b/Makefile
index ffed1fa..c2ff1b5 100644
--- a/Makefile
+++ b/Makefile
@@ -32,6 +32,7 @@ micropython:
$(RM) micropython/ports/nrf/build-$(BOARD)-s132/frozen_content.c
$(MAKE) -C micropython/ports/nrf \
BOARD=$(BOARD) SD=s132 \
+ MICROPY_VFS_LFS2=1 \
FROZEN_MANIFEST=$(PWD)/wasp/boards/$(BOARD)/manifest.py
python3 -m nordicsemi dfu genpkg \
--dev-type 0x0052 \
diff --git a/micropython b/micropython
-Subproject b2273b5d22bc4d948b5333b2b82a7be66f62cef
+Subproject a982035fdfd2dc12d375446472f0a2b1a99dd38
diff --git a/res/battery.png b/res/battery.png
new file mode 100644
index 0000000..d272dbf
--- /dev/null
+++ b/res/battery.png
Binary files differ
diff --git a/wasp/boards/pinetime/manifest.py b/wasp/boards/pinetime/manifest.py
index d292ba4..46016c8 100644
--- a/wasp/boards/pinetime/manifest.py
+++ b/wasp/boards/pinetime/manifest.py
@@ -1,3 +1,4 @@
+freeze('.', 'watch.py', opt=3)
freeze('../..',
(
'boot.py',
@@ -10,11 +11,15 @@ freeze('../..',
'drivers/vibrator.py',
'fonts.py',
'icons.py',
- 'main.py',
'manager.py',
'logo.py',
'widgets.py',
),
opt=3
)
-freeze('.', 'watch.py', opt=3)
+freeze('../../drivers/flash',
+ (
+ 'bdevice.py',
+ 'flash/flash_spi.py'
+ ), opt=3
+)
diff --git a/wasp/boards/pinetime/watch.py b/wasp/boards/pinetime/watch.py
index a8708c7..9415101 100644
--- a/wasp/boards/pinetime/watch.py
+++ b/wasp/boards/pinetime/watch.py
@@ -1,26 +1,21 @@
-from machine import Pin
+# Start measuring time (and feeding the watchdog) before *anything* else
from machine import RTCounter
+from drivers.nrf_rtc import RTC
+rtc = RTC(RTCounter(1, mode=RTCounter.PERIODIC))
+rtc.counter.start()
+
+import os
+import time
+
+from machine import Pin
#from machine import Signal
from machine import SPI
from drivers.battery import Battery
-from drivers.nrf_rtc import RTC
from drivers.signal import Signal
from drivers.st7789 import ST7789_SPI
from drivers.vibrator import Vibrator
-
-class Display(ST7789_SPI):
- def __init__(self):
- spi = SPI(0)
- # Mode 3, maximum clock speed!
- spi.init(polarity=1, phase=1, baudrate=8000000)
-
- # Configure the display
- cs = Pin("DISP_CS", Pin.OUT)
- dc = Pin("DISP_DC", Pin.OUT)
- rst = Pin("DISP_RST", Pin.OUT)
-
- super().__init__(240, 240, spi, cs=cs, dc=dc, res=rst)
+from flash.flash_spi import FLASH
class Backlight(object):
lo = Pin("BL_LO", Pin.OUT, value=0)
@@ -46,17 +41,43 @@ class Backlight(object):
self.mid(mid)
self.lo(lo)
+# Setup the display (and manage the backlight)
backlight = Backlight(0)
-display = Display()
-backlight.set(1)
-
-# Start measuring time (and feeding the watchdog)
-rtc = RTC(RTCounter(1, mode=RTCounter.PERIODIC))
-rtc.counter.start()
+spi = SPI(0)
+spi.init(polarity=1, phase=1, baudrate=8000000)
+display = ST7789_SPI(240, 240, spi,
+ cs=Pin("DISP_CS", Pin.OUT),
+ dc=Pin("DISP_DC", Pin.OUT),
+ res=Pin("DISP_RST", Pin.OUT))
+# Setup the last few bits and pieces
battery = Battery(
Pin('BATTERY', Pin.IN),
Signal(Pin('CHARGING', Pin.IN), invert=True),
Signal(Pin('USB_PWR', Pin.IN), invert=True))
vibrator = Vibrator(Pin('MOTOR', Pin.OUT, value=0), active_low=True)
button = Pin('BUTTON', Pin.IN)
+
+# Mount the filesystem
+flash = FLASH(spi, (Pin('NOR_CS', Pin.OUT, value=1),))
+try:
+ os.mount(flash, '/flash')
+except AttributeError:
+ # Format the filesystem (and provide a default version of main.py)
+ os.VfsLfs2.mkfs(flash)
+ os.mount(flash,'/flash')
+ with open('/flash/main.py', 'w') as f:
+ f.write('''\
+import manager
+wasp = manager.Manager(watch)
+wasp.run()
+''')
+
+# Only change directory if the button is not pressed (this will
+# allow us access to fix any problems with main.py)!
+if not button.value():
+ os.chdir('/flash')
+ backlight.set(1)
+else:
+ display.poweroff()
+
diff --git a/wasp/boards/simulator/micropython.py b/wasp/boards/simulator/micropython.py
index a5740f1..578a12d 100644
--- a/wasp/boards/simulator/micropython.py
+++ b/wasp/boards/simulator/micropython.py
@@ -1,5 +1,16 @@
-def const(x):
- return x
+def const(fn):
+ return fn
+
+def native(fn):
+ return fn
+
+def viper(fn):
+ def ptr8(buf):
+ return buf
+
+ # This is a bit of a hack since the scope for ptr8 won't be right
+ # but it does mean no changes to the client
+ fn.__globals__['ptr8'] = ptr8
+
+ return fn
-def native(x):
- return x
diff --git a/wasp/boot.py b/wasp/boot.py
index baed941..de05e13 100644
--- a/wasp/boot.py
+++ b/wasp/boot.py
@@ -1,3 +1 @@
-import manager
import watch
-wasp = manager.Manager(watch)
diff --git a/wasp/drivers/flash b/wasp/drivers/flash
new file mode 160000
+Subproject 8105da265b5c1779a1a4e93392c348f58c149ca
diff --git a/wasp/drivers/st7789.py b/wasp/drivers/st7789.py
index d96d417..1ec1ed4 100644
--- a/wasp/drivers/st7789.py
+++ b/wasp/drivers/st7789.py
@@ -19,6 +19,16 @@ _RAMWR = const(0x2c)
_COLMOD = const(0x3a)
_MADCTL = const(0x36)
+@micropython.viper
+def fastfill(mv, color: int, count: int, offset: int):
+ p = ptr8(mv)
+ colorhi = color >> 8
+ colorlo = color & 0xff
+
+ for x in range(count):
+ p[2*(x+offset) ] = colorhi
+ p[2*(x+offset) + 1] = colorlo
+
class ST7789(object):
def __init__(self, width, height):
self.width = width
@@ -111,12 +121,12 @@ class ST7789(object):
for rl in rle:
while rl:
- buf[bp] = color >> 8
- buf[bp+1] = color & 0xff
- bp += 2
- rl -= 1
+ count = min(sx - bp, rl)
+ fastfill(buf, color, count, bp)
+ bp += count
+ rl -= count
- if bp >= (2*sx):
+ if bp >= sx:
self.write_data(buf)
bp = 0
diff --git a/wasp/main.py b/wasp/main.py
index 6b41efa..cc4c8b6 100644
--- a/wasp/main.py
+++ b/wasp/main.py
@@ -1 +1,3 @@
+import manager, watch
+wasp = manager.Manager(watch)
wasp.run()