Zoltan Hudak / UsbHostMAX3421E

Dependents:   UsbHostMAX3421E_Hello

Committer:
hudakz
Date:
Sun Jul 12 20:39:26 2020 +0000
Revision:
0:84353c479782
Child:
1:2263e77400e9
MAX3421E-based USB Host Shield Library

Who changed what in which revision?

UserRevisionLine numberNew contents of line
hudakz 0:84353c479782 1 /*
hudakz 0:84353c479782 2 *******************************************************************************
hudakz 0:84353c479782 3 * USB-MIDI class driver for USB Host Shield 2.0 Library
hudakz 0:84353c479782 4 * Copyright (c) 2012-2018 Yuuichi Akagawa
hudakz 0:84353c479782 5 *
hudakz 0:84353c479782 6 * Idea from LPK25 USB-MIDI to Serial MIDI converter
hudakz 0:84353c479782 7 * by Collin Cunningham - makezine.com, narbotic.com
hudakz 0:84353c479782 8 *
hudakz 0:84353c479782 9 * for use with USB Host Shield 2.0 from Circuitsathome.com
hudakz 0:84353c479782 10 * https://github.com/felis/USB_Host_Shield_2.0
hudakz 0:84353c479782 11 *******************************************************************************
hudakz 0:84353c479782 12 * This program is free software; you can redistribute it and/or modify
hudakz 0:84353c479782 13 * it under the terms of the GNU General Public License as published by
hudakz 0:84353c479782 14 * the Free Software Foundation; either version 2 of the License, or
hudakz 0:84353c479782 15 * (at your option) any later version.
hudakz 0:84353c479782 16 *
hudakz 0:84353c479782 17 * This program is distributed in the hope that it will be useful,
hudakz 0:84353c479782 18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
hudakz 0:84353c479782 19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
hudakz 0:84353c479782 20 * GNU General Public License for more details.
hudakz 0:84353c479782 21 *
hudakz 0:84353c479782 22 * You should have received a copy of the GNU General Public License
hudakz 0:84353c479782 23 * along with this program. If not, see <http://www.gnu.org/licenses/>
hudakz 0:84353c479782 24 *******************************************************************************
hudakz 0:84353c479782 25 */
hudakz 0:84353c479782 26
hudakz 0:84353c479782 27 #if !defined(_USBH_MIDI_H_)
hudakz 0:84353c479782 28 #define _USBH_MIDI_H_
hudakz 0:84353c479782 29 //#define DEBUG_USB_HOST
hudakz 0:84353c479782 30 #include "Usb.h"
hudakz 0:84353c479782 31
hudakz 0:84353c479782 32 #define MIDI_MAX_ENDPOINTS 5 //endpoint 0, bulk_IN(MIDI), bulk_OUT(MIDI), bulk_IN(VSP), bulk_OUT(VSP)
hudakz 0:84353c479782 33 #define USB_SUBCLASS_MIDISTREAMING 3
hudakz 0:84353c479782 34 #define DESC_BUFF_SIZE 256
hudakz 0:84353c479782 35 #define MIDI_EVENT_PACKET_SIZE 64
hudakz 0:84353c479782 36 #define MIDI_MAX_SYSEX_SIZE 256
hudakz 0:84353c479782 37 class USBH_MIDI;
hudakz 0:84353c479782 38
hudakz 0:84353c479782 39 class USBH_MIDI : public USBDeviceConfig
hudakz 0:84353c479782 40 {
hudakz 0:84353c479782 41 protected:
hudakz 0:84353c479782 42 static const uint8_t epDataInIndex; // DataIn endpoint index(MIDI)
hudakz 0:84353c479782 43 static const uint8_t epDataOutIndex; // DataOUT endpoint index(MIDI)
hudakz 0:84353c479782 44 static const uint8_t epDataInIndexVSP; // DataIn endpoint index(Vendor Specific Protocl)
hudakz 0:84353c479782 45 static const uint8_t epDataOutIndexVSP; // DataOUT endpoint index(Vendor Specific Protocl)
hudakz 0:84353c479782 46
hudakz 0:84353c479782 47 /* mandatory members */
hudakz 0:84353c479782 48 USB *pUsb;
hudakz 0:84353c479782 49 uint8_t bAddress;
hudakz 0:84353c479782 50 uint8_t bConfNum; // configuration number
hudakz 0:84353c479782 51 uint8_t bNumEP; // total number of EP in the configuration
hudakz 0:84353c479782 52 bool bPollEnable;
hudakz 0:84353c479782 53 bool isMidiFound;
hudakz 0:84353c479782 54 uint16_t pid, vid; // ProductID, VendorID
hudakz 0:84353c479782 55 uint8_t bTransferTypeMask;
hudakz 0:84353c479782 56 /* Endpoint data structure */
hudakz 0:84353c479782 57 EpInfo epInfo[MIDI_MAX_ENDPOINTS];
hudakz 0:84353c479782 58 /* MIDI Event packet buffer */
hudakz 0:84353c479782 59 uint8_t recvBuf[MIDI_EVENT_PACKET_SIZE];
hudakz 0:84353c479782 60 uint8_t readPtr;
hudakz 0:84353c479782 61
hudakz 0:84353c479782 62 uint8_t parseConfigDescr(uint8_t addr, uint8_t conf);
hudakz 0:84353c479782 63 uint16_t countSysExDataSize(uint8_t *dataptr);
hudakz 0:84353c479782 64 void setupDeviceSpecific();
hudakz 0:84353c479782 65 #ifdef DEBUG_USB_HOST
hudakz 0:84353c479782 66 void PrintEndpointDescriptor( const USB_ENDPOINT_DESCRIPTOR* ep_ptr );
hudakz 0:84353c479782 67 #endif
hudakz 0:84353c479782 68 public:
hudakz 0:84353c479782 69 USBH_MIDI(USB *p);
hudakz 0:84353c479782 70 // Misc functions
hudakz 0:84353c479782 71 operator bool() { return (pUsb->getUsbTaskState()==USB_STATE_RUNNING); }
hudakz 0:84353c479782 72 uint16_t idVendor() { return vid; }
hudakz 0:84353c479782 73 uint16_t idProduct() { return pid; }
hudakz 0:84353c479782 74 // Methods for recieving and sending data
hudakz 0:84353c479782 75 uint8_t RecvData(uint16_t *bytes_rcvd, uint8_t *dataptr);
hudakz 0:84353c479782 76 uint8_t RecvData(uint8_t *outBuf, bool isRaw=false);
hudakz 0:84353c479782 77 uint8_t RecvRawData(uint8_t *outBuf);
hudakz 0:84353c479782 78 uint8_t SendData(uint8_t *dataptr, uint8_t nCable=0);
hudakz 0:84353c479782 79 uint8_t lookupMsgSize(uint8_t midiMsg, uint8_t cin=0);
hudakz 0:84353c479782 80 uint8_t SendSysEx(uint8_t *dataptr, uint16_t datasize, uint8_t nCable=0);
hudakz 0:84353c479782 81 uint8_t extractSysExData(uint8_t *p, uint8_t *buf);
hudakz 0:84353c479782 82 uint8_t SendRawData(uint16_t bytes_send, uint8_t *dataptr);
hudakz 0:84353c479782 83 // backward compatibility functions
hudakz 0:84353c479782 84 inline uint8_t RcvData(uint16_t *bytes_rcvd, uint8_t *dataptr) { return RecvData(bytes_rcvd, dataptr); };
hudakz 0:84353c479782 85 inline uint8_t RcvData(uint8_t *outBuf) { return RecvData(outBuf); };
hudakz 0:84353c479782 86
hudakz 0:84353c479782 87 // USBDeviceConfig implementation
hudakz 0:84353c479782 88 virtual uint8_t Init(uint8_t parent, uint8_t port, bool lowspeed);
hudakz 0:84353c479782 89 virtual uint8_t Release();
hudakz 0:84353c479782 90 virtual uint8_t GetAddress() { return bAddress; };
hudakz 0:84353c479782 91 };
hudakz 0:84353c479782 92 #endif //_USBH_MIDI_H_