Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

adc: add ioctl command to get the number of configured channels #4231

Merged
merged 1 commit into from
Jul 27, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
8 changes: 8 additions & 0 deletions arch/arm/src/cxd56xx/cxd56_adc.c
Original file line number Diff line number Diff line change
Expand Up @@ -929,6 +929,14 @@ static int cxd56_adc_ioctl(FAR struct file *filep, int cmd,
}
break;

case ANIOC_GET_NCHANNELS:
{
/* Return the number of configured channels */

ret = 1;
}
break;

default:
{
if (adc_validcheck(cmd))
Expand Down
24 changes: 23 additions & 1 deletion arch/arm/src/efm32/efm32_adc.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@
#include <nuttx/irq.h>
#include <nuttx/arch.h>
#include <nuttx/analog/adc.h>
#include <nuttx/analog/ioctl.h>

#include "arm_internal.h"
#include "arm_arch.h"
Expand Down Expand Up @@ -1174,7 +1175,28 @@ static void adc_rxint(FAR struct adc_dev_s *dev, bool enable)

static int adc_ioctl(FAR struct adc_dev_s *dev, int cmd, unsigned long arg)
{
return -ENOTTY;
FAR struct efm32_dev_s *priv = (FAR struct efm32_dev_s *)dev->ad_priv;
int ret = -ENOTTY;

switch (cmd)
{
case ANIOC_GET_NCHANNELS:
{
/* Return the number of configured channels */

ret = priv->nchannels;
}
break;

default:
{
aerr("ERROR: Unknown cmd: %d\n", cmd);
ret = -ENOTTY;
}
break;
}

return ret;
}

/****************************************************************************
Expand Down
26 changes: 23 additions & 3 deletions arch/arm/src/imxrt/imxrt_adc.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
#include <nuttx/irq.h>
#include <nuttx/arch.h>
#include <nuttx/analog/adc.h>
#include <nuttx/analog/ioctl.h>

#include "arm_internal.h"
#include "arm_arch.h"
Expand Down Expand Up @@ -458,11 +459,30 @@ static void adc_rxint(FAR struct adc_dev_s *dev, bool enable)

static int adc_ioctl(FAR struct adc_dev_s *dev, int cmd, unsigned long arg)
{
/* No ioctl commands supported */

/* TODO: ANIOC_TRIGGER, for SW triggered conversion */

return -ENOTTY;
FAR struct imxrt_dev_s *priv = (FAR struct imxrt_dev_s *)dev->ad_priv;
int ret = -ENOTTY;

switch (cmd)
{
case ANIOC_GET_NCHANNELS:
{
/* Return the number of configured channels */

ret = priv->nchannels;
}
break;

default:
{
aerr("ERROR: Unknown cmd: %d\n", cmd);
ret = -ENOTTY;
}
break;
}

return ret;
}

/****************************************************************************
Expand Down
51 changes: 31 additions & 20 deletions arch/arm/src/lc823450/lc823450_adc.c
Original file line number Diff line number Diff line change
Expand Up @@ -456,35 +456,46 @@ static int lc823450_adc_ioctl(FAR struct adc_dev_s *dev, int cmd,
switch (cmd)
{
case ANIOC_TRIGGER: /* Software trigger */
{
lc823450_adc_standby(0);

lc823450_adc_standby(0);
lc823450_adc_start(priv);

lc823450_adc_start(priv);
/* Get ADC data */

/* Get ADC data */
for (ch = 0; ch < CONFIG_LC823450_ADC_NCHANNELS; ch++)
{
val = getreg32(LC823450_ADC0DT(ch));

for (ch = 0; ch < CONFIG_LC823450_ADC_NCHANNELS; ch++)
{
val = getreg32(LC823450_ADC0DT(ch));
/* Give the ADC data to the ADC driver framework.
* adc_receive accepts 3 parameters:
*
* 1) The first is the ADC device instance for this ADC block.
* 2) The second is the channel number for the data, and
* 3) The third is the converted data for the channel.
*/

/* Give the ADC data to the ADC driver framework.
* adc_receive accepts 3 parameters:
*
* 1) The first is the ADC device instance for this ADC block.
* 2) The second is the channel number for the data, and
* 3) The third is the converted data for the channel.
*/
priv->cb->au_receive(dev, priv->chanlist[ch], val);
DEBUGASSERT(ret == OK);
}

priv->cb->au_receive(dev, priv->chanlist[ch], val);
DEBUGASSERT(ret == OK);
}
lc823450_adc_standby(1);
}
break;

case ANIOC_GET_NCHANNELS:
{
/* Return the number of configured channels */

lc823450_adc_standby(1);
ret = CONFIG_LC823450_ADC_NCHANNELS;
}
break;

default:
ret = -ENOTTY;
break;
default:
{
ret = -ENOTTY;
}
break;
}

lc823450_adc_sem_post(priv);
Expand Down
11 changes: 9 additions & 2 deletions arch/arm/src/nrf52/nrf52_adc.c
Original file line number Diff line number Diff line change
Expand Up @@ -879,16 +879,23 @@ static int nrf52_adc_ioctl(FAR struct adc_dev_s *dev, int cmd,
/* Trigger first sample */

nrf52_adc_putreg(priv, NRF52_SAADC_TASKS_SAMPLE_OFFSET, 1);
}
break;

break;
case ANIOC_GET_NCHANNELS:
{
/* Return the number of configured channels */

ret = priv->chan_len;
}
break;

default:
{
aerr("ERROR: Unknown cmd: %d\n", cmd);
ret = -ENOTTY;
break;
}
break;
}

return ret;
Expand Down
12 changes: 11 additions & 1 deletion arch/arm/src/sama5/sam_adc.c
Original file line number Diff line number Diff line change
Expand Up @@ -1258,10 +1258,20 @@ static int sam_adc_ioctl(struct adc_dev_s *dev, int cmd, unsigned long arg)
break;
#endif

case ANIOC_GET_NCHANNELS:
{
/* Return the number of configured channels */

ret = SAMA5_NCHANNELS;
}
break;

/* Unsupported or invalid command */

default:
ret = -ENOTTY;
{
ret = -ENOTTY;
}
break;
}

Expand Down
67 changes: 42 additions & 25 deletions arch/arm/src/samd2l2/sam_adc.c
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
#include <nuttx/signal.h>
#include <nuttx/fs/fs.h>
#include <nuttx/analog/adc.h>
#include <nuttx/analog/ioctl.h>
#include <nuttx/kmalloc.h>

#include <arch/chip/sam_adc.h>
Expand Down Expand Up @@ -387,35 +388,51 @@ static int sam_adc_ioctl(FAR struct adc_dev_s *dev,
struct sam_adc_param_s *params = (struct sam_adc_param_s *)arg;

switch (cmd)
{
case SAMD_ADC_IOCTL_START:
sam_adc_setup(dev);
sam_adc_rxint(dev, true);
break;

case SAMD_ADC_IOCTL_STOP:
sam_adc_rxint(dev, false);
sam_adc_shutdown(dev);
break;

case SAMD_ADC_IOCTL_SET_PARAMS:
if ((getreg8(SAM_ADC_CTRLA) & ADC_CTRLA_ENABLE) != 0)
{
case SAMD_ADC_IOCTL_START:
{
sam_adc_setup(dev);
sam_adc_rxint(dev, true);
break;
}

case SAMD_ADC_IOCTL_STOP:
{
sam_adc_rxint(dev, false);
sam_adc_shutdown(dev);
break;
}

case SAMD_ADC_IOCTL_SET_PARAMS:
{
ret = -EBUSY;
if ((getreg8(SAM_ADC_CTRLA) & ADC_CTRLA_ENABLE) != 0)
{
ret = -EBUSY;
break;
}

priv->averaging = params->averaging;
priv->prescaler = params->prescaler;
priv->samplen = params->samplen;
break;
}

priv->averaging = params->averaging;
priv->prescaler = params->prescaler;
priv->samplen = params->samplen;
break;

case SAMD_ADC_IOCTL_GET_PARAMS:
params->averaging = priv->averaging;
params->prescaler = priv->prescaler;
params->samplen = priv->samplen;
break;
}
case SAMD_ADC_IOCTL_GET_PARAMS:
{
params->averaging = priv->averaging;
params->prescaler = priv->prescaler;
params->samplen = priv->samplen;
break;
}

case ANIOC_GET_NCHANNELS:
{
/* Return the number of configured channels */

ret = priv->num_channels;
}
break;
}

return ret;
}
Expand Down
8 changes: 8 additions & 0 deletions arch/arm/src/stm32/stm32_adc.c
Original file line number Diff line number Diff line change
Expand Up @@ -3871,6 +3871,14 @@ static int adc_ioctl(FAR struct adc_dev_s *dev, int cmd, unsigned long arg)
break;
}

case ANIOC_GET_NCHANNELS:
{
/* Return the number of configured channels */

ret = priv->rnchannels;
}
break;

case IO_TRIGGER_REG:
{
/* Start regular conversion if regular channels configured */
Expand Down
18 changes: 15 additions & 3 deletions arch/arm/src/stm32/stm32_sdadc.c
Original file line number Diff line number Diff line change
Expand Up @@ -1193,12 +1193,24 @@ static int sdadc_ioctl(FAR struct adc_dev_s *dev, int cmd, unsigned long arg)
switch (cmd)
{
case ANIOC_TRIGGER:
sdadc_startconv(priv, true);
{
sdadc_startconv(priv, true);
}
break;

case ANIOC_GET_NCHANNELS:
{
/* Return the number of configured channels */

ret = priv->cchannels;
}
break;

default:
aerr("ERROR: Unknown cmd: %d\n", cmd);
ret = -ENOTTY;
{
aerr("ERROR: Unknown cmd: %d\n", cmd);
ret = -ENOTTY;
}
break;
}

Expand Down
8 changes: 8 additions & 0 deletions arch/arm/src/stm32f0l0g0/stm32_adc.c
Original file line number Diff line number Diff line change
Expand Up @@ -1960,6 +1960,14 @@ static int adc_ioctl(FAR struct adc_dev_s *dev, int cmd, unsigned long arg)
break;
}

case ANIOC_GET_NCHANNELS:
{
/* Return the number of configured channels */

ret = priv->cr_channels;
}
break;

case IO_TRIGGER_REG:
{
/* Start regular conversion if regular channels configured */
Expand Down
18 changes: 15 additions & 3 deletions arch/arm/src/stm32f7/stm32_adc.c
Original file line number Diff line number Diff line change
Expand Up @@ -1651,12 +1651,24 @@ static int adc_ioctl(FAR struct adc_dev_s *dev, int cmd, unsigned long arg)
switch (cmd)
{
case ANIOC_TRIGGER:
adc_startconv(priv, true);
{
adc_startconv(priv, true);
}
break;

case ANIOC_GET_NCHANNELS:
{
/* Return the number of configured channels */

ret = priv->cchannels;
}
break;

default:
aerr("ERROR: Unknown cmd: %d\n", cmd);
ret = -ENOTTY;
{
aerr("ERROR: Unknown cmd: %d\n", cmd);
ret = -ENOTTY;
}
break;
}

Expand Down
12 changes: 11 additions & 1 deletion arch/arm/src/stm32h7/stm32_adc.c
Original file line number Diff line number Diff line change
Expand Up @@ -1760,7 +1760,17 @@ static int adc_ioctl(FAR struct adc_dev_s *dev, int cmd, unsigned long arg)
switch (cmd)
{
case ANIOC_TRIGGER:
adc_startconv(priv, true);
{
adc_startconv(priv, true);
}
break;

case ANIOC_GET_NCHANNELS:
{
/* Return the number of configured channels */

ret = priv->cchannels;
}
break;

case ANIOC_WDOG_UPPER: /* Set watchdog upper threshold */
Expand Down