Skip to content

Instantly share code, notes, and snippets.

@d3nd3
Last active January 25, 2023 10:57
Show Gist options
  • Save d3nd3/c803643cfb6d57263c07384a5766c81f to your computer and use it in GitHub Desktop.
Save d3nd3/c803643cfb6d57263c07384a5766c81f to your computer and use it in GitHub Desktop.
Bangle.js

Drawing Images on Espruino Bangle.js Info

Brief Intro

Bangle.js has 64kb RAM, about 40k of this is usable by user JS code.

Strings in Espruino

There are 3 main strings that should interest us.

NativeString

Dees not use JSVars to store the data, its pointed to directly. This behaves like a pointer, a function that generates one is eg. E.memoryArea(addr,len). So it points to RAM on bangle.js because the SPI flash is not memory mapped.

FlashString

Thats where flash strings come in, these are the same as NativeStrings except they reference SPI Flash and are read-only.

FlatString

Uses contiguous blocks of JSVars to store the string in RAM. These are what ArrayBuffers.

Bypassing RAM limitation using SPI Flash

You can use the upload function of the web ide to put an image that is larger than Bangle.js RAM onto the flash. Its possible to render this image, thanks to FlashStrings.

When espruino is loading and parsing a javascript file, it uses "Storage".read() which returns a FlashString. Thus the Lexer, when parsing the code and getting next character jslGetNextCh and jsvStringIteratorNew call the function jsvStringIteratorLoadFlashString. The JsvStringIterator struct has a flashStringBuffer[16] member, this is where flash data is read and copied into, in chunks, when needed. Thus only ever using 16 bytes overhead of RAM at any given moment during parsing.

There is a technique to save on memory but consume more cpu. That is to store a function callback that returns data instead of store the data directly into a variable. Because the function pointer is stored as a pointer to Flash.

Info related to the Bangle.js watches

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment