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 utest_printf(
"Skipping %s peripheral %i with pin %s (%i)\r\n", pin_type,
120 port.peripheral, FormFactorType::pin_to_string(port.pins[i]), port.pins[i]);
124 if (PortType::pin_count > 1) {
125 find_port_pins<PortType, FormFactorType>(port);
128 not_matched_ports.push_back(port);
130 matched_ports.push_back(port);
137 template<
typename PortType,
typename FormFactorType,
typename FunctionType, FunctionType f>
138 void test_all_ports(std::list<PortType> &matched_ports, std::list<PortType> ¬_matched_ports)
140 typedef typename std::list<PortType>::iterator Iter;
141 utest_printf(
"***Testing %s on all form factor ports***\n", PortType::PinMap::name);
142 const PinList *ff_pins = FormFactorType::pins();
145 if (matched_ports.empty() && not_matched_ports.empty()) {
146 utest_printf(
"Could not find pins for %s testing \n", PortType::PinMap::name);
150 for (uint32_t i = 0; i < ff_pins->count; i++) {
151 for (Iter it = matched_ports.begin(); it != matched_ports.end(); ++it) {
152 PortType &port = *it;
153 for (uint32_t j = 0; j < PortType::pin_count; j++) {
154 if (ff_pins->pins[i] == port.pins[j]) {
155 utest_printf(
"%3s - %s pin tested on port: %s...", FormFactorType::pin_to_string(ff_pins->pins[i]),
156 PortType::PinMap::pin_type_names[j], port.str());
157 if (port.status == PortType::StatusNotTested) {
159 port.status = PortType::StatusPass;
161 utest_printf(
"%s\n", port.status == PortType::StatusPass ?
"succeeded" :
"failed");
162 goto end_port_iteration;
166 for (Iter it = not_matched_ports.begin(); it != not_matched_ports.end(); ++it) {
167 PortType &port = *it;
168 for (uint32_t j = 0; j < PortType::pin_count; j++) {
169 if (ff_pins->pins[i] == port.pins[j]) {
170 utest_printf(
"%3s - Could not find pins to test %s pin %s (%d)\n",
171 FormFactorType::pin_to_string(ff_pins->pins[i]),
172 PortType::PinMap::pin_type_names[j],
173 FormFactorType::pin_to_string(ff_pins->pins[i]),
175 goto end_port_iteration;
184 template<
typename PortType,
typename FunctionType, FunctionType f>
185 void test_peripheral(PortType &port)
188 utest_printf(
"%d - Could not find pins to test peripheral\n", port.peripheral);
190 utest_printf(
"%d - peripheral tested on port: %s...", port.peripheral, port.str());
191 if (port.status == PortType::StatusNotTested) {
194 port.status = PortType::StatusPass;
196 utest_printf(
"%s\n", port.status == PortType::StatusPass ?
"succeeded" :
"failed");
200 template<
typename PortType,
typename FunctionType, FunctionType f>
201 void test_all_peripherals(std::list<PortType> &matched_ports, std::list<PortType> ¬_matched_ports)
203 typedef typename std::list<PortType>::iterator Iter;
204 utest_printf(
"***Testing all %s peripherals***\n", PortType::PinMap::name);
206 if (matched_ports.empty() && not_matched_ports.empty()) {
207 utest_printf(
"Could not find pins for %s testing \n", PortType::PinMap::name);
211 matched_ports.sort(peripheral_less<PortType>);
212 not_matched_ports.sort(peripheral_less<PortType>);
214 for (Iter m_it = matched_ports.begin(), nm_it = not_matched_ports.begin();
215 m_it != matched_ports.end() || nm_it != not_matched_ports.end();) {
216 if (m_it != matched_ports.end() && nm_it != not_matched_ports.end()) {
217 if ((*m_it).peripheral < (*nm_it).peripheral) {
218 test_peripheral<PortType, FunctionType, f>(*m_it);
221 test_peripheral<PortType, FunctionType, f>(*nm_it);
224 }
else if (m_it != matched_ports.end()) {
225 test_peripheral<PortType, FunctionType, f>(*m_it);
227 }
else if (nm_it != not_matched_ports.end()) {
228 test_peripheral<PortType, FunctionType, f>(*nm_it);
245 template<
typename PortType,
typename FormFactorType,
typename PortType::TestFunctionType f>
248 std::list<PortType> matched_ports, not_matched_ports;
249 find_ports<PortType, FormFactorType>(matched_ports, not_matched_ports);
250 matched_ports.unique();
251 not_matched_ports.unique();
252 test_all_ports<PortType, FormFactorType, typename PortType::TestFunctionType, f>(matched_ports, not_matched_ports);
266 template<
typename PortType,
typename FormFactorType,
typename PortType::TestFunctionType f>
267 void all_peripherals()
269 std::list<PortType> matched_ports, not_matched_ports;
270 find_ports<PortType, FormFactorType>(matched_ports, not_matched_ports);
272 matched_ports.sort(peripheral_less<PortType>);
273 not_matched_ports.sort(peripheral_less<PortType>);
274 matched_ports.unique(peripheral_comparator<PortType>);
275 not_matched_ports.unique(peripheral_comparator<PortType>);
277 test_all_peripherals<PortType, typename PortType::TestFunctionType, f>(matched_ports, not_matched_ports);
291 template<
typename PortType,
typename FormFactorType,
typename PortType::TestFunctionType f>
292 void one_peripheral()
294 std::list<PortType> matched_ports, not_matched_ports;
295 find_ports<PortType, FormFactorType>(matched_ports, not_matched_ports);
297 utest_printf(
"***Testing one %s pin configuration***\n", PortType::PinMap::name);
298 if (matched_ports.empty()) {
299 utest_printf(
"Could not find pins for %s testing \n", PortType::PinMap::name);
301 test_peripheral<PortType, typename PortType::TestFunctionType, f>(matched_ports.front());
305 template <u
int32_t N,
typename PinMapType,
typename FormFactorType,
typename TestFunctionType>
308 template <u
int32_t N,
typename PinMapType,
typename FormFactorType,
typename TestFunctionType>
312 template <u
int32_t N,
typename PinMapType,
typename FormFactorType,
typename FunctionType>
319 static const uint32_t pin_count = N;
320 typedef PinMapType
PinMap;
321 typedef FunctionType TestFunctionType;
323 enum Status { StatusPass, StatusFail, StatusNotTested };
326 Port(): peripheral(NC), status(StatusNotTested)
339 for (uint32_t i = 0; i < N; i++) {
345 void copy_from(
const Port &port)
347 peripheral = port.peripheral;
348 status = port.status;
349 for (uint32_t i = 0; i < N; i++) {
350 pins[i] = port.pins[i];
356 if (peripheral == NC) {
359 for (uint32_t i = 0; i < N; i++) {
369 static char port_str[128];
371 sprintf(port_str,
"peripheral=(%d) ", peripheral);
372 for (uint32_t i = 0; i < N; i++) {
373 sprintf(pin_str,
"%s=(%s) ", PinMap::pin_type_names[i], FormFactorType::pin_to_string(pins[i]));
374 strcat(port_str, pin_str);
382 template <u
int32_t N,
typename PinMapType,
typename FormFactorType,
typename FunctionType>
385 template <u
int32_t N,
typename PinMapType,
typename FormFactorType,
typename FunctionType>
388 if (port1.peripheral != port2.peripheral) {
391 for (uint32_t i = 0; i < N; i++) {
392 if (port1.pins[i] != port2.pins[i]) {
410 return pinmap_ff_default_pins();
413 static const PinList *restricted_pins()
418 static const char *pin_to_string(PinName pin)
420 return pinmap_ff_default_pin_to_string(pin);
434 static const PinMap *maps[];
435 static const char *
const pin_type_names[];
436 static const char *
const name;
438 const PinMap *GPIOMaps::maps[] = {
gpio_pinmap() };
439 const char *
const GPIOMaps::pin_type_names[] = {
"IO" };
440 const char *
const GPIOMaps::name =
"GPIO";
443 #if DEVICE_INTERRUPTIN 444 #include "gpio_irq_api.h" 446 static const PinMap *maps[];
447 static const char *
const pin_type_names[];
448 static const char *
const name;
451 const char *
const GPIOIRQMaps::pin_type_names[] = {
"IRQ_IN" };
452 const char *
const GPIOIRQMaps::name =
"GPIO_IRQ";
459 static const PinMap *maps[];
460 static const char *
const pin_type_names[];
461 static const char *
const name;
464 const char *
const SPIMaps::pin_type_names[] = {
"MOSI",
"MISO",
"SCLK",
"SSEL" };
465 const char *
const SPIMaps::name =
"SPI";
469 static const PinMap *maps[];
470 static const char *
const pin_type_names[];
471 static const char *
const name;
474 const char *
const SPINoCSMaps::pin_type_names[] = {
"MOSI",
"MISO",
"SCLK" };
475 const char *
const SPINoCSMaps::name =
"SPI";
479 static const PinMap *maps[];
480 static const char *
const pin_type_names[];
481 static const char *
const name;
484 const char *
const SPISlaveMaps::pin_type_names[] = {
"MOSI",
"MISO",
"SCLK",
"SSEL" };
485 const char *
const SPISlaveMaps::name =
"SPISlave";
492 static const PinMap *maps[];
493 static const char *
const pin_type_names[];
494 static const char *
const name;
497 const char *
const I2CMaps::pin_type_names[] = {
"SDA",
"SCL" };
498 const char *
const I2CMaps::name =
"I2C";
503 #include "pwmout_api.h" 505 static const PinMap *maps[];
506 static const char *
const pin_type_names[];
507 static const char *
const name;
510 const char *
const PWMMaps::pin_type_names[] = {
"PWM_OUT" };
511 const char *
const PWMMaps::name =
"PWM";
516 #include "analogin_api.h" 518 static const PinMap *maps[];
519 static const char *
const pin_type_names[];
520 static const char *
const name;
523 const char *
const AnaloginMaps::pin_type_names[] = {
"ADC_IN" };
524 const char *
const AnaloginMaps::name =
"ADC";
529 #include "analogout_api.h" 531 static const PinMap *maps[];
532 static const char *
const pin_type_names[];
533 static const char *
const name;
536 const char *
const AnalogoutMaps::pin_type_names[] = {
"DAC_OUT" };
537 const char *
const AnalogoutMaps::name =
"DAC";
544 static const PinMap *maps[];
545 static const char *
const pin_type_names[];
546 static const char *
const name;
549 const char *
const UARTMaps::pin_type_names[] = {
"TX",
"RX",
"CLS",
"RTS" };
550 const char *
const UARTMaps::name =
"UART";
555 static const PinMap *maps[];
556 static const char *
const pin_type_names[];
557 static const char *
const name;
560 const char *
const UARTNoFCMaps::pin_type_names[] = {
"TX",
"RX" };
561 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 * spi_master_mosi_pinmap(void)
Get the pins that support SPI MOSI.
const PinMap * i2c_master_sda_pinmap(void)
Get the pins that support I2C SDA.
bool pinmap_list_has_peripheral(const PeripheralList *list, int peripheral)
Check if the peripheral is in the list.
const PinMap * gpio_pinmap(void)
Get the pins that support all GPIO tests.
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 * serial_cts_pinmap(void)
Get the pins that support Serial CTS.
const PinMap * spi_master_miso_pinmap(void)
Get the pins that support SPI MISO.
const PinMap * spi_master_cs_pinmap(void)
Get the pins that support SPI CS.
bool pinmap_list_has_pin(const PinList *list, PinName pin)
Check if the pin is in the list.
const PinMap * spi_master_clk_pinmap(void)
Get the pins that support SPI CLK.
const PeripheralList * pinmap_restricted_peripherals(void)
Get the pin list of peripherals to avoid during testing.
const PinMap * gpio_irq_pinmap(void)
Get the pins that support all GPIO IRQ tests.
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 * serial_rx_pinmap(void)
Get the pins that support Serial RX.
void operator==(const SafeBool< T > &lhs, const SafeBool< U > &rhs)
Avoid conversion to bool between different classes.
const PinMap * spi_slave_cs_pinmap(void)
Get the pins that support SPI CS.
const PinMap * spi_slave_mosi_pinmap(void)
Get the pins that support SPI MOSI.
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_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 * analogin_pinmap(void)
Get the pins that support analogin.