diff options
-rw-r--r-- | software/rhmixxx/Makefile | 2 | ||||
-rw-r--r-- | software/rhmixxx/analog.c | 46 | ||||
-rw-r--r-- | software/rhmixxx/analog.h | 1 | ||||
-rw-r--r-- | software/rhmixxx/rhmixxx.c | 24 |
4 files changed, 70 insertions, 3 deletions
diff --git a/software/rhmixxx/Makefile b/software/rhmixxx/Makefile index 60531a5..ae51e01 100644 --- a/software/rhmixxx/Makefile +++ b/software/rhmixxx/Makefile @@ -41,3 +41,5 @@ LUFA_OPTS += -D USB_PRODUCT="L\"rhmixxx midi controller\"" -D USB_PRODUCT_LEN=23 LUFA_COMPONENTS := USB USBCLASS SERIAL include ../include.mk + +CFLAGS += -DDISABLE_ANALOG 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 } diff --git a/software/rhmixxx/analog.h b/software/rhmixxx/analog.h index 925f5a6..4c98157 100644 --- a/software/rhmixxx/analog.h +++ b/software/rhmixxx/analog.h @@ -26,6 +26,7 @@ #define ANALOG_MIDI_NOTE_OFFSET 64 void analog_init(void); +uint8_t analog_get_value(uint8_t channel); void analog_task(void); #endif diff --git a/software/rhmixxx/rhmixxx.c b/software/rhmixxx/rhmixxx.c index 3e3d66f..f77c23a 100644 --- a/software/rhmixxx/rhmixxx.c +++ b/software/rhmixxx/rhmixxx.c @@ -125,13 +125,30 @@ static void process_outgoing_midi(void) .Data2 = 0,
.Data3 = 0,
};
+ MIDI_EventPacket_t MIDIEventAnalog = (MIDI_EventPacket_t)
+ {
+ .CableNumber = 0, // TODO: hardcoded value
+ .Command = (MIDI_COMMAND_NOTE_ON >> 4),
+ .Data1 = MIDI_COMMAND_NOTE_ON | 0,
+ .Data2 = 0,
+ .Data3 = 0,
+ };
uint8_t key, state;
while(eventqueue_pop(&key, &state)) {
if (USB_DeviceState == DEVICE_STATE_Configured) {
- MIDI_EventPacket_t* MIDIEvent = state ? &MIDIEventOn : &MIDIEventOff;
- MIDIEvent->Data2 = key;
- MIDI_Device_SendEventPacket(&MIDI_Interface, MIDIEvent);
+ MIDI_EventPacket_t* MIDIEvent = NULL;
+ if(key >= ANALOG_MIDI_NOTE_OFFSET && key < ANALOG_MIDI_NOTE_OFFSET + ANALOG_NUM_INPUTS) {
+ MIDIEvent = &MIDIEventAnalog;
+ MIDIEvent->Data2 = key;
+ MIDIEvent->Data3 = analog_get_value(key - ANALOG_MIDI_NOTE_OFFSET);
+ } else {
+ MIDIEvent = state ? &MIDIEventOn : &MIDIEventOff;
+ MIDIEvent->Data2 = key;
+ }
+
+ if(MIDIEvent)
+ MIDI_Device_SendEventPacket(&MIDI_Interface, MIDIEvent);
}
}
if (USB_DeviceState == DEVICE_STATE_Configured)
@@ -157,6 +174,7 @@ int main(void) keypad_task();
gpio_task();
+ analog_task();
process_outgoing_midi();
|