1
1
/*
2
2
* Copyright (c) 2020, Erik Henriksson
3
- * Copyright (c) 2020, Niklas Hauser
3
+ * Copyright (c) 2020, 2024, Niklas Hauser
4
4
*
5
5
* This file is part of the modm project.
6
6
*
@@ -33,6 +33,14 @@ public:
33
33
#ifdef PWR_CR2_USV
34
34
PWR->CR2 |= PWR_CR2_USV;
35
35
#endif
36
+ %% elif target.family in ["h5"]
37
+ #ifdef PWR_USBSCR_USB33DEN
38
+ PWR->USBSCR |= PWR_USBSCR_USB33DEN;
39
+ #endif
40
+ %% elif target.family in ["h7"]
41
+ #ifdef PWR_CR3_USB33DEN
42
+ PWR->CR3 |= PWR_CR3_USB33DEN;
43
+ #endif
36
44
%% endif
37
45
Rcc::enable<Peripheral::{{ peripheral }}>();
38
46
%% if is_remap
@@ -48,20 +56,97 @@ public:
48
56
connect()
49
57
{
50
58
using Connector = GpioConnector<Peripheral::{{ peripheral }}, Signals...>;
51
- %% if port == "fs"
52
59
using Dp = typename Connector::template GetSignal< Gpio::Signal::Dp >;
53
60
using Dm = typename Connector::template GetSignal< Gpio::Signal::Dm >;
54
61
%% if is_otg
55
62
using Id = typename Connector::template GetSignal< Gpio::Signal::Id >;
56
63
%% endif
57
- static_assert(((Connector::template IsValid<Dp> and Connector::template IsValid<Dm>) and sizeof...(Signals) >= 2),
58
- "{{ name }}::connect() requires at least one Dp and one Dm signal!");
64
+ static constexpr bool all_usb =
65
+ Connector::template IsValid<Dp> and Connector::template IsValid<Dm>;
66
+ %% if is_ulpi
67
+ static constexpr bool any_usb =
68
+ Connector::template IsValid<Dp> or Connector::template IsValid<Dm>;
69
+
70
+ using Ulpick = typename Connector::template GetSignal< Gpio::Signal::Ulpick >;
71
+ using Ulpistp = typename Connector::template GetSignal< Gpio::Signal::Ulpistp >;
72
+ using Ulpidir = typename Connector::template GetSignal< Gpio::Signal::Ulpidir >;
73
+ using Ulpinxt = typename Connector::template GetSignal< Gpio::Signal::Ulpinxt >;
74
+ using Ulpid0 = typename Connector::template GetSignal< Gpio::Signal::Ulpid0 >;
75
+ using Ulpid1 = typename Connector::template GetSignal< Gpio::Signal::Ulpid1 >;
76
+ using Ulpid2 = typename Connector::template GetSignal< Gpio::Signal::Ulpid2 >;
77
+ using Ulpid3 = typename Connector::template GetSignal< Gpio::Signal::Ulpid3 >;
78
+ using Ulpid4 = typename Connector::template GetSignal< Gpio::Signal::Ulpid4 >;
79
+ using Ulpid5 = typename Connector::template GetSignal< Gpio::Signal::Ulpid5 >;
80
+ using Ulpid6 = typename Connector::template GetSignal< Gpio::Signal::Ulpid6 >;
81
+ using Ulpid7 = typename Connector::template GetSignal< Gpio::Signal::Ulpid7 >;
82
+
83
+ static constexpr bool all_ulpi =
84
+ Connector::template IsValid< Ulpick > and
85
+ Connector::template IsValid< Ulpistp > and
86
+ Connector::template IsValid< Ulpidir > and
87
+ Connector::template IsValid< Ulpinxt > and
88
+ Connector::template IsValid< Ulpid0 > and
89
+ Connector::template IsValid< Ulpid1 > and
90
+ Connector::template IsValid< Ulpid2 > and
91
+ Connector::template IsValid< Ulpid3 > and
92
+ Connector::template IsValid< Ulpid4 > and
93
+ Connector::template IsValid< Ulpid5 > and
94
+ Connector::template IsValid< Ulpid6 > and
95
+ Connector::template IsValid< Ulpid7 >;
96
+ static constexpr bool any_ulpi =
97
+ Connector::template IsValid< Ulpick > or
98
+ Connector::template IsValid< Ulpistp > or
99
+ Connector::template IsValid< Ulpidir > or
100
+ Connector::template IsValid< Ulpinxt > or
101
+ Connector::template IsValid< Ulpid0 > or
102
+ Connector::template IsValid< Ulpid1 > or
103
+ Connector::template IsValid< Ulpid2 > or
104
+ Connector::template IsValid< Ulpid3 > or
105
+ Connector::template IsValid< Ulpid4 > or
106
+ Connector::template IsValid< Ulpid5 > or
107
+ Connector::template IsValid< Ulpid6 > or
108
+ Connector::template IsValid< Ulpid7 >;
59
109
110
+ static_assert((any_ulpi xor any_usb) and (all_ulpi or all_usb),
111
+ "{{ name }}::connect() requires at least Dp, Dm (+Id) signals OR 12 ULPI signals:\n"
112
+ " - CK\n"
113
+ " - STP\n"
114
+ " - DIR\n"
115
+ " - NXT\n"
116
+ " - D0\n"
117
+ " - D1\n"
118
+ " - D2\n"
119
+ " - D3\n"
120
+ " - D4\n"
121
+ " - D5\n"
122
+ " - D6\n"
123
+ " - D7");
124
+
125
+ if constexpr (all_ulpi and not all_usb)
126
+ {
127
+ Rcc::enable<Peripheral::{{ peripheral }}ulpi>();
128
+ GpioSet< Ulpick, Ulpistp, Ulpidir, Ulpinxt, Ulpid0, Ulpid1,
129
+ Ulpid2, Ulpid3, Ulpid4, Ulpid5, Ulpid6, Ulpid7>::configure(
130
+ Gpio::OutputType::PushPull, Gpio::OutputSpeed::High);
131
+ }
132
+ else if constexpr (not all_ulpi and all_usb)
133
+ {
134
+ Rcc::disable<Peripheral::{{ peripheral }}ulpi>();
135
+ %% set idt = "\t"
136
+ %% else
137
+ static_assert(all_usb and sizeof...(Signals) >= 2,
138
+ "{{ name }}::connect() requires at least one Dp and one Dm signal!");
139
+ %% set idt = ""
140
+ %% endif
141
+ {{idt}}GpioSet<Dp, Dm>::configure(Gpio::OutputType::PushPull, Gpio::OutputSpeed::High);
60
142
%% if is_otg
61
- Id::configure(Gpio::OutputType::OpenDrain, Gpio::OutputSpeed::High);
62
- Id::configure(Gpio::InputType::PullUp);
143
+ {{idt}} Id::configure(Gpio::OutputType::OpenDrain, Gpio::OutputSpeed::High);
144
+ {{idt}} Id::configure(Gpio::InputType::PullUp);
63
145
%% endif
146
+ %% if is_ulpi
147
+ }
64
148
%% endif
149
+
65
150
Connector::connect();
66
151
}
67
152
};
0 commit comments