Mbed OS Reference
Loading...
Searching...
No Matches
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#include <stdint.h>
26
27#ifdef __cplusplus
28extern "C" {
29#endif
30
31typedef struct {
32 PinName pin;
33 int peripheral;
34 int function;
35} PinMap;
36
37typedef struct {
38 uint32_t count;
39 const PinName *pins;
40} PinList;
41
42typedef struct {
43 uint32_t count;
44 const int *peripheral;
46
47void pin_function(PinName pin, int function);
48void pin_mode(PinName pin, PinMode mode);
49
50uint32_t pinmap_peripheral(PinName pin, const PinMap *map);
51uint32_t pinmap_function(PinName pin, const PinMap *map);
52uint32_t pinmap_merge(uint32_t a, uint32_t b);
53void pinmap_pinout(PinName pin, const PinMap *map);
54uint32_t pinmap_find_peripheral(PinName pin, const PinMap *map);
55uint32_t pinmap_find_function(PinName pin, const PinMap *map);
56
57/**
58 * Find a combination of pins suitable for use given the constraints
59 *
60 * This function finds pins which meet these specific properties:
61 * - The pin is part of the form factor
62 * - The pin is not in the restricted list
63 * - The pin is contained within the respective pinmap
64 * - The pin belongs to the given peripheral
65 * - Each pin found is distinct; in the example below
66 * mosi and miso will never be assigned the same pin
67 *
68 * Example:
69 * @code
70 * #include "mbed.h"
71 * #include "pinmap.h"
72 *
73 * int main()
74 * {
75 * int per = spi_master_cs_pinmap()->peripheral;
76 * const PinList *pins_ff = pinmap_ff_default_pins();
77 * PinName mosi = NC;
78 * PinName miso = NC;
79 * PinName sclk = NC;
80 * PinName ssel = NC;
81 * const PinMap *maps[] = {
82 * spi_master_mosi_pinmap(),
83 * spi_master_miso_pinmap(),
84 * spi_master_clk_pinmap(),
85 * spi_master_cs_pinmap()
86 * };
87 * PinName *pins[] = {
88 * &mosi,
89 * &miso,
90 * &sclk,
91 * &ssel
92 * };
93 * if (pinmap_find_peripheral_pins(pins_ff, pins_avoid, per, maps, pins, sizeof(maps) / sizeof(maps[0]))) {
94 * printf("Found SPI pins to test instance %i with:\n"
95 * " mosi=%s\n"
96 * " miso=%s\n"
97 * " sclk=%s\n"
98 * " ssel=%s\n", per,
99 * pinmap_ff_default_pin_to_string(mosi),
100 * pinmap_ff_default_pin_to_string(miso),
101 * pinmap_ff_default_pin_to_string(sclk),
102 * pinmap_ff_default_pin_to_string(ssel));
103 * } else {
104 * printf("Could not find SPI combination to test %i\n", per);
105 * }
106 * return 0;
107 * }
108 * @endcode
109 *
110 * @param whitelist List of pins to choose from
111 * @param blacklist List of pins which cannot be used
112 * @param per Peripheral to which the pins belong
113 * @param maps An array of pin maps to select from
114 * @param pins An array of pins to find. Pins already set to a value will be
115 * left unchanged. Only pins initialized to NC will be updated by this function
116 * @param count The size of maps and pins
117 * @return true if a suitable combination of pins was found and
118 * written to the pins array, otherwise false
119 */
120bool pinmap_find_peripheral_pins(const PinList *whitelist, const PinList *blacklist, int per, const PinMap *const *maps, PinName **pins, uint32_t count);
121
122/**
123 * Check if the pin is in the list
124 *
125 * @param list pin list to check
126 * @param pin pin to check for in the list
127 * @return true if the pin is in the list, false otherwise
128 */
129bool pinmap_list_has_pin(const PinList *list, PinName pin);
130
131/**
132 * Check if the peripheral is in the list
133 *
134 * @param list peripheral list to check
135 * @param peripheral peripheral to check for in the list
136 * @return true if the peripheral is in the list, false otherwise
137 */
138bool pinmap_list_has_peripheral(const PeripheralList *list, int peripheral);
139
140/**
141 * Get the pin list of peripherals per interface to avoid during testing
142 *
143 * The restricted peripheral list is used to indicate to testing
144 * that a peripheral should be skipped due to some caveat about it.
145 * For example, using the USB serial port during tests will interfere
146 * with the test runner and should be avoided.
147 *
148 * Targets should override the weak implementation of this
149 * function if they have peripherals which should be
150 * skipped during testing.
151 *
152 * @note Restricting peripheral is at the moment available for UART
153 * interface only as only STDIO UART must be skipped because it is
154 * used by Mbed.
155 * Restricting peripherals for other interfaces should be added
156 * in the future if required.
157 *
158 * @return Pointer to a peripheral list of peripheral to avoid
159 */
160#if DEVICE_SERIAL
162#endif
163
164/**
165 * Get the pin list of pins to avoid during GPIO/GPIO_IRQ testing
166 *
167 * The GPIO restricted pin list is used to indicate to testing
168 * that a pin should be skipped due to some caveat about it.
169 *
170 * Targets should override the weak implementation of this
171 * function if they have peripherals which should be
172 * skipped during testing.
173 *
174 * @note This is special case only for GPIO/GPIO_IRQ tests because
175 * targets do not provide pin-maps for GPIO.
176 *
177 * @return Pointer to a peripheral list of peripheral to avoid
178 */
180
181#if defined (TARGET_FF_ARDUINO) || (TARGET_FF_ARDUINO_UNO)
182
183/**
184 * Get the pin list of the Arduino form factor
185 *
186 * @return Pointer to the Arduino pin list
187 */
188const PinList *pinmap_ff_arduino_uno_pins(void);
189
190/**
191 * Get the string representation of a form factor pin
192 *
193 * @param pin Pin to get a string for
194 * @return String representing the form factor pin
195 */
196const char *pinmap_ff_arduino_uno_pin_to_string(PinName pin);
197
198/* Default to arduino form factor if unspecified */
199#ifndef MBED_CONF_TARGET_DEFAULT_FORM_FACTOR
200#define MBED_CONF_TARGET_DEFAULT_FORM_FACTOR arduino_uno
201#endif
202
203#endif
204
205#ifdef MBED_CONF_TARGET_DEFAULT_FORM_FACTOR
206
207#define PINMAP_DEFAULT_PINS_(name) pinmap_ff_ ## name ## _pins
208#define PINMAP_DEFAULT_PIN_TO_STRING_(name) pinmap_ff_ ## name ## _pin_to_string
209#define PINMAP_DEFAULT_PINS(name) PINMAP_DEFAULT_PINS_(name)
210#define PINMAP_DEFAULT_PIN_TO_STRING(name) PINMAP_DEFAULT_PIN_TO_STRING_(name)
211#define pinmap_ff_default_pins PINMAP_DEFAULT_PINS(MBED_CONF_TARGET_DEFAULT_FORM_FACTOR)
212#define pinmap_ff_default_pin_to_string PINMAP_DEFAULT_PIN_TO_STRING(MBED_CONF_TARGET_DEFAULT_FORM_FACTOR)
213
214/**
215 * Get the pin list of the default form factor
216 *
217 * This is an alias to whichever form factor is set
218 * to be the default.
219 *
220 * @return Pointer to the default pin list
221 */
222const PinList *pinmap_ff_default_pins(void);
223
224/**
225 * Get the string representation of a form factor pin
226 *
227 * This is an alias to whichever form factor is set
228 * to be the default.
229 *
230 * @param pin Pin to get a string for
231 * @return String representing the form factor pin
232 */
233const char *pinmap_ff_default_pin_to_string(PinName pin);
234
235#endif
236
237#ifdef __cplusplus
238}
239#endif
240
241#endif
242
243/** @}*/
bool pinmap_list_has_peripheral(const PeripheralList *list, int peripheral)
Check if the peripheral is in the list.
const PinList * pinmap_gpio_restricted_pins(void)
Get the pin list of pins to avoid during GPIO/GPIO_IRQ testing.
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.
const PeripheralList * pinmap_uart_restricted_peripherals(void)
Get the pin list of peripherals per interface to avoid during testing.