White Papers

11
return rc;
}
if ( level )
bmp |= 1 << chip_pin;
else
bmp &= ~(1 << chip_pin);
rc = _smbus_write_word(gc->fd, TCA9555_REG_OUTPUT, bmp);
if ( rc ) {
fprintf(stderr, "%s: failed to access controller\n", __FUNCTION__);
return rc;
}
return 0;
}
int gpio_pin_get_level(gpio_controller *gc, int pin, int *level)
{
int rc, chip_pin;
__u16 bmp;
chip_pin = map_to_chip_pin(pin);
if ( chip_pin < 0 ) {
fprintf(stderr, "%s: pin number %d is invalid\n", __FUNCTION__, pin);
return -EINVAL;
}
// We don't check the pin mode (i.e. input or output) here because the level
// could be read in both input and output mode
rc = _smbus_read_word(gc->fd, TCA9555_REG_INPUT, &bmp);
if ( rc ) {
fprintf(stderr, "%s: failed to access controller\n", __FUNCTION__);
return rc;
}
*level = !!(bmp & (1 << chip_pin));
return 0;
}
int gpio_pin_set_direction(gpio_controller *gc, int pin, int dir)
{
int chip_pin = map_to_chip_pin(pin);
if ( chip_pin < 0 ) {
fprintf(stderr, "%s: pin number %d is invalid\n", __FUNCTION__, pin);
return -EINVAL;
}
// On Embedded PC 3000 system, we do not allow user to change the directions of GPIO pins
return -ENOSYS;
}
int gpio_pin_get_direction(gpio_controller *gc, int pin, int *dir)
{
int chip_pin = map_to_chip_pin(pin);
if ( chip_pin < 0 ) {
fprintf(stderr, "%s: pin number %d is invalid\n", __FUNCTION__, pin);
return -EINVAL;
}
*dir = gc->pins[chip_pin].mode;
return 0;
}