diff options
| author | Daniel Thompson <daniel@redfelineninja.org.uk> | 2020-06-10 07:52:46 (GMT) |
|---|---|---|
| committer | Daniel Thompson <daniel@redfelineninja.org.uk> | 2020-06-10 07:52:46 (GMT) |
| commit | 12e883e68b1445cc60c61535333d460cb551ac9a (patch) | |
| tree | c637459cb9fe516fb1c840a4e1fce1b6f62ecd32 | |
| parent | 50f30616c634b09f87bae424dcf7eed00ed384b3 (diff) | |
boards: pinetime: Improve safe mode implementation
| -rw-r--r-- | wasp/boards/pinetime/watch.py.in | 87 |
1 files changed, 55 insertions, 32 deletions
diff --git a/wasp/boards/pinetime/watch.py.in b/wasp/boards/pinetime/watch.py.in index d064d8f..ef7d0f4 100644 --- a/wasp/boards/pinetime/watch.py.in +++ b/wasp/boards/pinetime/watch.py.in @@ -59,41 +59,64 @@ display = ST7789_SPI(240, 240, spi, res=Pin("DISP_RST", Pin.OUT)) drawable = draw565.Draw565(display) -# 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)) +def boot_msg(s): + drawable.string(s, 0, 108, width=240) + if safe_mode: + time.sleep_ms(500) + +safe_mode = False +boot_msg("Init button") button = Pin('BUTTON', Pin.IN) -i2c = I2C(1, scl='I2C_SCL', sda='I2C_SDA') -accel = BMA421(i2c) -touch = CST816S(i2c) -vibrator = Vibrator(Pin('MOTOR', Pin.OUT, value=0), active_low=True) - -# Release flash from deep power-down -nor_cs = Pin('NOR_CS', Pin.OUT, value=1) -nor_cs(0) -spi.write('\xAB') -nor_cs(1) - -# Mount the filesystem -flash = FLASH(spi, (Pin('NOR_CS', Pin.OUT, value=1),)) +safe_mode = button.value() +if safe_mode: + backlight.set(1) + time.sleep(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('''\ + # Setup the last few bits and pieces + boot_msg("Init hardware") + battery = Battery( + Pin('BATTERY', Pin.IN), + Signal(Pin('CHARGING', Pin.IN), invert=True), + Signal(Pin('USB_PWR', Pin.IN), invert=True)) + i2c = I2C(1, scl='I2C_SCL', sda='I2C_SDA') + accel = BMA421(i2c) + touch = CST816S(i2c) + vibrator = Vibrator(Pin('MOTOR', Pin.OUT, value=0), active_low=True) + + # Release flash from deep power-down + boot_msg("Wake SPINOR") + nor_cs = Pin('NOR_CS', Pin.OUT, value=1) + nor_cs(0) + spi.write('\xAB') + nor_cs(1) + + # Mount the filesystem + boot_msg("Init SPINOR") + flash = FLASH(spi, (Pin('NOR_CS', Pin.OUT, value=1),)) + try: + boot_msg("Mount FS") + os.mount(flash, '/flash') + except AttributeError: + # Format the filesystem (and provide a default version of main.py) + boot_msg("Format FS") + os.VfsLfs2.mkfs(flash) + boot_msg("Retry mount FS") + os.mount(flash,'/flash') + boot_msg("Write main.py") + with open('/flash/main.py', 'w') as f: + f.write('''\ #include('main.py') ''') -# 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') + # Only change directory if the button is not pressed (this will + # allow us access to fix any problems with main.py)! + if not safe_mode: + boot_msg("Enter /flash") + os.chdir('/flash') + boot_msg("Run main.py") + else: + boot_msg("Safe mode") +except: + drawable.string("FAILED", 0, 136, width=240) backlight.set(1) -else: - display.poweroff() - |
