1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
extern crate bluetooth_hci as hci;
extern crate byteorder;
extern crate embedded_hal as hal;
extern crate nb;
use byteorder::{ByteOrder, LittleEndian};
use hci::types::{ConnectionInterval, ExpectedConnectionLength};
pub trait Commands {
type Error;
fn connection_parameter_update_request(
&mut self,
params: &ConnectionParameterUpdateRequest,
) -> nb::Result<(), Self::Error>;
fn connection_parameter_update_response(
&mut self,
params: &ConnectionParameterUpdateResponse,
) -> nb::Result<(), Self::Error>;
}
impl<'bnrg, 'spi, 'dbuf, SPI, OutputPin1, OutputPin2, InputPin, SpiError, GpioError> Commands
for crate::ActiveBlueNRG<'bnrg, 'spi, 'dbuf, SPI, OutputPin1, OutputPin2, InputPin, GpioError>
where
SPI: hal::blocking::spi::Transfer<u8, Error = SpiError>
+ hal::blocking::spi::Write<u8, Error = SpiError>,
OutputPin1: hal::digital::v2::OutputPin<Error = GpioError>,
OutputPin2: hal::digital::v2::OutputPin<Error = GpioError>,
InputPin: hal::digital::v2::InputPin<Error = GpioError>,
{
type Error = crate::Error<SpiError, GpioError>;
impl_params!(
connection_parameter_update_request,
ConnectionParameterUpdateRequest,
crate::opcode::L2CAP_CONN_PARAM_UPDATE_REQ
);
impl_params!(
connection_parameter_update_response,
ConnectionParameterUpdateResponse,
crate::opcode::L2CAP_CONN_PARAM_UPDATE_RESP
);
}
pub struct ConnectionParameterUpdateRequest {
pub conn_handle: hci::ConnectionHandle,
pub conn_interval: ConnectionInterval,
}
impl ConnectionParameterUpdateRequest {
const LENGTH: usize = 10;
fn copy_into_slice(&self, bytes: &mut [u8]) {
assert_eq!(bytes.len(), Self::LENGTH);
LittleEndian::write_u16(&mut bytes[0..], self.conn_handle.0);
self.conn_interval.copy_into_slice(&mut bytes[2..10]);
}
}
pub struct ConnectionParameterUpdateResponse {
pub conn_handle: hci::ConnectionHandle,
pub conn_interval: ConnectionInterval,
pub expected_connection_length_range: ExpectedConnectionLength,
pub identifier: u8,
pub accepted: bool,
}
impl ConnectionParameterUpdateResponse {
const LENGTH: usize = 16;
fn copy_into_slice(&self, bytes: &mut [u8]) {
assert_eq!(bytes.len(), Self::LENGTH);
LittleEndian::write_u16(&mut bytes[0..], self.conn_handle.0);
self.conn_interval.copy_into_slice(&mut bytes[2..10]);
self.expected_connection_length_range
.copy_into_slice(&mut bytes[10..14]);
bytes[14] = self.identifier;
bytes[15] = self.accepted as u8;
}
}