Commit Graph

357 Commits

Author SHA1 Message Date
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