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