Port of flash_cc2531 to FreeBSD. This is likely more just include a wiringPi compatible library for FreeBSD. Any new files are BSD licensed and NOT GPLv3 license.
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 

103 lines
2.3 KiB

  1. /*-
  2. * Copyright 2020 John-Mark Gurney.
  3. *
  4. * Redistribution and use in source and binary forms, with or without
  5. * modification, are permitted provided that the following conditions
  6. * are met:
  7. * 1. Redistributions of source code must retain the above copyright
  8. * notice, this list of conditions and the following disclaimer.
  9. * 2. Redistributions in binary form must reproduce the above copyright
  10. * notice, this list of conditions and the following disclaimer in the
  11. * documentation and/or other materials provided with the distribution.
  12. *
  13. * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
  14. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  15. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  16. * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
  17. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  18. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  19. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  20. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  21. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  22. * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  23. * SUCH DAMAGE.
  24. *
  25. */
  26. #include <sys/types.h>
  27. #include <libgpio.h>
  28. #include <time.h>
  29. #include <stdint.h>
  30. #include <stdlib.h>
  31. #include <wiringPi.h>
  32. long
  33. micros(void)
  34. {
  35. int64_t i;
  36. struct timespec ts;
  37. clock_gettime(CLOCK_MONOTONIC_PRECISE, &ts);
  38. i = ts.tv_sec * 1000000000 + ts.tv_nsec;
  39. i /= 1000;
  40. return i;
  41. }
  42. static int opened;
  43. static gpio_handle_t gpiohndl;
  44. int
  45. wiringPiSetup(void)
  46. {
  47. if (opened)
  48. return 1;
  49. gpiohndl = gpio_open(0);
  50. opened = 1;
  51. return 1;
  52. }
  53. void
  54. pinMode(int pinnum, enum wp_dir direction)
  55. {
  56. if (direction == INPUT)
  57. gpio_pin_input(gpiohndl, pinnum);
  58. else if (direction == OUTPUT)
  59. gpio_pin_output(gpiohndl, pinnum);
  60. }
  61. enum wp_value
  62. digitalRead(int pinnum)
  63. {
  64. gpio_value_t v;
  65. v = gpio_pin_get(gpiohndl, pinnum);
  66. if (v == GPIO_VALUE_LOW)
  67. return LOW;
  68. else if (v == GPIO_VALUE_HIGH)
  69. return HIGH;
  70. else
  71. abort();
  72. }
  73. void
  74. digitalWrite(int pinnum, enum wp_value value)
  75. {
  76. gpio_value_t v;
  77. if (value == LOW)
  78. v = GPIO_VALUE_LOW;
  79. else if (value == HIGH)
  80. v = GPIO_VALUE_HIGH;
  81. else
  82. abort();
  83. gpio_pin_set(gpiohndl, pinnum, v);
  84. }