OpenCores
URL https://opencores.org/ocsvn/usb_fpga_2_14/usb_fpga_2_14/trunk

Subversion Repositories usb_fpga_2_14

[/] [usb_fpga_2_14/] [trunk/] [fx3/] [ztex-gpio.c] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 ZTEX
/*%
2
   ZTEX Firmware Kit for EZ-USB FX3 Microcontrollers
3
   Copyright (C) 2009-2017 ZTEX GmbH.
4
   http://www.ztex.de
5
 
6
   This Source Code Form is subject to the terms of the Mozilla Public
7
   License, v. 2.0. If a copy of the MPL was not distributed with this file,
8
   You can obtain one at http://mozilla.org/MPL/2.0/.
9
 
10
   Alternatively, the contents of this file may be used under the terms
11
   of the GNU General Public License Version 3, as described below:
12
 
13
   This program is free software; you can redistribute it and/or modify
14
   it under the terms of the GNU General Public License version 3 as
15
   published by the Free Software Foundation.
16
 
17
   This program is distributed in the hope that it will be useful, but
18
   WITHOUT ANY WARRANTY; without even the implied warranty of
19
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
20
   General Public License for more details.
21
 
22
   You should have received a copy of the GNU General Public License
23
   along with this program; if not, see http://www.gnu.org/licenses/.
24
%*/
25
/*
26
    GPIO functions.
27
*/
28
 
29
#include <cyu3gpio.h>
30
 
31
#ifndef _ZTEX_GPIO_C_
32
#define _ZTEX_GPIO_C_
33
 
34
uint8_t ztex_gpio_set_output(uint8_t num, CyBool_t val) {
35
    CyU3PGpioSimpleConfig_t cfg;
36
 
37
    cfg.outValue    = val;
38
    cfg.driveLowEn  = CyTrue;
39
    cfg.driveHighEn = CyTrue;
40
    cfg.inputEn     = CyFalse;
41
    cfg.intrMode    = CY_U3P_GPIO_NO_INTR;
42
    ZTEX_REC_RET( CyU3PGpioSetSimpleConfig( num, &cfg) );
43
    return 0;
44
}
45
 
46
void ztex_gpio_set (uint8_t num, CyBool_t val) {
47
    CyU3PReturnStatus_t status;
48
    status = CyU3PGpioSimpleSetValue(num, val);
49
    if ( status )  ZTEX_LOG("Error setting GPIO %d: %d", num, status);
50
}
51
 
52
CyBool_t ztex_gpio_get (uint8_t num) {
53
    CyBool_t val;
54
    CyU3PReturnStatus_t status;
55
    status = CyU3PGpioSimpleGetValue(num, &val);
56
    if ( status )  ZTEX_LOG("Error reading GPIO %d: %d", num, status);
57
    return val;
58
}
59
 
60
uint8_t ztex_gpio_set_open_drain(uint8_t num, CyBool_t val) {
61
    CyU3PGpioSimpleConfig_t cfg;
62
 
63
    cfg.outValue    = val;
64
    cfg.driveLowEn  = CyTrue;
65
    cfg.driveHighEn = CyFalse;
66
    cfg.inputEn     = CyTrue;
67
    cfg.intrMode    = CY_U3P_GPIO_NO_INTR;
68
    ZTEX_REC_RET( CyU3PGpioSetSimpleConfig( num, &cfg) );
69
    return 0;
70
}
71
 
72
uint8_t ztex_gpio_set_open_source(uint8_t num, CyBool_t val) {
73
    CyU3PGpioSimpleConfig_t cfg;
74
 
75
    cfg.outValue    = val;
76
    cfg.driveLowEn  = CyFalse;
77
    cfg.driveHighEn = CyTrue;
78
    cfg.inputEn     = CyTrue;
79
    cfg.intrMode    = CY_U3P_GPIO_NO_INTR;
80
    ZTEX_REC_RET( CyU3PGpioSetSimpleConfig( num, &cfg) );
81
    return 0;
82
}
83
 
84
uint8_t ztex_gpio_set_input(uint8_t num) {
85
    CyU3PGpioSimpleConfig_t cfg;
86
 
87
    cfg.outValue    = CyFalse;
88
    cfg.driveLowEn  = CyFalse;
89
    cfg.driveHighEn = CyFalse;
90
    cfg.inputEn     = CyTrue;
91
    cfg.intrMode    = CY_U3P_GPIO_NO_INTR;
92
    ZTEX_REC_RET( CyU3PGpioSetSimpleConfig( num, &cfg) );
93
    return 0;
94
}
95
 
96
void ztex_gpio_init() {
97
    CyU3PGpioClock_t cfg;
98
 
99
    cfg.fastClkDiv = 2;
100
    cfg.slowClkDiv = 0;
101
    cfg.simpleDiv  = CY_U3P_GPIO_SIMPLE_DIV_BY_2;
102
    cfg.clkSrc     = CY_U3P_SYS_CLK;
103
    cfg.halfDiv    = 0;
104
 
105
    ZTEX_REC( CyU3PGpioInit (&cfg, GPIO_INT_HANDLER) );
106
}
107
 
108
#endif // _ZTEX_GPIO_C_

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.