Add style check matching RP2040 core (#740)

Will let us backport the BackgroundAudio patches to libhelix easier and clean
up some ugly formatting we've let develop.
This commit is contained in:
Earle F. Philhower, III authored and GitHub committed 2025-04-11 12:09:49 -07:00
1 parent 62dd23a74a
commit f9e72dbb21
434 files changed
+94604 -93082

No files matched your search

+47 -47
View File
@@ -1,25 +1,25 @@
/*
AudioFileSourceSPIRAMBuffer
Buffered file source in external SPI RAM
AudioFileSourceSPIRAMBuffer
Buffered file source in external SPI RAM
Copyright (C) 2017 Sebastien Decourriere
Based on AudioFileSourceBuffer class from Earle F. Philhower, III
Copyright (C) 2017 Sebastien Decourriere
Based on AudioFileSourceBuffer class from Earle F. Philhower, III
Copyright (C) 2020 Earle F. Philhower, III
Rewritten for speed and functionality
Copyright (C) 2020 Earle F. Philhower, III
Rewritten for speed and functionality
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#if defined(ESP32) || defined(ESP8266)
@@ -29,8 +29,7 @@
#pragma GCC optimize ("O3")
AudioFileSourceSPIRAMBuffer::AudioFileSourceSPIRAMBuffer(AudioFileSource *source, uint8_t csPin, uint32_t buffSizeBytes)
{
AudioFileSourceSPIRAMBuffer::AudioFileSourceSPIRAMBuffer(AudioFileSource *source, uint8_t csPin, uint32_t buffSizeBytes) {
ram.begin(40, csPin);
ramSize = buffSizeBytes;
writePtr = 0;
@@ -40,13 +39,11 @@ AudioFileSourceSPIRAMBuffer::AudioFileSourceSPIRAMBuffer(AudioFileSource *source
audioLogger->printf_P(PSTR("SPI RAM buffer size: %u Bytes\n"), ramSize);
}
AudioFileSourceSPIRAMBuffer::~AudioFileSourceSPIRAMBuffer()
{
AudioFileSourceSPIRAMBuffer::~AudioFileSourceSPIRAMBuffer() {
ram.end();
}
bool AudioFileSourceSPIRAMBuffer::seek(int32_t pos, int dir)
{
bool AudioFileSourceSPIRAMBuffer::seek(int32_t pos, int dir) {
// Invalidate
readPtr = 0;
writePtr = 0;
@@ -54,28 +51,23 @@ bool AudioFileSourceSPIRAMBuffer::seek(int32_t pos, int dir)
return src->seek(pos, dir);
}
bool AudioFileSourceSPIRAMBuffer::close()
{
bool AudioFileSourceSPIRAMBuffer::close() {
return src->close();
}
bool AudioFileSourceSPIRAMBuffer::isOpen()
{
bool AudioFileSourceSPIRAMBuffer::isOpen() {
return src->isOpen();
}
uint32_t AudioFileSourceSPIRAMBuffer::getSize()
{
uint32_t AudioFileSourceSPIRAMBuffer::getSize() {
return src->getSize();
}
uint32_t AudioFileSourceSPIRAMBuffer::getPos()
{
uint32_t AudioFileSourceSPIRAMBuffer::getPos() {
return src->getPos() - (writePtr - readPtr);
}
uint32_t AudioFileSourceSPIRAMBuffer::read(void *data, uint32_t len)
{
uint32_t AudioFileSourceSPIRAMBuffer::read(void *data, uint32_t len) {
uint32_t bytes = 0;
// Check if the buffer isn't empty, otherwise we try to fill completely
@@ -90,7 +82,9 @@ uint32_t AudioFileSourceSPIRAMBuffer::read(void *data, uint32_t len)
int length = src->read(buffer, toRead);
if (length > 0) {
#ifdef FAKERAM
for (size_t i=0; i<length; i++) fakeRAM[(i+writePtr)%ramSize] = buffer[i];
for (size_t i = 0; i < length; i++) {
fakeRAM[(i + writePtr) % ramSize] = buffer[i];
}
#else
ram.writeBytes(writePtr % ramSize, buffer, length);
#endif
@@ -109,7 +103,9 @@ uint32_t AudioFileSourceSPIRAMBuffer::read(void *data, uint32_t len)
uint8_t *ptr = reinterpret_cast<uint8_t*>(data);
if (toReadFromBuffer > 0) {
#ifdef FAKERAM
for (size_t i=0; i<toReadFromBuffer; i++) ptr[i] = fakeRAM[(i+readPtr)%ramSize];
for (size_t i = 0; i < toReadFromBuffer; i++) {
ptr[i] = fakeRAM[(i + readPtr) % ramSize];
}
#else
ram.readBytes(readPtr % ramSize, ptr, toReadFromBuffer);
#endif
@@ -128,12 +124,13 @@ uint32_t AudioFileSourceSPIRAMBuffer::read(void *data, uint32_t len)
return bytes;
}
void AudioFileSourceSPIRAMBuffer::fill()
{
void AudioFileSourceSPIRAMBuffer::fill() {
// Make sure the buffer is pre-filled before make partial fill.
if (!filled) return;
if (!filled) {
return;
}
for (auto i=0; i<5; i++) {
for (auto i = 0; i < 5; i++) {
// Make sure there is at least buffer size free in RAM
uint8_t buffer[128];
if ((ramSize - (writePtr - readPtr)) < sizeof(buffer)) {
@@ -143,7 +140,9 @@ void AudioFileSourceSPIRAMBuffer::fill()
int cnt = src->readNonBlock(buffer, sizeof(buffer));
if (cnt) {
#ifdef FAKERAM
for (size_t i=0; i<cnt; i++) fakeRAM[(i+writePtr)%ramSize] = buffer[i];
for (size_t i = 0; i < cnt; i++) {
fakeRAM[(i + writePtr) % ramSize] = buffer[i];
}
#else
ram.writeBytes(writePtr % ramSize, buffer, cnt);
#endif
@@ -152,18 +151,19 @@ void AudioFileSourceSPIRAMBuffer::fill()
}
}
bool AudioFileSourceSPIRAMBuffer::loop()
{
bool AudioFileSourceSPIRAMBuffer::loop() {
static uint32_t last = 0;
if (!src->loop()) return false;
if (!src->loop()) {
return false;
}
fill();
if ((ESP.getCycleCount() - last) > microsecondsToClockCycles(1000000)) {
last = ESP.getCycleCount();
char str[65];
memset(str, '#', 64);
str[64] = 0;
str[((writePtr - readPtr) * 64)/ramSize] = 0;
cb.st(((writePtr - readPtr) * 100)/ramSize, str);
char str[65];
memset(str, '#', 64);
str[64] = 0;
str[((writePtr - readPtr) * 64) / ramSize] = 0;
cb.st(((writePtr - readPtr) * 100) / ramSize, str);
}
return true;
}