Skip to content

Commit 7071513

Browse files
committed
Add form factor pinmap support
Add support for listing all the pins of one or more form factors. This is in preparation for automated testing of the default form factor. This patch includes the following: -A function to get a list of restricted pins which should not be used for testing due to some caveat. -The target config "default-form-factor" which can specify which form factor should be tested -Form factor information for the arduino form factor
1 parent 0dee05a commit 7071513

File tree

3 files changed

+155
-0
lines changed

3 files changed

+155
-0
lines changed

hal/mbed_pinmap_default.c

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
/* mbed Microcontroller Library
2+
* Copyright (c) 2019 ARM Limited
3+
* SPDX-License-Identifier: Apache-2.0
4+
*
5+
* Licensed under the Apache License, Version 2.0 (the "License");
6+
* you may not use this file except in compliance with the License.
7+
* You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
18+
#include <stdlib.h>
19+
#include "hal/pinmap.h"
20+
#include "platform/mbed_toolchain.h"
21+
#include "platform/mbed_assert.h"
22+
#include "device.h"
23+
24+
//*** Common form factors ***
25+
#ifdef TARGET_FF_ARDUINO
26+
27+
static const PinName ff_arduino_pins[] = {
28+
D0, D1, D2, D3, D4, D5, D6, D7,
29+
D8, D9, D10, D11, D12, D13, D14, D15,
30+
A0, A1, A2, A3, A4, A5
31+
};
32+
33+
static const char *ff_arduino_names[] = {
34+
"D0", "D1", "D2", "D3", "D4", "D5", "D6", "D7",
35+
"D8", "D9", "D10", "D11", "D12", "D13", "D14", "D15",
36+
"A0", "A1", "A2", "A3", "A4", "A5"
37+
};
38+
39+
static const PinList ff_arduino_list = {
40+
sizeof(ff_arduino_pins) / sizeof(ff_arduino_pins[0]),
41+
ff_arduino_pins
42+
};
43+
44+
MBED_STATIC_ASSERT(sizeof(ff_arduino_pins) / sizeof(ff_arduino_pins[0]) == sizeof(ff_arduino_names) / sizeof(ff_arduino_names[0]),
45+
"Arrays must have the same length");
46+
47+
const PinList *pinmap_ff_arduino_pins()
48+
{
49+
return &ff_arduino_list;
50+
}
51+
52+
const char *pinmap_ff_arduino_pin_to_string(PinName pin)
53+
{
54+
if (pin == NC) {
55+
return "NC";
56+
}
57+
for (size_t i = 0; i < ff_arduino_list.count; i++) {
58+
if (ff_arduino_list.pins[i] == pin) {
59+
return ff_arduino_names[i];
60+
}
61+
}
62+
return "Unknown";
63+
}
64+
65+
#endif
66+
67+
//*** Default restricted pins ***
68+
MBED_WEAK const PinList *pinmap_restricted_pins()
69+
{
70+
static const PinName pins[] = {
71+
USBTX, USBRX
72+
};
73+
static const PinList pin_list = {
74+
sizeof(pins) / sizeof(pins[0]),
75+
pins
76+
};
77+
return &pin_list;
78+
}
79+

hal/pinmap.h

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -123,6 +123,78 @@ bool pinmap_find_peripheral_pins(const PinList *whitelist, const PinList *blackl
123123
*/
124124
bool pinmap_list_has_pin(const PinList *list, PinName pin);
125125

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+
126198
#ifdef __cplusplus
127199
}
128200
#endif

targets/targets.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,10 @@
3434
"mpu-rom-end": {
3535
"help": "Last address of ROM protected by the MPU",
3636
"value": "0x0fffffff"
37+
},
38+
"default-form-factor": {
39+
"help": "Default form factor of this board taken from supported_form_factors. This must be a lowercase string such as 'arduino'",
40+
"value": null
3741
}
3842
}
3943
},

0 commit comments

Comments
 (0)