samd: AnalogOut: Better handle boards which IGNOREd analog pins
This commit is contained in:
parent
194d99f588
commit
fb768dfc14
@ -44,26 +44,36 @@
|
||||
#include "hpl/pm/hpl_pm_base.h"
|
||||
#endif
|
||||
|
||||
#define HAVE_ANALOGOUT ( \
|
||||
(defined(PIN_PA02) && !defined(IGNORE_PA02)) || \
|
||||
(defined(SAM_D5X_E5X) && defined(PIN_PA05) && !defined(IGNORE_PA05)) \
|
||||
)
|
||||
|
||||
void common_hal_analogio_analogout_construct(analogio_analogout_obj_t* self,
|
||||
const mcu_pin_obj_t *pin) {
|
||||
#if defined(SAMD21) && !defined(PIN_PA02)
|
||||
#if !HAVE_ANALOGOUT
|
||||
mp_raise_NotImplementedError(translate("No DAC on chip"));
|
||||
#else
|
||||
if (pin->number != PIN_PA02
|
||||
#ifdef SAM_D5X_E5X
|
||||
&& pin->number != PIN_PA05
|
||||
|
||||
int channel = -1;
|
||||
|
||||
#if defined(PIN_PA02) && !defined(IGNORE_PIN_PA02)
|
||||
if (pin->number != PIN_PA02) {
|
||||
channel = 0;
|
||||
}
|
||||
#endif
|
||||
) {
|
||||
#if defined(PIN_PA05) && defined(PIN_PA05) && !defined(IGNORE_PIN_PA05)
|
||||
if (pin->number != PIN_PA05) {
|
||||
channel = 1;
|
||||
}
|
||||
#endif
|
||||
|
||||
if(channel == -1) {
|
||||
mp_raise_ValueError(translate("AnalogOut not supported on given pin"));
|
||||
return;
|
||||
}
|
||||
|
||||
self->channel = 0;
|
||||
#ifdef SAM_D5X_E5X
|
||||
if (pin->number == PIN_PA05) {
|
||||
self->channel = 1;
|
||||
}
|
||||
#endif
|
||||
self->channel = channel;
|
||||
|
||||
#ifdef SAM_D5X_E5X
|
||||
hri_mclk_set_APBDMASK_DAC_bit(MCLK);
|
||||
@ -105,11 +115,15 @@ void common_hal_analogio_analogout_construct(analogio_analogout_obj_t* self,
|
||||
}
|
||||
|
||||
bool common_hal_analogio_analogout_deinited(analogio_analogout_obj_t *self) {
|
||||
#if !HAVE_ANALOGOUT
|
||||
return false;
|
||||
#else
|
||||
return self->deinited;
|
||||
#endif
|
||||
}
|
||||
|
||||
void common_hal_analogio_analogout_deinit(analogio_analogout_obj_t *self) {
|
||||
#if (defined(SAMD21) && defined(PIN_PA02)) || defined(SAM_D5X_E5X)
|
||||
#if HAVE_ANALOGOUT
|
||||
if (common_hal_analogio_analogout_deinited(self)) {
|
||||
return;
|
||||
}
|
||||
@ -130,12 +144,11 @@ void common_hal_analogio_analogout_deinit(analogio_analogout_obj_t *self) {
|
||||
|
||||
void common_hal_analogio_analogout_set_value(analogio_analogout_obj_t *self,
|
||||
uint16_t value) {
|
||||
#if defined(SAMD21) && !defined(PIN_PA02)
|
||||
return;
|
||||
#endif
|
||||
#if HAVE_ANALOGOUT
|
||||
// Input is 16 bit so make sure and set LEFTADJ to 1 so it takes the top
|
||||
// bits. This is currently done in asf4_conf/*/hpl_dac_config.h.
|
||||
dac_sync_write(&self->descriptor, self->channel, &value, 1);
|
||||
#endif
|
||||
}
|
||||
|
||||
void analogout_reset(void) {
|
||||
@ -143,7 +156,7 @@ void analogout_reset(void) {
|
||||
// if it was enabled, so do that instead if AudioOut is enabled.
|
||||
#if CIRCUITPY_AUDIOIO
|
||||
audioout_reset();
|
||||
#else
|
||||
#elif HAVE_ANALOGOUT
|
||||
#ifdef SAMD21
|
||||
while (DAC->STATUS.reg & DAC_STATUS_SYNCBUSY) {}
|
||||
#endif
|
||||
|
Loading…
x
Reference in New Issue
Block a user