2 * Copyright (c) 2023 ARM Limited. All rights reserved.
4 * SPDX-License-Identifier: Apache-2.0
6 * Licensed under the Apache License, Version 2.0 (the License); you may
7 * not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an AS IS BASIS, WITHOUT
14 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License.
18 * $Date: 2. March 2023
21 * Project: GPIO (General-purpose Input/Output) Driver definitions
24 #ifndef DRIVER_GPIO_H_
25 #define DRIVER_GPIO_H_
32 #include "Driver_Common.h"
38 typedef uint32_t ARM_GPIO_Pin_t;
44 ARM_GPIO_INPUT, ///< Input (default)
45 ARM_GPIO_OUTPUT ///< Output
49 \brief GPIO Output Mode
52 ARM_GPIO_PUSH_PULL, ///< Push-pull (default)
53 ARM_GPIO_OPEN_DRAIN ///< Open-drain
54 } ARM_GPIO_OUTPUT_MODE;
57 \brief GPIO Pull Resistor
60 ARM_GPIO_PULL_NONE, ///< None (default)
61 ARM_GPIO_PULL_UP, ///< Pull-up
62 ARM_GPIO_PULL_DOWN ///< Pull-down
63 } ARM_GPIO_PULL_RESISTOR;
66 \brief GPIO Event Trigger
69 ARM_GPIO_TRIGGER_NONE, ///< None (default)
70 ARM_GPIO_TRIGGER_RISING_EDGE, ///< Rising-edge
71 ARM_GPIO_TRIGGER_FALLING_EDGE, ///< Falling-edge
72 ARM_GPIO_TRIGGER_EITHER_EDGE ///< Either edge (rising and falling)
73 } ARM_GPIO_EVENT_TRIGGER;
76 /****** GPIO Event *****/
77 #define ARM_GPIO_EVENT_RISING_EDGE (1UL << 0) ///< Rising-edge detected
78 #define ARM_GPIO_EVENT_FALLING_EDGE (1UL << 1) ///< Falling-edge detected
79 #define ARM_GPIO_EVENT_EITHER_EDGE (1UL << 2) ///< Either edge detected (only when hardware cannot distinguish between rising and falling edge)
82 /****** GPIO specific error codes *****/
83 #define ARM_GPIO_ERROR_PIN (ARM_DRIVER_ERROR_SPECIFIC - 1) ///< Specified Pin not available
86 // Function documentation
88 \fn int32_t ARM_GPIO_Setup (ARM_GPIO_Pin_t pin, ARM_GPIO_SignalEvent_t cb_event)
89 \brief Setup GPIO Interface.
90 \param[in] pin GPIO Pin
91 \param[in] cb_event Pointer to \ref ARM_GPIO_SignalEvent
92 \return \ref execution_status
94 \fn int32_t ARM_GPIO_SetDirection (ARM_GPIO_Pin_t pin, ARM_GPIO_DIRECTION direction)
95 \brief Set GPIO Direction.
96 \param[in] pin GPIO Pin
97 \param[in] direction \ref ARM_GPIO_DIRECTION
98 \return \ref execution_status
100 \fn int32_t ARM_GPIO_SetOutputMode (ARM_GPIO_Pin_t pin, ARM_GPIO_OUTPUT_MODE mode)
101 \brief Set GPIO Output Mode.
102 \param[in] pin GPIO Pin
103 \param[in] mode \ref ARM_GPIO_OUTPUT_MODE
104 \return \ref execution_status
106 \fn int32_t ARM_GPIO_SetPullResistor (ARM_GPIO_Pin_t pin, ARM_GPIO_PULL_RESISTOR resistor)
107 \brief Set GPIO Pull Resistor.
108 \param[in] pin GPIO Pin
109 \param[in] resistor \ref ARM_GPIO_PULL_RESISTOR
110 \return \ref execution_status
112 \fn int32_t ARM_GPIO_SetEventTrigger (ARM_GPIO_Pin_t pin, ARM_GPIO_EVENT_TRIGGER trigger)
113 \brief Set GPIO Event Trigger.
114 \param[in] pin GPIO Pin
115 \param[in] trigger \ref ARM_GPIO_EVENT_TRIGGER
116 \return \ref execution_status
118 \fn void ARM_GPIO_SetOutput (ARM_GPIO_Pin_t pin, uint32_t val)
119 \brief Set GPIO Output Level.
120 \param[in] pin GPIO Pin
121 \param[in] level GPIO Pin Level (0 or 1)
123 \fn uint32_t ARM_GPIO_GetInput (ARM_GPIO_Pin_t pin)
124 \brief Get GPIO Input Level.
125 \param[in] pin GPIO Pin
126 \return GPIO Pin Level (0 or 1)
128 \fn void ARM_GPIO_SignalEvent (ARM_GPIO_Pin_t pin, uint32_t event)
129 \brief Signal GPIO Events.
130 \param[in] pin GPIO Pin on which event occurred
131 \param[in] event \ref GPIO_events notification mask
134 typedef void (*ARM_GPIO_SignalEvent_t) (ARM_GPIO_Pin_t pin, uint32_t event); /* Pointer to \ref ARM_GPIO_SignalEvent : Signal GPIO Event */
138 \brief Access structure of the GPIO Driver.
141 int32_t (*Setup) (ARM_GPIO_Pin_t pin, ARM_GPIO_SignalEvent_t cb_event); ///< Pointer to \ref ARM_GPIO_Setup : Setup GPIO Interface.
142 int32_t (*SetDirection) (ARM_GPIO_Pin_t pin, ARM_GPIO_DIRECTION direction); ///< Pointer to \ref ARM_GPIO_SetDirection : Set GPIO Direction.
143 int32_t (*SetOutputMode) (ARM_GPIO_Pin_t pin, ARM_GPIO_OUTPUT_MODE mode); ///< Pointer to \ref ARM_GPIO_SetOutputMode : Set GPIO Output Mode.
144 int32_t (*SetPullResistor) (ARM_GPIO_Pin_t pin, ARM_GPIO_PULL_RESISTOR resistor); ///< Pointer to \ref ARM_GPIO_SetPullResistor : Set GPIO Pull Resistor.
145 int32_t (*SetEventTrigger) (ARM_GPIO_Pin_t pin, ARM_GPIO_EVENT_TRIGGER trigger); ///< Pointer to \ref ARM_GPIO_SetEventTrigger : Set GPIO Event Trigger.
146 void (*SetOutput) (ARM_GPIO_Pin_t pin, uint32_t level); ///< Pointer to \ref ARM_GPIO_SetOutput : Set GPIO Output Level.
147 uint32_t (*GetInput) (ARM_GPIO_Pin_t pin); ///< Pointer to \ref ARM_GPIO_GetInput : Get GPIO Input Level.
148 } const ARM_DRIVER_GPIO;
154 #endif /* DRIVER_GPIO_H_ */