Giulio D'Aversa <> [2010-11-14 13:49:50]:
> Im using a ts 7200 I need a example code (C) in order to move the DIO pins.
What do you mean by "move"? If setting/getting their state, it's quite easy in
new kernels, example code for blinking 3 LEDs connected to DIO pins 0-2:
echo 8 > /sys/class/gpio/export
echo 9 > /sys/class/gpio/export
echo 10 > /sys/class/gpio/export
echo out > /sys/class/gpio/gpio8/direction
echo out > /sys/class/gpio/gpio9/direction
echo out > /sys/class/gpio/gpio10/direction
while true; do
echo 1 > /sys/class/gpio/gpio8/value
sleep 1
echo 0 > /sys/class/gpio/gpio8/value
echo 1 > /sys/class/gpio/gpio9/value
sleep 1
echo 0 > /sys/class/gpio/gpio9/value
echo 1 > /sys/class/gpio/gpio10/value
sleep 1
echo 0 > /sys/class/gpio/gpio10/value
done
Example for reading state of 2 buttons connected to DIO pins 3 and 4:
echo 11 > /sys/class/gpio/export
echo 12 > /sys/class/gpio/export
echo in > /sys/class/gpio/gpio11/direction
echo in > /sys/class/gpio/gpio12/direction
echo 1 > /sys/class/gpio/gpio11/active_low
echo 1 > /sys/class/gpio/gpio12/active_low
while true; do
echo "state of button1: `cat /sys/class/gpio/gpio11/value`"
echo "state of button2: `cat /sys/class/gpio/gpio12/value`"
sleep 1
done
No C code necessary at all. If you want some more standard interface to the
buttons, you can take a look at kernel patch for GPIO keys[1] for Linux input
event interface(using the same DIO pins 3,4 as above) and then you can read
the state of the buttons by simply reading one /dev/input/event0 interface,
using for example evtest[2] or my test code in Lua scripting language:
local input_event_size = 16 -- sizeof(struct input_event)
function log(...)
io.stdout:write(string.format(...), '\n')
end
function tohex(s)
return s:gsub(".", function (x) return string.format("%02x ",
x:byte()) end)
end
function u16(v)
local v1 = v:sub(1, 1):byte()
local v2 = v:sub(2):byte()
return ((v1 & 0x0f) << 8) | v2
end
function event_to_key(e)
local EV_KEY = 1
local keys = {
[103] = 'key_up',
[108] = 'key_down',
}
local state = {
[0] = 'release',
[1] = 'press',
}
local type = u16(e:sub(8, 9))
local code = u16(e:sub(10, 11))
local value = e:sub(13, 14):byte()
if type == EV_KEY then
if keys[code] then
if state[value] then
return keys[code], state[value]
else
return keys[code], 'unknown'
end
end
end
return nil, nil
end
function test()
local f = io.open("/dev/input/event0", "r")
if not f then
log("open error\n")
return
end
while true do
local d = f:read(input_event_size)
local type = u16(d:sub(8, 9))
local code = u16(d:sub(10, 11))
local value = d:sub(13, 14):byte()
-- log(string.format("type: '%d' code: '%d' value:
'%d'\n", type, code, value))
local key, state = event_to_key(d)
if key then
log('key: %s, state: %s', key, state)
end
end
end
test()
-- ynezz
1.
https://github.com/ynezz/linux-2.6/commit/e58130845348ec896ab6331cae9b5bc7e474dd26
2. http://www.koders.com/c/fidB6AFFE7B3519E85CC2CAE5DE9E4FC206EE00228C.aspx
------------------------------------
Yahoo! Groups Links
<*> To visit your group on the web, go to:
http://groups.yahoo.com/group/ts-7000/
<*> Your email settings:
Individual Email | Traditional
<*> To change settings online go to:
http://groups.yahoo.com/group/ts-7000/join
(Yahoo! ID required)
<*> To change settings via email:
<*> To unsubscribe from this group, send an email to:
<*> Your use of Yahoo! Groups is subject to:
http://docs.yahoo.com/info/terms/
|