1 | /// Peripheral state |
2 | #[cfg_attr (feature = "defmt" , derive(defmt::Format))] |
3 | #[derive (PartialEq, Clone, Copy)] |
4 | pub enum State { |
5 | /// Peripheral is being setup or reconfigured |
6 | Reset, |
7 | /// Ready to start acquisition |
8 | Ready, |
9 | /// In process of sensor acquisition |
10 | Busy, |
11 | /// Error occured during acquisition |
12 | Error, |
13 | } |
14 | |
15 | /// Individual group status checked after acquisition reported as complete |
16 | /// For groups with multiple channel pins, may take longer because acquisitions |
17 | /// are done sequentially. Check this status before pulling count for each |
18 | /// sampled channel |
19 | #[cfg_attr (feature = "defmt" , derive(defmt::Format))] |
20 | #[derive (PartialEq, Clone, Copy)] |
21 | pub enum GroupStatus { |
22 | /// Acquisition for channel still in progress |
23 | Ongoing, |
24 | /// Acquisition either not started or complete |
25 | Complete, |
26 | } |
27 | |
28 | /// Group identifier used to interrogate status |
29 | #[cfg_attr (feature = "defmt" , derive(defmt::Format))] |
30 | #[allow (missing_docs)] |
31 | #[derive (PartialEq, Clone, Copy)] |
32 | pub enum Group { |
33 | One, |
34 | Two, |
35 | Three, |
36 | Four, |
37 | Five, |
38 | Six, |
39 | #[cfg (any(tsc_v2, tsc_v3))] |
40 | Seven, |
41 | #[cfg (tsc_v3)] |
42 | Eight, |
43 | } |
44 | |
45 | impl Into<usize> for Group { |
46 | fn into(self) -> usize { |
47 | match self { |
48 | Group::One => 0, |
49 | Group::Two => 1, |
50 | Group::Three => 2, |
51 | Group::Four => 3, |
52 | Group::Five => 4, |
53 | Group::Six => 5, |
54 | #[cfg (any(tsc_v2, tsc_v3))] |
55 | Group::Seven => 6, |
56 | #[cfg (tsc_v3)] |
57 | Group::Eight => 7, |
58 | } |
59 | } |
60 | } |
61 | |
62 | /// Error returned when attempting to create a Group from an invalid numeric value. |
63 | #[derive (Debug, Clone, Copy, PartialEq, Eq)] |
64 | pub struct InvalidGroupError { |
65 | invalid_value: usize, |
66 | } |
67 | |
68 | impl InvalidGroupError { |
69 | #[allow (missing_docs)] |
70 | pub fn new(value: usize) -> Self { |
71 | Self { invalid_value: value } |
72 | } |
73 | } |
74 | |
75 | impl TryFrom<usize> for Group { |
76 | type Error = InvalidGroupError; |
77 | |
78 | fn try_from(value: usize) -> Result<Self, Self::Error> { |
79 | match value { |
80 | 0 => Ok(Group::One), |
81 | 1 => Ok(Group::Two), |
82 | 2 => Ok(Group::Three), |
83 | 3 => Ok(Group::Four), |
84 | 4 => Ok(Group::Five), |
85 | 5 => Ok(Group::Six), |
86 | #[cfg (any(tsc_v2, tsc_v3))] |
87 | 6 => Ok(Group::Two), |
88 | #[cfg (tsc_v3)] |
89 | 7 => Ok(Group::Two), |
90 | n: usize => Err(InvalidGroupError::new(n)), |
91 | } |
92 | } |
93 | } |
94 | |