added prescaler for 16 bit pwm in LPC1347 target
Fork of mbed-dev by
common/mbed_pinmap_common.c@147:ba84b7dc41a7, 2016-09-10 (annotated)
- Committer:
- JojoS
- Date:
- Sat Sep 10 15:32:04 2016 +0000
- Revision:
- 147:ba84b7dc41a7
- Parent:
- 144:ef7eb2e8f9f7
added prescaler for 16 bit timers (solution as in LPC11xx), default prescaler 31 for max 28 ms period time
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
<> | 144:ef7eb2e8f9f7 | 1 | /* mbed Microcontroller Library |
<> | 144:ef7eb2e8f9f7 | 2 | * Copyright (c) 2006-2013 ARM Limited |
<> | 144:ef7eb2e8f9f7 | 3 | * |
<> | 144:ef7eb2e8f9f7 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
<> | 144:ef7eb2e8f9f7 | 5 | * you may not use this file except in compliance with the License. |
<> | 144:ef7eb2e8f9f7 | 6 | * You may obtain a copy of the License at |
<> | 144:ef7eb2e8f9f7 | 7 | * |
<> | 144:ef7eb2e8f9f7 | 8 | * http://www.apache.org/licenses/LICENSE-2.0 |
<> | 144:ef7eb2e8f9f7 | 9 | * |
<> | 144:ef7eb2e8f9f7 | 10 | * Unless required by applicable law or agreed to in writing, software |
<> | 144:ef7eb2e8f9f7 | 11 | * distributed under the License is distributed on an "AS IS" BASIS, |
<> | 144:ef7eb2e8f9f7 | 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
<> | 144:ef7eb2e8f9f7 | 13 | * See the License for the specific language governing permissions and |
<> | 144:ef7eb2e8f9f7 | 14 | * limitations under the License. |
<> | 144:ef7eb2e8f9f7 | 15 | */ |
<> | 144:ef7eb2e8f9f7 | 16 | #include "pinmap.h" |
<> | 144:ef7eb2e8f9f7 | 17 | #include "mbed_error.h" |
<> | 144:ef7eb2e8f9f7 | 18 | |
<> | 144:ef7eb2e8f9f7 | 19 | void pinmap_pinout(PinName pin, const PinMap *map) { |
<> | 144:ef7eb2e8f9f7 | 20 | if (pin == NC) |
<> | 144:ef7eb2e8f9f7 | 21 | return; |
<> | 144:ef7eb2e8f9f7 | 22 | |
<> | 144:ef7eb2e8f9f7 | 23 | while (map->pin != NC) { |
<> | 144:ef7eb2e8f9f7 | 24 | if (map->pin == pin) { |
<> | 144:ef7eb2e8f9f7 | 25 | pin_function(pin, map->function); |
<> | 144:ef7eb2e8f9f7 | 26 | |
<> | 144:ef7eb2e8f9f7 | 27 | pin_mode(pin, PullNone); |
<> | 144:ef7eb2e8f9f7 | 28 | return; |
<> | 144:ef7eb2e8f9f7 | 29 | } |
<> | 144:ef7eb2e8f9f7 | 30 | map++; |
<> | 144:ef7eb2e8f9f7 | 31 | } |
<> | 144:ef7eb2e8f9f7 | 32 | error("could not pinout"); |
<> | 144:ef7eb2e8f9f7 | 33 | } |
<> | 144:ef7eb2e8f9f7 | 34 | |
<> | 144:ef7eb2e8f9f7 | 35 | uint32_t pinmap_merge(uint32_t a, uint32_t b) { |
<> | 144:ef7eb2e8f9f7 | 36 | // both are the same (inc both NC) |
<> | 144:ef7eb2e8f9f7 | 37 | if (a == b) |
<> | 144:ef7eb2e8f9f7 | 38 | return a; |
<> | 144:ef7eb2e8f9f7 | 39 | |
<> | 144:ef7eb2e8f9f7 | 40 | // one (or both) is not connected |
<> | 144:ef7eb2e8f9f7 | 41 | if (a == (uint32_t)NC) |
<> | 144:ef7eb2e8f9f7 | 42 | return b; |
<> | 144:ef7eb2e8f9f7 | 43 | if (b == (uint32_t)NC) |
<> | 144:ef7eb2e8f9f7 | 44 | return a; |
<> | 144:ef7eb2e8f9f7 | 45 | |
<> | 144:ef7eb2e8f9f7 | 46 | // mis-match error case |
<> | 144:ef7eb2e8f9f7 | 47 | error("pinmap mis-match"); |
<> | 144:ef7eb2e8f9f7 | 48 | return (uint32_t)NC; |
<> | 144:ef7eb2e8f9f7 | 49 | } |
<> | 144:ef7eb2e8f9f7 | 50 | |
<> | 144:ef7eb2e8f9f7 | 51 | uint32_t pinmap_find_peripheral(PinName pin, const PinMap* map) { |
<> | 144:ef7eb2e8f9f7 | 52 | while (map->pin != NC) { |
<> | 144:ef7eb2e8f9f7 | 53 | if (map->pin == pin) |
<> | 144:ef7eb2e8f9f7 | 54 | return map->peripheral; |
<> | 144:ef7eb2e8f9f7 | 55 | map++; |
<> | 144:ef7eb2e8f9f7 | 56 | } |
<> | 144:ef7eb2e8f9f7 | 57 | return (uint32_t)NC; |
<> | 144:ef7eb2e8f9f7 | 58 | } |
<> | 144:ef7eb2e8f9f7 | 59 | |
<> | 144:ef7eb2e8f9f7 | 60 | uint32_t pinmap_peripheral(PinName pin, const PinMap* map) { |
<> | 144:ef7eb2e8f9f7 | 61 | uint32_t peripheral = (uint32_t)NC; |
<> | 144:ef7eb2e8f9f7 | 62 | |
<> | 144:ef7eb2e8f9f7 | 63 | if (pin == (PinName)NC) |
<> | 144:ef7eb2e8f9f7 | 64 | return (uint32_t)NC; |
<> | 144:ef7eb2e8f9f7 | 65 | peripheral = pinmap_find_peripheral(pin, map); |
<> | 144:ef7eb2e8f9f7 | 66 | if ((uint32_t)NC == peripheral) // no mapping available |
<> | 144:ef7eb2e8f9f7 | 67 | error("pinmap not found for peripheral"); |
<> | 144:ef7eb2e8f9f7 | 68 | return peripheral; |
<> | 144:ef7eb2e8f9f7 | 69 | } |
<> | 144:ef7eb2e8f9f7 | 70 | |
<> | 144:ef7eb2e8f9f7 | 71 | uint32_t pinmap_find_function(PinName pin, const PinMap* map) { |
<> | 144:ef7eb2e8f9f7 | 72 | while (map->pin != NC) { |
<> | 144:ef7eb2e8f9f7 | 73 | if (map->pin == pin) |
<> | 144:ef7eb2e8f9f7 | 74 | return map->function; |
<> | 144:ef7eb2e8f9f7 | 75 | map++; |
<> | 144:ef7eb2e8f9f7 | 76 | } |
<> | 144:ef7eb2e8f9f7 | 77 | return (uint32_t)NC; |
<> | 144:ef7eb2e8f9f7 | 78 | } |
<> | 144:ef7eb2e8f9f7 | 79 | |
<> | 144:ef7eb2e8f9f7 | 80 | uint32_t pinmap_function(PinName pin, const PinMap* map) { |
<> | 144:ef7eb2e8f9f7 | 81 | uint32_t function = (uint32_t)NC; |
<> | 144:ef7eb2e8f9f7 | 82 | |
<> | 144:ef7eb2e8f9f7 | 83 | if (pin == (PinName)NC) |
<> | 144:ef7eb2e8f9f7 | 84 | return (uint32_t)NC; |
<> | 144:ef7eb2e8f9f7 | 85 | function = pinmap_find_function(pin, map); |
<> | 144:ef7eb2e8f9f7 | 86 | if ((uint32_t)NC == function) // no mapping available |
<> | 144:ef7eb2e8f9f7 | 87 | error("pinmap not found for function"); |
<> | 144:ef7eb2e8f9f7 | 88 | return function; |
<> | 144:ef7eb2e8f9f7 | 89 | } |