Annotation of src/share/man/man3lua/gpio.3lua, Revision 1.4
1.4 ! mbalmer 1: .\" $NetBSD: gpio.3lua,v 1.3 2014/01/06 09:25:08 wiz Exp $
1.1 mbalmer 2: .\"
1.4 ! mbalmer 3: .\" Copyright (c) 2013, 2014 Marc Balmer <mbalmer@NetBSD.org>.
! 4: .\" All rights reserved.
1.1 mbalmer 5: .\"
6: .\" Redistribution and use in source and binary forms, with or without
7: .\" modification, are permitted provided that the following conditions
8: .\" are met:
9: .\" 1. Redistributions of source code must retain the above copyright
10: .\" notice, this list of conditions and the following disclaimer.
11: .\" 2. Redistributions in binary form must reproduce the above copyright
12: .\" notice, this list of conditions and the following disclaimer in the
13: .\" documentation and/or other materials provided with the distribution.
14: .\" 3. Neither the name of the University nor the names of its contributors
15: .\" may be used to endorse or promote products derived from this software
16: .\" without specific prior written permission.
17: .\"
18: .\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
19: .\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
20: .\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
21: .\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
22: .\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
23: .\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
24: .\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
25: .\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
26: .\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
27: .\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
28: .\" SUCH DAMAGE.
29: .\"
30: .\"
1.4 ! mbalmer 31: .Dd Januar 7, 2014
1.1 mbalmer 32: .Dt GPIO 3lua
33: .Os
34: .Sh NAME
35: .Nm gpio
36: .Nd access
37: .Xr gpio 4
38: pins from Lua
39: .Sh SYNOPSIS
1.4 ! mbalmer 40: .Cd "local gpio = require 'gpio'"
1.1 mbalmer 41: .Pp
42: .Bl -tag -width XXXX -compact
43: .It Dv gpiodev = gpio.open(path)
44: .It Dv pins = gpio.info(gpiodev)
45: .It Dv gpio.close(gpiodev)
46: .It Dv gpio.set(gpiodev, pin, flags)
47: .It Dv gpio.unset(gpiodev, pin)
48: .It Dv state = gpio.read(gpiodev, pin)
49: .It Dv oldstate = gpio.write(gpiodev, pin, state)
50: .It Dv gpio.toggle(gpiodev, pin)
51: .It Dv gpio.attach(gpiodev, driver, offset, mask [, flags])
52: .El
53: .Sh DESCRIPTION
54: The
55: .Nm
1.2 mbalmer 56: Lua binding provides access to a
1.1 mbalmer 57: .Xr gpio 4
58: device using the
59: .Xr ioctl 2
60: interface.
61: .Pp
62: .Bl -tag -width XXXX -compact
63: .Pp
64: .It Dv gpiodev = gpio.open(path)
65: Open the gpio device and return an object to access its pins.
66: .Pp
67: .It Dv pins = gpio.info(gpiodev)
68: Returns the number of pins.
69: As with all remaining functions, this can also be called using the :
70: notation, i.e. as
71: .Em gpiodev:info() .
72: .Pp
73: .It Dv gpio.close(gpiodev)
74: Close the gpio device.
75: .Pp
76: .It Dv gpio.set(gpiodev, pin, flags)
77: Set gpio pin flags.
78: Note that the pin number in this and all remaining functions is zero based and
79: not one based, this to avoid confusion with tools like
80: .Xr gpioctl 8
81: which also number pins starting at zero.
82: The following flags are defined:
83: .Pp
84: .Bl -tag -width XXXX -compact
85: .It Dv gpio.PIN_INPUT
86: Pin is an input.
87: .Pp
88: .It Dv gpio.PIN_OUTPUT
89: Pin is an output.
90: .Pp
91: .It Dv gpio.PIN_INOUT
92: Pin is birectional.
93: .Pp
94: .It Dv gpio.PIN_OPENDRAIN
95: Pin is an open-drain output.
96: .Pp
97: .It Dv gpio.PIN_PUSHPULL
98: Pin is a push-pull output.
99: .Pp
100: .It Dv gpio.PIN_TRISTATE
101: Pin is tri-state (output disabled).
102: .Pp
103: .It Dv gpio.PIN_PULLUP
104: Pin has an internal pull-up enabled.
105: .Pp
106: .It Dv gpio.PIN_PULLDOWN
107: Pin has an internal pull-down enabled.
108: .Pp
109: .It Dv gpio.PIN_INVIN
110: Invert input.
111: .Pp
112: .It Dv gpio.PIN_INVOUT
113: Invert output.
114: .Pp
115: .It Dv gpio.PIN_USER
116: Pin accessible by users.
117: .Pp
118: .It Dv gpio.PIN_PULSATE
119: Pulsate pin at a hardware set frequency.
120: .Pp
121: .It Dv gpio.PIN_SET
122: Pin is set.
123: .El
124: .Pp
125: .It Dv gpio.unset(gpiodev, pin)
126: Unset gpio pin.
127: .Pp
128: .It Dv stat = gpio.read(gpiodev, pin)
129: Read the current pin state.
130: .Pp
131: .It Dv oldstate = gpio.write(gpiodev, pin, state)
132: Write the pin state returning the old state.
133: The following states are defined:
134: .Pp
135: .Bl -tag -width XXXX -compact
136: .It Dv gpio.PIN_LOW
137: Pin is in the low state.
138: .Pp
139: .It Dv gpio.PIN_HIGH
140: Pin is in the high state.
141: .El
142: .Pp
143: .It Dv gpio.toggle(gpiodev, pin)
144: Toggle pin state.
145: .Pp
146: .It Dv gpio.attach(gpiodev, driver, offset, mask [, flags])
147: Attach a device driver with offset, mask, and optional flags at a pin.
148: .El
149: .Sh EXAMPLES
150: The following example code opens
151: .Pa /dev/gpio0
152: and prints all pin values:
153: .Bd -literal
154: local gpio = require 'gpio'
155:
156: gpiodev = gpio.open('/dev/gpio0')
157:
158: local npins = gpiodev:info()
159:
160: for n = 1, npins do
161: print('pin ' .. n .. ': ' .. gpiodev:read(n - 1))
162: end
163: .Ed
164: .Sh SEE ALSO
165: .Xr lua 1 ,
166: .Xr luac 1 ,
167: .Xr intro 3lua ,
168: .Xr gpio 4
169: .Sh HISTORY
1.3 wiz 170: A
1.1 mbalmer 171: .Nm
172: manual appeared in
173: .Nx 7.0 .
174: .Sh AUTHORS
175: .An -nosplit
176: The
177: .Nm
178: Lua binding was written by
179: .An Marc Balmer Aq Mt mbalmer@NetBSD.org .
CVSweb <webmaster@jp.NetBSD.org>