1#![no_std]
2#![deny(
3missing_debug_implementations,
5missing_copy_implementations,
6trivial_casts,
7trivial_numeric_casts,
8unstable_features,
9unused_import_braces,
10unused_qualifications,
11clippy::all
12)]
13#![forbid(unsafe_code)]
14
15use core::task;
16use embedded_platform::platform;
17use embedded_platform::specs;
18
19pub mod error;
20pub mod gpio;
21pub mod i2c;
22
23use nrf52840_hal::gpio as hal_gpio;
24use nrf52840_hal::gpio::p0;
25use nrf52840_hal::gpio::p1;
26
27#[derive(Debug)]
28pub struct ParticleArgon {
29 p0: gpio::P0,
30 p1: gpio::P1,
31}
32
33impl platform::Platform for ParticleArgon {
34 type Error = error::Error;
35
36 fn poll_initialize(_cx: &mut task::Context<'_>) -> task::Poll<Result<Self, Self::Error>> {
37 let peripherals = nrf52840_hal::nrf52840_pac::Peripherals::take()
38 .expect("A nrf52840 platform was already initialized");
39 let p0 = gpio::P0::new(peripherals.P0);
40 let p1 = gpio::P1::new(peripherals.P1);
41
42 task::Poll::Ready(Ok(Self { p0, p1 }))
43 }
44}
45
46impl specs::feather::Feather for ParticleArgon {
47 type MainLed = Self::D7;
48 type MainI2cMapping = i2c::I2cMapping<Self::SDA, Self::SCL>;
49
50 type SDA = gpio::Pin<p0::P0_26<hal_gpio::Input<hal_gpio::Floating>>>;
51 type SCL = gpio::Pin<p0::P0_27<hal_gpio::Input<hal_gpio::Floating>>>;
52 type D2 = gpio::Pin<p1::P1_01<hal_gpio::Input<hal_gpio::Floating>>>;
53 type D3 = gpio::Pin<p1::P1_02<hal_gpio::Input<hal_gpio::Floating>>>;
54 type D4 = gpio::Pin<p1::P1_08<hal_gpio::Input<hal_gpio::Floating>>>;
55 type D5 = gpio::Pin<p1::P1_10<hal_gpio::Input<hal_gpio::Floating>>>;
56 type D6 = gpio::Pin<p1::P1_11<hal_gpio::Input<hal_gpio::Floating>>>;
57 type D7 = gpio::Pin<p1::P1_12<hal_gpio::Input<hal_gpio::Floating>>>;
58 type D8 = gpio::Pin<p1::P1_03<hal_gpio::Input<hal_gpio::Floating>>>;
59 type P0 = gpio::Pin<p0::P0_11<hal_gpio::Input<hal_gpio::Floating>>>;
60 type TX = gpio::Pin<p0::P0_06<hal_gpio::Input<hal_gpio::Floating>>>;
61 type RX = gpio::Pin<p0::P0_08<hal_gpio::Input<hal_gpio::Floating>>>;
62 type MISO = gpio::Pin<p1::P1_14<hal_gpio::Input<hal_gpio::Floating>>>;
63 type MOSI = gpio::Pin<p1::P1_13<hal_gpio::Input<hal_gpio::Floating>>>;
64 type SCK = gpio::Pin<p1::P1_15<hal_gpio::Input<hal_gpio::Floating>>>;
65 type A5 = gpio::Pin<p0::P0_31<hal_gpio::Input<hal_gpio::Floating>>>;
66 type A4 = gpio::Pin<p0::P0_30<hal_gpio::Input<hal_gpio::Floating>>>;
67 type A3 = gpio::Pin<p0::P0_29<hal_gpio::Input<hal_gpio::Floating>>>;
68 type A2 = gpio::Pin<p0::P0_28<hal_gpio::Input<hal_gpio::Floating>>>;
69 type A1 = gpio::Pin<p0::P0_04<hal_gpio::Input<hal_gpio::Floating>>>;
70 type A0 = gpio::Pin<p0::P0_03<hal_gpio::Input<hal_gpio::Floating>>>;
71
72 fn take_main_led(&mut self) -> Self::MainLed {
73 self.p1.p1_12.take().expect("pin 1.12 is already taken")
74 }
75
76 fn take_main_i2c(
77 &mut self,
78 ) -> <Self::MainI2cMapping as embedded_platform::i2c::I2cBusMapping<Self::SDA, Self::SCL>>::Bus
79 {
80 unimplemented!()
81 }
82
83 fn take_sda(&mut self) -> Self::SDA {
84 self.p0.p0_26.take().expect("pin 0.26 is already taken")
85 }
86
87 fn take_scl(&mut self) -> Self::SCL {
88 self.p0.p0_27.take().expect("pin 0.27 is already taken")
89 }
90
91 fn take_d2(&mut self) -> Self::D2 {
92 self.p1.p1_01.take().expect("pin 1.01 is already taken")
93 }
94
95 fn take_d3(&mut self) -> Self::D3 {
96 self.p1.p1_02.take().expect("pin 1.02 is already taken")
97 }
98
99 fn take_d4(&mut self) -> Self::D4 {
100 self.p1.p1_08.take().expect("pin 1.08 is already taken")
101 }
102
103 fn take_d5(&mut self) -> Self::D5 {
104 self.p1.p1_10.take().expect("pin 1.10 is already taken")
105 }
106
107 fn take_d6(&mut self) -> Self::D6 {
108 self.p1.p1_11.take().expect("pin 1.11 is already taken")
109 }
110
111 fn take_d7(&mut self) -> Self::D7 {
112 self.p1.p1_12.take().expect("pin 1.12 is already taken")
113 }
114
115 fn take_d8(&mut self) -> Self::D8 {
116 self.p1.p1_03.take().expect("pin 1.03 is already taken")
117 }
118
119 fn take_p0(&mut self) -> Self::P0 {
120 self.p0.p0_11.take().expect("pin 0.11 is already taken")
121 }
122
123 fn take_tx(&mut self) -> Self::TX {
124 self.p0.p0_06.take().expect("pin 0.06 is already taken")
125 }
126
127 fn take_rx(&mut self) -> Self::RX {
128 self.p0.p0_08.take().expect("pin 0.08 is already taken")
129 }
130
131 fn take_miso(&mut self) -> Self::MISO {
132 self.p1.p1_14.take().expect("pin 1.14 is already taken")
133 }
134
135 fn take_mosi(&mut self) -> Self::MOSI {
136 self.p1.p1_13.take().expect("pin 1.13 is already taken")
137 }
138
139 fn take_sck(&mut self) -> Self::SCK {
140 self.p1.p1_15.take().expect("pin 1.15 is already taken")
141 }
142
143 fn take_a5(&mut self) -> Self::A5 {
144 self.p0.p0_31.take().expect("pin 0.31 is already taken")
145 }
146
147 fn take_a4(&mut self) -> Self::A4 {
148 self.p0.p0_30.take().expect("pin 0.30 is already taken")
149 }
150
151 fn take_a3(&mut self) -> Self::A3 {
152 self.p0.p0_29.take().expect("pin 0.29 is already taken")
153 }
154
155 fn take_a2(&mut self) -> Self::A2 {
156 self.p0.p0_28.take().expect("pin 0.28 is already taken")
157 }
158
159 fn take_a1(&mut self) -> Self::A1 {
160 self.p0.p0_04.take().expect("pin 0.04 is already taken")
161 }
162
163 fn take_a0(&mut self) -> Self::A0 {
164 self.p0.p0_03.take().expect("pin 0.03 is already taken")
165 }
166}