From 83ecbcc01da2d653da27e29600ed1c6a04fadcfd Mon Sep 17 00:00:00 2001 From: Kevin O'Connor Date: Tue, 10 May 2022 13:28:00 -0400 Subject: [PATCH] command: Add command.h file to make importing Klipper code easier Signed-off-by: Kevin O'Connor --- src/command.h | 19 +++++++++++++++++++ src/ctr.h | 20 -------------------- src/generic/armcm_boot.c | 4 ++++ src/generic/canbus.c | 1 + src/stm32/can.c | 1 + src/stm32/gpio.c | 2 +- 6 files changed, 26 insertions(+), 21 deletions(-) create mode 100644 src/command.h diff --git a/src/command.h b/src/command.h new file mode 100644 index 0000000..29fb0d5 --- /dev/null +++ b/src/command.h @@ -0,0 +1,19 @@ +#ifndef __COMMAND_H +#define __COMMAND_H + +#include "ctr.h" // DECL_CTR + +// Declare a constant exported to the host +#define DECL_CONSTANT(NAME, VALUE) \ + DECL_CTR_INT("DECL_CONSTANT " NAME, 1, CTR_INT(VALUE)) +#define DECL_CONSTANT_STR(NAME, VALUE) \ + DECL_CTR("DECL_CONSTANT_STR " NAME " " VALUE) + +// Declare an enumeration +#define DECL_ENUMERATION(ENUM, NAME, VALUE) \ + DECL_CTR_INT("DECL_ENUMERATION " ENUM " " NAME, 1, CTR_INT(VALUE)) +#define DECL_ENUMERATION_RANGE(ENUM, NAME, VALUE, COUNT) \ + DECL_CTR_INT("DECL_ENUMERATION_RANGE " ENUM " " NAME, \ + 2, CTR_INT(VALUE), CTR_INT(COUNT)) + +#endif // command.h diff --git a/src/ctr.h b/src/ctr.h index 527c8a5..4032e26 100644 --- a/src/ctr.h +++ b/src/ctr.h @@ -35,24 +35,4 @@ __section(".compile_time_request") = { \ (REQUEST), { args }, 0 } - -/******************************************************************** - * - * Useful CTR macros from Klipper's command.h - * - *******************************************************************/ - -// Declare a constant exported to the host -#define DECL_CONSTANT(NAME, VALUE) \ - DECL_CTR_INT("DECL_CONSTANT " NAME, 1, CTR_INT(VALUE)) -#define DECL_CONSTANT_STR(NAME, VALUE) \ - DECL_CTR("DECL_CONSTANT_STR " NAME " " VALUE) - -// Declare an enumeration -#define DECL_ENUMERATION(ENUM, NAME, VALUE) \ - DECL_CTR_INT("DECL_ENUMERATION " ENUM " " NAME, 1, CTR_INT(VALUE)) -#define DECL_ENUMERATION_RANGE(ENUM, NAME, VALUE, COUNT) \ - DECL_CTR_INT("DECL_ENUMERATION_RANGE " ENUM " " NAME, \ - 2, CTR_INT(VALUE), CTR_INT(COUNT)) - #endif // ctr.h diff --git a/src/generic/armcm_boot.c b/src/generic/armcm_boot.c index 4f1b8a7..a52b247 100644 --- a/src/generic/armcm_boot.c +++ b/src/generic/armcm_boot.c @@ -8,6 +8,10 @@ #include "autoconf.h" // CONFIG_MCU #include "board/internal.h" // SysTick #include "board/irq.h" // irq_disable +#include "command.h" // DECL_CONSTANT_STR + +// Export MCU type +DECL_CONSTANT_STR("MCU", CONFIG_MCU); // Symbols created by armcm_link.lds.S linker script extern uint32_t _data_start, _data_end, _data_flash; diff --git a/src/generic/canbus.c b/src/generic/canbus.c index ebe5d15..16c67ca 100644 --- a/src/generic/canbus.c +++ b/src/generic/canbus.c @@ -10,6 +10,7 @@ #include "byteorder.h" // cpu_to_le32 #include "canbus.h" // canbus_set_uuid #include "canboot_main.h" +#include "command.h" // DECL_TASK #include "sched.h" // sched_wake_task static uint32_t canbus_assigned_id; diff --git a/src/stm32/can.c b/src/stm32/can.c index 8316195..6c4915e 100644 --- a/src/stm32/can.c +++ b/src/stm32/can.c @@ -9,6 +9,7 @@ #include // memcpy #include "autoconf.h" // CONFIG_MACH_STM32F1 #include "board/irq.h" // irq_disable +#include "command.h" // DECL_CONSTANT_STR #include "fasthash.h" // fasthash64 #include "generic/armcm_boot.h" // armcm_enable_irq #include "generic/canbus.h" // canbus_notify_tx diff --git a/src/stm32/gpio.c b/src/stm32/gpio.c index 4402bc2..03c4ad1 100644 --- a/src/stm32/gpio.c +++ b/src/stm32/gpio.c @@ -9,7 +9,7 @@ #include "gpio.h" // gpio_out_setup #include "internal.h" // gpio_peripheral #include "compiler.h" // ARRAY_SIZE -#include "ctr.h" // DECL_ENUMERATION_RANGE +#include "command.h" // DECL_ENUMERATION_RANGE DECL_ENUMERATION_RANGE("pin", "PA0", GPIO('A', 0), 16); DECL_ENUMERATION_RANGE("pin", "PB0", GPIO('B', 0), 16);