Skip to content

Commit 50bb413

Browse files
committed
Add pinmap_gpio_restricted_pins() to provide list of restricted GPIO pins
This is a special case since targets do not provide by default GPIO pin-maps. This extension is required for FPGA GPIO tests - if some pins have limitations (e.g. fixed pull-up) we need to skip these pins while testing. To do that we were adding a dummy pin-map with commented out pins that can't be tested because of the limitations. This solution is redundant and the proposition is to provide a list of restricted gpio pins if required (by default weak implementation is provided with an empty list). This mechanism will be backward compatible, so the old method with dummy gpio pinmap will also work. The switch from dummy pin-maps to pinmap_gpio_restricted_pins() will be performed in separate commits/PRs.
1 parent 35635f8 commit 50bb413

File tree

3 files changed

+41
-2
lines changed

3 files changed

+41
-2
lines changed

components/testing/COMPONENT_FPGA_CI_TEST_SHIELD/test_utils.h

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,8 @@
2828
#define I2C_NAME "I2C"
2929
#define SPI_NAME "SPI"
3030
#define SPISLAVE_NAME "SPISlave"
31+
#define GPIO_NAME "GPIO"
32+
#define GPIO_IRQ_NAME "GPIO_IRQ"
3133

3234
// test function prototypes
3335
typedef void (*TF1)(PinName p0);
@@ -125,6 +127,15 @@ void find_ports(std::list<PortType> &matched_ports, std::list<PortType> &not_mat
125127
continue;
126128
}
127129

130+
if (!strcmp(PortType::PinMap::name, GPIO_IRQ_NAME) || !strcmp(PortType::PinMap::name, GPIO_NAME)) {
131+
// Don't test restricted gpio pins
132+
if (pinmap_list_has_pin(pinmap_gpio_restricted_pins(), port.pins[i])) {
133+
utest_printf("Skipping %s pin %s (%i)\r\n", pin_type,
134+
FormFactorType::pin_to_string(port.pins[i]), port.pins[i]);
135+
continue;
136+
}
137+
}
138+
128139
if (!strcmp(PortType::PinMap::name, UART_NAME) || !strcmp(PortType::PinMap::name, UARTNOFC_NAME)) {
129140
if (pinmap_list_has_peripheral(pinmap_uart_restricted_peripherals(), port.peripheral)) {
130141
utest_printf("Skipping %s peripheral %i with pin %s (%i)\r\n", pin_type,
@@ -455,7 +466,7 @@ struct GPIOMaps {
455466
};
456467
const PinMap *GPIOMaps::maps[] = { gpio_pinmap() };
457468
const char *const GPIOMaps::pin_type_names[] = { "IO" };
458-
const char *const GPIOMaps::name = "GPIO";
469+
const char *const GPIOMaps::name = GPIO_NAME;
459470
typedef Port<1, GPIOMaps, DefaultFormFactor, TF1> GPIOPort;
460471

461472
#if DEVICE_INTERRUPTIN
@@ -467,7 +478,7 @@ struct GPIOIRQMaps {
467478
};
468479
const PinMap *GPIOIRQMaps::maps[] = { gpio_irq_pinmap() };
469480
const char *const GPIOIRQMaps::pin_type_names[] = { "IRQ_IN" };
470-
const char *const GPIOIRQMaps::name = "GPIO_IRQ";
481+
const char *const GPIOIRQMaps::name = GPIO_IRQ_NAME;
471482
typedef Port<1, GPIOIRQMaps, DefaultFormFactor, TF1> GPIOIRQPort;
472483
#endif
473484

hal/mbed_pinmap_default.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,17 @@ MBED_WEAK const PinList *pinmap_restricted_pins()
7878
return &pin_list;
7979
}
8080

81+
//*** Default restricted gpio pins ***
82+
// GPIO pins are special case because there are no pin-maps for GPIO
83+
MBED_WEAK const PinList *pinmap_gpio_restricted_pins()
84+
{
85+
static const PinList pin_list = {
86+
0,
87+
0
88+
};
89+
return &pin_list;
90+
}
91+
8192
//*** Default restricted peripherals ***
8293
MBED_WEAK const PeripheralList *pinmap_uart_restricted_peripherals()
8394
{

hal/pinmap.h

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -176,6 +176,23 @@ const PinList *pinmap_restricted_pins(void);
176176
*/
177177
const PeripheralList *pinmap_uart_restricted_peripherals(void);
178178

179+
/**
180+
* Get the pin list of pins to avoid during GPIO/GPIO_IRQ testing
181+
*
182+
* The GPIO restricted pin list is used to indicate to testing
183+
* that a pin should be skipped due to some caveat about it.
184+
*
185+
* Targets should override the weak implementation of this
186+
* function if they have peripherals which should be
187+
* skipped during testing.
188+
*
189+
* @note This is special case only for GPIO/GPIO_IRQ tests because
190+
* targets do not provide pin-maps for GPIO.
191+
*
192+
* @return Pointer to a peripheral list of peripheral to avoid
193+
*/
194+
const PinList *pinmap_gpio_restricted_pins(void);
195+
179196
#ifdef TARGET_FF_ARDUINO
180197

181198
/**

0 commit comments

Comments
 (0)