+ System.out.println();
+ }
+
+ // Private //////////////////////////////////////////////////////////////////////////////
+
+ private void flush() throws IOException { ftdiuart.getOutputStream().flush(); }
+
+ private int dbits = 0;
+ private void setDBusLine() throws IOException {
+ ftdiuart.getOutputStream().write((byte)dbits);
+ }
+ private void clearDBusLines() throws IOException {
+ dbits = 0;
+ setDBusLine();
+ }
+ private void setDBusLine(int bit, boolean val) throws IOException {
+ dbits = val ? (dbits | (1 << bit)) : (dbits & (~(1 << bit)));
+ setDBusLine();
+ }
+
+ private void sendConfigBits(int dat, int numbits) throws IOException {
+ for(int i=(numbits-1); i>=0; i--) {
+ boolean bit = (dat & (1<<i)) != 0;
+ configDataPin(bit);
+ cclkPin(true);
+ dbits &= ~(1<<6); // let the clock fall with the next data bit, whenever it goes out
+ }
+ }
+
+ // tricky: RESET has a weak pull-up, and is wired to a CBUS line. So,
+ // we can pull it down (assert reset) from uart-mode, or we can
+ // let it float upward from either mode.
+ private void resetPin(boolean on) throws IOException {
+ ftdiuart.uart_and_cbus_mode(1<<1, on ? (1<<1) : 0);
+ flush();
+ if (on) {
+ ftdiuart.dbus_mode(dmask);
+ flush();
+ }
+ }
+
+ private void releaseConPin() throws IOException {
+ dmask &= ~(1<<0);
+ ftdiuart.dbus_mode(dmask);