44
44
#include "hpl/pm/hpl_pm_base.h"
45
45
#endif
46
46
47
+ #define HAVE_ANALOGOUT ( \
48
+ (defined(PIN_PA02) && !defined(IGNORE_PA02)) || \
49
+ (defined(SAM_D5X_E5X) && defined(PIN_PA05) && !defined(IGNORE_PA05)) \
50
+ )
51
+
47
52
void common_hal_analogio_analogout_construct (analogio_analogout_obj_t * self ,
48
53
const mcu_pin_obj_t * pin ) {
49
- #if defined( SAMD21 ) && !defined( PIN_PA02 )
54
+ #if ! HAVE_ANALOGOUT
50
55
mp_raise_NotImplementedError (translate ("No DAC on chip" ));
51
56
#else
52
- if (pin -> number != PIN_PA02
53
- #ifdef SAM_D5X_E5X
54
- && pin -> number != PIN_PA05
57
+
58
+ int channel = -1 ;
59
+
60
+ #if defined(PIN_PA02 ) && !defined(IGNORE_PIN_PA02 )
61
+ if (pin -> number != PIN_PA02 ) {
62
+ channel = 0 ;
63
+ }
64
+ #endif
65
+ #if defined(PIN_PA05 ) && defined(PIN_PA05 ) && !defined(IGNORE_PIN_PA05 )
66
+ if (pin -> number != PIN_PA05 ) {
67
+ channel = 1 ;
68
+ }
55
69
#endif
56
- ) {
70
+
71
+ if (channel == -1 ) {
57
72
mp_raise_ValueError (translate ("AnalogOut not supported on given pin" ));
58
73
return ;
59
74
}
60
75
61
- self -> channel = 0 ;
62
- #ifdef SAM_D5X_E5X
63
- if (pin -> number == PIN_PA05 ) {
64
- self -> channel = 1 ;
65
- }
66
- #endif
76
+ self -> channel = channel ;
67
77
68
78
#ifdef SAM_D5X_E5X
69
79
hri_mclk_set_APBDMASK_DAC_bit (MCLK );
@@ -105,11 +115,15 @@ void common_hal_analogio_analogout_construct(analogio_analogout_obj_t* self,
105
115
}
106
116
107
117
bool common_hal_analogio_analogout_deinited (analogio_analogout_obj_t * self ) {
118
+ #if !HAVE_ANALOGOUT
119
+ return false;
120
+ #else
108
121
return self -> deinited ;
122
+ #endif
109
123
}
110
124
111
125
void common_hal_analogio_analogout_deinit (analogio_analogout_obj_t * self ) {
112
- #if (defined( SAMD21 ) && defined( PIN_PA02 )) || defined( SAM_D5X_E5X )
126
+ #if HAVE_ANALOGOUT
113
127
if (common_hal_analogio_analogout_deinited (self )) {
114
128
return ;
115
129
}
@@ -130,20 +144,19 @@ void common_hal_analogio_analogout_deinit(analogio_analogout_obj_t *self) {
130
144
131
145
void common_hal_analogio_analogout_set_value (analogio_analogout_obj_t * self ,
132
146
uint16_t value ) {
133
- #if defined(SAMD21 ) && !defined(PIN_PA02 )
134
- return ;
135
- #endif
147
+ #if HAVE_ANALOGOUT
136
148
// Input is 16 bit so make sure and set LEFTADJ to 1 so it takes the top
137
149
// bits. This is currently done in asf4_conf/*/hpl_dac_config.h.
138
150
dac_sync_write (& self -> descriptor , self -> channel , & value , 1 );
151
+ #endif
139
152
}
140
153
141
154
void analogout_reset (void ) {
142
155
// audioout_reset also resets the DAC, and does a smooth ramp down to avoid clicks
143
156
// if it was enabled, so do that instead if AudioOut is enabled.
144
157
#if CIRCUITPY_AUDIOIO
145
158
audioout_reset ();
146
- #else
159
+ #elif HAVE_ANALOGOUT
147
160
#ifdef SAMD21
148
161
while (DAC -> STATUS .reg & DAC_STATUS_SYNCBUSY ) {}
149
162
#endif
0 commit comments