How to build your very own keyboard firmware

Labern

25 Nov 2016, 11:22

I was wondering if someone could help me.
I would like to make a 4 button keyboard but seeing I'm a super Noob I have know idea what I'm doing.
I brought a Teensy 3.2 but now after looking for ways to program it I'm not sure if that was the best option as everyone else seems to be using Teensy 2's.

Is there pre-written .ino file that I can open in Arduino compiler that I can edit then compile to my Teensy?

Zayter

05 Dec 2016, 17:23

I am getting this error while trying to compile on windows a one about not having stdint on my ubuntu machine. I would love some help!
oajaoj.PNG
oajaoj.PNG (22.85 KiB) Viewed 11094 times

Aran.E99

17 Dec 2016, 14:45

Hey guys, I don't normally post on this site but rather GH hence my low stats here. Recently I've been busy with college so haven't had time to fix my keyboard.

Anyways, this keyboard worked when i made it a long time ago. the only problem was a few keys didn't register. now i have time, i decided to check my code and found problems. after cleaning the code up and trying 'make -f makefile' i get the error:

"Makefile:135: ../../tmk_core/rules.mk: No such file or directory
make: *** No rule to make target '../../tmk_core/rules.mk'. Stop."

this looks like a simple case of going into the makefile and changing the dir but i have checked it and changed it many times and it still gives the same message. I'm 100% sure this is a stupid mistake and somebody will maybe give me a hint as to why.

Also, i don't find it necessary to include my code because it is a directory problem. i will if i need to. if somebody has already had this problem solved, i appologize for wasting time.

UPDATE
i re-downloaded the tmk-keyboard file and put my gh60 folder into it. it now says all of my keys are undeclared.

Thanks

User avatar
Cortes

21 Jan 2017, 23:21

Hi people!, I came here asking for some help, because I'm totally lost with my personalized keyboard based on teensy 2.0.

First of all, I do not speak English, and I'm translating all this into Uncle google


The question is that this is my second keyboard based on Teensy 2.0, and the functional part of keyboard works correctly, but the question is that this second keyboard sends it backlight and I'm very lost with it.


My idea is to have 2 independent leds, backlight and leds case, and I would use pins B6 and B7

I have these parts of code backlight.c that gave me the user breh:

Code: Select all

    /*
    Copyright 2013 Mathias Andersson <wraul@dbox.se>

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
    */

    #include "backlight.h"
    #include "eeconfig.h"
    #include "debug.h"

    backlight_config_t backlight_config;

    void backlight_init(void)
    {
        //check signature
        if (!eeconfig_is_enabled()) {
            eeconfig_init();
        }
        backlight_config.raw = eeconfig_read_backlight();
        backlight_set(backlight_config.enable ? backlight_config.level : 0);
    }

    void backlight_increase(void)
    {
        if(backlight_config.level < BACKLIGHT_LEVELS)
        {
            backlight_config.level++;
            backlight_config.enable = 1;
            eeconfig_write_backlight(backlight_config.raw);
        }
        dprintf("backlight increase: %u\n", backlight_config.level);
        backlight_set(backlight_config.level);
    }

    void backlight_decrease(void)
    {
        if(backlight_config.level > 0)
        {
            backlight_config.level--;
            backlight_config.enable = !!backlight_config.level;
            eeconfig_write_backlight(backlight_config.raw);
        }
        dprintf("backlight decrease: %u\n", backlight_config.level);
        backlight_set(backlight_config.level);
    }

    void backlight_toggle(void)
    {
        backlight_config.enable ^= 1;
        eeconfig_write_backlight(backlight_config.raw);
        dprintf("backlight toggle: %u\n", backlight_config.enable);
        backlight_set(backlight_config.enable ? backlight_config.level : 0);
    }

    void backlight_step(void)
    {
        backlight_config.level++;
        if(backlight_config.level > BACKLIGHT_LEVELS)
        {
            backlight_config.level = 0;
        }
        backlight_config.enable = !!backlight_config.level;
        eeconfig_write_backlight(backlight_config.raw);
        dprintf("backlight step: %u\n", backlight_config.level);
        backlight_set(backlight_config.level);
    }

    void backlight_level(uint8_t level)
    {
        backlight_config.level ^= level;
        backlight_config.enable = !!backlight_config.level;
        eeconfig_write_backlight(backlight_config.raw);
        backlight_set(backlight_config.level);
    }

    // Plank Code for Backlight

    //#include <avr/io.h>
    //#include "backlight.h"

    #define CHANNEL OCR1B
    // Plank is OCR1C
    void backlight_init_ports()
    {

        // Setup PB7 as output and output low.
        DDRB |= (1<<6);
        PORTB &= ~(1<<6);
       
        // Use full 16-bit resolution.
        ICR1 = 0xFFFF;

        // I could write a wall of text here to explain... but TL;DW
        // Go read the ATmega32u4 datasheet.
        // And this: http://blog.saikoled.com/post/43165849837/secret-konami-cheat-code-to-high-resolution-pwm-on
       
        // Pin PB7 = OCR1C (Timer 1, Channel C)
       // Pin PB6 = OCR1B (Timer 1, Channel B)
        // Compare Output Mode = Clear on compare match, Channel C = COM1C1=1 COM1C0=0
       // Compare Output Mode = Clear on compare match, Channel C = COM1B1=1 COM1B0=0
        // (i.e. start high, go low when counter matches.)
        // WGM Mode 14 (Fast PWM) = WGM13=1 WGM12=1 WGM11=1 WGM10=0
        // Clock Select = clk/1 (no prescaling) = CS12=0 CS11=0 CS10=1
       
        TCCR1A = _BV(COM1B1) | _BV(WGM11); // = 0b00001010;
        TCCR1B = _BV(WGM13) | _BV(WGM12) | _BV(CS10); // = 0b00011001;

        backlight_init();
    }

    void backlight_set(uint8_t level)
    {
        if ( level == 0 )
        {
            // Turn off PWM control on PB6, revert to output low.
            TCCR1A &= ~(_BV(COM1B1));
            CHANNEL = 0x0;
            // Prevent backlight blink on lowest level
            PORTB &= ~(_BV(PORTB6));
        }
        else if ( level == BACKLIGHT_LEVELS )
        {
            // Prevent backlight blink on lowest level
            PORTB &= ~(_BV(PORTB6));
            // Turn on PWM control of PB6
            TCCR1A |= _BV(COM1B1);
            // Set the brightness
            CHANNEL = 0xFFFF;
        }
        else       
        {
            // Prevent backlight blink on lowest level
            PORTB &= ~(_BV(PORTB6));
            // Turn on PWM control of PB6
            TCCR1A |= _BV(COM1B1);
            // Set the brightness
            CHANNEL = 0xFFFF >> ((BACKLIGHT_LEVELS - level) * ((BACKLIGHT_LEVELS + 1) / 2));
        }
    }
I want to do something like breh does on your numeric keypad, have specific keys (the ones above the arrows) for the regular backlight, power on / off / more brightness / less brightness, and in another layer to control the LEDs of the case.

Here also the complete keyboard configuration:

Https://dl.dropboxusercontent.com/u/5052546/Shiro.rar


Two pics :D
Spoiler:
Image

Image

User avatar
Eszett

01 Mar 2017, 03:31

[obsolete..]

lunas

20 Mar 2017, 20:42

richfiles wrote: What I want to know, is where the matrix definitions need to be ordered by electrical sequence, or if the values are arbitrary, and allow for physical sequence (as long as the values are correctly defined). The obviously functional way is to lay the matrix out electrically. This seems to be what's assumed.

My question then is which (if either, or both, or neither, or 42 :mrgreen: ) would be correct?

My question is, are the values entered into the table above dependent on position in the list, or just by content. It'd be FAR easier to follow the second layout, but I don't know if it screws with the code to mix and match rows and columns like that, or whether it's all good, as long as the numbers match.

Basically, is the code expecting all the rows and columns to be in a neat and orderly incrementing layout (all the columns, in order, 0 to the maximum, for row one, then repeating for row two, and so on), or is this list arbitrarily defining the intersection values based not he numbers entered (arbitrarily defining what key labels are to be used for each matrix intersection, without regard to were in the list the sit, so long as row and column numbers match up)?
@richfiles - Did you ever get an answer to your question from several months ago? I'm digging through TMK/QMK threads here and at GH to understand how, among other things, the keymap.h file works.

gooftrupe

22 Mar 2017, 19:45

I have my code compiling and ready to load, but I'm using a Teensy 3.2. Can I not use gh60 with a Teensy 3.2? It doesn't appear to be supported, I'm in a bind though and would really like to use my 3.2. Is there a way around this?

Findecanor

22 Mar 2017, 20:15

The GH60 has a ATmega32u4 microcontroller on the board already so there is no need for an additional controller board. You could save it for another project.

lqa

12 Apr 2017, 13:59

Good job on the tutorial!
But I have a problem, when Im in the GH60 directory I can get everything to work. But I wanted a own directory so I copied the files I needed. Now when I run the make command I get:

Code: Select all

tmk_core/protocol/lufa/lufa.c:694: undefined reference to `led_set'
tmk_core/common/keyboard.c:182: undefined reference to `led_set'
I don't want any leds at all so how would I specify that?

Haase

14 Apr 2017, 22:38

Can somebody give me a brief explanation how to compile my hex file using AtmelStudio? How do i get the code inside the programm?

Catsorck45

18 Apr 2017, 05:15

Would it be possible for someone to compile this for me? I can't figure it out for the life of me.

https://drive.google.com/drive/folders/ ... sp=sharing

khanhj

23 Apr 2017, 09:54

Cortes wrote: Hi people!, I came here asking for some help, because I'm totally lost with my personalized keyboard based on teensy 2.0.

First of all, I do not speak English, and I'm translating all this into Uncle google


The question is that this is my second keyboard based on Teensy 2.0, and the functional part of keyboard works correctly, but the question is that this second keyboard sends it backlight and I'm very lost with it.


My idea is to have 2 independent leds, backlight and leds case, and I would use pins B6 and B7

I have these parts of code backlight.c that gave me the user breh:

Code: Select all

    /*
    Copyright 2013 Mathias Andersson <wraul@dbox.se>

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 2 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
    */

    #include "backlight.h"
    #include "eeconfig.h"
    #include "debug.h"

    backlight_config_t backlight_config;

    void backlight_init(void)
    {
        //check signature
        if (!eeconfig_is_enabled()) {
            eeconfig_init();
        }
        backlight_config.raw = eeconfig_read_backlight();
        backlight_set(backlight_config.enable ? backlight_config.level : 0);
    }

    void backlight_increase(void)
    {
        if(backlight_config.level < BACKLIGHT_LEVELS)
        {
            backlight_config.level++;
            backlight_config.enable = 1;
            eeconfig_write_backlight(backlight_config.raw);
        }
        dprintf("backlight increase: %u\n", backlight_config.level);
        backlight_set(backlight_config.level);
    }

    void backlight_decrease(void)
    {
        if(backlight_config.level > 0)
        {
            backlight_config.level--;
            backlight_config.enable = !!backlight_config.level;
            eeconfig_write_backlight(backlight_config.raw);
        }
        dprintf("backlight decrease: %u\n", backlight_config.level);
        backlight_set(backlight_config.level);
    }

    void backlight_toggle(void)
    {
        backlight_config.enable ^= 1;
        eeconfig_write_backlight(backlight_config.raw);
        dprintf("backlight toggle: %u\n", backlight_config.enable);
        backlight_set(backlight_config.enable ? backlight_config.level : 0);
    }

    void backlight_step(void)
    {
        backlight_config.level++;
        if(backlight_config.level > BACKLIGHT_LEVELS)
        {
            backlight_config.level = 0;
        }
        backlight_config.enable = !!backlight_config.level;
        eeconfig_write_backlight(backlight_config.raw);
        dprintf("backlight step: %u\n", backlight_config.level);
        backlight_set(backlight_config.level);
    }

    void backlight_level(uint8_t level)
    {
        backlight_config.level ^= level;
        backlight_config.enable = !!backlight_config.level;
        eeconfig_write_backlight(backlight_config.raw);
        backlight_set(backlight_config.level);
    }

    // Plank Code for Backlight

    //#include <avr/io.h>
    //#include "backlight.h"

    #define CHANNEL OCR1B
    // Plank is OCR1C
    void backlight_init_ports()
    {

        // Setup PB7 as output and output low.
        DDRB |= (1<<6);
        PORTB &= ~(1<<6);
       
        // Use full 16-bit resolution.
        ICR1 = 0xFFFF;

        // I could write a wall of text here to explain... but TL;DW
        // Go read the ATmega32u4 datasheet.
        // And this: http://blog.saikoled.com/post/43165849837/secret-konami-cheat-code-to-high-resolution-pwm-on
       
        // Pin PB7 = OCR1C (Timer 1, Channel C)
       // Pin PB6 = OCR1B (Timer 1, Channel B)
        // Compare Output Mode = Clear on compare match, Channel C = COM1C1=1 COM1C0=0
       // Compare Output Mode = Clear on compare match, Channel C = COM1B1=1 COM1B0=0
        // (i.e. start high, go low when counter matches.)
        // WGM Mode 14 (Fast PWM) = WGM13=1 WGM12=1 WGM11=1 WGM10=0
        // Clock Select = clk/1 (no prescaling) = CS12=0 CS11=0 CS10=1
       
        TCCR1A = _BV(COM1B1) | _BV(WGM11); // = 0b00001010;
        TCCR1B = _BV(WGM13) | _BV(WGM12) | _BV(CS10); // = 0b00011001;

        backlight_init();
    }

    void backlight_set(uint8_t level)
    {
        if ( level == 0 )
        {
            // Turn off PWM control on PB6, revert to output low.
            TCCR1A &= ~(_BV(COM1B1));
            CHANNEL = 0x0;
            // Prevent backlight blink on lowest level
            PORTB &= ~(_BV(PORTB6));
        }
        else if ( level == BACKLIGHT_LEVELS )
        {
            // Prevent backlight blink on lowest level
            PORTB &= ~(_BV(PORTB6));
            // Turn on PWM control of PB6
            TCCR1A |= _BV(COM1B1);
            // Set the brightness
            CHANNEL = 0xFFFF;
        }
        else       
        {
            // Prevent backlight blink on lowest level
            PORTB &= ~(_BV(PORTB6));
            // Turn on PWM control of PB6
            TCCR1A |= _BV(COM1B1);
            // Set the brightness
            CHANNEL = 0xFFFF >> ((BACKLIGHT_LEVELS - level) * ((BACKLIGHT_LEVELS + 1) / 2));
        }
    }
I want to do something like breh does on your numeric keypad, have specific keys (the ones above the arrows) for the regular backlight, power on / off / more brightness / less brightness, and in another layer to control the LEDs of the case.

Here also the complete keyboard configuration:

Https://dl.dropboxusercontent.com/u/5052546/Shiro.rar


Two pics :D
Spoiler:
Image

Image
interesting project. i'm currently researching to do something like you do. Let me know if you have solution on your code.

teyuze

27 Apr 2017, 12:25

Please I need help understanding how to define the keymap (The K00, KO1 etc part). I am trying to turn an old laptop keyboard to a USB keyboard but stuck on the part 2 of this guide.
Attachments
20170427_112049#1.jpg
20170427_112049#1.jpg (1.42 MiB) Viewed 10743 times

deirdreinamber

03 May 2017, 03:58

Hi! I just built a keyboard using matt3o's excellent guide, and have been working on the firmware for the last week or so, but I hit a snag a couple days ago. I based mine off of the teensy_lc_onekey example in tmk_keyboards, and all of the keys work except the F keys and a few of the action keys (copy, paste, undo, again). The mouse keys all work, and the layers are working correctly. When I try to use the F1-F12 keys, though, it either does nothing or outputs a number and tilde, like 0~ or 5~.

I have put most of my changes here: https://pastebin.com/GSGqK9Cy

Picture of board, put together (totally unnecessary): https://www.instagram.com/p/BTOqX7hBD89 ... s_in_socks
Please help! I really want to close up my new keyboard!!

trebb

03 May 2017, 09:42

deirdreinamber wrote: When I try to use the F1-F12 keys, though, it either does nothing or outputs a number and tilde, like 0~ or 5~.
This doesn't look wrong to me. How do other keyboards behave in this context?

deirdreinamber

03 May 2017, 23:13

F1/F2 control brightness, F7-F12 control media

User avatar
richfiles

07 May 2017, 22:17

lunas wrote:
richfiles wrote: What I want to know, is where the matrix definitions need to be ordered by electrical sequence, or if the values are arbitrary, and allow for physical sequence (as long as the values are correctly defined). The obviously functional way is to lay the matrix out electrically. This seems to be what's assumed.

My question then is which (if either, or both, or neither, or 42 :mrgreen: ) would be correct?

My question is, are the values entered into the table above dependent on position in the list, or just by content. It'd be FAR easier to follow the second layout, but I don't know if it screws with the code to mix and match rows and columns like that, or whether it's all good, as long as the numbers match.

Basically, is the code expecting all the rows and columns to be in a neat and orderly incrementing layout (all the columns, in order, 0 to the maximum, for row one, then repeating for row two, and so on), or is this list arbitrarily defining the intersection values based on the numbers entered (arbitrarily defining what key labels are to be used for each matrix intersection, without regard to were in the list they sit, so long as row and column numbers match up)?
@richfiles - Did you ever get an answer to your question from several months ago? I'm digging through TMK/QMK threads here and at GH to understand how, among other things, the keymap.h file works.
Honestly... No, I never got my question answered, and sadly, my keyboard is STILL sitting without firmware. It's a pretty paperweight at the moment. I got busy at work, and then I got really into my Kerbal Space Program instrument/control panel, then i had to deal with an injury, then a dead motherboard... And now Nearly a year has passed, and I still don't have a functioning keyboard.

On the bright side, I got my number pad plate manufactured, so I have that! Unfortunately, it still does nothing... :?

That only means i now have to consider the numberpad as well as the regular keyboard, making my firmware needs even more complex now than when I was just asking about getting the main keyboard up and running... At this point, I think I need a dedicated thread to figuring out how to make a firmware for this. Now, it not only needs to do the regular polling of the main keyboard, but it also now needs to monitor the state of a logic input to determine if the external number pad is present, and ONLY if it is, then poll a port expander over I2C (and to ignore the I2C ports if the logic signal tells the numberpad is detached.

For someone with no C experience, I really feel like I'm in way over my head with this... Hardware is what I know... :(
Keyboard76_NP_DZ_Split.jpg
Keyboard76_NP_DZ_Split.jpg (309.82 KiB) Viewed 10611 times

User avatar
j0d1

07 May 2017, 23:34

Holy cow this keyboard is gorgeous, it MUST become functional.
If you have a Teensy 3.2 (other variant may work but I'm not sure...), I can help you, if you're willing to ditch TMK/QMK and build your own firmware under Linux.

I tried TMK/QMK and I found them overly complicated for my needs.
I decided to code my own firmware _from scratch_ (well it runs on top of Teensyduino): https://github.com/jodigiordano/mode_ke ... aster/code

Its a keyboard with layers and controllable RGB LEDs so the code can become way more simpler for your needs.
If you're interested, I can strip down my code to its bare minimum so you have an easy-to-understand firmware to drive your main board. Then you can build on top of it to control the other board!

__red__

08 May 2017, 03:19

deirdreinamber wrote: F1/F2 control brightness, F7-F12 control media
So, the ~ plus characters is actually correct for function keys. That's what they've output for 30-40 years.

What you're used to is what modern manufacturers have done where they've made the default for those keys fn+Fkey which usually maps to your media / brightness. It's frequently a bios setting.

If that is what you want for your keyboard, you need to change the mapping in firmware so that instead of emitting F1-F12 it emits your specials...

deirdreinamber

08 May 2017, 04:38

Interesting. I tried the specials, and they weren't working either, but it seems like that's just an incorrect setting to track down. Thank you, that's one of those not-easy-to-google-for problems. :/

User avatar
richfiles

08 May 2017, 06:58

j0d1 wrote: Holy cow this keyboard is gorgeous, it MUST become functional.
If you have a Teensy 3.2 (other variant may work but I'm not sure...), I can help you, if you're willing to ditch TMK/QMK and build your own firmware under Linux...
Keyboard75+1WireLacingFinal.jpg
Keyboard75+1WireLacingFinal.jpg (411.7 KiB) Viewed 10650 times
I'm running a Teensy 2.0 in this thing. It's very hand wired... and laced into the keyboard.

I'm potentially open to anything, I suppose, though I'm running a Hackintosh with a rarely used Windows 10 volume as a bootable option. If I ever get another SSD, I thought I'd maybe put Ubuntu on like I had on my old PC and my PS3. My biggest problem, is my C coding skills ultimately amount to looking at existing commented code examples, and modifying them (through many mistaken iterations) to my needs... I don't actually have a grasp of much of any of the fundamentals yet. Worse, what little I did learn, pretty much faded away in the literal year that's passed since I last tried to do this.

Since I still have to hand wire my number pad yet, I figure, if I can just get the basics working for the main keyboard, I'd probably be alright. It was literally just one question that had me hung up on TMK (at least as far as I'd gotten). I would imagine finishing what I started would be the quickest path to a functioning main keyboard, and I can look at other firmware options when it comes time to integrate the numberpad functionality.

User avatar
j0d1

08 May 2017, 15:18

richfiles wrote:I'm running a Teensy 2.0 in this thing. It's very hand wired... and laced into the keyboard.
What kind of switches do you use?

I'm puzzled, there seem to be way more wires than needed, do you have the schematics for this?
richfiles wrote:Since I still have to hand wire my number pad yet, I figure, if I can just get the basics working for the main keyboard, I'd probably be alright. It was literally just one question that had me hung up on TMK (at least as far as I'd gotten). I would imagine finishing what I started would be the quickest path to a functioning main keyboard, and I can look at other firmware options when it comes time to integrate the numberpad functionality.
Yeah if you are near to make it work on TMK, maybe the best course of action is to continue on this path.

User avatar
richfiles

08 May 2017, 18:24

I use Gateron Blue, but some have green springs. The top housings have all been dyed blue, to match the anodized aluminum plate.

The reason there are more wires is I have LEDs in every switch. All LEDs are amber, controlled from a PWM pin of the Teensy 2.0. There are actually 4 banks of 22 LEDs, covering the 88 total keys. LEDs are wired in series pairs with a 100 Ohm resistor inline, and those 11 pairs are then wired in parallel and driven by a simple transistor driver. There are 4 transistor drivers, to spread out current load, so no individual driver transistor is more than approximately 50% its max current rating. Keeps the transistors unstressed. The LEDs are set to only generate a mild ambient light. They're not very bright, but that's cause I want them USB powered. I'll start the keyboard at low brightness, when powered on. With the number pad plugged in, I think I might lock out the highest brightness level.

The thicker wires are for power and LEDs. The thin blue wires are rows, columns, and data to the Magsafe port. The layout compresses 88 keys into a 13x7 matrix, to allow one LED PWM line, one Caps Lock line, two I2C wires, and a Sense wire that changes logic level when the numberpad is attached or detached.

I only mention TMK, cause I actually was through a lot of the work to make it work. I just was stumpped at the onequestion, and life happened right when I hit a wall, and it took me a year to come back to this.

I've got a crude row column schematic, and I have the row column connection guide posted. The LEDs were done in my head, so I've never drawn out a schematic for their configuration.

**EDIT** Posted this from a Chromebook on my break at work... And it double posted? Weird. Fixed.

K-rnix

11 May 2017, 01:25

Hi. I'm electronic engineer but my experience in coding is very limited (some BASIC in the past...)
My project is a Commodore 64 Keyboard, switching between "Emulator Mode" and "PC Mode", and having some RGB LED switching color according which mode is on.
For Emulator Mode, a plain matrix is needed. Emulator takes care of the rest (VICE Emulator in Positional Configuration for most "pure" emulation). For PC Mode, some remapping and macros are needed.
So my questions are:

1. Can I use a Teensy 2.0++ (90USB1286)? (I have three of those). Do I have to change anything else in makefile besides MCU = at90usb1286 ?
2. Any guide how to integrate LED control to the code?
3. I know how to use TeensyLoader for loading an .hex file to the T2.0++, but how do I compile in Windows?

PS: Actually my goal is getting a R-Pi 3 inside the C-64 case and having the closest experience possible to a real C-64.

khanhj

28 May 2017, 18:42

Rejerh wrote: For whoever is interested, after quite some difficulties and still wondering how everything works I managed to make my backlight work.

My set up is as follows:
1- All my 69 Leds with some resistors in series (be careful to take strong enough resistors so you don't try to get more than 500mA out of the USB port) are connected in parallel to the VCC and to one of the outside pins of a transistor (not the middle one).
2- The transistor has its middle pin connected to PD7 on a teensy 2.0 and its last pin connected to the GND.
The idea is to control the PWM on the PD7 to make the transistor open and close more or less to control the brightness of the Leds

I have designed schematic to control 84 led of my keyboard. As instruction of Rejerh, but it draw more than 500mA for those leds.
Rejerh, Matt3o or anyone please take a look at my attached pic and advise... thank in advance
Attachments
keyboard_84_led_schematic.png
keyboard_84_led_schematic.png (129.64 KiB) Viewed 10382 times

__red__

29 May 2017, 02:19

This isn't the way I would solve this problem. Consider using an LED driver IC, charlieplexing, or individually addressable LEDs.

khanhj

29 May 2017, 15:17

__red__ wrote: This isn't the way I would solve this problem. Consider using an LED driver IC, charlieplexing, or individually addressable LEDs.
Could you explain in more detail? I'm afraid we dont have enought controller pin for this.

User avatar
kekstee

29 May 2017, 16:47

The NerD60 uses PB6 and PB7 for pcb and in switch backlight as well. It's simple and gets you a working PWM control at least.
Don't know how involved a separate LED driver solution might become.

K-rnix

03 Jun 2017, 06:54

I'm having problems compiling in Cygwin. I get the same error than Zayter. I just try to compile the "default" files. Not touching the code yet... Any clue?
Attachments
Error CygWin.jpg
Error CygWin.jpg (470.27 KiB) Viewed 10269 times

User avatar
Mieber

08 Jun 2017, 20:16

I just created the following post to request help with my setup. One minute after I posted this I realised my mistake, as I ignored the following sentence:
Start counting from the right. The first bit is PIN0, the last is PIN7. Just set the pins you use to 1. Peachy, isn't it?
After I adjusted that my setup is working now. I decided to still post this as it maybe could help someone:

Hello, I soldered my own whitefox and trying to get it running with hasu's firmware. My first try resulted in keys not working as expected at all. So I created a very stripped down test setup that contains only two columns and two rows.

My setup:
Teensy 2.0 ++
Whitefox Plate

This is my soldered setup:
Image

As you can see my connected rows are D3 (top) and D2 (lower) and the columns are F5 (left) and F4 (right) (as seen from the front).

Attached you can find my complete setup files. The relevant parts are:

config.sh

Code: Select all

#define MATRIX_ROWS 2
#define MATRIX_COLS 2
keymap_my.c

Code: Select all

const uint8_t PROGMEM keymaps[][MATRIX_ROWS][MATRIX_COLS] = {
    /* 0: qwerty */
    KEYMAP(1,  2, \
           3,  4),
};
Makefile

Code: Select all

MCU = at90usb1286
OPT_DEFS += -DBOOTLOADER_SIZE=4096
matrix.c - Rows: D3 (top) and D2 (lower) / Columns: F5 (left) and F4 (right)

Code: Select all

static void  init_cols(void)
{
    // Input with pull-up(DDR:0, PORT:1)
    DDRF  &= ~(1<<5 | 1<<4 );
    PORTF |=  (1<<5 | 1<<4 );
}

static matrix_row_t read_cols(void)
{
    return (PINF&(1<<5) ? 0 : (1<<0)) |
           (PINF&(1<<4) ? 0 : (1<<1));
}

static void unselect_rows(void)
{
    // Hi-Z(DDR:0, PORT:0) to unselect
    // HERE I DID IT WRONG! THIS IS NOT HOW IT SHOULD BE:
    // DDRD  &= ~0b00110000;
    // PORTD &= ~0b00110000;

   // THIS IS CORRECT, COUNT FROM RIGHT :)
    DDRD  &= ~0b00001100;
    PORTD &= ~0b00001100;

}

static void select_row(uint8_t row)
{
    // Output low(DDR:1, PORT:0) to select
    switch (row) {
        case 0:
            DDRD  |= (1<<3);
            PORTD &= ~(1<<3);
            break;
        case 1:
            DDRD  |= (1<<2);
            PORTD &= ~(1<<2);
            break;
    }
}
keymap_common.h

Code: Select all

#define KEYMAP( \
    K00, K01, \
    K10, K11 \
) { \
   // ANOTHER MISTAKE I MADE. I MAPPED THE SAME KEY IN TWO ROWS (K01)
    { KC_##K00, KC_##K01 }, \
    { KC_##K10, KC_##K01 } \
}
I mapped the four keys to 1,2,3,4. But what happens is this:
  • Pressing 1 results in 13
    Pressing 2 results in 2
    Pressing 3 results in 13
    Pressing 4 results in 2
Any help much appreciated. I checked all switches with a multimeter. Checked the soldering several times. From the hardware perspective I don't see what to change. Unless I understood sth wrongly in general. As you can see from my soldering quality I'm a newb.
Attachments
tst_whitefox.zip
All test files that I used. Mind: they still contain the mistakes I made. See my text.
(76.3 KiB) Downloaded 266 times

Post Reply

Return to “Workshop”