Skip to content

Commit

Permalink
Merge pull request #50 from superna9999/local-gpio-yaml-fix
Browse files Browse the repository at this point in the history
local_gpio: simplify yaml description
  • Loading branch information
lumag authored Nov 4, 2023
2 parents 494b048 + e08d14a commit abcf427
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 22 deletions.
30 changes: 15 additions & 15 deletions README
Original file line number Diff line number Diff line change
Expand Up @@ -66,21 +66,21 @@ devices:
console: /dev/serial/by-id/usb-1234-if00-port0
name: GPIO controller board
local_gpio:
- power:
chip: gpiochip0
line: 7
active_low: true
- fastboot_key:
chip: gpiochip0
line: 8
active_low: true
- power_key:
chip: gpiochip0
line: 14
active_low: true
- usb_disconnect:
chip: gpiochip1
line: 4
power:
chip: gpiochip0
line: 7
active_low: true
fastboot_key:
chip: gpiochip0
line: 8
active_low: true
power_key:
chip: gpiochip0
line: 14
active_low: true
usb_disconnect:
chip: gpiochip1
line: 4
fastboot: cacafada
fastboot_set_active: true
fastboot_key_timeout: 2
10 changes: 3 additions & 7 deletions local-gpio.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,16 +54,14 @@ void *local_gpio_parse_options(struct device_parser *dp)
char value[TOKEN_LENGTH];
char key[TOKEN_LENGTH];

device_parser_expect(dp, YAML_SEQUENCE_START_EVENT, NULL, 0);
device_parser_expect(dp, YAML_MAPPING_START_EVENT, NULL, 0);

options = calloc(1, sizeof(*options));

/* Loop over sub-properties */
while (device_parser_accept(dp, YAML_MAPPING_START_EVENT, NULL, 0)) {
while (device_parser_accept(dp, YAML_SCALAR_EVENT, key, TOKEN_LENGTH)) {
int gpio_id;

device_parser_accept(dp, YAML_SCALAR_EVENT, key, TOKEN_LENGTH);

if (!strcmp(key, "power")) {
gpio_id = GPIO_POWER;
} else if (!strcmp(key, "fastboot_key")) {
Expand Down Expand Up @@ -98,11 +96,9 @@ void *local_gpio_parse_options(struct device_parser *dp)
device_parser_expect(dp, YAML_MAPPING_END_EVENT, NULL, 0);

options->gpios[gpio_id].present = true;

device_parser_expect(dp, YAML_MAPPING_END_EVENT, NULL, 0);
}

device_parser_expect(dp, YAML_SEQUENCE_END_EVENT, NULL, 0);
device_parser_expect(dp, YAML_MAPPING_END_EVENT, NULL, 0);

return options;
}
Expand Down

0 comments on commit abcf427

Please sign in to comment.