3 extern crate atsamd_hal as hal;
6 extern crate cortex_m_rt;
8 pub use cortex_m_rt::entry;
13 pub use hal::common::*;
14 pub use hal::samd21::*;
15 pub use hal::target_device as pac;
17 use gpio::{Floating, Input, PfC, Port};
18 use hal::clock::GenericClockController;
19 use hal::sercom::{I2CMaster3, PadPin, SPIMaster4, UART0};
22 #[cfg(feature = "usb")]
23 use hal::usb::usb_device::bus::UsbBusAllocator;
24 #[cfg(feature = "usb")]
25 pub use hal::usb::UsbBus;
28 /// Maps the pins to their arduino names and
29 /// the numbers printed on the board.
31 target_device: target_device,
33 /// AREF pin - has 1uF capacitor to ground
36 /// Analog pin 0. Can act as a true analog output
37 /// as it has a DAC (which is not currently supported
38 /// by this hal) as well as input.
56 /// Pin 5, PWM capable
58 /// Pin 6, PWM capable
60 /// Pin 9, PWM capable. Also analog input (A7)
62 /// Pin 10, PWM capable
64 /// Pin 11, PWM capable
66 /// Pin 12, PWM capable
68 /// Pin 13, which is also attached to
69 /// the red LED. PWM capable.
74 /// The I2C clock line
89 /// SPI chip select for the RFM module
90 #[cfg(feature = "rfm")]
93 /// Reset for the RFM module
94 #[cfg(feature = "rfm")]
97 /// Interrupt from the RFM module
98 #[cfg(feature = "rfm")]
102 #[cfg(feature = "express")]
105 /// SPI clock for the external flash
106 #[cfg(feature = "express")]
109 /// SPI MOSI for the external flash
110 #[cfg(feature = "express")]
113 /// SPI MISO for the external flash
114 #[cfg(feature = "express")]
115 pin flash_miso = a14,
117 /// SPI chip select for the external flash
118 #[cfg(feature = "express")]
122 /// Convenience for setting up the labelled SPI peripheral.
123 /// This powers up SERCOM4 and configures it for use as an
124 /// SPI Master in SPI Mode 0.
125 pub fn spi_master<F: Into<Hertz>>(
126 clocks: &mut GenericClockController,
128 sercom4: pac::SERCOM4,
130 sck: gpio::Pb11<Input<Floating>>,
131 mosi: gpio::Pb10<Input<Floating>>,
132 miso: gpio::Pa12<Input<Floating>>,
135 hal::sercom::Sercom4Pad0<gpio::Pa12<gpio::PfD>>,
136 hal::sercom::Sercom4Pad2<gpio::Pb10<gpio::PfD>>,
137 hal::sercom::Sercom4Pad3<gpio::Pb11<gpio::PfD>>,
139 let gclk0 = clocks.gclk0();
141 &clocks.sercom4_core(&gclk0).unwrap(),
143 hal::hal::spi::Mode {
144 phase: hal::hal::spi::Phase::CaptureOnFirstTransition,
145 polarity: hal::hal::spi::Polarity::IdleLow,
149 (miso.into_pad(port), mosi.into_pad(port), sck.into_pad(port)),
153 /// Convenience for setting up the labelled SDA, SCL pins to
154 /// operate as an I2C master running at the specified frequency.
155 pub fn i2c_master<F: Into<Hertz>>(
156 clocks: &mut GenericClockController,
158 sercom3: pac::SERCOM3,
160 sda: gpio::Pa22<Input<Floating>>,
161 scl: gpio::Pa23<Input<Floating>>,
164 hal::sercom::Sercom3Pad0<hal::gpio::Pa22<hal::gpio::PfC>>,
165 hal::sercom::Sercom3Pad1<hal::gpio::Pa23<hal::gpio::PfC>>,
167 let gclk0 = clocks.gclk0();
169 &clocks.sercom3_core(&gclk0).unwrap(),
178 /// Convenience for setting up the labelled RX, TX pins to
179 /// operate as a UART device running at the specified baud.
180 pub fn uart<F: Into<Hertz>>(
181 clocks: &mut GenericClockController,
183 sercom0: pac::SERCOM0,
185 d0: gpio::Pa11<Input<Floating>>,
186 d1: gpio::Pa10<Input<Floating>>,
189 hal::sercom::Sercom0Pad3<gpio::Pa11<PfC>>,
190 hal::sercom::Sercom0Pad2<gpio::Pa10<PfC>>,
194 let gclk0 = clocks.gclk0();
197 &clocks.sercom0_core(&gclk0).unwrap(),
201 (d0.into_pad(port), d1.into_pad(port)),
205 #[cfg(feature = "usb")]
206 pub fn usb_allocator(
208 clocks: &mut GenericClockController,
210 dm: gpio::Pa24<Input<Floating>>,
211 dp: gpio::Pa25<Input<Floating>>,
213 ) -> UsbBusAllocator<UsbBus> {
214 use gpio::IntoFunction;
216 let gclk0 = clocks.gclk0();
217 let usb_clock = &clocks.usb(&gclk0).unwrap();
219 UsbBusAllocator::new(UsbBus::new(
222 dm.into_function(port),
223 dp.into_function(port),