pos 机 gd32f103 midi设备

1/芯片本身有usb 直接 初始化成 usb midi 设备,然后将 io 数据传输到串口就ok
引用连接:https://blog.csdn.net/weixin_41082557/article/details/105579510?utm_source=app&app_version=4.7.1
修改 hid 接口,增加 midi 接口
在原是STM32F103 USB HID的工程基础上改为USB MIDI设备

主要内容修改配置描述符 USBD_CUSTOM_HID_CfgDesc,

注意MIDI属于音频类,需要配置为Audio类,并且需要添加控制端点。

__ALIGN_BEGIN static uint8_t USBD_CUSTOM_HID_CfgDesc[USB_CUSTOM_HID_CONFIG_DESC_SIZ] __ALIGN_END =

{

0x09, /* bLength: Configuration Descriptor size */

USB_DESC_TYPE_CONFIGURATION, /* bDescriptorType: Configuration */

USB_CUSTOM_HID_CONFIG_DESC_SIZ,

/* wTotalLength: Bytes returned */

0x00,

0x02,//1 /bNumInterfaces: 2 interface/

0x01, /bConfigurationValue: Configuration value/

0x00, /*iConfiguration: Index of string descriptor describing

the configuration*/

0xC0, /*bmAttributes: bus powered */

0x32, /MaxPower 100 mA: this current is used for detecting Vbus/

/******************* Standard AC Interface Descriptor *********************/

/* 09 */

0x09, /bLength: Interface Descriptor size/

USB_DESC_TYPE_INTERFACE, /bDescriptorType: Interface descriptor type/

0x00, /bInterfaceNumber: Number of Interface/

0x00, /bAlternateSetting: Alternate setting/

0x00, /bNumEndpoints/

0x01, /bInterfaceClass: Audio/

0x01, /bInterfaceSubClass : Audio Control/

0, /nInterfaceProtocol/

0, /iInterface: Index of string descriptor/

/**************** Class-specific AC Interface Descriptor ******************/

/* 18 */

0x09, /bLength: Interface Descriptor size/

0x24, /bDescriptorType: Class-specific interface descriptor type/

0x01, /bDescriptorSubType: Header/

0x00, /bcdADC: Revision of class specification - 1.0/

0x01,

0x09, /wTotalLength: Total size of class specific discriptor/

0x00,

0x01, /bInCollection: Number of streaming interfaces/

0x01, /*baInterfaceNr : MIDIStreaming interface 1 belongs to

                            this AudioControl interface*/

/******************* Standard MS Interface Descriptor *********************/

/* 27 */

0x09, /bLength: Interface Descriptor size/

USB_DESC_TYPE_INTERFACE, /bDescriptorType: Interface descriptor type/

0x01, /bInterfaceNumber: Number of Interface/

0x00, /bAlternateSetting: Alternate setting/

0x02, /bNumEndpoints/

0x01, /bInterfaceClass: Audio/

0x03, /bInterfaceSubClass : MIDI Streaming/

0, /nInterfaceProtocol/

0, /iInterface: Index of string descriptor/

/**************** Class-specific MS Interface Descriptor ******************/

/* 36 */

0x07, /bLength: Interface Descriptor size/

0x24, /bDescriptorType: Class-specific interface descriptor type/

0x01, /bDescriptorSubType: MS Header/

0x00, /bcdADC: Revision of class specification/

0x01,

0x41, /wTotalLength: Total size of class specific discriptor/

0x00,

/******************* MIDI IN Jack Descriptor (Embedded) *******************/

/* 43 */

0x06, /bLength: Size of this descriptor/

0x24, /bDescriptorType: Class-specific interface descriptor type/

0x02, /bDescriptorSubType: MIDI IN Jack/

0x01, /bJackType: Embedded/

0x01, /bJackID: ID of this Jack/

0x00, /iJack/

/******************* MIDI IN Jack Descriptor (External) 扩展midi输入接口*******************/

/* 49 */

0x06, /bLength: Size of this descriptor/

0x24, /bDescriptorType: Class-specific interface descriptor type/

0x02, /bDescriptorSubType: MIDI IN Jack/

0x02, /bJackType: External/

0x02, /bJackID: ID of this Jack/

0x00, /iJack/

/******************* MIDI OUT Jack Descriptor (Embedded) ******************/

/* 55 */

0x09, /bLength: Size of this descriptor/

0x24, /bDescriptorType: Class-specific interface descriptor type/

0x03, /bDescriptorSubType: MIDI OUT Jack/

0x01, /bJackType: Embedded/

0x03, /bJackID: ID of this Jack/

0x01, /bNrInputPins: Number of Input Pins of this Jack/

0x02, /BaSourceID: ID of the Entry to which this Pin is connected/

0x01, /*BaSourceID: Output Pin number of the Entry to

                        which this Input Pin is connected*/

0x00, /iJack/

/******************* MIDI OUT Jack Descriptor (External) 扩展 midi 输出接口******************/

/* 64 */

0x09, /bLength: Size of this descriptor/

0x24, /bDescriptorType: Class-specific interface descriptor type/

0x03, /bDescriptorSubType: MIDI OUT Jack/

0x02, /bJackType: External/

0x04, /bJackID: ID of this Jack/

0x01, /bNrInputPins: Number of Input Pins of this Jack/

0x01, /BaSourceID: ID of the Entry to which this Pin is connected/

0x01, /*BaSourceID: Output Pin number of the Entry to

                        which this Input Pin is connected*/

0x00, /iJack/

/****************** Standard Bulk OUT Endpoint Descriptor *****************/

/* 73 */

0x09, /bLength: Size of this descriptor/

USB_DESC_TYPE_ENDPOINT, /bDescriptorType: Endpoint descriptor type/

0x01, /bEndpointAddress: OUT Endpoint 1/

0x02, /bmAttributes: Bulk, not shared./

0x40, /wMaxPacketSize 64/

0x00,

0x00, /bInterval/

0x00, /bRefresh/

0x00, /bSynchAddress/

/************* Class-specific MS Bulk OUT Endpoint Descriptor *************/

/* 82 */

0x05, /bLength: Size of this descriptor/

0x25, /bDescriptorType: Class-specific endpoint descriptor type/

0x01, /bDescriptorSubType: MS General/

0x01, /bNumEmbMIDIJack: Number of embedded MIDI IN Jack/

0x01, /BaAssocJackID: ID of the Embedded MIDI IN Jack/

/****************** Standard Bulk IN Endpoint Descriptor 标准绑定输入端点***************/

/* 87 */

0x09, /bLength: Size of this descriptor/

USB_DESC_TYPE_ENDPOINT, /bDescriptorType: Endpoint descriptor type/

0x81, /bEndpointAddress: IN Endpoint 1/

0x02, /bmAttributes: Bulk, not shared./

0x40, /wMaxPacketSize 64/

0x00,

0x00, /bInterval/

0x00, /bRefresh/

0x00, /bSynchAddress/

/************* Class-specific MS Bulk OUT Endpoint Descriptor 特别类 低位绑定输出端点***********/

/* 96 */

0x05, /bLength: Size of this descriptor/

0x25, /bDescriptorType: Class-specific endpoint descriptor type/

0x01, /bDescriptorSubType: MS General/

0x01, /bNumEmbMIDIJack: Number of embedded MIDI OUT Jack/

0x03, /BaAssocJackID: ID of the Embedded MIDI OUT Jack/

/* 101 */

} ;

修改配置描述符长度
hidsend 发送数据 修改为 键盘轮询接口 并加入串口收发就ok

2/电子琴需要外接两个74hc164增加

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值