gpio 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  1. .TH GPIO 3
  2. .SH NAME
  3. gpio \- access to Raspberry Pi GPIO pins
  4. .SH SYNOPSIS
  5. .B bind -a #G /dev
  6. .PP
  7. .B /dev/gpio
  8. .fi
  9. .SH DESCRIPTION
  10. .I Gpio
  11. serves a single file that provides access to the GPIO pins on the
  12. Raspberry Pi.
  13. Reads from the file receive a 16-character hexadecimal string
  14. representing a
  15. .B vlong
  16. giving the values of up to 64 GPIO lines.
  17. (The processor on both the first and second generation Pis provides
  18. 54 actual GPIO lines.)
  19. The proper method for sampling GPIO 27 is as follows:
  20. .IP
  21. .B read(gfd, buf, 16);
  22. .br
  23. .B buf[16] = 0;
  24. .br
  25. .B gvals = strtoull(buf, nil, 16);
  26. .br
  27. .B "pin27 = gvals & (1 << 27);"
  28. .PP
  29. Writes to
  30. .B gpio
  31. control the characteristics and output values of GPIO lines.
  32. The exact operation is specified by one of the following commands:
  33. .TP
  34. .BI function " pin f"
  35. Set the function of GPIO
  36. .I pin
  37. to
  38. .I f.
  39. The valid values for
  40. .I f
  41. are:
  42. .BR in ,
  43. .BR out ,
  44. .BR alt0 ,
  45. .BR alt1 ,
  46. .BR alt2 ,
  47. .BR alt3 ,
  48. .BR alt4 ,
  49. .BR atl5 ,
  50. and
  51. .BR pulse .
  52. The functions
  53. .B in
  54. and
  55. .B out
  56. set the specified GPIO line to be a general purpose input
  57. and output, respectively.
  58. The various
  59. .BI alt n
  60. functions are as specified in the Broadcom documentation and
  61. differ on a per-pin basis.
  62. The
  63. .B pulse
  64. function is somewhat specialized.
  65. It causes the pin to be set to an output for
  66. 2μS and then to be set to a input.
  67. With the value of the line set to 0 and a pullup resistor on the
  68. line, this operation provides a short low pulse suitable for bit-banging
  69. a 1-wire interface.
  70. .TP
  71. .BI pullup " pin"
  72. Enables the internal pullup resistor for the specified GPIO pin.
  73. .TP
  74. .BI pulldown " pin"
  75. Enables the internal pulldown resistor for the specified GPIO pin.
  76. .TP
  77. .BI float " pin"
  78. Disables both internal pullup and pulldown resistors for the specified
  79. GPIO pin.
  80. .TP
  81. .BI set " pin value"
  82. For GPIO pins set to the output function, this command sets the output
  83. value for the pin.
  84. The
  85. .I value
  86. should be either 0 or 1.
  87. .SH NOTES
  88. All pin number references are according to the SoC documentation.
  89. These GPIO signal numbers do
  90. .I not
  91. match the pin numbers on the header on the Pi board.
  92. Reads sample the external signal values.
  93. As a result, the values read for output pins might not match
  94. the value written to them if externally they are driven harder
  95. than the SoC drives them.
  96. .SH SOURCE
  97. .B /sys/src/9/bcm/devgpio.c
  98. .br
  99. .B /sys/src/9/bcm/gpio.c