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
pull/9449/head
Russ Butler 2019-01-21 17:26:53 -06:00
parent 0dee05a843
commit 7071513d7f
3 changed files with 155 additions and 0 deletions

79
hal/mbed_pinmap_default.c Normal file
View File

@ -0,0 +1,79 @@
/* mbed Microcontroller Library
* Copyright (c) 2019 ARM Limited
* SPDX-License-Identifier: Apache-2.0
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include <stdlib.h>
#include "hal/pinmap.h"
#include "platform/mbed_toolchain.h"
#include "platform/mbed_assert.h"
#include "device.h"
//*** Common form factors ***
#ifdef TARGET_FF_ARDUINO
static const PinName ff_arduino_pins[] = {
D0, D1, D2, D3, D4, D5, D6, D7,
D8, D9, D10, D11, D12, D13, D14, D15,
A0, A1, A2, A3, A4, A5
};
static const char *ff_arduino_names[] = {
"D0", "D1", "D2", "D3", "D4", "D5", "D6", "D7",
"D8", "D9", "D10", "D11", "D12", "D13", "D14", "D15",
"A0", "A1", "A2", "A3", "A4", "A5"
};
static const PinList ff_arduino_list = {
sizeof(ff_arduino_pins) / sizeof(ff_arduino_pins[0]),
ff_arduino_pins
};
MBED_STATIC_ASSERT(sizeof(ff_arduino_pins) / sizeof(ff_arduino_pins[0]) == sizeof(ff_arduino_names) / sizeof(ff_arduino_names[0]),
"Arrays must have the same length");
const PinList *pinmap_ff_arduino_pins()
{
return &ff_arduino_list;
}
const char *pinmap_ff_arduino_pin_to_string(PinName pin)
{
if (pin == NC) {
return "NC";
}
for (size_t i = 0; i < ff_arduino_list.count; i++) {
if (ff_arduino_list.pins[i] == pin) {
return ff_arduino_names[i];
}
}
return "Unknown";
}
#endif
//*** Default restricted pins ***
MBED_WEAK const PinList *pinmap_restricted_pins()
{
static const PinName pins[] = {
USBTX, USBRX
};
static const PinList pin_list = {
sizeof(pins) / sizeof(pins[0]),
pins
};
return &pin_list;
}

View File

@ -123,6 +123,78 @@ bool pinmap_find_peripheral_pins(const PinList *whitelist, const PinList *blackl
*/
bool pinmap_list_has_pin(const PinList *list, PinName pin);
/**
* Get the pin list of pins to avoid during testing
*
* The restricted pin list is used to indicate to testing
* that a pin should be skipped due to some caveat about it.
* For example, using USBRX and USBTX during tests will interfere
* with the test runner and should be avoided.
*
* Targets should override the weak implementation of this
* function if they have additional pins which should be
* skipped during testing.
*
* @return Pointer to a pin list of pins to avoid
*/
const PinList *pinmap_restricted_pins(void);
#ifdef TARGET_FF_ARDUINO
/**
* Get the pin list of the Arduino form factor
*
* @return Pointer to the Arduino pin list
*/
const PinList *pinmap_ff_arduino_pins(void);
/**
* Get the string representation of a form factor pin
*
* @param pin Pin to get a string for
* @return String representing the form factor pin
*/
const char *pinmap_ff_arduino_pin_to_string(PinName pin);
/* Default to arduino form factor if unspecified */
#ifndef MBED_CONF_TARGET_DEFAULT_FORM_FACTOR
#define MBED_CONF_TARGET_DEFAULT_FORM_FACTOR arduino
#endif
#endif
#ifdef MBED_CONF_TARGET_DEFAULT_FORM_FACTOR
#define PINMAP_DEFAULT_PINS_(name) pinmap_ff_ ## name ## _pins
#define PINMAP_DEFAULT_PIN_TO_STRING_(name) pinmap_ff_ ## name ## _pin_to_string
#define PINMAP_DEFAULT_PINS(name) PINMAP_DEFAULT_PINS_(name)
#define PINMAP_DEFAULT_PIN_TO_STRING(name) PINMAP_DEFAULT_PIN_TO_STRING_(name)
#define pinmap_ff_default_pins PINMAP_DEFAULT_PINS(MBED_CONF_TARGET_DEFAULT_FORM_FACTOR)
#define pinmap_ff_default_pin_to_string PINMAP_DEFAULT_PIN_TO_STRING(MBED_CONF_TARGET_DEFAULT_FORM_FACTOR)
/**
* Get the pin list of the default form factor
*
* This is an alias to whichever form factor is set
* to be the default.
*
* @return Pointer to the default pin list
*/
const PinList *pinmap_ff_default_pins(void);
/**
* Get the string representation of a form factor pin
*
* This is an alias to whichever form factor is set
* to be the default.
*
* @param pin Pin to get a string for
* @return String representing the form factor pin
*/
const char *pinmap_ff_default_pin_to_string(PinName pin);
#endif
#ifdef __cplusplus
}
#endif

View File

@ -34,6 +34,10 @@
"mpu-rom-end": {
"help": "Last address of ROM protected by the MPU",
"value": "0x0fffffff"
},
"default-form-factor": {
"help": "Default form factor of this board taken from supported_form_factors. This must be a lowercase string such as 'arduino'",
"value": null
}
}
},