ws2812_esp32_rmt_driver/mock/
mod.rs1pub mod esp_idf_hal {
5 pub use super::esp_idf_sys as sys;
6
7 pub mod gpio {
9 use super::peripheral::Peripheral;
10 use paste::paste;
11
12 pub trait OutputPin {}
14
15 macro_rules! define_pins_struct {
16 ($($num:expr),*) => {
17 paste! {
18 #[derive(Debug, Default)]
20 pub struct Pins {
21 $(
22 pub [<gpio $num>]: [<Gpio $num>],
23 )*
24 }
25 }
26 }
27 }
28 define_pins_struct!(
29 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23,
30 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45,
31 46, 47, 48
32 );
33
34 impl Pins {
35 pub(super) fn new() -> Self {
36 Default::default()
37 }
38 }
39
40 macro_rules! define_gpio_structs {
41 ($($num:expr),*) => {
42 paste! {
43 $(
44 #[doc = concat!("Mock struct for `esp_idf_hal::gpio::Gpio", stringify!($num) ,"`")]
45 #[derive(Debug, Default)]
46 pub struct [<Gpio $num>] {}
47
48 impl OutputPin for [<Gpio $num>] {}
55 impl Peripheral for [<Gpio $num>] {
56 type P=[<Gpio $num>];
57 }
58 )*
59 }
60 };
61 }
62 define_gpio_structs!(
63 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23,
64 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45,
65 46, 47, 48
66 );
67 }
68
69 pub mod peripheral {
71 pub trait Peripheral: Sized {
73 type P;
75 }
76 }
77
78 pub mod peripherals {
80 use super::gpio;
81 use super::rmt;
82
83 pub struct Peripherals {
85 pub pins: gpio::Pins,
86 pub rmt: rmt::RMT,
87 }
88
89 impl Peripherals {
90 pub fn take() -> Result<Self, super::sys::EspError> {
91 Ok(Self::new())
92 }
93
94 pub fn new() -> Self {
100 Self {
101 pins: gpio::Pins::new(),
102 rmt: rmt::RMT::new(),
103 }
104 }
105 }
106 }
107
108 pub mod rmt {
110 use super::gpio::OutputPin;
111 use super::peripheral::Peripheral;
112 use super::sys::EspError;
113 use config::TransmitConfig;
114 use core::marker::PhantomData;
115 use paste::paste;
116
117 macro_rules! define_channel_structs {
118 ($($num:expr),*) => {
119 paste! {
120 $(
121 #[doc = concat!("Mock struct for `esp_idf_hal::rmt::CHANNEL", stringify!($num) ,"`")]
122 #[derive(Debug, Default)]
123 pub struct [<CHANNEL $num>] {}
124
125 impl [<CHANNEL $num>] {
126 pub fn new() -> Self {
127 Self {}
128 }
129 }
130
131 impl Peripheral for [<CHANNEL $num>] {
132 type P=[<CHANNEL $num>];
133 }
134
135 impl RmtChannel for [<CHANNEL $num>] {}
136 )*
137 }
138 };
139 }
140 define_channel_structs!(0, 1, 2, 3, 4, 5, 6, 7);
141
142 #[derive(Debug, Default)]
144 pub struct RMT {
145 pub channel0: CHANNEL0,
146 pub channel1: CHANNEL1,
147 pub channel2: CHANNEL2,
148 pub channel3: CHANNEL3,
149 pub channel4: CHANNEL4,
150 pub channel5: CHANNEL5,
151 pub channel6: CHANNEL6,
152 pub channel7: CHANNEL7,
153 }
154
155 impl RMT {
156 pub fn new() -> Self {
157 Default::default()
158 }
159 }
160
161 pub trait RmtChannel {}
163
164 pub struct TxRmtDriver<'d> {
168 _p: PhantomData<&'d mut ()>,
169 }
170
171 impl<'d> TxRmtDriver<'d> {
172 pub fn new<C: RmtChannel>(
175 _channel: impl Peripheral<P = C> + 'd,
176 _pin: impl Peripheral<P = impl OutputPin> + 'd,
177 _config: &TransmitConfig,
178 ) -> Result<Self, EspError> {
179 Ok(Self { _p: PhantomData })
180 }
181 }
182
183 pub mod config {
185 #[derive(Debug, Clone)]
187 pub struct TransmitConfig {}
188
189 impl TransmitConfig {
190 pub fn new() -> Self {
191 Self {}
192 }
193 #[allow(unused_mut)]
194 pub fn clock_divider(mut self, _divider: u8) -> Self {
195 self
196 }
197 }
198 }
199 }
200}
201
202pub mod esp_idf_sys {
204 use core::fmt;
205
206 #[repr(transparent)]
208 #[derive(Copy, Clone, Eq, PartialEq, Hash, Debug)]
209 pub struct EspError();
210
211 #[cfg(feature = "std")]
212 impl std::error::Error for EspError {}
213
214 impl fmt::Display for EspError {
215 fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
216 fmt::Display::fmt("EspError", f)
217 }
218 }
219}