slitaz-arm view rpi/raspicomm @ rev 214
tazbian: typo
author | Pascal Bellard <pascal.bellard@slitaz.org> |
---|---|
date | Thu May 05 17:03:59 2016 +0200 (2016-05-05) |
parents | 1bf7d711c88d |
children |
line source
1 #!/bin/sh
2 #
3 # rapicomm: A tiny utility to play with a RaspiComm board and SliTaz.
4 # It can be used to initialize the board from a cmdline or at boot time.
5 # RaspiComm can also be used to run a testsuite to check the board.
6 # Read the official RaspiComm user manual to find the GPIO pins map.
7 # The utility is compatible with Busybox Ash and should be usable on
8 # any GNU/Linux OS.
9 #
10 # (C) 2014 SliTaz Raspberry Pi - BSD License
11 # AUTHORS: Christophe Lincoln <pankso@slitaz.org>
12 #
13 . /lib/libtaz.sh
14 check_root
16 gpio="/sys/class/gpio"
18 #
19 # TODO: RS-232 serial port + RS-485 motors control
20 #
22 # RTC initialization
23 init_rtc() {
24 i2c="/sys/class/i2c-adapter/i2c-1"
25 new_device="$i2c/new_device"
26 if [ ! -d "$i2c/1-0068" ]; then
27 echo -n "Configuring real time clock..."
28 echo ds1307 0x68 > ${new_device}; status
29 fi
30 hwclock --hctosys
31 }
33 # Usage: read_pin_value pinNB
34 read_pin_value() {
35 local pin="$1"
36 while true; do
37 value=$(cat ${gpio}/gpio${pin}/value)
38 usleep 500000
39 if [ "$value" == "1" ]; then
40 status && break
41 fi
42 done
43 }
45 load_modules() {
46 modprobe i2c-bcm2708
47 modprobe i2c-dev
48 }
50 case "$1" in
51 init)
52 # Initialize all components
53 colorize 35 "Initializing RaspiComm board..."
54 load_modules
56 # Real Time Clock
57 init_rtc
59 # Joystick gpio pins
60 echo -n "Activating the joystick..."
61 for pi in 4 22 23 24 25
62 do
63 echo ${pi} > ${gpio}/export
64 echo in > ${gpio}/gpio${pi}/direction
65 done; status
67 # Output LEDs
68 echo -n "Configuring LEDs..."
69 for pi in 18 27
70 do
71 echo ${pi} > ${gpio}/export
72 echo out > ${gpio}/gpio${pi}/direction
73 done; status ;;
75 init-rtc)
76 # Init only the RTC: boot time alternative to init
77 load_modules
78 init_rtc ;;
80 testsuite)
81 colorize 35 "Testing RaspiComm board..."
83 # Clock
84 echo -n "Hardware clock: "; hwclock -r
86 # LEDs
87 echo -n "Turning on LED1..."
88 echo 1 > ${gpio}/gpio18/value; status
89 sleep 2
90 echo -n "Turning on LED2..."
91 echo 1 > ${gpio}/gpio27/value; status
92 sleep 2
93 echo -n "Turning off LED1..."
94 echo 0 > ${gpio}/gpio18/value; status
95 sleep 2
96 echo -n "Turning off LED2..."
97 echo 0 > ${gpio}/gpio27/value; status
99 # Joystick
100 echo -n "Move joystick left (towards audio) "
101 read_pin_value 24
102 echo -n "Move joystick top (towards usb) "
103 read_pin_value 25 ;;
105 *)
106 echo "Usage: $(basename $0) [init|init-rtc|testsuite]" ;;
108 esac
109 exit 0