build: cleanup src/jtag/drivers directory
[openocd.git] / 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, write to the *
16 * Free Software Foundation, Inc., *
17 * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. *
18 ***************************************************************************/
19
20 #ifdef HAVE_CONFIG_H
21 #include "config.h"
22 #endif
23
24 #include <string.h>
25
26 #include "../versaloon_include.h"
27 #include "../versaloon.h"
28 #include "../versaloon_internal.h"
29 #include "usbtoxxx.h"
30 #include "usbtoxxx_internal.h"
31
32 RESULT usbtogpio_init(uint8_t interface_index)
33 {
34 return usbtoxxx_init_command(USB_TO_GPIO, interface_index);
35 }
36
37 RESULT usbtogpio_fini(uint8_t interface_index)
38 {
39 return usbtoxxx_fini_command(USB_TO_GPIO, interface_index);
40 }
41
42 RESULT usbtogpio_config(uint8_t interface_index, uint32_t mask,
43 uint32_t dir_mask, uint32_t pull_en_mask,
44 uint32_t input_pull_mask)
45 {
46 uint8_t conf[8];
47
48 #if PARAM_CHECK
49 if (interface_index > 7) {
50 LOG_BUG(ERRMSG_INVALID_INTERFACE_NUM, interface_index);
51 return ERROR_FAIL;
52 }
53 #endif
54
55 dir_mask &= mask;
56 SET_LE_U16(&conf[0], mask);
57 SET_LE_U16(&conf[2], dir_mask);
58 SET_LE_U16(&conf[4], pull_en_mask);
59 SET_LE_U16(&conf[6], input_pull_mask);
60
61 return usbtoxxx_conf_command(USB_TO_GPIO, interface_index, conf,
62 sizeof(conf));
63 }
64
65 RESULT usbtogpio_in(uint8_t interface_index, uint32_t mask, uint32_t *value)
66 {
67 uint8_t buf[2];
68
69 #if PARAM_CHECK
70 if (interface_index > 7) {
71 LOG_BUG(ERRMSG_INVALID_INTERFACE_NUM, interface_index);
72 return ERROR_FAIL;
73 }
74 #endif
75
76 SET_LE_U16(&buf[0], mask);
77
78 return usbtoxxx_in_command(USB_TO_GPIO, interface_index, buf, 2, 2,
79 (uint8_t *)value, 0, 2, 0);
80 }
81
82 RESULT usbtogpio_out(uint8_t interface_index, uint32_t mask, uint32_t value)
83 {
84 uint8_t buf[4];
85
86 #if PARAM_CHECK
87 if (interface_index > 7) {
88 LOG_BUG(ERRMSG_INVALID_INTERFACE_NUM, interface_index);
89 return ERROR_FAIL;
90 }
91 #endif
92
93 SET_LE_U16(&buf[0], mask);
94 SET_LE_U16(&buf[2], value);
95
96 return usbtoxxx_out_command(USB_TO_GPIO, interface_index, buf, 4, 0);
97 }