added prescaler for 16 bit pwm in LPC1347 target
Fork of mbed-dev by
targets/hal/TARGET_Freescale/TARGET_KSDK2_MCUS/api/port_api.c@121:7f86b4238bec, 2016-05-03 (annotated)
- Committer:
- mbed_official
- Date:
- Tue May 03 00:15:16 2016 +0100
- Revision:
- 121:7f86b4238bec
Synchronized with git revision 9cef243de23875778f461bbe9a8c1bc47e65212b
Full URL: https://github.com/mbedmicro/mbed/commit/9cef243de23875778f461bbe9a8c1bc47e65212b/
Switch to KSDK 2.0
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 "port_api.h" |
mbed_official | 121:7f86b4238bec | 17 | |
mbed_official | 121:7f86b4238bec | 18 | #if DEVICE_PORTIN || DEVICE_PORTOUT |
mbed_official | 121:7f86b4238bec | 19 | |
mbed_official | 121:7f86b4238bec | 20 | #include "pinmap.h" |
mbed_official | 121:7f86b4238bec | 21 | #include "gpio_api.h" |
mbed_official | 121:7f86b4238bec | 22 | |
mbed_official | 121:7f86b4238bec | 23 | /* Array of GPIO peripheral base address. */ |
mbed_official | 121:7f86b4238bec | 24 | static GPIO_Type *const port_addrs[] = GPIO_BASE_PTRS; |
mbed_official | 121:7f86b4238bec | 25 | |
mbed_official | 121:7f86b4238bec | 26 | PinName port_pin(PortName port, int pin_n) { |
mbed_official | 121:7f86b4238bec | 27 | return (PinName)((port << GPIO_PORT_SHIFT) | pin_n); |
mbed_official | 121:7f86b4238bec | 28 | } |
mbed_official | 121:7f86b4238bec | 29 | |
mbed_official | 121:7f86b4238bec | 30 | void port_init(port_t *obj, PortName port, int mask, PinDirection dir) { |
mbed_official | 121:7f86b4238bec | 31 | obj->port = port; |
mbed_official | 121:7f86b4238bec | 32 | obj->mask = mask; |
mbed_official | 121:7f86b4238bec | 33 | |
mbed_official | 121:7f86b4238bec | 34 | // The function is set per pin: reuse gpio logic |
mbed_official | 121:7f86b4238bec | 35 | for (uint32_t i = 0; i < 32; i++) { |
mbed_official | 121:7f86b4238bec | 36 | if (obj->mask & (1 << i)) { |
mbed_official | 121:7f86b4238bec | 37 | gpio_set(port_pin(obj->port, i)); |
mbed_official | 121:7f86b4238bec | 38 | } |
mbed_official | 121:7f86b4238bec | 39 | } |
mbed_official | 121:7f86b4238bec | 40 | |
mbed_official | 121:7f86b4238bec | 41 | port_dir(obj, dir); |
mbed_official | 121:7f86b4238bec | 42 | } |
mbed_official | 121:7f86b4238bec | 43 | |
mbed_official | 121:7f86b4238bec | 44 | void port_mode(port_t *obj, PinMode mode) { |
mbed_official | 121:7f86b4238bec | 45 | |
mbed_official | 121:7f86b4238bec | 46 | // The mode is set per pin: reuse pinmap logic |
mbed_official | 121:7f86b4238bec | 47 | for (uint32_t i = 0; i < 32; i++) { |
mbed_official | 121:7f86b4238bec | 48 | if (obj->mask & (1 << i)) { |
mbed_official | 121:7f86b4238bec | 49 | pin_mode(port_pin(obj->port, i), mode); |
mbed_official | 121:7f86b4238bec | 50 | } |
mbed_official | 121:7f86b4238bec | 51 | } |
mbed_official | 121:7f86b4238bec | 52 | } |
mbed_official | 121:7f86b4238bec | 53 | |
mbed_official | 121:7f86b4238bec | 54 | void port_dir(port_t *obj, PinDirection dir) { |
mbed_official | 121:7f86b4238bec | 55 | GPIO_Type *base = port_addrs[obj->port]; |
mbed_official | 121:7f86b4238bec | 56 | uint32_t direction = base->PDDR; |
mbed_official | 121:7f86b4238bec | 57 | |
mbed_official | 121:7f86b4238bec | 58 | switch (dir) { |
mbed_official | 121:7f86b4238bec | 59 | case PIN_INPUT : |
mbed_official | 121:7f86b4238bec | 60 | direction &= ~obj->mask; |
mbed_official | 121:7f86b4238bec | 61 | break; |
mbed_official | 121:7f86b4238bec | 62 | case PIN_OUTPUT: |
mbed_official | 121:7f86b4238bec | 63 | direction |= obj->mask; |
mbed_official | 121:7f86b4238bec | 64 | break; |
mbed_official | 121:7f86b4238bec | 65 | } |
mbed_official | 121:7f86b4238bec | 66 | base->PDDR = direction; |
mbed_official | 121:7f86b4238bec | 67 | } |
mbed_official | 121:7f86b4238bec | 68 | |
mbed_official | 121:7f86b4238bec | 69 | void port_write(port_t *obj, int value) { |
mbed_official | 121:7f86b4238bec | 70 | GPIO_Type *base = port_addrs[obj->port]; |
mbed_official | 121:7f86b4238bec | 71 | uint32_t input = base->PDIR & ~obj->mask; |
mbed_official | 121:7f86b4238bec | 72 | |
mbed_official | 121:7f86b4238bec | 73 | base->PDOR = (input | (uint32_t)(value & obj->mask)); |
mbed_official | 121:7f86b4238bec | 74 | } |
mbed_official | 121:7f86b4238bec | 75 | |
mbed_official | 121:7f86b4238bec | 76 | int port_read(port_t *obj) { |
mbed_official | 121:7f86b4238bec | 77 | GPIO_Type *base = port_addrs[obj->port]; |
mbed_official | 121:7f86b4238bec | 78 | |
mbed_official | 121:7f86b4238bec | 79 | return (int)(base->PDIR & obj->mask); |
mbed_official | 121:7f86b4238bec | 80 | } |
mbed_official | 121:7f86b4238bec | 81 | |
mbed_official | 121:7f86b4238bec | 82 | #endif |