diff options
| author | Donald Delmar Davis <don@suspectdevices.com> | 2013-04-18 01:02:16 -0700 |
|---|---|---|
| committer | Donald Delmar Davis <don@suspectdevices.com> | 2013-04-18 01:02:16 -0700 |
| commit | e6de0a9b4152c0b004d258f3adf0236efb2b4b6b (patch) | |
| tree | 22da18e848bf012780fd3ccd68e93c81898c981e | |
| parent | d00237f1bd8cf886d4b4662c7c4c2cb037e1a431 (diff) | |
Rough in of reset
| -rw-r--r-- | libmaple/MidiSpecs.h | 11 | ||||
| -rw-r--r-- | libmaple/MinSysex.c | 126 | ||||
| -rw-r--r-- | libmaple/MinSysex.h | 9 |
3 files changed, 139 insertions, 7 deletions
diff --git a/libmaple/MidiSpecs.h b/libmaple/MidiSpecs.h index 0cc618c..5e0be20 100644 --- a/libmaple/MidiSpecs.h +++ b/libmaple/MidiSpecs.h @@ -133,6 +133,17 @@ typedef struct // may need to be adjusted for other compilers and bitfield order #define MIDIv1_UNIVERSAL_REALTIME_ID 0x7F #define MIDIv1_UNIVERSAL_NON_REALTIME_ID 0x7E #define MIDIv1_UNIVERSAL_ALL_CHANNELS 0x7F +/* + * Susbset of universal sysex (general info request) + * As described http://www.blitter.com/~russtopia/MIDI/~jglatt/tech/midispec.htm + */ +#define USYSEX_NON_REAL_TIME 0x7E +#define USYSEX_REAL_TIME 0x7F +#define USYSEX_ALL_CHANNELS 0x7F +#define USYSEX_GENERAL_INFO 0x06 +#define USYSEX_GI_ID_REQUEST 0x01 +#define USYSEX_GI_ID_RESPONSE 0x02 + #endif diff --git a/libmaple/MinSysex.c b/libmaple/MinSysex.c index 350ebb6..9b42771 100644 --- a/libmaple/MinSysex.c +++ b/libmaple/MinSysex.c @@ -13,16 +13,134 @@ 0x06 Sub-ID -- General Information 0x01 Sub-ID2 -- Identity Request 0xF7 End of SysEx -*/ +---- response + 0xF0 SysEx + 0x7E Non-Realtime + 0x7F The SysEx channel. Could be from 0x00 to 0x7F. + Here we set it to "disregard channel". + 0x06 Sub-ID -- General Information + 0x02 Sub-ID2 -- Identity Reply + 0xID Manufacturer's ID + 0xf1 The f1 and f2 bytes make up the family code. Each + 0xf2 manufacturer assigns different family codes to his products. + 0xp1 The p1 and p2 bytes make up the model number. Each + 0xp2 manufacturer assigns different model numbers to his products. + 0xv1 The v1, v2, v3 and v4 bytes make up the version number. + 0xv2 + 0xv3 + 0xv4 + 0xF7 End of SysEx +*/ +// change this to packets +#define STANDARD_ID_RESPONSE_LENGTH 24 #include <libmaple/usb_midi_device.h> +#include <libmaple/nvic.h> +#include <libmaple/delay.h> #include <MinSysex.h> +//#include <wirish/wirish.h> + + #define MAX_SYSEX_SIZE 256 + +/********************************* ACHTUNG! ignores usbmidi cable ********************************/ +const uint8 standardIDResponse[]={ + CIN_SYSEX, + MIDIv1_SYSEX_START, + USYSEX_NON_REAL_TIME, + USYSEX_ALL_CHANNELS, + CIN_SYSEX, + USYSEX_GENERAL_INFO, + USYSEX_GI_ID_RESPONSE, + LEAFLABS_MMA_VENDOR_1, + CIN_SYSEX, + LEAFLABS_MMA_VENDOR_2, // extended ID + LEAFLABS_MMA_VENDOR_3, // extended ID + 1, // family #1 + CIN_SYSEX, + 2, // family #2 + 1, // part #1 + 2, // part #2 + CIN_SYSEX, + 0, // version 1 + 0, // version 2 + 1, // version 3 + CIN_SYSEX_ENDS_IN_2, + '!', // lgl compatible + MIDIv1_SYSEX_END, + 0 +}; +//#define STANDARD_ID_RESPONSE_LENGTH (sizeof(standardIDResponse)) + typedef enum {NOT_IN_SYSEX=0,IN_SYSEX,COULD_BE_MY_SYSEX,YUP_ITS_MY_SYSEX,ITS_NOT_MY_SYSEX,I_GOT_MY_SYSEX} sysexStates; volatile uint8 sysexBuffer[MAX_SYSEX_SIZE]; volatile sysexStates sysexState; volatile int sysexFinger=0; + +/* + 0xF0 SysEx + 0x?? LEAFLABS_MMA_VENDOR_1 + 0x?? LEAFLABS_MMA_VENDOR_2 + + 0x?? LEAFLABS_MMA_VENDOR_3 + 0x10 LGL_DEVICE_NUMBER + 0xLE CMD: REBOOT + + 0xf7 EOSysEx +*/ +#define STACK_TOP 0x20000800 +#define EXC_RETURN 0xFFFFFFF9 +#define DEFAULT_CPSR 0x61000000 +#define RESET_DELAY 100000 +static void wait_reset(void) { + delay_us(RESET_DELAY); + nvic_sys_reset(); +} + + void dealWithItQuickly(){ + switch (sysexBuffer[1]) { + case USYSEX_NON_REAL_TIME: + switch (sysexBuffer[3]) { + case USYSEX_GENERAL_INFO: + if (sysexBuffer[4]==USYSEX_GI_ID_REQUEST) { + usb_midi_tx(standardIDResponse, STANDARD_ID_RESPONSE_LENGTH); + } + } + case USYSEX_REAL_TIME: + break; + case LEAFLABS_MMA_VENDOR_1: + if (sysexBuffer[5]==LGL_RESET_CMD) { + uintptr_t target = (uintptr_t)wait_reset | 0x1; + asm volatile("mov r0, %[stack_top] \n\t" // Reset stack + "mov sp, r0 \n\t" + "mov r0, #1 \n\t" + "mov r1, %[target_addr] \n\t" + "mov r2, %[cpsr] \n\t" + "push {r2} \n\t" // Fake xPSR + "push {r1} \n\t" // PC target addr + "push {r0} \n\t" // Fake LR + "push {r0} \n\t" // Fake R12 + "push {r0} \n\t" // Fake R3 + "push {r0} \n\t" // Fake R2 + "push {r0} \n\t" // Fake R1 + "push {r0} \n\t" // Fake R0 + "mov lr, %[exc_return] \n\t" + "bx lr" + : + : [stack_top] "r" (STACK_TOP), + [target_addr] "r" (target), + [exc_return] "r" (EXC_RETURN), + [cpsr] "r" (DEFAULT_CPSR) + : "r0", "r1", "r2"); + /* Can't happen. */ + ASSERT_FAULT(0); + + } + + default: + break; + } ;//turn the led on? } @@ -43,10 +161,10 @@ void LglSysexHandler(uint8 *midiBufferRx,uint32 *rx_offset,uint32 *n_unread_byte case NOT_IN_SYSEX : // new sysex. sysexFinger=0; if (packet->midi0 == MIDIv1_SYSEX_START) { - if (packet->midi1==MIDIv1_UNIVERSAL_REALTIME_ID - ||packet->midi1==MIDIv1_UNIVERSAL_NON_REALTIME_ID) { + if (packet->midi1==USYSEX_REAL_TIME + ||packet->midi1==USYSEX_NON_REAL_TIME) { if ((packet->midi2==myMidiChannel) - ||(packet->midi2==MIDIv1_UNIVERSAL_ALL_CHANNELS) + ||(packet->midi2==USYSEX_ALL_CHANNELS) ) { sysexState=YUP_ITS_MY_SYSEX; sysexBuffer[sysexFinger++]=MIDIv1_SYSEX_START; diff --git a/libmaple/MinSysex.h b/libmaple/MinSysex.h index c882d74..c9fa358 100644 --- a/libmaple/MinSysex.h +++ b/libmaple/MinSysex.h @@ -5,17 +5,20 @@ // Created by Donald D Davis on 4/11/13. // Copyright (c) 2013 Suspect Devices. All rights reserved. // -#ifndef __LETS_MIN_SYSEX_H__ -#define __LETS_MIN_SYSEX_H__ 1 +#ifndef __LGL_MIN_SYSEX_H__ +#define __LGL_MIN_SYSEX_H__ 1 #include "MidiSpecs.h" - +//#include "LGL.h" #define LEAFLABS_MMA_VENDOR_1 0x7D #define LEAFLABS_MMA_VENDOR_2 0x1E #define LEAFLABS_MMA_VENDOR_3 0x4F +// move to LGL.h +#define LGL_RESET_CMD 0x1e + #define DEFAULT_MIDI_CHANNEL 0x0A #define DEFAULT_MIDI_DEVICE 0x0A #define DEFAULT_MIDI_CABLE 0x00 |
