API

The EVT-core library is broken up into several semantic sections. The sections are meant as a way to divide functionality semantically. Each section may or may not have additional divisions between platform specific and platform agnostic features. For more information on each section, and for specifics on using the EVT-core API refer to the links below.

DEV

Devices, representation of hardware that can be interfaced with. In general, devices are communicated with via some sort of IO interface, but that is not strictly a rule. An LED is a simplistic example of a device.

LED

class EVT::core::DEV::LED

Public Types

enum ActiveState

Represents if the LED is active high or active low.

Values:

enumerator HIGH
enumerator LOW

Public Functions

LED(EVT::core::IO::GPIO &gpio, ActiveState activeState)

Create an instance of the LED based on the given GPIO pin.

Parameters
  • gpio[in] – GPIO pin

  • activeState[in] – Represents if the LED is active high or active low

void toggle()

Toggle the current state of the LED.

void setState(EVT::core::IO::GPIO::State state)

Set the current state of the LED.

Parameters

state[in] – The state to set the LED to.

RTC

class EVT::core::DEV::RTC

The RTC is the real time clock interface.

This class represents features common acrross real time clocks.

Subclassed by EVT::core::DEV::RTCf302x8

Public Functions

virtual void getTime(EVT::core::time::TimeStamp &time) = 0

Get the current time as determined by the real time clock.

Parameters

time[out] The time struct to populate

virtual uint32_t getTime() = 0

Get the timestamp since epoch in seconds.

Returns

The time since epoch as determined by the RTC

virtual void setTime(EVT::core::time::TimeStamp &time) = 0

Set the time of the real time clock.

Parameters

time[in] The time to set the RTC to use.

IO

IO represents different IO interfaces. The common ones are I2C, GPIO, PWM, and CAN. IO generally includes and means for interfacing beyond the microcontroller running the code.

Each platform will implement the IO functionality (if supported by the microcontroller). Since the IO interfaces represent common functionality shared across many devices, platform specific functionality may be supported by the platform’s implementation of the IO interface.

ADC

class EVT::core::IO::ADC

Subclassed by EVT::core::IO::ADCf302x8

Public Functions

ADC(Pin pin)

Setup the given pin for ADC (analog to digital) usage.

Parameters

pin – The pin to setup for ADC

virtual float read() = 0

Reads the current voltage in volts on the ADC.

Returns

The voltage in volts

virtual uint32_t readRaw() = 0

Read the raw value from the ADC.

Returns

The raw value from the ADC

virtual float readPercentage() = 0

Read the value from the ADC as a percentage of the possible values from 0 to 1 This is based on the maximum possible valie the ADC can read.

Returns

The ADC value as a percentage

CAN

class EVT::core::IO::CAN

Generic interface for CAN bus communication.

Devices can send and recieve messages over the CAN bus using this interface.

This provides the standard set of features supported across all hardware for CAN communication. Any hardware specific features are not included. This interface should be used for the majority of cases and should be deviated from when there is a need for hardware spoecific functionality.

NOTE: You cannot directly make an instance of this class via a constructor. You will need to use the getCAN function in the IO namespace.

Subclassed by EVT::core::IO::CANf302x8

Public Functions

CAN(Pin txPin, Pin rxPin, bool loopbackEnabled = false)

Creates a new instance of the CAN interface which will use the given transmit and receive pins.

Parameters
  • txPin[in] – The pin to use for transmitting data

  • rxPin[in] – The pin to use for receiving data

  • loopbackEnabled[in] – Flag to enable CAN loop back functionality

virtual void transmit(CANMessage &message) = 0

Transmit the message over CAN.

Parameters

message[in] – The message to send over CAN.

virtual CANMessage *receive(CANMessage *message, bool blocking = false) = 0

Receive a message over CAN.

The user can either receive in blocking or non-blocking mode. In blocking mode, the code will hang until a message is received then return a pointer to the message that was passed in. In non-blocking, a nullptr will be returned if no message is currently in the mailbox.

Parameters
  • message[out] – The message to populate with data

  • blocking[in] – Used to determine if received should block or not, by default receive is blocking

Returns

A pointer to the passed in message, nullptr if message not received.

GPIO

class EVT::core::IO::GPIO

Interface for interacting with GPIO pins on a device.

GPIO pins can have their state read and written to.

This provides the standard set of features supported across all hardware for GPIO pins. Hardware specific features are not included. This interface should be used for the majority of cases and should only be deviated from when there is a need for hardware specific functionality.

NOTE: You cannot directly make an instance of this class via a constructor. To make an instance, use the GPIO::getInstance method.

Subclassed by EVT::core::IO::GPIOf302x8

Public Types

enum State

Binary representation of the states the GPIO can be in.

Values:

enumerator LOW
enumerator HIGH
enum Direction

Binary representation of the flow of information, either input or output.

Values:

enumerator INPUT
enumerator OUTPUT
enum TriggerEdge

Enum to handler the possible GPIO trigger states.

Values:

enumerator RISING
enumerator FALLING
enumerator RISING_FALLING

Public Functions

GPIO(Pin pin)

Create a new GPIO interface on a specific pin.

The direction will not be set and will have to be set manually.

Parameters

pin[in] – The pin for the GPIO instance to use.

GPIO(Pin pin, Direction direction)

Create a new GPIO instance on a specific pin with a given direction.

Parameters
  • pin[in] – The pin for the GPIO instance to use.

  • direction[in] – The directional flow of data.

virtual void setDirection(Direction direction) = 0

Set the direction of the pin.

Parameters

direction[in] – The direction of information.

virtual void writePin(State state) = 0

Used for writing a state to a pin.

Parameters

state[in] – The state to write to the pin

virtual State readPin() = 0

Used for reading the state of a pin.

Returns

The state of the pin.

virtual void registerIRQ(TriggerEdge edge, void (*irqHandler)(GPIO *pin)) = 0

Registers the IRQHandler for this instances GPIO pin on the given edge condition.

Parameters
  • edge[in] – The edge trigger event to trigger the interrupt

  • irqHandler[in] – The function pointer to handle the GPIO interrupt

I2C

class EVT::core::IO::I2C

Subclassed by EVT::core::IO::I2Cf302x8

Public Functions

I2C(Pin sclPin, Pin sdaPin)

Make an instance of an I2C interface that will use the given pins for clock and data lines.

Parameters
  • sclPin[in] – The clock pin

  • sdaPin[in] – The data pin

virtual void write(uint8_t addr, uint8_t byte) = 0

Write a single byte out over I2C.

Parameters
  • addr[in] – The 7 bit unshifted I2C address to write to

  • byte[in] – The value to write over I2C.

virtual uint8_t read(uint8_t addr) = 0

Read a single byte back from the I2C bus.

Parameters

addr[in] – The 7 bit unshifted I2C address to read from.

Returns

The byte read from the address.

void write(uint8_t addr, uint8_t *bytes, uint8_t length)

Write out multiple bytes over I2C.

Each byte will be written one by one.

Parameters
  • addr[in] – The 7 bit unshifted I2C address to write to.

  • bytes[in] – The bytes to write out over I2C.

  • length[in] – The number of bytes to write out.

void read(uint8_t addr, uint8_t *bytes, uint8_t length)

Read multiple bytes from an I2C device.

Parameters
  • addr[in] – The 7 bit unshifted I2C address to write to

  • bytes[out] – The buffer to fill with the read in bytes.

  • length[in] – The number of bytes to read.

void writeReg(uint8_t addr, uint8_t reg, uint8_t byte)

Write a value to a register has that 8 bit addresses and 8 bit values.

Parameters
  • addr – The 7 bit unshifted I2C address to write to.

  • reg – The 8 bit register

  • byte – The byte to write out

uint8_t readReg(uint8_t addr, uint8_t reg)

Read a value from a register that has an 8 bit address and 8 bit value.

Parameters
  • addr[in] – The 7 bit unshifted I2C address to read from.

  • reg[in] – The 8 bit register

Returns

The 8 bit value of the register.

void writeReg(uint8_t addr, uint8_t *reg, uint8_t regLength, uint8_t *bytes, uint8_t length)

Write out a multi byte register value.

Parameters
  • addr[in] – The 7 bit unshifted I2C address to write to

  • reg[in] – The register bytes

  • regLength[in] – The number of bytes in the register address

  • bytes[in] – The data to write out

  • length[in] – The number of bytes in the data

void readReg(uint8_t addr, uint8_t *reg, uint8_t regLength, uint8_t *bytes, uint8_t length)

Read a value from a register.

Parameters
  • addr[in] – The 7 bit unshifted I2C address to read from.

  • reg[in] – The bytes containing the register to read from

  • regLength[in] – The size in bytes of the register

  • bytes[out] – The bytes read from the register

  • length[in] – The size of the data returned by the register in bytes

PWM

class EVT::core::IO::PWM

Subclassed by EVT::core::IO::PWMf302x8

Public Functions

PWM(Pin pin)

Setup the given pin for PWM usage.

Parameters

pin[in] – The pin to setup for PWM

virtual void setDutyCycle(float dutyCycle) = 0

Set the duty cycle for the pin to operate at.

Parameters

dutyCycle[in] – Duty cycle to set the pin to.

virtual void setPeriod(float period) = 0

Set the period for the PWM in seconds.

Parameters

period[in] – The period of the PWM in seconds.

virtual float getDutyCycle() = 0

Get the current duty cycle.

Returns

The duty cycle the PWM is operating at.

virtual uint32_t getPeriod() = 0

Get the current period.

Returns

The period the PWM is operating at in seconds.

UART

class EVT::core::IO::UART

Interface for UART operations.

The UART has the ability for character and byte centered operations.

This provides the standard set of features that are shared across all UART modules. Hardware specific features are not included.

The UART modules support both character and byte oriented transmit and receive operations. While fundametally these operations are the same, semantically this makes working with character cetered data and byte centered data cleaner.

NOTE: You cannot directly make an instance of this class via a constructor. To make an isntance, use the UART::getInstance method.

Subclassed by EVT::core::IO::UARTf302x8

Public Types

enum Parity

Represents the options for the parity settings that may be used when setting up a UART.

Values:

enumerator NONE
enumerator ODD
enumerator EVEN
enumerator MASK
enumerator SPACE
enum WordLength

Represents the possible lengths of words that can exist for UART.

Values:

enumerator FIVE
enumerator SIX
enumerator SEVEN
enumerator EIGHT
enum NumStopBits

Represents the number of stop bits that are used.

Values:

enumerator ONE
enumerator TWO

Public Functions

UART(Pin txPin, Pin rxPin, uint32_t baudrate)

Creates a new UART instance that will have the given TX and RX pins as well as the given baud rate.

Parameters
  • txPin[in] – The UART TX pin.

  • rxPin[in] – The UART RX pin.

  • baudrate[in] – The baudrate to operate the UART with.

virtual void setBaudrate(uint32_t baudrate) = 0

Set the baudrate that the UART will operate with.

Parameters

baudrate[in] – The new baudrate to use

virtual void setFormat(WordLength wordLength = WordLength::EIGHT, Parity parity = Parity::NONE, NumStopBits numStopBits = NumStopBits::ONE) = 0

Set the format that data will be communicated with over UART.

DEFAULT: 8 bit words, no parity, 1 stop bit

Parameters
  • wordLength[in] – The number of bits in a work (5-8)

  • parity[in] – The parity settings to use.

  • numStopBits[in] – The number of stop bits (1-2)

virtual void sendBreak() = 0

Sends a serial break condition over UART.

virtual bool isReadable() = 0

Determins if the UART is currently readable.

Returns

True if the UART is readable.

virtual bool isWritable() = 0

Determins if the UART is currently writable.

Returns

True if the UART is writable

virtual void putc(char c) = 0

Put a single character to the UART module.

Parameters

c[in] – The character to send over UART.

virtual void puts(const char *s) = 0

Put a null-terminal string out over UART.

Parameters

s[in] – The null-terminated string to put over UART.

virtual char getc() = 0

Blocking call to read a single character from the UART module.

Returns

The character read in over UART.

char *gets(char *buf, size_t size)

Blocking call to get a string from the UART module.

Stops when a newline or EOF character is received or if the maximum size is reached.

Parameters
  • buf – The character array to fill

  • size – The maximum number of characters to read.

Returns

The buf pointer on success, NULL otherwise

virtual void printf(const char *format, ...) = 0

Print a formatted string over UART, not great performance so best in test situations not production.

Parameters

format – The format string to print out.

virtual void write(uint8_t byte) = 0

Write out a single byte over UART.

Parameters

byte[in] – The byte to write out over UART.

virtual uint8_t read() = 0

Blocking reading of a single byte from the UART.

Returns

The byte read in from UART.

virtual void writeBytes(uint8_t *bytes, size_t size) = 0

Write an arbitrary number of bytes out over UART.

Parameters
  • bytes[in] – The data to send out over UART

  • size[in] – The number of bytes to send out over UART.

virtual void readBytes(uint8_t *bytes, size_t size) = 0

Blocking reading of an arbitrary number of bytes in over UART.

Parameters
  • bytes[out] – The data buffer to fill

  • size[in] – The number of bytes to read in.

Types

CANMessage

class EVT::core::IO::CANMessage

Represents a generic CAN message which can be sent and received over a CAN bus.

Public Functions

CANMessage(uint32_t id, uint8_t dataLength, uint8_t *payload)

Create an instance of a CANMessage.

Parameters
  • id[in] – The id of the CAN Message

  • dataLength[in] – The size of the payload (<= CAN_MAX_PAYLOAD_SIZE)

  • payload[in] – The data in the CAN message

CANMessage()

Create an empty CANMessage, the id will be 0, dataLength will be 0 and the payload will be empty.

uint32_t getId()

Get the id of the CAN message.

Returns

id of the specific CAN message

uint8_t getDataLength()

Get the size of the payload in bytes.

Returns

The size of the payload in bytes.

uint8_t *getPayload()

Get the pointer to the payload.

Returns

pointer to the payload.

void setId(uint32_t id)

Set the id of the CAN Message.

Parameters

id[in] – The id of the CAN message

void setDataLength(uint8_t size)

Set the size of the payload in bytes.

Parameters

size[in] – The size of the payload in bytes

void setPayload(const uint8_t *payload)

Set the payload to the contents of the provided array.

Does a copy of the bytes stored.

NOTE: Will copy over CAN_MAX_PAYLOAD_SIZE number of bytes over

Parameters

payload[in] – The payload to copy over

CANMessage &operator=(const CANMessage &other)

Assignment operator where the contents of the CANMessage is copied into this message.

Parameters

other – The CANMessage to copy from

Public Static Attributes

static constexpr uint8_t CAN_MAX_PAYLOAD_SIZE = 8

Represents the maximum payload size of a CAN message.

Platform Implementations

Platform

Platform represents the microcontroller that the code is running on. Platform specific code such as system setup is included here. For example, placing the microcontroller into a “low power mode” is specific to the microcontroller itself.

Utils

Utilities refer to software utilities that make development easier. These can be used to reduce duplicated code, abstract common tasks, or handle functionality that is very common across platforms such as having the system wait for a number of seconds.

Time

namespace EVT::core::time

The functions defined in here are used for time based operations.

All operations are platform independent.

Functions

void wait(uint32_t ms)

Function to have the program hold for a set amount of time before continuing.

Parameters

ms – The number of milliseconds to wait for

struct TimeStamp
#include <time.hpp>

Struct representing a timestamp.

Public Members

uint16_t year

The current year.

uint8_t month

The current month (1-12)

uint8_t day

The current day (1-31)

uint8_t hour

The hour in a 24 hour timeframe.

uint8_t minute

The minute (0-59)

uint8_t second

The second (0-59)