|
|
|
|
@ -41,6 +41,7 @@ static int get_value(unsigned offset){ |
|
|
|
|
DEBUG_OUT("%s: GET_VALUE of pin%d\n",MOD_NAME,offset); |
|
|
|
|
|
|
|
|
|
if( !is_output(offset) ){ |
|
|
|
|
|
|
|
|
|
if( ftdi_read_pins(&ftdic,&USB_GPIO_PIN) < 0){ |
|
|
|
|
LOG("%s: Unable to read pin%d \n",MOD_NAME,offset); |
|
|
|
|
} |
|
|
|
|
@ -142,7 +143,7 @@ enum cmd_states {CMD_PORT_NUM, CMD_CMD}; |
|
|
|
|
static int cmd_fsm(char c){ |
|
|
|
|
static int state = CMD_PORT_NUM; |
|
|
|
|
static char pin = 0; |
|
|
|
|
int ret; |
|
|
|
|
int val; |
|
|
|
|
switch(state){ |
|
|
|
|
case CMD_PORT_NUM: |
|
|
|
|
pin=c; |
|
|
|
|
@ -165,9 +166,14 @@ static int cmd_fsm(char c){ |
|
|
|
|
set_value((unsigned)pin,0); |
|
|
|
|
return 0; |
|
|
|
|
case CMD_READ: |
|
|
|
|
ret = get_value((unsigned)pin); |
|
|
|
|
DEBUG_OUT("Value of %d is %d\n", pin,ret); |
|
|
|
|
fputc((char)ret,fd); |
|
|
|
|
val = get_value((unsigned)pin); |
|
|
|
|
DEBUG_OUT("Value of %d is %d\n", pin,val); |
|
|
|
|
errno=0; |
|
|
|
|
fputc((char)val,fd); |
|
|
|
|
if( errno ){ |
|
|
|
|
LOG("%s: Error writing to device ernno=%d\n",MOD_NAME,errno ); |
|
|
|
|
} |
|
|
|
|
fflush(fd); |
|
|
|
|
return 0; |
|
|
|
|
} |
|
|
|
|
} |
|
|
|
|
@ -176,7 +182,12 @@ static int cmd_fsm(char c){ |
|
|
|
|
|
|
|
|
|
int main(void){ |
|
|
|
|
int ret=ftdi_chip_init(); |
|
|
|
|
fd=fopen("/dev/usb_gpio","rw"); |
|
|
|
|
errno=0; |
|
|
|
|
fd=fopen("/dev/usb_gpio","r+"); |
|
|
|
|
if(fd==(void*)0){ |
|
|
|
|
LOG("%s: Could not open device errno=%d\n",MOD_NAME,errno ); |
|
|
|
|
return errno; |
|
|
|
|
} |
|
|
|
|
if(ret!=0){ |
|
|
|
|
return ret; |
|
|
|
|
} |
|
|
|
|
|