UdonLibrary
1.0.0
機械システム研究部 C++ ライブラリ
Toggle main menu visibility
読み取り中…
検索中…
一致する文字列を見つけられません
PioClock.hpp
[詳解]
1
//
2
// raspberry pi pico PIO clock
3
//
4
// Copyright (c) 2022 udonrobo
5
//
6
7
#pragma once
8
9
#if defined(ARDUINO_ARCH_RP2040)
10
11
# include "
SquareWave.pio.hpp
"
12
# include "
StateMachineAllocator.hpp
"
13
14
namespace
Udon
15
{
16
21
inline
bool
PioClockBegin(uint8_t pin, uint32_t clockSpeed)
22
{
23
auto
sm = Pio::AllocateStateMachine(Udon::Pio::Sqwave::squarewave_program);
24
if
(not sm)
25
{
26
return
false
;
27
}
28
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];
31
32
sm->pio->sm[sm->index].clkdiv = (uint32_t)(F_CPU * 0.25f * (1 << 16) / clockSpeed);
// 周波数設定(周波数低めのほうが誤差が少ない)
33
34
sm->pio->sm[sm->index].pinctrl = (1 << PIO_SM0_PINCTRL_SET_COUNT_LSB) | (pin << PIO_SM0_PINCTRL_SET_BASE_LSB);
// PIOがIOピンにアクセスできるようにする
35
36
gpio_set_function(pin, sm->pio == pio0 ? GPIO_FUNC_PIO0 : GPIO_FUNC_PIO1);
37
38
// pio_sm_init(pio, sm, offset, &c);
39
pio_sm_set_enabled(sm->pio, sm->index,
true
);
40
41
return
true
;
42
}
43
44
}
// namespace Udon
45
46
#endif
SquareWave.pio.hpp
StateMachineAllocator.hpp
Udon
Definition
Bit.hpp:12