xref: /netbsd-src/share/man/man3lua/gpio.3lua (revision 3feacbccbd4c8b6fd5f19c8e34474c4c3f8923d7)
1.\"	$NetBSD: gpio.3lua,v 1.4 2014/01/07 21:54:17 mbalmer Exp $
2.\"
3.\" Copyright (c) 2013, 2014 Marc Balmer <mbalmer@NetBSD.org>.
4.\" All rights reserved.
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.\"
31.Dd Januar 7, 2014
32.Dt GPIO 3lua
33.Os
34.Sh NAME
35.Nm gpio
36.Nd access
37.Xr gpio 4
38pins from Lua
39.Sh SYNOPSIS
40.Cd "local gpio = require 'gpio'"
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
54The
55.Nm
56Lua binding provides access to a
57.Xr gpio 4
58device using the
59.Xr ioctl 2
60interface.
61.Pp
62.Bl -tag -width XXXX -compact
63.Pp
64.It Dv gpiodev = gpio.open(path)
65Open the gpio device and return an object to access its pins.
66.Pp
67.It Dv pins = gpio.info(gpiodev)
68Returns the number of pins.
69As with all remaining functions, this can also be called using the :
70notation, i.e. as
71.Em gpiodev:info() .
72.Pp
73.It Dv gpio.close(gpiodev)
74Close the gpio device.
75.Pp
76.It Dv gpio.set(gpiodev, pin, flags)
77Set gpio pin flags.
78Note that the pin number in this and all remaining functions is zero based and
79not one based, this to avoid confusion with tools like
80.Xr gpioctl 8
81which also number pins starting at zero.
82The following flags are defined:
83.Pp
84.Bl -tag -width XXXX -compact
85.It Dv gpio.PIN_INPUT
86Pin is an input.
87.Pp
88.It Dv gpio.PIN_OUTPUT
89Pin is an output.
90.Pp
91.It Dv gpio.PIN_INOUT
92Pin is birectional.
93.Pp
94.It Dv gpio.PIN_OPENDRAIN
95Pin is an open-drain output.
96.Pp
97.It Dv gpio.PIN_PUSHPULL
98Pin is a push-pull output.
99.Pp
100.It Dv gpio.PIN_TRISTATE
101Pin is tri-state (output disabled).
102.Pp
103.It Dv gpio.PIN_PULLUP
104Pin has an internal pull-up enabled.
105.Pp
106.It Dv gpio.PIN_PULLDOWN
107Pin has an internal pull-down enabled.
108.Pp
109.It Dv gpio.PIN_INVIN
110Invert input.
111.Pp
112.It Dv gpio.PIN_INVOUT
113Invert output.
114.Pp
115.It Dv gpio.PIN_USER
116Pin accessible by users.
117.Pp
118.It Dv gpio.PIN_PULSATE
119Pulsate pin at a hardware set frequency.
120.Pp
121.It Dv gpio.PIN_SET
122Pin is set.
123.El
124.Pp
125.It Dv gpio.unset(gpiodev, pin)
126Unset gpio pin.
127.Pp
128.It Dv stat = gpio.read(gpiodev, pin)
129Read the current pin state.
130.Pp
131.It Dv oldstate = gpio.write(gpiodev, pin, state)
132Write the pin state returning the old state.
133The following states are defined:
134.Pp
135.Bl -tag -width XXXX -compact
136.It Dv gpio.PIN_LOW
137Pin is in the low state.
138.Pp
139.It Dv gpio.PIN_HIGH
140Pin is in the high state.
141.El
142.Pp
143.It Dv gpio.toggle(gpiodev, pin)
144Toggle pin state.
145.Pp
146.It Dv gpio.attach(gpiodev, driver, offset, mask [, flags])
147Attach a device driver with offset, mask, and optional flags at a pin.
148.El
149.Sh EXAMPLES
150The following example code opens
151.Pa /dev/gpio0
152and prints all pin values:
153.Bd -literal
154local gpio = require 'gpio'
155
156gpiodev = gpio.open('/dev/gpio0')
157
158local npins = gpiodev:info()
159
160for n = 1, npins do
161	print('pin ' .. n .. ': ' .. gpiodev:read(n - 1))
162end
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
170A
171.Nm
172manual appeared in
173.Nx 7.0 .
174.Sh AUTHORS
175.An -nosplit
176The
177.Nm
178Lua binding was written by
179.An Marc Balmer Aq Mt mbalmer@NetBSD.org .
180