inport from local

Dependents:   Hobbyking_Cheetah_0511

Committer:
NYX
Date:
Mon Mar 16 06:35:48 2020 +0000
Revision:
0:85b3fd62ea1a
reinport to mbed;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
NYX 0:85b3fd62ea1a 1 /* mbed Microcontroller Library
NYX 0:85b3fd62ea1a 2 *******************************************************************************
NYX 0:85b3fd62ea1a 3 * Copyright (c) 2016, STMicroelectronics
NYX 0:85b3fd62ea1a 4 * All rights reserved.
NYX 0:85b3fd62ea1a 5 *
NYX 0:85b3fd62ea1a 6 * Redistribution and use in source and binary forms, with or without
NYX 0:85b3fd62ea1a 7 * modification, are permitted provided that the following conditions are met:
NYX 0:85b3fd62ea1a 8 *
NYX 0:85b3fd62ea1a 9 * 1. Redistributions of source code must retain the above copyright notice,
NYX 0:85b3fd62ea1a 10 * this list of conditions and the following disclaimer.
NYX 0:85b3fd62ea1a 11 * 2. Redistributions in binary form must reproduce the above copyright notice,
NYX 0:85b3fd62ea1a 12 * this list of conditions and the following disclaimer in the documentation
NYX 0:85b3fd62ea1a 13 * and/or other materials provided with the distribution.
NYX 0:85b3fd62ea1a 14 * 3. Neither the name of STMicroelectronics nor the names of its contributors
NYX 0:85b3fd62ea1a 15 * may be used to endorse or promote products derived from this software
NYX 0:85b3fd62ea1a 16 * without specific prior written permission.
NYX 0:85b3fd62ea1a 17 *
NYX 0:85b3fd62ea1a 18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
NYX 0:85b3fd62ea1a 19 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
NYX 0:85b3fd62ea1a 20 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
NYX 0:85b3fd62ea1a 21 * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
NYX 0:85b3fd62ea1a 22 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
NYX 0:85b3fd62ea1a 23 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
NYX 0:85b3fd62ea1a 24 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
NYX 0:85b3fd62ea1a 25 * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
NYX 0:85b3fd62ea1a 26 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
NYX 0:85b3fd62ea1a 27 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
NYX 0:85b3fd62ea1a 28 *******************************************************************************
NYX 0:85b3fd62ea1a 29 */
NYX 0:85b3fd62ea1a 30 #ifndef MBED_PINNAMESTYPES_H
NYX 0:85b3fd62ea1a 31 #define MBED_PINNAMESTYPES_H
NYX 0:85b3fd62ea1a 32
NYX 0:85b3fd62ea1a 33 #include "cmsis.h"
NYX 0:85b3fd62ea1a 34
NYX 0:85b3fd62ea1a 35 #ifdef __cplusplus
NYX 0:85b3fd62ea1a 36 extern "C" {
NYX 0:85b3fd62ea1a 37 #endif
NYX 0:85b3fd62ea1a 38
NYX 0:85b3fd62ea1a 39 /* STM PIN data as used in pin_function is coded on 32 bits as below
NYX 0:85b3fd62ea1a 40 * [2:0] Function (like in MODER reg) : Input / Output / Alt / Analog
NYX 0:85b3fd62ea1a 41 * [3] Output Push-Pull / Open Drain (as in OTYPER reg)
NYX 0:85b3fd62ea1a 42 * [5:4] as in PUPDR reg: No Pull, Pull-up, Pull-Donc
NYX 0:85b3fd62ea1a 43 * [7:6] Reserved for speed config (as in OSPEEDR), but not used yet
NYX 0:85b3fd62ea1a 44 * [11:8] Alternate Num (as in AFRL/AFRG reg)
NYX 0:85b3fd62ea1a 45 * [16:12] Channel (Analog/Timer specific)
NYX 0:85b3fd62ea1a 46 * [17] Inverted (Analog/Timer specific)
NYX 0:85b3fd62ea1a 47 * [18] Analog ADC control - Only valid for specific families
NYX 0:85b3fd62ea1a 48 * [32:19] Reserved
NYX 0:85b3fd62ea1a 49 */
NYX 0:85b3fd62ea1a 50
NYX 0:85b3fd62ea1a 51 #define STM_PIN_FUNCTION_MASK 0x07
NYX 0:85b3fd62ea1a 52 #define STM_PIN_FUNCTION_SHIFT 0
NYX 0:85b3fd62ea1a 53 #define STM_PIN_FUNCTION_BITS (STM_PIN_FUNCTION_MASK << STM_PIN_FUNCTION_SHIFT)
NYX 0:85b3fd62ea1a 54
NYX 0:85b3fd62ea1a 55 #define STM_PIN_OD_MASK 0x01
NYX 0:85b3fd62ea1a 56 #define STM_PIN_OD_SHIFT 3
NYX 0:85b3fd62ea1a 57 #define STM_PIN_OD_BITS (STM_PIN_OD_MASK << STM_PIN_OD_SHIFT)
NYX 0:85b3fd62ea1a 58
NYX 0:85b3fd62ea1a 59 #define STM_PIN_PUPD_MASK 0x03
NYX 0:85b3fd62ea1a 60 #define STM_PIN_PUPD_SHIFT 4
NYX 0:85b3fd62ea1a 61 #define STM_PIN_PUPD_BITS (STM_PIN_PUPD_MASK << STM_PIN_PUPD_SHIFT)
NYX 0:85b3fd62ea1a 62
NYX 0:85b3fd62ea1a 63 #define STM_PIN_SPEED_MASK 0x03
NYX 0:85b3fd62ea1a 64 #define STM_PIN_SPEED_SHIFT 6
NYX 0:85b3fd62ea1a 65 #define STM_PIN_SPEED_BITS (STM_PIN_SPEED_MASK << STM_PIN_SPEED_SHIFT)
NYX 0:85b3fd62ea1a 66
NYX 0:85b3fd62ea1a 67 #define STM_PIN_AFNUM_MASK 0x0F
NYX 0:85b3fd62ea1a 68 #define STM_PIN_AFNUM_SHIFT 8
NYX 0:85b3fd62ea1a 69 #define STM_PIN_AFNUM_BITS (STM_PIN_AFNUM_MASK << STM_PIN_AFNUM_SHIFT)
NYX 0:85b3fd62ea1a 70
NYX 0:85b3fd62ea1a 71 #define STM_PIN_CHAN_MASK 0x1F
NYX 0:85b3fd62ea1a 72 #define STM_PIN_CHAN_SHIFT 12
NYX 0:85b3fd62ea1a 73 #define STM_PIN_CHANNEL_BIT (STM_PIN_CHAN_MASK << STM_PIN_CHAN_SHIFT)
NYX 0:85b3fd62ea1a 74
NYX 0:85b3fd62ea1a 75 #define STM_PIN_INV_MASK 0x01
NYX 0:85b3fd62ea1a 76 #define STM_PIN_INV_SHIFT 17
NYX 0:85b3fd62ea1a 77 #define STM_PIN_INV_BIT (STM_PIN_INV_MASK << STM_PIN_INV_SHIFT)
NYX 0:85b3fd62ea1a 78
NYX 0:85b3fd62ea1a 79 #define STM_PIN_AN_CTRL_MASK 0x01
NYX 0:85b3fd62ea1a 80 #define STM_PIN_AN_CTRL_SHIFT 18
NYX 0:85b3fd62ea1a 81 #define STM_PIN_ANALOG_CONTROL_BIT (STM_PIN_AN_CTRL_MASK << STM_PIN_AN_CTRL_SHIFT)
NYX 0:85b3fd62ea1a 82
NYX 0:85b3fd62ea1a 83 #define STM_PIN_FUNCTION(X) (((X) >> STM_PIN_FUNCTION_SHIFT) & STM_PIN_FUNCTION_MASK)
NYX 0:85b3fd62ea1a 84 #define STM_PIN_OD(X) (((X) >> STM_PIN_OD_SHIFT) & STM_PIN_OD_MASK)
NYX 0:85b3fd62ea1a 85 #define STM_PIN_PUPD(X) (((X) >> STM_PIN_PUPD_SHIFT) & STM_PIN_PUPD_MASK)
NYX 0:85b3fd62ea1a 86 #define STM_PIN_SPEED(X) (((X) >> STM_PIN_SPEED_SHIFT) & STM_PIN_SPEED_MASK)
NYX 0:85b3fd62ea1a 87 #define STM_PIN_AFNUM(X) (((X) >> STM_PIN_AFNUM_SHIFT) & STM_PIN_AFNUM_MASK)
NYX 0:85b3fd62ea1a 88 #define STM_PIN_CHANNEL(X) (((X) >> STM_PIN_CHAN_SHIFT) & STM_PIN_CHAN_MASK)
NYX 0:85b3fd62ea1a 89 #define STM_PIN_INVERTED(X) (((X) >> STM_PIN_INV_SHIFT) & STM_PIN_INV_MASK)
NYX 0:85b3fd62ea1a 90 #define STM_PIN_ANALOG_CONTROL(X) (((X) >> STM_PIN_AN_CTRL_SHIFT) & STM_PIN_AN_CTRL_MASK)
NYX 0:85b3fd62ea1a 91
NYX 0:85b3fd62ea1a 92 #define STM_PIN_DEFINE(FUNC_OD, PUPD, AFNUM) ((int)(FUNC_OD) |\
NYX 0:85b3fd62ea1a 93 ((PUPD & STM_PIN_PUPD_MASK) << STM_PIN_PUPD_SHIFT) |\
NYX 0:85b3fd62ea1a 94 ((AFNUM & STM_PIN_AFNUM_MASK) << STM_PIN_AFNUM_SHIFT))
NYX 0:85b3fd62ea1a 95
NYX 0:85b3fd62ea1a 96 #define STM_PIN_DEFINE_EXT(FUNC_OD, PUPD, AFNUM, CHAN, INV) \
NYX 0:85b3fd62ea1a 97 ((int)(FUNC_OD) |\
NYX 0:85b3fd62ea1a 98 ((PUPD & STM_PIN_PUPD_MASK) << STM_PIN_PUPD_SHIFT) |\
NYX 0:85b3fd62ea1a 99 ((AFNUM & STM_PIN_AFNUM_MASK) << STM_PIN_AFNUM_SHIFT) |\
NYX 0:85b3fd62ea1a 100 ((CHAN & STM_PIN_CHAN_MASK) << STM_PIN_CHAN_SHIFT) |\
NYX 0:85b3fd62ea1a 101 ((INV & STM_PIN_INV_MASK) << STM_PIN_INV_SHIFT))
NYX 0:85b3fd62ea1a 102
NYX 0:85b3fd62ea1a 103 /*
NYX 0:85b3fd62ea1a 104 * MACROS to support the legacy definition of PIN formats
NYX 0:85b3fd62ea1a 105 * The STM_MODE_ defines contain the function and the Push-pull/OpenDrain
NYX 0:85b3fd62ea1a 106 * configuration (legacy inheritance).
NYX 0:85b3fd62ea1a 107 */
NYX 0:85b3fd62ea1a 108 #define STM_PIN_DATA(FUNC_OD, PUPD, AFNUM) \
NYX 0:85b3fd62ea1a 109 STM_PIN_DEFINE(FUNC_OD, PUPD, AFNUM)
NYX 0:85b3fd62ea1a 110 #define STM_PIN_DATA_EXT(FUNC_OD, PUPD, AFNUM, CHANNEL, INVERTED) \
NYX 0:85b3fd62ea1a 111 STM_PIN_DEFINE_EXT(FUNC_OD, PUPD, AFNUM, CHANNEL, INVERTED)
NYX 0:85b3fd62ea1a 112
NYX 0:85b3fd62ea1a 113 typedef enum {
NYX 0:85b3fd62ea1a 114 STM_PIN_INPUT = 0,
NYX 0:85b3fd62ea1a 115 STM_PIN_OUTPUT = 1,
NYX 0:85b3fd62ea1a 116 STM_PIN_ALTERNATE = 2,
NYX 0:85b3fd62ea1a 117 STM_PIN_ANALOG = 3,
NYX 0:85b3fd62ea1a 118 } StmPinFunction;
NYX 0:85b3fd62ea1a 119
NYX 0:85b3fd62ea1a 120 #define STM_MODE_INPUT (STM_PIN_INPUT)
NYX 0:85b3fd62ea1a 121 #define STM_MODE_OUTPUT_PP (STM_PIN_OUTPUT)
NYX 0:85b3fd62ea1a 122 #define STM_MODE_OUTPUT_OD (STM_PIN_OUTPUT | STM_PIN_OD_BITS)
NYX 0:85b3fd62ea1a 123 #define STM_MODE_AF_PP (STM_PIN_ALTERNATE)
NYX 0:85b3fd62ea1a 124 #define STM_MODE_AF_OD (STM_PIN_ALTERNATE | STM_PIN_OD_BITS)
NYX 0:85b3fd62ea1a 125 #define STM_MODE_ANALOG (STM_PIN_ANALOG)
NYX 0:85b3fd62ea1a 126 #define STM_MODE_ANALOG_ADC_CONTROL (STM_PIN_ANALOG | STM_PIN_ANALOG_CONTROL_BIT)
NYX 0:85b3fd62ea1a 127
NYX 0:85b3fd62ea1a 128 // High nibble = port number (0=A, 1=B, 2=C, 3=D, 4=E, 5=F, 6=G, 7=H)
NYX 0:85b3fd62ea1a 129 // Low nibble = pin number
NYX 0:85b3fd62ea1a 130 #define STM_PORT(X) (((uint32_t)(X) >> 4) & 0xF)
NYX 0:85b3fd62ea1a 131 #define STM_PIN(X) ((uint32_t)(X) & 0xF)
NYX 0:85b3fd62ea1a 132
NYX 0:85b3fd62ea1a 133 /* Defines to be used by application */
NYX 0:85b3fd62ea1a 134 typedef enum {
NYX 0:85b3fd62ea1a 135 PIN_INPUT = 0,
NYX 0:85b3fd62ea1a 136 PIN_OUTPUT
NYX 0:85b3fd62ea1a 137 } PinDirection;
NYX 0:85b3fd62ea1a 138
NYX 0:85b3fd62ea1a 139 typedef enum {
NYX 0:85b3fd62ea1a 140 PullNone = 0,
NYX 0:85b3fd62ea1a 141 PullUp = 1,
NYX 0:85b3fd62ea1a 142 PullDown = 2,
NYX 0:85b3fd62ea1a 143 OpenDrainPullUp = 3,
NYX 0:85b3fd62ea1a 144 OpenDrainNoPull = 4,
NYX 0:85b3fd62ea1a 145 OpenDrainPullDown = 5,
NYX 0:85b3fd62ea1a 146 PushPullNoPull = PullNone,
NYX 0:85b3fd62ea1a 147 PushPullPullUp = PullUp,
NYX 0:85b3fd62ea1a 148 PushPullPullDown = PullDown,
NYX 0:85b3fd62ea1a 149 OpenDrain = OpenDrainPullUp,
NYX 0:85b3fd62ea1a 150 PullDefault = PullNone
NYX 0:85b3fd62ea1a 151 } PinMode;
NYX 0:85b3fd62ea1a 152
NYX 0:85b3fd62ea1a 153 #ifdef __cplusplus
NYX 0:85b3fd62ea1a 154 }
NYX 0:85b3fd62ea1a 155 #endif
NYX 0:85b3fd62ea1a 156
NYX 0:85b3fd62ea1a 157 #endif
NYX 0:85b3fd62ea1a 158