I have been using the AVR family of micro-controllers and at some point decided to make my collection of Hardware Abstraction Layer (HAL) drivers, hal_lib_avr_cpp, available for others to use. Of course one can simply use the Arduino IDE and it’s libraries, but might as well, just like me, want to use something lighter that uses less RAM and flash. Those drivers are usable for both AtMegas and ATTINYs.
I have written those drivers to fit my own needs and only those that are ready for use with minimal configuration are included in the driver collection so far. I have used them successfully on Arduino hardware using the Arduino IDE to compile as well. This had worked just fine because Arduino uses the GCC cross compiler for AVR and the driver collection is written for the same compiler.
The hal_lib_avr_cpp is available at my Github repository and everybody might use it in correspondence with the MIT open sours license. https://github.com/deelbg/hal_lib_avr_cpp
The hal_lib_avr_cpp is written in C++ and consists of a number of classes. Each class provides a driver for a specific peripheral of the AVR micro controller. Some classes use an object of another class or require another peripheral to be initialized and running in order to be functional. For example the rotary encoder class requires an object of the IO class to be already created and needs a reference to it in the constructor. The reason is that the encoder class uses the IO driver class to read the inputs. There is some micro controller specific configuration needed to be done in advance. Also in some places conditional compilation is used with the goal of reducing the used RAM and FLASH.
The hal_lib_avr_cpp can be found HERE and gives means to configure IO lines and input, with or without internal pull-ups or output. Software digital input debaunce logic is also included and one can select whether to read the debaunced or the raw state of an input line. There is support for rotary encoders as human interface as well. Other classes provide i2c driver for micro controllers with both TWI and USI hardware. Drivers for internal EEPROM and i2c connected EEPROM chips are included as well.
Here is a list of the files at this stage and which class what driver provides :
- hal_avr_io.h – Digital IO driver.
- hal_encoder.h – Rotary encoder driver.
- hal_avr_i2c.h – i2c driver for microcontrollers with TWI (ATMEGA) or USI (ATTINY) hardware.
- hal_avr_eeprom.h – Driver for the internal EEPROM of AVR microcontrollers.
- hal_at24cxx_eeprom.h – Driver for EEPROM chips AT24C01, AT24C02, AT24C04, AT24C08, AT24C16, AT24C32, AT24C64.
Details on the classes and the configuration needed for each of them is provided in the detailed description HERE.
THIS is an example sketch for Arduino UNO . The examples are written as an Arduino sketch with the idea to make it easier to demonstrate the drivers and for one who is interested in using them top test them. Explanation over the examples are included in the sketch.