![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Color Oled(SSD1331) connect to STMicroelectronics Nucleo-F466
mbed-os/targets/TARGET_NUVOTON/TARGET_NANO100/gpio_api.c@0:8fdf9a60065b, 2018-10-10 (annotated)
- Committer:
- kadonotakashi
- Date:
- Wed Oct 10 00:33:53 2018 +0000
- Revision:
- 0:8fdf9a60065b
how to make mbed librry
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
kadonotakashi | 0:8fdf9a60065b | 1 | /* mbed Microcontroller Library |
kadonotakashi | 0:8fdf9a60065b | 2 | * Copyright (c) 2015-2017 Nuvoton |
kadonotakashi | 0:8fdf9a60065b | 3 | * |
kadonotakashi | 0:8fdf9a60065b | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
kadonotakashi | 0:8fdf9a60065b | 5 | * you may not use this file except in compliance with the License. |
kadonotakashi | 0:8fdf9a60065b | 6 | * You may obtain a copy of the License at |
kadonotakashi | 0:8fdf9a60065b | 7 | * |
kadonotakashi | 0:8fdf9a60065b | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
kadonotakashi | 0:8fdf9a60065b | 9 | * |
kadonotakashi | 0:8fdf9a60065b | 10 | * Unless required by applicable law or agreed to in writing, software |
kadonotakashi | 0:8fdf9a60065b | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
kadonotakashi | 0:8fdf9a60065b | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
kadonotakashi | 0:8fdf9a60065b | 13 | * See the License for the specific language governing permissions and |
kadonotakashi | 0:8fdf9a60065b | 14 | * limitations under the License. |
kadonotakashi | 0:8fdf9a60065b | 15 | */ |
kadonotakashi | 0:8fdf9a60065b | 16 | |
kadonotakashi | 0:8fdf9a60065b | 17 | #include "gpio_api.h" |
kadonotakashi | 0:8fdf9a60065b | 18 | #include "mbed_assert.h" |
kadonotakashi | 0:8fdf9a60065b | 19 | #include "pinmap.h" |
kadonotakashi | 0:8fdf9a60065b | 20 | #include "mbed_error.h" |
kadonotakashi | 0:8fdf9a60065b | 21 | #include "PeripheralPins.h" |
kadonotakashi | 0:8fdf9a60065b | 22 | |
kadonotakashi | 0:8fdf9a60065b | 23 | uint32_t gpio_set(PinName pin) |
kadonotakashi | 0:8fdf9a60065b | 24 | { |
kadonotakashi | 0:8fdf9a60065b | 25 | if (pin == (PinName) NC) { |
kadonotakashi | 0:8fdf9a60065b | 26 | return 0; |
kadonotakashi | 0:8fdf9a60065b | 27 | } |
kadonotakashi | 0:8fdf9a60065b | 28 | |
kadonotakashi | 0:8fdf9a60065b | 29 | uint32_t pin_index = NU_PINNAME_TO_PIN(pin); |
kadonotakashi | 0:8fdf9a60065b | 30 | |
kadonotakashi | 0:8fdf9a60065b | 31 | // GPIO PinMap |
kadonotakashi | 0:8fdf9a60065b | 32 | pin_function(pin, 0 << NU_MFP_POS(pin_index)); |
kadonotakashi | 0:8fdf9a60065b | 33 | |
kadonotakashi | 0:8fdf9a60065b | 34 | return (uint32_t)(1 << pin_index); // Return the pin mask |
kadonotakashi | 0:8fdf9a60065b | 35 | } |
kadonotakashi | 0:8fdf9a60065b | 36 | |
kadonotakashi | 0:8fdf9a60065b | 37 | int gpio_is_connected(const gpio_t *obj) |
kadonotakashi | 0:8fdf9a60065b | 38 | { |
kadonotakashi | 0:8fdf9a60065b | 39 | return (obj->pin != (PinName) NC); |
kadonotakashi | 0:8fdf9a60065b | 40 | } |
kadonotakashi | 0:8fdf9a60065b | 41 | |
kadonotakashi | 0:8fdf9a60065b | 42 | void gpio_init(gpio_t *obj, PinName pin) |
kadonotakashi | 0:8fdf9a60065b | 43 | { |
kadonotakashi | 0:8fdf9a60065b | 44 | obj->pin = pin; |
kadonotakashi | 0:8fdf9a60065b | 45 | |
kadonotakashi | 0:8fdf9a60065b | 46 | if (obj->pin == (PinName) NC) { |
kadonotakashi | 0:8fdf9a60065b | 47 | return; |
kadonotakashi | 0:8fdf9a60065b | 48 | } |
kadonotakashi | 0:8fdf9a60065b | 49 | |
kadonotakashi | 0:8fdf9a60065b | 50 | obj->mask = gpio_set(pin); |
kadonotakashi | 0:8fdf9a60065b | 51 | /* Default mode/direction */ |
kadonotakashi | 0:8fdf9a60065b | 52 | obj->mode = PullUp; |
kadonotakashi | 0:8fdf9a60065b | 53 | obj->direction = PIN_INPUT; |
kadonotakashi | 0:8fdf9a60065b | 54 | } |
kadonotakashi | 0:8fdf9a60065b | 55 | |
kadonotakashi | 0:8fdf9a60065b | 56 | void gpio_mode(gpio_t *obj, PinMode mode) |
kadonotakashi | 0:8fdf9a60065b | 57 | { |
kadonotakashi | 0:8fdf9a60065b | 58 | if (obj->pin == (PinName) NC) { |
kadonotakashi | 0:8fdf9a60065b | 59 | return; |
kadonotakashi | 0:8fdf9a60065b | 60 | } |
kadonotakashi | 0:8fdf9a60065b | 61 | |
kadonotakashi | 0:8fdf9a60065b | 62 | switch (mode) { |
kadonotakashi | 0:8fdf9a60065b | 63 | case PullNone: |
kadonotakashi | 0:8fdf9a60065b | 64 | case PullDown: |
kadonotakashi | 0:8fdf9a60065b | 65 | case PullUp: |
kadonotakashi | 0:8fdf9a60065b | 66 | /* H/W doesn't support separate configuration for input pull mode/direction. |
kadonotakashi | 0:8fdf9a60065b | 67 | * We translate to input-only/push-pull output I/O mode dependent on direction. */ |
kadonotakashi | 0:8fdf9a60065b | 68 | obj->mode = (obj->direction == PIN_INPUT) ? InputOnly : PushPullOutput; |
kadonotakashi | 0:8fdf9a60065b | 69 | break; |
kadonotakashi | 0:8fdf9a60065b | 70 | |
kadonotakashi | 0:8fdf9a60065b | 71 | |
kadonotakashi | 0:8fdf9a60065b | 72 | case InputOnly: |
kadonotakashi | 0:8fdf9a60065b | 73 | case PushPullOutput: |
kadonotakashi | 0:8fdf9a60065b | 74 | /* We may meet contradictory I/O mode/direction configuration. Favor I/O mode |
kadonotakashi | 0:8fdf9a60065b | 75 | * in the gpio_mode call here. */ |
kadonotakashi | 0:8fdf9a60065b | 76 | if (mode == InputOnly) { |
kadonotakashi | 0:8fdf9a60065b | 77 | obj->direction = PIN_INPUT; |
kadonotakashi | 0:8fdf9a60065b | 78 | obj->mode = InputOnly; |
kadonotakashi | 0:8fdf9a60065b | 79 | } else { |
kadonotakashi | 0:8fdf9a60065b | 80 | obj->direction = PIN_OUTPUT; |
kadonotakashi | 0:8fdf9a60065b | 81 | obj->mode = PushPullOutput; |
kadonotakashi | 0:8fdf9a60065b | 82 | } |
kadonotakashi | 0:8fdf9a60065b | 83 | break; |
kadonotakashi | 0:8fdf9a60065b | 84 | |
kadonotakashi | 0:8fdf9a60065b | 85 | default: |
kadonotakashi | 0:8fdf9a60065b | 86 | /* Allow for configuring other I/O modes directly */ |
kadonotakashi | 0:8fdf9a60065b | 87 | obj->mode = mode; |
kadonotakashi | 0:8fdf9a60065b | 88 | break; |
kadonotakashi | 0:8fdf9a60065b | 89 | } |
kadonotakashi | 0:8fdf9a60065b | 90 | |
kadonotakashi | 0:8fdf9a60065b | 91 | pin_mode(obj->pin, obj->mode); |
kadonotakashi | 0:8fdf9a60065b | 92 | } |
kadonotakashi | 0:8fdf9a60065b | 93 | |
kadonotakashi | 0:8fdf9a60065b | 94 | void gpio_dir(gpio_t *obj, PinDirection direction) |
kadonotakashi | 0:8fdf9a60065b | 95 | { |
kadonotakashi | 0:8fdf9a60065b | 96 | if (obj->pin == (PinName) NC) { |
kadonotakashi | 0:8fdf9a60065b | 97 | return; |
kadonotakashi | 0:8fdf9a60065b | 98 | } |
kadonotakashi | 0:8fdf9a60065b | 99 | |
kadonotakashi | 0:8fdf9a60065b | 100 | obj->direction = direction; |
kadonotakashi | 0:8fdf9a60065b | 101 | |
kadonotakashi | 0:8fdf9a60065b | 102 | switch (obj->mode) { |
kadonotakashi | 0:8fdf9a60065b | 103 | case PullNone: |
kadonotakashi | 0:8fdf9a60065b | 104 | case PullDown: |
kadonotakashi | 0:8fdf9a60065b | 105 | case PullUp: |
kadonotakashi | 0:8fdf9a60065b | 106 | /* H/W doesn't support separate configuration for input pull mode/direction. |
kadonotakashi | 0:8fdf9a60065b | 107 | * We translate to input-only/push-pull output I/O mode dependent on direction. */ |
kadonotakashi | 0:8fdf9a60065b | 108 | obj->mode = (obj->direction == PIN_INPUT) ? InputOnly : PushPullOutput; |
kadonotakashi | 0:8fdf9a60065b | 109 | break; |
kadonotakashi | 0:8fdf9a60065b | 110 | |
kadonotakashi | 0:8fdf9a60065b | 111 | case InputOnly: |
kadonotakashi | 0:8fdf9a60065b | 112 | case PushPullOutput: |
kadonotakashi | 0:8fdf9a60065b | 113 | /* We may meet contradictory I/O mode/direction configuration. Favor direction |
kadonotakashi | 0:8fdf9a60065b | 114 | * in the gpio_dir call here. */ |
kadonotakashi | 0:8fdf9a60065b | 115 | obj->mode = (obj->direction == PIN_INPUT) ? InputOnly : PushPullOutput; |
kadonotakashi | 0:8fdf9a60065b | 116 | break; |
kadonotakashi | 0:8fdf9a60065b | 117 | |
kadonotakashi | 0:8fdf9a60065b | 118 | default: |
kadonotakashi | 0:8fdf9a60065b | 119 | break; |
kadonotakashi | 0:8fdf9a60065b | 120 | } |
kadonotakashi | 0:8fdf9a60065b | 121 | |
kadonotakashi | 0:8fdf9a60065b | 122 | pin_mode(obj->pin, obj->mode); |
kadonotakashi | 0:8fdf9a60065b | 123 | } |