5 * Copyright (c) 1999,2000 David A. Schleef <ds@schleef.org>
7 * This file may be freely modified, distributed, and combined with
8 * other software, as long as proper attribution is given in the
12 * Requirements: A board with a digital I/O subdevice. Not just
13 * a 'digital input' or 'digital output' subdevice, but one in
14 * which the channels can be configured between input and output.
18 #include <comedilib.h>
30 int wait1 = usec_to_nsec(0);
31 int wait2 = usec_to_nsec(0);
35 void write_bits(int bits);
38 int main(int argc, char *argv[])
44 parse_options(argc,argv);
46 device=comedi_open(filename);
48 comedi_perror(filename);
54 stype = comedi_get_subdevice_type(device,subdevice);
55 if(stype!=COMEDI_SUBD_DIO){
56 printf("%d is not a digital I/O subdevice\n",subdevice);
60 printf("configuring pin %d for output...\n",chan_dat);
61 ret=comedi_dio_config(device,subdevice,chan_dat,COMEDI_OUTPUT);
63 printf("configuring pin %d for output...\n",chan_clk);
64 ret=comedi_dio_config(device,subdevice,chan_clk,COMEDI_OUTPUT);
75 void write_bits(int bits)
80 int mask = (1<<chan_dat)|(1<<chan_clk);
88 memset(insn,0,sizeof(insn));
90 /* clock low, set data */
91 insn[0].insn = INSN_BITS;
93 insn[0].data = data + 0;
94 insn[0].subdev = subdevice;
97 insn[1].insn = INSN_WAIT;
99 insn[1].data = data + 2;
101 /* clock high, same data */
102 insn[2].insn = INSN_BITS;
104 insn[2].data = data + 4;
105 insn[2].subdev = subdevice;
108 insn[3].insn = INSN_WAIT;
110 insn[3].data = data + 6;
112 /* clock low, same data */
113 insn[4].insn = INSN_BITS;
115 insn[4].data = data + 8;
116 insn[4].subdev = subdevice;
121 //printf("writing %d\n",bit&bits);
124 data[1] = (bits&bit)?(1<<chan_dat):0;
130 data[5] = ((bits&bit)?(1<<chan_dat):0)|(1<<chan_clk);
136 data[9] = (bits&bit)?(1<<chan_dat):0;
138 ret = comedi_do_insnlist(device,&il);
140 // printf("comedi_do_insnlist returned %d\n",ret);