move uClock into lib folder for extern visibility

This commit is contained in:
2025-07-01 10:53:04 -07:00
parent eab29f3c46
commit 2123c6378b
3 changed files with 30 additions and 10 deletions

View File

@ -13,7 +13,7 @@
#define CLOCK_H
#include <NeoHWSerial.h>
#include <uClock.h>
#include "uClock.h"
#include "peripherials.h"
@ -54,7 +54,7 @@ class Clock {
// MIDI events.
uClock.setOnClockStart(sendMIDIStart);
uClock.setOnClockStop(sendMIDIStop);
// uClock.setOnSync24(sendMIDIClock);
uClock.setOnSync24(sendMIDIClock);
// uClock.setOnSync48(sendPulseOut);
uClock.start();

View File

@ -26,7 +26,7 @@
* DEALINGS IN THE SOFTWARE.
*/
#include "uClock.h"
#include "platforms/avr.h"
#include "uClock/platforms/avr.h"
//
// Platform specific timer setup/control
@ -72,6 +72,7 @@ uClockClass::uClockClass()
resetCounters();
onOutputPPQNCallback = nullptr;
onSync24Callback = nullptr;
onClockStartCallback = nullptr;
onClockStopCallback = nullptr;
// initialize reference data
@ -96,6 +97,7 @@ uint32_t uClockClass::bpmToMicroSeconds(float bpm)
void uClockClass::calculateReferencedata()
{
mod_clock_ref = output_ppqn / input_ppqn;
mod_sync24_ref = output_ppqn / PPQN_24;
}
void uClockClass::setOutputPPQN(PPQNResolution resolution)
@ -191,13 +193,7 @@ float uClockClass::getTempo()
}
// for software timer implementation(fallback for no board support)
void uClockClass::run()
{
#if !defined(UCLOCK_PLATFORM_FOUND)
// call software timer implementation of software
softwareTimerHandler(micros());
#endif
}
void uClockClass::run() {}
float inline uClockClass::freqToBpm(uint32_t freq)
{
@ -243,6 +239,10 @@ void uClockClass::resetCounters()
tick = 0;
int_clock_tick = 0;
mod_clock_counter = 0;
mod_sync24_counter = 0;
sync24_tick = 0;
ext_clock_tick = 0;
ext_clock_us = 0;
ext_interval_idx = 0;
@ -327,6 +327,17 @@ void uClockClass::handleTimerInt()
++int_clock_tick;
}
++mod_clock_counter;
// Sync24 callback
if (onSync24Callback) {
if (mod_sync24_counter == mod_sync24_ref)
mod_sync24_counter = 0;
if (mod_sync24_counter == 0) {
onSync24Callback(sync24_tick);
++sync24_tick;
}
++mod_sync24_counter;
}
// main PPQNCallback
if (onOutputPPQNCallback) {

View File

@ -80,6 +80,10 @@ class uClockClass {
onOutputPPQNCallback = callback;
}
void setOnSync24(void (*callback)(uint32_t tick)) {
onSync24Callback = callback;
}
void setOnClockStart(void (*callback)()) {
onClockStartCallback = callback;
}
@ -132,6 +136,7 @@ class uClockClass {
void calculateReferencedata();
void (*onOutputPPQNCallback)(uint32_t tick);
void (*onSync24Callback)(uint32_t tick);
void (*onClockStartCallback)();
void (*onClockStopCallback)();
@ -144,6 +149,10 @@ class uClockClass {
uint8_t mod_clock_counter;
uint16_t mod_clock_ref;
uint8_t mod_sync24_counter;
uint16_t mod_sync24_ref;
uint32_t sync24_tick;
// external clock control
volatile uint32_t ext_clock_us;
volatile uint32_t ext_clock_tick;