From 9ae823595a6f77cd55ed91a2dd23d152a5e385c4 Mon Sep 17 00:00:00 2001 From: Gregory Nutt Date: Thu, 24 Jul 2014 10:21:04 -0600 Subject: Convert ac_format and ac_controls to unions to make access a little cleaner --- apps/system/nxplayer/nxplayer.c | 52 +++++++++++++++++++-------------------- nuttx/audio/pcm_decode.c | 12 ++++----- nuttx/drivers/audio/audio_null.c | 44 +++++++++++++++------------------ nuttx/drivers/audio/vs1053.c | 42 ++++++++++++++----------------- nuttx/drivers/audio/wm8904.c | 39 ++++++++++++++--------------- nuttx/include/nuttx/audio/audio.h | 17 ++++++++++--- 6 files changed, 101 insertions(+), 105 deletions(-) diff --git a/apps/system/nxplayer/nxplayer.c b/apps/system/nxplayer/nxplayer.c index bbd9d5cec..74328c595 100644 --- a/apps/system/nxplayer/nxplayer.c +++ b/apps/system/nxplayer/nxplayer.c @@ -255,10 +255,8 @@ static int nxplayer_opendevice(FAR struct nxplayer_s *pPlayer, int format, { /* Test if this device supports the format we want */ - int ac_format = caps.ac_format[0] | (caps.ac_format[1] << 8); - - if (((ac_format & (1 << (format - 1))) != 0) && - (caps.ac_controls[0] & AUDIO_TYPE_OUTPUT)) + if (((caps.ac_format.hw & (1 << (format - 1))) != 0) && + (caps.ac_controls.b[0] & AUDIO_TYPE_OUTPUT)) { /* Do subformat detection */ @@ -267,7 +265,7 @@ static int nxplayer_opendevice(FAR struct nxplayer_s *pPlayer, int format, /* Prepare to get sub-formats for this main format */ caps.ac_subtype = format; - caps.ac_format[0] = 0; + caps.ac_format.b[0] = 0; while (ioctl(pPlayer->devFd, AUDIOIOC_GETCAPS, (unsigned long) &caps) == caps.ac_len) @@ -276,13 +274,13 @@ static int nxplayer_opendevice(FAR struct nxplayer_s *pPlayer, int format, for (x = 0; x < sizeof(caps.ac_controls); x++) { - if (caps.ac_controls[x] == subfmt) + if (caps.ac_controls.b[x] == subfmt) { /* Sub format supported! */ break; } - else if (caps.ac_controls[x] == AUDIO_SUBFMT_END) + else if (caps.ac_controls.b[x] == AUDIO_SUBFMT_END) { /* Sub format not supported */ @@ -300,9 +298,9 @@ static int nxplayer_opendevice(FAR struct nxplayer_s *pPlayer, int format, break; } - /* Increment ac_format[0] to get next set of subformats */ + /* Increment ac_format.b[0] to get next set of subformats */ - caps.ac_format[0]++; + caps.ac_format.b[0]++; } } @@ -887,10 +885,10 @@ int nxplayer_setvolume(FAR struct nxplayer_s *pPlayer, uint16_t volume) #ifdef CONFIG_AUDIO_MULTI_SESSION cap_desc.session= pPlayer->session; #endif - cap_desc.caps.ac_len = sizeof(struct audio_caps_s); - cap_desc.caps.ac_type = AUDIO_TYPE_FEATURE; - *((uint16_t *) cap_desc.caps.ac_format) = AUDIO_FU_VOLUME; - *((uint16_t *) cap_desc.caps.ac_controls) = volume; + cap_desc.caps.ac_len = sizeof(struct audio_caps_s); + cap_desc.caps.ac_type = AUDIO_TYPE_FEATURE; + cap_desc.caps.ac_format.hw = AUDIO_FU_VOLUME; + cap_desc.caps.ac_controls.hw[0] = volume; ioctl(pPlayer->devFd, AUDIOIOC_CONFIGURE, (unsigned long) &cap_desc); } @@ -966,10 +964,10 @@ int nxplayer_setbass(FAR struct nxplayer_s *pPlayer, uint8_t level) #ifdef CONFIG_AUDIO_MULTI_SESSION cap_desc.session= pPlayer->session; #endif - cap_desc.caps.ac_len = sizeof(struct audio_caps_s); - cap_desc.caps.ac_type = AUDIO_TYPE_FEATURE; - *((uint16_t *) cap_desc.caps.ac_format) = AUDIO_FU_BASS; - cap_desc.caps.ac_controls[0] = level; + cap_desc.caps.ac_len = sizeof(struct audio_caps_s); + cap_desc.caps.ac_type = AUDIO_TYPE_FEATURE; + cap_desc.caps.ac_format.hw = AUDIO_FU_BASS; + cap_desc.caps.ac_controls.b[0] = level; ioctl(pPlayer->devFd, AUDIOIOC_CONFIGURE, (unsigned long) &cap_desc); } @@ -1018,10 +1016,10 @@ int nxplayer_settreble(FAR struct nxplayer_s *pPlayer, uint8_t level) #ifdef CONFIG_AUDIO_MULTI_SESSION cap_desc.session= pPlayer->session; #endif - cap_desc.caps.ac_len = sizeof(struct audio_caps_s); - cap_desc.caps.ac_type = AUDIO_TYPE_FEATURE; - *((uint16_t *) cap_desc.caps.ac_format) = AUDIO_FU_TREBLE; - cap_desc.caps.ac_controls[0] = level; + cap_desc.caps.ac_len = sizeof(struct audio_caps_s); + cap_desc.caps.ac_type = AUDIO_TYPE_FEATURE; + cap_desc.caps.ac_format.hw = AUDIO_FU_TREBLE; + cap_desc.caps.ac_controls.b[0] = level; ioctl(pPlayer->devFd, AUDIOIOC_CONFIGURE, (unsigned long) &cap_desc); } @@ -1065,10 +1063,10 @@ int nxplayer_setbalance(FAR struct nxplayer_s *pPlayer, uint16_t balance) #ifdef CONFIG_AUDIO_MULTI_SESSION cap_desc.session= pPlayer->session; #endif - cap_desc.caps.ac_len = sizeof(struct audio_caps_s); - cap_desc.caps.ac_type = AUDIO_TYPE_FEATURE; - *((uint16_t *) cap_desc.caps.ac_format) = AUDIO_FU_BALANCE; - *((uint16_t *) cap_desc.caps.ac_controls) = balance; + cap_desc.caps.ac_len = sizeof(struct audio_caps_s); + cap_desc.caps.ac_type = AUDIO_TYPE_FEATURE; + cap_desc.caps.ac_format.hw = AUDIO_FU_BALANCE; + cap_desc.caps.ac_controls.hw[0] = balance; ioctl(pPlayer->devFd, AUDIOIOC_CONFIGURE, (unsigned long) &cap_desc); } @@ -1268,8 +1266,8 @@ int nxplayer_setdevice(FAR struct nxplayer_s *pPlayer, FAR const char *pDevice) /* Save the path and format capabilities of the preferred device */ strncpy(pPlayer->prefdevice, pDevice, sizeof(pPlayer->prefdevice)); - pPlayer->prefformat = caps.ac_format[0] | (caps.ac_format[1] << 8); - pPlayer->preftype = caps.ac_controls[0]; + pPlayer->prefformat = caps.ac_format.b[0] | (caps.ac_format.b[1] << 8); + pPlayer->preftype = caps.ac_controls.b[0]; return OK; } diff --git a/nuttx/audio/pcm_decode.c b/nuttx/audio/pcm_decode.c index 45937fd12..6b46f770b 100644 --- a/nuttx/audio/pcm_decode.c +++ b/nuttx/audio/pcm_decode.c @@ -407,7 +407,7 @@ static int pcm_getcaps(FAR struct audio_lowerhalf_s *dev, int type, if (caps->ac_subtype == AUDIO_TYPE_QUERY) { - *((uint16_t *)&caps->ac_format[0]) = (1 << (AUDIO_FMT_PCM - 1)); + caps->ac_format.hw = (1 << (AUDIO_FMT_PCM - 1)); } return caps->ac_len; @@ -749,12 +749,12 @@ static int pcm_enqueuebuffer(FAR struct audio_lowerhalf_s *dev, DEBUGASSERT(priv->samprate < 65535); - caps.ac_len = sizeof(struct audio_caps_s); - caps.ac_type = AUDIO_TYPE_OUTPUT; - caps.ac_channels = priv->nchannels; + caps.ac_len = sizeof(struct audio_caps_s); + caps.ac_type = AUDIO_TYPE_OUTPUT; + caps.ac_channels = priv->nchannels; - *((uint16_t *)&caps.ac_controls[0]) = (uint16_t)priv->samprate; - caps.ac_controls[2] = priv->bpsamp; + caps.ac_controls.hw[0] = (uint16_t)priv->samprate; + caps.ac_controls.b[2] = priv->bpsamp; #ifdef CONFIG_AUDIO_MULTI_SESSION ret = lower->ops->configure(lower, priv->session, &caps); diff --git a/nuttx/drivers/audio/audio_null.c b/nuttx/drivers/audio/audio_null.c index 401cf1d75..1dff793a9 100644 --- a/nuttx/drivers/audio/audio_null.c +++ b/nuttx/drivers/audio/audio_null.c @@ -186,12 +186,8 @@ static int null_getcaps(FAR struct audio_lowerhalf_s *dev, int type, /* Fill in the caller's structure based on requested info */ - caps->ac_format[0] = 0; - caps->ac_format[1] = 0; - caps->ac_controls[0] = 0; - caps->ac_controls[1] = 0; - caps->ac_controls[2] = 0; - caps->ac_controls[3] = 0; + caps->ac_format.hw = 0; + caps->ac_controls.w = 0; switch (caps->ac_type) { @@ -214,19 +210,19 @@ static int null_getcaps(FAR struct audio_lowerhalf_s *dev, int type, /* The types of audio units we implement */ - caps->ac_controls[0] = AUDIO_TYPE_OUTPUT | AUDIO_TYPE_FEATURE | - AUDIO_TYPE_PROCESSING; + caps->ac_controls.b[0] = AUDIO_TYPE_OUTPUT | AUDIO_TYPE_FEATURE | + AUDIO_TYPE_PROCESSING; break; case AUDIO_FMT_MIDI: /* We only support Format 0 */ - caps->ac_controls[0] = AUDIO_SUBFMT_END; + caps->ac_controls.b[0] = AUDIO_SUBFMT_END; break; default: - caps->ac_controls[0] = AUDIO_SUBFMT_END; + caps->ac_controls.b[0] = AUDIO_SUBFMT_END; break; } @@ -244,10 +240,10 @@ static int null_getcaps(FAR struct audio_lowerhalf_s *dev, int type, /* Report the Sample rates we support */ - caps->ac_controls[0] = AUDIO_SAMP_RATE_8K | AUDIO_SAMP_RATE_11K | - AUDIO_SAMP_RATE_16K | AUDIO_SAMP_RATE_22K | - AUDIO_SAMP_RATE_32K | AUDIO_SAMP_RATE_44K | - AUDIO_SAMP_RATE_48K; + caps->ac_controls.b[0] = AUDIO_SAMP_RATE_8K | AUDIO_SAMP_RATE_11K | + AUDIO_SAMP_RATE_16K | AUDIO_SAMP_RATE_22K | + AUDIO_SAMP_RATE_32K | AUDIO_SAMP_RATE_44K | + AUDIO_SAMP_RATE_48K; break; case AUDIO_FMT_MP3: @@ -271,8 +267,8 @@ static int null_getcaps(FAR struct audio_lowerhalf_s *dev, int type, { /* Fill in the ac_controls section with the Feature Units we have */ - caps->ac_controls[0] = AUDIO_FU_VOLUME | AUDIO_FU_BASS | AUDIO_FU_TREBLE; - caps->ac_controls[1] = AUDIO_FU_BALANCE >> 8; + caps->ac_controls.b[0] = AUDIO_FU_VOLUME | AUDIO_FU_BASS | AUDIO_FU_TREBLE; + caps->ac_controls.b[1] = AUDIO_FU_BALANCE >> 8; } else { @@ -293,14 +289,14 @@ static int null_getcaps(FAR struct audio_lowerhalf_s *dev, int type, /* Provide the type of Processing Units we support */ - caps->ac_controls[0] = AUDIO_PU_STEREO_EXTENDER; + caps->ac_controls.b[0] = AUDIO_PU_STEREO_EXTENDER; break; case AUDIO_PU_STEREO_EXTENDER: /* Provide capabilities of our Stereo Extender */ - caps->ac_controls[0] = AUDIO_STEXT_ENABLE | AUDIO_STEXT_WIDTH; + caps->ac_controls.b[0] = AUDIO_STEXT_ENABLE | AUDIO_STEXT_WIDTH; break; default: @@ -360,21 +356,21 @@ static int null_configure(FAR struct audio_lowerhalf_s *dev, /* Process based on Feature Unit */ - switch (*((uint16_t *)caps->ac_format)) + switch (caps->ac_format.hw) { #ifndef CONFIG_AUDIO_EXCLUDE_VOLUME case AUDIO_FU_VOLUME: - audvdbg(" Volume: %d\n", *(uint16_t *)caps->ac_controls); + audvdbg(" Volume: %d\n", caps->ac_controls.hw[0]); break; #endif /* CONFIG_AUDIO_EXCLUDE_VOLUME */ #ifndef CONFIG_AUDIO_EXCLUDE_TONE case AUDIO_FU_BASS: - audvdbg(" Bass: %d\n", caps->ac_controls[0]); + audvdbg(" Bass: %d\n", caps->ac_controls.b[0]); break; case AUDIO_FU_TREBLE: - audvdbg(" Treble: %d\n", caps->ac_controls[0]); + audvdbg(" Treble: %d\n", caps->ac_controls.b[0]); break; #endif /* CONFIG_AUDIO_EXCLUDE_TONE */ @@ -387,8 +383,8 @@ static int null_configure(FAR struct audio_lowerhalf_s *dev, case AUDIO_TYPE_OUTPUT: audvdbg(" AUDIO_TYPE_OUTPUT:\n"); audvdbg(" Number of channels: %u\n", caps->ac_channels); - audvdbg(" Sample rate: %u\n", *(uint16_t*)&ac_controls[0]); - audvdbg(" Sample width: %u\n", ac_controls[2]); + audvdbg(" Sample rate: %u\n", ac_controls.hw[0]); + audvdbg(" Sample width: %u\n", ac_controls.b[2]); break; case AUDIO_TYPE_PROCESSING: diff --git a/nuttx/drivers/audio/vs1053.c b/nuttx/drivers/audio/vs1053.c index 32d04df15..1ebd79ec5 100644 --- a/nuttx/drivers/audio/vs1053.c +++ b/nuttx/drivers/audio/vs1053.c @@ -568,12 +568,8 @@ static int vs1053_getcaps(FAR struct audio_lowerhalf_s *lower, int type, /* Fill in the caller's structure based on requested info */ - pCaps->ac_format[0] = 0; - pCaps->ac_format[1] = 0; - pCaps->ac_controls[0] = 0; - pCaps->ac_controls[1] = 0; - pCaps->ac_controls[2] = 0; - pCaps->ac_controls[3] = 0; + pCaps->ac_format.hw = 0; + pCaps->ac_controls.w = 0; switch (pCaps->ac_type) { @@ -592,7 +588,7 @@ static int vs1053_getcaps(FAR struct audio_lowerhalf_s *lower, int type, case AUDIO_TYPE_QUERY: /* The input formats we can decode / accept */ - *((uint16_t *) &pCaps->ac_format[0]) = 0 + pCaps->ac_format.hw = 0 #ifdef CONFIG_AUDIO_FORMAT_AC3 | (1 << (AUDIO_FMT_AC3 - 1)) #endif @@ -615,7 +611,7 @@ static int vs1053_getcaps(FAR struct audio_lowerhalf_s *lower, int type, /* The types of audio units we implement */ - pCaps->ac_controls[0] = AUDIO_TYPE_OUTPUT | AUDIO_TYPE_FEATURE | + pCaps->ac_controls.b[0] = AUDIO_TYPE_OUTPUT | AUDIO_TYPE_FEATURE | AUDIO_TYPE_PROCESSING; break; @@ -626,13 +622,13 @@ static int vs1053_getcaps(FAR struct audio_lowerhalf_s *lower, int type, case AUDIO_FMT_MIDI: /* We only support Format 0 */ - pCaps->ac_controls[0] = AUDIO_SUBFMT_MIDI_0; - pCaps->ac_controls[1] = AUDIO_SUBFMT_END; + pCaps->ac_controls.b[0] = AUDIO_SUBFMT_MIDI_0; + pCaps->ac_controls.b[1] = AUDIO_SUBFMT_END; break; #endif default: - pCaps->ac_controls[0] = AUDIO_SUBFMT_END; + pCaps->ac_controls.b[0] = AUDIO_SUBFMT_END; break; } @@ -650,7 +646,7 @@ static int vs1053_getcaps(FAR struct audio_lowerhalf_s *lower, int type, /* Report the Sample rates we support */ - pCaps->ac_controls[0] = AUDIO_SAMP_RATE_8K | AUDIO_SAMP_RATE_11K | + pCaps->ac_controls.b[0] = AUDIO_SAMP_RATE_8K | AUDIO_SAMP_RATE_11K | AUDIO_SAMP_RATE_16K | AUDIO_SAMP_RATE_22K | AUDIO_SAMP_RATE_32K | AUDIO_SAMP_RATE_44K | AUDIO_SAMP_RATE_48K; @@ -686,8 +682,8 @@ static int vs1053_getcaps(FAR struct audio_lowerhalf_s *lower, int type, { /* Fill in the ac_controls section with the Feature Units we have */ - pCaps->ac_controls[0] = AUDIO_FU_VOLUME | AUDIO_FU_BASS | AUDIO_FU_TREBLE; - pCaps->ac_controls[1] = AUDIO_FU_BALANCE >> 8; + pCaps->ac_controls.b[0] = AUDIO_FU_VOLUME | AUDIO_FU_BASS | AUDIO_FU_TREBLE; + pCaps->ac_controls.b[1] = AUDIO_FU_BALANCE >> 8; } else { @@ -708,14 +704,14 @@ static int vs1053_getcaps(FAR struct audio_lowerhalf_s *lower, int type, /* Provide the type of Processing Units we support */ - pCaps->ac_controls[0] = AUDIO_PU_STEREO_EXTENDER; + pCaps->ac_controls.b[0] = AUDIO_PU_STEREO_EXTENDER; break; case AUDIO_PU_STEREO_EXTENDER: /* Proivde capabilities of our Stereo Extender */ - pCaps->ac_controls[0] = AUDIO_STEXT_ENABLE | AUDIO_STEXT_WIDTH; + pCaps->ac_controls.b[0] = AUDIO_STEXT_ENABLE | AUDIO_STEXT_WIDTH; break; default: @@ -777,13 +773,13 @@ static int vs1053_configure(FAR struct audio_lowerhalf_s *lower, /* Process based on Feature Unit */ - switch (*((uint16_t *) pCaps->ac_format)) + switch (pCaps->ac_format.hw) { #ifndef CONFIG_AUDIO_EXCLUDE_VOLUME case AUDIO_FU_VOLUME: /* Set the volume */ - dev->volume = *((uint16_t *) pCaps->ac_controls); + dev->volume = pCaps->ac_controls.hw[0]); vs1053_setvolume(dev); break; @@ -793,7 +789,7 @@ static int vs1053_configure(FAR struct audio_lowerhalf_s *lower, case AUDIO_FU_BALANCE: /* Set the volume */ - dev->balance = *((uint16_t *) pCaps->ac_controls); + dev->balance = pCaps->ac_controls.hw[0]); vs1053_setvolume(dev); break; @@ -805,7 +801,7 @@ static int vs1053_configure(FAR struct audio_lowerhalf_s *lower, * ac_controls[0] parameter. */ - dev->bass = pCaps->ac_controls[0]; + dev->bass = pCaps->ac_controls.b[0]; if (dev->bass > 100) dev->bass = 100; vs1053_setbass(dev); @@ -814,10 +810,10 @@ static int vs1053_configure(FAR struct audio_lowerhalf_s *lower, case AUDIO_FU_TREBLE: /* Set the treble. The percentage level (0-100) is in the - * ac_controls[0] parameter. + * ac_controls.b[0] parameter. */ - dev->treble = pCaps->ac_controls[0]; + dev->treble = pCaps->ac_controls.b[0]; if (dev->treble > 100) dev->treble = 100; vs1053_setbass(dev); @@ -840,7 +836,7 @@ static int vs1053_configure(FAR struct audio_lowerhalf_s *lower, /* We only support STEREO_EXTENDER */ - if (*((uint16_t *) pCaps->ac_format) == AUDIO_PU_STEREO_EXTENDER) + if (pCaps->ac_format.hw == AUDIO_PU_STEREO_EXTENDER) { } diff --git a/nuttx/drivers/audio/wm8904.c b/nuttx/drivers/audio/wm8904.c index a7bec06be..a1bf4a677 100644 --- a/nuttx/drivers/audio/wm8904.c +++ b/nuttx/drivers/audio/wm8904.c @@ -563,12 +563,9 @@ static int wm8904_getcaps(FAR struct audio_lowerhalf_s *dev, int type, /* Fill in the caller's structure based on requested info */ - caps->ac_format[0] = 0; - caps->ac_format[1] = 0; - caps->ac_controls[0] = 0; - caps->ac_controls[1] = 0; - caps->ac_controls[2] = 0; - caps->ac_controls[3] = 0; + caps->ac_format[0] = 0; + caps->ac_format[1] = 0; + caps->ac_controls.w = 0; switch (caps->ac_type) { @@ -591,7 +588,7 @@ static int wm8904_getcaps(FAR struct audio_lowerhalf_s *dev, int type, /* The types of audio units we implement */ - caps->ac_controls[0] = AUDIO_TYPE_OUTPUT | AUDIO_TYPE_FEATURE | + caps->ac_controls.b[0] = AUDIO_TYPE_OUTPUT | AUDIO_TYPE_FEATURE | AUDIO_TYPE_PROCESSING; break; @@ -599,11 +596,11 @@ static int wm8904_getcaps(FAR struct audio_lowerhalf_s *dev, int type, case AUDIO_FMT_MIDI: /* We only support Format 0 */ - caps->ac_controls[0] = AUDIO_SUBFMT_END; + caps->ac_controls.b[0] = AUDIO_SUBFMT_END; break; default: - caps->ac_controls[0] = AUDIO_SUBFMT_END; + caps->ac_controls.b[0] = AUDIO_SUBFMT_END; break; } @@ -621,7 +618,7 @@ static int wm8904_getcaps(FAR struct audio_lowerhalf_s *dev, int type, /* Report the Sample rates we support */ - caps->ac_controls[0] = AUDIO_SAMP_RATE_8K | AUDIO_SAMP_RATE_11K | + caps->ac_controls.b[0] = AUDIO_SAMP_RATE_8K | AUDIO_SAMP_RATE_11K | AUDIO_SAMP_RATE_16K | AUDIO_SAMP_RATE_22K | AUDIO_SAMP_RATE_32K | AUDIO_SAMP_RATE_44K | AUDIO_SAMP_RATE_48K; @@ -648,8 +645,8 @@ static int wm8904_getcaps(FAR struct audio_lowerhalf_s *dev, int type, { /* Fill in the ac_controls section with the Feature Units we have */ - caps->ac_controls[0] = AUDIO_FU_VOLUME | AUDIO_FU_BASS | AUDIO_FU_TREBLE; - caps->ac_controls[1] = AUDIO_FU_BALANCE >> 8; + caps->ac_controls.b[0] = AUDIO_FU_VOLUME | AUDIO_FU_BASS | AUDIO_FU_TREBLE; + caps->ac_controls.b[1] = AUDIO_FU_BALANCE >> 8; } else { @@ -670,14 +667,14 @@ static int wm8904_getcaps(FAR struct audio_lowerhalf_s *dev, int type, /* Provide the type of Processing Units we support */ - caps->ac_controls[0] = AUDIO_PU_STEREO_EXTENDER; + caps->ac_controls.b[0] = AUDIO_PU_STEREO_EXTENDER; break; case AUDIO_PU_STEREO_EXTENDER: /* Provide capabilities of our Stereo Extender */ - caps->ac_controls[0] = AUDIO_STEXT_ENABLE | AUDIO_STEXT_WIDTH; + caps->ac_controls.b[0] = AUDIO_STEXT_ENABLE | AUDIO_STEXT_WIDTH; break; default: @@ -748,7 +745,7 @@ static int wm8904_configure(FAR struct audio_lowerhalf_s *dev, { /* Set the volume */ - uint16_t volume = *(uint16_t *)caps->ac_controls; + uint16_t volume = caps->ac_controls.hw[0]; audvdbg(" Volume: %d\n", volume); if (volume >= 0 && volume <= 1000) @@ -769,10 +766,10 @@ static int wm8904_configure(FAR struct audio_lowerhalf_s *dev, case AUDIO_FU_BASS: { /* Set the bass. The percentage level (0-100) is in the - * ac_controls[0] parameter. + * ac_controls.b[0] parameter. */ - uint8_t bass = caps->ac_controls[0]; + uint8_t bass = caps->ac_controls.b[0]; audvdbg(" Bass: %d\n", bass); if (bass <= 100) @@ -789,10 +786,10 @@ static int wm8904_configure(FAR struct audio_lowerhalf_s *dev, case AUDIO_FU_TREBLE: { /* Set the treble. The percentage level (0-100) is in the - * ac_controls[0] parameter. + * ac_controls.b[0] parameter. */ - uint8_t treble = caps->ac_controls[0]; + uint8_t treble = caps->ac_controls.b[0]; audvdbg(" Treble: %d\n", treble); if (treble <= 100) @@ -817,8 +814,8 @@ static int wm8904_configure(FAR struct audio_lowerhalf_s *dev, case AUDIO_TYPE_OUTPUT: audvdbg(" AUDIO_TYPE_OUTPUT:\n"); audvdbg(" Number of channels: %u\n", caps->ac_channels); - audvdbg(" Sample rate: %u\n", *(uint16_t*)&ac_controls[0]); - audvdbg(" Sample width: %u\n", ac_controls[2]); + audvdbg(" Sample rate: %u\n", ac_controls.hw[0]); + audvdbg(" Sample width: %u\n", ac_controls.b[2]); #warning Missing logic break; diff --git a/nuttx/include/nuttx/audio/audio.h b/nuttx/include/nuttx/audio/audio.h index 0230437b7..761159d87 100644 --- a/nuttx/include/nuttx/audio/audio.h +++ b/nuttx/include/nuttx/audio/audio.h @@ -300,10 +300,19 @@ struct audio_caps_s uint8_t ac_type; /* Capabilities (device) type */ uint8_t ac_subtype; /* Capabilities sub-type, if needed */ uint8_t ac_channels; /* Number of channels (1, 2, 5, 7) */ - uint8_t ac_format[2]; /* Audio data format(s) for this device */ - uint8_t ac_controls[4]; /* Device specific controls. For AUDIO_DEVICE_QUERY, - * this field reports the device type supported - * by this lower-half driver. */ + + union /* Audio data format(s) for this device */ + { + uint8_t b[2]; + uint16_t hw; + } ac_format; + + union /* Device specific controls. For AUDIO_DEVICE_QUERY, */ + { /* this field reports the device type supported */ + uint8_t b[4]; /* by this lower-half driver. */ + uint16_t hw[2]; + uint32_t w; + } ac_controls; }; struct audio_caps_desc_s -- cgit v1.2.3