Skip to content

Commit 58392be

Browse files
committed
fixed up DAC refs
1 parent 83834c3 commit 58392be

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

cores/arduino/wiring.c

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,11 @@ void init( void )
7878
// Clock TC/TCC for Pulse and Analog
7979
PM->APBCMASK.reg |= PM_APBCMASK_TCC0 | PM_APBCMASK_TCC1 | PM_APBCMASK_TCC2 | PM_APBCMASK_TC3 | PM_APBCMASK_TC4 | PM_APBCMASK_TC5 ;
8080

81+
// ATSAMR, for example, doesn't have a DAC
82+
#ifdef PM_APBCMASK_DAC
8183
// Clock ADC/DAC for Analog
8284
PM->APBCMASK.reg |= PM_APBCMASK_ADC | PM_APBCMASK_DAC ;
85+
#endif
8386

8487
// Setup all pins (digital and analog) in INPUT mode (default is nothing)
8588
for ( ul = 0 ; ul < NUM_DIGITAL_PINS ; ul++ )
@@ -119,9 +122,13 @@ void init( void )
119122
GCLK_CLKCTRL_GEN_GCLK0 | // Generic Clock Generator 0 is source
120123
GCLK_CLKCTRL_CLKEN ;
121124

125+
// ATSAMR, for example, doesn't have a DAC
126+
#ifdef DAC
122127
while ( DAC->STATUS.bit.SYNCBUSY == 1 ); // Wait for synchronization of registers between the clock domains
123128
DAC->CTRLB.reg = DAC_CTRLB_REFSEL_AVCC | // Using the 3.3V reference
124129
DAC_CTRLB_EOEN ; // External Output Enable (Vout)
130+
#endif
131+
125132
}
126133

127134
#ifdef __cplusplus

cores/arduino/wiring_analog.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,12 +34,15 @@ static void syncADC() {
3434
;
3535
}
3636

37+
// ATSAMR, for example, doesn't have a DAC
38+
#ifdef DAC
3739
// Wait for synchronization of registers between the clock domains
3840
static __inline__ void syncDAC() __attribute__((always_inline, unused));
3941
static void syncDAC() {
4042
while (DAC->STATUS.bit.SYNCBUSY == 1)
4143
;
4244
}
45+
#endif
4346

4447
// Wait for synchronization of registers between the clock domains
4548
static __inline__ void syncTC_8(Tc* TCx) __attribute__((always_inline, unused));
@@ -149,13 +152,16 @@ uint32_t analogRead( uint32_t ulPin )
149152

150153
pinPeripheral(ulPin, PIO_ANALOG);
151154

155+
// ATSAMR, for example, doesn't have a DAC
156+
#ifdef DAC
152157
if (ulPin == A0) // Disable DAC, if analogWrite(A0,dval) used previously the DAC is enabled
153158
{
154159
syncDAC();
155160
DAC->CTRLA.bit.ENABLE = 0x00; // Disable DAC
156161
//DAC->CTRLB.bit.EOEN = 0x00; // The DAC output is turned off.
157162
syncDAC();
158163
}
164+
#endif
159165

160166
syncADC();
161167
ADC->INPUTCTRL.bit.MUXPOS = g_APinDescription[ulPin].ulADCChannelNumber; // Selection for the positive ADC input
@@ -206,6 +212,8 @@ void analogWrite( uint32_t ulPin, uint32_t ulValue )
206212
{
207213
uint32_t attr = g_APinDescription[ulPin].ulPinAttribute ;
208214

215+
// ATSAMR, for example, doesn't have a DAC
216+
#ifdef DAC
209217
if ( (attr & PIN_ATTR_ANALOG) == PIN_ATTR_ANALOG )
210218
{
211219
if ( ulPin != PIN_A0 ) // Only 1 DAC on A0 (PA02)
@@ -222,6 +230,7 @@ void analogWrite( uint32_t ulPin, uint32_t ulValue )
222230
syncDAC();
223231
return ;
224232
}
233+
#endif
225234

226235
if ( (attr & PIN_ATTR_PWM) == PIN_ATTR_PWM )
227236
{

0 commit comments

Comments
 (0)