SPI general purpose interface code for file system.
More...
#include <stdio.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include "include/linux/spi/spidev.h"
#include "bbbandroidHAL.h"
|
int | spiTransfer (const int spiFD, const uint8_t tx[], const uint8_t rx[], const int len) |
|
int | spiReadByte (const int spiFD, const uint8_t regAdd) |
|
unsigned char * | spiReadBytes (const int spiFD, const int len, const uint8_t startAdd) |
|
int | spiWriteRegByte (const int spiFD, const uint8_t regAdd, const uint8_t data) |
|
int | spiWriteBytes (const int spiFD, const uint8_t data[], const int len) |
|
int | spiSetMode (const int spiFD, const uint8_t mode) |
|
int | spiSetSpeed (const int spiFD, const uint32_t speed) |
|
int | spiSetBitsPerWord (const int spiFD, const uint8_t bpw) |
|
int | spiOpen (const uint8_t bus, const uint8_t device, const uint32_t speed, const uint8_t mode, const uint8_t bpw) |
|
void | spiClose (const int spiFD) |
|
SPI general purpose interface code for file system.
- Author
- Ankur Yadav (ankur.nosp@m.ayad.nosp@m.av@gm.nosp@m.ail..nosp@m.com)
Maximum buffer for creating path using snprintf()
Macro defination for MODE0
Macro defination for MODE1
Macro defination for MODE2
Macro defination for MODE3
void spiClose |
( |
const int |
spiFD | ) |
|
This function is used to close SPI file descriptor.
- Parameters
-
spiFD | a constant integer argument. |
int spiOpen |
( |
const uint8_t |
bus, |
|
|
const uint8_t |
device, |
|
|
const uint32_t |
speed, |
|
|
const uint8_t |
mode, |
|
|
const uint8_t |
bpw |
|
) |
| |
This function takes input bus number, device number, speed of device, mode of device and bits per word for the device and internally opens the file and sets speed mode and bits per word for the device using spiSetMode(), spiSetSpeed() and spiSetBitsPerWord() and then returns the file descriptor.
- Parameters
-
bus | a constant unsigned integer argument. |
device | a constant uint8_t argument. |
speed | a constant uint32_t argument. |
mode | a constant uuint8_t argument. |
bpw | a constant uuint8_t argument. |
- Returns
- If successful then SPI file descriptor is returned and if it fails then -1 is returned.
int spiReadByte |
( |
const int |
spiFD, |
|
|
const uint8_t |
regAdd |
|
) |
| |
It takes spi file descriptor and register address as input and returns the value present at that address.
- Parameters
-
spiFD | a constant integer argument. |
regAdd | a constant uint8_t argument. |
- Returns
- value present at that address.
unsigned char* spiReadBytes |
( |
const int |
spiFD, |
|
|
const int |
len, |
|
|
const uint8_t |
startAdd |
|
) |
| |
It takes file descriptor, length of data to be read and starting address of register from which data is to be read and returns a pointer to the array of data bytes read. It is used to get 'length' number of bytes in array from 'startAdd' starting address.
- Parameters
-
spiFD | a constant integer argument. |
len | a constant integer argument. |
startAdd | a constant uint8_t argument. |
- Returns
- a pointer to the array of data bytes read.
int spiSetBitsPerWord |
( |
const int |
spiFD, |
|
|
const uint8_t |
bpw |
|
) |
| |
It takes file descriptor and 'bpw' bits per word as input and sets the bpw provided in the argument to the device represented by file descriptor.
- Parameters
-
spiFD | a constant integer argument. |
bpw | a constant uint8_t argument. |
- Returns
- 0 if successful and -1 if it fails.
int spiSetMode |
( |
const int |
spiFD, |
|
|
const uint8_t |
mode |
|
) |
| |
It takes file descriptor and mode as input and sets the mode provided in the argument to the device represented by file descriptor.
- Parameters
-
spiFD | a constant integer argument. |
mode | a constant uint8_t argument. |
- Returns
- 0 if successful and -1 if it fails.
int spiSetSpeed |
( |
const int |
spiFD, |
|
|
const uint32_t |
speed |
|
) |
| |
It takes file descriptor and speed as input and sets the speed provided in the argument to the device represented by file descriptor.
- Parameters
-
spiFD | a constant integer argument. |
speed | a constant uint32_t argument. |
- Returns
- 0 if successful and -1 if it fails.
int spiTransfer |
( |
const int |
spiFD, |
|
|
const uint8_t |
tx[], |
|
|
const uint8_t |
rx[], |
|
|
const int |
len |
|
) |
| |
This function takes input SPI file descriptor, tx buffer array to transmit data, rx buffer array to receive data and length of data to be transferred. It then transfers and receives data using ioctl function call.
- Parameters
-
spiFD | a constant integer argument. |
tx | a constant uint8_t array argument. |
rx | a constant uint8_t array argument. |
len | a constant integer argument. |
- Returns
- 0 if successful and -1 if it fails.
int spiWriteBytes |
( |
const int |
spiFD, |
|
|
const uint8_t |
data[], |
|
|
const int |
len |
|
) |
| |
It takes spi file descriptor , array of data to be written and length of data to be written as input. It writes length number of data bytes from the data buffer provided.
- Parameters
-
spiFD | a constant integer argument. |
data | a constant uint8_t argument argument. |
len | a constant integer argument. |
- Returns
- 0
int spiWriteRegByte |
( |
const int |
spiFD, |
|
|
const uint8_t |
regAdd, |
|
|
const uint8_t |
data |
|
) |
| |
This function takes file descriptor, address of register to write and byte to be written as input and writes byte provided in the argument at the address provided.
- Parameters
-
spiFD | a constant integer argument. |
regAdd | a constant uint8_t argument. |
data | a constant uint8_t argument. |
- Returns
- 0