mbed library sources. Supersedes mbed-src.

Dependents:   Nucleo_Hello_Encoder BLE_iBeaconScan AM1805_DEMO DISCO-F429ZI_ExportTemplate1 ... more

Committer:
AnnaBridge
Date:
Wed Jun 21 17:46:44 2017 +0100
Revision:
167:e84263d55307
This updates the lib to the mbed lib v 145

Who changed what in which revision?

UserRevisionLine numberNew contents of line
AnnaBridge 167:e84263d55307 1 /* mbed Microcontroller Library
AnnaBridge 167:e84263d55307 2 * Copyright (c) 2013-2016 Realtek Semiconductor Corp.
AnnaBridge 167:e84263d55307 3 *
AnnaBridge 167:e84263d55307 4 * Licensed under the Apache License, Version 2.0 (the "License");
AnnaBridge 167:e84263d55307 5 * you may not use this file except in compliance with the License.
AnnaBridge 167:e84263d55307 6 * You may obtain a copy of the License at
AnnaBridge 167:e84263d55307 7 *
AnnaBridge 167:e84263d55307 8 * http://www.apache.org/licenses/LICENSE-2.0
AnnaBridge 167:e84263d55307 9 *
AnnaBridge 167:e84263d55307 10 * Unless required by applicable law or agreed to in writing, software
AnnaBridge 167:e84263d55307 11 * distributed under the License is distributed on an "AS IS" BASIS,
AnnaBridge 167:e84263d55307 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
AnnaBridge 167:e84263d55307 13 * See the License for the specific language governing permissions and
AnnaBridge 167:e84263d55307 14 * limitations under the License.
AnnaBridge 167:e84263d55307 15 */
AnnaBridge 167:e84263d55307 16 #include "objects.h"
AnnaBridge 167:e84263d55307 17 #include "pinmap.h"
AnnaBridge 167:e84263d55307 18
AnnaBridge 167:e84263d55307 19 #if CONFIG_GPIO_EN
AnnaBridge 167:e84263d55307 20 #include "gpio_irq_api.h"
AnnaBridge 167:e84263d55307 21
AnnaBridge 167:e84263d55307 22 int gpio_irq_init(gpio_irq_t *obj, PinName pin, gpio_irq_handler handler, uint32_t id)
AnnaBridge 167:e84263d55307 23 {
AnnaBridge 167:e84263d55307 24 uint32_t pin_name;
AnnaBridge 167:e84263d55307 25
AnnaBridge 167:e84263d55307 26 if (pin == NC) return -1;
AnnaBridge 167:e84263d55307 27
AnnaBridge 167:e84263d55307 28 obj->pin = pin;
AnnaBridge 167:e84263d55307 29 pin_name = HAL_GPIO_GetPinName((u32)pin);; // get the IP pin name
AnnaBridge 167:e84263d55307 30 obj->hal_pin.pin_name = pin_name;
AnnaBridge 167:e84263d55307 31 obj->hal_pin.pin_mode = INT_FALLING; // default use Falling trigger
AnnaBridge 167:e84263d55307 32 obj->hal_port_num = HAL_GPIO_GET_PORT_BY_NAME(pin_name);
AnnaBridge 167:e84263d55307 33 obj->hal_pin_num = HAL_GPIO_GET_PIN_BY_NAME(pin_name);
AnnaBridge 167:e84263d55307 34 HAL_GPIO_Irq_Init(&obj->hal_pin);
AnnaBridge 167:e84263d55307 35 HAL_GPIO_UserRegIrq(&obj->hal_pin, (VOID*) handler, (VOID*) id);
AnnaBridge 167:e84263d55307 36
AnnaBridge 167:e84263d55307 37 return 0;
AnnaBridge 167:e84263d55307 38 }
AnnaBridge 167:e84263d55307 39
AnnaBridge 167:e84263d55307 40 void gpio_irq_free(gpio_irq_t *obj)
AnnaBridge 167:e84263d55307 41 {
AnnaBridge 167:e84263d55307 42 HAL_GPIO_UserUnRegIrq(&obj->hal_pin);
AnnaBridge 167:e84263d55307 43 HAL_GPIO_DeInit(&obj->hal_pin);
AnnaBridge 167:e84263d55307 44 }
AnnaBridge 167:e84263d55307 45
AnnaBridge 167:e84263d55307 46 void gpio_irq_set(gpio_irq_t *obj, gpio_irq_event event, uint32_t enable)
AnnaBridge 167:e84263d55307 47 {
AnnaBridge 167:e84263d55307 48 HAL_GPIO_MaskIrq(&obj->hal_pin);
AnnaBridge 167:e84263d55307 49 switch((uint32_t)event) {
AnnaBridge 167:e84263d55307 50 case IRQ_RISE:
AnnaBridge 167:e84263d55307 51 obj->hal_pin.pin_mode = INT_RISING;
AnnaBridge 167:e84263d55307 52 break;
AnnaBridge 167:e84263d55307 53
AnnaBridge 167:e84263d55307 54 case IRQ_FALL:
AnnaBridge 167:e84263d55307 55 obj->hal_pin.pin_mode = INT_FALLING;
AnnaBridge 167:e84263d55307 56 break;
AnnaBridge 167:e84263d55307 57
AnnaBridge 167:e84263d55307 58 case IRQ_NONE:
AnnaBridge 167:e84263d55307 59 break;
AnnaBridge 167:e84263d55307 60
AnnaBridge 167:e84263d55307 61 default:
AnnaBridge 167:e84263d55307 62 break;
AnnaBridge 167:e84263d55307 63 }
AnnaBridge 167:e84263d55307 64 HAL_GPIO_Init_8195a(&obj->hal_pin);
AnnaBridge 167:e84263d55307 65
AnnaBridge 167:e84263d55307 66 HAL_GPIO_IntCtrl(&obj->hal_pin, enable);
AnnaBridge 167:e84263d55307 67 if(enable){
AnnaBridge 167:e84263d55307 68 HAL_GPIO_UnMaskIrq(&obj->hal_pin);
AnnaBridge 167:e84263d55307 69 } else{
AnnaBridge 167:e84263d55307 70 HAL_GPIO_MaskIrq(&obj->hal_pin);
AnnaBridge 167:e84263d55307 71 }
AnnaBridge 167:e84263d55307 72 }
AnnaBridge 167:e84263d55307 73
AnnaBridge 167:e84263d55307 74 void gpio_irq_enable(gpio_irq_t *obj)
AnnaBridge 167:e84263d55307 75 {
AnnaBridge 167:e84263d55307 76 HAL_GPIO_UnMaskIrq(&obj->hal_pin);
AnnaBridge 167:e84263d55307 77 }
AnnaBridge 167:e84263d55307 78
AnnaBridge 167:e84263d55307 79 void gpio_irq_disable(gpio_irq_t *obj)
AnnaBridge 167:e84263d55307 80 {
AnnaBridge 167:e84263d55307 81 HAL_GPIO_MaskIrq(&obj->hal_pin);
AnnaBridge 167:e84263d55307 82 }
AnnaBridge 167:e84263d55307 83 #endif
AnnaBridge 167:e84263d55307 84