Initial commit

Dependencies:   FastPWM

Committer:
lypinator
Date:
Wed Sep 16 01:11:49 2020 +0000
Revision:
0:bb348c97df44
Added PWM

Who changed what in which revision?

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