Skip to content

Commit d84ff02

Browse files
Allow setting PWMAudio frequency before begin (#2726)
I2S allows setting freq before ::begin, so allow same for PWMAudio.
1 parent cc2581a commit d84ff02

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

libraries/PWMAudio/src/PWMAudio.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -101,7 +101,8 @@ bool PWMAudio::setFrequency(int frequency) {
101101
return true; // We're already at the right speed
102102
}
103103
if (_pacer < 0) {
104-
return false;
104+
_sampleRate = frequency;
105+
return true;
105106
}
106107
uint16_t _pacer_D, _pacer_N;
107108
// Flip fraction(N for D, D for N) because we are using it as sys_clk * fraction(mechanic of dma_timer_set_fraction) for smaller than sys_clk values
@@ -152,6 +153,7 @@ bool PWMAudio::begin() {
152153
if (_pacer < 0) {
153154
return false;
154155
}
156+
155157
uint16_t _pacer_D = 0;
156158
uint16_t _pacer_N = 0;
157159
// Flip fraction(N for D, D for N) because we are using it as sys_clk * fraction(mechanic of dma_timer_set_fraction) for smaller than sys_clk values

0 commit comments

Comments
 (0)