31
31
#include "py/gc.h"
32
32
#include "py/mperrno.h"
33
33
#include "py/runtime.h"
34
- #include "common-hal/audiopwmio/AudioOut .h"
34
+ #include "common-hal/audiopwmio/PWMAudioOut .h"
35
35
#include "common-hal/pulseio/PWMOut.h"
36
- #include "shared-bindings/audiopwmio/AudioOut .h"
36
+ #include "shared-bindings/audiopwmio/PWMAudioOut .h"
37
37
#include "shared-bindings/microcontroller/__init__.h"
38
38
#include "shared-bindings/microcontroller/Pin.h"
39
39
#include "supervisor/shared/translate.h"
40
40
41
41
// TODO: This should be the same size as PWMOut.c:pwms[], but there's no trivial way to accomplish that
42
- STATIC audiopwmio_audioout_obj_t * active_audio [4 ];
42
+ STATIC audiopwmio_pwmaudioout_obj_t * active_audio [4 ];
43
43
44
44
#define F_TARGET (62500)
45
45
#define F_PWM (16000000)
@@ -63,15 +63,15 @@ STATIC uint32_t calculate_pwm_parameters(uint32_t sample_rate, uint32_t *top_out
63
63
return multiplier - 1 ;
64
64
}
65
65
66
- STATIC void activate_audiopwmout_obj (audiopwmio_audioout_obj_t * self ) {
66
+ STATIC void activate_audiopwmout_obj (audiopwmio_pwmaudioout_obj_t * self ) {
67
67
for (size_t i = 0 ; i < MP_ARRAY_SIZE (active_audio ); i ++ ) {
68
68
if (!active_audio [i ]) {
69
69
active_audio [i ] = self ;
70
70
break ;
71
71
}
72
72
}
73
73
}
74
- STATIC void deactivate_audiopwmout_obj (audiopwmio_audioout_obj_t * self ) {
74
+ STATIC void deactivate_audiopwmout_obj (audiopwmio_pwmaudioout_obj_t * self ) {
75
75
for (size_t i = 0 ; i < MP_ARRAY_SIZE (active_audio ); i ++ ) {
76
76
if (active_audio [i ] == self )
77
77
active_audio [i ] = NULL ;
@@ -83,7 +83,7 @@ void audiopwmout_reset() {
83
83
active_audio [i ] = NULL ;
84
84
}
85
85
86
- STATIC void fill_buffers (audiopwmio_audioout_obj_t * self , int buf ) {
86
+ STATIC void fill_buffers (audiopwmio_pwmaudioout_obj_t * self , int buf ) {
87
87
self -> pwm -> EVENTS_SEQSTARTED [1 - buf ] = 0 ;
88
88
uint16_t * dev_buffer = self -> buffers [buf ];
89
89
uint8_t * buffer ;
@@ -92,7 +92,7 @@ STATIC void fill_buffers(audiopwmio_audioout_obj_t *self, int buf) {
92
92
audiosample_get_buffer (self -> sample , false, 0 ,
93
93
& buffer , & buffer_length );
94
94
if (get_buffer_result == GET_BUFFER_ERROR ) {
95
- common_hal_audiopwmio_audioout_stop (self );
95
+ common_hal_audiopwmio_pwmaudioout_stop (self );
96
96
return ;
97
97
}
98
98
uint32_t num_samples = buffer_length / self -> bytes_per_sample / self -> spacing ;
@@ -132,8 +132,8 @@ STATIC void fill_buffers(audiopwmio_audioout_obj_t *self, int buf) {
132
132
}
133
133
}
134
134
135
- STATIC void audiopwmout_background_obj (audiopwmio_audioout_obj_t * self ) {
136
- if (!common_hal_audiopwmio_audioout_get_playing (self ))
135
+ STATIC void audiopwmout_background_obj (audiopwmio_pwmaudioout_obj_t * self ) {
136
+ if (!common_hal_audiopwmio_pwmaudioout_get_playing (self ))
137
137
return ;
138
138
if (self -> loop && self -> single_buffer ) {
139
139
self -> pwm -> LOOP = 0xffff ;
@@ -156,7 +156,7 @@ void audiopwmout_background() {
156
156
}
157
157
}
158
158
159
- void common_hal_audiopwmio_audioout_construct ( audiopwmio_audioout_obj_t * self ,
159
+ void common_hal_audiopwmio_pwmaudioout_construct ( audiopwmio_pwmaudioout_obj_t * self ,
160
160
const mcu_pin_obj_t * left_channel , const mcu_pin_obj_t * right_channel , uint16_t quiescent_value ) {
161
161
assert_pin_free (left_channel );
162
162
assert_pin_free (right_channel );
@@ -188,12 +188,12 @@ void common_hal_audiopwmio_audioout_construct(audiopwmio_audioout_obj_t* self,
188
188
// TODO: Ramp from 0 to quiescent value
189
189
}
190
190
191
- bool common_hal_audiopwmio_audioout_deinited ( audiopwmio_audioout_obj_t * self ) {
191
+ bool common_hal_audiopwmio_pwmaudioout_deinited ( audiopwmio_pwmaudioout_obj_t * self ) {
192
192
return !self -> pwm ;
193
193
}
194
194
195
- void common_hal_audiopwmio_audioout_deinit ( audiopwmio_audioout_obj_t * self ) {
196
- if (common_hal_audiopwmio_audioout_deinited (self )) {
195
+ void common_hal_audiopwmio_pwmaudioout_deinit ( audiopwmio_pwmaudioout_obj_t * self ) {
196
+ if (common_hal_audiopwmio_pwmaudioout_deinited (self )) {
197
197
return ;
198
198
}
199
199
// TODO: ramp the pwm down from quiescent value to 0
@@ -216,9 +216,9 @@ void common_hal_audiopwmio_audioout_deinit(audiopwmio_audioout_obj_t* self) {
216
216
self -> buffers [1 ] = NULL ;
217
217
}
218
218
219
- void common_hal_audiopwmio_audioout_play ( audiopwmio_audioout_obj_t * self , mp_obj_t sample , bool loop ) {
220
- if (common_hal_audiopwmio_audioout_get_playing (self )) {
221
- common_hal_audiopwmio_audioout_stop (self );
219
+ void common_hal_audiopwmio_pwmaudioout_play ( audiopwmio_pwmaudioout_obj_t * self , mp_obj_t sample , bool loop ) {
220
+ if (common_hal_audiopwmio_pwmaudioout_get_playing (self )) {
221
+ common_hal_audiopwmio_pwmaudioout_stop (self );
222
222
}
223
223
self -> sample = sample ;
224
224
self -> loop = loop ;
@@ -268,7 +268,7 @@ void common_hal_audiopwmio_audioout_play(audiopwmio_audioout_obj_t* self, mp_obj
268
268
self -> paused = false;
269
269
}
270
270
271
- void common_hal_audiopwmio_audioout_stop ( audiopwmio_audioout_obj_t * self ) {
271
+ void common_hal_audiopwmio_pwmaudioout_stop ( audiopwmio_pwmaudioout_obj_t * self ) {
272
272
deactivate_audiopwmout_obj (self );
273
273
self -> pwm -> TASKS_STOP = 1 ;
274
274
self -> stopping = false;
@@ -281,7 +281,7 @@ void common_hal_audiopwmio_audioout_stop(audiopwmio_audioout_obj_t* self) {
281
281
self -> buffers [1 ] = NULL ;
282
282
}
283
283
284
- bool common_hal_audiopwmio_audioout_get_playing ( audiopwmio_audioout_obj_t * self ) {
284
+ bool common_hal_audiopwmio_pwmaudioout_get_playing ( audiopwmio_pwmaudioout_obj_t * self ) {
285
285
if (self -> pwm -> EVENTS_STOPPED ) {
286
286
self -> playing = false;
287
287
self -> pwm -> EVENTS_STOPPED = 0 ;
@@ -305,14 +305,14 @@ bool common_hal_audiopwmio_audioout_get_playing(audiopwmio_audioout_obj_t* self)
305
305
* feels instant. (This also saves on memory, for long in-memory "single buffer"
306
306
* samples!)
307
307
*/
308
- void common_hal_audiopwmio_audioout_pause ( audiopwmio_audioout_obj_t * self ) {
308
+ void common_hal_audiopwmio_pwmaudioout_pause ( audiopwmio_pwmaudioout_obj_t * self ) {
309
309
self -> paused = true;
310
310
}
311
311
312
- void common_hal_audiopwmio_audioout_resume ( audiopwmio_audioout_obj_t * self ) {
312
+ void common_hal_audiopwmio_pwmaudioout_resume ( audiopwmio_pwmaudioout_obj_t * self ) {
313
313
self -> paused = false;
314
314
}
315
315
316
- bool common_hal_audiopwmio_audioout_get_paused ( audiopwmio_audioout_obj_t * self ) {
316
+ bool common_hal_audiopwmio_pwmaudioout_get_paused ( audiopwmio_pwmaudioout_obj_t * self ) {
317
317
return self -> paused ;
318
318
}
0 commit comments