gpio_helper.c 786 B

12345678910111213141516171819202122232425262728293031323334
  1. /*
  2. * Copyright (c) Siemens AG, 2019-2022
  3. *
  4. * Authors:
  5. * Gao Nian <nian.gao@siemens.com>
  6. * Chao Zeng <chao.zeng@siemens.com>
  7. *
  8. * This file is subject to the terms and conditions of the MIT License. See
  9. * COPYING.MIT file in the top-level directory.
  10. */
  11. #include <stdlib.h>
  12. #include <stdio.h>
  13. #include <gpiod.h>
  14. #include <string.h>
  15. #include "gpio_helper.h"
  16. void gpio_set(const uint8_t *line_name, uint32_t value)
  17. {
  18. struct gpiod_line *line;
  19. line = gpiod_line_find(line_name);
  20. if (!line) {
  21. printf("Unable to find GPIO line %s\n", line_name);
  22. return;
  23. }
  24. if (gpiod_line_request_output(line, "switchserialmode", value) < 0) {
  25. perror("gpiod_line_request_output");
  26. }
  27. gpiod_line_release(line);
  28. gpiod_line_close_chip(line);
  29. }