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. 71
      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"
//
// General Arduino AVRs port
// Generic, board-agnostic, not-accurate, no-interrupt, software-only port
//
#if defined(ARDUINO_ARCH_AVR)
#include "platforms/avr.h"
#endif
//
// Teensyduino ARMs port
//
#if defined(TEENSYDUINO)
#include "platforms/teensy.h"
#endif
//
// Seedstudio XIAO M0 port
//
#if defined(SEEED_XIAO_M0)
#include "platforms/samd.h"
#if !defined(USE_UCLOCK_GENERIC)
//
// General Arduino AVRs port
//
#if defined(ARDUINO_ARCH_AVR)
#include "platforms/avr.h"
#define UCLOCK_PLATFORM_FOUND
#endif
//
// Teensyduino ARMs port
//
#if defined(TEENSYDUINO)
#include "platforms/teensy.h"
#define UCLOCK_PLATFORM_FOUND
#endif
//
// Seedstudio XIAO M0 port
//
#if defined(SEEED_XIAO_M0)
#include "platforms/samd.h"
#define UCLOCK_PLATFORM_FOUND
#endif
//
// ESP32 family
//
#if defined(ARDUINO_ARCH_ESP32) || defined(ESP32)
#include "platforms/esp32.h"
#define UCLOCK_PLATFORM_FOUND
#endif
//
// STM32XX family
//
#if defined(ARDUINO_ARCH_STM32)
#include "platforms/stm32.h"
#define UCLOCK_PLATFORM_FOUND
#endif
#endif
//
// ESP32 family
//
#if defined(ARDUINO_ARCH_ESP32) || defined(ESP32)
#include "platforms/esp32.h"
#endif
//
// STM32XX family
//
#if defined(ARDUINO_ARCH_STM32)
#include "platforms/stm32.h"
#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
//
// Platform specific timer setup/control
//
@ -72,6 +88,7 @@ void uclockInitTimer()
void setTimerTempo(float bpm)
{
Serial.printf("setTimerTempo(%3.3f)..", bpm);
setTimer(uClock.bpmToMicroSeconds(bpm));
}
@ -119,7 +136,7 @@ void uClockClass::init()
uint32_t uClockClass::bpmToMicroSeconds(float bpm)
{
return (60000000 / ppqn / bpm);
return (60000000.0f / (float)ppqn / bpm);
}
void uClockClass::setPPQN(PPQNResolution resolution)

Loading…
Cancel
Save