mbed library sources
Dependents: Encrypted my_mbed lklk CyaSSL_DTLS_Cellular ... more
Superseded
This library was superseded by mbed-dev - https://os.mbed.com/users/mbed_official/code/mbed-dev/.
Development branch of the mbed library sources. This library is kept in synch with the latest changes from the mbed SDK and it is not guaranteed to work.
If you are looking for a stable and tested release, please import one of the official mbed library releases:
Import librarymbed
The official Mbed 2 C/C++ SDK provides the software platform and libraries to build your applications.
targets/hal/TARGET_ARM_SSG/TARGET_MPS2/gpio_api.c@580:3c14cb9b87c5, 2015-07-02 (annotated)
- Committer:
- mbed_official
- Date:
- Thu Jul 02 16:15:09 2015 +0100
- Revision:
- 580:3c14cb9b87c5
Synchronized with git revision 213caf296f26963a7bea129b8ec4f33bbd1e6588
Full URL: https://github.com/mbedmicro/mbed/commit/213caf296f26963a7bea129b8ec4f33bbd1e6588/
commit of mps2
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mbed_official | 580:3c14cb9b87c5 | 1 | /* mbed Microcontroller Library |
mbed_official | 580:3c14cb9b87c5 | 2 | * Copyright (c) 2006-2015 ARM Limited |
mbed_official | 580:3c14cb9b87c5 | 3 | * |
mbed_official | 580:3c14cb9b87c5 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
mbed_official | 580:3c14cb9b87c5 | 5 | * you may not use this file except in compliance with the License. |
mbed_official | 580:3c14cb9b87c5 | 6 | * You may obtain a copy of the License at |
mbed_official | 580:3c14cb9b87c5 | 7 | * |
mbed_official | 580:3c14cb9b87c5 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
mbed_official | 580:3c14cb9b87c5 | 9 | * |
mbed_official | 580:3c14cb9b87c5 | 10 | * Unless required by applicable law or agreed to in writing, software |
mbed_official | 580:3c14cb9b87c5 | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
mbed_official | 580:3c14cb9b87c5 | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
mbed_official | 580:3c14cb9b87c5 | 13 | * See the License for the specific language governing permissions and |
mbed_official | 580:3c14cb9b87c5 | 14 | * limitations under the License. |
mbed_official | 580:3c14cb9b87c5 | 15 | */ |
mbed_official | 580:3c14cb9b87c5 | 16 | #include "gpio_api.h" |
mbed_official | 580:3c14cb9b87c5 | 17 | #include "pinmap.h" |
mbed_official | 580:3c14cb9b87c5 | 18 | |
mbed_official | 580:3c14cb9b87c5 | 19 | // function to enable the GPIO pin |
mbed_official | 580:3c14cb9b87c5 | 20 | uint32_t gpio_set(PinName pin) { |
mbed_official | 580:3c14cb9b87c5 | 21 | return (1); |
mbed_official | 580:3c14cb9b87c5 | 22 | } |
mbed_official | 580:3c14cb9b87c5 | 23 | |
mbed_official | 580:3c14cb9b87c5 | 24 | //function to initialise the gpio pin |
mbed_official | 580:3c14cb9b87c5 | 25 | // this links the board control bits for each pin |
mbed_official | 580:3c14cb9b87c5 | 26 | // with the object created for the pin |
mbed_official | 580:3c14cb9b87c5 | 27 | void gpio_init(gpio_t *obj, PinName pin) { |
mbed_official | 580:3c14cb9b87c5 | 28 | if(pin == NC){ return;} |
mbed_official | 580:3c14cb9b87c5 | 29 | else { |
mbed_official | 580:3c14cb9b87c5 | 30 | int pin_value = 0; |
mbed_official | 580:3c14cb9b87c5 | 31 | obj->pin = pin; |
mbed_official | 580:3c14cb9b87c5 | 32 | if(pin <=15){ |
mbed_official | 580:3c14cb9b87c5 | 33 | pin_value = pin; |
mbed_official | 580:3c14cb9b87c5 | 34 | }else if (pin >= 16 && pin <= 31){ |
mbed_official | 580:3c14cb9b87c5 | 35 | pin_value = pin-16; |
mbed_official | 580:3c14cb9b87c5 | 36 | }else if (pin >= 32 && pin <= 47){ |
mbed_official | 580:3c14cb9b87c5 | 37 | pin_value = pin-32; |
mbed_official | 580:3c14cb9b87c5 | 38 | }else if (pin >= 48 && pin <= 51){ |
mbed_official | 580:3c14cb9b87c5 | 39 | pin_value = pin-48; |
mbed_official | 580:3c14cb9b87c5 | 40 | }else if (pin == 100 || pin == 101){ |
mbed_official | 580:3c14cb9b87c5 | 41 | pin_value = pin-100; |
mbed_official | 580:3c14cb9b87c5 | 42 | }else if (pin == 110 || pin == 111){ |
mbed_official | 580:3c14cb9b87c5 | 43 | pin_value = pin-110; |
mbed_official | 580:3c14cb9b87c5 | 44 | }else if (pin >= 200 && pin <= 207){ |
mbed_official | 580:3c14cb9b87c5 | 45 | pin_value = pin-200; |
mbed_official | 580:3c14cb9b87c5 | 46 | }else if (pin >= 210 && pin <= 217){ |
mbed_official | 580:3c14cb9b87c5 | 47 | pin_value = pin-210; |
mbed_official | 580:3c14cb9b87c5 | 48 | }else if (pin == 303){ |
mbed_official | 580:3c14cb9b87c5 | 49 | pin_value = pin-302; |
mbed_official | 580:3c14cb9b87c5 | 50 | }else if (pin == 307){ |
mbed_official | 580:3c14cb9b87c5 | 51 | pin_value = pin-307; |
mbed_official | 580:3c14cb9b87c5 | 52 | }else if (pin == 308){ |
mbed_official | 580:3c14cb9b87c5 | 53 | pin_value = pin-305; |
mbed_official | 580:3c14cb9b87c5 | 54 | }else if (pin == 309){ |
mbed_official | 580:3c14cb9b87c5 | 55 | pin_value = pin-305; |
mbed_official | 580:3c14cb9b87c5 | 56 | }else if (pin == 310){ |
mbed_official | 580:3c14cb9b87c5 | 57 | pin_value = pin-305; |
mbed_official | 580:3c14cb9b87c5 | 58 | }else if (pin == 311){ |
mbed_official | 580:3c14cb9b87c5 | 59 | pin_value = pin-305; |
mbed_official | 580:3c14cb9b87c5 | 60 | } |
mbed_official | 580:3c14cb9b87c5 | 61 | |
mbed_official | 580:3c14cb9b87c5 | 62 | obj->mask = 0x1 << pin_value; |
mbed_official | 580:3c14cb9b87c5 | 63 | obj->pin_number = pin; |
mbed_official | 580:3c14cb9b87c5 | 64 | if(pin <=15) { |
mbed_official | 580:3c14cb9b87c5 | 65 | obj->reg_data = &CMSDK_GPIO0->DATAOUT ; |
mbed_official | 580:3c14cb9b87c5 | 66 | obj->reg_in = &CMSDK_GPIO0->DATA ; |
mbed_official | 580:3c14cb9b87c5 | 67 | obj->reg_dir = &CMSDK_GPIO0->OUTENABLESET ; |
mbed_official | 580:3c14cb9b87c5 | 68 | obj->reg_dirclr = &CMSDK_GPIO0->OUTENABLECLR ; |
mbed_official | 580:3c14cb9b87c5 | 69 | } else if (pin >= 16 && pin <= 31){ |
mbed_official | 580:3c14cb9b87c5 | 70 | obj->reg_data = &CMSDK_GPIO1->DATAOUT ; |
mbed_official | 580:3c14cb9b87c5 | 71 | obj->reg_in = &CMSDK_GPIO1->DATA ; |
mbed_official | 580:3c14cb9b87c5 | 72 | obj->reg_dir = &CMSDK_GPIO1->OUTENABLESET ; |
mbed_official | 580:3c14cb9b87c5 | 73 | obj->reg_dirclr = &CMSDK_GPIO1->OUTENABLECLR ; |
mbed_official | 580:3c14cb9b87c5 | 74 | } else if (pin >= 32 && pin <= 47){ |
mbed_official | 580:3c14cb9b87c5 | 75 | obj->reg_data = &CMSDK_GPIO2->DATAOUT; |
mbed_official | 580:3c14cb9b87c5 | 76 | obj->reg_in = &CMSDK_GPIO2->DATA; |
mbed_official | 580:3c14cb9b87c5 | 77 | obj->reg_dir = &CMSDK_GPIO2->OUTENABLESET ; |
mbed_official | 580:3c14cb9b87c5 | 78 | obj->reg_dirclr = &CMSDK_GPIO2->OUTENABLECLR ; |
mbed_official | 580:3c14cb9b87c5 | 79 | } else if (pin >= 48 && pin <= 51){ |
mbed_official | 580:3c14cb9b87c5 | 80 | obj->reg_data = &CMSDK_GPIO3->DATAOUT; |
mbed_official | 580:3c14cb9b87c5 | 81 | obj->reg_in = &CMSDK_GPIO3->DATA; |
mbed_official | 580:3c14cb9b87c5 | 82 | obj->reg_dir = &CMSDK_GPIO3->OUTENABLESET ; |
mbed_official | 580:3c14cb9b87c5 | 83 | obj->reg_dirclr = &CMSDK_GPIO3->OUTENABLECLR ; |
mbed_official | 580:3c14cb9b87c5 | 84 | } else if (pin == 100 || pin == 101){ |
mbed_official | 580:3c14cb9b87c5 | 85 | obj->reg_data = &MPS2_FPGAIO->LED; //user leds |
mbed_official | 580:3c14cb9b87c5 | 86 | obj->reg_in = &MPS2_FPGAIO->LED; |
mbed_official | 580:3c14cb9b87c5 | 87 | } else if (pin == 110 || pin == 111){ |
mbed_official | 580:3c14cb9b87c5 | 88 | obj->reg_data = &MPS2_FPGAIO->BUTTON; //user switches |
mbed_official | 580:3c14cb9b87c5 | 89 | obj->reg_in = &MPS2_FPGAIO->BUTTON; //user switches |
mbed_official | 580:3c14cb9b87c5 | 90 | }else if (pin >= 200 && pin <= 207){ |
mbed_official | 580:3c14cb9b87c5 | 91 | obj->reg_data = &MPS2_SCC->LEDS; //mcc leds |
mbed_official | 580:3c14cb9b87c5 | 92 | obj->reg_in = &MPS2_SCC->LEDS; //mcc leds |
mbed_official | 580:3c14cb9b87c5 | 93 | }else if (pin >= 210 && pin <= 217){ |
mbed_official | 580:3c14cb9b87c5 | 94 | obj->reg_in = &MPS2_SCC->SWITCHES; //mcc switches |
mbed_official | 580:3c14cb9b87c5 | 95 | }else if (pin == 303 || pin == 307){ |
mbed_official | 580:3c14cb9b87c5 | 96 | obj->reg_data = &MPS2_FPGAIO->MISC; //spi chip select = 303, clcd chip select = 307 |
mbed_official | 580:3c14cb9b87c5 | 97 | }else if (pin == 308 || pin == 309 || pin == 310 || pin == 311){ |
mbed_official | 580:3c14cb9b87c5 | 98 | obj->reg_data = &MPS2_FPGAIO->MISC; //clcd control bits |
mbed_official | 580:3c14cb9b87c5 | 99 | } |
mbed_official | 580:3c14cb9b87c5 | 100 | } |
mbed_official | 580:3c14cb9b87c5 | 101 | } |
mbed_official | 580:3c14cb9b87c5 | 102 | |
mbed_official | 580:3c14cb9b87c5 | 103 | void gpio_mode(gpio_t *obj, PinMode mode) { |
mbed_official | 580:3c14cb9b87c5 | 104 | pin_mode(obj->pin, mode); |
mbed_official | 580:3c14cb9b87c5 | 105 | } |
mbed_official | 580:3c14cb9b87c5 | 106 | |
mbed_official | 580:3c14cb9b87c5 | 107 | void gpio_dir(gpio_t *obj, PinDirection direction) { |
mbed_official | 580:3c14cb9b87c5 | 108 | if(obj->pin >= 0 && obj->pin <= 51) |
mbed_official | 580:3c14cb9b87c5 | 109 | { |
mbed_official | 580:3c14cb9b87c5 | 110 | switch (direction) { |
mbed_official | 580:3c14cb9b87c5 | 111 | case PIN_INPUT : *obj->reg_dirclr = obj->mask; break; |
mbed_official | 580:3c14cb9b87c5 | 112 | case PIN_OUTPUT: *obj->reg_dir |= obj->mask; break; |
mbed_official | 580:3c14cb9b87c5 | 113 | } |
mbed_official | 580:3c14cb9b87c5 | 114 | } else {return;} |
mbed_official | 580:3c14cb9b87c5 | 115 | } |
mbed_official | 580:3c14cb9b87c5 | 116 | |
mbed_official | 580:3c14cb9b87c5 | 117 | int gpio_is_connected(const gpio_t *obj){ |
mbed_official | 580:3c14cb9b87c5 | 118 | if(obj->pin != (PinName)NC){ |
mbed_official | 580:3c14cb9b87c5 | 119 | return 1; |
mbed_official | 580:3c14cb9b87c5 | 120 | } else { |
mbed_official | 580:3c14cb9b87c5 | 121 | return 0; |
mbed_official | 580:3c14cb9b87c5 | 122 | } |
mbed_official | 580:3c14cb9b87c5 | 123 | } |
mbed_official | 580:3c14cb9b87c5 | 124 |