Skip to content

Commit 4eb1fe1

Browse files
committed
Tweaks from feedback:
* default_value is now quiescent_value * Use step = -step format for sign switch * Add note about analogout_reset being empty
1 parent c209165 commit 4eb1fe1

File tree

4 files changed

+17
-16
lines changed

4 files changed

+17
-16
lines changed

ports/atmel-samd/common-hal/analogio/AnalogOut.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,4 +138,5 @@ void common_hal_analogio_analogout_set_value(analogio_analogout_obj_t *self,
138138
}
139139

140140
void analogout_reset(void) {
141+
// AudioOut resets the DAC in case its been used for audio which requires special handling.
141142
}

ports/atmel-samd/common-hal/audioio/AudioOut.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,8 @@ static void ramp_value(uint16_t start, uint16_t end) {
6060
int32_t step = 49;
6161
int32_t steps = diff / step;
6262
if (diff < 0) {
63-
steps *= -1;
64-
step *= -1;
63+
steps = -steps;
64+
step = -step;
6565
}
6666
for (int32_t i = 0; i < steps; i++) {
6767
uint32_t value = start + step * i;
@@ -81,8 +81,8 @@ static void ramp_value(uint16_t start, uint16_t end) {
8181
int32_t step = 49;
8282
int32_t steps = diff / step;
8383
if (diff < 0) {
84-
steps *= -1;
85-
step *= -1;
84+
steps = -steps;
85+
step = -step;
8686
}
8787

8888
for (int32_t i = 0; i < steps; i++) {
@@ -119,7 +119,7 @@ void audioout_reset(void) {
119119
}
120120

121121
void common_hal_audioio_audioout_construct(audioio_audioout_obj_t* self,
122-
const mcu_pin_obj_t* left_channel, const mcu_pin_obj_t* right_channel, uint16_t default_value) {
122+
const mcu_pin_obj_t* left_channel, const mcu_pin_obj_t* right_channel, uint16_t quiescent_value) {
123123
#ifdef SAMD51
124124
bool dac_clock_enabled = hri_mclk_get_APBDMASK_DAC_bit(MCLK);
125125
#endif
@@ -299,8 +299,8 @@ void common_hal_audioio_audioout_construct(audioio_audioout_obj_t* self,
299299
self->tc_to_dac_event_channel = channel;
300300

301301
// Ramp the DAC up.
302-
self->default_value = default_value;
303-
ramp_value(0, default_value);
302+
self->quiescent_value = quiescent_value;
303+
ramp_value(0, quiescent_value);
304304

305305
// Leave the DMA setup to playback.
306306
}
@@ -315,7 +315,7 @@ void common_hal_audioio_audioout_deinit(audioio_audioout_obj_t* self) {
315315
}
316316

317317
// Ramp the DAC down.
318-
ramp_value(self->default_value, 0);
318+
ramp_value(self->quiescent_value, 0);
319319

320320
DAC->CTRLA.bit.ENABLE = 0;
321321
#ifdef SAMD21
@@ -461,7 +461,7 @@ void common_hal_audioio_audioout_stop(audioio_audioout_obj_t* self) {
461461
#endif
462462
// Ramp the DAC to default. The start is ignored when the current value can be readback.
463463
// Otherwise, we just set it immediately.
464-
ramp_value(self->default_value, self->default_value);
464+
ramp_value(self->quiescent_value, self->quiescent_value);
465465
}
466466

467467
bool common_hal_audioio_audioout_get_playing(audioio_audioout_obj_t* self) {

ports/atmel-samd/common-hal/audioio/AudioOut.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ typedef struct {
4444

4545
uint8_t tc_to_dac_event_channel;
4646
bool playing;
47-
uint16_t default_value;
47+
uint16_t quiescent_value;
4848
} audioio_audioout_obj_t;
4949

5050
void audioout_reset(void);

shared-bindings/audioio/AudioOut.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,15 +43,15 @@
4343
//|
4444
//| AudioOut can be used to output an analog audio signal on a given pin.
4545
//|
46-
//| .. class:: AudioOut(left_channel, *, right_channel=None, default_value=0x8000)
46+
//| .. class:: AudioOut(left_channel, *, right_channel=None, quiescent_value=0x8000)
4747
//|
4848
//| Create a AudioOut object associated with the given pin(s). This allows you to
4949
//| play audio signals out on the given pin(s).
5050
//|
5151
//| :param ~microcontroller.Pin left_channel: The pin to output the left channel to
5252
//| :param ~microcontroller.Pin right_channel: The pin to output the right channel to
53-
//| :param int default_value: The default output value. Samples should start and end with this
54-
//| value to prevent popping.
53+
//| :param int quiescent_value: The output value when no signal is present. Samples should start
54+
//| and end with this value to prevent audible popping.
5555
//|
5656
//| Simple 8ksps 440 Hz sin wave::
5757
//|
@@ -97,11 +97,11 @@ STATIC mp_obj_t audioio_audioout_make_new(const mp_obj_type_t *type, size_t n_ar
9797
mp_arg_check_num(n_args, n_kw, 1, 2, true);
9898
mp_map_t kw_args;
9999
mp_map_init_fixed_table(&kw_args, n_kw, pos_args + n_args);
100-
enum { ARG_left_channel, ARG_right_channel, ARG_default_value };
100+
enum { ARG_left_channel, ARG_right_channel, ARG_quiescent_value };
101101
static const mp_arg_t allowed_args[] = {
102102
{ MP_QSTR_left_channel, MP_ARG_OBJ | MP_ARG_REQUIRED },
103103
{ MP_QSTR_right_channel, MP_ARG_OBJ | MP_ARG_KW_ONLY, {.u_rom_obj = mp_const_none} },
104-
{ MP_QSTR_default_value, MP_ARG_OBJ | MP_ARG_KW_ONLY, {.u_int = 0x8000} },
104+
{ MP_QSTR_quiescent_value, MP_ARG_OBJ | MP_ARG_KW_ONLY, {.u_int = 0x8000} },
105105
};
106106
mp_arg_val_t args[MP_ARRAY_SIZE(allowed_args)];
107107
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
120120
// create AudioOut object from the given pin
121121
audioio_audioout_obj_t *self = m_new_obj(audioio_audioout_obj_t);
122122
self->base.type = &audioio_audioout_type;
123-
common_hal_audioio_audioout_construct(self, left_channel_pin, right_channel_pin, args[ARG_default_value].u_int);
123+
common_hal_audioio_audioout_construct(self, left_channel_pin, right_channel_pin, args[ARG_quiescent_value].u_int);
124124

125125
return MP_OBJ_FROM_PTR(self);
126126
}

0 commit comments

Comments
 (0)