update readme, remove debug, add some comments

pull/35/head
doctea 8 months ago
parent 91ed686ea8
commit 3b2d17f5f8
  1. 26
      README.md
  2. 11
      src/platforms/generic.h

@ -2,7 +2,9 @@
The **uClock BPM Generator library** is designed to implement precise and reliable BPM clock tick calls using the microcontroller's timer hardware interruption. It is designed to be multi-architecture, portable, and easy to use within the Opensource community universe. The **uClock BPM Generator library** is designed to implement precise and reliable BPM clock tick calls using the microcontroller's timer hardware interruption. It is designed to be multi-architecture, portable, and easy to use within the Opensource community universe.
We have chosen PlatformIO and Arduino as our official deployment platforms. The library has been supported and tested on general **AVR boards (ATmega168/328, ATmega16u4/32u4, and ATmega2560)** as well as **ARM boards (Teensy, STM32XX, and Seedstudio XIAO M0)**. We have chosen PlatformIO and Arduino as our official deployment platforms. The library has been supported and tested on general **AVR boards (ATmega168/328, ATmega16u4/32u4, and ATmega2560)** as well as **ARM boards (Teensy, STM32XX, and Seedstudio XIAO M0)**.
(See also the generic fallback mode)
The absence of real-time features necessary for creating professional-level embedded devices for music and video on Opensource community-based platforms like Arduino led to the development of uClock. By leveraging the use of timer hardware interruptions, the library can schedule and manage real-time-like processing with safe shared resource access through its API. The absence of real-time features necessary for creating professional-level embedded devices for music and video on Opensource community-based platforms like Arduino led to the development of uClock. By leveraging the use of timer hardware interruptions, the library can schedule and manage real-time-like processing with safe shared resource access through its API.
@ -18,6 +20,28 @@ The uClock library API operates through attached callback functions mechanism:
5. **setOnClockStart(onClockStartCallback) > onClockStartCallback()** on uClock Start event 5. **setOnClockStart(onClockStartCallback) > onClockStartCallback()** on uClock Start event
6. **setOnClockStop(onClockStopCallback) > onClockStopCallback()** on uClock Stop event 6. **setOnClockStop(onClockStopCallback) > onClockStopCallback()** on uClock Stop event
### Generic mode - for unsupported boards (or avoiding usage of interrupts)
If a supported board isn't detected during compilation then a generic fallback approach will be used that does not utilise any interrupts to ensure accurate timekeeping. This can be useful to port projets to boards that do not have support in uClock yet, or to test if suspected bugs are related to interactions with interrupts or task handling.
You can force this non-interrupt "generic mode" even on supported boards by defining the build flag `USE_UCLOCK_GENERIC`.
In order for generic mode to work, you need to add a call to your `loop()` function to process ticks. For example,
```c++
// prototype of
void uClockCheckTime(uint32_t micros_time);
void loop() {
#ifdef USE_UCLOCK_GENERIC
uClockCheckTime(micros());
#endif
// do anything else you need to do inside loop()...
}
```
## uClock v2.0 Breakchanges ## uClock v2.0 Breakchanges
If you are comming from uClock version < 2.0 versions keep attention to the breakchanges so you can update your code to the new API interface changes: If you are comming from uClock version < 2.0 versions keep attention to the breakchanges so you can update your code to the new API interface changes:

@ -1,6 +1,12 @@
#include <Arduino.h> #include <Arduino.h>
//#define ATOMIC(X) noInterrupts(); X; interrupts(); /*
Generic fallback approach that doesn't rely on any particular MCU's interrupts or RTOS threads etc.
Simply checks micros() and compares last time tick happened and interval size to determine when a tick is due.
requires calling uClockCheckTime(micros()); inside loop() in order to trigger tick processing.
function signature: void uClockCheckTime(uint32_t micros_time);
*/
#define ATOMIC(X) X; #define ATOMIC(X) X;
// forward declaration of ISR // forward declaration of ISR
@ -12,7 +18,7 @@ uint32_t uclock_us_interval;
// call this as often as possible to tick the uClock // call this as often as possible to tick the uClock
void uClockCheckTime(uint32_t micros_time) { void uClockCheckTime(uint32_t micros_time) {
if (micros_time - uclock_last_time_ticked >= uclock_us_interval) { if (micros_time - uclock_last_time_ticked >= uclock_us_interval) {
uclock_last_time_ticked = micros(); uclock_last_time_ticked = micros_time;
uClockHandler(); uClockHandler();
} }
} }
@ -26,5 +32,4 @@ void initTimer(uint32_t init_clock)
void setTimer(uint32_t us_interval) void setTimer(uint32_t us_interval)
{ {
uclock_us_interval = us_interval; uclock_us_interval = us_interval;
Serial.printf("setTimer(%d)\n", us_interval); Serial.flush();
} }
Loading…
Cancel
Save