ALSA: ump: Export MIDI1 / UMP conversion helpers
PATCH 1/1 ALSA: ump: Export MIDI1 / UMP conversion helpers
Yet more preliminary work for the upcoming USB gadget support.
Now export the helpers to convert between legacy MIDI1 and UMP data for handling the MIDI 1.0 USB interface. The header file is moved to include/sound.
The API functions are slightly changed, so that they can be used without the direct access to snd_ump object. The allocation is done in ump.c itself as it's a simple kcalloc().
Signed-off-by Takashi Iwai <[email protected]>
--- include/sound/ump_convert.h | 46 +++++++++++++++++++++ sound/core/ump.c | 18 ++++----- sound/core/ump_convert.c | 80 ++++++++++++++++--------------------- sound/core/ump_convert.h | 43 -------------------- 4 files changed, 89 insertions(+), 98 deletions(-) create mode 100644 include/sound/ump_convert.h delete mode 100644 sound/core/ump_convert.h
include/sound/ump_convert.h new file +46 -0
@@ -0,0 +1,46 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +#ifndef __SOUND_UMP_CONVERT_H +#define __SOUND_UMP_CONVERT_H + +#include <sound/ump_msg.h> + +/* context for converting from legacy control messages to UMP packet */ +struct ump_cvt_to_ump_bank { +bool rpn_set; +bool nrpn_set; +bool bank_set; +unsigned char cc_rpn_msb, cc_rpn_lsb; +unsigned char cc_nrpn_msb, cc_nrpn_lsb; +unsigned char cc_data_msb, cc_data_lsb; +unsigned char cc_bank_msb, cc_bank_lsb; +}; + +/* context for converting from MIDI1 byte stream to UMP packet */ +struct ump_cvt_to_ump { +/* MIDI1 intermediate buffer */ +unsigned char buf[4 ]; +int len; +int cmd_bytes; + +/* UMP output packet */ +u32 ump[4 ]; +int ump_bytes; + +/* various status */ +unsigned int in_sysex; +struct ump_cvt_to_ump_bank bank[16 ];/* per channel */ +}; + +int snd_ump_convert_from_ump (const u32 *data,unsigned char *dst, +unsigned char *group_ret); +void snd_ump_convert_to_ump (struct ump_cvt_to_ump *cvt,unsigned char group, +unsigned int protocol,unsigned char c); + +/* reset the converter context, called at each open to ump */ +static inline void snd_ump_convert_reset (struct ump_cvt_to_ump *ctx) +{ +memset (ctx,0 ,sizeof (*ctx)); + +} + +#endif /* __SOUND_UMP_CONVERT_H */
sound/core/ump.c +9 -9
@@ -11,7 +11,7 @@#include <sound/core.h> #include <sound/rawmidi.h> #include <sound/ump.h> -#include "ump_convert.h" +#include <sound/ump_convert.h> #define ump_err(ump, fmt, args...) dev_err(&(ump)->core.dev, fmt, ##args) #define ump_warn(ump, fmt, args...) dev_warn(&(ump)->core.dev, fmt, ##args)
@@ -87,7 +87,7 @@ static void snd_ump_endpoint_free(struct snd_rawmidi *rmidi) ump->private_free (ump);#if IS_ENABLED (CONFIG_SND_UMP_LEGACY_RAWMIDI ) -snd_ump_convert_free (ump); +kfree (ump->out_cvts);#endif }
@@ -1002,7 +1002,7 @@ static int snd_ump_legacy_open(struct snd_rawmidi_substream *substream) goto unlock; } ump->legacy_out_opens++; -snd_ump_reset_convert_to_ump (ump, group); +snd_ump_convert_reset (&ump->out_cvts[group]); }spin_lock_irq (&ump->legacy_locks[dir]); ump->legacy_substreams[dir][group] = substream;
@@ -1091,7 +1091,7 @@ static int process_legacy_output(struct snd_ump_endpoint *ump, ctx = &ump->out_cvts[group];while (!ctx->ump_bytes &&snd_rawmidi_transmit (substream, &c,1 ) >0 ) -snd_ump_convert_to_ump (ump, group, c); +snd_ump_convert_to_ump (ctx, group, ump->info.protocol, c);if (ctx->ump_bytes && ctx->ump_bytes <= count) { size = ctx->ump_bytes;memcpy (buffer, ctx->ump, size);
@@ -1113,7 +1113,7 @@ static void process_legacy_input(struct snd_ump_endpoint *ump, const u32 *src,const int dir =SNDRV_RAWMIDI_STREAM_INPUT ;int size; - size =snd_ump_convert_from_ump (ump, src, buf, &group); + size =snd_ump_convert_from_ump (src, buf, &group);if (size <=0 )return ;spin_lock_irqsave (&ump->legacy_locks[dir], flags);
@@ -1130,9 +1130,9 @@ int snd_ump_attach_legacy_rawmidi(struct snd_ump_endpoint *ump,bool input, output;int err; - err =snd_ump_convert_init (ump); -if (err <0 ) -return err; + ump->out_cvts =kcalloc (16 ,sizeof (*ump->out_cvts),GFP_KERNEL ); +if (!ump->out_cvts) +return -ENOMEM ; input = ump->core.info_flags &SNDRV_RAWMIDI_INFO_INPUT ; output = ump->core.info_flags &SNDRV_RAWMIDI_INFO_OUTPUT ;
@@ -1140,7 +1140,7 @@ int snd_ump_attach_legacy_rawmidi(struct snd_ump_endpoint *ump, output ?16 :0 , input ?16 :0 , &rmidi);if (err <0 ) { -snd_ump_convert_free (ump); +kfree (ump->out_cvts);return err; }
sound/core/ump_convert.c +34 -46
131 lines not on this page · raw message
sound/core/ump_convert.h deleted +0 -43
43 lines not on this page · raw message
Signature · 1 line
2.35.3