proof-of-concept of a board-agnostic, simple micros()-check-based mode

pull/35/head
doctea 8 months ago
parent de055fa68c
commit 91ed686ea8
  1. 30
      src/platforms/generic.h
  2. 63
      src/uClock.cpp

@ -0,0 +1,30 @@
#include <Arduino.h>
//#define ATOMIC(X) noInterrupts(); X; interrupts();
#define ATOMIC(X) X;
// forward declaration of ISR
void uClockHandler();
uint32_t uclock_last_time_ticked;
uint32_t uclock_us_interval;
// call this as often as possible to tick the uClock
void uClockCheckTime(uint32_t micros_time) {
if (micros_time - uclock_last_time_ticked >= uclock_us_interval) {
uclock_last_time_ticked = micros();
uClockHandler();
}
}
void initTimer(uint32_t init_clock)
{
// basically nothing to do for software-implemented version..?
uclock_last_time_ticked = micros();
}
void setTimer(uint32_t us_interval)
{
uclock_us_interval = us_interval;
Serial.printf("setTimer(%d)\n", us_interval); Serial.flush();
}

@ -28,36 +28,52 @@
#include "uClock.h" #include "uClock.h"
// //
// General Arduino AVRs port // Generic, board-agnostic, not-accurate, no-interrupt, software-only port
// //
#if defined(ARDUINO_ARCH_AVR) #if !defined(USE_UCLOCK_GENERIC)
//
// General Arduino AVRs port
//
#if defined(ARDUINO_ARCH_AVR)
#include "platforms/avr.h" #include "platforms/avr.h"
#endif #define UCLOCK_PLATFORM_FOUND
// #endif
// Teensyduino ARMs port //
// // Teensyduino ARMs port
#if defined(TEENSYDUINO) //
#if defined(TEENSYDUINO)
#include "platforms/teensy.h" #include "platforms/teensy.h"
#endif #define UCLOCK_PLATFORM_FOUND
// #endif
// Seedstudio XIAO M0 port //
// // Seedstudio XIAO M0 port
#if defined(SEEED_XIAO_M0) //
#if defined(SEEED_XIAO_M0)
#include "platforms/samd.h" #include "platforms/samd.h"
#endif #define UCLOCK_PLATFORM_FOUND
// #endif
// ESP32 family //
// // ESP32 family
#if defined(ARDUINO_ARCH_ESP32) || defined(ESP32) //
#if defined(ARDUINO_ARCH_ESP32) || defined(ESP32)
#include "platforms/esp32.h" #include "platforms/esp32.h"
#endif #define UCLOCK_PLATFORM_FOUND
// #endif
// STM32XX family //
// // STM32XX family
#if defined(ARDUINO_ARCH_STM32) //
#if defined(ARDUINO_ARCH_STM32)
#include "platforms/stm32.h" #include "platforms/stm32.h"
#define UCLOCK_PLATFORM_FOUND
#endif
#endif
#if !defined(UCLOCK_PLATFORM_FOUND)
#pragma message ("NOTE: uClock is using the 'generic' approach instead of specific board support, because board is not supported or because of USE_UCLOCK_GENERIC build flag.")
#include "platforms/generic.h"
#endif #endif
// //
// Platform specific timer setup/control // Platform specific timer setup/control
// //
@ -72,6 +88,7 @@ void uclockInitTimer()
void setTimerTempo(float bpm) void setTimerTempo(float bpm)
{ {
Serial.printf("setTimerTempo(%3.3f)..", bpm);
setTimer(uClock.bpmToMicroSeconds(bpm)); setTimer(uClock.bpmToMicroSeconds(bpm));
} }
@ -119,7 +136,7 @@ void uClockClass::init()
uint32_t uClockClass::bpmToMicroSeconds(float bpm) uint32_t uClockClass::bpmToMicroSeconds(float bpm)
{ {
return (60000000 / ppqn / bpm); return (60000000.0f / (float)ppqn / bpm);
} }
void uClockClass::setPPQN(PPQNResolution resolution) void uClockClass::setPPQN(PPQNResolution resolution)

Loading…
Cancel
Save