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