Jetgpio 2.1
C library to manage the GPIO header of the Nvidia JETSON boards
|
#include <stddef.h>
#include <stdint.h>
Go to the source code of this file.
Functions | |
int | gpioInitialise (void) |
Initialises the library. gpioInitialise must be called before using the other library functions, it stores the status of all the relevant registers before using/modifying them. More... | |
void | gpioTerminate (void) |
Terminates the library. This function restores the used registers to their previous state and releases memory. More... | |
int | gpioSetMode (unsigned gpio, unsigned mode) |
Sets the GPIO mode, typically input or output. More... | |
int | gpioRead (unsigned gpio) |
Reads the GPIO level, on or off, 0 or 1. Arduino style: digitalRead. Wheter a pin has been set as input or output it can be read with this function. More... | |
int | gpioWrite (unsigned gpio, unsigned level) |
Sets the GPIO level, on or off. Arduino style: digitalWrite. More... | |
int | gpioSetISRFunc (unsigned gpio, unsigned edge, unsigned debounce, unsigned long *timestamp, void(*f)()) |
Registers a function to be called (a callback) whenever the specified. More... | |
int | gpioSetPWMfrequency (unsigned gpio, unsigned frequency) |
Sets the frequency in hertz to be used for the GPIO. More... | |
int | gpioPWM (unsigned gpio, unsigned dutycycle) |
Starts PWM on the GPIO, dutycycle between 0 (off) and range (fully on). Arduino style: analogWrite. More... | |
int | i2cOpen (unsigned i2cBus, unsigned i2cFlags) |
This returns a handle for the device at the address on the I2C bus. More... | |
int | i2cClose (unsigned handle) |
This closes the I2C device associated with the handle. More... | |
int | i2cWriteByteData (unsigned handle, unsigned i2cAddr, unsigned i2cReg, unsigned bVal) |
This writes a single byte to the specified register of the device associated with handle. More... | |
int | i2cReadByteData (unsigned handle, unsigned i2cAddr, unsigned i2cReg) |
This reads a single byte from the specified register of the device associated with handle. More... | |
int | i2cWriteWordData (unsigned handle, unsigned i2cAddr, unsigned i2cReg, unsigned wVal) |
This writes two bytes to the specified consecutive register(s) of the device associated with handle. More... | |
int | i2cReadWordData (unsigned handle, unsigned i2cAddr, unsigned i2cReg) |
This reads two bytes from the specified consecutive register(s) of the device associated with handle. More... | |
int | spiOpen (unsigned spiChan, unsigned speed, unsigned mode, unsigned cs_delay, unsigned bits_word, unsigned lsb_first, unsigned cs_change) |
This function returns a handle for the SPI device on the channel. Data will be transferred at baud bits per second. The flags may be used to modify the default behaviour of a 4-wire operation, mode 0, active low chip select. There are 2 SPI channels called SPI1 & SPI2 on Nano and SPI0 & SPI1 on Orin Nano, Orin NX and Xavier NX. For Orin AGX there is only 1 SPI channel: SPI1 (pins 21, 19...so forth). The pins used are given in the following table. More... | |
int | spiClose (unsigned handle) |
This functions closes the SPI device identified by the handle. More... | |
int | spiXfer (unsigned handle, char *txBuf, char *rxBuf, unsigned len) |
This function transfers len bytes of data from txBuf to the SPI device associated with the handle. Simultaneously len bytes of data are read from the device and placed in rxBuf. More... | |
int | extPeripheralRate (unsigned clk_name, unsigned rate) |
Orin family only. This functions changes the rate of one of the external peripheral clocks. There are 2 (pins 29 and 31) in Orin Nano and only one (pin 7) in Orin AGX. More... | |
int | extPeripheralEnable (unsigned clk_name) |
Orin family only. This functions enables one of the external peripheral clocks. There are 2 (pins 29 and 31) in Orin Nano and only one (pin 7) in Orin AGX. More... | |
int | extPeripheralDisable (unsigned clk_name) |
Orin family only. This functions disables one of the external peripheral clocks. There are 2 (pins 29 and 31) in Orin Nano and only one (pin 7) in Orin AGX. More... | |
int extPeripheralDisable | ( | unsigned | clk_name | ) |
Orin family only. This functions disables one of the external peripheral clocks. There are 2 (pins 29 and 31) in Orin Nano and only one (pin 7) in Orin AGX.
clk_name | possible values are: EXTPERIPH3 -> pin 29 Orin Nano, EXTPERIPH4 -> pin 31 Orin Nano and pin 7 in Orin AGX |
int extPeripheralEnable | ( | unsigned | clk_name | ) |
Orin family only. This functions enables one of the external peripheral clocks. There are 2 (pins 29 and 31) in Orin Nano and only one (pin 7) in Orin AGX.
clk_name | possible values are: EXTPERIPH3 -> pin 29 Orin Nano, EXTPERIPH4 -> pin 31 Orin Nano and pin 7 in Orin AGX |
int extPeripheralRate | ( | unsigned | clk_name, |
unsigned | rate | ||
) |
Orin family only. This functions changes the rate of one of the external peripheral clocks. There are 2 (pins 29 and 31) in Orin Nano and only one (pin 7) in Orin AGX.
clk_name | possible values are: EXTPERIPH3 -> pin 29 Orin Nano, EXTPERIPH4 -> pin 31 Orin Nano and pin 7 in Orin AGX |
rate | number between 3200000 to 51000000, this is the value of the clock in Hz |
int gpioInitialise | ( | void | ) |
Initialises the library. gpioInitialise must be called before using the other library functions, it stores the status of all the relevant registers before using/modifying them.
int gpioPWM | ( | unsigned | gpio, |
unsigned | dutycycle | ||
) |
Starts PWM on the GPIO, dutycycle between 0 (off) and range (fully on). Arduino style: analogWrite.
gpio | Nano & Xavier NX: 32, 33 Orin Nano,NX: 15, 32, 33 Orin AGX: 13, 15, 18 |
dutycycle | 0-256 (0 to 100%) |
int gpioRead | ( | unsigned | gpio | ) |
Reads the GPIO level, on or off, 0 or 1. Arduino style: digitalRead. Wheter a pin has been set as input or output it can be read with this function.
gpio | 3-40, 7-40 on Xavier NX dev kit |
int gpioSetISRFunc | ( | unsigned | gpio, |
unsigned | edge, | ||
unsigned | debounce, | ||
unsigned long * | timestamp, | ||
void(*)() | f | ||
) |
Registers a function to be called (a callback) whenever the specified.
GPIO interrupt occurs. This function will start a thread that will monitor the status of the interrupt.One function may be registered per GPIO.
gpio | 3-40, 7-40 on Xavier NX dev kit |
edge | RISING_EDGE, FALLING_EDGE, or EITHER_EDGE |
debounce | 0-1000 useconds, to avoid bouncing specially on mechanical inputs |
timestamp | timestamp of the detected edge in nanoseconds in EPOCH format |
f | the callback function, this will be execute if an edge is detected in the selected pin |
int gpioSetMode | ( | unsigned | gpio, |
unsigned | mode | ||
) |
Sets the GPIO mode, typically input or output.
gpio | 3-40, 7-40 on Xavier NX dev kit |
mode | JET_INPUT, JET_OUTPUT |
int gpioSetPWMfrequency | ( | unsigned | gpio, |
unsigned | frequency | ||
) |
Sets the frequency in hertz to be used for the GPIO.
gpio | Nano & Xavier NX: 32, 33 Orin Nano,NX: 15, 32, 33 Orin AGX: 13, 15, 18 |
frequency | 25Hz to 187 kHz on Nano and 50 Hz to 1593 kHz on Orin and Xavier |
void gpioTerminate | ( | void | ) |
Terminates the library. This function restores the used registers to their previous state and releases memory.
int gpioWrite | ( | unsigned | gpio, |
unsigned | level | ||
) |
Sets the GPIO level, on or off. Arduino style: digitalWrite.
gpio | 3-40, 7-40 on Xavier NX dev kit |
level | 0-1 |
int i2cClose | ( | unsigned | handle | ) |
This closes the I2C device associated with the handle.
handle | >=0, as returned by a call to [i2cOpen] |
int i2cOpen | ( | unsigned | i2cBus, |
unsigned | i2cFlags | ||
) |
This returns a handle for the device at the address on the I2C bus.
i2cBus | 0 or 1, 0 are pins 27 (SDA) & 28 (SCL), 1 are pins 3(SDA) & 5(SCL) In Orin the pins are the same but the i2c devices are: 0->i2c-1 & 1->i2c-7 In Xavier NX the pins are the same but the i2c devices are: 0->i2c-1 & 1->i2c-8 Flags allow you to change the bus speed. NOTE - FLAGS WILL NOT CAUSE ANY EFFECT FOR MACHINES WITH JETPACK >= 6: |
i2cFlags | 0 -> 100 kHz |
i2cFlags | 1 -> 400 kHz |
i2cFlags | 2 -> 1 MHz |
int i2cReadByteData | ( | unsigned | handle, |
unsigned | i2cAddr, | ||
unsigned | i2cReg | ||
) |
This reads a single byte from the specified register of the device associated with handle.
handle | >=0, as returned by a call to [i2cOpen] |
i2cAddr | 0-0x7F, the I2C slave address |
i2cReg | 0-255, the register to read |
int i2cReadWordData | ( | unsigned | handle, |
unsigned | i2cAddr, | ||
unsigned | i2cReg | ||
) |
This reads two bytes from the specified consecutive register(s) of the device associated with handle.
handle | >=0, as returned by a call to [i2cOpen] |
i2cAddr | 0-0x7F, the I2C slave address |
i2cReg | 0-255, the register to read |
int i2cWriteByteData | ( | unsigned | handle, |
unsigned | i2cAddr, | ||
unsigned | i2cReg, | ||
unsigned | bVal | ||
) |
This writes a single byte to the specified register of the device associated with handle.
handle | >=0, as returned by a call to [i2cOpen] |
i2cAddr | 0-0x7F, the I2C slave address |
i2cReg | 0-255, the register to write |
bVal | 0-0xFF, the value to write |
int i2cWriteWordData | ( | unsigned | handle, |
unsigned | i2cAddr, | ||
unsigned | i2cReg, | ||
unsigned | wVal | ||
) |
This writes two bytes to the specified consecutive register(s) of the device associated with handle.
handle | >=0, as returned by a call to [i2cOpen] |
i2cAddr | 0-0x7F, the I2C slave address |
i2cReg | 0-255, the register to write |
wVal | 0-0xFFFF, the value to write |
int spiClose | ( | unsigned | handle | ) |
This functions closes the SPI device identified by the handle.
handle | >=0, as returned by a call to [spiOpen] |
int spiOpen | ( | unsigned | spiChan, |
unsigned | speed, | ||
unsigned | mode, | ||
unsigned | cs_delay, | ||
unsigned | bits_word, | ||
unsigned | lsb_first, | ||
unsigned | cs_change | ||
) |
This function returns a handle for the SPI device on the channel. Data will be transferred at baud bits per second. The flags may be used to modify the default behaviour of a 4-wire operation, mode 0, active low chip select. There are 2 SPI channels called SPI1 & SPI2 on Nano and SPI0 & SPI1 on Orin Nano, Orin NX and Xavier NX. For Orin AGX there is only 1 SPI channel: SPI1 (pins 21, 19...so forth). The pins used are given in the following table.
Port | MISO | MOSI | SCLK | CS0 | CS1 |
---|---|---|---|---|---|
SPI1/SPI0 | 21 | 19 | 23 | 24 | 26 |
SPI2/SPI1 | 22 | 37 | 13 | 18 | 16 |
spiChan | 0-1 (0 stands for SPI1 on Nano, SPI0 on Orin Nano and SPI1 on Orin AGX, 1 stands for SPI2 on Nano and SPI1 on Orin Nano) |
speed | up to 50M (beyond that expect problems, actually we are not going beyond that) |
mode | defines the SPI mode |
Mode | POL | PHA |
---|---|---|
0 | 0 | 0 |
1 | 0 | 1 |
2 | 1 | 0 |
3 | 1 | 1 |
cs_delay | delay if nonzero, how long to delay after the last bit transfer in us before optionally deselecting the device before the next transfer |
bits_word | bits per word from 1 to 32 bits |
lsb_first | is 1 if least significant bit first 0 otherwise |
cs_change | is 1 to deselect device before starting the next transfer otherwise 0 |
int spiXfer | ( | unsigned | handle, |
char * | txBuf, | ||
char * | rxBuf, | ||
unsigned | len | ||
) |
This function transfers len bytes of data from txBuf to the SPI device associated with the handle. Simultaneously len bytes of data are read from the device and placed in rxBuf.
handle | >=0, as returned by a call to [spiOpen] |
txBuf | the data bytes to write |
rxBuf | the received data bytes |
len | the number of bytes to transfer |