VSF Documented
gpio.h
Go to the documentation of this file.
1/*****************************************************************************
2 * Copyright(C)2009-2022 by VSF Team *
3 * *
4 * Licensed under the Apache License, Version 2.0 (the "License"); *
5 * you may not use this file except in compliance with the License. *
6 * You may obtain a copy of the License at *
7 * *
8 * http://www.apache.org/licenses/LICENSE-2.0 *
9 * *
10 * Unless required by applicable law or agreed to in writing, software *
11 * distributed under the License is distributed on an "AS IS" BASIS, *
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. *
13 * See the License for the specific language governing permissions and *
14 * limitations under the License. *
15 * *
16 ****************************************************************************/
17
18#ifndef __HAL_DRIVER_RP2040_GPIO_H__
19#define __HAL_DRIVER_RP2040_GPIO_H__
20
21/*============================ INCLUDES ======================================*/
22
23#include "hal/vsf_hal_cfg.h"
24
25#if VSF_HAL_USE_GPIO == ENABLED
26
27#include "../__device.h"
28
29/*============================ MACROS ========================================*/
30
31/* RP2040 hardware constants for the FUNCSEL field in IO_BANK0.GPIOx_CTRL. */
32#define __VSF_HW_GPIO_FUNCSEL_SHIFT 0
33#define __VSF_HW_GPIO_FUNCSEL_BITS 5
34#define __VSF_HW_GPIO_FUNCSEL_MASK ((1u << __VSF_HW_GPIO_FUNCSEL_BITS) - 1)
35#define __VSF_HW_GPIO_FUNCSEL_SIO 5u
36#define __VSF_HW_GPIO_FUNCSEL_NULL 0x1Fu /* 31 = NULL function */
37
38/* Bit positions in the packed vsf_gpio_mode_t. */
39#define __VSF_HW_GPIO_IS_OUTPUT_POS 5
40#define __VSF_HW_GPIO_IS_AF_POS 14
41#define __VSF_HW_GPIO_OD_EMULATED_POS 15
42#define __VSF_HW_GPIO_PULL_POS 8
43#define __VSF_HW_GPIO_PULL_MASK 0x3u
44#define __VSF_HW_GPIO_EXTI_TRIG_POS 10
45#define __VSF_HW_GPIO_EXTI_TRIG_MASK 0xFu
46
47/* PADS_BANK0 bit positions — directly encoded in mode bits [7:6]. */
48#define __RP2040_PADS_PDE (1u << 2)
49#define __RP2040_PADS_PUE (1u << 3)
50#define __RP2040_PADS_IE (1u << 6) /* mode bit 6 */
51#define __RP2040_PADS_OD (1u << 7) /* mode bit 7 */
52
53/* PADS_BANK0 reset default: SCHMITT=1 (bit 1), DRIVE=01 (bit 4). */
54#define __RP2040_PADS_DEFAULT 0x12
55
56/*============================ MACROFIED FUNCTIONS ===========================*/
57/*============================ TYPES =========================================*/
58
59/* The RP2040 GPIO driver reimplements vsf_gpio_mode_t so that mode bits
60 * directly encode hardware register fields, eliminating manual translation
61 * in gpio.c.
62 *
63 * Bit layout:
64 * [4:0] FUNCSEL — written directly to IO_BANK0.GPIOx_CTRL
65 * __VSF_HW_GPIO_FUNCSEL_SIO (for INPUT/OUTPUT/EXTI)
66 * __VSF_HW_GPIO_FUNCSEL_NULL (for ANALOG)
67 * [5] is_output — direction hint; RP2040 direction is SIO.OE, not PADS
68 * [6] IE — directly maps to PADS_BANK0 bit 6 (input enable)
69 * [7] OD — directly maps to PADS_BANK0 bit 7 (output disable)
70 * [9:8] pull: 0 = none, 1 = up, 2 = down
71 * [13:10] EXTI trigger — directly maps to IO_BANK0 INTR/INTE 4-bit field
72 * 1 = LEVEL_LOW, 2 = LEVEL_HIGH, 4 = EDGE_LOW, 8 = EDGE_HIGH
73 * [14] is_AF — alternate function mode, FUNCSEL from cfg.alternate_function
74 * [15] OD_emulated — open-drain is software-emulated via OE toggling
75 *
76 * Hardware reference (RP2040 datasheet, IO_BANK0 / PADS_BANK0 / SIO):
77 * IO_BANK0 GPIOn_CTRL: [4:0] FUNCSEL
78 * PADS_BANK0 GPIOn: [7] OD, [6] IE, [3] PUE, [2] PDE
79 * SIO: gpio_oe, gpio_out, gpio_in
80 */
81
82#define VSF_GPIO_CFG_REIMPLEMENT_TYPE_MODE ENABLED
83
84typedef enum vsf_gpio_mode_t {
85 /* Base modes — FUNCSEL in bits [4:0], PADS IE/OD in bits [7:6] */
112
113 /* Pull-up / pull-down */
117
118 /* EXTI trigger modes — values directly usable as RP2040 INTR/INTE field */
127
128/*============================ INCLUDES ======================================*/
129/*============================ PROTOTYPES ====================================*/
130
131#endif /* VSF_HAL_USE_GPIO */
132#endif /* __HAL_DRIVER_RP2040_GPIO_H__ */
133/* EOF */
vsf_gpio_mode_t
Definition gpio.h:31
@ VSF_GPIO_NO_PULL_UP_DOWN
Definition gpio.h:39
@ VSF_GPIO_EXTI_MODE_HIGH_LEVEL
Definition gpio.h:50
@ VSF_GPIO_OUTPUT_PUSH_PULL
Definition gpio.h:43
@ VSF_GPIO_EXTI
Definition gpio.h:45
@ VSF_GPIO_EXTI_MODE_LOW_LEVEL
Definition gpio.h:49
@ VSF_GPIO_EXTI_MODE_NONE
Definition gpio.h:48
@ VSF_GPIO_EXTI_MODE_RISING
Definition gpio.h:51
@ VSF_GPIO_EXTI_MODE_RISING_FALLING
Definition gpio.h:53
@ VSF_GPIO_PULL_UP
Definition gpio.h:37
@ VSF_GPIO_AF
Definition gpio.h:46
@ VSF_GPIO_INPUT
Definition gpio.h:41
@ VSF_GPIO_ANALOG
Definition gpio.h:44
@ VSF_GPIO_EXTI_MODE_FALLING
Definition gpio.h:52
@ VSF_GPIO_OUTPUT_OPEN_DRAIN
Definition gpio.h:42
@ VSF_GPIO_PULL_DOWN
Definition gpio.h:38
#define __RP2040_PADS_IE
Definition gpio.h:50
#define __RP2040_PADS_OD
Definition gpio.h:51
#define __VSF_HW_GPIO_FUNCSEL_SIO
Definition gpio.h:35
#define __VSF_HW_GPIO_FUNCSEL_SHIFT
Definition gpio.h:32
#define __VSF_HW_GPIO_OD_EMULATED_POS
Definition gpio.h:41
#define __VSF_HW_GPIO_FUNCSEL_NULL
Definition gpio.h:36
#define __VSF_HW_GPIO_PULL_POS
Definition gpio.h:42
#define __VSF_HW_GPIO_EXTI_TRIG_POS
Definition gpio.h:44
#define __VSF_HW_GPIO_IS_OUTPUT_POS
Definition gpio.h:39
#define __VSF_HW_GPIO_IS_AF_POS
Definition gpio.h:40
Generated from commit: vsfteam/vsf@3b461d0