1 /*
2  * Copyright (c) 2023 ARM Limited. All rights reserved.
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  *
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
9  *
10  * www.apache.org/licenses/LICENSE-2.0
11  *
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.
17  */
18 
19 #include "Driver_GPIO.h"
20 
21 // Pin mapping
22 #define GPIO_MAX_PINS           64U
23 #define PIN_IS_AVAILABLE(n)     ((n) < GPIO_MAX_PINS)
24 
25 
26 // Setup GPIO Interface
GPIO_Setup(ARM_GPIO_Pin_t pin,ARM_GPIO_SignalEvent_t cb_event)27 static int32_t GPIO_Setup (ARM_GPIO_Pin_t pin, ARM_GPIO_SignalEvent_t cb_event) {
28   int32_t result = ARM_DRIVER_OK;
29 
30   if (PIN_IS_AVAILABLE(pin)) {
31   } else {
32     result = ARM_GPIO_ERROR_PIN;
33   }
34 
35   return result;
36 }
37 
38 // Set GPIO Direction
GPIO_SetDirection(ARM_GPIO_Pin_t pin,ARM_GPIO_DIRECTION direction)39 static int32_t GPIO_SetDirection (ARM_GPIO_Pin_t pin, ARM_GPIO_DIRECTION direction) {
40   int32_t result = ARM_DRIVER_OK;
41 
42   if (PIN_IS_AVAILABLE(pin)) {
43     switch (direction) {
44       case ARM_GPIO_INPUT:
45         break;
46       case ARM_GPIO_OUTPUT:
47         break;
48       default:
49         result = ARM_DRIVER_ERROR_PARAMETER;
50         break;
51     }
52   } else {
53     result = ARM_GPIO_ERROR_PIN;
54   }
55 
56   return result;
57 }
58 
59 // Set GPIO Output Mode
GPIO_SetOutputMode(ARM_GPIO_Pin_t pin,ARM_GPIO_OUTPUT_MODE mode)60 static int32_t GPIO_SetOutputMode (ARM_GPIO_Pin_t pin, ARM_GPIO_OUTPUT_MODE mode) {
61   int32_t result = ARM_DRIVER_OK;
62 
63   if (PIN_IS_AVAILABLE(pin)) {
64     switch (mode) {
65       case ARM_GPIO_PUSH_PULL:
66         break;
67       case ARM_GPIO_OPEN_DRAIN:
68         break;
69       default:
70         result = ARM_DRIVER_ERROR_PARAMETER;
71         break;
72     }
73   } else {
74     result = ARM_GPIO_ERROR_PIN;
75   }
76 
77   return result;
78 }
79 
80 // Set GPIO Pull Resistor
GPIO_SetPullResistor(ARM_GPIO_Pin_t pin,ARM_GPIO_PULL_RESISTOR resistor)81 static int32_t GPIO_SetPullResistor (ARM_GPIO_Pin_t pin, ARM_GPIO_PULL_RESISTOR resistor) {
82   int32_t result = ARM_DRIVER_OK;
83 
84   if (PIN_IS_AVAILABLE(pin)) {
85     switch (resistor) {
86       case ARM_GPIO_PULL_NONE:
87         break;
88       case ARM_GPIO_PULL_UP:
89         break;
90       case ARM_GPIO_PULL_DOWN:
91         break;
92       default:
93         result = ARM_DRIVER_ERROR_PARAMETER;
94         break;
95     }
96   } else {
97     result = ARM_GPIO_ERROR_PIN;
98   }
99 
100   return result;
101 }
102 
103 // Set GPIO Event Trigger
GPIO_SetEventTrigger(ARM_GPIO_Pin_t pin,ARM_GPIO_EVENT_TRIGGER trigger)104 static int32_t GPIO_SetEventTrigger (ARM_GPIO_Pin_t pin, ARM_GPIO_EVENT_TRIGGER trigger) {
105   int32_t result = ARM_DRIVER_OK;
106 
107   if (PIN_IS_AVAILABLE(pin)) {
108     switch (trigger) {
109       case ARM_GPIO_TRIGGER_NONE:
110         break;
111       case ARM_GPIO_TRIGGER_RISING_EDGE:
112         break;
113       case ARM_GPIO_TRIGGER_FALLING_EDGE:
114         break;
115       case ARM_GPIO_TRIGGER_EITHER_EDGE:
116         break;
117       default:
118         result = ARM_DRIVER_ERROR_PARAMETER;
119         break;
120     }
121   } else {
122     result = ARM_GPIO_ERROR_PIN;
123   }
124 
125   return result;
126 }
127 
128 // Set GPIO Output Level
GPIO_SetOutput(ARM_GPIO_Pin_t pin,uint32_t val)129 static void GPIO_SetOutput (ARM_GPIO_Pin_t pin, uint32_t val) {
130 
131   if (PIN_IS_AVAILABLE(pin)) {
132   }
133 }
134 
135 // Get GPIO Input Level
GPIO_GetInput(ARM_GPIO_Pin_t pin)136 static uint32_t GPIO_GetInput (ARM_GPIO_Pin_t pin) {
137   uint32_t val = 0U;
138 
139   if (PIN_IS_AVAILABLE(pin)) {
140   }
141   return val;
142 }
143 
144 
145 // GPIO Driver access structure
146 ARM_DRIVER_GPIO Driver_GPIO0 = {
147   GPIO_Setup,
148   GPIO_SetDirection,
149   GPIO_SetOutputMode,
150   GPIO_SetPullResistor,
151   GPIO_SetEventTrigger,
152   GPIO_SetOutput,
153   GPIO_GetInput
154 };
155