Compare commits
18 commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
694368b2a1 | ||
|
|
a790623b8f | ||
| b39e9eb1db | |||
| 876dc42186 | |||
| 920ae98a6e | |||
|
|
e90ad5e8a8 | ||
| d46093e893 | |||
| fc0d5dec90 | |||
|
|
ab8f652df7 | ||
|
|
53c9426360 | ||
| 8ec9cf55e4 | |||
| 5226e40540 | |||
| 47d0787e32 | |||
|
|
87edec7486 | ||
| 2987d8f4a2 | |||
| d32c71a344 | |||
|
|
09a576e38d | ||
|
|
3a3b3895c8 |
332 changed files with 2793 additions and 10688 deletions
22
.github/workflows/pull-request.yml
vendored
22
.github/workflows/pull-request.yml
vendored
|
|
@ -10,7 +10,7 @@ jobs:
|
|||
|
||||
# Consistent style, spelling
|
||||
astyle:
|
||||
name: Spelling, Style, Boards, Package, PIO
|
||||
name: Spelling, Style, Boards, Package
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
|
|
@ -19,8 +19,13 @@ jobs:
|
|||
- name: Run codespell
|
||||
uses: codespell-project/actions-codespell@v2
|
||||
with:
|
||||
skip: ./ArduinoCore-API,./libraries/ESP8266SdFat,./libraries/Adafruit_TinyUSB_Arduino,./libraries/LittleFS/lib,./tools/pyserial,./pico-sdk,./.github,./docs/i2s.rst,./cores/rp2040/api,./libraries/FreeRTOS,./tools/libbearssl/bearssl,./include,./libraries/WiFi/examples/BearSSL_Server,./ota/uzlib,./libraries/http-parser/lib,./libraries/WebServer/examples/HelloServerBearSSL/HelloServerBearSSL.ino,./libraries/HTTPUpdateServer/examples/SecureBearSSLUpdater/SecureBearSSLUpdater.ino,./.git,./libraries/FatFS/lib/fatfs,./libraries/FatFS/src/diskio.h,./libraries/FatFS/src/ff.cpp,./libraries/FatFS/src/ffconf.h,./libraries/FatFS/src/ffsystem.cpp,./libraries/FatFS/src/ff.h,./libraries/lwIP_WINC1500/src/driver,./libraries/lwIP_WINC1500/src/common,./libraries/lwIP_WINC1500/src/bus_wrapper,./libraries/lwIP_WINC1500/src/spi_flash,./libraries/WiFi/examples/BearSSL_Validation/certs.h
|
||||
skip: ./ArduinoCore-API,./libraries/ESP8266SdFat,./libraries/Adafruit_TinyUSB_Arduino,./libraries/LittleFS/lib,./tools/pyserial,./pico-sdk,./.github,./docs/i2s.rst,./cores/rp2040/api,./libraries/FreeRTOS,./tools/libbearssl/bearssl,./include,./libraries/WiFi/examples/BearSSL_Server,./ota/uzlib,./libraries/http-parser/lib,./libraries/WebServer/examples/HelloServerBearSSL/HelloServerBearSSL.ino,./libraries/HTTPUpdateServer/examples/SecureBearSSLUpdater/SecureBearSSLUpdater.ino,./.git,./libraries/FatFS/lib/fatfs,./libraries/FatFS/src/diskio.h,./libraries/FatFS/src/ff.cpp,./libraries/FatFS/src/ffconf.h,./libraries/FatFS/src/ffsystem.cpp,./libraries/FatFS/src/ff.h,./libraries/lwIP_WINC1500/src/driver,./libraries/lwIP_WINC1500/src/common,./libraries/lwIP_WINC1500/src/bus_wrapper,./libraries/lwIP_WINC1500/src/spi_flash
|
||||
ignore_words_list: ser,dout,shiftIn,acount,froms
|
||||
- name: Get submodules for following tests
|
||||
run: git submodule update --init
|
||||
- name: Check package references
|
||||
run: |
|
||||
./tests/ci/pkgrefs_test.sh
|
||||
- name: Check boards.txt was not edited after makeboards.py
|
||||
run: |
|
||||
./tools/makeboards.py
|
||||
|
|
@ -33,15 +38,6 @@ jobs:
|
|||
./tests/restyle.sh
|
||||
# If anything changed, GIT should return an error and fail the test
|
||||
git diff --exit-code
|
||||
- name: Check compiled PIO files
|
||||
run: |
|
||||
(cd ./tools && ./get.py)
|
||||
./tools/makepio.py
|
||||
# If anything changed, GIT should return an error and fail the test
|
||||
git diff -w --exit-code
|
||||
- name: Check package references
|
||||
run: |
|
||||
./tests/ci/pkgrefs_test.sh
|
||||
|
||||
# Build all examples on linux (core and Arduino IDE)
|
||||
build-linux:
|
||||
|
|
@ -268,8 +264,8 @@ jobs:
|
|||
run: |
|
||||
python -m pip install --upgrade pip
|
||||
pip install --upgrade platformio
|
||||
rm -rf ~/.platformio/platforms/raspberrypi*
|
||||
pio pkg install --global --platform https://github.com/maxgerhardt/platform-raspberrypi.git
|
||||
pio pkg update --global --platform https://github.com/maxgerhardt/platform-raspberrypi.git
|
||||
pio pkg install --global --tool symlink://.
|
||||
cp -f /home/runner/work/arduino-pico/arduino-pico/tools/json/*.json /home/runner/.platformio/platforms/raspberrypi/boards/.
|
||||
- name: Build Multicore Example
|
||||
|
|
@ -325,8 +321,8 @@ jobs:
|
|||
run: |
|
||||
python -m pip install --upgrade pip
|
||||
pip install --upgrade platformio
|
||||
rm -rf ~/.platformio/platforms/raspberrypi*
|
||||
pio pkg install --global --platform https://github.com/maxgerhardt/platform-raspberrypi.git
|
||||
pio pkg update --global --platform https://github.com/maxgerhardt/platform-raspberrypi.git
|
||||
pio pkg install --global --tool symlink://.
|
||||
cp -f /home/runner/work/arduino-pico/arduino-pico/tools/json/*.json /home/runner/.platformio/platforms/raspberrypi/boards/.
|
||||
- name: Build Every Variant
|
||||
|
|
|
|||
5
.gitignore
vendored
5
.gitignore
vendored
|
|
@ -5,8 +5,5 @@ docs/_build
|
|||
ota/build
|
||||
ota/build-rp2350
|
||||
ota/build-rp2350-riscv
|
||||
tools/libpico/boot
|
||||
tools/libpico/build-rp2040
|
||||
tools/libpico/build-rp2350
|
||||
tools/libpico/build-rp2350-riscv
|
||||
tools/libpico/build
|
||||
platform.local.txt
|
||||
|
|
|
|||
6
.gitmodules
vendored
6
.gitmodules
vendored
|
|
@ -10,6 +10,9 @@
|
|||
[submodule "libraries/LittleFS/lib/littlefs"]
|
||||
path = libraries/LittleFS/lib/littlefs
|
||||
url = https://github.com/littlefs-project/littlefs.git
|
||||
[submodule "libraries/SdFat"]
|
||||
path = libraries/ESP8266SdFat
|
||||
url = https://github.com/earlephilhower/ESP8266SdFat.git
|
||||
[submodule "libraries/Keyboard"]
|
||||
path = libraries/HID_Keyboard
|
||||
url = https://github.com/earlephilhower/Keyboard.git
|
||||
|
|
@ -46,6 +49,3 @@
|
|||
[submodule "libraries/ESPHost"]
|
||||
path = libraries/ESPHost
|
||||
url = https://github.com/Networking-for-Arduino/ESPHost.git
|
||||
[submodule "libraries/SdFat"]
|
||||
path = libraries/SdFat
|
||||
url = https://github.com/greiman/SdFat.git
|
||||
|
|
|
|||
|
|
@ -1 +1 @@
|
|||
Subproject commit 82928635c893189343cf8eb78569f0c4136fded0
|
||||
Subproject commit ece6e68f29c6f406a4434659bcbcfe558baaa3a9
|
||||
10
README.md
10
README.md
|
|
@ -25,7 +25,6 @@ Read the [Contributing Guide](https://github.com/earlephilhower/arduino-pico/blo
|
|||
* Adafruit KB2040
|
||||
* Adafruit Macropad RP2040
|
||||
* Adafruit Metro RP2040
|
||||
* Adafruit Metro RP2350
|
||||
* Adafruit QTPy RP2040
|
||||
* Adafruit STEMMA Friend RP2040
|
||||
* Adafruit Trinkey RP2040 QT
|
||||
|
|
@ -69,21 +68,16 @@ Read the [Contributing Guide](https://github.com/earlephilhower/arduino-pico/blo
|
|||
* Melopero Cookie RP2040
|
||||
* Melopero Shake RP2040
|
||||
* METE HOCA Akana R1
|
||||
* Makerbase MKSTHR36
|
||||
* Makerbase MKSTHR42
|
||||
* MyMakers RP2040
|
||||
* Neko Systems BL2040 Mini
|
||||
* Newsan Archi
|
||||
* nullbits Bit-C PRO
|
||||
* Olimex Pico2XL
|
||||
* Olimex Pico2XXL
|
||||
* Olimex RP2040-Pico30
|
||||
* Pimoroni PGA2040
|
||||
* Pimoroni Pico Plus 2
|
||||
* Pimoroni Pico Plus 2W
|
||||
* Pimoroni Plasma2040
|
||||
* Pimoroni Plasma2350
|
||||
* Pimoroni Servo2040
|
||||
* Pimoroni Tiny2040
|
||||
* Pimoroni Tiny2350
|
||||
* Pintronix PinMax
|
||||
|
|
@ -98,13 +92,11 @@ Read the [Contributing Guide](https://github.com/earlephilhower/arduino-pico/blo
|
|||
* Solder Party RP2040 Stamp
|
||||
* Solder Party RP2350 Stamp
|
||||
* Solder Party RP2350 Stamp XL
|
||||
* SparkFun IoT RedBoard RP2350
|
||||
* SparkFun MicroMod RP2040
|
||||
* SparkFun ProMicro RP2040
|
||||
* SparkFun ProMicro RP2350
|
||||
* SparkFun Thing Plus RP2040
|
||||
* SparkFun Thing Plus RP2350
|
||||
* SparkFun XRP Controller
|
||||
* uPesy RP2040 DevKit
|
||||
* VCC-GND YD-RP2040
|
||||
* Viyalab Mizu RP2040
|
||||
|
|
@ -156,7 +148,7 @@ The RP2040 PIO state machines (SMs) are used to generate jitter-free:
|
|||
* I2S Input
|
||||
* I2S Output
|
||||
* Software UARTs (Serial ports)
|
||||
* Software SPIs
|
||||
|
||||
|
||||
# Installing via Arduino Boards Manager
|
||||
## Windows-specific Notes
|
||||
|
|
|
|||
6806
boards.txt
6806
boards.txt
File diff suppressed because it is too large
Load diff
|
|
@ -27,23 +27,10 @@
|
|||
#include "RP2040Version.h"
|
||||
#include "api/ArduinoAPI.h"
|
||||
#include "api/itoa.h" // ARM toolchain doesn't provide itoa etc, provide them
|
||||
#include <pico.h>
|
||||
#undef PICO_RP2350A // Set in the RP2350 SDK boards file, overridden in the variant pins_arduino.h
|
||||
#include <pins_arduino.h>
|
||||
#include <hardware/gpio.h> // Required for the port*Register macros
|
||||
#include "debug_internal.h"
|
||||
|
||||
// Chip sanity checking. SDK uses interesting way of separating 2350A from 2350B, see https://github.com/raspberrypi/pico-sdk/issues/2364
|
||||
#if (!defined(PICO_RP2040) && !defined(PICO_RP2350)) || defined(PICO_RP2040) && defined(PICO_RP2350)
|
||||
#error Invalid core definition. Either PICO_RP2040 or PICO_RP2350 must be defined.
|
||||
#endif
|
||||
#if defined(PICO_RP2350) && !defined(PICO_RP2350A)
|
||||
#error Invalid RP2350 definition. Need to set PICO_RP2350A=0/1 for A/B variant
|
||||
#endif
|
||||
#if defined(PICO_RP2350B)
|
||||
#error Do not define PICO_RP2350B. Use PICO_RP2350A=0 to indicate RP2350B. See the SDK for more details
|
||||
#endif
|
||||
|
||||
// Try and make the best of the old Arduino abs() macro. When in C++, use
|
||||
// the sane std::abs() call, but for C code use their macro since stdlib abs()
|
||||
// is int but their macro "works" for everything (with potential side effects)
|
||||
|
|
@ -123,7 +110,7 @@ extern bool __isFreeRTOS;
|
|||
#endif
|
||||
|
||||
#ifndef PGM_VOID_P
|
||||
#define PGM_VOID_P const void *
|
||||
#define PGM_VOID_P void *
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
|
@ -165,14 +152,10 @@ constexpr uint64_t __bitset(const int (&a)[N], size_t i = 0U) {
|
|||
#define PSRAM __attribute__((section("\".psram\"")))
|
||||
|
||||
// General GPIO/ADC layout info
|
||||
#if defined(PICO_RP2350) && !PICO_RP2350A
|
||||
#ifdef PICO_RP2350B
|
||||
#define __GPIOCNT 48
|
||||
#define __FIRSTANALOGGPIO 40
|
||||
#else
|
||||
#define __GPIOCNT 30
|
||||
#define __FIRSTANALOGGPIO 26
|
||||
#endif
|
||||
|
||||
#ifdef __cplusplus
|
||||
using namespace arduino;
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -20,21 +20,10 @@
|
|||
|
||||
#pragma once
|
||||
|
||||
/**
|
||||
@brief Wrapper class for polling the BOOTSEL button
|
||||
*/
|
||||
class __Bootsel {
|
||||
public:
|
||||
__Bootsel() { }
|
||||
/**
|
||||
@brief Get state of the BOOTSEL pin
|
||||
|
||||
@returns True if BOOTSEL pushed
|
||||
*/
|
||||
operator bool();
|
||||
};
|
||||
|
||||
/**
|
||||
@brief BOOTSEL accessor instance
|
||||
*/
|
||||
extern __Bootsel BOOTSEL;
|
||||
|
|
|
|||
|
|
@ -1,2 +1 @@
|
|||
#include "api/IPAddress.h"
|
||||
using arduino::IPAddress;
|
||||
|
|
|
|||
|
|
@ -33,6 +33,7 @@
|
|||
|
||||
static std::map<const pio_program_t *, int> __pioMap[PIOCNT];
|
||||
static bool __pioAllocated[PIOCNT];
|
||||
static bool __pioHighGPIO[PIOCNT];
|
||||
auto_init_mutex(_pioMutex);
|
||||
|
||||
PIOProgram::PIOProgram(const pio_program_t *pgm) {
|
||||
|
|
@ -53,16 +54,26 @@ bool PIOProgram::prepare(PIO *pio, int *sm, int *offset, int start, int cnt) {
|
|||
CoreMutex m(&_pioMutex);
|
||||
PIO pi[PIOCNT] = { PIOS };
|
||||
|
||||
uint gpioBaseNeeded = ((start + cnt) >= 32) ? 16 : 0;
|
||||
DEBUGV("PIOProgram %p: Searching for base=%d, pins %d-%d\n", _pgm, gpioBaseNeeded, start, start + cnt - 1);
|
||||
#if 0
|
||||
uint usm;
|
||||
uint uoff;
|
||||
auto ret = pio_claim_free_sm_and_add_program_for_gpio_range(_pgm, pio, &usm, &uoff, start, cnt, true);
|
||||
*sm = usm;
|
||||
*offset = uoff;
|
||||
DEBUGV("clain %d\n", ret);
|
||||
return ret;
|
||||
#endif
|
||||
|
||||
bool needsHigh = (start + cnt) >= 32;
|
||||
DEBUGV("PIOProgram %p: Searching for high=%d, pins %d-%d\n", _pgm, needsHigh ? 1 : 0, start, start + cnt - 1);
|
||||
|
||||
// If it's already loaded into PIO IRAM, try and allocate in that specific PIO
|
||||
for (int o = 0; o < PIOCNT; o++) {
|
||||
auto p = __pioMap[o].find(_pgm);
|
||||
if ((p != __pioMap[o].end()) && (pio_get_gpio_base(pio_get_instance(o)) == gpioBaseNeeded)) {
|
||||
if ((p != __pioMap[o].end()) && (__pioHighGPIO[o] == needsHigh)) {
|
||||
int idx = pio_claim_unused_sm(pi[o], false);
|
||||
if (idx >= 0) {
|
||||
DEBUGV("PIOProgram %p: Reusing IMEM ON PIO %p(base=%d) for pins %d-%d\n", _pgm, pi[o], pio_get_gpio_base(pio_get_instance(o)), start, start + cnt - 1);
|
||||
DEBUGV("PIOProgram %p: Reusing IMEM ON PIO %p(high=%d) for pins %d-%d\n", _pgm, pi[o], __pioHighGPIO[o] ? 1 : 0, start, start + cnt - 1);
|
||||
_pio = pi[o];
|
||||
_sm = idx;
|
||||
*pio = pi[o];
|
||||
|
|
@ -75,12 +86,12 @@ bool PIOProgram::prepare(PIO *pio, int *sm, int *offset, int start, int cnt) {
|
|||
|
||||
// Not in any PIO IRAM, so try and add
|
||||
for (int o = 0; o < PIOCNT; o++) {
|
||||
if (__pioAllocated[o] && (pio_get_gpio_base(pio_get_instance(o)) == gpioBaseNeeded)) {
|
||||
if (__pioAllocated[o] && (__pioHighGPIO[o] == needsHigh)) {
|
||||
DEBUGV("PIOProgram: Checking PIO %p\n", pi[o]);
|
||||
if (pio_can_add_program(pi[o], _pgm)) {
|
||||
int idx = pio_claim_unused_sm(pi[o], false);
|
||||
if (idx >= 0) {
|
||||
DEBUGV("PIOProgram %p: Adding IMEM ON PIO %p(base=%d) for pins %d-%d\n", _pgm, pi[o], pio_get_gpio_base(pio_get_instance(o)), start, start + cnt - 1);
|
||||
DEBUGV("PIOProgram %p: Adding IMEM ON PIO %p(high=%d) for pins %d-%d\n", _pgm, pi[o], __pioHighGPIO[o] ? 1 : 0, start, start + cnt - 1);
|
||||
int off = pio_add_program(pi[o], _pgm);
|
||||
__pioMap[o].insert({_pgm, off});
|
||||
_pio = pi[o];
|
||||
|
|
@ -112,7 +123,8 @@ bool PIOProgram::prepare(PIO *pio, int *sm, int *offset, int start, int cnt) {
|
|||
}
|
||||
assert(!__pioAllocated[o]);
|
||||
__pioAllocated[o] = true;
|
||||
DEBUGV("PIOProgram %p: Allocating new PIO %p(base=%d) for pins %d-%d\n", _pgm, pi[o], pio_get_gpio_base(pio_get_instance(o)), start, start + cnt - 1);
|
||||
__pioHighGPIO[o] = needsHigh;
|
||||
DEBUGV("PIOProgram %p: Allocating new PIO %p(high=%d) for pins %d-%d\n", _pgm, pi[o], __pioHighGPIO[o] ? 1 : 0, start, start + cnt - 1);
|
||||
__pioMap[o].insert({_pgm, off});
|
||||
_pio = pi[o];
|
||||
_sm = idx;
|
||||
|
|
|
|||
|
|
@ -182,16 +182,13 @@ extern "C" void loop1() __attribute__((weak));
|
|||
extern "C" bool core1_separate_stack;
|
||||
extern "C" uint32_t* core1_separate_stack_address;
|
||||
|
||||
/**
|
||||
@brief RP2040/RP2350 helper function for HW-specific features
|
||||
*/
|
||||
class RP2040 {
|
||||
public:
|
||||
RP2040() { /* noop */ }
|
||||
~RP2040() { /* noop */ }
|
||||
|
||||
void begin(int cpuid) {
|
||||
_epoch[cpuid] = 0;
|
||||
void begin() {
|
||||
_epoch = 0;
|
||||
#if !defined(__riscv) && !defined(__PROFILE)
|
||||
if (!__isFreeRTOS) {
|
||||
// Enable SYSTICK exception
|
||||
|
|
@ -200,70 +197,43 @@ public:
|
|||
systick_hw->rvr = 0x00FFFFFF;
|
||||
} else {
|
||||
#endif
|
||||
// Only start 1 instance of the PIO SM
|
||||
if (cpuid == 0) {
|
||||
int off = 0;
|
||||
_ccountPgm = new PIOProgram(&ccount_program);
|
||||
_ccountPgm->prepare(&_pio, &_sm, &off);
|
||||
ccount_program_init(_pio, _sm, off);
|
||||
pio_sm_set_enabled(_pio, _sm, true);
|
||||
}
|
||||
int off = 0;
|
||||
_ccountPgm = new PIOProgram(&ccount_program);
|
||||
_ccountPgm->prepare(&_pio, &_sm, &off);
|
||||
ccount_program_init(_pio, _sm, off);
|
||||
pio_sm_set_enabled(_pio, _sm, true);
|
||||
#if !defined(__riscv) && !defined(__PROFILE)
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
@brief Convert from microseconds to PIO clock cycles
|
||||
|
||||
@returns the PIO cycles for a given microsecond delay
|
||||
*/
|
||||
// Convert from microseconds to PIO clock cycles
|
||||
static int usToPIOCycles(int us) {
|
||||
// Parenthesis needed to guarantee order of operations to avoid 32bit overflow
|
||||
return (us * (clock_get_hz(clk_sys) / 1'000'000));
|
||||
}
|
||||
|
||||
/**
|
||||
@brief Gets the active CPU speed (may differ from F_CPU
|
||||
|
||||
@returns CPU frequency in Hz
|
||||
*/
|
||||
// Get current clock frequency
|
||||
static int f_cpu() {
|
||||
return clock_get_hz(clk_sys);
|
||||
}
|
||||
|
||||
/**
|
||||
@brief Get the core ID that is currently executing this code
|
||||
|
||||
@returns 0 for Core 0, 1 for Core 1
|
||||
*/
|
||||
// Get current CPU core number
|
||||
static int cpuid() {
|
||||
return sio_hw->cpuid;
|
||||
}
|
||||
|
||||
/**
|
||||
@brief CPU cycle counter epoch (24-bit cycle). For internal use
|
||||
*/
|
||||
volatile uint64_t _epoch[2] = {};
|
||||
/**
|
||||
@brief Get the count of CPU clock cycles since power on.
|
||||
|
||||
@details
|
||||
The 32-bit count will overflow every 4 billion cycles, so consider using ``getCycleCount64`` for
|
||||
longer measurements
|
||||
|
||||
@returns CPU clock cycles since power up
|
||||
*/
|
||||
// Get CPU cycle count. Needs to do magic to extens 24b HW to something longer
|
||||
volatile uint64_t _epoch = 0;
|
||||
inline uint32_t getCycleCount() {
|
||||
#if !defined(__riscv) && !defined(__PROFILE)
|
||||
// Get CPU cycle count. Needs to do magic to extend 24b HW to something longer
|
||||
if (!__isFreeRTOS) {
|
||||
uint32_t epoch;
|
||||
uint32_t ctr;
|
||||
do {
|
||||
epoch = (uint32_t)_epoch[sio_hw->cpuid];
|
||||
epoch = (uint32_t)_epoch;
|
||||
ctr = systick_hw->cvr;
|
||||
} while (epoch != (uint32_t)_epoch[sio_hw->cpuid]);
|
||||
} while (epoch != (uint32_t)_epoch);
|
||||
return epoch + (1 << 24) - ctr; /* CTR counts down from 1<<24-1 */
|
||||
} else {
|
||||
#endif
|
||||
|
|
@ -272,20 +242,16 @@ public:
|
|||
}
|
||||
#endif
|
||||
}
|
||||
/**
|
||||
@brief Get the count of CPU clock cycles since power on as a 64-bit quantrity
|
||||
|
||||
@returns CPU clock cycles since power up
|
||||
*/
|
||||
inline uint64_t getCycleCount64() {
|
||||
#if !defined(__riscv) && !defined(__PROFILE)
|
||||
if (!__isFreeRTOS) {
|
||||
uint64_t epoch;
|
||||
uint64_t ctr;
|
||||
do {
|
||||
epoch = _epoch[sio_hw->cpuid];
|
||||
epoch = _epoch;
|
||||
ctr = systick_hw->cvr;
|
||||
} while (epoch != _epoch[sio_hw->cpuid]);
|
||||
} while (epoch != _epoch);
|
||||
return epoch + (1LL << 24) - ctr;
|
||||
} else {
|
||||
#endif
|
||||
|
|
@ -295,53 +261,23 @@ public:
|
|||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
@brief Gets total unused heap (dynamic memory)
|
||||
|
||||
@details
|
||||
Note that the allocations of the size of the total free heap may fail due to fragmentation.
|
||||
For example, ``getFreeHeap`` can report 100KB available, but an allocation of 90KB may fail
|
||||
because there may not be a contiguous 90KB space available
|
||||
|
||||
@returns Free heap in bytes
|
||||
*/
|
||||
inline int getFreeHeap() {
|
||||
return getTotalHeap() - getUsedHeap();
|
||||
}
|
||||
|
||||
/**
|
||||
@brief Gets total used heap (dynamic memory)
|
||||
|
||||
@returns Used heap in bytes
|
||||
*/
|
||||
inline int getUsedHeap() {
|
||||
struct mallinfo m = mallinfo();
|
||||
return m.uordblks;
|
||||
}
|
||||
|
||||
/**
|
||||
@brief Gets total heap (dynamic memory) compiled into the program
|
||||
|
||||
@returns Total heap size in bytes
|
||||
*/
|
||||
inline int getTotalHeap() {
|
||||
return &__StackLimit - &__bss_end__;
|
||||
}
|
||||
|
||||
/**
|
||||
@brief On the RP2350, returns the amount of heap (dynamic memory) available in PSRAM
|
||||
|
||||
@returns Total free heap in PSRAM, or 0 if no PSRAM present
|
||||
*/
|
||||
inline int getFreePSRAMHeap() {
|
||||
return getTotalPSRAMHeap() - getUsedPSRAMHeap();
|
||||
}
|
||||
|
||||
/**
|
||||
@brief On the RP2350, returns the total amount of PSRAM heap (dynamic memory) used
|
||||
|
||||
@returns Bytes used in PSRAM, or 0 if no PSRAM present
|
||||
*/
|
||||
inline int getUsedPSRAMHeap() {
|
||||
#if defined(RP2350_PSRAM_CS)
|
||||
extern size_t __psram_total_used();
|
||||
|
|
@ -351,11 +287,6 @@ public:
|
|||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
@brief On the RP2350, gets total heap (dynamic memory) compiled into the program
|
||||
|
||||
@returns Total PSRAM heap size in bytes, or 0 if no PSRAM present
|
||||
*/
|
||||
inline int getTotalPSRAMHeap() {
|
||||
#if defined(RP2350_PSRAM_CS)
|
||||
extern size_t __psram_total_space();
|
||||
|
|
@ -365,11 +296,6 @@ public:
|
|||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
@brief Gets the current stack pointer in a ARM/RISC-V safe manner
|
||||
|
||||
@returns Current SP
|
||||
*/
|
||||
inline uint32_t getStackPointer() {
|
||||
uint32_t *sp;
|
||||
#if defined(__riscv)
|
||||
|
|
@ -380,14 +306,6 @@ public:
|
|||
return (uint32_t)sp;
|
||||
}
|
||||
|
||||
/**
|
||||
@brief Calculates approximately how much stack space is still available for the running core. Handles multiprocessing and separate stacks.
|
||||
|
||||
@details
|
||||
Not valid in FreeRTOS. Use the FreeRTOS internal functions to access this information.
|
||||
|
||||
@returns Approximation of the amount of stack available for use on the specific core
|
||||
*/
|
||||
inline int getFreeStack() {
|
||||
const unsigned int sp = getStackPointer();
|
||||
uint32_t ref = 0x20040000;
|
||||
|
|
@ -401,11 +319,6 @@ public:
|
|||
return sp - ref;
|
||||
}
|
||||
|
||||
/**
|
||||
@brief On the RP2350, gets the size of attached PSRAM
|
||||
|
||||
@returns PSRAM size in bytes, or 0 if no PSRAM present
|
||||
*/
|
||||
inline size_t getPSRAMSize() {
|
||||
#if defined(RP2350_PSRAM_CS)
|
||||
extern size_t __psram_size;
|
||||
|
|
@ -415,48 +328,20 @@ public:
|
|||
#endif
|
||||
}
|
||||
|
||||
/**
|
||||
@brief Freezes the other core in a flash-write-safe state. Not generally needed by applications
|
||||
|
||||
@details
|
||||
When the external flash chip is erasing or writing, the Pico cannot fetch instructions from it.
|
||||
In this case both the core doing the writing and the other core (if active) need to run from a
|
||||
routine that's contained in RAM. This call forces the other core into a tight, RAM-based loop
|
||||
safe for this operation. When flash erase/write is completed, ``resumeOtherCore`` to return
|
||||
it to operation.
|
||||
|
||||
Be sure to disable any interrupts or task switches before calling to avoid deadlocks.
|
||||
|
||||
If the second core is not started, this is a no-op.
|
||||
*/
|
||||
void idleOtherCore() {
|
||||
fifo.idleOtherCore();
|
||||
}
|
||||
|
||||
/**
|
||||
@brief Resumes normal operation of the other core
|
||||
*/
|
||||
void resumeOtherCore() {
|
||||
fifo.resumeOtherCore();
|
||||
}
|
||||
|
||||
/**
|
||||
@brief Hard resets the 2nd core (CORE1).
|
||||
|
||||
@details
|
||||
Because core1 will restart with the heap and global variables not in the same state as
|
||||
power-on, this call may not work as desired and a full CPU reset may be necessary in
|
||||
certain cases.
|
||||
*/
|
||||
void restartCore1() {
|
||||
multicore_reset_core1();
|
||||
fifo.clear();
|
||||
multicore_launch_core1(main1);
|
||||
}
|
||||
|
||||
/**
|
||||
@brief Warm-reboots the chip in normal mode
|
||||
*/
|
||||
void reboot() {
|
||||
watchdog_reboot(0, 0, 10);
|
||||
while (1) {
|
||||
|
|
@ -464,16 +349,10 @@ public:
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
@brief Warm-reboots the chip in normal mode
|
||||
*/
|
||||
inline void restart() {
|
||||
reboot();
|
||||
}
|
||||
|
||||
/**
|
||||
@brief Warm-reboots the chip into the USB bootloader mode
|
||||
*/
|
||||
inline void rebootToBootloader() {
|
||||
reset_usb_boot(0, 0);
|
||||
while (1) {
|
||||
|
|
@ -485,32 +364,16 @@ public:
|
|||
static void enableDoubleResetBootloader();
|
||||
#endif
|
||||
|
||||
/**
|
||||
@brief Starts the hardware watchdog timer. The CPU will reset if the watchdog is not fed every delay_ms
|
||||
|
||||
@param [in] delay_ms Milliseconds without a wdt_reset before rebooting
|
||||
*/
|
||||
void wdt_begin(uint32_t delay_ms) {
|
||||
watchdog_enable(delay_ms, 1);
|
||||
}
|
||||
|
||||
/**
|
||||
@brief Feeds the watchdog timer, resetting it for another delay_ms countdown
|
||||
*/
|
||||
void wdt_reset() {
|
||||
watchdog_update();
|
||||
}
|
||||
|
||||
/**
|
||||
@brief Best-effort reasons for chip reset
|
||||
*/
|
||||
enum resetReason_t {UNKNOWN_RESET, PWRON_RESET, RUN_PIN_RESET, SOFT_RESET, WDT_RESET, DEBUG_RESET, GLITCH_RESET, BROWNOUT_RESET};
|
||||
|
||||
/**
|
||||
@brief Attempts to determine the reason for the last chip reset. May not always be able to determine accurately
|
||||
|
||||
@returns Reason for reset
|
||||
*/
|
||||
resetReason_t getResetReason(void) {
|
||||
io_rw_32 *WD_reason_reg = (io_rw_32 *)(WATCHDOG_BASE + WATCHDOG_REASON_OFFSET);
|
||||
|
||||
|
|
@ -564,10 +427,6 @@ public:
|
|||
return UNKNOWN_RESET;
|
||||
}
|
||||
|
||||
/**
|
||||
@brief Get unique ID string for the running board
|
||||
@returns String with the unique board ID as determined by the SDK
|
||||
*/
|
||||
const char *getChipID() {
|
||||
static char id[2 * PICO_UNIQUE_BOARD_ID_SIZE_BYTES + 1] = { 0 };
|
||||
if (!id[0]) {
|
||||
|
|
@ -578,17 +437,6 @@ public:
|
|||
|
||||
#pragma GCC push_options
|
||||
#pragma GCC optimize ("Os")
|
||||
/**
|
||||
@brief Perform a memcpy using a DMA engine for speed
|
||||
|
||||
@details
|
||||
Uses the DMA to copy to and from RAM. Only works on 4-byte aligned, 4-byte multiple length
|
||||
sources and destination (i.e. word-aligned, word-length). Falls back to normal memcpy otherwise.
|
||||
|
||||
@param [out] dest Memcpy destination, 4-byte aligned
|
||||
@param [in] src Memcpy source, 4-byte aligned
|
||||
@param [in] n Count in bytes to transfer (should be a multiple of 4 bytes)
|
||||
*/
|
||||
void *memcpyDMA(void *dest, const void *src, size_t n) {
|
||||
// Allocate a DMA channel on 1st call, reuse it every call after
|
||||
if (memcpyDMAChannel < 1) {
|
||||
|
|
@ -617,32 +465,14 @@ public:
|
|||
}
|
||||
#pragma GCC pop_options
|
||||
|
||||
/**
|
||||
@brief Multicore communications FIFO
|
||||
*/
|
||||
// Multicore comms FIFO
|
||||
_MFIFO fifo;
|
||||
|
||||
|
||||
/**
|
||||
@brief Return a 32-bit from the hardware random number generator
|
||||
|
||||
@returns Random value using appropriate hardware (RP2350 has true RNG, RP2040 has a less true RNG method)
|
||||
*/
|
||||
uint32_t hwrand32() {
|
||||
return get_rand_32();
|
||||
}
|
||||
|
||||
/**
|
||||
@brief Determines if code is running on a Pico or a PicoW
|
||||
|
||||
@details
|
||||
Code compiled for the RP2040 PicoW can run on the RP2040 Pico. This call lets an application
|
||||
identify if the current device is really a Pico or PicoW and handle appropriately. For
|
||||
the RP2350, this runtime detection is not available and the call returns whether it was
|
||||
compiled for the CYW43 WiFi driver
|
||||
|
||||
@returns True if running on a PicoW board with CYW43 WiFi chip.
|
||||
*/
|
||||
bool isPicoW() {
|
||||
#if !defined(PICO_CYW43_SUPPORTED)
|
||||
return false;
|
||||
|
|
@ -669,8 +499,8 @@ public:
|
|||
|
||||
|
||||
private:
|
||||
static void __no_inline_not_in_flash_func(_SystickHandler)() {
|
||||
rp2040._epoch[sio_hw->cpuid] += 1LL << 24;
|
||||
static void _SystickHandler() {
|
||||
rp2040._epoch += 1LL << 24;
|
||||
}
|
||||
PIO _pio;
|
||||
int _sm;
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
#pragma once
|
||||
#define ARDUINO_PICO_MAJOR 4
|
||||
#define ARDUINO_PICO_MINOR 5
|
||||
#define ARDUINO_PICO_REVISION 4
|
||||
#define ARDUINO_PICO_VERSION_STR "4.5.4"
|
||||
#define ARDUINO_PICO_MINOR 4
|
||||
#define ARDUINO_PICO_REVISION 1
|
||||
#define ARDUINO_PICO_VERSION_STR "4.4.1"
|
||||
|
|
|
|||
|
|
@ -24,9 +24,7 @@
|
|||
|
||||
// Input/output will be handled by OpenOCD
|
||||
|
||||
/**
|
||||
@brief Semihosting host API opcodes, from https://developer.arm.com/documentation/dui0471/g/Semihosting/Semihosting-operations?lang=en
|
||||
*/
|
||||
// From https://developer.arm.com/documentation/dui0471/g/Semihosting/Semihosting-operations?lang=en
|
||||
typedef enum {
|
||||
SEMIHOST_SYS_CLOSE = 0x02,
|
||||
SEMIHOST_SYS_CLOCK = 0x10,
|
||||
|
|
@ -54,13 +52,7 @@ typedef enum {
|
|||
|
||||
#ifdef __arm__
|
||||
|
||||
/**
|
||||
@brief Execute a semihosted request, from https://github.com/ErichStyger/mcuoneclipse/blob/master/Examples/MCUXpresso/FRDM-K22F/FRDM-K22F_Semihosting/source/McuSemihost.c
|
||||
|
||||
@param [in] reason Opcode to execute
|
||||
@param [in] arg Any arguments for the opcode
|
||||
@returns Result of operation
|
||||
*/
|
||||
// From https://github.com/ErichStyger/mcuoneclipse/blob/master/Examples/MCUXpresso/FRDM-K22F/FRDM-K22F_Semihosting/source/McuSemihost.c
|
||||
static inline int __attribute__((always_inline)) Semihost(int reason, void *arg) {
|
||||
int value;
|
||||
__asm volatile(
|
||||
|
|
@ -77,13 +69,7 @@ static inline int __attribute__((always_inline)) Semihost(int reason, void *arg)
|
|||
}
|
||||
#else
|
||||
|
||||
/**
|
||||
@brief Execute a semihosted request, from https://groups.google.com/a/groups.riscv.org/g/sw-dev/c/n-5VQ9PHZ4w/m/KbzH5t9MBgAJ
|
||||
|
||||
@param [in] reason Opcode to execute
|
||||
@param [in] argPack Any arguments for the opcode
|
||||
@returns Result of operation
|
||||
*/
|
||||
// https://groups.google.com/a/groups.riscv.org/g/sw-dev/c/n-5VQ9PHZ4w/m/KbzH5t9MBgAJ
|
||||
static inline int __attribute__((always_inline)) Semihost(int reason, void *argPack) {
|
||||
register int value asm("a0") = reason;
|
||||
register void *ptr asm("a1") = argPack;
|
||||
|
|
|
|||
|
|
@ -68,10 +68,13 @@ static PIOProgram *_getRxProgram(int bits) {
|
|||
}
|
||||
// ------------------------------------------------------------------------
|
||||
|
||||
static int __not_in_flash_func(_parity)(int data) {
|
||||
data ^= data >> 4;
|
||||
data &= 0xf;
|
||||
return (0x6996 >> data) & 1;
|
||||
// TODO - this works, but there must be a faster/better way...
|
||||
static int _parity(int bits, int data) {
|
||||
int p = 0;
|
||||
for (int b = 0; b < bits; b++) {
|
||||
p ^= (data & (1 << b)) ? 1 : 0;
|
||||
}
|
||||
return p;
|
||||
}
|
||||
|
||||
// We need to cache generated SerialPIOs so we can add data to them from
|
||||
|
|
@ -95,16 +98,20 @@ void __not_in_flash_func(SerialPIO::_handleIRQ)() {
|
|||
}
|
||||
while (!pio_sm_is_rx_fifo_empty(_rxPIO, _rxSM)) {
|
||||
uint32_t decode = _rxPIO->rxf[_rxSM];
|
||||
uint32_t val = decode >> (32 - _rxBits - 1);
|
||||
decode >>= 33 - _rxBits;
|
||||
uint32_t val = 0;
|
||||
for (int b = 0; b < _bits + 1; b++) {
|
||||
val |= (decode & (1 << (b * 2))) ? 1 << b : 0;
|
||||
}
|
||||
if (_parity == UART_PARITY_EVEN) {
|
||||
int p = ::_parity(val);
|
||||
int p = ::_parity(_bits, val);
|
||||
int r = (val & (1 << _bits)) ? 1 : 0;
|
||||
if (p != r) {
|
||||
// TODO - parity error
|
||||
continue;
|
||||
}
|
||||
} else if (_parity == UART_PARITY_ODD) {
|
||||
int p = ::_parity(val);
|
||||
int p = ::_parity(_bits, val);
|
||||
int r = (val & (1 << _bits)) ? 1 : 0;
|
||||
if (p == r) {
|
||||
// TODO - parity error
|
||||
|
|
@ -227,7 +234,7 @@ void SerialPIO::begin(unsigned long baud, uint16_t config) {
|
|||
_writer = 0;
|
||||
_reader = 0;
|
||||
|
||||
_rxBits = _bits + (_parity != UART_PARITY_NONE ? 1 : 0);
|
||||
_rxBits = 2 * (_bits + _stop + (_parity != UART_PARITY_NONE ? 1 : 0) + 1) - 1;
|
||||
_rxPgm = _getRxProgram(_rxBits);
|
||||
int off;
|
||||
if (!_rxPgm->prepare(&_rxPIO, &_rxSM, &off, _rx, 1)) {
|
||||
|
|
@ -242,7 +249,7 @@ void SerialPIO::begin(unsigned long baud, uint16_t config) {
|
|||
pio_sm_clear_fifos(_rxPIO, _rxSM); // Remove any existing data
|
||||
|
||||
// Put phase divider into OSR w/o using add'l program memory
|
||||
pio_sm_put_blocking(_rxPIO, _rxSM, clock_get_hz(clk_sys) / (_baud * 2) - 3);
|
||||
pio_sm_put_blocking(_rxPIO, _rxSM, clock_get_hz(clk_sys) / (_baud * 2) - 7 /* insns in PIO halfbit loop */);
|
||||
pio_sm_exec(_rxPIO, _rxSM, pio_encode_pull(false, false));
|
||||
|
||||
// Join the TX FIFO to the RX one now that we don't need it
|
||||
|
|
@ -371,10 +378,10 @@ size_t SerialPIO::write(uint8_t c) {
|
|||
if (_parity == UART_PARITY_NONE) {
|
||||
val |= 7 << _bits; // Set 2 stop bits, the HW will only transmit the required number
|
||||
} else if (_parity == UART_PARITY_EVEN) {
|
||||
val |= ::_parity(c) << _bits;
|
||||
val |= ::_parity(_bits, c) << _bits;
|
||||
val |= 7 << (_bits + 1);
|
||||
} else {
|
||||
val |= (1 ^ ::_parity(c)) << _bits;
|
||||
val |= (1 ^ ::_parity(_bits, c)) << _bits;
|
||||
val |= 7 << (_bits + 1);
|
||||
}
|
||||
val <<= 1; // Start bit = low
|
||||
|
|
|
|||
|
|
@ -29,7 +29,7 @@
|
|||
|
||||
extern "C" typedef struct uart_inst uart_inst_t;
|
||||
|
||||
class SerialPIO : public arduino::HardwareSerial {
|
||||
class SerialPIO : public HardwareSerial {
|
||||
public:
|
||||
static const pin_size_t NOPIN = 0xff; // Use in constructor to disable RX or TX unit
|
||||
SerialPIO(pin_size_t tx, pin_size_t rx, size_t fifoSize = 32);
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@
|
|||
#include "Arduino.h"
|
||||
#include "api/HardwareSerial.h"
|
||||
|
||||
class SerialSemiClass : public arduino::HardwareSerial {
|
||||
class SerialSemiClass : public HardwareSerial {
|
||||
public:
|
||||
SerialSemiClass() {
|
||||
/* noop */
|
||||
|
|
|
|||
|
|
@ -32,20 +32,15 @@ extern void serialEvent1() __attribute__((weak));
|
|||
extern void serialEvent2() __attribute__((weak));
|
||||
|
||||
bool SerialUART::setRX(pin_size_t pin) {
|
||||
#if defined(PICO_RP2350) && !PICO_RP2350A // RP2350B
|
||||
constexpr uint64_t valid[2] = { __bitset({1, 3, 13, 15, 17, 19, 29, 31, 33, 35, 45, 47}) /* UART0 */,
|
||||
__bitset({5, 7, 9, 11, 21, 23, 25, 27, 37, 39, 41, 43}) /* UART1 */
|
||||
};
|
||||
#elif defined(PICO_RP2350)
|
||||
constexpr uint64_t valid[2] = { __bitset({1, 3, 13, 15, 17, 19, 29}) /* UART0 */,
|
||||
__bitset({5, 7, 9, 11, 21, 23, 25, 27}) /* UART1 */
|
||||
#ifdef PICO_RP2350B
|
||||
constexpr uint64_t valid[2] = { __bitset({1, 13, 17, 29, 33, 45}) /* UART0 */,
|
||||
__bitset({5, 9, 21, 25, 37, 41}) /* UART1 */
|
||||
};
|
||||
#else
|
||||
constexpr uint64_t valid[2] = { __bitset({1, 13, 17, 29}) /* UART0 */,
|
||||
__bitset({5, 9, 21, 25}) /* UART1 */
|
||||
};
|
||||
#endif
|
||||
|
||||
if ((!_running) && ((1LL << pin) & valid[uart_get_index(_uart)])) {
|
||||
_rx = pin;
|
||||
return true;
|
||||
|
|
@ -64,13 +59,9 @@ bool SerialUART::setRX(pin_size_t pin) {
|
|||
}
|
||||
|
||||
bool SerialUART::setTX(pin_size_t pin) {
|
||||
#if defined(PICO_RP2350) && !PICO_RP2350A // RP2350B
|
||||
constexpr uint64_t valid[2] = { __bitset({0, 2, 12, 14, 16, 18, 28, 30, 32, 34, 44, 46}) /* UART0 */,
|
||||
__bitset({4, 6, 8, 10, 20, 22, 24, 26, 36, 38, 40, 42}) /* UART1 */
|
||||
};
|
||||
#elif defined(PICO_RP2350)
|
||||
constexpr uint64_t valid[2] = { __bitset({0, 2, 12, 14, 16, 18, 28}) /* UART0 */,
|
||||
__bitset({4, 6, 8, 10, 20, 22, 24, 26}) /* UART1 */
|
||||
#ifdef PICO_RP2350B
|
||||
constexpr uint64_t valid[2] = { __bitset({0, 12, 16, 28, 32, 44}) /* UART0 */,
|
||||
__bitset({4, 8, 20, 24, 36, 40}) /* UART1 */
|
||||
};
|
||||
#else
|
||||
constexpr uint64_t valid[2] = { __bitset({0, 12, 16, 28}) /* UART0 */,
|
||||
|
|
@ -95,7 +86,7 @@ bool SerialUART::setTX(pin_size_t pin) {
|
|||
}
|
||||
|
||||
bool SerialUART::setRTS(pin_size_t pin) {
|
||||
#if defined(PICO_RP2350) && !PICO_RP2350A // RP2350B
|
||||
#ifdef PICO_RP2350B
|
||||
constexpr uint64_t valid[2] = { __bitset({3, 15, 19, 31, 35, 47}) /* UART0 */,
|
||||
__bitset({7, 11, 23, 27, 39, 43}) /* UART1 */
|
||||
};
|
||||
|
|
@ -122,7 +113,7 @@ bool SerialUART::setRTS(pin_size_t pin) {
|
|||
}
|
||||
|
||||
bool SerialUART::setCTS(pin_size_t pin) {
|
||||
#if defined(PICO_RP2350) && !PICO_RP2350A // RP2350B
|
||||
#ifdef PICO_RP2350B
|
||||
constexpr uint64_t valid[2] = { __bitset({2, 14, 18, 30, 34, 46}) /* UART0 */,
|
||||
__bitset({6, 10, 22, 26, 38, 42}) /* UART1 */
|
||||
};
|
||||
|
|
@ -179,41 +170,6 @@ SerialUART::SerialUART(uart_inst_t *uart, pin_size_t tx, pin_size_t rx, pin_size
|
|||
static void _uart0IRQ();
|
||||
static void _uart1IRQ();
|
||||
|
||||
// Does the selected TX/RX need UART_AUX function (rp2350)
|
||||
static gpio_function_t __gpioFunction(int pin) {
|
||||
switch (pin) {
|
||||
#if defined(PICO_RP2350) && !PICO_RP2350A
|
||||
case 2:
|
||||
case 3:
|
||||
case 6:
|
||||
case 7:
|
||||
case 10:
|
||||
case 11:
|
||||
case 14:
|
||||
case 15:
|
||||
case 18:
|
||||
case 19:
|
||||
case 22:
|
||||
case 23:
|
||||
case 26:
|
||||
case 27:
|
||||
case 30:
|
||||
case 31:
|
||||
case 34:
|
||||
case 35:
|
||||
case 38:
|
||||
case 39:
|
||||
case 42:
|
||||
case 43:
|
||||
case 46:
|
||||
case 47:
|
||||
return GPIO_FUNC_UART_AUX;
|
||||
#endif
|
||||
default:
|
||||
return GPIO_FUNC_UART;
|
||||
}
|
||||
}
|
||||
|
||||
void SerialUART::begin(unsigned long baud, uint16_t config) {
|
||||
if (_running) {
|
||||
end();
|
||||
|
|
@ -224,9 +180,9 @@ void SerialUART::begin(unsigned long baud, uint16_t config) {
|
|||
|
||||
_fcnTx = gpio_get_function(_tx);
|
||||
_fcnRx = gpio_get_function(_rx);
|
||||
gpio_set_function(_tx, __gpioFunction(_tx));
|
||||
gpio_set_function(_tx, GPIO_FUNC_UART);
|
||||
gpio_set_outover(_tx, _invertTX ? 1 : 0);
|
||||
gpio_set_function(_rx, __gpioFunction(_rx));
|
||||
gpio_set_function(_rx, GPIO_FUNC_UART);
|
||||
gpio_set_inover(_rx, _invertRX ? 1 : 0);
|
||||
if (_rts != UART_PIN_NOT_DEFINED) {
|
||||
_fcnRts = gpio_get_function(_rts);
|
||||
|
|
|
|||
|
|
@ -29,7 +29,7 @@
|
|||
extern "C" typedef struct uart_inst uart_inst_t;
|
||||
|
||||
#define UART_PIN_NOT_DEFINED (255u)
|
||||
class SerialUART : public arduino::HardwareSerial {
|
||||
class SerialUART : public HardwareSerial {
|
||||
public:
|
||||
SerialUART(uart_inst_t *uart, pin_size_t tx, pin_size_t rx, pin_size_t rts = UART_PIN_NOT_DEFINED, pin_size_t cts = UART_PIN_NOT_DEFINED);
|
||||
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@
|
|||
#include "api/HardwareSerial.h"
|
||||
#include <stdarg.h>
|
||||
|
||||
class SerialUSB : public arduino::HardwareSerial {
|
||||
class SerialUSB : public HardwareSerial {
|
||||
public:
|
||||
SerialUSB() { }
|
||||
void begin(unsigned long baud = 115200) override;
|
||||
|
|
|
|||
|
|
@ -22,18 +22,9 @@
|
|||
|
||||
#include "SerialPIO.h"
|
||||
|
||||
/**
|
||||
@brief Implements a UART port using PIO for input and output
|
||||
*/
|
||||
class SoftwareSerial : public SerialPIO {
|
||||
public:
|
||||
/**
|
||||
@brief Constructs a PIO-based UART
|
||||
|
||||
@param [in] rx GPIO for RX pin or -1 for transmit-only
|
||||
@param [in] tx GPIO for TX pin or -1 for receive-only
|
||||
@param [in] invert True to invert the receive and transmit lines
|
||||
*/
|
||||
// Note the rx/tx pins are swapped in PIO vs SWSerial
|
||||
SoftwareSerial(pin_size_t rx, pin_size_t tx, bool invert = false) : SerialPIO(tx, rx) {
|
||||
_invert = invert;
|
||||
}
|
||||
|
|
@ -41,37 +32,18 @@ public:
|
|||
~SoftwareSerial() {
|
||||
}
|
||||
|
||||
/**
|
||||
@brief Starts the PIO UART
|
||||
|
||||
@param [in] baud Serial bit rate
|
||||
*/
|
||||
virtual void begin(unsigned long baud = 115200) override {
|
||||
begin(baud, SERIAL_8N1);
|
||||
};
|
||||
|
||||
/**
|
||||
@brief Starts the PIO UART
|
||||
|
||||
@param [in] baud Serial bit rate
|
||||
@param [in] config Start/Stop/Len configuration (i.e. SERIAL_8N1 or SERIAL_7E2)
|
||||
*/
|
||||
void begin(unsigned long baud, uint16_t config) override {
|
||||
setInvertTX(_invert);
|
||||
setInvertRX(_invert);
|
||||
SerialPIO::begin(baud, config);
|
||||
}
|
||||
|
||||
/**
|
||||
@brief No-op on this core
|
||||
*/
|
||||
void listen() { /* noop */ }
|
||||
|
||||
/**
|
||||
@brief No-op on this core
|
||||
|
||||
@returns True always
|
||||
*/
|
||||
bool isListening() {
|
||||
return true;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -71,7 +71,10 @@ void tone(uint8_t pin, unsigned int frequency, unsigned long duration) {
|
|||
return; // Weird deadlock case
|
||||
}
|
||||
|
||||
unsigned int delay = (RP2040::f_cpu() + frequency) / (frequency * 2) - 3; // rounded
|
||||
int us = 1'000'000 / frequency / 2;
|
||||
if (us < 5) {
|
||||
us = 5;
|
||||
}
|
||||
auto entry = _toneMap.find(pin);
|
||||
Tone *newTone;
|
||||
if (entry == _toneMap.end()) {
|
||||
|
|
@ -96,7 +99,7 @@ void tone(uint8_t pin, unsigned int frequency, unsigned long duration) {
|
|||
tone2_program_init(newTone->pio, newTone->sm, newTone->off, pin);
|
||||
}
|
||||
pio_sm_clear_fifos(newTone->pio, newTone->sm); // Remove any old updates that haven't yet taken effect
|
||||
pio_sm_put_blocking(newTone->pio, newTone->sm, delay);
|
||||
pio_sm_put_blocking(newTone->pio, newTone->sm, RP2040::usToPIOCycles(us));
|
||||
pio_sm_exec(newTone->pio, newTone->sm, pio_encode_pull(false, false));
|
||||
pio_sm_exec(newTone->pio, newTone->sm, pio_encode_mov(pio_x, pio_osr));
|
||||
pio_sm_set_enabled(newTone->pio, newTone->sm, true);
|
||||
|
|
|
|||
|
|
@ -28,7 +28,7 @@ static const struct pio_program ccount_program = {
|
|||
.instructions = ccount_program_instructions,
|
||||
.length = 2,
|
||||
.origin = -1,
|
||||
.pio_version = ccount_pio_version,
|
||||
.pio_version = 0,
|
||||
#if PICO_PIO_VERSION > 0
|
||||
.used_gpio_ranges = 0x0
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -22,11 +22,7 @@
|
|||
#include "RP2040USB.h"
|
||||
#include <pico/stdlib.h>
|
||||
#include <pico/multicore.h>
|
||||
#include <hardware/vreg.h>
|
||||
#include <reent.h>
|
||||
#ifdef RP2350_PSRAM_CS
|
||||
#include "psram.h"
|
||||
#endif
|
||||
|
||||
RP2040 rp2040;
|
||||
extern "C" {
|
||||
|
|
@ -51,14 +47,9 @@ void initVariant() { }
|
|||
|
||||
// Optional 2nd core setup and loop
|
||||
bool core1_separate_stack __attribute__((weak)) = false;
|
||||
bool core1_disable_systick __attribute__((weak)) = false;
|
||||
extern void setup1() __attribute__((weak));
|
||||
extern void loop1() __attribute__((weak));
|
||||
extern "C" void main1() {
|
||||
if (!core1_disable_systick) {
|
||||
// Don't install the SYSTICK exception handler. rp2040.getCycleCount will not work properly on core1
|
||||
rp2040.begin(1);
|
||||
}
|
||||
rp2040.fifo.registerCore();
|
||||
if (setup1) {
|
||||
setup1();
|
||||
|
|
@ -89,41 +80,9 @@ static struct _reent *_impure_ptr1 = nullptr;
|
|||
|
||||
extern "C" int main() {
|
||||
#if (defined(PICO_RP2040) && (F_CPU != 125000000)) || (defined(PICO_RP2350) && (F_CPU != 150000000))
|
||||
|
||||
#if defined(PICO_RP2040)
|
||||
// From runtime_init_clocks() to bump up RP2040 V for 200Mhz+ operation
|
||||
if ((F_CPU > 133000000) && (vreg_get_voltage() < VREG_VOLTAGE_1_15)) {
|
||||
vreg_set_voltage(VREG_VOLTAGE_1_15);
|
||||
// wait for voltage to settle; must use CPU cycles as TIMER is not yet clocked correctly
|
||||
busy_wait_at_least_cycles((uint32_t)((SYS_CLK_VREG_VOLTAGE_AUTO_ADJUST_DELAY_US * (uint64_t)XOSC_HZ) / 1000000));
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(RP2350_PSRAM_CS) && (F_CPU > 150000000)
|
||||
// Need to increase the qmi divider before upping sysclk to ensure we keep the output sck w/in legal bounds
|
||||
psram_reinit_timing(F_CPU);
|
||||
// Per datasheet, need to do a dummy access and memory barrier before it takes effect
|
||||
extern uint8_t __psram_start__;
|
||||
volatile uint8_t *x = &__psram_start__;
|
||||
*x ^= 0xff;
|
||||
*x ^= 0xff;
|
||||
asm volatile("" ::: "memory");
|
||||
#endif
|
||||
|
||||
set_sys_clock_khz(F_CPU / 1000, true);
|
||||
|
||||
#if defined(RP2350_PSRAM_CS) && (F_CPU < 150000000)
|
||||
psram_reinit_timing();
|
||||
// Per datasheet, need to do a dummy access and memory barrier before it takes effect
|
||||
extern uint8_t __psram_start__;
|
||||
volatile uint8_t *x = &__psram_start__;
|
||||
*x ^= 0xff;
|
||||
*x ^= 0xff;
|
||||
asm volatile("" ::: "memory");
|
||||
#endif
|
||||
|
||||
#endif // over/underclock
|
||||
|
||||
// Let rest of core know if we're using FreeRTOS
|
||||
__isFreeRTOS = initFreeRTOS ? true : false;
|
||||
|
||||
|
|
@ -133,7 +92,7 @@ extern "C" int main() {
|
|||
_REENT_INIT_PTR(_impure_ptr1);
|
||||
}
|
||||
|
||||
rp2040.begin(0);
|
||||
rp2040.begin();
|
||||
|
||||
initVariant();
|
||||
|
||||
|
|
@ -244,10 +203,3 @@ void hexdump(const void* mem, uint32_t len, uint8_t cols) {
|
|||
}
|
||||
|
||||
const String emptyString = "";
|
||||
|
||||
extern "C" void __attribute__((__noreturn__)) __wrap___stack_chk_fail() {
|
||||
while (true) {
|
||||
panic("*** stack smashing detected ***: terminated\n");
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -73,25 +73,20 @@ static inline void pio_tx_program_init(PIO pio, uint sm, uint offset, uint pin_t
|
|||
; IN pin 0 and JMP pin are both mapped to the GPIO used as UART RX.
|
||||
|
||||
start:
|
||||
set x, 18 ; Preload bit counter...overwritten by the app
|
||||
set x, 18 ; Preload bit counter...we'll shift in the start bit and stop bit, and each bit will be double-recorded (to be fixed by RP2040 code)
|
||||
wait 0 pin 0 ; Stall until start bit is asserted
|
||||
|
||||
bitloop:
|
||||
; Delay until 1/2 way into the bit time
|
||||
mov y, osr
|
||||
wait_mid_start:
|
||||
jmp y-- wait_mid_start
|
||||
wait_half:
|
||||
jmp y-- wait_half
|
||||
|
||||
bitloop:
|
||||
mov y, osr
|
||||
bitloop1:
|
||||
jmp y-- bitloop1
|
||||
mov y, osr
|
||||
bitloop2:
|
||||
jmp y-- bitloop2
|
||||
|
||||
in pins, 1
|
||||
jmp x-- bitloop
|
||||
push
|
||||
; Read in the bit
|
||||
in pins, 1 ; Shift data bit into ISR
|
||||
jmp x-- bitloop ; Loop all bits
|
||||
|
||||
push ; Stuff it and wait for next start
|
||||
|
||||
% c-sdk {
|
||||
static inline void pio_rx_program_init(PIO pio, uint sm, uint offset, uint pin) {
|
||||
|
|
|
|||
|
|
@ -32,7 +32,7 @@ static const struct pio_program pio_tx_program = {
|
|||
.instructions = pio_tx_program_instructions,
|
||||
.length = 6,
|
||||
.origin = -1,
|
||||
.pio_version = pio_tx_pio_version,
|
||||
.pio_version = 0,
|
||||
#if PICO_PIO_VERSION > 0
|
||||
.used_gpio_ranges = 0x0
|
||||
#endif
|
||||
|
|
@ -71,7 +71,7 @@ static inline void pio_tx_program_init(PIO pio, uint sm, uint offset, uint pin_t
|
|||
// ------ //
|
||||
|
||||
#define pio_rx_wrap_target 0
|
||||
#define pio_rx_wrap 10
|
||||
#define pio_rx_wrap 6
|
||||
#define pio_rx_pio_version 0
|
||||
|
||||
static const uint16_t pio_rx_program_instructions[] = {
|
||||
|
|
@ -80,22 +80,18 @@ static const uint16_t pio_rx_program_instructions[] = {
|
|||
0x2020, // 1: wait 0 pin, 0
|
||||
0xa047, // 2: mov y, osr
|
||||
0x0083, // 3: jmp y--, 3
|
||||
0xa047, // 4: mov y, osr
|
||||
0x0085, // 5: jmp y--, 5
|
||||
0xa047, // 6: mov y, osr
|
||||
0x0087, // 7: jmp y--, 7
|
||||
0x4001, // 8: in pins, 1
|
||||
0x0044, // 9: jmp x--, 4
|
||||
0x8020, // 10: push block
|
||||
0x4001, // 4: in pins, 1
|
||||
0x0042, // 5: jmp x--, 2
|
||||
0x8020, // 6: push block
|
||||
// .wrap
|
||||
};
|
||||
|
||||
#if !PICO_NO_HARDWARE
|
||||
static const struct pio_program pio_rx_program = {
|
||||
.instructions = pio_rx_program_instructions,
|
||||
.length = 11,
|
||||
.length = 7,
|
||||
.origin = -1,
|
||||
.pio_version = pio_rx_pio_version,
|
||||
.pio_version = 0,
|
||||
#if PICO_PIO_VERSION > 0
|
||||
.used_gpio_ranges = 0x0
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -23,7 +23,6 @@
|
|||
#include <errno.h>
|
||||
#include <_syslist.h>
|
||||
#include <sys/times.h>
|
||||
#include <sys/unistd.h>
|
||||
#include <pico/stdlib.h>
|
||||
#include <pico/multicore.h>
|
||||
|
||||
|
|
|
|||
|
|
@ -195,7 +195,10 @@ static size_t __no_inline_not_in_flash_func(get_psram_size)(void) {
|
|||
///
|
||||
/// @note This function expects interrupts to be enabled on entry
|
||||
|
||||
static void __no_inline_not_in_flash_func(set_psram_timing)(uint32_t sysHz) {
|
||||
static void __no_inline_not_in_flash_func(set_psram_timing)(void) {
|
||||
// Get secs / cycle for the system clock - get before disabling interrupts.
|
||||
uint32_t sysHz = (uint32_t)clock_get_hz(clk_sys);
|
||||
|
||||
// Calculate the clock divider - goal to get clock used for PSRAM <= what
|
||||
// the PSRAM IC can handle - which is defined in SFE_PSRAM_MAX_SCK_HZ
|
||||
volatile uint8_t clockDivider = (sysHz + SFE_PSRAM_MAX_SCK_HZ - 1) / SFE_PSRAM_MAX_SCK_HZ;
|
||||
|
|
@ -280,7 +283,7 @@ static void __no_inline_not_in_flash_func(runtime_init_setup_psram)(/*uint32_t p
|
|||
|
||||
// check our interrupts and setup the timing
|
||||
restore_interrupts(intr_stash);
|
||||
set_psram_timing((uint32_t)clock_get_hz(clk_sys));
|
||||
set_psram_timing();
|
||||
|
||||
// and now stash interrupts again
|
||||
intr_stash = save_and_disable_interrupts();
|
||||
|
|
@ -320,11 +323,8 @@ static void __no_inline_not_in_flash_func(runtime_init_setup_psram)(/*uint32_t p
|
|||
PICO_RUNTIME_INIT_FUNC_RUNTIME(runtime_init_setup_psram, PICO_RUNTIME_INIT_PSRAM);
|
||||
|
||||
// update timing -- used if the system clock/timing was changed.
|
||||
void psram_reinit_timing(uint32_t hz) {
|
||||
if (!hz) {
|
||||
hz = (uint32_t)clock_get_hz(clk_sys);
|
||||
}
|
||||
set_psram_timing(hz);
|
||||
void psram_reinit_timing() {
|
||||
set_psram_timing();
|
||||
}
|
||||
|
||||
static bool __psram_heap_init() {
|
||||
|
|
|
|||
|
|
@ -31,7 +31,7 @@
|
|||
|
||||
#include <Arduino.h>
|
||||
|
||||
void psram_reinit_timing(uint32_t hz = 0);
|
||||
void psram_reinit_timing();
|
||||
void *__psram_malloc(size_t size);
|
||||
void __psram_free(void *ptr);
|
||||
void *__psram_realloc(void *ptr, size_t size);
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@
|
|||
SPDX-License-Identifier: BSD-3-Clause
|
||||
*/
|
||||
|
||||
#if defined(PICO_CYW43_SUPPORTED)
|
||||
#if defined(ARDUINO_RASPBERRY_PI_PICO_W)
|
||||
#include <btstack.h>
|
||||
#include <pico/btstack_flash_bank.h>
|
||||
#include <hardware/flash.h>
|
||||
|
|
|
|||
|
|
@ -18,7 +18,7 @@
|
|||
|
||||
; Side-set pin 0 is used for Tone output
|
||||
|
||||
; OSR == Halfcycle count - 3
|
||||
; OSR == Halfcycle count
|
||||
|
||||
.program tone2
|
||||
.side_set 1 opt
|
||||
|
|
@ -26,11 +26,10 @@
|
|||
; pull ; TXFIFO -> OSR, or X -> OSR if no new period
|
||||
; mov x, osr ; OSR -> X
|
||||
|
||||
.wrap_target
|
||||
high:
|
||||
pull noblock ; Potentially grab new HALFCYCLECOUNT, OTW copy from backup in X
|
||||
mov x, osr side 1 ; OSR -> X
|
||||
mov y, osr ; HALFCYCLECOUNT -> Y
|
||||
mov x, osr ; OSR -> X
|
||||
mov y, osr side 1 ; HALFCYCLECOUNT -> Y
|
||||
highloop:
|
||||
jmp y-- highloop ; while (y--) { /* noop delay */ }
|
||||
|
||||
|
|
@ -39,7 +38,7 @@ low:
|
|||
lowloop:
|
||||
jmp y-- lowloop ; while (y--) { /* noop delay */ }
|
||||
|
||||
.wrap ; GOTO high
|
||||
jmp high ; GOTO high
|
||||
|
||||
% c-sdk {
|
||||
static inline void tone2_program_init(PIO pio, uint sm, uint offset, uint pin) {
|
||||
|
|
|
|||
|
|
@ -13,26 +13,27 @@
|
|||
// ----- //
|
||||
|
||||
#define tone2_wrap_target 0
|
||||
#define tone2_wrap 5
|
||||
#define tone2_wrap 6
|
||||
#define tone2_pio_version 0
|
||||
|
||||
static const uint16_t tone2_program_instructions[] = {
|
||||
// .wrap_target
|
||||
0x8080, // 0: pull noblock
|
||||
0xb827, // 1: mov x, osr side 1
|
||||
0xa047, // 2: mov y, osr
|
||||
0xa027, // 1: mov x, osr
|
||||
0xb847, // 2: mov y, osr side 1
|
||||
0x0083, // 3: jmp y--, 3
|
||||
0xb047, // 4: mov y, osr side 0
|
||||
0x0085, // 5: jmp y--, 5
|
||||
0x0000, // 6: jmp 0
|
||||
// .wrap
|
||||
};
|
||||
|
||||
#if !PICO_NO_HARDWARE
|
||||
static const struct pio_program tone2_program = {
|
||||
.instructions = tone2_program_instructions,
|
||||
.length = 6,
|
||||
.length = 7,
|
||||
.origin = -1,
|
||||
.pio_version = tone2_pio_version,
|
||||
.pio_version = 0,
|
||||
#if PICO_PIO_VERSION > 0
|
||||
.used_gpio_ranges = 0x0
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -56,9 +56,9 @@ extern "C" void shiftOut(pin_size_t dataPin, pin_size_t clockPin, BitOrder bitOr
|
|||
}
|
||||
for (i = 0; i < 8; i++) {
|
||||
if (bitOrder == LSBFIRST) {
|
||||
digitalWrite(dataPin, !!(val & (1 << i)) ? HIGH : LOW);
|
||||
digitalWrite(dataPin, !!(val & (1 << i)));
|
||||
} else {
|
||||
digitalWrite(dataPin, !!(val & (1 << (7 - i))) ? HIGH : LOW);
|
||||
digitalWrite(dataPin, !!(val & (1 << (7 - i))));
|
||||
}
|
||||
|
||||
digitalWrite(clockPin, HIGH);
|
||||
|
|
|
|||
13
docs/adc.rst
13
docs/adc.rst
|
|
@ -12,9 +12,9 @@ need to be periodically sampled to be read by applications, easily, such as:
|
|||
* Light dependent resistors (LDR), etc.
|
||||
|
||||
|
||||
Up to 4 (or 8 in the case of the RP2350B) analog samples can be recorded by the
|
||||
hardware (``A0`` ... ``A3``), and all recording is done at 16-bit levels (but be
|
||||
aware that the ADC in the Pico will only ever return values between 0...4095).
|
||||
Up to 4 analog samples can be recorded by the hardware (``A0`` ... ``A3``), and all
|
||||
recording is done at 16-bit levels (but be aware that the ADC in the Pico will only
|
||||
ever return values between 0...4095).
|
||||
|
||||
The interface for the ``ADCInput`` device is very similar to the ``I2S`` input
|
||||
device, and most code can be ported simply by instantiating a ``ADCInput``
|
||||
|
|
@ -26,12 +26,11 @@ allowed while in use.
|
|||
ADC Input API
|
||||
-------------
|
||||
|
||||
ADCInput(pin0 [, pin1, pin2, pin3[, pin4, pin5, pin6, pin7])
|
||||
ADCInput(pin0 [, pin1, pin2, pin3])
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
Creates an ADC input object which will record the pins specified in the code.
|
||||
Only pins ``A0`` ... ``A3`` (``A7`` on RP2350B) can be used, and they must be
|
||||
specified in increasing order (i.e. ``ADCInput(A0, A1);`` is valid,
|
||||
but ``ADCInput(A1, A0)`` is not.
|
||||
Only pins ``A0`` ... ``A3`` can be used, and they must be specified in increasing
|
||||
order (i.e. ``ADCInput(A0, A1);`` is valid, but ``ADCInput(A1, A0)`` is not.
|
||||
|
||||
bool setBuffers(size_t buffers, size_t bufferWords)
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
|
|
|||
|
|
@ -54,9 +54,9 @@ author = u'Earle F. Philhower, III'
|
|||
# built documents.
|
||||
#
|
||||
# The short X.Y version.
|
||||
version = u'4.5.4'
|
||||
version = u'4.4.1'
|
||||
# The full version, including alpha/beta/rc tags.
|
||||
release = u'4.5.4'
|
||||
release = u'4.4.1'
|
||||
|
||||
# The language for content autogenerated by Sphinx. Refer to documentation
|
||||
# for a list of supported languages.
|
||||
|
|
|
|||
|
|
@ -112,7 +112,7 @@ For only RP2350A variants (using the compile options, not the onboard ID registe
|
|||
|
||||
.. code:: cpp
|
||||
|
||||
#if defined(PICO_RP2350A) && PICO_RP2350A
|
||||
#if defined(PICO_RP2350) && !defined(PICO_RP2350B)
|
||||
...RP2350A only code...
|
||||
#endif
|
||||
|
||||
|
|
@ -121,7 +121,7 @@ and not the chip ID register):
|
|||
|
||||
.. code:: cpp
|
||||
|
||||
#if defined(PICO_RP2350A) && !PICO_RP2350A
|
||||
#if defined(PICO_RP2350B)
|
||||
...48-GPIO version code here
|
||||
#endif
|
||||
|
||||
|
|
|
|||
17
docs/fs.rst
17
docs/fs.rst
|
|
@ -174,23 +174,6 @@ second SPI port, ``SPI1``. Just use the following call in place of
|
|||
|
||||
SD.begin(cspin, SPI1);
|
||||
|
||||
Enabling SDIO operation for SD
|
||||
------------------------------
|
||||
SDIO support is available thanks to SdFat implementing a PIO-based SDIO controller.
|
||||
This mode can significantly increase IO performance to SD cards but it requires that
|
||||
all 4 DAT0..DAT3 lines to be wired to the Pico (most SD breakout boards only provide
|
||||
1-but SPI mode of operation).
|
||||
|
||||
To enable SDIO mode, simply specify the SD_CLK, SD_CMD, and SD_DAT0 GPIO pins. The clock
|
||||
and command pins can be any GPIO (not limited to legal SPI pins). The DAT0 pin can be any
|
||||
GPIO with remaining DAT1...3 pins consecutively connected.
|
||||
|
||||
..code:: cpp
|
||||
|
||||
SD.begin(RP_CLK_GPIO, RP_CMD_GPIO, RP_DAT0_GPIO);
|
||||
|
||||
No other changes are required in the application to take advantage of this high
|
||||
performance mode.
|
||||
|
||||
Using VFS (Virtual File System) for POSIX support
|
||||
-------------------------------------------------
|
||||
|
|
|
|||
36
docs/i2s.rst
36
docs/i2s.rst
|
|
@ -30,12 +30,6 @@ I2S(INPUT)
|
|||
Creates an I2S input port. Needs to be connected up to the
|
||||
desired pins (see below) and started before any input can happen.
|
||||
|
||||
I2S(INPUT_PULLUP)
|
||||
~~~~~~~~~~~~~~~~~
|
||||
Creates a bi-directional I2S input and output port. Needs to be
|
||||
connected up to the desired pins (see below) and started before
|
||||
any input or output can happen.
|
||||
|
||||
bool setBCLK(pin_size_t pin)
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
Sets the BCLK pin of the I2S device. The LRCLK/word clock will be ``pin + 1``
|
||||
|
|
@ -43,18 +37,7 @@ due to limitations of the PIO state machines. Call this before ``I2S::begin()``
|
|||
|
||||
bool setDATA(pin_size_t pin)
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
Sets the DOUT or DIN pin of the I2S device. Any pin may be used. In bi-directional
|
||||
operation, must use ``I2S::setDOUT()`` and ``I2S::setDIN`` instead.
|
||||
Call before ``I2S::begin()``
|
||||
|
||||
bool setDOUT(pin_size_t pin)
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
Sets the DOUT pin of the I2S device. Any pin may be used.
|
||||
Call before ``I2S::begin()``
|
||||
|
||||
bool setDIN(pin_size_t pin)
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
Sets the DIN pin of the I2S device. Any pin may be used.
|
||||
Sets the DOUT or DIN pin of the I2S device. Any pin may be used.
|
||||
Call before ``I2S::begin()``
|
||||
|
||||
bool setMCLK(pin_size_t pin)
|
||||
|
|
@ -132,14 +115,6 @@ void getOverUnderflow()
|
|||
Returns a flag indicating if the I2S system ran our of data to send on output,
|
||||
or had to throw away data on input.
|
||||
|
||||
void getOverflow()
|
||||
~~~~~~~~~~~~~~~~~~~~~~~
|
||||
Returns a flag indicating if the I2S system had to throw away data on input.
|
||||
|
||||
void getUnderflow()
|
||||
~~~~~~~~~~~~~~~~~~~~~~~
|
||||
Returns a flag indicating if the I2S system ran our of data to send on output.
|
||||
|
||||
size_t write(uint8_t/int8_t/int16_t/int32_t)
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
Writes a single sample of ``bitsPerSample`` to the buffer. It is up to the
|
||||
|
|
@ -164,7 +139,7 @@ size_t write(const uint8_t \*buffer, size_t size)
|
|||
Transfers number of bytes from an application buffer to the I2S output buffer.
|
||||
Be aware that ``size`` is in *bytes** and not samples. Size must be a multiple
|
||||
of **4 bytes**. Will not block, so check the return value to find out how
|
||||
many 32-bit words were actually written.
|
||||
many bytes were actually written.
|
||||
|
||||
int availableForWrite()
|
||||
~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
|
@ -181,13 +156,6 @@ int peek()
|
|||
Returns the next sample to be read from the I2S buffer (without actually
|
||||
removing it).
|
||||
|
||||
size_t read(uint8_t \*buffer, size_t size)
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
Transfers number of bytes from the I2S input buffer to an application buffer.
|
||||
Be aware that ``size`` is in *bytes** and not samples. Size must be a multiple
|
||||
of **4 bytes**. Will not block, so check the return value to find out how
|
||||
many 32-bit words were actually read.
|
||||
|
||||
void onTransmit(void (\*fn)(void))
|
||||
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
Sets a callback to be called when an I2S DMA buffer is fully transmitted.
|
||||
|
|
|
|||
|
|
@ -16,25 +16,6 @@ not necessarily simultaneously!).
|
|||
See the ``Multicore.ino`` example in the ``rp2040`` example directory for a
|
||||
quick introduction.
|
||||
|
||||
Core 1 Operation
|
||||
----------------
|
||||
|
||||
By default, core1 (the second core) has no non-user written code running on it.
|
||||
No interrupts, exceptions, or other background processing is done (but the core
|
||||
is still subject to hardware stalls due to on-die memory resource conflicts).
|
||||
When flash erase or write operations (i.e. ``LittleFS`` or ``EEPROM``) are called
|
||||
from core0, core1 **will** be paused.
|
||||
|
||||
If ``rp2040.getCycleCount`` is needed to operate on the second core, then a
|
||||
periodic (once ever 16M clock cycles) ``SYSTICK`` exception will happen behind
|
||||
the scenes. For extremely time-critical operations this may not be desirable
|
||||
and can be disabled by defining a new ``bool`` variable to ``true`` anywhere
|
||||
in your sketch:
|
||||
|
||||
.. code:: cpp
|
||||
|
||||
bool core1_disable_systick = true;
|
||||
|
||||
Stack Sizes
|
||||
-----------
|
||||
|
||||
|
|
@ -86,9 +67,6 @@ void rp2040.restartCore1()
|
|||
~~~~~~~~~~~~~~~~~~~~~~~~~~
|
||||
|
||||
Hard resets Core1 from Core 0 and restarts its operation from ``setup1()``.
|
||||
This can cause unpredictable behavior because globals and the heap
|
||||
are shared between cores and not re-initialized with this call. Use with
|
||||
extreme caution.
|
||||
|
||||
Communicating Between Cores
|
||||
---------------------------
|
||||
|
|
|
|||
|
|
@ -172,37 +172,6 @@ To learn more about PSRAM usage, see: :doc:`RP2350 PSRAM Support <psram>`
|
|||
; PSRAM size: 4MB
|
||||
board_upload.psram_length = 4194304
|
||||
|
||||
PSRAM chip select (CS)
|
||||
----------------------
|
||||
|
||||
For RP2350 based boards, this controls what chip-select (also called: slave-select / SS) pin to use when wanting to talk to the PSRAM chip.
|
||||
|
||||
Note that it's not needed to set this with a board that is known to have a PSRAM chip on-board, such as a "Sparkfun Thing Plus 2350". The ``pins_arduino.h`` of that variant already has the correct definition.
|
||||
|
||||
To learn more about PSRAM usage, see: :doc:`RP2350 PSRAM Support <psram>`
|
||||
|
||||
.. code:: ini
|
||||
|
||||
; PSRAM CS is at GP47
|
||||
build_flags =
|
||||
-DRP2350_PSRAM_CS=47
|
||||
|
||||
|
||||
Boot2 Source
|
||||
------------
|
||||
|
||||
Boot2 is the second stage bootloader and predominantly used on the RP2040.
|
||||
Its main purpose is to configure the communication with the Flash at the highest, safest speed it can.
|
||||
All known boards have their correct value already configured. However, when choosing ``board = generic``,
|
||||
you can freely configure the Boot2 to be for a different flash.
|
||||
|
||||
For possible Boot2 filenames, `please see here <https://github.com/earlephilhower/arduino-pico/tree/master/boot2/rp2040>`__.
|
||||
|
||||
.. code:: ini
|
||||
|
||||
; expect an ISSI IS25LP080 flash, SPI frequency = CPU frequency divided by 2
|
||||
board_build.arduino.earlephilhower.boot2_source = boot2_is25lp080_2_padded_checksum.S
|
||||
|
||||
CPU Speed
|
||||
---------
|
||||
|
||||
|
|
|
|||
13
docs/spi.rst
13
docs/spi.rst
|
|
@ -28,19 +28,6 @@ pin itself, as is the standard way in Arduino.
|
|||
|
||||
* The interrupt calls (``attachInterrupt``, and ``detachInterrpt``) are not implemented.
|
||||
|
||||
Software SPI (Master Only)
|
||||
==========================
|
||||
|
||||
Similar to ``SoftwareSerial``, ``SoftwareSPI`` creates a PIO based SPI interface that
|
||||
can be used in the same manner as the hardware SPI devices. The constructor takes the
|
||||
pins desired, which can be any GPIO pins with the rule that if hardware CS is used then
|
||||
it must be on pin ``SCK + 1``. Construct a ``SoftwareSPI`` object in your code as
|
||||
follows and use it as needed (i.e. pass it into ``SD.begin(_CS, softwareSPI);``
|
||||
|
||||
.. code:: cpp
|
||||
|
||||
#include <SoftwareSPI.h>
|
||||
SoftwareSPI softSPI(_sck, _miso, _mosi); // no HW CS support, any selection of pins can be used
|
||||
|
||||
SPI Slave (SPISlave)
|
||||
====================
|
||||
|
|
|
|||
|
|
@ -1,2 +1,2 @@
|
|||
// Do not edit -- Automatically generated by tools/sdk/ssl/bearssl/Makefile
|
||||
#define BEARSSL_GIT aca1383
|
||||
#define BEARSSL_GIT 5b7f3d5
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@
|
|||
|
||||
#define PICO_SDK_VERSION_MAJOR 2
|
||||
#define PICO_SDK_VERSION_MINOR 1
|
||||
#define PICO_SDK_VERSION_REVISION 2
|
||||
#define PICO_SDK_VERSION_STRING "2.1.2-develop"
|
||||
#define PICO_SDK_VERSION_REVISION 0
|
||||
#define PICO_SDK_VERSION_STRING "2.1.0"
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -13,7 +13,7 @@
|
|||
|
||||
#define PICO_SDK_VERSION_MAJOR 2
|
||||
#define PICO_SDK_VERSION_MINOR 1
|
||||
#define PICO_SDK_VERSION_REVISION 2
|
||||
#define PICO_SDK_VERSION_STRING "2.1.2-develop"
|
||||
#define PICO_SDK_VERSION_REVISION 0
|
||||
#define PICO_SDK_VERSION_STRING "2.1.0"
|
||||
|
||||
#endif
|
||||
|
|
|
|||
|
|
@ -54,7 +54,6 @@
|
|||
-iwithprefixbefore/pico-sdk/src/rp2_common/pico_lwip/include
|
||||
-iwithprefixbefore/pico-sdk/src/rp2_common/pico_multicore/include
|
||||
-iwithprefixbefore/pico-sdk/src/rp2_common/pico_platform/include
|
||||
-iwithprefixbefore/pico-sdk/src/rp2_common/pico_platform_common/include
|
||||
-iwithprefixbefore/pico-sdk/src/rp2_common/pico_platform_compiler/include
|
||||
-iwithprefixbefore/pico-sdk/src/rp2_common/pico_platform_sections/include
|
||||
-iwithprefixbefore/pico-sdk/src/rp2_common/pico_platform_panic/include
|
||||
|
|
|
|||
|
|
@ -67,5 +67,3 @@
|
|||
-Wl,--wrap=cyw43_tcpip_link_status
|
||||
-Wl,--wrap=cyw43_cb_tcpip_init
|
||||
-Wl,--wrap=cyw43_cb_tcpip_deinit
|
||||
|
||||
-Wl,--wrap=__stack_chk_fail
|
||||
|
|
|
|||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
|
@ -10,6 +10,5 @@
|
|||
-iwithprefixbefore/pico-sdk/lib/btstack/src
|
||||
-iwithprefixbefore/pico-sdk/lib/btstack/3rd-party/bluedroid/decoder/include
|
||||
-iwithprefixbefore/pico-sdk/lib/btstack/3rd-party/bluedroid/encoder/include
|
||||
-iwithprefixbefore/pico-sdk/lib/btstack/3rd-party/yxml
|
||||
-iwithprefixbefore/pico-sdk/lib/btstack/platform/embedded
|
||||
-iwithprefixbefore/pico-sdk/src/rp2_common/cmsis/stub/CMSIS/Device/RP2040/Include
|
||||
|
|
|
|||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
|
@ -1,5 +1,4 @@
|
|||
-DPICO_CYW43_ARCH_THREADSAFE_BACKGROUND=1
|
||||
-DTARGET_RP2350
|
||||
-DCYW43_LWIP=1
|
||||
-DCYW43_PIO_CLOCK_DIV_DYNAMIC=1
|
||||
-DCFG_TUSB_MCU=OPT_MCU_RP2040
|
||||
|
|
|
|||
|
|
@ -15,5 +15,4 @@
|
|||
-iwithprefixbefore/pico-sdk/lib/btstack/src
|
||||
-iwithprefixbefore/pico-sdk/lib/btstack/3rd-party/bluedroid/decoder/include
|
||||
-iwithprefixbefore/pico-sdk/lib/btstack/3rd-party/bluedroid/encoder/include
|
||||
-iwithprefixbefore/pico-sdk/lib/btstack/3rd-party/yxml
|
||||
-iwithprefixbefore/pico-sdk/lib/btstack/platform/embedded
|
||||
|
|
|
|||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
|
@ -1,5 +1,4 @@
|
|||
-DPICO_CYW43_ARCH_THREADSAFE_BACKGROUND=1
|
||||
-DTARGET_RP2350
|
||||
-DCYW43_LWIP=1
|
||||
-DCYW43_PIO_CLOCK_DIV_DYNAMIC=1
|
||||
-DCFG_TUSB_MCU=OPT_MCU_RP2040
|
||||
|
|
|
|||
|
|
@ -13,5 +13,4 @@
|
|||
-iwithprefixbefore/pico-sdk/lib/btstack/src
|
||||
-iwithprefixbefore/pico-sdk/lib/btstack/3rd-party/bluedroid/decoder/include
|
||||
-iwithprefixbefore/pico-sdk/lib/btstack/3rd-party/bluedroid/encoder/include
|
||||
-iwithprefixbefore/pico-sdk/lib/btstack/3rd-party/yxml
|
||||
-iwithprefixbefore/pico-sdk/lib/btstack/platform/embedded
|
||||
|
|
|
|||
|
|
@ -49,7 +49,12 @@ bool ADCInput::setBuffers(size_t buffers, size_t bufferWords) {
|
|||
|
||||
int ADCInput::_mask(pin_size_t p) {
|
||||
switch (p) {
|
||||
#if defined(PICO_RP2350) && !PICO_RP2350A // RP2350B
|
||||
#if !defined(PICO_RP2350B)
|
||||
case 26: return 1;
|
||||
case 27: return 2;
|
||||
case 28: return 4;
|
||||
case 29: return 8;
|
||||
#else // Starts at 40 and there are 8 of them
|
||||
case 40: return 1;
|
||||
case 41: return 2;
|
||||
case 42: return 4;
|
||||
|
|
@ -58,11 +63,6 @@ int ADCInput::_mask(pin_size_t p) {
|
|||
case 45: return 32;
|
||||
case 46: return 64;
|
||||
case 47: return 128;
|
||||
#else
|
||||
case 26: return 1;
|
||||
case 27: return 2;
|
||||
case 28: return 4;
|
||||
case 29: return 8;
|
||||
#endif
|
||||
default: return 0;
|
||||
}
|
||||
|
|
@ -77,9 +77,8 @@ bool ADCInput::setPins(pin_size_t pin0, pin_size_t pin1, pin_size_t pin2, pin_si
|
|||
}
|
||||
|
||||
bool ADCInput::setFrequency(int newFreq) {
|
||||
_freq = newFreq;
|
||||
int scaledFreq = newFreq * __builtin_popcount(_pinMask); // Want to sample all channels at given frequency
|
||||
adc_set_clkdiv(48000000.0f / scaledFreq - 1.0f);
|
||||
_freq = newFreq * __builtin_popcount(_pinMask); // Want to sample all channels at given frequency
|
||||
adc_set_clkdiv(48000000.0f / _freq - 1.0f);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
@ -106,7 +105,7 @@ bool ADCInput::begin() {
|
|||
// Set up the GPIOs to go to ADC
|
||||
adc_init();
|
||||
int cnt = 0;
|
||||
#if defined(PICO_RP2350) && !PICO_RP2350A // RP2350B
|
||||
#if !defined(PICO_RP2350B)
|
||||
int startpin = 26;
|
||||
int maxpin = 29;
|
||||
#else
|
||||
|
|
|
|||
|
|
@ -1 +1 @@
|
|||
Subproject commit 6b772c0ac4a8158011a738e794463a2fe4e84a33
|
||||
Subproject commit f5211f42269dc18ca7a8c6d17a8f6b04c34b644a
|
||||
|
|
@ -204,6 +204,7 @@ size_t AudioBufferManager::write(const uint32_t *v, size_t words, bool sync) {
|
|||
/* noop busy wait */
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
size_t availToWriteThisBuff = _wordsPerBuffer - _userOff;
|
||||
size_t toWrite = std::min(availToWriteThisBuff, words);
|
||||
|
|
@ -244,38 +245,6 @@ bool AudioBufferManager::read(uint32_t *v, bool sync) {
|
|||
return true;
|
||||
}
|
||||
|
||||
size_t AudioBufferManager::read(uint32_t *v, size_t words, bool sync) {
|
||||
size_t read = 0;
|
||||
|
||||
if (!_running || _isOutput) {
|
||||
return 0;
|
||||
}
|
||||
while (words) {
|
||||
AudioBuffer ** volatile p = (AudioBuffer ** volatile)&_filled;
|
||||
if (!*p) {
|
||||
if (!sync) {
|
||||
return read;
|
||||
} else {
|
||||
while (!*p) {
|
||||
/* noop busy wait */
|
||||
}
|
||||
}
|
||||
}
|
||||
size_t availToReadThisBuff = _wordsPerBuffer - _userOff;
|
||||
size_t toRead = std::min(availToReadThisBuff, words);
|
||||
memcpy((void *)v, &((*p)->buff[_userOff]), toRead * sizeof(uint32_t));
|
||||
v += toRead;
|
||||
read += toRead;
|
||||
_userOff += toRead;
|
||||
words -= toRead;
|
||||
if (_userOff == _wordsPerBuffer) {
|
||||
_addToList(&_empty, _takeFromList(p));
|
||||
_userOff = 0;
|
||||
}
|
||||
}
|
||||
return read;
|
||||
}
|
||||
|
||||
bool AudioBufferManager::getOverUnderflow() {
|
||||
bool hold = _overunderflow;
|
||||
_overunderflow = false;
|
||||
|
|
|
|||
|
|
@ -36,7 +36,6 @@ public:
|
|||
bool write(uint32_t v, bool sync = true);
|
||||
size_t write(const uint32_t *v, size_t words, bool sync = true);
|
||||
bool read(uint32_t *v, bool sync = true);
|
||||
size_t read(uint32_t *v, size_t words, bool sync = true);
|
||||
void flush();
|
||||
|
||||
bool getOverUnderflow();
|
||||
|
|
|
|||
|
|
@ -82,7 +82,7 @@ void deviceDisconnectedCallback(BLEDevice * device) {
|
|||
@text In BTstack, the Read Callback is first called to query the size of the
|
||||
Characteristic Value, before it is called to provide the data.
|
||||
Both times, the size has to be returned. The data is only stored in the provided
|
||||
buffer, if the buffer argument is not NULL.
|
||||
buffer, if the buffer argeument is not NULL.
|
||||
If more than one dynamic Characteristics is used, the value handle is used
|
||||
to distinguish them.
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -196,7 +196,7 @@ static void extract_service(gatt_client_service_t * service, uint8_t * packet) {
|
|||
service->start_group_handle = little_endian_read_16(packet, 4);
|
||||
service->end_group_handle = little_endian_read_16(packet, 6);
|
||||
service->uuid16 = 0;
|
||||
reverse_128(&packet[12], service->uuid128);
|
||||
reverse_128(&packet[8], service->uuid128);
|
||||
if (uuid_has_bluetooth_prefix(service->uuid128)) {
|
||||
service->uuid16 = big_endian_read_32(service->uuid128, 0);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -676,9 +676,6 @@ void A2DPSink::avrcp_target_packet_handler(uint8_t packet_type, uint16_t channel
|
|||
volume_percentage = volume * 100 / 127;
|
||||
DEBUGV("AVRCP Target : Volume set to %d%% (%d)\n", volume_percentage, volume);
|
||||
_consumer->setVolume(volume);
|
||||
if (_volumeCB) {
|
||||
_volumeCB(_volumeData, volume);
|
||||
}
|
||||
break;
|
||||
|
||||
case AVRCP_SUBEVENT_OPERATION:
|
||||
|
|
@ -776,11 +773,6 @@ void A2DPSink::a2dp_sink_packet_handler(uint8_t packet_type, uint16_t channel, u
|
|||
DEBUGV("A2DP Sink : Streaming connection is established, address %s, cid 0x%02x, local seid %d\n",
|
||||
bd_addr_to_str(a2dp_conn->addr), a2dp_conn->a2dp_cid, a2dp_conn->a2dp_local_seid);
|
||||
memcpy(_sourceAddress, a2dp_conn->addr, sizeof(_sourceAddress));
|
||||
|
||||
_connected = true;
|
||||
if (_connectCB) {
|
||||
_connectCB(_connectData, true);
|
||||
}
|
||||
break;
|
||||
|
||||
case A2DP_SUBEVENT_STREAM_STARTED:
|
||||
|
|
@ -792,6 +784,10 @@ void A2DPSink::a2dp_sink_packet_handler(uint8_t packet_type, uint16_t channel, u
|
|||
// prepare media processing
|
||||
media_processing_init(&a2dp_conn->sbc_configuration);
|
||||
// audio stream is started when buffer reaches minimal level
|
||||
_connected = true;
|
||||
if (_connectCB) {
|
||||
_connectCB(_connectData, true);
|
||||
}
|
||||
break;
|
||||
|
||||
case A2DP_SUBEVENT_STREAM_SUSPENDED:
|
||||
|
|
|
|||
|
|
@ -30,7 +30,7 @@
|
|||
#include "btstack_resample.h"
|
||||
#include "btstack_ring_buffer.h"
|
||||
|
||||
class A2DPSink {
|
||||
class A2DPSink : public Stream {
|
||||
public:
|
||||
A2DPSink() {
|
||||
_title[0] = 0;
|
||||
|
|
@ -38,6 +38,33 @@ public:
|
|||
_album[0] = 0;
|
||||
_genre[0] = 0;
|
||||
}
|
||||
virtual int available() override {
|
||||
return 0; // Unreadable, this is output only
|
||||
}
|
||||
|
||||
virtual int read() override {
|
||||
return 0;
|
||||
}
|
||||
|
||||
virtual int peek() override {
|
||||
return 0;
|
||||
}
|
||||
|
||||
virtual void flush() override {
|
||||
}
|
||||
virtual size_t write(const uint8_t *buffer, size_t size) override {
|
||||
(void) buffer;
|
||||
(void) size;
|
||||
return 0;
|
||||
}
|
||||
virtual int availableForWrite() override {
|
||||
return 0;
|
||||
}
|
||||
|
||||
virtual size_t write(uint8_t s) override {
|
||||
(void) s;
|
||||
return 0;
|
||||
}
|
||||
|
||||
bool setName(const char *name) {
|
||||
if (_running) {
|
||||
|
|
@ -48,6 +75,11 @@ public:
|
|||
return true;
|
||||
}
|
||||
|
||||
void onTransmit(void (*cb)(void *), void *cbData = nullptr) {
|
||||
_transmitCB = cb;
|
||||
_transmitData = cbData;
|
||||
}
|
||||
|
||||
void onAVRCP(void (*cb)(void *, avrcp_operation_id_t, int), void *cbData = nullptr) {
|
||||
_avrcpCB = cb;
|
||||
_avrcpData = cbData;
|
||||
|
|
@ -205,6 +237,8 @@ private:
|
|||
bool _connected = false;
|
||||
|
||||
// Callbacks
|
||||
void (*_transmitCB)(void *) = nullptr;
|
||||
void *_transmitData;
|
||||
void (*_avrcpCB)(void *, avrcp_operation_id_t, int) = nullptr;
|
||||
void *_avrcpData;
|
||||
void (*_batteryCB)(void *, avrcp_battery_status_t) = nullptr;
|
||||
|
|
|
|||
|
|
@ -223,7 +223,7 @@ size_t A2DPSource::write(const uint8_t *buffer, size_t size) {
|
|||
size = std::min((size_t)availableForWrite(), size);
|
||||
|
||||
size_t count = 0;
|
||||
size /= sizeof(int16_t); // Convert size to samples
|
||||
size /= 2;
|
||||
|
||||
// First copy from writer to either end of
|
||||
uint32_t start = _pcmWriter;
|
||||
|
|
@ -262,7 +262,7 @@ int A2DPSource::availableForWrite() {
|
|||
} else {
|
||||
avail = _pcmBufferSize - _pcmWriter + _pcmReader - 1;
|
||||
}
|
||||
avail *= sizeof(int16_t); // Convert samples to bytes
|
||||
avail /= sizeof(uint32_t); // availableForWrite always 32b sample pairs in this core...
|
||||
return avail;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -125,14 +125,6 @@ public:
|
|||
return _hci.scan(mask, scanTimeSec, async);
|
||||
}
|
||||
|
||||
bool scanAsyncDone() {
|
||||
return _hci.scanAsyncDone();
|
||||
}
|
||||
|
||||
std::vector<BTDeviceInfo> scanAsyncResult() {
|
||||
return _hci.scanAsyncResult();
|
||||
}
|
||||
|
||||
bool connect(const uint8_t *addr = nullptr);
|
||||
|
||||
bool connected() {
|
||||
|
|
@ -159,7 +151,6 @@ public:
|
|||
}
|
||||
|
||||
// from Print (see notes on write() methods below)
|
||||
// Writes only full samples (size must be divisible by sample size in bytes)
|
||||
virtual size_t write(const uint8_t *buffer, size_t size) override;
|
||||
virtual int availableForWrite() override;
|
||||
|
||||
|
|
|
|||
1
libraries/ESP8266SdFat
Submodule
1
libraries/ESP8266SdFat
Submodule
|
|
@ -0,0 +1 @@
|
|||
Subproject commit 9e1457101ca47b9ace198086dbd8854efc573ccf
|
||||
|
|
@ -1,36 +0,0 @@
|
|||
/*
|
||||
I2S bi-directional input and output loopback example
|
||||
Released to the Public Domain by Cooper Dalrymple
|
||||
*/
|
||||
|
||||
#include <I2S.h>
|
||||
|
||||
I2S i2s(INPUT_PULLUP);
|
||||
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
|
||||
i2s.setDOUT(0);
|
||||
i2s.setDIN(1);
|
||||
i2s.setBCLK(2); // Note: LRCLK = BCLK + 1
|
||||
i2s.setBitsPerSample(16);
|
||||
i2s.setFrequency(22050);
|
||||
// NOTE: The following values are known to work with the Adafruit microphone:
|
||||
// i2s.setBitsPerSample(32);
|
||||
// i2s.setFrequency(16000);
|
||||
i2s.begin();
|
||||
|
||||
while (1) {
|
||||
int16_t l, r;
|
||||
i2s.read16(&l, &r);
|
||||
i2s.write16(l, r);
|
||||
// NOTE: Adafruit microphone word size needs to match the BPS above.
|
||||
// int32_t l, r;
|
||||
// i2s.read32(&l, &r);
|
||||
// i2s.write32(l, r);
|
||||
}
|
||||
}
|
||||
|
||||
void loop() {
|
||||
/* Nothing here */
|
||||
}
|
||||
|
|
@ -1,39 +0,0 @@
|
|||
/*
|
||||
I2S bi-directional input and output buffered loopback example
|
||||
Released to the Public Domain by Cooper Dalrymple
|
||||
*/
|
||||
|
||||
#include <I2S.h>
|
||||
|
||||
I2S i2s(INPUT_PULLUP);
|
||||
|
||||
#define SIZE 256
|
||||
int16_t buffer[SIZE];
|
||||
|
||||
void setup() {
|
||||
Serial.begin(115200);
|
||||
|
||||
i2s.setDOUT(0);
|
||||
i2s.setDIN(1);
|
||||
i2s.setBCLK(2); // Note: LRCLK = BCLK + 1
|
||||
i2s.setBitsPerSample(16);
|
||||
i2s.setFrequency(22050);
|
||||
i2s.setBuffers(6, SIZE * sizeof(int16_t) / sizeof(uint32_t));
|
||||
i2s.begin();
|
||||
|
||||
size_t count, index;
|
||||
while (1) {
|
||||
count = i2s.read((uint8_t *)&buffer, SIZE * sizeof(int16_t)) * sizeof(uint32_t) / sizeof(int16_t);
|
||||
index = 0;
|
||||
while (index < count) {
|
||||
// Reduce volume by half
|
||||
buffer[index++] >>= 1; // right
|
||||
buffer[index++] >>= 1; // left
|
||||
}
|
||||
i2s.write((const uint8_t *)&buffer, count * sizeof(int16_t));
|
||||
}
|
||||
}
|
||||
|
||||
void loop() {
|
||||
/* Nothing here */
|
||||
}
|
||||
|
|
@ -24,15 +24,13 @@
|
|||
#include <pico/stdlib.h>
|
||||
|
||||
|
||||
I2S::I2S(PinMode direction, pin_size_t bclk, pin_size_t data, pin_size_t mclk, pin_size_t data_rx) {
|
||||
I2S::I2S(PinMode direction, pin_size_t bclk, pin_size_t data, pin_size_t mclk) {
|
||||
_running = false;
|
||||
_bps = 16;
|
||||
_writtenHalf = false;
|
||||
_isInput = direction == INPUT || direction == INPUT_PULLUP;
|
||||
_isOutput = direction == OUTPUT || direction == INPUT_PULLUP;
|
||||
_isOutput = direction == OUTPUT;
|
||||
_pinBCLK = bclk;
|
||||
_pinDOUT = data;
|
||||
_pinDIN = direction == INPUT ? data : data_rx;
|
||||
_pinMCLK = mclk;
|
||||
_MCLKenabled = false;
|
||||
#ifdef PIN_I2S_BCLK
|
||||
|
|
@ -46,17 +44,14 @@ I2S::I2S(PinMode direction, pin_size_t bclk, pin_size_t data, pin_size_t mclk, p
|
|||
#endif
|
||||
|
||||
#ifdef PIN_I2S_DIN
|
||||
if (_isInput) {
|
||||
_pinDIN = PIN_I2S_DIN;
|
||||
if (!_isOutput) {
|
||||
_pinDOUT = PIN_I2S_DIN;
|
||||
}
|
||||
#endif
|
||||
_freq = 48000;
|
||||
_arbInput = nullptr;
|
||||
_cbInput = nullptr;
|
||||
_cbdInput = nullptr;
|
||||
_arbOutput = nullptr;
|
||||
_cbOutput = nullptr;
|
||||
_cbdOutput = nullptr;
|
||||
_arb = nullptr;
|
||||
_cb = nullptr;
|
||||
_cbd = nullptr;
|
||||
_buffers = 6;
|
||||
_bufferWords = 0;
|
||||
_silenceSample = 0;
|
||||
|
|
@ -86,20 +81,7 @@ bool I2S::setMCLK(pin_size_t pin) {
|
|||
_pinMCLK = pin;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool I2S::setDATA(pin_size_t pin) {
|
||||
if (_running || (pin >= __GPIOCNT) || (_isOutput && _isInput)) {
|
||||
return false;
|
||||
}
|
||||
if (_isOutput) {
|
||||
_pinDOUT = pin;
|
||||
} else {
|
||||
_pinDIN = pin;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
bool I2S::setDOUT(pin_size_t pin) {
|
||||
if (_running || (pin >= __GPIOCNT)) {
|
||||
return false;
|
||||
}
|
||||
|
|
@ -107,14 +89,6 @@ bool I2S::setDOUT(pin_size_t pin) {
|
|||
return true;
|
||||
}
|
||||
|
||||
bool I2S::setDIN(pin_size_t pin) {
|
||||
if (_running || (pin >= __GPIOCNT)) {
|
||||
return false;
|
||||
}
|
||||
_pinDIN = pin;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool I2S::setBitsPerSample(int bps) {
|
||||
if (_running || ((bps != 8) && (bps != 16) && (bps != 24) && (bps != 32))) {
|
||||
return false;
|
||||
|
|
@ -137,10 +111,10 @@ bool I2S::setFrequency(int newFreq) {
|
|||
_freq = newFreq;
|
||||
if (_running) {
|
||||
if (_MCLKenabled) {
|
||||
int bitClk = _freq * _bps * (_isTDM ? (double)_tdmChannels : 2.0) /* channels */ * (_isInput && _isOutput ? 4.0 : 2.0) /* edges per clock */;
|
||||
int bitClk = _freq * _bps * (_isTDM ? (double)_tdmChannels : 2.0) /* channels */ * 2.0 /* edges per clock */;
|
||||
pio_sm_set_clkdiv_int_frac(_pio, _sm, clock_get_hz(clk_sys) / bitClk, 0);
|
||||
} else {
|
||||
float bitClk = _freq * _bps * (_isTDM ? (double)_tdmChannels : 2.0) /* channels */ * (_isInput && _isOutput ? 4.0 : 2.0) /* edges per clock */;
|
||||
float bitClk = _freq * _bps * (_isTDM ? (double)_tdmChannels : 2.0) /* channels */ * 2.0 /* edges per clock */;
|
||||
pio_sm_set_clkdiv(_pio, _sm, (float)clock_get_hz(clk_sys) / bitClk);
|
||||
}
|
||||
}
|
||||
|
|
@ -170,7 +144,7 @@ bool I2S::setMCLKmult(int mult) {
|
|||
}
|
||||
|
||||
bool I2S::setLSBJFormat() {
|
||||
if (_running || !_isOutput || _isInput) {
|
||||
if (_running || !_isOutput) {
|
||||
return false;
|
||||
}
|
||||
_isLSBJ = true;
|
||||
|
|
@ -194,7 +168,7 @@ bool I2S::setTDMChannels(int channels) {
|
|||
}
|
||||
|
||||
bool I2S::swapClocks() {
|
||||
if (_running) {
|
||||
if (_running || !_isOutput) {
|
||||
return false;
|
||||
}
|
||||
_swapClocks = true;
|
||||
|
|
@ -203,38 +177,38 @@ bool I2S::swapClocks() {
|
|||
|
||||
void I2S::onTransmit(void(*fn)(void)) {
|
||||
if (_isOutput) {
|
||||
_cbOutput = fn;
|
||||
_cb = fn;
|
||||
if (_running) {
|
||||
_arbOutput->setCallback(_cbOutput);
|
||||
_arb->setCallback(_cb);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void I2S::onTransmit(void(*fn)(void *), void *cbData) {
|
||||
if (_isOutput) {
|
||||
_cbdOutput = fn;
|
||||
_cbdataOutput = cbData;
|
||||
_cbd = fn;
|
||||
_cbdata = cbData;
|
||||
if (_running) {
|
||||
_arbOutput->setCallback(_cbdOutput, _cbdataOutput);
|
||||
_arb->setCallback(_cbd, _cbdata);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void I2S::onReceive(void(*fn)(void)) {
|
||||
if (_isInput) {
|
||||
_cbInput = fn;
|
||||
if (!_isOutput) {
|
||||
_cb = fn;
|
||||
if (_running) {
|
||||
_arbInput->setCallback(_cbInput);
|
||||
_arb->setCallback(_cb);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void I2S::onReceive(void(*fn)(void *), void *cbData) {
|
||||
if (_isInput) {
|
||||
_cbdInput = fn;
|
||||
_cbdataInput = cbData;
|
||||
if (!_isOutput) {
|
||||
_cbd = fn;
|
||||
_cbdata = cbData;
|
||||
if (_running) {
|
||||
_arbInput->setCallback(_cbdInput, _cbdataInput);
|
||||
_arb->setCallback(_cbd, _cbdata);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -255,21 +229,12 @@ bool I2S::begin() {
|
|||
_isHolding = 0;
|
||||
int off = 0;
|
||||
if (!_swapClocks) {
|
||||
_i2s = new PIOProgram(_isOutput ? (_isInput ? (_isTDM ? &pio_tdm_inout_program : &pio_i2s_inout_program) : (_isTDM ? &pio_tdm_out_program : (_isLSBJ ? &pio_lsbj_out_program : &pio_i2s_out_program))) : &pio_i2s_in_program);
|
||||
_i2s = new PIOProgram(_isOutput ? (_isTDM ? &pio_tdm_out_program : (_isLSBJ ? &pio_lsbj_out_program : &pio_i2s_out_program)) : &pio_i2s_in_program);
|
||||
} else {
|
||||
_i2s = new PIOProgram(_isOutput ? (_isInput ? (_isTDM ? &pio_tdm_inout_swap_program : &pio_i2s_inout_swap_program) : (_isTDM ? &pio_tdm_out_swap_program : (_isLSBJ ? &pio_lsbj_out_swap_program : &pio_i2s_out_swap_program))) : &pio_i2s_in_swap_program);
|
||||
}
|
||||
int minpin, maxpin;
|
||||
if (_isOutput && _isInput) {
|
||||
minpin = std::min(std::min((int)_pinDOUT, (int)_pinDIN), (int)_pinBCLK);
|
||||
maxpin = std::max(std::min((int)_pinDOUT, (int)_pinDIN), (int)_pinBCLK + 1);
|
||||
} else if (_isOutput) {
|
||||
minpin = std::min((int)_pinDOUT, (int)_pinBCLK);
|
||||
maxpin = std::max((int)_pinDOUT, (int)_pinBCLK + 1);
|
||||
} else {
|
||||
minpin = std::min((int)_pinDIN, (int)_pinBCLK);
|
||||
maxpin = std::max((int)_pinDIN, (int)_pinBCLK + 1);
|
||||
_i2s = new PIOProgram(_isOutput ? (_isTDM ? &pio_tdm_out_swap_program : (_isLSBJ ? &pio_lsbj_out_swap_program : &pio_i2s_out_swap_program)) : &pio_i2s_in_swap_program);
|
||||
}
|
||||
int minpin = std::min((int)_pinDOUT, (int)_pinBCLK);
|
||||
int maxpin = std::max((int)_pinDOUT, (int)_pinBCLK + 1);
|
||||
if (!_i2s->prepare(&_pio, &_sm, &off, minpin, maxpin - minpin + 1)) {
|
||||
_running = false;
|
||||
delete _i2s;
|
||||
|
|
@ -277,13 +242,7 @@ bool I2S::begin() {
|
|||
return false;
|
||||
}
|
||||
if (_isOutput) {
|
||||
if (_isInput) {
|
||||
if (_isTDM) {
|
||||
pio_tdm_inout_program_init(_pio, _sm, off, _pinDIN, _pinDOUT, _pinBCLK, _bps, _swapClocks, _tdmChannels);
|
||||
} else {
|
||||
pio_i2s_inout_program_init(_pio, _sm, off, _pinDIN, _pinDOUT, _pinBCLK, _bps, _swapClocks);
|
||||
}
|
||||
} else if (_isTDM) {
|
||||
if (_isTDM) {
|
||||
pio_tdm_out_program_init(_pio, _sm, off, _pinDOUT, _pinBCLK, _bps, _swapClocks, _tdmChannels);
|
||||
} else if (_isLSBJ) {
|
||||
pio_lsbj_out_program_init(_pio, _sm, off, _pinDOUT, _pinBCLK, _bps, _swapClocks);
|
||||
|
|
@ -291,7 +250,7 @@ bool I2S::begin() {
|
|||
pio_i2s_out_program_init(_pio, _sm, off, _pinDOUT, _pinBCLK, _bps, _swapClocks);
|
||||
}
|
||||
} else {
|
||||
pio_i2s_in_program_init(_pio, _sm, off, _pinDIN, _pinBCLK, _bps, _swapClocks);
|
||||
pio_i2s_in_program_init(_pio, _sm, off, _pinDOUT, _pinBCLK, _bps, _swapClocks);
|
||||
}
|
||||
setFrequency(_freq);
|
||||
if (_MCLKenabled) {
|
||||
|
|
@ -307,39 +266,19 @@ bool I2S::begin() {
|
|||
if (!_bufferWords) {
|
||||
_bufferWords = 64 * (_bps == 32 ? 2 : 1);
|
||||
}
|
||||
if (_isInput) {
|
||||
_arbInput = new AudioBufferManager(_buffers, _bufferWords, _silenceSample, INPUT);
|
||||
if (!_arbInput->begin(pio_get_dreq(_pio, _sm, false), (volatile void*)&_pio->rxf[_sm])) {
|
||||
_running = false;
|
||||
delete _arbInput;
|
||||
_arbInput = nullptr;
|
||||
delete _i2s;
|
||||
_i2s = nullptr;
|
||||
return false;
|
||||
}
|
||||
if (_cbdInput) {
|
||||
_arbInput->setCallback(_cbdInput, _cbdataInput);
|
||||
} else {
|
||||
_arbInput->setCallback(_cbInput);
|
||||
}
|
||||
_arb = new AudioBufferManager(_buffers, _bufferWords, _silenceSample, _isOutput ? OUTPUT : INPUT);
|
||||
if (!_arb->begin(pio_get_dreq(_pio, _sm, _isOutput), _isOutput ? &_pio->txf[_sm] : (volatile void*)&_pio->rxf[_sm])) {
|
||||
_running = false;
|
||||
delete _arb;
|
||||
_arb = nullptr;
|
||||
delete _i2s;
|
||||
_i2s = nullptr;
|
||||
return false;
|
||||
}
|
||||
if (_isOutput) {
|
||||
_arbOutput = new AudioBufferManager(_buffers, _bufferWords, _silenceSample, OUTPUT);
|
||||
if (!_arbOutput->begin(pio_get_dreq(_pio, _sm, true), &_pio->txf[_sm])) {
|
||||
_running = false;
|
||||
delete _arbOutput;
|
||||
_arbOutput = nullptr;
|
||||
delete _arbInput;
|
||||
_arbInput = nullptr;
|
||||
delete _i2s;
|
||||
_i2s = nullptr;
|
||||
return false;
|
||||
}
|
||||
if (_cbdOutput) {
|
||||
_arbOutput->setCallback(_cbdOutput, _cbdataOutput);
|
||||
} else {
|
||||
_arbOutput->setCallback(_cbOutput);
|
||||
}
|
||||
if (_cbd) {
|
||||
_arb->setCallback(_cbd, _cbdata);
|
||||
} else {
|
||||
_arb->setCallback(_cb);
|
||||
}
|
||||
pio_sm_set_enabled(_pio, _sm, true);
|
||||
|
||||
|
|
@ -355,10 +294,8 @@ bool I2S::end() {
|
|||
}
|
||||
pio_sm_set_enabled(_pio, _sm, false);
|
||||
_running = false;
|
||||
delete _arbOutput;
|
||||
_arbOutput = nullptr;
|
||||
delete _arbInput;
|
||||
_arbInput = nullptr;
|
||||
delete _arb;
|
||||
_arb = nullptr;
|
||||
delete _i2s;
|
||||
_i2s = nullptr;
|
||||
}
|
||||
|
|
@ -366,12 +303,12 @@ bool I2S::end() {
|
|||
}
|
||||
|
||||
int I2S::available() {
|
||||
if (!_running || !_isInput) {
|
||||
if (!_running) {
|
||||
return 0;
|
||||
} else {
|
||||
auto avail = _arbInput->available();
|
||||
avail *= 4; // 4 bytes per 32-bits
|
||||
if (_bps < 24) {
|
||||
auto avail = _arb->available();
|
||||
avail *= 4; // 4 samples per 32-bits
|
||||
if (_bps < 24 && !_isOutput) {
|
||||
avail += _isHolding / 8;
|
||||
}
|
||||
return avail;
|
||||
|
|
@ -379,7 +316,7 @@ int I2S::available() {
|
|||
}
|
||||
|
||||
int I2S::read() {
|
||||
if (!_running || !_isInput) {
|
||||
if (!_running || _isOutput) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
@ -415,7 +352,7 @@ int I2S::read() {
|
|||
}
|
||||
|
||||
int I2S::peek() {
|
||||
if (!_running || !_isInput) {
|
||||
if (!_running || _isOutput) {
|
||||
return 0;
|
||||
}
|
||||
if (!_hasPeeked) {
|
||||
|
|
@ -427,12 +364,7 @@ int I2S::peek() {
|
|||
|
||||
void I2S::flush() {
|
||||
if (_running) {
|
||||
if (_isOutput) {
|
||||
_arbOutput->flush();
|
||||
}
|
||||
if (_isInput) {
|
||||
_arbInput->flush();
|
||||
}
|
||||
_arb->flush();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -476,7 +408,7 @@ size_t I2S::write(int32_t val, bool sync) {
|
|||
if (!_running || !_isOutput) {
|
||||
return 0;
|
||||
}
|
||||
return _arbOutput->write(val, sync);
|
||||
return _arb->write(val, sync);
|
||||
}
|
||||
|
||||
size_t I2S::write8(int8_t l, int8_t r) {
|
||||
|
|
@ -509,14 +441,14 @@ size_t I2S::write32(int32_t l, int32_t r) {
|
|||
}
|
||||
|
||||
size_t I2S::read(int32_t *val, bool sync) {
|
||||
if (!_running || !_isInput) {
|
||||
if (!_running || _isOutput) {
|
||||
return 0;
|
||||
}
|
||||
return _arbInput->read((uint32_t *)val, sync);
|
||||
return _arb->read((uint32_t *)val, sync);
|
||||
}
|
||||
|
||||
bool I2S::read8(int8_t *l, int8_t *r) {
|
||||
if (!_running || !_isInput) {
|
||||
if (!_running || _isOutput) {
|
||||
return false;
|
||||
}
|
||||
if (_isHolding) {
|
||||
|
|
@ -533,7 +465,7 @@ bool I2S::read8(int8_t *l, int8_t *r) {
|
|||
}
|
||||
|
||||
bool I2S::read16(int16_t *l, int16_t *r) {
|
||||
if (!_running || !_isInput) {
|
||||
if (!_running || _isOutput) {
|
||||
return false;
|
||||
}
|
||||
int32_t o;
|
||||
|
|
@ -544,7 +476,7 @@ bool I2S::read16(int16_t *l, int16_t *r) {
|
|||
}
|
||||
|
||||
bool I2S::read24(int32_t *l, int32_t *r) {
|
||||
if (!_running || !_isInput) {
|
||||
if (!_running || _isOutput) {
|
||||
return false;
|
||||
}
|
||||
read32(l, r);
|
||||
|
|
@ -555,7 +487,7 @@ bool I2S::read24(int32_t *l, int32_t *r) {
|
|||
}
|
||||
|
||||
bool I2S::read32(int32_t *l, int32_t *r) {
|
||||
if (!_running || !_isInput) {
|
||||
if (!_running || _isOutput) {
|
||||
return false;
|
||||
}
|
||||
read(l, true);
|
||||
|
|
@ -563,31 +495,17 @@ bool I2S::read32(int32_t *l, int32_t *r) {
|
|||
return true;
|
||||
}
|
||||
|
||||
size_t I2S::read(uint8_t *buffer, size_t size) {
|
||||
// We can only read 32-bit chunks here
|
||||
if (size & 0x3 || !_running || !_isInput) {
|
||||
return 0;
|
||||
}
|
||||
return _arbInput->read((uint32_t *)buffer, size / sizeof(uint32_t), false);
|
||||
}
|
||||
|
||||
size_t I2S::write(const uint8_t *buffer, size_t size) {
|
||||
// We can only write 32-bit chunks here
|
||||
if (size & 0x3 || !_running || !_isOutput) {
|
||||
return 0;
|
||||
}
|
||||
return _arbOutput->write((const uint32_t *)buffer, size / sizeof(uint32_t), false);
|
||||
return _arb->write((const uint32_t *)buffer, size / sizeof(uint32_t), false);
|
||||
}
|
||||
|
||||
int I2S::availableForWrite() {
|
||||
if (!_running || !_isOutput) {
|
||||
return 0;
|
||||
} else {
|
||||
auto avail = _arbOutput->available();
|
||||
avail *= 4; // 4 bytes per 32-bits
|
||||
if (_bps < 24 && _isInput) {
|
||||
avail += _isHolding / 8;
|
||||
}
|
||||
return avail;
|
||||
}
|
||||
return available();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -26,13 +26,11 @@
|
|||
|
||||
class I2S : public Stream, public AudioOutputBase {
|
||||
public:
|
||||
I2S(PinMode direction = OUTPUT, pin_size_t bclk = 26, pin_size_t data = 28, pin_size_t mclk = 25, pin_size_t data_rx = 22);
|
||||
I2S(PinMode direction = OUTPUT, pin_size_t bclk = 26, pin_size_t data = 28, pin_size_t mclk = 25);
|
||||
virtual ~I2S();
|
||||
|
||||
bool setBCLK(pin_size_t pin);
|
||||
bool setDATA(pin_size_t pin);
|
||||
bool setDOUT(pin_size_t pin);
|
||||
bool setDIN(pin_size_t pin);
|
||||
bool setMCLK(pin_size_t pin);
|
||||
virtual bool setBitsPerSample(int bps) override;
|
||||
virtual bool setBuffers(size_t buffers, size_t bufferWords, int32_t silenceSample = 0) override;
|
||||
|
|
@ -54,6 +52,9 @@ public:
|
|||
|
||||
virtual bool begin() override;
|
||||
virtual bool end() override;
|
||||
virtual bool getUnderflow() override {
|
||||
return getOverUnderflow();
|
||||
}
|
||||
|
||||
// from Stream
|
||||
virtual int available() override;
|
||||
|
|
@ -70,21 +71,7 @@ public:
|
|||
if (!_running) {
|
||||
return false;
|
||||
} else {
|
||||
return _isOutput ? _arbOutput->getOverUnderflow() : _arbInput->getOverUnderflow();
|
||||
}
|
||||
}
|
||||
bool getOverflow() {
|
||||
if (!_running || !_isInput) {
|
||||
return false;
|
||||
} else {
|
||||
return _arbInput->getOverUnderflow();
|
||||
}
|
||||
}
|
||||
virtual bool getUnderflow() override {
|
||||
if (!_running || !_isOutput) {
|
||||
return false;
|
||||
} else {
|
||||
return _arbOutput->getOverUnderflow();
|
||||
return _arb->getOverUnderflow();
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -127,9 +114,6 @@ public:
|
|||
bool read24(int32_t *l, int32_t *r); // Note that 24b reads will be left-aligned (see above)
|
||||
bool read32(int32_t *l, int32_t *r);
|
||||
|
||||
// Read samples into buffer
|
||||
size_t read(uint8_t *buffer, size_t size);
|
||||
|
||||
// Note that these callback are called from **INTERRUPT CONTEXT** and hence
|
||||
// should be in RAM, not FLASH, and should be quick to execute.
|
||||
void onTransmit(void(*)(void));
|
||||
|
|
@ -140,7 +124,6 @@ public:
|
|||
private:
|
||||
pin_size_t _pinBCLK;
|
||||
pin_size_t _pinDOUT;
|
||||
pin_size_t _pinDIN;
|
||||
pin_size_t _pinMCLK;
|
||||
int _bps;
|
||||
int _freq;
|
||||
|
|
@ -151,7 +134,6 @@ private:
|
|||
bool _isLSBJ;
|
||||
bool _isTDM;
|
||||
int _tdmChannels;
|
||||
bool _isInput;
|
||||
bool _isOutput;
|
||||
bool _swapClocks;
|
||||
bool _MCLKenabled;
|
||||
|
|
@ -168,18 +150,13 @@ private:
|
|||
int32_t _holdWord = 0;
|
||||
int _isHolding = 0;
|
||||
|
||||
void (*_cbInput)();
|
||||
void (*_cbdInput)(void *);
|
||||
void *_cbdataInput;
|
||||
|
||||
void (*_cbOutput)();
|
||||
void (*_cbdOutput)(void *);
|
||||
void *_cbdataOutput;
|
||||
void (*_cb)();
|
||||
void (*_cbd)(void *);
|
||||
void *_cbdata;
|
||||
|
||||
void MCLKbegin();
|
||||
|
||||
AudioBufferManager *_arbInput;
|
||||
AudioBufferManager *_arbOutput;
|
||||
AudioBufferManager *_arb;
|
||||
PIOProgram *_i2s;
|
||||
PIOProgram *_i2sMCLK;
|
||||
PIO _pio, _pioMCLK;
|
||||
|
|
|
|||
|
|
@ -104,41 +104,6 @@ lastbit:
|
|||
; Loop back to the beginning
|
||||
|
||||
|
||||
.program pio_tdm_inout
|
||||
.side_set 2 ; 0 = bclk, 1 = wclk
|
||||
; The C code should place (number of bits * channels - 1) in Y and update SHIFTCTRL
|
||||
; to be 32 (as per the TDM specs)
|
||||
; +----- WCLK
|
||||
; |+---- BCLK
|
||||
mov x, y side 0b01 [1]
|
||||
bitloop:
|
||||
out pins, 1 side 0b00 ; Output changes on falling edge
|
||||
in pins, 1 side 0b00 ; Sample input on falling edge
|
||||
jmp x-- bitloop side 0b11 [1] ; Last bit toggles WCLK to mark frame boundary
|
||||
|
||||
lastbit:
|
||||
in pins, 1 side 0b10
|
||||
out pins, 1 side 0b10
|
||||
; Loop back to the beginning
|
||||
|
||||
|
||||
.program pio_tdm_inout_swap
|
||||
.side_set 2 ; 0 = bclk, 1 = wclk
|
||||
; The C code should place (number of bits * channels - 1) in Y and update SHIFTCTRL
|
||||
; to be 32 (as per the TDM specs)
|
||||
; +----- WCLK
|
||||
; |+---- BCLK
|
||||
mov x, y side 0b10 [1]
|
||||
bitloop:
|
||||
out pins, 1 side 0b00 ; Output changes on falling edge
|
||||
in pins, 1 side 0b00 ; Sample input on falling edge
|
||||
jmp x-- bitloop side 0b11 [1] ; Last bit toggles WCLK to mark frame boundary
|
||||
|
||||
lastbit:
|
||||
in pins, 1 side 0b01
|
||||
out pins, 1 side 0b01
|
||||
; Loop back to the beginning
|
||||
|
||||
|
||||
.program pio_lsbj_out
|
||||
.side_set 2 ; 0 = bclk, 1=wclk
|
||||
|
|
@ -229,58 +194,6 @@ right1:
|
|||
; Loop back to beginning...
|
||||
|
||||
|
||||
|
||||
.program pio_i2s_inout
|
||||
.side_set 2 ; 0 = bclk, 1=wclk
|
||||
|
||||
; The C code should place (number of bits/sample - 2) in Y and
|
||||
; also update the SHIFTCTRL to be 24 or 32 as appropriate
|
||||
|
||||
; +----- WCLK
|
||||
; |+---- BCLK
|
||||
mov x, y side 0b00 [1]
|
||||
left1:
|
||||
out pins, 1 side 0b01
|
||||
in pins, 1 side 0b01
|
||||
jmp x--, left1 side 0b00 [1]
|
||||
out pins, 1 side 0b01
|
||||
in pins, 1 side 0b01 ; 2584 LRCK stays low until BCLK goes low
|
||||
; Last bit of left has WCLK change per I2S spec
|
||||
mov x, y side 0b10 [1]
|
||||
right1:
|
||||
out pins, 1 side 0b11
|
||||
in pins, 1 side 0b11
|
||||
jmp x--, right1 side 0b10 [1]
|
||||
out pins, 1 side 0b11
|
||||
in pins, 1 side 0b11 ; 2584 LRCK stays high until BCLK goes low
|
||||
; Loop back to beginning...
|
||||
|
||||
|
||||
.program pio_i2s_inout_swap ; Note this is the same as _out, just "in" and not "out"
|
||||
.side_set 2 ; 0 = wclk, 1=bclk
|
||||
|
||||
; The C code should place (number of bits/sample - 2) in Y and
|
||||
; also update the SHIFTCTRL to be 24 or 32 as appropriate
|
||||
|
||||
; +----- BCLK
|
||||
; |+---- WCLK
|
||||
mov x, y side 0b00 [1]
|
||||
left1:
|
||||
out pins, 1 side 0b10
|
||||
in pins, 1 side 0b10
|
||||
jmp x--, left1 side 0b00 [1]
|
||||
out pins, 1 side 0b10
|
||||
in pins, 1 side 0b10 ;2584 LRCK stays low until BCLK goes low
|
||||
|
||||
mov x, y side 0b01 [1]
|
||||
right1:
|
||||
out pins, 1 side 0b11
|
||||
in pins, 1 side 0b11
|
||||
jmp x--, right1 side 0b01 [1]
|
||||
out pins, 1 side 0b11
|
||||
in pins, 1 side 0b11 ; 2584 LRCK stays high until BCLK goes low
|
||||
; Loop back to beginning...
|
||||
|
||||
|
||||
|
||||
% c-sdk {
|
||||
|
|
@ -348,42 +261,6 @@ static inline void pio_tdm_out_program_init(PIO pio, uint sm, uint offset, uint
|
|||
pio_sm_exec(pio, sm, pio_encode_out(pio_osr, 32));
|
||||
}
|
||||
|
||||
static inline void pio_tdm_inout_program_init(PIO pio, uint sm, uint offset, uint data_in_pin, uint data_out_pin, uint clock_pin_base, uint bits, bool swap, uint channels) {
|
||||
pio_gpio_init(pio, data_in_pin);
|
||||
pio_gpio_init(pio, data_out_pin);
|
||||
pio_gpio_init(pio, clock_pin_base);
|
||||
pio_gpio_init(pio, clock_pin_base + 1);
|
||||
|
||||
pio_sm_config c = swap ? pio_tdm_inout_swap_program_get_default_config(offset) : pio_tdm_inout_program_get_default_config(offset);
|
||||
|
||||
sm_config_set_in_pins(&c, data_in_pin);
|
||||
sm_config_set_out_pins(&c, data_out_pin, 1);
|
||||
sm_config_set_sideset_pins(&c, clock_pin_base);
|
||||
sm_config_set_in_shift(&c, false, true, 32);
|
||||
sm_config_set_out_shift(&c, false, true, 32);
|
||||
sm_config_set_fifo_join(&c, PIO_FIFO_JOIN_NONE);
|
||||
|
||||
pio_sm_init(pio, sm, offset, &c);
|
||||
|
||||
pio_sm_set_consecutive_pindirs(pio, sm, data_in_pin, 1, false);
|
||||
pio_sm_set_consecutive_pindirs(pio, sm, data_out_pin, 1, true);
|
||||
pio_sm_set_consecutive_pindirs(pio, sm, clock_pin_base, 2, true);
|
||||
pio_sm_set_set_pins(pio, sm, data_out_pin, 1);
|
||||
pio_sm_set_set_pins(pio, sm, clock_pin_base, 2);
|
||||
|
||||
// Initialize PIO state for TDM
|
||||
// Can't set constant > 31, so push and pop/mov if needed
|
||||
if (bits * channels - 1 > 31) {
|
||||
pio_sm_put_blocking(pio, sm, bits * channels - 2);
|
||||
pio_sm_exec(pio, sm, pio_encode_pull(false, false));
|
||||
pio_sm_exec(pio, sm, pio_encode_mov(pio_y, pio_osr));
|
||||
} else {
|
||||
pio_sm_exec(pio, sm, pio_encode_set(pio_y, bits * channels - 2));
|
||||
}
|
||||
|
||||
// Need to make OSR believe there's nothing left to shift out
|
||||
pio_sm_exec(pio, sm, pio_encode_out(pio_osr, 32));
|
||||
}
|
||||
|
||||
static inline void pio_lsbj_out_program_init(PIO pio, uint sm, uint offset, uint data_pin, uint clock_pin_base, uint bits, bool swap) {
|
||||
pio_gpio_init(pio, data_pin);
|
||||
|
|
@ -437,35 +314,4 @@ static inline void pio_i2s_in_program_init(PIO pio, uint sm, uint offset, uint d
|
|||
pio_sm_exec(pio, sm, pio_encode_in(pio_pins, bits - 1)); // Shift in 1st R data modulo one bit, avoiding bit shift from #2037
|
||||
}
|
||||
|
||||
static inline void pio_i2s_inout_program_init(PIO pio, uint sm, uint offset, uint data_in_pin, uint data_out_pin, uint clock_pin_base, uint bits, bool swap) {
|
||||
pio_gpio_init(pio, data_in_pin);
|
||||
pio_gpio_init(pio, data_out_pin);
|
||||
pio_gpio_init(pio, clock_pin_base);
|
||||
pio_gpio_init(pio, clock_pin_base + 1);
|
||||
|
||||
pio_sm_config sm_config = swap ? pio_i2s_inout_swap_program_get_default_config(offset) : pio_i2s_inout_program_get_default_config(offset);
|
||||
|
||||
sm_config_set_in_pins(&sm_config, data_in_pin);
|
||||
sm_config_set_out_pins(&sm_config, data_out_pin, 1);
|
||||
sm_config_set_sideset_pins(&sm_config, clock_pin_base);
|
||||
sm_config_set_in_shift(&sm_config, false, true, (bits <= 16) ? 2 * bits : bits);
|
||||
sm_config_set_out_shift(&sm_config, false, true, (bits <= 16) ? 2 * bits : bits);
|
||||
|
||||
pio_sm_init(pio, sm, offset, &sm_config);
|
||||
|
||||
//uint pin_mask = (1u << data_out_pin) | (3u << clock_pin_base);
|
||||
//pio_sm_set_pindirs_with_mask(pio, sm, pin_mask, pin_mask);
|
||||
//pio_sm_set_pins(pio, sm, 0); // clear pins
|
||||
pio_sm_set_consecutive_pindirs(pio, sm, data_in_pin, 1, false);
|
||||
pio_sm_set_consecutive_pindirs(pio, sm, data_out_pin, 1, true);
|
||||
pio_sm_set_consecutive_pindirs(pio, sm, clock_pin_base, 2, true);
|
||||
pio_sm_set_set_pins(pio, sm, data_out_pin, 1);
|
||||
pio_sm_set_set_pins(pio, sm, clock_pin_base, 2);
|
||||
|
||||
pio_sm_exec(pio, sm, pio_encode_set(pio_y, bits - 2));
|
||||
|
||||
pio_sm_exec(pio, sm, pio_encode_in(pio_pins, bits)); // Shift in 1st L data
|
||||
pio_sm_exec(pio, sm, pio_encode_in(pio_pins, bits - 1)); // Shift in 1st R data modulo one bit, avoiding bit shift from #2037
|
||||
}
|
||||
|
||||
%}
|
||||
|
|
|
|||
|
|
@ -28,7 +28,7 @@ static const struct pio_program pio_i2s_mclk_program = {
|
|||
.instructions = pio_i2s_mclk_program_instructions,
|
||||
.length = 2,
|
||||
.origin = -1,
|
||||
.pio_version = pio_i2s_mclk_pio_version,
|
||||
.pio_version = 0,
|
||||
#if PICO_PIO_VERSION > 0
|
||||
.used_gpio_ranges = 0x0
|
||||
#endif
|
||||
|
|
@ -67,7 +67,7 @@ static const struct pio_program pio_i2s_out_program = {
|
|||
.instructions = pio_i2s_out_program_instructions,
|
||||
.length = 8,
|
||||
.origin = -1,
|
||||
.pio_version = pio_i2s_out_pio_version,
|
||||
.pio_version = 0,
|
||||
#if PICO_PIO_VERSION > 0
|
||||
.used_gpio_ranges = 0x0
|
||||
#endif
|
||||
|
|
@ -107,7 +107,7 @@ static const struct pio_program pio_i2s_out_swap_program = {
|
|||
.instructions = pio_i2s_out_swap_program_instructions,
|
||||
.length = 8,
|
||||
.origin = -1,
|
||||
.pio_version = pio_i2s_out_swap_pio_version,
|
||||
.pio_version = 0,
|
||||
#if PICO_PIO_VERSION > 0
|
||||
.used_gpio_ranges = 0x0
|
||||
#endif
|
||||
|
|
@ -143,7 +143,7 @@ static const struct pio_program pio_tdm_out_program = {
|
|||
.instructions = pio_tdm_out_program_instructions,
|
||||
.length = 4,
|
||||
.origin = -1,
|
||||
.pio_version = pio_tdm_out_pio_version,
|
||||
.pio_version = 0,
|
||||
#if PICO_PIO_VERSION > 0
|
||||
.used_gpio_ranges = 0x0
|
||||
#endif
|
||||
|
|
@ -179,7 +179,7 @@ static const struct pio_program pio_tdm_out_swap_program = {
|
|||
.instructions = pio_tdm_out_swap_program_instructions,
|
||||
.length = 4,
|
||||
.origin = -1,
|
||||
.pio_version = pio_tdm_out_swap_pio_version,
|
||||
.pio_version = 0,
|
||||
#if PICO_PIO_VERSION > 0
|
||||
.used_gpio_ranges = 0x0
|
||||
#endif
|
||||
|
|
@ -193,82 +193,6 @@ static inline pio_sm_config pio_tdm_out_swap_program_get_default_config(uint off
|
|||
}
|
||||
#endif
|
||||
|
||||
// ------------- //
|
||||
// pio_tdm_inout //
|
||||
// ------------- //
|
||||
|
||||
#define pio_tdm_inout_wrap_target 0
|
||||
#define pio_tdm_inout_wrap 5
|
||||
#define pio_tdm_inout_pio_version 0
|
||||
|
||||
static const uint16_t pio_tdm_inout_program_instructions[] = {
|
||||
// .wrap_target
|
||||
0xa922, // 0: mov x, y side 1 [1]
|
||||
0x6001, // 1: out pins, 1 side 0
|
||||
0x4001, // 2: in pins, 1 side 0
|
||||
0x1941, // 3: jmp x--, 1 side 3 [1]
|
||||
0x5001, // 4: in pins, 1 side 2
|
||||
0x7001, // 5: out pins, 1 side 2
|
||||
// .wrap
|
||||
};
|
||||
|
||||
#if !PICO_NO_HARDWARE
|
||||
static const struct pio_program pio_tdm_inout_program = {
|
||||
.instructions = pio_tdm_inout_program_instructions,
|
||||
.length = 6,
|
||||
.origin = -1,
|
||||
.pio_version = pio_tdm_inout_pio_version,
|
||||
#if PICO_PIO_VERSION > 0
|
||||
.used_gpio_ranges = 0x0
|
||||
#endif
|
||||
};
|
||||
|
||||
static inline pio_sm_config pio_tdm_inout_program_get_default_config(uint offset) {
|
||||
pio_sm_config c = pio_get_default_sm_config();
|
||||
sm_config_set_wrap(&c, offset + pio_tdm_inout_wrap_target, offset + pio_tdm_inout_wrap);
|
||||
sm_config_set_sideset(&c, 2, false, false);
|
||||
return c;
|
||||
}
|
||||
#endif
|
||||
|
||||
// ------------------ //
|
||||
// pio_tdm_inout_swap //
|
||||
// ------------------ //
|
||||
|
||||
#define pio_tdm_inout_swap_wrap_target 0
|
||||
#define pio_tdm_inout_swap_wrap 5
|
||||
#define pio_tdm_inout_swap_pio_version 0
|
||||
|
||||
static const uint16_t pio_tdm_inout_swap_program_instructions[] = {
|
||||
// .wrap_target
|
||||
0xb122, // 0: mov x, y side 2 [1]
|
||||
0x6001, // 1: out pins, 1 side 0
|
||||
0x4001, // 2: in pins, 1 side 0
|
||||
0x1941, // 3: jmp x--, 1 side 3 [1]
|
||||
0x4801, // 4: in pins, 1 side 1
|
||||
0x6801, // 5: out pins, 1 side 1
|
||||
// .wrap
|
||||
};
|
||||
|
||||
#if !PICO_NO_HARDWARE
|
||||
static const struct pio_program pio_tdm_inout_swap_program = {
|
||||
.instructions = pio_tdm_inout_swap_program_instructions,
|
||||
.length = 6,
|
||||
.origin = -1,
|
||||
.pio_version = pio_tdm_inout_swap_pio_version,
|
||||
#if PICO_PIO_VERSION > 0
|
||||
.used_gpio_ranges = 0x0
|
||||
#endif
|
||||
};
|
||||
|
||||
static inline pio_sm_config pio_tdm_inout_swap_program_get_default_config(uint offset) {
|
||||
pio_sm_config c = pio_get_default_sm_config();
|
||||
sm_config_set_wrap(&c, offset + pio_tdm_inout_swap_wrap_target, offset + pio_tdm_inout_swap_wrap);
|
||||
sm_config_set_sideset(&c, 2, false, false);
|
||||
return c;
|
||||
}
|
||||
#endif
|
||||
|
||||
// ------------ //
|
||||
// pio_lsbj_out //
|
||||
// ------------ //
|
||||
|
|
@ -295,7 +219,7 @@ static const struct pio_program pio_lsbj_out_program = {
|
|||
.instructions = pio_lsbj_out_program_instructions,
|
||||
.length = 8,
|
||||
.origin = -1,
|
||||
.pio_version = pio_lsbj_out_pio_version,
|
||||
.pio_version = 0,
|
||||
#if PICO_PIO_VERSION > 0
|
||||
.used_gpio_ranges = 0x0
|
||||
#endif
|
||||
|
|
@ -335,7 +259,7 @@ static const struct pio_program pio_lsbj_out_swap_program = {
|
|||
.instructions = pio_lsbj_out_swap_program_instructions,
|
||||
.length = 8,
|
||||
.origin = -1,
|
||||
.pio_version = pio_lsbj_out_swap_pio_version,
|
||||
.pio_version = 0,
|
||||
#if PICO_PIO_VERSION > 0
|
||||
.used_gpio_ranges = 0x0
|
||||
#endif
|
||||
|
|
@ -375,7 +299,7 @@ static const struct pio_program pio_i2s_in_program = {
|
|||
.instructions = pio_i2s_in_program_instructions,
|
||||
.length = 8,
|
||||
.origin = -1,
|
||||
.pio_version = pio_i2s_in_pio_version,
|
||||
.pio_version = 0,
|
||||
#if PICO_PIO_VERSION > 0
|
||||
.used_gpio_ranges = 0x0
|
||||
#endif
|
||||
|
|
@ -415,7 +339,7 @@ static const struct pio_program pio_i2s_in_swap_program = {
|
|||
.instructions = pio_i2s_in_swap_program_instructions,
|
||||
.length = 8,
|
||||
.origin = -1,
|
||||
.pio_version = pio_i2s_in_swap_pio_version,
|
||||
.pio_version = 0,
|
||||
#if PICO_PIO_VERSION > 0
|
||||
.used_gpio_ranges = 0x0
|
||||
#endif
|
||||
|
|
@ -427,94 +351,6 @@ static inline pio_sm_config pio_i2s_in_swap_program_get_default_config(uint offs
|
|||
sm_config_set_sideset(&c, 2, false, false);
|
||||
return c;
|
||||
}
|
||||
#endif
|
||||
|
||||
// ------------- //
|
||||
// pio_i2s_inout //
|
||||
// ------------- //
|
||||
|
||||
#define pio_i2s_inout_wrap_target 0
|
||||
#define pio_i2s_inout_wrap 11
|
||||
#define pio_i2s_inout_pio_version 0
|
||||
|
||||
static const uint16_t pio_i2s_inout_program_instructions[] = {
|
||||
// .wrap_target
|
||||
0xa122, // 0: mov x, y side 0 [1]
|
||||
0x6801, // 1: out pins, 1 side 1
|
||||
0x4801, // 2: in pins, 1 side 1
|
||||
0x0141, // 3: jmp x--, 1 side 0 [1]
|
||||
0x6801, // 4: out pins, 1 side 1
|
||||
0x4801, // 5: in pins, 1 side 1
|
||||
0xb122, // 6: mov x, y side 2 [1]
|
||||
0x7801, // 7: out pins, 1 side 3
|
||||
0x5801, // 8: in pins, 1 side 3
|
||||
0x1147, // 9: jmp x--, 7 side 2 [1]
|
||||
0x7801, // 10: out pins, 1 side 3
|
||||
0x5801, // 11: in pins, 1 side 3
|
||||
// .wrap
|
||||
};
|
||||
|
||||
#if !PICO_NO_HARDWARE
|
||||
static const struct pio_program pio_i2s_inout_program = {
|
||||
.instructions = pio_i2s_inout_program_instructions,
|
||||
.length = 12,
|
||||
.origin = -1,
|
||||
.pio_version = pio_i2s_inout_pio_version,
|
||||
#if PICO_PIO_VERSION > 0
|
||||
.used_gpio_ranges = 0x0
|
||||
#endif
|
||||
};
|
||||
|
||||
static inline pio_sm_config pio_i2s_inout_program_get_default_config(uint offset) {
|
||||
pio_sm_config c = pio_get_default_sm_config();
|
||||
sm_config_set_wrap(&c, offset + pio_i2s_inout_wrap_target, offset + pio_i2s_inout_wrap);
|
||||
sm_config_set_sideset(&c, 2, false, false);
|
||||
return c;
|
||||
}
|
||||
#endif
|
||||
|
||||
// ------------------ //
|
||||
// pio_i2s_inout_swap //
|
||||
// ------------------ //
|
||||
|
||||
#define pio_i2s_inout_swap_wrap_target 0
|
||||
#define pio_i2s_inout_swap_wrap 11
|
||||
#define pio_i2s_inout_swap_pio_version 0
|
||||
|
||||
static const uint16_t pio_i2s_inout_swap_program_instructions[] = {
|
||||
// .wrap_target
|
||||
0xa122, // 0: mov x, y side 0 [1]
|
||||
0x7001, // 1: out pins, 1 side 2
|
||||
0x5001, // 2: in pins, 1 side 2
|
||||
0x0141, // 3: jmp x--, 1 side 0 [1]
|
||||
0x7001, // 4: out pins, 1 side 2
|
||||
0x5001, // 5: in pins, 1 side 2
|
||||
0xa922, // 6: mov x, y side 1 [1]
|
||||
0x7801, // 7: out pins, 1 side 3
|
||||
0x5801, // 8: in pins, 1 side 3
|
||||
0x0947, // 9: jmp x--, 7 side 1 [1]
|
||||
0x7801, // 10: out pins, 1 side 3
|
||||
0x5801, // 11: in pins, 1 side 3
|
||||
// .wrap
|
||||
};
|
||||
|
||||
#if !PICO_NO_HARDWARE
|
||||
static const struct pio_program pio_i2s_inout_swap_program = {
|
||||
.instructions = pio_i2s_inout_swap_program_instructions,
|
||||
.length = 12,
|
||||
.origin = -1,
|
||||
.pio_version = pio_i2s_inout_swap_pio_version,
|
||||
#if PICO_PIO_VERSION > 0
|
||||
.used_gpio_ranges = 0x0
|
||||
#endif
|
||||
};
|
||||
|
||||
static inline pio_sm_config pio_i2s_inout_swap_program_get_default_config(uint offset) {
|
||||
pio_sm_config c = pio_get_default_sm_config();
|
||||
sm_config_set_wrap(&c, offset + pio_i2s_inout_swap_wrap_target, offset + pio_i2s_inout_swap_wrap);
|
||||
sm_config_set_sideset(&c, 2, false, false);
|
||||
return c;
|
||||
}
|
||||
|
||||
static inline void pio_i2s_MCLK_program_init(PIO pio, uint sm, uint offset, uint MCLK_pin) {
|
||||
pio_gpio_init(pio, MCLK_pin);
|
||||
|
|
@ -566,36 +402,6 @@ static inline void pio_tdm_out_program_init(PIO pio, uint sm, uint offset, uint
|
|||
// Need to make OSR believe there's nothing left to shift out, or the 1st word will be the count we just passed in, not a sample
|
||||
pio_sm_exec(pio, sm, pio_encode_out(pio_osr, 32));
|
||||
}
|
||||
static inline void pio_tdm_inout_program_init(PIO pio, uint sm, uint offset, uint data_in_pin, uint data_out_pin, uint clock_pin_base, uint bits, bool swap, uint channels) {
|
||||
pio_gpio_init(pio, data_in_pin);
|
||||
pio_gpio_init(pio, data_out_pin);
|
||||
pio_gpio_init(pio, clock_pin_base);
|
||||
pio_gpio_init(pio, clock_pin_base + 1);
|
||||
pio_sm_config c = swap ? pio_tdm_inout_swap_program_get_default_config(offset) : pio_tdm_inout_program_get_default_config(offset);
|
||||
sm_config_set_in_pins(&c, data_in_pin);
|
||||
sm_config_set_out_pins(&c, data_out_pin, 1);
|
||||
sm_config_set_sideset_pins(&c, clock_pin_base);
|
||||
sm_config_set_in_shift(&c, false, true, 32);
|
||||
sm_config_set_out_shift(&c, false, true, 32);
|
||||
sm_config_set_fifo_join(&c, PIO_FIFO_JOIN_NONE);
|
||||
pio_sm_init(pio, sm, offset, &c);
|
||||
pio_sm_set_consecutive_pindirs(pio, sm, data_in_pin, 1, false);
|
||||
pio_sm_set_consecutive_pindirs(pio, sm, data_out_pin, 1, true);
|
||||
pio_sm_set_consecutive_pindirs(pio, sm, clock_pin_base, 2, true);
|
||||
pio_sm_set_set_pins(pio, sm, data_out_pin, 1);
|
||||
pio_sm_set_set_pins(pio, sm, clock_pin_base, 2);
|
||||
// Initialize PIO state for TDM
|
||||
// Can't set constant > 31, so push and pop/mov if needed
|
||||
if (bits * channels - 1 > 31) {
|
||||
pio_sm_put_blocking(pio, sm, bits * channels - 2);
|
||||
pio_sm_exec(pio, sm, pio_encode_pull(false, false));
|
||||
pio_sm_exec(pio, sm, pio_encode_mov(pio_y, pio_osr));
|
||||
} else {
|
||||
pio_sm_exec(pio, sm, pio_encode_set(pio_y, bits * channels - 2));
|
||||
}
|
||||
// Need to make OSR believe there's nothing left to shift out
|
||||
pio_sm_exec(pio, sm, pio_encode_out(pio_osr, 32));
|
||||
}
|
||||
static inline void pio_lsbj_out_program_init(PIO pio, uint sm, uint offset, uint data_pin, uint clock_pin_base, uint bits, bool swap) {
|
||||
pio_gpio_init(pio, data_pin);
|
||||
pio_gpio_init(pio, clock_pin_base);
|
||||
|
|
@ -635,30 +441,6 @@ static inline void pio_i2s_in_program_init(PIO pio, uint sm, uint offset, uint d
|
|||
pio_sm_exec(pio, sm, pio_encode_in(pio_pins, bits)); // Shift in 1st L data
|
||||
pio_sm_exec(pio, sm, pio_encode_in(pio_pins, bits - 1)); // Shift in 1st R data modulo one bit, avoiding bit shift from #2037
|
||||
}
|
||||
static inline void pio_i2s_inout_program_init(PIO pio, uint sm, uint offset, uint data_in_pin, uint data_out_pin, uint clock_pin_base, uint bits, bool swap) {
|
||||
pio_gpio_init(pio, data_in_pin);
|
||||
pio_gpio_init(pio, data_out_pin);
|
||||
pio_gpio_init(pio, clock_pin_base);
|
||||
pio_gpio_init(pio, clock_pin_base + 1);
|
||||
pio_sm_config sm_config = swap ? pio_i2s_inout_swap_program_get_default_config(offset) : pio_i2s_inout_program_get_default_config(offset);
|
||||
sm_config_set_in_pins(&sm_config, data_in_pin);
|
||||
sm_config_set_out_pins(&sm_config, data_out_pin, 1);
|
||||
sm_config_set_sideset_pins(&sm_config, clock_pin_base);
|
||||
sm_config_set_in_shift(&sm_config, false, true, (bits <= 16) ? 2 * bits : bits);
|
||||
sm_config_set_out_shift(&sm_config, false, true, (bits <= 16) ? 2 * bits : bits);
|
||||
pio_sm_init(pio, sm, offset, &sm_config);
|
||||
//uint pin_mask = (1u << data_out_pin) | (3u << clock_pin_base);
|
||||
//pio_sm_set_pindirs_with_mask(pio, sm, pin_mask, pin_mask);
|
||||
//pio_sm_set_pins(pio, sm, 0); // clear pins
|
||||
pio_sm_set_consecutive_pindirs(pio, sm, data_in_pin, 1, false);
|
||||
pio_sm_set_consecutive_pindirs(pio, sm, data_out_pin, 1, true);
|
||||
pio_sm_set_consecutive_pindirs(pio, sm, clock_pin_base, 2, true);
|
||||
pio_sm_set_set_pins(pio, sm, data_out_pin, 1);
|
||||
pio_sm_set_set_pins(pio, sm, clock_pin_base, 2);
|
||||
pio_sm_exec(pio, sm, pio_encode_set(pio_y, bits - 2));
|
||||
pio_sm_exec(pio, sm, pio_encode_in(pio_pins, bits)); // Shift in 1st L data
|
||||
pio_sm_exec(pio, sm, pio_encode_in(pio_pins, bits - 1)); // Shift in 1st R data modulo one bit, avoiding bit shift from #2037
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
|
|
|
|||
|
|
@ -161,7 +161,7 @@ bool MDNSResponder::_prepareMDNSMessage(MDNSResponder::stcMDNSSendParameter& p_r
|
|||
// Prepare header; count answers
|
||||
stcMDNS_MsgHeader msgHeader(p_rSendParameter.m_u16ID, p_rSendParameter.m_bResponse, 0,
|
||||
p_rSendParameter.m_bAuthorative);
|
||||
// If this is a response, the answers are answers,
|
||||
// If this is a response, the answers are anwers,
|
||||
// else this is a query or probe and the answers go into auth section
|
||||
uint16_t& ru16Answers
|
||||
= (p_rSendParameter.m_bResponse ? msgHeader.m_u16ANCount : msgHeader.m_u16NSCount);
|
||||
|
|
|
|||
|
|
@ -1 +1 @@
|
|||
Subproject commit 8ed63b27be79ab59ee1cd15a950ddd64e7a602f7
|
||||
Subproject commit d01280e64934a09ba16cac60cf9d3a37e228bb66
|
||||
|
|
@ -31,7 +31,7 @@ static inline void pdm_pio_program_init(PIO pio, uint sm, uint offset, uint clkP
|
|||
pio_sm_set_consecutive_pindirs(pio, sm, dataPin, 1, false);
|
||||
pio_sm_set_consecutive_pindirs(pio, sm, clkPin, 1, true);
|
||||
pio_sm_set_pins_with_mask(pio, sm, 0, (1u << clkPin) );
|
||||
pio_gpio_init(pio, dataPin);
|
||||
//pio_gpio_init(pio, dataPin);
|
||||
pio_gpio_init(pio, clkPin);
|
||||
|
||||
pio_sm_init(pio, sm, offset, &c);
|
||||
|
|
|
|||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Reference in a new issue