9#if defined(ARDUINO_ARCH_RP2040)
21 inline bool PioClockBegin(uint8_t pin, uint32_t clockSpeed)
23 auto sm = Pio::AllocateStateMachine(Udon::Pio::Sqwave::squarewave_program);
29 for (
unsigned int i = 0; i < count_of(Pio::Sqwave::squarewave_program_instructions); i++)
30 sm->pio->instr_mem[i] = Pio::Sqwave::squarewave_program_instructions[i];
32 sm->pio->sm[sm->index].clkdiv = (uint32_t)(F_CPU * 0.25f * (1 << 16) / clockSpeed);
34 sm->pio->sm[sm->index].pinctrl = (1 << PIO_SM0_PINCTRL_SET_COUNT_LSB) | (pin << PIO_SM0_PINCTRL_SET_BASE_LSB);
36 gpio_set_function(pin, sm->pio == pio0 ? GPIO_FUNC_PIO0 : GPIO_FUNC_PIO1);
39 pio_sm_set_enabled(sm->pio, sm->index,
true);