Forked mbed-dev as I use an 20 pins stm32F042 and not the 32 pins version
Fork of mbed-dev by
targets/TARGET_ublox/TARGET_HI2110/gpio_api.c@153:0a78729d3229, 2017-01-22 (annotated)
- Committer:
- riktw
- Date:
- Sun Jan 22 22:20:36 2017 +0000
- Revision:
- 153:0a78729d3229
- Parent:
- 150:02e0a0aed4ec
Back to 8Mhz clock. Revision 1.0
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
<> | 150:02e0a0aed4ec | 1 | /* mbed Microcontroller Library |
<> | 150:02e0a0aed4ec | 2 | * Copyright (c) 2016 u-blox |
<> | 150:02e0a0aed4ec | 3 | * |
<> | 150:02e0a0aed4ec | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
<> | 150:02e0a0aed4ec | 5 | * you may not use this file except in compliance with the License. |
<> | 150:02e0a0aed4ec | 6 | * You may obtain a copy of the License at |
<> | 150:02e0a0aed4ec | 7 | * |
<> | 150:02e0a0aed4ec | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
<> | 150:02e0a0aed4ec | 9 | * |
<> | 150:02e0a0aed4ec | 10 | * Unless required by applicable law or agreed to in writing, software |
<> | 150:02e0a0aed4ec | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
<> | 150:02e0a0aed4ec | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
<> | 150:02e0a0aed4ec | 13 | * See the License for the specific language governing permissions and |
<> | 150:02e0a0aed4ec | 14 | * limitations under the License. |
<> | 150:02e0a0aed4ec | 15 | */ |
<> | 150:02e0a0aed4ec | 16 | |
<> | 150:02e0a0aed4ec | 17 | #include "mbed_assert.h" |
<> | 150:02e0a0aed4ec | 18 | #include "gpio_api.h" |
<> | 150:02e0a0aed4ec | 19 | #include "pinmap.h" |
<> | 150:02e0a0aed4ec | 20 | |
<> | 150:02e0a0aed4ec | 21 | /* ---------------------------------------------------------------- |
<> | 150:02e0a0aed4ec | 22 | * MACROS |
<> | 150:02e0a0aed4ec | 23 | * ----------------------------------------------------------------*/ |
<> | 150:02e0a0aed4ec | 24 | |
<> | 150:02e0a0aed4ec | 25 | /* ---------------------------------------------------------------- |
<> | 150:02e0a0aed4ec | 26 | * TYPES |
<> | 150:02e0a0aed4ec | 27 | * ----------------------------------------------------------------*/ |
<> | 150:02e0a0aed4ec | 28 | |
<> | 150:02e0a0aed4ec | 29 | /* ---------------------------------------------------------------- |
<> | 150:02e0a0aed4ec | 30 | * GLOBAL VARIABLES |
<> | 150:02e0a0aed4ec | 31 | * ----------------------------------------------------------------*/ |
<> | 150:02e0a0aed4ec | 32 | |
<> | 150:02e0a0aed4ec | 33 | /* ---------------------------------------------------------------- |
<> | 150:02e0a0aed4ec | 34 | * MBED API CALLS |
<> | 150:02e0a0aed4ec | 35 | * ----------------------------------------------------------------*/ |
<> | 150:02e0a0aed4ec | 36 | |
<> | 150:02e0a0aed4ec | 37 | void gpio_init(gpio_t *obj, PinName pin) |
<> | 150:02e0a0aed4ec | 38 | { |
<> | 150:02e0a0aed4ec | 39 | if (pin == (PinName)NC) { |
<> | 150:02e0a0aed4ec | 40 | return; |
<> | 150:02e0a0aed4ec | 41 | } |
<> | 150:02e0a0aed4ec | 42 | |
<> | 150:02e0a0aed4ec | 43 | MBED_ASSERT (pin < NUM_PINS); |
<> | 150:02e0a0aed4ec | 44 | |
<> | 150:02e0a0aed4ec | 45 | obj->pin = pin; |
<> | 150:02e0a0aed4ec | 46 | obj->mask = (1ul << pin); |
<> | 150:02e0a0aed4ec | 47 | |
<> | 150:02e0a0aed4ec | 48 | obj->reg_set = &GPIO_OUT_BITSET; |
<> | 150:02e0a0aed4ec | 49 | obj->reg_clr = &GPIO_OUT_BITCLR; |
<> | 150:02e0a0aed4ec | 50 | obj->reg_val = &GPIO_VALUE; |
<> | 150:02e0a0aed4ec | 51 | obj->reg_dir = &GPIO_DIR; |
<> | 150:02e0a0aed4ec | 52 | |
<> | 150:02e0a0aed4ec | 53 | /* Claim the pin */ |
<> | 150:02e0a0aed4ec | 54 | pin_function(pin, PIN_FUNCTION_GPIO); |
<> | 150:02e0a0aed4ec | 55 | } |
<> | 150:02e0a0aed4ec | 56 | |
<> | 150:02e0a0aed4ec | 57 | void gpio_mode(gpio_t *obj, PinMode mode) |
<> | 150:02e0a0aed4ec | 58 | { |
<> | 150:02e0a0aed4ec | 59 | pin_mode(obj->pin, mode); |
<> | 150:02e0a0aed4ec | 60 | } |
<> | 150:02e0a0aed4ec | 61 | |
<> | 150:02e0a0aed4ec | 62 | void gpio_dir(gpio_t *obj, PinDirection direction) |
<> | 150:02e0a0aed4ec | 63 | { |
<> | 150:02e0a0aed4ec | 64 | MBED_ASSERT(obj->pin != (PinName)NC); |
<> | 150:02e0a0aed4ec | 65 | |
<> | 150:02e0a0aed4ec | 66 | switch (direction) { |
<> | 150:02e0a0aed4ec | 67 | case PIN_INPUT: |
<> | 150:02e0a0aed4ec | 68 | { |
<> | 150:02e0a0aed4ec | 69 | *(obj->reg_dir) &= ~(obj->mask); |
<> | 150:02e0a0aed4ec | 70 | } |
<> | 150:02e0a0aed4ec | 71 | break; |
<> | 150:02e0a0aed4ec | 72 | case PIN_OUTPUT: |
<> | 150:02e0a0aed4ec | 73 | { |
<> | 150:02e0a0aed4ec | 74 | *(obj->reg_dir) |= obj->mask; |
<> | 150:02e0a0aed4ec | 75 | } |
<> | 150:02e0a0aed4ec | 76 | break; |
<> | 150:02e0a0aed4ec | 77 | /* TODO: looks as though the default is |
<> | 150:02e0a0aed4ec | 78 | * not normally trapped here */ |
<> | 150:02e0a0aed4ec | 79 | } |
<> | 150:02e0a0aed4ec | 80 | } |