Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 2390dc4

Browse files
committed
rf233 component: replace integer with constant
and fix typo in comment
1 parent 6289b6c commit 2390dc4

File tree

2 files changed

+15
-9
lines changed

2 files changed

+15
-9
lines changed

boards/components/src/rf233.rs

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ macro_rules! rf233_component_static {
3939
capsules_core::virtualizers::virtual_spi::VirtualSpiMasterDevice<'static, $S>,
4040
>
4141
);
42-
// The RF233 radio stack requires our buffers for its SPI operations:
42+
// The RF233 radio stack requires four buffers for its SPI operations:
4343
//
4444
// 1. buf: a packet-sized buffer for SPI operations, which is
4545
// used as the read buffer when it writes a packet passed to it and the write
@@ -48,8 +48,10 @@ macro_rules! rf233_component_static {
4848
// 3 + 4: two small buffers for performing registers
4949
// operations (one read, one write).
5050
let rf233_buf = kernel::static_buf!([u8; kernel::hil::radio::MAX_BUF_SIZE]);
51-
let rf233_reg_write = kernel::static_buf!([u8; 2]);
52-
let rf233_reg_read = kernel::static_buf!([u8; 2]);
51+
let rf233_reg_write =
52+
kernel::static_buf!([u8; capsules_extra::rf233::SPI_REGISTER_TRANSACTION_LENGTH]);
53+
let rf233_reg_read =
54+
kernel::static_buf!([u8; capsules_extra::rf233::SPI_REGISTER_TRANSACTION_LENGTH]);
5355

5456
(spi_device, rf233_buf, rf233_reg_write, rf233_reg_read)
5557
};};
@@ -88,15 +90,17 @@ impl<S: SpiMaster<'static> + 'static> Component for RF233Component<S> {
8890
type StaticInput = (
8991
&'static mut MaybeUninit<RF233<'static, VirtualSpiMasterDevice<'static, S>>>,
9092
&'static mut MaybeUninit<[u8; hil::radio::MAX_BUF_SIZE]>,
91-
&'static mut MaybeUninit<[u8; 2]>,
92-
&'static mut MaybeUninit<[u8; 2]>,
93+
&'static mut MaybeUninit<[u8; capsules_extra::rf233::SPI_REGISTER_TRANSACTION_LENGTH]>,
94+
&'static mut MaybeUninit<[u8; capsules_extra::rf233::SPI_REGISTER_TRANSACTION_LENGTH]>,
9395
);
9496
type Output = &'static RF233<'static, VirtualSpiMasterDevice<'static, S>>;
9597

9698
fn finalize(self, s: Self::StaticInput) -> Self::Output {
9799
let rf233_buf = s.1.write([0; hil::radio::MAX_BUF_SIZE]);
98-
let rf233_reg_write = s.2.write([0; 2]);
99-
let rf233_reg_read = s.3.write([0; 2]);
100+
let rf233_reg_write =
101+
s.2.write([0; capsules_extra::rf233::SPI_REGISTER_TRANSACTION_LENGTH]);
102+
let rf233_reg_read =
103+
s.3.write([0; capsules_extra::rf233::SPI_REGISTER_TRANSACTION_LENGTH]);
100104
let rf233 = s.0.write(RF233::new(
101105
self.spi,
102106
rf233_buf,

capsules/extra/src/rf233.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -189,6 +189,8 @@ enum InternalState {
189189
// and waits for the interrupt specifying the entire packet has been
190190
// received.
191191

192+
pub const SPI_REGISTER_TRANSACTION_LENGTH: usize = 2;
193+
192194
pub struct RF233<'a, S: spi::SpiMasterDevice<'a>> {
193195
spi: &'a S,
194196
radio_on: Cell<bool>,
@@ -1034,8 +1036,8 @@ impl<'a, S: spi::SpiMasterDevice<'a>> RF233<'a, S> {
10341036
pub fn new(
10351037
spi: &'a S,
10361038
spi_buf: &'static mut [u8],
1037-
reg_write: &'static mut [u8; 2],
1038-
reg_read: &'static mut [u8; 2],
1039+
reg_write: &'static mut [u8; SPI_REGISTER_TRANSACTION_LENGTH],
1040+
reg_read: &'static mut [u8; SPI_REGISTER_TRANSACTION_LENGTH],
10391041
reset: &'a dyn gpio::Pin,
10401042
sleep: &'a dyn gpio::Pin,
10411043
irq: &'a dyn gpio::InterruptPin<'a>,

0 commit comments

Comments
 (0)