Mouse code for the MacroRat
mbed-dev/targets/TARGET_ARM_SSG/TARGET_MPS2/gpio_api.c@18:6a4db94011d3, 2017-05-14 (annotated)
- Committer:
- sahilmgandhi
- Date:
- Sun May 14 23:18:57 2017 +0000
- Revision:
- 18:6a4db94011d3
Publishing again
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-2015 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 "gpio_api.h" |
sahilmgandhi | 18:6a4db94011d3 | 17 | #include "pinmap.h" |
sahilmgandhi | 18:6a4db94011d3 | 18 | |
sahilmgandhi | 18:6a4db94011d3 | 19 | // function to enable the GPIO pin |
sahilmgandhi | 18:6a4db94011d3 | 20 | uint32_t gpio_set(PinName pin) { |
sahilmgandhi | 18:6a4db94011d3 | 21 | return (1); |
sahilmgandhi | 18:6a4db94011d3 | 22 | } |
sahilmgandhi | 18:6a4db94011d3 | 23 | |
sahilmgandhi | 18:6a4db94011d3 | 24 | //function to initialise the gpio pin |
sahilmgandhi | 18:6a4db94011d3 | 25 | // this links the board control bits for each pin |
sahilmgandhi | 18:6a4db94011d3 | 26 | // with the object created for the pin |
sahilmgandhi | 18:6a4db94011d3 | 27 | void gpio_init(gpio_t *obj, PinName pin) { |
sahilmgandhi | 18:6a4db94011d3 | 28 | if(pin == NC){ return;} |
sahilmgandhi | 18:6a4db94011d3 | 29 | else { |
sahilmgandhi | 18:6a4db94011d3 | 30 | int pin_value = 0; |
sahilmgandhi | 18:6a4db94011d3 | 31 | obj->pin = pin; |
sahilmgandhi | 18:6a4db94011d3 | 32 | if(pin <=15){ |
sahilmgandhi | 18:6a4db94011d3 | 33 | pin_value = pin; |
sahilmgandhi | 18:6a4db94011d3 | 34 | }else if (pin >= 16 && pin <= 31){ |
sahilmgandhi | 18:6a4db94011d3 | 35 | pin_value = pin-16; |
sahilmgandhi | 18:6a4db94011d3 | 36 | }else if (pin >= 32 && pin <= 47){ |
sahilmgandhi | 18:6a4db94011d3 | 37 | pin_value = pin-32; |
sahilmgandhi | 18:6a4db94011d3 | 38 | }else if (pin >= 48 && pin <= 51){ |
sahilmgandhi | 18:6a4db94011d3 | 39 | pin_value = pin-48; |
sahilmgandhi | 18:6a4db94011d3 | 40 | }else if (pin == 100 || pin == 101){ |
sahilmgandhi | 18:6a4db94011d3 | 41 | pin_value = pin-100; |
sahilmgandhi | 18:6a4db94011d3 | 42 | }else if (pin == 110 || pin == 111){ |
sahilmgandhi | 18:6a4db94011d3 | 43 | pin_value = pin-110; |
sahilmgandhi | 18:6a4db94011d3 | 44 | }else if (pin >= 200 && pin <= 207){ |
sahilmgandhi | 18:6a4db94011d3 | 45 | pin_value = pin-200; |
sahilmgandhi | 18:6a4db94011d3 | 46 | }else if (pin >= 210 && pin <= 217){ |
sahilmgandhi | 18:6a4db94011d3 | 47 | pin_value = pin-210; |
sahilmgandhi | 18:6a4db94011d3 | 48 | }else if (pin == 303){ |
sahilmgandhi | 18:6a4db94011d3 | 49 | pin_value = pin-302; |
sahilmgandhi | 18:6a4db94011d3 | 50 | }else if (pin == 307){ |
sahilmgandhi | 18:6a4db94011d3 | 51 | pin_value = pin-307; |
sahilmgandhi | 18:6a4db94011d3 | 52 | }else if (pin == 308){ |
sahilmgandhi | 18:6a4db94011d3 | 53 | pin_value = pin-305; |
sahilmgandhi | 18:6a4db94011d3 | 54 | }else if (pin == 309){ |
sahilmgandhi | 18:6a4db94011d3 | 55 | pin_value = pin-305; |
sahilmgandhi | 18:6a4db94011d3 | 56 | }else if (pin == 310){ |
sahilmgandhi | 18:6a4db94011d3 | 57 | pin_value = pin-305; |
sahilmgandhi | 18:6a4db94011d3 | 58 | }else if (pin == 311){ |
sahilmgandhi | 18:6a4db94011d3 | 59 | pin_value = pin-305; |
sahilmgandhi | 18:6a4db94011d3 | 60 | }else if (pin == 323){ |
sahilmgandhi | 18:6a4db94011d3 | 61 | pin_value = pin-315; |
sahilmgandhi | 18:6a4db94011d3 | 62 | }else if (pin == 334){ |
sahilmgandhi | 18:6a4db94011d3 | 63 | pin_value = pin-325; |
sahilmgandhi | 18:6a4db94011d3 | 64 | }else if (pin == 653){ |
sahilmgandhi | 18:6a4db94011d3 | 65 | pin_value = pin-646; |
sahilmgandhi | 18:6a4db94011d3 | 66 | } |
sahilmgandhi | 18:6a4db94011d3 | 67 | |
sahilmgandhi | 18:6a4db94011d3 | 68 | obj->mask = 0x1 << pin_value; |
sahilmgandhi | 18:6a4db94011d3 | 69 | obj->pin_number = pin; |
sahilmgandhi | 18:6a4db94011d3 | 70 | if(pin <=15) { |
sahilmgandhi | 18:6a4db94011d3 | 71 | obj->reg_data = &CMSDK_GPIO0->DATAOUT ; |
sahilmgandhi | 18:6a4db94011d3 | 72 | obj->reg_in = &CMSDK_GPIO0->DATA ; |
sahilmgandhi | 18:6a4db94011d3 | 73 | obj->reg_dir = &CMSDK_GPIO0->OUTENABLESET ; |
sahilmgandhi | 18:6a4db94011d3 | 74 | obj->reg_dirclr = &CMSDK_GPIO0->OUTENABLECLR ; |
sahilmgandhi | 18:6a4db94011d3 | 75 | } else if (pin >= 16 && pin <= 31){ |
sahilmgandhi | 18:6a4db94011d3 | 76 | obj->reg_data = &CMSDK_GPIO1->DATAOUT ; |
sahilmgandhi | 18:6a4db94011d3 | 77 | obj->reg_in = &CMSDK_GPIO1->DATA ; |
sahilmgandhi | 18:6a4db94011d3 | 78 | obj->reg_dir = &CMSDK_GPIO1->OUTENABLESET ; |
sahilmgandhi | 18:6a4db94011d3 | 79 | obj->reg_dirclr = &CMSDK_GPIO1->OUTENABLECLR ; |
sahilmgandhi | 18:6a4db94011d3 | 80 | } else if (pin >= 32 && pin <= 47){ |
sahilmgandhi | 18:6a4db94011d3 | 81 | obj->reg_data = &CMSDK_GPIO2->DATAOUT; |
sahilmgandhi | 18:6a4db94011d3 | 82 | obj->reg_in = &CMSDK_GPIO2->DATA; |
sahilmgandhi | 18:6a4db94011d3 | 83 | obj->reg_dir = &CMSDK_GPIO2->OUTENABLESET ; |
sahilmgandhi | 18:6a4db94011d3 | 84 | obj->reg_dirclr = &CMSDK_GPIO2->OUTENABLECLR ; |
sahilmgandhi | 18:6a4db94011d3 | 85 | } else if (pin >= 48 && pin <= 51){ |
sahilmgandhi | 18:6a4db94011d3 | 86 | obj->reg_data = &CMSDK_GPIO3->DATAOUT; |
sahilmgandhi | 18:6a4db94011d3 | 87 | obj->reg_in = &CMSDK_GPIO3->DATA; |
sahilmgandhi | 18:6a4db94011d3 | 88 | obj->reg_dir = &CMSDK_GPIO3->OUTENABLESET ; |
sahilmgandhi | 18:6a4db94011d3 | 89 | obj->reg_dirclr = &CMSDK_GPIO3->OUTENABLECLR ; |
sahilmgandhi | 18:6a4db94011d3 | 90 | } else if (pin == 100 || pin == 101){ |
sahilmgandhi | 18:6a4db94011d3 | 91 | obj->reg_data = &MPS2_FPGAIO->LED; //user leds |
sahilmgandhi | 18:6a4db94011d3 | 92 | obj->reg_in = &MPS2_FPGAIO->LED; |
sahilmgandhi | 18:6a4db94011d3 | 93 | } else if (pin == 110 || pin == 111){ |
sahilmgandhi | 18:6a4db94011d3 | 94 | obj->reg_data = &MPS2_FPGAIO->BUTTON; //user switches |
sahilmgandhi | 18:6a4db94011d3 | 95 | obj->reg_in = &MPS2_FPGAIO->BUTTON; //user switches |
sahilmgandhi | 18:6a4db94011d3 | 96 | }else if (pin >= 200 && pin <= 207){ |
sahilmgandhi | 18:6a4db94011d3 | 97 | obj->reg_data = &MPS2_SCC->LEDS; //mcc leds |
sahilmgandhi | 18:6a4db94011d3 | 98 | obj->reg_in = &MPS2_SCC->LEDS; //mcc leds |
sahilmgandhi | 18:6a4db94011d3 | 99 | }else if (pin >= 210 && pin <= 217){ |
sahilmgandhi | 18:6a4db94011d3 | 100 | obj->reg_in = &MPS2_SCC->SWITCHES; //mcc switches |
sahilmgandhi | 18:6a4db94011d3 | 101 | }else if (pin == 303 || pin == 307){ |
sahilmgandhi | 18:6a4db94011d3 | 102 | obj->reg_data = &MPS2_FPGAIO->MISC; //spi chip select = 303, clcd chip select = 307 |
sahilmgandhi | 18:6a4db94011d3 | 103 | }else if (pin == 308 || pin == 309 || pin == 310 || pin == 311){ |
sahilmgandhi | 18:6a4db94011d3 | 104 | obj->reg_data = &MPS2_FPGAIO->MISC; //clcd control bits |
sahilmgandhi | 18:6a4db94011d3 | 105 | }else if (pin == 323 || pin == 334 || pin == 653){ //spi 3 chip select = 323, spi 4 chip select = 334, adc chip select = 653 |
sahilmgandhi | 18:6a4db94011d3 | 106 | obj->reg_data = &MPS2_FPGAIO->MISC; //spi cs bits |
sahilmgandhi | 18:6a4db94011d3 | 107 | } |
sahilmgandhi | 18:6a4db94011d3 | 108 | |
sahilmgandhi | 18:6a4db94011d3 | 109 | if (pin == 323){ |
sahilmgandhi | 18:6a4db94011d3 | 110 | CMSDK_GPIO0->ALTFUNCSET |= 0x1000; |
sahilmgandhi | 18:6a4db94011d3 | 111 | }else if (pin == 334){ |
sahilmgandhi | 18:6a4db94011d3 | 112 | CMSDK_GPIO2->ALTFUNCSET |= 0x0040; |
sahilmgandhi | 18:6a4db94011d3 | 113 | }else if (pin == 653){ |
sahilmgandhi | 18:6a4db94011d3 | 114 | CMSDK_GPIO1->ALTFUNCSET |= 0x0001; |
sahilmgandhi | 18:6a4db94011d3 | 115 | } |
sahilmgandhi | 18:6a4db94011d3 | 116 | } |
sahilmgandhi | 18:6a4db94011d3 | 117 | } |
sahilmgandhi | 18:6a4db94011d3 | 118 | |
sahilmgandhi | 18:6a4db94011d3 | 119 | void gpio_mode(gpio_t *obj, PinMode mode) { |
sahilmgandhi | 18:6a4db94011d3 | 120 | pin_mode(obj->pin, mode); |
sahilmgandhi | 18:6a4db94011d3 | 121 | } |
sahilmgandhi | 18:6a4db94011d3 | 122 | |
sahilmgandhi | 18:6a4db94011d3 | 123 | void gpio_dir(gpio_t *obj, PinDirection direction) { |
sahilmgandhi | 18:6a4db94011d3 | 124 | if(obj->pin >= 0 && obj->pin <= 51) |
sahilmgandhi | 18:6a4db94011d3 | 125 | { |
sahilmgandhi | 18:6a4db94011d3 | 126 | switch (direction) { |
sahilmgandhi | 18:6a4db94011d3 | 127 | case PIN_INPUT : *obj->reg_dirclr = obj->mask; break; |
sahilmgandhi | 18:6a4db94011d3 | 128 | case PIN_OUTPUT: *obj->reg_dir |= obj->mask; break; |
sahilmgandhi | 18:6a4db94011d3 | 129 | } |
sahilmgandhi | 18:6a4db94011d3 | 130 | } else {return;} |
sahilmgandhi | 18:6a4db94011d3 | 131 | } |
sahilmgandhi | 18:6a4db94011d3 | 132 | |
sahilmgandhi | 18:6a4db94011d3 | 133 | int gpio_is_connected(const gpio_t *obj){ |
sahilmgandhi | 18:6a4db94011d3 | 134 | if(obj->pin != (PinName)NC){ |
sahilmgandhi | 18:6a4db94011d3 | 135 | return 1; |
sahilmgandhi | 18:6a4db94011d3 | 136 | } else { |
sahilmgandhi | 18:6a4db94011d3 | 137 | return 0; |
sahilmgandhi | 18:6a4db94011d3 | 138 | } |
sahilmgandhi | 18:6a4db94011d3 | 139 | } |
sahilmgandhi | 18:6a4db94011d3 | 140 |