BLE MIDI TO UART MIDI

Dependencies:   BLE_API BufferedSerial mbed nRF51822

Fork of MIDI-to-BLE-MIDI-bridge by Samuele Cornell

Committer:
niklasjakob
Date:
Mon Jun 12 17:14:01 2017 +0000
Revision:
1:5cdcb9c72948
Parent:
0:244f1d0a3810
BLE RECEIVER

Who changed what in which revision?

UserRevisionLine numberNew contents of line
popcornell 0:244f1d0a3810 1 /*
popcornell 0:244f1d0a3810 2 * Copyright (c) 2016 Samuele Cornell
popcornell 0:244f1d0a3810 3 *
popcornell 0:244f1d0a3810 4 * Permission is hereby granted, free of charge, to any person obtaining a copy
popcornell 0:244f1d0a3810 5 * of this software and associated documentation files (the "Software"), to deal
popcornell 0:244f1d0a3810 6 * in the Software without restriction, including without limitation the rights
popcornell 0:244f1d0a3810 7 * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
popcornell 0:244f1d0a3810 8 * copies of the Software, and to permit persons to whom the Software is
popcornell 0:244f1d0a3810 9 * furnished to do so, subject to the following conditions:
popcornell 0:244f1d0a3810 10 *
popcornell 0:244f1d0a3810 11 * The above copyright notice and this permission notice shall be included in all
popcornell 0:244f1d0a3810 12 * copies or substantial portions of the Software.
popcornell 0:244f1d0a3810 13 *
popcornell 0:244f1d0a3810 14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
popcornell 0:244f1d0a3810 15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
popcornell 0:244f1d0a3810 16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
popcornell 0:244f1d0a3810 17 * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
popcornell 0:244f1d0a3810 18 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
popcornell 0:244f1d0a3810 19 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
popcornell 0:244f1d0a3810 20 * SOFTWARE.
popcornell 0:244f1d0a3810 21 *
popcornell 0:244f1d0a3810 22 */
popcornell 0:244f1d0a3810 23
popcornell 0:244f1d0a3810 24 #define UART_RX_PIN D0 // RX UART Pin
popcornell 0:244f1d0a3810 25
popcornell 0:244f1d0a3810 26 #define UART_TX_PIN D1 // TX UART Pin
popcornell 0:244f1d0a3810 27
popcornell 0:244f1d0a3810 28 // i have used DFRobot MIDI Shield but there are other commercially available similar products, also it is possible to interface directly a MIDI cable via an optocoupler (several projects are already available online )
popcornell 0:244f1d0a3810 29
popcornell 0:244f1d0a3810 30 #define LIGHT_SHOW 1 // 0 if visual feedback isn't needed (saves energy )
popcornell 0:244f1d0a3810 31
popcornell 0:244f1d0a3810 32 #define TX_LED D6 // the state of this led will change whenever a message is to be sent over ble-midi
popcornell 0:244f1d0a3810 33
popcornell 0:244f1d0a3810 34 #define RX_LED D7 // the state of this led will change whenever a message received over ble-midi
popcornell 0:244f1d0a3810 35
popcornell 0:244f1d0a3810 36
popcornell 0:244f1d0a3810 37 /*******************************************************************************************************
popcornell 0:244f1d0a3810 38 PERFORMANCE TWEAKS
popcornell 0:244f1d0a3810 39 *******************************************************************************************************/
popcornell 0:244f1d0a3810 40
popcornell 0:244f1d0a3810 41
popcornell 0:244f1d0a3810 42 #define BUFSERIAL_LENGHT 256 // define the software circular buffer lenght used for the UART.
popcornell 0:244f1d0a3810 43
popcornell 0:244f1d0a3810 44
popcornell 0:244f1d0a3810 45 #define ONLY_MIDI_to_BLEMIDI 0 // if only unidirectional MIDI to BLE-MIDI is desired set this to 1
popcornell 0:244f1d0a3810 46
popcornell 0:244f1d0a3810 47
popcornell 0:244f1d0a3810 48 #define ONLY_BLEMIDI_to_MIDI 0 // if only unidirectional BLE-MIDI to MIDI is desired set this to 1
popcornell 0:244f1d0a3810 49
popcornell 0:244f1d0a3810 50 // unidirectional operation allows to save energy. It also leads to better performance as if ONLY MIDI to BLE MIDI is required, for example it is possible to shorten the SENDBLE_INTERVAL
popcornell 0:244f1d0a3810 51 // without reliability issues (to a certain extent).
popcornell 0:244f1d0a3810 52
popcornell 0:244f1d0a3810 53 #define SENDBLEMIDI_INTERVAL 0.01 // this defines how frequently MIDI Events from the UART are polled, parsed and then sent via BLE-MIDI.
popcornell 0:244f1d0a3810 54 // a lower value means less latency but it also increase energy comsuption and if is set too low can cause reliability issues in MIDI to BLE-MIDI operation (especially for long SysEx messages).
popcornell 0:244f1d0a3810 55
popcornell 0:244f1d0a3810 56
popcornell 0:244f1d0a3810 57 /***************************************************************************************************************
popcornell 0:244f1d0a3810 58 CONNECTION PARAMETERS
popcornell 0:244f1d0a3810 59 ***************************************************************************************************************/
popcornell 0:244f1d0a3810 60
popcornell 0:244f1d0a3810 61 namespace Config {
popcornell 0:244f1d0a3810 62
popcornell 0:244f1d0a3810 63 //
popcornell 0:244f1d0a3810 64 const int minConnectionInterval = 6; // (1.25 ms units)
popcornell 0:244f1d0a3810 65 const int maxConnectionInterval = 15; // (1.25 ms units)
popcornell 0:244f1d0a3810 66 const int slaveLatency = 0;
popcornell 0:244f1d0a3810 67 const int supervisionTimeout = 500; // (10 ms units)
popcornell 0:244f1d0a3810 68
popcornell 0:244f1d0a3810 69
popcornell 0:244f1d0a3810 70
popcornell 0:244f1d0a3810 71 }