Commit graph

1637 commits

Author SHA1 Message Date
Eric Lammerts
ca53f8b390 Fix infinite loop when there's a partial frame at the end of the file. 2024-09-23 16:46:20 -04:00
RetiredWizard
32537edb09 esp32s3: Implement sdioio 2024-09-18 17:37:59 -04:00
Dan Halbert
1f68fffa13 merge from main 2024-09-10 16:36:32 -04:00
Dan Halbert
bc6f065447 working on compilation errors 2024-09-06 23:10:41 -04:00
James Bowman
73eb5944bf Extend EVE hardware opcodes for future-compatibility
Extend the bitfields of these instructions: BitmapHandle, ClearTag, Tag, BitmapSource, PaletteSource
Add instructions: BitmapSourceH PaletteSourceH

All the new bits and opcodes are ignored by earlier hardware, so this change is backwards-compatible.

Passes tests on all EVE hardware.
2024-09-06 10:53:05 -07:00
James Bowman
862ad62901 Make BitmapTransform* methods backwards-compatible
The setmodel() method controls the behavior
So existing code will continue to work unchanged
Subsequent releases of the ``eve`` library will call setmodel() to enable the new behavior
Confirmed all code paths on EVE hardware
2024-09-04 11:20:48 -07:00
19e5cf3d8f Avoid crashing when display components are deinitialized
Now, try_lock (SPI & I2C) & begin_transaction (display bus core) will check
that the related objects are still valid first; if they are not,
the lock/begin transaction will fail by returning false, rather than
"other things" such as raising a Python exception where it is not
permitted, accessing invalid memory, etc.

Closes #8278 and Closes #9426
2024-08-28 09:44:02 -05:00
Dan Halbert
e5e9c5ca84
Merge pull request #9469 from dhalbert/merge-from-micropython-v1.22.2
Merge from micropython v1.22.2
2024-08-21 18:11:19 -04:00
Scott Shawcroft
4950bebff0
Remove unique error messages
The two checks on self->type should be impossible to hit so they
are removed. Switch to `Invalid ...` for two others.
2024-08-13 09:41:23 -07:00
Scott Shawcroft
d9fcaa00ae
Merge pull request #9488 from wyrdsec/main
Driver for Pervasive Display's Aurora based E-ink display
2024-08-12 09:41:27 -07:00
wyrdsec
2a98af336c More pre-commit formating 2024-08-08 21:26:17 -04:00
wyrdsec
e416ac0570 pre-commit fixes 2024-08-08 20:37:49 -04:00
Scott Shawcroft
5376443f58
Add support for RP2350 to CircuitPython
This adds support for the next RP2 microcontroller, the RP2350.

Thanks to Raspberry Pi folks for early access and to @arturo182,
@oberchoo and @SalamCytron for helping with CircuitPython.
2024-08-08 09:54:51 -07:00
wyrdsec
6208124bd1
Merge branch 'adafruit:main' into main 2024-08-07 18:01:23 -04:00
Radomir Dopieralski
2c7b11b1af displayio.Bitmap is now byte-aligned for depth < 8
The traditional layout of pixels in bitmaps of depth less than eight
is with the order of values in a byte reversed, but with bytes in
the same order as the pixels on the line.

Before now, displayio.Bitmap did reverse the values, but did it on a
word (four bytes) basis, not byte, which resulted in groups of four
bytes being in the order opposite to the screen order.

This patch fixes this, by making processing of pixels in bitmaps of
depth less than 8 bits based on bytes, not words. Since the internal
details are changing, any code that accessed bitmaps through the
memoryview buffer, or that created bitmaps directly from raw data,
and that used depth of less than 8 bits will be affected.

Therefore, the gen_display_resources.py script also had to be modified
to account for the changes.
2024-08-05 23:14:55 +02:00
wyrdsec
b580df5ab3
Merge branch 'adafruit:main' into main 2024-08-02 13:42:51 -04:00
wyrdsec
4ae6afa0c1 Updated copyright 2024-08-02 13:39:57 -04:00
Dan Halbert
be6fa2af21 merge from main 2024-07-29 17:41:46 -04:00
Dan Halbert
71f17b08fb wip: fixing compilation 2024-07-26 18:38:46 -04:00
Tim
ce67e2a0fb remove dead code 2024-07-17 13:18:00 -07:00
Tim
a1fe288ab8 make loop=True required for constant play, add test code 2024-07-16 13:47:09 -07:00
Tim
b3b3577513 add double buffering to RawSample 2024-07-09 11:21:07 -07:00
Dan Halbert
48dd9e3046 shared-module/sdcardio/SDCard.c: check for deinit more thoroughly 2024-07-09 10:40:37 -04:00
ed5591c5cb
Merge pull request #9318 from jepler/sslsocket-stream-protocol
SSLSocket: Add stream protocol
2024-06-14 10:02:17 -05:00
4d4d654677 MP3Decoder: set the nonblocking flag as needed
this makes SSL sockets (which return readable when not yet actually
readable) work better.
2024-06-13 11:11:17 -05:00
3215f6c4ff SSLSocket: handle exceptions during protocol read/write operations
These protocol operations should not raise exceptions, but sometimes
they do. Catch the exception and extract the errno value if available.

At the same time, harmonize the argument types for the underlying C
routines
2024-06-12 16:41:19 -05:00
Dan Halbert
8b39b3b6a6 shared-module/usb_hid/Device.c: update tud_hid_set_report_cb() 2024-06-10 18:19:27 -04:00
49a612056e take micropython tricks for selectability of ssl sockets 2024-06-10 12:07:48 -05:00
wyrdsec
e6a569a1e5 shared-module/aurora_epaper/aurora_framebuffer.c: More comments 2024-06-07 17:08:58 -04:00
7969638740 SSLSocket: Add stream protocol
including select. This assumes that the SSL layer is readable/writable
exactly when the underlying socket is readable/writable.
2024-06-07 14:49:35 -05:00
wyrdsec
633f1a6bf9 shared-module/aurora_epaper: small compilation error 2024-06-07 10:19:22 -04:00
wyrdsec
e9c416bda2 shared-module/aurora_epaper: Formatting
shared-bindings/aurora_epaper: Formatting
2024-06-07 10:03:02 -04:00
wyrdsec
707026623f
Merge branch 'adafruit:main' into main 2024-06-06 20:30:44 -04:00
wyrdsec
bafe45fde9 Docs 2024-06-06 20:29:50 -04:00
Scott Shawcroft
1aa17b39b6
Merge pull request #9284 from jepler/mp3-stream
MP3: Stream them
2024-06-06 12:15:30 -07:00
wyrdsec
1214b699ca Pervasive Displays Aurora E-paper driver 2024-06-05 20:00:45 -04:00
6c9eaf1415 MP3Decoder: better handle underflows of mp3 stream
* Don't consume in the case of "indata overflow".
   Doing so leaves us at a bad boundary within the MP3 data
   and can continue decoding from an inappropriate spot
   i.e., one that looks likede mp3 data but is NOT.

   because there are many crashing bugs in the helix mp3 library on
   invalid input data, we must do our best to avoid them, and this
   is one way to do that.

 * clear the output buffer in the case there's not a sync word in the
   buffer. this can also happen when too little data is available.

   this changes more "stuttering" conditions into "silent" conditions.

With these changes, I can get through 3+ plays of "idea.mp3" from a local
http server with long pauses (but not stuttering glitches or safe mode
crashes).

I was also able to play through 10+ minutes of http://ice2.somafm.com/dronezone-128-mp3
without crashing or "end of stream", though again there are pauses
due to packet loss.

I think this is good now, except for the problems that arise when
the socket layer doesn't deliver a fresh packet for a long time.
2024-06-05 14:52:07 -05:00
cb295c57d7 MP3Decoder: Make it possible to start in the middle of an MP3
You can now, e.g.,
```
with open("/whatever.mp3") as mp3_file:
    mp3_file.seek(16000*30)
    decoder.file = mp3_file
    i2s.play(decoder)
```
to start about 30 seconds into a 128kbit/s CBR track.

If a track is looped, the loop will start at the beginning.

This also changes the behavior if the track is started & stopped: it will
continue from where it left off, except if it had prevously run to
completion. To get other behavior, you can seek the file and then re-assign
the file property.
2024-06-05 10:33:40 -05:00
6f6b680c18 MP3Decoder: improve some comments 2024-06-04 12:24:34 -05:00
Scott Shawcroft
254cac059e
Make time_to_refresh return 0 correctly
Redo Feather C6 pinout so it include standard D# labels for feathers

Fixes #9244
2024-06-03 15:33:11 -07:00
f81a3aed68 MP3Decoder: avoid all blocking reads in background
This gets MP3 playback of a soma.fm stream working for up to a minute
at a time, though it's still vulnerable to network glitches.

 * the buffer can empty, in which case a single block of audio
   plays repeatedly in max headroom stutter fashion
 * the server eventually (after 1 to 5 5 minutes) stops getting packets
   at all. At this point stream playback stops, with the internal error
   indicating a problem MP3 decoding (which doesn't quite make sense):
   -9, ERR_MP3_INVALID_HUFFCODES.
 * other combinations of audiomixer buffer & mp3 buffer might give
   different results
```py
import time

import adafruit_connection_manager
import adafruit_requests
import audiobusio
import audiomixer
import audiomp3
import board
import wifi

pool = adafruit_connection_manager.get_radio_socketpool(wifi.radio)
ssl_context = adafruit_connection_manager.get_radio_ssl_context(wifi.radio)
requests = adafruit_requests.Session(pool, ssl_context)

# todo: parse PLS files like https://somafm.com/nossl/dronezone.pls
# todo: figure out why https URLs don't work at all (missing select?)
# STREAMING_URL = "http://ice2.somafm.com/dronezone-128-mp3"
STREAMING_URL = "http://ice4.somafm.com/tikitime-128-mp3"


def get_mp3_stream():
    if STREAMING_URL.startswith("http:") or STREAMING_URL.startswith("https:"):
        return requests.get(STREAMING_URL, headers={"connection": "close"}).socket
    return open(STREAMING_URL, "rb")


mixer_buffer_size = 1152 * 2
mp3_buffer = bytearray(32768)

with audiobusio.I2SOut(
    bit_clock=board.D12, word_select=board.D13, data=board.D11
) as i2s, get_mp3_stream() as stream, audiomp3.MP3Decoder(
    stream, mp3_buffer
) as sample, audiomixer.Mixer(
    channel_count=2, sample_rate=44100, buffer_size=mixer_buffer_size
) as m:

    v = m.voice[0]
    print(sample)

    i2s.play(m)

    v.play(sample, loop=False)
    while v.playing:
        time.sleep(0.1)
```
2024-06-03 15:49:14 -05:00
a5c4a86349 MP3Decoder: ssize_t type is not portable, don't use it 2024-05-30 16:45:35 -05:00
dffc55ee17 MP3Decoder: STATIC -> static 2024-05-30 14:32:48 -05:00
9bc89f5fba MP3Decoder: better handle INDATA_UNDERFLOW & MAINDATA_UNDERFLOW
This allows playback of some 128k http streams from somafm, though
glitches occur with some regularity.

```py
import time

import adafruit_connection_manager
import adafruit_requests
import audiobusio
import audiomixer
import audiomp3
import board
import wifi

pool = adafruit_connection_manager.get_radio_socketpool(wifi.radio)
ssl_context = adafruit_connection_manager.get_radio_ssl_context(wifi.radio)
requests = adafruit_requests.Session(pool, ssl_context)

# todo: parse PLS files like https://somafm.com/nossl/dronezone.pls
# todo: figure out why https URLs don't work at all (missing select?)
# STREAMING_URL = "http://ice2.somafm.com/dronezone-128-mp3"
STREAMING_URL = "http://ice4.somafm.com/tikitime-128-mp3"


def get_mp3_stream():
    if STREAMING_URL.startswith("http:") or STREAMING_URL.startswith("https:"):
        return requests.get(STREAMING_URL, headers={"connection": "close"}).socket
    return open(STREAMING_URL, "rb")


mixer_buffer_size = 1152 * 16
mp3_buffer = bytearray(16384)

with audiobusio.I2SOut(
    bit_clock=board.D12, word_select=board.D13, data=board.D11
) as i2s, get_mp3_stream() as stream, audiomp3.MP3Decoder(
    stream, mp3_buffer
) as sample, audiomixer.Mixer(
    channel_count=2, sample_rate=44100, buffer_size=mixer_buffer_size
) as m:

    v = m.voice[0]
    print(sample)

    i2s.play(m)

    v.play(sample, loop=False)
    while v.playing:
        time.sleep(0.1)
```
2024-05-30 14:22:51 -05:00
974b21a079 MP3Decoder: do better at keeping stream buffer full 2024-05-30 14:22:51 -05:00
a80311d4c0 MP3Decoder: make testable in coverage build
An mp3 decoder (note that this needs `audiocore.get_buffer`, not
enabled on devices):
```py
import sys
import audiomp3
import audiocore

GET_BUFFER_DONE, GET_BUFFER_MORE_DATA, GET_BUFFER_ERROR = range(3)

with audiomp3.MP3Decoder(sys.argv[1]) as decoder, open(sys.argv[2], "wb") as target:

    while True:
        res, samples = audiocore.get_buffer(decoder)
        if res != GET_BUFFER_ERROR:
            target.write(samples)
        if res != GET_BUFFER_MORE_DATA:
            break
```

this doesn't actually add any tests though
2024-05-30 14:22:39 -05:00
d6ddd55462 MP3Decoder: Allow passing any stream-like object
This can sort-of play MP3s from a http request, but the buffering is
not good enough to play glitch-free. A new kind of buffer that can
read ahead further without blocking is needed.
2024-05-30 14:21:34 -05:00
Dan Halbert
3f4d9310ff CircuitPython files: replace STATIC with static 2024-05-20 11:02:17 -04:00
Dan Halbert
950b5d09d2 guard2once -s ... 2024-05-19 20:40:44 -04:00
Dan Halbert
dbef48d5e2 add #pragma once to all CircuitPython header files without any include guards 2024-05-19 20:38:07 -04:00