Skip to content

Commit 69e5262

Browse files
authored
chore: rewrite HciExtendedPowerManagement (#113)
* chore: rewrite `HciExtendedPowerManagement` To define members. * chore: add a changelog
1 parent 7dac481 commit 69e5262

File tree

2 files changed

+74
-126
lines changed

2 files changed

+74
-126
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
- `set_xxx(true_or_false)` methods of the Registers and the Extended Capabilities are split into `set_xxx()` and `clear_xxx()`.
99
- `CapabilityParameters1::max_primary_stream_array_size` is renamed to `CapabilityParameters1::maximum_primary_stream_array_size`.
1010
- Bit setter and clearer now return mutable references to `Self`.
11+
- `extended_capabilities::HciExtendedPowerManagement` is rewritten so that it contains members.
1112

1213
## 0.6.0 - 2021-04-27
1314
### Added

src/extended_capabilities/hci_extended_power_management.rs

Lines changed: 73 additions & 126 deletions
Original file line numberDiff line numberDiff line change
@@ -3,153 +3,100 @@
33
use super::ExtendedCapability;
44
use accessor::Mapper;
55
use accessor::Single;
6-
use bit_field::BitField;
7-
use core::convert::TryInto;
86

97
/// 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)
12128
}
29+
}
12230

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);
12843
}
12944
impl_debug_from_methods! {
130-
HciExtendedPowerManagement {
45+
PowerManagementCapabilities {
13146
pme_support,
13247
d2_support,
13348
d1_support,
13449
aux_current,
13550
dsi,
13651
pme_clock,
13752
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 {
13869
pme_status,
13970
data_scale,
14071
data_select,
14172
pme_en,
14273
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 {
14387
bpcc_en,
14488
b2_b3,
145-
data,
14689
}
14790
}
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
154101
}
155102
}

0 commit comments

Comments
 (0)