added prescaler for 16 bit pwm in LPC1347 target
Fork of mbed-dev by
targets/hal/TARGET_Freescale/TARGET_KSDK2_MCUS/api/gpio_api.c@144:ef7eb2e8f9f7, 2016-09-02 (annotated)
- Committer:
- <>
- Date:
- Fri Sep 02 15:07:44 2016 +0100
- Revision:
- 144:ef7eb2e8f9f7
- Parent:
- 121:7f86b4238bec
This updates the lib to the mbed lib v125
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
mbed_official | 121:7f86b4238bec | 1 | /* mbed Microcontroller Library |
mbed_official | 121:7f86b4238bec | 2 | * Copyright (c) 2006-2013 ARM Limited |
mbed_official | 121:7f86b4238bec | 3 | * |
mbed_official | 121:7f86b4238bec | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
mbed_official | 121:7f86b4238bec | 5 | * you may not use this file except in compliance with the License. |
mbed_official | 121:7f86b4238bec | 6 | * You may obtain a copy of the License at |
mbed_official | 121:7f86b4238bec | 7 | * |
mbed_official | 121:7f86b4238bec | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
mbed_official | 121:7f86b4238bec | 9 | * |
mbed_official | 121:7f86b4238bec | 10 | * Unless required by applicable law or agreed to in writing, software |
mbed_official | 121:7f86b4238bec | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
mbed_official | 121:7f86b4238bec | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
mbed_official | 121:7f86b4238bec | 13 | * See the License for the specific language governing permissions and |
mbed_official | 121:7f86b4238bec | 14 | * limitations under the License. |
mbed_official | 121:7f86b4238bec | 15 | */ |
mbed_official | 121:7f86b4238bec | 16 | #include "mbed_assert.h" |
mbed_official | 121:7f86b4238bec | 17 | #include "gpio_api.h" |
mbed_official | 121:7f86b4238bec | 18 | #include "pinmap.h" |
mbed_official | 121:7f86b4238bec | 19 | #include "fsl_port.h" |
<> | 144:ef7eb2e8f9f7 | 20 | #include "fsl_gpio.h" |
<> | 144:ef7eb2e8f9f7 | 21 | |
<> | 144:ef7eb2e8f9f7 | 22 | static GPIO_Type * const gpio_addrs[] = GPIO_BASE_PTRS; |
mbed_official | 121:7f86b4238bec | 23 | |
mbed_official | 121:7f86b4238bec | 24 | uint32_t gpio_set(PinName pin) { |
mbed_official | 121:7f86b4238bec | 25 | MBED_ASSERT(pin != (PinName)NC); |
mbed_official | 121:7f86b4238bec | 26 | uint32_t pin_num = pin & 0xFF; |
mbed_official | 121:7f86b4238bec | 27 | |
mbed_official | 121:7f86b4238bec | 28 | pin_function(pin, (int)kPORT_MuxAsGpio); |
mbed_official | 121:7f86b4238bec | 29 | return 1 << pin_num; |
mbed_official | 121:7f86b4238bec | 30 | } |
mbed_official | 121:7f86b4238bec | 31 | |
mbed_official | 121:7f86b4238bec | 32 | void gpio_init(gpio_t *obj, PinName pin) { |
mbed_official | 121:7f86b4238bec | 33 | obj->pin = pin; |
mbed_official | 121:7f86b4238bec | 34 | if (pin == (PinName)NC) |
mbed_official | 121:7f86b4238bec | 35 | return; |
mbed_official | 121:7f86b4238bec | 36 | |
mbed_official | 121:7f86b4238bec | 37 | pin_function(pin, (int)kPORT_MuxAsGpio); |
mbed_official | 121:7f86b4238bec | 38 | } |
mbed_official | 121:7f86b4238bec | 39 | |
mbed_official | 121:7f86b4238bec | 40 | void gpio_mode(gpio_t *obj, PinMode mode) { |
mbed_official | 121:7f86b4238bec | 41 | pin_mode(obj->pin, mode); |
mbed_official | 121:7f86b4238bec | 42 | } |
mbed_official | 121:7f86b4238bec | 43 | |
mbed_official | 121:7f86b4238bec | 44 | void gpio_dir(gpio_t *obj, PinDirection direction) { |
mbed_official | 121:7f86b4238bec | 45 | MBED_ASSERT(obj->pin != (PinName)NC); |
mbed_official | 121:7f86b4238bec | 46 | uint32_t port = obj->pin >> GPIO_PORT_SHIFT; |
mbed_official | 121:7f86b4238bec | 47 | uint32_t pin_num = obj->pin & 0xFF; |
mbed_official | 121:7f86b4238bec | 48 | GPIO_Type *base = gpio_addrs[port]; |
mbed_official | 121:7f86b4238bec | 49 | |
mbed_official | 121:7f86b4238bec | 50 | switch (direction) { |
mbed_official | 121:7f86b4238bec | 51 | case PIN_INPUT: |
mbed_official | 121:7f86b4238bec | 52 | base->PDDR &= ~(1U << pin_num); |
mbed_official | 121:7f86b4238bec | 53 | break; |
mbed_official | 121:7f86b4238bec | 54 | case PIN_OUTPUT: |
mbed_official | 121:7f86b4238bec | 55 | base->PDDR |= (1U << pin_num); |
mbed_official | 121:7f86b4238bec | 56 | break; |
mbed_official | 121:7f86b4238bec | 57 | } |
mbed_official | 121:7f86b4238bec | 58 | } |
<> | 144:ef7eb2e8f9f7 | 59 | |
<> | 144:ef7eb2e8f9f7 | 60 | void gpio_write(gpio_t *obj, int value) { |
<> | 144:ef7eb2e8f9f7 | 61 | MBED_ASSERT(obj->pin != (PinName)NC); |
<> | 144:ef7eb2e8f9f7 | 62 | uint32_t port = obj->pin >> GPIO_PORT_SHIFT; |
<> | 144:ef7eb2e8f9f7 | 63 | uint32_t pin = obj->pin & 0xFF; |
<> | 144:ef7eb2e8f9f7 | 64 | |
<> | 144:ef7eb2e8f9f7 | 65 | GPIO_WritePinOutput(gpio_addrs[port], pin, value); |
<> | 144:ef7eb2e8f9f7 | 66 | } |
<> | 144:ef7eb2e8f9f7 | 67 | |
<> | 144:ef7eb2e8f9f7 | 68 | int gpio_read(gpio_t *obj) { |
<> | 144:ef7eb2e8f9f7 | 69 | MBED_ASSERT(obj->pin != (PinName)NC); |
<> | 144:ef7eb2e8f9f7 | 70 | uint32_t port = obj->pin >> GPIO_PORT_SHIFT; |
<> | 144:ef7eb2e8f9f7 | 71 | uint32_t pin = obj->pin & 0xFF; |
<> | 144:ef7eb2e8f9f7 | 72 | |
<> | 144:ef7eb2e8f9f7 | 73 | return (int)GPIO_ReadPinInput(gpio_addrs[port], pin); |
<> | 144:ef7eb2e8f9f7 | 74 | } |