2 at89prog - support for FTDI
3 (c) 2003-2004 Jelmer Vernooij <jelmer@samba.org>
4 (c) 2006 Stefan Lievens <zatalian@gmail.com>
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
23 #include <sys/termios.h>
25 #include <sys/types.h>
34 #include <sys/ioctl.h>
38 static struct ftdi_context ftdic;
39 static int ftdi_data = 0;
41 static char *available_pins[] = { "P0", "P1", "P2", "P3", "P4", "P5", "P6",
44 static int ftdi_at98prog_init(char *location)
50 fd = ftdi_usb_open(&ftdic, 0x0403, 0x6001);
51 if(fd < 0 && fd != -5) {
52 perror("Error opening ftdi device");
56 i = ftdi_enable_bitbang(&ftdic, bitmask);
57 i = ftdi_set_baudrate(&ftdic, 9600);
64 static int ftdi_at98prog_close()
66 ftdi_disable_bitbang(&ftdic);
67 ftdi_usb_close(&ftdic);
72 static void ftdi_at98prog_set(int p)
74 ftdi_data |= (0x01 << p);
75 ftdi_write_data(&ftdic, (unsigned char *) &ftdi_data, 1);
78 static void ftdi_at98prog_clear(int p)
81 ftdi_data &= ~(0x01 << p);
82 ftdi_write_data(&ftdic, (unsigned char *) &ftdi_data, 1);
85 static int ftdi_at98prog_get(int p)
89 ftdi_read_pins(&ftdic, (unsigned char *) &status);
90 if (status & (0x01 << p)) return 1; else return 0;
93 struct pins_backend ftdi = {