3131#include "py/gc.h"
3232#include "py/mperrno.h"
3333#include "py/runtime.h"
34- #include "common-hal/audiopwmio/AudioOut .h"
34+ #include "common-hal/audiopwmio/PWMAudioOut .h"
3535#include "common-hal/pulseio/PWMOut.h"
36- #include "shared-bindings/audiopwmio/AudioOut .h"
36+ #include "shared-bindings/audiopwmio/PWMAudioOut .h"
3737#include "shared-bindings/microcontroller/__init__.h"
3838#include "shared-bindings/microcontroller/Pin.h"
3939#include "supervisor/shared/translate.h"
4040
4141// 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 ];
4343
4444#define F_TARGET (62500)
4545#define F_PWM (16000000)
@@ -63,15 +63,15 @@ STATIC uint32_t calculate_pwm_parameters(uint32_t sample_rate, uint32_t *top_out
6363 return multiplier - 1 ;
6464}
6565
66- STATIC void activate_audiopwmout_obj (audiopwmio_audioout_obj_t * self ) {
66+ STATIC void activate_audiopwmout_obj (audiopwmio_pwmaudioout_obj_t * self ) {
6767 for (size_t i = 0 ; i < MP_ARRAY_SIZE (active_audio ); i ++ ) {
6868 if (!active_audio [i ]) {
6969 active_audio [i ] = self ;
7070 break ;
7171 }
7272 }
7373}
74- STATIC void deactivate_audiopwmout_obj (audiopwmio_audioout_obj_t * self ) {
74+ STATIC void deactivate_audiopwmout_obj (audiopwmio_pwmaudioout_obj_t * self ) {
7575 for (size_t i = 0 ; i < MP_ARRAY_SIZE (active_audio ); i ++ ) {
7676 if (active_audio [i ] == self )
7777 active_audio [i ] = NULL ;
@@ -83,7 +83,7 @@ void audiopwmout_reset() {
8383 active_audio [i ] = NULL ;
8484}
8585
86- STATIC void fill_buffers (audiopwmio_audioout_obj_t * self , int buf ) {
86+ STATIC void fill_buffers (audiopwmio_pwmaudioout_obj_t * self , int buf ) {
8787 self -> pwm -> EVENTS_SEQSTARTED [1 - buf ] = 0 ;
8888 uint16_t * dev_buffer = self -> buffers [buf ];
8989 uint8_t * buffer ;
@@ -92,7 +92,7 @@ STATIC void fill_buffers(audiopwmio_audioout_obj_t *self, int buf) {
9292 audiosample_get_buffer (self -> sample , false, 0 ,
9393 & buffer , & buffer_length );
9494 if (get_buffer_result == GET_BUFFER_ERROR ) {
95- common_hal_audiopwmio_audioout_stop (self );
95+ common_hal_audiopwmio_pwmaudioout_stop (self );
9696 return ;
9797 }
9898 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) {
132132 }
133133}
134134
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 ))
137137 return ;
138138 if (self -> loop && self -> single_buffer ) {
139139 self -> pwm -> LOOP = 0xffff ;
@@ -156,7 +156,7 @@ void audiopwmout_background() {
156156 }
157157}
158158
159- void common_hal_audiopwmio_audioout_construct ( audiopwmio_audioout_obj_t * self ,
159+ void common_hal_audiopwmio_pwmaudioout_construct ( audiopwmio_pwmaudioout_obj_t * self ,
160160 const mcu_pin_obj_t * left_channel , const mcu_pin_obj_t * right_channel , uint16_t quiescent_value ) {
161161 assert_pin_free (left_channel );
162162 assert_pin_free (right_channel );
@@ -188,12 +188,12 @@ void common_hal_audiopwmio_audioout_construct(audiopwmio_audioout_obj_t* self,
188188 // TODO: Ramp from 0 to quiescent value
189189}
190190
191- bool common_hal_audiopwmio_audioout_deinited ( audiopwmio_audioout_obj_t * self ) {
191+ bool common_hal_audiopwmio_pwmaudioout_deinited ( audiopwmio_pwmaudioout_obj_t * self ) {
192192 return !self -> pwm ;
193193}
194194
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 )) {
197197 return ;
198198 }
199199 // 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) {
216216 self -> buffers [1 ] = NULL ;
217217}
218218
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 );
222222 }
223223 self -> sample = sample ;
224224 self -> loop = loop ;
@@ -268,7 +268,7 @@ void common_hal_audiopwmio_audioout_play(audiopwmio_audioout_obj_t* self, mp_obj
268268 self -> paused = false;
269269}
270270
271- void common_hal_audiopwmio_audioout_stop ( audiopwmio_audioout_obj_t * self ) {
271+ void common_hal_audiopwmio_pwmaudioout_stop ( audiopwmio_pwmaudioout_obj_t * self ) {
272272 deactivate_audiopwmout_obj (self );
273273 self -> pwm -> TASKS_STOP = 1 ;
274274 self -> stopping = false;
@@ -281,7 +281,7 @@ void common_hal_audiopwmio_audioout_stop(audiopwmio_audioout_obj_t* self) {
281281 self -> buffers [1 ] = NULL ;
282282}
283283
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 ) {
285285 if (self -> pwm -> EVENTS_STOPPED ) {
286286 self -> playing = false;
287287 self -> pwm -> EVENTS_STOPPED = 0 ;
@@ -305,14 +305,14 @@ bool common_hal_audiopwmio_audioout_get_playing(audiopwmio_audioout_obj_t* self)
305305 * feels instant. (This also saves on memory, for long in-memory "single buffer"
306306 * samples!)
307307 */
308- void common_hal_audiopwmio_audioout_pause ( audiopwmio_audioout_obj_t * self ) {
308+ void common_hal_audiopwmio_pwmaudioout_pause ( audiopwmio_pwmaudioout_obj_t * self ) {
309309 self -> paused = true;
310310}
311311
312- void common_hal_audiopwmio_audioout_resume ( audiopwmio_audioout_obj_t * self ) {
312+ void common_hal_audiopwmio_pwmaudioout_resume ( audiopwmio_pwmaudioout_obj_t * self ) {
313313 self -> paused = false;
314314}
315315
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 ) {
317317 return self -> paused ;
318318}
0 commit comments