19cdd273eSMauro Carvalho Chehab===================================================
29cdd273eSMauro Carvalho Chehabspi_butterfly - parport-to-butterfly adapter driver
39cdd273eSMauro Carvalho Chehab===================================================
49cdd273eSMauro Carvalho Chehab
59cdd273eSMauro Carvalho ChehabThis is a hardware and software project that includes building and using
69cdd273eSMauro Carvalho Chehaba parallel port adapter cable, together with an "AVR Butterfly" to run
79cdd273eSMauro Carvalho Chehabfirmware for user interfacing and/or sensors.  A Butterfly is a $US20
89cdd273eSMauro Carvalho Chehabbattery powered card with an AVR microcontroller and lots of goodies:
99cdd273eSMauro Carvalho Chehabsensors, LCD, flash, toggle stick, and more.  You can use AVR-GCC to
109cdd273eSMauro Carvalho Chehabdevelop firmware for this, and flash it using this adapter cable.
119cdd273eSMauro Carvalho Chehab
129cdd273eSMauro Carvalho ChehabYou can make this adapter from an old printer cable and solder things
139cdd273eSMauro Carvalho Chehabdirectly to the Butterfly.  Or (if you have the parts and skills) you
14*d1ad0a73SStéphane Blondoncan come up with something fancier, providing circuit protection to the
159cdd273eSMauro Carvalho ChehabButterfly and the printer port, or with a better power supply than two
169cdd273eSMauro Carvalho Chehabsignal pins from the printer port.  Or for that matter, you can use
179cdd273eSMauro Carvalho Chehabsimilar cables to talk to many AVR boards, even a breadboard.
189cdd273eSMauro Carvalho Chehab
199cdd273eSMauro Carvalho ChehabThis is more powerful than "ISP programming" cables since it lets kernel
209cdd273eSMauro Carvalho ChehabSPI protocol drivers interact with the AVR, and could even let the AVR
219cdd273eSMauro Carvalho Chehabissue interrupts to them.  Later, your protocol driver should work
229cdd273eSMauro Carvalho Chehabeasily with a "real SPI controller", instead of this bitbanger.
239cdd273eSMauro Carvalho Chehab
249cdd273eSMauro Carvalho Chehab
259cdd273eSMauro Carvalho ChehabThe first cable connections will hook Linux up to one SPI bus, with the
269cdd273eSMauro Carvalho ChehabAVR and a DataFlash chip; and to the AVR reset line.  This is all you
279cdd273eSMauro Carvalho Chehabneed to reflash the firmware, and the pins are the standard Atmel "ISP"
289cdd273eSMauro Carvalho Chehabconnector pins (used also on non-Butterfly AVR boards).  On the parport
299cdd273eSMauro Carvalho Chehabside this is like "sp12" programming cables.
309cdd273eSMauro Carvalho Chehab
319cdd273eSMauro Carvalho Chehab	======	  =============	  ===================
329cdd273eSMauro Carvalho Chehab	Signal	  Butterfly	  Parport (DB-25)
339cdd273eSMauro Carvalho Chehab	======	  =============	  ===================
349cdd273eSMauro Carvalho Chehab	SCK	  J403.PB1/SCK	  pin 2/D0
359cdd273eSMauro Carvalho Chehab	RESET	  J403.nRST	  pin 3/D1
369cdd273eSMauro Carvalho Chehab	VCC	  J403.VCC_EXT	  pin 8/D6
379cdd273eSMauro Carvalho Chehab	MOSI	  J403.PB2/MOSI	  pin 9/D7
389cdd273eSMauro Carvalho Chehab	MISO	  J403.PB3/MISO	  pin 11/S7,nBUSY
399cdd273eSMauro Carvalho Chehab	GND	  J403.GND	  pin 23/GND
409cdd273eSMauro Carvalho Chehab	======	  =============	  ===================
419cdd273eSMauro Carvalho Chehab
429cdd273eSMauro Carvalho ChehabThen to let Linux master that bus to talk to the DataFlash chip, you must
439cdd273eSMauro Carvalho Chehab(a) flash new firmware that disables SPI (set PRR.2, and disable pullups
449cdd273eSMauro Carvalho Chehabby clearing PORTB.[0-3]); (b) configure the mtd_dataflash driver; and
459cdd273eSMauro Carvalho Chehab(c) cable in the chipselect.
469cdd273eSMauro Carvalho Chehab
479cdd273eSMauro Carvalho Chehab	======	  ============	  ===================
489cdd273eSMauro Carvalho Chehab	Signal	  Butterfly	  Parport (DB-25)
499cdd273eSMauro Carvalho Chehab	======	  ============	  ===================
509cdd273eSMauro Carvalho Chehab	VCC	  J400.VCC_EXT	  pin 7/D5
519cdd273eSMauro Carvalho Chehab	SELECT	  J400.PB0/nSS	  pin 17/C3,nSELECT
529cdd273eSMauro Carvalho Chehab	GND	  J400.GND	  pin 24/GND
539cdd273eSMauro Carvalho Chehab	======	  ============	  ===================
549cdd273eSMauro Carvalho Chehab
559cdd273eSMauro Carvalho ChehabOr you could flash firmware making the AVR into an SPI slave (keeping the
569cdd273eSMauro Carvalho ChehabDataFlash in reset) and tweak the spi_butterfly driver to make it bind to
579cdd273eSMauro Carvalho Chehabthe driver for your custom SPI-based protocol.
589cdd273eSMauro Carvalho Chehab
599cdd273eSMauro Carvalho ChehabThe "USI" controller, using J405, can also be used for a second SPI bus.
609cdd273eSMauro Carvalho ChehabThat would let you talk to the AVR using custom SPI-with-USI firmware,
619cdd273eSMauro Carvalho Chehabwhile letting either Linux or the AVR use the DataFlash.  There are plenty
629cdd273eSMauro Carvalho Chehabof spare parport pins to wire this one up, such as:
639cdd273eSMauro Carvalho Chehab
649cdd273eSMauro Carvalho Chehab	======	  =============	  ===================
659cdd273eSMauro Carvalho Chehab	Signal	  Butterfly	  Parport (DB-25)
669cdd273eSMauro Carvalho Chehab	======	  =============	  ===================
679cdd273eSMauro Carvalho Chehab	SCK	  J403.PE4/USCK	  pin 5/D3
689cdd273eSMauro Carvalho Chehab	MOSI	  J403.PE5/DI	  pin 6/D4
699cdd273eSMauro Carvalho Chehab	MISO	  J403.PE6/DO	  pin 12/S5,nPAPEROUT
709cdd273eSMauro Carvalho Chehab	GND	  J403.GND	  pin 22/GND
719cdd273eSMauro Carvalho Chehab
729cdd273eSMauro Carvalho Chehab	IRQ	  J402.PF4	  pin 10/S6,ACK
739cdd273eSMauro Carvalho Chehab	GND	  J402.GND(P2)	  pin 25/GND
749cdd273eSMauro Carvalho Chehab	======	  =============	  ===================
75