summaryrefslogtreecommitdiff
path: root/bsp/phytium/libraries/standalone/common/fpinctrl.h
blob: 891e8f74de714ed0c6fe3f4eb1d10d3b5863e73f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
/*
 * Copyright : (C) 2022 Phytium Information Technology, Inc.
 * All Rights Reserved.
 *
 * This program is OPEN SOURCE software: you can redistribute it and/or modify it
 * under the terms of the Phytium Public License as published by the Phytium Technology Co.,Ltd,
 * either version 1.0 of the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,but WITHOUT ANY WARRANTY;
 * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
 * See the Phytium Public License for more details.
 *
 *
 * FilePath: fpinctrl.h
 * Date: 2022-03-28 14:16:09
 * LastEditTime: 2022-03-28 14:16:10
 * Description:  This files is for IO pin ctrl API definition
 *
 * Modify History:
 *  Ver   Who        Date         Changes
 * ----- ------     --------    --------------------------------------
 * 1.0   zhugengyu   2022/3/28   init commit
 */
#ifndef  COMMON_FPINCTRL_H
#define  COMMON_FPINCTRL_H

#ifdef __cplusplus
extern "C"
{
#endif

/***************************** Include Files *********************************/
#include "ftypes.h"
#include "sdkconfig.h"

#if defined(CONFIG_TARGET_F2000_4) || defined(CONFIG_TARGET_D2000)
#ifndef FPIN_IO_CTRL
#define FPIN_IO_CTRL
#endif
#endif

#if defined(CONFIG_TARGET_E2000)
#ifndef FPIN_IO_PAD
#define FPIN_IO_PAD
#endif
#endif

#if defined(FPIN_IO_CTRL)
#include "fioctrl.h"
#endif

#if defined(FPIN_IO_PAD)
#include "fiopad.h"
#endif

/**************************** Type Definitions *******************************/

typedef enum
{
    FPIN_FUNC0 = 0b000,
    FPIN_FUNC1,
    FPIN_FUNC2,
    FPIN_FUNC3 = 0b011,
#if defined(FPIN_IO_PAD) /* E2000 support more pin func */
    FPIN_FUNC4,
    FPIN_FUNC5,
    FPIN_FUNC6,
    FPIN_FUNC7 = 0b111,
#endif
    FPIN_NUM_OF_FUNC
} FPinFunc; /* 引脚复用功能配置, func0为默认功能 */

#if defined(FPIN_IO_PAD) /* Only support driver strength config in E2000 */
typedef enum
{
    FPIN_DRV0 = 0b0000,
    FPIN_DRV1,
    FPIN_DRV2,
    FPIN_DRV3,
    FPIN_DRV4,
    FPIN_DRV5,
    FPIN_DRV6,
    FPIN_DRV7,
    FPIN_DRV8,
    FPIN_DRV9,
    FPIN_DRV10,
    FPIN_DRV11,
    FPIN_DRV12,
    FPIN_DRV13,
    FPIN_DRV14,
    FPIN_DRV15 = 0b1111,

    FPIN_NUM_OF_DRIVE
} FPinDrive; /* 引脚驱动能力配置 */
#endif

typedef enum
{
    FPIN_PULL_NONE = 0b00,
    FPIN_PULL_DOWN = 0b01,
    FPIN_PULL_UP = 0b10,

    FPIN_NUM_OF_PULL
} FPinPull; /* 引脚上下拉配置 */

typedef enum
{
    FPIN_OUTPUT_DELAY = 0, /* 延时设置方向为输出 */
    FPIN_INPUT_DELAY, /* 延时设置方向为输入 */

    FPIN_NUM_OF_DELAY_DIR
} FPinDelayDir; /* 引脚延时配置方向 */

typedef enum
{
    FPIN_DELAY_COARSE_TUNING = 0, /* 延迟粗调档位 */
    FPIN_DELAY_FINE_TUNING, /* 延迟精调档位 */

    FPIN_NUM_OF_DELAY_TYPE
} FPinDelayType; /* 引脚延时配置类型 */

typedef enum
{
    FPIN_DELAY_NONE = 0,
    FPIN_DELAY_1,
    FPIN_DELAY_2,
    FPIN_DELAY_3,
    FPIN_DELAY_4,
    FPIN_DELAY_5,
    FPIN_DELAY_6,
    FPIN_DELAY_7,

    FPIN_NUM_OF_DELAY
} FPinDelay;

typedef enum
{
    FPIN_DELAY_IN_TYPE = 0,     /*  input delay */
    FPIN_DELAY_OUT_TYPE = 1,    /* output delay */
} FPinDelayIOType;

typedef struct
{
    u32 reg_off; /* 引脚配置寄存器偏移量 */
    u32 reg_bit; /* 引脚配置起始位 */
} FPinIndex; /* 引脚索引 */
/************************** Variable Definitions *****************************/

/***************** Macros (Inline Functions) Definitions *********************/
#define FPIN_NULL  {0xffffffff, 0}

/************************** Function Prototypes ******************************/
/* 获取IO引脚当前的复用功能 */
FPinFunc FPinGetFunc(const FPinIndex pin);

/* 设置IO引脚复用功能 */
void FPinSetFunc(const FPinIndex pin, FPinFunc func);

/* 获取IO引脚当前的上下拉设置 */
FPinPull FPinGetPull(const FPinIndex pin);

/* 设置IO引脚的上下拉 */
void FPinSetPull(const FPinIndex pin, FPinPull pull);

#if defined(FPIN_IO_PAD)
/* 获取IO引脚的驱动能力 */
FPinDrive FPinGetDrive(const FPinIndex pin);

/* 设置IO引脚的驱动能力 */
void FPinSetDrive(const FPinIndex pin, FPinDrive drive);

/* 获取IO引脚的复用、上下拉和驱动能力设置 */
void FPinGetConfig(const FPinIndex pin, FPinFunc *func, FPinPull *pull, FPinDrive *drive);

/* 设置IO引脚的复用、上下拉和驱动能力 */
void FPinSetConfig(const FPinIndex pin, FPinFunc func, FPinPull pull, FPinDrive drive);

#else

/* 获取IO引脚的复用、上下拉和驱动能力设置 */
void FPinGetConfig(const FPinIndex pin, FPinFunc *func, FPinPull *pull);

/* 设置IO引脚的复用、上下拉和驱动能力 */
void FPinSetConfig(const FPinIndex pin, FPinFunc func, FPinPull pull);

#endif

/* 获取IO引脚当前的单项延时设置 */
FPinDelay FPinGetDelay(const FPinIndex pin, FPinDelayDir dir, FPinDelayType type);

/* 检查IO引脚延时是否使能 */
boolean FPinGetDelayEn(const FPinIndex pin, FPinDelayDir dir);

/* 设置IO引脚单项延时 */
void FPinSetDelay(const FPinIndex pin, FPinDelayDir dir, FPinDelayType type, FPinDelay delay);

/* 使能或去使能IO引脚延时 */
void FPinSetDelayEn(const FPinIndex pin, FPinDelayDir dir, boolean enable);

/* Update and enable common IO pin delay config */
void FPinSetDelayConfig(const FPinIndex pin, FPinDelayIOType in_out_type, FPinDelay roungh_delay, FPinDelay delicate_delay, boolean enable);

/* Get current common IO pin delay config */
void FPinGetDelayConfig(const FPinIndex pin, FPinDelay *in_roungh_delay, FPinDelay *in_delicate_delay,
                        FPinDelay *out_roungh_delay, FPinDelay *out_delicate_delay);

#ifdef __cplusplus
}
#endif

#endif