summaryrefslogtreecommitdiff
path: root/src/lpc/ao_arch_funcs.h
diff options
context:
space:
mode:
authorKeith Packard <keithp@keithp.com>2013-06-14 04:38:11 -0700
committerKeith Packard <keithp@keithp.com>2013-06-15 01:21:39 -0700
commit7361371190bf3805b6d0414e61f697aca7c7cff1 (patch)
tree9f3709ecaedfb4833f450e4c5402a34e1d2eae4b /src/lpc/ao_arch_funcs.h
parent6827d0a7c59d606ea05387465f1ad4d914babd49 (diff)
altos/lpc: Make ADC inputs work
They're still very unstable (bouncing around a lot), but at least they seem to report useful stuff now. Signed-off-by: Keith Packard <keithp@keithp.com>
Diffstat (limited to 'src/lpc/ao_arch_funcs.h')
-rw-r--r--src/lpc/ao_arch_funcs.h18
1 files changed, 14 insertions, 4 deletions
diff --git a/src/lpc/ao_arch_funcs.h b/src/lpc/ao_arch_funcs.h
index 204d1227..179b2f4d 100644
--- a/src/lpc/ao_arch_funcs.h
+++ b/src/lpc/ao_arch_funcs.h
@@ -51,12 +51,22 @@
(1 << LPC_IOCONF_ADMODE)); \
} while (0)
-#define ao_enable_analog(port,bit) do { \
- vuint32_t *_ioconf = &lpc_ioconf.pio0_0 + ((port)*24+(bit)); \
+#define lpc_token_paster_2(x,y) x ## y
+#define lpc_token_evaluator_2(x,y) lpc_token_paster_2(x,y)
+#define lpc_token_paster_3(x,y,z) x ## y ## z
+#define lpc_token_evaluator_3(x,y,z) lpc_token_paster_3(x,y,z)
+#define lpc_token_paster_4(w,x,y,z) w ## x ## y ## z
+#define lpc_token_evaluator_4(w,x,y,z) lpc_token_paster_4(w,x,y,z)
+#define analog_reg(port,bit) lpc_token_evaluator_4(pio,port,_,bit)
+#define analog_func(id) lpc_token_evaluator_2(LPC_IOCONF_FUNC_AD,id)
+
+#define ao_enable_analog(port,bit,id) do { \
+ uint32_t _mode; \
ao_enable_port(port); \
lpc_gpio.dir[port] &= ~(1 << bit); \
- *_ioconf = *_ioconf & ~((1 << LPC_IOCONF_ADMODE) | \
- (LPC_IOCONF_MODE_MASK << LPC_IOCONF_MODE)); \
+ _mode = ((analog_func(id) << LPC_IOCONF_FUNC) | \
+ (0 << LPC_IOCONF_ADMODE)); \
+ lpc_ioconf.analog_reg(port,bit) = _mode; \
} while (0)
#define ARM_PUSH32(stack, val) (*(--(stack)) = (val))