Summary

  • namespaceapi Application Programming Interface.
  • namespacecalc Standard Calculation and Software Routines.
  • namespacechrono Chrono (managing time, timers and clocks)
  • namespacedraw Drawing Graphics.
  • namespacedsp Digital Signal Processing.
  • namespaceev Events.
  • namespacefmt File Formats.
  • namespacehal Hardware Abstraction Layer.
  • namespaceinet Internet Namespace.
  • namespacesgfx Classes for Stratify Graphics library.
  • namespacesm State Machine.
  • namespacesys System Access (POSIX wrappers)
  • namespacetest Test framework.
  • namespaceui User Interface.
  • namespacevar Data Management.

namespace api

The api namespace contains all top level objects. All objects inherit from api::ApiObject. Below api::ApiObject this is api::ApiWorkObject and api::ApiInfoObject.

Work objects include an error number and are the base for objects that do work and make system calls.

Info objects are used for storing and managing static data structures. They don't make system calls and can't store errors. Info objects also include classes with only static methods.

Diagrams

To see a top level inheritance diagram of the entire API see api::ApiObject.

For work objects only, see api::WorkObject.

For info object only, see api::InfoObject.

Classes

class api::ApiInfo

Provides inforamation abou the API library.

class api::ApiObject

The API Object class is the parent of all other classes. The API namespace contains two other classes that inherit this object

InfoObject is for classes that are used to access static data and don't do any work or have the potential to have errors. InfoObjects also include classes that consist purely of static methods and members.

WorkObject has an interface to setting the error and issuing a fatal exit if a fatal error occurs.

All object in the API inherit either InfoObject or WorkObject.

class api::CalcInfoObject

See also: calc namespace

class api::CalcWorkObject

See also: calc namespace

class api::ChronoInfoObject

See also: chrono namespace

class api::ChronoWorkObject

See also: chrono namespace

class api::DrawInfoObject

See also: draw namespace

class api::DrawWorkObject

See also: draw namespace

class api::DspInfoObject

See also: dsp namespace

class api::DspWorkObject

See also: dsp namespace

class api::EvInfoObject

See also: ev namespace

class api::EvWorkObject

See also: ev namespace

class api::FmtFileObject

This class is for format object that inherit sys::File.

See also: fmt namespace

class api::FmtInfoObject

See also: fmt namespace

class api::FmtWorkObject

See also: fmt namespace

class api::HalInfoObject

Hal Objects for storing information like device attributes, device information and pin assignment structures.

See also: hal namespace

class api::HalWorkObject

The Hal Work Object class is the parent of all Hal objects.

See also: hal namespace

class api::InetInfoObject

See also: inet namespace

class api::InetWorkObject

See also: inet namespace

class api::InfoObject

Classes that inherit from information objects are used for static data storage and access. They don't do any work that could cause errors.

See also: api::WorkObject

Methods

Details

public inline virtual u32info_size() const


public inline virtual void *info_to_void()


public inline virtual const void *info_to_void() const


class api::SgfxInfoObject

See also: sgfx namespace

class api::SgfxObject

class api::SgfxWorkObject

The Sgfx Object Class is the parent class of all work objects in the sgfx namespace.

See also: sgfx namespace

class api::SmInfoObject

See also: sm namespace

class api::SmWorkObject

See also: sm namespace

class api::SysInfoObject

See also: sys namespace

class api::SysWorkObject

See also: sys namespace

class api::TestInfoObject

See also: test namespace

class api::TestWorkObject

See also: test namespace

class api::UiInfoObject

See also: ui namespace

class api::UiWorkObject

See also: ui namespace

class api::VarInfoObject

See also: var namespace

class api::VarWorkObject

See also: var namespace

class api::WorkObject

The WorkObject is the base object for all work classes in the Stratify API.

It is a simple object that allows the inheriting class to set an error or halt the program if it encouters a fatal problem.

It is used as the base of objects that make system calls so that the error generated by the system can be reported through the object.

See also: api::InfoObject

Methods

Details

publicWorkObject()


public inline voidclear_error_number() const

Clears the current error.


public inline interror_number() const

Returns the error number.

If the error number is zero. There is no error.

If the error number is greater than zero. It indicates an error indicator from the standard C library (such as ENOENT).

If the error number is less than zero, it refers to a StratifyAPI defined error like ERROR_NONE.


protected inline voidset_error_number(int value) const


protected intset_error_number_if_error(int ret) const


protected void *set_error_number_if_null(void * ret) const


protected voidset_error_number_to_errno() const


enum@0

  • ERROR_NONE No Errors

namespace calc

Classes

class calc::Base64

This class includes methods to encode and decode data using the base64 algorithm. Base64 is useful for representing binary data using text characters. This can be useful when transmitting data over certain serial links that do not support binary transfers.

To encode data in Base 64 format use this code:

#include <sapi/calc.hpp>

u8 raw_data[64]; //raw binary data that needs to be encoded
char * encoded_data;
int encoded_size;

encoded_size = Base64::calc_encoded_size(64);
encoded_data = malloc(encoded_size);
Base64::encode(encoded_data, raw_data, 64);

You can then decode the data using this code snippet:

#include <sapi/calc.hpp>

char encoded_data[64]; //Base64 encoded data that needs to be decoded
u8 * raw_data;
int decoded_size;

decoded_size = Base64::calc_decoded_size(64);
raw_data = malloc(decoded_size);
Base64::decode(raw_data, encoded_data, 64);

class calc::Checksum

The Checksum class is purely static and provides methods for calculating and verifying checksums on data structures.

class calc::Ema

This class is a template for an exponential moving average (EMA) calculation. The EMA is a type of low pass filter and is helpful when trying to smooth out data that is sampled on the ADC.

The following is an example of using the Ema class using 32-bit integers.

#include <sapi/hal.hpp>
#include <sapi/calc.hpp>
#include <cstdio>

 //first initialize a filter with a value of 0 and with an averaging constant of 0.1
Ema_s32 filter(0, DSP_EMA_I32_ALPHA(0.1));
 //Or do:  Ema<u16, s32, s64> filter(0, DSP_EMA_I32_ALPHA(0.1));

 //now use the ADC to get some data
Adc adc(0);
adc_sample_t sample;
adc.init(1<<0); //initialize with channel 0 enabled

for(i=0; i < 100; i++){  //take 100 samples and filter as we go
   adc.read(0, &sample, sizeof(sample));
   filter.calc(sample);
   printf("%d %d %d;\n", i, sample, filter.avg());
}

The filter is easy-to-use and uses minimal resources. For more information on EMA filtering see this wiki article.

Methods

  • public inlineEma(intmedium start,intsmall alpha) Constructs a new Ema object.
  • public inline intmediumaverage() const
  • public inline intmediumcalc(intmedium in)
  • public inline intmediumcalculate(intmedium in) Calculates the next average using an input value.
  • public inline intmediumpresent_value() const Accesses the current average (no calculations are made here).
  • public inline voidset_average(intmedium v) Sets the average value.

Details

public inlineEma(intmedium start,intsmall alpha)

Constructs a new Ema object.

Parameters * start Initial value

  • alpha Averaging value

public inline intmediumaverage() const


public inline intmediumcalc(intmedium in)


public inline intmediumcalculate(intmedium in)

Calculates the next average using an input value.

Parameters * in Input value

Returns

The updated average (same as average())


public inline intmediumpresent_value() const

Accesses the current average (no calculations are made here).

Returns

The current average value


public inline voidset_average(intmedium v)

Sets the average value.

Parameters * v The new initial value

This method can also be used to set the initial value.


class calc::Ema_f

See Ema for details

Methods

  • public inlineEma_f(float start,float alpha) Constructs a EMA object for floating point calculations
  • public inline floataverage() const
  • public inline floatavg() const
  • public inline floatcalc(float in)
  • public inline floatcalculate(float in) Calculates the next value based on the given input
  • public inline floatpresent_value() const Accesses the present value of the filter.
  • public inline voidset(float v)
  • public inline voidset_average(float v)
  • public inline voidset_present_value(float v) Sets the present value of the filter.

Details

public inlineEma_f(float start,float alpha)

Constructs a EMA object for floating point calculations


public inline floataverage() const


public inline floatavg() const


public inline floatcalc(float in)


public inline floatcalculate(float in)

Calculates the next value based on the given input


public inline floatpresent_value() const

Accesses the present value of the filter.


public inline voidset(float v)


public inline voidset_average(float v)


public inline voidset_present_value(float v)

Sets the present value of the filter.


class calc::Ema_s16

See Ema for details

Methods

  • public inlineEma_s16(s16 start,u8 alpha) Construct a EMA object for a signed 16 bit calculations

Details

public inlineEma_s16(s16 start,u8 alpha)

Construct a EMA object for a signed 16 bit calculations


class calc::Ema_s32

See Ema for details

Methods

  • public inlineEma_s32(s32 start,u16 alpha) Construct a EMA object for a signed 32 bit calculations

Details

public inlineEma_s32(s32 start,u16 alpha)

Construct a EMA object for a signed 32 bit calculations


class calc::Ema_u16

See Ema for details

Methods

  • public inlineEma_u16(u16 start,u8 alpha) Construct a EMA object for a unsigned 16 bit calculations

Details

public inlineEma_u16(u16 start,u8 alpha)

Construct a EMA object for a unsigned 16 bit calculations


class calc::Ema_u32

See Ema for details

Methods

  • public inlineEma_u32(u32 start,u16 alpha) Construct a EMA object for a unsigned 32 bit calculations

Details

public inlineEma_u32(u32 start,u16 alpha)

Construct a EMA object for a unsigned 32 bit calculations


class calc::HighPassFilterF32

See LowPassFilter for details

Methods

  • publicHighPassFilterF32(float start,float r_value) Constructs a EMA object for floating point calculations
  • public floatcalculate(float input)
  • public voidreset(float start) Resets the filter to the given start value.
  • public voidset_r_value(float r_value)

Details

publicHighPassFilterF32(float start,float r_value)

Constructs a EMA object for floating point calculations


public floatcalculate(float input)


public voidreset(float start)

Resets the filter to the given start value.


public voidset_r_value(float r_value)


class calc::Lookup

This class is for implementing lookup tables using linear extrapolation.

#include <sapi/calc.hpp>

#define ENTRIES 4

const float lookup_table[ENTRIES*2] = {  //for each entry there are 2 float values
   0.0, 2.0,  //this is an x,y pair where x is 0.0 and y is 2.0, list must have x values in ascending order
   1.0, 4.0,
   2.0, 16.0,
   3.0, 25.0
};

float lookup_value(float x){
   Lookup<float> lookup(lookup_table, ENTRIES);
   return lookup.calc_value(x);
}

Methods

  • public inlineLookup(const T * table,int size) Constructs a lookup table object.
  • public inline Tcalc_value(T x) Calculates the y value using linear interpolation.

Details

public inlineLookup(const T * table,int size)

Constructs a lookup table object.

Parameters * table A pointer to a table with x and y values alternating, x values must be in ascending order

  • size The number of x,y entries in the table

public inline Tcalc_value(T x)

Calculates the y value using linear interpolation.

Parameters * x Input value

Returns

y Value calculated using linear interpolation


class calc::LowPassFilter

This class is a template for a simple low pass filter (also known as an exponential moving average) calculation.

The following is an example of using the Ema class using 32-bit integers.

#include <sapi/hal.hpp>
#include <sapi/calc.hpp>
#include <cstdio>

 //first initialize a filter with a value of 0 and with an averaging constant of 0.1
LowPassFilterS32 filter(0, LOW_PASS_FILTER_S32_ALPHA(0.1));
 //Or do:  LowPassFilter<u16, s32, s64> filter(0, LOW_PASS_FILTER_S32_ALPHA(0.1));

 //now use the ADC to get some data
Adc adc(0);
adc_sample_t sample;
adc.init(1<<0); //initialize with channel 0 enabled

for(i=0; i < 100; i++){  //take 100 samples and filter as we go
   adc.read(0, &sample, sizeof(sample));
   filter << sample;
   printf("%d %d %d;\n", i, sample, filter.present_value());
}

For more information on this filter see this wiki article.

Methods

  • public inlineLowPassFilter(intmedium start,intsmall alpha) Constructs a new Ema object.
  • public inline intmediumaverage() const
  • public inline intmediumcalculate(intmedium in) Calculates the next average using an input value.
  • public inline intmediumpresent_value() const Accesses the current average (no calculations are made here).
  • public inline voidset_average(intmedium v) Sets the average value.

Details

public inlineLowPassFilter(intmedium start,intsmall alpha)

Constructs a new Ema object.

Parameters * start Initial value

  • alpha Averaging value

public inline intmediumaverage() const


public inline intmediumcalculate(intmedium in)

Calculates the next average using an input value.

Parameters * in Input value

Returns

The updated average (same as average())


public inline intmediumpresent_value() const

Accesses the current average (no calculations are made here).

Returns

The current average value


public inline voidset_average(intmedium v)

Sets the average value.

Parameters * v The new initial value

This method can also be used to set the initial value.


class calc::LowPassFilterF32

See LowPassFilter for details

Methods

  • publicLowPassFilterF32(float start,float alpha) Constructs a EMA object for floating point calculations
  • public floatcalculate(float in)
  • public voidreset(float start)

Details

publicLowPassFilterF32(float start,float alpha)

Constructs a EMA object for floating point calculations


public floatcalculate(float in)


public voidreset(float start)


class calc::LowPassFilterS16

See Ema for details

Methods

  • public inlineLowPassFilterS16(s16 start,u8 alpha) Construct a EMA object for a signed 16 bit calculations

Details

public inlineLowPassFilterS16(s16 start,u8 alpha)

Construct a EMA object for a signed 16 bit calculations


class calc::LowPassFilterS32

See Ema for details

Methods

  • public inlineLowPassFilterS32(s32 start,u16 alpha) Construct a EMA object for a signed 32 bit calculations

Details

public inlineLowPassFilterS32(s32 start,u16 alpha)

Construct a EMA object for a signed 32 bit calculations


class calc::LowPassFilterU16

See Ema for details

Methods

  • public inlineLowPassFilterU16(u16 start,u8 alpha) Construct a EMA object for a unsigned 16 bit calculations

Details

public inlineLowPassFilterU16(u16 start,u8 alpha)

Construct a EMA object for a unsigned 16 bit calculations


class calc::LowPassFilterU32

See Ema for details

Methods

  • public inlineLowPassFilterU32(u32 start,u16 alpha) Construct a EMA object for a unsigned 32 bit calculations

Details

public inlineLowPassFilterU32(u32 start,u16 alpha)

Construct a EMA object for a unsigned 32 bit calculations


class calc::Pid_f

This class implements a PID control loop using floating point values.

A PID control loop uses three constant values in order to calculate a control variable such that the input converges on the target variable.

The following terminology is used in this documentation.

  • kp: Proportional constant

  • ki: Integral constant

  • kd: Differential constant

  • present value: the current value of the system output

  • target variable: desired output value of the system

  • control variable: calculated value to apply such that the input tends to the target variable

  • error variable: the error variable is the difference between the target variable and the present value

An example for using a PID control loop is temperature control. Consider a system that uses a PWM value to heat an element and a temperature sensor to read the output. The above terminology is applied as follows:

  • kp: Value selected by the developer to tune the control loop

  • ki: Value selected by the developer to tune the control loop

  • kd: Value selected by the developer to tune the control loop

  • present value: the value of the temperature sensor output

  • target variable: the desired temperature sensor output

  • control variable: the PWM duty cycle that should be applied to the heater

  • error variable: the different between the desired temperature output and the present temperature output

#include <sapi/calc.hpp>
#include <sapi/hal.hpp>

Pid_f pid_loop;
Pwm control(0);
Adc present_value(0);
u16 adc_value;

volatile bool is_active = true;

pid_loop.set_kp(1.0);
pid_loop.set_ki(0.1);
pid_loop.set_kd(0.001);
pid_loop.set_maximum(1000); //max duty cycle
pid_loop.set_minimum(0); //min duty cycle

 //Init the PWM output and ADC input

while( is_active ){
 present_value.read(0, &adc_value, 2);
control.set_duty( pid_looop.calc_control_variable( 3.3 * adc_value / 4096 ) );
}

Methods

  • publicPid_f(float target,float kp,float ki,float kd,float min,float max) Constructs a new PID (float) object.
  • public floatcalc_control_variable(float present_value) Calculates the control variable based on the current state of the system.
  • public inline floatcalc_value(float present_value)
  • public inline floatkd() const Returns the differential constant.
  • public inline floatki() const Returns the integral constant.
  • public inline floatkp() const Returns the proportional constant.
  • public inline floatmax() const Returns the maximum value for the control variable.
  • public inline floatmin() const Returns the minimum value for the control variable.
  • public voidreset() Resets the state of the PID control loop.
  • public inline voidset_kd(float v) Sets the differential constant value.
  • public inline voidset_ki(float v) Sets the integral constant value.
  • public inline voidset_kp(float v) Sets the proportional constant value.
  • public inline voidset_max(float v) Sets the maximum allowed value of the target variable.
  • public inline voidset_min(float v) Sets the minimum allowed value of the target variable.
  • public inline voidset_target(float v) Sets the value for the target variable.
  • public inline floattarget() const Returns the target variable.

Details

publicPid_f(float target,float kp,float ki,float kd,float min,float max)

Constructs a new PID (float) object.

Parameters * target The target value

  • kp The proportional constant

  • ki The integral constant

  • kd The differential constant

  • min The minimum value for the calculated control value

  • max The maximum value for the calculated control value


public floatcalc_control_variable(float present_value)

Calculates the control variable based on the current state of the system.

Parameters * present_value The present value of the system

Returns

The updated control variable to be applied to the system


public inline floatcalc_value(float present_value)


public inline floatkd() const

Returns the differential constant.


public inline floatki() const

Returns the integral constant.


public inline floatkp() const

Returns the proportional constant.


public inline floatmax() const

Returns the maximum value for the control variable.


public inline floatmin() const

Returns the minimum value for the control variable.


public voidreset()

Resets the state of the PID control loop.


public inline voidset_kd(float v)

Sets the differential constant value.


public inline voidset_ki(float v)

Sets the integral constant value.


public inline voidset_kp(float v)

Sets the proportional constant value.


public inline voidset_max(float v)

Sets the maximum allowed value of the target variable.


public inline voidset_min(float v)

Sets the minimum allowed value of the target variable.


public inline voidset_target(float v)

Sets the value for the target variable.


public inline floattarget() const

Returns the target variable.


class calc::Rle

This class implements Run length encoding and decoding algorithms.

Methods

Details

publicRle()


class calc::RleAppfs

Methods

  • publicRleAppfs()
  • public intread(void * buf,int nbyte) Reads and decodes data from a file.
  • public intwrite(const void * buf,int nbyte) Encodes then writes the data to a file.

Details

publicRleAppfs()


public intread(void * buf,int nbyte)

Reads and decodes data from a file.

Parameters * buf A pointer to the destination memory

  • nbyte The number of bytes to read

Returns

The number of bytes read after decoding


public intwrite(const void * buf,int nbyte)

Encodes then writes the data to a file.

Parameters * buf The source data

  • nbyte The number of bytes to encode and write

Returns

The number of un-encoded bytes that were written


class calc::RleFile

Methods

  • public intread(void * buf,int nbyte) Reads from a file then decodes data.
  • public intwrite(const void * buf,int nbyte) Encodes using run length encoding and writes the data to a file.

Details

public intread(void * buf,int nbyte)

Reads from a file then decodes data.

Parameters * buf A pointer to the destination memory

  • nbyte The maximum number of bytes to read

Returns

The number of bytes read after decoding


public intwrite(const void * buf,int nbyte)

Encodes using run length encoding and writes the data to a file.

Parameters * buf The source data

  • nbyte The number of bytes to encode and write

Returns

The number of un-encoded bytes that were written


class calc::SimpleFilter

Methods

  • public inlineSimpleFilter()
  • public Tcalculate(T a) Calculates the next value based on the given input and returns the new average value.
  • public inline C &operator<<(T a) Calculates the next value and returns a reference to this object.
  • public inline Tpresent_value() const Returns a copy of the present value.
  • public inline voidset_present_value(const T & value) Sets the present value of the filter.
  • protected Tm_present_value

Details

public inlineSimpleFilter()


public Tcalculate(T a)

Calculates the next value based on the given input and returns the new average value.


public inline C &operator<<(T a)

Calculates the next value and returns a reference to this object.


public inline Tpresent_value() const

Returns a copy of the present value.


public inline voidset_present_value(const T & value)

Sets the present value of the filter.


protected Tm_present_value


namespace chrono

The chrono namespace includes the following time-measurement objects.

  • MicroTime: 32-bit value for microseconds

  • ClockTime: 64-bit value for seconds and nanoseconds (clock as in CPU clock)

  • Time: 32-bit value in seconds (basically a time_t object)

The parent object for all chrono items is api::ChronoWorkObject or api::ChronoInfoObject. Both of the top level objects provide a way to insert a static delay.

#include <sapi/chrono.hpp>

Timer::wait_seconds(1); //wait for one second -- Timer inherits ChronoWorkObject so it can use the wait methods statically
Timer::wait_milliseconds(100);
Timer::wait_microseconds(100);

ClockTime clock_time;
Timer::wait(clock_time); //wait based on a clock time value

MicroTime micro_time;
micro_time.set_milliseconds(100);
Timer::wait(micro_time); //wait based on a micro time value

Time time(3, 2, 1); //3 seconds, 2 minutes, 1 hour
Timer::wait(time); //waits for 3 + 2*60 + 1*3600 seconds -- days, months, years are ignored

Classes

class chrono::Clock

The clock class is used for reading the system CPU clocks.

It reads out a chrono::ClockTime object which is a 64-bit value with seconds and nanoseconds based on struct timeval.

Methods

Details

enum@2


class chrono::ClockTime

The ClockTime class is a helper class for using struct timespec times. This is a 64-bit time with a 32-bit seconds element and a 32-bit nanoseconds element.

Methods

Details

public inlineClockTime(s32 seconds,s32 nanoseconds)

Constructs a MicroTime object using a u32 value.

The default initial value is zero.


public inlineClockTime(const structtimespec& nano_time)

Constructs a clock time object based on the timespec.


publicClockTime(constMicroTime& micro_time)

Contructs an object from a micro time object.


public inlineClockTime()

Constructs a zero value ClockTime object.


publicClockTimeage() const


public inline boolis_valid() const

Returns true if the time is set to a valid value.


public inline s32nanoseconds() const

Returns the nanoseconds component.


public booloperator !=(constClockTime& a) const

Returns true if this is not equal to a.


public inlineClockTimeoperator -(constClockTime& a) const

Returns the difference of this object and a.


public inlineClockTime&operator -=(constClockTime& a)

Subracts from this and assigned to this.


public booloperator >(constClockTime& a) const

Returns true if this is greater than a.


public booloperator >=(constClockTime& a) const

Returns true if this is greater than or equal to a.


public inlineoperator const struct timespec *() const

Returns a pointer to the struct timespec.

This allows the object to be passed directly to functions that required a pointer to struct timespec (read-only)


public inlineoperator struct timespec *()

Returns a pointer to the struct timespec.

This allows the object to be passed directly to functions that required a pointer to struct timespec (read-write)


public inlineClockTimeoperator+(constClockTime& a) const

Returns the sum of this object and a.


public inlineClockTime&operator+=(constClockTime& a)

Adds to this and assigned to this.


public booloperator<(constClockTime& a) const

Returns true if this is less than a.


public booloperator<=(constClockTime& a) const

Returns true if this is less than or equal to a.


public booloperator==(constClockTime& a) const

Returns true if this is equal to a.


public inline voidreset()

Resets the value of the clock to zero.


public inline s32seconds() const

Returns the seconds component.


public inline voidset(s32 seconds,s32 nanoseconds)

Sets the value of the clock.

Parameters * seconds The seconds value

  • nanoseconds The nanosecond value

public inline struct timespec *timespec()

Returns a pointer to a strut timespec.


public inline const struct timespec *timespec() const

Returns a pointer to a strut timespec (read-only).


class chrono::MicroTime

The MicroTime class is used for keeping track of microsecond accurate time intervals. It uses a 32-bit value so it is good for 4B microseconds (or about 66 minutes).

It is very handy for converting between microseconds, milliseconds, and seconds. It also serves to remove ambiguity when specifying short time intervals.

For example:

void set_period(const MicroTime & micro_time); //un-ambiguous and nice code completion
void set_period(u32 value); //the units here are not clear
void set_period_milliseconds(u32 value); //this is better but adds complexity

Methods

Details

public inline explicitMicroTime(u32 microseconds)

Constructs a MicroTime object using a u32 value.

The default initial value is zero.


public inlineMicroTime(constClockTime& clock_time)


publicMicroTime(constTimer& timer)


public inline boolis_valid() const

Returns true if the time is set to a valid value.


public inlinemicro_time_tmicroseconds() const

Returns the value in microseconds.


public inline u32milliseconds() const

Returns the value in milliseconds.


public inline u32msec() const


public inline booloperator !=(constMicroTime& a) const


public inlineMicroTime&operator -=(constMicroTime& micro_time)


public inline booloperator >(constMicroTime& a) const


public inline booloperator >=(constMicroTime& a) const


public inlineMicroTime&operator+=(constMicroTime& micro_time)


public inline booloperator<(constMicroTime& a) const


public inline booloperator<=(constMicroTime& a)


public inline booloperator==(constMicroTime& a) const


public inline u32sec() const


public inline u32seconds() const

Returns the value in seconds.


public inline voidset_microseconds(micro_time_tmicroseconds)

Sets the value of the time in microseconds.

Parameters * microseconds The value in microseconds


public inline voidset_milliseconds(u32 msec)

Sets the value of the time in milliseconds.

Parameters * msec The value to assign in milliseconds.


public inline voidset_msec(u32 msec)


public inline voidset_sec(u32 sec)


public inline voidset_seconds(u32 sec)

Sets the value of the time in seconds.

Parameters * sec The number of seconds.


public inline voidset_usec(micro_time_tusec)


public inlinemicro_time_tusec() const


public inline voidwait() const

Waits for the value of the microtime.


class chrono::Time

This class is for accessing the current time as well as adding and subtracting times and dates.

The time is based on the value of the RTC in the system. The RTC will keep the same value even when the device is reset. This class should provide accurate access to the current data and time.

It holds a c style time_t value that can be managed which is a 32-bit value with accuracy to the second.

Time now; //current time
Time ten_minutes(0, 10, 0); //duration of 10 minutes

now += ten_minutes; //adds ten minutes to now

Methods

  • publicTime() Constructs using current time.
  • public inline explicitTime(const time_t & t)
  • publicTime(u32 sec,u32 min,u32 hour) Constructs using an amount of time.
  • public inlineTimeage() const
  • public u32day() const Returns the day of month (from 1 to 31).
  • public struct tmget_tm() const Converts the time to a struct tm.
  • public u32hour() const Returns hours (from 0 to 23).
  • public inline boolis_valid()
  • public u32minute() const Returns minutes (from 0 to 59).
  • public u32month() const Returns the month (from 1 to 12).
  • public constvar::ConstStringmonth_name() const Gets the name of the month.
  • public inline booloperator !=(constTime& a) const
  • public inlineTimeoperator -(constTime& a) const
  • public inline booloperator >(constTime& a) const
  • public inline booloperator >=(constTime& a) const
  • public inlineTimeoperator+(constTime& a) const
  • publicTime&operator+=(constTime& a) Adds to the current value.
  • publicTime&operator-=(constTime& a) Subtracts from the current value.
  • public inline booloperator<(constTime& a) const
  • public inline booloperator<=(constTime& a) const
  • publicTime&operator=(constTime& a) Assigns another Time.
  • publicTime&operator=(u32 a) Assigns another time value (time_t).
  • public inline booloperator==(constTime& a) const
  • public u32second() const Returns seconds (from 0 to 59).
  • public voidset_time(u32 sec,u32 min,u32 hour) Sets the value in Time to a number of seconds.
  • public inline voidset_time(time_t tm) Sets the current value.
  • public intset_time_of_day() Sets the system time to the time stored in this object.
  • public inline time_ttime() const Returns the time value (number of seconds since epoch).
  • public u32weekday() const Returns the day of week (from 1 to 7).
  • public u32year() const Returns the year (e.g. 2014)
  • public u32yearday() const Returns the day of the year (1 to 366).

Details

publicTime()

Constructs using current time.


public inline explicitTime(const time_t & t)


publicTime(u32 sec,u32 min,u32 hour)

Constructs using an amount of time.


public inlineTimeage() const


public u32day() const

Returns the day of month (from 1 to 31).


public struct tmget_tm() const

Converts the time to a struct tm.


public u32hour() const

Returns hours (from 0 to 23).


public inline boolis_valid()


public u32minute() const

Returns minutes (from 0 to 59).


public u32month() const

Returns the month (from 1 to 12).


public constvar::ConstStringmonth_name() const

Gets the name of the month.


public inline booloperator !=(constTime& a) const


public inlineTimeoperator -(constTime& a) const


public inline booloperator >(constTime& a) const


public inline booloperator >=(constTime& a) const


public inlineTimeoperator+(constTime& a) const


publicTime&operator+=(constTime& a)

Adds to the current value.


publicTime&operator-=(constTime& a)

Subtracts from the current value.


public inline booloperator<(constTime& a) const


public inline booloperator<=(constTime& a) const


publicTime&operator=(constTime& a)

Assigns another Time.


publicTime&operator=(u32 a)

Assigns another time value (time_t).


public inline booloperator==(constTime& a) const


public u32second() const

Returns seconds (from 0 to 59).


public voidset_time(u32 sec,u32 min,u32 hour)

Sets the value in Time to a number of seconds.

Parameters * hour Number of hours

  • min Number of minutes

  • sec Number of seconds

This Time object will hold a duration of time rather than a calendar time.


public inline voidset_time(time_t tm)

Sets the current value.

Parameters * tm Number of seconds since epoch


public intset_time_of_day()

Sets the system time to the time stored in this object.


public inline time_ttime() const

Returns the time value (number of seconds since epoch).


public u32weekday() const

Returns the day of week (from 1 to 7).


public u32year() const

Returns the year (e.g. 2014)


public u32yearday() const

Returns the day of the year (1 to 366).


class chrono::Timer

This class implements a logical timer based on the Stratify OS system timer.

Physical timers are controlled using the hal::Tmr class.

The Timer has the following states:

  • Reset: not running, not stopped

  • Running: running, not stopped

  • Stopped: not running, stopped

These methods are used to jump between states:

  • start(): start running if not already running

  • restart(): restart running from zero

  • stop(): stop running (if running)

  • resume(): resume counting after a stop

  • reset(): set to not running, not stopped, zero value

Here is an example of using the timer to time events.

#include <sapi/sys.hpp>

int main(int argc, char * argv[]){
   Timer t;
   t.start(); //start
   Timer::wait(500);
   t.stop();
   printf("Timer value after 500usec is %d\n", t.usec());

}

The output of the above code varies depending on the MCU clock cycles and the scheduler. The following is a sample output. Timer value after 500usec is 502

Methods

Details

publicTimer()

Constructs an empty Timer.


public inline u32calc_msec() const


public inline u32calc_sec() const


public inline u32calc_usec() const


publicClockTimeclock_time() const

Returns the value of the timer as a ClockTime object.


public inline boolis_reset() const

Returns true if the timer is in a reset state.


public inline boolis_running() const

Returns true if the timer is currently counting meaning it has been started but has not been stopped.

If the timer has been stopped and resumed, this method will return true;


public inline boolis_started() const

Returns true if the timer has been started.

It the timer has been started and stopped, this method will return true. If the timer has been reset() or never started, this method will return false.


public inline boolis_stopped() const

Returns true if the timer is stopped.

If the timer has not yet been started or has been reset(), this method will return true. If the timer is currently running, this method will return false.


public inline u32microseconds() const

Calculates the timer value in microseconds.

This is similar to calc_msec() but returns the value in microseconds rather than milliseconds.

Returns

The number of microseconds that have elapsed since start.


public inline u32milliseconds() const

Calculates the timer value in milliseconds.

Returns

The number of milliseconds that have elapsed since start. This value can be read when the timer is running to get a live value or after it has been stopped to get the time elapsed between start() and stop()


public inline u32msec() const


public inline booloperator !=(constchrono::MicroTime& a) const


public inline booloperator >(constchrono::MicroTime& a) const


public inline booloperator >=(constchrono::MicroTime& a) const


public inline booloperator<(constchrono::MicroTime& a) const


public inline booloperator<=(constchrono::MicroTime& a) const


public inline booloperator==(constchrono::MicroTime& a) const


public voidreset()

Resets the value of the timer.

After calling this method, is_running(), and is_started() will both all return false;


public voidrestart()

Restarts the timer.

If the timer is currently running, it starts over. If it is not running, it is started.


public voidresume()

Resumes counting after a stop().

If the timer is currently running this method has no effect. If the timer has not been started, this method will start the timer.


public inline u32sec() const


public inline u32seconds() const

Calculates the timer value in seconds.

This is similar to calc_msec() but returns the value in seconds rather than milliseconds.

Returns

The number of seconds that have elapsed since start.


public voidstart()

Starts the timer.

If the timer is currently running, this method has no effect. If the timer has been stopped, it will restart. Use resume() to resume running a stopped timer.


public voidstop()

Stops the timer from counting.

Subsequent calls to value() will return the same number. Once the timer has been stopped(), a call to resume() will resume counting and a call to start() or restart() will restart counting from zero.


public inline u32usec() const


namespace draw

The draw namespace contains classes used for drawing and animating objects. The classes are built on the sgfx namespace which provides an API for accessing the Stratify Graphics library.

The base object is a Drawing. Classes that inherit objects must implement one of two methods: draw() or draw_to_scale().

The draw() method will draw objects on an abstract drawing canvas with a width and height of DrawingAttr::scale() usually 1000.

The draw_to_scale() is ultimately called by the draw() method to draw directly on a hal::Display.

Classes

Details

publicdrawing_area_tdrawing_area(drawing_size_tw,drawing_size_th)

This returns a drawing_area_t populated with the width and height.

Parameters * w Width of the returned data

  • h Height of the retured data

Returns

A drawing_area_t with w and h populated as specified


publicdrawing_area_tdrawing_dim(drawing_size_tw,drawing_size_th)


publicdrawing_point_tdrawing_point(drawing_int_tx,drawing_int_ty)

This returns a drawing_point_t populated with x and y


class draw::Animation

Methods

Details

publicAnimation()

Constructs a new animation object.


publicAnimation(constAnimationAttr& attr)


public boolexec(void(*)(void *, int, int) draw,void * obj)

Executes the animation.

Parameters * draw A callback that is execute between each frame

  • obj The argument passed to the draw callback

The draw callback can be used to update the display. This will work best on areas of the screen that are not affected by the animation.


public voidinit(Drawing* current,Drawing* target,constDrawingAttr& attr)

Initializes the animation.

Parameters * current The current drawing

  • target The target drawing

  • attr The drawing attributes

If current is non-null it will be drawn on the visible screen when init() is called.

If target is non-null, it will be drawn on the scratch bitmap. Most animations will transition from the currentDrawing to the target drawing.

The drawing attributes (attr) will be used to define the starting point and dimensions of the animation attributes.


public voidreinit()


class draw::AnimationAttr

Methods

Details

publicAnimationAttr()

Constructs a new animation attribute object.


public inline sg_area_tarea() const

Accesses the animation's dimension (width and height from top-left corner).


public inline voidassign(constAnimationAttr& attr)


public inline sg_animation_t &attr()

Returns a reference to the attibutes.


public inline sg_animation_t *data()


public inlinedrawing_size_tdrawing_motion_total() const

Accesses the motion total in a drawing scale.


public inline u16frame_delay() const

Accesses the frame delay of the animation.


public inline sg_size_tmotion_total() const

Accesses the total motion (in pixels).


public inline u8path() const

Accesses the path (e.g. Animation::SQUARED).


public inline voidset_drawing_motion_total(drawing_size_tv)

Sets the total amount of motion as a ratio to the drawing scale.


public inline voidset_frame_delay(u16 value)

Sets the frame delay (in ms) of the animation.

Parameters * value The number of milliseconds to wait between frames.

The animation will at least wait the amount of time required to refresh the display. This delay will only have an effect if it is longer than the time required to update the display.


public inline voidset_motion_total(sg_size_t v)

Sets the total amount of motion (in pixels) of the animation.


public inline voidset_path(u8 v)

Sets the path (e.g. Animation::SQUARED).


public inline voidset_step_total(u8 v)

Sets the total number of steps in the animation.


public inline voidset_type(u8 v)

Sets the animation type (e.g. Animation::PUSH_DOWN).


public inline sg_point_tstart() const

Accesses the animation start point (top-left corner).


public inline u16step_total() const

Accesses the animation step total.


public inline u8type() const

Accesses the type (e.g. Animation::PUSH_DOWN).


enum@3

  • PUSH_LEFT Push Left
  • PUSH_RIGHT Push Right
  • PUSH_UP Push Up
  • PUSH_DOWN Push Down
  • SLIDE_LEFT Slide Left
  • UNDO_SLIDE_LEFT
  • SLIDE_UP Slide Up
  • UNDO_SLIDE_UP Undo Slide up
  • SLIDE_RIGHT Slide Right
  • UNDO_SLIDE_RIGHT
  • SLIDE_DOWN Slide Down
  • UNDO_SLIDE_DOWN Undo Slide Down
  • NONE No Animation
  • BOUNCE_UP Bounce off the top when scrolling up
  • BOUNCE_DOWN Bounce off the bottom when scrolling down
  • BOUNCE_LEFT Bounce off the left side
  • BOUNCE_RIGHT Bounce off the right side

enum@4

  • LINEAR Linear Animation
  • SQUARED Accelerating animation
  • SQUARED_UNDO De-accelerating animation

class draw::ArcProgress

The Progress Class displays a progress arc on the screen.

Methods

Details

publicArcProgress()


public virtual voiddraw_to_scale(constDrawingScaledAttr& attr)

Draw a scaled version of the arc using the specified attr


public inline voidset_direction(s8 dir)


public inline voidset_offset(s16 offset)


class draw::Axis

Methods

  • public inlineAxis()
  • public inlineAxis(float min,float max,constvar::ConstString& label)
  • public inline const char *label() const
  • public inline floatmax() const
  • public inline floatmin() const
  • public floatrange() const
  • public inline voidset(float min,float max,float tick)
  • public inline voidset_max(float value)
  • public inline voidset_min(float value)

Details

public inlineAxis()


public inlineAxis(float min,float max,constvar::ConstString& label)


public inline const char *label() const


public inline floatmax() const


public inline floatmin() const


public floatrange() const


public inline voidset(float min,float max,float tick)


public inline voidset_max(float value)


public inline voidset_min(float value)


class draw::BarGraph

This class can be used to draw a scalable bar graph.

Methods

Details

publicBarGraph()


class draw::BarProgress

The Progress Class displays a progress bar on the screen.

Methods

Details

publicBarProgress()


public inline virtual voiddraw(constDrawingAttr& attr)

This method draws the object using the specified drawing attributes.

The attributes specify which bitmap to draw on, what size to draw, and where to draw. The dimensions and position are scaled to fit on the bitmap.


public virtual voiddraw_to_scale(constDrawingScaledAttr& attr)

This methods draws the drawing on the specified attributes.

Parameters * attr Specifies the bitmap, point and area to draw the drawing


class draw::CircleProgress

The Progress Class displays a progress circle on the screen.

Methods

Details

publicCircleProgress()


public virtual voiddraw_to_scale(constDrawingScaledAttr& attr)

Draw a scaled version of the circle as specified by attr


class draw::DataSet

Methods

  • public inlineDataSet() Construct an empy data set.
  • public inlineDataSet(float * data,u32 n_data) Construct a data set with data and n_data points.
  • public inline virtual floatat(u32 i) const Returns the data at point i.
  • public floatmax() const Returns the maximum value in the set.
  • public floatmin() const Retuns the minimum value in the set.
  • public inline voidset(const float * data,u32 n) Set the data pointer and number of points.
  • public inline virtual u32size() const Returns the number of data points in the set.

Details

public inlineDataSet()


public inlineDataSet(float * data,u32 n_data)


public inline virtual floatat(u32 i) const


public floatmax() const


public floatmin() const


public inline voidset(const float * data,u32 n)

This sets the data to use in the graph. The caller needs to manage the memory for the data points. This object simply has a pointer to the external data.

Parameters * data A pointer to the data

  • n The number of data points

public inline virtual u32size() const


class draw::Drawing

This is the base class for creating drawings. A Drawing class allows for nesting and positioning of graphics within a bitmap.

void MyObject::draw(const DrawingAttr::attr){
   Icon my_icon;
   drawing_area_t square;

   square = attr.square_w(500);

   //this will draw my icon centered in the bitmap specified by attr
   //adding drawing_point(250, 250) offset the icon by 25% of the bitmap in both x and y
   //adding a drawing_area_t will then scale icon to fit in a square that is half the width of the bitmap (see square_width())
   //draw will call the underlying draw_to_scale() method unless Icon re-implements draw
   my_icon.draw(attr + drawing_point(250, 250) + square);

}

Methods

Details

publicDrawing()


public inline booldark() const


public virtual voiddraw(constDrawingAttributes& attr)

This method draws the object using the specified drawing attributes.

The attributes specify which bitmap to draw on, what size to draw, and where to draw. The dimensions and position are scaled to fit on the bitmap.


public voiddraw(sgfx::Bitmap& b,drawing_int_tx,drawing_int_ty,drawing_size_tw,drawing_size_th)


public virtual voiddraw_scratch(constDrawingAttributes& attr)


public virtual voiddraw_to_scale(constDrawingScaledAttr& attr)

This methods draws the drawing on the specified attributes.

Parameters * attr Specifies the bitmap, point and area to draw the drawing


public voiddraw_to_scale(sgfx::Bitmap& b,sg_int_t x,sg_int_t y,sg_size_t w,sg_size_t h)


public inline boolinvert() const


public inline boolis_align_bottom() const


public inline boolis_align_center() const


public inline boolis_align_left() const


public inline boolis_align_middle() const


public inline boolis_align_right() const


public inline boolis_align_top() const


public inline boolis_visible() const


public inline voidset_align_bottom(bool v)


public inline voidset_align_center(bool v)


public inline voidset_align_left(bool v)


public inline voidset_align_middle(bool v)


public inline voidset_align_right(bool v)


public inline voidset_align_top(bool v)


public inline voidset_dark(bool v)


public inline voidset_invert(bool v)


public inline voidset_visible(bool v)


protected sg_area_tdim_on_bitmap(sgfx::Bitmap& b) const


protected boolflag(u32 flag) const


protected sg_point_tpoint_on_bitmap(sgfx::Bitmap& b,drawing_size_tx,drawing_size_ty,sg_area_t d)


protected voidset_flag(u32 flag,bool v)


class draw::DrawingArea

Methods

Details

public inlineDrawingArea()


public inlineDrawingArea(drawing_size_tw,drawing_size_th)


public inlineDrawingArea(constdrawing_area_t& area)


public inline constdrawing_area_t&area() const


public inlinedrawing_area_t&area()


public inlinedrawing_size_theight() const


public inline voidset_height(drawing_size_tvalue)


public inline voidset_width(drawing_size_tvalue)


public inlinedrawing_size_twidth() const


class draw::DrawingAttributes

This class contains the information needed to draw various Drawing objects on a bitmap.

This class is passed to Drawing::drawidth() to render graphics on a bitmap.

Methods

Details

publicDrawingAttributes()

Construct an object


publicDrawingAttributes(constdrawing_attr_t& attr)

Construct an object from a drawing_attr_t


public inlinedrawing_area_tarea() const

Returns a copy of the dimensions.


public inlinedrawing_attr_t&attr()

Access the underlying attr object


public inlinesgfx::Bitmap&bitmap() const

Access the bitmap


public inline sg_area_tcalc_dim_on_bitmap() const


publicdrawing_size_tcalc_height(drawing_size_tv) const

Calculate the scaled height relative to the height of the DrawingAttributes object.

Parameters * v The value to calculate

This method will calculate a height relative to the heigh of the object and the scale() value. For example, if the current object maps to a region of a bitmap height of 500 pixels, this method will return a drawing height that will be from 0 to 500 pixels with v being from 0 to DrawingAttributes::scale().


public inline sg_size_tcalc_height_on_bitmap() const


public inline sg_size_tcalc_height_on_bitmap(drawing_size_tvalue) const


public inline sg_point_tcalc_point_on_bitmap() const


public inline sg_region_tcalc_region_on_bitmap() const


publicdrawing_area_tcalc_square(drawing_size_tv) const

Calculate dimensions that will map to the bitmap as a square.

Parameters * v The maximum width or height

Returns

Square dimensions


public inlinedrawing_area_tcalc_square_h(drawing_size_tv) const


publicdrawing_area_tcalc_square_height(drawing_size_tv) const

Calculate dimensions that will map to the bitmap as a square with the given height.

Parameters * v The height (width will be calculated)

Returns

Square dimensions


public inlinedrawing_area_tcalc_square_w(drawing_size_tv) const


publicdrawing_area_tcalc_square_width(drawing_size_tv) const

Calculate dimensions that will map to the bitmap as a square with the given width.

Parameters * v The width (height will be calculated)

Returns

Square dimensions


publicdrawing_size_tcalc_width(drawing_size_tv) const

Calculate the scaled width (width of object on the bitmap)


public inline sg_size_tcalc_width_on_bitmap() const


public inline sg_size_tcalc_width_on_bitmap(drawing_size_tvalue) const


public inlinedrawing_size_theight() const

Return the height


public inline boolis_bitmap_available() const

Checks to see if bitmap is available.


public inlineoperator drawing_attr_t()

Return the underlying drawing_attr_t


publicDrawingAttributesoperator+(drawing_point_td) const

Add a drawing_point_t offset

This operated can be used to create a subregion within the object when used with operation+ (drawing_area_t).

For example:

DrawingAttributes attr0;
DrawingAttributes attr1;
attr0 = attr1 + drawing_point(250,250) + drawing_dim(500,500);

When mapped to the same bitmap, attr0 will be half the height and half the width of attr1. attr0 and attr1 will have the same center point.

These operators can be used to draw sub-drawings on drawings. The following example draws a rectangles recursively in an object.

void draw_rect_recursive(const DrawingAttributes & attr){
 Rect rect;
 attr.bitmap().set_pen_flags(Pen::FLAG_IS_INVERT);
 rect.draw(attr + drawing_point(250,250) + drawing_dim(500,500);
 if( attr.width() > 100 ){
   draw_rect_recursive(attr);
   }
}

publicDrawingAttributesoperator+(drawing_area_td) const

Update the dimension (must come after adding drawing_point_t)


publicDrawingAttributesoperator+(DrawingPoint d) const


publicDrawingAttributesoperator+(DrawingArea d) const


public inlinedrawing_point_tpoint() const

Returns a copy of the position.


public inline drawing_region_tregion() const

Returns a copy of the region.


public inlinesgfx::Bitmap*scratch() const

Access the scratch bitmap


public voidset(sgfx::Bitmap& b,drawing_point_tp,drawing_area_td,sgfx::Bitmap* scratch)

Assign the bitmap point and dimensions


public inline voidset_bitmap(sgfx::Bitmap& b)

Set the bitmap


public inline voidset_dim(drawing_area_td)

Set the dimensions. Both width and height are from 0 to 1000.


public inline voidset_dim(drawing_size_tw,drawing_size_th)

Set the dimensions. Both width and height are from 0 to 1000.


public inline voidset_point(drawing_point_tp)

Set the location. Both x and y are from 0 to 1000.


public inline voidset_point(drawing_int_tx,drawing_int_ty)

Set the location. Both x and y are from 0 to 1000.


public inline voidset_scratch(sgfx::Bitmap* b)

Set the scratch bitmap


public inlinedrawing_size_twidth() const

Return the width


public inlinedrawing_int_tx() const

Return the x value


public inlinedrawing_int_ty() const

Return the y value


class draw::DrawingPoint

Methods

Details

public inlineDrawingPoint()


public inlineDrawingPoint(drawing_int_tx,drawing_int_ty)


public inlineDrawingPoint(constdrawing_point_t& point)


public inline constdrawing_point_t&point() const


public inlinedrawing_point_t&point()


public inline voidset_x(drawing_size_tvalue)


public inline voidset_y(drawing_size_tvalue)


public inlinedrawing_size_tx() const


public inlinedrawing_size_ty() const


class draw::DrawingScaledAttributes

This is similar to draw::DrawingAttr but the point and dimensions have been scaled to fit in the target bitmap.

Methods

Details

public inlineDrawingScaledAttributes()


public inlineDrawingScaledAttributes(constDrawingAttributes& attr)


public inline sg_area_tarea() const


public inlinedrawing_scaled_attr_t&attr()


public inlinesgfx::Bitmap&bitmap() const


public sg_size_tcalc_height(drawing_size_tv) const


public sg_size_tcalc_width(drawing_size_tv) const

Calculate a width value

Parameters * v Unscaled drawing dimensions

Returns


public inline sg_size_theight() const

Return the height


public inlineoperator drawing_scaled_attr_t()


publicDrawingScaledAttributesoperator+(sg_point_t d) const

Add an sg_point_t


publicDrawingScaledAttributesoperator+(sg_area_t d) const

Add an sg_area_t


public inline sg_point_tpoint() const


public inline sg_region_tregion() const


public voidset(sgfx::Bitmap& b,sg_point_t p,sg_area_t d)


public inline voidset_bitmap(sgfx::Bitmap& b)

Assign a value to the bitmap pointer using a reference


public inline voidset_dim(sg_area_t d)

Assign dimensions


public inline voidset_dim(sg_size_t w,sg_size_t h)

Assign dimensions using width and height parameters


public inline voidset_height(sg_size_t h)

Set the height of the object


public inline voidset_point(sg_point_t p)

Assign the position


public inline voidset_width(sg_size_t w)

Set the width of the object


public inline voidset_x(sg_int_t x)

Set the x value of the object


public inline voidset_y(sg_int_t y)

Set the y value of the object


public inline sg_size_twidth() const

Return the width


public inline sg_int_tx() const

Return the x value


public inline sg_int_ty() const

Return the y value


class draw::Graph

Methods

Details

publicGraph()


public inlineAxis&x_axis()


public inlineDataSet&x_data()


public inlineAxis&y_axis()


public inlineDataSet&y_data()


protectedsgfx::Pointpoint_on_bitmap(sgfx::Bitmap* b,float x,float y,constsgfx::Area& d)


class draw::Icon

This class draws icons that can be scaled and rotated on a bitmap.

When an icon is drawn, the icon's pen attributes are used to draw on the bitmap.

Methods

  • publicIcon() Construct an empty graphic
  • public inline sg_region_t &bounds() This returns the bounds of the icon. It is only valid after the icon has been drawn on a bitmap.
  • public virtual voiddraw_to_scale(constDrawingScaledAttr& attr) Draws the graphic to scale on the specified bitmap

Details

publicIcon()

Construct an empty graphic


public inline sg_region_t &bounds()

This returns the bounds of the icon. It is only valid after the icon has been drawn on a bitmap.

Returns

The bounds of the last time this icon was drawn on a bitmap using draw_to_scale()


public virtual voiddraw_to_scale(constDrawingScaledAttr& attr)

Draws the graphic to scale on the specified bitmap


class draw::IconAttributes

This class defines the attributes of a Gfx object.

Methods

Details

public inlineIconAttributes(constvar::ConstString& name)


public inline constvar::String&name() const


public inline s16rotation() const

Returns the rotation


public inline voidset_name(constvar::ConstString& name)


public inline voidset_rotation(s16 rotation)

Set the rotation


enum@6

  • RIGHT Point to the right.
  • DOWN Point down.
  • LEFT Point to the left.
  • UP Point up.
  • QUARTER_CLOCKWISE Add/subtract to/from RIGHT, DOWN, etc.
  • QUARTER_COUNTER_CLOCKWISE Add/subtract to/from RIGHT, DOWN, etc.
  • EIGHTH_CLOCKWISE Add/subtract to/from RIGHT, DOWN, etc.
  • EIGHTH_COUNTER_CLOCKWISE Add/subtract to/from RIGHT, DOWN, etc.

Icon rotation orientations


class draw::Image

The Image class draws a bitmap image on the drawing bitmap.

Methods

Details

publicImage()


publicImage(constsgfx::Bitmap& bitmap)


publicdrawing_area_tcalc_area()


public virtual voiddraw_to_scale(constDrawingScaledAttr& attr)

This methods draws the drawing on the specified attributes.

Parameters * attr Specifies the bitmap, point and area to draw the drawing


public inline voidset_bitmap(constsgfx::Bitmap* bitmap)

Sets the bitmap that is to be drawn as the image.

Parameters * bitmap A pointer to the bitmap to draw


class draw::LineGraph

Methods

Details

publicLineGraph()


class draw::Panel

This class draws a rounded rectangle for a panel to hold text.

Methods

Details

publicPanel()


public virtual voiddraw_to_scale(constDrawingScaledAttr& attr)

This methods draws the drawing on the specified attributes.

Parameters * attr Specifies the bitmap, point and area to draw the drawing


class draw::PanelAttr

Methods

Details

public inline Pen &pen()


public inline sg_size_tradius()


public inline voidset_radius(sg_size_t radius)


protected Penm_pen


protected sg_size_tm_radius


class draw::Progress

The Progress Class defines the top level object for progress bars etc.

Methods

Details

public inlineProgress()


public inlinedrawing_size_tborder_thickness() const


public inline voidset_border_thickness(drawing_size_tborder_thickness)


protected sg_size_tm_scaled_border_thickness


protected inline sg_size_tscaled_border_thickness() const


class draw::ProgressAttr

This class defines the attributes of any progress object. This class is available as a minimal way to store progress without having to inherit Drawing by using Progress object.

Methods

  • public inlineProgressAttr()
  • public inlineProgressAttr(u16 value,u16 max)
  • public inline u16max() const The maximum value for progress
  • public inlineoperator progress_t() const
  • public inlinesgfx::Pen&pen()
  • public inline voidset_attr(u16 value,u16 max) Set both the value and the max
  • public inline voidset_attr(const progress_t * progress)
  • public inline voidset_attr(const progress_t & progress)
  • public inline voidset_max(u16 max) Set the maximum value
  • public inline voidset_value(u16 value) Set the progress value
  • public inline u16value() const The progress value

Details

public inlineProgressAttr()


public inlineProgressAttr(u16 value,u16 max)


public inline u16max() const

The maximum value for progress


public inlineoperator progress_t() const


public inlinesgfx::Pen&pen()


public inline voidset_attr(u16 value,u16 max)

Set both the value and the max


public inline voidset_attr(const progress_t * progress)


public inline voidset_attr(const progress_t & progress)


public inline voidset_max(u16 max)

Set the maximum value


public inline voidset_value(u16 value)

Set the progress value


public inline u16value() const

The progress value


class draw::Rect

The Rect class draws a rectangle on the display. It can be used for both horizontal and vertical separators as well.

Methods

Details

publicRect()


public virtual voiddraw_to_scale(constDrawingScaledAttr& attr)

This methods draws the drawing on the specified attributes.

Parameters * attr Specifies the bitmap, point and area to draw the drawing


class draw::Text

This is a text label. The object automatically chooses the correct font height to fit within the area specified.

In order for this class to work correctly, sys::Assets::init() must be invoked so that the application is aware of the system fonts.

Methods

Details

publicText(constvar::ConstString& text)

Construct a label with text


public virtual voiddraw_to_scale(constDrawingScaledAttr& attr)

Draw the scaled text as specified by attr


class draw::TextAttributes

This class contains the information needed to draw text. It allows the text to be stored separate from the drawing object.

Methods

Details

public inlineTextAttributes()


public inline constsgfx::Font*font() const

Gets a pointer to the current font.


public inline sg_size_tfont_size() const

Return the font size


public inline boolfont_style() const

Returns whether font is bold or not


public inlinesgfx::Font*set_font(sgfx::Font* font)

Specify a font

If no font is specified, the text will use sys::Assets::find_font() to load a font that most closely matches font_size(). If font_size() is zero, the text will get a font that most close matches the height of the container without exceeding the container height.


public inline voidset_font_size(sg_size_t v)

Set the font size


public inline voidset_font_style(u8 style)

Sets the font style.

Parameters * style Should be a value from enum sgfx::FontInfo::style


public inlinevar::String&string()

Gets a reference to the text string.


public inline constvar::String&string() const

Gets a reference to the text string (read-only).


protected constsgfx::Font*resolve_font(sg_size_t h) const


class draw::TextBox

This class is a scrolling text box that can be used to show long text messages.

Methods

Details

publicTextBox()

Construct a new text box


public intcount_lines(sg_size_t w)


public inline voiddec_scroll()


public virtual voiddraw_to_scale(constDrawingScaledAttr& attr)

This methods draws the drawing on the specified attributes.

Parameters * attr Specifies the bitmap, point and area to draw the drawing


public inline voidinc_scroll()


public inline sg_size_tscroll() const

Access the scroll value


public inline sg_size_tscroll_max() const

Access the max scroll value


struct draw::drawing_area_t

Methods

Details

publicdrawing_size_theight

Height of the object


publicdrawing_size_twidth

Width of the object


struct draw::drawing_attr_t

This data structure holds a real bitmap but the point and dimensions haven't been mapped to the bitmap. The point p and dimension d are both in a universal coordinate system from 0 to draw::DrawingAttributes::scale(). For example if draw::DrawingAttributes::scale() is 1000 and p.x and p.y both are equal to 500, the top left corner of any item drawn using these attibutes will be in the center of the target bitmap (regardless of the target bitmap's size).

Methods

Details

publicsgfx::Bitmap*bitmap

A pointer to the target bitmap


public drawing_region_tregion

The region on the bitmap where draw::Drawing will be drawn


publicsgfx::Bitmap*scratch

A pointer to the scratch bitmap used for animations (0 if not available)


struct draw::drawing_point_t

Methods

Details

publicdrawing_int_tx

X position


publicdrawing_int_ty

Y position


struct draw::drawing_region_t

Methods

Details

publicdrawing_area_tarea

Height of the object


publicdrawing_point_tpoint

Point in the region


struct draw::drawing_scaled_attr_t

Methods

  • publicsgfx::Bitmap*bitmap The target bitmap
  • public sg_region_tregion The region on the bitmap where draw::DrawingScaled will be drawn

Details

publicsgfx::Bitmap*bitmap

The target bitmap


public sg_region_tregion

The region on the bitmap where draw::DrawingScaled will be drawn


struct draw::progress_t

Methods

Details

public u16max


public u16value


namespace dsp

The Digital Signal Processing (dsp) namespace includes signal processing algorithms including wrappers and data management tools for using the ARM CMSIS DSP library.

Classes

class dsp::BiquadCoefficientsF32

Methods

  • public inlineBiquadCoefficientsF32(u8 n_stages)
  • public inline float32_t &a1(u32 stage)
  • public inline float32_t &a2(u32 stage)
  • public inline float32_t &b0(u32 stage)
  • public inline float32_t &b1(u32 stage)
  • public inline float32_t &b2(u32 stage)
  • public inline u8stages() const

Details

public inlineBiquadCoefficientsF32(u8 n_stages)


public inline float32_t &a1(u32 stage)


public inline float32_t &a2(u32 stage)


public inline float32_t &b0(u32 stage)


public inline float32_t &b1(u32 stage)


public inline float32_t &b2(u32 stage)


public inline u8stages() const


class dsp::BiquadCoefficientsQ15

Methods

  • public inlineBiquadCoefficientsQ15(u8 n_stages)
  • public inline q15_t &a1(u32 stage)
  • public inline q15_t &a2(u32 stage)
  • public inline q15_t &b0(u32 stage)
  • public inline q15_t &b1(u32 stage)
  • public inline q15_t &b2(u32 stage)
  • public inline u8stages() const

Details

public inlineBiquadCoefficientsQ15(u8 n_stages)


public inline q15_t &a1(u32 stage)


public inline q15_t &a2(u32 stage)


public inline q15_t &b0(u32 stage)


public inline q15_t &b1(u32 stage)


public inline q15_t &b2(u32 stage)


public inline u8stages() const


class dsp::BiquadCoefficientsQ31

Methods

  • public inlineBiquadCoefficientsQ31(u8 n_stages)
  • public inline q31_t &a1(u32 stage)
  • public inline q31_t &a2(u32 stage)
  • public inline q31_t &b0(u32 stage)
  • public inline q31_t &b1(u32 stage)
  • public inline q31_t &b2(u32 stage)
  • public inline u8stages() const

Details

public inlineBiquadCoefficientsQ31(u8 n_stages)


public inline q31_t &a1(u32 stage)


public inline q31_t &a2(u32 stage)


public inline q31_t &b0(u32 stage)


public inline q31_t &b1(u32 stage)


public inline q31_t &b2(u32 stage)


public inline u8stages() const


class dsp::BiquadFilterF32

Methods

Details

publicBiquadFilterF32(const BiquadCoefficientsF32 & coefficients)


public inline u32samples() const


class dsp::BiquadFilterQ15

Methods

  • publicBiquadFilterQ15(const BiquadCoefficientsQ15 & coefficients,s8 post_shift)
  • public inline u32samples() const

Details

publicBiquadFilterQ15(const BiquadCoefficientsQ15 & coefficients,s8 post_shift)


public inline u32samples() const


class dsp::BiquadFilterQ31

Methods

  • publicBiquadFilterQ31(const BiquadCoefficientsQ31 & coefficients,s8 post_shift)
  • public inline u32samples() const

Details

publicBiquadFilterQ31(const BiquadCoefficientsQ31 & coefficients,s8 post_shift)


public inline u32samples() const


class dsp::Complex

The Complex class is a template for holding raw data types that comprise complex data.

Methods

  • public inline T &imaginary() Returns a reference to the complex component (read/write).
  • public inline const T &imaginary() const Returns a reference to the imaginary component (read-only).
  • public inline booloperator !=(const T & a) const
  • public inline Toperator -(const T & a) const Subtracts this to a and returns a new object.
  • public inline T &operator -=(const T & a) Subtracts a from this object.
  • public inline Toperator+(const T & a) const Adds this to a and returns a new object.
  • public inline T &operator+=(const T & a) Adds a to this object.
  • public inline booloperator==(const T & a) const
  • public inline T &real() Returns a reference to the real component (read/write).
  • public inline const T &real() const Returns a reference to the real component (read-only).

Details

public inline T &imaginary()

Returns a reference to the complex component (read/write).


public inline const T &imaginary() const

Returns a reference to the imaginary component (read-only).


public inline booloperator !=(const T & a) const


public inline Toperator -(const T & a) const

Subtracts this to a and returns a new object.


public inline T &operator -=(const T & a)

Subtracts a from this object.


public inline Toperator+(const T & a) const

Adds this to a and returns a new object.


public inline T &operator+=(const T & a)

Adds a to this object.


public inline booloperator==(const T & a) const


public inline T &real()

Returns a reference to the real component (read/write).


public inline const T &real() const

Returns a reference to the real component (read-only).


class dsp::ComplexF32

The ComplexF32 represents a single complex value in the 32-bit floating point format.

Methods

  • public inlineComplexF32(float32_t r,float32_t imag)

Details

public inlineComplexF32(float32_t r,float32_t imag)


class dsp::ComplexQ15

The ComplexQ15 represents a single complex value in the q1.15 fixed point format.

Methods

  • public inlineComplexQ15(q15_t r,q15_t imag) Constructs a new value.

Details

public inlineComplexQ15(q15_t r,q15_t imag)

Constructs a new value.

Parameters * r real value

  • imag imaginary value

class dsp::ComplexQ31

The ComplexQ31 represents a single complex value in the q1.31 fixed point format.

Methods

Details

public inlineComplexQ31(q31_t r,q31_t imag)


class dsp::Fft

Methods

  • public inline SignalTypecreate_frequency_signal() const Returns a signal capable of holding FFT destination data and IFFT source data.
  • public inline SignalTypecreate_time_signal() const Returns a signal capable of holding FFT source data and IFFT destination data.
  • public inline const T *instance() const
  • public inline T *instance()
  • public u32samples() const

Details

public inline SignalTypecreate_frequency_signal() const

Returns a signal capable of holding FFT destination data and IFFT source data.


public inline SignalTypecreate_time_signal() const

Returns a signal capable of holding FFT source data and IFFT destination data.


public inline const T *instance() const


public inline T *instance()


public u32samples() const


class dsp::FftComplexF32

Methods

Details

publicFftComplexF32(u32 n_samples)


public inline u32samples() const


class dsp::FftComplexQ15

Methods

Details

publicFftComplexQ15(u32 n_samples)


public inline u32samples() const


class dsp::FftComplexQ31

The source data for an FFT transform should match the number of samples the FFT computes. The destination should be the number of samples times two.

When performing an inverse, FFT the source data is the number of samples times two and the destination matches the number of samples.

Methods

  • publicFftComplexQ31(u32 n_samples) Contructs a new object.
  • public inline u32samples() const Returns the number of samples used on each computation.

Details

publicFftComplexQ31(u32 n_samples)

Contructs a new object.

Parameters * n_samples The number of samples to compute on each transform

The object is passed to the signal transform() methods.


public inline u32samples() const

Returns the number of samples used on each computation.


class dsp::FftRealF32

Methods

Details

publicFftRealF32(u32 n_samples)


public inline u32samples() const


class dsp::FftRealQ15

Methods

Details

publicFftRealQ15(u32 n_samples)


public inline u32samples() const


class dsp::FftRealQ31

The Real FFT object for q1.31.

RealFftQ31 fft(32);
SignalComplexQ31 source(32);
SignalComplexQ31 destination;
destination = source.transform(fft);

//subsequent calls can avoid dyncamic memory allocation
source.transform(destination, fft);

//Now the inverse
destination.transform(source, fft, true);

Methods

  • publicFftRealQ31(u32 n_samples) Contructs an object.
  • public inline u32samples() const Returns the number of samples computed on each transform.

Details

publicFftRealQ31(u32 n_samples)

Contructs an object.

Parameters * n_samples The number of samples to compute on each transform

The n_samples value must be a power of 2 between 32 and 2048.


public inline u32samples() const

Returns the number of samples computed on each transform.


class dsp::Filter

Methods

Details

public inline const T *instance() const


protected inline T *instance()


class dsp::FirDecimateFilterQ31

Methods

Details

publicFirDecimateFilterQ31(constSignalQ31& coefficients,u8 M,u32 n_samples)


class dsp::FirFilterF32

Methods

Details

publicFirFilterF32(constSignalF32& coefficients,u32 n_samples)


public inline u32samples() const


class dsp::FirFilterQ15

Methods

Details

publicFirFilterQ15(constSignalQ15& coefficients,u32 n_samples)


public inline u32samples() const


class dsp::FirFilterQ31

Methods

Details

publicFirFilterQ31(constSignalQ31& coefficients,u32 n_samples)


public inline u32samples() const


class dsp::SignalComplexF32

Methods

Details

public inlineSignalComplexF32()


public inlineSignalComplexF32(u32 count)


public inline boolis_api_available() const


public SignalComplexF32transform(FftRealF32 & fft,bool is_inverse)


public voidtransform(SignalComplexF32 & output,FftRealF32 & fft,bool is_inverse)


public voidtransform(FftComplexF32 & fft,bool is_inverse,bool is_bit_reversal)


class dsp::SignalComplexQ15

This class is used for storing complex signal data in q1.15 format.

Complex data is required when performing transform operations (FFT and DCT).

Methods

Details

public inlineSignalComplexQ15()


public inlineSignalComplexQ15(u32 count)


public inline virtual boolis_api_available() const


publicSignalComplexQ15transform(FftRealQ15 & fft,bool is_inverse)


public voidtransform(SignalComplexQ15& output,FftRealQ15 & fft,bool is_inverse)


public voidtransform(FftComplexQ15 & fft,bool is_inverse,bool is_bit_reversal)


class dsp::SignalComplexQ31

This class is used for storing complex signal data in q1.31 format.

Complex data is required when performing transform operations (FFT and DCT).

Methods

Details

public inlineSignalComplexQ31()


public inlineSignalComplexQ31(u32 count)


public inline virtual boolis_api_available() const


publicSignalComplexQ31transform(FftRealQ31& fft,bool is_inverse)

Transforms this object and returns a new signal with the transformed data.


public voidtransform(SignalComplexQ31& output,FftRealQ31& fft,bool is_inverse)


public voidtransform(FftComplexQ31& fft,bool is_inverse,bool is_bit_reversal)


class dsp::SignalData

The SignalData class is a template class for signal data vectors used in DSP processing algorithms.

All signals are dynamically allocated using the var::Vector class.

Methods

  • public inlineSignalData()
  • public inlineSignalData(int count)
  • public virtualSignalData< T, BigType >abs() const Calculates the absolute value of each value in the signal.
  • public virtual voidabs(SignalData& output) const Calculates the absolute value of each value in the signal.
  • public inline virtual Derivedadd(const Derived & a) const
  • public inline virtual Derivedadd(const T & a) const
  • public inline virtual Derived &add_assign(const Derived & a)
  • public inline virtual Derived &add_assign(const T & a)
  • public virtualSignalDataconvolve(constSignalData& a) const
  • public virtual voidconvolve(SignalData& output,constSignalData& a) const
  • public virtual BigTypedot_product(constSignalData& a) const Calculates and returns the dot product of this signal and the the parameter passed.
  • public virtualSignalDatafilter(const BiquadFilterType & filter) const Filters the signal.
  • public virtual voidfilter(SignalData& output,const BiquadFilterType & filter) const Filters the signal.
  • public virtualSignalDatafilter(const FirFilterType & filter) const Filters the signal.
  • public voidfilter(SignalData& output,const FirFilterType & filter) const Filters the signal.
  • public inline virtual boolis_api_available() const
  • public virtual Tmax() const Calculates and returns the maximum value of the signal.
  • public virtual Tmax(u32 & idx) const Calculates and returns the maximum value of the signal.
  • public virtual Tmean() const Returns the mean value of the signal.
  • public virtual Tmin() const Calculates and returns the minimum value of the signal.
  • public virtual Tmin(u32 & idx) const Calculates and returns the minimum value of the signal.
  • public inline virtual Derivedmultiply(const Derived & a) const
  • public inline virtual Derivedmultiply(const T & scale_fraction) const
  • public inline virtual Derived &multiply_assign(const Derived & a)
  • public inline virtual Derived &multiply_assign(const T & scale_fraction)
  • public virtualSignalDatanegate() const Returns a new signal that a negated copy of this signal.
  • public virtual voidnegate(SignalData& output) const Assigns the negated value of this signal to output.
  • public virtualSignalDataoffset(T offset_value) const Adds an offset to each element in the signal.
  • public inline booloperator !=(const Derived & a) const Returns true if this signal is not equivalent as a.
  • public inline Derivedoperator *(const Derived & a) const Calculates element-by-element multiplication.
  • public inline Derivedoperator *(const T & value) const Multiplies each element by a scaling value.
  • public inline Derived &operator *=(const Derived & a) Multiples this with and stores the result in this signal.
  • public inline Derived &operator *=(const T & value) Multiplies each element of this signal by a scalar value.
  • public inline Derivedoperator -(const Derived & a) const Performs element-wise subtraction.
  • public inline Derivedoperator -(const T & a) const Subtracts a scalar value from each element.
  • public inline Derived &operator -=(const Derived & a) Performs element-wise subtraction and saves the result in this signal.
  • public inline Derived &operator -=(const T & a) Subtracts a scalar value from each element in this signal.
  • public inline Derivedoperator >>(s8 value) const Shifts this signal.
  • public inline Derived &operator >>=(s8 value) Shifts this signal value bits to the right.
  • public inline Derivedoperator+(const Derived & a) const Performs element-wise addition.
  • public inline Derivedoperator+(const T & a) const Adds a constant value to all elements.
  • public inline Derived &operator+=(const Derived & a) Performs element-wise addition.
  • public inline Derived &operator+=(const T & a) Adds a constant value to all elements in this signal.
  • public inline Derivedoperator<<(s8 value) const Shifts this signal.
  • public inline Derived &operator<<=(s8 value) Shifts this signal value bits to the left.
  • public inline booloperator==(const Derived & a) const Returns true if this signal is equivalent as a.
  • public virtual BigTypepower() const
  • public virtual Trms() const Calculates the RMS value of the signal.
  • public virtualSignalDatascale(T scale_fraction,s8 shift)
  • public virtual voidscale(SignalData& output,T scale_fraction,s8 shift)
  • public inline virtual Derivedshift(s8 value) const
  • public inline virtual Derived &shift_assign(s8 value)
  • public virtual Tstd() const Calculates and returns the standard deviation value of the signal.
  • public inline virtual Derivedsubtract(const Derived & a) const
  • public inline virtual Derived &subtract_assign(const Derived & a)
  • public virtual Tvariance() const Calculates and returns the variance value of the signal.

Details

public inlineSignalData()


public inlineSignalData(int count)


public virtualSignalData< T, BigType >abs() const

Calculates the absolute value of each value in the signal.

Returns

A new signal containing the absolute value of this signal.

This method will allocate a new signal and return it.


public virtual voidabs(SignalData& output) const

Calculates the absolute value of each value in the signal. Parameters * output A reference to the destination signal

Returns

A new signal containing the absolute value of this signal.


public inline virtual Derivedadd(const Derived & a) const


public inline virtual Derivedadd(const T & a) const


public inline virtual Derived &add_assign(const Derived & a)


public inline virtual Derived &add_assign(const T & a)


public virtualSignalDataconvolve(constSignalData& a) const


public virtual voidconvolve(SignalData& output,constSignalData& a) const


public virtual BigTypedot_product(constSignalData& a) const

Parameters * a Used as the second signal used to calculate the dot product.

Returns

Returns the dot product of a and this signal.


public virtualSignalDatafilter(const BiquadFilterType & filter) const

Filters the signal.

Parameters * filter Biquad Filter to use

This method uses dynamic memory allocation.


public virtual voidfilter(SignalData& output,const BiquadFilterType & filter) const

Filters the signal.

Parameters * output A reference to the output signal

  • filter Biquad Filter to use

public virtualSignalDatafilter(const FirFilterType & filter) const

Filters the signal.

Parameters * filter An FIR filter to apply to the signal

This method uses dynamic memory allocation.


public voidfilter(SignalData& output,const FirFilterType & filter) const

Filters the signal.

Parameters * output A reference to the output signal

  • filter An FIR filter to apply to the signal

public inline virtual boolis_api_available() const


public virtual Tmax() const

Calculates and returns the maximum value of the signal.

This method utilizes the arm_max_q15() function.


public virtual Tmax(u32 & idx) const

Calculates and returns the maximum value of the signal.

Parameters * idx A reference to the index value of the maximum. This parameter will be written with the location of the maximum value.

This method utilizes the arm_max_q15() function.


public virtual Tmean() const

Returns the mean value of the signal.

SignalQ31 data(16);

data.fill(10);
printf("Mean is %ld\n", data.mean());

public virtual Tmin() const

Calculates and returns the minimum value of the signal.

This method utilizes the arm_min_q15() function.


public virtual Tmin(u32 & idx) const

Calculates and returns the minimum value of the signal.

Parameters * idx A reference to the index value of the minimum. This parameter will be written with the location of the minimum value.

This method utilizes the arm_min_q15() function.


public inline virtual Derivedmultiply(const Derived & a) const


public inline virtual Derivedmultiply(const T & scale_fraction) const


public inline virtual Derived &multiply_assign(const Derived & a)


public inline virtual Derived &multiply_assign(const T & scale_fraction)


public virtualSignalDatanegate() const

Returns a new signal that a negated copy of this signal.

This method uses dynamic memory allocation.


public virtual voidnegate(SignalData& output) const

Assigns the negated value of this signal to output.


public virtualSignalDataoffset(T offset_value) const

Adds an offset to each element in the signal.


public inline booloperator !=(const Derived & a) const

Returns true if this signal is not equivalent as a.


public inline Derivedoperator *(const Derived & a) const

Calculates element-by-element multiplication.

Parameters * a The second operand of the multiply operation

Returns

A new signal containing the product of a and this signal.

This operator requires the use of dynamic memory allocation. operator *=() does not.


public inline Derivedoperator *(const T & value) const

Multiplies each element by a scaling value.

Operators are not implemented on complex signals.


public inline Derived &operator *=(const Derived & a)

Multiples this with and stores the result in this signal.

Parameters * a The signal to multiply with.

This is faster than operator *() because no dynamic memory allocation is used.


public inline Derived &operator *=(const T & value)

Multiplies each element of this signal by a scalar value.

Operators are not implemented on complex signals.


public inline Derivedoperator -(const Derived & a) const

Performs element-wise subtraction.

Operators are not implemented on complex signals.

This operator uses dynamic memory allocation


public inline Derivedoperator -(const T & a) const

Subtracts a scalar value from each element.

Operators are not implemented on complex signals.

This operator uses dynamic memory allocation


public inline Derived &operator -=(const Derived & a)

Performs element-wise subtraction and saves the result in this signal.

Operators are not implemented on complex signals.


public inline Derived &operator -=(const T & a)

Subtracts a scalar value from each element in this signal.

Operators are not implemented on complex signals.


public inline Derivedoperator >>(s8 value) const

Shifts this signal.

Parameters * value Number of bits to left shift

Returns

A new signal with each element equal to this >> value

Operators are not implemented on complex signals. Shift is not available for any floating-point types.

This operator uses dynamic memory allocation.


public inline Derived &operator >>=(s8 value)

Shifts this signal value bits to the right.

Operators are not implemented on complex signals. Shift is not available for any floating-point types.


public inline Derivedoperator+(const Derived & a) const

Performs element-wise addition.

Operators are not implemented on complex signals.

This operator uses dynamic memory allocation


public inline Derivedoperator+(const T & a) const

Adds a constant value to all elements.

Operators are not implemented on complex signals.

This operator uses dynamic memory allocation


public inline Derived &operator+=(const Derived & a)

Performs element-wise addition.

Operators are not implemented on complex signals.


public inline Derived &operator+=(const T & a)

Adds a constant value to all elements in this signal.


public inline Derivedoperator<<(s8 value) const

Shifts this signal.

Parameters * value Number of bits to left shift

Returns

A new signal with each element equal to this << value

This operator uses dynamic memory allocation.

Operators are not implemented on complex signals. Shift is not available for any floating-point types.


public inline Derived &operator<<=(s8 value)

Shifts this signal value bits to the left.

Operators are not implemented on complex signals. Shift is not available for any floating-point types.


public inline booloperator==(const Derived & a) const

Returns true if this signal is equivalent as a.


public virtual BigTypepower() const


public virtual Trms() const

Calculates the RMS value of the signal.


public virtualSignalDatascale(T scale_fraction,s8 shift)


public virtual voidscale(SignalData& output,T scale_fraction,s8 shift)


public inline virtual Derivedshift(s8 value) const


public inline virtual Derived &shift_assign(s8 value)


public virtual Tstd() const

Calculates and returns the standard deviation value of the signal.

This method utilizes the arm_std_q15() function.


public inline virtual Derivedsubtract(const Derived & a) const


public inline virtual Derived &subtract_assign(const Derived & a)


public virtual Tvariance() const

Calculates and returns the variance value of the signal.

This method utilizes the arm_var_q15() function.


class dsp::SignalF32

This class holds a 32-bit floating point signal with real values.

#include <sapi/dsp.hpp>

SignalF32 a(32);
SignalF32 b(32);
a.fill(0);
b.fill(5);
a += b; //add elements from b to a
a += 10.0f; //offset a by 10.0f
printf("A mean is %0.2f\n", a.mean());

Methods

Details

public inlineSignalF32(int count)


public inlineSignalF32()


public virtualSignalF32abs() const

Calculates the absolute value of each value in the signal.

Returns

A new signal containing the absolute value of this signal.

This method will allocate a new signal and return it.


public voidabs(SignalF32& output) const


publicSignalF32add(float32_t offset_value) const


public virtualSignalF32add(constSignalF32& a) const


publicSignalF32&add_assign(float32_t offset_value)


public virtualSignalF32&add_assign(constSignalF32& a)


publicSignalF32convolve(constSignalF32& a) const


public voidconvolve(SignalF32& output,constSignalF32& a) const


public float32_tdot_product(constSignalF32& a) const


publicSignalF32filter(const FirFilterF32 & filter) const


public voidfilter(SignalF32& output,const FirFilterF32 & filter) const


publicSignalF32filter(const BiquadFilterF32 & filter) const


public voidfilter(SignalF32& output,const BiquadFilterF32 & filter) const


public inline virtual boolis_api_available() const


public virtual float32_tmax() const

Calculates and returns the maximum value of the signal.

This method utilizes the arm_max_q15() function.


public virtual float32_tmax(u32 & idx) const

Calculates and returns the maximum value of the signal.

Parameters * idx A reference to the index value of the maximum. This parameter will be written with the location of the maximum value.

This method utilizes the arm_max_q15() function.


public virtual float32_tmean() const

Returns the mean value of the signal.

SignalQ31 data(16);

data.fill(10);
printf("Mean is %ld\n", data.mean());

public virtual float32_tmin() const

Calculates and returns the minimum value of the signal.

This method utilizes the arm_min_q15() function.


public virtual float32_tmin(u32 & idx) const

Calculates and returns the minimum value of the signal.

Parameters * idx A reference to the index value of the minimum. This parameter will be written with the location of the minimum value.

This method utilizes the arm_min_q15() function.


publicSignalF32multiply(float32_t value) const


public virtualSignalF32multiply(constSignalF32& a) const


publicSignalF32&multiply_assign(float32_t value)


public virtualSignalF32&multiply_assign(constSignalF32& a)


public virtualSignalF32negate() const

Returns a new signal that a negated copy of this signal.

This method uses dynamic memory allocation.


public voidnegate(SignalF32& output) const


public virtual float32_tpower() const


public virtual float32_trms() const

Calculates the RMS value of the signal.


publicSignalF32scale(float32_t scale_fraction,s8 shift) const


public voidscale(SignalF32& output,float32_t scale_fraction,s8 shift) const


public voidshift(SignalF32& output,s8 value) const


public virtual float32_tstd() const

Calculates and returns the standard deviation value of the signal.

This method utilizes the arm_std_q15() function.


public virtualSignalF32subtract(constSignalF32& a) const


public virtualSignalF32&subtract_assign(constSignalF32& a)


public virtual float32_tvariance() const

Calculates and returns the variance value of the signal.

This method utilizes the arm_var_q15() function.


class dsp::SignalQ15

This class holds signal data in the q1.15 fixed-point format.

Methods

Details

public inlineSignalQ15(int count)


public inlineSignalQ15()


public virtualSignalQ15abs() const

Calculates the absolute value of each value in the signal.

Returns

A new signal containing the absolute value of this signal.

This method will allocate a new signal and return it.


public voidabs(SignalQ15& output) const


publicSignalQ15add(q15_t offset_value) const


public virtualSignalQ15add(constSignalQ15& a) const


publicSignalQ15&add_assign(q15_t offset_value)


public virtualSignalQ15&add_assign(constSignalQ15& a)


publicSignalQ15convolve(constSignalQ15& a) const


public voidconvolve(SignalQ15& output,constSignalQ15& a) const


public q63_tdot_product(constSignalQ15& a) const


publicSignalQ15filter(const FirFilterQ15 & filter) const


public voidfilter(SignalQ15& output,const FirFilterQ15 & filter) const


publicSignalQ15filter(const BiquadFilterQ15 & filter) const


public voidfilter(SignalQ15& output,const BiquadFilterQ15 & filter) const


public inline virtual boolis_api_available() const


public virtual q15_tmax() const

Calculates and returns the maximum value of the signal.

This method utilizes the arm_max_q15() function.


public virtual q15_tmax(u32 & idx) const

Calculates and returns the maximum value of the signal.

Parameters * idx A reference to the index value of the maximum. This parameter will be written with the location of the maximum value.

This method utilizes the arm_max_q15() function.


public virtual q15_tmean() const

Returns the mean value of the signal.

SignalQ31 data(16);

data.fill(10);
printf("Mean is %ld\n", data.mean());

public virtual q15_tmin() const

Calculates and returns the minimum value of the signal.

This method utilizes the arm_min_q15() function.


public virtual q15_tmin(u32 & idx) const

Calculates and returns the minimum value of the signal.

Parameters * idx A reference to the index value of the minimum. This parameter will be written with the location of the minimum value.

This method utilizes the arm_min_q15() function.


publicSignalQ15multiply(q15_t value) const


public virtualSignalQ15multiply(constSignalQ15& a) const


publicSignalQ15&multiply_assign(q15_t value)


public virtualSignalQ15&multiply_assign(constSignalQ15& a)


public virtualSignalQ15negate() const

Returns a new signal that a negated copy of this signal.

This method uses dynamic memory allocation.


public voidnegate(SignalQ15& output) const


public virtual q63_tpower() const


public virtual q15_trms() const

Calculates the RMS value of the signal.


publicSignalQ15scale(q15_t scale_fraction,s8 shift) const


public voidscale(SignalQ15& output,q15_t scale_fraction,s8 shift) const


public voidshift(SignalQ15& output,s8 value) const


public virtualSignalQ15shift(s8 value) const


public virtualSignalQ15&shift_assign(s8 value)


public virtual q15_tstd() const

Calculates and returns the standard deviation value of the signal.

This method utilizes the arm_std_q15() function.


public virtualSignalQ15subtract(constSignalQ15& a) const


public virtualSignalQ15&subtract_assign(constSignalQ15& a)


public virtual q15_tvariance() const

Calculates and returns the variance value of the signal.

This method utilizes the arm_var_q15() function.


class dsp::SignalQ31

The SignalQ31 class stores a real q1.31 data signal.

Methods

Details

public inlineSignalQ31(int count)

Constructs a signal with uninitialized values.

Parameters * count The number of data points


public inlineSignalQ31()

Contructs an empty signal.


public virtualSignalQ31abs() const

Calculates the absolute value of each value in the signal.

Returns

A new signal containing the absolute value of this signal.

This method will allocate a new signal and return it.


public voidabs(SignalQ31& output) const


publicSignalQ31add(q31_t offset_value) const


public virtualSignalQ31add(constSignalQ31& a) const


publicSignalQ31&add_assign(q31_t offset_value)


public virtualSignalQ31&add_assign(constSignalQ31& a)


publicSignalQ31convolve(constSignalQ31& a) const


public voidconvolve(SignalQ31& output,constSignalQ31& a) const


public q63_tdot_product(constSignalQ31& a) const


publicSignalQ31filter(const FirFilterQ31 & filter) const


public voidfilter(SignalQ31& output,const FirFilterQ31 & filter) const


publicSignalQ31filter(const BiquadFilterQ31 & filter) const


public voidfilter(SignalQ31& output,const BiquadFilterQ31 & filter) const


publicSignalQ31filter(const FirDecimateFilterQ31 & filter)


public voidfilter(SignalQ31& output,const FirDecimateFilterQ31 & filter)


public inline virtual boolis_api_available() const


public virtual q31_tmax() const

Calculates and returns the maximum value of the signal.

This method utilizes the arm_max_q15() function.


public virtual q31_tmax(u32 & idx) const

Calculates and returns the maximum value of the signal.

Parameters * idx A reference to the index value of the maximum. This parameter will be written with the location of the maximum value.

This method utilizes the arm_max_q15() function.


public virtual q31_tmean() const

Returns the mean value of the signal.

SignalQ31 data(16);

data.fill(10);
printf("Mean is %ld\n", data.mean());

public virtual q31_tmin() const

Calculates and returns the minimum value of the signal.

This method utilizes the arm_min_q15() function.


public virtual q31_tmin(u32 & idx) const

Calculates and returns the minimum value of the signal.

Parameters * idx A reference to the index value of the minimum. This parameter will be written with the location of the minimum value.

This method utilizes the arm_min_q15() function.


publicSignalQ31multiply(q31_t value) const


public virtualSignalQ31multiply(constSignalQ31& a) const


publicSignalQ31&multiply_assign(q31_t value)


public virtualSignalQ31&multiply_assign(constSignalQ31& a)


public virtualSignalQ31negate() const

Returns a new signal that a negated copy of this signal.

This method uses dynamic memory allocation.


public voidnegate(SignalQ31& output) const


public virtual q63_tpower() const


public virtual q31_trms() const

Calculates the RMS value of the signal.


publicSignalQ31scale(q31_t scale_fraction,s8 shift) const


public voidscale(SignalQ31& output,q31_t scale_fraction,s8 shift) const


public voidshift(SignalQ31& output,s8 value) const


public virtualSignalQ31shift(s8 value) const


public virtualSignalQ31&shift_assign(s8 value)


public virtual q31_tstd() const

Calculates and returns the standard deviation value of the signal.

This method utilizes the arm_std_q15() function.


public virtualSignalQ31subtract(constSignalQ31& a) const


public virtualSignalQ31&subtract_assign(constSignalQ31& a)


public virtual q31_tvariance() const

Calculates and returns the variance value of the signal.

This method utilizes the arm_var_q15() function.


namespace ev

Classes

class ev::Button

This class implements a button that can be pressed by the user. It implements the timing for button actuations, button holds, presses and releases. It is an abstract class where the inheriting classes must implement the ev::Button::get_value() method which returns the value of input.

Methods

  • public inlineev::Eventevent()
  • public enumev::Event::button_idevent_id() const Access the event ID of the button
  • public boolget_actuated() Returns true if the button was pressed then released This will return true only once per button press.
  • publicchrono::MicroTimeget_duration() Returns the duration of the last button press. This method will only return a non-zero value once per button press.
  • publicev::Eventget_event() This method checks the state of the actuation and then returns an Event if needed.
  • public boolget_held() Returns true if the button has been held for the specified duration This will only return true once per button press.
  • public boolget_pressed() Returns true if the button has been pressed. This will only return true once per button press.
  • public boolget_released() Returns true if the button has been released. This will only return true one time for each button press.
  • public boolis_active() const Returns true if the button is currently in the active state. The active state is updated each time Button::update() is called.
  • public virtual voidreset() Reset the state of the button
  • protected virtual voidupdate() This will update the state of the button. This method should be called periodically.

Details

public inlineev::Eventevent()


public enumev::Event::button_idevent_id() const

Access the event ID of the button


public boolget_actuated()

Returns true if the button was pressed then released This will return true only once per button press.


publicchrono::MicroTimeget_duration()

Returns the duration of the last button press. This method will only return a non-zero value once per button press.


publicev::Eventget_event()

This method checks the state of the actuation and then returns an Event if needed.

It will report the following events


public boolget_held()

Returns true if the button has been held for the specified duration This will only return true once per button press.


public boolget_pressed()

Returns true if the button has been pressed. This will only return true once per button press.


public boolget_released()

Returns true if the button has been released. This will only return true one time for each button press.


public boolis_active() const

Returns true if the button is currently in the active state. The active state is updated each time Button::update() is called.


public virtual voidreset()

Reset the state of the button


protected virtual voidupdate()

This will update the state of the button. This method should be called periodically.


class ev::DeviceButton

The Device Button class implements one or more buttons using the sos/dev/button.h device driver interface.

Because the button events are running at the device driver level, the button responses will be better than ui::PinButton.

Also, using a device driver for the buttons makes the applications much more portable.

Methods

  • publicDeviceButton()
  • public intcount() const Returns the number of buttons available.
  • public inline virtual enumev::Event::button_idevent_id() const Access the event ID of the button
  • public virtual boolget_actuated() Returns true if the button was pressed then released This will return true only once per button press.
  • public virtualchrono::MicroTimeget_duration() Returns the duration of the last button press. This method will only return a non-zero value once per button press.
  • public virtual boolget_held() Returns true if the button has been held for the specified duration This will only return true once per button press.
  • public virtual boolget_pressed() Returns true if the button has been pressed. This will only return true once per button press.
  • public virtual boolget_released() Returns true if the button has been released. This will only return true one time for each button press.
  • public intinit() Initializes the button driver.
  • public virtual boolis_active() const Returns true if the button is currently in the active state. The active state is updated each time Button::update() is called.
  • public virtual voidreset() Reset the state of the button
  • public inline voidset(int location) Sets the button to the index specified.
  • public intset_attributes(int location,int id,constchrono::MicroTimeheld_threshold,constchrono::MicroTimeactuated_threshold) Sets the attributes for the specified button.
  • protected virtual voidupdate() This will update the state of the button. This method should be called periodically.

Details

publicDeviceButton()


public intcount() const

Returns the number of buttons available.

This will query the device for the number of buttons available. The set() method will select which button is read.


public inline virtual enumev::Event::button_idevent_id() const

Access the event ID of the button


public virtual boolget_actuated()

Returns true if the button was pressed then released This will return true only once per button press.


public virtualchrono::MicroTimeget_duration()

Returns the duration of the last button press. This method will only return a non-zero value once per button press.


public virtual boolget_held()

Returns true if the button has been held for the specified duration This will only return true once per button press.


public virtual boolget_pressed()

Returns true if the button has been pressed. This will only return true once per button press.


public virtual boolget_released()

Returns true if the button has been released. This will only return true one time for each button press.


public intinit()

Initializes the button driver.

Returns

Zero on success.


public virtual boolis_active() const

Returns true if the button is currently in the active state. The active state is updated each time Button::update() is called.


public virtual voidreset()

Reset the state of the button


public inline voidset(int location)

Sets the button to the index specified.

Parameters * location The button channel/location value

If the device supports multiple buttons, this method will select which button is effective.

One object can emit events for multiple buttons using this method.

#include <sapi/ui.hpp>

DeviceButton button;

button.open("/dev/button0");

int count = button.count();
for(int i = 0; i < count; i++){
  button.set(i);
  Event event = button.get_event();
}

public intset_attributes(int location,int id,constchrono::MicroTimeheld_threshold,constchrono::MicroTimeactuated_threshold)

Sets the attributes for the specified button.

Parameters * location The button index

  • id The Event ID to assign to the button

  • held_threshold The threshold to wait before button held event is triggered

  • actuated_threshold The minimum button press time for an actuation event

Returns

Zero on success


protected virtual voidupdate()

This will update the state of the button. This method should be called periodically.


class ev::Event

This class defines action-able events (such as button presses) that occur within ui::EventLoop and are handled by ui::Element::handle_event().

The event includes the type and a pointer to an object associated with the event. For example, events of type Event::SIGNAL will include a pointer to a sys::Signal object.

Methods

Details

publicEvent()


public inlineEvent(enumevent_typetype,void * object)

Construct a new event with the specified type and object


public inlineEvent(enumevent_typetype,ev::Button* button)

Constructs a new event referencing a button.

Parameters type The type of event (should be one of BUTTON_ events)

  • button A pointer to the button which caused the event.

public inlineEvent(enumevent_typetype,ui::Element* element)


public inline void *application() const


public inlineev::Button*button() const

Accesses the button associated with the event.

Returns

A pointer to the button or zero if the event is not a button event.


public inlineui::Element*element() const


public inlineEventHandler*event_handler() const


public inlineui::ListItem*list_item() const


public inline voidset_event(enumevent_typet,void * object)


public inline voidset_event(enumevent_typet,ev::Button* button)


public inline voidset_type(enumevent_typev)


public inlinesys::Signal*signal() const

Accesses the signal associated with the event.

Returns

A pointer to the signal if type is Event::SIGNAL or zero if not.


public inline enumevent_typetype() const


enum@7

  • FLAG_IS_BUTTON
  • BUTTON_FLAG
  • FLAG_IS_LIST_ITEM
  • LIST_ITEM_FLAG
  • FLAG_IS_EVENT_HANDLER
  • FLAG_IS_ELEMENT

enumbutton_id

  • NO_BUTTON No Button
  • UP_BUTTON Up Button
  • DOWN_BUTTON Down Button
  • LEFT_BUTTON LeftButton
  • RIGHT_BUTTON Right Button
  • SELECT_BUTTON Select Button
  • BACK_BUTTON Back Button
  • EXIT_BUTTON Exit Button
  • USER_BUTTON0 User button 0
  • USER_BUTTON1 User button 1
  • USER_BUTTON2 User button 2
  • USER_BUTTON3 User button 3
  • USER_BUTTON4 User button 4
  • USER_BUTTON5 User button 5
  • USER_BUTTON6 User button 6
  • USER_BUTTON7 User button 7
  • USER_BUTTON8 User button 8
  • USER_BUTTON9 User button 9
  • USER_BUTTON10 User button 10
  • USER_BUTTON11 User button 11
  • USER_BUTTON12 User button 12
  • USER_BUTTON13 User button 13
  • USER_BUTTON14 User button 14
  • USER_BUTTON15 User button 15

Button definitions


enumevent_type

  • NONE
  • SETUP This event is called at startup after all objects have been constructed
  • ENTER This event is called when the element becomes active
  • UPDATE This event is called in a loop while the element is active
  • BUTTON_ACTUATED This event is called when a button is actuated (pressed and released). Use button() to access button details.
  • BUTTON_ACTUATION
  • BUTTON_HELD This event is called when a button is held. Use button() to access button details.
  • BUTTON_HOLD
  • BUTTON_PRESSED This event is called when a button is pressed. Use button() to access button details.
  • BUTTON_RELEASED This event is called when a button is released. Use button() to access button details.
  • NETWORK_DATA This event is called when data arrives on the network
  • SIGNAL_RECEIVED This event is called when the process receives a signal
  • SIGNAL
  • APPLICATION This event is application specific where the data is specified by the application
  • LIST_ITEM_SELECTED Select an item in a list
  • LIST_ITEM_ACTUATED Actuate an item in a list
  • LIST_ACTUATED Select an item in a list or menu
  • LIST_ACTUATE
  • LIST_UP Scroll up in a list or menu
  • LIST_DOWN Scroll down in a list or menu
  • SCROLL_UP Scroll up (same as LIST_UP)
  • SCROLL_DOWN Scroll down (same as LIST_DOWN)
  • MENU_BACK Go back in the menu
  • TAB_LEFT Slide to the tab on the left
  • TAB_RIGHT Slide to the tab on the left
  • MENU_ACTUATED Select the item in the menu
  • MENU_ACTUATE
  • EXIT The application transitioned to a new element (last event on current element)

The event type


class ev::EventHandler

Methods

Details

publicEventHandler()


public inlineEventLoop*event_loop() const

Returns a pointer to the element's event loop.

If the element isn't running in an event loop, this method will return 0.


public virtualEventHandler*handle_event(constEvent& event)

Handles an event for the currently active EventHandler.

Parameters * event The event to execute

Returns

Determines if the ev::EventLoop transitions to another EventHandler or stays on this one.

ev::EventLoop::execute() and ev::EventLoop::run() execute this method each time an event happens (e.g., ev::Event::UPDATE, ev::Event::SETUP, ev::Event::BUTTON_PRESSED).

If this method returns a pointer to another EventHandler, then that event handler becomes the active ev::EventHandler.


protected inline voidset_event_loop(EventLoop* event_loop)


class ev::EventLoop

This class executes an event loop. The events are passed to the current_element() and handled using Element::handle_event(). If Element::handle_event() returns a pointer to a new element, the event loop will Event::EXIT the current element and Event::ENTER the new element and execute an animation to the new event.

The EventLoop is an abstract class, and you must implement the process_events() method which needs to process user events that are specific to the system.

ui::ButtonPin select_button(0,1); //select button is on pin 0.1

MyEventLoop::MyEventLoop(ui::Element & start_element, sgfx::Bitmap & bitmap, sgfx::Bitmap * scratch) :
   EventLoop(start_element, bitmap, scratch){
}

void MyEventLoop::process_events() {
   select_button.update();
   handle_event(select_button.event());
}

Methods

Details

publicEventLoop(EventHandler& start_event_handler)

Constructs a new headless (no display) event loop.

Parameters * start_event_handler The initial element to process

The EventLoop will typically update the display when the current_element() indicates that it should. By initializing an EventLoop using this constructor the display is ignored.


public inline virtualEventHandler*catch_null_handler(EventHandler* last_event_handler)

Is executed when the event handler returns a null event and the current event is set to null.

Parameters * last_event_handler The event handler that returned a null handler.

The default behavior is to exit from the EventLoop (execute() method). This method can be reimplemented by the application to update the event handler based on the value and state of last_event_handler.


public inlineEventHandler*current_event_handler() const

Accesses the current event handler.


public virtual voidexecute()

Executes the event loop.

First the event loop will have the current ev::EventHandler handle Event::SETUP.

The loop will then transition to the initial ev::EventHandler and execute Event::ENTER.

The loop will then fire Event::UPDATE every update_period(). If hibernation_threshold() is less than update_period(), the loop will attempt to put the processor in hibernation periodically to save power.

If period() is less then hibernation_threshold(), the loop will execute process_events() every period().

If EventHandler::handle_event() returns a pointer to a new EventHandler, a transtion will occur which includes:

The loop will then continue to process_events() and fire Event::UPDATE as well as hibernate as appropriate for the new element.

If EventHandler::handle_event() returns 0 (null pointer), the event loop will stop executing. That is this method will return.


public virtual voidloop()

Loops while the current element is valid. It handles sending events to the active element. See execute() for more details.


public voidprocess_events()

This method should call handle_event for each possible event in the event loop.

Button * up_button;
Button * down_button;

void MyEventLoop::process_events(){

   handle_event(up_button->event());
   handle_event(down_button->event());
   //call handle event on any other events -- Event loop handles SETUP, ENTER, and UPDATE

}

public inline voidset_current_event_handler(EventHandler* v)

Sets the current event handler.


public virtual voidstart()

This is called just before the loop starts executing. This method will send the Event::SETUP and Event::ENTER events to the primary element.


protected voidcheck_loop_for_hibernate()


protected voidcheck_loop_for_update()


protected virtual boolhandle_event(constEvent& event)

Handles the specified event.

Parameters * event Event to handle within the loop

This method should be called by process_events() whenever the system triggers an event. For example, if the system needs to just handle an up button or down button press:

#include <sapi/hal.hpp>

ButtonPin up_button(0,0);
ButtonPin down_button(0,1)

void MyEventLoop::process_events(){
 up_button.update(); //refresh button status
 down_button.update();

 handle_event(up_button.event());
 handle_event(down_button.event());

}

protected inlinechrono::Timer&loop_timer()


protected inlinechrono::Timer&update_timer()


class ev::EventLoopAttributes

This class defines attributes that apply to an ui::EventLoop.

Methods

Details

publicEventLoopAttributes()

Construct new Event Loop attributes


public inlinechrono::MicroTimehibernation_threshold() const

Accesses the hibernate timeout in chrono::MicroTime.


public inlineoperator event_loop_attr_t() const


public inlinechrono::MicroTimeperiod() const

Accesses the minimum period of the event loop in chrono::MicroTime.


public inlinechrono::MicroTimerefresh_wait_resolution() const

Accesses the display refresh wait resolution time in microseconds.

The loop will always wait for the display driver to complete its refresh before handling events that modify the display memory. This value determines how long to sleep between polling events to the display driver.


public inline voidset_hibernation_threshold(constchrono::MicroTime& value)

Sets the hibernate threshold in MicroTime.

Parameters * value The hibernate threshold as a MicroTime value

If the update period (set_update_period()) is greater than the hibernation threshold, the event loop will execute the kernel request for hibernation. If the kernel request is not handled, the event loop will put the system in hibernate. The logic looks like this:

if( update_period() > hibernation_threshold() ){
   if( Sys::request(SAPI_REQUEST_HIBERNATE) < 0 ){
      Sys::hibernate( update_period() / 1000 );  //kernel hibernate will wake on an RTC alarm if the RTC is present
   }
}

This logic allows the BSP (which implements the kernel_request() function called by Sys::request()) to override or delay the hibernation until other applications or tasks are ready.

By default, the hibernation threshold is set to the max value (65536) effectively disabling hibernation.

The system will stay in hibernation mode until a hardware interrupt wakes the processor. This interrupt typically needs to be a external pin interrupt or RTC alarm because most peripherals are off during hiberation.


public inline voidset_period(constchrono::MicroTime& value)

Sets the period of the event loop in chrono::MicroTime.

Parameters * msec The loop period in milliseconds.

The loop will delay this amount on every iteration. This determines how often events are processed (such as buttons). It is typically a much smaller value than the update period which determines how often Event::UPDATE is handled.


public inline voidset_refresh_wait_resolution(constchrono::MicroTime& value)

Sets the value of the display refresh wait resolution in microseconds.

Parameters * value The number of microseconds to between display driver polling events

See refresh_wait_resolution() for more details.


public inline voidset_update_period(constchrono::MicroTime& value)

Sets the Event::UPDATE period which defines how often the event loop will trigger the Event::UPDATE command for the current element.

Parameters * value The period as chrono::MicroTime

If the update period is less than the loop period (see set_period()), Event::UPDATE will be called on every loop at the loop period interval.


public inlinechrono::MicroTimeupdate_period() const

Accesses the period for firing the Event::UPDATE in chrono::MicroTime.


protected event_loop_attr_tm_attr


class ev::PinButton

This class implements a button using a hal::Pin object.

This class samples the pin during the ui::EventLoop. If the ui::EventLoop is sluggish at times, the button presses might not be responsive (or may be missed).

If this is the case, it is better to use DeviceButton because DeviceButton samples in the the background and will queue button presses if the ui::EventLoop is being slow.

Methods

  • publicPinButton(int port,int pin,bool active_value) Construct a new ButtonPin
  • public inline boolactive_value() const This method accesses the active value.
  • public inline virtual enumev::Event::button_idevent_id() const Access the event ID of the button
  • public virtual boolget_actuated() Returns true if the button was pressed then released This will return true only once per button press.
  • public virtualchrono::MicroTimeget_duration() Returns the duration of the last button press. This method will only return a non-zero value once per button press.
  • public virtual boolget_held() Returns true if the button has been held for the specified duration This will only return true once per button press.
  • public virtual boolget_pressed() Returns true if the button has been pressed. This will only return true once per button press.
  • public virtual boolget_released() Returns true if the button has been released. This will only return true one time for each button press.
  • public inline virtual boolis_active() const Returns true if the button is currently in the active state. The active state is updated each time Button::update() is called.
  • public virtual voidreset() Reset the state of the button
  • public inline voidset_event_id(enumev::Event::button_idv)
  • public inline voidset_id(enumev::Event::button_idv) Set the ID of the button for Events
  • protected virtual boolget_is_active() const
  • protected virtual voidupdate() This will update the state of the button. This method should be called periodically.

Details

publicPinButton(int port,int pin,bool active_value)

Construct a new ButtonPin

The pin must be initialized using Pin::init()

Parameters * port The port associated with the pin

  • pin The pin number on the port for the button input

  • active_value true for active high and false for active low


public inline boolactive_value() const

This method accesses the active value.

Returns

True for active high and false for active low.


public inline virtual enumev::Event::button_idevent_id() const

Access the event ID of the button


public virtual boolget_actuated()

Returns true if the button was pressed then released This will return true only once per button press.


public virtualchrono::MicroTimeget_duration()

Returns the duration of the last button press. This method will only return a non-zero value once per button press.


public virtual boolget_held()

Returns true if the button has been held for the specified duration This will only return true once per button press.


public virtual boolget_pressed()

Returns true if the button has been pressed. This will only return true once per button press.


public virtual boolget_released()

Returns true if the button has been released. This will only return true one time for each button press.


public inline virtual boolis_active() const

Returns true if the button is currently in the active state. The active state is updated each time Button::update() is called.


public virtual voidreset()

Reset the state of the button


public inline voidset_event_id(enumev::Event::button_idv)


public inline voidset_id(enumev::Event::button_idv)

Set the ID of the button for Events


protected virtual boolget_is_active() const


protected virtual voidupdate()

This will update the state of the button. This method should be called periodically.


struct ev::event_loop_attr_t

Methods

Details

public u16hibernation_threshold_msec


public u16period_usec


public u16refresh_wait_resolution_usec


public u16update_period_usec


namespace fmt

Classes

class fmt::Bmp

Methods

  • publicBmp(constvar::ConstString& name) Constructs a new bitmap object and opens the bitmap as a read-only file.
  • publicBmp() Constructs an empty bitmap object.
  • public inline u16bits_per_pixel() const Returns the bitmap bits per pixel (after bitmap has been opened).
  • public unsigned intcalc_row_size() const Calculates the bytes needed to store one row of data (after bitmap has been opened).
  • public intcreate(constvar::ConstString& name,s32 width,s32 height,u16 planes,u16 bits_per_pixel) Creates a new bitmap using the specified parameters.
  • public inline s32height() const Returns the bitmap height (after bitmap has been opened).
  • public virtual intopen(constvar::ConstString& name,int access) Opens the specified bitmap with the specified access (e.g., Bmp::READONLY).
  • public intopen_readonly(constvar::ConstString& name) Opens the specified bitmap as readonly.
  • public intopen_readwrite(constvar::ConstString& name) Opens the specified bitmap as read write.
  • public inline u16planes() const Returns the bitmap planes (after bitmap has been opened).
  • public intread_pixel(u8 * pixel,u32 pixel_size,bool mono,u8 thres) Reads a pixel from the bitmap (optionally convert to a mono value).
  • public inline voidrewind() Moves file pointer to the start of the bitmap data.
  • public intseek_row(s32 y) const Seeks the file to the data at the specified row.
  • public inline s32width() const Returns the bitmap width (after bitmap has been opened).

Details

publicBmp(constvar::ConstString& name)

Constructs a new bitmap object and opens the bitmap as a read-only file.


publicBmp()

Constructs an empty bitmap object.


public inline u16bits_per_pixel() const

Returns the bitmap bits per pixel (after bitmap has been opened).


public unsigned intcalc_row_size() const

Calculates the bytes needed to store one row of data (after bitmap has been opened).


public intcreate(constvar::ConstString& name,s32 width,s32 height,u16 planes,u16 bits_per_pixel)

Creates a new bitmap using the specified parameters.


public inline s32height() const

Returns the bitmap height (after bitmap has been opened).


public virtual intopen(constvar::ConstString& name,int access)

Opens the specified bitmap with the specified access (e.g., Bmp::READONLY).


public intopen_readonly(constvar::ConstString& name)

Opens the specified bitmap as readonly.


public intopen_readwrite(constvar::ConstString& name)

Opens the specified bitmap as read write.


public inline u16planes() const

Returns the bitmap planes (after bitmap has been opened).


public intread_pixel(u8 * pixel,u32 pixel_size,bool mono,u8 thres)

Reads a pixel from the bitmap (optionally convert to a mono value).

Parameters * pixel Data pointing to destination

  • pixel_size in bytes

  • mono true to convert to a mono pixel

  • thres threshold brightness for a mono pixel to be on


public inline voidrewind()

Moves file pointer to the start of the bitmap data.


public intseek_row(s32 y) const

Seeks the file to the data at the specified row.


public inline s32width() const

Returns the bitmap width (after bitmap has been opened).


class fmt::Png

Methods

Details

publicPng(constvar::ConstString& name)


class fmt::Son

The SON (Stratify Object Notation) is an important class to be familiar with. It is closely related to JSON (and very closely related to BSON). It allows you to store, access, and modify data in the same way but is designed for use on resource constrained systems.

SON data can be easily converted to JSON data using the to_json() method.

Important things to note:

  • Key names are limited to 15 (SON_KEY_NAME_SIZE) characters (longer names are truncated)

  • The stacksize template value is the depth limit when creating files

  • You can't modify the length of strings or data objects within a file

  • You must create root ("") as the first object or array

Creation example:

#include <sapi/fmt.hpp>

int main(int argc, char * argv[]){
   Son son<4>; //depth is limited to 4

//tabs are added to help visualize the data in JSON format
   son.create("/home/settings.son");
      son.open_object("");
         son.write("name", "Stratify"); //create a string
         son.write("date", "today"); //create another string
         son.write("value", (u32)100); //write a number);
         son.open_object("time"); //create a new object
            son.write("hour", 12); //add some values
            son.write("min", 00);
            son.write("sec", 59);
         son.close_obj(); //close 'time'
      son.close_obj(); //close root ""
   son.close();

   char buffer[32];
   u32 value;
   son.open_read("/home/settings.son"); //opens read-only

   son.read_str("name", buffer, 32);
   //buffer holds "Stratify"

   value = son.read_unum("hour");
   son.read_str("sec", buffer, 32);
   //buffer holds "59"

   son.to_json("/home.settings.json");
   son.close();

   }

The home/settings.json files looks like: { "name": "Stratify", "date": "today", "value": 100, "time": { "hour": 12, "min": 0, "sec": 59 } }

Note that JSON numbers are always in floating point format. So unum and num values get converted to float value. If the JSON data is converted to SON, all numbers will be in float format.

Methods

  • publicSon(u16 max_depth,son_stack_t * stack) Constructs a new SON object.
  • public~Son()
  • public inline intclose() Closes a SON file.
  • public inline intclose_array() Closes an array while writing or appending.
  • public inline intclose_data() Closes a data object.
  • public inline intclose_object() Closes an object while writing or appending a file.
  • public inline intcreate(constvar::ConstString& name) Creates a new SON file
  • public inline intcreate_message(void * message,int nbyte) Creates a memory message SON object.
  • public inline intcreate_message(var::Data& data) Creates a memory message SON object.
  • public inline intcreate_message(int nbyte) Creates a memory message SON object using dynamic memory allocation.
  • public inline intedit(constvar::ConstString& access,float v) Edits a float value.
  • public inline intedit(constvar::ConstString& access,const void * data,son_size_t size) Edits a data value.
  • public inline intedit(constvar::ConstString& access,constvar::ConstString& str) Edits a string value.
  • public inline intedit(constvar::ConstString& access,constvar::String& v) Edits a string value.
  • public inline intedit(constvar::ConstString& access,s32 v) Edits a number value (signed 32-bit).
  • public inline intedit(constvar::ConstString& access,u32 v) Edits a number value (unsigned 32-bit).
  • public inline intedit(constvar::ConstString& access,bool v) Edits a boolean value.
  • public inline interr() const Returns the current error value.
  • public inline intfileno() const Returns file descriptor of the SON file.
  • public inline intget_error() Gets the current error value.
  • public inline intget_message_size() Gets the size of the message in bytes.
  • public inline u16max_depth() const
  • public inline intopen_append(constvar::ConstString& name) Opens a file for appending data.
  • public inline intopen_array(constvar::ConstString& key) Opens a new array while writing or appending.
  • public inline intopen_data(constvar::ConstString& key) Opens a data object while writing or appending.
  • public inline intopen_edit(constvar::ConstString& name) Opens a SON file for editing.
  • public inline intopen_edit_message(void * message,int nbyte) Opens a SON message for editing.
  • public inline intopen_message(void * message,int nbyte) Opens a SON message for reading.
  • public inline intopen_message(var::Data& data)
  • public inline intopen_object(constvar::ConstString& key) Opens a new object while writing or appending.
  • public inline intopen_read(constvar::ConstString& name) Opens a SON file for reading.
  • public inline intopen_read_message(void * message,int nbyte)
  • public inline intopen_read_message(var::Data& data)
  • public inlineoperator son_t &()
  • public inline boolread_bool(constvar::ConstString& access) Reads the specified key as a bool.
  • public inline intread_data(constvar::ConstString& access,void * data,son_size_t size) Reads the specified key as data. Regardless of the storage type, the key will be returned as binary data.
  • public inline floatread_float(constvar::ConstString& access) Reads the specified key as a number (float).
  • public inline s32read_num(constvar::ConstString& access) Reads the specified key as a number (s32). If the original key was not written as a s32, it will be converted to one. A string of "100" will be converted to (s32)100. Objects that cannot be converted will return 0.
  • public inlinevar::Stringread_string(constvar::ConstString& access) Reads the specified key as a string. If the original key was not written as a string, it will be converted to a string. For example, a (u32)100 will be converted to "100". A data object will be converted to base64 encoding.
  • public inline u32read_unum(constvar::ConstString& access) Reads the specified key as a number (u32). If the original key was not written as a s32, it will be converted to one. A string of "100" will be converted to (u32)100. Objects that cannot be converted will return 0.
  • public inline intrecv_message(int fd,int timeout_msec) Receives a message on the specified file descriptor.
  • public inline intseek(constvar::ConstString& access,son_size_t & data_size) Seeks to the location of the access code and gets the size of the data in bytes.
  • public inline intseek_next(var::String& name,son_value_t * type) Seeks the next value in the file.
  • public inline intseek_next(var::String& name,son_value_t & type)
  • public inline intsend_message(int fd,int timeout_msec) Sends a message on the specified file descriptor.
  • public inline son_t &son() Access the son_t data object.
  • public inline u16stack_size() const
  • public inline intto_json(constvar::ConstString& path) Converts the data file to JSON.
  • public inline intto_json(son_to_json_callback_t callback,void * context) Converts the data file to JSON.
  • public inline intwrite(constvar::ConstString& key,constvar::ConstString& v) Writes a key/string pair to the file.
  • public inline intwrite(constvar::ConstString& key,s32 v) Writes a key/number pair to the file (s32).
  • public inline intwrite(constvar::ConstString& key,u32 v) Writes a key/number pair to the file (u32).
  • public inline intwrite(constvar::ConstString& key,float v) Writes a key/number pair to the file (float).
  • public inline intwrite(constvar::ConstString& key,bool v) Writes a key/bool pair to the file.
  • public inline intwrite(constvar::ConstString& key,const void * v,son_size_t size) Writes a key/data pair to the file. The data is stored in the file in binary format.
  • public inline intwrite_open_data(const void * v,son_size_t size) Adds data to an open key.
  • enumson_err_t

Details

publicSon(u16 max_depth,son_stack_t * stack)

Constructs a new SON object.


public~Son()


public inline intclose()

Closes a SON file.


public inline intclose_array()

Closes an array while writing or appending.

Returns

Zero on success

To proper operation, this a call to this method must correspond to a call to open_data().


public inline intclose_data()

Closes a data object.

Returns

Zero on success

To proper operation, this a call to this method must correspond to a call to open_data().


public inline intclose_object()

Closes an object while writing or appending a file.


public inline intcreate(constvar::ConstString& name)

Creates a new SON file

Parameters * name The name of the file

Returns

Zero on success


public inline intcreate_message(void * message,int nbyte)

Creates a memory message SON object.

Parameters * message The memory message

  • nbyte The number of bytes in the message

Returns

Zero on success


public inline intcreate_message(var::Data& data)

Creates a memory message SON object.

Parameters * data A reference to the data object used to store the message

Returns

Zero on success


public inline intcreate_message(int nbyte)

Creates a memory message SON object using dynamic memory allocation.

Parameters * nbyte The number of bytes in the message

Returns

Zero on success


public inline intedit(constvar::ConstString& access,float v)

Edits a float value.

Parameters * access The access code for the value

  • v The new value to write

Returns

Zero on success


public inline intedit(constvar::ConstString& access,const void * data,son_size_t size)

Edits a data value.

Parameters * access The access code for the value

  • data A pointer to the source data

  • size The number of bytes to edit

Returns

Zero on success

If size exceeds the size of the orginal data object, the new data will be truncated to that size.


public inline intedit(constvar::ConstString& access,constvar::ConstString& str)

Edits a string value.

Parameters * access The acces for for the value

  • str The new string

Returns

Zero on success

If the length of the new string exceeds the length of the original string, the new string will be truncated to fit.


public inline intedit(constvar::ConstString& access,constvar::String& v)

Edits a string value.

Parameters * access The acces for for the value

  • v The new string

Returns

Zero on success

If the length of the new string exceeds the length of the original string, the new string will be truncated to fit.


public inline intedit(constvar::ConstString& access,s32 v)

Edits a number value (signed 32-bit).

Parameters * access The access for for the value

  • v The new value

Returns

Zero on success


public inline intedit(constvar::ConstString& access,u32 v)

Edits a number value (unsigned 32-bit).

Parameters * access The access for for the value

  • v The new value

Returns

Zero on success


public inline intedit(constvar::ConstString& access,bool v)

Edits a boolean value.

Parameters * access The access for for the value

  • v The new value

Returns

Zero on success


public inline interr() const

Returns the current error value.


public inline intfileno() const

Returns file descriptor of the SON file.


public inline intget_error()

Gets the current error value.

Returns

The SON error value

The current error value is returned. This method will clear the error value such that if it is called twice it will return the error then it will return SON_ERR_NONE.


public inline intget_message_size()

Gets the size of the message in bytes.

Returns

The number of bytes that will be sent is send_message() is called or less than zero for an error.


public inline u16max_depth() const


public inline intopen_append(constvar::ConstString& name)

Opens a file for appending data.

Parameters * name The path/name of the file to open

Returns

Less than zero for an error


public inline intopen_array(constvar::ConstString& key)

Opens a new array while writing or appending.

Parameters * key The key to use for the new array

Returns

Zero on success


public inline intopen_data(constvar::ConstString& key)

Opens a data object while writing or appending.

Parameters * key The key to use for the new data

Returns

Zero on success


public inline intopen_edit(constvar::ConstString& name)

Opens a SON file for editing.

Parameters * name Name of the file

Returns

Zero on success


public inline intopen_edit_message(void * message,int nbyte)

Opens a SON message for editing.

Parameters * message The memory message

  • nbyte The number of bytes in the message

Returns

Zero on success


public inline intopen_message(void * message,int nbyte)

Opens a SON message for reading.

Parameters * message The memory message

  • nbyte The number of bytes in the message

Returns

Zero on success


public inline intopen_message(var::Data& data)


public inline intopen_object(constvar::ConstString& key)

Opens a new object while writing or appending.

Parameters * key The key to use for the new object

Returns

Zero on success


public inline intopen_read(constvar::ConstString& name)

Opens a SON file for reading.

Parameters * name Name of the file

Returns

Zero on success


public inline intopen_read_message(void * message,int nbyte)


public inline intopen_read_message(var::Data& data)


public inlineoperator son_t &()


public inline boolread_bool(constvar::ConstString& access)

Reads the specified key as a bool.

Parameters * access Key parameters

Returns

True if the key is found and is true; false otherwise.


public inline intread_data(constvar::ConstString& access,void * data,son_size_t size)

Reads the specified key as data. Regardless of the storage type, the key will be returned as binary data.

Parameters * access Key parameters

  • data A pointer to the destination data

  • size The number of bytes to read

Returns

The number of bytes read


public inline floatread_float(constvar::ConstString& access)

Reads the specified key as a number (float).

Parameters * access Key parameters

Returns

The number

If the original key was not written as a float, it will be converted to one. A string of "100" will be converted to (float)100. Objects that cannot be converted will return 0.


public inline s32read_num(constvar::ConstString& access)

Reads the specified key as a number (s32). If the original key was not written as a s32, it will be converted to one. A string of "100" will be converted to (s32)100. Objects that cannot be converted will return 0.

Parameters * access Key parameters

Returns

The number


public inlinevar::Stringread_string(constvar::ConstString& access)

Reads the specified key as a string. If the original key was not written as a string, it will be converted to a string. For example, a (u32)100 will be converted to "100". A data object will be converted to base64 encoding.

Parameters * access Key parameters

Returns

The number of bytes actually read


public inline u32read_unum(constvar::ConstString& access)

Reads the specified key as a number (u32). If the original key was not written as a s32, it will be converted to one. A string of "100" will be converted to (u32)100. Objects that cannot be converted will return 0.

Parameters * access Key parameters

Returns

The number


public inline intrecv_message(int fd,int timeout_msec)

Receives a message on the specified file descriptor.

Parameters * fd The file descriptor to listen for the message on.

  • timeout_msec The max number of milliseconds to wait between bytes before aborting.

Returns

The number of bytes received or less than zero for an error


public inline intseek(constvar::ConstString& access,son_size_t & data_size)

Seeks to the location of the access code and gets the size of the data in bytes.

Parameters * access The access code to seek to

  • data_size A pointer to write the data size to (null if not needed)

Returns

Zero on success


public inline intseek_next(var::String& name,son_value_t * type)

Seeks the next value in the file.

Parameters * name A reference to a string where the name will be stored

  • type If non-null, the type of the object will be written to this value.

Returns

Less than zero for an error or the son_value_t of the current item.


public inline intseek_next(var::String& name,son_value_t & type)


public inline intsend_message(int fd,int timeout_msec)

Sends a message on the specified file descriptor.

Parameters * fd The file descriptor to write the message to.

  • timeout_msec The max number of milliseconds to wait between bytes before aborting.

Returns

The number of bytes sent or less then zero for an error


public inline son_t &son()

Access the son_t data object.


public inline u16stack_size() const


public inline intto_json(constvar::ConstString& path)

Converts the data file to JSON.

Parameters * path The path to a file to create with the JSON data

Returns

Zero on success


public inline intto_json(son_to_json_callback_t callback,void * context)

Converts the data file to JSON.

Parameters * callback A callback that is used to process the JSON data (c string)

  • context The parameter that is passed to callback

Returns

Zero on success


public inline intwrite(constvar::ConstString& key,constvar::ConstString& v)

Writes a key/string pair to the file.

Parameters * key The value key

  • v A pointer to the string

Returns

Number of bytes in the value portion to be successfully stored


public inline intwrite(constvar::ConstString& key,s32 v)

Writes a key/number pair to the file (s32).

Parameters * key The value key

  • v The number to write

Returns

Number of bytes stored (4) if successful


public inline intwrite(constvar::ConstString& key,u32 v)

Writes a key/number pair to the file (u32).

Parameters * key The value key

  • v The number to write

Returns

Number of bytes stored (4) if successful


public inline intwrite(constvar::ConstString& key,float v)

Writes a key/number pair to the file (float).

Parameters * key The value key

  • v The number to write

Returns

Number of bytes stored (4) if successful


public inline intwrite(constvar::ConstString& key,bool v)

Writes a key/bool pair to the file.

Parameters * key The value key

  • v true or false

Returns

Number of bytes stored if successful


public inline intwrite(constvar::ConstString& key,const void * v,son_size_t size)

Writes a key/data pair to the file. The data is stored in the file in binary format.

Parameters * key The value key

  • v A pointer to the data to be written

  • size The number of bytes to write

Returns

Number of bytes stored (4) if successful


public inline intwrite_open_data(const void * v,son_size_t size)

Adds data to an open key.

Parameters * v A pointer to the data to be written

  • size The number of bytes to write

Returns

Number of bytes stored (4) if successful

This is used with open_data() and close_data(). These methods are useful for writing data to the file when the amount of data to be written is unknown when writing begins.

#include <sapi/Var.hpp>
Son son<4>;

son.create("/home/data.son");
son.open_data("datakey");
son.write_open_data(buffer, 32);
son.close_data();

enumson_err_t

  • ERR_NONE This value indicates no error has occurred.
  • ERR_NO_ROOT This error happens when a top level object or array is not created.
  • ERR_OPEN_IO This error happens if there is an IO failure to create or open a file (run perror() for more info).
  • ERR_READ_IO This error happens when an IO read operation fails (run perror() for more info).
  • ERR_WRITE_IO This error happens when an IO write operation fails (run perror() for more info).
  • ERR_CLOSE_IO This error happens when an IO close operation fails (run perror() for more info).
  • ERR_SEEK_IO This error happens when an IO seek operation fails (run perror() for more info).
  • ERR_READ_CHECKSUM This error happens when the data in the file has a invalid checksum which indicates a corrupted file or bad file format.
  • ERR_CANNOT_APPEND This error happens when an append is attempted on a file that has not been saved for appending
  • ERR_CANNOT_WRITE This error happens if a write is attempted on a file that has been opened for reading
  • ERR_CANNOT_READ This error happens if a read is attempted on a file that has been opened for writing or appending
  • ERR_INVALID_ROOT This error happens when the root object is not valid (usually a bad file format or corrupted file).
  • ERR_ARRAY_INDEX_NOT_FOUND This error happens when an array index could not be found
  • ERR_ACCESS_TOO_LONG This error happens if the access parameter len exceeds SON_ACCESS_MAX_USER_SIZE.
  • ERR_KEY_NOT_FOUND This error happens when the key specified by the access parameter could not be found.
  • ERR_STACK_OVERFLOW This error happens if the depth (son_open_array() or son_open_object()) exceeds, the handle's stack size.
  • ERR_INVALID_KEY This happens if an empty key is passed to anything but the root object.
  • ERR_CANNOT_CONVERT This happens if a read is tried by the base data can't be converted
  • ERR_EDIT_TYPE_MISMATCH This happens if a value is edited with a function that doesn't match the base type

class fmt::Svic

The Svc class manages files that contain collections of Stratify Vector icons.

Methods

Details

publicSvic(constvar::ConstString& path)


public intappend(constvar::ConstString& name,constvar::Vector< sg_vector_path_description_t > & list)


public sgfx::VectorPathat(u32 i) const


public inline u32count() const


public sgfx::VectorPathget(constvar::ConstString& name) const


publicvar::Stringname_at(u32 i) const


class fmt::Wav

Methods

Details

publicWav(constvar::ConstString& name)

Constructs a new WAV object and open the WAV as a read-only file.


public inline u32bits_sample() const


public inline u32bytes_sec() const


public inline u32channels() const


public inline u32data_size() const


public inline u32sample_rate() const


public inline virtual u32size() const

Returns the file size.


public inline u32wav_fmt() const


public inline u32wav_size() const


namespace hal

The hal namespace includes classes for accessing mcu peripheral hardware and other devices.

All objects in the hal namespace inherit either:

Work objects inherit sys::File and allow access to the hardware using a POSIX style API (open(), close(), read(), write() and ioctl()).

Info objects contain attributes that facilitate configuring and querying hardware.

Classes

class hal::Adc

This class implements ADC device peripherals.

#include <sapi/hal.hpp>

int main(int argc, char * argv[]){
   Adc adc(0);  //create an instance of ADC to access port 0
   u32 samples[16];
   adc.init(); //initialize the ADC using the default configuration
   adc.read(0, samples, 16*sizeof(u32)); //read 16 samples from channel 0
   adc.read(1, samples, 16*sizeof(u32)); //read 16 samples from channel 1
   adc.close(); //close the ADC
}

Methods

Details

publicAdc(port_tport)

Initializes the object with port.


publicAdcInfoget_info() const

Returns an AdcInfo object associated with the ADC.


public inline intinit(u32 o_flags,u32 freq,constadc_pin_assignment_t* pin_assignment)


public inline intset_attr(u32 o_flags,u32 freq,constadc_pin_assignment_t* pin_assignment) const


enum@8

  • FLAG_SET_CONVERTER
  • FLAG_IS_LEFT_JUSTIFIED
  • FLAG_IS_RIGHT_JUSTIFIED
  • SET_CONVERTER See ADC_FLAG_SET_CONVERTER
  • IS_LEFT_JUSTIFIED See ADC_FLAG_IS_LEFT_JUSTIFIED
  • IS_RIGHT_JUSTIFIED Set to specify right justified data
  • SET_MASTER
  • SET_SLAVE
  • IS_TRIGGER_TMR
  • IS_TRIGGER_EINT
  • SET_CHANNELS
  • IS_SCAN_MODE
  • IS_TRIGGER_EINT_EDGE_RISING Trigger the sample on the rising edge
  • IS_TRIGGER_EINT_EDGE_FALLING Trigger the sample on the falling edge
  • IS_GROUP Set channel as part of a group
  • IS_CONTINOUS_CONVERSION Start the next conversion as soon as the previous conversion completes

class hal::AdcAttributes

This class is for containing ADC attributes.

Methods

Details

public inlineAdcAttributes()


public inlineAdcAttributes(u32 o_flags,u32 freq)


public inline voidconfigure_group_channel(u16 channel,u32 rank,u32 sampling_time)

Configures a channel in a group for sampling.

Parameters * channel The channel number to sample

  • rank The rank (order) of the channel

  • sampling_time The sampling time (in ADC clocks for the channel)

AdcAttributes adc_attributes;
adc_attributes.configure_group_channel(0, 1, 15);
Adc adc(0);

adc.init();
adc.set_attributes(adc_attributes);

public inline voidset_channel(u16 channel)


public inline voidset_rank(u32 rank)


public inline voidset_sampling_time(u32 sampling_time)


class hal::AdcInfo

Methods

Details

public inlineAdcInfo()


public inline u8bytes_per_sample() const


public inline u32calculate_millivolts(u32 sample_value) const


public inline u32frequency() const


public inline const adc_info_t &info() const


public inline adc_info_t &info()


public inline boolis_valid() const


public inline u32maximum_value() const


public inline u32o_events() const


public inline u32o_flags() const


public inline u32reference_millivolts() const


public inline u32resolution() const


class hal::AdcPinAssignment

This class allows simple manipulation of the adc_pin_assignment_t.

class hal::CFifo

The Channeled FIFO allows access to channeled fifo devices. A channeled FIFO device is a FIFO with multiple independent channels. The file descriptor's location/offset (updated with lseek()) is used to set the channel.

Methods

  • public intexit(int channel) const Exits the FIFO specified by channel.
  • public intflush(int channel) const Flushes the FIFO specified by channel.
  • public intget_count() const Gets the number of channels in the channeled fifo.
  • public intget_info(cfifo_info_t & info) const Gets the info for the channeled fifo.
  • public intget_info(int channel,fifo_info_t & info) const Gets the info specified by channel.
  • publicFifoInfoget_info(int channel) Returns the Fifo info for the specified channel.
  • public intget_owner(int channel,int & owner) const Gets the owner of the specified channel.
  • public inline u32get_ready_channels() const Gets a bitmask of channels that have at least one byte that is ready to be read.
  • public inline intinit(int channel) const
  • public intinitialize(int channel) const Initializes the FIFO specified by channel.
  • public inline intset_attr(int channel,constfifo_attr_t& attr) const
  • public intset_attributes(int channel,constfifo_attr_t& attr) const Sets the FIFO attributes specified by channel.
  • public intset_owner(int channel,int owner) const Sets the owner of a channel.
  • public intset_writeblock(int channel,bool value) const Enables or disables write blocking on the FIFO specified by channel.

Details

public intexit(int channel) const

Exits the FIFO specified by channel.

Parameters * channel The FIFO channel to de-initialize

Returns

Zero on success


public intflush(int channel) const

Flushes the FIFO specified by channel.

Parameters * channel The channel to flush

Returns

Zero on success


public intget_count() const

Gets the number of channels in the channeled fifo.


public intget_info(cfifo_info_t & info) const

Gets the info for the channeled fifo.


public intget_info(int channel,fifo_info_t & info) const

Gets the info specified by channel.

Parameters * channel The channel for which to fetch the FIFO info

  • info A reference to the destination information

Returns

Zero on success


publicFifoInfoget_info(int channel)

Returns the Fifo info for the specified channel.


public intget_owner(int channel,int & owner) const

Gets the owner of the specified channel.

Parameters * channel The channel that is queried

  • owner A reference to write the owner value

Returns

Zero on success or less than zero for an error

This method along with set_owner() provides a mechanism to reserve the channel for a particular application. If the owner has been set to a non-zero value, it is already being used by another process and should not be used.


public inline u32get_ready_channels() const

Gets a bitmask of channels that have at least one byte that is ready to be read.

Returns

Bitmask of channels that are ready to be read


public inline intinit(int channel) const


public intinitialize(int channel) const

Initializes the FIFO specified by channel.

Parameters * channel The FIFO channel to initialize

Returns

Zero on success


public inline intset_attr(int channel,constfifo_attr_t& attr) const


public intset_attributes(int channel,constfifo_attr_t& attr) const

Sets the FIFO attributes specified by channel.

Parameters * channel The channel for which to set the FIFO attributes

  • attr A reference to the fifo attributes

Returns


public intset_owner(int channel,int owner) const

Sets the owner of a channel.

Parameters * channel The channel

  • owner The owner (usually the process ID)

Returns

Zero on success

This method is used with get_owner() to allow processes to reserve channels for passing information.


public intset_writeblock(int channel,bool value) const

Enables or disables write blocking on the FIFO specified by channel.

Parameters * channel The target channel

  • value True to enable write blocking

Returns

Zero on success

If write blocking is enabled, the FIFO will block (or return EAGAIN is O_NONBLOCK is on) if no bytes can be written to the FIFO. If a single byte can be written, write() will return 1.

With write blocking disable, write() will never block. It will simply overwrite the data that is already in the FIFO.


class hal::CFifoInfo

Methods

Details

public inlineCFifoInfo()


public inlineCFifoInfo(const cfifo_info_t & info)


public inline u16count() const


public inline u32o_flags() const


public inline u32o_ready() const


public inlineoperator const cfifo_info_t &() const


public inline u16size() const


class hal::Core

This is the Core class. It is used to access core MCU information such as clock speed and to adjust interrupt priorities.

Here is an example of how to read the MCU serial number:

#include <sapi/hal.hpp>
#include <cstdio>

int main(int argc, char * argv[]){
   int i;
   Core core(0);
   core_attr_t attr;
   core.open();
   core.get_attr(&attr);
   printf("Serial Number is:");
   for(i=3; i >= 0; i--){
      printf("%X", attr.serial_number[i]);
   }
   printf("\n");
   core.close(); //core is never "powered-down" but this frees the file descriptor
}

Methods

  • publicCore(port_tport) Contructs a new core object using the specified port.
  • public intget_mcu_board_config(mcu_board_config_t & config) Loads the MCU board configuration data provided by the board support package.
  • public voidinvoke_bootloader() Invokes the device's bootloader. If no bootloader is available, a normal reset will occur.
  • public voidreset() Resets the device.
  • public intset_clock_divide(u32 value) Sets the core CPU clock divider.
  • public intset_pin_function(constcore_pinfunc_t& req) Changes pin functionality using a core_pinfunc_t structure.
  • public inline intset_pin_function(int port,int pin,int func,int func_port) Changes pin function.
  • enumfunc Core functional types

Details

publicCore(port_tport)

Contructs a new core object using the specified port.

Parameters * port The core port (zero for all single core devices)


public intget_mcu_board_config(mcu_board_config_t & config)

Loads the MCU board configuration data provided by the board support package.

Parameters * config A reference to the destination data

Returns

Zero on success


public voidinvoke_bootloader()

Invokes the device's bootloader. If no bootloader is available, a normal reset will occur.


public voidreset()

Resets the device.


public intset_clock_divide(u32 value)

Sets the core CPU clock divider.

Parameters * value The amount to divide the clock by

Returns

Zero on success

This method will change the CPU clock speed (if supported). If the native clock speed is 120MHz the following code will make it 60MHz

Core core(0);
core.open();
core.set_clock_divide(2); //set to 60MHz
core.set_clock_divide(1); //restore to 120MHz
core.close();

public intset_pin_function(constcore_pinfunc_t& req)

Changes pin functionality using a core_pinfunc_t structure.


public inline intset_pin_function(int port,int pin,int func,int func_port)

Changes pin function.

Parameters * port The PIO port

  • pin The PIO pin number

  • func The function (e.g. Core::UART)

  • func_port The functional port (e.g. 0 for UART0)

Returns

Zero on success

This can be used if the default pinassign values are not adequate for your application.


enumfunc

  • CORE Core Functionality
  • ADC Analog to Digital Converter
  • DAC Digital to Analog Converter
  • UART UART
  • SPI SPI
  • USB USB
  • CAN CAN
  • ENET ENET
  • I2C I2C
  • I2S I2S
  • MEM External memory interface
  • RTC RTC
  • CEC Consumer Electronic Control (Part of HDMI)
  • QEI Quadrature Encoder Interface
  • PWM PWM
  • PIO GPIO
  • TMR Timer (output compare and input capture)
  • EINT External interrupts
  • WDT Watch dog timer
  • BOD Brown out detection
  • DMA Direct Memory Access
  • JTAG JTAG
  • RESET Reset
  • CLKOUT Clockout
  • LCD LCD
  • LCD1 LCD
  • LCD2 LCD
  • LCD3 LCD
  • EMC External Memory Controller
  • MCI Multimedia Card Interface
  • SSP SSP
  • MCPWM Motor Control PWM
  • NMI Non-maskable Interrupt
  • TRACE Trace data

Core functional types


class hal::CoreAttributes

class hal::CoreInfo

Methods

  • public inlineCoreInfo() Constructs an empty Core Info object.
  • public inlineCoreInfo(const core_info_t & info) Constructs a Core Info object from a core_info_t data structure.
  • public inline u32o_events() const Returns the events that are supported by the core.
  • public inline u32o_flags() const Returns the flags that are supported by the core.
  • public inlinesys::SerialNumberserial_number() const Returns the serial number of the MCU.

Details

public inlineCoreInfo()

Constructs an empty Core Info object.


public inlineCoreInfo(const core_info_t & info)

Constructs a Core Info object from a core_info_t data structure.


public inline u32o_events() const

Returns the events that are supported by the core.


public inline u32o_flags() const

Returns the flags that are supported by the core.


public inlinesys::SerialNumberserial_number() const

Returns the serial number of the MCU.


class hal::Dac

DAC (Digital to Analog Converter) Class

The DAC class is used to write data to the digital to analog converter. Here is an example:

#include <sapi/hal.hpp>
#include <sapi/sys.hpp>

int main(int argc, char * argv[]){
   Dac dac(0);
   u32 samples[50];
   dac.init(); //init with default settings

 //here, write meaningful values to samples

   dac.write(0, samples, 50*sizeof(u32)); //This returns when all 50 samples are written

 //if you want to do other things while the sample is written use AIO
   Aio aio(samples, 50*sizeof(u32));

   dac.write(aio);
 //Here you can do other things while the data is written
   while( aio.is_busy() == true ){
      Timer::wait_usec(500); //wait until the write is complete
   }

   dac.close(); //this will power off the DAC if nothing else has it open

   return 0;
}

Methods

  • publicDac(port_tport)
  • public inline u32get_channel(u32 loc) const Gets the current value of the DAC channel.
  • public inline intinit(u32 o_flags,u32 freq,const dac_pin_assignment_t * pin_assignment) Opens the DAC and sets the attributes using specified values.
  • public inline intset_attr(u32 o_flags,u32 freq,const dac_pin_assignment_t * pin_assignment) const Sets the DAC attributes using specified values.
  • public inline intset_channel(u32 loc,u32 value) const Sets the value of the DAC channel.
  • enum@9

Details

publicDac(port_tport)


public inline u32get_channel(u32 loc) const

Gets the current value of the DAC channel.

Parameters * loc The DAC channel to get

Returns

The current value of the channel or (u32)-1 if ther is an error


public inline intinit(u32 o_flags,u32 freq,const dac_pin_assignment_t * pin_assignment)

Opens the DAC and sets the attributes using specified values.

See set_attr() for parameter descriptions.


public inline intset_attr(u32 o_flags,u32 freq,const dac_pin_assignment_t * pin_assignment) const

Sets the DAC attributes using specified values.

Parameters * o_flags Enabled channels as a bitmask

  • freq DAC output frequency

  • pin_assignment The pins to use (if null, default pins will be used if available)


public inline intset_channel(u32 loc,u32 value) const

Sets the value of the DAC channel.

Parameters * value Value to write to the DAC

  • loc The DAC channel

Returns

Zero on success


enum@9

  • FLAG_SET_CONVERTER
  • FLAG_LEFT_JUSTIFIED
  • FLAG_RIGHT_JUSTIFIED
  • SET_CONVERTER Set to configure the converter
  • LEFT_JUSTIFIED Set to left justify the data
  • RIGHT_JUSTIFIED Set to right justify the data

class hal::DacAttributes

This class is for containing DAC attributes.

Methods

Details

public inlineDacAttributes(u32 o_flags,u32 freq)


class hal::DacPinAssignment

This class allows simple manipulation of the dac_pin_assignment_t.

class hal::Device

This is a device class used for accessing MCU peripherals and other devices.

  • MCU peripheral hardware (most devices have a class that inherits this class)

  • Devices with built-in drivers (see "/dev" folder on the device)

#include <sapi/hal.hpp>

int main(int argc, char * argv[]){
  char buffer[16];
  Device device;
  device.open("/dev/fifo", Device::RDWR); //open the system fifo (if it exists)
  device.read(0, buffer, 16);             //read 16 bytes from channel (location) 0
  device.close();                         //close the SPI (power it off)
  return 0;
}

Methods

Details

publicDevice()

Constructs a Device.

Unlike sys::File, upon creation the is_close_on_destruct() flag is cleared for all devices (and hal::Periph). In order to close a device, close() must be called explicitly.

This is the desired behavior because it is common to create more than one hal::Device object to access the same hardware in different contexts.


public intcancel(int channel,int o_events)


public intcancel_read(int channel)


public intcancel_write(int channel)


public inline virtual constDevice&operator<<(constchrono::MicroTime& t) const


public virtual intread(sys::Aio& aio) const

Reads the device asynchronously.

Parameters * aio A reference to the sys::Aio object to use for reading

See also: sys::Aio


public intset_interrupt_priority(int priority,int request)


public inline intset_signal_action(constDeviceSignal& signal,u32 o_events,u32 channel)

Configures the device to send a signal when an event happens.

Parameters * signal The signal to send

  • o_events A bitmask of events which will cause the signal to be sent

  • channel The hardware channel to listen for events on


public virtual intwrite(sys::Aio& aio) const

Writes the device asynchronously.

Parameters * aio A reference to the sys::Aio object to use for writing

See also: sys::Aio


class hal::DeviceSignal

This class allows you to configure physical events to trigger signals. For example, a rising edge on a pin can cause the system to send a signal to a thread. Here is an example:

#include <sapi/sys.hpp>
#include <sapi/hal.hpp>

volatile bool my_var;
void my_handler(int a){
   //this executes on the rising edge of EINT0
   my_var = true;
   //you shouldn't use any non re-entrant functions here (such as printf() and malloc())

}

int main(int argc, char * argv[]){
   Eint eint(0);

   DeviceSignal dev_signal(true, Signal::USR1);  //send SIGUSR1 to this thread on every rising edge
   SignalHandler handler(my_handler);

   eint.init(0);
   event.set_handler(handler);

   //this configures the hardware to send the signal to this thread (my_handler() will execute)
   //dev_signal MUST exist as long as this action is set
   eint.set_action( dev_signal.create_action(EINT_ACTION_EVENT_RISING) );

   while(my_var == false){
      Timer::wait_sec(1);
   }

   return 0;
}

Methods

  • public inlineDeviceSignal(bool persistent,int signo,int sigvalue,int sigcode) Constructs a signal event based on a hardware device action.
  • public inlineDeviceSignal(bool persistent,int signo,void * sigptr,int sigcode) Constructs a signal event based on a hardware device action.
  • public inlineDeviceSignal(const devfs_signal_callback_t & context) Constructs a signal event based on a hardware device action using a signal_callback_t data structure.
  • public inlinemcu_action_tcreate_action(int event,int channel,int prio) const This returns a mcu_action_t data structure that can be used to set the action associated with a hardware event.

Details

public inlineDeviceSignal(bool persistent,int signo,int sigvalue,int sigcode)

Constructs a signal event based on a hardware device action.

Parameters * persistent If false, the signal will be sent only on the first hardware event

  • signo The signal number

  • sigcode The signal code

  • sigvalue The signal value


public inlineDeviceSignal(bool persistent,int signo,void * sigptr,int sigcode)

Constructs a signal event based on a hardware device action.

Parameters * persistent If false, the signal will be sent only on the first hardware event

  • signo The signal number

  • sigcode The signal code

  • sigptr The signal value as a pointer


public inlineDeviceSignal(const devfs_signal_callback_t & context)

Constructs a signal event based on a hardware device action using a signal_callback_t data structure.

Parameters * context A copy of the signal_callback_t data to use to handle the event.


public inlinemcu_action_tcreate_action(int event,int channel,int prio) const

This returns a mcu_action_t data structure that can be used to set the action associated with a hardware event.

Parameters * event The hardware event

  • channel The hardware channel

Returns

a copy of a mcu_action_t data structure


class hal::Display

The Display class is for drawing on a display such as an OLED or LCD.

Methods

  • public inlineDisplay() Constructs a new object with no video memory.
  • public inlineDisplay(sg_bmap_data_t * mem,sg_size_t w,sg_size_t h) Constructs a new object with the provided memory buffer
  • public inlineDisplay(sg_size_t w,sg_size_t h) Constructs a new object and dynamically allocates memory for the buffer.
  • public intdisable() const Turns the display off.
  • public intenable() const Turns the display on.
  • public intinitialize(constvar::ConstString& name) Initializes the display.

Details

public inlineDisplay()

Constructs a new object with no video memory.


public inlineDisplay(sg_bmap_data_t * mem,sg_size_t w,sg_size_t h)

Constructs a new object with the provided memory buffer

Parameters * mem A pointer to the bitmap memory

  • w The width of the memory area in pixels

  • h The height of the memory area in pixels


public inlineDisplay(sg_size_t w,sg_size_t h)

Constructs a new object and dynamically allocates memory for the buffer.

Parameters * w The width of the display

  • h The height of the display

public intdisable() const

Turns the display off.


public intenable() const

Turns the display on.


public intinitialize(constvar::ConstString& name)

Initializes the display.


class hal::DisplayDevice

This class is a display device. It inherits both Display and Dev so that a display found at, for example, "/dev/display0" can be drawn on.

Methods

  • publicDisplayDevice()
  • public virtual voidclear() Fill the data with zeros.
  • public virtual intdisable() const Turns the display off.
  • public virtual intenable() const Turns the display on.
  • public virtual intinitialize(constvar::ConstString& name) Initializes the display.
  • public virtual boolis_busy() const Returns true if the display is actively copying the video buffer to the display
  • public virtual voidrefresh() const Refreshes the display.
  • public voidwait(u16 resolution) const Blocks until the display is not busy anymore.

Details

publicDisplayDevice()


public virtual voidclear()

Fill the data with zeros.


public virtual intdisable() const

Turns the display off.


public virtual intenable() const

Turns the display on.


public virtual intinitialize(constvar::ConstString& name)

Initializes the display.


public virtual boolis_busy() const

Returns true if the display is actively copying the video buffer to the display

Returns

True if the LCD is busy


public virtual voidrefresh() const

Refreshes the display.

This method will cause the driver to write the current video memory to the display.


public voidwait(u16 resolution) const

Blocks until the display is not busy anymore.


class hal::DisplayPalette

A display palette is used to map bitmap colors to an actual display. The Stratify graphics library supports the following formats.

  • 1bpp (1 bit per pixel)

  • 2bpp

  • 4bpp

  • 8bpp

This class is used to manage how the graphics pixel formats maps to the display. For example, if the graphics use 4bpp and the display uses RGB565, the palette would have 16 entries that contain RGB565 values and define how a color in the 4bpp format maps to a color on the display.

Methods

Details

publicDisplayPalette()


publicDisplayPalette(constdisplay_palette_t& palette,bool readonly)


public intalloc_colors(int count,int pixel_size)

Allocates memory for count colors with pixel_size bytes each.

Parameters * count The total number of colors

  • pixel_size The number of bytes occupied by each color

Returns

Less than zero if there were an error allocating memory


public u16bits_per_pixel() const


public inlinevar::Data&colors()


public inline constvar::Data&colors() const


public inline u8count() const

Returns the number of colors in the palette.


public intload(const char * path)


public inline u8pixel_format() const

Returns the pixel format.


public intsave(const char * path) const


public voidset_color(u32 v,u8 r,u8 g,u8 b)

Sets the color.

Parameters * v The color index

  • r The red component

  • g The green component

  • b The blue component

The color format is converted based on the value of pixel_format(). For example, if pixel_format() returns PIXEL_FORMAT_RGB565, the color will be set in the palette to match that format.


public voidset_colors(void * v,int count,int pixel_size,bool readonly)


public intset_monochrome()


public inline voidset_pixel_format(int v)


enum@10

  • PIXEL_FORMAT_1BPP
  • PIXEL_FORMAT_RGB444
  • PIXEL_FORMAT_RGB565
  • PIXEL_FORMAT_RGB666
  • PIXEL_FORMAT_RGB888

class hal::Eint

This class gives access to external interrupt circuitry. You can use this class to have the interrupt trigger a function or block a thread until the interrupt arrives.

Here is an example:

#include <sapi/hal.hpp>
#include <sapi/sys.hpp>

 //This will be executed when the event is triggered
int event_callback(void * args, const void * data){
   volatile int * done = (int*)args;
   *done = 1;
   return 0; //return 0 to clear the callback and 1 to keep it
}

void eint_example(){
   volatile int done;
   Eint eint(0); //use eint port 0 (pin 2.10 on lpc17xx devices)

   eint.init(); //open and set attributes

   eint.set_action(0, //use channel 0
      EINT_ACTION_EVENT_FALLING, //trigger on a falling edge
      event_callback, //execute this function (in privileged mode when complete)
      &done //pass this to event_callback as the first argumen
      );

   while( done == 0 ){
      Timer::wait_milliseconds(1); //wait for the signal to arrive
   }

}

 //alternatively you can configure (set_action() and block by writing hwpl_action_t to the device)

 mcu_action_t action;
 action.channel = 0;
 action.event = EINT_ACTION_EVENT_FALLING;
 action.callback = 0; //this is ignored and doesn't need to be set
 action.context = 0; //this is ignored and doesn't need to be set
 eint.write(&action, sizeof(action)); //this will block until a falling edge arrives

Methods

Details

publicEint(port_tport)


public inline boolget_value()

Reads the value of the pin


class hal::EintAttributes

class hal::EintPinAssignment

This class allows simple manipulation of the eint_pin_assignment_t.

class hal::FFifo

The FFIFO class is for access devices that are framed FIFOs from <sos/dev/ffifo.h>.

A framed FIFO is a FIFO where each read and write operation must match an integer multiple value of the frame size.

They are useful for storing audio data streams where fixed frame sizes arrive and need to be buffered before being processed.

Methods

Details

publicFFifo()


public intflush() const

Flushes the FIFO.

Returns

Zero on success


publicFFifoInfoget_info() const

Returns the information for the FFIFO.


public intget_info(FFifoInfo& info) const

Gets the FFIFO information.

Parameters * info A reference to the destination value

Returns

Less than zero on an error


public intinitialize(constvar::ConstString& path,const FFifoAttributes & attributes,int o_flags)

Opens and initiliazes the device.

Parameters * path The path to the device (e.g., /dev/ffifo0)

  • attr The attributes to assign

  • o_flags Flags to use when opening e.g. FFifo::NONBLOCK

Returns

Zero on success or less than zero for an error


public inlineFFifo&operator<<(const FFifoAttributes & attributes)


public intset_attributes(const FFifoAttributes & attributes) const

Sets the FIFO attributes.


class hal::FFifoAttributes

Methods

Details

public inlineFFifoAttributes()

Constructs an object set to all zeros.


public inlineFFifoAttributes(constffifo_attr_t& attr)

Constructs an object from a ffifo_attr_t data structure.


public inline voidset_overflow()

Sets the overflow flag.

This will cause the device to overwrite old data rather than block when the device is full.


public inline voidset_write_block()

Sets the write block flag.

This will cause the device to block or return errno EAGAIN if a write is attempted while the FIFO is full.


class hal::FFifoInfo

Methods

  • public inlineFFifoInfo() Constructs an object with all zeros.
  • public inlineFFifoInfo(const ffifo_info_t & info) Constructs an object by copying info.
  • public inline u16frame_count() const Returns the number of frames in the framed FIFO.
  • public inline u16frame_count_ready() const Returns the number of frames currently in use.
  • public inline u16frame_size() const Returns the number of frames in the framed FIFO.
  • public inline boolis_overflow() const Returns true if the FFIFO has overflowed. This flag is cleared on FFifo::get_info().
  • public inline boolis_valid() const Returns true if the info is valid.
  • public inline u32size() const Returns the total number of bytes used by the FFIFO buffer (frame size * frame count).

Details

public inlineFFifoInfo()

Constructs an object with all zeros.


public inlineFFifoInfo(const ffifo_info_t & info)

Constructs an object by copying info.


public inline u16frame_count() const

Returns the number of frames in the framed FIFO.


public inline u16frame_count_ready() const

Returns the number of frames currently in use.

This is the number of frames that is ready to be read.


public inline u16frame_size() const

Returns the number of frames in the framed FIFO.


public inline boolis_overflow() const

Returns true if the FFIFO has overflowed. This flag is cleared on FFifo::get_info().


public inline boolis_valid() const

Returns true if the info is valid.


public inline u32size() const

Returns the total number of bytes used by the FFIFO buffer (frame size * frame count).


class hal::Fifo

The Fifo class connects to Fifo devices which can be used for:

  • Inter-process communication

  • Buffering serial I/O from SPI, I2S, USB, etc

For example, the default STDIO is implemented as two fifo buffers: one for input and one for output. A typical application will write the STDOUT fifo while the USB protocol will read the fifo and display it on the screen. Alternatively, a separate application or the kernel could read the STDOUT and print it on a display or send it out the UART.

Fifo's can be opened in blocking and non-blocking modes when both reading and writing. If Fifo::set_writeblock() is called, a write will block when the Fifo is full. Otherwise, the Fifo will overflow and FifoInfo::is_overflow() will return true.

#include <cstdio>
#include <sapi/hal.hpp>

Fifo fifo;
FifoInfo attr;

if( fifo.open("/dev/fifo", Fifo::RDWR) < 0 ){
   perror("failed to open fifo");
}

if( fifo.attr().used() > 0){
   //fifo is not empty
}

//write some data to the fifo
fifo.write("Testing fifo write\n");

fifo.close();

Methods

  • publicFifo()
  • public intfinalize() const
  • public intflush() const Flushes the FIFO.
  • public intget_info(FifoInfo& info) const Reads the Fifo Attributes.
  • publicFifoInfoget_info() const Returns the fifo info.
  • public intinitialize() const Initialize the FIFO. This function should only be called once even if several contexts access the FIFO.
  • public intset_writeblock(bool value) const Sets the FIFO in write block mode.
  • enum@11

Details

publicFifo()


public intfinalize() const


public intflush() const

Flushes the FIFO.


public intget_info(FifoInfo& info) const

Reads the Fifo Attributes.


publicFifoInfoget_info() const

Returns the fifo info.


public intinitialize() const

Initialize the FIFO. This function should only be called once even if several contexts access the FIFO.

Returns

Less than zero for an error.


public intset_writeblock(bool value) const

Sets the FIFO in write block mode.

Parameters * value True to enable write block or false to disable it

If write blocking is enabled, the FIFO will block (or return EAGAIN is O_NONBLOCK is on) if no bytes can be written to the FIFO. If a single byte can be written, write() will return 1.

With write blocking disable, write() will never block. It will simply overwrite the data that is already in the FIFO.


enum@11

  • FLAG_SET_WRITEBLOCK
  • FLAG_IS_OVERFLOW
  • FLAG_NOTIFY_WRITE
  • FLAG_NOTIFY_READ
  • FLAG_INIT
  • FLAG_EXIT
  • FLAG_FLUSH
  • SET_WRITEBLOCK
  • IS_OVERFLOW
  • IS_NOTIFY_WRITE
  • IS_NOTIFY_READ
  • INIT
  • EXIT
  • FLUSH

class hal::FifoInfo

Methods

  • public inlineFifoInfo() Constructs an object with all zeros.
  • public inlineFifoInfo(const fifo_info_t & info) Constructs an object from a fifo_info_t reference.
  • public inline boolis_overflow() const This method accesses whether or not the FIFO has overflowed since the last time the FIFO attributes have been read.
  • public inline boolis_valid() const Returns true if the FIFO info object is valid.
  • public inline booloverflow() const
  • public inline u32size() const This method accesses the maximum number of bytes allocated for the FIFO.
  • public inline u32size_ready() const The number of bytes in the FIFO that are currently used (ie available for reading.

Details

public inlineFifoInfo()

Constructs an object with all zeros.


public inlineFifoInfo(const fifo_info_t & info)

Constructs an object from a fifo_info_t reference.


public inline boolis_overflow() const

This method accesses whether or not the FIFO has overflowed since the last time the FIFO attributes have been read.


public inline boolis_valid() const

Returns true if the FIFO info object is valid.


public inline booloverflow() const


public inline u32size() const

This method accesses the maximum number of bytes allocated for the FIFO.


public inline u32size_ready() const

The number of bytes in the FIFO that are currently used (ie available for reading.

Returns

The number of bytes available for reading.


class hal::I2C

This class implements I2C device peripherals.

An I2C ptr/data transfer (I2C::FLAG_PREPARE_PTR_DATA) updates the register pointer and then either reads or writes data. For example:

#include <sapi/hal.hpp>

int main(int argc, char * argv[]){
   u16 data;
   I2C i2c(0); //use I2C port 0
   i2c.init(); //Initialize the I2C using the BSP defaults
   i2c.prepare(0x4C); //slave addr is 0x4C - operation is 8-bit ptr plus data
   i2c.read(5, &data, sizeof(data)); //read 2 bytes from register 5
   i2c.close();
}

The code above will execute 2 I2C transactions. It will write 5 to the I2C slave device register pointer. It will then read 2 bytes from the slave device.

The following example doesn't write the register pointer. It also shows how to customize the initialization.

int main(int argc, char * argv[]){
u16 data;
   I2C i2c(1);
   I2CPinAssignment pin_assignment;
   pin_assignment->sda = mcu_pin(0,10);
   pin_assignment->scl = mcu_pin(0,11);

   i2c.init(I2C::FLAG_SET_MASTER, 400000, pin_assignment);
   i2c.prepare(0x4C, FLAG_PREPARE_DATA); //prepare for data only transactions
   i2c.write(&data, sizeof(u16)); //write two bytes
   i2c.read(&data, sizeof(u16)); //read two bytes
i2c.close();
}

The I2C can also be configured using POSIX calls.

int main(int argc, char * argv[]){
   int fd;
   fd = open("/dev/i2c0", O_RDWR);
   if( fd < 0 ){
      perror("Failed to open I2C");
   } else {
      i2c_attr_t attr;
      attr.o_flags = I2C_FLAG_SET_MASTER;
      attr.freq = 100000;
      attr.pin_assignment.sda = mcu_pin(0,10);
      attr.pin_assignment.scl = mcu_pin(0,11);
      if( ioctl(fd, I_I2C_SETATTR, &attr) < 0 ){
         perror("Failed to set I2C attr");

         //Or the BSP defaults can be used
         if( ioctl(fd, I_I2C_SETATTR, 0) < 0 ){
            perror("No BSP defaults");
         }
      } else {

         attr.o_flags = I2C_FLAG_PREPARE_PTR_DATA;
         attr.slave_addr[0].addr8[0] = 0x4C;
         ioctl(fd, I_I2C_SETATTR, &attr);
         lseek(fd, 10, SEEK_SET);
         write(fd, &value, sizeof(u16)); //first writes 10 (from lseek) then writes 2 bytes (value)
      }
      close(fd);
   }

return 0;
}

See also: hal::I2CPinAssignment

See also: hal::I2CAttr

Methods

  • publicI2C(port_tport) Constructs an I2C object using the specified port.
  • public inline intclear(int loc,int bit) Clears the bit in a register on an I2C device.
  • public inline intget_err() const
  • public intget_error() const Gets the last error.
  • public inline intinit(u32 o_flags,u32 freq,consti2c_pin_assignment_t* pin_assignment)
  • public intprepare(u8 slave_addr,u32 o_flags) const Prepares an I2C transaction.
  • public intread(int loc,u8 & reg) Reads the value of a register on an I2C device
  • public intreset() const Resets the I2C bus state.
  • public intset(int loc,int bit,bool high) Sets (or clears) a specific bit in a a register on an I2C device.
  • public inline intset_attr(u32 o_flags,u32 freq,consti2c_pin_assignment_t* pin_assignment)
  • public intwrite(int loc,u8 reg) Writes the value of a register on an I2C device
  • enum@12
  • enum@13

Details

publicI2C(port_tport)

Constructs an I2C object using the specified port.


public inline intclear(int loc,int bit)

Clears the bit in a register on an I2C device.


public inline intget_err() const


public intget_error() const

Gets the last error.


public inline intinit(u32 o_flags,u32 freq,consti2c_pin_assignment_t* pin_assignment)


public intprepare(u8 slave_addr,u32 o_flags) const

Prepares an I2C transaction.

Parameters * slave_addr The slave address for the transaction

  • o_flags The flags for the transaction

Returns

Zero on success

The o_flags can be:

  • FLAG_PREPARE_PTR_DATA (default)

  • FLAG_PREPARE_PTR_16_DATA

  • FLAG_PREPARE_PTR

  • FLAG_PREPARE_DATA


public intread(int loc,u8 & reg)

Reads the value of a register on an I2C device


public intreset() const

Resets the I2C bus state.


public intset(int loc,int bit,bool high)

Sets (or clears) a specific bit in a a register on an I2C device.

Parameters * loc The register offset value

  • bit The bit to set (or clear)

  • high true to set the bit and false to clear it

Returns

Zero on success


public inline intset_attr(u32 o_flags,u32 freq,consti2c_pin_assignment_t* pin_assignment)


public intwrite(int loc,u8 reg)

Writes the value of a register on an I2C device


enum@12

  • ERROR_NONE No errors
  • ERROR_START Error while starting
  • ERROR_WRITE Error while writing
  • ERROR_ACK Ack Error (most common error for a mis-wired hardware)
  • ERROR_STOP Error while stopping
  • ERROR_MASTER_ACK The master could not create an ACK
  • ERROR_BUS_BUSY The Bus is busy (happens with multi-masters on bus)
  • ERROR_LONG_SLEW
  • ERROR_ARBITRATION_LOST Arbitration lost on multi-master bus

enum@13

  • FLAG_NONE
  • FLAG_SET_MASTER
  • FLAG_SET_SLAVE
  • FLAG_IS_SLAVE_ACK_GENERAL_CALL
  • FLAG_IS_PULLUP
  • FLAG_PREPARE_PTR_DATA
  • FLAG_IS_PTR_16
  • FLAG_PREPARE_PTR
  • FLAG_PREPARE_DATA
  • FLAG_IS_SLAVE_ADDR0
  • FLAG_IS_SLAVE_ADDR1
  • FLAG_IS_SLAVE_ADDR2
  • FLAG_IS_SLAVE_ADDR3
  • FLAG_IS_SLAVE_PTR_8
  • FLAG_IS_SLAVE_PTR_16
  • FLAG_RESET
  • FLAG_STRETCH_CLOCK
  • FLAG_IS_NO_STOP
  • SET_MASTER Operate as a master I2C bus
  • SET_SLAVE Operate as a slave (ignored if master is set)
  • IS_SLAVE_ACK_GENERAL_CALL If slave operation, ack general call
  • IS_PULLUP Enable internal pullups if available (ignore otherwise)
  • PREPARE_PTR_DATA This prepares the driver to write the ptr then read/write data
  • IS_PTR_16 This prepares the driver to write a 16-bit ptr then read/write data
  • PREPARE_PTR This will write the ptr value only without writing or reading any data.
  • PREPARE_DATA This will read/write data without first writing the pointer information
  • IS_SLAVE_ADDR0 If hardware supports multiple slave addrs, use the first slot (default)
  • IS_SLAVE_ADDR1 If hardware supports multiple slave addrs, use the second slot
  • IS_SLAVE_ADDR2 If hardware supports multiple slave addrs, use the third slot
  • IS_SLAVE_ADDR3 If hardware supports multiple slave addrs, use the fourth slot
  • IS_SLAVE_PTR_8 Use a 8-bit address pointer when accessing data (default)
  • IS_SLAVE_PTR_16 Use a 16-bit address pointer when accessing data (set automatically is size > 255)
  • RESET Reset the state of the I2C
  • IS_STRETCH_CLOCK
  • IS_NO_STOP Don't issue a stop condition when complete (use with I2C_FLAG_PREPARE_DATA)

class hal::I2CAttributes

The I2C attribute class is used for configuring and storing I2C port settings.

See also: hal::I2CPinAssignment

See also: hal::I2C

Methods

  • public inlineI2CAttributes(u32 o_flags,u32 freq)
  • public inlinemcu_pin_tscl() const Access the SCL pin assignment value.
  • public inlinemcu_pin_tsda() const Accesses the SDA pin assignment value.
  • public inline voidset_scl(constmcu_pin_t& pin) Sets the SCL pin assignment value.
  • public inline voidset_scl(u8 port,u8 pin) Sets the SCL pin assignment value.
  • public inline voidset_sda(constmcu_pin_t& pin) Sets the SDA pin assignment value.
  • public inline voidset_sda(u8 port,u8 pin) Sets the SDA pin assignment value.
  • public inline voidset_slave_addr(u8 addr) Sets the 7-bit slave address value.
  • public inline voidset_slave_addr16(u16 addr) Sets the 16-bit slave address value.
  • public inline u8slave_addr() const Access the slave address value.
  • public inline u8slave_addr16() const Accesses the 16-bit slave address value.

Details

public inlineI2CAttributes(u32 o_flags,u32 freq)


public inlinemcu_pin_tscl() const

Access the SCL pin assignment value.


public inlinemcu_pin_tsda() const

Accesses the SDA pin assignment value.


public inline voidset_scl(constmcu_pin_t& pin)

Sets the SCL pin assignment value.


public inline voidset_scl(u8 port,u8 pin)

Sets the SCL pin assignment value.


public inline voidset_sda(constmcu_pin_t& pin)

Sets the SDA pin assignment value.


public inline voidset_sda(u8 port,u8 pin)

Sets the SDA pin assignment value.


public inline voidset_slave_addr(u8 addr)

Sets the 7-bit slave address value.


public inline voidset_slave_addr16(u16 addr)

Sets the 16-bit slave address value.


public inline u8slave_addr() const

Access the slave address value.


public inline u8slave_addr16() const

Accesses the 16-bit slave address value.


class hal::I2CPinAssignment

This class allows simple manipulation of the i2c_pin_assignment_t.

See also: hal::I2C

See also: hal::I2CAttributes

class hal::I2S

Methods

  • publicI2S(port_tport)
  • public inline intinit(u32 o_flags,u32 freq,u32 mck_mult,const i2s_pin_assignment_t * pin_assignment) This method initializes the I2C port.
  • public inline intset_attr(u32 o_flags,u32 freq,u32 mck_mult,const i2s_pin_assignment_t * pin_assignment)
  • enum@14

Details

publicI2S(port_tport)


public inline intinit(u32 o_flags,u32 freq,u32 mck_mult,const i2s_pin_assignment_t * pin_assignment)

This method initializes the I2C port.

Parameters * o_flags Flag bitmask

  • freq Bitrate

  • pin_assignment Pin assignment or null to use default pin assignment

Returns

Zero on success

This method calls open() then set_attr().


public inline intset_attr(u32 o_flags,u32 freq,u32 mck_mult,const i2s_pin_assignment_t * pin_assignment)


enum@14

  • IS_WIDTH_8 I2S Word Width 8 bits
  • IS_WIDTH_16 I2S Word Width 16 bits
  • IS_WIDTH_24 I2S Word Width 24 bits
  • IS_WIDTH_32 I2S Word Width 32 bits
  • IS_MONO I2S Mono mode
  • IS_STEREO I2S Stereo mode (default behavoir)
  • SET_MASTER Set the I2S as a master
  • SET_SLAVE Set the I2S as a slave
  • IS_TRANSMITTER Set the I2S transmitter (master or slave)
  • IS_RECEIVER Set the I2S receiver (master or slave)
  • IS_FORMAT_MSB Set this bit for MSB format
  • IS_FORMAT_LSB Set this bit for LSB format
  • IS_MCK_ENABLED Set this bit to enable the mclk output
  • IS_FORMAT_PCM_SHORT Set this bit for PCM Short format
  • IS_FORMAT_PCM_LONG Set this bit for PCM Long format
  • IS_WIDTH_16_EXTENDED I2S has 16-bits of data in 32-bit blocks

class hal::I2SAttributes

The I2C attribute class is used for configuring and storing I2C port settings.

See also: hal::I2CPinAssignment

See also: hal::I2C

Methods

  • public inlineI2SAttributes(u32 o_flags,u32 freq,u32 mck_mult)
  • public inlinemcu_pin_tsdin() const Accesses the serial data input pin assignment value.
  • public inlinemcu_pin_tsdout() const Access the serial data output pin assignment value.
  • public inline voidset_flags(u32 o_flags) Sets the o_flags value as specified.
  • public inline voidset_freq(u32 frequency)
  • public inline voidset_frequency(u32 frequency) Sets the frequency (rate for left/right clock).
  • public inline voidset_mck(constmcu_pin_t& pin) Sets the SCL pin assignment value.
  • public inline voidset_sck(constmcu_pin_t& pin) Sets the SCL pin assignment value.
  • public inline voidset_sdin(constmcu_pin_t& pin) Sets the SDA pin assignment value.
  • public inline voidset_sdout(constmcu_pin_t& pin) Sets the SCL pin assignment value.
  • public inline voidset_ws(constmcu_pin_t& pin) Sets the SCL pin assignment value.

Details

public inlineI2SAttributes(u32 o_flags,u32 freq,u32 mck_mult)


public inlinemcu_pin_tsdin() const

Accesses the serial data input pin assignment value.


public inlinemcu_pin_tsdout() const

Access the serial data output pin assignment value.


public inline voidset_flags(u32 o_flags)

Sets the o_flags value as specified.


public inline voidset_freq(u32 frequency)


public inline voidset_frequency(u32 frequency)

Sets the frequency (rate for left/right clock).


public inline voidset_mck(constmcu_pin_t& pin)

Sets the SCL pin assignment value.


public inline voidset_sck(constmcu_pin_t& pin)

Sets the SCL pin assignment value.


public inline voidset_sdin(constmcu_pin_t& pin)

Sets the SDA pin assignment value.


public inline voidset_sdout(constmcu_pin_t& pin)

Sets the SCL pin assignment value.


public inline voidset_ws(constmcu_pin_t& pin)

Sets the SCL pin assignment value.


class hal::I2SPinAssignment

This class allows simple manipulation of the i2c_pin_assignment_t.

See also: hal::I2S

See also: hal::I2SAttr

class hal::Led

The LED Class is used to control LEDs based on the standard LED driver.

Methods

  • publicLed()
  • public intdisable(bool high_impedance) const Disables the LED.
  • public intenable(u32 duty,u32 period) const Enables the LED with the specified duty cycle and period.
  • public inline intenable() const Turns the LED on.
  • public inline intenable(float brightness) const Enables the LED with the specified brightness.
  • public inline intflash(float duty_cycle,float period) Flashes the LED.
  • public intget_info(led_info_t& info) const Gets the info for the LED.
  • enum@15

Details

publicLed()


public intdisable(bool high_impedance) const

Disables the LED.

Parameters * high_impedance True to set the off state to float

Returns

Zero on success

For the pin to be set to float, the driver must support the FLAG_IS_HIGH_IMPEDANCE flag.


public intenable(u32 duty,u32 period) const

Enables the LED with the specified duty cycle and period.

Parameters * duty The duty cycle (in microseconds) to be on

  • period The period in microseconds

This method can be used to both set the brightness and flash the LED. To use as brightness control, set the period to a small value.

Returns

Zero on success


public inline intenable() const

Turns the LED on.

Returns

Zero on success


public inline intenable(float brightness) const

Enables the LED with the specified brightness.

Parameters * brightness Brightness from 0.0 to 1.0

Returns

Zero on success


public inline intflash(float duty_cycle,float period)

Flashes the LED.

Parameters * duty_cycle The duty cycle in seconds

  • period The period in seconds

Returns

Zero on success


public intget_info(led_info_t& info) const

Gets the info for the LED.

Parameters * info A reference to the destination information

Returns

Zero on success

After this method is called, the info.o_flags value will indicate what flags are supported by the driver. If FLAG_IS_DUTY_CYCLE is set, then the driver supports brightness control and flashing. Otherwise, the driver can simple enable and disable the LED.


enum@15

  • FLAG_IS_HIGH_IMPEDANCE
  • FLAG_IS_DUTY_CYCLE
  • FLAG_ENABLE
  • FLAG_DISABLE
  • IS_HIGH_IMPEDANCE See LED_FLAG_IS_HIGH_IMPEDANCE
  • IS_DUTY_CYCLE See LED_FLAG_IS_DUTY_CYCLE
  • ENABLE See LED_FLAG_ENABLE
  • DISABLE See LED_FLAG_DISABLE

class hal::Periph

This is an abstract class for a microcontroller peripheral.

All peripherals have a common interface based on the following function:

The classes that inherit Periph implement a method for each ioctl() call available on the peripheral. For example, the UART has an ioctl request called I_UART_SETATTR so the method Uart::set_attr() implements the ioctl request.

Methods

  • public inlinePeriph(core_periph_tperiph,port_tport) Constructs an MCU peripheral object
  • public inline intget_info(info_t & info) const Gets the peripheral info.
  • public inline intget_version() const Gets the version of the peripheral driver.
  • public inline intinitialize() Initializes the hardware using the default attributes.
  • public inline intinitialize(const AttributesClass & attributes) Initializes the peripheral using the provided attributes
  • public inlinePeriph&operator<<(const AttributesClass & attributes) const Applies the given attributes to the peripheral.
  • public inlinePeriph&operator<<(constmcu_action_t& action)
  • public inlineport_tport() const
  • public inline intset_action(constmcu_action_t& action) const
  • public inline intset_action(u32 channel,u32 o_events,s8 prio,mcu_callback_t callback,void * context) const Sets the action callback for the event.
  • public inline intset_attributes() const Sets the default attributes on the hardware.
  • public inline intset_attributes(const AttributesClass & attributes) const Sets the peripheral attributes based on the attributes passed.
  • public inline intset_attributes(const attr_t & attr) const
  • public inline intset_priority(s8 priority,u32 o_events,int channel) Adjusts the priority of the hardware interrupt for the MCU peripheral.
  • protected inline u32get_channel(u32 loc,int request) const
  • protected inline intset_channel(const mcu_channel_t & channel,int request) const
  • protected inline intset_channel(u32 loc,u32 value,int request) const

Details

public inlinePeriph(core_periph_tperiph,port_tport)

Constructs an MCU peripheral object Parameters * periph Core peripheral value

  • port Port number

public inline intget_info(info_t & info) const

Gets the peripheral info.

Parameters * info A reference to the info object that will be written.

Returns

Zero on success, less than one for an error


public inline intget_version() const

Gets the version of the peripheral driver.

Returns

The BCD version of the driver

The version is a 24-bit BCD value. For example, 0x010203 is version 1.2.3 where:

  • 1 is the major version

  • 2 is the minor version

  • 3 is the patch version

If the major version of the driver is not the same as the major version of the driver interface header in the SDK, there will be problems using the hardware.

Here is a code sample using a Pwm object (which inherits this object)

#include <sapi.hal.hpp>

Pwm pwm(1); //pwm inherits this object
pwm.open();
if( (pwm.get_version()) >> 16 != (PWM_VERSION >>16) ){
 printf("Major versions are not the same\n");
} else {
 printf("Major versions match\n");
}

public inline intinitialize()

Initializes the hardware using the default attributes.

Returns

Less than zero on an error.

The system should set the error number to ENOSYS if no default attributes are provided.


public inline intinitialize(const AttributesClass & attributes)

Initializes the peripheral using the provided attributes


public inlinePeriph&operator<<(const AttributesClass & attributes) const

Applies the given attributes to the peripheral.

Use error_number() to see if the operation was successful.


public inlinePeriph&operator<<(constmcu_action_t& action)


public inlineport_tport() const


public inline intset_action(constmcu_action_t& action) const


public inline intset_action(u32 channel,u32 o_events,s8 prio,mcu_callback_t callback,void * context) const

Sets the action callback for the event.

Parameters * channel

  • o_events

  • prio

  • callback

  • context

Returns


public inline intset_attributes() const

Sets the default attributes on the hardware.

Returns

Zero on success

For this method to work correctly, the board support package must include the configuration information for the device. If the information is not provided, this method will return an error.

The system should set the error number to ENOSYS if no default attributes are provided.


public inline intset_attributes(const AttributesClass & attributes) const

Sets the peripheral attributes based on the attributes passed.

Parameters * attributes A const reference to the attributes used to apply to the peripheral.

Returns

Zero on success or less than zero for an error

UartAttributes uart_attributes; //default attributes
uart_attributes.set_frequency(9600);

Uart uart(0);
uart.open();
uart.set_attributes(uart_attributes);

public inline intset_attributes(const attr_t & attr) const


public inline intset_priority(s8 priority,u32 o_events,int channel)

Adjusts the priority of the hardware interrupt for the MCU peripheral.

Returns

Zero on success


protected inline u32get_channel(u32 loc,int request) const


protected inline intset_channel(const mcu_channel_t & channel,int request) const


protected inline intset_channel(u32 loc,u32 value,int request) const


class hal::PeriphAttributes

Methods

  • public inlinePeriphAttributes()
  • public inline const attr_t &attributes() const
  • public inline attr_t &attributes()
  • public inline u32freq() const
  • public inline u32frequency() const Access the frequency in hertz (bits/second).
  • public inline u32o_flags() const Accesses the value of the flags.
  • public inline attr_t *operator ->()
  • public inline const attr_t *operator ->() const
  • public inline u8port() const Accesses the value of the port.
  • public inline voidset_flags(u32 o_flags) Sets the value of the flags.
  • public inline voidset_freq(u32 freq_hz)
  • public inline voidset_frequency(u32 freq_hz) Set the frequency.
  • public inline voidset_port(u8 port) Sets the value of the port.
  • protected attr_tm_attr

Details

public inlinePeriphAttributes()


public inline const attr_t &attributes() const


public inline attr_t &attributes()


public inline u32freq() const


public inline u32frequency() const

Access the frequency in hertz (bits/second).


public inline u32o_flags() const

Accesses the value of the flags.


public inline attr_t *operator ->()


public inline const attr_t *operator ->() const


public inline u8port() const

Accesses the value of the port.


public inline voidset_flags(u32 o_flags)

Sets the value of the flags.


public inline voidset_freq(u32 freq_hz)


public inline voidset_frequency(u32 freq_hz)

Set the frequency.

Parameters * freq_hz The frequency in Hertz (bits/second)


public inline voidset_port(u8 port)

Sets the value of the port.


protected attr_tm_attr


class hal::PeriphObject

This class handles general peripheral IO. It re-implments open(), close(), read(), write(), ioctl() in order to manage the file descriptors for MCU peripherals.

Methods

  • public virtual intclose() Closes the file or device.
  • public intfileno() const
  • public virtual intioctl(int req,void * arg) const Executes an IO control request.
  • public intopen(int o_mode) This method opens the peripheral. For each instance, the peripheral only needs to be opened one time. The port is typically opened with open() and configured with set_attr(). After that, other instances of the peripheral can read and write without opening again.
  • public virtual intread(void * buf,int nbyte) const Reads the file.
  • public virtual intread(sys::Aio& aio) const Reads the device asynchronously.
  • public virtual intseek(int loc,int whence) const Seeks to a location in the file or on the device.
  • public virtual intwrite(const void * buf,int nbyte) const Write the file.
  • public virtual intwrite(sys::Aio& aio) const Writes the device asynchronously.
  • protected u16m_periph_port
  • protected intlookup_fileno() const
  • protected virtual intopen(constvar::ConstString& name,int flags) Opens a file.
  • protected voidupdate_fileno() const
  • typedefport_t Defines the type to use when specifying a peripheral port.

Details

public virtual intclose()

Closes the file or device.


public intfileno() const


public virtual intioctl(int req,void * arg) const

Executes an IO control request.

Parameters * req The request value

  • arg A pointer to the arguments

This method is typically only implemented for devices and other special file systems.


public intopen(int o_mode)

This method opens the peripheral. For each instance, the peripheral only needs to be opened one time. The port is typically opened with open() and configured with set_attr(). After that, other instances of the peripheral can read and write without opening again.


public virtual intread(void * buf,int nbyte) const

Reads the file.

Parameters * buf A pointer to the destination buffer

  • nbyte The number of bytes to read

Returns

The number of bytes read or less than zero on an error


public virtual intread(sys::Aio& aio) const

Reads the device asynchronously.

Parameters * aio A reference to the sys::Aio object to use for reading

See also: sys::Aio


public virtual intseek(int loc,int whence) const

Seeks to a location in the file or on the device.


public virtual intwrite(const void * buf,int nbyte) const

Write the file.

Parameters * buf A pointer to the source buffer

  • nbyte The number of bytes to read

Returns

The number of bytes written or less than zero on an error


public virtual intwrite(sys::Aio& aio) const

Writes the device asynchronously.

Parameters * aio A reference to the sys::Aio object to use for writing

See also: sys::Aio


protected u16m_periph_port


protected intlookup_fileno() const


protected virtual intopen(constvar::ConstString& name,int flags)

Opens a file.

Parameters * name The path to the file

  • flags The flags used to open the flag (e.g. File::READONLY)

Returns

Zero on success


protected voidupdate_fileno() const


typedefport_t

Defines the type to use when specifying a peripheral port.


class hal::Pin

This class controls the operation of a single pin. It works similarly to the Pio class, but the mask is built-in.

Here is an example of using the Pin class:

#include <sapi/hal.hpp>

Pin pin(1,0); //control pin P1.0
//Or if working with the pinmask Pin  pin(1, 1<<0, true);

pin.init(Pin::OUTPUT); //initialize as an output

//These three all set the pin high
pin = true;
pin.set();

//These turn the pin off
pin = false;
pin.clear();

//now convert to an input
pin.set_attr(Pin::INPUT | Pin::PULLUP); //or use Pin::FLOAT, Pin::PULLDOWN, etc
//or to init as an input use pin.init(Pin::INPUT);

 //now check to see if the value is high or low
if( pin.get_value() == true ){
 //pin is high
} else {
   //pin is low
}

pin.close(); //close the associated file descriptor (pin keeps its IO properties and state)

Methods

  • public inlinePin(port_tport,u32 pin,bool ismask) Constructs the object with a port/pin combination.
  • public inlinePin(constmcu_pin_t& p) Contructs a new pin object from an mcu_pin_t data structure.
  • public inline intclear() const Clear the pin low (assign value 0)
  • public inline boolget_value() const Gets the value of the pin (true is high, false is low).
  • public inline intinitialize(u32 o_flags) Initializes the pin with the specified mode.
  • public inline boolis_floating(u32 o_restore_flags) const
  • public inlineoperator bool() const Returns true if the pin is high and false if it is low.
  • public inline virtual constPin&operator<<(constchrono::MicroTime& a) const
  • public inline constPin&operator<<(bool value) const Assigns a boolean to the pin (true is high, false is low).
  • public inline constPin&operator=(bool value) const Assigns a boolean to the pin (true is high, false is low).
  • public inline u32pinmask() const Accesses the pin's associated Pio pinmask.
  • public inline intset() const Sets the pin high (assign value 1)
  • public inline intset_attributes(u32 o_flags) const Sets the pin attributes.
  • public inline intset_input(u32 o_flags) Initializes the pin as an input.
  • public inline intset_output(u32 o_flags) Initializes the pin as an input.
  • public inline voidset_value(bool value) const Assigns a boolean to the pin.

Details

public inlinePin(port_tport,u32 pin,bool ismask)

Constructs the object with a port/pin combination.


public inlinePin(constmcu_pin_t& p)

Contructs a new pin object from an mcu_pin_t data structure.


public inline intclear() const

Clear the pin low (assign value 0)


public inline boolget_value() const

Gets the value of the pin (true is high, false is low).


public inline intinitialize(u32 o_flags)

Initializes the pin with the specified mode.

Parameters * o_flags The mode to start the pin (e.g., Pin::INPUT | Pin::PULLUP)

Hardware intialization opens the device for reading/writing and then sets the device attributes as specified.

The following is an example of initializing a pin.

#include <sapi/hal.hpp>

Pin p(0,1); //Port 0, pin 1

p.init(Pin::INPUT | Pin::PULLUP);

if( p.get_value() == 0 ){
//this means something is driving the pin low
}

See also: open(), set_attr()


public inline boolis_floating(u32 o_restore_flags) const


public inlineoperator bool() const

Returns true if the pin is high and false if it is low.

This allows the following code to work:

Pin button;

if( button ){
  printf("Button is logic high\n");
} else {
  printf("Button is logic low\n");
}

public inline virtual constPin&operator<<(constchrono::MicroTime& a) const


public inline constPin&operator<<(bool value) const

Assigns a boolean to the pin (true is high, false is low).


public inline constPin&operator=(bool value) const

Assigns a boolean to the pin (true is high, false is low).


public inline u32pinmask() const

Accesses the pin's associated Pio pinmask.


public inline intset() const

Sets the pin high (assign value 1)


public inline intset_attributes(u32 o_flags) const

Sets the pin attributes.

Parameters * o_flags The pin mode (e.g., Pin::INPUT)

Returns

Zero on success


public inline intset_input(u32 o_flags)

Initializes the pin as an input.

Parameters * o_flags Optionally set FLAG_IS_PULLUP, etc

Returns

Zero on success


public inline intset_output(u32 o_flags)

Initializes the pin as an input.

Parameters * o_flags Optionally set FLAG_IS_OPENDRAIN, etc

Returns

Zero on success


public inline voidset_value(bool value) const

Assigns a boolean to the pin.

Parameters * value If true, sets the pin high


class hal::PinAssignment

The Pin Assignment class is a template class for manipulating pin assignment data structures.

The following is an example of how to configure the SPI using the hal::SpiPinAssignment class (which inherits this class).

#include <sapi/hal.hpp>

SpiPinAssignment pin_assignment;
pin_assignment->mosi = mcu_pin(2,0);
pin_assignment->sck = mcu_pin(2,0);
pin_assignment->miso = mcu_pin(2,0);

Spi spi(0);

spi.init(
 Spi::FLAG_SET_MASTER|Spi::FLAG_IS_MODE0|Spi::FLAG_IS_FORMAT_SPI,
 10000000, 8, pin_assignment
);

Methods

  • public inlinePinAssignment() Contructs a new pin assignment object.
  • public inline voidassign(const pin_assignment_type & pin_assignment) Assigns the value of the pin assignment as specified.
  • public inline voidclear() Clears the pin assignment data structure (assigns 0xff to all ports/pins.
  • public inline voidcopy(pin_assignment_type & pin_assignment) Copies the pin assignment information to the object specified.
  • public inline u32count() const Returns the number of pins in the pin assignment data structure.
  • public inline pin_assignment_type *operator ->() Provides read and write access to the members of the pin assignment structure.
  • public inlineoperator const pin_assignment_type *() const Returns a const pointer to the pin assignment data structure.
  • public inline u32size() const Returns the number of bytes in the data structure.

Details

public inlinePinAssignment()

Contructs a new pin assignment object.

All pin assignments are "cleared" when created meaning all ports and pins are set to 0xff so that any access to the pin assignment info will be ignored.


public inline voidassign(const pin_assignment_type & pin_assignment)

Assigns the value of the pin assignment as specified.

Parameters * pin_assignment A reference to the pin assignment which will be assigned to this object


public inline voidclear()

Clears the pin assignment data structure (assigns 0xff to all ports/pins.


public inline voidcopy(pin_assignment_type & pin_assignment)

Copies the pin assignment information to the object specified.

Parameters * pin_assignment A reference to the destination pin assignment data


public inline u32count() const

Returns the number of pins in the pin assignment data structure.


public inline pin_assignment_type *operator ->()

Provides read and write access to the members of the pin assignment structure.


public inlineoperator const pin_assignment_type *() const

Returns a const pointer to the pin assignment data structure.

This operator makes it easy to pass pin assignment data to set_attr() methods.


public inline u32size() const

Returns the number of bytes in the data structure.


class hal::PinAssignmentPeriphAttributes

Methods

Details

public inlinePinAssignmentPeriphAttributes()


public inline const pin_assignment_t *pin_assignment() const

Gets a pointer of the pin assignment.


class hal::Pio

This class controls pin input/output.

See also: Hal::Pin

Example:

#include <sapi/hal.hpp>

int main(int argc, char * argv[]){

//This allocates a PIO object but does not affect HW state
   Pio pio(2); //use pio port 2

   //This opens the port and sets the attributes -- same as pio.open(); pio.set_attr(1<<10, PIO_MODE_OUTPUT);
   pio.init(Pio::FLAG_SET_OUTPUT, 1<<10);

   //Bits can be manipulated using clrmask() and setmask()
   pio.clear_mask(1<<10); //clear bit 10 of port 2
   pio.set_mask(1<<10); //set bit 10

//the pin can be reconfigured as an input
   pio.set_attr(Pio::FLAG_SET_INPUT | Pio::FLAG_IS_PULLDOWN, (1<<10)); //set as an input with internal pulldown

   //get() is used to read the port
   if( pio.get_value() & (1<<10) ){
   //bit 10 is set
   }

   //This closes the port for all instances (ports are closed automatically when program exits)
   pio.close();

}

Methods

  • publicPio(port_tport)
  • public intassign(u32 mask) const Assigns the mask value to the port
  • public intclear_mask(u32 mask) const Clears the specified mask.
  • public u32get_value() const Gets the value of the port.
  • public inline constPio&operator<<(u32 value) const
  • public intset_mask(u32 mask) const Sets the specified pin mask
  • public intset_value(unsigned int value) const Sets the value of the port
  • enum@16

Details

publicPio(port_tport)


public intassign(u32 mask) const

Assigns the mask value to the port

Parameters * mask Bits that are set will be output as 1 and bits that are clear will be output as zero

Returns

Zero on success


public intclear_mask(u32 mask) const

Clears the specified mask.


public u32get_value() const

Gets the value of the port.


public inline constPio&operator<<(u32 value) const


public intset_mask(u32 mask) const

Sets the specified pin mask


public intset_value(unsigned int value) const

Sets the value of the port

Parameters * value The value to assign to the port


enum@16


class hal::PioAttributes

Methods

Details

public inlinePioAttributes(u32 o_flags,u32 o_pinmask)


public inline u32o_flags() const


public inline u32o_pinmask() const


public inline voidset_flags(u32 value)


public inline voidset_pinmask(u32 value)


class hal::Pwm

This class implements PWM outputs.

Here is an example of how to use the Pwm class

#include <sapi/hal.hpp>

Pwm pwm(1); //use PWM port 1
PwmPinAssignment pin_assignment;
pin_assignment->channel[0] = mcu_pin(1,20); //Use Pin 1.20
pwm.init(Pwm::SET_TIMER | Pwm::IS_ENABLED, 24000000, 1000, pin_assignment);
pwm.set_channel(2, 500);

Methods

  • publicPwm(port_tport)
  • public inline intdisable() const Disables the PWM timer.
  • public inline intenable() const Enables the PWM timer.
  • public inline intget_channel(u32 loc) Gets the channel value.
  • public inline u32get_channel()
  • public inline intinit(u32 o_flags,u32 freq,u32 period,const pwm_pin_assignment_t * pin_assignment)
  • public inline intset_attr(u32 o_flags,u32 freq,u32 period,const pwm_pin_assignment_t * pin_assignment) const
  • public inline intset_channel(u32 loc,u32 value) const Sets the channel to the specified value.
  • public inline intset_channel(const mcu_channel_t & channel) const Sets the channel using the channel reference.
  • public inline intset_channels(const pwm_pin_assignment_t * pin_assignment) Sets the channel configuration.
  • enum@17

Details

publicPwm(port_tport)


public inline intdisable() const

Disables the PWM timer.

See also: enable()


public inline intenable() const

Enables the PWM timer.

Returns

Zero on success

This method can be used with disable() to start and stop the PWM timer while preserving the attributes.


public inline intget_channel(u32 loc)

Gets the channel value.

Parameters * loc Channel location

Returns

The value of the channel or (u32)-1 for an error


public inline u32get_channel()


public inline intinit(u32 o_flags,u32 freq,u32 period,const pwm_pin_assignment_t * pin_assignment)


public inline intset_attr(u32 o_flags,u32 freq,u32 period,const pwm_pin_assignment_t * pin_assignment) const


public inline intset_channel(u32 loc,u32 value) const

Sets the channel to the specified value.

Parameters * loc The channel location (number)

  • value The value to assign to the channel

Returns

Zero on success


public inline intset_channel(const mcu_channel_t & channel) const

Sets the channel using the channel reference.

Parameters * channel The channel location and value

Returns

Zero on success


public inline intset_channels(const pwm_pin_assignment_t * pin_assignment)

Sets the channel configuration.

Parameters * pin_assignment A pointer to the pin assignment

Returns

Zero on success

This method is equivalent to set_attr() with o_flags set to PWM::FLAG_SET_CHANNELS.


enum@17


class hal::PwmAttributes

This class is for containing PWM attributes.

Methods

  • public inlinePwmAttributes(u32 o_flags,u32 frequency,u32 period) Constructs an object with detault values.
  • public inline mcu_channel_tchannel() const details Access the current channel that the attributes refers to.
  • public inline u32period() const Accesses the PWM period.
  • public inline voidset_channel(u32 loc,u32 value) Sets the PWM channel associated with the attributes.
  • public inline voidset_channel(const mcu_channel_t & channel) Sets the PWM attributes channel.
  • public inline voidset_period(u32 period) Sets the PWM period.

Details

public inlinePwmAttributes(u32 o_flags,u32 frequency,u32 period)

Constructs an object with detault values.

Parameters * o_flags Flags to apply

  • frequency Frequency of timer

  • period Period of PWM timer


public inline mcu_channel_tchannel() const

details Access the current channel that the attributes refers to.


public inline u32period() const

Accesses the PWM period.


public inline voidset_channel(u32 loc,u32 value)

Sets the PWM channel associated with the attributes.


public inline voidset_channel(const mcu_channel_t & channel)

Sets the PWM attributes channel.


public inline voidset_period(u32 period)

Sets the PWM period.


class hal::PwmPinAssignment

This class allows simple manipulation of the pwm_pin_assignment_t.

class hal::Rtc

This class implements an RTC. (Not yet implemented)

Methods

Details

publicRtc(port_tport)


public intget_time(rtc_time_t& time) const

Gets RTC time.


public intset_time(constrtc_time_t& time) const

Set RTC time.


enum@18

  • FLAG_ENABLE
  • FLAG_DISABLE
  • FLAG_IS_SOURCE_EXTERNAL_32768
  • FLAG_IS_SOURCE_INTERNAL_40000
  • FLAG_ENABLE_ALARM
  • FLAG_DISABLE_ALARM
  • FLAG_IS_ALARM_ONCE
  • FLAG_IS_ALARM_MINUTE
  • FLAG_IS_ALARM_HOURLY
  • FLAG_IS_ALARM_DAILY
  • FLAG_IS_ALARM_WEEKLY
  • FLAG_IS_ALARM_MONTHLY
  • FLAG_IS_ALARM_YEARLY
  • FLAG_ENABLE_COUNT_EVENT
  • FLAG_IS_COUNT_SECOND
  • FLAG_IS_COUNT_MINUTE
  • FLAG_IS_COUNT_HOUR
  • FLAG_IS_COUNT_DAY_OF_WEEK
  • FLAG_IS_COUNT_DAY_OF_MONTH
  • FLAG_IS_COUNT_DAY_OF_YEAR
  • FLAG_IS_COUNT_WEEK
  • FLAG_IS_COUNT_MONTH
  • FLAG_IS_COUNT_YEAR
  • FLAG_DISABLE_COUNT_EVENT
  • ENABLE Set the alarm
  • DISABLE Set the alarm
  • IS_SOURCE_EXTERNAL_32768 External 32.768KHz Crystal
  • IS_SOURCE_INTERNAL_40000 Internal 40KHz Oscillator
  • ENABLE_ALARM Enable the alarm
  • DISABLE_ALARM Enable the alarm
  • IS_ALARM_ONCE One time alarm
  • IS_ALARM_MINUTE Alarm every minute
  • IS_ALARM_HOURLY Alarm every hour
  • IS_ALARM_DAILY Daily alarm
  • IS_ALARM_WEEKLY Weekly alarm
  • IS_ALARM_MONTHLY Monthly alarm
  • IS_ALARM_YEARLY Yearly alarm
  • ENABLE_COUNT_EVENT Enable a count event
  • IS_COUNT_SECOND One time alarm
  • IS_COUNT_MINUTE One time alarm
  • IS_COUNT_HOUR One time alarm
  • IS_COUNT_DAY_OF_WEEK One time alarm
  • IS_COUNT_DAY_OF_MONTH One time alarm
  • IS_COUNT_DAY_OF_YEAR One time alarm
  • IS_COUNT_WEEK One time alarm
  • IS_COUNT_MONTH One time alarm
  • IS_COUNT_YEAR One time alarm
  • DISABLE_COUNT_EVENT Enable a count event

class hal::RtcAttributes

class hal::Spi

This class gives access to a SPI port.

#include <sapi/hal.hpp>

int main(int argc, char * argv[]){
  char buffer[16];
  Spi spi(0);           //access to SPI port 0
  spi.init();           //init SPI with default settings from BSP
  spi.read(buffer, 16); //read 16 bytes from the SPI
  spi.close();          //close the SPI (power it off)
  return 0;
}

Methods

  • publicSpi(port_tport) Constructs a SPI object using port.
  • public inline intinit(u32 o_flags,u32 freq,u32 width,constspi_pin_assignment_t* pin_assignment)
  • public inline intinitialize(u32 o_flags,u32 freq,u32 width,constspi_pin_assignment_t* pin_assignment)
  • public inline intinitialize() Initializes the peripheral using the provided attributes
  • public inline intinitialize() Initializes the hardware using the default attributes.
  • public inline intset_attr(u32 o_flags,u32 freq,u32 width,constspi_pin_assignment_t* pin_assignment) const
  • public intswap(int byte) const swap a byte on the SPI bus
  • public inttransfer(const void * write_data,void * read_data,int nbytes)
  • enum@19

Details

publicSpi(port_tport)

Constructs a SPI object using port.


public inline intinit(u32 o_flags,u32 freq,u32 width,constspi_pin_assignment_t* pin_assignment)


public inline intinitialize(u32 o_flags,u32 freq,u32 width,constspi_pin_assignment_t* pin_assignment)


public inline intinitialize()

Initializes the peripheral using the provided attributes


public inline intinitialize()

Initializes the hardware using the default attributes.

Returns

Less than zero on an error.

The system should set the error number to ENOSYS if no default attributes are provided.


public inline intset_attr(u32 o_flags,u32 freq,u32 width,constspi_pin_assignment_t* pin_assignment) const


public intswap(int byte) const

swap a byte on the SPI bus


public inttransfer(const void * write_data,void * read_data,int nbytes)


enum@19


class hal::SpiAttributes

Methods

Details

public inlineSpiAttributes(u32 o_flags,u32 freq,u8 width)


public inlinemcu_pin_tcs() const


public inlinemcu_pin_tmiso() const


public inlinemcu_pin_tmosi() const


public inlinemcu_pin_tsck() const


public inline voidset_cs(constmcu_pin_t& pin)


public inline voidset_miso(constmcu_pin_t& pin)


public inline voidset_mosi(constmcu_pin_t& pin)


public inline voidset_sck(constmcu_pin_t& pin)


public inline voidset_width(u8 value)


public inline u8width() const


class hal::SpiPinAssignment

This class allows simple manipulation of the spi_pin_assignment_t.

class hal::StreamFFifo

Methods

Details

publicStreamFFifo()


public intflush()


public intget_info(stream_ffifo_info_t & info)


public inline StreamFFifo &operator<<(const StreamFFifoAttributes & attributes)


public inline intset_attributes(const StreamFFifoAttributes & attributes)


public intstart()


public intstop()


enum@20

  • START
  • STOP
  • FLUSH

class hal::StreamFFifoAttributes

Methods

Details

public inlineStreamFFifoAttributes()


public inlineoperator const stream_ffifo_attr_t &() const


public inline voidset_flags(u32 value)


class hal::StreamFFifoChannelInfo

Methods

Details

public inlineStreamFFifoChannelInfo(const stream_ffifo_channel_info_t & info)


public inlineFFifoInfoffifo() const


public inlineFFifoInfoffifo_info() const


public inline boolis_valid() const


class hal::StreamFFifoInfo

Methods

Details

public inlineStreamFFifoInfo()


public inline boolis_valid() const


public inlineoperator const stream_ffifo_info_t &() const


public inlineoperator stream_ffifo_info_t &()


public inline const StreamFFifoChannelInfo &receive() const


public inline const StreamFFifoChannelInfo &transmit() const


class hal::Switchboard

The Switchboard class is used to interface with /dev/switchboard0 and similar devices.

The switchboard can connect two devices together such that when data is received on one device, it will be written to another device.

A good application for using the switchboard is connecting streaming audio devices together.

#include <sapi/hal.hpp>
Switchboard switchboard;
SwitchboardTerminal input("mic"); //will refer to /dev/mic
SwitchboardTerminal output("speaker"); //refers to /dev/speaker
SwitchboardConnection connection = switchboard.create_persistent_connnection(input, output);

Methods

Details

publicSwitchboard()

Constructs a new object.


public intcreate_fixed_size_connection(constSwitchboardTerminal& input,constSwitchboardTerminal& output,s32 nbyte) const

create_fixed_size_connection Parameters * input The input terminal

  • output The output terminal

  • nbyte The number of bytes to transfer

Returns

Zero on success or less than zero for an error


public intcreate_persistent_connection(constSwitchboardTerminal& input,constSwitchboardTerminal& output,s32 nbyte,u32 o_flags) const

Creates a new persistent connection on the switchboard.

Parameters * input The input terminal

  • output The output terminal

  • nbyte The number of bytes to transfer per transaction (default is maximum)

  • o_flags Additional flags to apply while creating the connection

Returns

The id number of the new connection or less than zero for an error

The connection will persist until it is disconnected using destroy_connection() or it encounters a read or write error.


public intdestroy_connection(u16 id) const

Destroys the specified connection.

Parameters * id The connection to disconnect

Returns

Zero on success

After a connection is destroyed, it can be used again. The connection may take some time to stop.


public intdestroy_connection(SwitchboardConnection& connection)

Disconnects the specified connection.

Parameters * connection A reference to the connection


public intget_active_connection_count() const

Returns the number of active connections.


public intget_available_connection() const

Gets a free connection that can be used for a new connection.

Returns

Less than zero if no connection is available


publicSwitchboardConnectionget_connection(u16 id) const

Gets the connection specified by id.


public intget_connection(SwitchboardConnection& connection) const

Reloads the latest status on the connection.

Parameters * connection A reference to the connection to reload

Returns

Zero on success

The connection parameter must have a valid id() value.

Switchboard sb;
sb.open();
SwitchboardConnection connection = sb.get_connection(0); //assumes 0 is a valid connection
printf("connection input bytes transferred %d\n", connection.input().bytes_transferred());
sleep(1);
sb.get_connection(connection); //grab the latest status
printf("connection input bytes transferred %d\n", connection.input().bytes_transferred());

public intget_info(switchboard_info_t & info) const

Gets information from the switchboard.


publicSwitchboardInfoget_info() const

Gets information from the switchboard.


public virtual intopen(constvar::ConstString& name,int o_flags)

Opens a switch board Parameters * name The path to the switchboard (default is /dev/swithboard0)

Returns

Zero on success

To open a different switchboard, use

Switchboard sb1;
sb1.open("/dev/switchboard1");

public voidprint_connections() const


public intset_attr(switchboard_attr_t& attr) const

Sets the attributes of the switchboard.

Use connect() and disconnect() to manage basic connections. This method can do more advanced features.


enum@21

  • CONNECT Connect Flag
  • DISCONNECT Disconnect Flag
  • IS_PERSISTENT Is Persistent Flag
  • IS_FIXED_SIZE Is Fixed Size Flag
  • IS_CONNECTED Connection is connected and running (otherwise IS_ERROR, IS_CANCELED, or IS_DESTROYED)
  • IS_ERROR Stopped because of an error
  • IS_CANCELED Stopped because an operation was canceled
  • IS_DESTROYED Stopped because the connection was destroyed
  • IS_FILL_ZERO Fill output with zeros if no input data is available
  • IS_INPUT_NON_BLOCKING Execute input transactions as non-blocking
  • IS_OUTPUT_NON_BLOCKING Execute input transactions as non-blocking
  • IS_FILL_LAST_8 Fill output with last byte of most recent packet
  • IS_FILL_LAST_16 Fill output with last 16-bit word of most recent packet
  • IS_FILL_LAST_32 Fill output with last 32-bit word of most recent packet
  • IS_FILL_LAST_64 Fill output with last 64-bit word of most recent packet

class hal::SwitchboardConnection

Methods

  • public inlineSwitchboardConnection() Constructs a new empty connection.
  • public inlineSwitchboardConnection(constSwitchboardTerminal& input,constSwitchboardTerminal& output,s32 nbyte) Constructs a connection with the specified terminals.
  • public inline interror_number() const Returns the error number associated with the is_stopped_on_error() condition.
  • public inline u16id() const Returns the connection ID value.
  • public inlineSwitchboardTerminalinput() const Returns a copy of the input terminal.
  • public inline boolis_canceled() const Returns true if the connection stopped because an operation was canceled.
  • public inline boolis_connected() const Returns true if the connection is currently running.
  • public inline boolis_destroyed() const Returns true if the connection has been destroyed.
  • public inline boolis_error() const Returns true if the connection has stopped on an error.
  • public inline boolis_valid() const Returns true if the object holds valid information.
  • public inline s32nbyte() const Returns the number of bytes transferred on the last transaction.
  • public inline u32o_flags() const Returns the status flags of the connection.
  • public inlineSwitchboardTerminaloutput() const Returns a copy of the output terminal.
  • public voidprint() const Prints details about the connection on the standard output.
  • public inline voidset_input(constSwitchboardTerminal& value) Sets the connection's input terminal.
  • public inline voidset_output(constSwitchboardTerminal& value) Sets the connections's output terminal.

Details

public inlineSwitchboardConnection()

Constructs a new empty connection.


public inlineSwitchboardConnection(constSwitchboardTerminal& input,constSwitchboardTerminal& output,s32 nbyte)

Constructs a connection with the specified terminals.


public inline interror_number() const

Returns the error number associated with the is_stopped_on_error() condition.


public inline u16id() const

Returns the connection ID value.

If this value is equal to invalid_id(), the connection is not valid.


public inlineSwitchboardTerminalinput() const

Returns a copy of the input terminal.


public inline boolis_canceled() const

Returns true if the connection stopped because an operation was canceled.


public inline boolis_connected() const

Returns true if the connection is currently running.


public inline boolis_destroyed() const

Returns true if the connection has been destroyed.


public inline boolis_error() const

Returns true if the connection has stopped on an error.


public inline boolis_valid() const

Returns true if the object holds valid information.


public inline s32nbyte() const

Returns the number of bytes transferred on the last transaction.

If this value is negative, then an error has occurred.


public inline u32o_flags() const

Returns the status flags of the connection.


public inlineSwitchboardTerminaloutput() const

Returns a copy of the output terminal.


public voidprint() const

Prints details about the connection on the standard output.


public inline voidset_input(constSwitchboardTerminal& value)

Sets the connection's input terminal.


public inline voidset_output(constSwitchboardTerminal& value)

Sets the connections's output terminal.


class hal::SwitchboardInfo

Methods

Details

public inlineSwitchboardInfo()


public inline u16connection_buffer_size() const

Returns the switchboard's internal connection buffer size.


public inline u16connection_count() const

Returns the number of connections available.


public inlineoperator const switchboard_info_t &() const


public inline u16transaction_limit() const

Returns the transaction limit of the switchboard.


class hal::SwitchboardTerminal

A Switchboard terminal defines the data structure for either an input or an output.

Inputs and outputs are defined identically. When a terminal is passed to the Switchboard as an input it will be read. And when passed as an output, it will be written.

Methods

Details

public inlineSwitchboardTerminal(constvar::ConstString& name,int loc,s8 priority)

Constructs a new Switchboard terminal.

Parameters * name The name of the terminal (e.g. uart0 not /dev/uart0)

  • loc The channel/location to read or write

  • priority Zero for default priority


public inlineSwitchboardTerminal(constswitchboard_terminal_t& terminal)

Constructs a terminal from a switchboard_terminal_t.


public inline u32bytes_transferred() const

Returns the number of bytes transferred on the terminal.


public inline u32loc() const

Returns the location/channel value for the terminal.


public inlinevar::ConstStringname() const

Returns the terminal's name.


public inline s8priority() const

Returns the terminal interrupt priority.


public inline voidset_loc(int loc)

Sets the location/channel of the terminal.


public inline voidset_name(constvar::ConstString& name)

Sets the name of the terminal. Parameters * name A pointer to the terminal name


public inline voidset_priority(s8 priority)

Sets the priority of the terminal.


class hal::Tmr

This class implements a hardware timer. The Timer class implements a logical timer that is based on the system clock and can be used for many timing functions.

The Tmr class can be used to configure a timer to count rising edges on an input capture pin or to generate waveforms on an output compare pin. It can also configure the timer to use the internal CPU clock at various frequencies.

For example this will start a microsecond timer (1Mhz) using an internal clock:

Tmr tmr(0); //use /dev/tmr0
tmr.init(); //initialize the timer
tmr.set(0); //set the value to zero
tmr.on(); //turn the timer on
Timer::wait_milliseconds(100);
printf("My timer value is %d\n", tmr.value()); //The value will be about 100,000

Here is an example using the Tmr to count external edges on input capture 0

You can also use the output compare channels to set the top value of the timer.

Methods

  • publicTmr(port_tport) Constructs a new timer object using port.
  • public intdisable() const Turns the TMR off (stop counting)
  • public intenable() const Turns the TMR on (start counting)
  • public inline u32get_channel(u32 loc) Gets the value of the specified channel.
  • public u32get_value() const Gets the value of the timer.
  • public inline intinit(u32 o_flags,u32 freq,u32 period,const tmr_pin_assignment_t * pin_assignment)
  • public inline intset_attr(u32 o_flags,u32 freq,u32 period,const tmr_pin_assignment_t * pin_assignment)
  • public inline intset_channel(u32 loc,u32 value) Sets the value of the specified channel.
  • public intset_value(u32 value) const Sets the value of the timer.
  • enum@22

Details

publicTmr(port_tport)

Constructs a new timer object using port.


public intdisable() const

Turns the TMR off (stop counting)


public intenable() const

Turns the TMR on (start counting)


public inline u32get_channel(u32 loc)

Gets the value of the specified channel.

Parameters * loc The channel number

Returns

The value of the channel or (u32)-1 if the IOCTL request fails

The loc parameter is the input or output channel. Input channels should be or'd with the MCU_CHANNEL_FLAG_IS_INPUT value.


public u32get_value() const

Gets the value of the timer.


public inline intinit(u32 o_flags,u32 freq,u32 period,const tmr_pin_assignment_t * pin_assignment)


public inline intset_attr(u32 o_flags,u32 freq,u32 period,const tmr_pin_assignment_t * pin_assignment)


public inline intset_channel(u32 loc,u32 value)

Sets the value of the specified channel.

Parameters * loc The channel number

  • value The value to assign to the channel

Returns

Zero on success

The loc parameter is the input or output channel. Input channels should be or'd with the MCU_CHANNEL_FLAG_IS_INPUT value.


public intset_value(u32 value) const

Sets the value of the timer.


enum@22


class hal::TmrAttributes

Methods

Details

public inlineTmrAttributes(u32 o_flags,u32 freq,u32 period)


public inlinemcu_pin_tchannel(u8 channel) const


public inline u32period() const


public inline voidset_channel(const mcu_channel_t & channel)


public inline voidset_channel_pin(u8 channel,constmcu_pin_t& pin)


public inline voidset_period(u32 period)


class hal::TmrPinAssignment

This class allows simple manipulation of the tmr_pin_assignment_t.

class hal::Uart

This class implements a serial UART port.

Here is an example of how to use the UART using default parameters provide by the board support package.

#include <sapi/hal.hpp>

int main(int argc, char * argv[]){
   Uart uart(0); //use UART0
   char buffer[256];
   uart.init(); //initializes using default parameters
   uart.read(buffer, 256); //this will block until at least one byte arrives
   uart.close(); //free the file descriptors and power down the device
   return 0;
}

The above example opens using the UART in blocking mode. If you want to be able to read the UART without blocking until a byte arrives, you can use non-blocking mode.

#include <sapi/hal.hpp>

int main(int argc, char * argv[]){
   Uart uart(0);
   char buffer[256];
   UartPinAssignment pin_assignment;
   uart.open(Uart::NONBLOCK|Uart::RDWR);
   //now set the attributes
   pin_assignment->tx = mcu_pin(0,0);
   pin_assignment->rx = mcu_pin(0,1);
   uart.set_attr(Uart::FLAG_IS_STOP1|Uart::FLAG_IS_PARITY_NONE,
   115200, //115200 baud rate
   8,
   pin_assignment); //this value can be null to use the BSP's default pin assignment values
   uart.read(buffer, 256); //returns immediately even if no data is available (errno is set to EAGAIN if no data)
   uart.close(); //free the resources
}

The UART can also be configured directly using the POSIX API.

#include <sos/dev/uart.h>
#include <unistd.h>
#include <fcntl.h>

int main(int argc, char * argv[]){
   int fd;
   uart_attr_t attr;
   char str[] = "Hello!\n";
   fd = open("/dev/uart0", O_RDWR);
   if( fd < 0 ){
      perror("Failed to open uart");
   } else {
      attr.o_flags = UART_FLAG_SET_LINE_CODING | UART_FLAG_IS_PARITY_NONE;
      attr.width = 8;
      attr.freq = 115200;
      attr.pin_assignment.tx = mcu_pin(0,0);
      attr.pin_assignment.rx = mcu_pin(0,1);
      attr.pin_assignment.cts = mcu_pin(0xff,0xff); //don't use CTS
      attr.pin_assignment.rts = mcu_pin(0xff,0xff); //don't use RTS
      if( ioctl(fd, I_UART_SETATTR, &attr) < 0 ){
         perror("Failed to set uart attr");
      } else {
         write(fd, str, strlen(str));
      }

      close(fd);
   }

   return 0;
}

See also: hal::UartPinAssignment

See also: hal::UartAttr

Methods

  • publicUart(port_tport) Constructs a new Uart object.
  • public intflush() Flushes the TX/RX buffers.
  • public intget(char & c) Reads a single byte (if available from the UART). Upon success, the byte is written to the value pointed to by c.
  • public inline intinit(u32 o_flags,u32 freq,u32 width,const uart_pin_assignment_t * pin_assignment)
  • public intput(char c) Writes a single byte on the UART.
  • public inline intset_attr(u32 o_flags,u32 freq,u32 width,const uart_pin_assignment_t * pin_assignment) const
  • enum@23

Details

publicUart(port_tport)

Constructs a new Uart object.

Parameters * port The port to use (Zero is always the first port)


public intflush()

Flushes the TX/RX buffers.


public intget(char & c)

Reads a single byte (if available from the UART). Upon success, the byte is written to the value pointed to by c.

Returns

Zero on successfully reading a byte, -1 if no bytes are available.


public inline intinit(u32 o_flags,u32 freq,u32 width,const uart_pin_assignment_t * pin_assignment)


public intput(char c)

Writes a single byte on the UART.

Parameters * c The character to write

Returns

Zero on success


public inline intset_attr(u32 o_flags,u32 freq,u32 width,const uart_pin_assignment_t * pin_assignment) const


enum@23


class hal::UartAttributes

The Uart Attributes Class can be used to configure the UART. The sys::Cli classes can populate a UartAttr object using arguments passed on the command line.

For example, the following sample code will initialize a UART port based on parameters passed on the command line.

int main(int argc, char * argv[]){
   UartAttr uart_attr;
   Cli cli(argc, argv);

   cli.handle_uart(uart_attr);

   Uart uart(uart_attr.port());
   uart.init(uart_attr);
}

See also: hal::Uart

Methods

  • public inlineUartAttributes(u32 o_flags,u32 freq,u32 width) Constructs UART attributes with default settings.
  • public inlinemcu_pin_tcts() const Accesses the cts pin assignment value.
  • public inlinemcu_pin_trts() const Accesses the rts pin assignment value.
  • public inlinemcu_pin_trx() const Accesses the rx pin assignment value.
  • public inline voidset_cts(constmcu_pin_t& pin) Sets the cts pin assignment value.
  • public inline voidset_rts(constmcu_pin_t& pin) Sets the rts pin assignment value.
  • public inline voidset_rx(constmcu_pin_t& pin) Sets the rx pin assignment value.
  • public inline voidset_tx(constmcu_pin_t& pin) Sets the tx pin assignment value.
  • public inline voidset_width(u8 bits) Sets the width in bits.
  • public inlinemcu_pin_ttx() const Accesses the tx pin assignment value.
  • public inline u8width() const Accesses the width in bits (usually 8).

Details

public inlineUartAttributes(u32 o_flags,u32 freq,u32 width)

Constructs UART attributes with default settings.

Parameters * o_flags Flags for attibutes (default is UART_FLAG_SET_LINE_CODING_DEFAULT)

  • freq UART frequency (bitrate; default is 115200)

  • width UART byte width (default is 8)


public inlinemcu_pin_tcts() const

Accesses the cts pin assignment value.


public inlinemcu_pin_trts() const

Accesses the rts pin assignment value.


public inlinemcu_pin_trx() const

Accesses the rx pin assignment value.


public inline voidset_cts(constmcu_pin_t& pin)

Sets the cts pin assignment value.

Parameters * pin The cts pin


public inline voidset_rts(constmcu_pin_t& pin)

Sets the rts pin assignment value.

Parameters * pin The rts pin


public inline voidset_rx(constmcu_pin_t& pin)

Sets the rx pin assignment value.

Parameters * pin The rx pin


public inline voidset_tx(constmcu_pin_t& pin)

Sets the tx pin assignment value.

Parameters * pin The tx pin


public inline voidset_width(u8 bits)

Sets the width in bits.

Parameters * bits The number of bits to use


public inlinemcu_pin_ttx() const

Accesses the tx pin assignment value.


public inline u8width() const

Accesses the width in bits (usually 8).


class hal::UartPinAssignment

This class allows simple manipulation of the uart_pin_assignment_t.

UartPinAssignment pin_assignment;
pin_assignment->tx = mcu_pin(0,1);
pin_assignment->rx = mcu_pin(0,1);

Uart uart(0);
uart.set_attr(Uart::FLAG_SET_LINE_CODING, 115200, 8, pin_assignment);

See also: hal::Uart

class hal::Usb

This class implements a USB transceiver.

Methods

Details

publicUsb(port_tport)


public intattach() const


public intconfigure() const


public intdetach() const


public intdisable_endpoint(int ep) const


public intenable_endpoint(int ep) const


public boolis_connected() const


public intreset() const


public intreset_endpoint(int ep) const


public intset_addr(int addr) const


public intstall_endpoint(int ep) const


public intunstall_endpoint(int ep) const


enum@24

  • FLAG_SET_UNCONFIGURED
  • FLAG_SET_DEVICE
  • FLAG_SET_HOST
  • FLAG_SET_OTG
  • FLAG_RESET
  • FLAG_ATTACH
  • FLAG_DETACH
  • FLAG_CONFIGURE
  • FLAG_UNCONFIGURE
  • FLAG_SET_ADDRESS
  • FLAG_RESET_ENDPOINT
  • FLAG_ENABLE_ENDPOINT
  • FLAG_DISABLE_ENDPOINT
  • FLAG_STALL_ENDPOINT
  • FLAG_UNSTALL_ENDPOINT
  • FLAG_CONFIGURE_ENDPOINT
  • SET_UNCONFIGURED
  • SET_DEVICE
  • SET_HOST
  • SET_OTG
  • RESET
  • ATTACH
  • DETACH
  • CONFIGURE
  • UNCONFIGURE
  • SET_ADDRESS
  • RESET_ENDPOINT
  • ENABLE_ENDPOINT
  • DISABLE_ENDPOINT
  • STALL_ENDPOINT
  • UNSTALL_ENDPOINT
  • CONFIGURE_ENDPOINT

class hal::UsbAttributes

class hal::UsbPinAssignment

This class allows simple manipulation of the usb_pin_assignment_t.

namespace inet

These classes are currently experimental.

Classes

class inet::Http

Methods

  • publicHttp(Socket & socket)
  • protected inline Socket &socket()

Details

publicHttp(Socket & socket)


protected inline Socket &socket()


class inet::HttpClient

Methods

Details

publicHttpClient(Socket & socket)


public intclose_connection()


public intconnect(constvar::ConstString& url)


public intget(constvar::ConstString& url,constsys::File& response,constsys::ProgressCallback* progress_callback)


public inthead(constvar::ConstString& url)


public inline constvar::String&header() const

Returns a reference to the header that is returned by the request.


public inlinevar::Vector< HttpHeaderPair > &header_request_pairs()


public inline constvar::Vector< HttpHeaderPair > &header_request_pairs() const


public inlinevar::Vector< HttpHeaderPair > &header_response_pairs()


public inline constvar::Vector< HttpHeaderPair > &header_response_pairs() const


public inline boolis_follow_redirects() const


public inline boolis_keep_alive() const


public intoptions(constvar::ConstString& url)


public intpatch(constvar::ConstString& url,constvar::ConstString& request,constsys::File& response,constsys::ProgressCallback* progress_callback)


public intpatch(constvar::ConstString& url,constsys::File& request,constsys::File& response,constsys::ProgressCallback* progress_callback)


public intpost(constvar::ConstString& url,constvar::ConstString& request,constsys::File& response,constsys::ProgressCallback* progress_callback)


public intpost(constvar::ConstString& url,constsys::File& request,constsys::File& response,constsys::ProgressCallback* progress_callback)


public intput(constvar::ConstString& url,constvar::ConstString& request,constsys::File& response,constsys::ProgressCallback* progress_callback)


public intput(constvar::ConstString& url,constsys::File& request,constsys::File& response,constsys::ProgressCallback* progress_callback)


public intremove(constvar::ConstString& url,constvar::String& data)


public inline voidset_chunked_transfer_encoding_enabled(bool value)


public inline voidset_follow_redirects(bool value)


public inline voidset_keep_alive(bool value)

Keeps the connection alive between requests.

Parameters * value If true, the connection is kept alive between requests


public inline voidset_transfer_size(u32 value)


public inline intstatus_code() const

Returns the status code of the last request.

The status code will be 200 for a successful request.


public inttrace(constvar::ConstString& url)


public inline u32transfer_size() const


enum@25

  • NONE
  • FAILED_TO_CREATE_SOCKET
  • FAILED_TO_CONNECT_TO_SOCKET
  • FAILED_TO_WRITE_HEADER
  • FAILED_TO_WRITE_DATA
  • FAILED_TO_WRITE_INCOMING_DATA_TO_FILE
  • FAILED_TO_FIND_ADDRESS
  • FAILED_WRONG_DOMAIN

class inet::HttpHeaderPair

Methods

Details

public inlineHttpHeaderPair()


public inlineHttpHeaderPair(constvar::ConstString& key,constvar::ConstString& value)


public inlinevar::Stringto_string() const


class inet::HttpServer

Methods

Details

publicHttpServer()


class inet::SecureSocket

Methods

  • publicSecureSocket()
  • publicSecureSocket(u32 ticket_lifetime)
  • public Socketaccept(SocketAddress & address) const
  • public virtual intbind_and_listen(const SocketAddress & address,int backlog) const
  • public virtual intclose()
  • public virtual intconnect(const SocketAddress & address)
  • public virtual intcreate(const SocketAddress & address)
  • public virtual intread(void * buf,int nbyte) const
  • public virtual intshutdown(int how) const
  • public inline constvar::Data&ticket() const
  • public inlinevar::Data&ticket()
  • public virtual intwrite(const void * buf,int nbyte) const

Details

publicSecureSocket()


publicSecureSocket(u32 ticket_lifetime)


public Socketaccept(SocketAddress & address) const


public virtual intbind_and_listen(const SocketAddress & address,int backlog) const


public virtual intclose()


public virtual intconnect(const SocketAddress & address)


public virtual intcreate(const SocketAddress & address)


public virtual intread(void * buf,int nbyte) const


public virtual intshutdown(int how) const


public inline constvar::Data&ticket() const


public inlinevar::Data&ticket()


public virtual intwrite(const void * buf,int nbyte) const


class inet::SocketAddressInfo

The Socket Address Info class is used to get socket address information for a given node and service.

For example, if you have a web URL this class can be used to converto that to information that can be used to open a socket.

The following is an example of how to use this class for connected to a server.

#include <sapi/inet.hpp>
#include <sapi/var.hpp>

SocketAddressInfo socket_address_info; //construct with defaults
Vector<SocketAddressInfo> result = socket_address_info.fetch_node("stratifylabs.co");

if( result.count() > 0 ){
 SocketAddress socket_address(result.at(0));
 Socket socket;
 socket.create(socket_address); //create a socket that can connect to stratifylabs.co

 socket.connect(socket_address); //connect to stratifylabs.co

 String request = "...";
 socket.write(request);
 //then read the response

 socket.close();
}

Methods

  • publicSocketAddressInfo(int family,int type,int protocol,int flags) Constructs a new socket address infomation object.
  • public inline constvar::ConstString&canon_name() const
  • public virtual intclose()
  • public inline intfamily() const Accesses the family.
  • public inline intflags() const Accesses the flags.
  • public inline boolis_valid()
  • public boolis_valid() const
  • public Socket &operator<<(const SocketOption & option) Sets options for the socket.
  • public inline intprotocol() const Accesses the protocol.
  • public virtual intread(void * buf,int nbyte) const
  • public intread(var::Data& data,SocketAddress & address)
  • public intread(void * buf,int nbyte,SocketAddress & address)
  • public intread(void * buf,int nbyte,struct sockaddr * ai_addr,socklen_t * ai_addrlen) const
  • public inline voidset_family(int value) Sets the family for getting address info.
  • public inline voidset_flags(int value) Sets the flags used for getting address info.
  • public inline voidset_protocol(int value) Sets the protocol for getting address info.
  • public inline voidset_type(int value) Sets the type for getting address info.
  • public virtual intshutdown(int how) const Fetches the socket address information from DNS servers based on the node and service specified.
  • public inline inttype() const Accesses the type.
  • public virtual intwrite(const void * buf,int nbyte) const
  • public inline intwrite(constvar::Data& data,const SocketAddress & address) Writes to the address specified.
  • public intwrite(const void * buf,int nbyte,const struct sockaddr * ai_addr,socklen_t ai_addrlen) const
  • public inline intwrite(const void * buf,int nbyte,const SocketAddress & socket_address) const
  • protected intm_socket
  • protected intdecode_socket_return(int value) const Initializes the system socket API.
  • enumfamily Enumerates the socket address family options.
  • enumprotocol Enumerates the socket address protocol options.
  • enumtype Enumerates the socket address type options.

Details

publicSocketAddressInfo(int family,int type,int protocol,int flags)

Constructs a new socket address infomation object.

Parameters * family Socket family (defautl is FAMILY_INET)

  • type Socket type (default is TYPE_STREAM)

  • protocol Socket protocol (default is PROTOCOL_TCP)

  • flags Socket flags (default is none)


public inline constvar::ConstString&canon_name() const


public virtual intclose()


public inline intfamily() const

Accesses the family.


public inline intflags() const

Accesses the flags.


public inline boolis_valid()


public boolis_valid() const


public Socket &operator<<(const SocketOption & option)

Sets options for the socket.

Parameters * option The option to set for the socket

SocketAddressIpv4 address(0, 8080);
Socket socket;
socket.create(address);
socket << SocketOption().set_reuse_address() << SocketOption().set_reuse_port();
socket.bind(address);

public inline intprotocol() const

Accesses the protocol.


public virtual intread(void * buf,int nbyte) const


public intread(var::Data& data,SocketAddress & address)


public intread(void * buf,int nbyte,SocketAddress & address)


public intread(void * buf,int nbyte,struct sockaddr * ai_addr,socklen_t * ai_addrlen) const


public inline voidset_family(int value)

Sets the family for getting address info.


public inline voidset_flags(int value)

Sets the flags used for getting address info.


public inline voidset_protocol(int value)

Sets the protocol for getting address info.


public inline voidset_type(int value)

Sets the type for getting address info.


public virtual intshutdown(int how) const

Fetches the socket address information from D