Tweaks based on dhalbert's feedback.
This commit is contained in:
parent
8dcfeb6240
commit
22194d5977
|
@ -364,15 +364,12 @@ SRC_COMMON_HAL += \
|
|||
audiobusio/__init__.c \
|
||||
audiobusio/I2SOut.c
|
||||
endif
|
||||
ifeq ($(CHIP_VARIANT),SAMD51G18)
|
||||
SRC_COMMON_HAL += \
|
||||
audiobusio/__init__.c \
|
||||
audiobusio/I2SOut.c
|
||||
endif
|
||||
ifeq ($(CHIP_VARIANT),SAMD51G19)
|
||||
SRC_COMMON_HAL += \
|
||||
audiobusio/__init__.c \
|
||||
audiobusio/I2SOut.c
|
||||
ifneq ($(CHIP_VARIANT),SAMD51G18A)
|
||||
ifneq ($(CHIP_VARIANT),SAMD51G19A)
|
||||
SRC_COMMON_HAL += \
|
||||
audiobusio/__init__.c \
|
||||
audiobusio/I2SOut.c
|
||||
endif
|
||||
endif
|
||||
|
||||
SRC_SHARED_MODULE_EXPANDED = $(addprefix shared-bindings/, $(SRC_SHARED_MODULE)) \
|
||||
|
|
|
@ -35,7 +35,7 @@
|
|||
// TODO(tannewt): Should we have a way of sharing GCLKs based on their speed? Divisor doesn't
|
||||
// gaurantee speed because it depends on the source.
|
||||
uint8_t find_free_gclk(uint16_t divisor) {
|
||||
if (divisor > (1 << 8)) {
|
||||
if (divisor > 0xff) {
|
||||
if (gclk_enabled(1)) {
|
||||
return 0xff;
|
||||
}
|
||||
|
|
|
@ -51,11 +51,21 @@
|
|||
#include "timers.h"
|
||||
|
||||
void audioout_reset(void) {
|
||||
// Only reset DMA. PWMOut will reset the timer. Other code will reset the DAC.
|
||||
}
|
||||
|
||||
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) {
|
||||
#ifdef SAMD51
|
||||
bool dac_clock_enabled = hri_mclk_get_APBDMASK_DAC_bit(MCLK);
|
||||
#endif
|
||||
|
||||
#ifdef SAMD21
|
||||
bool dac_clock_enabled = PM->APBCMASK.bit.DAC_;
|
||||
#endif
|
||||
// Only support exclusive use of the DAC.
|
||||
if (dac_clock_enabled && DAC->CTRLA.bit.ENABLE == 1) {
|
||||
mp_raise_RuntimeError("DAC already in use");
|
||||
}
|
||||
#ifdef SAMD21
|
||||
if (right_channel != NULL) {
|
||||
mp_raise_ValueError("Right channel unsupported");
|
||||
|
@ -102,14 +112,10 @@ void common_hal_audioio_audioout_construct(audioio_audioout_obj_t* self,
|
|||
// SAMD51: This clock should be <= 350kHz, per datasheet table 37-6.
|
||||
_gclk_enable_channel(DAC_GCLK_ID, CONF_GCLK_DAC_SRC);
|
||||
|
||||
// There is a small chance the other output is being used by AnalogOut on the SAMD51 so
|
||||
// only reset if the DAC is disabled.
|
||||
if (DAC->CTRLA.bit.ENABLE == 0) {
|
||||
|
||||
DAC->CTRLA.bit.SWRST = 1;
|
||||
while (DAC->CTRLA.bit.SWRST == 1) {}
|
||||
|
||||
}
|
||||
|
||||
bool channel0_enabled = true;
|
||||
#ifdef SAMD51
|
||||
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) {
|
|||
return;
|
||||
}
|
||||
|
||||
DAC->CTRLA.bit.ENABLE = 0;
|
||||
#ifdef SAMD21
|
||||
while (DAC->STATUS.bit.SYNCBUSY == 1) {}
|
||||
#endif
|
||||
#ifdef SAMD51
|
||||
while (DAC->SYNCBUSY.bit.ENABLE == 1) {}
|
||||
#endif
|
||||
|
||||
disable_event_channel(self->tc_to_dac_event_channel);
|
||||
|
||||
reset_pin(self->left_channel->pin);
|
||||
|
@ -320,9 +334,6 @@ void common_hal_audioio_audioout_stop(audioio_audioout_obj_t* self) {
|
|||
#ifdef SAMD51
|
||||
audio_dma_stop(&self->right_dma);
|
||||
#endif
|
||||
|
||||
// FIXME(tannewt): Do we want to disable? What if we're sharing with an AnalogOut on the 51?
|
||||
// dac_disable(MP_STATE_VM(audioout_dac_instance));
|
||||
}
|
||||
|
||||
bool common_hal_audioio_audioout_get_playing(audioio_audioout_obj_t* self) {
|
||||
|
|
|
@ -44,7 +44,7 @@
|
|||
//| .. class:: RawSample(buffer, *, channel_count=1, sample_rate=8000)
|
||||
//|
|
||||
//| Create a RawSample based on the given buffer of signed values. If channel_count is more than
|
||||
//| 1 then each channel's samples should rotate. In other words, for a two channel buffer, the
|
||||
//| 1 then each channel's samples should alternate. In other words, for a two channel buffer, the
|
||||
//| first sample will be for channel 1, the second sample will be for channel two, the third for
|
||||
//| channel 1 and so on.
|
||||
//|
|
||||
|
|
|
@ -39,7 +39,8 @@
|
|||
//| :class:`WaveFile` -- Load a wave file for audio playback
|
||||
//| ========================================================
|
||||
//|
|
||||
//| A .wav file prepped for audio playback
|
||||
//| A .wav file prepped for audio playback. Only mono and stereo files are supported. Samples must
|
||||
//| be 8 bit unsigned or 16 bit signed.
|
||||
//|
|
||||
//| .. class:: WaveFile(filename)
|
||||
//|
|
||||
|
|
Loading…
Reference in New Issue