00

Committer:
ganlikun
Date:
Sun Jun 12 14:02:44 2022 +0000
Revision:
0:13413ea9a877
00

Who changed what in which revision?

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