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
#![no_std]
extern crate atsamd_hal as hal;
#[cfg(feature = "rt")]
extern crate cortex_m_rt;
#[cfg(feature = "rt")]
pub use cortex_m_rt::entry;
use hal::prelude::*;
use hal::*;
pub use hal::target_device as pac;
pub use hal::common::*;
pub use hal::samd21::*;
use gpio::{Floating, Input, PfD, Port};
use hal::clock::GenericClockController;
use hal::sercom::{I2CMaster2, PadPin, UART0};
use hal::time::Hertz;
define_pins!(
struct Pins,
target_device: target_device,
pin d0 = a8,
pin d1 = a2,
pin d2 = a9,
pin d3 = a7,
pin d4 = a6,
pin d13 = a10,
pin dotstar_ci = a1,
pin dotstar_di = a0,
pin swdio = a31,
pin swdclk = a30,
pin usb_host_enable = a28,
pin usb_sof = a23,
pin usb_dm = a24,
pin usb_dp = a25,
);
pub fn uart<F: Into<Hertz>>(
clocks: &mut GenericClockController,
baud: F,
sercom0: pac::SERCOM0,
pm: &mut pac::PM,
d3: gpio::Pa7<Input<Floating>>,
d4: gpio::Pa6<Input<Floating>>,
port: &mut Port,
) -> UART0<hal::sercom::Sercom0Pad3<gpio::Pa7<PfD>>, hal::sercom::Sercom0Pad2<gpio::Pa6<PfD>>, (), ()>
{
let gclk0 = clocks.gclk0();
UART0::new(
&clocks.sercom0_core(&gclk0).unwrap(),
baud.into(),
sercom0,
pm,
(d3.into_pad(port), d4.into_pad(port)),
)
}
pub fn i2c_master<F: Into<Hertz>>(
clocks: &mut GenericClockController,
bus_speed: F,
sercom2: pac::SERCOM2,
pm: &mut pac::PM,
sda: gpio::Pa8<Input<Floating>>,
scl: gpio::Pa9<Input<Floating>>,
port: &mut Port,
) -> I2CMaster2<
hal::sercom::Sercom2Pad0<gpio::Pa8<gpio::PfD>>,
hal::sercom::Sercom2Pad1<gpio::Pa9<gpio::PfD>>,
> {
let gclk0 = clocks.gclk0();
I2CMaster2::new(
&clocks.sercom2_core(&gclk0).unwrap(),
bus_speed.into(),
sercom2,
pm,
sda.into_pad(port),
scl.into_pad(port),
)
}