geekhack

geekhack Projects => Making Stuff Together! => Topic started by: tokyo on Fri, 20 May 2016, 21:37:25

Title: tmk usb_usb how to #define?
Post by: tokyo on Fri, 20 May 2016, 21:37:25
I am newbie to C programming.
I read about various #defines for example:
tmk_core/doc/build.md

I am compiling under tmk_keyboard-master/converter/usb_usb/
But am not sure where to put those.
For example:
Makefile
config.h
keymap.c

I put them in keymap.c and it does not seem to work.

Code: [Select]
#include "keymap_common.h"
#include "action_layer.h"  //for layer_on functions

//disable debug since I have no idea how to debug my usb2usb
#define CONSOLE_ENABLE = no
#define COMMAND_ENABLE = no
#define NO_DEBUG
#define NO_PRINT
#define SLEEP_LED_ENABLE = yes
//maybe these need to be commented out somewhere? instead of define to no

//todo: mimic a generic one, google didn't get one
#define VENDOR_ID       0xFEED
#define PRODUCT_ID      0x005B
#define DEVICE_VER      0x0814
#define MANUFACTURER    Dell
#define PRODUCT         USB keyboard
#define DESCRIPTION     USB keyboard


#define TAPPING_TERM    300   
#define TAPPING_TOGGLE 5

#define ONESHOT_TIMEOUT 400

const uint8_t keymaps[][MATRIX_ROWS][MATRIX_COLS] PROGMEM = {
    /* 0: plain Qwerty without layer switching
Title: Re: tmk usb_usb how to #define?
Post by: suicidal_orange on Sat, 21 May 2016, 04:04:55
Makefile is used to tell the compiler how to compile the firmware so it shouldn't be mentioned in any file, while a #define is used to store a value with a meaningful name for use later - either you're very confused or I'm reading this completely wrong, both are equally likely :))

What are you trying to do and what error are you getting when you do it?
Title: Re: tmk usb_usb how to #define?
Post by: tokyo on Sun, 22 May 2016, 03:08:48
I am trying to place "#define" properly but not sure the correct way.
  for example: before the "#include"?
     in make file?
I am new to C programming and TMK.

Hope that clears up confusion.
Title: Re: tmk usb_usb how to #define?
Post by: suicidal_orange on Sun, 22 May 2016, 05:31:06
The answer to your question is #define goes in .c and .h files, not make makefiles.  You have to #define the NAME before you can refer to it to get the VALUE so they are often right at the top of the code but don't have to be.  The format is:
Code: [Select]
#define NAME VALUE
Includes are the same - you can't refer to something in the included file until after the #include line, so they too are usually at the top (but don't have to be). 

If in doubt put them all at the top, the order doesn't much matter.

Does that help?
Title: Re: tmk usb_usb how to #define?
Post by: tokyo on Mon, 23 May 2016, 16:43:37
Thanks for help!

I wonder if "#define" should be put in config.h or keymap.c 
before or after "#include"

Title: Re: tmk usb_usb how to #define?
Post by: Darkshado on Mon, 23 May 2016, 20:36:44
See where the defines are used and go from there... Instinctively I'd say pretty high in the config.h file, but I haven't looked at the TMK code yet.
Title: Re: tmk usb_usb how to #define?
Post by: tokyo on Sat, 04 June 2016, 19:33:46
about undef
#undef CONSOLE_ENABLE
#undef COMMAND_ENABLE
#undef SLEEP_LED_ENABLE

Hasu said it might work in the config.h, it does not. :D
Title: Re: tmk usb_usb how to #define?
Post by: hasu on Sat, 04 June 2016, 22:47:47
about undef
#undef CONSOLE_ENABLE
#undef COMMAND_ENABLE
#undef SLEEP_LED_ENABLE

Hasu said it might work in the config.h, it does not. :D

Because those macros are  not used in source code :p You are confused with Makefile(build script) and config.h(code).