ATY_LIB V2_102_230218
ATY_LIB for general devices or ALGO
 
Loading...
Searching...
No Matches
fw_gpio.h
Go to the documentation of this file.
1// Copyright 2021 IOsetting <iosetting(at)outlook.com>
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7// http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15#ifndef ___FW_GPIO_H___
16#define ___FW_GPIO_H___
17
18#include "fw_conf.h"
19#include "fw_types.h"
20
21typedef enum
22{
23 GPIO_Mode_InOut_QBD = 0x00, /* quasi-bidirectional(be compatible with classical 8051 MCUs) */
24 GPIO_Mode_Output_PP = 0x01, /* push-pull output */
25 GPIO_Mode_Input_HIP = 0x02, /* high-impedance input */
26 GPIO_Mode_InOut_OD = 0x03, /* open drain output */
28
29typedef enum
30{
37#if (__CONF_MCU_TYPE == 1 ) || (__CONF_MCU_TYPE == 3 )
40#endif
42
43typedef enum
44{
55
56typedef enum
57{
61
62typedef enum
63{
67
68typedef enum
69{
73
74#define GPIO_P0_SetMode(__PINS__, __MODE__) do { \
75 P0M0 = P0M0 & ~(__PINS__) | (((__MODE__) & 0x01)? (__PINS__) : 0x00); \
76 P0M1 = P0M1 & ~(__PINS__) | (((__MODE__) & 0x02)? (__PINS__) : 0x00); \
77 } while(0)
78
79#define GPIO_P1_SetMode(__PINS__, __MODE__) do { \
80 P1M0 = P1M0 & ~(__PINS__) | (((__MODE__) & 0x01)? (__PINS__) : 0x00); \
81 P1M1 = P1M1 & ~(__PINS__) | (((__MODE__) & 0x02)? (__PINS__) : 0x00); \
82 } while(0)
83
84#define GPIO_P2_SetMode(__PINS__, __MODE__) do { \
85 P2M0 = P2M0 & ~(__PINS__) | (((__MODE__) & 0x01)? (__PINS__) : 0x00); \
86 P2M1 = P2M1 & ~(__PINS__) | (((__MODE__) & 0x02)? (__PINS__) : 0x00); \
87 } while(0)
88
89#define GPIO_P3_SetMode(__PINS__, __MODE__) do { \
90 P3M0 = P3M0 & ~(__PINS__) | (((__MODE__) & 0x01)? (__PINS__) : 0x00); \
91 P3M1 = P3M1 & ~(__PINS__) | (((__MODE__) & 0x02)? (__PINS__) : 0x00); \
92 } while(0)
93
94#define GPIO_P4_SetMode(__PINS__, __MODE__) do { \
95 P4M0 = P4M0 & ~(__PINS__) | (((__MODE__) & 0x01)? (__PINS__) : 0x00); \
96 P4M1 = P4M1 & ~(__PINS__) | (((__MODE__) & 0x02)? (__PINS__) : 0x00); \
97 } while(0)
98
99#define GPIO_P5_SetMode(__PINS__, __MODE__) do { \
100 P5M0 = P5M0 & ~(__PINS__) | (((__MODE__) & 0x01)? (__PINS__) : 0x00); \
101 P5M1 = P5M1 & ~(__PINS__) | (((__MODE__) & 0x02)? (__PINS__) : 0x00); \
102 } while(0)
103
104#if (__CONF_MCU_TYPE == 1 ) || (__CONF_MCU_TYPE == 3 )
105#define GPIO_P6_SetMode(__PINS__, __MODE__) do { \
106 P6M0 = P6M0 & ~(__PINS__) | (((__MODE__) & 0x01)? (__PINS__) : 0x00); \
107 P6M1 = P6M1 & ~(__PINS__) | (((__MODE__) & 0x02)? (__PINS__) : 0x00); \
108 } while(0)
109
110#define GPIO_P7_SetMode(__PINS__, __MODE__) do { \
111 P7M0 = P7M0 & ~(__PINS__) | (((__MODE__) & 0x01)? (__PINS__) : 0x00); \
112 P7M1 = P7M1 & ~(__PINS__) | (((__MODE__) & 0x02)? (__PINS__) : 0x00); \
113 } while(0)
114#endif
115
116#define GPIO_SetPullUp(__PORT__, __PINS__, __STATE__) do { \
117 SFRX_ON(); \
118 SFRX(PxPU + (__PORT__)) = SFRX(PxPU + (__PORT__)) \
119 & ~(__PINS__) | (((__STATE__) & 0x01)? (__PINS__) : 0x00); \
120 SFRX_OFF(); \
121 } while(0)
122
123#define GPIO_SetSchmittTrigger(__PORT__, __PINS__, __STATE__) do { \
124 SFRX_ON(); \
125 SFRX(PxNCS + (__PORT__)) = SFRX(PxNCS + (__PORT__)) \
126 & ~(__PINS__) | (((__STATE__) & 0x01)? (__PINS__) : 0x00); \
127 SFRX_OFF(); \
128 } while(0)
129
130#define GPIO_SetSwitchSpeed(__PORT__, __PINS__, __STATE__) do { \
131 SFRX_ON(); \
132 SFRX(PxSR + (__PORT__)) = SFRX(PxSR + (__PORT__)) \
133 & ~(__PINS__) | (((__STATE__) & 0x01)? (__PINS__) : 0x00); \
134 SFRX_OFF(); \
135 } while(0)
136
137#define GPIO_SetDriveCapability(__PORT__, __PINS__, __STATE__) do { \
138 SFRX_ON(); \
139 SFRX(PxDR + (__PORT__)) = SFRX(PxDR + (__PORT__)) \
140 & ~(__PINS__) | (((__STATE__) & 0x01)? (__PINS__) : 0x00); \
141 SFRX_OFF(); \
142 } while(0)
143
144#define GPIO_SetDigitalInput(__PORT__, __PINS__, __STATE__) do { \
145 SFRX_ON(); \
146 SFRX(PxIE + (__PORT__)) = SFRX(PxIE + (__PORT__)) \
147 & ~(__PINS__) | (((__STATE__) & 0x01)? (__PINS__) : 0x00); \
148 SFRX_OFF(); \
149 } while(0)
150
151
152#endif
GPIO_SwitchSpeed_t
Definition: fw_gpio.h:63
@ GPIO_SwitchSpeed_Low
Definition: fw_gpio.h:65
@ GPIO_SwitchSpeed_High
Definition: fw_gpio.h:64
GPIO_SchmittTrigger_t
Definition: fw_gpio.h:57
@ GPIO_SchmittTrigger_ON
Definition: fw_gpio.h:58
@ GPIO_SchmittTrigger_OFF
Definition: fw_gpio.h:59
GPIO_Pin_t
Definition: fw_gpio.h:44
@ GPIO_Pin_5
Definition: fw_gpio.h:50
@ GPIO_Pin_2
Definition: fw_gpio.h:47
@ GPIO_Pin_0
Definition: fw_gpio.h:45
@ GPIO_Pin_4
Definition: fw_gpio.h:49
@ GPIO_Pin_3
Definition: fw_gpio.h:48
@ GPIO_Pin_All
Definition: fw_gpio.h:53
@ GPIO_Pin_1
Definition: fw_gpio.h:46
@ GPIO_Pin_6
Definition: fw_gpio.h:51
@ GPIO_Pin_7
Definition: fw_gpio.h:52
GPIO_DriveCapability_t
Definition: fw_gpio.h:69
@ GPIO_DriveCapability_Normal
Definition: fw_gpio.h:71
@ GPIO_DriveCapability_High
Definition: fw_gpio.h:70
GPIO_Port_t
Definition: fw_gpio.h:30
@ GPIO_Port_6
Definition: fw_gpio.h:38
@ GPIO_Port_1
Definition: fw_gpio.h:32
@ GPIO_Port_0
Definition: fw_gpio.h:31
@ GPIO_Port_4
Definition: fw_gpio.h:35
@ GPIO_Port_5
Definition: fw_gpio.h:36
@ GPIO_Port_3
Definition: fw_gpio.h:34
@ GPIO_Port_2
Definition: fw_gpio.h:33
@ GPIO_Port_7
Definition: fw_gpio.h:39
GPIO_Mode_t
Definition: fw_gpio.h:22
@ GPIO_Mode_InOut_OD
Definition: fw_gpio.h:26
@ GPIO_Mode_Input_HIP
Definition: fw_gpio.h:25
@ GPIO_Mode_Output_PP
Definition: fw_gpio.h:24
@ GPIO_Mode_InOut_QBD
Definition: fw_gpio.h:23
#define B00010000
Definition: fw_types.h:40
#define B11111111
Definition: fw_types.h:65
#define B00100000
Definition: fw_types.h:45
#define B00001000
Definition: fw_types.h:36
#define B00000001
Definition: fw_types.h:30
#define B00000010
Definition: fw_types.h:31
#define B10000000
Definition: fw_types.h:58
#define B00000100
Definition: fw_types.h:33
#define B01000000
Definition: fw_types.h:51