diff options
| author | Scott Shawcroft <scott.shawcroft@gmail.com> | 2018-04-13 10:51:01 -0700 |
|---|---|---|
| committer | Scott Shawcroft <scott.shawcroft@gmail.com> | 2018-04-13 10:51:01 -0700 |
| commit | 22194d5977e5fe0ce9254043d6aefd1469982a97 (patch) | |
| tree | ebbbaa578966b4478ba78cc4be33f63a91171baa | |
| parent | 8dcfeb6240cb5a02c8621a25d4a34c45ece3059f (diff) | |
Tweaks based on dhalbert's feedback.
| -rw-r--r-- | ports/atmel-samd/Makefile | 15 | ||||
| -rw-r--r-- | ports/atmel-samd/clocks.c | 2 | ||||
| -rw-r--r-- | ports/atmel-samd/common-hal/audioio/AudioOut.c | 29 | ||||
| -rw-r--r-- | shared-bindings/audioio/RawSample.c | 2 | ||||
| -rw-r--r-- | shared-bindings/audioio/WaveFile.c | 3 |
5 files changed, 30 insertions, 21 deletions
diff --git a/ports/atmel-samd/Makefile b/ports/atmel-samd/Makefile index bfba3cd78..7d2982ca0 100644 --- a/ports/atmel-samd/Makefile +++ b/ports/atmel-samd/Makefile @@ -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)) \ diff --git a/ports/atmel-samd/clocks.c b/ports/atmel-samd/clocks.c index 0a945a6e7..87da2e862 100644 --- a/ports/atmel-samd/clocks.c +++ b/ports/atmel-samd/clocks.c @@ -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; } diff --git a/ports/atmel-samd/common-hal/audioio/AudioOut.c b/ports/atmel-samd/common-hal/audioio/AudioOut.c index 64da34863..3d03bfd67 100644 --- a/ports/atmel-samd/common-hal/audioio/AudioOut.c +++ b/ports/atmel-samd/common-hal/audioio/AudioOut.c @@ -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) { diff --git a/shared-bindings/audioio/RawSample.c b/shared-bindings/audioio/RawSample.c index c4342677a..3f8f71a1f 100644 --- a/shared-bindings/audioio/RawSample.c +++ b/shared-bindings/audioio/RawSample.c @@ -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. //| diff --git a/shared-bindings/audioio/WaveFile.c b/shared-bindings/audioio/WaveFile.c index 0a28ad10f..13c4d6b8f 100644 --- a/shared-bindings/audioio/WaveFile.c +++ b/shared-bindings/audioio/WaveFile.c @@ -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) //| |
