sp339e.c 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  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 "switchserialmode.h"
  16. #include "gpio_helper.h"
  17. static void sp339e_set_mode(uint32_t mode0, uint32_t mode1)
  18. {
  19. gpio_set("UART0-enable", 1);
  20. gpio_set("UART0-mode0", mode0);
  21. gpio_set("UART0-mode1", mode1);
  22. }
  23. static void sp339e_set_termination(uint8_t onoff)
  24. {
  25. gpio_set("UART0-terminate", onoff);
  26. }
  27. static void sp339e_switch_mode(const uint8_t *mode)
  28. {
  29. if (0 == strcasecmp(mode, "rs232"))
  30. {
  31. sp339e_set_mode(1, 0);
  32. }
  33. else if(0 == strcasecmp(mode, "rs485"))
  34. {
  35. sp339e_set_mode(0, 1);
  36. }
  37. else if(0 == strcasecmp(mode, "rs422"))
  38. {
  39. sp339e_set_mode(1, 1);
  40. }
  41. }
  42. transceiver_ops_t sp339e_ops = {
  43. .transceiver_set_termination = sp339e_set_termination,
  44. .transceiver_switch_mode = sp339e_switch_mode,
  45. };