Commit graph

183 commits

Author SHA1 Message Date
Earle F. Philhower, III
803184c164
Update to latest Adafruit_TinyUSB (#639)
Fixes #582
2022-06-19 08:57:14 -07:00
Earle F. Philhower, III
c4623f4297
Disable Wire slave interrupt on ::end (#621)
Fixes #620
2022-06-10 11:42:04 -07:00
Earle F. Philhower, III
10b869ef30
Fix XIAO RP2040, allow swapping HW units 0/1 (#606)
Add plumbing to allow `Wire`, `Serial1`, `SPI1` to map to the 2nd
hardware unit for devices where the PCB layout only brings out the
2nd port.

Fix the Seeedstudio XAIO pins

Fixes #594
2022-06-04 21:37:28 -07:00
Earle F. Philhower, III
24583494c6
Fix Wire::available() when ::requestFrom fails (#604)
Avoids returning 2^32 bytes in the case of a requestFrom read fails
due to timeout.
2022-06-01 17:58:54 -07:00
Earle F. Philhower, III
a3a5abac23
Fix Wire I2C restart handling (#586)
Fixes #585

On an I2C bus restart, call the onReceive callback and clear the buffer.

Thanks to @DWiskow for the debug and patch!
2022-05-19 16:00:52 -07:00
Earle F. Philhower, III
07500e89db
Rewrite I2S from scratch, add I2S input support (#569)
Rewrite the I2S code from scratch to eliminate the dependence on the
pico-extras implementation and to support I2S input as well.

8-bit, 16-bit, 24-bit, and 32-bit words are supported.

Multiple I2S ports are allowed (theoretically up to 6 because
2 DMA channels are required per port).

I2S input and I2S output are supported.

Add input example

Fixes #535
Fixes #99
Fixes #562
2022-05-04 18:43:27 -07:00
ogatatsu
55394a7dcd
Fix compile error when configSUPPORT_STATIC_ALLOCATION is set to 1 (#564) (#566) 2022-04-30 19:07:21 -07:00
Earle F. Philhower, III
cfc91804c8
Fix memory corruption introducted in FreeRTOS port (#556)
To remove compiler warning the valid core macro was modified to only check
that the core passed in was < # of total cores.  Unfortunately there are
parts of the FreeRTOS code where the passed in core # is -1.  The upstream
catches this and returns FALSE, but my hacked version returned TRUE.  This
caused interesting memory corruption errors and crashes when the
current task block[-1] was updated.

Undo the change and fix the 1 spot where a warning happens instead.

Undo the forced compiler -O0 for port.c, it was only masking the fault.
2022-04-27 09:42:15 -07:00
Earle F. Philhower, III
88d213a30b
Additional FreeRTOS adjustments (#555)
Use low power WFE when idle.

Set PORT.C to built `-O0` always because it seems to occasinally end
up with interrupts disabled in task code, causing the SYSTICK never to
fire and killing task switching.

No need for dynamic exceptions.  We don't move the execbase.
2022-04-27 03:53:07 -07:00
Earle F. Philhower, III
189b796499 More FreeRTOS ISR work 2022-04-25 19:11:38 -07:00
Andy2No
797abb5a7f
Update SimpleTone.ino (#552)
Adds code to define which pins are used, moving them from the defaults, which are the same as the only three analogue input pins, and adding comments to explain how to change them.

The original didn't give any clues about which pins were used, which isn't ideal for a beginner - it was necessary to look at the code for the library, to work that out.

The new code redundantly defines a pWS pin number (as pBCLK+1), which isn't used in the example, but is meant as a reminder to the person using it, of how to wire up WS.
2022-04-25 12:21:34 -07:00
Earle F. Philhower, III
ffff21a936
Update FreeRTOS library to avoid random crashes (#553) 2022-04-25 12:10:48 -07:00
Earle F. Philhower, III
bda630e419
Add FreeRTOS support thanks to @hfellner (#533)
Using all the work from @hfellner and others, add FreeRTOS
SMP support.

Allow idling cores through the FreeRTOS FIFO queue to
allow for file system and EEPROM support.

Make delay a weak function so FreeRTOS can override.

Add cycle count support under FreeRTOS using a PIO SM.

Use a task-based approach for handling the USB periodic work
instead of the IRQ-based one in the main core.

Set 8 prio levels so it fits in 3 bits nicely (0..7).
2022-04-24 20:59:57 -07:00
Earle F. Philhower, III
1c0133704e
Update to LittleFS 2.5 (#545) 2022-04-22 12:22:27 -07:00
Bodmer
5a0d67f1ac
PDM library: Update PIO and interrupt use (#496)
The PIO and state machine were hard wired, so this caused problems if they were not free. The approach used by the Servo library has been adopted so a free PIO and SM are searched.

The DMA_IRQ_0 was grabbed exclusively, but this conflicts with SPI DMA use. The interrupt is now shared, but has been allocated the highest possible priority.

Since the PDM PIO use is receive only, the PIO state machine RX FIFO's can be joined to reduce DMA interrupt load.
2022-02-20 13:20:43 -08:00
Earle F. Philhower, III
c4046602f0
Allow changing I2C clock speed while running (#459)
Fixes #458
2022-02-04 18:08:35 -08:00
Spegs21
36bb604d38
Update tinyusb 1.9.2 (#445) 2022-01-29 03:22:14 -08:00
Earle F. Philhower, III
a7035ab61e Rename SDFat directory for Adafruit compatibility
Fixes #416
2022-01-24 12:38:35 -08:00
Earle F. Philhower, III
2c97bffc54
Update to latest upstream LittleFS (#425)
Also clean up output in SpeedTest, make more human friendly
2022-01-19 18:09:40 -08:00
Earle F. Philhower, III
626b62c413
Update to latest upstream Keyboard/Mouse (#424)
Keyboard class now has support for non-en_US layouts, and documentation has
been added to the Mouse class.

Thanks to @rico0260 for letting me know about the update, and for the initial PR!
2022-01-19 17:46:31 -08:00
Earle F. Philhower, III
25b9ca821e
Only call Wire.onReceive if data is available (#423)
The Pico HW seems to generate an interrupt on the end of every I2C
write cycle, even if the slave address wasn't actually targeted.
This would cause the onReceive method to be called with a 0-len
parameter for every write on the I2C bus.

Now, only call onReceive if there is 1 or more bytes of data available.
2022-01-19 16:16:39 -08:00
Earle F. Philhower, III
d5ddf4cd7f
Move SdFat to master/head (#422)
SdFat used to point to unnamed commit in the ESP8266SdFat repo.
Master in that repo has now been moved to that commit, so make this
core use the master branch for sanity's sake.
2022-01-19 12:30:12 -08:00
Earle F. Philhower, III
464ee85884
Make Wire buffer default to 256 for MBED compatibility (#412)
Fixes #411
2022-01-05 12:14:34 -08:00
Earle F. Philhower, III
f46d7cc84f
Speed up SPI by not reinitting if the paramters are the same as before (#394)
Leave the SPI port initted after a transaction, and when a new one comes in
check if it is the same settings we're already running.  If so, do nothing.
If not, deinit and reinit.  In general the settings will be identical, so
this will speed things up massively.

Fixes #392
2021-12-27 12:25:12 -08:00
Earle F. Philhower, III
29756de336
Update to SDFat 2.1.1 with UTF-8 support (#343) 2021-11-30 17:06:58 -08:00
SirSydom
3585c58688
Reset the SDA and SCL pins to INPUT at Wire.end() to prevent multiple pins connected to I2C when changing pins (#302) 2021-09-03 08:40:18 -07:00
Earle F. Philhower, III
580970cd72
Use Stream::setTimeout to specify I2C TO (#263)
Use the existing Arduino Stream method of setTimeout to set the Wire
I2C timeout delay.

Fixes #260
2021-07-23 15:20:34 -07:00
Earle F. Philhower, III
c13bb1ec2b
Make multiple SDFS/LittleFS.begin calls noops (#262)
When LittleFS.begin() or SDFS.begin() is called after the filesystem is
already mounted, don't unmount/remount.  When an unmount happens, all old
Files become invalid (but the core doesn't know this), so you would end
up with random crashes in FS code.

Now, check for _mounted, and if so just return immediately from begin().
2021-07-23 14:16:57 -07:00
Earle F. Philhower, III
cb9931f3e8
Set available() to 0 when Wire.requestFrom fails (#259)
Wire::requestFrom() returns the number of bytes read from the slave.  In
the case of error, the slave can end up returning a very large integer
for PICO_GENERIC_ERROR which would then be used as the # of bytes read
causing crashes and errors.

Running TalkingToMyself without connecting the I2C ports would show
this behavior.

Now, when PICO_GENERIC_ERROR is returned, set the read-back buffer len
to 0 explicitly.
2021-07-21 18:59:24 -07:00
Ha Thach
3a9703fc20
Update tinyusb 1.3.0 (#228)
* update included tinyusb to 1.2.0

move tusb_config.h from core to library for more portability

* pump tinyusb

* update tinyusb to 1.3.0

* try to fix ci warning
2021-06-30 08:22:36 -07:00
Earle F. Philhower, III
03e740a511
Add CPU cycle counter accessors (#226)
Use the 24-bit SYSTICK peripheral, wrapped in logic to extend it to a
full 32 or 64bits.  W/o the wrapper, SYSTICK will wrap around in ~100ms.

Adds rp2040.getCycleCount() and rp2040.getCycleCount64()

Clean up the libpico build process as crt0.S from the pico-sdk should
be directly used.

Clean up the keywords file.
2021-06-28 20:53:40 -07:00
Earle F. Philhower, III
f299120798 Remove accidental debug message 2021-06-25 18:47:02 -07:00
Earle F. Philhower, III
aac8146f00 Clear I2C status on short slave reads
Fixes #222

The HW needs to have the TXC_ABRT flag cleared when a slave transmission is
cut short by the master, or else it will effectively break the I2C bus and
never recover.
2021-06-25 18:39:44 -07:00
Earle F. Philhower, III
35c974d4c0
Fix file creation on SD and SDFS (#216)
The O_CREAT/etc. flags on the Pico are a full 32-bits in size, but the
core was generating a flag for SdFat using an 8-bit type, so all the
O_CREAT, O_TRUNC, O_APPEND, etc. flags got cut off.

Fix the flag size.

Fixes #214
2021-06-19 12:15:11 -07:00
Earle F. Philhower, III
b02b9c4be8
Add PDM library for Arduino Nano RP2040 Connect (#213)
* Add PDM library for Arduino Nano RP2040 Connect

* No PDM test in CI, only works on Arduino Nano RP2040
2021-06-16 08:17:09 -07:00
Earle F. Philhower, III
bedfbda372
Clear PIO FIFOs when updating Tone and Servos (#206)
The PIO programs that generate tone() and Servo() use the TX FIFO to
receive updates to the period/duty cycle.

The original code would push into the FIFO (potentially blocking the
app if the FIFO was full) and generate at least one cycle of every
value written into the control.  Basically, the output would
lag the changes by 1 cycle or more (which could be 20ms+ on Servo).

Fix this by clearing any old, ungrabbed values from the FIFO before
sending a new one to the program.  Instead of a FIFO, there is
effectively now just a control register and updates will be immediate.

Update the Siren.ino example with delays because now the tone() calls
will not block and run 10x+ faster.
2021-06-11 12:27:48 -07:00
Earle F. Philhower, III
c65c4bfb4e
Allow continuous tone frequency changes (#186)
Fixes #121
Supersedes #185

Redo the PIO program to allow the tone generator on a pin to be updated
without interruption, at waveform boundaries.  This allows for things like
sirens or slurs to be implemented simply.

Use an alarm, not the PIO hardware, to manage time-limited tones().

Add a simple siren example.
2021-06-04 02:45:13 -07:00
Ha Thach
6431b8157b
Add tone music example (#185) 2021-06-04 02:39:04 -07:00
per1234
7d1e83b416
Use optimal bundled library names (#183)
When multiple libraries contain files matching an #include directive in the program, the Arduino build system must pick
one to use for compilation. Multiple factors are used in order to make an intelligent determination of which library is
best.

In order to enhance this determination, the closeness of match between the library.properties name value and the
filename in the #include directive is being added as one of those factors. This new factor is referred to as
"Library Name Priority".

Unfortunately, this change can result in platform bundled libraries which had previously been correctly correctly chosen
no longer being given priority over their equivalent standalone libraries, which may be incompatible or not optimized
for the platform's boards.

This priority inversion only occurs when all the following conditions are true:

- There is a standalone library installed which provides a header filename collision.
- The platform bundled library is architecture optimized (e.g., architectures=esp32).
- The standalone library is architecture compatible (architectures=*).
- The standalone library has equal "Folder Name Priority".
- The standalone library has better "Library Name Priority" (e.g., name=SD vs name=SD(ESP32) for a library with primary
  header file SD.h.

The fix is to simply give the platform bundled library a perfect "Library Name Priority".

Some platform bundled libraries were given a modified name as a workaround to a bug in the Arduino IDE's Library Manager
which caused Library Manager to always show the library as updatable under specific circumstances. That bug was fixed in
Arduino IDE 1.8.6, ~3 years ago.
2021-05-31 07:32:20 -07:00
Earle F. Philhower, III
fd685aac82
PANIC on attempting an invalid setXXX pin (#182)
Fixes #169

Trying to change pinout while running, or to an illegal configuration,
will now immediately panic() with an error message.  Such an attempt
is a pretty big problem since pinouts are hardware related/static.

Prior code would fail silently and return false, but nobody checked
the setXXX return values, anyway.
2021-05-29 10:50:13 -07:00
Earle F. Philhower, III
1fd0b0404d
Add TinyUSB include to all libs (#180)
Fixes #167

For Serial when selecting TinyUSB.  Can't include in the core because Arduino IDE
will not link in libraries called from the core.  Instead, add the header to all
the standard libraries in the hope it will still catch some user cases where they
use these libraries.

See https://github.com/earlephilhower/arduino-pico/issues/167#issuecomment-848622174
2021-05-28 19:23:19 -07:00
Limor "Ladyada" Fried
860b43b342
Two board variant definitions and a high speed SPI transfer function (#172) 2021-05-26 18:09:49 -07:00
Earle F. Philhower, III
8016a932f3
Add astyle format, boards.txt, and package check (#166)
Miscellaneous CI checks for code style, boards.txt update, and that all
referenced packages are available.
2021-05-24 15:01:03 -07:00
Earle F. Philhower, III
fd4f7bbf0b
Add TinyUSB examples to CI (#163) 2021-05-23 09:29:44 -07:00
Earle F. Philhower, III
83a32f1ba3
Add compilation to CI (#155)
Stolen from ESP8266, modified to run basic sanity compiles on the core.

Fix warnings identified by the new checks.
2021-05-22 02:58:57 -07:00
Earle F. Philhower, III
052331168e
Fix repo spelling issues (#152) 2021-05-19 18:03:12 -07:00
Earle F. Philhower, III
a0dac52e0e
Rationalize Adafruit Feather infra, update docs (#145)
Use same board.txt format as other Adafruit boards.
Add in quick note about the new USB stack to the docs.
2021-05-19 10:07:03 -07:00
Ha Thach
f8a2f38fe7
Port Adafruit_TinyUSB_Arduino lib (#127)
* initial tinyusb lib port

* add Adafruit_TinyUSB_Arduino as submodules

* add yield() to main loop

* sync with tinyusb lib latest

* add USB manufacturer and product

* fix typo in tinyusb lib

* sync with master

updating implementation

* Rationalize link stage command line

Make the build process less insane.

* clean up delay

* clean up platform and board

* update makeboards.py for generating usbstack menu

* update tinyusb lib to 1.0.0
2021-05-18 18:10:47 -07:00
Earle F. Philhower, III
af8b548e29
Add time support (time, gettimeofday, etc.) (#138) 2021-05-16 03:23:25 -07:00
Earle F. Philhower, III
d3c5039c2f Clean up USB includes and naming 2021-05-14 12:08:00 -07:00
Earle F. Philhower, III
4a8ac3d902
Add support for shared USB Serial, Keyboard, Mouse (#132)
Use a shared infrastructure based on TinyUSB, allow users to use sketches
with ported Arduino Keyboard and Mouse libraries.
2021-05-13 19:20:24 -07:00
Earle F. Philhower, III
70a30dc219
Add multicore safety, FIFO, update pico-sdk (#122)
Update pico-sdk to 1.1.2

Add methods to block the opposite core while doing flash updates.
Ensure opposite core is stopped in LittleFS and EEPROM while doing
flash updates.

Update documentation with new calls.
2021-05-06 19:57:21 -07:00
Earle F. Philhower, III
1815c45f92
Add multicore support with setup1/loop1 (#113)
Support running code on the second core by adding a setup1() and/or
a loop1() routine to a sketch.  These functions operate exactly like
the normal Arduino ones, and anything they call will be run on
the second core automatically.

Add a simple multicore example.
2021-04-24 11:40:29 -07:00
Earle F. Philhower, III
6e51516d6c
Set default pins for peripherals per datasheet (#103)
Using the official Raspberry Pi Pico datasheet and the Adafruit Feather
RP2040 schematic, set the default pins for peripherals to match.

Fixes #92
2021-04-16 10:23:43 -07:00
Earle F. Philhower, III
bbac9d4b96
Add full-fledged documentation, update I2S API (#80)
Last step before 1.0. Docs for readthedocs.io.

Update the I2S API to mimic others where `setXXX` is called before
`begin()` to set the GPIO pins used.
2021-04-06 08:01:45 -07:00
Earle F. Philhower, III
4e50fe866a
Add LittleFS, SD, and SDFS Filesystems and File:: interface (#49)
Pull in the ESP8266 File/Dir/etc. filesystem and port LittleFS
and SD/SDFS to the RP2040.

See https://arduino-esp8266.readthedocs.io/en/latest/filesystem.html
for more information
2021-04-02 17:46:12 -07:00
Earle F. Philhower, III
1eb48f724d
Add I2S output support and I2S class/library (#73)
Using the PIO-driven I2S from pico-extras, add I2S output support.

Be sure to `git submodule update --init` to get the new directories.
2021-04-02 16:21:36 -07:00
Scott Smith
ed29fc539c
Correct analogReadTemp KEYWORD (#75)
reference: cores/rp2040/wiring_analog.cpp:108:extern "C" float analogReadTemp()
2021-04-02 11:36:20 -07:00
Earle F. Philhower, III
c988c1c8a4 Add debug prints on error conditions to the core 2021-03-30 18:17:52 -07:00
Earle F. Philhower, III
96e31c640e
Add analogReadTemp() to get RP2040 core temp (#63) 2021-03-30 16:10:06 -07:00
Earle F. Philhower, III
1124455627 Add BOOTSEL, allowing BOOTSEL use as a button
Since every board has a bootsel button, allow end users to read its
state with a simple `if (BOOTSEL)`.  Uses code from the pico-examples.
2021-03-29 16:14:45 -07:00
Earle F. Philhower, III
4076bf85ab Fix INPUT_PULLUP/DOWN, I2C 0-len probes, timeout
Fix the drive logic for pullup and pulldown inputs.

Add a bitbanged I2C ACK checker for 0-byte I2C transfers (since the HW
doesn't support it).

Add a timeout on I2C reads and writes so they don't hang forever if a
device is not present.

Fixes #38
2021-03-27 19:50:31 -07:00
Earle F. Philhower, III
73336ddda3 Add I2C slave support and include a simple example
Also fix the initial pins for the 2nd I2C interface onboard.
2021-03-27 15:07:10 -07:00
Earle F. Philhower, III
b463825374 Rationalize pin selection using readable template
Use a constexpr template to calculate the valid pins for different IO
hardware.  This lets us have an easily readable list of pin numbers that
we can adjust/check.
2021-03-25 17:54:46 -07:00
Earle F. Philhower, III
c4bbccdead Add serialEvent support for USB, UART0, UART1 2021-03-25 12:42:05 -07:00
Earle F. Philhower, III
9976d638b0 Fix EEPROM::begin missing underscore
Added size validation to the EEPROM begin, but forgot to set the class
variable with the new adjusted size.
Fixes #10
2021-03-24 03:20:18 -07:00
Earle F. Philhower, III
6f915a901d Remove library warning in rp2040 dir 2021-03-21 11:27:37 -07:00
Earle F. Philhower, III
e78f833851 Use well known TwoWire class name
Allows Adafruit GFX libraries to be used
2021-03-20 15:18:38 -07:00
Earle F. Philhower, III
76430b3d7d Ensure Servo detach()es only on idle state
Avoid any short pulses which could cause servo twitches or damage by
adding a shutdown command to the PIO program and checking it's in that
safe part of the loop before detaching the servo.
2021-03-18 16:00:38 -07:00
Earle F. Philhower, III
ba0777e557 Add SPI debug dumps 2021-03-17 17:35:41 -07:00
Earle F. Philhower, III
6adb1a641c Initial debugging framework 2021-03-17 10:54:13 -07:00
Earle F. Philhower, III
c0a606510c Clean up SPI library info 2021-03-16 22:11:16 -07:00
Earle F. Philhower, III
4ea383c0d7 Clean up SPI API, pin selection logic 2021-03-16 22:07:06 -07:00
Earle F. Philhower, III
ca7a219ee9 Clean up SPI library, add info 2021-03-16 21:44:17 -07:00
Earle F. Philhower, III
9f25417036 Add working default Fade example 2021-03-16 18:12:50 -07:00
Earle F. Philhower, III
62508fa98c Use one program per PIO, not per SM. Add RP2040 utils 2021-03-16 16:57:22 -07:00
Earle F. Philhower, III
5ac0a175e1 Stop PIO PM on Servo detach 2021-03-16 09:26:45 -07:00
Earle F. Philhower, III
d4427f87ce Add Servo library support, driven by the PIO SMs 2021-03-15 20:11:10 -07:00
Earle F. Philhower, III
129e59ab3c Add EEPROM library, using last flash sector 2021-03-12 19:38:14 -08:00
Earle F. Philhower, III
f785f360a9 Fix and test I2C/Wire, works now 2021-03-12 17:39:57 -08:00
Earle F. Philhower, III
4924cd9d35 Add I2C master support library 2021-03-12 13:23:27 -08:00
Earle F. Philhower, III
b3dad2ba62 Cleanup, add licenses to all files 2021-03-05 22:09:05 -08:00
Earle F. Philhower, III
93d194b0ac Add hardware SPI support
SPI = spi0, SPI1 = spi1
2021-03-05 21:44:40 -08:00