Skip to content

Commit 4f519f3

Browse files
committed
mb9bf560l added peripheral to ignore when clearing to prevent clearing a peripheral when not needed
1 parent 3c4a288 commit 4f519f3

1 file changed

Lines changed: 21 additions & 17 deletions

File tree

targets/core/cypress/mb9bf560l/port.hpp

Lines changed: 21 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -78,36 +78,40 @@ namespace klib::core::mb9bf560l::io::detail::pins {
7878
*
7979
* @tparam Index
8080
* @tparam Pin
81+
* @tparam IgnorePeriph
8182
*/
82-
template <uint32_t Index, typename Pin>
83+
template <uint32_t Index, typename Pin, typename IgnorePeriph>
8384
static void peripheral_helper_clear_alternate_functions() {
8485
// go through all items in the alternate functions tuple
8586
using alternate = std::tuple_element_t<Index, typename Pin::alternate>;
8687

8788
// make sure the input id is valid
8889
static_assert(alternate::periph::id <= 20 || alternate::periph::id == spsr_id, "Invalid peripheral id");
8990

90-
// check what peripheral id we need to clear
91-
if constexpr (alternate::periph::id == spsr_id) {
92-
// clear the alternate function if it is set
93-
peripheral_helper_clear_alternate(
94-
&Pin::port::port->SPSR, alternate::periph::offset, alternate::periph::bits, alternate::value
95-
);
96-
}
97-
else {
98-
// get the pointer to the pin select we need to write to
99-
volatile uint32_t *const epfr = &Pin::port::port->EPFR00;
91+
// check if we can ignore this peripheral
92+
if constexpr (!std::is_same_v<alternate, IgnorePeriph>) {
93+
// check what peripheral id we need to clear
94+
if constexpr (alternate::periph::id == spsr_id) {
95+
// clear the alternate function if it is set
96+
peripheral_helper_clear_alternate(
97+
&Pin::port::port->SPSR, alternate::periph::offset, alternate::periph::bits, alternate::value
98+
);
99+
}
100+
else {
101+
// get the pointer to the pin select we need to write to
102+
volatile uint32_t *const epfr = &Pin::port::port->EPFR00;
100103

101-
// clear the alternate function if it is set
102-
peripheral_helper_clear_alternate(
103-
&epfr[alternate::periph::id], alternate::periph::offset, alternate::periph::bits, alternate::value
104-
);
104+
// clear the alternate function if it is set
105+
peripheral_helper_clear_alternate(
106+
&epfr[alternate::periph::id], alternate::periph::offset, alternate::periph::bits, alternate::value
107+
);
108+
}
105109
}
106110

107111
// check the next index
108112
if constexpr ((Index + 1) < std::tuple_size<typename Pin::alternate>::value) {
109113
// call the function again with the next pin
110-
peripheral_helper_clear_alternate_functions<Index + 1, Pin>();
114+
peripheral_helper_clear_alternate_functions<Index + 1, Pin, IgnorePeriph>();
111115
}
112116
}
113117

@@ -152,7 +156,7 @@ namespace klib::core::mb9bf560l::io::detail::pins {
152156
// new one. This is only needed when the user application switches
153157
// the alternate function of a pin more than once. We do it here just
154158
// in case to make sure we do not have any issues with other peripherals
155-
peripheral_helper_clear_alternate_functions<0, Pin>();
159+
peripheral_helper_clear_alternate_functions<0, Pin, Periph>();
156160

157161
// check what peripheral id we need to set
158162
if constexpr (Periph::periph::id == spsr_id) {

0 commit comments

Comments
 (0)