-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathWireMaster_FeatherM0.hpp
101 lines (88 loc) · 3.49 KB
/
WireMaster_FeatherM0.hpp
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
#pragma once
//
// (c)2018 by Lucky Resistor. See LICENSE for details.
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License along
// with this program; if not, write to the Free Software Foundation, Inc.,
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
//
#include "GPIO_FeatherM0.hpp"
#include "WireMaster_SAMD21.hpp"
namespace lr {
/// A rock solid I2C implementation for SAM D21 chips.
///
/// This provides all valid configurations for the Adafruit Feather M0 platform.
///
/// @note Each SERCOM can only be used once!
///
class WireMaster_FeatherM0 : public WireMaster_SAMD21
{
public:
/// The setup for the bus.
///
enum class Setup {
A1_A2, ///< A1 = SDA, A2 = SCL, SERCOM0.
A3_A4, ///< A3 = SDA, A4 = SCL, SERCOM4.
P11_P13_1, ///< 11 = SDA, 13 = SCL, SERCOM1.
P11_P13_3, ///< 11 = SDA, 13 = SCL, SERCOM3.
SDA_SCL_3, ///< SDA = SDA, SCL = SCL, SERCOM3.
SDA_SCL_5, ///< SDA = SDA, SCL = SCL, SERCOM5.
Default = SDA_SCL_3, ///< The default bus.
};
private:
static inline Interface getInterfaceForSetup(const Setup setup)
{
switch (setup) {
case Setup::A1_A2: return Interface::SerCom4Alt;
case Setup::A3_A4: return Interface::SerCom0Alt;
case Setup::P11_P13_1: return Interface::SerCom1;
case Setup::P11_P13_3: return Interface::SerCom3Alt;
case Setup::SDA_SCL_5: return Interface::SerCom5Alt;
default:
break;
}
return Interface::SerCom3;
}
static inline GPIO::PinNumber getSdaPinForSetup(const Setup setup)
{
switch (setup) {
case Setup::A1_A2: return static_cast<GPIO::PinNumber>(GPIO::Port::PB08);
case Setup::A3_A4: return static_cast<GPIO::PinNumber>(GPIO::Port::PA04);
case Setup::P11_P13_1: return static_cast<GPIO::PinNumber>(GPIO::Port::PA16);
case Setup::P11_P13_3: return static_cast<GPIO::PinNumber>(GPIO::Port::PA16);
case Setup::SDA_SCL_5: return static_cast<GPIO::PinNumber>(GPIO::Port::PA22);
default:
break;
}
return static_cast<GPIO::PinNumber>(GPIO::FeatherM0::SDA);
}
static inline GPIO::PinNumber getSclPinForSetup(const Setup setup)
{
switch (setup) {
case Setup::A1_A2: return static_cast<GPIO::PinNumber>(GPIO::Port::PB09);
case Setup::A3_A4: return static_cast<GPIO::PinNumber>(GPIO::Port::PA05);
case Setup::P11_P13_1: return static_cast<GPIO::PinNumber>(GPIO::Port::PA17);
case Setup::P11_P13_3: return static_cast<GPIO::PinNumber>(GPIO::Port::PA17);
case Setup::SDA_SCL_5: return static_cast<GPIO::PinNumber>(GPIO::Port::PA23);
default:
break;
}
return static_cast<GPIO::PinNumber>(GPIO::FeatherM0::SCL);
}
public:
inline explicit WireMaster_FeatherM0(const Setup setup = Setup::Default)
: WireMaster_SAMD21(getInterfaceForSetup(setup), getSdaPinForSetup(setup), getSclPinForSetup(setup))
{
}
};
}