Author Topic: Business card source code  (Read 127104 times)

0 Members and 1 Guest are viewing this topic.

Offline komar007

  • Thread Starter
  • Posts: 712
  • Location: Poland
    • komar's blog
Business card source code
« on: Mon, 13 January 2014, 11:52:05 »
Hi,
it has been requested for some time that I release the source code for what runs on the techkeys latest business card.
The code is a quickly stripped-down version of ukbdc with a lot of stuff removed.
I'm aware that it's hard to work with this code, because not only is ukbdc still a bit messy, but also this particular code I wrote quickly and assuming no one will want it;), but as I have already mentioned in a couple places, I'm still working on ukbdc, especially because of upcoming GH60 which will use it, and when everything I need is implemented, it will also work on the techkeys card.

The code compiles on linux with avr-gcc. If you're using a different system, and makefiles don't work for some reason, just open Makefile.config where you'll find a list of source files which need to be compiled (basically all the .c files from the main directory), and also the compiler options (LDFLAGS, CFLAGS).
The file main_techkeys.c should give you an example how to send keypress events to the PC and read switches/light LEDs.

In order to flash the card with your code, you need to connect it to USB, then short the two small pads near the USB receptacle until it enumerates as Atmel DFU and then use Atmel's FLIP or dfu-programmer to download the hex file (the process is the same as flashing GH60, instructions here: http://geekhack.org/index.php?topic=37570.msg717519#msg717519)

* techkeys_source.tar.gz (13.57 kB - downloaded 420 times.) (outdated)
* techkeys_source.zip (19.84 kB - downloaded 1284 times.) (bugfix for windows + new windows-compatible makefile)

To compile in windows, you'll need 1 thing
avr-gcc for windows: http://andybrown.me.uk/wk/files/avrgcc-4.7.0-avrlibc-1.8.0.zip

After unpacking avr-gcc, add the bin directory inside avr-gcc to your PATH (right click Computer -> Properties -> Advanced -> Environment Variables -> PATH -> Edit -> Add the full path after semicolon)
Then use the console to cd into the unpacked techkeys sources and type make.
In the bin directory you should get the compiled hex file.
« Last Edit: Tue, 14 January 2014, 14:17:24 by komar007 »
GH60 rev. B w/ ali's case|Cherry G80-3000 HFU/05|IBM Model M (51G8572)
Check out the GH60 project! | How to make a keyboard

Offline Grendel

  • Posts: 462
  • Location: OR, USA
    • Firmware for Costar Replacement Controllers
Re: Business card source code
« Reply #1 on: Mon, 13 January 2014, 12:40:33 »
Thanks, appreciate it ! Allowed me to pick up some info I was lacking (F_CPU, USB id's) and plug them into my demo code.

I would be grateful if someone would take the plunge to test the code since my card is stuck in the mail :( HEX file can be found in the archive.

Right now the keys are mapped to the three LOCK keys (left-to-right: Caps, Scroll, Num.) If SCR-LOCK is on alone for 5s, the card should invoke the boot-loader. If no LOCK is active, the LED's should start a demo display after 5s. The whole code is rather simple I'm afraid, but it does do the job. It's based on the code I threw together for the CM Storm Demo board, it should work (emphasis on "should" !)

I used a Windows based environment -- to compile the code, get WinAVR-20100110 and install it to C:\Tools\WinAVR-20100110. Then install AVR Studio 4.19. Extract the archive and double click on the *.aps file. W/in AVRS select Build ->Build to rebuild KeyCard.hex.

To change the key-bindings, change the arrays in build_kbd_report(). All possible U_... defines can be found in kbusages.h.

Code is not finished and not tested, use at your own risk !

Edit: link to FLIP.

[ Attachment Invalid Or Does Not Exist ] Outdated. Do not use.

Please see post #18 for an updated version.
« Last Edit: Thu, 30 January 2014, 14:49:51 by Grendel »
Currently using: RK-9000WH/GR, CMS QFXT w/ Ghost Squid
- I'm game !

Offline SpAmRaY

  • NOT a Moderator
  • * Certified Spammer
  • Posts: 14667
  • Location: ¯\(°_o)/¯
  • because reasons.......
Re: Business card source code
« Reply #2 on: Mon, 13 January 2014, 12:50:33 »
Thanks for sharing komar!!

Offline komar007

  • Thread Starter
  • Posts: 712
  • Location: Poland
    • komar's blog
Re: Business card source code
« Reply #3 on: Mon, 13 January 2014, 13:04:55 »
Oh, forgot to add: if you're compiling without the makefiles provided, you'll also need to add -DPLATFORM_techkeys to compiler options.
You can prepare the hex file with 2 commands:
avr-gcc -Os -std=gnu99 -g -ggdb -Wall -Wextra -mmcu=atmega16u2 -DPLATFORM_techkeys -lm main_techkeys.c io.c platforms.c usb.c usb_config.c usb_hardware.c timer.c hid.c -o card.elf
and then:
avr-objcopy card.elf -O ihex card.hex
GH60 rev. B w/ ali's case|Cherry G80-3000 HFU/05|IBM Model M (51G8572)
Check out the GH60 project! | How to make a keyboard

Offline heedpantsnow

  • * Esteemed Elder
  • Posts: 3692
  • Location: Orlando, FL
  • Old enough to know better
Re: Business card source code
« Reply #4 on: Mon, 13 January 2014, 13:08:41 »
Thank you guys so much for taking the time to do this!
I'm back.

Espresso machine overhaul: https://geekhack.org/index.php?topic=78261.0

Carbon Fiber keyboard base: https://geekhack.org/index.php?topic=54825

Offline i3oilermaker

  • * Moderator
  • Posts: 2362
  • Location: Chicago
  • techkeys.us
    • TechKeys
Re: Business card source code
« Reply #5 on: Tue, 14 January 2014, 11:20:10 »
komar / anyone - I would love some help compiling this on windows...does anyone have a program that works well and/or could provide steps?

Offline komar007

  • Thread Starter
  • Posts: 712
  • Location: Poland
    • komar's blog
Re: Business card source code
« Reply #6 on: Tue, 14 January 2014, 11:39:15 »
This should be fairly simple, I'll check out what can be done.


EDIT: this is ridiculous!
I have a file in my sources named aux.h (it contains functions I couldn't logically name, so I called them auxiliary functions).
It appears that this name is forbidden in windows and there's no way to compile my source without renaming it!
Can you believe it? It's just amazing how brain-damaged one has to be to reserve such a name. To reserve any name without special characters, actually...


EDIT1:
Okay, here's the solution
1. Download avr-gcc for windows: http://andybrown.me.uk/wk/files/avrgcc-4.7.0-avrlibc-1.8.0.zip (or probably you can use winavr as well).
2. Set your PATH to include the bin/ directory of avr-gcc
3. Go to the directory with sources and type:
avr-gcc -Os -std=gnu99 -mmcu=atmega16u2 -DPLATFORM_techkeys *.c -o card.elf
4. Then type:
avr-objcopy card.elf -O ihex card.hex
5. card.hex is your file to flash the card with FLIP.


Here's an updated package for windows (with aux.h changed to _aux.h :D ):
* techkeys_source.zip (18.55 kB - downloaded 371 times.)

Everything above this sentence is either outdated or moved to the OP, please use the sources and quick tutorial from the OP.
« Last Edit: Tue, 14 January 2014, 13:04:01 by komar007 »
GH60 rev. B w/ ali's case|Cherry G80-3000 HFU/05|IBM Model M (51G8572)
Check out the GH60 project! | How to make a keyboard

Offline Grendel

  • Posts: 462
  • Location: OR, USA
    • Firmware for Costar Replacement Controllers
Re: Business card source code
« Reply #7 on: Tue, 14 January 2014, 12:19:30 »
Windows doesn't allow any file with the name aux.*, so it's a bit tricky. I changed the header aux.h to _aux.h, added the clock definitions to work around a bug in WinAVR-20100110, and set up a AVRS project. It compiles inta a HEX file on my machine, can't test it (yet) though.

To compile:

- install WinAVR-20100110 to C:\Tools\WinAVR-20100110.
  If you install it to a different directory the paths to make & gcc need to be changed in the AVRS project file (Project -->
  Configuration  Options --> Custom Options)
- download and install AVR Studio 4.19 (AVRS)
- extract the attached techkeys_src_win.zip, double-click TK_Card.aps to start AVRS and load the project
- from the menu run: Build -> Rebuild All to make sure everything works. TK_Card.hex will be in the bin sub-directory.
Currently using: RK-9000WH/GR, CMS QFXT w/ Ghost Squid
- I'm game !

Offline Grendel

  • Posts: 462
  • Location: OR, USA
    • Firmware for Costar Replacement Controllers
Re: Business card source code
« Reply #8 on: Tue, 14 January 2014, 12:26:06 »
Beat you by 2min ;P But yeah, the aux thing. MS-DOS remnant :/
Currently using: RK-9000WH/GR, CMS QFXT w/ Ghost Squid
- I'm game !

Offline komar007

  • Thread Starter
  • Posts: 712
  • Location: Poland
    • komar's blog
Re: Business card source code
« Reply #9 on: Tue, 14 January 2014, 12:31:59 »
didn't check the topic before editing;)
GH60 rev. B w/ ali's case|Cherry G80-3000 HFU/05|IBM Model M (51G8572)
Check out the GH60 project! | How to make a keyboard

Offline Grendel

  • Posts: 462
  • Location: OR, USA
    • Firmware for Costar Replacement Controllers
Re: Business card source code
« Reply #10 on: Tue, 14 January 2014, 14:07:53 »
 
To compile in windows, you'll need 2 things
Gnu Make: http://gnuwin32.sourceforge.net/downlinks/make.php
avr-gcc for windows: http://andybrown.me.uk/wk/files/avrgcc-4.7.0-avrlibc-1.8.0.zip

The make that's included in avrgcc-4.7.0-avrlibc-1.8.0.zip doesn't work ? Thanks for that link BTW, wasn't aware of it :)
Currently using: RK-9000WH/GR, CMS QFXT w/ Ghost Squid
- I'm game !

Offline komar007

  • Thread Starter
  • Posts: 712
  • Location: Poland
    • komar's blog
Re: Business card source code
« Reply #11 on: Tue, 14 January 2014, 14:16:52 »
Oh, sure it does.
I wasn't aware there was one in this package.


Fixed OP.
GH60 rev. B w/ ali's case|Cherry G80-3000 HFU/05|IBM Model M (51G8572)
Check out the GH60 project! | How to make a keyboard

Offline Grendel

  • Posts: 462
  • Location: OR, USA
    • Firmware for Costar Replacement Controllers
Re: Business card source code
« Reply #12 on: Thu, 16 January 2014, 18:59:03 »
Got my KeyCard today, yay ! ;D Fun little piece of hardware, many thanks to i3oilermaker for making and selling it !

After spending the afternoon knee-deep in my firmware and throwing a USB analyzer at it, I found the differences in Atmels U2 module. And some other minor bugs *cough*. KeyCard-02.zip (attached) contains the latest source and the hex file that now actually works.

To load the hex file, you'll need Atmel's FLIP  (and Java if you don't have it installed.) To activate the DFU boot-loader on the Keycard, briefly short the two pads next to the USB mini connector (right above the robots head) with something metallic (wire, screwdriver etc.) while the card is connected to the computer.

For more details on FLIP follow the link to the instructions in the OP.

To edit and compile the code you need AVR Studio 4.19 (AVRS) and avr-gcc 4.7.0 + avr-libc 1.8. Install AVRS and extract the avrgcc archive into C:\Tools. Extract the KeyCard archive, then double-click KeyCard.aps -- this will start AVRS and load the KeyCard project. Select "Build" --> "Build" to rebuild KeyCard.hex.

Right now the keys are mapped to the three LOCK keys (left-to-right: Caps, Scroll, Num.) The LED's are mapped to the respective functions.

If the SCR-LOCK LED is on alone for 5s, control is passed to the DFU boot-loader (no need for shorting the pads anymore :).) If no LOCK LED is active, the LED's start a demo display after 5s.

The key-bindings are defined in build_kbd_report() (in kb.c). All possible U_... defines can be found in kbusages.h.

Let me know if you have questions.

[ Attachment Invalid Or Does Not Exist ] Outdated, see post #15 for an updated version.
« Last Edit: Thu, 30 January 2014, 14:50:26 by Grendel »
Currently using: RK-9000WH/GR, CMS QFXT w/ Ghost Squid
- I'm game !

Offline komar007

  • Thread Starter
  • Posts: 712
  • Location: Poland
    • komar's blog
Re: Business card source code
« Reply #13 on: Fri, 17 January 2014, 04:11:10 »
Nice, it works on mine;)
GH60 rev. B w/ ali's case|Cherry G80-3000 HFU/05|IBM Model M (51G8572)
Check out the GH60 project! | How to make a keyboard

Offline domoaligato

  • * Exquisite Elder
  • Posts: 1672
  • Location: USA
  • All your base are belong to us!
    • All your base are belong to us!
Re: Business card source code
« Reply #14 on: Fri, 17 January 2014, 13:05:08 »
would someone please link me to a push button that is like the one on the gh60 that I could solder on the card for it to switch to bootloader mode? I am good with tweezers but I would like to add a button.
:D

Offline Grendel

  • Posts: 462
  • Location: OR, USA
    • Firmware for Costar Replacement Controllers
Re: Business card source code
« Reply #15 on: Fri, 17 January 2014, 14:15:37 »
This one may work.

Here is a slightly fine-tuned version of my firmware, should be the last version for a while. Changes:
  • to start the boot-loader, now the Num- and Scroll-lock LED's have to be on for 5s at the same time (any other combination will not start the BL)
  • changed the PWM mechanism, also went from 6b to 8b PWM
  • Lock-on LED indicators are now run at 12.5% brightness
  • more catchy demo-mode
  • demo-mode can be toggled on/off by pressing all three switches at the same time (if off the system LED will be on very faintly if no lock LED is active)
  • reordered LED's & switches to match the LED sequence on keyboards: NUM, CAPS, SCR (left-to-right)
See post #12 for compile & load instructions.

Enjoy !

[ Attachment Invalid Or Does Not Exist ] See post #20 for an updated version.
« Last Edit: Thu, 30 January 2014, 14:50:43 by Grendel »
Currently using: RK-9000WH/GR, CMS QFXT w/ Ghost Squid
- I'm game !

Offline GeorgeK

  • Posts: 758
  • Location: Ashford, Kent, United Kingdom
Re: Business card source code
« Reply #16 on: Sat, 18 January 2014, 11:01:07 »
I'm a complete beginner when it comes to any form of programming of any kind...  How would I alter the file that you've got there to make it type a word or sentence (for simplicity's sake 'hello')

Thanks in advance

GK
Black Filco TKL - Stickered, Lubed Reds || Poker w/Plate, Alu Case -  Stickered, Lubed 65g Ergo-Clears || Cherry G80-3700 w/SS Plate - Lubed 65g Ergo-Clears

Offline domoaligato

  • * Exquisite Elder
  • Posts: 1672
  • Location: USA
  • All your base are belong to us!
    • All your base are belong to us!
Re: Business card source code
« Reply #17 on: Mon, 20 January 2014, 15:55:01 »
in komar's download zip

see main_techkeys.c

Code: [Select]
uint8_t keys1[] = {KH, KT, KT, KP, KSEMICOLON, KSLASH, KSLASH, KW, KW, KW,
KPERIOD, KT, KE, KC, KH, KK, KE, KY, KS, KPERIOD, KU, KS};

uint8_t keys2[] = {KM, KA, KI, KL, KT, KO, KSEMICOLON, KI, KN, KF, KO, K2,
KT, KE, KC, KH, KK, KE, KY, KS, KPERIOD, KU, KS};

uint8_t keys3[] = {KH, KT, KT, KP, KSEMICOLON, KSLASH, KSLASH, KW, KW, KW,
KPERIOD, KF, KA, KC, KE, KB, KO, KO, KK, KPERIOD, KC, KO, KM, KSLASH,
KT, KE, KC, KH, KK, KE, KY, KS, KU, KS};

This is pretty much
uint8_t keys1 = http://www.techkeys.us
uint8_t keys2 = mailto:INFO@TECHKEYS.US
uint8_t keys3 = http://www.facebook.com/techkeysus

to find the keymaps (KH,KT,ETC) look in usb_keyboard.h all the scancodes are defined there.

Spy should be like this. I am only confused about how the shift's would be used to perform right shift + / to get ?

uint8_t keys3[] = {KH, KT, KT, KP, KSEMICOLON, KSLASH, KSLASH, KG, KE, KE,
   KK, KH, KA, KC, KK, KPERIOD, KO, KR, KG, KSLASH, KI, KN, KD, KE,
   KX, KPERIOD, KP, KH, KP, KRIGHT_SHIFT, KSLASH, KA, KC, KT, KI, KO, KN,
        KEQUAL, KR, KE, KC, KE, KN, KT, KT, KO, KP, KI, KC, KS};

http://geekhack.org/index.php?action=recenttopics


I am confused also because somehow K2 = @ instead of 2 ?

Offline komar007

  • Thread Starter
  • Posts: 712
  • Location: Poland
    • komar's blog
Re: Business card source code
« Reply #18 on: Mon, 20 January 2014, 16:03:20 »
This is done as a very ugly trick, because I only needed 2 shifted keys: @ and :
This line (and a couple more):
         if (k == KSEMICOLON || k == K2) { (I can't get the index operator to work, because SMF keeps making this italic...)
simply press shift each time they see semicolon or 2, so that they become colon and at, respectively. If you need to use that code to output '2' or ';', you're out of luck:(
« Last Edit: Mon, 20 January 2014, 16:05:34 by komar007 »
GH60 rev. B w/ ali's case|Cherry G80-3000 HFU/05|IBM Model M (51G8572)
Check out the GH60 project! | How to make a keyboard

Offline domoaligato

  • * Exquisite Elder
  • Posts: 1672
  • Location: USA
  • All your base are belong to us!
    • All your base are belong to us!
Re: Business card source code
« Reply #19 on: Mon, 20 January 2014, 16:20:02 »
I can not wait to see how/when you implement something like hasu's macro action function!

Offline Grendel

  • Posts: 462
  • Location: OR, USA
    • Firmware for Costar Replacement Controllers
Re: Business card source code
« Reply #20 on: Thu, 23 January 2014, 12:55:20 »
More fine-tuning. Mainly enabled the endpoint for system/consumer controls. Default key-mapping for SCR lock off is: Vol-, Mute, Vol+; for SCR lock on: PrevTrack, Pause, NextTrack.

Happy hacking ! :cool:

[ Attachment Invalid Or Does Not Exist ] See post #34 for an updated version.
« Last Edit: Thu, 30 January 2014, 14:51:00 by Grendel »
Currently using: RK-9000WH/GR, CMS QFXT w/ Ghost Squid
- I'm game !

Offline GeorgeK

  • Posts: 758
  • Location: Ashford, Kent, United Kingdom
Re: Business card source code
« Reply #21 on: Fri, 24 January 2014, 05:41:49 »
in komar's download zip

see main_techkeys.c

Code: [Select]
uint8_t keys1[] = {KH, KT, KT, KP, KSEMICOLON, KSLASH, KSLASH, KW, KW, KW,
KPERIOD, KT, KE, KC, KH, KK, KE, KY, KS, KPERIOD, KU, KS};

uint8_t keys2[] = {KM, KA, KI, KL, KT, KO, KSEMICOLON, KI, KN, KF, KO, K2,
KT, KE, KC, KH, KK, KE, KY, KS, KPERIOD, KU, KS};

uint8_t keys3[] = {KH, KT, KT, KP, KSEMICOLON, KSLASH, KSLASH, KW, KW, KW,
KPERIOD, KF, KA, KC, KE, KB, KO, KO, KK, KPERIOD, KC, KO, KM, KSLASH,
KT, KE, KC, KH, KK, KE, KY, KS, KU, KS};

This is pretty much
uint8_t keys1 = http://www.techkeys.us
uint8_t keys2 = mailto:INFO@TECHKEYS.US
uint8_t keys3 = http://www.facebook.com/techkeysus

to find the keymaps (KH,KT,ETC) look in usb_keyboard.h all the scancodes are defined there.

Spy should be like this. I am only confused about how the shift's would be used to perform right shift + / to get ?

uint8_t keys3[] = {KH, KT, KT, KP, KSEMICOLON, KSLASH, KSLASH, KG, KE, KE,
   KK, KH, KA, KC, KK, KPERIOD, KO, KR, KG, KSLASH, KI, KN, KD, KE,
   KX, KPERIOD, KP, KH, KP, KRIGHT_SHIFT, KSLASH, KA, KC, KT, KI, KO, KN,
        KEQUAL, KR, KE, KC, KE, KN, KT, KT, KO, KP, KI, KC, KS};

http://geekhack.org/index.php?action=recenttopics


I am confused also because somehow K2 = @ instead of 2 ?

Thanks for that - I told you I was a noob!  One problem though - even if I click build before I have made any changes the build fails...  Any idea about that?  If I open Grendel's file and click build it works fine but I can't figure out how to change his...

Thanks again for putting up with my questions!

GK
Black Filco TKL - Stickered, Lubed Reds || Poker w/Plate, Alu Case -  Stickered, Lubed 65g Ergo-Clears || Cherry G80-3700 w/SS Plate - Lubed 65g Ergo-Clears

Offline komar007

  • Thread Starter
  • Posts: 712
  • Location: Poland
    • komar's blog
Re: Business card source code
« Reply #22 on: Fri, 24 January 2014, 09:46:38 »
Where do you click "build"?
My sources don't have a build button:D
GH60 rev. B w/ ali's case|Cherry G80-3000 HFU/05|IBM Model M (51G8572)
Check out the GH60 project! | How to make a keyboard

Offline Grendel

  • Posts: 462
  • Location: OR, USA
    • Firmware for Costar Replacement Controllers
Re: Business card source code
« Reply #23 on: Fri, 24 January 2014, 17:00:35 »
Using AVR Studio, I guess :)

The project file probably points to the "wrong" compiler. If you use avr-gcc 4.7.0 + avr-libc 1.8, go to Project -> Configuration Options -> Custom Options and point avr-gcc: to C:\Tools\avrgcc\bin\avr-gcc.exe, make: to C:\Tools\avrgcc\bin\make.exe .

(On a side-note, the Build -> Clean action will not work w/ this setup, since it doesn't contain a rm.exe .)

If you use WinAVR, the paths are C:\Tools\WinAVR-20100110\bin\avr-gcc.exe and C:\Tools\WinAVR-20100110\utils\bin\make.exe
« Last Edit: Fri, 24 January 2014, 17:04:35 by Grendel »
Currently using: RK-9000WH/GR, CMS QFXT w/ Ghost Squid
- I'm game !

Offline Laser

  • Posts: 102
  • Location: euROpe
Re: Business card source code
« Reply #24 on: Sat, 25 January 2014, 15:32:44 »

In the main_techkeys.us file, if i'd want to detect multiple simultaneous key presses, would it be enough to set a bit (of 3) for every i that gives a false (0) IO_get(4+i) call?

e.g. something like:

uint8_t keys = 0;
for (int i = 0; i < 3; ++i) {
         if (!IO_get(4+i)) {
             keys += 1<<i;
         }
      }
if (!keys)
   continue;

Offline komar007

  • Thread Starter
  • Posts: 712
  • Location: Poland
    • komar's blog
Re: Business card source code
« Reply #25 on: Sat, 25 January 2014, 16:07:56 »
Makes perfect sense.
GH60 rev. B w/ ali's case|Cherry G80-3000 HFU/05|IBM Model M (51G8572)
Check out the GH60 project! | How to make a keyboard

Offline GeorgeK

  • Posts: 758
  • Location: Ashford, Kent, United Kingdom
Re: Business card source code
« Reply #26 on: Sun, 26 January 2014, 03:42:49 »
Using AVR Studio, I guess :)

The project file probably points to the "wrong" compiler. If you use avr-gcc 4.7.0 + avr-libc 1.8, go to Project -> Configuration Options -> Custom Options and point avr-gcc: to C:\Tools\avrgcc\bin\avr-gcc.exe, make: to C:\Tools\avrgcc\bin\make.exe .

(On a side-note, the Build -> Clean action will not work w/ this setup, since it doesn't contain a rm.exe .)

If you use WinAVR, the paths are C:\Tools\WinAVR-20100110\bin\avr-gcc.exe and C:\Tools\WinAVR-20100110\utils\bin\make.exe

Thanks for that - unfortunately I still get build failed...  If I wanted to alter your file Grendel to type a string of letters how would I do that?  If I open one of your files and click Build it works but I can't figure out how to alter yours...

Thanks again

George
Black Filco TKL - Stickered, Lubed Reds || Poker w/Plate, Alu Case -  Stickered, Lubed 65g Ergo-Clears || Cherry G80-3700 w/SS Plate - Lubed 65g Ergo-Clears

Offline Grendel

  • Posts: 462
  • Location: OR, USA
    • Firmware for Costar Replacement Controllers
Re: Business card source code
« Reply #27 on: Sun, 26 January 2014, 18:45:32 »
Sorry, my bad -- I was still working w/ WinAVR-20100110 when I created the project for AVRS -- avr-libc 1.6.7 has a bug related to the clock prescaler definitions for the ATmega16U2 and I added some code to _aux.h to fix it. Unfortunately that code isn't compatible w/ avr-libc 1.8.0 :/ You can fix it by

1. in _aux.h, remove everything after the line

 // Missing in power.h for the ATmegaXU2 (WinAVR 20100110)

or
2. in _aux.h, change the line

 #if ! defined(clock_prescale_set)

to

 #if ! defined(clock_prescale_get)

My firmware does not support macros (yet...), it only allows you to map single key-codes to the switches.
« Last Edit: Sun, 26 January 2014, 18:48:27 by Grendel »
Currently using: RK-9000WH/GR, CMS QFXT w/ Ghost Squid
- I'm game !

Offline heedpantsnow

  • * Esteemed Elder
  • Posts: 3692
  • Location: Orlando, FL
  • Old enough to know better
Re: Business card source code
« Reply #28 on: Thu, 30 January 2014, 07:52:41 »
Can someone tell me which way the LEDS go on?  I forgot all my basic circuit knowledge
I'm back.

Espresso machine overhaul: https://geekhack.org/index.php?topic=78261.0

Carbon Fiber keyboard base: https://geekhack.org/index.php?topic=54825

Offline SpAmRaY

  • NOT a Moderator
  • * Certified Spammer
  • Posts: 14667
  • Location: ¯\(°_o)/¯
  • because reasons.......
Re: Business card source code
« Reply #29 on: Thu, 30 January 2014, 07:54:15 »
Can someone tell me which way the LEDS go on?  I forgot all my basic circuit knowledge

I believe it's short side in round and tall in square.

Offline jdcarpe

  • * Curator
  • Posts: 8852
  • Location: Odessa, TX
  • Live long, and prosper.
Re: Business card source code
« Reply #30 on: Thu, 30 January 2014, 08:52:56 »
I just pressed a key and held the legs of the LED to the pads to find out which orientation lit the LED. That's how I commonly test for LED orientation.
KMAC :: LZ-GH :: WASD CODE :: WASD v2 :: GH60 :: Alps64 :: JD45 :: IBM Model M :: IBM 4704 "Pingmaster"

http://jd40.info :: http://jd45.info


in memoriam

"When I was a kid, I used to take things apart and never put them back together."

Offline heedpantsnow

  • * Esteemed Elder
  • Posts: 3692
  • Location: Orlando, FL
  • Old enough to know better
Re: Business card source code
« Reply #31 on: Thu, 30 January 2014, 09:00:11 »
Can someone tell me which way the LEDS go on?  I forgot all my basic circuit knowledge

I believe it's short side in round and tall in square.

I think that's right but on all my cards both holes are round
I'm back.

Espresso machine overhaul: https://geekhack.org/index.php?topic=78261.0

Carbon Fiber keyboard base: https://geekhack.org/index.php?topic=54825

Offline heedpantsnow

  • * Esteemed Elder
  • Posts: 3692
  • Location: Orlando, FL
  • Old enough to know better
Re: Business card source code
« Reply #32 on: Thu, 30 January 2014, 09:01:08 »
I just pressed a key and held the legs of the LED to the pads to find out which orientation lit the LED. That's how I commonly test for LED orientation.

Hmmm well I guess that's what I will do too then :-\
I'm back.

Espresso machine overhaul: https://geekhack.org/index.php?topic=78261.0

Carbon Fiber keyboard base: https://geekhack.org/index.php?topic=54825

Offline heedpantsnow

  • * Esteemed Elder
  • Posts: 3692
  • Location: Orlando, FL
  • Old enough to know better
Re: Business card source code
« Reply #33 on: Thu, 30 January 2014, 09:35:36 »
OK, I just tested it.  The short side goes on the same side as the diode.  Hope that helps sby.
I'm back.

Espresso machine overhaul: https://geekhack.org/index.php?topic=78261.0

Carbon Fiber keyboard base: https://geekhack.org/index.php?topic=54825

Offline Grendel

  • Posts: 462
  • Location: OR, USA
    • Firmware for Costar Replacement Controllers
Re: Business card source code
« Reply #34 on: Thu, 30 January 2014, 14:13:33 »
The longer pin on an LED (before cutting..) is always + (aka VCC), the shorter is - (aka GND).

Here is the latest (and probably final) version of my firmware, now w/ macros.

The LED's reflect the NUM, CAPS, and SCR lock LED's of a keyboard. If no lock LED is on, the card will start a little demo display after 5s. The NUM and SCR lock LED status is used to select different layers/functions:
  • NUM and SCR off: keys behave like the original firmware, ie. output www, mail, and fb links
  • NUM on: keys are mapped to (l2r) : Vol-, Mute, Vol+
  • SCR on: keys are mapped to (l2r): Prev. Track, Play/Pause, Next Track
  • NUM and SCR on: bootloader will be started after 5s
  • if the CAPS LED is on the keys will behave like the original firmware, regardless of the state of the other two LED's
The key mapping can be found in build_kbd_report(), the macros in play_macro(). Notes on the macros:
  • a macro is a list of usages (not characters)
  • each entry in the macro will create a report containing that entry, except
  • modifiers. Each modifier will be applied to the next non-modifier entry, eg. use U_LftShift, U_3 to echo #, U_LftGui, U_L to lock the computer, and U_LftCtrl, U_LftAlt, U_Del to issue Ctrl+Alt+Del
  • to echo multiple identical usages, seperate them w/ U_None, eg. www as U_W, U_None, U_W, U_None, U_W
  • the last entry of a macro must be U_None
  • no System Control or Consumer Control usages are supported (should be easy to add if necessary)


To load the hex file, you'll need Atmel's FLIP  (and Java if you don't have it installed.) To activate the DFU boot-loader on the Keycard, briefly short the two pads next to the USB mini connector (right above the robots head) with something metallic (wire, screwdriver etc.) while the card is connected to the computer.

For more details about using FLIP, follow the link to the instructions in the OP or check the FLIP help files.

To edit and compile the code you need AVR Studio 4.19 (AVRS) and avr-gcc 4.7.0 + avr-libc 1.8. Install AVRS and extract the avrgcc archive into C:\Tools. Extract the KeyCard archive into an empty directory, then double-click KeyCard\KeyCard.aps -- this will start AVRS and load the KeyCard project. Select "Build" --> "Build" to rebuild KeyCard\bin\KeyCard.hex.
« Last Edit: Fri, 31 January 2014, 11:52:23 by Grendel »
Currently using: RK-9000WH/GR, CMS QFXT w/ Ghost Squid
- I'm game !

Offline i3oilermaker

  • * Moderator
  • Posts: 2362
  • Location: Chicago
  • techkeys.us
    • TechKeys
Re: Business card source code
« Reply #35 on: Thu, 30 January 2014, 15:16:10 »

Offline neun_sechs_zwei

  • Posts: 34
  • Location: California
Re: Business card source code
« Reply #36 on: Tue, 11 February 2014, 01:28:44 »
Thanks for this (and the cool business card as well, techkeys)! Really easy to get going and for trying out building and flashing trivial changes. I just have it working as F10–F12 for my Mac right now (volume controls). But I bought it to play around with the atmega and the avr toolchain, and maybe eventually try doing something with the extra pins :)

Offline fatchoi

  • Posts: 218
  • Location: Hong Kong
Re: Business card source code
« Reply #37 on: Thu, 13 March 2014, 00:07:10 »
That sounds cool. Lemme get a few business cards.

Offline Pacifist

  • Report me *again* if there are gifs in my sig
  • * Elevated Elder
  • Posts: 3599
  • Location: Cali
  • on hiatus
Re: Business card source code
« Reply #38 on: Sat, 15 March 2014, 22:26:55 »
Sweet firmware, going to figure out how to use it :))

Can it be possible to load soarer's converter onto this card?

Offline Sifo

  • Alter
  • * Exquisite Elder
  • Posts: 7487
  • Location: #GOLDSPRINGS, #LEGITBALLIN
  • Illustrious
Re: Business card source code
« Reply #39 on: Mon, 31 March 2014, 21:48:12 »
Finally programmed this bad boy after almost a year now :D
I love Elzy

Offline metalliqaz

  • * Maker
  • Posts: 4951
  • Location: the Making Stuff subforum
  • Leopold fanboy
Re: Business card source code
« Reply #40 on: Sat, 12 April 2014, 13:48:11 »
Oh, forgot to add: if you're compiling without the makefiles provided, you'll also need to add -DPLATFORM_techkeys to compiler options.
You can prepare the hex file with 2 commands:
avr-gcc -Os -std=gnu99 -g -ggdb -Wall -Wextra -mmcu=atmega16u2 -DPLATFORM_techkeys -lm main_techkeys.c io.c platforms.c usb.c usb_config.c usb_hardware.c timer.c hid.c -o card.elf
and then:
avr-objcopy card.elf -O ihex card.hex

I followed these directions and it produced a .hex that doesn't function.  Does anyone have the techkeys binary?

Offline fatchoi

  • Posts: 218
  • Location: Hong Kong
Re: Business card source code
« Reply #41 on: Sat, 03 May 2014, 01:16:05 »
The longer pin on an LED (before cutting..) is always + (aka VCC), the shorter is - (aka GND).

Here is the latest (and probably final) version of my firmware, now w/ macros.

The LED's reflect the NUM, CAPS, and SCR lock LED's of a keyboard. If no lock LED is on, the card will start a little demo display after 5s. The NUM and SCR lock LED status is used to select different layers/functions:
  • NUM and SCR off: keys behave like the original firmware, ie. output www, mail, and fb links
  • NUM on: keys are mapped to (l2r) : Vol-, Mute, Vol+
  • SCR on: keys are mapped to (l2r): Prev. Track, Play/Pause, Next Track
  • NUM and SCR on: bootloader will be started after 5s
  • if the CAPS LED is on the keys will behave like the original firmware, regardless of the state of the other two LED's
The key mapping can be found in build_kbd_report(), the macros in play_macro(). Notes on the macros:
  • a macro is a list of usages (not characters)
  • each entry in the macro will create a report containing that entry, except
  • modifiers. Each modifier will be applied to the next non-modifier entry, eg. use U_LftShift, U_3 to echo #, U_LftGui, U_L to lock the computer, and U_LftCtrl, U_LftAlt, U_Del to issue Ctrl+Alt+Del
  • to echo multiple identical usages, seperate them w/ U_None, eg. www as U_W, U_None, U_W, U_None, U_W
  • the last entry of a macro must be U_None
  • no System Control or Consumer Control usages are supported (should be easy to add if necessary)
Show Image


To load the hex file, you'll need Atmel's FLIP  (and Java if you don't have it installed.) To activate the DFU boot-loader on the Keycard, briefly short the two pads next to the USB mini connector (right above the robots head) with something metallic (wire, screwdriver etc.) while the card is connected to the computer.

For more details about using FLIP, follow the link to the instructions in the OP or check the FLIP help files.

To edit and compile the code you need AVR Studio 4.19 (AVRS) and avr-gcc 4.7.0 + avr-libc 1.8. Install AVRS and extract the avrgcc archive into C:\Tools. Extract the KeyCard archive into an empty directory, then double-click KeyCard\KeyCard.aps -- this will start AVRS and load the KeyCard project. Select "Build" --> "Build" to rebuild KeyCard\bin\KeyCard.hex.


Hi! Thank you for your codes, they are fantastic!

I'm customizing my business card, based on your work. And I have got a quick few questions on the coding, appreciate you could help please.

1. For the key stroke "U_None", what does it mean indeed? Is it related to simultaneously pressing a few keys and U_None tells the computer to release the key?
(Indeed I want to press a key, then it will do "Win+R" and type "EXCEL". This would launch the Microsoft Excel application on my computer)

2. Which section of the code should I look at if I want to customize the LED glowing pattern?

Many thanks!
« Last Edit: Sat, 03 May 2014, 01:19:17 by fatchoi »

Offline fatchoi

  • Posts: 218
  • Location: Hong Kong
Re: Business card source code
« Reply #42 on: Sat, 03 May 2014, 01:17:22 »
Oh, forgot to add: if you're compiling without the makefiles provided, you'll also need to add -DPLATFORM_techkeys to compiler options.
You can prepare the hex file with 2 commands:
avr-gcc -Os -std=gnu99 -g -ggdb -Wall -Wextra -mmcu=atmega16u2 -DPLATFORM_techkeys -lm main_techkeys.c io.c platforms.c usb.c usb_config.c usb_hardware.c timer.c hid.c -o card.elf
and then:
avr-objcopy card.elf -O ihex card.hex

I followed these directions and it produced a .hex that doesn't function.  Does anyone have the techkeys binary?

Hi, I've followed Grendel's instruction and it works. I've compiled a hex file successfully (note I fail to compile using Komar's code, as there are probably some components missing).
Do you need the hex file or what? I could email to you.

Offline fatchoi

  • Posts: 218
  • Location: Hong Kong
Re: Business card source code
« Reply #43 on: Sat, 03 May 2014, 01:18:03 »
[duplicate post]

Offline Grendel

  • Posts: 462
  • Location: OR, USA
    • Firmware for Costar Replacement Controllers
Re: Business card source code
« Reply #44 on: Sat, 03 May 2014, 02:44:35 »
1. For the key stroke "U_None", what does it mean indeed? Is it related to simultaneously pressing a few keys and U_None tells the computer to release the key?
(Indeed I want to press a key, then it will do "Win+R" and type "EXCEL". This would launch the Microsoft Excel application on my computer)

It has to do w/ the way how keys are transported over USB -- each data packet send to the computer reflects which keys are down (unlike PS/2 where the events themselves are send.) Every time a key changes state a data packet needs to be send to the computer letting it know what's going on. The keycodes send are called "usages" (hence the U_ prefix.) A single key down/up will always cause two data transactions -- when the key goes down and when the key goes up. The macro mechanism will simply read the data out of the arrays and send a data package for each entry, containing just that entry (w/ the exception of the modifiers as explained above.) If you want to send eg. the two characters 'e' and 'x' the sequence is { U_E, U_X, U_None } and is translated into three transmissions -- 1. send U_E, 2. send U_X (the computer will see that U_E is not active anymore), and 3. send U_None (basically an empty packet) to let the computer know that no key is down anymore.

So your macro should look like this:

{ U_LftGui, U_R, U_None, U_E, U_X, U_C, U_E, U_L, U_None, U_Enter, U_None }

(the 1st and the 2nd U_None may be superfluous, threw them in for good measure ;))

2. Which section of the code should I look at if I want to customize the LED glowing pattern?

The "demo" pattern is created by the function led_demo(). It's called every millisecond and uses its local static variables timer and idx to keep track of its state (every time timer elapses the new brightness levels are set from the breathe[] array using idx as index.)
Currently using: RK-9000WH/GR, CMS QFXT w/ Ghost Squid
- I'm game !

Offline fatchoi

  • Posts: 218
  • Location: Hong Kong
Re: Business card source code
« Reply #45 on: Sat, 03 May 2014, 05:19:48 »
1. For the key stroke "U_None", what does it mean indeed? Is it related to simultaneously pressing a few keys and U_None tells the computer to release the key?
(Indeed I want to press a key, then it will do "Win+R" and type "EXCEL". This would launch the Microsoft Excel application on my computer)

It has to do w/ the way how keys are transported over USB -- each data packet send to the computer reflects which keys are down (unlike PS/2 where the events themselves are send.) Every time a key changes state a data packet needs to be send to the computer letting it know what's going on. The keycodes send are called "usages" (hence the U_ prefix.) A single key down/up will always cause two data transactions -- when the key goes down and when the key goes up. The macro mechanism will simply read the data out of the arrays and send a data package for each entry, containing just that entry (w/ the exception of the modifiers as explained above.) If you want to send eg. the two characters 'e' and 'x' the sequence is { U_E, U_X, U_None } and is translated into three transmissions -- 1. send U_E, 2. send U_X (the computer will see that U_E is not active anymore), and 3. send U_None (basically an empty packet) to let the computer know that no key is down anymore.

So your macro should look like this:

{ U_LftGui, U_R, U_None, U_E, U_X, U_C, U_E, U_L, U_None, U_Enter, U_None }

(the 1st and the 2nd U_None may be superfluous, threw them in for good measure ;))

2. Which section of the code should I look at if I want to customize the LED glowing pattern?

The "demo" pattern is created by the function led_demo(). It's called every millisecond and uses its local static variables timer and idx to keep track of its state (every time timer elapses the new brightness levels are set from the breathe[] array using idx as index.)

Thanks man! For 1, may I ask how the computer knows I want to press "U_LftGui" and "U_R" together, but not the first 3 keys together (U_LftGui, U_R, U_E)?
In other words, the computer will released the "U_LftGui" after I use "U_R"?

For the LED, probably I need to take more time drilling on the codes.
Thank you so much again for your help. This card is a lot of fun. ;)

Edited:
Just tried to put all the word, powerpoint and excel into the code. But sometimes keys are not registered. Probably the "Run" box isn't fast enough to pop-up.
Any idea how to introduce a delay please?
« Last Edit: Sat, 03 May 2014, 06:45:06 by fatchoi »

Offline Grendel

  • Posts: 462
  • Location: OR, USA
    • Firmware for Costar Replacement Controllers
Re: Business card source code
« Reply #46 on: Sat, 03 May 2014, 17:41:59 »
Thanks man! For 1, may I ask how the computer knows I want to press "U_LftGui" and "U_R" together, but not the first 3 keys together (U_LftGui, U_R, U_E)?
In other words, the computer will released the "U_LftGui" after I use "U_R"?

The modifier usages are added to the next regular usage in the macro stream and reset after that. Eg. { U_LCtrl, U_LAlt, U_Del, U_Esc, U_None }
Ctrl and Alt are collected and send along w/ Del. The next packet contains only Esc and thus resets all three previous keys.

Edited:
Just tried to put all the word, powerpoint and excel into the code. But sometimes keys are not registered. Probably the "Run" box isn't fast enough to pop-up.
Any idea how to introduce a delay please?

Why yes, I do ;) I added that functionality shortly after the last release, I've attached the latest version to this post. The macro routine moved out of kb.c and the macros are now defined in kb.h (MACRO_1, 2, and 3.) Besides a delay they now can also contain consumer and system control codes. To insert a delay, use uDms(x), where x is the delay in milliseconds (max. 16383, ie 16.4s.) Try something like this:

{ U_LftGui, U_R, U_None, uDms(750), U_E, U_X, U_C, U_E, U_L, U_None, uDms(250), U_Enter, U_None }

[ Attachment Invalid Or Does Not Exist ] Outdated. Do not use.

Please see post #48 for an updated version.
« Last Edit: Sun, 04 May 2014, 14:48:56 by Grendel »
Currently using: RK-9000WH/GR, CMS QFXT w/ Ghost Squid
- I'm game !

Offline fatchoi

  • Posts: 218
  • Location: Hong Kong
Re: Business card source code
« Reply #47 on: Sat, 03 May 2014, 20:01:50 »
Thanks man! For 1, may I ask how the computer knows I want to press "U_LftGui" and "U_R" together, but not the first 3 keys together (U_LftGui, U_R, U_E)?
In other words, the computer will released the "U_LftGui" after I use "U_R"?

The modifier usages are added to the next regular usage in the macro stream and reset after that. Eg. { U_LCtrl, U_LAlt, U_Del, U_Esc, U_None }
Ctrl and Alt are collected and send along w/ Del. The next packet contains only Esc and thus resets all three previous keys.

Edited:
Just tried to put all the word, powerpoint and excel into the code. But sometimes keys are not registered. Probably the "Run" box isn't fast enough to pop-up.
Any idea how to introduce a delay please?

Why yes, I do ;) I added that functionality shortly after the last release, I've attached the latest version to this post. The macro routine moved out of kb.c and the macros are now defined in kb.h (MACRO_1, 2, and 3.) Besides a delay they now can also contain consumer and system control codes. To insert a delay, use uDms(x), where x is the delay in milliseconds (max. 16383, ie 16.4s.) Try something like this:

{ U_LftGui, U_R, U_None, uDms(750), U_E, U_X, U_C, U_E, U_L, U_None, uDms(250), U_Enter, U_None }

Great work! I will take a look. It's much easier starting with your code. :D Could code some useful shortcut keys for my daily Excel work.

I'm planning to make 3 macros for the 3 layers. Separating them probably allows more flexibility. (could just put 1 keystroke anyway in the macro section, say the Mute)

And I will separate the LED breathing array to 3 arrays, such that the pattern could be controlled individually. (seems the array sizes should be the same or else the "idx" might have some difficult to reset)
I'm also thinking about pressing a key to light up an associated LED, or play a particular LED pattern once and stop. (e.g. 3 different patterns for 3 keys)

I have some other ideas flowing on my mind but really I have to be more familiar with the coding. e.g. pressing 3 keys together might toggle the LED demo pattern on/off.
This card is really fun to play with and experiment. Lucky I've got a few. :)

Edit:
Perhaps we could utilize the blue LED on the top right corner of the card for some flashing pattern or indicative purpose, similar to your idea of lighting up a LED when the NumLock/ Scroll/ Caps is on.

Edit2:
Or use pressing 3 keys to toggle another 3 layers of functionality.  :cool: Probably feasible. Can further use the blue LED that come with the card to indicate which 3 layers are currently used.
« Last Edit: Sat, 03 May 2014, 20:07:23 by fatchoi »

Offline Grendel

  • Posts: 462
  • Location: OR, USA
    • Firmware for Costar Replacement Controllers
Re: Business card source code
« Reply #48 on: Sun, 04 May 2014, 14:46:52 »
Dang, introduced a bug in the last version (wrong USB_HIDREP_DESC_CTRL_SZ value in usb_cfg.h) My apologies, I have attached the fixed source.
Currently using: RK-9000WH/GR, CMS QFXT w/ Ghost Squid
- I'm game !

Offline rosslerosa

  • Posts: 25
  • Location: TORONTO CANADA
  • MF DOOM
Re: Business card source code
« Reply #49 on: Sat, 17 May 2014, 00:58:35 »
This is awesome! Was reading the posts and it really made me want to buy one and reprogram the keys for anything.
Perhaps I could even surprise my girlfriend with a little letter when she presses on a button?
Your posts have really opened my eyes on how friendly this forum is too!
I will come back here when I receive my card.
Thanks a lot!