The official Mbed 2 C/C++ SDK provides the software platform and libraries to build your applications.

Dependents:   hello SerialTestv11 SerialTestv12 Sierpinski ... more

mbed 2

This is the mbed 2 library. If you'd like to learn about Mbed OS please see the mbed-os docs.

Committer:
Anna Bridge
Date:
Fri Jun 22 15:38:59 2018 +0100
Revision:
169:a7c7b631e539
Parent:
167:84c0a372a020
mbed library. Release version 162

Who changed what in which revision?

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