Search code examples
c++embeddedhardwaredebianports

C++ Hardware Development


I was wondering if there are any sets of C++ classes in order to interact with hardware devices, I mean, I/O trough ports like Serial or Parallel or something like that.

I've found some info but only in C, I hope there are C++ classes already written.


Solution

  • Embedded hardware is typically proprietary, so any such library would still require some sort of hardware abstraction layer (this is true of both C and C++). UART and GPIO are relatively trivial but at the same time very chip specific, and often there are application specific requirements too, so the utility of such a library is questionable.

    It might be useful to define some common abstract interface to these resources so that application layer code would be portable between platforms, but any generic interface available may or may not suit your requirements. So you will often be better off implementing your own design and reusing it rather than being constrained by anybody else's implementation.

    If you can find suitable C libraries, then the simplest approach would be to implement suitable C++ wrappers. C code is entirely interoperable with C++.

    If the standard C library for your platform has been ported to support stdio on devices such as UARTs then the standard C++ iostream library will work, but does not provide a standard low-level interface for setting framing and baud rate; you could implement that directly or through custom ioctl() commands. If stream I/O semantics are suitable, you can implement low-level drivers for other devices and file-systems to allow access via iostream.