hidkey_gpio
Differences
This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| hidkey_gpio [2012/11/25 22:01] – [Theory] steve_m | hidkey_gpio [2013/02/27 00:10] (current) – [Results] steve_m | ||
|---|---|---|---|
| Line 1: | Line 1: | ||
| ====== AVR Programmer built from a USB Keyboard ====== | ====== AVR Programmer built from a USB Keyboard ====== | ||
| - | Recently, my old keyboard became louder and louder while typing, so I decided to buy a new one. But what to do with the old one? Ever since I saw the [[http:// | + | Recently, my keyboard became louder and louder while typing, so I decided to buy a new one. But what to do with the old one? Ever since I saw the [[http:// |
| ===== Theory ===== | ===== Theory ===== | ||
| - | Most keyboards have at least three indicator LEDs (num lock, caps lock and scroll lock), which can be controlled from the host using a HID '' | + | Most keyboards have at least three indicator LEDs (Num-, Caps- and Scroll-Lock), which can be controlled from the host using a HID '' |
| ===== Hardware ===== | ===== Hardware ===== | ||
| Line 23: | Line 23: | ||
| {{ : | {{ : | ||
| - | You can see the keyboard controller PCB, the optocoupler, | + | You can see the keyboard controller PCB, the optocoupler, |
| I desoldered the LEDs and directly connected the 5V outputs (since there were already 330Ω current limiting resistors in place) as follows: | I desoldered the LEDs and directly connected the 5V outputs (since there were already 330Ω current limiting resistors in place) as follows: | ||
| Line 30: | Line 30: | ||
| |Caps lock|MOSI|out| | |Caps lock|MOSI|out| | ||
| |Scroll lock|Reset|out| | |Scroll lock|Reset|out| | ||
| - | |row/column of right shift key|MISO|in| | + | |row/column of right shift key|MISO |
| For the optocoupler I added a 470Ω current limiting resistor. | For the optocoupler I added a 470Ω current limiting resistor. | ||
| Line 36: | Line 36: | ||
| ===== Software ===== | ===== Software ===== | ||
| - | First I wrote a small libusb-based test utility for experimenting with the keyboard. I'm directly communicating with the keyboard from userspace, unloading the kernel driver first. | + | First I wrote a [[https:// |
| ==== Speed ==== | ==== Speed ==== | ||
| - | Just toggling the LEDs in a while-loop gives a signal fluctuating between 500 Hz and 1.2 kHz on the output, which is faster than I assumed. Unfortunately, | + | Just toggling the LEDs in a while-loop gives a signal fluctuating between 500 Hz and 1.2 kHz on the output, which is faster than I assumed. Unfortunately, |
| {{ : | {{ : | ||
| Line 59: | Line 59: | ||
| ==== Results ==== | ==== Results ==== | ||
| < | < | ||
| - | $ ./avrdude -c hidkey -C avrdude.conf -pattiny2313 | + | $ ./avrdude -c hidkey -C avrdude.conf -p attiny2313 |
| avrdude: AVR device initialized and ready to accept instructions | avrdude: AVR device initialized and ready to accept instructions | ||
| Line 79: | Line 79: | ||
| </ | </ | ||
| - | Well, as you can see, programming takes quite a while, mainly because of the slow input speed I mentioned before, but is very reliable. Since I assume that many people have some old USB keyboard | + | Well, as you can see, programming takes quite a while, mainly because of the slow input speed I mentioned before, but is very reliable. Since I assume that many people have some old USB keyboard |
| + | |||
| + | ===== Update #1 ===== | ||
| + | |||
| + | Since reading the MISO input is much slower than writing the outputs, as I mentioned above, I took a closer look at the avrdude code. As it turns out, the inputs are read every time, even if the data isn't used at all afterwards (like when writing a byte). I applied a crude hack, so that MISO is only being read if the data is used afterwards. I pushed that change to a new [[https:// | ||
| + | |||
| + | With those changes, flashing my 86 byte demo application is now over ten times faster (11.75s vs. 123.79s)! | ||
| + | < | ||
| + | $ ./avrdude -c hidkey -C avrdude.conf -p attiny2313 -U flash: | ||
| + | |||
| + | avrdude: AVR device initialized and ready to accept instructions | ||
| + | |||
| + | Reading | ################################################## | ||
| + | |||
| + | avrdude: Device signature = 0x1e910a | ||
| + | avrdude: NOTE: " | ||
| + | To disable this feature, specify the -D option. | ||
| + | avrdude: erasing chip | ||
| + | avrdude: reading input file "/ | ||
| + | avrdude: writing flash (86 bytes): | ||
| + | |||
| + | Writing | ################################################## | ||
| + | |||
| + | avrdude: 86 bytes of flash written | ||
| + | avrdude: verifying flash memory against / | ||
| + | avrdude: load data flash data from input file / | ||
| + | avrdude: input file / | ||
| + | avrdude: reading on-chip flash data: | ||
| + | |||
| + | Reading | ################################################## | ||
| + | |||
| + | avrdude: verifying ... | ||
| + | avrdude: 86 bytes of flash verified | ||
| + | |||
| + | avrdude: safemode: Fuses OK | ||
| + | |||
| + | avrdude done. Thank you. | ||
| + | </ | ||
| + | |||
| + | Programming the whole flash of the ATiny2313 now only takes 4 minutes 37 seconds: | ||
| + | |||
| + | < | ||
| + | $ ./avrdude -c hidkey -C avrdude.conf -p attiny2313 -U flash: | ||
| + | avrdude: AVR device initialized and ready to accept instructions | ||
| + | |||
| + | Reading | ################################################## | ||
| + | |||
| + | avrdude: Device signature = 0x1e910a | ||
| + | avrdude: NOTE: " | ||
| + | To disable this feature, specify the -D option. | ||
| + | avrdude: erasing chip | ||
| + | avrdude: reading input file "/ | ||
| + | avrdude: writing flash (2046 bytes): | ||
| + | |||
| + | Writing | ################################################## | ||
| + | |||
| + | avrdude: 2046 bytes of flash written | ||
| + | avrdude: verifying flash memory against / | ||
| + | avrdude: load data flash data from input file / | ||
| + | avrdude: input file / | ||
| + | avrdude: reading on-chip flash data: | ||
| + | |||
| + | Reading | ########## | ||
| + | </ | ||
| + | |||
| + | I'd say that's quite an improvement, | ||
| + | |||
| + | This project was featured on [[http:// | ||
| == Reference Literature == | == Reference Literature == | ||
hidkey_gpio.1353880879.txt.gz · Last modified: 2012/11/25 22:01 by steve_m
