Adc, ports access, system clock, irqs and tasks are starting to become somehow stable.
The API is still not fixed and very little has been actually tested.
Please come back in a few days / weeks / months.
This is library for the atmega 328. This is the IC used in arduinos.
Instead of defining pins and settings with C-macros, everything is set using C/C++ code. This is mostly possible through template arguments.
For instance pin definitions are passed around as template arguments.
This class never creates objects! Everything is static and resolved during compile time, making the generated code very compact and efficient. This is not a typical C++ library!
Only very few features are implemented using C-macros.
I still hope that the described type-stack in
b.atch.se will at some point replace the
#include C-macro tricks, which are currently necessary to register
irq handlers and tasks.
This library is only tested with gcc!
This README shows some simple examples. Only parts of the
functionality of alibvr are covered.
Every subsystem has its own README_*. I've tried to show the complete functionality in those READMEs.
If you still need more detailed information use the doxygen documentation or simply read the comments in the code itself.
I find doxygen documentations hard to read and hope that most use cases are covered through examples in the READMEs, but the doxygen comments are far more detailed.
The following code snippets are extracted from example*.cpp files in
doc/code/src.
typedefPIN_C2 Led;
Led::DDR = ports::DataDirection::Output; // Put Led pin into output mode.
Led::PORT = 1; // Set Led pin output to high. (I.e. turn it on.)typedefPIN_C2 Led;
typedefPIN_ADC0 AnalogIn;
// Only one byte is pushed onto the stack because of the uint8_t cast.voidf(constuint16_t& result) {
Led::PORT = ((uint8_t)result) > 0x0F;
}
typedef adc::Adc<adc::Ref::V1_1, AnalogIn, adc::Mode::FreeRunning, f> MyAdc;
#defineNEW_ADC MyAdc
#include REGISTER_ADC
intmain(void) {
Led::DDR = ports::DataDirection::Output; // Put Led pin into output mode.
Led::PORT = 1; // Set Led pin output to high. (I.e. turn it on.)MyAdc::init();
MyAdc::start_adc_8bit();constuint16_t fastReaction = ms_to_units<100>();
uint16_t startTimer = Clock;
Led::PORT = 1;
while (Button::PIN != 1);
uint16_t stopTimer = Clock;
if ((stopTimer - startTimer) < fastReaction) {
FastLed::PORT = 1;
}uint16_ttoggleLed1(uint16_t) {
Led1::toggle();
return clock::ms_to_units<300>();
}
#defineNEW_TASK toggleLed1
#include REGISTER_TASK
// Instead of fetching the current input from a pin,// an irq-task could set a flag. The current code// would toggle continuously while the button is pressed.voidtoggleLedButton(uint32_t) {
if (Button::PIN) {
LedButton::toggle();
}
}
#defineNEW_TASK toggleLedButton
#include REGISTER_TASK
intmain(void) {
initPorts();
for(;;) {
EXEC_TASKS();
}
}
#include REGISTER_IRQS