Skip to content

Commit e51f22e

Browse files
committed
RP2040 compile errors
1 parent a00853e commit e51f22e

File tree

5 files changed

+51
-44
lines changed

5 files changed

+51
-44
lines changed

src/AudioBasic/StrExt.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -24,19 +24,19 @@ class StrExt : public Str {
2424
public:
2525
StrExt() = default;
2626

27-
StrExt(int initialAllocatedLength){
27+
StrExt(int initialAllocatedLength) : Str() {
2828
maxlen = initialAllocatedLength;
2929
}
3030

31-
StrExt(Str &source){
31+
StrExt(Str &source) : Str() {
3232
set(source);
3333
}
3434

35-
StrExt(StrExt &source){
35+
StrExt(StrExt &source) : Str(){
3636
set(source);
3737
}
3838

39-
StrExt(const char* str){
39+
StrExt(const char* str) : Str() {
4040
if (str!=nullptr){
4141
len = strlen(str);
4242
maxlen = len;

src/AudioConfig.h

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -96,11 +96,11 @@
9696
* @brief PWM
9797
*/
9898
#ifndef PWM_BUFFER_SIZE
99-
#define PWM_BUFFER_SIZE 512
99+
#define PWM_BUFFER_SIZE 1024
100100
#endif
101101

102102
#ifndef PWM_BUFFERS
103-
#define PWM_BUFFERS 10
103+
#define PWM_BUFFERS 50
104104
#endif
105105

106106
#ifndef PWM_FREQUENCY
@@ -223,8 +223,8 @@ typedef uint32_t eps32_i2s_sample_rate_type;
223223
#endif
224224

225225
//----------------
226-
#if defined(DARDUINO_ARCH_MBED_RP2040)
227-
#define USE_I2S 1
226+
#if defined(ARDUINO_ARCH_MBED_RP2040)
227+
//#define USE_I2S 1
228228
#define USE_PWM
229229

230230
#define PWM_START_PIN 6
@@ -241,7 +241,8 @@ typedef uint32_t eps32_i2s_sample_rate_type;
241241
#define IRAM_ATTR
242242
//#define USE_ESP8266_AUDIO
243243

244-
#elif defined(DARDUINO_ARCH_RP2040)
244+
//----------------
245+
#elif defined(ARDUINO_ARCH_RP2040)
245246
#define USE_I2S 1
246247
#define USE_PWM
247248

src/AudioI2S/I2SRP2040.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
#pragma once
22

3-
#if defined(ARDUINO_ARCH_RP2040)
3+
#if defined(ARDUINO_ARCH_RP2040) && !defined(ARDUINO_ARCH_MBED_RP2040)
44
#include "AudioI2S/I2SConfig.h"
5-
#include "AudioExperiments/I2SBitBangRP2040.h"
5+
//#include "AudioExperiments/I2SBitBangRP2040.h"
66
#include <I2S.h>
77
namespace audio_tools {
88

src/AudioPWM/PWMAudioBase.h

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ struct PWMConfig : public AudioBaseInfo {
7070
LOGI("bits_per_sample: %d", bits_per_sample);
7171
LOGI("buffer_size: %u", buffer_size);
7272
LOGI("pwm_frequency: %lu", pwm_frequency);
73-
//LOGI("resolution: %d", resolution);
73+
LOGI("resolution: %d", resolution);
7474
//LOGI("timer_id: %d", timer_id);
7575
}
7676

@@ -201,7 +201,6 @@ class PWMAudioStreamBase : public AudioPrint, public AudioBaseInfoDependent {
201201
is_timer_started = false;
202202
}
203203

204-
205204
virtual int availableForWrite() {
206205
return buffer==nullptr ? 0 : buffer->availableForWrite();
207206
}
@@ -297,7 +296,7 @@ class PWMAudioStreamBase : public AudioPrint, public AudioBaseInfoDependent {
297296
/// writes the next frame to the output pins
298297
void playNextFrameStream(){
299298
if (is_timer_started){
300-
//LOGD(LOG_METHOD);
299+
//LOGD(LOG_METHOD);
301300
int required = (audio_config.bits_per_sample / 8) * audio_config.channels;
302301
if (buffer->available() >= required){
303302
for (int j=0;j<audio_config.channels;j++){
@@ -308,21 +307,18 @@ class PWMAudioStreamBase : public AudioPrint, public AudioBaseInfoDependent {
308307
underflow_count++;
309308
}
310309
updateStatistics();
311-
} else {
312-
//LOGE("is_timer_started is false");
313-
}
310+
}
314311
}
315312

316313
void playNextFrame(){
317-
//LOGD(LOG_METHOD);
314+
// LOGD(LOG_METHOD);
318315
if (user_callback!=nullptr){
319316
playNextFrameCallback();
320317
} else {
321318
playNextFrameStream();
322319
}
323320
}
324321

325-
326322
/// determines the next scaled value
327323
virtual int nextValue() {
328324
int result = 0;

src/AudioPWM/PWMAudioRP2040.h

Lines changed: 35 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11

22
#pragma once
3-
#if defined(ARDUINO_ARCH_RP2040)
3+
#if defined(ARDUINO_ARCH_RP2040) && !defined(ARDUINO_ARCH_MBED_RP2040)
44
#include "AudioPWM/PWMAudioBase.h"
55
#include "hardware/gpio.h"
66
#include "hardware/adc.h"
@@ -12,7 +12,7 @@ namespace audio_tools {
1212
// forwrd declaratioin of callback
1313
class PWMAudioStreamPico;
1414
typedef PWMAudioStreamPico PWMAudioStream;
15-
bool defaultPWMAudioOutputCallbackPico(repeating_timer* ptr);
15+
//bool defaultPWMAudioOutputCallbackPico(repeating_timer* ptr);
1616

1717
/**
1818
* @brief Rasperry Pico Channel to pin assignments
@@ -36,7 +36,7 @@ struct PicoChannelOut {
3636
*/
3737

3838
class PWMAudioStreamPico : public PWMAudioStreamBase {
39-
friend bool defaultPWMAudioOutputCallbackPico(repeating_timer* ptr);
39+
//friend bool defaultPWMAudioOutputCallbackPico(repeating_timer* ptr);
4040

4141
public:
4242

@@ -45,8 +45,9 @@ class PWMAudioStreamPico : public PWMAudioStreamBase {
4545
}
4646

4747
/// Ends the output -> resets the timer and the pins
48-
void end(){
49-
LOGD(LOG_METHOD);
48+
void end() override {
49+
LOGD(LOG_METHOD);
50+
is_timer_started = false;
5051
if (!cancel_repeating_timer(&timer)){
5152
LOGE("cancel_repeating_timer failed")
5253
}
@@ -61,10 +62,14 @@ class PWMAudioStreamPico : public PWMAudioStreamBase {
6162
Vector<PicoChannelOut> pins;
6263
repeating_timer_t timer;
6364

65+
virtual void startTimer() override {
66+
//LOGI(LOG_METHOD);
67+
is_timer_started = true;
68+
}
6469

6570
// setup pwm config and all pins
66-
void setupPWM(){
67-
LOGD(LOG_METHOD);
71+
void setupPWM() override {
72+
LOGD(LOG_METHOD);
6873
pwm_config cfg = setupPWMConfig();
6974

7075
// initialize empty pins
@@ -96,8 +101,11 @@ class PWMAudioStreamPico : public PWMAudioStreamBase {
96101
pwm_config pico_pwm_config = pwm_get_default_config();
97102
int wrap_value = maxOutputValue(); // amplitude of square wave (pwm values -amplitude to amplitude) for one byte
98103
float pwmClockDivider = static_cast<float>(clock_get_hz(clk_sys)) / (audio_config.pwm_frequency * wrap_value);
99-
LOGI("->clock speed is %f", static_cast<float>(clock_get_hz(clk_sys)));
100-
LOGI("->divider is %f", pwmClockDivider);
104+
float clock_speed = static_cast<float>(clock_get_hz(clk_sys));
105+
LOGI("->wrap_value = %d", wrap_value);
106+
LOGI("->max clock speed = %f", clock_speed);
107+
LOGI("->divider = %f", pwmClockDivider);
108+
LOGI("->clock speed = %f", clock_speed/pwmClockDivider);
101109
pwm_config_set_clkdiv(&pico_pwm_config, pwmClockDivider);
102110
pwm_config_set_clkdiv_mode(&pico_pwm_config, PWM_DIV_FREE_RUNNING);
103111
//pwm_config_set_phase_correct(&pico_pwm_config, false);
@@ -106,7 +114,7 @@ class PWMAudioStreamPico : public PWMAudioStreamBase {
106114
}
107115

108116
// set up pwm
109-
void setupPWMPin(pwm_config &cfg, PicoChannelOut &pinInfo){
117+
void setupPWMPin(pwm_config &cfg, PicoChannelOut &pinInfo) {
110118
LOGD("%s for gpio %d",LOG_METHOD, pinInfo.gpio);
111119
// setup pwm pin
112120
int gpio = pinInfo.gpio;
@@ -119,43 +127,45 @@ class PWMAudioStreamPico : public PWMAudioStreamBase {
119127
pwm_set_chan_level(pinInfo.slice, pinInfo.channel, 0);
120128
}
121129

122-
void setupTimer(){
123-
LOGD(LOG_METHOD);
130+
void setupTimer() override {
131+
LOGD(LOG_METHOD);
124132
// setup timer
125133
uint32_t time = 1000000UL / audio_config.sample_rate;
126134
LOGI("->Timer value %ld us", time);
127-
128135
if (!add_repeating_timer_us(-time, &defaultPWMAudioOutputCallbackPico, this, &timer)){
129136
LOGE("Error: alarm_pool_add_repeating_timer_us failed; no alarm slots available");
137+
} else {
138+
LOGI("repeating timer has started");
130139
}
131140
}
132141

133142
/// The pico supports max 16 pwm pins
134-
virtual int maxChannels() {
143+
virtual int maxChannels() override{
135144
return 16;
136145
};
137146

138147
/// Max pwm output value
139-
virtual int maxOutputValue(){
140-
return 255;
148+
virtual int maxOutputValue()override{
149+
return std::pow(audio_config.resolution,2)-1;
141150
}
142151

143152
/// write a pwm value to the indicated channel. The values are between 0 and 255
144-
void pwmWrite(int audioChannel, int value){
153+
void pwmWrite(int audioChannel, int value)override{
145154
pwm_set_chan_level(pins[audioChannel].slice, pins[audioChannel].channel, value);
146155
}
147156

157+
// timed output executed at the sampleRate
158+
static bool defaultPWMAudioOutputCallbackPico(repeating_timer* ptr) {
159+
PWMAudioStreamPico *self = (PWMAudioStreamPico*) ptr->user_data;
160+
//if (self!=nullptr){
161+
self->playNextFrame();
162+
//}
163+
return true;
164+
}
165+
148166
};
149167

150168

151-
// timed output executed at the sampleRate
152-
bool defaultPWMAudioOutputCallbackPico(repeating_timer* ptr) {
153-
PWMAudioStreamPico *self = (PWMAudioStreamPico*) ptr->user_data;
154-
if (self!=nullptr){
155-
self->playNextFrame();
156-
}
157-
return true;
158-
}
159169

160170
} // Namespace
161171

0 commit comments

Comments
 (0)