libgpiod.bmx 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. ' Copyright (c) .NET Foundation and Contributors
  2. ' Copyright (c) 2019 Bruce A Henderson
  3. '
  4. ' All rights reserved.
  5. '
  6. ' Permission is hereby granted, free of charge, to any person obtaining a copy
  7. ' of this software and associated documentation files (the "Software"), to deal
  8. ' in the Software without restriction, including without limitation the rights
  9. ' to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  10. ' copies of the Software, and to permit persons to whom the Software is
  11. ' furnished to do so, subject to the following conditions:
  12. '
  13. ' The above copyright notice and this permission notice shall be included in all
  14. ' copies or substantial portions of the Software.
  15. '
  16. ' THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  17. ' IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  18. ' FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  19. ' AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  20. ' LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  21. ' OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
  22. ' SOFTWARE.
  23. '
  24. SuperStrict
  25. Import "link.bmx"
  26. Import "../gpiodriver.bmx"
  27. Private
  28. Global _libgpiod:Byte Ptr=LoadGpiod()
  29. Function LoadGpiod:Byte Ptr()
  30. Return dlopen_("libgpiod.so", 2)
  31. End Function
  32. Public
  33. Rem
  34. bbdoc: Returns #True if libgpiod is available.
  35. End Rem
  36. Function LibGpiodAvailable:Int()
  37. Return _libgpiod <> Null
  38. End Function
  39. Const GPIOD_LINE_BULK_MAX_LINES:Int = 64
  40. Global gpiod_chip_open:Byte Ptr(path:Byte Ptr)=LinkSymbol(_libgpiod, "gpiod_chip_open")
  41. Global gpiod_chip_open_by_name:Byte Ptr(name:Byte Ptr)=LinkSymbol(_libgpiod, "gpiod_chip_open_by_name")
  42. Global gpiod_chip_open_by_number:Byte Ptr(num:UInt)=LinkSymbol(_libgpiod, "gpiod_chip_open_by_number")
  43. Global gpiod_chip_open_by_label:Byte Ptr(label:Byte Ptr)=LinkSymbol(_libgpiod, "gpiod_chip_open_by_label")
  44. Global gpiod_chip_open_lookup:Byte Ptr(desc:Byte Ptr)=LinkSymbol(_libgpiod, "gpiod_chip_open_lookup")
  45. Global gpiod_chip_close(chip:Byte Ptr)=LinkSymbol(_libgpiod, "gpiod_chip_close")
  46. Global gpiod_chip_name:Byte Ptr(chip:Byte Ptr)=LinkSymbol(_libgpiod, "gpiod_chip_name")
  47. Global gpiod_chip_label:Byte Ptr(chip:Byte Ptr)=LinkSymbol(_libgpiod, "gpiod_chip_label")
  48. Global gpiod_chip_num_lines:UInt(chip:Byte Ptr)=LinkSymbol(_libgpiod, "gpiod_chip_num_lines")
  49. Global gpiod_chip_get_line:Byte Ptr(chip:Byte Ptr, offset:UInt)=LinkSymbol(_libgpiod, "gpiod_chip_get_line")
  50. Global gpiod_chip_get_lines:Int(chip:Byte Ptr, offsets:UInt Ptr, numOffsets:UInt, bulk:Byte Ptr)=LinkSymbol(_libgpiod, "gpiod_chip_get_lines")
  51. Global gpiod_chip_get_all_lines:Int(chip:Byte Ptr, bulk:Byte Ptr)=LinkSymbol(_libgpiod, "gpiod_chip_get_all_lines")
  52. Global gpiod_chip_find_line:Byte Ptr(chip:Byte Ptr, name$z)=LinkSymbol(_libgpiod, "gpiod_chip_find_line")
  53. Global gpiod_line_offset:UInt(line:Byte Ptr)=LinkSymbol(_libgpiod, "gpiod_line_offset")
  54. Global gpiod_line_name:Byte Ptr(line:Byte Ptr)=LinkSymbol(_libgpiod, "gpiod_line_name")
  55. Global gpiod_line_consumer:Byte Ptr(line:Byte Ptr)=LinkSymbol(_libgpiod, "gpiod_line_consumer")
  56. Global gpiod_line_direction:Int(line:Byte Ptr)=LinkSymbol(_libgpiod, "gpiod_line_direction")
  57. Global gpiod_line_active_state:Int(line:Byte Ptr)=LinkSymbol(_libgpiod, "gpiod_line_active_state")
  58. Global gpiod_line_is_used:Int(line:Byte Ptr)=LinkSymbol(_libgpiod, "gpiod_line_is_used")
  59. Global gpiod_line_is_open_drain:Int(line:Byte Ptr)=LinkSymbol(_libgpiod, "gpiod_line_is_open_drain")
  60. Global gpiod_line_is_open_source:Int(line:Byte Ptr)=LinkSymbol(_libgpiod, "gpiod_line_is_open_source")
  61. Global gpiod_line_update:Int(line:Byte Ptr)=LinkSymbol(_libgpiod, "gpiod_line_update")
  62. Global gpiod_line_needs_update:Int(line:Byte Ptr)=LinkSymbol(_libgpiod, "gpiod_line_needs_update")
  63. Global gpiod_line_release(line:Byte Ptr)=LinkSymbol(_libgpiod, "gpiod_line_release")
  64. Global gpiod_line_get_value:Int(line:Byte Ptr)=LinkSymbol(_libgpiod, "gpiod_line_get_value")
  65. Global gpiod_line_is_requested:Int(line:Byte Ptr)=LinkSymbol(_libgpiod, "gpiod_line_is_requested")
  66. Global gpiod_line_set_value:Int(line:Byte Ptr, value:Int)=LinkSymbol(_libgpiod, "gpiod_line_set_value")
  67. Global gpiod_line_request_input:Int(line:Byte Ptr, consumer$z)=LinkSymbol(_libgpiod, "gpiod_line_request_input")
  68. Global gpiod_line_request_output:Int(line:Byte Ptr, consumer$z, defaultValue:Int)=LinkSymbol(_libgpiod, "gpiod_line_request_output")
  69. Global gpiod_line_request_both_edges_events:Int(line:Byte Ptr, consumer$z)=LinkSymbol(_libgpiod, "gpiod_line_request_both_edges_events")
  70. Global gpiod_line_event_wait:Int(line:Byte Ptr, timespec:STimeSpec Var)=LinkSymbol(_libgpiod, "gpiod_line_event_wait")
  71. Global gpiod_line_event_read:Int(line:Byte Ptr, lineEvent:SGpioLineEvent Var)=LinkSymbol(_libgpiod, "gpiod_line_event_read")
  72. Global gpiod_line_is_free:Int(line:Byte Ptr)=LinkSymbol(_libgpiod, "gpiod_line_is_free")
  73. Enum ELineRequestType
  74. GPIOD_LINE_REQUEST_DIRECTION_AS_IS = 1
  75. GPIOD_LINE_REQUEST_DIRECTION_INPUT
  76. GPIOD_LINE_REQUEST_DIRECTION_OUTPUT
  77. GPIOD_LINE_REQUEST_EVENT_FALLING_EDGE
  78. GPIOD_LINE_REQUEST_EVENT_RISING_EDGE
  79. GPIOD_LINE_REQUEST_EVENT_BOTH_EDGES
  80. End Enum
  81. Enum ELineRequestFlags Flags
  82. GPIOD_LINE_REQUEST_FLAG_OPEN_DRAIN = 1 Shl 0
  83. GPIOD_LINE_REQUEST_FLAG_OPEN_SOURCE = 1 Shl 1
  84. GPIOD_LINE_REQUEST_FLAG_ACTIVE_LOW = 1 Shl 2
  85. End Enum
  86. Public
  87. Struct SGpioLineEvent
  88. Field timespec:STimeSpec
  89. Field eventType:Int
  90. Method AsPinEventType:EPinEventTypes()
  91. If eventType = 1 Then
  92. Return EPinEventTypes.Rising
  93. Else
  94. Return EPinEventTypes.Falling
  95. End If
  96. End Method
  97. End Struct