Software Specification

< All Topics

The Trēo software library provides an easy-to-use API to initialize, configure, and run every module in the system on every supported microprocessor. Trēo is able to do this because an each module’s API is written using a set of Trēo communication functions that are specially defined for each supported platform. This abstracts the libraries, allowing it to be easily ported to other platforms as illustrated below.

NightShade Electronics - Software Specification
Trēo Software Abstraction

The details of each module’s API can be found in the module’s datasheet.

Trēo Communication Functions

Trēo I2C

C++ Example

NightShade_Treo_TWI twi();

// Write 0xA2 to register 0x00
uint8_t buffer[2] = {0x00, 0xA2};
twi.begin(1, 0x63, 100000u);
twi.write(buffer, 2, 1);
twi.end();

// Read and return value of register 0x05
return twi.readByte(0x05);

Constructor

NightShade_Treo_TWI()

Declares a TWI communication object.

Methods

begin(int port, uint8_t sevenBitAddress, uint32_t clockSpeed)

Initializes a communication exchange. Must be called at the start of every exchange. Returns error code (int).

write(uint8_t *buffer, int numberOfBytes, int sendStop)

Writes bytes from a FIFO buffer to the slave defined with begin().Returns error code (int).

read(uint8_t *buffer, int numberOfBytes, int sendStop)

Reads bytes from the slave defined with begin(). Bytes are written to FIFO buffer. Returns error code (int).

end()

Completes an exchange. Must be called at the end of each communication exchange. Returns error code (int).

writeByte(uint8_t regAddress, uint8_t byteValue)

Performs the necessary writes and reads to write 1 byte to memory. Requires the use of begin() and end(). Returns error code (int).

readByte(uint8_t regAddress)

Performs the necessary writes and reads to read 1 byte from memory.Requires the use of begin() and end(). Returns byte read (uint8_t).

writeWord(uint8_t regAddress, uint16_t wordValue, int isBigEndian)

Performs the necessary writes and reads to write a word (2 bytes) to memory in either big endian or little endian format. Requires the use of begin() and end(). Returns error code (int).

writeWord(uint8_t regAddress, uint16_t wordValue)

Performs the necessary writes and reads to write a word (2 bytes) to memory assuming little endian format. Requires the use of begin() and end(). Returns error code (int).

readWord(uint8_t regAddress, int isBigEndian)

Performs the necessary writes and reads to read a word (2 bytes) from memory in either big endian or little endian format. Requires the use of begin() and end(). Returns word read (uint16_t).

readWord(uint8_t regAddress)

Performs the necessary writes and reads to read a word (2 bytes) from memory assuming little endian format. Requires the use of begin() and end(). Returns word read (uint16_t).

Trēo SPI

C++ Example

NightShade_Treo_SPI spi();

// Write 0x2D5E to 16-bit register 0x05
uint8_t buffer[3] = {0x05, 0x5E, 0x2D};
spi.begin(1, 8, 5000000u);
spi.transfer(buffer, 3);
spi.end();

// Read word (2 bytes) from register 0x10
spi.begin(1, 8, 5000000u);
spi.transfer(buffer, 2);
spi.end;

// Return 16-bit value
return (buffer[1] << 8) | buffer[0];

Contructor

NightShade_Treo_SPI()

Creates a Trēo SPI communication object.

Methods

begin(int port, int chipSelectPin, uint32_t maxBaudrate, int spiMode, int bitsPerWord, int lsbFirst)

Initializes a communication exchange. Must be called at the start of every exchange. Returns error code (int).

transfer(uint8_t *buffer, int numberOfBytes)

Transmits bytes from FIFO buffer while simultaneously writing received bytes to the same FIFO buffer. Returns error code (int).

end()

Completes an exchange. Must be called at the end of each communication exchange. Returns error code (int).

Trēo GPIO

C++ Example

NightShade_Treo_GPIO gpio();

int clkpin = 8;
int datapin = 9;
uint8_t data = 0;

gpio.setup(clkpin, GPIO_OUTPUT);
gpio.setup(datapin, GPIO_INPUT);

// Read 8 bits of data from slave
for (int x=0; x<8; ++x) {
    gpio.write(clkpin, GPIO_HIGH);
    usleep(10);
    gpio.write(clkpin, GPIO_LOW);
    usleep(5);
    data = data << 1;
    if (gpio.read()) data |= 1;
}

return data;

Constructor

NightShade_Treo_GPIO()

Creates a GPIO communication object.

Methods

setup(int pin, int mode)

Sets the mode of a GPIO pin as an input or output. Returns error code (int).

write(int pin, int state)

Writes the output states of a GPIO pin. Returns error code (int).

read(int pin)

Reads the input state of a GPIO pin. Returns pin state (int).

Trēo UART

C++ Example

NightShade_Treo_UART uart();

uint8_t buffer[5] = {0x00, 0x05, 0x07, 0xA0, 0x10};

uart.begin(1, 115200u, 8, 0, 1);
uart.write(buffer, 5);
uart.end();

Constructor

NightShade_Treo_UART()

Creates a GPIO communication object.

Methods

begin(int port, uint32_t baudrate, uint8_t dataBits, uint8_t parity, uint8_t endBits)

Initializes a communication exchange. Must be called at the start of every exchange. Returns error code (int).

write(uint8_t *buffer, int numberOfBytes)

Writes bytes from a FIFO buffer to the slave defined with begin().Returns error code (int).

read(uint8_t *buffer, int numberOfBytes)

Reads bytes from the slave defined with begin(). Bytes are written to FIFO buffer. Returns error code (int).

end()

Completes an exchange. Must be called at the end of each communication exchange. Returns error code (int).

Previous Mechanical Specification
Table of Contents