1#![no_std]
2
3pub mod sent;
6
7#[derive(Clone, Copy)]
8pub struct SettingDMA {
9 pub add_periph: u32,
10 pub add_mem: u32,
11 pub nb_data: u16,
12}
13
14impl SettingDMA {
15 pub fn new() -> Self {
16 Self {
17 add_periph: 0x4000043C,
18 add_mem: 0x20000200,
19 nb_data: 0x13,
20 }
21 }
22}
23
24#[derive(Clone, Copy)]
25pub struct SettingClock {
26 pub freq: f32,
27 pub period: f32,
28}
29
30impl SettingClock {
31 pub fn new() -> Self {
32 let f: f32 = 8.0;
33 Self {
34 freq: f,
35 period: 1.0 / f,
36 }
37 }
38}
39
40#[derive(Debug)]
41pub struct Sent<DELAY, PIN> {
42 pub delay: DELAY,
43 pub pin: PIN,
44 pub t_frame: u32,
45 pub t_tick: u32,
46 pub t_sync: u32,
47 pub t_offset: u32,
48 pub nb_nibbles: u32,
49}
50
51impl<DELAY, PIN> Sent<DELAY, PIN> {
52 pub fn new(
53 delay: DELAY,
54 pin: PIN,
55 t_frame: u32,
56 t_tick: u32,
57 t_sync: u32,
58 t_offset: u32,
59 nb_nibbles: u32,
60 ) -> Self {
61 Self {
62 delay,
63 pin,
64 t_frame,
65 t_tick,
66 t_sync,
67 t_offset,
68 nb_nibbles,
69 }
70 }
71
72 pub fn new_default(delay: DELAY, pin: PIN) -> Self {
73 Self::new(delay, pin, 5000, 15, 56 * 15, 12 * 15, 6)
74 }
75}
76
77pub fn calcul_checksum(status: &u8, data: &[u8; 6]) -> u8 {
78 let crc_data: u8 = status + data.iter().sum::<u8>();
79
80 0xF - (crc_data & 0xF)
81}