24 typedef void (*TF1)(PinName p0);
25 typedef void (*TF2)(PinName p0, PinName p1);
26 typedef void (*TF3)(PinName p0, PinName p1, PinName p2);
27 typedef void (*TF4)(PinName p0, PinName p1, PinName p2, PinName p3);
28 typedef void (*TF5)(PinName p0, PinName p1, PinName p2, PinName p3, PinName p4);
30 template<
typename PortType,
typename FunctionType, FunctionType f>
35 template<
typename PortType, TF1 f>
37 void operator()(PortType &port)
43 template<
typename PortType, TF2 f>
45 void operator()(PortType &port)
47 f(port.pins[0], port.pins[1]);
51 template<
typename PortType, TF3 f>
53 void operator()(PortType &port)
55 f(port.pins[0], port.pins[1], port.pins[2]);
59 template<
typename PortType, TF4 f>
61 void operator()(PortType &port)
63 f(port.pins[0], port.pins[1], port.pins[2], port.pins[3]);
67 template<
typename PortType, TF5 f>
69 void operator()(PortType &port)
71 f(port.pins[0], port.pins[1], port.pins[2], port.pins[3], port.pins[4]);
75 template <
typename PortType>
76 bool peripheral_comparator(
const PortType &port1,
const PortType &port2)
78 return port1.peripheral == port2.peripheral;
81 template <
typename PortType>
82 bool peripheral_less(
const PortType &port1,
const PortType &port2)
84 return port1.peripheral < port2.peripheral;
87 template<
typename PortType,
typename FormFactorType>
88 static bool find_port_pins(PortType &port)
91 port.peripheral, PortType::PinMap::maps, port.ppins, PortType::pin_count);
94 template<
typename PortType,
typename FormFactorType>
95 void find_ports(std::list<PortType> &matched_ports, std::list<PortType> ¬_matched_ports)
98 for (uint32_t i = 0; i < PortType::pin_count; i++) {
99 const PinMap *map = PortType::PinMap::maps[i];
100 const char *pin_type = PortType::PinMap::pin_type_names[i];
103 for (; map->pin != NC; map++) {
106 port.pins[i] = map->pin;
107 port.peripheral = map->peripheral;
114 utest_printf(
"Skipping %s pin %s (%i)\r\n", pin_type,
115 FormFactorType::pin_to_string(port.pins[i]), port.pins[i]);
119 if (PortType::pin_count > 1) {
120 find_port_pins<PortType, FormFactorType>(port);
123 not_matched_ports.push_back(port);
125 matched_ports.push_back(port);
132 template<
typename PortType,
typename FormFactorType,
typename FunctionType, FunctionType f>
133 void test_all_ports(std::list<PortType> &matched_ports, std::list<PortType> ¬_matched_ports)
135 typedef typename std::list<PortType>::iterator Iter;
136 utest_printf(
"***Testing %s on all form factor ports***\n", PortType::PinMap::name);
137 const PinList *ff_pins = FormFactorType::pins();
140 if (matched_ports.empty() && not_matched_ports.empty()) {
141 utest_printf(
"Could not find pins for %s testing \n", PortType::PinMap::name);
145 for (uint32_t i = 0; i < ff_pins->count; i++) {
146 for (Iter it = matched_ports.begin(); it != matched_ports.end(); ++it) {
147 PortType &port = *it;
148 for (uint32_t j = 0; j < PortType::pin_count; j++) {
149 if (ff_pins->pins[i] == port.pins[j]) {
150 utest_printf(
"%3s - %s pin tested on port: %s...", FormFactorType::pin_to_string(ff_pins->pins[i]),
151 PortType::PinMap::pin_type_names[j], port.str());
152 if (port.status == PortType::StatusNotTested) {
154 port.status = PortType::StatusPass;
156 utest_printf(
"%s\n", port.status == PortType::StatusPass ?
"succeeded" :
"failed");
157 goto end_port_iteration;
161 for (Iter it = not_matched_ports.begin(); it != not_matched_ports.end(); ++it) {
162 PortType &port = *it;
163 for (uint32_t j = 0; j < PortType::pin_count; j++) {
164 if (ff_pins->pins[i] == port.pins[j]) {
165 utest_printf(
"%3s - Could not find pins to test %s pin %s (%d)\n",
166 FormFactorType::pin_to_string(ff_pins->pins[i]),
167 PortType::PinMap::pin_type_names[j],
168 FormFactorType::pin_to_string(ff_pins->pins[i]),
170 goto end_port_iteration;
179 template<
typename PortType,
typename FunctionType, FunctionType f>
180 void test_peripheral(PortType &port)
183 utest_printf(
"%d - Could not find pins to test peripheral\n", port.peripheral);
185 utest_printf(
"%d - peripheral tested on port: %s...", port.peripheral, port.str());
186 if (port.status == PortType::StatusNotTested) {
189 port.status = PortType::StatusPass;
191 utest_printf(
"%s\n", port.status == PortType::StatusPass ?
"succeeded" :
"failed");
195 template<
typename PortType,
typename FunctionType, FunctionType f>
196 void test_all_peripherals(std::list<PortType> &matched_ports, std::list<PortType> ¬_matched_ports)
198 typedef typename std::list<PortType>::iterator Iter;
199 utest_printf(
"***Testing all %s peripherals***\n", PortType::PinMap::name);
201 if (matched_ports.empty() && not_matched_ports.empty()) {
202 utest_printf(
"Could not find pins for %s testing \n", PortType::PinMap::name);
206 matched_ports.sort(peripheral_less<PortType>);
207 not_matched_ports.sort(peripheral_less<PortType>);
209 for (Iter m_it = matched_ports.begin(), nm_it = not_matched_ports.begin();
210 m_it != matched_ports.end() || nm_it != not_matched_ports.end();) {
211 if (m_it != matched_ports.end() && nm_it != not_matched_ports.end()) {
212 if ((*m_it).peripheral < (*nm_it).peripheral) {
213 test_peripheral<PortType, FunctionType, f>(*m_it);
216 test_peripheral<PortType, FunctionType, f>(*nm_it);
219 }
else if (m_it != matched_ports.end()) {
220 test_peripheral<PortType, FunctionType, f>(*m_it);
222 }
else if (nm_it != not_matched_ports.end()) {
223 test_peripheral<PortType, FunctionType, f>(*nm_it);
240 template<
typename PortType,
typename FormFactorType,
typename PortType::TestFunctionType f>
243 std::list<PortType> matched_ports, not_matched_ports;
244 find_ports<PortType, FormFactorType>(matched_ports, not_matched_ports);
245 matched_ports.unique();
246 not_matched_ports.unique();
247 test_all_ports<PortType, FormFactorType, typename PortType::TestFunctionType, f>(matched_ports, not_matched_ports);
261 template<
typename PortType,
typename FormFactorType,
typename PortType::TestFunctionType f>
262 void all_peripherals()
264 std::list<PortType> matched_ports, not_matched_ports;
265 find_ports<PortType, FormFactorType>(matched_ports, not_matched_ports);
267 matched_ports.sort(peripheral_less<PortType>);
268 not_matched_ports.sort(peripheral_less<PortType>);
269 matched_ports.unique(peripheral_comparator<PortType>);
270 not_matched_ports.unique(peripheral_comparator<PortType>);
272 test_all_peripherals<PortType, typename PortType::TestFunctionType, f>(matched_ports, not_matched_ports);
286 template<
typename PortType,
typename FormFactorType,
typename PortType::TestFunctionType f>
287 void one_peripheral()
289 std::list<PortType> matched_ports, not_matched_ports;
290 find_ports<PortType, FormFactorType>(matched_ports, not_matched_ports);
292 utest_printf(
"***Testing one %s pin configuration***\n", PortType::PinMap::name);
293 if (matched_ports.empty()) {
294 utest_printf(
"Could not find pins for %s testing \n", PortType::PinMap::name);
296 test_peripheral<PortType, typename PortType::TestFunctionType, f>(matched_ports.front());
300 template <u
int32_t N,
typename PinMapType,
typename FormFactorType,
typename TestFunctionType>
303 template <u
int32_t N,
typename PinMapType,
typename FormFactorType,
typename TestFunctionType>
307 template <u
int32_t N,
typename PinMapType,
typename FormFactorType,
typename FunctionType>
314 static const uint32_t pin_count = N;
315 typedef PinMapType
PinMap;
316 typedef FunctionType TestFunctionType;
318 enum Status { StatusPass, StatusFail, StatusNotTested };
321 Port(): peripheral(NC), status(StatusNotTested)
334 for (uint32_t i = 0; i < N; i++) {
340 void copy_from(
const Port &port)
342 peripheral = port.peripheral;
343 status = port.status;
344 for (uint32_t i = 0; i < N; i++) {
345 pins[i] = port.pins[i];
351 if (peripheral == NC) {
354 for (uint32_t i = 0; i < N; i++) {
364 static char port_str[128];
366 sprintf(port_str,
"peripheral=(%d) ", peripheral);
367 for (uint32_t i = 0; i < N; i++) {
368 sprintf(pin_str,
"%s=(%s) ", PinMap::pin_type_names[i], FormFactorType::pin_to_string(pins[i]));
369 strcat(port_str, pin_str);
377 template <u
int32_t N,
typename PinMapType,
typename FormFactorType,
typename FunctionType>
380 template <u
int32_t N,
typename PinMapType,
typename FormFactorType,
typename FunctionType>
383 if (port1.peripheral != port2.peripheral) {
386 for (uint32_t i = 0; i < N; i++) {
387 if (port1.pins[i] != port2.pins[i]) {
405 return pinmap_ff_default_pins();
408 static const PinList *restricted_pins()
413 static const char *pin_to_string(PinName pin)
415 return pinmap_ff_default_pin_to_string(pin);
431 static const PinMap *maps[];
432 static const char *
const pin_type_names[];
433 static const char *
const name;
436 const char *
const SPIMaps::pin_type_names[] = {
"MOSI",
"MISO",
"SCLK",
"SSEL" };
437 const char *
const SPIMaps::name =
"SPI";
441 static const PinMap *maps[];
442 static const char *
const pin_type_names[];
443 static const char *
const name;
446 const char *
const SPINoCSMaps::pin_type_names[] = {
"MOSI",
"MISO",
"SCLK" };
447 const char *
const SPINoCSMaps::name =
"SPI";
451 static const PinMap *maps[];
452 static const char *
const pin_type_names[];
453 static const char *
const name;
456 const char *
const SPISlaveMaps::pin_type_names[] = {
"MOSI",
"MISO",
"SCLK",
"SSEL" };
457 const char *
const SPISlaveMaps::name =
"SPISlave";
464 static const PinMap *maps[];
465 static const char *
const pin_type_names[];
466 static const char *
const name;
469 const char *
const I2CMaps::pin_type_names[] = {
"SDA",
"SCL" };
470 const char *
const I2CMaps::name =
"I2C";
475 #include "pwmout_api.h" 477 static const PinMap *maps[];
478 static const char *
const pin_type_names[];
479 static const char *
const name;
482 const char *
const PWMMaps::pin_type_names[] = {
"PWM_OUT" };
483 const char *
const PWMMaps::name =
"PWM";
488 #include "analogin_api.h" 490 static const PinMap *maps[];
491 static const char *
const pin_type_names[];
492 static const char *
const name;
495 const char *
const AnaloginMaps::pin_type_names[] = {
"ADC_IN" };
496 const char *
const AnaloginMaps::name =
"ADC";
501 #include "analogout_api.h" 503 static const PinMap *maps[];
504 static const char *
const pin_type_names[];
505 static const char *
const name;
508 const char *
const AnalogoutMaps::pin_type_names[] = {
"DAC_OUT" };
509 const char *
const AnalogoutMaps::name =
"DAC";
515 static const PinMap *maps[];
516 static const char *
const pin_type_names[];
517 static const char *
const name;
520 const char *
const UARTMaps::pin_type_names[] = {
"TX",
"RX",
"CLS",
"RTS" };
521 const char *
const UARTMaps::name =
"UART";
525 static const PinMap *maps[];
526 static const char *
const pin_type_names[];
527 static const char *
const name;
530 const char *
const UARTNoFCMaps::pin_type_names[] = {
"TX",
"RX" };
531 const char *
const UARTNoFCMaps::name =
"UART-no-FC";
const PinMap * serial_tx_pinmap(void)
Get the pins that support Serial TX.
const PinMap * i2c_master_scl_pinmap(void)
Get the pins that support I2C SCL.
const PinMap * i2c_master_sda_pinmap(void)
Get the pins that support I2C SDA.
const PinMap * spi_slave_mosi_pinmap(void)
Get the pins that support SPI MOSI.
bool pinmap_find_peripheral_pins(const PinList *whitelist, const PinList *blacklist, int per, const PinMap *const *maps, PinName **pins, uint32_t count)
Find a combination of pins suitable for use given the constraints.
const PinMap * spi_slave_clk_pinmap(void)
Get the pins that support SPI CLK.
const PinMap * spi_slave_miso_pinmap(void)
Get the pins that support SPI MISO.
const PinMap * serial_cts_pinmap(void)
Get the pins that support Serial CTS.
const PinMap * spi_master_clk_pinmap(void)
Get the pins that support SPI CLK.
bool pinmap_list_has_pin(const PinList *list, PinName pin)
Check if the pin is in the list.
const PinMap * pwmout_pinmap(void)
Get the pins that support PWM.
const PinMap * serial_rts_pinmap(void)
Get the pins that support Serial RTS.
const PinMap * spi_master_cs_pinmap(void)
Get the pins that support SPI CS.
const PinMap * serial_rx_pinmap(void)
Get the pins that support Serial RX.
const PinMap * spi_master_mosi_pinmap(void)
Get the pins that support SPI MOSI.
void operator==(const SafeBool< T > &lhs, const SafeBool< U > &rhs)
Avoid conversion to bool between different classes.
const PinList * pinmap_restricted_pins(void)
Get the pin list of pins to avoid during testing.
const PinMap * analogout_pinmap(void)
Get the pins that support analogout.
const PinMap * spi_slave_cs_pinmap(void)
Get the pins that support SPI CS.
const PinMap * analogin_pinmap(void)
Get the pins that support analogin.
const PinMap * spi_master_miso_pinmap(void)
Get the pins that support SPI MISO.