summaryrefslogtreecommitdiff
path: root/wasp
diff options
context:
space:
mode:
authorDaniel Thompson <daniel@redfelineninja.org.uk>2020-02-09 19:49:52 (GMT)
committerDaniel Thompson <daniel@redfelineninja.org.uk>2020-02-09 19:49:52 (GMT)
commitb2c5b482d5eaba86441c7c68fefc787cd8076821 (patch)
tree4c8695173ef261e015872a523370eb8f378d1432 /wasp
parent3bc59b1c71db1f73d16655c41a5ebc3340882f75 (diff)
wasp: pinetime: Enable filesystem support
Diffstat (limited to 'wasp')
-rw-r--r--wasp/boards/pinetime/manifest.py9
-rw-r--r--wasp/boards/pinetime/watch.py63
-rw-r--r--wasp/boot.py2
-rw-r--r--wasp/main.py2
4 files changed, 51 insertions, 25 deletions
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/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/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()