summaryrefslogtreecommitdiff
path: root/software
diff options
context:
space:
mode:
authorChristian Pointner <equinox@helsinki.at>2014-06-02 14:19:52 (GMT)
committerChristian Pointner <equinox@helsinki.at>2014-06-02 14:19:52 (GMT)
commitf6619f221a79604c5b7cbf37731a02453d185681 (patch)
tree9a099f9ad7b2b6db175cf18e58d2ea3c5de20c3c /software
parent78068e9588cdbd7d99c4334685d5b6664444d8bd (diff)
code cleanups
Diffstat (limited to 'software')
-rw-r--r--software/rhmixxx/gpio.c10
-rw-r--r--software/rhmixxx/gpio.h5
-rw-r--r--software/rhmixxx/keypad.c11
-rw-r--r--software/rhmixxx/keypad.h6
-rw-r--r--software/rhmixxx/rhmixxx.c25
5 files changed, 34 insertions, 23 deletions
diff --git a/software/rhmixxx/gpio.c b/software/rhmixxx/gpio.c
index 4b3171a..bd4906a 100644
--- a/software/rhmixxx/gpio.c
+++ b/software/rhmixxx/gpio.c
@@ -26,8 +26,6 @@
#define GPIO_PIN PINE
#define GPIO_PORT PORTE
#define GPIO_DDR DDRE
-#define GPIO_NUM_INPUTS 4
-#define GPIO_NUM_OUTPUTS 4
uint8_t input_last_sent[GPIO_NUM_INPUTS];
@@ -45,18 +43,24 @@ void gpio_out_on(uint8_t num)
{
if(num < GPIO_NUM_OUTPUTS)
GPIO_PORT |= (1 << num);
+ else
+ GPIO_PORT |= 0x0F;
}
void gpio_out_off(uint8_t num)
{
if(num < GPIO_NUM_OUTPUTS)
GPIO_PORT &= ~(1 << num);
+ else
+ GPIO_PORT &= 0xF0;
}
void gpio_out_toggle(uint8_t num)
{
if(num < GPIO_NUM_OUTPUTS)
GPIO_PORT ^= (1 << num);
+ else
+ GPIO_PORT ^= 0x0F;
}
void gpio_task(void)
@@ -66,7 +70,7 @@ void gpio_task(void)
uint8_t current_state = GPIO_PIN & (1<<(i+4));
if(current_state != input_last_sent[i]) {
input_last_sent[i] = current_state;
- eventqueue_push(i + 64, ((current_state) ? 0 : 1)); // TODO: offset should be defined somewhere
+ eventqueue_push(i + GPIO_MIDI_NOTE_OFFSET, ((current_state) ? 0 : 1));
}
}
}
diff --git a/software/rhmixxx/gpio.h b/software/rhmixxx/gpio.h
index 3c27d78..710c4e0 100644
--- a/software/rhmixxx/gpio.h
+++ b/software/rhmixxx/gpio.h
@@ -22,6 +22,11 @@
#ifndef RHMIXXX_gpio_h_INCLUDED
#define RHMIXXX_gpio_h_INCLUDED
+#define GPIO_NUM_INPUTS 4
+#define GPIO_NUM_OUTPUTS 4
+#define GPIO_MIDI_NOTE_OFFSET 32
+#define GPIO_MIDI_NOTE_ALL_OUTPUTS GPIO_MIDI_NOTE_OFFSET + 31
+
void gpio_init(void);
void gpio_out_on(uint8_t num);
diff --git a/software/rhmixxx/keypad.c b/software/rhmixxx/keypad.c
index f27c711..57a6380 100644
--- a/software/rhmixxx/keypad.c
+++ b/software/rhmixxx/keypad.c
@@ -28,9 +28,6 @@
#define KEYPAD_PIN PINA
#define KEYPAD_PORT PORTA
#define KEYPAD_DDR DDRA
-#define KEYPAD_NUM_COLS 4
-#define KEYPAD_NUM_ROWS 4
-#define KEYPAD_NUM_KEYS KEYPAD_NUM_COLS * KEYPAD_NUM_ROWS
#define KEYPAD_LP_CNT_MAX 200
static struct {
@@ -84,7 +81,7 @@ void keypad_led_on(uint8_t led)
case 13:
case 14:
case 15: PORTD |= (1 << (led - 12 + 4)); break;
- case 127: PORTC = 0xFF; PORTB |= 0xF0; PORTD |= 0xF0; break;
+ case KEYPAD_MIDI_NOTE_ALL - KEYPAD_MIDI_NOTE_OFFSET: PORTC = 0xFF; PORTB |= 0xF0; PORTD |= 0xF0; break;
}
keypad_led_blink(led, 0);
}
@@ -108,7 +105,7 @@ void keypad_led_off(uint8_t led)
case 13:
case 14:
case 15: PORTD &= ~(1 << (led - 12 + 4)); break;
- case 127: PORTC = 0x00; PORTB &= 0x0F; PORTD &= 0x0F; break;
+ case KEYPAD_MIDI_NOTE_ALL - KEYPAD_MIDI_NOTE_OFFSET: PORTC = 0x00; PORTB &= 0x0F; PORTD &= 0x0F; break;
}
keypad_led_blink(led, 0);
}
@@ -132,7 +129,7 @@ void keypad_led_toggle(uint8_t led)
case 13:
case 14:
case 15: PORTD ^= (1 << (led - 12 + 4)); break;
- case 127: PORTC ^= 0xFF; PORTB ^= 0xF0; PORTD ^= 0xF0; break;
+ case KEYPAD_MIDI_NOTE_ALL - KEYPAD_MIDI_NOTE_OFFSET: PORTC ^= 0xFF; PORTB ^= 0xF0; PORTD ^= 0xF0; break;
}
}
@@ -160,7 +157,7 @@ static inline void keypad_key_lowpass(uint8_t key_idx, uint8_t current_state)
if(current_state != keypad_state[key_idx].last_sent) {
keypad_state[key_idx].last_sent = current_state;
- eventqueue_push(key_idx, ((current_state) ? 0 : 1));
+ eventqueue_push(KEYPAD_MIDI_NOTE_OFFSET + key_idx, ((current_state) ? 0 : 1));
}
}
}
diff --git a/software/rhmixxx/keypad.h b/software/rhmixxx/keypad.h
index 92c4188..87ab9c8 100644
--- a/software/rhmixxx/keypad.h
+++ b/software/rhmixxx/keypad.h
@@ -22,6 +22,12 @@
#ifndef RHMIXXX_keypad_h_INCLUDED
#define RHMIXXX_keypad_h_INCLUDED
+#define KEYPAD_NUM_COLS 4
+#define KEYPAD_NUM_ROWS 4
+#define KEYPAD_NUM_KEYS KEYPAD_NUM_COLS * KEYPAD_NUM_ROWS
+#define KEYPAD_MIDI_NOTE_OFFSET 0
+#define KEYPAD_MIDI_NOTE_ALL KEYPAD_MIDI_NOTE_OFFSET + 31
+
void keypad_init(void);
void keypad_led_on(uint8_t led);
diff --git a/software/rhmixxx/rhmixxx.c b/software/rhmixxx/rhmixxx.c
index d5ac080..f94b67b 100644
--- a/software/rhmixxx/rhmixxx.c
+++ b/software/rhmixxx/rhmixxx.c
@@ -83,24 +83,23 @@ static void process_incoming_midi(void)
uint8_t cmd = ReceivedMIDIEvent.Data1 & 0xF0;
uint8_t note = ReceivedMIDIEvent.Data2;
uint8_t value = ReceivedMIDIEvent.Data3 & 0x7F;
- if(note < 16 || note == 0x7F) { // KEYPAD
+ if((note >= KEYPAD_MIDI_NOTE_OFFSET && note < KEYPAD_MIDI_NOTE_OFFSET + KEYPAD_NUM_KEYS) || // KEYPAD
+ note == KEYPAD_MIDI_NOTE_ALL) {
if(cmd == MIDI_COMMAND_NOTE_ON) {
- if(value <= 2) {
- switch(value) {
- case 0: keypad_led_off(note); break;
- case 1: keypad_led_on(note); break;
- case 2: keypad_led_toggle(note); break;
- }
- } else if(value <= 0x7F) {
- keypad_led_blink(note, value);
+ switch(value) {
+ case 0: keypad_led_off(note - KEYPAD_MIDI_NOTE_OFFSET); break;
+ case 1: keypad_led_on(note - KEYPAD_MIDI_NOTE_OFFSET); break;
+ case 2: keypad_led_toggle(note - KEYPAD_MIDI_NOTE_OFFSET); break;
+ default: keypad_led_blink(note, value); break;
}
}
- } else if(note >= 64 && note <= 68) { // GPIO
+ } else if((note >= GPIO_MIDI_NOTE_OFFSET && note < GPIO_MIDI_NOTE_OFFSET + GPIO_NUM_OUTPUTS) || // GPIO
+ note == GPIO_MIDI_NOTE_ALL_OUTPUTS) {
if(cmd == MIDI_COMMAND_NOTE_ON) {
switch(value) {
- case 0: gpio_out_off(note - 64); break;
- case 1: gpio_out_on(note - 64); break;
- case 2: gpio_out_toggle(note - 64); break;
+ case 0: gpio_out_off(note - GPIO_MIDI_NOTE_OFFSET); break;
+ case 1: gpio_out_on(note - GPIO_MIDI_NOTE_OFFSET); break;
+ case 2: gpio_out_toggle(note - GPIO_MIDI_NOTE_OFFSET); break;
}
}
}