Refactor A/D conversion in adc.c

Now the necessary settings are in adc.h. Refactored to allow repeated
ADC reads without reinitialization. Arduino allows setting
analogReference, this is now also implemented.
ADC is now initialized to sane values in apps/arduino/arduino-process.c
dev/arduino/arduino-compat.h now has all hardware independent settings
for arduino (some moved from platform/osd-merkur/dev/hw-arduino.h).
turnOffPWM re-implemented with hw_timer, removed from wiring_digital.c
ADC-specific arduino stuff moved to arduino-compat.h
Arduinos wiring_analog no longer necessary.
arduino-sketch example now reads analog inputs 1 and 5 using analogRead.
This commit is contained in:
Ralf Schlatterbeck 2014-06-29 17:26:15 +02:00
parent f0ad042bfc
commit abdf6f8c6b
12 changed files with 154 additions and 199 deletions

View file

@ -84,6 +84,7 @@ extern "C" {
#include "contiki.h"
#include "hw_timer.h"
#include "adc.h"
#ifdef __cplusplus
} // extern "C"
@ -145,6 +146,43 @@ static inline void analogWrite(uint8_t pin, int val)
}
}
/*
* turnOffPWM of arduino is implemented by hw_timer
*/
#define turnOffPWM(atimer) \
( (atimer) == NOT_ON_TIMER \
? (void)0 \
: (void)hwtimer_pwm_disable \
(atimer >> HW_TIMER_SHIFT, atimer & HWT_CHANNEL_MASK) \
)
/*
* micros on arduino takes timer overflows into account.
* We put in the seconds counter. To get a consistent seconds / ticks
* value we have to disable interrupts.
*/
static inline uint32_t micros (void)
{
uint32_t ticks;
uint8_t sreg = SREG;
cli ();
ticks = clock_seconds () * 1000000L
+ clock_time () * 1000L / CLOCK_SECOND;
SREG = sreg;
return ticks;
}
/*
* millis counts only internal timer ticks since start, not trying to do
* something about overflows. Note that we don't try to emulate overflow
* behaviour of arduino implementation.
*/
#define millis() (((uint32_t)clock_time())*1000L/CLOCK_SECOND)
#define micros() (clock_seconds()*1000L+
#define delay(ms) clock_delay_msec(ms)
#define delayMicroseconds(us) clock_delay_usec(us)
#define analogRead(analogpin) readADC(analogpin)
#ifdef __cplusplus
} // extern "C"
#endif