Please enable javascript, or click here to visit my ecommerce web site powered by Shopify.
Jump to: navigation, search

Difference between revisions of "Rock/GPIO"

 
(7 intermediate revisions by 2 users not shown)
Line 1: Line 1:
= GPIO on the extension header =
+
{{rock_header}}
  
 +
Checkout the [[rock/extension_header]] page for gpios on the extension header.
  
 
Below is programming in different languages to bit flipping the GPIO on RR.
 
Below is programming in different languages to bit flipping the GPIO on RR.
  
 
== C ==
 
== C ==
 +
 +
wiringX is a modular approach to several GPIO interfaces. WiringX officially supports radxa rock/pro/lite, please check [[Rock/wiringX]] for how to use it.
 +
 
<syntaxhighlight lang="c" enclose="div">
 
<syntaxhighlight lang="c" enclose="div">
  
Line 44: Line 48:
  
 
== Python ==
 
== Python ==
 +
 +
Python library.
 +
    sudo apt-get install gcc  python-dev
 +
 
<syntaxhighlight lang="python" enclose="div">
 
<syntaxhighlight lang="python" enclose="div">
  
Line 93: Line 101:
 
</syntaxhighlight>
 
</syntaxhighlight>
  
==pin numbers ==
+
==JavaScript (Node.js)==
<syntaxhighlight lang="c" enclose="div">
+
    Follow the directions at https://github.com/jdarling/radxa-nodejs-img
#define      NUM_GROUP 32
+
<syntaxhighlight lang="javascript" enclose="div">
#define      PIN_BASE            160
+
var fs = require('fs');
  
#define RK30_PIN0_PA0 (0*NUM_GROUP + PIN_BASE + 0)
+
// Enable the GPIO 172
#define RK30_PIN0_PA1 (0*NUM_GROUP + PIN_BASE + 1)
+
fs.writeFileSync('/sys/class/gpio/export', 172);
#define RK30_PIN0_PA2 (0*NUM_GROUP + PIN_BASE + 2)
+
#define RK30_PIN0_PA3 (0*NUM_GROUP + PIN_BASE + 3)
+
#define RK30_PIN0_PA4 (0*NUM_GROUP + PIN_BASE + 4)
+
#define RK30_PIN0_PA5 (0*NUM_GROUP + PIN_BASE + 5)
+
#define RK30_PIN0_PA6 (0*NUM_GROUP + PIN_BASE + 6)
+
#define RK30_PIN0_PA7 (0*NUM_GROUP + PIN_BASE + 7)
+
#define RK30_PIN0_PB0 (0*NUM_GROUP + PIN_BASE + 8)
+
#define RK30_PIN0_PB1 (0*NUM_GROUP + PIN_BASE + 9)
+
#define RK30_PIN0_PB2 (0*NUM_GROUP + PIN_BASE + 10)
+
#define RK30_PIN0_PB3 (0*NUM_GROUP + PIN_BASE + 11)
+
#define RK30_PIN0_PB4 (0*NUM_GROUP + PIN_BASE + 12)
+
#define RK30_PIN0_PB5 (0*NUM_GROUP + PIN_BASE + 13)
+
#define RK30_PIN0_PB6 (0*NUM_GROUP + PIN_BASE + 14)
+
#define RK30_PIN0_PB7 (0*NUM_GROUP + PIN_BASE + 15)
+
#define RK30_PIN0_PC0 (0*NUM_GROUP + PIN_BASE + 16)
+
#define RK30_PIN0_PC1 (0*NUM_GROUP + PIN_BASE + 17)
+
#define RK30_PIN0_PC2 (0*NUM_GROUP + PIN_BASE + 18)
+
#define RK30_PIN0_PC3 (0*NUM_GROUP + PIN_BASE + 19)
+
#define RK30_PIN0_PC4 (0*NUM_GROUP + PIN_BASE + 20)
+
#define RK30_PIN0_PC5 (0*NUM_GROUP + PIN_BASE + 21)
+
#define RK30_PIN0_PC6 (0*NUM_GROUP + PIN_BASE + 22)
+
#define RK30_PIN0_PC7 (0*NUM_GROUP + PIN_BASE + 23)
+
#define RK30_PIN0_PD0 (0*NUM_GROUP + PIN_BASE + 24)
+
#define RK30_PIN0_PD1 (0*NUM_GROUP + PIN_BASE + 25)
+
#define RK30_PIN0_PD2 (0*NUM_GROUP + PIN_BASE + 26)
+
#define RK30_PIN0_PD3 (0*NUM_GROUP + PIN_BASE + 27)
+
#define RK30_PIN0_PD4 (0*NUM_GROUP + PIN_BASE + 28)
+
#define RK30_PIN0_PD5 (0*NUM_GROUP + PIN_BASE + 29)
+
#define RK30_PIN0_PD6 (0*NUM_GROUP + PIN_BASE + 30)
+
#define RK30_PIN0_PD7 (0*NUM_GROUP + PIN_BASE + 31)
+
  
#define RK30_PIN1_PA0 (1*NUM_GROUP + PIN_BASE + 0)
+
// Set it to output
#define RK30_PIN1_PA1 (1*NUM_GROUP + PIN_BASE + 1)
+
fs.writeFileSync('/sys/class/gpio/gpio172/direction', 'out');
#define RK30_PIN1_PA2 (1*NUM_GROUP + PIN_BASE + 2)
+
#define RK30_PIN1_PA3 (1*NUM_GROUP + PIN_BASE + 3)
+
#define RK30_PIN1_PA4 (1*NUM_GROUP + PIN_BASE + 4)
+
#define RK30_PIN1_PA5 (1*NUM_GROUP + PIN_BASE + 5)
+
#define RK30_PIN1_PA6 (1*NUM_GROUP + PIN_BASE + 6)
+
#define RK30_PIN1_PA7 (1*NUM_GROUP + PIN_BASE + 7)
+
#define RK30_PIN1_PB0 (1*NUM_GROUP + PIN_BASE + 8)
+
#define RK30_PIN1_PB1 (1*NUM_GROUP + PIN_BASE + 9)
+
#define RK30_PIN1_PB2 (1*NUM_GROUP + PIN_BASE + 10)
+
#define RK30_PIN1_PB3 (1*NUM_GROUP + PIN_BASE + 11)
+
#define RK30_PIN1_PB4 (1*NUM_GROUP + PIN_BASE + 12)
+
#define RK30_PIN1_PB5 (1*NUM_GROUP + PIN_BASE + 13)
+
#define RK30_PIN1_PB6 (1*NUM_GROUP + PIN_BASE + 14)
+
#define RK30_PIN1_PB7 (1*NUM_GROUP + PIN_BASE + 15)
+
#define RK30_PIN1_PC0 (1*NUM_GROUP + PIN_BASE + 16)
+
#define RK30_PIN1_PC1 (1*NUM_GROUP + PIN_BASE + 17)
+
#define RK30_PIN1_PC2 (1*NUM_GROUP + PIN_BASE + 18)
+
#define RK30_PIN1_PC3 (1*NUM_GROUP + PIN_BASE + 19)
+
#define RK30_PIN1_PC4 (1*NUM_GROUP + PIN_BASE + 20)
+
#define RK30_PIN1_PC5 (1*NUM_GROUP + PIN_BASE + 21)
+
#define RK30_PIN1_PC6 (1*NUM_GROUP + PIN_BASE + 22)
+
#define RK30_PIN1_PC7 (1*NUM_GROUP + PIN_BASE + 23)
+
#define RK30_PIN1_PD0 (1*NUM_GROUP + PIN_BASE + 24)
+
#define RK30_PIN1_PD1 (1*NUM_GROUP + PIN_BASE + 25)
+
#define RK30_PIN1_PD2 (1*NUM_GROUP + PIN_BASE + 26)
+
#define RK30_PIN1_PD3 (1*NUM_GROUP + PIN_BASE + 27)
+
#define RK30_PIN1_PD4 (1*NUM_GROUP + PIN_BASE + 28)
+
#define RK30_PIN1_PD5 (1*NUM_GROUP + PIN_BASE + 29)
+
#define RK30_PIN1_PD6 (1*NUM_GROUP + PIN_BASE + 30)
+
#define RK30_PIN1_PD7 (1*NUM_GROUP + PIN_BASE + 31)
+
  
#define RK30_PIN2_PA0 (2*NUM_GROUP + PIN_BASE + 0)
+
// Turn on the LED
#define RK30_PIN2_PA1 (2*NUM_GROUP + PIN_BASE + 1)
+
fs.writeFileSync('/ssy/class/gpio/gpio172/value', 1);
#define RK30_PIN2_PA2 (2*NUM_GROUP + PIN_BASE + 2)
+
#define RK30_PIN2_PA3 (2*NUM_GROUP + PIN_BASE + 3)
+
#define RK30_PIN2_PA4 (2*NUM_GROUP + PIN_BASE + 4)
+
#define RK30_PIN2_PA5 (2*NUM_GROUP + PIN_BASE + 5)
+
#define RK30_PIN2_PA6 (2*NUM_GROUP + PIN_BASE + 6)
+
#define RK30_PIN2_PA7 (2*NUM_GROUP + PIN_BASE + 7)
+
#define RK30_PIN2_PB0 (2*NUM_GROUP + PIN_BASE + 8)
+
#define RK30_PIN2_PB1 (2*NUM_GROUP + PIN_BASE + 9)
+
#define RK30_PIN2_PB2 (2*NUM_GROUP + PIN_BASE + 10)
+
#define RK30_PIN2_PB3 (2*NUM_GROUP + PIN_BASE + 11)
+
#define RK30_PIN2_PB4 (2*NUM_GROUP + PIN_BASE + 12)
+
#define RK30_PIN2_PB5 (2*NUM_GROUP + PIN_BASE + 13)
+
#define RK30_PIN2_PB6 (2*NUM_GROUP + PIN_BASE + 14)
+
#define RK30_PIN2_PB7 (2*NUM_GROUP + PIN_BASE + 15)
+
#define RK30_PIN2_PC0 (2*NUM_GROUP + PIN_BASE + 16)
+
#define RK30_PIN2_PC1 (2*NUM_GROUP + PIN_BASE + 17)
+
#define RK30_PIN2_PC2 (2*NUM_GROUP + PIN_BASE + 18)
+
#define RK30_PIN2_PC3 (2*NUM_GROUP + PIN_BASE + 19)
+
#define RK30_PIN2_PC4 (2*NUM_GROUP + PIN_BASE + 20)
+
#define RK30_PIN2_PC5 (2*NUM_GROUP + PIN_BASE + 21)
+
#define RK30_PIN2_PC6 (2*NUM_GROUP + PIN_BASE + 22)
+
#define RK30_PIN2_PC7 (2*NUM_GROUP + PIN_BASE + 23)
+
#define RK30_PIN2_PD0 (2*NUM_GROUP + PIN_BASE + 24)
+
#define RK30_PIN2_PD1 (2*NUM_GROUP + PIN_BASE + 25)
+
#define RK30_PIN2_PD2 (2*NUM_GROUP + PIN_BASE + 26)
+
#define RK30_PIN2_PD3 (2*NUM_GROUP + PIN_BASE + 27)
+
#define RK30_PIN2_PD4 (2*NUM_GROUP + PIN_BASE + 28)
+
#define RK30_PIN2_PD5 (2*NUM_GROUP + PIN_BASE + 29)
+
#define RK30_PIN2_PD6 (2*NUM_GROUP + PIN_BASE + 30)
+
#define RK30_PIN2_PD7 (2*NUM_GROUP + PIN_BASE + 31)
+
  
#define RK30_PIN3_PA0 (3*NUM_GROUP + PIN_BASE + 0)
+
// Wait 1 second then turn it off
#define RK30_PIN3_PA1 (3*NUM_GROUP + PIN_BASE + 1)
+
setTimeout(function(){
#define RK30_PIN3_PA2 (3*NUM_GROUP + PIN_BASE + 2)
+
  fs.writeFileSync('/ssy/class/gpio/gpio172/value', 0);
#define RK30_PIN3_PA3 (3*NUM_GROUP + PIN_BASE + 3)  
+
}, 1000);
#define RK30_PIN3_PA4 (3*NUM_GROUP + PIN_BASE + 4)  
+
#define RK30_PIN3_PA5 (3*NUM_GROUP + PIN_BASE + 5)
+
#define RK30_PIN3_PA6 (3*NUM_GROUP + PIN_BASE + 6)
+
#define RK30_PIN3_PA7 (3*NUM_GROUP + PIN_BASE + 7)
+
#define RK30_PIN3_PB0 (3*NUM_GROUP + PIN_BASE + 8)
+
#define RK30_PIN3_PB1 (3*NUM_GROUP + PIN_BASE + 9)
+
#define RK30_PIN3_PB2 (3*NUM_GROUP + PIN_BASE + 10)
+
#define RK30_PIN3_PB3 (3*NUM_GROUP + PIN_BASE + 11)
+
#define RK30_PIN3_PB4 (3*NUM_GROUP + PIN_BASE + 12)
+
#define RK30_PIN3_PB5 (3*NUM_GROUP + PIN_BASE + 13)
+
#define RK30_PIN3_PB6 (3*NUM_GROUP + PIN_BASE + 14)
+
#define RK30_PIN3_PB7 (3*NUM_GROUP + PIN_BASE + 15)
+
#define RK30_PIN3_PC0 (3*NUM_GROUP + PIN_BASE + 16)
+
#define RK30_PIN3_PC1 (3*NUM_GROUP + PIN_BASE + 17)
+
#define RK30_PIN3_PC2 (3*NUM_GROUP + PIN_BASE + 18)
+
#define RK30_PIN3_PC3 (3*NUM_GROUP + PIN_BASE + 19)
+
#define RK30_PIN3_PC4 (3*NUM_GROUP + PIN_BASE + 20)
+
#define RK30_PIN3_PC5 (3*NUM_GROUP + PIN_BASE + 21)
+
#define RK30_PIN3_PC6 (3*NUM_GROUP + PIN_BASE + 22)
+
#define RK30_PIN3_PC7 (3*NUM_GROUP + PIN_BASE + 23)
+
#define RK30_PIN3_PD0 (3*NUM_GROUP + PIN_BASE + 24)
+
#define RK30_PIN3_PD1 (3*NUM_GROUP + PIN_BASE + 25)
+
#define RK30_PIN3_PD2 (3*NUM_GROUP + PIN_BASE + 26)
+
#define RK30_PIN3_PD3 (3*NUM_GROUP + PIN_BASE + 27)
+
#define RK30_PIN3_PD4 (3*NUM_GROUP + PIN_BASE + 28)
+
#define RK30_PIN3_PD5 (3*NUM_GROUP + PIN_BASE + 29)
+
#define RK30_PIN3_PD6 (3*NUM_GROUP + PIN_BASE + 30)
+
#define RK30_PIN3_PD7 (3*NUM_GROUP + PIN_BASE + 31)
+
 
</syntaxhighlight>
 
</syntaxhighlight>
 +
    Or better yet, use https://github.com/jdarling/radxa-rock
 +
 +
==pin numbers ==
 +
Pin number for kernel 3.0.36 starts from 160. For kernel version 3.10 and later(device tree based), the pin number starts from 0.
 +
===Kernel 3.0.36===
 +
<pre>
 +
GPIO0_A0 = 160
 +
GPIO0_A1 = 161
 +
GPIO0_A2 = 162
 +
GPIO0_A3 = 163
 +
GPIO0_A4 = 164
 +
GPIO0_A5 = 165
 +
GPIO0_A6 = 166
 +
GPIO0_A7 = 167
 +
GPIO0_B0 = 168
 +
GPIO0_B1 = 169
 +
GPIO0_B2 = 170
 +
GPIO0_B3 = 171
 +
GPIO0_B4 = 172
 +
GPIO0_B5 = 173
 +
GPIO0_B6 = 174
 +
GPIO0_B7 = 175
 +
GPIO0_C0 = 176
 +
GPIO0_C1 = 177
 +
GPIO0_C2 = 178
 +
GPIO0_C3 = 179
 +
GPIO0_C4 = 180
 +
GPIO0_C5 = 181
 +
GPIO0_C6 = 182
 +
GPIO0_C7 = 183
 +
GPIO0_D0 = 184
 +
GPIO0_D1 = 185
 +
GPIO0_D2 = 186
 +
GPIO0_D3 = 187
 +
GPIO0_D4 = 188
 +
GPIO0_D5 = 189
 +
GPIO0_D6 = 190
 +
GPIO0_D7 = 191
 +
GPIO1_A0 = 192
 +
GPIO1_A1 = 193
 +
GPIO1_A2 = 194
 +
GPIO1_A3 = 195
 +
GPIO1_A4 = 196
 +
GPIO1_A5 = 197
 +
GPIO1_A6 = 198
 +
GPIO1_A7 = 199
 +
GPIO1_B0 = 200
 +
GPIO1_B1 = 201
 +
GPIO1_B2 = 202
 +
GPIO1_B3 = 203
 +
GPIO1_B4 = 204
 +
GPIO1_B5 = 205
 +
GPIO1_B6 = 206
 +
GPIO1_B7 = 207
 +
GPIO1_C0 = 208
 +
GPIO1_C1 = 209
 +
GPIO1_C2 = 210
 +
GPIO1_C3 = 211
 +
GPIO1_C4 = 212
 +
GPIO1_C5 = 213
 +
GPIO1_C6 = 214
 +
GPIO1_C7 = 215
 +
GPIO1_D0 = 216
 +
GPIO1_D1 = 217
 +
GPIO1_D2 = 218
 +
GPIO1_D3 = 219
 +
GPIO1_D4 = 220
 +
GPIO1_D5 = 221
 +
GPIO1_D6 = 222
 +
GPIO1_D7 = 223
 +
GPIO2_A0 = 224
 +
GPIO2_A1 = 225
 +
GPIO2_A2 = 226
 +
GPIO2_A3 = 227
 +
GPIO2_A4 = 228
 +
GPIO2_A5 = 229
 +
GPIO2_A6 = 230
 +
GPIO2_A7 = 231
 +
GPIO2_B0 = 232
 +
GPIO2_B1 = 233
 +
GPIO2_B2 = 234
 +
GPIO2_B3 = 235
 +
GPIO2_B4 = 236
 +
GPIO2_B5 = 237
 +
GPIO2_B6 = 238
 +
GPIO2_B7 = 239
 +
GPIO2_C0 = 240
 +
GPIO2_C1 = 241
 +
GPIO2_C2 = 242
 +
GPIO2_C3 = 243
 +
GPIO2_C4 = 244
 +
GPIO2_C5 = 245
 +
GPIO2_C6 = 246
 +
GPIO2_C7 = 247
 +
GPIO2_D0 = 248
 +
GPIO2_D1 = 249
 +
GPIO2_D2 = 250
 +
GPIO2_D3 = 251
 +
GPIO2_D4 = 252
 +
GPIO2_D5 = 253
 +
GPIO2_D6 = 254
 +
GPIO2_D7 = 255
 +
GPIO3_A0 = 256
 +
GPIO3_A1 = 257
 +
GPIO3_A2 = 258
 +
GPIO3_A3 = 259
 +
GPIO3_A4 = 260
 +
GPIO3_A5 = 261
 +
GPIO3_A6 = 262
 +
GPIO3_A7 = 263
 +
GPIO3_B0 = 264
 +
GPIO3_B1 = 265
 +
GPIO3_B2 = 266
 +
GPIO3_B3 = 267
 +
GPIO3_B4 = 268
 +
GPIO3_B5 = 269
 +
GPIO3_B6 = 270
 +
GPIO3_B7 = 271
 +
GPIO3_C0 = 272
 +
GPIO3_C1 = 273
 +
GPIO3_C2 = 274
 +
GPIO3_C3 = 275
 +
GPIO3_C4 = 276
 +
GPIO3_C5 = 277
 +
GPIO3_C6 = 278
 +
GPIO3_C7 = 279
 +
GPIO3_D0 = 280
 +
GPIO3_D1 = 281
 +
GPIO3_D2 = 282
 +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+
GPIO3_D1 = 121
 +
GPIO3_D2 = 122
 +
GPIO3_D3 = 123
 +
GPIO3_D4 = 124
 +
GPIO3_D5 = 125
 +
GPIO3_D6 = 126
 +
GPIO3_D7 = 127
 +
</pre>

Latest revision as of 09:05, 16 June 2015

Checkout the rock/extension_header page for gpios on the extension header.

Below is programming in different languages to bit flipping the GPIO on RR.

C

wiringX is a modular approach to several GPIO interfaces. WiringX officially supports radxa rock/pro/lite, please check Rock/wiringX for how to use it.

#include <stdio.h>

int main()
{
  FILE *fp = fopen("/sys/class/gpio/export", "w");
  if( !fp )
  {
    printf("error open export file");
    return 1;
  }
  fprintf(fp, "%d", 172);
  fclose(fp);

  fp = fopen("/sys/class/gpio/gpio175/direction", "w");

  if( !fp )
  {
    printf("error open export file");
    return 1;
  }
  fprintf(fp, "%s", "out");
  fclose(fp);

  fp = fopen("/sys/class/gpio/gpio175/value", "w");

  if( !fp )
  {
    printf("error open export file");
    return 1;
  }
  fprintf(fp, "%d", 1);
 
}

Python

Python library.

   sudo apt-get install gcc  python-dev
import time

def initpin(pinnum, mode):
  '''
  pinnum: pin number, eg. 172, 175 etc.
  mode: pin mode, valid values: in or out
  '''

  with open('/sys/class/gpio/export', 'w') as f:
    f.write(str(pinnum))

  with open('/sys/class/gpio/gpio' + str(pinnum) + '/direction', 'w') as f:
    f.write(str(mode))

def setpin(pinnum, value):
 
  with open('/sys/class/gpio/gpio' + str(pinnum) + '/value', 'w') as f:
    f.write(str(value))

if __name__ == '__main__':
  initpin(172, 'out')
  while True:
    setpin(172, 0)
    time.sleep(1)
    setpin(172, 1)
    time.sleep(1)

Shell

#!/bin/sh

# enable the gpio 172 -> green led
echo 172 > /sys/class/gpio/export

# set the direction to output
echo "out" > /sys/class/gpio/gpio172/direction
while true;
do
echo 0 > /sys/class/gpio/gpio172/value #led on
sleep 1
echo 1 > /sys/class/gpio/gpio172/value #led off
sleep 1
done

JavaScript (Node.js)

   Follow the directions at https://github.com/jdarling/radxa-nodejs-img
var fs = require('fs');

// Enable the GPIO 172
fs.writeFileSync('/sys/class/gpio/export', 172);

// Set it to output
fs.writeFileSync('/sys/class/gpio/gpio172/direction', 'out');

// Turn on the LED
fs.writeFileSync('/ssy/class/gpio/gpio172/value', 1);

// Wait 1 second then turn it off
setTimeout(function(){
  fs.writeFileSync('/ssy/class/gpio/gpio172/value', 0);
}, 1000);
   Or better yet, use https://github.com/jdarling/radxa-rock

pin numbers

Pin number for kernel 3.0.36 starts from 160. For kernel version 3.10 and later(device tree based), the pin number starts from 0.

Kernel 3.0.36

GPIO0_A0 = 160
GPIO0_A1 = 161
GPIO0_A2 = 162
GPIO0_A3 = 163
GPIO0_A4 = 164
GPIO0_A5 = 165
GPIO0_A6 = 166
GPIO0_A7 = 167
GPIO0_B0 = 168
GPIO0_B1 = 169
GPIO0_B2 = 170
GPIO0_B3 = 171
GPIO0_B4 = 172
GPIO0_B5 = 173
GPIO0_B6 = 174
GPIO0_B7 = 175
GPIO0_C0 = 176
GPIO0_C1 = 177
GPIO0_C2 = 178
GPIO0_C3 = 179
GPIO0_C4 = 180
GPIO0_C5 = 181
GPIO0_C6 = 182
GPIO0_C7 = 183
GPIO0_D0 = 184
GPIO0_D1 = 185
GPIO0_D2 = 186
GPIO0_D3 = 187
GPIO0_D4 = 188
GPIO0_D5 = 189
GPIO0_D6 = 190
GPIO0_D7 = 191
GPIO1_A0 = 192
GPIO1_A1 = 193
GPIO1_A2 = 194
GPIO1_A3 = 195
GPIO1_A4 = 196
GPIO1_A5 = 197
GPIO1_A6 = 198
GPIO1_A7 = 199
GPIO1_B0 = 200
GPIO1_B1 = 201
GPIO1_B2 = 202
GPIO1_B3 = 203
GPIO1_B4 = 204
GPIO1_B5 = 205
GPIO1_B6 = 206
GPIO1_B7 = 207
GPIO1_C0 = 208
GPIO1_C1 = 209
GPIO1_C2 = 210
GPIO1_C3 = 211
GPIO1_C4 = 212
GPIO1_C5 = 213
GPIO1_C6 = 214
GPIO1_C7 = 215
GPIO1_D0 = 216
GPIO1_D1 = 217
GPIO1_D2 = 218
GPIO1_D3 = 219
GPIO1_D4 = 220
GPIO1_D5 = 221
GPIO1_D6 = 222
GPIO1_D7 = 223
GPIO2_A0 = 224
GPIO2_A1 = 225
GPIO2_A2 = 226
GPIO2_A3 = 227
GPIO2_A4 = 228
GPIO2_A5 = 229
GPIO2_A6 = 230
GPIO2_A7 = 231
GPIO2_B0 = 232
GPIO2_B1 = 233
GPIO2_B2 = 234
GPIO2_B3 = 235
GPIO2_B4 = 236
GPIO2_B5 = 237
GPIO2_B6 = 238
GPIO2_B7 = 239
GPIO2_C0 = 240
GPIO2_C1 = 241
GPIO2_C2 = 242
GPIO2_C3 = 243
GPIO2_C4 = 244
GPIO2_C5 = 245
GPIO2_C6 = 246
GPIO2_C7 = 247
GPIO2_D0 = 248
GPIO2_D1 = 249
GPIO2_D2 = 250
GPIO2_D3 = 251
GPIO2_D4 = 252
GPIO2_D5 = 253
GPIO2_D6 = 254
GPIO2_D7 = 255
GPIO3_A0 = 256
GPIO3_A1 = 257
GPIO3_A2 = 258
GPIO3_A3 = 259
GPIO3_A4 = 260
GPIO3_A5 = 261
GPIO3_A6 = 262
GPIO3_A7 = 263
GPIO3_B0 = 264
GPIO3_B1 = 265
GPIO3_B2 = 266
GPIO3_B3 = 267
GPIO3_B4 = 268
GPIO3_B5 = 269
GPIO3_B6 = 270
GPIO3_B7 = 271
GPIO3_C0 = 272
GPIO3_C1 = 273
GPIO3_C2 = 274
GPIO3_C3 = 275
GPIO3_C4 = 276
GPIO3_C5 = 277
GPIO3_C6 = 278
GPIO3_C7 = 279
GPIO3_D0 = 280
GPIO3_D1 = 281
GPIO3_D2 = 282
GPIO3_D3 = 283
GPIO3_D4 = 284
GPIO3_D5 = 285
GPIO3_D6 = 286
GPIO3_D7 = 287

Kernel 3.10 and later

GPIO0_A0 = 0
GPIO0_A1 = 1
GPIO0_A2 = 2
GPIO0_A3 = 3
GPIO0_A4 = 4
GPIO0_A5 = 5
GPIO0_A6 = 6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= 85
GPIO2_C6 = 86
GPIO2_C7 = 87
GPIO2_D0 = 88
GPIO2_D1 = 89
GPIO2_D2 = 90
GPIO2_D3 = 91
GPIO2_D4 = 92
GPIO2_D5 = 93
GPIO2_D6 = 94
GPIO2_D7 = 95
GPIO3_A0 = 96
GPIO3_A1 = 97
GPIO3_A2 = 98
GPIO3_A3 = 99
GPIO3_A4 = 100
GPIO3_A5 = 101
GPIO3_A6 = 102
GPIO3_A7 = 103
GPIO3_B0 = 104
GPIO3_B1 = 105
GPIO3_B2 = 106
GPIO3_B3 = 107
GPIO3_B4 = 108
GPIO3_B5 = 109
GPIO3_B6 = 110
GPIO3_B7 = 111
GPIO3_C0 = 112
GPIO3_C1 = 113
GPIO3_C2 = 114
GPIO3_C3 = 115
GPIO3_C4 = 116
GPIO3_C5 = 117
GPIO3_C6 = 118
GPIO3_C7 = 119
GPIO3_D0 = 120
GPIO3_D1 = 121
GPIO3_D2 = 122
GPIO3_D3 = 123
GPIO3_D4 = 124
GPIO3_D5 = 125
GPIO3_D6 = 126
GPIO3_D7 = 127