rustuino/
include.rs

1//! Contains all pinmaps for pinmode and init functions and error enums.
2
3use pins::*;
4
5#[doc(hidden)]
6pub static mut PIN_CONF: heapless::Vec<(char, u8), 50> = heapless::Vec::new();
7
8/// Pin aliases for function parameters. Use with pinmode- and init functions.
9pub mod pins {
10  macro_rules! generate_pins {
11    ($([$block:literal, $pin:literal]),+) => {
12      use paste::paste;
13
14      paste!{
15        $(
16          pub const [<$block:upper $pin>]: (char, u8) = ($block, $pin);
17        )+
18      }
19    };
20  }
21
22  generate_pins![
23    ['a', 0],
24    ['a', 1],
25    ['a', 2],
26    ['a', 3],
27    ['a', 4],
28    ['a', 5],
29    ['a', 6],
30    ['a', 7],
31    ['a', 8],
32    ['a', 9],
33    ['a', 10],
34    ['a', 11],
35    ['a', 12],
36    ['a', 13],
37    ['a', 14],
38    ['a', 15],
39
40    ['b', 0],
41    ['b', 1],
42    ['b', 2],
43    ['b', 3],
44    ['b', 4],
45    ['b', 5],
46    ['b', 6],
47    ['b', 7],
48    ['b', 8],
49    ['b', 9],
50    ['b', 10],
51    ['b', 11],
52    ['b', 12],
53    ['b', 13],
54    ['b', 14],
55    ['b', 15],
56
57    ['c', 0],
58    ['c', 1],
59    ['c', 2],
60    ['c', 3],
61    ['c', 4],
62    ['c', 5],
63    ['c', 6],
64    ['c', 7],
65    ['c', 8],
66    ['c', 9],
67    ['c', 10],
68    ['c', 11],
69    ['c', 12],
70    ['c', 13],
71    ['c', 14],
72    ['c', 15],
73
74    ['d', 2],
75
76    ['h', 0],
77    ['h', 1]
78  ];
79}
80
81
82#[doc(hidden)]
83pub struct ADCMap {
84  pub pins: [(char, u8); 16],
85  pub adcs: [u8; 16],
86  pub channels: [u8; 16]
87}
88
89/// Pinmap of the available analog inputs and outputs.
90/// 
91/// These pins are available for [pinmode_analog()](crate::gpio::pinmode_analog) as an analog input over the internal ADC.
92/// 
93/// ## WARNING:
94/// 
95/// Whitch ADC and channel the pin uses is not important for normal use, but if you intent to use one of these ADCs manually while the pin is configured, normal function of the pin is not guaranteed!
96/// 
97/// | Pin | Channel | ADCs      |
98/// | --- | ------- | --------- |
99/// | PA0 | 0       | 1, 2, 3   |
100/// | PA1 | 1       | 1, 2, 3   |
101/// | PA2 | 2       | 1, 2, 3   |
102/// | PA3 | 3       | 1, 2, 3   |
103/// | PA4 | 1       | 1, 2, DAC |
104/// | PA5 | 2       | 1, 2, DAC |
105/// | PA6 | 6       | 1, 2      |
106/// | PA7 | 7       | 1, 2      |
107/// | PB0 | 8       | 1, 2      |
108/// | PB1 | 9       | 1, 2      |
109/// | PC0 | 10      | 1, 2, 3   |
110/// | PC1 | 11      | 1, 2, 3   |
111/// | PC2 | 12      | 1, 2, 3   |
112/// | PC3 | 13      | 1, 2, 3   |
113/// | PC4 | 14      | 1, 2      |
114/// | PC5 | 15      | 1, 2      |
115pub const ADC_MAP: ADCMap = ADCMap {
116  pins:     [A0, A1, A2, A3, A4, A5, A6, A7, B0, B1, C0, C1, C2, C3, C4, C5],
117  adcs:     [1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1,  1],
118  channels: [0,  1,  2,  3,  4,  5,  6,  7,  8,  9,  10, 11, 12, 13, 14, 15]
119};
120
121#[doc(hidden)]
122pub struct PWMMap {
123  pub pins: [(char, u8); 27],
124  pub timers: [u8; 27],
125  pub ccchs: [u8; 27]
126}
127
128/// Pinmap of the available PWM outputs.
129/// 
130/// In [`pinmode_pwm()`](crate::gpio::pinmode_pwm) these pins are available for PWM output. You see that some channels of timer 2 and 3 are used for multiple pins. If you configure both pin of the same channel, the output on both pin will be the same, regardless of whitch pin you modify.
131/// 
132/// ## WARNING:
133/// 
134/// Whitch timer and channel the pin uses is not important for normal use, but if you intent to use one of these timers for other purposes, be aware that modifying the values of the timer could lead to a broken PWM signal.
135/// 
136/// | Timer | Pin                          | Channel          |
137/// | ----- | ---------------------------- | ---------------- |
138/// | 1     | PA8, PA9, PA10, PA11         | 1, 2, 3, 4       |
139/// | 2     | PA0, PA1, PA2, PA3           | 1, 2, 3, 4       |
140/// | 2     | PA15, PB2, PB3, PB10, PB11   | 1, 1, 4, 2, 3, 4 |
141/// | 3     | PA6, PA7, PB0, PB1           | 1, 2, 3, 4       |
142/// | 3     | PB4, PB5, PC6, PC7, PC8, PC9 | 1, 2, 1, 2, 3, 4 |
143/// | 4     | PB6, PB7, PB8, PB9           | 1, 2, 3, 4       |
144pub const PWM_MAP: PWMMap = PWMMap {
145  pins:   [A8, A9, A10, A11, A0, A1, A2, A3, A15, B2, B3, B10, B11, A6, A7, B0, B1, B4, B5, C6, C7, C8, C9, B6, B7, B8, B9],
146  timers: [1,  1,  1,   1,   2,  2,  2,  2,  2,   2,  2,  2,   2,   3,  3,  3,  3,  3,  3,  3,  3,  3,  3,  4,  4,  4,  4],
147  ccchs:  [1,  2,  3,   4,   1,  2,  3,  4,  1,   4,  2,  3,   4,   1,  2,  3,  4,  1,  2,  1,  2,  3,  4,  1,  2,  3,  4]
148};
149
150#[doc(hidden)]
151pub struct UARTMap {
152  pub tx_pins: [(char, u8); 16],
153  pub rx_pins: [(char, u8); 16],
154  pub cores: [u8; 16]
155}
156
157/// Pinmap for the UART peripheral.
158/// 
159/// In [`UART::new()`](crate::uart::UART::new) choose the desired peripheral and a combination of available pins for it. Here are the available pins for each core:
160/// 
161/// | UART Core      | TX Pins    | RX Pins         |
162/// | -------------- | ---------- | --------------- |
163/// | 1              | PA9, PB6   | PA10, PB7       |
164/// | 2 (USB Serial) | PA2        | PA3             |
165/// | 3              | PB10, PC10 | PB11, PC5, PC11 |
166/// | 4              | PA0, PC10  | PA1, PC11       |
167/// | 5              | PC12       | PD2             |
168/// | 6              | PC6        | PC7             |
169pub const UART_MAP: UARTMap = UARTMap {
170  tx_pins: [A9,  A9, B6,  B6, B10, B10, B10, C10, C10, C10, A0, A0,  C10, C10, C12, C6],
171  rx_pins: [A10, B7, A10, B7, B11, C5,  C11, B11, C5,  C11, A1, C11, A1,  C11, D2,  C7],
172  cores:   [1,   1,  1,   1,  3,   3,   3,   3,   3,   3,   4,  4,   4,   4,   5,   6]
173};
174
175#[doc(hidden)]
176pub struct I2CMap {
177  pub scl_pins: [(char, u8); 9],
178  pub sda_pins: [(char, u8); 9],
179  pub cores: [u8; 9]
180}
181
182/// Pinmap for the I2C peripheral.
183/// 
184/// In [`I2C::new()`](crate::i2c::I2C::new) choose the desired peripheral and a combination of available pins for it. Here are the available pins for each core:
185/// 
186/// | I2C Core | SCL Pins | SDA Pins        |
187/// | -------- | -------- | --------------- |
188/// | I2C1     | PB6, PB8 | PB7, PB9        |
189/// | I2C2     | PB10     | PB3, PB11, PC12 |
190/// | I2C3     | PA8      | PB4, PC3        |
191pub const I2C_MAP: I2CMap = I2CMap {
192  scl_pins: [B6, B6, B8, B8, B10, B10, B10, A8, A8],
193  sda_pins: [B7, B9, B7, B9, B3,  B11, C12, B4, C3],
194  cores:    [1,  1,  1,  1,  2,   2,   2,   3,  3]
195};
196
197#[doc(hidden)]
198pub struct SPIData {
199  pub s1_sck: [(char, u8); 2],
200  pub s2_sck: [(char, u8); 4],
201  pub s3_sck: [(char, u8); 2],
202  pub s1_miso: [(char, u8); 2],
203  pub s2_miso: [(char, u8); 2],
204  pub s3_miso: [(char, u8); 2],
205  pub s1_mosi: [(char, u8); 2],
206  pub s2_mosi: [(char, u8); 2],
207  pub s3_mosi: [(char, u8); 2],
208}
209
210/// Pinmap for the SPI peripheral.
211/// 
212/// In SPI::new() choose the desired peripheral and a combination of available pins for it. Here are the available pins for each core:
213/// 
214/// | Core | SCK Pins             | MISO Pins | MOSI Pins |
215/// | ---- | -------------------- | --------- | --------- |
216/// | 1    | PA5, PB3             | PA6, PB4  | PA7, PB5  |
217/// | 2    | PA9, PB10, PB13, PC7 | PB14, PC2 | PB15, PC3 |
218/// | 3    | PB3, PC10            | PB4, PC11 | PB5, PC12 |
219pub const SPI_DATA: SPIData = SPIData {
220  s1_sck: [A5, B3],
221  s2_sck: [A9, B10, B13, C7],
222  s3_sck: [B3,C10],
223  s1_miso: [A6, B4],
224  s2_miso: [B14, C2],
225  s3_miso: [B4, C11],
226  s1_mosi: [A7, B5],
227  s2_mosi: [B15, C3],
228  s3_mosi: [B5, C12]
229};
230
231
232/// A universal implementation specific error.
233///
234/// These error kinds can be used to signal implementation specific errors unrelated to the
235/// specific peripheral. This will be used for all sorts of connectivity and configuraton problems.
236/// 
237/// All of the enums in this crate are marked as `#[non_exhaustive]` to allow for additions of new
238/// error kinds without requiring a breaking change and version bump.
239#[derive(Debug, Clone, PartialEq, Eq)]
240#[non_exhaustive]
241pub enum ProgError {
242  /// Unspecified internal driver error
243  Internal,
244  /// Ran out of memory while trying to allocate required buffers
245  OutOfMemory,
246  /// Operation timed out, please retry
247  TimedOut,
248  /// The peripheral cannot work with the specified settings
249  InvalidConfiguration,
250  /// Tried to use peripheral without configuring it properly
251  NotConfigured,
252  /// Tried to setup a peripheral that is already configured
253  AlreadyConfigured,
254  /// Invalid action
255  PermissionDenied
256}
257
258/// A GPIO (General input/output) specific error.
259///
260/// This error type contains errors specific to GPIO peripherals. Also it has an "Prog" kind to
261/// pass through implementation specific errors occuring while trying to use a GPIO peripheral.
262#[derive(Debug, Clone, PartialEq, Eq)]
263#[non_exhaustive]
264pub enum GpioError {
265  /// The peripheral is in the wrong operational mode for the intended operation
266  WrongMode,
267  /// Implementation specific error (shared across all peripheral specific error kinds)
268  Prog(ProgError)
269}
270
271/// A Serial specific error.
272///
273/// This error type contains errors specific to Serial peripherals. Also it has an "Prog" kind to pass
274/// through implementation specific errors occurring while trying to use a Serial peripheral.
275#[derive(Debug, Clone, PartialEq, Eq)]
276#[non_exhaustive]
277pub enum SerialError {
278  /// The peripheral receive buffer was overrun.
279  Overrun,
280  /// Received data does not conform to the peripheral configuration.
281  /// Can be caused by a misconfigured device on either end of the serial line.
282  FrameFormat,
283  /// Parity check failed.
284  Parity,
285  /// Serial line is too noisy to read valid data.
286  Noise,
287  /// Implementation specific error (shared across all peripheral specific error kinds).
288  Prog(ProgError)
289}
290
291/// An I2C specific error.
292///
293/// This error type contains errors specific to I2C peripherals. Also it has an "Prog" kind to pass
294/// through implementation specific errors occurring while trying to use an I2C peripheral.
295#[derive(Debug, Clone, PartialEq, Eq)]
296#[non_exhaustive]
297pub enum I2cError {
298  /// An unspecific bus error occured
299  Bus,
300  /// The arbitration was lost, e.g. electrical problems with the clock signal
301  ArbitrationLoss,
302  /// A bus operation received a NACK, e.g. due to the addressed device not being available on
303  /// the bus or device not being ready to process any requests at the moment
304  NACK,
305  /// The peripheral receive buffer was overrun or ran out of data
306  OverrunUnderrun,
307  /// Parity check failed.
308  Parity,
309  /// Implementation specific error (shared across all peripheral specific error kinds)
310  Prog(ProgError)
311}
312
313/// A SPI specific error.
314///
315/// This error type contains errors specific to SPI peripherals. Also it has an "Prog" kind to pass
316/// through implementation specific errors occuring while trying to use a SPI peripheral.
317#[derive(Debug, Clone, PartialEq, Eq)]
318#[non_exhaustive]
319pub enum SpiError {
320  /// The peripheral receive buffer was overrun
321  Overrun,
322  /// Multiple devices on the SPI bus are trying across each other, e.g. in a multi-master setup
323  ModeFault,
324  /// CRC does not match the received data
325  CRCError,
326  /// Implementation specific error (shared across all peripheral specific error kinds)
327  Prog(ProgError)
328}