summaryrefslogtreecommitdiff
path: root/software/rhmixxx/analog.c
diff options
context:
space:
mode:
authorChristian Pointner <equinox@helsinki.at>2014-06-03 02:19:59 (GMT)
committerChristian Pointner <equinox@helsinki.at>2014-06-03 02:19:59 (GMT)
commitc7befc2a68d78c3bd445433dc55bdc70ea2276e7 (patch)
tree87b7407b5be316ea7afae279a4df8e744b4a6476 /software/rhmixxx/analog.c
parent8cba9d9165c6645a94c8ea97bd15f43674984997 (diff)
added support for analog pins (not perfect...)
Diffstat (limited to 'software/rhmixxx/analog.c')
-rw-r--r--software/rhmixxx/analog.c46
1 files changed, 46 insertions, 0 deletions
diff --git a/software/rhmixxx/analog.c b/software/rhmixxx/analog.c
index 45c89b0..e15c2eb 100644
--- a/software/rhmixxx/analog.c
+++ b/software/rhmixxx/analog.c
@@ -27,10 +27,56 @@
#define ANALOG_PORT PORTF
#define ANALOG_DDR DDRF
+#ifndef DISABLE_ANALOG
+
+#include <LUFA/Drivers/Peripheral/ADC.h>
+uint8_t analog_last_sent[ANALOG_NUM_INPUTS];
+static uint8_t analog_channels[] = { ADC_CHANNEL0, ADC_CHANNEL1, ADC_CHANNEL2, ADC_CHANNEL3,
+ ADC_CHANNEL4, ADC_CHANNEL5, ADC_CHANNEL6, ADC_CHANNEL7 };
+
+#endif
+
void analog_init(void)
{
+ ANALOG_DDR = 0x00;
+ ANALOG_PORT = 0x00;
+
+#ifndef DISABLE_ANALOG
+ int i;
+ for(i = 0; i < ANALOG_NUM_INPUTS; ++i)
+ analog_last_sent[i] = 0;
+
+ ADC_Init(ADC_SINGLE_CONVERSION | ADC_PRESCALE_2);
+ ADC_SetupChannel(ADC_CHANNEL0);
+ ADC_SetupChannel(ADC_CHANNEL1);
+ ADC_SetupChannel(ADC_CHANNEL2);
+ ADC_SetupChannel(ADC_CHANNEL3);
+ ADC_SetupChannel(ADC_CHANNEL4);
+ ADC_SetupChannel(ADC_CHANNEL5);
+ ADC_SetupChannel(ADC_CHANNEL6);
+ ADC_SetupChannel(ADC_CHANNEL7);
+#endif
+}
+
+uint8_t analog_get_value(uint8_t channel)
+{
+#ifndef DISABLE_ANALOG
+ if(channel < ANALOG_NUM_INPUTS)
+ return analog_last_sent[channel];
+#endif
+ return 0;
}
void analog_task(void)
{
+#ifndef DISABLE_ANALOG
+ uint8_t i;
+ for(i = 0; i < ANALOG_NUM_INPUTS; ++i) {
+ uint8_t tmp = (ADC_GetChannelReading(ADC_REFERENCE_AVCC | ADC_RIGHT_ADJUSTED | analog_channels[i])) >> 3;
+ if(analog_last_sent[i] != tmp) {
+ analog_last_sent[i] = tmp;
+ eventqueue_push(ANALOG_MIDI_NOTE_OFFSET + i, 0);
+ }
+ }
+#endif
}