Match PWM Library on Wio Terminal

I’m interested in outputing frequencies that are not dependent upon integer period assignments commonly used for timer recipes to toggle a pin. For example, you can use the SAMD51 timer library which accepts an integer argument in microseconds. This works fine for approximate frequencies but ultimately breaks down at moderate frequencies into the kHz range.

Optivolt-Labs has a library that compiles and appears to work on the Adafruit M4 platforms which also use the SAMD51 chip. With that said, the compilation of the following fails on the Wio Terminal as the GClk variable is not defined (at a minimum). This is getting beyond my level of knowlege and was hoping someone might be able to aid in identifying how to access this clock using the Wio Terminal?

Below is an example .ino that works for the Adafruit platform but not the Wio Terminal.

#include <Arduino.h>
#include "mpwm.h"

// valid GCLK value depends on which internal clock you want to use
// some of them are used by arduino core or in other libs, it's worth poking around
// arduino core to double check since it sometimes varies from board to board
// personally found GCLK2 to be a safe bet

MPwm::MatchPwm pwm_signal = MPwm::MatchPwm(33, MPwm::GClk::GCLK2);

void setup() {
    pinMode(30, OUTPUT);

    // set pwm to some default value to start with
    pwm_signal.enable();
    pwm_signal.write(.5, 100000); // 50% duty cycle at 100000Hz
}

float max_freq = 150000;
float min_freq = 50000;
float freq_stp = 10000;
bool increase_duty = true;

void loop() {
    if(increase_duty) {
        float freq_target = pwm_signal.getFrequency() + freq_stp;
        if (freq_target > max_freq) {
            increase_duty = false;
        } else {
            pwm_signal.setFrequency(freq_target);
        }
    } else {
        float freq_target = pwm_signal.getFrequency() - freq_stp;
        if (freq_target < min_freq) {
            increase_duty = true;
        } else {
            pwm_signal.setFrequency(freq_target);
        }
    }
}

Here’s the error trace for the Wio Terminal:

In file included from /Users/gandalf/Library/Arduino15/packages/Seeeduino/hardware/samd/1.7.9/cores/arduino/delay.h:24:0,
                     from /Users/gandalf/Library/Arduino15/packages/Seeeduino/hardware/samd/1.7.9/cores/arduino/Arduino.h:84,
                     from sketch/mpwm.h:3,
                     from sketch/mpwm.cpp:1:
    /Users/gandalf/Library/Arduino15/packages/Seeeduino/hardware/samd/1.7.9/variants/wio_terminal/variant.h:260:15: error: expected identifier before '(' token
     #define GCLK0 (36ul)
                   ^
    sketch/mpwm.h:11:22: note: in expansion of macro 'GCLK0'
         enum class GClk {GCLK0, GCLK1, GCLK2};
                          ^~~~~
    /Users/gandalf/Library/Arduino15/packages/Seeeduino/hardware/samd/1.7.9/variants/wio_terminal/variant.h:260:15: error: expected '}' before '(' token
     #define GCLK0 (36ul)
                   ^
    sketch/mpwm.h:11:22: note: in expansion of macro 'GCLK0'
         enum class GClk {GCLK0, GCLK1, GCLK2};
                          ^~~~~
    /Users/gandalf/Library/Arduino15/packages/Seeeduino/hardware/samd/1.7.9/variants/wio_terminal/variant.h:260:16: error: expected unqualified-id before numeric constant
     #define GCLK0 (36ul)
                    ^
    sketch/mpwm.h:11:22: note: in expansion of macro 'GCLK0'
         enum class GClk {GCLK0, GCLK1, GCLK2};
                          ^~~~~
    /Users/gandalf/Library/Arduino15/packages/Seeeduino/hardware/samd/1.7.9/variants/wio_terminal/variant.h:260:16: error: expected ')' before numeric constant
     #define GCLK0 (36ul)
                    ^
    sketch/mpwm.h:11:22: note: in expansion of macro 'GCLK0'
         enum class GClk {GCLK0, GCLK1, GCLK2};
                          ^~~~~
    In file included from sketch/mpwm.cpp:1:0:
    mpwm.h:15:36: error: 'GClk' has not been declared
                 MatchPwm(uint32_t pin, GClk clk);
                                        ^~~~
    In file included from /Users/gandalf/Library/Arduino15/packages/Seeeduino/hardware/samd/1.7.9/cores/arduino/delay.h:24:0,
                     from /Users/gandalf/Library/Arduino15/packages/Seeeduino/hardware/samd/1.7.9/cores/arduino/Arduino.h:84,
                     from /Users/gandalf/Google Drive/Electronics/Arduino/Wio_Match_PWM/Wio_Match_PWM.ino:1:
    /Users/gandalf/Library/Arduino15/packages/Seeeduino/hardware/samd/1.7.9/variants/wio_terminal/variant.h:260:15: error: expected identifier before '(' token
     #define GCLK0 (36ul)
                   ^
    sketch/mpwm.h:11:22: note: in expansion of macro 'GCLK0'
         enum class GClk {GCLK0, GCLK1, GCLK2};
                          ^~~~~
    /Users/gandalf/Library/Arduino15/packages/Seeeduino/hardware/samd/1.7.9/variants/wio_terminal/variant.h:260:15: error: expected '}' before '(' token
     #define GCLK0 (36ul)
                   ^
    sketch/mpwm.h:11:22: note: in expansion of macro 'GCLK0'
         enum class GClk {GCLK0, GCLK1, GCLK2};
                          ^~~~~
    /Users/gandalf/Library/Arduino15/packages/Seeeduino/hardware/samd/1.7.9/variants/wio_terminal/variant.h:260:16: error: expected unqualified-id before numeric constant
     #define GCLK0 (36ul)
                    ^
    sketch/mpwm.h:11:22: note: in expansion of macro 'GCLK0'
         enum class GClk {GCLK0, GCLK1, GCLK2};
                          ^~~~~
    /Users/gandalf/Library/Arduino15/packages/Seeeduino/hardware/samd/1.7.9/variants/wio_terminal/variant.h:260:16: error: expected ')' before numeric constant
     #define GCLK0 (36ul)
                    ^
    sketch/mpwm.h:11:22: note: in expansion of macro 'GCLK0'
         enum class GClk {GCLK0, GCLK1, GCLK2};
                          ^~~~~
    In file included from /Users/gandalf/Google Drive/Electronics/Arduino/Wio_Match_PWM/Wio_Match_PWM.ino:2:0:
    mpwm.h:15:36: error: 'GClk' has not been declared
                 MatchPwm(uint32_t pin, GClk clk);
                                        ^~~~
    mpwm.h:33:19: error: 'GClk' does not name a type; did you mean 'Gclk'?
                 const GClk _clk;
                       ^~~~
                       Gclk
    mpwm.h:33:19: error: 'GClk' does not name a type; did you mean 'Gclk'?
                 const GClk _clk;
                       ^~~~
                       Gclk
    sketch/mpwm.h: In constructor 'MatchPwm::MatchPwm(uint32_t)':
    mpwm.h:16:61: error: 'GClk' has not been declared
                 explicit MatchPwm(uint32_t pin) : MatchPwm(pin, GClk::GCLK0) {};
                                                                 ^~~~
    In file included from /Users/gandalf/Library/Arduino15/packages/Seeeduino/hardware/samd/1.7.9/cores/arduino/delay.h:24:0,
                     from /Users/gandalf/Library/Arduino15/packages/Seeeduino/hardware/samd/1.7.9/cores/arduino/Arduino.h:84,
                     from /Users/gandalf/Google Drive/Electronics/Arduino/Wio_Match_PWM/Wio_Match_PWM.ino:1:
    /Users/gandalf/Library/Arduino15/packages/Seeeduino/hardware/samd/1.7.9/variants/wio_terminal/variant.h:260:15: error: expected unqualified-id before '(' token
     #define GCLK0 (36ul)
                   ^
    sketch/mpwm.h:16:67: note: in expansion of macro 'GCLK0'
                 explicit MatchPwm(uint32_t pin) : MatchPwm(pin, GClk::GCLK0) {};
                                                                       ^~~~~
    In file included from /Users/gandalf/Google Drive/Electronics/Arduino/Wio_Match_PWM/Wio_Match_PWM.ino:2:0:
    sketch/mpwm.h: At global scope:
    mpwm.h:38:1: error: expected declaration before '}' token
     }
     ^
    sketch/mpwm.h: In constructor 'MatchPwm::MatchPwm(uint32_t)':
    mpwm.h:16:61: error: 'GClk' has not been declared
                 explicit MatchPwm(uint32_t pin) : MatchPwm(pin, GClk::GCLK0) {};
                                                                 ^~~~
    In file included from /Users/gandalf/Library/Arduino15/packages/Seeeduino/hardware/samd/1.7.9/cores/arduino/delay.h:24:0,
                     from /Users/gandalf/Library/Arduino15/packages/Seeeduino/hardware/samd/1.7.9/cores/arduino/Arduino.h:84,
                     from sketch/mpwm.h:3,
                     from sketch/mpwm.cpp:1:
    /Users/gandalf/Library/Arduino15/packages/Seeeduino/hardware/samd/1.7.9/variants/wio_terminal/variant.h:260:15: error: expected unqualified-id before '(' token
     #define GCLK0 (36ul)
                   ^
    sketch/mpwm.h:16:67: note: in expansion of macro 'GCLK0'
                 explicit MatchPwm(uint32_t pin) : MatchPwm(pin, GClk::GCLK0) {};
                                                                       ^~~~~
    In file included from sketch/mpwm.cpp:1:0:
    sketch/mpwm.h: At global scope:
    mpwm.h:38:1: error: expected declaration before '}' token
     }
     ^
    exit status 1
    'GClk' has not been declared