analog-arm.c: use configured analog pins, not two fixed ones.
An obvious neccessity, just not done before to show better how stuff works.
This commit is contained in:
parent
f81000a4b6
commit
708289714f
26
analog-arm.c
26
analog-arm.c
|
|
@ -15,7 +15,6 @@
|
|||
|
||||
#include "cmsis-lpc11xx.h"
|
||||
#include "arduino.h"
|
||||
#include "temp.h"
|
||||
|
||||
|
||||
/** Inititalise the analog subsystem.
|
||||
|
|
@ -29,7 +28,7 @@
|
|||
*/
|
||||
void analog_init() {
|
||||
|
||||
if (NUM_TEMP_SENSORS) { // At least one channel in use.
|
||||
if (analog_mask) { // At least one channel in use.
|
||||
|
||||
LPC_SYSCON->PDRUNCFG &= ~(1 << 4); // Turn on ADC clock.
|
||||
LPC_SYSCON->SYSAHBCLKCTRL |= (1 << 13); // Turn on ADC power.
|
||||
|
|
@ -45,8 +44,7 @@ void analog_init() {
|
|||
AD0DRn LPC_ADC->DR[n] A/D channel n data register.
|
||||
AD0STAT LPC_ADC->STAT A/D status register.
|
||||
*/
|
||||
// TODO: enable only the channels we use.
|
||||
LPC_ADC->CR = (0xFF << 0) // All pins on (for now).
|
||||
LPC_ADC->CR = ((uint32_t)analog_mask << 0) // Mask of used pins.
|
||||
| ((F_CPU / 1000000) << 8) // 1 MHz ADC clock.
|
||||
| (1 << 16) // Hardware scan mode.
|
||||
| (0x0 << 17) // Maximum accuracy.
|
||||
|
|
@ -54,14 +52,18 @@ void analog_init() {
|
|||
|
||||
LPC_ADC->INTEN = 0; // No interrupt generation.
|
||||
|
||||
// TODO: set up the channels configured, not two arbitrary ones.
|
||||
LPC_IOCON->PIO1_0_CMSIS = (0x2 << 0) // Function AD1.
|
||||
| (0 << 3) // Pullup inactive.
|
||||
| (0 << 7); // Analog input mode.
|
||||
LPC_IOCON->PIO1_1_CMSIS = (0x2 << 0) // Function AD2.
|
||||
| (0 << 3) // Pullup inactive.
|
||||
| (0 << 7); // Analog input mode.
|
||||
}
|
||||
// Auto-generate pin setup.
|
||||
#undef DEFINE_TEMP_SENSOR
|
||||
#define DEFINE_TEMP_SENSOR(name, type, pin, additional) \
|
||||
LPC_IOCON->pin ## _CMSIS = \
|
||||
((type == TT_THERMISTOR) || (type == TT_AD595)) ? ( \
|
||||
(0x2 << 0) /* Function ADx. */ \
|
||||
| (0 << 3) /* Pullup inactive. */ \
|
||||
| (0 << 7)) /* Analog input mode. */ \
|
||||
: LPC_IOCON->pin ## _CMSIS;
|
||||
#include "config_wrapper.h"
|
||||
#undef DEFINE_TEMP_SENSOR
|
||||
} /* analog_mask */
|
||||
}
|
||||
|
||||
/** Read analog value.
|
||||
|
|
|
|||
15
analog-avr.c
15
analog-avr.c
|
|
@ -5,27 +5,14 @@
|
|||
|
||||
#if defined TEACUP_C_INCLUDE && defined __AVR__
|
||||
|
||||
#include "temp.h"
|
||||
#include "pinio.h"
|
||||
#include "memory_barrier.h"
|
||||
|
||||
/* OR-combined mask of all channels */
|
||||
#undef DEFINE_TEMP_SENSOR
|
||||
//! automagically generate analog_mask from DEFINE_TEMP_SENSOR entries in config.h
|
||||
#define DEFINE_TEMP_SENSOR(name, type, pin, additional) \
|
||||
| (((type == TT_THERMISTOR) || (type == TT_AD595)) ? (1 << (pin ## _ADC)) : 0)
|
||||
#ifdef AIO8_PIN
|
||||
static const uint16_t analog_mask = 0
|
||||
#else
|
||||
static const uint8_t analog_mask = 0
|
||||
#endif
|
||||
#include "config_wrapper.h"
|
||||
;
|
||||
#undef DEFINE_TEMP_SENSOR
|
||||
|
||||
static uint8_t adc_counter;
|
||||
static volatile uint16_t BSS adc_result[NUM_TEMP_SENSORS];
|
||||
|
||||
#undef DEFINE_TEMP_SENSOR
|
||||
#define DEFINE_TEMP_SENSOR(name, type, pin, additional) \
|
||||
((type == TT_THERMISTOR) || (type == TT_AD595)) ? (pin ## _ADC) : 255,
|
||||
static uint8_t adc_channel[NUM_TEMP_SENSORS] =
|
||||
|
|
|
|||
17
analog.c
17
analog.c
|
|
@ -4,6 +4,23 @@
|
|||
*/
|
||||
|
||||
#include "analog.h"
|
||||
#include "temp.h"
|
||||
|
||||
/**
|
||||
OR-combined mask of all channels. Auto-magically generated from
|
||||
DEFINE_TEMP_SENSOR() entries in config_wrapper.h
|
||||
*/
|
||||
#undef DEFINE_TEMP_SENSOR
|
||||
#define DEFINE_TEMP_SENSOR(name, type, pin, additional) \
|
||||
| (((type == TT_THERMISTOR) || (type == TT_AD595)) ? (1 << (pin ## _ADC)) : 0)
|
||||
#ifdef AIO8_PIN
|
||||
static const uint16_t analog_mask = 0
|
||||
#else
|
||||
static const uint8_t analog_mask = 0
|
||||
#endif
|
||||
#include "config_wrapper.h"
|
||||
;
|
||||
#undef DEFINE_TEMP_SENSOR
|
||||
|
||||
#define TEACUP_C_INCLUDE
|
||||
#include "analog-avr.c"
|
||||
|
|
|
|||
|
|
@ -145,31 +145,37 @@
|
|||
#define PIO0_11_PIN 11
|
||||
#define PIO0_11_PORT LPC_GPIO0
|
||||
#define PIO0_11_OUTPUT ((0x01 << 0) | (0x01 << 7))
|
||||
#define PIO0_11_ADC 0
|
||||
|
||||
#define PIO1_0_CMSIS R_PIO1_0
|
||||
#define PIO1_0_PIN 0
|
||||
#define PIO1_0_PORT LPC_GPIO1
|
||||
#define PIO1_0_OUTPUT ((0x01 << 0) | (0x01 << 7))
|
||||
#define PIO1_0_ADC 1
|
||||
|
||||
#define PIO1_1_CMSIS R_PIO1_1
|
||||
#define PIO1_1_PIN 1
|
||||
#define PIO1_1_PORT LPC_GPIO1
|
||||
#define PIO1_1_OUTPUT ((0x01 << 0) | (0x01 << 7))
|
||||
#define PIO1_1_ADC 2
|
||||
|
||||
#define PIO1_2_CMSIS R_PIO1_2
|
||||
#define PIO1_2_PIN 2
|
||||
#define PIO1_2_PORT LPC_GPIO1
|
||||
#define PIO1_2_OUTPUT ((0x01 << 0) | (0x01 << 7))
|
||||
#define PIO1_2_ADC 3
|
||||
|
||||
#define PIO1_3_CMSIS SWDIO_PIO1_3
|
||||
#define PIO1_3_PIN 3
|
||||
#define PIO1_3_PORT LPC_GPIO1
|
||||
#define PIO1_3_OUTPUT ((0x01 << 0) | (0x01 << 7))
|
||||
#define PIO1_3_ADC 4
|
||||
|
||||
#define PIO1_4_CMSIS PIO1_4
|
||||
#define PIO1_4_PIN 4
|
||||
#define PIO1_4_PORT LPC_GPIO1
|
||||
#define PIO1_4_OUTPUT (0x01 << 7)
|
||||
#define PIO1_4_ADC 5
|
||||
|
||||
#define PIO1_5_CMSIS PIO1_5
|
||||
#define PIO1_5_PIN 5
|
||||
|
|
|
|||
Loading…
Reference in New Issue