Commit Graph

1433 Commits

Author SHA1 Message Date
Jeff Epler
2b0231e9d3
synthio: re-striking a note should re-enter attack
.. without changing the current note amplitude
2023-05-04 07:23:50 -05:00
Jeff Epler
021aaa4599
synthio: remove unused 'phase' from Note objects 2023-05-04 07:23:50 -05:00
Jeff Epler
1701552dec
synthio: make sustain level relative to attack level
and re-vamp overall envelope calculation again.

Now, if you set a low overall attack level like 0.2 this avoids the
"diminishing volume" effect when many notes sound at once. You need
simply choose a maximum attack level that is appropriate for the max
number of voices that will actually be played.
2023-05-04 07:23:50 -05:00
Jeff Epler
c06597c07a
synthio: replace the quietest releasing note when over-writing 2023-05-04 07:23:49 -05:00
Jeff Epler
4f56b7646e
synthio: slow ramp overall envelope back up
.. and account releasing notes at their sustain level until they're
done.

this ameliorates the effect where multiple releasing notes
don't seem to actually be releasing, but stay at a constant volume.
2023-05-04 07:23:49 -05:00
Jeff Epler
a7da245ad0
synthio: Add synthio.Note
This class allows much more expressive sound synthesis:
 * tremolo & vibrato
 * arbitrary frequency
 * different evelope & waveform per note
 * all properties dynamically settable from Python code
2023-05-04 07:23:49 -05:00
Jeff Epler
5514e3065d
synthio: add midi_to_hz
to convert notes in the MIDI 1-127 note scale to floating point Hz
2023-05-04 07:23:48 -05:00
Jeff Epler
bd9aca2526
Merge pull request #7862 from jepler/synthio-envelope
Synthio envelope
2023-05-03 12:42:56 -05:00
Jeff Epler
dd262258e0
synthio: Add MidiTrack.error_location to record errors
.. instead of just printing the unraiseable error on the repl
2023-05-03 09:37:02 -05:00
Jeff Epler
d8550f4e7c
synthio: fix offset in default square waveform 2023-05-03 09:37:02 -05:00
Dan Halbert
34f565dd89
Merge pull request #7891 from tannewt/fix_epd_uc
Add address_little_endian and fix display memory reuse
2023-04-26 00:27:59 -04:00
Scott Shawcroft
75046b3a58
Save space with consolidated errors 2023-04-25 13:26:48 -07:00
Scott Shawcroft
eab202aa53
Fix SH110x 2023-04-25 10:36:34 -07:00
Jeff Epler
12c1a72f03
synthio: implement envelope
This works for me (tested playing midi to raw files on host computer, as
well as a variant of the nunchuk instrument on pygamer)

it has to re-factor how/when MIDI reading occurs, because reasons.

endorse new test results

.. and allow `-1` to specify a note with no sustain (plucked)
2023-04-25 12:05:53 -05:00
Scott Shawcroft
87fc5eff26
Re-enable partial updates when available 2023-04-24 16:24:33 -07:00
Scott Shawcroft
3ee8d0b5cb
Merge pull request #7878 from gamblor21/gifio_palettes
Palettes for OnDiskGif
2023-04-24 12:44:53 -07:00
foamyguy
01197a96d1 remove abs() from radius 2023-04-21 16:54:46 -05:00
Scott Shawcroft
b16037859c
Fix native epd boards 2023-04-21 14:36:35 -07:00
Scott Shawcroft
7089ea4d65
Add address_little_endian for displayio
Add address_little_endian for epaper displays with little endian
(low byte first) addresses.

Also clears allocated display and display bus memory so it has a
known state. The acep member wasn't always set so it varied
accidentally.

Fixes #7560. May fix #7778. Fixes #5119.
2023-04-21 12:19:29 -07:00
gamblor21
afae39765f PR review fixups 2023-04-20 18:26:04 -05:00
Scott Shawcroft
66edcf5d03
Add PicoDVI support
PicoDVI in CP support 640x480 and 800x480 on Feather DVI, Pico and
Pico W. 1 and 2 bit grayscale are full resolution. 8 and 16 bit
color are half resolution.

Memory layout is modified to give the top most 4k of ram to the
second core. Its MPU is used to prevent flash access after startup.

The port saved word is moved to a watchdog scratch register so that
it doesn't get overwritten by other things in RAM.

Right align status bar and scroll area. This normally gives a few
pixels of padding on the left hand side and improves the odds it is
readable in a case. Fixes #7562

Fixes c stack checking. The length was correct but the top was being
set to the current stack pointer instead of the correct top.
Fixes #7643

This makes Bitmap subscr raise IndexError instead of ValueError
when the index arguments are wrong.
2023-04-19 15:14:02 -07:00
gamblor21
403ea89d57 Initial paletts for OnDiskGif 2023-04-18 19:44:03 -05:00
CanyonCasa
61f868a14e
Update shared-module/onewireio/OneWire.c
Co-authored-by: Scott Shawcroft <scott@tannewt.org>
2023-04-17 12:02:45 -06:00
Debian
8927e41180 Reset stuck low detection 2023-04-15 17:05:12 -06:00
Jeff Epler
79d093d957
tweak max envelope calculation vs number of active notes 2023-04-05 17:43:03 -05:00
Jeff Epler
9993b4b01c
Prevent playing the same note on 2 channels 2023-04-05 16:53:08 -05:00
Scott Shawcroft
6df88ac948
Merge pull request #7825 from jepler/better-synthio
Better synthio
2023-04-05 12:23:10 -07:00
Jeff Epler
f2e26e8bde
get the cmsis macros the right way 2023-04-05 13:37:18 -05:00
Jeff Epler
04f4092e11
synthio: support audio outputs that need double buffering
closes #7837

tested on rp2040 pico w on pico dv shield
2023-04-05 11:57:13 -05:00
Jeff Epler
b9dea05dbf
Enable audiomixer on unix port, for testing 2023-04-05 09:02:03 -05:00
foamyguy
8bf94d03e4 try to fix multi-display reset 2023-04-04 20:31:42 -05:00
foamyguy
60e12c5c1d only add circuitpython_splash to display if it's not already in another group 2023-04-03 15:43:29 -05:00
Jeff Epler
b011468251
Add synthio.Synthesizer
In contrast to MidiTrack, this can be controlled from Python code,
turning notes on/off as desired.

Not tested on real HW yet, just the acceptance test based on checking
which notes it thinks are held internally.
2023-04-02 20:37:23 -05:00
Jeff Epler
e0984fa195
Factor out the synthesizer from midi track 2023-04-02 18:54:07 -05:00
Jeff Epler
e728a0c1b9
switch to 16.16 fixed point for synthesis 2023-04-01 11:47:27 -05:00
Jeff Epler
e9e4ce9546
add waveform support in synthio
a waveform object (array of 'h') can be passed in, replacing the
standard square wave. This waveform must be a 'single cycle waveform'
and some obvious things to pass in are sine, triangle or sawtooth waves,
but you can construct whatever you like.
2023-04-01 11:46:38 -05:00
Jeff Epler
13e17e6dcd
Make synthio debuggable in unix coverage port 2023-04-01 11:46:36 -05:00
Jeff Epler
db1e01c462
Don't require huge buffers for long-held notes 2023-04-01 11:46:36 -05:00
Jeff Epler
7f73ff1b2d
hold accumulator phase across span
this fixes grunk in held notes
2023-04-01 11:46:35 -05:00
Jeff Epler
02f8a45dfa
synthio: allow increasing number of channels
12 channels works well on metro m7
2023-04-01 11:46:27 -05:00
jposada202020
1931b6c042 fixing algorithm and MAX 2023-03-30 18:08:17 -04:00
jposada202020
4986ad6d6b
Update shared-module/bitmaptools/__init__.c
Co-authored-by: Dan Halbert <halbert@halwitz.org>
2023-03-30 15:43:57 -04:00
jposada202020
f6a0fb20f2
Update shared-module/bitmaptools/__init__.c
Co-authored-by: Dan Halbert <halbert@halwitz.org>
2023-03-30 15:29:39 -04:00
jposada202020
533f532ff2
Update shared-module/bitmaptools/__init__.c
Co-authored-by: Dan Halbert <halbert@halwitz.org>
2023-03-30 15:29:18 -04:00
jposada202020
6ad053e403 correcting feedback 2023-03-30 08:51:52 -04:00
jposada202020
f3d85d6932 Merge branch 'main' into adding_circle_bitmaptools 2023-03-30 07:44:07 -04:00
Dan Halbert
5909ceacc6
Merge pull request #7806 from dhalbert/no-report-id-out-reports
Handle HID OUT reports with no report ID
2023-03-29 15:33:36 -04:00
Dan Halbert
81482a6f66 Merge remote-tracking branch 'adafruit/8.0.x' into merge-8.0.x-to-main 2023-03-29 14:52:49 -04:00
Jeff Epler
a8bbb21eeb
Use short-circuiting or (also may save some code size)
Co-authored-by: Dan Halbert <halbert@adafruit.com>
2023-03-29 10:09:01 -05:00
Jeff Epler
cc3d0f6fa1
getenv: treat a read error like eof
Otherwise, the following would occur:
 * settings.toml is in the process of being written by host computer
 * soft-reset begins
 * web workflow tries to grab CIRCUITPY_WIFI_SSID, but loops forever
   because FAT filesystem is in inconsistent state and file reads error
 * settings.toml write by host computer never completes and the filesystem
   remains corrupt
 * restarting yields a soft-bricked device, because startup reads
   CIRCUITPY_WIFI_SSID again
2023-03-29 10:04:06 -05:00
Dan Halbert
d289329344 Handle HID OUT reports with no report ID 2023-03-28 11:38:38 -04:00
Neradoc
1fad969389 add unsigned ints and 64 bit types to msgpack
change msgpack error message when format invalid
2023-03-27 19:37:23 +02:00
Dan Halbert
0639c0850f
Merge pull request #7751 from hathach/add-codespell
Add codespell to pre-commit to scan and fix typo
2023-03-23 13:26:24 -04:00
Dan Halbert
db76fbd55f
Merge pull request #7712 from gamblor21/ondiskgif_freemem_fix
Add deinit to OnDiskGif
2023-03-23 09:03:07 -04:00
hathach
8c1095b268
Merge branch 'main' into add-codespell 2023-03-23 14:09:57 +07:00
gamblor21
e993d0f3c3 Missing brace 2023-03-22 20:19:09 -05:00
gamblor21
3020893ba2 Tweak to try to reduce low space builds 2023-03-22 19:20:20 -05:00
gamblor21
2c1e2061db Change free function 2023-03-22 19:20:20 -05:00
gamblor21
aa423cc1c6 Free memory allocated by bitmap obj 2023-03-22 19:20:20 -05:00
gamblor21
07e83674c9 Add deinit to displayio.Bitmap 2023-03-22 19:20:20 -05:00
gamblor21
8b9f5e7f53 Remove del obj and add deinited 2023-03-22 19:20:20 -05:00
Dan Halbert
2492fb0b0a
Merge pull request #7780 from jepler/fix-struct-pack
use `values` in this error message ...
2023-03-22 20:19:08 -04:00
Dan Halbert
05e783cbbd
Merge pull request #7775 from tannewt/fix_pyportal
Add more checks for read-only Bitmaps
2023-03-22 20:16:43 -04:00
Dan Halbert
3ef2b7f81f
Merge pull request #7777 from tannewt/fix_epd_grayscale
Fix tricolor epd and add EPD feather
2023-03-22 20:13:23 -04:00
jposada202020
29613c73e1 pre-commit 2023-03-22 19:05:18 -04:00
jposada202020
0b3099a9ff adding bitmaptools circle 2023-03-22 18:44:45 -04:00
Jeff Epler
127a7092bf
use values in this error message ...
matching the documentation of struct.pack, which has `def pack(fmt: str,
*values: Any)` as the signature.
2023-03-22 16:11:22 -05:00
Scott Shawcroft
16c8dad078
Fix Pallete cache for grayscale and tricolor epd 2023-03-22 11:54:43 -07:00
Scott Shawcroft
a280c010c2
Fix tricolor epd and add EPD feather 2023-03-22 11:14:38 -07:00
Scott Shawcroft
36dbaf4ccc
Add more checks for read-only Bitmaps
Fixes #7768
2023-03-22 10:14:42 -07:00
Jeff Epler
98c546bf57
call common validation function
Co-authored-by: MicroDev <70126934+microdev1@users.noreply.github.com>
2023-03-22 10:16:48 -05:00
Jeff Epler
349dedca54
struct: Check that argument counts match, similar to cpython3
.. and test our struct module during the build-time tests

Closes #7771
2023-03-22 09:35:09 -05:00
Dan Halbert
c93560144b
Merge pull request #7678 from FoamyGuy/boundary_fill_background_tasks
do background tasks and handle interrupt during boundary fill
2023-03-21 23:38:05 -04:00
Scott Shawcroft
67e0a49a1f
Merge pull request #7724 from tannewt/get_perfbench_running
Improve iMX RT performance
2023-03-21 09:00:48 -07:00
jposada202020
ace25e83ce correcting vectorshape location property 2023-03-20 15:44:49 -04:00
hathach
fecc1bdedb
fix typos (partial) detected by codepell 2023-03-18 22:17:02 +07:00
foamyguy
d30b89d8d1 Merge branch 'main' into boundary_fill_background_tasks 2023-03-14 18:24:01 -05:00
Scott Shawcroft
5bb8a7a7c6
Improve iMX RT performance
* Enable dcache for OCRAM where the VM heap lives.
* Add CIRCUITPY_SWO_TRACE for pushing program counters out over the
  SWO pin via the ITM module in the CPU. Exempt some functions from
  instrumentation to reduce traffic and allow inlining.
* Place more functions in ITCM to handle errors using code in RAM-only
  and speed up CP.
* Use SET and CLEAR registers for digitalio. The SDK does read, mask
  and write.
* Switch to 2MiB reserved for CircuitPython code. Up from 1MiB.
* Run USB interrupts during flash erase and write.
* Allow storage writes from CP if the USB drive is disabled.
* Get perf bench tests running on CircuitPython and increase timeouts
  so it works when instrumentation is active.
2023-03-14 12:30:58 -07:00
Dan Halbert
5cb21539f2 use revised USB host API on mimxrt10xx 2023-03-10 13:12:37 -05:00
MicroDev
b9e478af39
Merge pull request #7471 from matemaciek/main
Add function for drawing polygons to bitmaptools
2023-03-07 08:28:07 +05:30
foamyguy
7740cbac97 do background tasks and handle interrupt during boundary fill 2023-03-04 13:13:59 -06:00
Dan Halbert
bac1a9625a OnDiskGif delay was being chopped to 8 bits 2023-03-02 16:47:07 -05:00
Dan Halbert
859a48723f
Merge pull request #7633 from tannewt/fix_imx_pwm
Fix `pwmio` on iMX RT.
2023-02-28 14:11:06 -05:00
Dan Halbert
f9831b3bbc
Merge pull request #7639 from adafruit/8.0.x
Merge 8.0.x up to main
2023-02-24 19:32:09 -05:00
Scott Shawcroft
b79661d631
Alphabetize, fix typo and remove incorrect comment 2023-02-23 14:34:54 -08:00
Scott Shawcroft
1acf65ee22
Fix pwmio on iMX RT.
It now handles deinit, never_reset and sharing tracking. PWM
now runs in the WAIT state as well during a time.sleep().

_reset_ok() was removed because it was called in one spot right
before deinit().

Some PWMOut were also switched to a bitmap for use instead of
reference count. That way init and deinit are idempotent.

Fixes #6589. Fixes #4841. Fixes #4541.
2023-02-22 11:22:39 -08:00
Scott Shawcroft
de5f58a61d
Merge branch 'main' into banglejs2 2023-02-21 12:04:28 -08:00
Scott Shawcroft
a8b34bd067
Merge pull request #7549 from gamblor21/gif_displayio_support
Animated GIF support
2023-02-21 11:39:29 -08:00
Dan Halbert
3f66a0be83
Merge pull request #7611 from gamblor21/colorconverter-mem-fix
ColorConverter output colorspace non-initialization fix
2023-02-19 20:34:30 -05:00
gamblor21
e78875a93b ColorConverter output colorspace fix 2023-02-18 15:35:56 -06:00
Scott Shawcroft
931c7c1c51
Add Bangle.js 2, JDI memory displays and ACeP epd
This 2-in-1 PR started with the goal of support the Bangle.js 2
smartwatch with *no USB*.
* Adds "secure" DFU build support with a committed private key.
* Adds 3-bit color support with one dummy bit for the JDI memory display
* Allows nrf boards to have a board_background_task() run in RUN_BACKGROUND_TASK.
  This is needed because the Bangle.js 2 uses the watchdog to reset.
* Renamed port_background_task() to port_background_tick() to indicate it
  runs on tick, not RUN_BACKGROUND_TASK.
* Marks serial connected when the display terminal is inited. This means
  that safe mode messages show up on the display.

ACep, 7-color epaper displays also pack 3 bits in 4. So, I added that
support as well.
* Adds 3-bit ACeP color support for 7-color e-paper displays. (Not
  watch related but similar due to color depth.)
* Allows a refresh sequence instead of a single int command. The 7" ACeP
  display requires a data byte for refresh.
* Adds optional delay after resetting the display. The ACeP displays
  need this. (Probably to load LUTs from flash.)
* Adds a cleaning phase for ACeP displays before the real refresh.

For both:
* Add dither support to Palette.
* Palette no longer converts colors when set. Instead, it caches
  converted colors at each index.
* ColorConverter now caches the last converted color. It should make
  conversions faster for repeated colors (not dithering.)
2023-02-15 15:03:40 -08:00
Mark
fa435468fa
Merge branch 'main' into gif_displayio_support 2023-02-13 18:30:51 -06:00
gamblor21
cab38ed6a6 Doc fixes and renamed play_frame to next_frame 2023-02-12 11:51:23 -06:00
gamblor21
0c95e6a08e Moving to gifio module 2023-02-12 11:17:34 -06:00
gamblor21
29e91e0d4f Fix for changing frame size and disposal method issues 2023-02-12 09:11:12 -06:00
gamblor21
da9b6fb0e2 Moving library to /lib 2023-02-10 18:31:59 -06:00
Neradoc
3c93594563 Deinit the reset pin when displayio.I2CDisplay raises an exception 2023-02-10 19:54:10 +01:00
gamblor21
19eba41630 Doc fixes and return next frame delay 2023-02-08 22:58:44 -06:00
gamblor21
dbe518680a Memory savings and more properties 2023-02-05 10:54:04 -06:00
gamblor21
6a9b7199ec Initial gif proof of concept 2023-02-04 16:44:29 -06:00
foamyguy
fab1bb5f21 fix for native is31fl3741 2023-02-03 17:43:12 -06:00
Maciej Sokołowski
e474df3a18 Add function for drawing polygons to bitmaptools 2023-01-20 23:14:38 +01:00
Maciej Sokołowski
2276254f6c Fix compilation 2023-01-19 21:50:59 +01:00
Maciej Sokołowski
483f14b73f Allow lines with ends out of bitmap in bitmaptools_obj_draw_line 2023-01-19 21:37:25 +01:00
Dan Halbert
a3adcf0e1a clarify read-only mac address; reuse translate msgs 2023-01-02 10:13:20 -05:00
Jeff Epler
34043c2d38
Only store up to 'width' pixels, not 'stride'
error detected by clang scan-build static analysis
2023-01-01 16:45:40 -06:00
Jeff Epler
d808185744
Emphasize that ALIGN_BITS is a constant 2023-01-01 16:45:40 -06:00
Jeff Epler
d2361ae4f9
Avoid an undefined shift
(1 << 32), an operation on a signed 32-bit int, is undefined in C. The
operation on the unsigned int (1u<<32) is defined as zero, which is
the desired outcome (subtracting 1 yields the value with all bits set)

This problem was detected by clang scan-build static analysis
2023-01-01 16:45:35 -06:00
Jeff Epler
7a005aa96b
break out after reading the value
This is a small optimization, it avoids reading the full file when an
early key is requested.

In the case of an *invalid* TOML file such as
```
K=80
K=81
```
this stops the value of K actually returned being 8081 and makes it 80
instead; but as it's a malformed file it doesn't really matter much.
2022-12-28 13:24:38 -06:00
Jeff Epler
15a24b400d
Permit trailing whitespace in getenv_int 2022-12-28 12:37:27 -06:00
Jeff Epler
f6b69cf5e3
Allow settings.toml to end without a newline 2022-12-26 10:53:58 -06:00
Jeff Epler
4dbbfa0931
Print errors to repl about getenv 2022-12-26 10:53:58 -06:00
Dan Halbert
398b7c26ca
Merge pull request #7321 from jepler/dotenv-becomes-toml
Dotenv becomes toml
2022-12-13 19:56:36 -05:00
Jeff Epler
d40ba94449
explain why this is its own file 2022-12-13 13:19:10 -06:00
Jeff Epler
35f2046ab2
Fix returning GETENV_ERR_LENGTH for over-long strings 2022-12-13 12:02:07 -06:00
Radomir Dopieralski
6412d971fa displayio: Set in_group to false when removing a layer from a group
Otherwise the removed layer cannot be re-added.
2022-12-11 02:59:56 +01:00
Jeff Epler
dd6dd5df21
rework the getenv test again
* use a virtual fat filesystem during the test
 * this makes the file I/O part more closely patch runtime which is nice
 * side-steps the need to add a special function for testing
   * but test still can't be run on a device, because the vfs calls
     are incompatible, and you intentionally can't remount "/" anyway
 * and side-steps problems with storing 'bad' toml files
2022-12-10 12:58:08 -06:00
Jeff Epler
040fac0724
No need to track excess length
.. this is a relic from when the actual required length was given
back to the caller
2022-12-09 14:29:14 -06:00
Jeff Epler
cc7d550407
Really finish renaming to getenv 2022-12-09 14:28:46 -06:00
Jeff Epler
44f15d563d
Rename "environ" errors to "getenv" errors 2022-12-09 14:14:53 -06:00
Jeff Epler
3a92c079fc
Finish renaming os_environ_get_key to os_getenv
.. for consistency.
2022-12-09 14:07:23 -06:00
Jeff Epler
3459fe322b
Withdraw the _environ module
This existed solely for testing, so expose it a different way during
the unix coverage build

Also turn off os.getenv support on samd21.
2022-12-08 15:33:10 -06:00
Jeff Epler
ef2bfdb5db
dotenv becomes settings.toml 2022-12-08 12:44:20 -06:00
Scott Shawcroft
9e104c04ae
Merge pull request #7215 from FoamyGuy/set_root_group
displayio.show() API change
2022-12-02 08:45:20 -08:00
foamyguy
57462092b5 return None instead of NULL for framebuffer and epaper 2022-12-01 17:34:43 -06:00
foamyguy
42f1d50acc remove extra function call. handle show(None) for framebuffer and epaper 2022-12-01 17:25:36 -06:00
Dan Halbert
082b0d1aed
Merge pull request #7191 from jepler/fastpixelmap
Add a fast PixelMap-like class
2022-12-01 11:43:00 -05:00
foamyguy
0563487433 get slicing 2022-11-30 19:16:20 -06:00
Jeff Epler
db01dfea20
use a standard length validator 2022-11-30 12:06:19 -06:00
foamyguy
1bbdc820c0 make show(None) show the terminal 2022-11-28 17:02:46 -06:00
foamyguy
553d48f887 return None for NULL 2022-11-28 09:03:03 -06:00
foamyguy
b8d6605cff code format, extra space 2022-11-27 17:26:46 -06:00
foamyguy
6844dc0cb7 code format, extra space 2022-11-27 14:20:15 -06:00
foamyguy
15a9e63fda remove is_null troubleshooting function. remove empty line 2022-11-27 14:08:38 -06:00
foamyguy
738b73d4b4 check for NULL in fill_area. moved start_terminal to reset_display. 2022-11-27 13:54:53 -06:00
foamyguy
2c479f4fce working on None behavior 2022-11-26 11:00:09 -06:00
foamyguy
57d7f7f2ad move to _pixelmap 2022-11-24 09:07:08 -06:00
foamyguy
e5ea1d2247 try to revert pixelbuf merge brokenness. remove second color_u def. 2022-11-22 18:47:25 -06:00
foamyguy
19f1119994 Merge branch 'main' into fastpixelmap
# Conflicts:
#	shared-module/adafruit_pixelbuf/PixelBuf.c
2022-11-21 20:25:58 -06:00
foamyguy
fa4b480439 looking into how null show works 2022-11-21 20:21:39 -06:00
foamyguy
ef3398422a allow set_root_group for FrameBufferDisplay instead of show() 2022-11-19 11:41:48 -06:00
foamyguy
e3cae22297 allow set_root_group for EPaperDisplay instead of show() 2022-11-18 17:34:03 -06:00
foamyguy
403e3ef430 change to CIRCUITPYTHON_TERMINAL. change internal API to use set_root_group 2022-11-18 16:53:18 -06:00
MicroDev
f637332de6
Merge pull request #7209 from jepler/code-optimize-pixelbuf
Save code space by packing rgbw values into C union
2022-11-18 14:46:55 +05:30
foamyguy
5b64a62c16 move hidden declare inside struct 2022-11-15 18:37:23 -06:00
Jeff Epler
14ba5a75a3
skip converting from long int if long ints aren't enabled
.. saves 20 bytes on proxlight trinkey
2022-11-14 21:26:58 -06:00
Jeff Epler
2d08473ee0
this version actually saves more code space on cortex-m0 with -Os (samd21s) 2022-11-14 21:18:40 -06:00
Jeff Epler
adca341d3b
Save code space by packing rgbw values into C union
It's more efficient passing one register-sized structure than 4
arguments or 4 pointers; working on intermediate values of 'int' size
is also more efficient in code size!

On raspberry pi pico w, this increased free flash space by +104 bytes.
It also increased the speed of my testing animation very slightly, from
187fps to 189fps when run 'unthrottled'
2022-11-14 09:29:45 -06:00
foamyguy
3c4d8c6926 implement self hidden property for vectorio shapes 2022-11-11 17:50:07 -06:00
Jeff Epler
f5c637dc10
Add adafruit_pixelmap.PixelMap
.. a fast helper for animations. It is similar to and inspired by the
PixelMap helper in Adafruit LED Animation library, but with an extremely
fast 'paste' method for setting a series of pixels. This is a common
operation for many animations, and can give a substantial speed improvement.

It's named `adafruit_pixelmap` so that we can package a compatible version
in pure Python for systems that can't fit it in C in flash, or for
Blinka.

This is a proof of concept and can make a very fast comet animation:
```python
import time
import adafruit_pixelbuf
import adafruti_pixelmap
import board
import neopixel
from supervisor import ticks_ms
from adafruit_led_animation.animation.solid import Solid
from adafruit_led_animation import color

pixel_pin = board.GP0
pixel_num = 96

pixels = neopixel.NeoPixel(pixel_pin, pixel_num, brightness=1, auto_write=False, pixel_order="RGB")

evens = adafruit_pixelmap.PixelMap(pixels, tuple(range(0, pixel_num, 2)))
odd_indices = tuple((i, i+2) for i in range(1, pixel_num, 4))
print(odd_indices)
odds = adafruit_pixelbuf.PixelMap(pixels, odd_indices)
assert len(odds) == len(odd_indices)


comet_length = 16

comet1 = [color.calculate_intensity(color.GREEN, ((1+i) / comet_length) ** 2.4)
        for i in range(comet_length)]
comet2 = [color.calculate_intensity(color.PURPLE, ((1+i) / comet_length) ** 2.4)
        for i in range(comet_length)]

pos1 = 0
pos2 = 96//4

while True:
    evens.paste(comet1, pos1, wrap=True, reverse=False, others=0)
    pos1 = (pos1 + 1) % len(evens)

    odds.paste(comet2, pos2, wrap=True, reverse=True, others=0)
    pos2 = (pos2 - 1) % len(odds)
    pixels.show()

    m = ticks_ms()
    if m % 2000 > 1000:
        time.sleep(.02)
```
2022-11-11 07:54:33 -06:00