White Papers

11
__FUNCTION__, pin);
return -EINVAL;
}
}
else
return -EINVAL;
gc->pins[pin].mode = dir;
index = pin / 8;
dev_num = sio_devices[index].device_num;
base_port = sio_devices[index].base_port;
enter_extended_function_mode();
lpc_reg_write(0x07, dev_num);
bmp = lpc_reg_read(base_port);
if ( dir == GPIO_MODE_INPUT )
bmp |= (1 << (pin % 8));
else
bmp &= ~(1 << (pin % 8));
lpc_reg_write(base_port, bmp);
leave_extended_function_mode();
return 0;
}
int gpio_pin_get_direction(gpio_controller *gc, int pin, int *dir)
{
VERIFY_PARAMETERS(gc, pin);
*dir = gc->pins[pin].mode;
return 0;
}
int main(int argc, char** argv)
{
int rc, level, dir;
gpio_controller *gc = gpio_initialize();
if ( !gc ) {
fprintf(stderr, "Failed to initialize Embedded Box PC 5000 GPIO controller\n");
return -1;
}
printf("Set level of PIN_GPO0 to 0\n");
rc = gpio_pin_set_level(gc, PIN_GPO0, 0);
if ( rc )
printf("error happened\n");
rc = gpio_pin_get_level(gc, PIN_GPI0, &level);
if ( rc )
printf("error happened\n");
else
printf("Read PIN_GPI0 level = %d\n", level);
printf("Set level of PIN_GPO0 to 1\n");
rc = gpio_pin_set_level(gc, PIN_GPO0, 1);
if ( rc )
printf("error happened\n");
rc = gpio_pin_get_level(gc, PIN_GPI0, &level);