Add gpio_setdirection

added error checks.