Mouse code for the MacroRat
mbed-dev/hal/mbed_gpio.c@34:69342782fb68, 2017-05-26 (annotated)
- Committer:
- sahilmgandhi
- Date:
- Fri May 26 17:21:04 2017 +0000
- Revision:
- 34:69342782fb68
- Parent:
- 18:6a4db94011d3
Added small reverse turns before the break so that we can stop faster.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
sahilmgandhi | 18:6a4db94011d3 | 1 | /* mbed Microcontroller Library |
sahilmgandhi | 18:6a4db94011d3 | 2 | * Copyright (c) 2006-2013 ARM Limited |
sahilmgandhi | 18:6a4db94011d3 | 3 | * |
sahilmgandhi | 18:6a4db94011d3 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
sahilmgandhi | 18:6a4db94011d3 | 5 | * you may not use this file except in compliance with the License. |
sahilmgandhi | 18:6a4db94011d3 | 6 | * You may obtain a copy of the License at |
sahilmgandhi | 18:6a4db94011d3 | 7 | * |
sahilmgandhi | 18:6a4db94011d3 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
sahilmgandhi | 18:6a4db94011d3 | 9 | * |
sahilmgandhi | 18:6a4db94011d3 | 10 | * Unless required by applicable law or agreed to in writing, software |
sahilmgandhi | 18:6a4db94011d3 | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
sahilmgandhi | 18:6a4db94011d3 | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
sahilmgandhi | 18:6a4db94011d3 | 13 | * See the License for the specific language governing permissions and |
sahilmgandhi | 18:6a4db94011d3 | 14 | * limitations under the License. |
sahilmgandhi | 18:6a4db94011d3 | 15 | */ |
sahilmgandhi | 18:6a4db94011d3 | 16 | #include "hal/gpio_api.h" |
sahilmgandhi | 18:6a4db94011d3 | 17 | |
sahilmgandhi | 18:6a4db94011d3 | 18 | static inline void _gpio_init_in(gpio_t* gpio, PinName pin, PinMode mode) |
sahilmgandhi | 18:6a4db94011d3 | 19 | { |
sahilmgandhi | 18:6a4db94011d3 | 20 | gpio_init(gpio, pin); |
sahilmgandhi | 18:6a4db94011d3 | 21 | if (pin != NC) { |
sahilmgandhi | 18:6a4db94011d3 | 22 | gpio_dir(gpio, PIN_INPUT); |
sahilmgandhi | 18:6a4db94011d3 | 23 | gpio_mode(gpio, mode); |
sahilmgandhi | 18:6a4db94011d3 | 24 | } |
sahilmgandhi | 18:6a4db94011d3 | 25 | } |
sahilmgandhi | 18:6a4db94011d3 | 26 | |
sahilmgandhi | 18:6a4db94011d3 | 27 | static inline void _gpio_init_out(gpio_t* gpio, PinName pin, PinMode mode, int value) |
sahilmgandhi | 18:6a4db94011d3 | 28 | { |
sahilmgandhi | 18:6a4db94011d3 | 29 | gpio_init(gpio, pin); |
sahilmgandhi | 18:6a4db94011d3 | 30 | if (pin != NC) { |
sahilmgandhi | 18:6a4db94011d3 | 31 | gpio_write(gpio, value); |
sahilmgandhi | 18:6a4db94011d3 | 32 | gpio_dir(gpio, PIN_OUTPUT); |
sahilmgandhi | 18:6a4db94011d3 | 33 | gpio_mode(gpio, mode); |
sahilmgandhi | 18:6a4db94011d3 | 34 | } |
sahilmgandhi | 18:6a4db94011d3 | 35 | } |
sahilmgandhi | 18:6a4db94011d3 | 36 | |
sahilmgandhi | 18:6a4db94011d3 | 37 | void gpio_init_in(gpio_t* gpio, PinName pin) { |
sahilmgandhi | 18:6a4db94011d3 | 38 | gpio_init_in_ex(gpio, pin, PullDefault); |
sahilmgandhi | 18:6a4db94011d3 | 39 | } |
sahilmgandhi | 18:6a4db94011d3 | 40 | |
sahilmgandhi | 18:6a4db94011d3 | 41 | void gpio_init_in_ex(gpio_t* gpio, PinName pin, PinMode mode) { |
sahilmgandhi | 18:6a4db94011d3 | 42 | _gpio_init_in(gpio, pin, mode); |
sahilmgandhi | 18:6a4db94011d3 | 43 | } |
sahilmgandhi | 18:6a4db94011d3 | 44 | |
sahilmgandhi | 18:6a4db94011d3 | 45 | void gpio_init_out(gpio_t* gpio, PinName pin) { |
sahilmgandhi | 18:6a4db94011d3 | 46 | gpio_init_out_ex(gpio, pin, 0); |
sahilmgandhi | 18:6a4db94011d3 | 47 | } |
sahilmgandhi | 18:6a4db94011d3 | 48 | |
sahilmgandhi | 18:6a4db94011d3 | 49 | void gpio_init_out_ex(gpio_t* gpio, PinName pin, int value) { |
sahilmgandhi | 18:6a4db94011d3 | 50 | _gpio_init_out(gpio, pin, PullNone, value); |
sahilmgandhi | 18:6a4db94011d3 | 51 | } |
sahilmgandhi | 18:6a4db94011d3 | 52 | |
sahilmgandhi | 18:6a4db94011d3 | 53 | void gpio_init_inout(gpio_t* gpio, PinName pin, PinDirection direction, PinMode mode, int value) { |
sahilmgandhi | 18:6a4db94011d3 | 54 | if (direction == PIN_INPUT) { |
sahilmgandhi | 18:6a4db94011d3 | 55 | _gpio_init_in(gpio, pin, mode); |
sahilmgandhi | 18:6a4db94011d3 | 56 | if (pin != NC) |
sahilmgandhi | 18:6a4db94011d3 | 57 | gpio_write(gpio, value); // we prepare the value in case it is switched later |
sahilmgandhi | 18:6a4db94011d3 | 58 | } else { |
sahilmgandhi | 18:6a4db94011d3 | 59 | _gpio_init_out(gpio, pin, mode, value); |
sahilmgandhi | 18:6a4db94011d3 | 60 | } |
sahilmgandhi | 18:6a4db94011d3 | 61 | } |