diff --git a/ports/atmel-samd/common-hal/analogio/AnalogOut.c b/ports/atmel-samd/common-hal/analogio/AnalogOut.c index 8419927fe7..19475e00bf 100644 --- a/ports/atmel-samd/common-hal/analogio/AnalogOut.c +++ b/ports/atmel-samd/common-hal/analogio/AnalogOut.c @@ -138,4 +138,5 @@ void common_hal_analogio_analogout_set_value(analogio_analogout_obj_t *self, } void analogout_reset(void) { + // AudioOut resets the DAC in case its been used for audio which requires special handling. } diff --git a/ports/atmel-samd/common-hal/audioio/AudioOut.c b/ports/atmel-samd/common-hal/audioio/AudioOut.c index b15c642b53..596f3214af 100644 --- a/ports/atmel-samd/common-hal/audioio/AudioOut.c +++ b/ports/atmel-samd/common-hal/audioio/AudioOut.c @@ -60,8 +60,8 @@ static void ramp_value(uint16_t start, uint16_t end) { int32_t step = 49; int32_t steps = diff / step; if (diff < 0) { - steps *= -1; - step *= -1; + steps = -steps; + step = -step; } for (int32_t i = 0; i < steps; i++) { uint32_t value = start + step * i; @@ -81,8 +81,8 @@ static void ramp_value(uint16_t start, uint16_t end) { int32_t step = 49; int32_t steps = diff / step; if (diff < 0) { - steps *= -1; - step *= -1; + steps = -steps; + step = -step; } for (int32_t i = 0; i < steps; i++) { @@ -119,7 +119,7 @@ void audioout_reset(void) { } void common_hal_audioio_audioout_construct(audioio_audioout_obj_t* self, - const mcu_pin_obj_t* left_channel, const mcu_pin_obj_t* right_channel, uint16_t default_value) { + const mcu_pin_obj_t* left_channel, const mcu_pin_obj_t* right_channel, uint16_t quiescent_value) { #ifdef SAMD51 bool dac_clock_enabled = hri_mclk_get_APBDMASK_DAC_bit(MCLK); #endif @@ -299,8 +299,8 @@ void common_hal_audioio_audioout_construct(audioio_audioout_obj_t* self, self->tc_to_dac_event_channel = channel; // Ramp the DAC up. - self->default_value = default_value; - ramp_value(0, default_value); + self->quiescent_value = quiescent_value; + ramp_value(0, quiescent_value); // Leave the DMA setup to playback. } @@ -315,7 +315,7 @@ void common_hal_audioio_audioout_deinit(audioio_audioout_obj_t* self) { } // Ramp the DAC down. - ramp_value(self->default_value, 0); + ramp_value(self->quiescent_value, 0); DAC->CTRLA.bit.ENABLE = 0; #ifdef SAMD21 @@ -461,7 +461,7 @@ void common_hal_audioio_audioout_stop(audioio_audioout_obj_t* self) { #endif // Ramp the DAC to default. The start is ignored when the current value can be readback. // Otherwise, we just set it immediately. - ramp_value(self->default_value, self->default_value); + ramp_value(self->quiescent_value, self->quiescent_value); } bool common_hal_audioio_audioout_get_playing(audioio_audioout_obj_t* self) { diff --git a/ports/atmel-samd/common-hal/audioio/AudioOut.h b/ports/atmel-samd/common-hal/audioio/AudioOut.h index 9e5a7390d5..56b6b75c89 100644 --- a/ports/atmel-samd/common-hal/audioio/AudioOut.h +++ b/ports/atmel-samd/common-hal/audioio/AudioOut.h @@ -44,7 +44,7 @@ typedef struct { uint8_t tc_to_dac_event_channel; bool playing; - uint16_t default_value; + uint16_t quiescent_value; } audioio_audioout_obj_t; void audioout_reset(void); diff --git a/shared-bindings/audioio/AudioOut.c b/shared-bindings/audioio/AudioOut.c index 8c4b927855..18d908eef8 100644 --- a/shared-bindings/audioio/AudioOut.c +++ b/shared-bindings/audioio/AudioOut.c @@ -43,15 +43,15 @@ //| //| AudioOut can be used to output an analog audio signal on a given pin. //| -//| .. class:: AudioOut(left_channel, *, right_channel=None, default_value=0x8000) +//| .. class:: AudioOut(left_channel, *, right_channel=None, quiescent_value=0x8000) //| //| Create a AudioOut object associated with the given pin(s). This allows you to //| play audio signals out on the given pin(s). //| //| :param ~microcontroller.Pin left_channel: The pin to output the left channel to //| :param ~microcontroller.Pin right_channel: The pin to output the right channel to -//| :param int default_value: The default output value. Samples should start and end with this -//| value to prevent popping. +//| :param int quiescent_value: The output value when no signal is present. Samples should start +//| and end with this value to prevent audible popping. //| //| Simple 8ksps 440 Hz sin wave:: //| @@ -97,11 +97,11 @@ STATIC mp_obj_t audioio_audioout_make_new(const mp_obj_type_t *type, size_t n_ar mp_arg_check_num(n_args, n_kw, 1, 2, true); mp_map_t kw_args; mp_map_init_fixed_table(&kw_args, n_kw, pos_args + n_args); - enum { ARG_left_channel, ARG_right_channel, ARG_default_value }; + enum { ARG_left_channel, ARG_right_channel, ARG_quiescent_value }; static const mp_arg_t allowed_args[] = { { MP_QSTR_left_channel, MP_ARG_OBJ | MP_ARG_REQUIRED }, { MP_QSTR_right_channel, MP_ARG_OBJ | MP_ARG_KW_ONLY, {.u_rom_obj = mp_const_none} }, - { MP_QSTR_default_value, MP_ARG_OBJ | MP_ARG_KW_ONLY, {.u_int = 0x8000} }, + { MP_QSTR_quiescent_value, MP_ARG_OBJ | MP_ARG_KW_ONLY, {.u_int = 0x8000} }, }; mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)]; mp_arg_parse_all(n_args, pos_args, &kw_args, MP_ARRAY_SIZE(allowed_args), allowed_args, args); @@ -120,7 +120,7 @@ STATIC mp_obj_t audioio_audioout_make_new(const mp_obj_type_t *type, size_t n_ar // create AudioOut object from the given pin audioio_audioout_obj_t *self = m_new_obj(audioio_audioout_obj_t); self->base.type = &audioio_audioout_type; - common_hal_audioio_audioout_construct(self, left_channel_pin, right_channel_pin, args[ARG_default_value].u_int); + common_hal_audioio_audioout_construct(self, left_channel_pin, right_channel_pin, args[ARG_quiescent_value].u_int); return MP_OBJ_FROM_PTR(self); }