3 Example to use CBUS bitbang mode of newer chipsets.
4 You must enable CBUS bitbang mode in the EEPROM first.
6 Thanks to Steve Brown <sbrown@ewol.com> for the
7 the information how to do it.
9 The top nibble controls input/output and the bottom nibble
10 controls the state of the lines set to output. The datasheet isn't clear
11 what happens if you set a bit in the output register when that line is
12 conditioned for input. This is described in more detail
13 in the FT232R bitbang app note.
19 | |------ Output Control 0->LO, 1->HI
20 |----------- Input/Output 0->Input, 1->Output
23 All pins to output with 0 bit high: 0xF1 (11110001)
24 Bits 0 and 1 to input, 2 and 3 to output and masked high: 0xCC (11001100)
26 The input is standard "0x" hex notation.
27 A carriage return terminates the program.
29 This program is distributed under the GPL, version 2
39 struct ftdi_context *ftdi;
42 unsigned char bitmask;
45 if ((ftdi = ftdi_new()) == 0)
47 fprintf(stderr, "ftdi_new failed\n");
51 f = ftdi_usb_open(ftdi, 0x0403, 0x6001);
54 fprintf(stderr, "unable to open ftdi device: %d (%s)\n", f, ftdi_get_error_string(ftdi));
58 printf("ftdi open succeeded: %d\n",f);
62 // Set bitmask from input
63 char *s = fgets(input, sizeof(input) - 1, stdin);
64 if (s == NULL || input[0] == '\n')
66 bitmask = strtol(input, NULL, 0);
67 printf("Using bitmask 0x%02x\n", bitmask);
68 f = ftdi_set_bitmode(ftdi, bitmask, BITMODE_CBUS);
71 fprintf(stderr, "set_bitmode failed for 0x%x, error %d (%s)\n", bitmask, f, ftdi_get_error_string(ftdi));
78 f = ftdi_read_pins(ftdi, &buf[0]);
81 fprintf(stderr, "read_pins failed, error %d (%s)\n", f, ftdi_get_error_string(ftdi));
86 printf("Read returned 0x%01x\n", buf[0] & 0x0f);
88 printf("disabling bitbang mode\n");
89 ftdi_disable_bitbang(ftdi);