@@ -148,11 +148,12 @@ uint32_t analogRead(uint32_t ulPin)
148
148
case ADC11 :
149
149
150
150
// Enable the corresponding channel
151
- if (ulChannel != latestSelectedChannel ) {
151
+ if (adc_get_channel_status ( ADC , ulChannel ) != 1 ) {
152
152
adc_enable_channel ( ADC , ulChannel );
153
- if ( latestSelectedChannel != (uint32_t )-1 )
153
+ if ( latestSelectedChannel != (uint32_t )-1 && ulChannel != latestSelectedChannel )
154
154
adc_disable_channel ( ADC , latestSelectedChannel );
155
155
latestSelectedChannel = ulChannel ;
156
+ g_pinStatus [ulPin ] = (g_pinStatus [ulPin ] & 0xF0 ) | PIN_STATUS_ANALOG ;
156
157
}
157
158
158
159
// Start the ADC
@@ -189,13 +190,9 @@ static void TC_SetCMR_ChannelB(Tc *tc, uint32_t chan, uint32_t v)
189
190
}
190
191
191
192
static uint8_t PWMEnabled = 0 ;
192
- static uint8_t pinEnabled [PINS_COUNT ];
193
193
static uint8_t TCChanEnabled [] = {0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 };
194
194
195
195
void analogOutputInit (void ) {
196
- uint8_t i ;
197
- for (i = 0 ; i < PINS_COUNT ; i ++ )
198
- pinEnabled [i ] = 0 ;
199
196
}
200
197
201
198
// Right now, PWM output only works on the pins with
@@ -263,7 +260,7 @@ void analogWrite(uint32_t ulPin, uint32_t ulValue) {
263
260
}
264
261
265
262
uint32_t chan = g_APinDescription [ulPin ].ulPWMChannel ;
266
- if (! pinEnabled [ulPin ]) {
263
+ if (( g_pinStatus [ulPin ] & 0xF ) != PIN_STATUS_PWM ) {
267
264
// Setup PWM for this pin
268
265
PIO_Configure (g_APinDescription [ulPin ].pPort ,
269
266
g_APinDescription [ulPin ].ulPinType ,
@@ -273,7 +270,7 @@ void analogWrite(uint32_t ulPin, uint32_t ulValue) {
273
270
PWMC_SetPeriod (PWM_INTERFACE , chan , PWM_MAX_DUTY_CYCLE );
274
271
PWMC_SetDutyCycle (PWM_INTERFACE , chan , ulValue );
275
272
PWMC_EnableChannel (PWM_INTERFACE , chan );
276
- pinEnabled [ulPin ] = 1 ;
273
+ g_pinStatus [ulPin ] = ( g_pinStatus [ ulPin ] & 0xF0 ) | PIN_STATUS_PWM ;
277
274
}
278
275
279
276
PWMC_SetDutyCycle (PWM_INTERFACE , chan , ulValue );
@@ -328,12 +325,12 @@ void analogWrite(uint32_t ulPin, uint32_t ulValue) {
328
325
TC_SetCMR_ChannelB (chTC , chNo , TC_CMR_BCPB_CLEAR | TC_CMR_BCPC_SET );
329
326
}
330
327
}
331
- if (! pinEnabled [ulPin ]) {
328
+ if (( g_pinStatus [ulPin ] & 0xF ) != PIN_STATUS_PWM ) {
332
329
PIO_Configure (g_APinDescription [ulPin ].pPort ,
333
330
g_APinDescription [ulPin ].ulPinType ,
334
331
g_APinDescription [ulPin ].ulPin ,
335
332
g_APinDescription [ulPin ].ulPinConfiguration );
336
- pinEnabled [ulPin ] = 1 ;
333
+ g_pinStatus [ulPin ] = ( g_pinStatus [ ulPin ] & 0xF0 ) | PIN_STATUS_PWM ;
337
334
}
338
335
if (!TCChanEnabled [interfaceID ]) {
339
336
TC_Start (chTC , chNo );
0 commit comments