#include "stdlib.h"
#include "hardware/pwm.h"
#include "RP2040_PWM.h"
uint start = 0;
void pwm_handler() {
pwm_clear_irq(pwm_gpio_to_slice_num(2));
// pwm_set_irq_enabled(pwm_gpio_to_slice_num(2), false);
Serial1.println(micros() - start);
Serial1.println("interrupt!");
}
void setup() {
// put your setup code here, to run once:
Serial1.begin(115200);
Serial1.println("Hello, Raspberry Pi Pico!");
// gpio_set_function(2, GPIO_FUNC_PWM);
// gpio_set_function(5, GPIO_FUNC_PWM);
// uint slice1 = pwm_gpio_to_slice_num(2);
// pwm_set_phase_correct(slice1, true);
// // pwm_set_clkdiv(slice1, 133.f);
// pwm_set_wrap(slice1, 100);
// pwm_set_chan_level(slice1, pwm_gpio_to_channel(2), 50);
// pwm_set_enabled(slice1, true);
// uint _pin = 2;
// gpio_set_function(_pin, GPIO_FUNC_PWM);
// uint _slice_num = pwm_gpio_to_slice_num(_pin);
// // Serial1.println(_slice_num);
// pwm_config config = pwm_get_default_config();
// // Set phaseCorrect
// pwm_set_phase_correct(_slice_num, true);
// pwm_config_set_clkdiv_int(&config, 133);
// pwm_config_set_wrap(&config, 100);
// // auto start running once configured
// pwm_init(_slice_num, &config, true);
// pwm_set_gpio_level(_pin, 50);
// _pin = 5;
// gpio_set_function(_pin, GPIO_FUNC_PWM);
// _slice_num = pwm_gpio_to_slice_num(_pin);
// Serial1.println(_slice_num);
// pwm_set_phase_correct(_slice_num, true);
// Set phaseCorrect
// pwm_set_phase_correct(_slice_num, false);
// pwm_config_set_clkdiv_int(&config, 133);
// pwm_config_set_wrap(&config, 100);
// // auto start running once configured
// pwm_init(_slice_num, &config, true);
// pwm_set_gpio_level(_pin, 50);
// uint slice2 = pwm_gpio_to_slice_num(5);
// pwm_set_clkdiv(slice2, 133.f);
// pwm_set_wrap(slice2, 100);
// pwm_set_chan_level(slice2, pwm_gpio_to_channel(5), 50);
// pwm_set_enabled(1, true);
// pwm_set_enabled(2, true);
// pwm_set_mask_enabled(1 < 1 | 1 < 2);
// pwm_clear_irq(slice_num);
// pwm_set_irq_enabled(slice_num, true);
// Configure the processor to run dma_handler() when DMA IRQ 0 is asserted
// irq_set_exclusive_handler(PWM_IRQ_WRAP, pwm_handler);
// irq_set_enabled(PWM_IRQ_WRAP, true);
// pwm_set_enabled(slice_num, true);
// Get some sensible defaults for the slice configuration. By default, the
// counter is allowed to wrap over its maximum range (0 to 2**16-1)
// pwm_config config = pwm_get_default_config();
// Set divider, reduces counter clock to sysclock/this value
// pwm_config_set_clkdiv(&config, 100.f);
// Load the configuration into our PWM slice, and set it running.
// pwm_init(slice_num, &config, true);
start = micros();
}
void loop() {
// put your main code here, to run repeatedly:
delay(1); // this speeds up the simulation
}