8000 Tweaks based on dhalbert's feedback. · rbarraud/circuitpython@22194d5 · GitHub
[go: up one dir, main page]

Skip to content

Commit 22194d5

Browse files
committed
Tweaks based on dhalbert's feedback.
1 parent 8dcfeb6 commit 22194d5

File tree

5 files changed

+30
-21
lines changed

5 files changed

+30
-21
lines changed

ports/atmel-samd/Makefile

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -364,15 +364,12 @@ SRC_COMMON_HAL += \
364364
audiobusio/__init__.c \
365365
audiobusio/I2SOut.c
366366
endif
367-
ifeq ($(CHIP_VARIANT),SAMD51G18)
368-
SRC_COMMON_HAL += \
369-
audiobusio/__init__.c \
370-
audiobusio/I2SOut.c
371-
endif
372-
ifeq ($(CHIP_VARIANT),SAMD51G19)
373-
SRC_COMMON_HAL += \
374-
audiobusio/__init__.c \
375-
audiobusio/I2SOut.c
367+
ifneq ($(CHIP_VARIANT),SAMD51G18A)
368+
ifneq ($(CHIP_VARIANT),SAMD51G19A)
369+
SRC_COMMON_HAL += \
370+
audiobusio/__init__.c \
371+
audiobusio/I2SOut.c
372+
endif
376373
endif
377374

378375
SRC_SHARED_MODULE_EXPANDED = $(addprefix shared-bindings/, $(SRC_SHARED_MODULE)) \

ports/atmel-samd/clocks.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535
// TODO(tannewt): Should we have a way of sharing GCLKs based on their speed? Divisor doesn't
3636
// gaurantee speed because it depends on the source.
3737
uint8_t find_free_gclk(uint16_t divisor) {
38-
if (divisor > (1 << 8)) {
38+
if (divisor > 0xff) {
3939
if (gclk_enabled(1)) {
4040
return 0xff;
4141
}

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

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -51,11 +51,21 @@
5151
#include "timers.h"
5252

5353
void audioout_reset(void) {
54-
// Only reset DMA. PWMOut will reset the timer. Other code will reset the DAC.
5554
}
5655

5756
void common_hal_audioio_audioout_construct(audioio_audioout_obj_t* self,
5857
const mcu_pin_obj_t* left_channel, const mcu_pin_obj_t* right_channel) {
58+
#ifdef SAMD51
59+
bool dac_clock_enabled = hri_mclk_get_APBDMASK_DAC_bit(MCLK);
60+
#endif
61+
62+
#ifdef SAMD21
63+
bool dac_clock_enabled = PM->APBCMASK.bit.DAC_;
64+
#endif
65+
// Only support exclusive use of the DAC.
66+
if (dac_clock_enabled && DAC->CTRLA.bit.ENABLE == 1) {
67+
mp_raise_RuntimeError("DAC already in use");
68+
}
5969
#ifdef SAMD21
6070
if (right_channel != NULL) {
6171
mp_raise_ValueError("Right channel unsupported");
@@ -102,14 +112,10 @@ void common_hal_audioio_audioout_construct(audioio_audioout_obj_t* self,
102112
// SAMD51: This clock should be <= 350kHz, per datasheet table 37-6.
103113
_gclk_enable_channel(DAC_GCLK_ID, CONF_GCLK_DAC_SRC);
104114

105-
// There is a small chance the other output is being used by AnalogOut on the SAMD51 so
106-
// only reset if the DAC is disabled.
107-
if (DAC->CTRLA.bit.ENABLE == 0) {
115+
108116
DAC->CTRLA.bit.SWRST = 1;
109117
while (DAC->CTRLA.bit.SWRST == 1) {}
110118

111-
}
112-
113119
bool channel0_enabled = true;
114120
#ifdef SAMD51
115121
channel0_enabled = self->left_channel == &pin_PA02 || self->right_channel == &pin_PA02;
@@ -224,6 +230,14 @@ void common_hal_audioio_audioout_deinit(audioio_audioout_obj_t* self) {
224230
return;
225231
}
226232

233+
DAC->CTRLA.bit.ENABLE = 0;
234+
#ifdef SAMD21
235+
while (DAC->STATUS.bit.SYNCBUSY == 1) {}
236+
#endif
237+
#ifdef SAMD51
238+
while (DAC->SYNCBUSY.bit.ENABLE == 1) {}
239+
#endif
240+
227241
disable_event_channel(self->tc_to_dac_event_channel);
228242

229243
reset_pin(self->left_channel->pin);
@@ -320,9 +334,6 @@ void common_hal_audioio_audioout_stop(audioio_audioout_obj_t* self) {
320334
#ifdef SAMD51
321335
audio_dma_stop(&self->right_dma);
322336
#endif
323-
324-
// FIXME(tannewt): Do we want to disable? What if we're sharing with an AnalogOut on the 51?
325-
// dac_disable(MP_STATE_VM(audioout_dac_instance));
326337
}
327338

328339
bool common_hal_audioio_audioout_get_playing(audioio_audioout_obj_t* self) {

shared-bindings/audioio/RawSample.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@
4444
//| .. class:: RawSample(buffer, *, channel_count=1, sample_rate=8000)
4545
//|
4646
//| Create a RawSample based on the given buffer of signed values. If channel_count is more than
47-
//| 1 then each channel's samples should rotate. In other words, for a two channel buffer, the
47+
//| 1 then each channel's samples should alternate. In other words, for a two channel buffer, the
4848
//| first sample will be for channel 1, the second sample will be for channel two, the third for
4949
//| channel 1 and so on.
5050
//|

shared-bindings/audioio/WaveFile.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@
3939
//| :class:`WaveFile` -- Load a wave file for audio playback
4040
//| ========================================================
4141
//|
42-
//| A .wav file prepped for audio playback
42+
//| A .wav file prepped for audio playback. Only mono and stereo files are supported. Samples must
43+
//| be 8 bit unsigned or 16 bit signed.
4344
//|
4445
//| .. class:: WaveFile(filename)
4546
//|

0 commit comments

Comments
 (0)
0