Shunya Interfaces core API - shunyaos/shunyainterfaces GitHub Wiki

Shunya Interfaces Core API

Shunya Interfaces depends on the core library to provide basic API's to Interact with the Microprocessor Interfaces like GPIO, SPI, UART, I2C.

While porting sensors Use these API's for interacting with sensors.

GPIO API

API Description Details
pinmode() Sets the direction of the GPIO pin to INPUT or OUTPUT Read More
digitalWrite() Sets the digital value of the GPIO pin Read More
digitalRead() Read digital value of the GPIO pin Read More

Interrupt API

API Description Details
attachInterrupt() Sets the digital value of the GPIO pin. Read More

Delay API

API Description Details
delay() Code sleeps for given milliseconds Read More
delayMicroseconds() Code sleeps for given microseconds Read More

I2C API

API Description Details
wireBegin() Initializes the I2C device Read More
wireBeginTransmission() Starts I2C communication Read More
wireWrite() Send data to the I2C device Read More
wireRequestFrom() Request Data from the I2C device Read More
wireAvailable() Check number of bytes available to read from the device Read More
wireRead() Read from the I2C device Read More
wireEndTransmission() End communication to the I2C device Read More
wireEnd() De-initialize the I2C device Read More

SPI API

API Description Details
spiBegin() Initializes the SPI device Read More
spiBeginTransaction() Starts SPI communication. Read More
spiTransfer() Send data to the I2C device Read More
spiEndTransaction() End the SPI transaction Read More
spiEnd() End the SPI communication Read More
spiSetBitOrder() Set the bit order to MSB or LSB first Read More
spiSetClock() Set SPI clock rate Read More
spiSetDataMode() Set SPI mode Read More

GPIO API

pinmode()

Description : Sets the direction of the GPIO pin to INPUT or OUTPUT

Parameters

  • physicalPin(int) - Physical pin number of the GPIO
  • mode(int) - GPIO mode either INPUT or OUTPUT

Return-type : void

Usage : pinmode(7, OUTPUT);


digitalWrite()

Description : Sets the digital value of the GPIO pin

Parameters

  • physicalPin(int) - Physical pin number of the GPIO
  • value(int) - value is either HIGH or LOW

Return-type : void

Usage : digitalWrite(7, HIGH);


digitalRead()

Description : Read digital value of the GPIO pin

Parameters

  • physicalPin(int) - Physical pin number of the GPIO

Return-type : int

Returns : Return GPIO pin value on SUCCESS, Return -1 on FAILURE

Usage : result = digitalRead(7);


Delay API

delay()

Description : Used to produce millisecond delays

Parameters

  • howLong(unsigned int) - Delay in ms to be produced

Return-type : void

Usage : delay(50);


delayMicroseconds()

Description: Used to produce microsecond delays

Parameters

  • howLong(unsigned int) - Delay in us to be produced

Return-type: void

Usage: delayMicroseconds(50);


I2C/TWI API

wireBegin()

Description : Initializes the I2C device

Parameters

  • bus(const int) - I2C device node

Usage : wireBegin(1); //1 is the board I2C 1


wireBeginTransmission()

Description : Starts I2C communication

Parameters

  • addr(const int) - I2C device address

Return-type : void

Usage : wireBeginTransmission(0x23); //0x23 is the device address


wireWrite()

Description : Send data to the I2C device

Parameters

  • val(int) - Value to be written to the device.

Return-type : void

Usage : wireWrite(1);


wireRequestFrom()

Description : Request Data from the I2C device

Parameters

  • addr(int) - I2C address
  • count(int) - Number of Bytes to request

Return-type : int

Returns : count of the data available or returns -1 on FAILURE

Usage : wireRequestFrom(0x23,5); //0x23 is the address of the I2C device


wireAvailable()

Description : Check number of bytes available to read from the device

Return-type : int

Returns : count of the data available to read or returns -1 on FAILURE

Usage : ret = wireAvailable();

wireRead()

Description : Read from the I2C device.

Return-type : int

Returns : -1 on FAILURE

Usage : val = wireRead();


wireEndTransmission()

Description : End communication to the I2C device

Return-type : void

Usage : wireEndTransmission();


wireEnd()

Description : De-initialize the I2C device

Return-type : void

Returns : -1 on FAILURE

Usage : wireWriteReg8(fd,0x10,0x01); //Write 0x01 in the register whose address is 0x10


SPI API

spiBegin()

Description : Initializes the SPI bus.

Return-type : void

Usage : spiBegin();


spiBeginTransaction()

Description : Starts SPI communication.

Parameters

  • clock SPI clock in Hz
  • bit_order Bit order for SPI
  • mode SPI mode (can be 0,1,2,3)

Return-type : void

Usage : spiBeginTransaction(50000, MSBFIRST, 0);


spiTransfer()

Description : Write 8 bits (1 byte) of data to the SPI bus.

Parameters

  • val Data to be written to the SPI device.

Return-type : Returns the Rx buffer of the SPI bus.

Usage : spiTransfer(0x5D);


spiEndTransaction()

Description : Ends the SPI communication.

Return-type : void

Usage : spiEndTransaction();


spiEnd()

Description : Ends the SPI device.

Return-type : void

Usage : spiEnd();


spiSetBitOrder()

Description : Set the bit order to MSB or LSB first.

Parameters

  • order Bit order

Return-type : void

Usage : spiSetBitOrder(MSBFIRST);


spiSetClock()

Description : Set SPI clock rate

Parameters

  • max_speed Clock rate

Return-type : void

Usage : spiSetClock(500000);


spiSetDataMode()

Description : Set SPI mode

Parameters

  • mode SPI mode (can be 0,1,2,3)

Return-type : void

Usage : spiSetDataMode(0);