aboutsummaryrefslogtreecommitdiffstats
path: root/src/wiring/wiring_analog.c
diff options
context:
space:
mode:
authoriperry <iperry@749a229e-a60e-11de-b98f-4500b42dc123>2009-12-17 02:37:07 +0000
committeriperry <iperry@749a229e-a60e-11de-b98f-4500b42dc123>2009-12-17 02:37:07 +0000
commit32e57dac2e61e79b029593eb4d34d727bcc10678 (patch)
tree98d7ff41993576bb150d13d5f63dc744f6812852 /src/wiring/wiring_analog.c
downloadlibrambutan-32e57dac2e61e79b029593eb4d34d727bcc10678.tar.gz
librambutan-32e57dac2e61e79b029593eb4d34d727bcc10678.zip
Initial commit of library code, moved from leaftest repo
git-svn-id: https://leaflabs.googlecode.com/svn/trunk/library@69 749a229e-a60e-11de-b98f-4500b42dc123
Diffstat (limited to 'src/wiring/wiring_analog.c')
-rw-r--r--src/wiring/wiring_analog.c33
1 files changed, 33 insertions, 0 deletions
diff --git a/src/wiring/wiring_analog.c b/src/wiring/wiring_analog.c
new file mode 100644
index 0000000..abcf7c6
--- /dev/null
+++ b/src/wiring/wiring_analog.c
@@ -0,0 +1,33 @@
+#include "adc.h"
+#include "gpio.h"
+#include "wiring.h"
+#include <stdio.h>
+
+/* Indexed by pins A[0-15] */
+uint32_t PIN_TO_ADC[NR_ANALOG_PINS] = {
+ 10, // A0/D14 ADC10
+ 11, // A1/D15 ADC11
+ 12, // A2/D16 ADC12
+ 13, // A3/D17 ADC13
+ 14, // A4/D18 ADC14
+ 15, // A5/D19 ADC15
+ 3, // A6/D0 ADC3
+ 2, // A7/D1 ADC2
+ 0, // A8/D2 ADC0
+ 1, // A9/D3 ADC1
+ 4, // A10/D10 ADC4
+ 7, // A11/D11 ADC7
+ 6, // A12/D12 ADC6
+ 5, // A13/D13 ADC5
+ 8, // A14/D26 ADC8
+ 9, // A15/D11 ADC9
+};
+
+/* Assumes that the ADC has been initialized and
+ * that the pin is set to ANALOG_INPUT */
+uint32_t analogRead(uint8_t pin) {
+ if (pin >= NR_ANALOG_PINS)
+ return 0;
+
+ return adc_read(PIN_TO_ADC[pin]);
+}