2017-04-06 08:09:03 +00:00
|
|
|
/* mbed Microcontroller Library
|
2017-12-13 13:28:54 +00:00
|
|
|
* Copyright (c) 2006-2018 ARM Limited
|
2017-04-06 08:09:03 +00:00
|
|
|
*
|
|
|
|
* 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 "mbed_assert.h"
|
|
|
|
#include "pinmap.h"
|
|
|
|
#include "mbed_error.h"
|
2017-12-13 13:28:54 +00:00
|
|
|
#include "objects.h"
|
2017-04-06 08:09:03 +00:00
|
|
|
|
|
|
|
void pin_function(PinName pin, int function)
|
|
|
|
{
|
2017-12-13 13:28:54 +00:00
|
|
|
struct arm_gpio_dev_t *gpio_dev;
|
|
|
|
uint32_t flags;
|
2017-06-14 09:16:47 +00:00
|
|
|
|
2017-12-13 13:28:54 +00:00
|
|
|
MBED_ASSERT(pin != NC);
|
2017-04-06 08:09:03 +00:00
|
|
|
|
2017-12-13 13:28:54 +00:00
|
|
|
/* The pin has to be a GPIO pin */
|
2017-06-14 09:16:47 +00:00
|
|
|
if (pin >= EXP0 && pin <= EXP51) {
|
2017-12-13 13:28:54 +00:00
|
|
|
switch (function) {
|
|
|
|
case ALTERNATE_FUNC:
|
|
|
|
flags = ARM_GPIO_PIN_DISABLE;
|
|
|
|
break;
|
|
|
|
case GPIO_FUNC:
|
|
|
|
flags = ARM_GPIO_PIN_ENABLE;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
return;
|
2017-06-14 09:16:47 +00:00
|
|
|
}
|
2017-12-13 13:28:54 +00:00
|
|
|
|
|
|
|
switch (GPIO_DEV_NUMBER(pin)) {
|
|
|
|
#ifdef ARM_GPIO0
|
|
|
|
case GPIO0_NUMBER:
|
|
|
|
gpio_dev = &ARM_GPIO0_DEV;
|
|
|
|
break;
|
|
|
|
#endif /* ARM_GPIO0 */
|
|
|
|
#ifdef ARM_GPIO1
|
|
|
|
case GPIO1_NUMBER:
|
|
|
|
gpio_dev = &ARM_GPIO1_DEV;
|
|
|
|
break;
|
|
|
|
#endif /* ARM_GPIO1 */
|
|
|
|
#ifdef ARM_GPIO2
|
|
|
|
case GPIO2_NUMBER:
|
|
|
|
gpio_dev = &ARM_GPIO2_DEV;
|
|
|
|
break;
|
|
|
|
#endif /* ARM_GPIO2 */
|
|
|
|
#ifdef ARM_GPIO3
|
|
|
|
case GPIO3_NUMBER:
|
|
|
|
gpio_dev = &ARM_GPIO3_DEV;
|
|
|
|
break;
|
|
|
|
#endif /* ARM_GPIO3 */
|
|
|
|
default:
|
|
|
|
error("GPIO %d, associated with expansion pin %d, is disabled",
|
|
|
|
pin, GPIO_DEV_NUMBER(pin));
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
arm_gpio_init(gpio_dev);
|
|
|
|
(void)arm_gpio_config(gpio_dev, ARM_GPIO_ACCESS_PIN,
|
|
|
|
GPIO_PIN_NUMBER(pin), flags);
|
2017-06-14 09:16:47 +00:00
|
|
|
}
|
2017-04-06 08:09:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void pin_mode(PinName pin, PinMode mode)
|
|
|
|
{
|
2017-12-13 13:28:54 +00:00
|
|
|
MBED_ASSERT(pin != NC);
|
2017-04-06 08:09:03 +00:00
|
|
|
|
2017-12-13 13:28:54 +00:00
|
|
|
/* PinMode is not supported */
|
2017-04-06 08:09:03 +00:00
|
|
|
}
|