samv7/adc: fix handling of ANIOC_TRIGGER ioctl
ADC peripheral can be configured also for PWM trigger, so the ifdef should depend only on CONFIG_SAMV7_AFEC_SWTRIG. Also handle the situation when ANIOC_TRIGGER is called and the peripheral is not configured for SW trigger (but the other one may be, so config option is set). Trigger values saved to the private structure are also changed to enums for better code clarity. Signed-off-by: Michal Lenc <michallenc@seznam.cz>
This commit is contained in:
parent
2c4fe28d4e
commit
758b3baef0
1 changed files with 26 additions and 12 deletions
|
|
@ -90,6 +90,13 @@
|
|||
* Private Types
|
||||
****************************************************************************/
|
||||
|
||||
enum samv7_afec_triggers
|
||||
{
|
||||
AFEC_TRIGGER_SW = 0,
|
||||
AFEC_TRIGGER_TIMER,
|
||||
AFEC_TRIGGER_PWM
|
||||
};
|
||||
|
||||
struct samv7_dev_s
|
||||
{
|
||||
const struct adc_callback_s *cb; /* Upper driver callback */
|
||||
|
|
@ -186,14 +193,14 @@ static struct samv7_dev_s g_adcpriv0 =
|
|||
.initialized = 0,
|
||||
.resolution = CONFIG_SAMV7_AFEC0_RES,
|
||||
#if defined (CONFIG_SAMV7_AFEC0_PWMTRIG)
|
||||
.trigger = 2,
|
||||
.trigger = AFEC_TRIGGER_PWM,
|
||||
.event_line = CONFIG_SAMV7_AFEC0_PWMEVENT,
|
||||
#elif defined (CONFIG_SAMV7_AFEC0_TIOATRIG)
|
||||
.trigger = 1,
|
||||
.trigger = AFEC_TRIGGER_TIMER,
|
||||
.timer_channel = CONFIG_SAMV7_AFEC0_TIOACHAN,
|
||||
.frequency = CONFIG_SAMV7_AFEC0_TIOAFREQ,
|
||||
#else
|
||||
.trigger = 0,
|
||||
.trigger = AFEC_TRIGGER_SW,
|
||||
#endif
|
||||
.base = SAM_AFEC0_BASE,
|
||||
};
|
||||
|
|
@ -230,14 +237,14 @@ static struct samv7_dev_s g_adcpriv1 =
|
|||
.initialized = 0,
|
||||
.resolution = CONFIG_SAMV7_AFEC1_RES,
|
||||
#if defined (CONFIG_SAMV7_AFEC1_PWMTRIG)
|
||||
.trigger = 2,
|
||||
.trigger = AFEC_TRIGGER_PWM,
|
||||
.event_line = CONFIG_SAMV7_AFEC0_PWMEVENT,
|
||||
#elif defined (CONFIG_SAMV7_AFEC1_TIOATRIG)
|
||||
.trigger = 1,
|
||||
.trigger = AFEC_TRIGGER_TIMER,
|
||||
.timer_channel = CONFIG_SAMV7_AFEC1_TIOACHAN,
|
||||
.frequency = CONFIG_SAMV7_AFEC1_TIOAFREQ,
|
||||
#else
|
||||
.trigger = 0,
|
||||
.trigger = AFEC_TRIGGER_SW,
|
||||
#endif
|
||||
.base = SAM_AFEC1_BASE,
|
||||
};
|
||||
|
|
@ -630,7 +637,7 @@ static int sam_afec_trigger(struct samv7_dev_s *priv)
|
|||
int ret = OK;
|
||||
|
||||
#ifdef CONFIG_SAMV7_AFEC_SWTRIG
|
||||
if (priv->trigger == 0)
|
||||
if (priv->trigger == AFEC_TRIGGER_SW)
|
||||
{
|
||||
ainfo("Setup software trigger\n");
|
||||
|
||||
|
|
@ -643,7 +650,7 @@ static int sam_afec_trigger(struct samv7_dev_s *priv)
|
|||
|
||||
#endif
|
||||
#ifdef CONFIG_SAMV7_AFEC_TIOATRIG
|
||||
if (priv->trigger == 1)
|
||||
if (priv->trigger == AFEC_TRIGGER_TIMER)
|
||||
{
|
||||
ainfo("Setup timer/counter trigger\n");
|
||||
|
||||
|
|
@ -676,7 +683,7 @@ static int sam_afec_trigger(struct samv7_dev_s *priv)
|
|||
|
||||
#endif
|
||||
#ifdef CONFIG_SAMV7_AFEC_PWMTRIG
|
||||
if (priv->trigger == 2)
|
||||
if (priv->trigger == AFEC_TRIGGER_PWM)
|
||||
{
|
||||
regval = afec_getreg(priv, SAM_AFEC_MR_OFFSET);
|
||||
regval &= ~AFEC_MR_TRGSEL_MASK;
|
||||
|
|
@ -755,7 +762,7 @@ static void afec_reset(struct adc_dev_s *dev)
|
|||
#endif
|
||||
|
||||
#ifdef CONFIG_SAMV7_AFEC_TIOATRIG
|
||||
if (priv->trigger == 1)
|
||||
if (priv->trigger == AFEC_TRIGGER_TIMER)
|
||||
{
|
||||
sam_afec_freetimer(priv);
|
||||
}
|
||||
|
|
@ -1026,10 +1033,17 @@ static int afec_ioctl(struct adc_dev_s *dev, int cmd, unsigned long arg)
|
|||
|
||||
switch (cmd)
|
||||
{
|
||||
#ifndef CONFIG_SAMV7_AFEC_TIOATRIG
|
||||
#ifdef CONFIG_SAMV7_AFEC_SWTRIG
|
||||
case ANIOC_TRIGGER:
|
||||
{
|
||||
afec_putreg(priv, SAM_AFEC_CR_OFFSET, AFEC_CR_START);
|
||||
if (priv->trigger == AFEC_TRIGGER_SW)
|
||||
{
|
||||
afec_putreg(priv, SAM_AFEC_CR_OFFSET, AFEC_CR_START);
|
||||
}
|
||||
else
|
||||
{
|
||||
ret = -ENOTTY;
|
||||
}
|
||||
}
|
||||
break;
|
||||
#endif
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue