command: Add command.h file to make importing Klipper code easier

Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
Kevin O'Connor 2022-05-10 13:28:00 -04:00 committed by Eric Callahan
parent db6a9b4d96
commit 83ecbcc01d
6 changed files with 26 additions and 21 deletions

19
src/command.h Normal file
View File

@ -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

View File

@ -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

View File

@ -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;

View File

@ -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;

View File

@ -9,6 +9,7 @@
#include <string.h> // 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

View File

@ -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);