2 * Copyright (C) 2008 dhewg, #wiidev efnet
4 * this file is part of wiifuse
5 * http://wiibrew.org/index.php?title=Wiifuse
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
31 #define FTDI_PACKET_SIZE 3968
34 // this whole approach blocks, how do i implement a timeout with tty's?
36 static int fd_gecko
= -1;
38 int gecko_open (const char *dev
) {
39 struct termios newtio
;
41 fd_gecko
= open (dev
, O_RDWR
| O_NOCTTY
| O_SYNC
| O_NONBLOCK
);
44 perror ("gecko_open");
48 if (fcntl (fd_gecko
, F_SETFL
, 0)) {
49 perror ("F_SETFL on serial port");
53 if (tcgetattr(fd_gecko
, &newtio
)) {
60 newtio
.c_cflag
|= CRTSCTS
| CS8
| CLOCAL
| CREAD
;
62 if (tcsetattr (fd_gecko
, TCSANOW
, &newtio
)) {
78 // TODO doesnt seem to work with ftdi-sio
79 // i need a way to check if data is actually available
80 tcflush (fd_gecko
, TCIOFLUSH
);
83 int gecko_read (void *buf
, size_t count
) {
84 size_t left
, chunk
, res
;
89 if (chunk
> FTDI_PACKET_SIZE
)
90 chunk
= FTDI_PACKET_SIZE
;
92 res
= read (fd_gecko
, buf
, chunk
);
94 perror ("gecko_read");
105 int gecko_write (const void *buf
, size_t count
) {
106 size_t left
, chunk
, res
;
112 if (chunk
> FTDI_PACKET_SIZE
)
113 chunk
= FTDI_PACKET_SIZE
;
115 res
= write (fd_gecko
, buf
, count
);
117 perror ("gecko_write");
124 // does this work with ftdi-sio?
125 if (tcdrain (fd_gecko
)) {
126 perror ("gecko_drain");