1 package com.atmel.fpslic;
5 // TODO: more state checking (ie must have reset high before uart-mode, etc)
8 * Pin-level access to the bootstrap port of an FPSLIC via an FTDI USB-UART
10 public class FpslicBootPinsUsb implements FpslicBootPins {
12 private FtdiUart ftdiuart;
14 public FpslicBootPinsUsb(FtdiUart ftdiuart) {
15 this.ftdiuart = ftdiuart;
18 public void avrrstPin(boolean on) throws IOException { setDBusLine(7, on); }
19 public void cclkPin(boolean on) throws IOException { setDBusLine(6, on); }
20 public void configDataPin(boolean on) throws IOException { setDBusLine(5, on); }
21 public boolean initPin() throws IOException { flush(); return (ftdiuart.readPins() & (1<<4))!=0; }
23 // tricky: RESET has a weak pull-up, and is wired to a CBUS line. So,
24 // we can pull it down (assert reset) from uart-mode, or we can
25 // let it float upward from either mode.
26 public void resetPin(boolean on) throws IOException {
27 ftdiuart.uart_and_cbus_mode(1<<1, on ? (1<<1) : 0);
30 ftdiuart.dbus_mode(dmask);
35 public void flush() throws IOException { ftdiuart.getOutputStream().flush(); }
37 private int dbits = 0;
38 public void setDBusLine() throws IOException {
39 ftdiuart.getOutputStream().write((byte)dbits);
41 public void clearDBusLines() throws IOException {
45 public void setDBusLine(int bit, boolean val) throws IOException {
46 dbits = val ? (dbits | (1 << bit)) : (dbits & (~(1 << bit)));
50 public void releaseConPin() throws IOException {
52 ftdiuart.dbus_mode(dmask);
56 public void conPin(boolean on) throws IOException {
58 ftdiuart.dbus_mode(dmask);
63 public void close() throws IOException {
64 // switching to uart mode will implicitly release AVRRST
67 ftdiuart.uart_and_cbus_mode(1<<1, 1<<1);
80 public InputStream getUartInputStream() throws IOException { return ftdiuart.getInputStream(); }
81 public OutputStream getUartOutputStream() throws IOException { return ftdiuart.getOutputStream(); }