|
|
|
@ -30,25 +30,18 @@ |
|
|
|
|
//
|
|
|
|
|
// Timer setup for work clock
|
|
|
|
|
//
|
|
|
|
|
#if defined(TEENSYDUINO) && !defined(__AVR_ATmega32U4__) |
|
|
|
|
// all non-avr timmers setup
|
|
|
|
|
// Teensyduino port
|
|
|
|
|
#if defined(TEENSYDUINO) |
|
|
|
|
IntervalTimer _uclockTimer; |
|
|
|
|
void uclockISR(); |
|
|
|
|
void uclockInitTimer() |
|
|
|
|
{ |
|
|
|
|
ATOMIC( |
|
|
|
|
#endif |
|
|
|
|
// Seedstudio XIAO M0 port
|
|
|
|
|
#if defined(SEEED_XIAO_M0) |
|
|
|
|
#include <TimerTCC0.h> |
|
|
|
|
TimerTCC0 _uclockTimer; |
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
// begin at 120bpm (20833us)
|
|
|
|
|
_uclockTimer.begin(uclockISR, 20833);
|
|
|
|
|
|
|
|
|
|
// Set the interrupt priority level, controlling which other interrupts
|
|
|
|
|
// this timer is allowed to interrupt. Lower numbers are higher priority,
|
|
|
|
|
// with 0 the highest and 255 the lowest. Most other interrupts default to 128.
|
|
|
|
|
// As a general guideline, interrupt routines that run longer should be given
|
|
|
|
|
// lower priority (higher numerical values).
|
|
|
|
|
_uclockTimer.priority(0); |
|
|
|
|
) |
|
|
|
|
} |
|
|
|
|
#else |
|
|
|
|
#if defined(ARDUINO_ARCH_AVR) |
|
|
|
|
void uclockInitTimer() |
|
|
|
|
{ |
|
|
|
|
ATOMIC( |
|
|
|
@ -67,6 +60,32 @@ void uclockInitTimer() |
|
|
|
|
TIMSK1 |= (1 << OCIE1A); |
|
|
|
|
) |
|
|
|
|
} |
|
|
|
|
#else |
|
|
|
|
void uclockISR(); |
|
|
|
|
void uclockInitTimer() |
|
|
|
|
{ |
|
|
|
|
// begin at 120bpm (20833us)
|
|
|
|
|
const uint16_t init_clock = 20833; |
|
|
|
|
ATOMIC( |
|
|
|
|
#if defined(TEENSYDUINO) |
|
|
|
|
_uclockTimer.begin(uclockISR, init_clock);
|
|
|
|
|
|
|
|
|
|
// Set the interrupt priority level, controlling which other interrupts
|
|
|
|
|
// this timer is allowed to interrupt. Lower numbers are higher priority,
|
|
|
|
|
// with 0 the highest and 255 the lowest. Most other interrupts default to 128.
|
|
|
|
|
// As a general guideline, interrupt routines that run longer should be given
|
|
|
|
|
// lower priority (higher numerical values).
|
|
|
|
|
_uclockTimer.priority(0); |
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
#if defined(SEEED_XIAO_M0) |
|
|
|
|
_uclockTimer.initialize(init_clock); |
|
|
|
|
|
|
|
|
|
// attach to generic uclock ISR
|
|
|
|
|
_uclockTimer.attachInterrupt(uclockISR); |
|
|
|
|
#endif |
|
|
|
|
) |
|
|
|
|
} |
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
namespace umodular { namespace clock { |
|
|
|
@ -153,11 +172,7 @@ void uClockClass::setTimerTempo(float bpm) |
|
|
|
|
tick_us_interval = (60000000 / 24 / bpm); |
|
|
|
|
tick_hertz_interval = 1/((float)tick_us_interval/1000000); |
|
|
|
|
|
|
|
|
|
#if defined(TEENSYDUINO) && !defined(__AVR_ATmega32U4__) |
|
|
|
|
ATOMIC( |
|
|
|
|
_uclockTimer.update(tick_us_interval); |
|
|
|
|
) |
|
|
|
|
#else |
|
|
|
|
#if defined(ARDUINO_ARCH_AVR) |
|
|
|
|
uint32_t ocr; |
|
|
|
|
uint8_t tccr = 0; |
|
|
|
|
|
|
|
|
@ -188,6 +203,16 @@ void uClockClass::setTimerTempo(float bpm) |
|
|
|
|
TCCR1B |= (1 << WGM12); |
|
|
|
|
TCCR1B |= tccr; |
|
|
|
|
) |
|
|
|
|
#else |
|
|
|
|
ATOMIC( |
|
|
|
|
#if defined(TEENSYDUINO) |
|
|
|
|
_uclockTimer.update(tick_us_interval); |
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
#if defined(SEEED_XIAO_M0) |
|
|
|
|
_uclockTimer.setPeriod(tick_us_interval); |
|
|
|
|
#endif |
|
|
|
|
) |
|
|
|
|
#endif |
|
|
|
|
} |
|
|
|
|
|
|
|
|
@ -355,15 +380,15 @@ void uClockClass::handleTimerInt() |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (onClock96PPQNCallback) { |
|
|
|
|
onClock96PPQNCallback(&internal_tick); |
|
|
|
|
onClock96PPQNCallback(internal_tick); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (mod6_counter == 0) { |
|
|
|
|
if (onClock32PPQNCallback) { |
|
|
|
|
onClock32PPQNCallback(&div32th_counter); |
|
|
|
|
onClock32PPQNCallback(div32th_counter); |
|
|
|
|
} |
|
|
|
|
if (onClock16PPQNCallback) { |
|
|
|
|
onClock16PPQNCallback(&div16th_counter); |
|
|
|
|
onClock16PPQNCallback(div16th_counter); |
|
|
|
|
} |
|
|
|
|
div16th_counter++; |
|
|
|
|
div32th_counter++; |
|
|
|
@ -371,7 +396,7 @@ void uClockClass::handleTimerInt() |
|
|
|
|
|
|
|
|
|
if (mod6_counter == 3) { |
|
|
|
|
if (onClock32PPQNCallback) { |
|
|
|
|
onClock32PPQNCallback(&div32th_counter); |
|
|
|
|
onClock32PPQNCallback(div32th_counter); |
|
|
|
|
} |
|
|
|
|
div32th_counter++; |
|
|
|
|
} |
|
|
|
@ -439,10 +464,10 @@ volatile uint32_t _timer = 0; |
|
|
|
|
// TIMER INTERRUPT HANDLER
|
|
|
|
|
//
|
|
|
|
|
//
|
|
|
|
|
#if defined(TEENSYDUINO) && !defined(__AVR_ATmega32U4__) |
|
|
|
|
void uclockISR()
|
|
|
|
|
#else |
|
|
|
|
#if defined(ARDUINO_ARCH_AVR) |
|
|
|
|
ISR(TIMER1_COMPA_vect) |
|
|
|
|
#else |
|
|
|
|
void uclockISR()
|
|
|
|
|
#endif |
|
|
|
|
{ |
|
|
|
|
// global timer counter
|
|
|
|
|