Author Topic: tmk usb_usb how to #define?  (Read 2023 times)

0 Members and 1 Guest are viewing this topic.

Offline tokyo

  • Thread Starter
  • Posts: 17
tmk usb_usb how to #define?
« 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

Offline suicidal_orange

  • * Global Moderator
  • Posts: 4771
  • Location: England
Re: tmk usb_usb how to #define?
« Reply #1 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?
120/100g linear Zealio R1  
GMK Hyperfuse
'Split everything' perfection  
MX Clear
SA Hack'd by Geeks     
EasyAVR mod

Offline tokyo

  • Thread Starter
  • Posts: 17
Re: tmk usb_usb how to #define?
« Reply #2 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.

Offline suicidal_orange

  • * Global Moderator
  • Posts: 4771
  • Location: England
Re: tmk usb_usb how to #define?
« Reply #3 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?
120/100g linear Zealio R1  
GMK Hyperfuse
'Split everything' perfection  
MX Clear
SA Hack'd by Geeks     
EasyAVR mod

Offline tokyo

  • Thread Starter
  • Posts: 17
Re: tmk usb_usb how to #define?
« Reply #4 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"


Offline Darkshado

  • Posts: 79
  • Location: Montréal
Re: tmk usb_usb how to #define?
« Reply #5 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.

Offline tokyo

  • Thread Starter
  • Posts: 17
Re: tmk usb_usb how to #define?
« Reply #6 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

Offline hasu

  • Posts: 3472
  • Location: Tokyo, Japan
  • @tmk
    • tmk keyboard firmware project
Re: tmk usb_usb how to #define?
« Reply #7 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).