From e1f9c0ada85d1538e08d5d51986bd4593f05ff9c Mon Sep 17 00:00:00 2001 From: DaveHodder67 Date: Thu, 2 Jul 2015 18:32:18 +0100 Subject: added trivial simulator.c MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Though it’s nice, as it’s part of the build process to run the simulator - so if your app crashes, it won’t even get as far as the device. --- Makefile | 13 +++++-- tools/simulator.c | 114 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 124 insertions(+), 3 deletions(-) create mode 100644 tools/simulator.c diff --git a/Makefile b/Makefile index 8c91f24..3e15b46 100644 --- a/Makefile +++ b/Makefile @@ -14,8 +14,10 @@ LIB = lib/launchpad_pro.a ELF = $(BUILDDIR)/launchpad_pro.elf HEX = $(BUILDDIR)/launchpad_pro.hex HEXTOSYX = $(BUILDDIR)/hextosyx +SIMULATOR = $(BUILDDIR)/simulator -HOST_CC = g++ +HOST_GPP = g++ +HOST_GCC = gcc CC = arm-none-eabi-gcc LD = arm-none-eabi-gcc OBJCOPY = arm-none-eabi-objcopy @@ -33,12 +35,17 @@ LDFLAGS += -T$(LDSCRIPT) -u _start -u _Minimum_Stack_Size -mcpu=cortex-m3 -mthu all: $(SYX) # build the final sysex file from the ELF -$(SYX): $(HEX) $(HEXTOSYX) +$(SYX): $(HEX) $(HEXTOSYX) $(SIMULATOR) + ./$(SIMULATOR) ./$(HEXTOSYX) $(HEX) $(SYX) # build the tool for conversion of ELF files to sysex ready for upload to the unit $(HEXTOSYX): - $(HOST_CC) -Ofast -std=c++0x -I./$(TOOLS)/libintelhex/include ./$(TOOLS)/libintelhex/src/intelhex.cc $(TOOLS)/hextosyx.cpp -o $(HEXTOSYX) + $(HOST_GPP) -Ofast -std=c++0x -I./$(TOOLS)/libintelhex/include ./$(TOOLS)/libintelhex/src/intelhex.cc $(TOOLS)/hextosyx.cpp -o $(HEXTOSYX) + +# build the simulator and run it (it's a very basic test of the code before it runs on the device!) +$(SIMULATOR): + $(HOST_GCC) -O0 -std=c99 -Iinclude $(TOOLS)/simulator.c src/app.c -o $(SIMULATOR) $(HEX): $(ELF) $(OBJCOPY) -O ihex $< $@ diff --git a/tools/simulator.c b/tools/simulator.c new file mode 100644 index 0000000..56298d7 --- /dev/null +++ b/tools/simulator.c @@ -0,0 +1,114 @@ +/****************************************************************************** + + Copyright (c) 2015, Focusrite Audio Engineering Ltd. + All rights reserved. + + Redistribution and use in source and binary forms, with or without + modification, are permitted provided that the following conditions are met: + + * Redistributions of source code must retain the above copyright notice, this + list of conditions and the following disclaimer. + + * Redistributions in binary form must reproduce the above copyright notice, + this list of conditions and the following disclaimer in the documentation + and/or other materials provided with the distribution. + + * Neither the name of Focusrite Audio Engineering Ltd., nor the names of its + contributors may be used to endorse or promote products derived from + this software without specific prior written permission. + + THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE + DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE + FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER + CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, + OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE + OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. + + *****************************************************************************/ + +#include +#include "app.h" + +// ____________________________________________________________________________ +// +// Simulator "hal". This lets you exercise your device code without having to upload +// it to the hardware, which also means you can debug it interactively. +// ____________________________________________________________________________ + +void hal_plot_led(u8 type, u8 index, u8 red, u8 green, u8 blue) +{ + // wire this up to MIDI out... + printf("...hal_plot_led(%d, %d, %d, %d, %d);\n", type, index, red, green, blue); +} + +void hal_send_midi(u8 port, u8 status, u8 d1, u8 d2) +{ + // send this up a virtual MIDI port? + printf("...hal_send_midi(%d, 0x%2.2x, 0x%2.2x, 0x%2.2x);\n", port, status, d1, d2); +} + +void hal_send_sysex(u8 port, const u8* data, u16 length) +{ + // as above, or just dump to console? + printf("...hal_send_midi(%d, (data), %d);\n", port, length); +} + +// ____________________________________________________________________________ +// +// App event wrappers - these just log to the console. Would be nice to wire +// these up to a MIDI input from the real Launchpad Pro! +// ____________________________________________________________________________ + +static void sim_app_init() +{ + printf("calling app_init()...\n"); + app_init(); +} + +static void sim_app_surface_event(u8 type, u8 index, u8 value) +{ + printf("calling sim_app_surface_event(%d, %d, %d)...\n", type, index, value); + app_surface_event(type, index, value); +} + +static void sim_app_midi_event(u8 port, u8 status, u8 d1, u8 d2) +{ + printf("calling app_midi_event(%d, 0x%2.2x, 0x%2.2x, 0x%2.2x)...\n", port, status, d1, d2); + app_midi_event(port, status, d1, d2); +} + +static void sim_app_timer_event() +{ + printf("calling app_timer_event()...\n"); + app_timer_event(); +} + +// ____________________________________________________________________________ + +int main(int argc, char * argv[]) +{ + // let's just call a few things to give the app a very brief workout. + sim_app_init(); + + // surface + sim_app_surface_event(TYPEPAD, 35, 127); + sim_app_surface_event(TYPESETUP, 0, 127); + sim_app_surface_event(TYPEPAD, 35, 0); + + // MIDI + sim_app_midi_event(USBSTANDALONE, NOTEON, 60, 127); + sim_app_midi_event(USBSTANDALONE, NOTEON, 60, 0); + + // timer + const int timerTicks = 21; + printf("sending %d timer events via app_timer_event()...\n", timerTicks); + for (int i=0; i < timerTicks; ++i) + { + sim_app_timer_event(); + } + return 0; +} \ No newline at end of file -- cgit v1.2.1