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

Difference between revisions of "Rockpi4/android-mraa"

Line 56: Line 56:
  
 
==== Gpio ====
 
==== Gpio ====
{| class="wikitable"
+
{| class="wikitable" style="width:100%;"
 
|-
 
|-
| width="200px" | Methods
+
! scope="col" width="30%" height="60px" | Methods
| width="150px" | Parameter
+
! scope="col" width="15%" | Parameter
| width="600px" | Description
+
! scope="col" width="40%" | Description
| width="190px" | Return  
+
! scope="col" width="15%" | Return  
 
|-
 
|-
| dir(Dir dir)    || Dir    || Set input/output                || Result
+
| height="45px" | dir(Dir dir)    || Dir    || Set input/output                || Result
 
|-
 
|-
| readDir()      || void  || Read input/output dir            || Dir
+
| height="45px" | readDir()      || void  || Read input/output dir            || Dir
 
|-
 
|-
| mode(Mode mode) || Mode  || Set  STRONG/PULLUP/PULLDOWN/HIZ  || Result
+
| height="45px" | mode(Mode mode) || Mode  || Set  STRONG/PULLUP/PULLDOWN/HIZ  || Result
 
|-
 
|-
| read()          || void  || Set input and read gpio value    || 0/1
+
| height="45px" | read()          || void  || Set input and read gpio value    || 0/1
 
|-
 
|-
| write(int v)    || 0/1    || Set output value                || Result
+
| height="45px" | write(int v)    || 0/1    || Set output value                || Result
 
|-
 
|-
| unexport()      || void  || Unexport gpio in /dev/class/gpio || Result
+
| height="45px" | unexport()      || void  || Unexport gpio in /dev/class/gpio || Result
 
|}
 
|}
  
Line 90: Line 90:
  
 
==== Aio ====
 
==== Aio ====
{| class="wikitable"
+
{| class="wikitable" style="width:100%;"
 
|-
 
|-
| width="200px" | Methods
+
! scope="col" width="30%" height="60px" | Methods
| width="150px" | Parameter
+
! scope="col" width="15%" | Parameter
| width="600px" | Description
+
! scope="col" width="40%" | Description
| width="190px" | Return  
+
! scope="col" width="15%" | Return  
 
|-
 
|-
| read()        || void  || Read value. Default will shift the raw value up/down to a 10 bit.  || long
+
| height="45px" | read()        || void  || Read value. Default will shift the raw value up/down to a 10 bit.  || long
 
|-
 
|-
| readFloat()  || void  || Read value and return it as a normalized float.                    || 0.0 - 1.0
+
| height="45px" | readFloat()  || void  || Read value and return it as a normalized float.                    || 0.0 - 1.0
 
|-
 
|-
| setBit(int b) || int    || Set the bit value which will shift the raw reading from the ADC to. || Result
+
| height="45px" | setBit(int b) || int    || Set the bit value which will shift the raw reading from the ADC to. || Result
 
|-
 
|-
| getBit()      || void  || Gets the bit value mraa is shifting the analog read to.            || int
+
| height="45px" | getBit()      || void  || Gets the bit value mraa is shifting the analog read to.            || int
 
|}
 
|}
  
 
==== I2C ====
 
==== I2C ====
{| class="wikitable"
+
{| class="wikitable" style="width:100%;"
 
|-
 
|-
| width="280px" | Methods
+
! scope="col" width="30%" height="60px" | Methods
| width="240px" | Parameter
+
! scope="col" width="15%" | Parameter
| width="600px" | Description
+
! scope="col" width="40%" | Description
| width="190px" | Return  
+
! scope="col" width="15%" | Return  
 
|-
 
|-
| address(short a)  || 0x00-0xFF || Set i2c address                  || Result
+
| height="45px" | address(short a)  || 0x00-0xFF || Set i2c address                  || Result
 
|-
 
|-
| readByte()        || void      || Read a byte data form i2c        || short
+
| height="45px" | readByte()        || void      || Read a byte data form i2c        || short
 
|-
 
|-
| writeByte(short b) || Mode      || Write a byte data to i2c          || Result
+
| height="45px" | writeByte(short b) || Mode      || Write a byte data to i2c          || Result
 
|-
 
|-
| read(byte[] buf)  || byte[]    || Read a byte[] data form i2c      || read size
+
| height="45px" | read(byte[] buf)  || byte[]    || Read a byte[] data form i2c      || read size
 
|-
 
|-
| write(byte[] buf)  || byte[]    || Write a byte[] data to i2c        || Result
+
| height="45px" | write(byte[] buf)  || byte[]    || Write a byte[] data to i2c        || Result
 
|-
 
|-
| readReg(short a)  || 0x00-0xFF || Read a byte data form i2c addr    || short
+
| height="45px" | readReg(short a)  || 0x00-0xFF || Read a byte data form i2c addr    || short
 
|-
 
|-
| writeReg(short a, short d) || 0x00-0xFF, 0x00-0xFF || Write a byte data to i2c addr || Result
+
| height="45px" | writeReg(short a, short d) || 0x00-0xFF, 0x00-0xFF || Write a byte data to i2c addr || Result
 
|-
 
|-
| readWordReg(short a) || 0x00-0xFF || Read a byte[2] data form i2c addr || int
+
| height="45px" | readWordReg(short a) || 0x00-0xFF || Read a byte[2] data form i2c addr || int
 
|-
 
|-
| writeWordReg(short a, int d) || 0x00-0xFF, 0x0000-0xFFFF || Write a byte[2] data to i2c addr || Result
+
| height="45px" | writeWordReg(short a, int d) || 0x00-0xFF, 0x0000-0xFFFF || Write a byte[2] data to i2c addr || Result
 
|-
 
|-
| readBytesReg(short a, byte[] b) || 0x00-0xFF, byte[] || Read a byte[] data form i2c addr || int
+
| height="45px" | readBytesReg(short a, byte[] b) || 0x00-0xFF, byte[] || Read a byte[] data form i2c addr || int
 
|-
 
|-
 
|}
 
|}
  
 
==== Pwm ====
 
==== Pwm ====
{| class="wikitable"
+
{| class="wikitable" style="width:100%;"
 
|-
 
|-
| width="200px" | Methods
+
! scope="col" width="30%" height="60px" | Methods
| width="160px" | Parameter
+
! scope="col" width="15%" | Parameter
| width="600px" | Description
+
! scope="col" width="40%" | Description
| width="190px" | Return  
+
! scope="col" width="15%" | Return  
 
|-
 
|-
| period(float s)    || 0.0001 - 2.147483  || Set pwm period      || Result
+
| height="45px" | period(float s)    || 0.0001 - 2.147483  || Set pwm period      || Result
 
|-
 
|-
| period_ms(int m)    || 1 - 2147          || Set pwm period      || Result
+
| height="45px" | period_ms(int m)    || 1 - 2147          || Set pwm period      || Result
 
|-
 
|-
| period_us(int u)    || 1 - 2147483        || Set pwm period      || Result
+
| height="45px" | period_us(int u)    || 1 - 2147483        || Set pwm period      || Result
 
|-
 
|-
| pulsewidth(float s)  || 0.0001 - 2.147483 || Set pwm duty        || Result
+
| height="45px" | pulsewidth(float s)  || 0.0001 - 2.147483 || Set pwm duty        || Result
 
|-
 
|-
| pulsewidth_ms(int m) || 1 - 2147          || Set pwm duty        || Result
+
| height="45px" | pulsewidth_ms(int m) || 1 - 2147          || Set pwm duty        || Result
 
|-
 
|-
| pulsewidth_us(int u) || 1 - 2147483      || Set pwm duty        || Result
+
| height="45px" | pulsewidth_us(int u) || 1 - 2147483      || Set pwm duty        || Result
 
|-
 
|-
| max_period()        || void              || Get pwm max period  || int(us)
+
| height="45px" | max_period()        || void              || Get pwm max period  || int(us)
 
|-
 
|-
| min_period()        || void              || Get pwm min period  || int(us)
+
| height="45px" | min_period()        || void              || Get pwm min period  || int(us)
 
|-
 
|-
| read()              || void              || Get pwm period/duty || 0.0 - 1.0
+
| height="45px" | read()              || void              || Get pwm period/duty || 0.0 - 1.0
 
|-
 
|-
| write(float p)      || 0.0 - 1.0        || Set pwm period/duty percentage || Result
+
| height="45px" | write(float p)      || 0.0 - 1.0        || Set pwm period/duty percentage || Result
 
|-
 
|-
| enable(boolean e)    || true/false        || dis/enable pwm    || Result
+
| height="45px" | enable(boolean e)    || true/false        || dis/enable pwm    || Result
 
|-
 
|-
| unexport()          || void              || Unexport pwm in /dev/class/pwm || Result
+
| height="45px" | unexport()          || void              || Unexport pwm in /dev/class/pwm || Result
 
|}
 
|}
  
 
==== SPI ====
 
==== SPI ====
{| class="wikitable"
+
{| class="wikitable" style="width:100%;"
 
|-
 
|-
| width="200px" | Methods
+
! scope="col" width="30%" height="60px" | Methods
| width="160px" | Parameter
+
! scope="col" width="15%" | Parameter
| width="600px" | Description
+
! scope="col" width="40%" | Description
| width="190px" | Return  
+
! scope="col" width="15%" | Return  
 
|-
 
|-
| defaultConfig()    ||void        || Set mraa default config (mode0,lsb=0,bits=8) || Result
+
| height="45px" | defaultConfig()    ||void        || Set mraa default config (mode0,lsb=0,bits=8) || Result
 
|-
 
|-
| mode(Spi_Mode m)  || void      || Set spi mode                                || Result
+
| height="45px" | mode(Spi_Mode m)  || void      || Set spi mode                                || Result
 
|-
 
|-
| frequency(int f)  || int        || Set spi frequency max=48000000              || Result
+
| height="45px" | frequency(int f)  || int        || Set spi frequency max=48000000              || Result
 
|-
 
|-
| lsbmode(boolean l) || true/false || Set spi lsmode                              || Result
+
| height="45px" | lsbmode(boolean l) || true/false || Set spi lsmode                              || Result
 
|-
 
|-
| bitPerWord(long b) || 8/16      || Set spi bit_pre_word                        || Result
+
| height="45px" | bitPerWord(long b) || 8/16      || Set spi bit_pre_word                        || Result
 
|-
 
|-
| writeByte(short a) || 0x00-0xFF  || Write a byte data to spi                    || int(recv data)
+
| height="45px" | writeByte(short a) || 0x00-0xFF  || Write a byte data to spi                    || int(recv data)
 
|-
 
|-
| writeWord(int a)  || 0x0000-0xFFFF || Write a byte[2] data to spi              || int(recv data)
+
| height="45px" | writeWord(int a)  || 0x0000-0xFFFF || Write a byte[2] data to spi              || int(recv data)
 
|-
 
|-
| write(byte[] b)    || byte[]        || Write a byte[] data to spi                || byte[](recv data)
+
| height="45px" | write(byte[] b)    || byte[]        || Write a byte[] data to spi                || byte[](recv data)
 
|-
 
|-
 
|}
 
|}
  
 
==== UART ====
 
==== UART ====
{| class="wikitable"
+
{| class="wikitable" style="width:100%;"
 
|-
 
|-
| width="440px" | Methods
+
! scope="col" width="30%" height="60px" | Methods
| width="160px" | Parameter
+
! scope="col" width="15%" | Parameter
| width="600px" | Description
+
! scope="col" width="40%" | Description
| width="190px" | Return  
+
! scope="col" width="15%" | Return  
 
|-
 
|-
| defaultConfig()                                        ||void          || Set mraa default config (9600 8N1, no echo or special character)                || Result
+
| height="45px" | defaultConfig()                                        ||void          || Set mraa default config (9600 8N1, no echo or special character)                || Result
 
|-
 
|-
| setBaudRate(long b)                                    || long        || Set uart baudrate max=150000000                                                || Result
+
| height="45px" | setBaudRate(long b)                                    || long        || Set uart baudrate max=150000000                                                || Result
 
|-
 
|-
| setMode(int bytesize, UartParity parity, int stopbits) || int          || Set the transfer mode                                                          || Result
+
| height="45px" | setMode(int bytesize, UartParity parity, int stopbits) || int          || Set the transfer mode                                                          || Result
 
|-
 
|-
| setFlowcontrol(boolean xonxoff, boolean rtscts)        || true/false  || Set the flowcontrol                                                            || Result
+
| height="45px" | setFlowcontrol(boolean xonxoff, boolean rtscts)        || true/false  || Set the flowcontrol                                                            || Result
 
|-
 
|-
| setTimeout(int read, int write, int interchar)        || -1 - int_max || Set the timeout for read and write operations                                  || Result
+
| height="45px" | setTimeout(int read, int write, int interchar)        || -1 - int_max || Set the timeout for read and write operations                                  || Result
 
|-
 
|-
| setNonBlocking(boolean var1)                           || true/false  || Set the blocking state for write operations                                    || Result
+
| height="45px" | setNonBlocking(boolean b)                             || true/false  || Set the blocking state for write operations                                    || Result
 
|-
 
|-
| sendBreak(int var1)                                   || 0 - max_int  || Send a break to the device.                                                    || Result
+
| height="45px" | sendBreak(int b)                                       || 0 - max_int  || Send a break to the device.                                                    || Result
 
|-
 
|-
| flush()                                                || void        || Flush the outbound data.                                                        || Result
+
| height="45px" | flush()                                                || void        || Flush the outbound data.                                                        || Result
 
|-
 
|-
| dataAvailable()                                        || void        || Check to see if data is available on the device for reading, return immediately || boolean
+
| height="45px" | dataAvailable()                                        || void        || Check to see if data is available on the device for reading, return immediately || boolean
 
|-
 
|-
| dataAvailable(long var1)                               || 1 - int_max  || Check to see if data is available on the device for reading and time out        || boolean
+
| height="45px" | dataAvailable(long timeout)                           || 1 - int_max  || Check to see if data is available on the device for reading and time out        || boolean
 
|-
 
|-
| readStr(int length)                                    || 1 - int_max  || Read bytes from the device into a String object                                || String
+
| height="45px" | readStr(int length)                                    || 1 - int_max  || Read bytes from the device into a String object                                || String
 
|-
 
|-
| writeStr(String s)                                    || 1 - int_max  || Write bytes in String object to a device                                        || int
+
| height="45px" | writeStr(String s)                                    || 1 - int_max  || Write bytes in String object to a device                                        || int
 
|-
 
|-
| read(byte[] data)                                      || 1 - int_max  || Check to see if data is available on the device for reading and time out        || int(read size)
+
| height="45px" | read(byte[] data)                                      || 1 - int_max  || Check to see if data is available on the device for reading and time out        || int(read size)
 
|-
 
|-
| wrtie(byte[] data)                                    || 1 - int_max  || Check to see if data is available on the device for reading and time out        || int(write size)
+
| height="45px" | wrtie(byte[] data)                                    || 1 - int_max  || Check to see if data is available on the device for reading and time out        || int(write size)
 
|-
 
|-
 
|}
 
|}

Revision as of 02:55, 20 March 2020

Rock PI 4 Android Mraa API


Default IO Map



Class

class constructor constructor2 class constructor constructor2
Aio Aio (int pin_index) NA Gpio Gpio(int pin_index) NA
I2c I2c (int i2c_index) NA Pwm Pwm (int pin_index) NA
Spi Spi (int spi_index) NA Uart Uart(int uart_index) NA

Index Class

RockPI4I2C Field Index Value Hardware I2c Number RockPI4SPI Field Index Value Hardware Spi Number
ROCK_PI_4_I2C2 0 i2c2 ROCK_PI_4_SPI1 0 spi1
ROCK_PI_4_I2C6 1 i2c6 ROCK_PI_4_SPI2 1 spi2
ROCK_PI_4_I2C7 2 i2c7
RockPI4Uart Field Index Value Hardware Uart Number
ROCK_PI_4_UART2 0 uart2
ROCK_PI_4_UART4 1 uart4

Gpio

Methods Parameter Description Return
dir(Dir dir) Dir Set input/output Result
readDir() void Read input/output dir Dir
mode(Mode mode) Mode Set STRONG/PULLUP/PULLDOWN/HIZ Result
read() void Set input and read gpio value 0/1
write(int v) 0/1 Set output value Result
unexport() void Unexport gpio in /dev/class/gpio Result

Example

   import mraa.*;
   
   Gpio gpio40 = new Gpio(RockPI4.ROCK_PI_4_PIN40.swigValue());
   // output
   gpio40.dir(Dir.DIR_OUT);
   // set value
   gpio40.write(1);
   // release gpio if you want
   gpio40.unexport();

Aio

Methods Parameter Description Return
read() void Read value. Default will shift the raw value up/down to a 10 bit. long
readFloat() void Read value and return it as a normalized float. 0.0 - 1.0
setBit(int b) int Set the bit value which will shift the raw reading from the ADC to. Result
getBit() void Gets the bit value mraa is shifting the analog read to. int

I2C

Methods Parameter Description Return
address(short a) 0x00-0xFF Set i2c address Result
readByte() void Read a byte data form i2c short
writeByte(short b) Mode Write a byte data to i2c Result
read(byte[] buf) byte[] Read a byte[] data form i2c read size
write(byte[] buf) byte[] Write a byte[] data to i2c Result
readReg(short a) 0x00-0xFF Read a byte data form i2c addr short
writeReg(short a, short d) 0x00-0xFF, 0x00-0xFF Write a byte data to i2c addr Result
readWordReg(short a) 0x00-0xFF Read a byte[2] data form i2c addr int
writeWordReg(short a, int d) 0x00-0xFF, 0x0000-0xFFFF Write a byte[2] data to i2c addr Result
readBytesReg(short a, byte[] b) 0x00-0xFF, byte[] Read a byte[] data form i2c addr int

Pwm

Methods Parameter Description Return
period(float s) 0.0001 - 2.147483 Set pwm period Result
period_ms(int m) 1 - 2147 Set pwm period Result
period_us(int u) 1 - 2147483 Set pwm period Result
pulsewidth(float s) 0.0001 - 2.147483 Set pwm duty Result
pulsewidth_ms(int m) 1 - 2147 Set pwm duty Result
pulsewidth_us(int u) 1 - 2147483 Set pwm duty Result
max_period() void Get pwm max period int(us)
min_period() void Get pwm min period int(us)
read() void Get pwm period/duty 0.0 - 1.0
write(float p) 0.0 - 1.0 Set pwm period/duty percentage Result
enable(boolean e) true/false dis/enable pwm Result
unexport() void Unexport pwm in /dev/class/pwm Result

SPI

Methods Parameter Description Return
defaultConfig() void Set mraa default config (mode0,lsb=0,bits=8) Result
mode(Spi_Mode m) void Set spi mode Result
frequency(int f) int Set spi frequency max=48000000 Result
lsbmode(boolean l) true/false Set spi lsmode Result
bitPerWord(long b) 8/16 Set spi bit_pre_word Result
writeByte(short a) 0x00-0xFF Write a byte data to spi int(recv data)
writeWord(int a) 0x0000-0xFFFF Write a byte[2] data to spi int(recv data)
write(byte[] b) byte[] Write a byte[] data to spi byte[](recv data)

UART

Methods Parameter Description Return
defaultConfig() void Set mraa default config (9600 8N1, no echo or special character) Result
setBaudRate(long b) long Set uart baudrate max=150000000 Result
setMode(int bytesize, UartParity parity, int stopbits) int Set the transfer mode Result
setFlowcontrol(boolean xonxoff, boolean rtscts) true/false Set the flowcontrol Result
setTimeout(int read, int write, int interchar) -1 - int_max Set the timeout for read and write operations Result
setNonBlocking(boolean b) true/false Set the blocking state for write operations Result
sendBreak(int b) 0 - max_int Send a break to the device. Result
flush() void Flush the outbound data. Result
dataAvailable() void Check to see if data is available on the device for reading, return immediately boolean
dataAvailable(long timeout) 1 - int_max Check to see if data is available on the device for reading and time out boolean
readStr(int length) 1 - int_max Read bytes from the device into a String object String
writeStr(String s) 1 - int_max Write bytes in String object to a device int
read(byte[] data) 1 - int_max Check to see if data is available on the device for reading and time out int(read size)
wrtie(byte[] data) 1 - int_max Check to see if data is available on the device for reading and time out int(write size)