![](/media/cache/img/default_profile.jpg.50x50_q85.jpg)
Color Oled(SSD1331) connect to STMicroelectronics Nucleo-F466
mbed-os/targets/TARGET_Atmel/TARGET_SAM_CortexM4/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) 2006-2015 ARM Limited |
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 | #include "mbed_assert.h" |
kadonotakashi | 0:8fdf9a60065b | 17 | #include "PinNames.h" |
kadonotakashi | 0:8fdf9a60065b | 18 | #include "gpio_object.h" |
kadonotakashi | 0:8fdf9a60065b | 19 | #include "gpio_api.h" |
kadonotakashi | 0:8fdf9a60065b | 20 | #include "compiler.h" |
kadonotakashi | 0:8fdf9a60065b | 21 | #include "ioport.h" |
kadonotakashi | 0:8fdf9a60065b | 22 | |
kadonotakashi | 0:8fdf9a60065b | 23 | extern uint8_t g_sys_init; |
kadonotakashi | 0:8fdf9a60065b | 24 | |
kadonotakashi | 0:8fdf9a60065b | 25 | uint32_t gpio_set(PinName pin) |
kadonotakashi | 0:8fdf9a60065b | 26 | { |
kadonotakashi | 0:8fdf9a60065b | 27 | MBED_ASSERT(pin != (PinName)NC); |
kadonotakashi | 0:8fdf9a60065b | 28 | return (1UL << (pin % 32)); |
kadonotakashi | 0:8fdf9a60065b | 29 | } |
kadonotakashi | 0:8fdf9a60065b | 30 | |
kadonotakashi | 0:8fdf9a60065b | 31 | void gpio_init(gpio_t *obj, PinName pin) |
kadonotakashi | 0:8fdf9a60065b | 32 | { |
kadonotakashi | 0:8fdf9a60065b | 33 | MBED_ASSERT(pin != (PinName)NC); |
kadonotakashi | 0:8fdf9a60065b | 34 | if (g_sys_init == 0) { |
kadonotakashi | 0:8fdf9a60065b | 35 | sysclk_init(); |
kadonotakashi | 0:8fdf9a60065b | 36 | system_board_init(); |
kadonotakashi | 0:8fdf9a60065b | 37 | g_sys_init = 1; |
kadonotakashi | 0:8fdf9a60065b | 38 | } |
kadonotakashi | 0:8fdf9a60065b | 39 | obj->pin = pin; |
kadonotakashi | 0:8fdf9a60065b | 40 | |
kadonotakashi | 0:8fdf9a60065b | 41 | ioport_set_pin_dir(pin, IOPORT_DIR_INPUT); |
kadonotakashi | 0:8fdf9a60065b | 42 | ioport_set_pin_mode(pin, IOPORT_MODE_PULLUP); |
kadonotakashi | 0:8fdf9a60065b | 43 | } |
kadonotakashi | 0:8fdf9a60065b | 44 | |
kadonotakashi | 0:8fdf9a60065b | 45 | void gpio_mode(gpio_t *obj, PinMode mode) |
kadonotakashi | 0:8fdf9a60065b | 46 | { |
kadonotakashi | 0:8fdf9a60065b | 47 | MBED_ASSERT(obj->pin != (PinName)NC); |
kadonotakashi | 0:8fdf9a60065b | 48 | obj->mode = mode; |
kadonotakashi | 0:8fdf9a60065b | 49 | switch (mode) { |
kadonotakashi | 0:8fdf9a60065b | 50 | case PullNone : |
kadonotakashi | 0:8fdf9a60065b | 51 | ioport_set_pin_mode(obj->pin, IOPORT_MODE_OPEN_DRAIN); |
kadonotakashi | 0:8fdf9a60065b | 52 | break; |
kadonotakashi | 0:8fdf9a60065b | 53 | case PullUp: |
kadonotakashi | 0:8fdf9a60065b | 54 | ioport_set_pin_mode(obj->pin, IOPORT_MODE_PULLUP); |
kadonotakashi | 0:8fdf9a60065b | 55 | break; |
kadonotakashi | 0:8fdf9a60065b | 56 | case PullDown: |
kadonotakashi | 0:8fdf9a60065b | 57 | ioport_set_pin_mode(obj->pin, IOPORT_MODE_PULLDOWN); |
kadonotakashi | 0:8fdf9a60065b | 58 | break; |
kadonotakashi | 0:8fdf9a60065b | 59 | } |
kadonotakashi | 0:8fdf9a60065b | 60 | } |
kadonotakashi | 0:8fdf9a60065b | 61 | |
kadonotakashi | 0:8fdf9a60065b | 62 | void gpio_dir(gpio_t *obj, PinDirection direction) |
kadonotakashi | 0:8fdf9a60065b | 63 | { |
kadonotakashi | 0:8fdf9a60065b | 64 | MBED_ASSERT(obj->pin != (PinName)NC); |
kadonotakashi | 0:8fdf9a60065b | 65 | obj->direction = direction; |
kadonotakashi | 0:8fdf9a60065b | 66 | switch (direction) { |
kadonotakashi | 0:8fdf9a60065b | 67 | case PIN_INPUT : |
kadonotakashi | 0:8fdf9a60065b | 68 | ioport_set_pin_dir(obj->pin, IOPORT_DIR_INPUT); |
kadonotakashi | 0:8fdf9a60065b | 69 | break; |
kadonotakashi | 0:8fdf9a60065b | 70 | case PIN_OUTPUT: |
kadonotakashi | 0:8fdf9a60065b | 71 | ioport_set_pin_dir(obj->pin, IOPORT_DIR_OUTPUT); |
kadonotakashi | 0:8fdf9a60065b | 72 | break; |
kadonotakashi | 0:8fdf9a60065b | 73 | case PIN_INPUT_OUTPUT: |
kadonotakashi | 0:8fdf9a60065b | 74 | ioport_set_pin_dir(obj->pin, IOPORT_DIR_OUTPUT); |
kadonotakashi | 0:8fdf9a60065b | 75 | break; |
kadonotakashi | 0:8fdf9a60065b | 76 | } |
kadonotakashi | 0:8fdf9a60065b | 77 | } |