Commit Graph

410 Commits

Author SHA1 Message Date
Jeff Epler 40ab5c6b21 compression: Implement ciscorn's dictionary approach
Massive savings.  Thanks so much @ciscorn for providing the initial
code for choosing the dictionary.

This adds a bit of time to the build, both to find the dictionary
but also because (for reasons I don't fully understand), the binary
search in the compress() function no longer worked and had to be
replaced with a linear search.

I think this is because the intended invariant is that for codebook
entries that encode to the same number of bits, the entries are ordered
in ascending value.  However, I mis-placed the transition from "words"
to "byte/char values" so the codebook entries for words are in word-order
rather than their code order.

Because this price is only paid at build time, I didn't care to determine
exactly where the correct fix was.

I also commented out a line to produce the "estimated total memory size"
-- at least on the unix build with TRANSLATION=ja, this led to a build
time KeyError trying to compute the codebook size for all the strings.
I think this occurs because some single unicode code point ('ァ') is
no longer present as itself in the compressed strings, due to always
being replaced by a word.

As promised, this seems to save hundreds of bytes in the German translation
on the trinket m0.

Testing performed:
 - built trinket_m0 in several languages
 - built and ran unix port in several languages (en, de_DE, ja) and ran
   simple error-producing codes like ./micropython -c '1/0'
2020-09-12 10:10:45 -05:00
microDev 4da478382d Fix serial console output & add more boards 2020-09-12 17:46:52 +05:30
microDev 305bed6d9e Added esp32s2 safe_mode & fixed user_safe_mode 2020-09-11 21:06:54 +05:30
Scott Shawcroft 1ba28b3edc
Merge pull request #3370 from jepler/compression-bigrams
add bigram compression to makeqstrdata (save ~100 bytes on trinket m0 de_DE)
2020-09-10 11:44:56 -07:00
Jeff Epler 0eee93729a Fix decompression of unicode values above 2047
Two problems: The lead byte for 3-byte sequences was wrong, and one
mid-byte was not even filled in due to a missing "++"!

Apparently this was broken ever since the first "Compress as unicode,
not bytes" commit, but I believed I'd "tested" it by running on the
Pinyin translation.

This rendered at least the Korean and Japanese translations completely
illegible, affecting 5.0 and all later releases.
2020-09-08 20:54:47 -05:00
Jeff Epler bdb07adfcc translations: Make decompression clearer
Now this gets filled in with values e.g., 128 (0x80) and 159 (0x9f).
2020-09-08 19:07:53 -05:00
Scott Shawcroft 99f5011d74
Fix heap without PSRAM. Never set heap_size. 2020-09-08 17:06:09 -07:00
Scott Shawcroft 96cf60fbbd
Merge remote-tracking branch 'adafruit/main' into native_wifi 2020-09-03 16:34:56 -07:00
Scott Shawcroft 786f4ed114
Merge pull request #3344 from jepler/issue-3184
Fix RGBMatrix, FrameBufferDisplay bugs
2020-09-02 15:32:30 -07:00
Jeff Epler 07740d19f3 add bigram compression to makeqstrdata
Compress common unicode bigrams by making code points in the range
0x80 - 0xbf (inclusive) represent them.  Then, they can be greedily
encoded and the substituted code points handled by the existing Huffman
compression.  Normally code points in the range 0x80-0xbf are not used
in Unicode, so we stake our own claim.  Using the more arguably correct
"Private Use Area" (PUA) would mean that for scripts that only use
code points under 256 we would use more memory for the "values" table.

bigram means "two letters", and is also sometimes called a "digram".
It's nothing to do with "big RAM".  For our purposes, a bigram represents
two successive unicode code points, so for instance in our build on
trinket m0 for english the most frequent are:
['t ', 'e ', 'in', 'd ', ...].

The bigrams are selected based on frequency in the corpus, but the
selection is not necessarily optimal, for these reasons I can think of:
 * Suppose the corpus was just "tea" repeated 100 times.  The
   top bigrams would be "te", and "ea".  However,
   overlap, "te" could never be used.  Thus, some bigrams might actually
   waste space
    * I _assume_ this has to be why e.g., bigram 0x86 "s " is more
      frequent than bigram 0x85 " a" in English for Trinket M0, because
      sequences like "can't add" would get the "t " digram and then
      be unable to use the " a" digram.

 * And generally, if a bigram is frequent then so are its constituents.
   Say that "i" and "n" both encode to just 5 or 6 bits, then the huffman
   code for "in" had better compress to 10 or fewer bits or it's a net
   loss!
    * I checked though!  "i" is 5 bits, "n" is 6 bits (lucky guess)
      but the bigram 0x83 also just 6 bits, so this one is a win of
      5 bits for every "it" minus overhead.  Yay, this round goes to team
      compression.
    * On the other hand, the least frequent bigram 0x9d " n" is 10 bits
      long and its constituent code points are 4+6 bits so there's no
      savings, but there is the cost of the table entry.
    * and somehow 0x9f 'an' is never used at all!

With or without accounting for overlaps, there is some optimum number
of bigrams.  Adding one more bigram uses at least 2 bytes (for the
entry in the bigram table; 4 bytes if code points >255 are in the
source text) and also needs a slot in the Huffman dictionary, so
adding bigrams beyond the optimim number makes compression worse again.

If it's an improvement, the fact that it's not guaranteed optimal
doesn't seem to matter too much.  It just leaves a little more fruit
for the next sweep to pick up.  Perhaps try adding the most frequent
bigram not yet present, until it doesn't improve compression overall.

Right now, de_DE is again the "fullest" build on trinket_m0.  (It's
reclaimed that spot from the ja translation somehow)  This change saves
104 bytes there, increasing free space about 6.8%.  In the larger
(but not critically full) pyportal build it saves 324 bytes.

The specific number of bigrams used (32) was chosen as it is the max
number that fit within the 0x80..0xbf range.  Larger tables would
require the use of 16 bit code points in the de_DE build, losing savings
overall.

(Side note: The most frequent letters in English have been said
to be: ETA OIN SHRDLU; but we have UAC EIL MOPRST in our corpus)
2020-09-01 17:12:22 -05:00
Jeff Epler 9bd2a61d8b supervisor: Always allocate at least a 1x1 terminal
Otherwise, out of range writes would occur in tilegrid_set_tile, causing a safe mode reset.
```
Hardware watchpoint 6: -location *stack_alloc->ptr

Old value = 24652061
New value = 24641565
0x000444f2 in common_hal_displayio_tilegrid_set_tile (self=0x200002c8 <supervisor_terminal_text_grid>, x=1, y=1, tile_index=0 '\000')
    at ../../shared-module/displayio/TileGrid.c:236
236	    if (!self->partial_change) {
(gdb)
```
2020-09-01 10:55:45 -05:00
Dan Halbert 6dbd369272 merge from upstream 2020-08-30 14:39:03 -04:00
Scott Shawcroft 767ca5c3dc
Merge remote-tracking branch 'adafruit/main' into native_wifi 2020-08-27 11:42:31 -07:00
Jeff Epler 2e0a109331
Merge pull request #3318 from jepler/interrupt-serial-rx
supervisor: check for interrupt during rx_chr
2020-08-25 21:01:33 -05:00
Scott Shawcroft 8b71e26abd
Merge remote-tracking branch 'adafruit/main' into native_wifi 2020-08-25 16:39:23 -07:00
Scott Shawcroft 2b470b1486
Fix RGB LED use 2020-08-24 18:29:50 -07:00
Jeff Epler 1033e89561 supervisor: use mp_handle_pending to check for exceptions 2020-08-23 09:12:01 -05:00
Jeff Epler f8a9e11ff4 WIP supervisor: check for interrupt during rx_chr 2020-08-23 08:47:18 -05:00
Dan Halbert f714f53552 Merge remote-tracking branch 'adafruit/main' into ble_hci 2020-08-21 10:45:05 -04:00
Dan Halbert 0e30dd8bcc merge from upstream; working; includes debug_out code for debugging via Saleae for posterity 2020-08-20 20:29:57 -04:00
Jeff Epler 23aefe9509 Add usb-endpoint-count checking
.. however, the number of endpoints is only set for SAMD (8).
Other ports need to set the value.  Otherwise, the build will show
the message
```
Unable to check whether maximum number of endpoints is respected
```
2020-08-19 16:47:40 -05:00
Scott Shawcroft 9602ee6265
Disable wifi debug logging and memory log 2020-08-19 14:23:28 -07:00
Scott Shawcroft ddcff85fa2
Add debugging. Scanning doesn't crash but returns no results. Need to config station. 2020-08-19 14:22:12 -07:00
Scott Shawcroft 1a6f4e0fe0
Scanning WIP. Need to sort out supervisor memory 2020-08-19 14:22:12 -07:00
Scott Shawcroft d01f5dc0bd
Turn off terminalio for ja and ko
The font is missing many characters and the build needs the space.
We can optimize font storage when we get a good font.

The serial output will work as usual.
2020-08-17 17:17:59 -07:00
Jeff Epler 759ded9c38 Fix build errors when SHARPDISPLAY && !RGBMATRIX 2020-08-12 07:39:12 -05:00
Jeff Epler c1400bae9b sharpmemory: Implement support for Sharp Memory Displays in framebufferio 2020-08-12 07:32:18 -05:00
Scott Shawcroft bbac68e77c
Merge pull request #3232 from hierophect/esp32-neopixel
ESP32-S2: Add Neopixel support
2020-08-11 11:04:39 -07:00
Lucian Copeland 4613b58a31 Add skip for rgb matrix exception handling 2020-08-10 18:00:50 -04:00
Lucian Copeland d47bd5529c Fix neopixel macro issue, set default neopixel color 2020-08-10 13:16:20 -04:00
Lucian Copeland 78d049d0f1 Fix pwm reset spew, protect against null reference in led status 2020-08-05 14:05:53 -04:00
Lucian Copeland 14b3b51c58 Rework build flags, prevent idf errors 2020-08-04 18:40:24 -04:00
Jeff Epler 710c2dc54b safe_mode: Exclude NORDIC_SOFT_DEVICE_ASSERT str if possible 2020-08-04 14:45:45 -05:00
Dan Halbert 0a60aee3e4 wip: compiles 2020-08-02 11:36:38 -04:00
Jeff Epler d4801b8c54
Merge pull request #3225 from hathach/improve-highspeed-usb
Improve highspeed usb
2020-07-30 07:15:20 -05:00
Scott Shawcroft b76d37f24a
Merge pull request #3223 from dhalbert/unmount-before-reset
storage.erase_filesystem(): disconnect from USB and wait 1 second before resetting
2020-07-29 10:47:24 -07:00
hathach 1f4fcb399b
move CFG_TUSB_RHPORT0_MODE into generated header 2020-07-29 16:05:31 +07:00
hathach d8fef207d2 remove obsolete CFG in tusb_config.h 2020-07-29 15:45:01 +07:00
hathach 6063828279 replace USB_MSC_MAX_PACKET_SIZE with USB_HIGHSPEED in descriptor gen tool 2020-07-29 15:38:55 +07:00
Dan Halbert 65c22aa434 storage.erase_filesystem(): unmount and wait 1 second before resetting 2020-07-28 17:52:56 -04:00
Scott Shawcroft 2bd6d05663
Add externs. GCC10 complains about duplicate defines 2020-07-22 16:26:46 -07:00
Jeff Epler 9fd10322fe supervisor: rename some locals for clarity
It's perfectly OK for these variables with static linkage to have the
same name, but it's inconvenient for humans like me.
2020-07-20 08:45:31 -05:00
Jeff Epler db43c56f79 background callbacks: Clear any callbacks that were queued
Before this, a background callback that was on the list when
background_callback_reset was called could have ended up in a state
that made it "un-queueable": its "prev" pointer could have been non-NULL.
2020-07-20 08:44:39 -05:00
Jeff Epler 98eef79faa background_callback_gc_collect: We must traverse the whole list 2020-07-17 14:55:46 -05:00
Jeff Epler a18a392109 background_callback: Add gc collect callback
A background callback must never outlive its related object.  By
collecting the head of the linked list of background tasks, this will
not happen.

One hypothetical case where this could happen is if an MP3Decoder is
deleted while its callback to fill its buffer is scheduled.
2020-07-17 08:36:26 -05:00
Jeff Epler 81105cb9ef supervisor: usb: note that it's unusual to need to call usb_background 2020-07-15 11:49:44 -05:00
Jeff Epler 1df48176ce supervisor: factor supervisor_background_tasks from sundry ports 2020-07-15 11:49:44 -05:00
Jeff Epler 6160d11c5a supervisor: factor out, Handle USB via background callback 2020-07-15 11:49:44 -05:00
Jeff Epler 36b4646516 background_callback: Avoid CALLBACK_CRITICAL_BEGIN with nothing to do
CALLBACK_CRITICAL_BEGIN is heavyweight, but we can be confident we do
not have work to do as long as callback_head is NULL.

This gives back performance on nRF.
2020-07-15 09:26:47 -05:00
Jeff Epler 8c4a9f6444 supervisor: tick: only run background tasks once per tick 2020-07-15 09:26:47 -05:00
Jeff Epler 1474fccd2f supervisor: Add a linked list of background callbacks
In time, we should transition interrupt driven background tasks out of the
overall run_background_tasks into distinct background callbacks,
so that the number of checks that occur with each tick is reduced.
2020-07-15 09:26:47 -05:00
Jeff Epler 51b9a1aeca tick.c: adjust whitespace 2020-07-15 09:26:47 -05:00
Dan Halbert f6869c69c5 wip: advertising; not tested 2020-07-12 19:45:23 -04:00
Diego Elio Pettenò 34b4993d63 Add license to some obvious files. 2020-07-06 19:16:25 +01:00
Jeff Epler fcddfd0f39
Merge pull request #3083 from tannewt/esp32s2_busio
Add busio support for the ESP32-S2
2020-07-01 21:02:08 -05:00
Scott Shawcroft 1a0c10c328
Fix debug UART call 2020-06-29 17:15:01 -07:00
Dan Halbert 759929c24a hci early wip; refactor supervisor bluetooth.c for nrf: tested 2020-06-25 20:57:17 -04:00
Jeff Epler 076a96ccc6
Merge pull request #3046 from jepler/same51
Add basic SAM E54  support and SAM E54 Xplained board
2020-06-25 06:55:27 -05:00
Jeff Epler 87835c77e8
Merge pull request #3038 from jepler/compute-usb-devices
Compute USB_DEVICES instead of requiring it to be specified
2020-06-24 13:31:56 -05:00
Jeff Epler bf460ddf25
supervisor.mk: Conditionally assign USB_DEVICES
This restores the ability to remove CDC and/or MSC, at the price of
giving up the new automatic check that USB_DEVICES is correct.
Since devices have to have CDC and MSC to be "CircuitPython",
this is not a facility that is going to be used by any in-tree drivers.
2020-06-24 09:44:45 -05:00
Jeff Epler f232aef786 supervisor.mk: Compute USB_DEVICES; remove from boards and ports
Since Actions passed on the previous commit, where this computed value
was checked against the specified value (if any), this is no net change,
except that we no longer need to specify it for particular boards or
ports.
2020-06-23 12:59:01 -05:00
Scott Shawcroft 741e1d9828
Merge pull request #3043 from DavePutz/Issue-2865
Issue #2865 -Clean up after ctrl-c interrupt in sleep
2020-06-23 10:58:45 -07:00
DavePutz b80abf1a90
Update handing of a CTRL-C exception 2020-06-23 12:15:01 -05:00
Jeff Epler d5074220a8 atmel-samd: Add SAM E54 Xplained board
Few peripherals are actually tested.  However, USB, I2C and GPIO seem to work.

Most pins are silkscreened with the "PX00" style, so the board module
only includes the small number that are screened differently.

The default SPI, I2C, and UART are the ones on the EXT2 header.  This is
arbitrary, but the I2C on this connector is shared with the on-board I2C
devices and the PCC header, making it the most versatile.
2020-06-23 10:41:48 -05:00
DavePutz 65512cef1c
Update tick.c 2020-06-22 15:59:15 -05:00
Jeff Epler de14b5b02f flash: Correctly signal error on invalid flash read
This logic was intended to mirror what is done for "write", but
the wrong variable name was repeated twice.
2020-06-22 10:24:21 -05:00
DavePutz 182a8733a4
Rework handling of ctrl-c interrupt 2020-06-21 13:28:26 -05:00
DavePutz 0b52359190
Generate stacktrace and reset exception for ctrl-c interrupt
Added code in mp_hal_delay_ms() to generate stacktrace and reset exception for ctrl-c interrupt
2020-06-19 19:02:43 -05:00
Jeff Epler 8bbd539031 supervisor.mk: Compute what USB_DEVICES should be, and check it against what it is 2020-06-15 19:14:57 -05:00
Diego Elio Pettenò dd5d7c86d2 Fix up end of file and trailing whitespace.
This can be enforced by pre-commit, but correct it separately to make it easier to review.
2020-06-03 10:56:35 +01:00
Scott Shawcroft 323cca8910
Merge remote-tracking branch 'adafruit/master' into wdt-nrf 2020-06-01 15:18:12 -07:00
Brian Dean cf888dc02b .../devices.h: Add GigaDevices GD25S512MD 64 MiB flash chip support. 2020-05-29 15:40:56 -04:00
Scott Shawcroft 2fd7a43f2f
Merge remote-tracking branch 'adafruit/master' into wdt-nrf 2020-05-29 10:16:24 -07:00
Jeff Epler d0f9b5901e translations: document the compressed format 2020-05-28 11:30:46 -05:00
Jeff Epler fe3e8d1589 string compression: save a few bits per string
Length was stored as a 16-bit number always.  Most translations have
a max length far less.  For example, US English translation lengths
always fit in just 8 bits.  probably all languages fit in 9 bits.

This also has the side effect of reducing the alignment of
compressed_string_t from 2 bytes to 1.

testing performed: ran in german and english on pyruler, printed messages
looked right.

Firmware size, en_US
Before: 3044 bytes free in flash
After: 3408 bytes free in flash

Firmware size, de_DE (with #2967 merged to restore translations)
Before: 1236 bytes free in flash
After: 1600 bytes free in flash
2020-05-28 08:36:08 -05:00
Sean Cross c7efc94a33 watchdog: move timeout exception to shared-bindings
Make this exception globally available to all platforms that have
enabled the watchdog timer.

Signed-off-by: Sean Cross <sean@xobs.io>
2020-05-27 11:28:49 +08:00
Sean Cross 15530a69c7 supervisor: tick: check for watchdog exception if enabled
Check to see if the current exception is a Watchdog exception, if it's
enabled. This ensures we break out of the current sleep() if a watchdog
timeout hits.

Signed-off-by: Sean Cross <sean@xobs.io>
2020-05-27 11:28:49 +08:00
Sean Cross 8c5df5f732 supervisor: add a new WATCHDOG_RESET safe mode reason
This mode will be used if the board is reset due to the watchdog
expiring.

Signed-off-by: Sean Cross <sean@xobs.io>
2020-05-27 11:28:49 +08:00
Sean Cross ec99dae953 tick: break on watchdog timeout exception
Signed-off-by: Sean Cross <sean@xobs.io>
2020-05-27 11:28:49 +08:00
Sean Cross d1a7fdd9d4 supervisor: support debugging tinyusb
Allow for passing `-DCFG_TUSB_DEBUG=1` or `-DCFG_TUSB_DEBUG=2` on the
command line to enable debugging tinyusb within circuitpython.

Signed-off-by: Sean Cross <sean@xobs.io>
2020-05-21 21:35:30 +08:00
Scott Shawcroft 916ca9f8a6
Merge pull request #2910 from tannewt/esp32s2
Add initial ESP32S2 support
2020-05-19 12:53:23 -07:00
Sean Cross 34f91f01c6 bleio: adapter: add advertising timeout and status
Add a field to allow specifying a timeout when initiating advertising.
As part of this, add a new property to determine if the device is still
advertising.

Additionally, have the `anonymous` property require a timeout, and set
the timeout to the maximum possible value if no timeout is specified.

Signed-off-by: Sean Cross <sean@xobs.io>
2020-05-19 15:01:19 +08:00
Sean Cross cfe65742a3 _bleio: support anonymous advertising
Add a new parameter to the `start_advertising()` function to enable
anonymous advertising.  This forces a call to `sd_ble_gap_privacy_set()`
with `privacy_mode` set to `BLE_GAP_PRIVACY_MODE_DEVICE_PRIVACY` and
`private_addr_type` set to
`BLE_GAP_ADDR_TYPE_RANDOM_PRIVATE_RESOLVABLE`.

With this, addresses will cycle at a predefined rate (currently once
every 15 minutes).

Signed-off-by: Sean Cross <sean@xobs.io>
2020-05-19 15:01:18 +08:00
Scott Shawcroft 2c2b53303d
Merge pull request #2837 from k0d/serial-debug
Add support for a debug console, such as ST-Link VCP.
2020-05-18 18:13:31 -07:00
Mark Olsson 007c92ee6a Enable showing the console on a debug uart 2020-05-19 02:02:52 +02:00
Scott Shawcroft 6aaab005c5
Initial ESP32S2 port.
Basic blinky works but doesn't check pins.
2020-05-15 15:36:16 -07:00
Max Holliday 964040b770 More erroneous else statements 2020-05-09 12:16:04 -07:00
Max Holliday 8b6587a0c6 Unified single_status_byte & no_reset_cmd behavior 2020-05-09 12:09:01 -07:00
Max Holliday 9e01bb2136 Removing erroneous else statements 2020-05-09 12:03:26 -07:00
Max Holliday 9ef28d8536 Replacing device that was accidentally deleted 2020-05-09 12:00:59 -07:00
Dan Halbert c377d4bea7
Merge branch 'master' into non-standard-nvm 2020-05-04 16:08:45 -04:00
Brian Dean 28179a3aaf .../external_flash.c: Don't attempt to issue CMD_READ_STATUS2 for
devices with only a single_status_byte.
2020-05-03 18:33:01 -04:00
Max Holliday cc290c50c6 fixing diff error 2020-04-28 18:15:38 -07:00
Max Holliday 6c4decd4e2 decoupling chip specific functions from EXTERNAL_FLASH_QSPI_SINGLE 2020-04-28 11:51:07 -07:00
Scott Shawcroft 755d404edf
Merge remote-tracking branch 'adafruit/master' into lower_power 2020-04-27 16:45:10 -07:00
Max Holliday 86943ca8a1 Merge remote-tracking branch 'adafruit/master' 2020-04-27 13:51:51 -07:00
Scott Shawcroft 9e4b94f466
Merge pull request #2805 from tannewt/update_tinyusb
Update tinyusb
2020-04-26 20:55:36 -07:00
Scott Shawcroft dcb0e50f04
Fix USB midi and hid disable. 2020-04-21 14:15:44 -07:00
Sean Cross 05b5356acc external_flash: add support for mx25r1635f
This flash chip is used in Simmel.

Signed-off-by: Sean Cross <sean@xobs.io>
2020-04-21 09:56:05 +08:00
Scott Shawcroft bebf27e733
Merge remote-tracking branch 'adafruit/master' into lower_power
This isn't perfect and needs a bit more testing.
2020-04-20 18:25:13 -07:00