21
21
#define MBED_PINMAP_H
22
22
23
23
#include "PinNames.h"
24
+ #include <stdbool.h>
24
25
25
26
#ifdef __cplusplus
26
27
extern "C" {
@@ -32,6 +33,11 @@ typedef struct {
32
33
int function ;
33
34
} PinMap ;
34
35
36
+ typedef struct {
37
+ uint32_t count ;
38
+ const PinName * pins ;
39
+ } PinList ;
40
+
35
41
void pin_function (PinName pin , int function );
36
42
void pin_mode (PinName pin , PinMode mode );
37
43
@@ -42,6 +48,81 @@ void pinmap_pinout(PinName pin, const PinMap *map);
42
48
uint32_t pinmap_find_peripheral (PinName pin , const PinMap * map );
43
49
uint32_t pinmap_find_function (PinName pin , const PinMap * map );
44
50
51
+ /**
52
+ * Find a combination of pins suitable for use given the constraints
53
+ *
54
+ * This function finds pins which meet these specific properties:
55
+ * - The pin is part of the form factor
56
+ * - The pin is not in the restricted list
57
+ * - The pin is contained within the respective pinmap
58
+ * - The pin belongs to the given peripheral
59
+ * - Each pin found is distinct; in the example below
60
+ * mosi and miso will never be assigned the same pin
61
+ *
62
+ * Example:
63
+ * @code
64
+ * #include "mbed.h"
65
+ * #include "pinmap.h"
66
+ *
67
+ * int main()
68
+ * {
69
+ * int per = spi_master_cs_pinmap()->peripheral;
70
+ * const PinList *pins_ff = pinmap_ff_default_pins();
71
+ * const PinList *pins_avoid = pinmap_restricted_pins();
72
+ * PinName mosi = NC;
73
+ * PinName miso = NC;
74
+ * PinName sclk = NC;
75
+ * PinName ssel = NC;
76
+ * const PinMap *maps[] = {
77
+ * spi_master_mosi_pinmap(),
78
+ * spi_master_miso_pinmap(),
79
+ * spi_master_clk_pinmap(),
80
+ * spi_master_cs_pinmap()
81
+ * };
82
+ * PinName *pins[] = {
83
+ * &mosi,
84
+ * &miso,
85
+ * &sclk,
86
+ * &ssel
87
+ * };
88
+ * if (pinmap_find_peripheral_pins(pins_ff, pins_avoid, per, maps, pins, sizeof(maps) / sizeof(maps[0]))) {
89
+ * printf("Found SPI pins to test instance %i with:\n"
90
+ * " mosi=%s\n"
91
+ * " miso=%s\n"
92
+ * " sclk=%s\n"
93
+ * " ssel=%s\n", per,
94
+ * pinmap_ff_default_pin_to_string(mosi),
95
+ * pinmap_ff_default_pin_to_string(miso),
96
+ * pinmap_ff_default_pin_to_string(sclk),
97
+ * pinmap_ff_default_pin_to_string(ssel));
98
+ * } else {
99
+ * printf("Could not find SPI combination to test %i\n", per);
100
+ * }
101
+ * return 0;
102
+ * }
103
+ * @endcode
104
+ *
105
+ * @param whitelist List of pins to choose from
106
+ * @param blacklist List of pins which cannot be used
107
+ * @param per Peripheral to which the pins belong
108
+ * @param maps An array of pin maps to select from
109
+ * @param pins An array of pins to find. Pins already set to a value will be
110
+ * left unchanged. Only pins initialized to NC will be updated by this function
111
+ * @param count The size of maps and pins
112
+ * @return true if a suitable combination of pins was found and
113
+ * written to the pins array, otherwise false
114
+ */
115
+ bool pinmap_find_peripheral_pins (const PinList * whitelist , const PinList * blacklist , int per , const PinMap * const * maps , PinName * * pins , uint32_t count );
116
+
117
+ /**
118
+ * Check if the pin is in the list
119
+ *
120
+ * @param list pin list to check
121
+ * @param pin pin to check for in the list
122
+ * @return true if the pin is in the list, false otherwise
123
+ */
124
+ bool pinmap_list_has_pin (const PinList * list , PinName pin );
125
+
45
126
#ifdef __cplusplus
46
127
}
47
128
#endif
0 commit comments