staging: comedi: ni_labpc_common: introduce labpc_ao_write()
Introduce a helper function to write a value to a given DAC channel. Signed-off-by: H Hartley Sweeten <hsweeten@visionengravers.com> Reviewed-by: Ian Abbott <abbotti@mev.co.uk> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
This commit is contained in:
parent
1e3d3a4d1b
commit
8e06519b27
|
@ -918,6 +918,18 @@ static irqreturn_t labpc_interrupt(int irq, void *d)
|
||||||
return IRQ_HANDLED;
|
return IRQ_HANDLED;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void labpc_ao_write(struct comedi_device *dev,
|
||||||
|
struct comedi_subdevice *s,
|
||||||
|
unsigned int chan, unsigned int val)
|
||||||
|
{
|
||||||
|
struct labpc_private *devpriv = dev->private;
|
||||||
|
|
||||||
|
devpriv->write_byte(dev, val & 0xff, DAC_LSB_REG(chan));
|
||||||
|
devpriv->write_byte(dev, (val >> 8) & 0xff, DAC_MSB_REG(chan));
|
||||||
|
|
||||||
|
devpriv->ao_value[chan] = val;
|
||||||
|
}
|
||||||
|
|
||||||
static int labpc_ao_insn_write(struct comedi_device *dev,
|
static int labpc_ao_insn_write(struct comedi_device *dev,
|
||||||
struct comedi_subdevice *s,
|
struct comedi_subdevice *s,
|
||||||
struct comedi_insn *insn,
|
struct comedi_insn *insn,
|
||||||
|
@ -927,7 +939,6 @@ static int labpc_ao_insn_write(struct comedi_device *dev,
|
||||||
struct labpc_private *devpriv = dev->private;
|
struct labpc_private *devpriv = dev->private;
|
||||||
int channel, range;
|
int channel, range;
|
||||||
unsigned long flags;
|
unsigned long flags;
|
||||||
int lsb, msb;
|
|
||||||
|
|
||||||
channel = CR_CHAN(insn->chanspec);
|
channel = CR_CHAN(insn->chanspec);
|
||||||
|
|
||||||
|
@ -950,13 +961,7 @@ static int labpc_ao_insn_write(struct comedi_device *dev,
|
||||||
devpriv->write_byte(dev, devpriv->cmd6, CMD6_REG);
|
devpriv->write_byte(dev, devpriv->cmd6, CMD6_REG);
|
||||||
}
|
}
|
||||||
/* send data */
|
/* send data */
|
||||||
lsb = data[0] & 0xff;
|
labpc_ao_write(dev, s, channel, data[0]);
|
||||||
msb = (data[0] >> 8) & 0xff;
|
|
||||||
devpriv->write_byte(dev, lsb, DAC_LSB_REG(channel));
|
|
||||||
devpriv->write_byte(dev, msb, DAC_MSB_REG(channel));
|
|
||||||
|
|
||||||
/* remember value for readback */
|
|
||||||
devpriv->ao_value[channel] = data[0];
|
|
||||||
|
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
@ -1300,15 +1305,8 @@ int labpc_common_attach(struct comedi_device *dev,
|
||||||
s->insn_write = labpc_ao_insn_write;
|
s->insn_write = labpc_ao_insn_write;
|
||||||
|
|
||||||
/* initialize analog outputs to a known value */
|
/* initialize analog outputs to a known value */
|
||||||
for (i = 0; i < s->n_chan; i++) {
|
for (i = 0; i < s->n_chan; i++)
|
||||||
short lsb, msb;
|
labpc_ao_write(dev, s, i, s->maxdata / 2);
|
||||||
|
|
||||||
devpriv->ao_value[i] = s->maxdata / 2;
|
|
||||||
lsb = devpriv->ao_value[i] & 0xff;
|
|
||||||
msb = (devpriv->ao_value[i] >> 8) & 0xff;
|
|
||||||
devpriv->write_byte(dev, lsb, DAC_LSB_REG(i));
|
|
||||||
devpriv->write_byte(dev, msb, DAC_MSB_REG(i));
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
s->type = COMEDI_SUBD_UNUSED;
|
s->type = COMEDI_SUBD_UNUSED;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue