MIDI Stop Controller V1.0 suitable for driving Hauptwerk digital organ software. Written for the KL25Z uses BusInOut and will drive up to 16 illuminated push buttons each switch uses a single I/O pin to both drive the LED and act as a switch input. Pressing a button will alternately send MIDI note on / off messages and turn the LED on or off. If corresponding MIDI note on/off messages are received these will be used to drive the LEDs in preference to the locally generated LED signals. The MIDI channel used to send can be selected by jumpers on 4 pins of the J2 header.

Dependencies:   mbed

Committer:
djbottrill
Date:
Sat Sep 14 21:32:06 2013 +0000
Revision:
0:aac55e1fc12f
V1.0 MIDI Stop Controller

Who changed what in which revision?

UserRevisionLine numberNew contents of line
djbottrill 0:aac55e1fc12f 1 /* Copyright (c) 2010-2011 mbed.org, MIT License
djbottrill 0:aac55e1fc12f 2 *
djbottrill 0:aac55e1fc12f 3 * Permission is hereby granted, free of charge, to any person obtaining a copy of this software
djbottrill 0:aac55e1fc12f 4 * and associated documentation files (the "Software"), to deal in the Software without
djbottrill 0:aac55e1fc12f 5 * restriction, including without limitation the rights to use, copy, modify, merge, publish,
djbottrill 0:aac55e1fc12f 6 * distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the
djbottrill 0:aac55e1fc12f 7 * Software is furnished to do so, subject to the following conditions:
djbottrill 0:aac55e1fc12f 8 *
djbottrill 0:aac55e1fc12f 9 * The above copyright notice and this permission notice shall be included in all copies or
djbottrill 0:aac55e1fc12f 10 * substantial portions of the Software.
djbottrill 0:aac55e1fc12f 11 *
djbottrill 0:aac55e1fc12f 12 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
djbottrill 0:aac55e1fc12f 13 * BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
djbottrill 0:aac55e1fc12f 14 * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
djbottrill 0:aac55e1fc12f 15 * DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
djbottrill 0:aac55e1fc12f 16 * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
djbottrill 0:aac55e1fc12f 17 */
djbottrill 0:aac55e1fc12f 18
djbottrill 0:aac55e1fc12f 19 #ifndef USBDEVICE_H
djbottrill 0:aac55e1fc12f 20 #define USBDEVICE_H
djbottrill 0:aac55e1fc12f 21
djbottrill 0:aac55e1fc12f 22 #include "mbed.h"
djbottrill 0:aac55e1fc12f 23 #include "USBDevice_Types.h"
djbottrill 0:aac55e1fc12f 24 #include "USBHAL.h"
djbottrill 0:aac55e1fc12f 25
djbottrill 0:aac55e1fc12f 26 class USBDevice: public USBHAL
djbottrill 0:aac55e1fc12f 27 {
djbottrill 0:aac55e1fc12f 28 public:
djbottrill 0:aac55e1fc12f 29 USBDevice(uint16_t vendor_id, uint16_t product_id, uint16_t product_release);
djbottrill 0:aac55e1fc12f 30
djbottrill 0:aac55e1fc12f 31 /*
djbottrill 0:aac55e1fc12f 32 * Check if the device is configured
djbottrill 0:aac55e1fc12f 33 *
djbottrill 0:aac55e1fc12f 34 * @returns true if configured, false otherwise
djbottrill 0:aac55e1fc12f 35 */
djbottrill 0:aac55e1fc12f 36 bool configured(void);
djbottrill 0:aac55e1fc12f 37
djbottrill 0:aac55e1fc12f 38 /*
djbottrill 0:aac55e1fc12f 39 * Connect a device
djbottrill 0:aac55e1fc12f 40 */
djbottrill 0:aac55e1fc12f 41 void connect(void);
djbottrill 0:aac55e1fc12f 42
djbottrill 0:aac55e1fc12f 43 /*
djbottrill 0:aac55e1fc12f 44 * Disconnect a device
djbottrill 0:aac55e1fc12f 45 */
djbottrill 0:aac55e1fc12f 46 void disconnect(void);
djbottrill 0:aac55e1fc12f 47
djbottrill 0:aac55e1fc12f 48 /*
djbottrill 0:aac55e1fc12f 49 * Add an endpoint
djbottrill 0:aac55e1fc12f 50 *
djbottrill 0:aac55e1fc12f 51 * @param endpoint endpoint which will be added
djbottrill 0:aac55e1fc12f 52 * @param maxPacket Maximum size of a packet which can be sent for this endpoint
djbottrill 0:aac55e1fc12f 53 * @returns true if successful, false otherwise
djbottrill 0:aac55e1fc12f 54 */
djbottrill 0:aac55e1fc12f 55 bool addEndpoint(uint8_t endpoint, uint32_t maxPacket);
djbottrill 0:aac55e1fc12f 56
djbottrill 0:aac55e1fc12f 57 /*
djbottrill 0:aac55e1fc12f 58 * Start a reading on a certain endpoint.
djbottrill 0:aac55e1fc12f 59 * You can access the result of the reading by USBDevice_read
djbottrill 0:aac55e1fc12f 60 *
djbottrill 0:aac55e1fc12f 61 * @param endpoint endpoint which will be read
djbottrill 0:aac55e1fc12f 62 * @param maxSize the maximum length that can be read
djbottrill 0:aac55e1fc12f 63 * @return true if successful
djbottrill 0:aac55e1fc12f 64 */
djbottrill 0:aac55e1fc12f 65 bool readStart(uint8_t endpoint, uint32_t maxSize);
djbottrill 0:aac55e1fc12f 66
djbottrill 0:aac55e1fc12f 67 /*
djbottrill 0:aac55e1fc12f 68 * Read a certain endpoint. Before calling this function, USBUSBDevice_readStart
djbottrill 0:aac55e1fc12f 69 * must be called.
djbottrill 0:aac55e1fc12f 70 *
djbottrill 0:aac55e1fc12f 71 * Warning: blocking
djbottrill 0:aac55e1fc12f 72 *
djbottrill 0:aac55e1fc12f 73 * @param endpoint endpoint which will be read
djbottrill 0:aac55e1fc12f 74 * @param buffer buffer will be filled with the data received
djbottrill 0:aac55e1fc12f 75 * @param size the number of bytes read will be stored in *size
djbottrill 0:aac55e1fc12f 76 * @param maxSize the maximum length that can be read
djbottrill 0:aac55e1fc12f 77 * @returns true if successful
djbottrill 0:aac55e1fc12f 78 */
djbottrill 0:aac55e1fc12f 79 bool readEP(uint8_t endpoint, uint8_t * buffer, uint32_t * size, uint32_t maxSize);
djbottrill 0:aac55e1fc12f 80
djbottrill 0:aac55e1fc12f 81 /*
djbottrill 0:aac55e1fc12f 82 * Read a certain endpoint.
djbottrill 0:aac55e1fc12f 83 *
djbottrill 0:aac55e1fc12f 84 * Warning: non blocking
djbottrill 0:aac55e1fc12f 85 *
djbottrill 0:aac55e1fc12f 86 * @param endpoint endpoint which will be read
djbottrill 0:aac55e1fc12f 87 * @param buffer buffer will be filled with the data received (if data are available)
djbottrill 0:aac55e1fc12f 88 * @param size the number of bytes read will be stored in *size
djbottrill 0:aac55e1fc12f 89 * @param maxSize the maximum length that can be read
djbottrill 0:aac55e1fc12f 90 * @returns true if successful
djbottrill 0:aac55e1fc12f 91 */
djbottrill 0:aac55e1fc12f 92 bool readEP_NB(uint8_t endpoint, uint8_t * buffer, uint32_t * size, uint32_t maxSize);
djbottrill 0:aac55e1fc12f 93
djbottrill 0:aac55e1fc12f 94 /*
djbottrill 0:aac55e1fc12f 95 * Write a certain endpoint.
djbottrill 0:aac55e1fc12f 96 *
djbottrill 0:aac55e1fc12f 97 * Warning: blocking
djbottrill 0:aac55e1fc12f 98 *
djbottrill 0:aac55e1fc12f 99 * @param endpoint endpoint to write
djbottrill 0:aac55e1fc12f 100 * @param buffer data contained in buffer will be write
djbottrill 0:aac55e1fc12f 101 * @param size the number of bytes to write
djbottrill 0:aac55e1fc12f 102 * @param maxSize the maximum length that can be written on this endpoint
djbottrill 0:aac55e1fc12f 103 */
djbottrill 0:aac55e1fc12f 104 bool write(uint8_t endpoint, uint8_t * buffer, uint32_t size, uint32_t maxSize);
djbottrill 0:aac55e1fc12f 105
djbottrill 0:aac55e1fc12f 106
djbottrill 0:aac55e1fc12f 107 /*
djbottrill 0:aac55e1fc12f 108 * Write a certain endpoint.
djbottrill 0:aac55e1fc12f 109 *
djbottrill 0:aac55e1fc12f 110 * Warning: non blocking
djbottrill 0:aac55e1fc12f 111 *
djbottrill 0:aac55e1fc12f 112 * @param endpoint endpoint to write
djbottrill 0:aac55e1fc12f 113 * @param buffer data contained in buffer will be write
djbottrill 0:aac55e1fc12f 114 * @param size the number of bytes to write
djbottrill 0:aac55e1fc12f 115 * @param maxSize the maximum length that can be written on this endpoint
djbottrill 0:aac55e1fc12f 116 */
djbottrill 0:aac55e1fc12f 117 bool writeNB(uint8_t endpoint, uint8_t * buffer, uint32_t size, uint32_t maxSize);
djbottrill 0:aac55e1fc12f 118
djbottrill 0:aac55e1fc12f 119
djbottrill 0:aac55e1fc12f 120 /*
djbottrill 0:aac55e1fc12f 121 * Called by USBDevice layer on bus reset. Warning: Called in ISR context
djbottrill 0:aac55e1fc12f 122 *
djbottrill 0:aac55e1fc12f 123 * May be used to reset state
djbottrill 0:aac55e1fc12f 124 */
djbottrill 0:aac55e1fc12f 125 virtual void USBCallback_busReset(void) {};
djbottrill 0:aac55e1fc12f 126
djbottrill 0:aac55e1fc12f 127 /*
djbottrill 0:aac55e1fc12f 128 * Called by USBDevice on Endpoint0 request. Warning: Called in ISR context
djbottrill 0:aac55e1fc12f 129 * This is used to handle extensions to standard requests
djbottrill 0:aac55e1fc12f 130 * and class specific requests
djbottrill 0:aac55e1fc12f 131 *
djbottrill 0:aac55e1fc12f 132 * @returns true if class handles this request
djbottrill 0:aac55e1fc12f 133 */
djbottrill 0:aac55e1fc12f 134 virtual bool USBCallback_request() { return false; };
djbottrill 0:aac55e1fc12f 135
djbottrill 0:aac55e1fc12f 136 /*
djbottrill 0:aac55e1fc12f 137 * Called by USBDevice on Endpoint0 request completion
djbottrill 0:aac55e1fc12f 138 * if the 'notify' flag has been set to true. Warning: Called in ISR context
djbottrill 0:aac55e1fc12f 139 *
djbottrill 0:aac55e1fc12f 140 * In this case it is used to indicate that a HID report has
djbottrill 0:aac55e1fc12f 141 * been received from the host on endpoint 0
djbottrill 0:aac55e1fc12f 142 *
djbottrill 0:aac55e1fc12f 143 * @param buf buffer received on endpoint 0
djbottrill 0:aac55e1fc12f 144 * @param length length of this buffer
djbottrill 0:aac55e1fc12f 145 */
djbottrill 0:aac55e1fc12f 146 virtual void USBCallback_requestCompleted(uint8_t * buf, uint32_t length) {};
djbottrill 0:aac55e1fc12f 147
djbottrill 0:aac55e1fc12f 148 /*
djbottrill 0:aac55e1fc12f 149 * Called by USBDevice layer. Set configuration of the device.
djbottrill 0:aac55e1fc12f 150 * For instance, you can add all endpoints that you need on this function.
djbottrill 0:aac55e1fc12f 151 *
djbottrill 0:aac55e1fc12f 152 * @param configuration Number of the configuration
djbottrill 0:aac55e1fc12f 153 */
djbottrill 0:aac55e1fc12f 154 virtual bool USBCallback_setConfiguration(uint8_t configuration) { return false; };
djbottrill 0:aac55e1fc12f 155
djbottrill 0:aac55e1fc12f 156 /*
djbottrill 0:aac55e1fc12f 157 * Called by USBDevice layer. Set interface/alternate of the device.
djbottrill 0:aac55e1fc12f 158 *
djbottrill 0:aac55e1fc12f 159 * @param interface Number of the interface to be configured
djbottrill 0:aac55e1fc12f 160 * @param alternate Number of the alternate to be configured
djbottrill 0:aac55e1fc12f 161 * @returns true if class handles this request
djbottrill 0:aac55e1fc12f 162 */
djbottrill 0:aac55e1fc12f 163 virtual bool USBCallback_setInterface(uint16_t interface, uint8_t alternate) { return false; };
djbottrill 0:aac55e1fc12f 164
djbottrill 0:aac55e1fc12f 165 /*
djbottrill 0:aac55e1fc12f 166 * Get device descriptor. Warning: this method has to store the length of the report descriptor in reportLength.
djbottrill 0:aac55e1fc12f 167 *
djbottrill 0:aac55e1fc12f 168 * @returns pointer to the device descriptor
djbottrill 0:aac55e1fc12f 169 */
djbottrill 0:aac55e1fc12f 170 virtual uint8_t * deviceDesc();
djbottrill 0:aac55e1fc12f 171
djbottrill 0:aac55e1fc12f 172 /*
djbottrill 0:aac55e1fc12f 173 * Get configuration descriptor
djbottrill 0:aac55e1fc12f 174 *
djbottrill 0:aac55e1fc12f 175 * @returns pointer to the configuration descriptor
djbottrill 0:aac55e1fc12f 176 */
djbottrill 0:aac55e1fc12f 177 virtual uint8_t * configurationDesc(){return NULL;};
djbottrill 0:aac55e1fc12f 178
djbottrill 0:aac55e1fc12f 179 /*
djbottrill 0:aac55e1fc12f 180 * Get string lang id descriptor
djbottrill 0:aac55e1fc12f 181 *
djbottrill 0:aac55e1fc12f 182 * @return pointer to the string lang id descriptor
djbottrill 0:aac55e1fc12f 183 */
djbottrill 0:aac55e1fc12f 184 virtual uint8_t * stringLangidDesc();
djbottrill 0:aac55e1fc12f 185
djbottrill 0:aac55e1fc12f 186 /*
djbottrill 0:aac55e1fc12f 187 * Get string manufacturer descriptor
djbottrill 0:aac55e1fc12f 188 *
djbottrill 0:aac55e1fc12f 189 * @returns pointer to the string manufacturer descriptor
djbottrill 0:aac55e1fc12f 190 */
djbottrill 0:aac55e1fc12f 191 virtual uint8_t * stringImanufacturerDesc();
djbottrill 0:aac55e1fc12f 192
djbottrill 0:aac55e1fc12f 193 /*
djbottrill 0:aac55e1fc12f 194 * Get string product descriptor
djbottrill 0:aac55e1fc12f 195 *
djbottrill 0:aac55e1fc12f 196 * @returns pointer to the string product descriptor
djbottrill 0:aac55e1fc12f 197 */
djbottrill 0:aac55e1fc12f 198 virtual uint8_t * stringIproductDesc();
djbottrill 0:aac55e1fc12f 199
djbottrill 0:aac55e1fc12f 200 /*
djbottrill 0:aac55e1fc12f 201 * Get string serial descriptor
djbottrill 0:aac55e1fc12f 202 *
djbottrill 0:aac55e1fc12f 203 * @returns pointer to the string serial descriptor
djbottrill 0:aac55e1fc12f 204 */
djbottrill 0:aac55e1fc12f 205 virtual uint8_t * stringIserialDesc();
djbottrill 0:aac55e1fc12f 206
djbottrill 0:aac55e1fc12f 207 /*
djbottrill 0:aac55e1fc12f 208 * Get string configuration descriptor
djbottrill 0:aac55e1fc12f 209 *
djbottrill 0:aac55e1fc12f 210 * @returns pointer to the string configuration descriptor
djbottrill 0:aac55e1fc12f 211 */
djbottrill 0:aac55e1fc12f 212 virtual uint8_t * stringIConfigurationDesc();
djbottrill 0:aac55e1fc12f 213
djbottrill 0:aac55e1fc12f 214 /*
djbottrill 0:aac55e1fc12f 215 * Get string interface descriptor
djbottrill 0:aac55e1fc12f 216 *
djbottrill 0:aac55e1fc12f 217 * @returns pointer to the string interface descriptor
djbottrill 0:aac55e1fc12f 218 */
djbottrill 0:aac55e1fc12f 219 virtual uint8_t * stringIinterfaceDesc();
djbottrill 0:aac55e1fc12f 220
djbottrill 0:aac55e1fc12f 221 /*
djbottrill 0:aac55e1fc12f 222 * Get the length of the report descriptor
djbottrill 0:aac55e1fc12f 223 *
djbottrill 0:aac55e1fc12f 224 * @returns length of the report descriptor
djbottrill 0:aac55e1fc12f 225 */
djbottrill 0:aac55e1fc12f 226 virtual uint16_t reportDescLength() { return 0; };
djbottrill 0:aac55e1fc12f 227
djbottrill 0:aac55e1fc12f 228
djbottrill 0:aac55e1fc12f 229
djbottrill 0:aac55e1fc12f 230 protected:
djbottrill 0:aac55e1fc12f 231 virtual void busReset(void);
djbottrill 0:aac55e1fc12f 232 virtual void EP0setupCallback(void);
djbottrill 0:aac55e1fc12f 233 virtual void EP0out(void);
djbottrill 0:aac55e1fc12f 234 virtual void EP0in(void);
djbottrill 0:aac55e1fc12f 235 virtual void connectStateChanged(unsigned int connected);
djbottrill 0:aac55e1fc12f 236 virtual void suspendStateChanged(unsigned int suspended);
djbottrill 0:aac55e1fc12f 237 uint8_t * findDescriptor(uint8_t descriptorType);
djbottrill 0:aac55e1fc12f 238 CONTROL_TRANSFER * getTransferPtr(void);
djbottrill 0:aac55e1fc12f 239
djbottrill 0:aac55e1fc12f 240 uint16_t VENDOR_ID;
djbottrill 0:aac55e1fc12f 241 uint16_t PRODUCT_ID;
djbottrill 0:aac55e1fc12f 242 uint16_t PRODUCT_RELEASE;
djbottrill 0:aac55e1fc12f 243
djbottrill 0:aac55e1fc12f 244 private:
djbottrill 0:aac55e1fc12f 245 bool addRateFeedbackEndpoint(uint8_t endpoint, uint32_t maxPacket);
djbottrill 0:aac55e1fc12f 246 bool requestGetDescriptor(void);
djbottrill 0:aac55e1fc12f 247 bool controlOut(void);
djbottrill 0:aac55e1fc12f 248 bool controlIn(void);
djbottrill 0:aac55e1fc12f 249 bool requestSetAddress(void);
djbottrill 0:aac55e1fc12f 250 bool requestSetConfiguration(void);
djbottrill 0:aac55e1fc12f 251 bool requestSetFeature(void);
djbottrill 0:aac55e1fc12f 252 bool requestClearFeature(void);
djbottrill 0:aac55e1fc12f 253 bool requestGetStatus(void);
djbottrill 0:aac55e1fc12f 254 bool requestSetup(void);
djbottrill 0:aac55e1fc12f 255 bool controlSetup(void);
djbottrill 0:aac55e1fc12f 256 void decodeSetupPacket(uint8_t *data, SETUP_PACKET *packet);
djbottrill 0:aac55e1fc12f 257 bool requestGetConfiguration(void);
djbottrill 0:aac55e1fc12f 258 bool requestGetInterface(void);
djbottrill 0:aac55e1fc12f 259 bool requestSetInterface(void);
djbottrill 0:aac55e1fc12f 260
djbottrill 0:aac55e1fc12f 261 CONTROL_TRANSFER transfer;
djbottrill 0:aac55e1fc12f 262 USB_DEVICE device;
djbottrill 0:aac55e1fc12f 263
djbottrill 0:aac55e1fc12f 264 uint16_t currentInterface;
djbottrill 0:aac55e1fc12f 265 uint8_t currentAlternate;
djbottrill 0:aac55e1fc12f 266 };
djbottrill 0:aac55e1fc12f 267
djbottrill 0:aac55e1fc12f 268
djbottrill 0:aac55e1fc12f 269 #endif