Embedded Artistry C Interfaces
A reference collection of abstract interfaces in C.
|
This is a collection of abstract interfaces written in C. You can view this collection in multiple ways:
This collection is intended to serve as a reference only. The interfaces are subject to change. Do not rely on this repository remaining fixed - no guarantees are provided. If you need something, make a copy!
Generated API documentation can be found on the github-pages site for this repository. You can jump right to the list of types or the list of files.
Note that some links in the front-page (README) will not work as they are targeted for GitHub and incompatible with Doxygen. Other links will work properly.
In general, our interface design adheres to the following conventions:
getTemperature()
over temperature()
.temp0.getTemperature()
is preferred over temp0.read()
.read
as the method name when accessing data from sensors. For example, you might have a consistent sensor "base" interface that expects read
to be defined for all sensor types. This is a suitable approach, and these interfaces can be easily modified to support such cases.In general, we have opted to keep the interfaces as simple as possible. You will probably see interfaces with fewer functions and parameters than you might expect. Smaller interfaces are much easier to understand, implement, and use. Our goal is also to abstract only the common functionality required by general application code - code that is designed to be independent of any particular hardware platform, OS, or SDK.
We have generally left out initialization, configuration, and special operating modes. In our view, these details are hard to generalize (since each component, library, driver, etc. has slightly different options), and general application code does not need to access this information to do its job. Some part of the system will always be responsible for instantiating the specific implementation and mapping the implementation to an abstract interface. That part of the system can use the implementation's APIs to put the component in the system's expected state during initialization. That expectation means we can leave out a number of details.
Because we have tried to keep the interfaces as lean as possible, we have focused on the core idea for each type of interface. These interfaces can naturally be extended in many ways. Whenever we find a reusable interface pattern, we will note it here. Do not feel constrained by our lean focus - free to compose, edit, and tune these interfaces to suit the needs of your system!
The abstract interfaces we specify here are generally going to be struct
s of function pointers.
You would need to create your own functions with the same prototypes as those described by the struct
function pointers. Then, you declare an instance of the interface struct
and specify your functions as the values for the member variables.
You invoke the desired function by accessing the appropriate member variable:
This basic approach can be extended to support inheritance and polymorphism. For more information, see "Technique: Inheritance and Polymorphism in C".
For more on interface design, abstraction, and decoupling:
For more on C-specific techniques: