Mistake on this page?
Report an issue in GitHub or email us
pinmap.h
1 
2 /** \addtogroup hal */
3 /** @{*/
4 /* mbed Microcontroller Library
5  * Copyright (c) 2006-2013 ARM Limited
6  * SPDX-License-Identifier: Apache-2.0
7  *
8  * Licensed under the Apache License, Version 2.0 (the "License");
9  * you may not use this file except in compliance with the License.
10  * You may obtain a copy of the License at
11  *
12  * http://www.apache.org/licenses/LICENSE-2.0
13  *
14  * Unless required by applicable law or agreed to in writing, software
15  * distributed under the License is distributed on an "AS IS" BASIS,
16  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
17  * See the License for the specific language governing permissions and
18  * limitations under the License.
19  */
20 #ifndef MBED_PINMAP_H
21 #define MBED_PINMAP_H
22 
23 #include "PinNames.h"
24 #include <stdbool.h>
25 
26 #ifdef __cplusplus
27 extern "C" {
28 #endif
29 
30 typedef struct {
31  PinName pin;
32  int peripheral;
33  int function;
34 } PinMap;
35 
36 typedef struct {
37  uint32_t count;
38  const PinName *pins;
39 } PinList;
40 
41 void pin_function(PinName pin, int function);
42 void pin_mode(PinName pin, PinMode mode);
43 
44 uint32_t pinmap_peripheral(PinName pin, const PinMap *map);
45 uint32_t pinmap_function(PinName pin, const PinMap *map);
46 uint32_t pinmap_merge(uint32_t a, uint32_t b);
47 void pinmap_pinout(PinName pin, const PinMap *map);
48 uint32_t pinmap_find_peripheral(PinName pin, const PinMap *map);
49 uint32_t pinmap_find_function(PinName pin, const PinMap *map);
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 
126 /**
127  * Get the pin list of pins to avoid during testing
128  *
129  * The restricted pin list is used to indicate to testing
130  * that a pin should be skipped due to some caveat about it.
131  * For example, using USBRX and USBTX during tests will interfere
132  * with the test runner and should be avoided.
133  *
134  * Targets should override the weak implementation of this
135  * function if they have additional pins which should be
136  * skipped during testing.
137  *
138  * @return Pointer to a pin list of pins to avoid
139  */
140 const PinList *pinmap_restricted_pins(void);
141 
142 #ifdef TARGET_FF_ARDUINO
143 
144 /**
145  * Get the pin list of the Arduino form factor
146  *
147  * @return Pointer to the Arduino pin list
148  */
149 const PinList *pinmap_ff_arduino_pins(void);
150 
151 /**
152  * Get the string representation of a form factor pin
153  *
154  * @param pin Pin to get a string for
155  * @return String representing the form factor pin
156  */
157 const char *pinmap_ff_arduino_pin_to_string(PinName pin);
158 
159 /* Default to arduino form factor if unspecified */
160 #ifndef MBED_CONF_TARGET_DEFAULT_FORM_FACTOR
161 #define MBED_CONF_TARGET_DEFAULT_FORM_FACTOR arduino
162 #endif
163 
164 #endif
165 
166 #ifdef MBED_CONF_TARGET_DEFAULT_FORM_FACTOR
167 
168 #define PINMAP_DEFAULT_PINS_(name) pinmap_ff_ ## name ## _pins
169 #define PINMAP_DEFAULT_PIN_TO_STRING_(name) pinmap_ff_ ## name ## _pin_to_string
170 #define PINMAP_DEFAULT_PINS(name) PINMAP_DEFAULT_PINS_(name)
171 #define PINMAP_DEFAULT_PIN_TO_STRING(name) PINMAP_DEFAULT_PIN_TO_STRING_(name)
172 #define pinmap_ff_default_pins PINMAP_DEFAULT_PINS(MBED_CONF_TARGET_DEFAULT_FORM_FACTOR)
173 #define pinmap_ff_default_pin_to_string PINMAP_DEFAULT_PIN_TO_STRING(MBED_CONF_TARGET_DEFAULT_FORM_FACTOR)
174 
175 /**
176  * Get the pin list of the default form factor
177  *
178  * This is an alias to whichever form factor is set
179  * to be the default.
180  *
181  * @return Pointer to the default pin list
182  */
183 const PinList *pinmap_ff_default_pins(void);
184 
185 /**
186  * Get the string representation of a form factor pin
187  *
188  * This is an alias to whichever form factor is set
189  * to be the default.
190  *
191  * @param pin Pin to get a string for
192  * @return String representing the form factor pin
193  */
194 const char *pinmap_ff_default_pin_to_string(PinName pin);
195 
196 #endif
197 
198 #ifdef __cplusplus
199 }
200 #endif
201 
202 #endif
203 
204 /** @}*/
Definition: pinmap.h:36
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.
bool pinmap_list_has_pin(const PinList *list, PinName pin)
Check if the pin is in the list.
Definition: pinmap.h:30
const PinList * pinmap_restricted_pins(void)
Get the pin list of pins to avoid during testing.
Important Information for this Arm website

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies. If you are not happy with the use of these cookies, please review our Cookie Policy to learn how they can be disabled. By disabling cookies, some features of the site will not work.