Andrzej Pietrasiewicz
2014-10-16 10:13:41 UTC
This series aims at integrating configfs into hid, the way
it has been done for acm, ncm, ecm, eem, ecm subset, rndis, obex, phonet,
mass_storage, FunctionFS, loopback, sourcesink, uac1, uac2, uvc and hid.
It concludes converting functions explicitly available as f_xyz.c files
to configfs.
Rebased onto Felipe's testing/next.
Since Felipe has closed his tree for 3.18, this is meant for 3.19.
BACKWARD COMPATIBILITY
======================
Please note that the old g_midi.ko is still available and works.
USING THE NEW "GADGET"
======================
Please refer to this post:
http://www.spinics.net/lists/linux-usb/msg76388.html
for general information from Sebastian on how to use configfs-based
gadgets (*).
With configfs the procedure is as follows, compared to the information
mentioned above (*):
instead of mkdir functions/acm.ttyS1 do
mkdir functions/hid.<instance name>
e.g. mkdir functions/midi.usb0.
In the midi.usb0 directory there will be the following attributes:
buflen - MIDI buffer length
id - ID string for the USB MIDI adapter
in_ports - number of MIDI input ports
index - index value for the USB MIDI adapter
out_ports - number of MIDI output ports
qlen - USB read request queue length
Below is a script which creates a midi gadget:
# modprobe libcomposite
# mount none cfg -t configfs
# mkdir cfg/usb_gadget/g1
# cd cfg/usb_gadget/g1
# mkdir configs/c.1
# mkdir functions/midi.usb0
# mkdir strings/0x409
# mkdir configs/c.1/strings/0x409
# echo 0x0004 > idProduct
# echo 0x17b3 > idVendor
# echo serial > strings/0x409/serialnumber
# echo manufacturer > strings/0x409/manufacturer
# echo MIDI Gadget > strings/0x409/product
# echo "Conf 1" > configs/c.1/strings/0x409/configuration
# echo 120 > configs/c.1/MaxPower
# ln -s functions/midi.usb0 configs/c.1
# echo 12480000.hsotg > UDC
TESTING THE FUNCTION
====================
Run the gadget as above. There are two cases: playing a mid from the gadget to
the host and playing a mid from the host to the gadget.
1) Playing a mid from the gadget to the host
host)
$ arecordmidi -l
Port Client name Port name
14:0 Midi Through Midi Through Port-0
24:0 MIDI Gadget MIDI Gadget MIDI 1
$ arecordmidi -p 24:0 from_gadget.mid
gadget)
$ aplaymidi -l
Port Client name Port name
20:0 f_midi f_midi
$ aplaymidi -p 20:0 to_host.mid
2) Playing a mid from the host to the gadget
gadget)
$ arecordmidi -l
Port Client name Port name
20:0 f_midi f_midi
$ arecordmidi -p 20:0 from_host.mid
host)
$ aplaymidi -l
Port Client name Port name
14:0 Midi Through Midi Through Port-0
24:0 MIDI Gadget MIDI Gadget MIDI 1
$ aplaymidi -p24:0 to_gadget.mid
The from_gadget.mid should sound identical to the to_host.mid.
The from_host.id should sound identical to the to_gadget.mid.
MIDI files can be played to speakers/headphones with e.g. timidity installed
$ aplaymidi -l
Port Client name Port name
14:0 Midi Through Midi Through Port-0
24:0 MIDI Gadget MIDI Gadget MIDI 1
128:0 TiMidity TiMidity port 0
128:1 TiMidity TiMidity port 1
128:2 TiMidity TiMidity port 2
128:3 TiMidity TiMidity port 3
$ aplaymidi -p 128:0 file.mid
MIDI ports can be logically connected using the aconnect utility, e.g.:
$ aconnect 24:0 128:0 # try it on the host
After the gadget's MIDI port is connected to timidity's MIDI port,
whatever is played at the gadget side with aplaymidi -l is audible
in host's speakers/headphones.
Andrzej Pietrasiewicz (7):
usb: gadget: f_midi: enable use of the index parameter
usb: gadget: f_midi: check kstrdup() return value
usb: gadget: f_midi: convert to new function interface with backward
compatibility
usb: gadget: midi: convert to new interface of f_midi
usb: gadget: f_midi: remove compatibility layer
usb: gadget: f_midi: use usb_gstrings_attach
usb: gadget: f_midi: add configfs support
Documentation/ABI/testing/configfs-usb-gadget-midi | 12 +
drivers/usb/gadget/Kconfig | 16 +
drivers/usb/gadget/function/Makefile | 2 +
drivers/usb/gadget/function/f_midi.c | 364 ++++++++++++++++-----
drivers/usb/gadget/function/u_midi.h | 40 +++
drivers/usb/gadget/legacy/Kconfig | 1 +
drivers/usb/gadget/legacy/gmidi.c | 43 ++-
7 files changed, 382 insertions(+), 96 deletions(-)
create mode 100644 Documentation/ABI/testing/configfs-usb-gadget-midi
create mode 100644 drivers/usb/gadget/function/u_midi.h
it has been done for acm, ncm, ecm, eem, ecm subset, rndis, obex, phonet,
mass_storage, FunctionFS, loopback, sourcesink, uac1, uac2, uvc and hid.
It concludes converting functions explicitly available as f_xyz.c files
to configfs.
Rebased onto Felipe's testing/next.
Since Felipe has closed his tree for 3.18, this is meant for 3.19.
BACKWARD COMPATIBILITY
======================
Please note that the old g_midi.ko is still available and works.
USING THE NEW "GADGET"
======================
Please refer to this post:
http://www.spinics.net/lists/linux-usb/msg76388.html
for general information from Sebastian on how to use configfs-based
gadgets (*).
With configfs the procedure is as follows, compared to the information
mentioned above (*):
instead of mkdir functions/acm.ttyS1 do
mkdir functions/hid.<instance name>
e.g. mkdir functions/midi.usb0.
In the midi.usb0 directory there will be the following attributes:
buflen - MIDI buffer length
id - ID string for the USB MIDI adapter
in_ports - number of MIDI input ports
index - index value for the USB MIDI adapter
out_ports - number of MIDI output ports
qlen - USB read request queue length
Below is a script which creates a midi gadget:
# modprobe libcomposite
# mount none cfg -t configfs
# mkdir cfg/usb_gadget/g1
# cd cfg/usb_gadget/g1
# mkdir configs/c.1
# mkdir functions/midi.usb0
# mkdir strings/0x409
# mkdir configs/c.1/strings/0x409
# echo 0x0004 > idProduct
# echo 0x17b3 > idVendor
# echo serial > strings/0x409/serialnumber
# echo manufacturer > strings/0x409/manufacturer
# echo MIDI Gadget > strings/0x409/product
# echo "Conf 1" > configs/c.1/strings/0x409/configuration
# echo 120 > configs/c.1/MaxPower
# ln -s functions/midi.usb0 configs/c.1
# echo 12480000.hsotg > UDC
TESTING THE FUNCTION
====================
Run the gadget as above. There are two cases: playing a mid from the gadget to
the host and playing a mid from the host to the gadget.
1) Playing a mid from the gadget to the host
host)
$ arecordmidi -l
Port Client name Port name
14:0 Midi Through Midi Through Port-0
24:0 MIDI Gadget MIDI Gadget MIDI 1
$ arecordmidi -p 24:0 from_gadget.mid
gadget)
$ aplaymidi -l
Port Client name Port name
20:0 f_midi f_midi
$ aplaymidi -p 20:0 to_host.mid
2) Playing a mid from the host to the gadget
gadget)
$ arecordmidi -l
Port Client name Port name
20:0 f_midi f_midi
$ arecordmidi -p 20:0 from_host.mid
host)
$ aplaymidi -l
Port Client name Port name
14:0 Midi Through Midi Through Port-0
24:0 MIDI Gadget MIDI Gadget MIDI 1
$ aplaymidi -p24:0 to_gadget.mid
The from_gadget.mid should sound identical to the to_host.mid.
The from_host.id should sound identical to the to_gadget.mid.
MIDI files can be played to speakers/headphones with e.g. timidity installed
$ aplaymidi -l
Port Client name Port name
14:0 Midi Through Midi Through Port-0
24:0 MIDI Gadget MIDI Gadget MIDI 1
128:0 TiMidity TiMidity port 0
128:1 TiMidity TiMidity port 1
128:2 TiMidity TiMidity port 2
128:3 TiMidity TiMidity port 3
$ aplaymidi -p 128:0 file.mid
MIDI ports can be logically connected using the aconnect utility, e.g.:
$ aconnect 24:0 128:0 # try it on the host
After the gadget's MIDI port is connected to timidity's MIDI port,
whatever is played at the gadget side with aplaymidi -l is audible
in host's speakers/headphones.
Andrzej Pietrasiewicz (7):
usb: gadget: f_midi: enable use of the index parameter
usb: gadget: f_midi: check kstrdup() return value
usb: gadget: f_midi: convert to new function interface with backward
compatibility
usb: gadget: midi: convert to new interface of f_midi
usb: gadget: f_midi: remove compatibility layer
usb: gadget: f_midi: use usb_gstrings_attach
usb: gadget: f_midi: add configfs support
Documentation/ABI/testing/configfs-usb-gadget-midi | 12 +
drivers/usb/gadget/Kconfig | 16 +
drivers/usb/gadget/function/Makefile | 2 +
drivers/usb/gadget/function/f_midi.c | 364 ++++++++++++++++-----
drivers/usb/gadget/function/u_midi.h | 40 +++
drivers/usb/gadget/legacy/Kconfig | 1 +
drivers/usb/gadget/legacy/gmidi.c | 43 ++-
7 files changed, 382 insertions(+), 96 deletions(-)
create mode 100644 Documentation/ABI/testing/configfs-usb-gadget-midi
create mode 100644 drivers/usb/gadget/function/u_midi.h
--
1.9.1
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo-***@public.gmane.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
1.9.1
--
To unsubscribe from this list: send the line "unsubscribe linux-usb" in
the body of a message to majordomo-***@public.gmane.org
More majordomo info at http://vger.kernel.org/majordomo-info.html