Skip to content

Commit

Permalink
Updating docs
Browse files Browse the repository at this point in the history
Signed-off-by: jw-smaal <[email protected]>
  • Loading branch information
jw-smaal committed Oct 22, 2020
1 parent 7497a39 commit e5693da
Show file tree
Hide file tree
Showing 5 changed files with 61 additions and 33 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,4 @@ projectfiles
BUILD
mbed-os
TextLCD
SerialMidi
1 change: 0 additions & 1 deletion SerialMidi.lib

This file was deleted.

29 changes: 11 additions & 18 deletions main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@

#include "serial-usart-midi.h"

// "global" semaphores
//Semaphore sem_led(1);


/////////////////////////////////////////////////////////////////
// MIDI callback functions
Expand Down Expand Up @@ -214,14 +211,14 @@ int main()
uint16_t b3in_value;
uint16_t tmp;

// I prefer the USB console port of the mbed to be 115200
// I prefer the USB console port of the mbed to be 115200
// This way printf's don't slow down the execution of the thread.
// too much.
BufferedSerial pc(USBTX, USBRX);
pc.set_baud(115200);

// Initialise the digital pin LED1 as an output
//DigitalOut led(LED3);
//DigitalOut stat1(PTC3);
DigitalOut stat2(PTC2);
// Initialise the digital pin STAT2 as an output
DigitalOut stat2(PTC2);

#if 0
// Test all the notes
Expand All @@ -233,17 +230,15 @@ int main()

// Test lower half the modulation wheel steps
for(i = 128; i < 500; i++) {
// explicit case required as there are two implementations
// of this one
// explicit cast required as there are two implementations
// of this one based on the bitsize of the int
serialMidiGlob.ModWheel(SerialMidi::CH1, (uint16_t)i);
// serialMidi.PitchWheel(CH1, (uint16_t)i);
}

// Test Pitch wheel
for(i = 0x1F00; i < 0x2100; i++) {
// explicit case required as there are two implementations
// explicit cast required as there are two implementations
// of this one
// serialMidi.ModWheel(CH1, (uint16_t)i);
serialMidiGlob.PitchWheel(SerialMidi::CH1, (uint16_t)i);
ThisThread::sleep_for(10ms);
}
Expand All @@ -256,26 +251,24 @@ int main()
}
serialMidiGlob.ModWheel(SerialMidi::CH1, (uint8_t)0);
#endif

// All tests complete start the threads.

thread_led1.start(led1_thread);
//thread_led2.start(led2_thread);

thread_midi_tx.start(midi_tx_thread);


while (true) {
// Toggle green stat2 LED.
// Toggle green stat2 LED.
stat2 = !stat2;

/*
* MIDI RX processing
*/
//printf("Main Thread\n");
serialMidiGlob.ReceiveParser();

} // End of while(1) loop

return 0;
} // End of main(1) loop

/* EOF */
9 changes: 4 additions & 5 deletions serial-usart-midi.cpp → serial-midi.cpp
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
/**
* serial-usart-midi.c
* Class that implements MIDI transmissions and parsing
/** SerialMidi Class that implements USART MIDI transmissions and parsing
* for parsing pointers to callbacks/delegates need to
* be provided at instanciation.
*
* Created by Jan-Willem Smaal on 21/12/2014.
* Ported to C++ on 21/10/2020 for ARM MBED platform
* Copyright (c) 2014 Jan-Willem Smaal. All rights reserved.
*
*/
#include "serial-usart-midi.h"
#include "serial-midi.h"
#include "mbed.h"
#include <cstdint>
#include <cstdio>
Expand All @@ -25,7 +24,7 @@ SerialMidi::SerialMidi (
void (*control_change_handler_ptr)(uint8_t controller, uint8_t value),
void (*midi_pitchwheel_ptr)(uint8_t valueLSB, uint8_t valueMSB)
)
: serial_port(PTC17, PTC16, MIDI_BAUD_RATE) // Override default constructor
: serial_port(USART_TX, USART_RX, MIDI_BAUD_RATE) // Override default constructor
{
// Assign delegate's
midi_note_on_delegate = note_on_handler_ptr;
Expand Down
54 changes: 45 additions & 9 deletions serial-usart-midi.h → serial-midi.h
Original file line number Diff line number Diff line change
@@ -1,20 +1,57 @@
/**
* serial-usart-midi.h
/** SerialMidi class
* Used for traditional USART MIDI communication at 31250 BAUD
* not suitable MIDI-USB. This MIDI implementations
* follows the MIDI specification strictly and employs running_status
* reducing data transmissions considerably.
*
* ported from C avr to C++ on ARM mbed platform
*
* Example:
* @code
* include "mbed.h"
* include "serial-midi.h"
*
* SerialMidi serialMidiGlob(
* &midi_note_on_handler,
* &realtime_handler,
* &midi_note_off_handler,
* &midi_control_change_handler,
* &midi_pitchwheel_handler
* );
*
*
* void midi_note_on_handler(uint8_t note, uint8_t velocity) {
* printf("midi_note_on_handler(%2X, %2X)\n", note, velocity);
* return;
*}
*
*int main(void) {
* while (true) {
* serialMidiGlob.ReceiveParser();
* }
* }
* @endcode
*
* Created by Jan-Willem Smaal on 21/12/14.
* ported to C++ on 20 Oct 2020
* Copyright (c) 2014 Jan-Willem Smaal. All rights reserved.
* APACHE 2.0 license - Copyright (c) 2014 Jan-Willem Smaal.
*/
#ifndef _SERIAL_USART_MIDI
#define _SERIAL_USART_MIDI

// Includes
// MBED OS Includes
#include <cstdint>
#include <stdint.h>
#include "MK64F12.h"
#include "mbed.h"

// Hardware specific defines
// TODO: adjust for your board!
#define USART_TX PTC17
#define USART_RX PTC16




/*-----------------------------------------------------------------------*/
// Defines
Expand Down Expand Up @@ -64,7 +101,8 @@

class SerialMidi {
public:
// During the SerialMidiInit the delegate callback functions need to be assigned
/** During the SerialMidiInit the delegate callback functions need to be assigned
*/
SerialMidi(
void (*note_on_handler_ptr)( uint8_t note, uint8_t velocity),
void (*realtime_handler_ptr)( uint8_t msg),
Expand Down Expand Up @@ -215,11 +253,9 @@ class SerialMidi {

BufferedSerial serial_port;

/**
* Required to be able to process MIDI data.
* while keeping running state.
/** Required to be able to process MIDI data.
* while keeping running state.
*/
//uint8_t global_running_status;
uint8_t global_running_status_tx;
uint8_t global_running_status_rx;
uint8_t global_3rd_byte_flag;
Expand Down

0 comments on commit e5693da

Please sign in to comment.