Remove FSF address from GPL notices
[fw/openocd] / src / jtag / drivers / versaloon / usbtoxxx / usbtogpio.c
1 /***************************************************************************
2  *   Copyright (C) 2009 - 2010 by Simon Qian <SimonQian@SimonQian.com>     *
3  *                                                                         *
4  *   This program is free software; you can redistribute it and/or modify  *
5  *   it under the terms of the GNU General Public License as published by  *
6  *   the Free Software Foundation; either version 2 of the License, or     *
7  *   (at your option) any later version.                                   *
8  *                                                                         *
9  *   This program is distributed in the hope that it will be useful,       *
10  *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
11  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
12  *   GNU General Public License for more details.                          *
13  *                                                                         *
14  *   You should have received a copy of the GNU General Public License     *
15  *   along with this program.  If not, see <http://www.gnu.org/licenses/>. *
16  ***************************************************************************/
17
18 #ifdef HAVE_CONFIG_H
19 #include "config.h"
20 #endif
21
22 #include <string.h>
23
24 #include "../versaloon_include.h"
25 #include "../versaloon.h"
26 #include "../versaloon_internal.h"
27 #include "usbtoxxx.h"
28 #include "usbtoxxx_internal.h"
29
30 RESULT usbtogpio_init(uint8_t interface_index)
31 {
32         return usbtoxxx_init_command(USB_TO_GPIO, interface_index);
33 }
34
35 RESULT usbtogpio_fini(uint8_t interface_index)
36 {
37         return usbtoxxx_fini_command(USB_TO_GPIO, interface_index);
38 }
39
40 RESULT usbtogpio_config(uint8_t interface_index, uint32_t mask,
41         uint32_t dir_mask, uint32_t pull_en_mask,
42         uint32_t input_pull_mask)
43 {
44         uint8_t conf[8];
45
46 #if PARAM_CHECK
47         if (interface_index > 7) {
48                 LOG_BUG(ERRMSG_INVALID_INTERFACE_NUM, interface_index);
49                 return ERROR_FAIL;
50         }
51 #endif
52
53         dir_mask &= mask;
54         SET_LE_U16(&conf[0], mask);
55         SET_LE_U16(&conf[2], dir_mask);
56         SET_LE_U16(&conf[4], pull_en_mask);
57         SET_LE_U16(&conf[6], input_pull_mask);
58
59         return usbtoxxx_conf_command(USB_TO_GPIO, interface_index, conf,
60                 sizeof(conf));
61 }
62
63 RESULT usbtogpio_in(uint8_t interface_index, uint32_t mask, uint32_t *value)
64 {
65         uint8_t buf[2];
66
67 #if PARAM_CHECK
68         if (interface_index > 7) {
69                 LOG_BUG(ERRMSG_INVALID_INTERFACE_NUM, interface_index);
70                 return ERROR_FAIL;
71         }
72 #endif
73
74         SET_LE_U16(&buf[0], mask);
75
76         return usbtoxxx_in_command(USB_TO_GPIO, interface_index, buf, 2, 2,
77                 (uint8_t *)value, 0, 2, 0);
78 }
79
80 RESULT usbtogpio_out(uint8_t interface_index, uint32_t mask, uint32_t value)
81 {
82         uint8_t buf[4];
83
84 #if PARAM_CHECK
85         if (interface_index > 7) {
86                 LOG_BUG(ERRMSG_INVALID_INTERFACE_NUM, interface_index);
87                 return ERROR_FAIL;
88         }
89 #endif
90
91         SET_LE_U16(&buf[0], mask);
92         SET_LE_U16(&buf[2], value);
93
94         return usbtoxxx_out_command(USB_TO_GPIO, interface_index, buf, 4, 0);
95 }