|
3 | 3 | use super::ExtendedCapability;
|
4 | 4 | use accessor::Mapper;
|
5 | 5 | use accessor::Single;
|
6 |
| -use bit_field::BitField; |
7 |
| -use core::convert::TryInto; |
8 | 6 |
|
9 | 7 | /// HCI Extended Power Management Capability.
|
10 |
| -#[derive(Copy, Clone)] |
11 |
| -#[repr(transparent)] |
12 |
| -pub struct HciExtendedPowerManagement([u32; 2]); |
13 |
| -impl HciExtendedPowerManagement { |
14 |
| - /// Returns the value of the `PME_Support` field. |
15 |
| - #[must_use] |
16 |
| - pub fn pme_support(self) -> u8 { |
17 |
| - self.0[0].get_bits(27..=31).try_into().unwrap() |
18 |
| - } |
19 |
| - |
20 |
| - /// Returns the `D2_Support` bit. |
21 |
| - #[must_use] |
22 |
| - pub fn d2_support(self) -> bool { |
23 |
| - self.0[0].get_bit(26) |
24 |
| - } |
25 |
| - |
26 |
| - /// Returns the `D1_Support` bit. |
27 |
| - #[must_use] |
28 |
| - pub fn d1_support(self) -> bool { |
29 |
| - self.0[0].get_bit(25) |
30 |
| - } |
31 |
| - |
32 |
| - /// Returns the value of the `Aux_Current` field. |
33 |
| - #[must_use] |
34 |
| - pub fn aux_current(self) -> u8 { |
35 |
| - self.0[0].get_bits(22..=24).try_into().unwrap() |
36 |
| - } |
37 |
| - |
38 |
| - /// Returns the DSI bit. |
39 |
| - #[must_use] |
40 |
| - pub fn dsi(self) -> bool { |
41 |
| - self.0[0].get_bit(21) |
42 |
| - } |
43 |
| - |
44 |
| - /// Returns the PME Clock bit. |
45 |
| - #[must_use] |
46 |
| - pub fn pme_clock(self) -> bool { |
47 |
| - self.0[0].get_bit(19) |
48 |
| - } |
49 |
| - |
50 |
| - /// Returns the value of the Version field. |
51 |
| - #[must_use] |
52 |
| - pub fn version(self) -> u8 { |
53 |
| - self.0[0].get_bits(16..=18).try_into().unwrap() |
54 |
| - } |
55 |
| - |
56 |
| - /// Returns the `PME_Status` bit. |
57 |
| - #[must_use] |
58 |
| - pub fn pme_status(self) -> bool { |
59 |
| - self.0[1].get_bit(15) |
60 |
| - } |
61 |
| - |
62 |
| - /// Clears the `PME_Status` bit. |
63 |
| - pub fn clear_pme_status(&mut self) { |
64 |
| - self.0[1].set_bit(15, true); |
65 |
| - } |
66 |
| - |
67 |
| - /// Returns the value of the `Data_Scale` field. |
68 |
| - #[must_use] |
69 |
| - pub fn data_scale(self) -> u8 { |
70 |
| - self.0[1].get_bits(13..=14).try_into().unwrap() |
71 |
| - } |
72 |
| - |
73 |
| - /// Returns the value of the `Data_Select` field. |
74 |
| - #[must_use] |
75 |
| - pub fn data_select(self) -> u8 { |
76 |
| - self.0[1].get_bits(9..=12).try_into().unwrap() |
77 |
| - } |
78 |
| - |
79 |
| - /// Sets the value of the `Data_Select` field. |
80 |
| - pub fn set_data_select(&mut self, data_select: u8) { |
81 |
| - self.0[1].set_bits(9..=12, data_select.into()); |
82 |
| - } |
83 |
| - |
84 |
| - /// Returns the `PME_En` bit. |
85 |
| - #[must_use] |
86 |
| - pub fn pme_en(self) -> bool { |
87 |
| - self.0[1].get_bit(8) |
88 |
| - } |
89 |
| - |
90 |
| - /// Sets the `PME_En` bit. |
91 |
| - pub fn set_pme_en(&mut self) { |
92 |
| - self.0[1].set_bit(8, true); |
93 |
| - } |
94 |
| - |
95 |
| - /// Clears the `PME_En` bit. |
96 |
| - pub fn clear_pme_en(&mut self) { |
97 |
| - self.0[1].set_bit(8, false); |
98 |
| - } |
99 |
| - |
100 |
| - /// Returns the value of the `PowerState` field. |
101 |
| - #[must_use] |
102 |
| - pub fn power_state(self) -> u8 { |
103 |
| - self.0[1].get_bits(0..=1).try_into().unwrap() |
104 |
| - } |
105 |
| - |
106 |
| - /// Sets the value of the `PowerState` field. |
107 |
| - pub fn set_power_state(&mut self, s: u8) { |
108 |
| - self.0[1].set_bits(0..=1, s.into()); |
109 |
| - } |
110 |
| - |
111 |
| - /// Returns the `BPCC_En` bit. |
112 |
| - #[must_use] |
113 |
| - pub fn bpcc_en(self) -> bool { |
114 |
| - self.0[1].get_bit(23) |
115 |
| - } |
116 |
| - |
117 |
| - /// Returns the `B2_B3` bit. |
118 |
| - #[must_use] |
119 |
| - pub fn b2_b3(self) -> bool { |
120 |
| - self.0[1].get_bit(22) |
| 8 | +#[derive(Copy, Clone, Debug)] |
| 9 | +#[repr(C)] |
| 10 | +pub struct HciExtendedPowerManagement { |
| 11 | + _id: u8, |
| 12 | + _next: u8, |
| 13 | + /// Power Management Capabilities. |
| 14 | + pub pmc: PowerManagementCapabilities, |
| 15 | + /// Power Management Control Status Register. |
| 16 | + pub pmcsr: PowerManagementControlStatusRegister, |
| 17 | + /// PMESR_BSE. |
| 18 | + pub pmcsr_bse: PmesrBse, |
| 19 | + /// Data. |
| 20 | + pub data: Data, |
| 21 | +} |
| 22 | +impl<M> From<Single<HciExtendedPowerManagement, M>> for ExtendedCapability<M> |
| 23 | +where |
| 24 | + M: Mapper + Clone, |
| 25 | +{ |
| 26 | + fn from(h: Single<HciExtendedPowerManagement, M>) -> Self { |
| 27 | + ExtendedCapability::HciExtendedPowerManagementCapability(h) |
121 | 28 | }
|
| 29 | +} |
122 | 30 |
|
123 |
| - /// Returns the Data field. |
124 |
| - #[must_use] |
125 |
| - pub fn data(self) -> u8 { |
126 |
| - self.0[1].get_bits(24..=31).try_into().unwrap() |
127 |
| - } |
| 31 | +/// Power Management Capabilities. |
| 32 | +#[repr(transparent)] |
| 33 | +#[derive(Copy, Clone)] |
| 34 | +pub struct PowerManagementCapabilities(u16); |
| 35 | +impl PowerManagementCapabilities { |
| 36 | + ro_field!(11..=15, pme_support, "PME_Support", u8); |
| 37 | + ro_bit!(10, d2_support, "D2_Support"); |
| 38 | + ro_bit!(9, d1_support, "D1_Support"); |
| 39 | + ro_field!(6..=8, aux_current, "Aux_Current", u8); |
| 40 | + ro_bit!(5, dsi, "DSI"); |
| 41 | + ro_bit!(3, pme_clock, "PME Clock"); |
| 42 | + ro_field!(0..=2, version, "Version", u8); |
128 | 43 | }
|
129 | 44 | impl_debug_from_methods! {
|
130 |
| - HciExtendedPowerManagement { |
| 45 | + PowerManagementCapabilities { |
131 | 46 | pme_support,
|
132 | 47 | d2_support,
|
133 | 48 | d1_support,
|
134 | 49 | aux_current,
|
135 | 50 | dsi,
|
136 | 51 | pme_clock,
|
137 | 52 | version,
|
| 53 | + } |
| 54 | +} |
| 55 | + |
| 56 | +/// Power Management Control/Status Register. |
| 57 | +#[repr(transparent)] |
| 58 | +#[derive(Copy, Clone)] |
| 59 | +pub struct PowerManagementControlStatusRegister(u16); |
| 60 | +impl PowerManagementControlStatusRegister { |
| 61 | + rw1c_bit!(15, pme_status, "PME_Status"); |
| 62 | + ro_field!(13..=14, data_scale, "Data_Scale", u8); |
| 63 | + rw_field!(9..=12, data_select, "Data_Select", u8); |
| 64 | + rw_bit!(8, pme_en, "PME_En"); |
| 65 | + rw_field!(0..=1, power_state, "PowerState", u8); |
| 66 | +} |
| 67 | +impl_debug_from_methods! { |
| 68 | + PowerManagementControlStatusRegister { |
138 | 69 | pme_status,
|
139 | 70 | data_scale,
|
140 | 71 | data_select,
|
141 | 72 | pme_en,
|
142 | 73 | power_state,
|
| 74 | + } |
| 75 | +} |
| 76 | + |
| 77 | +/// `PMESR_BSE` Register. |
| 78 | +#[repr(transparent)] |
| 79 | +#[derive(Copy, Clone)] |
| 80 | +pub struct PmesrBse(u8); |
| 81 | +impl PmesrBse { |
| 82 | + ro_bit!(7, bpcc_en, "BPCC_En"); |
| 83 | + ro_bit!(6, b2_b3, "B2_B3"); |
| 84 | +} |
| 85 | +impl_debug_from_methods! { |
| 86 | + PmesrBse { |
143 | 87 | bpcc_en,
|
144 | 88 | b2_b3,
|
145 |
| - data, |
146 | 89 | }
|
147 | 90 | }
|
148 |
| -impl<M> From<Single<HciExtendedPowerManagement, M>> for ExtendedCapability<M> |
149 |
| -where |
150 |
| - M: Mapper + Clone, |
151 |
| -{ |
152 |
| - fn from(h: Single<HciExtendedPowerManagement, M>) -> Self { |
153 |
| - ExtendedCapability::HciExtendedPowerManagementCapability(h) |
| 91 | + |
| 92 | +/// Data. |
| 93 | +#[repr(transparent)] |
| 94 | +#[derive(Copy, Clone, Debug)] |
| 95 | +pub struct Data(u8); |
| 96 | +impl Data { |
| 97 | + /// Returns the wrapped data. |
| 98 | + #[must_use] |
| 99 | + pub fn get(self) -> u8 { |
| 100 | + self.0 |
154 | 101 | }
|
155 | 102 | }
|
0 commit comments