From ed60865743a5d65240c9da353edb4dc20cf7009f Mon Sep 17 00:00:00 2001 From: Duncan Wilkie Date: Tue, 18 Jul 2023 11:55:03 -0500 Subject: Rename, add startup file. --- controller/inc/base_midi.h | 206 ++++++++++++++++++++++++++++++++++++++++++++ controller/inc/midi.h | 207 --------------------------------------------- controller/inc/startup.h | 173 +++++++++++++++++++++++++++++++++++++ 3 files changed, 379 insertions(+), 207 deletions(-) create mode 100644 controller/inc/base_midi.h delete mode 100644 controller/inc/midi.h create mode 100644 controller/inc/startup.h (limited to 'controller/inc') diff --git a/controller/inc/base_midi.h b/controller/inc/base_midi.h new file mode 100644 index 0000000..e566a6f --- /dev/null +++ b/controller/inc/base_midi.h @@ -0,0 +1,206 @@ +#ifndef MIDI_H +#define MIDI_H + +#include +#include +#include + +// Configuration. +#define DEBUG 0 // If defined, enable input safety checking (e.g. too large data bytes, bad ID numbers, etc). + // These checks have some performance downside. +#define RUNNING_STATUS 0 // If defined, the MIDI instrument stores a transmit status and uses running statuses whenever possible. +#define KEY_ON_VELOCITY 0 // If defined, the MIDI instrument sends velocities with Note On messages. +#undef RELEASE_VELOCITY // If defined, the MIDI instrument sends Note Off messages with velocities. + // Otherwise, sends Note On velocity 0 or Note Off velocity 0 according to ACTUAL_OFF_MESSAGE. +#undef ACTUAL_OFF_MESSAGE // If defined, the MIDI instrument sends true Note Off messages. + // Otherwise sends Note On velocity 0 (so as to exploit running status). +#undef EXPORT_CONTROLLERS // If defined, export constants useful for controller messages. + +// Consumers must specify +typedef struct { + void (*uart_write)(uint8_t); // Blocking, single-byte UART transmit function. + // Channel voice handlers. + void (*note_on_handler)(uint8_t, uint8_t, uint8_t); + void (*note_off_handler)(uint8_t, uint8_t, uint8_t); + void (*poly_key_handler)(uint8_t, uint8_t, uint8_t); + void (*control_change_handler)(uint8_t, uint8_t, uint8_t); + void (*program_change_handler)(uint8_t, uint8_t); + void (*aftertouch_handler)(uint8_t, uint8_t); + void (*pitch_bend_change_handler)(uint8_t, uint8_t); + // Channel mode handlers. + void (*all_sound_off_handler)(uint8_t); + void (*reset_all_controllers_handler)(uint8_t); + void (*local_control_handler)(uint8_t, uint8_t); + void (*all_notes_off_handler)(uint8_t); + void (*omni_on_handler)(uint8_t); + void (*omni_off_handler)(uint8_t); + void (*mono_on_handler)(uint8_t, uint8_t); + void (*poly_on_handler)(uint8_t); + // System common handlers. + void (*mtc_quarter_frame_handler)(uint8_t, uint8_t); + void (*song_position_pointer_handler)(uint8_t, uint8_t); + void (*song_select_handler)(uint8_t); + void (*tune_request_handler)(); + // System real time handlers. + void (*timing_clock_handler)(); + void (*start_handler)(); + void (*continue_handler)(); + void (*stop_handler)(); + void (*active_sensing_handler)(); + void (*system_reset_handler)(); + // System Exclusive handlers. + bool (*sysex_collector)(uint8_t); // Feeds most recent byte system exclusive byte (status and eox excluded, ID included) + // to client, returning false whenever the client determines sysex can be safely discarded. + // Client is expected to maintain parsing state externally, + // including resetting correctly after aborted parses. + // Client also should not abort the parse before the first post-manufacturer-ID byte. + void (*end_of_sysex_handler)(); // Sent only when client + // Universal System Exclusive handlers. + void (*bulk_tuning_dump_request_handler)(uint8_t, uint8_t); + void (*bulk_tuning_dump_handler)(uint8_t, uint8_t, char*, uint8_t*); + void (*single_note_tuning_change_handler)(uint8_t, uint8_t, uint8_t, uint8_t*); + // TODO: more. + bool (*unimplemented_universal_sysex_collector)(uint8_t); // Same as above. Parsing ends with end_of_sysex_handler. +} ConsumerBehavior; + +extern ConsumerBehavior pfns; // Initialize this globally in your main. + +// System exclusive sends. +void sysex(uint16_t manufacturer_id, uint8_t* contents, size_t contents_len); +void universal_nonrealtime(uint8_t device_id, uint16_t sub_id, uint8_t* contents, size_t contents_len); +void universal_realtime(uint8_t device_id, uint16_t sub_id, uint8_t* contents, size_t contents_len); + +// Channel voice sends. +#ifdef KEY_ON_VELOCITY +void note_on(uint8_t channel, uint8_t note, uint8_t velocity); +#else +void note_on(uint8_t channel, uint8_t note); +#endif +#ifdef RELEASE_VELOCITY +void note_off(uint8_t channel, uint8_t note, uint8_t velocity); +#else +void note_off(uint8_t channel, uint8_t note); +#endif +void control_change(uint8_t channel, uint8_t controller_number, uint8_t control_value); +void program_change(uint8_t channel, uint8_t program_number); +void aftertouch(uint8_t channel, uint8_t pressure_value); +void pitch_bend_change(uint8_t channel, uint16_t pressure_value); + +// Channel mode sends. +void all_sound_off(uint8_t channel); +void reset_all_controllers(uint8_t channel); +void local_control_on(uint8_t channel); +void local_control_off(uint8_t channel); +void all_notes_off(uint8_t channel); +void omni_on(uint8_t channel); +void omni_off(uint8_t channel); +void mono_on(uint8_t channel, uint8_t channel_count); +void poly_on(uint8_t channel); + + +// System Common sends. +// MTC Quarter Frame unimplemented. +void song_position_pointer(uint16_t position); +void song_select(uint8_t song); +void tune_request(); + +// System Real Time sends. +void timing_clock(); +void srt_start(); +void srt_continue(); +void srt_stop(); +void active_sensing(); +void MIDI_reset(); + +// Universal SysEx. +// Only implement MTS; consumers can do their own parsing via unimplemented_universal_sysex_collector. + +// MIDI Tuning Standard sends. +void bulk_tuning_dump_request(uint8_t device_id, uint8_t program); +void bulk_tuning_dump(uint8_t device_id, uint8_t program, char* name, uint8_t* tuning_data); +void single_note_tuning_change(uint8_t device_id, uint8_t program, uint8_t *note_tuning_data, uint8_t keys_changed); + + +// Feed bytes to this in the UART interrupt handler. +void parse_midi_stream(uint8_t byte); + + +// Public constants; magic numbers useful for consumers. +#define ALL_CALL_DEVICE_ID 0x7f +#define DEVICE_KEY_COUNT 128 +#define TUNING_LENGTH (3 * DEVICE_KEY_COUNT) +#define TUNING_NAME_LENGTH 16 +#define NOTE_TUNING_BYTES_PER_KEY 4 + + +#ifdef EXPORT_CONTROLLERS +// Controller constants. +typedef enum Controller { + BANK_SELECT = 0, + MODULATION_WHEEL = 1, + BREATH_CONTROLLER = 2, + // Undefined + FOOT_CONTROLLER = 4, + PORTAMENTO_TIME = 5, + DATA_ENTRY_MSB = 6, + CHANNEL_VOLUME = 7, + BALANCE = 8, + // Undefined + PAN = 10, + EXPRESSION = 11, + EFFECT1 = 12, + EFFECT2 = 13, + // Undefined + GP1 = 16, + GP2 = 17, + GP3 = 18, + GP4 = 19, + DAMPER_PEDAL = 64, + PORTAMENTO_TOGGLE = 65, + SOSTENUTO = 66, + SOFT_PEDAL = 67, + LEGATO_FOOTSWITCH = 68, + HOLD2 = 69, + SC1_SOUND_VARIATION = 70, + SC2_TIMBRE = 71, + SC3_RELEASE_TIME = 72, + SC4_ATTACK_TIME = 73, + SC5_BRIGHTNESS = 74, + SC6 = 75, + SC7 = 76, + SC8 = 77, + SC9 = 78, + SC10 = 79, + GP5 = 80, + GP6 = 81, + GP7 = 82, + GP8 = 83, + PORTAMENTO_CONTROL = 84, + // Undefined + EFFECTS_DEPTH1 = 91, + EFFECTS_DEPTH2 = 92, + EFFECTS_DEPTH3 = 93, + EFFECTS_DEPTH4 = 94, + EFFECTS_DEPTH5 = 95, + DATA_INCREMENT = 96, + DATA_DECREMENT = 97, + NONREGISTERED_LSB = 98, + NONREGISTERED_MSB = 99, + REGISTERED_LSB = 100, + REGISTERED_MSB = 101, + // undefined 102-119 + // reserved for channel mode 120-127 +}; + +typedef enum RegisteredParams { + PITCH_BEND_SENSITIVITY = 0, + FINE_TUNING = 1, + COARSE_TUNING = 2, + TUNING_PROGRAM_SELECT = 3, + TUNING_BANK_SELECT = 4 +}; + +#endif + + +#endif diff --git a/controller/inc/midi.h b/controller/inc/midi.h deleted file mode 100644 index 819db03..0000000 --- a/controller/inc/midi.h +++ /dev/null @@ -1,207 +0,0 @@ -#ifndef MIDI_H -#define MIDI_H - -#include -#include -#include - -// Configuration. - -#define DEBUG 0 // If defined, enable input safety checking (e.g. too large data bytes, bad ID numbers, etc). - // These checks have some performance downside. -#define RUNNING_STATUS 0 // If defined, the MIDI instrument stores a transmit status and uses running statuses whenever possible. -#define KEY_ON_VELOCITY 0 // If defined, the MIDI instrument sends velocities with Note On messages. -#undef RELEASE_VELOCITY // If defined, the MIDI instrument sends Note Off messages with velocities. - // Otherwise, sends Note On velocity 0 or Note Off velocity 0 according to ACTUAL_OFF_MESSAGE. -#undef ACTUAL_OFF_MESSAGE // If defined, the MIDI instrument sends true Note Off messages. - // Otherwise sends Note On velocity 0 (so as to exploit running status). -#undef EXPORT_CONTROLLERS // If defined, export constants useful for controller messages. - -// Consumers must specify -typedef struct { - void (*uart_write)(uint8_t); // Blocking, single-byte UART transmit function. - // Channel voice handlers. - void (*note_on_handler)(uint8_t, uint8_t, uint8_t); - void (*note_off_handler)(uint8_t, uint8_t, uint8_t); - void (*poly_key_handler)(uint8_t, uint8_t, uint8_t); - void (*control_change_handler)(uint8_t, uint8_t, uint8_t); - void (*program_change_handler)(uint8_t, uint8_t); - void (*aftertouch_handler)(uint8_t, uint8_t); - void (*pitch_bend_change_handler)(uint8_t, uint8_t); - // Channel mode handlers. - void (*all_sound_off_handler)(uint8_t); - void (*reset_all_controllers_handler)(uint8_t); - void (*local_control_handler)(uint8_t, uint8_t); - void (*all_notes_off_handler)(uint8_t); - void (*omni_on_handler)(uint8_t); - void (*omni_off_handler)(uint8_t); - void (*mono_on_handler)(uint8_t, uint8_t); - void (*poly_on_handler)(uint8_t); - // System common handlers. - void (*mtc_quarter_frame_handler)(uint8_t, uint8_t); - void (*song_position_pointer_handler)(uint8_t, uint8_t); - void (*song_select_handler)(uint8_t); - void (*tune_request_handler)(); - // System real time handlers. - void (*timing_clock_handler)(); - void (*start_handler)(); - void (*continue_handler)(); - void (*stop_handler)(); - void (*active_sensing_handler)(); - void (*system_reset_handler)(); - // System Exclusive handlers. - bool (*sysex_collector)(uint8_t); // Feeds most recent byte system exclusive byte (status and eox excluded, ID included) - // to client, returning false whenever the client determines sysex can be safely discarded. - // Client is expected to maintain parsing state externally, - // including resetting correctly after aborted parses. - // Client also should not abort the parse before the first post-manufacturer-ID byte. - void (*end_of_sysex_handler)(); // Sent only when client - // Universal System Exclusive handlers. - void (*bulk_tuning_dump_request_handler)(uint8_t, uint8_t); - void (*bulk_tuning_dump_handler)(uint8_t, uint8_t, char*, uint8_t*); - void (*single_note_tuning_change_handler)(uint8_t, uint8_t, uint8_t, uint8_t*); - // TODO: more. - bool (*unimplemented_universal_sysex_collector)(uint8_t); // Same as above. Parsing ends with end_of_sysex_handler. -} ConsumerBehavior; - -extern ConsumerBehavior pfns; // Initialize this globally in your main. - -// System exclusive sends. -void sysex(uint16_t manufacturer_id, bool long_id, uint8_t* contents, size_t contents_len); -void universal_nonrealtime(uint8_t device_id, uint16_t sub_id, uint8_t* contents, size_t contents_len); -void universal_realtime(uint8_t device_id, uint16_t sub_id, uint8_t* contents, size_t contents_len); - -// Channel voice sends. -#ifdef KEY_ON_VELOCITY -void note_on(uint8_t channel, uint8_t note, uint8_t velocity); -#else -void note_on(uint8_t channel, uint8_t note); -#endif -#ifdef RELEASE_VELOCITY -void note_off(uint8_t channel, uint8_t note, uint8_t velocity); -#else -void note_off(uint8_t channel, uint8_t note); -#endif -void control_change(uint8_t channel, uint8_t controller_number, uint8_t control_value); -void program_change(uint8_t channel, uint8_t program_number); -void aftertouch(uint8_t channel, uint8_t pressure_value); -void pitch_bend_change(uint8_t channel, uint16_t pressure_value); - -// Channel mode sends. -void all_sound_off(uint8_t channel); -void reset_all_controllers(uint8_t channel); -void local_control_on(uint8_t channel); -void local_control_off(uint8_t channel); -void all_notes_off(uint8_t channel); -void omni_on(uint8_t channel); -void omni_off(uint8_t channel); -void mono_on(uint8_t channel, uint8_t channel_count); -void poly_on(uint8_t channel); - - -// System Common sends. -// MTC Quarter Frame unimplemented. -void song_position_pointer(uint16_t position); -void song_select(uint8_t song); -void tune_request(); - -// System Real Time sends. -void timing_clock(); -void srt_start(); -void srt_continue(); -void srt_stop(); -void active_sensing(); -void MIDI_reset(); - -// Universal SysEx. -// Only implement MTS; consumers can do their own parsing via unimplemented_universal_sysex_collector. - -// MIDI Tuning Standard sends. -void bulk_tuning_dump_request(uint8_t device_id, uint8_t program); -void bulk_tuning_dump(uint8_t device_id, uint8_t program, char* name, uint8_t* tuning_data); -void single_note_tuning_change(uint8_t device_id, uint8_t program, uint8_t *note_tuning_data, uint8_t keys_changed); - - -// Feed bytes to this in the UART interrupt handler. -void parse_midi_stream(uint8_t byte); - - -// Public constants; magic numbers useful for consumers. -#define ALL_CALL_DEVICE_ID 0x7f -#define DEVICE_KEY_COUNT 128 -#define TUNING_LENGTH (3 * DEVICE_KEY_COUNT) -#define TUNING_NAME_LENGTH 16 -#define NOTE_TUNING_BYTES_PER_KEY 4 - - -#ifdef EXPORT_CONTROLLERS -// Controller constants. -typedef enum Controller { - BANK_SELECT = 0, - MODULATION_WHEEL = 1, - BREATH_CONTROLLER = 2, - // Undefined - FOOT_CONTROLLER = 4, - PORTAMENTO_TIME = 5, - DATA_ENTRY_MSB = 6, - CHANNEL_VOLUME = 7, - BALANCE = 8, - // Undefined - PAN = 10, - EXPRESSION = 11, - EFFECT1 = 12, - EFFECT2 = 13, - // Undefined - GP1 = 16, - GP2 = 17, - GP3 = 18, - GP4 = 19, - DAMPER_PEDAL = 64, - PORTAMENTO_TOGGLE = 65, - SOSTENUTO = 66, - SOFT_PEDAL = 67, - LEGATO_FOOTSWITCH = 68, - HOLD2 = 69, - SC1_SOUND_VARIATION = 70, - SC2_TIMBRE = 71, - SC3_RELEASE_TIME = 72, - SC4_ATTACK_TIME = 73, - SC5_BRIGHTNESS = 74, - SC6 = 75, - SC7 = 76, - SC8 = 77, - SC9 = 78, - SC10 = 79, - GP5 = 80, - GP6 = 81, - GP7 = 82, - GP8 = 83, - PORTAMENTO_CONTROL = 84, - // Undefined - EFFECTS_DEPTH1 = 91, - EFFECTS_DEPTH2 = 92, - EFFECTS_DEPTH3 = 93, - EFFECTS_DEPTH4 = 94, - EFFECTS_DEPTH5 = 95, - DATA_INCREMENT = 96, - DATA_DECREMENT = 97, - NONREGISTERED_LSB = 98, - NONREGISTERED_MSB = 99, - REGISTERED_LSB = 100, - REGISTERED_MSB = 101, - // undefined 102-119 - // reserved for channel mode 120-127 -}; - -typedef enum RegisteredParams { - PITCH_BEND_SENSITIVITY = 0, - FINE_TUNING = 1, - COARSE_TUNING = 2, - TUNING_PROGRAM_SELECT = 3, - TUNING_BANK_SELECT = 4 -}; - -#endif - - -#endif diff --git a/controller/inc/startup.h b/controller/inc/startup.h new file mode 100644 index 0000000..5e47193 --- /dev/null +++ b/controller/inc/startup.h @@ -0,0 +1,173 @@ +#ifndef STARTUP_H +#define STARTUP_H +/* +* Copyright (c) 2018, Shawn D'silva +* All rights reserved. +* +* This file is free software: you can redistribute it and/or modify + * it under the terms of the GNU Lesser General Public License as published by + * the Free Software Foundation, either version 3 of the License, or + * (at your option) any later version. + * + * This file is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this library. If not, see . +* +* File: startup.c +* Author: Shawn D'silva . +* Version: 1.0.0. +* Description: startup header for the TM4C Launchpad board,defines the vector table + handlers and ISRS,also declares external variables +*/ + +// +-----------------------------------------------------------------------------------+ +// + Type Definitions and Macros + +// +-----------------------------------------------------------------------------------+ + +/* + * Defines a macro DEFAULT that aliases the function prototype + * to Default_Handler if the function is not defined +*/ +#define DEFAULT __attribute__((weak, alias("Default_Handler"))) + +/* Defines a type for the ISR's in the vector table */ +typedef void (*element_t)(void); + +/* Defines a type for the vector table */ +typedef union { + element_t isr; //all ISRs use this type + void *stack_top; //pointer to top of the stack +} vector_table_t; + + +// +-----------------------------------------------------------------------------------+ +// + Prototypes of Basic Exception Handlers + +// +-----------------------------------------------------------------------------------+ + +//Default Handler,does nothing +void Default_Handler(void); + +//System Exception Handlers + +void Reset_Handler(void); +DEFAULT void NMI_Handler(void); +DEFAULT void SVC_Handler(void); +DEFAULT void DebugMonitor_Handler(void); +DEFAULT void PendSV_Handler(void); +DEFAULT void SysTick_Handler(void); + +//Fault Handlers + +DEFAULT void HardFault_Handler(void); +DEFAULT void MemManageFault_Handler(void); +DEFAULT void BusFault_Handler(void); +DEFAULT void UsageFault_Handler(void); + +// +-----------------------------------------------------------------------------------+ +// + Prototypes of Interrupt Service Routines + +// +-----------------------------------------------------------------------------------+ +DEFAULT void GPIOPortA_ISR(void); +DEFAULT void GPIOPortB_ISR(void); +DEFAULT void GPIOPortC_ISR(void); +DEFAULT void GPIOPortD_ISR(void); +DEFAULT void GPIOPortE_ISR(void); +DEFAULT void UART0_ISR(void); +DEFAULT void UART1_ISR(void); +DEFAULT void SPI0_ISR(void); +DEFAULT void I2C0_ISR(void); +DEFAULT void PWM0Fault_ISR(void); +DEFAULT void PWM0Generator0_ISR(void); +DEFAULT void PWM0Generator1_ISR(void); +DEFAULT void PWM0Generator2_ISR(void); +DEFAULT void QEI0_ISR(void); +DEFAULT void ADC0Sequence0_ISR(void); +DEFAULT void ADC0Sequence1_ISR(void); +DEFAULT void ADC0Sequence2_ISR(void); +DEFAULT void ADC0Sequence3_ISR(void); +DEFAULT void WatchDogTimer_ISR(void); +DEFAULT void Timer0A_ISR(void); +DEFAULT void Timer0B_ISR(void); +DEFAULT void Timer1A_ISR(void); +DEFAULT void Timer1B_ISR(void); +DEFAULT void Timer2A_ISR(void); +DEFAULT void Timer2B_ISR(void); +DEFAULT void AnalogComparator0_ISR(void); +DEFAULT void AnalogComparator1_ISR(void); +DEFAULT void SystemCtrl_ISR(void); +DEFAULT void FlashCtrl_ISR(void); +DEFAULT void GPIOPortF_ISR(void); +DEFAULT void UART2_ISR(void); +DEFAULT void SPI1_ISR(void); +DEFAULT void Timer3A_ISR(void); +DEFAULT void Timer3B_ISR(void); +DEFAULT void I2C1_ISR(void); +DEFAULT void QEI1_ISR(void); +DEFAULT void CAN0_ISR(void); +DEFAULT void CAN1_ISR(void); +DEFAULT void Hibernation_ISR(void); +DEFAULT void USB0_ISR(void); +DEFAULT void PWM0Generator3_ISR(void); +DEFAULT void UDMASoftware_ISR(void); +DEFAULT void UDMAError_ISR(void); +DEFAULT void ADC1Sequence0_ISR(void); +DEFAULT void ADC1Sequence1_ISR(void); +DEFAULT void ADC1Sequence2_ISR(void); +DEFAULT void ADC1Sequence3_ISR(void); +DEFAULT void SPI2_ISR(void); +DEFAULT void SPI3_ISR(void); +DEFAULT void UART3_ISR(void); +DEFAULT void UART4_ISR(void); +DEFAULT void UART5_ISR(void); +DEFAULT void UART6_ISR(void); +DEFAULT void UART7_ISR(void); +DEFAULT void I2C2_ISR(void); +DEFAULT void I2C3_ISR(void); +DEFAULT void Timer4A_ISR(void); +DEFAULT void Timer4B_ISR(void); +DEFAULT void Timer5A_ISR(void); +DEFAULT void Timer5B_ISR(void); +DEFAULT void WideTimer0A_ISR(void); +DEFAULT void WideTimer0B_ISR(void); +DEFAULT void WideTimer1A_ISR(void); +DEFAULT void WideTimer1B_ISR(void); +DEFAULT void WideTimer2A_ISR(void); +DEFAULT void WideTimer2B_ISR(void); +DEFAULT void WideTimer3A_ISR(void); +DEFAULT void WideTimer3B_ISR(void); +DEFAULT void WideTimer4A_ISR(void); +DEFAULT void WideTimer4B_ISR(void); +DEFAULT void WideTimer5A_ISR(void); +DEFAULT void WideTimer5B_ISR(void); +DEFAULT void SystemException_ISR(void); +DEFAULT void PWM1Generator0_ISR(void); +DEFAULT void PWM1Generator1_ISR(void); +DEFAULT void PWM1Generator2_ISR(void); +DEFAULT void PWM1Generator3_ISR(void); +DEFAULT void PWM1Fault_ISR(void); + +// +-----------------------------------------------------------------------------------+ +// + External Variables declaration + +// +-----------------------------------------------------------------------------------+ + +//main() of your program +extern int main(void); + +//stack pointer +extern int _stack_ptr; +//.text/code,stored in Flash +extern int _etext; +//.data,copied into RAM on boot +extern int _data; +extern int _edata; +//.bss,unitialized variables +extern int _bss; +extern int _ebss; + +/***************************************** END OF FILE *******************************************/ + + +#endif -- cgit v1.2.3