summaryrefslogtreecommitdiffstats
path: root/include/app.h
blob: c26c13170c8e1cfe2ba03126539425a2acd477ce (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
#ifndef LAUNCHPAD_APP_H
#define LAUNCHPAD_APP_H

/******************************************************************************
 
 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.
 
 *****************************************************************************/

// ____________________________________________________________________________
//
// Don't modify this file!  This declares the binary interface to the library,
// so modifying it will probably break things.
// ____________________________________________________________________________
//
#include "app_defs.h"

/******************************************************************************
 Button indexing is as follows - numbers in brackets do not correspond to real
 buttons, but can be harmessly sent in hal_set_led.
 
 (90)91 92 93 94 95 96 97 98 (99)
 .......
 20  21 22 23 24 25 26 27 28  29
 10  11 12 13 14 15 16 17 18  19
 (0)  1  2  3  4  5  6  7  8  (9)
 
 *****************************************************************************/

// ____________________________________________________________________________
//
// Interface to the hardware (implemented in launchpad_pro.a library)
// ____________________________________________________________________________

/**
 * Set an LED's RGB value.  This function is safe to call from any
 * of the app functions below, at any time.
 *
 * @param type - TYPEPAD to address any pad or button, TYPESETUP to address the Setup button
 * @param index - The index of the button.  The buttons are indexed from the bottom left as detailed above.
 * @param red - red colour value, in [0, MAXLED]
 * @param green - green colour value, in [0, MAXLED]
 * @param blue - blue colour value, in [0, MAXLED]
 */
void hal_plot_led(u8 type, u8 index, u8 red, u8 green, u8 blue);

/**
 * Send a MIDI message to either USB port or to the DIN output.
 * 
 * @param port - which port to send the message to - can be USBSTANDALONE, USBMIDI or DINMIDI.
 * @param status - MIDI status byte
 * @param data1 - first MIDI data byte
 * @param data2 - second MIDI data byte
 *
 * There is little error checking in this code - if you send invalid MIDI, the results are undefined!
 */
void hal_send_midi(u8 port, u8 status, u8 data1, u8 data2);

/**
 * Send system exclusive to USB or DIN.  Messages must be correctly formatted
 * (F0 ... F7) and must not exceed 320 bytes.
 *
 * @param port - which port to send the message to - can be USBSTANDALONE, USBMIDI or DINMIDI.
 * @param data - pointer to array containing sysex data. Can be on the stack.
 * @param length - must not exceed 320 bytes, behaviour undefined if it does.
 */
void hal_send_sysex(u8 port, const u8* data, u16 length);

/**
 * Read some data from flash.
 *
 * Flash storage is in a single block, currently corresponding to one page.
 * The block is always USER_AREA_SIZE bytes long. You can read/write any bytes
 * within it - you do not need to worry about paging, that's handled by the HAL.
 *
 * The block size may increase to span multiple pages in future :)
 *
 * @param offset - how far into the USER_AREA_SIZE byte block to start reading
 * @param data - buffer to receive data (must be at least length bytes long)
 * @param length - bytes to read
 *
 * Attempts to read beyond the end of the block will fail silently.
 *
 * Note that your first ever read from a new device will contain 0xFF's until
 * you overwrite them.
 */
void hal_read_flash(u32 offset, u8 *data, u32 length);

/**
 * Write data to flash
 *
 * Do take care to avoid thrashing it, as you can wear it out with excessive
 * writes. The HAL does not currently do anything clever to mitigate this.
 *
 * @param offset - how far into the USER_AREA_SIZE byte block to start writing
 * @param data - buffer to write (must be at least length bytes long)
 * @param length - bytes to write
 *
 * Attempts to write beyond the end of the block will fail silently
 */
void hal_write_flash(u32 offset,const u8 *data, u32 length);

// ____________________________________________________________________________
//
// Callbacks from the hardware (implemented in your app.c)
// ____________________________________________________________________________

/**
 * Called on startup, this is a good place to do any initialisation.
 */
void app_init();

/**
 *  1kHz (1ms) timer.  You can set LEDs and send MIDI out from this function,
 *  but you will get LED tearing as there is (currently) no double buffering.
 *
 *  You will get some jitter.
 */
void app_timer_event();

/**
 * Called when a MIDI message is received from USB or DIN.
 *
 * @param port - the port the message was received from - USBSTANDALONE, USBMIDI or DINMIDI.
 * @param status - MIDI status byte
 * @param data1 - first MIDI data byte
 * @param data2 - second MIDI data byte
 */
void app_midi_event(u8 port, u8 status, u8 d1, u8 d2);

/**
 * As above, but for system exclusive messages.  Low level hardware buffering sets
 * a maximum message size of 320 bytes, messages larger than this will not work.
 *
 * @param port - the port the message was received from - USBSTANDALONE, USBMIDI or DINMIDI.
 * @param data - pointer to array containing sysex data.  Only valid in the scope of this callback.
 * @param length - the amount of data received.
 */
void app_sysex_event(u8 port, u8 * data, u16 count);

/**
 * Called when a MIDI DIN breakout cable is connected or disconnected.  Note that
 * you can still write MIDI events to the DIN ports even if no cable is connected.
 *
 * @param type - which cable was connected/disconnected - MIDI_IN_CABLE or MIDI_OUT_CABLE.
 * @param value - 0 = disconnected, nonzero = connected.
 */
void app_cable_event(u8 type, u8 value);

/**
 * Called when the user presses or releases any button or pad on the control surface.
 *
 * @param type - TYPEPAD for normal pads or buttons, TYPESETUP for the Setup button
 * @param index - The index of the button, as detailed at the start of this file.
 * @param value - 0 for release, nonzero for press.
 */
void app_surface_event(u8 type, u8 index, u8 value);

/**
 * Called when the low level pad scanning reports an aftertouch (pad pressure) event.
 * A pad press event will always come first.  Note that the factory firmware sets a
 * threshold to prevent excessive aftertouch after the initial hit, at the expense of
 * dynamic range.  This firmware does not - the full range of the pad is transmitted,
 * with the side effect that aftertouch onset is more rapid.
 *
 * @param index - The index of the pad, as detailed at the start of this file.
 * @param value - the aftertouch value in [0, 127]
 */
void app_aftertouch_event(u8 index, u8 value);


#endif