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

Difference between revisions of "Rock/wiringX"

Line 6: Line 6:
 
MIPS CI20 Creator. For Radxa Rock(pro/lite), wiringX provides interfaces for GPIO, I2C, SPI and ISR. You can easily use these function on Rock through wiringX.
 
MIPS CI20 Creator. For Radxa Rock(pro/lite), wiringX provides interfaces for GPIO, I2C, SPI and ISR. You can easily use these function on Rock through wiringX.
  
Firstly, you can get wiringX from [https://github.com/wiringX/wiringX github]:
+
Firstly, get wiringX from [https://github.com/wiringX/wiringX github]:
 
     '''git clone https://github.com/wiringX/wiringX.git'''
 
     '''git clone https://github.com/wiringX/wiringX.git'''
 
     '''cd wiringX'''
 
     '''cd wiringX'''
Line 15: Line 15:
 
Then, install wiringX follow the way on [https://github.com/wiringX/wiringX github].  
 
Then, install wiringX follow the way on [https://github.com/wiringX/wiringX github].  
  
When you compile you source code, add the static lib like:
+
When compile your source code, add the static lib like:
 
     '''gcc -o test test.c /usr/local/lib/libwiringX.a'''
 
     '''gcc -o test test.c /usr/local/lib/libwiringX.a'''
 
     '''./test'''
 
     '''./test'''
Line 21: Line 21:
  
 
== Pin Number Defined in WiringX==
 
== Pin Number Defined in WiringX==
You can find pin numbers for Radxa Rock(pro/lite) [http://radxa.com/Rock/extension_header here]. However, only those pins that can be used as GPIO are valid in wiringX. Thus, for J8, totally 21 pins can be used (number defined as 0-20) and for J12/15, 8 pins can be used (number 25-32). Besides, 3 onboard LEDs can be used on pin number 33-35.
+
You can find pin numbers for Radxa Rock(pro/lite) [http://radxa.com/Rock/extension_header here]. However, only pins can be used as GPIO are valid in wiringX. Thus, for J8, totally 21 pins can be used (number defined as 0-20) and for J12/15, 8 pins can be used (number 25-32). Besides, 3 onboard LEDs can be used, (number 33-35).
 
== GPIO ==
 
== GPIO ==
WiringX provide digitalread and digitalwrite to a pin, after you set it as input/output using pinMode:
+
WiringX provide digitalread and digitalwrite, after you set it as input/output using pinMode:
'''wiringXSetup();'''
+
    '''wiringXSetup();'''
'''pinMode(0, OUTPUT);'''
+
    '''pinMode(0, OUTPUT);'''
'''digitalWrite(0, HIGH);'''
+
    '''digitalWrite(0, HIGH);'''
 
+
 
+
  
 +
Theoretically, all pins can be used as GPIO. However, some multiplexed pins can't be used (pin number defined in extension header): J8: 11-16, 20, 22, 24, 26-28, 31-32; J12/15: 33-38. These pins can only be used as PWM, UART or SPI, not for GPIO.
  
 
== I2C ==
 
== I2C ==
 
+
I2C0 is connected to pin 31, 32 on J8, it can be simply used like:
 +
    '''#define I2C_ADDR        0x04 '''
 +
    '''fd_i2c = wiringXI2CSetup(I2C_ADDR)'''
 +
    '''data=wiringXI2CRead(fd_i2c);'''
 +
    '''wiringXI2CWrite(fd_i2c, data);'''
 
== SPI ==
 
== SPI ==
 
+
SPI0 and SPI1 are connected to J12/15, J8 respectively. It can be used like:
 +
    '''#define SPI_CHAN 0'''
 +
    '''#define SPI_SPEED 250000'''
 +
    '''wiringXSetup();'''
 +
    '''fd_spi = wiringXSPISetup(SPI_CHAN, SPI_SPEED);'''
 +
    '''wiringXSPIDataRW(SPI_CHAN, &spi_data, 1);'''
 
== ISR ==
 
== ISR ==
 +
For RK3188, Port A can be configured as interrupt. It can be used like:
 +
    '''pthread_t pth;'''
 +
    '''wiringXSetup();'''
 +
    '''wiringXISR(1, INT_EDGE_RISING);'''
 +
    '''pthread_create(&pth, NULL, interrupt, NULL);'''
 +
This will creat a thread "interrupt" to handle:
 +
    '''void *interrupt(void *param) {'''
 +
    ''' while(1) {'''
 +
    ''' if(waitForInterrupt(1, 1000) > 0)'''
 +
    ''' printf("interrupt\n");'''
 +
    ''' else'''
 +
    ''' printf("timeout\n");'''
 +
    ''' }'''
 +
    '''}'''
 +
It should take note that, for a linux kernel version below  3.12, interrupt only support INT_EDGE_RISING or INT_EDGE_FALLING, not for INT_EDGE_BOTH.

Revision as of 04:19, 9 June 2015

WiringX is a modular approach to several GPIO interfaces. Till now, it supports five platforms: Raspberry Pi, Hummingboard, BananaPi, Radxa Rock and MIPS CI20 Creator. For Radxa Rock(pro/lite), wiringX provides interfaces for GPIO, I2C, SPI and ISR. You can easily use these function on Rock through wiringX.

Firstly, get wiringX from github:

   git clone https://github.com/wiringX/wiringX.git
   cd wiringX

or

   wget https://github.com/wiringX/wiringX/archive/master.zip
   unzip master.zip
   cd  wiringX-master

Then, install wiringX follow the way on github.

When compile your source code, add the static lib like:

   gcc -o test test.c /usr/local/lib/libwiringX.a
   ./test

WiringX is running on your board!

Pin Number Defined in WiringX

You can find pin numbers for Radxa Rock(pro/lite) here. However, only pins can be used as GPIO are valid in wiringX. Thus, for J8, totally 21 pins can be used (number defined as 0-20) and for J12/15, 8 pins can be used (number 25-32). Besides, 3 onboard LEDs can be used, (number 33-35).

GPIO

WiringX provide digitalread and digitalwrite, after you set it as input/output using pinMode:

   wiringXSetup();
   pinMode(0, OUTPUT);
   digitalWrite(0, HIGH);

Theoretically, all pins can be used as GPIO. However, some multiplexed pins can't be used (pin number defined in extension header): J8: 11-16, 20, 22, 24, 26-28, 31-32; J12/15: 33-38. These pins can only be used as PWM, UART or SPI, not for GPIO.

I2C

I2C0 is connected to pin 31, 32 on J8, it can be simply used like:

   #define I2C_ADDR        0x04 
   fd_i2c = wiringXI2CSetup(I2C_ADDR)
   data=wiringXI2CRead(fd_i2c);
   wiringXI2CWrite(fd_i2c, data);

SPI

SPI0 and SPI1 are connected to J12/15, J8 respectively. It can be used like:

   #define SPI_CHAN	0
   #define SPI_SPEED	250000
   wiringXSetup();
   fd_spi = wiringXSPISetup(SPI_CHAN, SPI_SPEED);
   wiringXSPIDataRW(SPI_CHAN, &spi_data, 1);

ISR

For RK3188, Port A can be configured as interrupt. It can be used like:

   pthread_t pth;
   wiringXSetup();
   wiringXISR(1, INT_EDGE_RISING);
   pthread_create(&pth, NULL, interrupt, NULL);

This will creat a thread "interrupt" to handle:

   void *interrupt(void *param) {
   	while(1) {
   		if(waitForInterrupt(1, 1000) > 0)
   			printf("interrupt\n");
   		else
   			printf("timeout\n");
   	}
   }

It should take note that, for a linux kernel version below 3.12, interrupt only support INT_EDGE_RISING or INT_EDGE_FALLING, not for INT_EDGE_BOTH.