-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
10 changed files
with
114 additions
and
57 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
#ifndef EVENT_H_ | ||
#define EVENT_H_ | ||
|
||
#include <stdint.h> | ||
|
||
#define MAX_CALLBACKS_PER_EVENT 16 | ||
|
||
// the function type to which the callback addresses are converted | ||
#define CALLBACK_TYPE void(*)(void) | ||
|
||
class Event | ||
{ | ||
|
||
public: | ||
Event(); | ||
~Event(); | ||
uint8_t addListener(uint32_t callback); | ||
void removeListeners(); | ||
void emit(); | ||
|
||
private: | ||
uint32_t _callbacks[MAX_CALLBACKS_PER_EVENT]; | ||
uint8_t _endIndex; | ||
|
||
void _clearAllCallbacks(); | ||
void _clearCallbacks(); | ||
}; | ||
|
||
#endif /* EVENT_H_ */ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
#include "event.hpp" | ||
|
||
Event::Event() | ||
{ | ||
_clearAllCallbacks(); | ||
} | ||
|
||
Event::~Event() { | ||
_clearCallbacks(); | ||
} | ||
|
||
uint8_t Event::addListener(uint32_t callback) | ||
{ | ||
if (_endIndex < MAX_CALLBACKS_PER_EVENT) | ||
{ | ||
uint8_t callbackInd = _endIndex; | ||
_callbacks[_endIndex++] = callback; | ||
return callbackInd; | ||
} | ||
// error | ||
return MAX_CALLBACKS_PER_EVENT; | ||
} | ||
|
||
void Event::removeListeners() | ||
{ | ||
_clearCallbacks(); | ||
} | ||
|
||
void Event::emit() | ||
{ | ||
for (uint8_t i = 0; i < _endIndex; ++i) | ||
{ | ||
// convert the function address to a callable void function and call it | ||
((CALLBACK_TYPE)_callbacks[i])(); | ||
} | ||
} | ||
|
||
void Event::_clearAllCallbacks() | ||
{ | ||
for (uint8_t i = 0; i < MAX_CALLBACKS_PER_EVENT; ++i) | ||
{ | ||
_callbacks[i] = 0x00000000; | ||
} | ||
_endIndex = 0; | ||
} | ||
|
||
void Event::_clearCallbacks() | ||
{ | ||
for (uint8_t i = 0; i < _endIndex; ++i) | ||
{ | ||
_callbacks[i] = 0x00000000; | ||
} | ||
_endIndex = 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
#include "gpio.h" | ||
#include "gpio.hpp" | ||
|
||
GpioPin::GpioPin(GPIO_TypeDef* port, int pin) | ||
{ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,4 @@ | ||
|
||
#include "rtc.h" | ||
#include "rtc.hpp" | ||
|
||
Rtc::Rtc(uint32_t prescaler) | ||
{ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters