static int subcommand_gpio_dir(int argc, const char **argv) { /* > gpio dir $pin $dir(0:input, 1:output) */ uint8_t pin; bool dir; if (argc < 3) { return -1; } pin = (uint8_t)atoi(argv[1]); if (pin >= MAX_PIN_NUMBER) { return -1; } dir = !!atoi(argv[2]); gpio_set_dir(pin, dir); uart_put_line("gpio dir set: pin="); uart_put_char(ascii_num_to_char(pin/10)); uart_put_char(ascii_num_to_char(pin%10)); uart_put_line(" dir="); uart_put_char(ascii_num_to_char(gpio_get_dir(pin))); uart_put_char('\n'); return 0; }
int hwpl_gpio_getattr(int port, void * ctl){ gpio_attr_t * ctlp = (gpio_attr_t*)ctl; //read the direction pin status ctlp->output = gpio_get_dir(port); ctlp->input = ~ctlp->output; return 0; }
static int subcommand_gpio_list(int argc, const char **argv) { /* > gpio list */ uint8_t i; for (i=0; i<MAX_PIN_NUMBER; i++) { uart_put_char(ascii_num_to_char(i/10)); uart_put_char(ascii_num_to_char(i%10)); uart_put_line(": dir="); uart_put_line(gpio_get_dir(i) ? "out" : "in "); uart_put_line(" value="); uart_put_char(ascii_num_to_char(gpio_read(i))); uart_put_char('\n'); } return 0; }