Lines Matching +full:int +full:- +full:pin
6 * SPDX-License-Identifier: Apache-2.0
20 #define NGPIOS_UNKNOWN -1
23 /* Pin syntax maximum length */
38 gpio_pin_t pin; member
41 * Find idx-th pin reference from the set of non reserved
42 * pin numbers and provided line names.
50 gpio_pin_t pin; in port_pin_get() local
53 entry->handler = NULL; in port_pin_get()
55 /* Find allowed numeric pin reference */ in port_pin_get()
56 for (pin = 0; pin < GPIO_MAX_PINS_PER_PORT; pin++) { in port_pin_get()
57 reserved = ((BIT64(pin) & reserved_mask) != 0); in port_pin_get()
62 idx--; in port_pin_get()
66 if (pin < GPIO_MAX_PINS_PER_PORT) { in port_pin_get()
67 sprintf(pin_num, "%u", pin); in port_pin_get()
68 if ((pin < line_names_len) && (strlen(line_names[pin]) > 0)) { in port_pin_get()
69 /* pin can be specified by line name */ in port_pin_get()
70 name = line_names[pin]; in port_pin_get()
71 for (int i = 0; i < (sizeof(pin_syntax) - 1); i++) { in port_pin_get()
73 * For line-name tab completion to work replace any in port_pin_get()
81 pin_syntax[sizeof(pin_syntax) - 1] = '\0'; in port_pin_get()
82 entry->syntax = pin_syntax; in port_pin_get()
83 entry->help = pin_num; in port_pin_get()
85 /* fallback to pin specified by pin number */ in port_pin_get()
86 entry->syntax = pin_num; in port_pin_get()
87 entry->help = NULL; in port_pin_get()
91 entry->syntax = NULL; in port_pin_get()
92 entry->help = NULL; in port_pin_get()
114 entry->subcmd = NULL; \
155 int line_cmp(const char *input, const char *line_name) in line_cmp()
157 int i = 0; in line_cmp()
163 return (input[i] > line_name[i]) ? 1 : -1; in line_cmp()
171 static int get_gpio_pin(const struct shell *sh, const struct gpio_ctrl *ctrl, char *line_name) in get_gpio_pin()
173 gpio_pin_t pin = PIN_NOT_FOUND; in get_gpio_pin() local
175 int result; in get_gpio_pin()
177 for (i = 0; i < ctrl->ngpios; i++) { in get_gpio_pin()
178 result = line_cmp(line_name, ctrl->line_names[i]); in get_gpio_pin()
180 if ((BIT64(i) & ctrl->reserved_mask) != 0) { in get_gpio_pin()
181 shell_error(sh, "Reserved pin"); in get_gpio_pin()
182 return -EACCES; in get_gpio_pin()
183 } else if (pin == PIN_NOT_FOUND) { in get_gpio_pin()
184 pin = i; in get_gpio_pin()
187 return -EFAULT; in get_gpio_pin()
192 if (pin == PIN_NOT_FOUND) { in get_gpio_pin()
194 return -ENOENT; in get_gpio_pin()
197 return pin; in get_gpio_pin()
200 static int get_sh_gpio(const struct shell *sh, char **argv, struct sh_gpio *gpio) in get_sh_gpio()
203 int ret = 0; in get_sh_gpio()
204 int pin; in get_sh_gpio() local
209 return -EINVAL; in get_sh_gpio()
211 gpio->dev = ctrl->dev; in get_sh_gpio()
212 pin = shell_strtoul(argv[ARGV_PIN], 0, &ret); in get_sh_gpio()
214 pin = get_gpio_pin(sh, ctrl, argv[ARGV_PIN]); in get_sh_gpio()
215 if (pin < 0) { in get_sh_gpio()
216 return pin; in get_sh_gpio()
218 } else if ((BIT64(pin) & ctrl->reserved_mask) != 0) { in get_sh_gpio()
219 shell_error(sh, "Reserved pin"); in get_sh_gpio()
220 return -EACCES; in get_sh_gpio()
222 gpio->pin = pin; in get_sh_gpio()
227 static int cmd_gpio_conf(const struct shell *sh, size_t argc, char **argv, void *data) in cmd_gpio_conf()
232 int ret = 0; in cmd_gpio_conf()
240 for (int i = 0; i < strlen(argv[ARGV_CONF]); i++) { in cmd_gpio_conf()
320 * See include/zephyr/dt-bindings/gpio/ for the in cmd_gpio_conf()
330 ret = gpio_pin_configure(gpio.dev, gpio.pin, flags); in cmd_gpio_conf()
339 static int cmd_gpio_get(const struct shell *sh, size_t argc, char **argv) in cmd_gpio_get()
342 int value; in cmd_gpio_get()
343 int ret; in cmd_gpio_get()
351 value = gpio_pin_get(gpio.dev, gpio.pin); in cmd_gpio_get()
362 static int cmd_gpio_set(const struct shell *sh, size_t argc, char **argv) in cmd_gpio_set()
366 int ret = 0; in cmd_gpio_set()
380 ret = gpio_pin_set(gpio.dev, gpio.pin, value != 0); in cmd_gpio_set()
389 static int cmd_gpio_toggle(const struct shell *sh, size_t argc, char **argv) in cmd_gpio_toggle()
392 int ret = 0; in cmd_gpio_toggle()
400 ret = gpio_pin_toggle(gpio.dev, gpio.pin); in cmd_gpio_toggle()
409 static int cmd_gpio_devices(const struct shell *sh, size_t argc, char **argv) in cmd_gpio_devices()
413 shell_fprintf(sh, SHELL_NORMAL, "%-16s Other names\n", "Device"); in cmd_gpio_devices()
418 shell_fprintf(sh, SHELL_NORMAL, "%-16s", dev->name); in cmd_gpio_devices()
423 if (nl != NULL && nl->num_nodelabels > 0) { in cmd_gpio_devices()
424 for (size_t j = 0; j < nl->num_nodelabels; j++) { in cmd_gpio_devices()
425 const char *nodelabel = nl->nodelabels[j]; in cmd_gpio_devices()
441 static int cmd_gpio_blink(const struct shell *sh, size_t argc, char **argv) in cmd_gpio_blink()
447 int ret; in cmd_gpio_blink()
456 (void)sh->iface->api->read(sh->iface, &data, sizeof(data), &count); in cmd_gpio_blink()
459 (void)sh->iface->api->read(sh->iface, &data, sizeof(data), &count); in cmd_gpio_blink()
463 ret = gpio_pin_toggle(gpio.dev, gpio.pin); in cmd_gpio_blink()
480 entry->syntax = NULL; in device_name_get()
484 entry->syntax = gpio_list[idx].dev->name; in device_name_get()
485 entry->handler = NULL; in device_name_get()
486 entry->help = "Device"; in device_name_get()
487 entry->subcmd = gpio_list[idx].subcmd; in device_name_get()
495 gpio_pin_t pin; member
509 gpio_pin_t pin; in print_gpio_ctrl_info() local
513 shell_print(sh, " ngpios: %u", ctrl->ngpios); in print_gpio_ctrl_info()
514 shell_print(sh, " Reserved pin mask: 0x%08X", ctrl->reserved_mask); in print_gpio_ctrl_info()
518 shell_print(sh, " Reserved Pin Line Name"); in print_gpio_ctrl_info()
519 for (pin = 0; pin < ctrl->ngpios; pin++) { in print_gpio_ctrl_info()
520 reserved = (BIT64(pin) & ctrl->reserved_mask) != 0; in print_gpio_ctrl_info()
521 if (pin < ctrl->line_names_len) { in print_gpio_ctrl_info()
522 line_name = ctrl->line_names[pin]; in print_gpio_ctrl_info()
526 shell_print(sh, " %c %2u %s", reserved ? '*' : ' ', pin, line_name); in print_gpio_ctrl_info()
534 gpio_pin_t pin; in foreach_pin() local
538 for (pin = 0; pin < gpio_list[i].ngpios; pin++) { in foreach_pin()
541 info.reserved = (BIT64(pin) & reserved_mask) != 0; in foreach_pin()
542 info.pin = pin; in foreach_pin()
543 if (pin < gpio_list[i].line_names_len) { in foreach_pin()
544 info.line_name = gpio_list[i].line_names[pin]; in foreach_pin()
553 static int pin_cmp(const struct pin_info *a, const struct pin_info *b) in pin_cmp()
555 int result = strcmp(a->line_name, b->line_name); in pin_cmp()
560 result = strcmp(a->dev->name, b->dev->name); in pin_cmp()
564 result = (int)a->pin - (int)b->pin; in pin_cmp()
572 int result; in pin_get_next()
574 if (data->prev.line_name != NULL) { in pin_get_next()
575 result = pin_cmp(info, &data->prev); in pin_get_next()
580 if (data->next.line_name == NULL) { in pin_get_next()
581 data->next = *info; in pin_get_next()
584 result = pin_cmp(info, &data->next); in pin_get_next()
586 data->next = *info; in pin_get_next()
599 shell_print(data->sh, " %-12s %-8c %-16s %2u", in pin_ordered()
600 data->next.line_name, in pin_ordered()
601 data->next.reserved ? '*' : ' ', in pin_ordered()
602 data->next.dev->name, in pin_ordered()
603 data->next.pin); in pin_ordered()
605 data->prev = data->next; in pin_ordered()
606 data->next.line_name = NULL; in pin_ordered()
615 shell_print(sh, " %-12s %-8s %-16s %-3s", in print_ordered_info()
616 "Line", "Reserved", "Device", "Pin"); in print_ordered_info()
621 static int cmd_gpio_info(const struct shell *sh, size_t argc, char **argv) in cmd_gpio_info()
638 "Configure GPIO pin\n"
639 "Usage: gpio conf <device> <pin> <configuration <i|o>[u|d][h|l][0|1]> [vendor specific]\n"
640 "<i|o> - input|output\n"
641 "[u|d] - pull up|pull down, otherwise open\n"
642 "[h|l] - active high|active low, otherwise defaults to active high\n"
643 "[0|1] - initialise to logic 0|logic 1, otherwise defaults to logic 0\n"
644 "[vendor specific] - configuration flags within the mask 0xFF00\n"
645 " see include/zephyr/dt-bindings/gpio/",
648 "Get GPIO pin value\n"
649 "Usage: gpio get <device> <pin>", cmd_gpio_get, 3, 0),
651 "Set GPIO pin value\n"
652 "Usage: gpio set <device> <pin> <level 0|1>", cmd_gpio_set, 4, 0),
654 "Toggle GPIO pin\n"
655 "Usage: gpio toggle <device> <pin>", cmd_gpio_toggle, 3, 0),
660 "Blink GPIO pin\n"
661 "Usage: gpio blink <device> <pin>", cmd_gpio_blink, 3, 0),