Difference between revisions of "IoTGateway/BSP/Android/Gettingstarted/How to use GPIO for rk"

From ESS-WIKI
Jump to: navigation, search
(Created page with "=== Configuration/Test === ==== Configuration ==== The RK3288 bank/bit notation for GPIOs must be formed as "GPIO<GPIO_bank>_<gpio_bit>"  The num...")
 
Line 11: Line 11:
 
Group GPIO0 only 24 gpios,So each GPIO Num subtracts 8.
 
Group GPIO0 only 24 gpios,So each GPIO Num subtracts 8.
  
gpio_bit : A0~A7 0-7 B0~B7 8-15 C0~C7 16-23 D0~D7 24-31
+
gpio_bit&nbsp;: A0~A7 0-7 B0~B7 8-15 C0~C7 16-23 D0~D7 24-31
  
 
E.g. GPIO2_A4 becomes 60
 
E.g. GPIO2_A4 becomes 60
  
 
+
RSB-4680
 
 
===== RSB-4680 =====
 
  
 
{| style="width:500px" cellspacing="1" cellpadding="1" border="1"
 
{| style="width:500px" cellspacing="1" cellpadding="1" border="1"

Revision as of 03:44, 16 November 2017

Configuration/Test

Configuration

The RK3288 bank/bit notation for GPIOs must be formed as "GPIO<GPIO_bank>_<gpio_bit>" 

The numeric value of GPIO is calculated as follows:

32 x (gpio_bank) + gpio_bit - 8

Group GPIO0 only 24 gpios,So each GPIO Num subtracts 8.

gpio_bit : A0~A7 0-7 B0~B7 8-15 C0~C7 16-23 D0~D7 24-31

E.g. GPIO2_A4 becomes 60

RSB-4680

GPIO Number GPIO formed Numeric Representation
GPIO0 GPIO7_A3
219
GPIO1
GPIO7_A4
220
GPIO2
GPIO7_A5
221
GPIO3
GPIO7_C5
237
GPIO4
GPIO8_A2
250
GPIO5
GPIO8_A3
251
GPIO6
GPIO8_A0
248
GPIO7
GPIO8_A1
249

Test

Export GPIO then you can use control GPIO from userr space through sysfs

Export GPIO 27

# echo 27 > /sys/class/gpio/export

Set GPIO direction to in/out

# echo "out" > /sys/class/gpio/gpio27/direction

Set GPIO value 0/1 if GPIO pin define is output

#  echo 1 > /sys/class/gpio/gpio27/value

Used as IRQ signal

Note:You have to configure GPIO to input

#  echo "rising" > /sys/class/gpio/gpio27/edge
  • rising: Trigger on rising edge
  • falling: Trigger on falling edge
  • both: Trigger on both edges
  • none: Disable interrupt on both edges

Unexport GPIO 27

# echo 27 > /sys/class/gpio/unexport

Test

GPIO 27 and GPIO 29 are taken as an example:

  • Connect GPIO 27 and GPIO 29
  • Export GPIO 27 and GPIO 29
# echo 27 /sys/class/gpio/export
# echo 29 /sys/class/gpio/export
  • Set GPIO 27 to output
# echo "out" > /sys/class/gpio/gpio27/direction
  • Set GPIO 29 to input
# echo "in" > /sys/class/gpio/gpio29/direction
  • Change GPIO 27 to 1 and read GPIO 29 value
# echo 1 > /sys/class/gpio/gpio27/value
# cat /sys/class/gpio/gpio29/value
1
  • Change GPIO 27 to 0 and read GPIO 29 value
# echo 0 > /sys/class/gpio/gpio27/value
# cat /sys/class/gpio/gpio29/value
0