1 | #![allow (clippy::missing_safety_doc)] |
2 | #![allow (clippy::identity_op)] |
3 | #![allow (clippy::unnecessary_cast)] |
4 | #![allow (clippy::erasing_op)] |
5 | |
6 | #[doc = "CORDIC co-processor." ] |
7 | #[derive (Copy, Clone, Eq, PartialEq)] |
8 | pub struct Cordic { |
9 | ptr: *mut u8, |
10 | } |
11 | unsafe impl Send for Cordic {} |
12 | unsafe impl Sync for Cordic {} |
13 | impl Cordic { |
14 | #[inline (always)] |
15 | pub const unsafe fn from_ptr(ptr: *mut ()) -> Self { |
16 | Self { ptr: ptr as _ } |
17 | } |
18 | #[inline (always)] |
19 | pub const fn as_ptr(&self) -> *mut () { |
20 | self.ptr as _ |
21 | } |
22 | #[doc = "Control and status register." ] |
23 | #[inline (always)] |
24 | pub const fn csr(self) -> crate::common::Reg<regs::Csr, crate::common::RW> { |
25 | unsafe { crate::common::Reg::from_ptr(self.ptr.add(0x0usize) as _) } |
26 | } |
27 | #[doc = "Argument register." ] |
28 | #[inline (always)] |
29 | pub const fn wdata(self) -> crate::common::Reg<u32, crate::common::RW> { |
30 | unsafe { crate::common::Reg::from_ptr(self.ptr.add(0x04usize) as _) } |
31 | } |
32 | #[doc = "Result register." ] |
33 | #[inline (always)] |
34 | pub const fn rdata(self) -> crate::common::Reg<u32, crate::common::RW> { |
35 | unsafe { crate::common::Reg::from_ptr(self.ptr.add(0x08usize) as _) } |
36 | } |
37 | } |
38 | pub mod regs { |
39 | #[doc = "Control and status register." ] |
40 | #[repr (transparent)] |
41 | #[derive (Copy, Clone, Eq, PartialEq)] |
42 | pub struct Csr(pub u32); |
43 | impl Csr { |
44 | #[doc = "Function." ] |
45 | #[inline (always)] |
46 | pub const fn func(&self) -> super::vals::Func { |
47 | let val = (self.0 >> 0usize) & 0x0f; |
48 | super::vals::Func::from_bits(val as u8) |
49 | } |
50 | #[doc = "Function." ] |
51 | #[inline (always)] |
52 | pub fn set_func(&mut self, val: super::vals::Func) { |
53 | self.0 = (self.0 & !(0x0f << 0usize)) | (((val.to_bits() as u32) & 0x0f) << 0usize); |
54 | } |
55 | #[doc = "Precision required (number of iterations/cycles), where PRECISION = (number of iterations/4)." ] |
56 | #[inline (always)] |
57 | pub const fn precision(&self) -> super::vals::Precision { |
58 | let val = (self.0 >> 4usize) & 0x0f; |
59 | super::vals::Precision::from_bits(val as u8) |
60 | } |
61 | #[doc = "Precision required (number of iterations/cycles), where PRECISION = (number of iterations/4)." ] |
62 | #[inline (always)] |
63 | pub fn set_precision(&mut self, val: super::vals::Precision) { |
64 | self.0 = (self.0 & !(0x0f << 4usize)) | (((val.to_bits() as u32) & 0x0f) << 4usize); |
65 | } |
66 | #[doc = "Scaling factor. Input value has been multiplied by 2^(-n) before for argument. Output value will need to be multiplied by 2^n later for results." ] |
67 | #[inline (always)] |
68 | pub const fn scale(&self) -> super::vals::Scale { |
69 | let val = (self.0 >> 8usize) & 0x07; |
70 | super::vals::Scale::from_bits(val as u8) |
71 | } |
72 | #[doc = "Scaling factor. Input value has been multiplied by 2^(-n) before for argument. Output value will need to be multiplied by 2^n later for results." ] |
73 | #[inline (always)] |
74 | pub fn set_scale(&mut self, val: super::vals::Scale) { |
75 | self.0 = (self.0 & !(0x07 << 8usize)) | (((val.to_bits() as u32) & 0x07) << 8usize); |
76 | } |
77 | #[doc = "Enable interrupt." ] |
78 | #[inline (always)] |
79 | pub const fn ien(&self) -> bool { |
80 | let val = (self.0 >> 16usize) & 0x01; |
81 | val != 0 |
82 | } |
83 | #[doc = "Enable interrupt." ] |
84 | #[inline (always)] |
85 | pub fn set_ien(&mut self, val: bool) { |
86 | self.0 = (self.0 & !(0x01 << 16usize)) | (((val as u32) & 0x01) << 16usize); |
87 | } |
88 | #[doc = "Enable DMA wread channel." ] |
89 | #[inline (always)] |
90 | pub const fn dmaren(&self) -> bool { |
91 | let val = (self.0 >> 17usize) & 0x01; |
92 | val != 0 |
93 | } |
94 | #[doc = "Enable DMA wread channel." ] |
95 | #[inline (always)] |
96 | pub fn set_dmaren(&mut self, val: bool) { |
97 | self.0 = (self.0 & !(0x01 << 17usize)) | (((val as u32) & 0x01) << 17usize); |
98 | } |
99 | #[doc = "Enable DMA write channel." ] |
100 | #[inline (always)] |
101 | pub const fn dmawen(&self) -> bool { |
102 | let val = (self.0 >> 18usize) & 0x01; |
103 | val != 0 |
104 | } |
105 | #[doc = "Enable DMA write channel." ] |
106 | #[inline (always)] |
107 | pub fn set_dmawen(&mut self, val: bool) { |
108 | self.0 = (self.0 & !(0x01 << 18usize)) | (((val as u32) & 0x01) << 18usize); |
109 | } |
110 | #[doc = "Number of results in the RDATA register." ] |
111 | #[inline (always)] |
112 | pub const fn nres(&self) -> super::vals::Num { |
113 | let val = (self.0 >> 19usize) & 0x01; |
114 | super::vals::Num::from_bits(val as u8) |
115 | } |
116 | #[doc = "Number of results in the RDATA register." ] |
117 | #[inline (always)] |
118 | pub fn set_nres(&mut self, val: super::vals::Num) { |
119 | self.0 = (self.0 & !(0x01 << 19usize)) | (((val.to_bits() as u32) & 0x01) << 19usize); |
120 | } |
121 | #[doc = "Number of arguments expected by the WDATA register." ] |
122 | #[inline (always)] |
123 | pub const fn nargs(&self) -> super::vals::Num { |
124 | let val = (self.0 >> 20usize) & 0x01; |
125 | super::vals::Num::from_bits(val as u8) |
126 | } |
127 | #[doc = "Number of arguments expected by the WDATA register." ] |
128 | #[inline (always)] |
129 | pub fn set_nargs(&mut self, val: super::vals::Num) { |
130 | self.0 = (self.0 & !(0x01 << 20usize)) | (((val.to_bits() as u32) & 0x01) << 20usize); |
131 | } |
132 | #[doc = "Width of output data." ] |
133 | #[inline (always)] |
134 | pub const fn ressize(&self) -> super::vals::Size { |
135 | let val = (self.0 >> 21usize) & 0x01; |
136 | super::vals::Size::from_bits(val as u8) |
137 | } |
138 | #[doc = "Width of output data." ] |
139 | #[inline (always)] |
140 | pub fn set_ressize(&mut self, val: super::vals::Size) { |
141 | self.0 = (self.0 & !(0x01 << 21usize)) | (((val.to_bits() as u32) & 0x01) << 21usize); |
142 | } |
143 | #[doc = "Width of input data." ] |
144 | #[inline (always)] |
145 | pub const fn argsize(&self) -> super::vals::Size { |
146 | let val = (self.0 >> 22usize) & 0x01; |
147 | super::vals::Size::from_bits(val as u8) |
148 | } |
149 | #[doc = "Width of input data." ] |
150 | #[inline (always)] |
151 | pub fn set_argsize(&mut self, val: super::vals::Size) { |
152 | self.0 = (self.0 & !(0x01 << 22usize)) | (((val.to_bits() as u32) & 0x01) << 22usize); |
153 | } |
154 | #[doc = "Result ready flag." ] |
155 | #[inline (always)] |
156 | pub const fn rrdy(&self) -> bool { |
157 | let val = (self.0 >> 31usize) & 0x01; |
158 | val != 0 |
159 | } |
160 | #[doc = "Result ready flag." ] |
161 | #[inline (always)] |
162 | pub fn set_rrdy(&mut self, val: bool) { |
163 | self.0 = (self.0 & !(0x01 << 31usize)) | (((val as u32) & 0x01) << 31usize); |
164 | } |
165 | } |
166 | impl Default for Csr { |
167 | #[inline (always)] |
168 | fn default() -> Csr { |
169 | Csr(0) |
170 | } |
171 | } |
172 | impl core::fmt::Debug for Csr { |
173 | fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result { |
174 | f.debug_struct("Csr" ) |
175 | .field("func" , &self.func()) |
176 | .field("precision" , &self.precision()) |
177 | .field("scale" , &self.scale()) |
178 | .field("ien" , &self.ien()) |
179 | .field("dmaren" , &self.dmaren()) |
180 | .field("dmawen" , &self.dmawen()) |
181 | .field("nres" , &self.nres()) |
182 | .field("nargs" , &self.nargs()) |
183 | .field("ressize" , &self.ressize()) |
184 | .field("argsize" , &self.argsize()) |
185 | .field("rrdy" , &self.rrdy()) |
186 | .finish() |
187 | } |
188 | } |
189 | #[cfg (feature = "defmt" )] |
190 | impl defmt::Format for Csr { |
191 | fn format(&self, f: defmt::Formatter) { |
192 | #[derive (defmt :: Format)] |
193 | struct Csr { |
194 | func: super::vals::Func, |
195 | precision: super::vals::Precision, |
196 | scale: super::vals::Scale, |
197 | ien: bool, |
198 | dmaren: bool, |
199 | dmawen: bool, |
200 | nres: super::vals::Num, |
201 | nargs: super::vals::Num, |
202 | ressize: super::vals::Size, |
203 | argsize: super::vals::Size, |
204 | rrdy: bool, |
205 | } |
206 | let proxy = Csr { |
207 | func: self.func(), |
208 | precision: self.precision(), |
209 | scale: self.scale(), |
210 | ien: self.ien(), |
211 | dmaren: self.dmaren(), |
212 | dmawen: self.dmawen(), |
213 | nres: self.nres(), |
214 | nargs: self.nargs(), |
215 | ressize: self.ressize(), |
216 | argsize: self.argsize(), |
217 | rrdy: self.rrdy(), |
218 | }; |
219 | defmt::write!(f, "{}" , proxy) |
220 | } |
221 | } |
222 | } |
223 | pub mod vals { |
224 | #[repr (u8)] |
225 | #[derive (Copy, Clone, Debug, Eq, PartialEq, Ord, PartialOrd)] |
226 | #[cfg_attr (feature = "defmt" , derive(defmt::Format))] |
227 | pub enum Func { |
228 | #[doc = "Cosine function." ] |
229 | COSINE = 0x0, |
230 | #[doc = "Sine function." ] |
231 | SINE = 0x01, |
232 | #[doc = "Phase function." ] |
233 | PHASE = 0x02, |
234 | #[doc = "Modulus function." ] |
235 | MODULUS = 0x03, |
236 | #[doc = "Arctangent function." ] |
237 | ARCTANGENT = 0x04, |
238 | #[doc = "Hyperbolic Cosine function." ] |
239 | HYPERBOLIC_COSINE = 0x05, |
240 | #[doc = "Hyperbolic Sine function." ] |
241 | HYPERBOLIC_SINE = 0x06, |
242 | #[doc = "Arctanh function." ] |
243 | ARCTANH = 0x07, |
244 | #[doc = "Natural Logarithm function." ] |
245 | NATURAL_LOGARITHM = 0x08, |
246 | #[doc = "Square Root function." ] |
247 | SQUARE_ROOT = 0x09, |
248 | _RESERVED_a = 0x0a, |
249 | _RESERVED_b = 0x0b, |
250 | _RESERVED_c = 0x0c, |
251 | _RESERVED_d = 0x0d, |
252 | _RESERVED_e = 0x0e, |
253 | _RESERVED_f = 0x0f, |
254 | } |
255 | impl Func { |
256 | #[inline (always)] |
257 | pub const fn from_bits(val: u8) -> Func { |
258 | unsafe { core::mem::transmute(val & 0x0f) } |
259 | } |
260 | #[inline (always)] |
261 | pub const fn to_bits(self) -> u8 { |
262 | unsafe { core::mem::transmute(self) } |
263 | } |
264 | } |
265 | impl From<u8> for Func { |
266 | #[inline (always)] |
267 | fn from(val: u8) -> Func { |
268 | Func::from_bits(val) |
269 | } |
270 | } |
271 | impl From<Func> for u8 { |
272 | #[inline (always)] |
273 | fn from(val: Func) -> u8 { |
274 | Func::to_bits(val) |
275 | } |
276 | } |
277 | #[repr (u8)] |
278 | #[derive (Copy, Clone, Debug, Eq, PartialEq, Ord, PartialOrd)] |
279 | #[cfg_attr (feature = "defmt" , derive(defmt::Format))] |
280 | pub enum Num { |
281 | #[doc = "1 input/output" ] |
282 | NUM1 = 0x0, |
283 | #[doc = "2 input/output" ] |
284 | NUM2 = 0x01, |
285 | } |
286 | impl Num { |
287 | #[inline (always)] |
288 | pub const fn from_bits(val: u8) -> Num { |
289 | unsafe { core::mem::transmute(val & 0x01) } |
290 | } |
291 | #[inline (always)] |
292 | pub const fn to_bits(self) -> u8 { |
293 | unsafe { core::mem::transmute(self) } |
294 | } |
295 | } |
296 | impl From<u8> for Num { |
297 | #[inline (always)] |
298 | fn from(val: u8) -> Num { |
299 | Num::from_bits(val) |
300 | } |
301 | } |
302 | impl From<Num> for u8 { |
303 | #[inline (always)] |
304 | fn from(val: Num) -> u8 { |
305 | Num::to_bits(val) |
306 | } |
307 | } |
308 | #[repr (u8)] |
309 | #[derive (Copy, Clone, Debug, Eq, PartialEq, Ord, PartialOrd)] |
310 | #[cfg_attr (feature = "defmt" , derive(defmt::Format))] |
311 | pub enum Precision { |
312 | _RESERVED_0 = 0x0, |
313 | #[doc = "4 iterations." ] |
314 | ITERS4 = 0x01, |
315 | #[doc = "8 iterations." ] |
316 | ITERS8 = 0x02, |
317 | #[doc = "12 iterations." ] |
318 | ITERS12 = 0x03, |
319 | #[doc = "16 iterations." ] |
320 | ITERS16 = 0x04, |
321 | #[doc = "20 iterations." ] |
322 | ITERS20 = 0x05, |
323 | #[doc = "24 iterations." ] |
324 | ITERS24 = 0x06, |
325 | #[doc = "28 iterations." ] |
326 | ITERS28 = 0x07, |
327 | #[doc = "32 iterations." ] |
328 | ITERS32 = 0x08, |
329 | #[doc = "36 iterations." ] |
330 | ITERS36 = 0x09, |
331 | #[doc = "40 iterations." ] |
332 | ITERS40 = 0x0a, |
333 | #[doc = "44 iterations." ] |
334 | ITERS44 = 0x0b, |
335 | #[doc = "48 iterations." ] |
336 | ITERS48 = 0x0c, |
337 | #[doc = "52 iterations." ] |
338 | ITERS52 = 0x0d, |
339 | #[doc = "56 iterations." ] |
340 | ITERS56 = 0x0e, |
341 | #[doc = "60 iterations." ] |
342 | ITERS60 = 0x0f, |
343 | } |
344 | impl Precision { |
345 | #[inline (always)] |
346 | pub const fn from_bits(val: u8) -> Precision { |
347 | unsafe { core::mem::transmute(val & 0x0f) } |
348 | } |
349 | #[inline (always)] |
350 | pub const fn to_bits(self) -> u8 { |
351 | unsafe { core::mem::transmute(self) } |
352 | } |
353 | } |
354 | impl From<u8> for Precision { |
355 | #[inline (always)] |
356 | fn from(val: u8) -> Precision { |
357 | Precision::from_bits(val) |
358 | } |
359 | } |
360 | impl From<Precision> for u8 { |
361 | #[inline (always)] |
362 | fn from(val: Precision) -> u8 { |
363 | Precision::to_bits(val) |
364 | } |
365 | } |
366 | #[repr (u8)] |
367 | #[derive (Copy, Clone, Debug, Eq, PartialEq, Ord, PartialOrd)] |
368 | #[cfg_attr (feature = "defmt" , derive(defmt::Format))] |
369 | pub enum Scale { |
370 | #[doc = "Argument multiplied by 1, result multiplied by 1" ] |
371 | A1_R1 = 0x0, |
372 | #[doc = "Argument multiplied by 1/2, result multiplied by 2" ] |
373 | A1O2_R2 = 0x01, |
374 | #[doc = "Argument multiplied by 1/4, result multiplied by 4" ] |
375 | A1O4_R4 = 0x02, |
376 | #[doc = "Argument multiplied by 1/8, result multiplied by 8" ] |
377 | A1O8_R8 = 0x03, |
378 | #[doc = "Argument multiplied by 1/16, result multiplied by 16" ] |
379 | A1O16_R16 = 0x04, |
380 | #[doc = "Argument multiplied by 1/32, result multiplied by 32" ] |
381 | A1O32_R32 = 0x05, |
382 | #[doc = "Argument multiplied by 1/64, result multiplied by 64" ] |
383 | A1O64_R64 = 0x06, |
384 | #[doc = "Argument multiplied by 1/128, result multiplied by 128" ] |
385 | A1O128_R128 = 0x07, |
386 | } |
387 | impl Scale { |
388 | #[inline (always)] |
389 | pub const fn from_bits(val: u8) -> Scale { |
390 | unsafe { core::mem::transmute(val & 0x07) } |
391 | } |
392 | #[inline (always)] |
393 | pub const fn to_bits(self) -> u8 { |
394 | unsafe { core::mem::transmute(self) } |
395 | } |
396 | } |
397 | impl From<u8> for Scale { |
398 | #[inline (always)] |
399 | fn from(val: u8) -> Scale { |
400 | Scale::from_bits(val) |
401 | } |
402 | } |
403 | impl From<Scale> for u8 { |
404 | #[inline (always)] |
405 | fn from(val: Scale) -> u8 { |
406 | Scale::to_bits(val) |
407 | } |
408 | } |
409 | #[repr (u8)] |
410 | #[derive (Copy, Clone, Debug, Eq, PartialEq, Ord, PartialOrd)] |
411 | #[cfg_attr (feature = "defmt" , derive(defmt::Format))] |
412 | pub enum Size { |
413 | #[doc = "Use 32 bit input/output values." ] |
414 | BITS32 = 0x0, |
415 | #[doc = "Use 16 bit input/output values." ] |
416 | BITS16 = 0x01, |
417 | } |
418 | impl Size { |
419 | #[inline (always)] |
420 | pub const fn from_bits(val: u8) -> Size { |
421 | unsafe { core::mem::transmute(val & 0x01) } |
422 | } |
423 | #[inline (always)] |
424 | pub const fn to_bits(self) -> u8 { |
425 | unsafe { core::mem::transmute(self) } |
426 | } |
427 | } |
428 | impl From<u8> for Size { |
429 | #[inline (always)] |
430 | fn from(val: u8) -> Size { |
431 | Size::from_bits(val) |
432 | } |
433 | } |
434 | impl From<Size> for u8 { |
435 | #[inline (always)] |
436 | fn from(val: Size) -> u8 { |
437 | Size::to_bits(val) |
438 | } |
439 | } |
440 | } |
441 | |