diff options
author | DaveHodder67 <dave.hodder@focusrite.com> | 2015-07-02 18:32:18 +0100 |
---|---|---|
committer | DaveHodder67 <dave.hodder@focusrite.com> | 2015-07-02 18:32:18 +0100 |
commit | e1f9c0ada85d1538e08d5d51986bd4593f05ff9c (patch) | |
tree | 0dcd5b7ff29fdcfb468a7e607b0c4a968705066d | |
parent | 114d76fbcd987bf382bc255af0128a839321ed84 (diff) | |
download | launchpad-polymaker-e1f9c0ada85d1538e08d5d51986bd4593f05ff9c.tar.gz launchpad-polymaker-e1f9c0ada85d1538e08d5d51986bd4593f05ff9c.zip |
added trivial simulator.c
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.
-rw-r--r-- | Makefile | 13 | ||||
-rw-r--r-- | tools/simulator.c | 114 |
2 files changed, 124 insertions, 3 deletions
@@ -14,8 +14,10 @@ LIB = lib/launchpad_pro.a | |||
14 | ELF = $(BUILDDIR)/launchpad_pro.elf | 14 | ELF = $(BUILDDIR)/launchpad_pro.elf |
15 | HEX = $(BUILDDIR)/launchpad_pro.hex | 15 | HEX = $(BUILDDIR)/launchpad_pro.hex |
16 | HEXTOSYX = $(BUILDDIR)/hextosyx | 16 | HEXTOSYX = $(BUILDDIR)/hextosyx |
17 | SIMULATOR = $(BUILDDIR)/simulator | ||
17 | 18 | ||
18 | HOST_CC = g++ | 19 | HOST_GPP = g++ |
20 | HOST_GCC = gcc | ||
19 | CC = arm-none-eabi-gcc | 21 | CC = arm-none-eabi-gcc |
20 | LD = arm-none-eabi-gcc | 22 | LD = arm-none-eabi-gcc |
21 | OBJCOPY = arm-none-eabi-objcopy | 23 | OBJCOPY = arm-none-eabi-objcopy |
@@ -33,12 +35,17 @@ LDFLAGS += -T$(LDSCRIPT) -u _start -u _Minimum_Stack_Size -mcpu=cortex-m3 -mthu | |||
33 | all: $(SYX) | 35 | all: $(SYX) |
34 | 36 | ||
35 | # build the final sysex file from the ELF | 37 | # build the final sysex file from the ELF |
36 | $(SYX): $(HEX) $(HEXTOSYX) | 38 | $(SYX): $(HEX) $(HEXTOSYX) $(SIMULATOR) |
39 | ./$(SIMULATOR) | ||
37 | ./$(HEXTOSYX) $(HEX) $(SYX) | 40 | ./$(HEXTOSYX) $(HEX) $(SYX) |
38 | 41 | ||
39 | # build the tool for conversion of ELF files to sysex ready for upload to the unit | 42 | # build the tool for conversion of ELF files to sysex ready for upload to the unit |
40 | $(HEXTOSYX): | 43 | $(HEXTOSYX): |
41 | $(HOST_CC) -Ofast -std=c++0x -I./$(TOOLS)/libintelhex/include ./$(TOOLS)/libintelhex/src/intelhex.cc $(TOOLS)/hextosyx.cpp -o $(HEXTOSYX) | 44 | $(HOST_GPP) -Ofast -std=c++0x -I./$(TOOLS)/libintelhex/include ./$(TOOLS)/libintelhex/src/intelhex.cc $(TOOLS)/hextosyx.cpp -o $(HEXTOSYX) |
45 | |||
46 | # build the simulator and run it (it's a very basic test of the code before it runs on the device!) | ||
47 | $(SIMULATOR): | ||
48 | $(HOST_GCC) -O0 -std=c99 -Iinclude $(TOOLS)/simulator.c src/app.c -o $(SIMULATOR) | ||
42 | 49 | ||
43 | $(HEX): $(ELF) | 50 | $(HEX): $(ELF) |
44 | $(OBJCOPY) -O ihex $< $@ | 51 | $(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 @@ | |||
1 | /****************************************************************************** | ||
2 | |||
3 | Copyright (c) 2015, Focusrite Audio Engineering Ltd. | ||
4 | All rights reserved. | ||
5 | |||
6 | Redistribution and use in source and binary forms, with or without | ||
7 | modification, are permitted provided that the following conditions are met: | ||
8 | |||
9 | * Redistributions of source code must retain the above copyright notice, this | ||
10 | list of conditions and the following disclaimer. | ||
11 | |||
12 | * Redistributions in binary form must reproduce the above copyright notice, | ||
13 | this list of conditions and the following disclaimer in the documentation | ||
14 | and/or other materials provided with the distribution. | ||
15 | |||
16 | * Neither the name of Focusrite Audio Engineering Ltd., nor the names of its | ||
17 | contributors may be used to endorse or promote products derived from | ||
18 | this software without specific prior written permission. | ||
19 | |||
20 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | ||
21 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
22 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
23 | DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE | ||
24 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
25 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | ||
26 | SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | ||
27 | CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | ||
28 | OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
29 | OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | ||
30 | |||
31 | *****************************************************************************/ | ||
32 | |||
33 | #include <stdio.h> | ||
34 | #include "app.h" | ||
35 | |||
36 | // ____________________________________________________________________________ | ||
37 | // | ||
38 | // Simulator "hal". This lets you exercise your device code without having to upload | ||
39 | // it to the hardware, which also means you can debug it interactively. | ||
40 | // ____________________________________________________________________________ | ||
41 | |||
42 | void hal_plot_led(u8 type, u8 index, u8 red, u8 green, u8 blue) | ||
43 | { | ||
44 | // wire this up to MIDI out... | ||
45 | printf("...hal_plot_led(%d, %d, %d, %d, %d);\n", type, index, red, green, blue); | ||
46 | } | ||
47 | |||
48 | void hal_send_midi(u8 port, u8 status, u8 d1, u8 d2) | ||
49 | { | ||
50 | // send this up a virtual MIDI port? | ||
51 | printf("...hal_send_midi(%d, 0x%2.2x, 0x%2.2x, 0x%2.2x);\n", port, status, d1, d2); | ||
52 | } | ||
53 | |||
54 | void hal_send_sysex(u8 port, const u8* data, u16 length) | ||
55 | { | ||
56 | // as above, or just dump to console? | ||
57 | printf("...hal_send_midi(%d, (data), %d);\n", port, length); | ||
58 | } | ||
59 | |||
60 | // ____________________________________________________________________________ | ||
61 | // | ||
62 | // App event wrappers - these just log to the console. Would be nice to wire | ||
63 | // these up to a MIDI input from the real Launchpad Pro! | ||
64 | // ____________________________________________________________________________ | ||
65 | |||
66 | static void sim_app_init() | ||
67 | { | ||
68 | printf("calling app_init()...\n"); | ||
69 | app_init(); | ||
70 | } | ||
71 | |||
72 | static void sim_app_surface_event(u8 type, u8 index, u8 value) | ||
73 | { | ||
74 | printf("calling sim_app_surface_event(%d, %d, %d)...\n", type, index, value); | ||
75 | app_surface_event(type, index, value); | ||
76 | } | ||
77 | |||
78 | static void sim_app_midi_event(u8 port, u8 status, u8 d1, u8 d2) | ||
79 | { | ||
80 | printf("calling app_midi_event(%d, 0x%2.2x, 0x%2.2x, 0x%2.2x)...\n", port, status, d1, d2); | ||
81 | app_midi_event(port, status, d1, d2); | ||
82 | } | ||
83 | |||
84 | static void sim_app_timer_event() | ||
85 | { | ||
86 | printf("calling app_timer_event()...\n"); | ||
87 | app_timer_event(); | ||
88 | } | ||
89 | |||
90 | // ____________________________________________________________________________ | ||
91 | |||
92 | int main(int argc, char * argv[]) | ||
93 | { | ||
94 | // let's just call a few things to give the app a very brief workout. | ||
95 | sim_app_init(); | ||
96 | |||
97 | // surface | ||
98 | sim_app_surface_event(TYPEPAD, 35, 127); | ||
99 | sim_app_surface_event(TYPESETUP, 0, 127); | ||
100 | sim_app_surface_event(TYPEPAD, 35, 0); | ||
101 | |||
102 | // MIDI | ||
103 | sim_app_midi_event(USBSTANDALONE, NOTEON, 60, 127); | ||
104 | sim_app_midi_event(USBSTANDALONE, NOTEON, 60, 0); | ||
105 | |||
106 | // timer | ||
107 | const int timerTicks = 21; | ||
108 | printf("sending %d timer events via app_timer_event()...\n", timerTicks); | ||
109 | for (int i=0; i < timerTicks; ++i) | ||
110 | { | ||
111 | sim_app_timer_event(); | ||
112 | } | ||
113 | return 0; | ||
114 | } \ No newline at end of file | ||