This makes all the samples from Dan's collection register as 440Hz
when playing on pwmio or i2sout, using https://webaudiodemos.appspot.com/pitchdetect/index.html
to detect the frequency played (all should show as A 440Hz; an error
of up to 20 "cents" should be treated as OK)
There's an audible carrier with PWM output and the 8kHz samples. This is
probably a limitation of the peripheral which is documented as being for
input signals of 44 kHz or 48 kHz; the carrier frequency is a fixed
multiple of the sample frequency.
Closes#7800
* 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.
#7644 pointed out the need for better documentation.
To the best of my ability I noted the current behavior.
I think that there may be some ports that do not actually read
back the 'set' frequency value, but they are ports marked as beta
status (mimxrt10xx) or not maintained by us (cxd56).
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.)
The comment says it is `buffer[start:end]` but it assumed elements
were a single byte long. Now it correctly does multibyte elements
from array.array.
Fixes#4988
Previously the only other way of determining whether the Vfs has been mounted
read-write or read-only appears to be to attempt a write operation and detect a
possible OSError.
It wasn't possible for the user code to keep track of the state of the state
since the boot VM has to decide whether to (re)mount read-write or read-only,
but can't (easily) pass this information on to the runtime VM.
* read() is now readinto() and takes the buffer to write into.
* readinto() returns the number of valid samples.
* readinto() can be interrupted by ctrl-c.
* readinto() API doesn't support signed numbers because it never did.
* sample_rate is now required in the constructor because supported
values will vary per-port.
* 16 bit values are full range. 12 bit samples from RP2040 are stretched
in the same way they are for AnalogIn.
Fixes#7226
gaierror(-2) is raised in the failure case of getaddrinfo. This is
compatible with cpython's socket module.
Typical session:
```
>>> import socketpool
>>> import wifi
>>> socket = socketpool.SocketPool(wifi.radio)
>>> try: socket.getaddrinfo("boo", 0)
... except socket.gaierror as e: ee = e
...
>>> type(ee)
<class 'gaierror'>
>>> ee.errno == socket.EAI_NONAME
True
>>> ee.strerror
'Name or service not known'
>>> raise ee
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "<stdin>", line 1, in <module>
gaierror: (-2, 'Name or service not known')
```
Closes: #6941
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'
.. 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)
```
Because this must be treated like an in-use pin for all other purposes,
unfortunately a special case must be added in shared-bindings.
Multiple AnalogIn objects for VOLTAGE_MONITOR can be created (because
in use tracking isn't working) but this causes no harm.
Testing performed: Read the monitor, then imported wifi. When the
pin state was insufficiently restored, the second step would fail
with debug messages about do_ioctl timeout.
```
import analogio, board
a = analogio.AnalogIn(board.VOLTAGE_MONITOR)
print(a.value)
import wifi
```
Closes: #7020
When "Limitations:" is in the class docstring, it is sometimes taken
as a class attribute name because of the colon. When exactly is not clear, but
changing embedded colons or various indentations fixes the problem.
The standard Python 'fix' for 'send()' returning prematurely is to
use the 'sendall()' method instead. However, this method was not
available. adafruit_httpserver will probably need to code a version
of it for older versions or for Airlift, but when it's available
this code works (Tested on picow sending 8192 bytes) and may be more
efficient.
(implementing 'sendall' in python should take care to slice a memoryview
rather than the original buffer)
We adopted the file "py/ioctl.h" and the ioctl names beginning
with MP_IOCTL_POLL while micropython went with "py/stream.h" and
MP_STREAM_POLL.
Align with upstream.
Closes#6711
Tested with badssl.com:
1. Get client certificates from https://badssl.com/download/
2. Convert public portion with `openssl x509 -in badssl.com-client.pem -out CIRCUITPY/cert.pem`
3. Convert private portion with `openssl rsa -in badssl.com-client.pem -out CIRCUITPY/privkey.pem` and the password `badssl.com`
4. Put wifi settings in CIRCUITPY/.env
5. Run the below Python script:
```py
import os
import wifi
import socketpool
import ssl
import adafruit_requests
TEXT_URL = "https://client.badssl.com/"
wifi.radio.connect(os.getenv('WIFI_SSID'), os.getenv('WIFI_PASSWORD'))
pool = socketpool.SocketPool(wifi.radio)
context = ssl.create_default_context()
requests = adafruit_requests.Session(pool, context)
print(f"Fetching from {TEXT_URL} without certificate (should fail)")
response = requests.get(TEXT_URL)
print(f"{response.status_code=}, should be 400 Bad Request")
input("hit enter to continue\r")
print("Loading client certificate")
context.load_cert_chain("/cert.pem", "privkey.pem")
requests = adafruit_requests.Session(pool, context)
print(f"Fetching from {TEXT_URL} with certificate (should succeed)")
response = requests.get(TEXT_URL)
print(f"{response.status_code=}, should be 200 OK")
```
This module has not been built in years, since the (removed) esp8266 port.
Delete the code, as it is not likely to be useful in its current form.
Closes: #7015
Note: at this time, the ssl module on pico_w never verifies the server
certificate. This means it does not actually provide a higher security
level than regular socket / http protocols.
Correction of the timeout value range needed to set the timeout to 'forever'.
The line 162 checks timeout for a value of 0 while the function definition defaults timeout to -1. In the current version of the code timeout is only checked for a value of 0 or in the 'else if' part for a value of > 0. So, values of <0 will not be taken in to account. That is the reason of my modification.
Correction in function request() doc function signature.
(after speaking with @jepler on Discord).
(@jepler: 'Circuitpython always has floats enabled')
Modification of the doc text of function request().
1) The timout parameter is a keyword-only argument; so Added '*,' in the function signature;
2) for parameter timeout an integer is expected, not a float.
Originally, black_bindings found each contiguous "//|" block and sent
it to black independently. This was slower than it needed to be.
Instead, swap the comment prefix: when running black, take off
"//|" prefixes and put "##|" prefixes on all un-prefixed lines.
Then, after black is run, do the opposite operation
This more than doubles the overall speed of "pre-commit run --all",
from 3m20s to 55s CPU time on my local machine (32.5s to under 10s
"elapsed" time)
It also causes a small amount of churn in the bindings, because
black now sees enough context to know whether one 'def' follows another
or ends the 'def's in a 'class'. In the latter case, it adds an extra
newline, which becomes a "//|" line.
I'm less sure why a trailing comma was omitted before down in
rp2pio/StateMachine.c but let's roll with it.
My pings go out, and then they come back
```py
import os
import wifi
import ipaddress
wifi.radio.connect(os.getenv('WIFI_SSID'), os.getenv('WIFI_PASSWORD'))
ipv4 = ipaddress.ip_address("8.8.4.4")
print("Ping google.com: %f ms" % (wifi.radio.ping(ipv4)*1000))
```