Skip to content

Commit 58f40b8

Browse files
committed
Add new bitfield to manage ADC channel bank
For STM32L1xx, in Cat.3, Cat.4, Cat.5 and Cat.6 devices there are up to 42 multiplexed channels organized in 2 banks. Channels ADC_IN0 to ADC_IN31 are available in Bank A and channels ADC_IN0b to ADC_IN31b are available in Bank B. Signed-off-by: Frederic Pillon <frederic.pillon@st.com>
1 parent 8160331 commit 58f40b8

File tree

1 file changed

+32
-41
lines changed

1 file changed

+32
-41
lines changed

cores/arduino/stm32/PinNamesTypes.h

Lines changed: 32 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,13 @@
1-
/* *******************************************************************************
2-
* Copyright (c) 2016, STMicroelectronics
1+
/*
2+
*******************************************************************************
3+
* Copyright (c) 2016-2021, STMicroelectronics
34
* All rights reserved.
45
*
5-
* Redistribution and use in source and binary forms, with or without
6-
* modification, are permitted provided that the following conditions are met:
7-
*
8-
* 1. Redistributions of source code must retain the above copyright notice,
9-
* this list of conditions and the following disclaimer.
10-
* 2. Redistributions in binary form must reproduce the above copyright notice,
11-
* this list of conditions and the following disclaimer in the documentation
12-
* and/or other materials provided with the distribution.
13-
* 3. Neither the name of STMicroelectronics nor the names of its contributors
14-
* may be used to endorse or promote products derived from this software
15-
* without specific prior written permission.
6+
* This software component is licensed by ST under BSD 3-Clause license,
7+
* the "License"; You may not use this file except in compliance with the
8+
* License. You may obtain a copy of the License at:
9+
* opensource.org/licenses/BSD-3-Clause
1610
*
17-
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
18-
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19-
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
20-
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
21-
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22-
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
23-
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
24-
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
25-
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26-
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2711
*******************************************************************************
2812
*/
2913
#ifndef _PINNAMESTYPES_H
@@ -42,7 +26,8 @@ extern "C" {
4226
* [19:15] Channel (Analog/Timer specific)
4327
* [20] Inverted (Analog/Timer specific)
4428
* [21] Analog ADC control - Only valid for specific families
45-
* [32:22] Reserved
29+
* [22] Analog channel bank B - Only valid for specific families
30+
* [32:23] Reserved
4631
*/
4732

4833
#define STM_PIN_FUNCTION_MASK 0x07
@@ -77,16 +62,21 @@ extern "C" {
7762
#define STM_PIN_AN_CTRL_SHIFT 21
7863
#define STM_PIN_ANALOG_CONTROL_BIT (STM_PIN_AN_CTRL_MASK << STM_PIN_AN_CTRL_SHIFT)
7964

80-
#define STM_PIN_FUNCTION(X) (((X) >> STM_PIN_FUNCTION_SHIFT) & STM_PIN_FUNCTION_MASK)
81-
#define STM_PIN_OD(X) (((X) >> STM_PIN_OD_SHIFT) & STM_PIN_OD_MASK)
82-
#define STM_PIN_PUPD(X) (((X) >> STM_PIN_PUPD_SHIFT) & STM_PIN_PUPD_MASK)
83-
#define STM_PIN_SPEED(X) (((X) >> STM_PIN_SPEED_SHIFT) & STM_PIN_SPEED_MASK)
84-
#define STM_PIN_AFNUM(X) (((X) >> STM_PIN_AFNUM_SHIFT) & STM_PIN_AFNUM_MASK)
85-
#define STM_PIN_CHANNEL(X) (((X) >> STM_PIN_CHAN_SHIFT) & STM_PIN_CHAN_MASK)
86-
#define STM_PIN_INVERTED(X) (((X) >> STM_PIN_INV_SHIFT) & STM_PIN_INV_MASK)
87-
#define STM_PIN_ANALOG_CONTROL(X) (((X) >> STM_PIN_AN_CTRL_SHIFT) & STM_PIN_AN_CTRL_MASK)
88-
#define STM_PIN_MODE(X) ((STM_PIN_OD((X)) << 4) | \
89-
(STM_PIN_FUNCTION((X)) & (~STM_PIN_OD_BITS)))
65+
#define STM_PIN_AN_CHAN_BANK_B_MASK 0x01
66+
#define STM_PIN_AN_CHAN_BANK_B_SHIFT 22
67+
#define STM_PIN_ANALOG_CHAN_BANK_B_BIT (STM_PIN_AN_CHAN_BANK_B_MASK << STM_PIN_AN_CHAN_BANK_B_SHIFT)
68+
69+
#define STM_PIN_FUNCTION(X) (((X) >> STM_PIN_FUNCTION_SHIFT) & STM_PIN_FUNCTION_MASK)
70+
#define STM_PIN_OD(X) (((X) >> STM_PIN_OD_SHIFT) & STM_PIN_OD_MASK)
71+
#define STM_PIN_PUPD(X) (((X) >> STM_PIN_PUPD_SHIFT) & STM_PIN_PUPD_MASK)
72+
#define STM_PIN_SPEED(X) (((X) >> STM_PIN_SPEED_SHIFT) & STM_PIN_SPEED_MASK)
73+
#define STM_PIN_AFNUM(X) (((X) >> STM_PIN_AFNUM_SHIFT) & STM_PIN_AFNUM_MASK)
74+
#define STM_PIN_CHANNEL(X) (((X) >> STM_PIN_CHAN_SHIFT) & STM_PIN_CHAN_MASK)
75+
#define STM_PIN_INVERTED(X) (((X) >> STM_PIN_INV_SHIFT) & STM_PIN_INV_MASK)
76+
#define STM_PIN_ANALOG_CONTROL(X) (((X) >> STM_PIN_AN_CTRL_SHIFT) & STM_PIN_AN_CTRL_MASK)
77+
#define STM_PIN_ANALOG_CHANNEL_BANK_B(X) (((X) >> STM_PIN_AN_CHAN_BANK_B_SHIFT) & STM_PIN_AN_CHAN_BANK_B_MASK)
78+
#define STM_PIN_MODE(X) ((STM_PIN_OD((X)) << 4) | \
79+
(STM_PIN_FUNCTION((X)) & (~STM_PIN_OD_BITS)))
9080

9181
#define STM_PIN_DEFINE(FUNC_OD, PUPD, AFNUM) ((int)(FUNC_OD) |\
9282
((PUPD & STM_PIN_PUPD_MASK) << STM_PIN_PUPD_SHIFT) |\
@@ -116,13 +106,14 @@ typedef enum {
116106
STM_PIN_ANALOG = 3,
117107
} StmPinFunction;
118108

119-
#define STM_MODE_INPUT (STM_PIN_INPUT)
120-
#define STM_MODE_OUTPUT_PP (STM_PIN_OUTPUT)
121-
#define STM_MODE_OUTPUT_OD (STM_PIN_OUTPUT | STM_PIN_OD_BITS)
122-
#define STM_MODE_AF_PP (STM_PIN_ALTERNATE)
123-
#define STM_MODE_AF_OD (STM_PIN_ALTERNATE | STM_PIN_OD_BITS)
124-
#define STM_MODE_ANALOG (STM_PIN_ANALOG)
125-
#define STM_MODE_ANALOG_ADC_CONTROL (STM_PIN_ANALOG | STM_PIN_ANALOG_CONTROL_BIT)
109+
#define STM_MODE_INPUT (STM_PIN_INPUT)
110+
#define STM_MODE_OUTPUT_PP (STM_PIN_OUTPUT)
111+
#define STM_MODE_OUTPUT_OD (STM_PIN_OUTPUT | STM_PIN_OD_BITS)
112+
#define STM_MODE_AF_PP (STM_PIN_ALTERNATE)
113+
#define STM_MODE_AF_OD (STM_PIN_ALTERNATE | STM_PIN_OD_BITS)
114+
#define STM_MODE_ANALOG (STM_PIN_ANALOG)
115+
#define STM_MODE_ANALOG_ADC_CONTROL (STM_PIN_ANALOG | STM_PIN_ANALOG_CONTROL_BIT)
116+
#define STM_MODE_ANALOG_ADC_CHANNEL_BANK_B (STM_PIN_ANALOG | STM_PIN_ANALOG_CHAN_BANK_B_BIT)
126117

127118
// High nibble = port number (FirstPort <= PortName <= LastPort)
128119
// Low nibble = pin number

0 commit comments

Comments
 (0)