command: Always pass a string to the DECL_CONSTANT() macro
Make it clear that the name of the constant being defined is a string. When the value being defined is also a string, use a new DECL_CONSTANT_STR() macro. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
This commit is contained in:
parent
7eda55e2b0
commit
b28e95ca1a
|
@ -115,7 +115,7 @@ Declaring constants
|
||||||
Constants can also be exported. For example, the following:
|
Constants can also be exported. For example, the following:
|
||||||
|
|
||||||
```
|
```
|
||||||
DECL_CONSTANT(SERIAL_BAUD, 250000);
|
DECL_CONSTANT("SERIAL_BAUD", 250000);
|
||||||
```
|
```
|
||||||
|
|
||||||
would export a constant named "SERIAL_BAUD" with a value of 250000
|
would export a constant named "SERIAL_BAUD" with a value of 250000
|
||||||
|
|
|
@ -27,7 +27,7 @@ static const uint8_t adc_pins[] = {
|
||||||
};
|
};
|
||||||
|
|
||||||
#define ADC_FREQ_MAX 20000000
|
#define ADC_FREQ_MAX 20000000
|
||||||
DECL_CONSTANT(ADC_MAX, 4095);
|
DECL_CONSTANT("ADC_MAX", 4095);
|
||||||
|
|
||||||
struct gpio_adc
|
struct gpio_adc
|
||||||
gpio_adc_setup(uint8_t pin)
|
gpio_adc_setup(uint8_t pin)
|
||||||
|
|
|
@ -54,7 +54,7 @@ static const struct gpio_pwm_info pwm_regs[] = {
|
||||||
|
|
||||||
#define MAX_PWM 255
|
#define MAX_PWM 255
|
||||||
|
|
||||||
DECL_CONSTANT(PWM_MAX, MAX_PWM);
|
DECL_CONSTANT("PWM_MAX", MAX_PWM);
|
||||||
|
|
||||||
struct gpio_pwm
|
struct gpio_pwm
|
||||||
gpio_pwm_setup(uint8_t pin, uint32_t cycle_time, uint8_t val)
|
gpio_pwm_setup(uint8_t pin, uint32_t cycle_time, uint8_t val)
|
||||||
|
|
|
@ -10,7 +10,7 @@
|
||||||
#include "internal.h" // WDT
|
#include "internal.h" // WDT
|
||||||
#include "sched.h" // sched_main
|
#include "sched.h" // sched_main
|
||||||
|
|
||||||
DECL_CONSTANT(MCU, CONFIG_MCU);
|
DECL_CONSTANT_STR("MCU", CONFIG_MCU);
|
||||||
|
|
||||||
|
|
||||||
/****************************************************************
|
/****************************************************************
|
||||||
|
|
|
@ -51,7 +51,7 @@ gpio_adc_to_afec_chan(struct gpio_adc g)
|
||||||
}
|
}
|
||||||
|
|
||||||
#define ADC_FREQ_MAX 6000000UL
|
#define ADC_FREQ_MAX 6000000UL
|
||||||
DECL_CONSTANT(ADC_MAX, 4095);
|
DECL_CONSTANT("ADC_MAX", 4095);
|
||||||
|
|
||||||
static int
|
static int
|
||||||
init_afec(Afec* afec) {
|
init_afec(Afec* afec) {
|
||||||
|
|
|
@ -37,7 +37,7 @@ static const uint8_t adc_pins[] = {
|
||||||
};
|
};
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
DECL_CONSTANT(ADC_MAX, 4095);
|
DECL_CONSTANT("ADC_MAX", 4095);
|
||||||
|
|
||||||
static struct gpio_adc gpio_adc_pin_to_struct(uint8_t pin)
|
static struct gpio_adc gpio_adc_pin_to_struct(uint8_t pin)
|
||||||
{
|
{
|
||||||
|
|
|
@ -41,7 +41,7 @@ static const struct gpio_pwm_info pwm_regs[] = {
|
||||||
|
|
||||||
#define MAX_PWM 255
|
#define MAX_PWM 255
|
||||||
|
|
||||||
DECL_CONSTANT(PWM_MAX, MAX_PWM);
|
DECL_CONSTANT("PWM_MAX", MAX_PWM);
|
||||||
|
|
||||||
struct gpio_pwm
|
struct gpio_pwm
|
||||||
gpio_pwm_setup(uint8_t pin, uint32_t cycle_time, uint8_t val)
|
gpio_pwm_setup(uint8_t pin, uint32_t cycle_time, uint8_t val)
|
||||||
|
|
|
@ -8,7 +8,7 @@
|
||||||
#include "internal.h" // NVIC_SystemReset
|
#include "internal.h" // NVIC_SystemReset
|
||||||
#include "sched.h" // sched_main
|
#include "sched.h" // sched_main
|
||||||
|
|
||||||
DECL_CONSTANT(MCU, CONFIG_MCU);
|
DECL_CONSTANT_STR("MCU", CONFIG_MCU);
|
||||||
|
|
||||||
// Return the start of memory available for dynamic allocations
|
// Return the start of memory available for dynamic allocations
|
||||||
void *
|
void *
|
||||||
|
|
|
@ -36,7 +36,7 @@ static const uint8_t adc_pins[] PROGMEM = {
|
||||||
enum { ADMUX_DEFAULT = 0x40 };
|
enum { ADMUX_DEFAULT = 0x40 };
|
||||||
enum { ADC_ENABLE = (1<<ADPS0)|(1<<ADPS1)|(1<<ADPS2)|(1<<ADEN)|(1<<ADIF) };
|
enum { ADC_ENABLE = (1<<ADPS0)|(1<<ADPS1)|(1<<ADPS2)|(1<<ADEN)|(1<<ADIF) };
|
||||||
|
|
||||||
DECL_CONSTANT(ADC_MAX, 1023);
|
DECL_CONSTANT("ADC_MAX", 1023);
|
||||||
|
|
||||||
struct gpio_adc
|
struct gpio_adc
|
||||||
gpio_adc_setup(uint8_t pin)
|
gpio_adc_setup(uint8_t pin)
|
||||||
|
|
|
@ -74,7 +74,7 @@ static const struct gpio_pwm_info pwm_regs[] PROGMEM = {
|
||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
DECL_CONSTANT(PWM_MAX, 255);
|
DECL_CONSTANT("PWM_MAX", 255);
|
||||||
|
|
||||||
struct gpio_pwm
|
struct gpio_pwm
|
||||||
gpio_pwm_setup(uint8_t pin, uint32_t cycle_time, uint8_t val)
|
gpio_pwm_setup(uint8_t pin, uint32_t cycle_time, uint8_t val)
|
||||||
|
|
|
@ -12,7 +12,7 @@
|
||||||
#include "irq.h" // irq_enable
|
#include "irq.h" // irq_enable
|
||||||
#include "sched.h" // sched_main
|
#include "sched.h" // sched_main
|
||||||
|
|
||||||
DECL_CONSTANT(MCU, CONFIG_MCU);
|
DECL_CONSTANT_STR("MCU", CONFIG_MCU);
|
||||||
|
|
||||||
|
|
||||||
/****************************************************************
|
/****************************************************************
|
||||||
|
|
|
@ -16,7 +16,7 @@
|
||||||
* Low level timer code
|
* Low level timer code
|
||||||
****************************************************************/
|
****************************************************************/
|
||||||
|
|
||||||
DECL_CONSTANT(CLOCK_FREQ, CONFIG_CLOCK_FREQ);
|
DECL_CONSTANT("CLOCK_FREQ", CONFIG_CLOCK_FREQ);
|
||||||
|
|
||||||
// Return the number of clock ticks for a given number of microseconds
|
// Return the number of clock ticks for a given number of microseconds
|
||||||
uint32_t
|
uint32_t
|
||||||
|
|
|
@ -258,7 +258,7 @@ command_get_uptime(uint32_t *args)
|
||||||
DECL_COMMAND_FLAGS(command_get_uptime, HF_IN_SHUTDOWN, "get_uptime");
|
DECL_COMMAND_FLAGS(command_get_uptime, HF_IN_SHUTDOWN, "get_uptime");
|
||||||
|
|
||||||
#define SUMSQ_BASE 256
|
#define SUMSQ_BASE 256
|
||||||
DECL_CONSTANT(STATS_SUMSQ_BASE, SUMSQ_BASE);
|
DECL_CONSTANT("STATS_SUMSQ_BASE", SUMSQ_BASE);
|
||||||
|
|
||||||
void
|
void
|
||||||
stats_update(uint32_t start, uint32_t cur)
|
stats_update(uint32_t start, uint32_t cur)
|
||||||
|
|
|
@ -16,8 +16,8 @@
|
||||||
#define HF_IN_SHUTDOWN 0x01 // Handler can run even when in emergency stop
|
#define HF_IN_SHUTDOWN 0x01 // Handler can run even when in emergency stop
|
||||||
|
|
||||||
// Declare a constant exported to the host
|
// Declare a constant exported to the host
|
||||||
#define DECL_CONSTANT(NAME, VALUE) \
|
#define DECL_CONSTANT(NAME, VALUE) _DECL_CONSTANT(NAME, __stringify(VALUE))
|
||||||
_DECL_CONSTANT(NAME, VALUE)
|
#define DECL_CONSTANT_STR(NAME, VALUE) _DECL_CONSTANT(NAME, VALUE)
|
||||||
|
|
||||||
// Send an output message (and declare a static message type for it)
|
// Send an output message (and declare a static message type for it)
|
||||||
#define output(FMT, args...) \
|
#define output(FMT, args...) \
|
||||||
|
@ -89,7 +89,7 @@ uint8_t ctr_lookup_static_string(const char *str);
|
||||||
DECL_CTR("_DECL_COMMAND " __stringify(FUNC) " " __stringify(FLAGS) " " MSG)
|
DECL_CTR("_DECL_COMMAND " __stringify(FUNC) " " __stringify(FLAGS) " " MSG)
|
||||||
|
|
||||||
#define _DECL_CONSTANT(NAME, VALUE) \
|
#define _DECL_CONSTANT(NAME, VALUE) \
|
||||||
DECL_CTR("_DECL_CONSTANT " __stringify(NAME) " " __stringify(VALUE))
|
DECL_CTR("_DECL_CONSTANT " NAME " " VALUE)
|
||||||
|
|
||||||
#define _DECL_ENCODER(FMT) ({ \
|
#define _DECL_ENCODER(FMT) ({ \
|
||||||
DECL_CTR("_DECL_ENCODER " FMT); \
|
DECL_CTR("_DECL_ENCODER " FMT); \
|
||||||
|
|
|
@ -11,7 +11,7 @@
|
||||||
#include "command.h" // shutdown
|
#include "command.h" // shutdown
|
||||||
#include "sched.h" // sched_timer_dispatch
|
#include "sched.h" // sched_timer_dispatch
|
||||||
|
|
||||||
DECL_CONSTANT(CLOCK_FREQ, CONFIG_CLOCK_FREQ);
|
DECL_CONSTANT("CLOCK_FREQ", CONFIG_CLOCK_FREQ);
|
||||||
|
|
||||||
// Return the number of clock ticks for a given number of microseconds
|
// Return the number of clock ticks for a given number of microseconds
|
||||||
uint32_t
|
uint32_t
|
||||||
|
|
|
@ -19,8 +19,8 @@
|
||||||
static uint8_t receive_buf[RX_BUFFER_SIZE], receive_pos;
|
static uint8_t receive_buf[RX_BUFFER_SIZE], receive_pos;
|
||||||
static uint8_t transmit_buf[96], transmit_pos, transmit_max;
|
static uint8_t transmit_buf[96], transmit_pos, transmit_max;
|
||||||
|
|
||||||
DECL_CONSTANT(SERIAL_BAUD, CONFIG_SERIAL_BAUD);
|
DECL_CONSTANT("SERIAL_BAUD", CONFIG_SERIAL_BAUD);
|
||||||
DECL_CONSTANT(RECEIVE_WINDOW, RX_BUFFER_SIZE);
|
DECL_CONSTANT("RECEIVE_WINDOW", RX_BUFFER_SIZE);
|
||||||
|
|
||||||
// Rx interrupt - store read data
|
// Rx interrupt - store read data
|
||||||
void
|
void
|
||||||
|
|
|
@ -11,7 +11,7 @@
|
||||||
#include "command.h" // shutdown
|
#include "command.h" // shutdown
|
||||||
#include "sched.h" // sched_timer_dispatch
|
#include "sched.h" // sched_timer_dispatch
|
||||||
|
|
||||||
DECL_CONSTANT(CLOCK_FREQ, CONFIG_CLOCK_FREQ);
|
DECL_CONSTANT("CLOCK_FREQ", CONFIG_CLOCK_FREQ);
|
||||||
|
|
||||||
// Return the number of clock ticks for a given number of microseconds
|
// Return the number of clock ticks for a given number of microseconds
|
||||||
uint32_t
|
uint32_t
|
||||||
|
|
|
@ -107,7 +107,7 @@ DECL_COMMAND(command_set_digital_out, "set_digital_out pin=%u value=%c");
|
||||||
****************************************************************/
|
****************************************************************/
|
||||||
|
|
||||||
#define MAX_SOFT_PWM 256
|
#define MAX_SOFT_PWM 256
|
||||||
DECL_CONSTANT(SOFT_PWM_MAX, MAX_SOFT_PWM);
|
DECL_CONSTANT("SOFT_PWM_MAX", MAX_SOFT_PWM);
|
||||||
|
|
||||||
struct soft_pwm_s {
|
struct soft_pwm_s {
|
||||||
struct timer timer;
|
struct timer timer;
|
||||||
|
|
|
@ -13,7 +13,7 @@
|
||||||
#include "internal.h" // report_errno
|
#include "internal.h" // report_errno
|
||||||
#include "sched.h" // sched_shutdown
|
#include "sched.h" // sched_shutdown
|
||||||
|
|
||||||
DECL_CONSTANT(ADC_MAX, 4095); // Assume 12bit adc
|
DECL_CONSTANT("ADC_MAX", 4095); // Assume 12bit adc
|
||||||
|
|
||||||
#define IIO_PATH "/sys/bus/iio/devices/iio:device0/in_voltage%d_raw"
|
#define IIO_PATH "/sys/bus/iio/devices/iio:device0/in_voltage%d_raw"
|
||||||
|
|
||||||
|
|
|
@ -13,7 +13,7 @@
|
||||||
#include "internal.h" // console_setup
|
#include "internal.h" // console_setup
|
||||||
#include "sched.h" // sched_main
|
#include "sched.h" // sched_main
|
||||||
|
|
||||||
DECL_CONSTANT(MCU, "linux");
|
DECL_CONSTANT_STR("MCU", "linux");
|
||||||
|
|
||||||
|
|
||||||
/****************************************************************
|
/****************************************************************
|
||||||
|
|
|
@ -136,7 +136,7 @@ struct i2cpwm_s {
|
||||||
uint32_t max_duration;
|
uint32_t max_duration;
|
||||||
};
|
};
|
||||||
|
|
||||||
DECL_CONSTANT(PCA9685_MAX, VALUE_MAX);
|
DECL_CONSTANT("PCA9685_MAX", VALUE_MAX);
|
||||||
|
|
||||||
static uint_fast8_t
|
static uint_fast8_t
|
||||||
pca9685_end_event(struct timer *timer)
|
pca9685_end_event(struct timer *timer)
|
||||||
|
|
|
@ -106,7 +106,7 @@ timer_check_periodic(struct timespec *ts)
|
||||||
* Timers
|
* Timers
|
||||||
****************************************************************/
|
****************************************************************/
|
||||||
|
|
||||||
DECL_CONSTANT(CLOCK_FREQ, CONFIG_CLOCK_FREQ);
|
DECL_CONSTANT("CLOCK_FREQ", CONFIG_CLOCK_FREQ);
|
||||||
|
|
||||||
// Return the number of clock ticks for a given number of microseconds
|
// Return the number of clock ticks for a given number of microseconds
|
||||||
uint32_t
|
uint32_t
|
||||||
|
|
|
@ -23,7 +23,7 @@ static const uint8_t adc_pin_funcs[] = {
|
||||||
};
|
};
|
||||||
|
|
||||||
#define ADC_FREQ_MAX 13000000
|
#define ADC_FREQ_MAX 13000000
|
||||||
DECL_CONSTANT(ADC_MAX, 4095);
|
DECL_CONSTANT("ADC_MAX", 4095);
|
||||||
|
|
||||||
// The lpc176x adc is extremely noisy. Implement a 5 entry median
|
// The lpc176x adc is extremely noisy. Implement a 5 entry median
|
||||||
// filter to weed out obviously incorrect readings.
|
// filter to weed out obviously incorrect readings.
|
||||||
|
|
|
@ -8,7 +8,7 @@
|
||||||
#include "command.h" // DECL_CONSTANT
|
#include "command.h" // DECL_CONSTANT
|
||||||
#include "sched.h" // sched_main
|
#include "sched.h" // sched_main
|
||||||
|
|
||||||
DECL_CONSTANT(MCU, "lpc176x");
|
DECL_CONSTANT_STR("MCU", "lpc176x");
|
||||||
|
|
||||||
|
|
||||||
/****************************************************************
|
/****************************************************************
|
||||||
|
|
|
@ -16,7 +16,7 @@
|
||||||
* Analog to Digital Converter (ADC) pins
|
* Analog to Digital Converter (ADC) pins
|
||||||
****************************************************************/
|
****************************************************************/
|
||||||
|
|
||||||
DECL_CONSTANT(ADC_MAX, 4095);
|
DECL_CONSTANT("ADC_MAX", 4095);
|
||||||
|
|
||||||
static void
|
static void
|
||||||
adc_full_reset(void)
|
adc_full_reset(void)
|
||||||
|
|
|
@ -17,7 +17,7 @@
|
||||||
#include "internal.h" // SHARED_MEM
|
#include "internal.h" // SHARED_MEM
|
||||||
#include "sched.h" // sched_main
|
#include "sched.h" // sched_main
|
||||||
|
|
||||||
DECL_CONSTANT(MCU, "pru");
|
DECL_CONSTANT_STR("MCU", "pru");
|
||||||
|
|
||||||
|
|
||||||
/****************************************************************
|
/****************************************************************
|
||||||
|
|
|
@ -13,7 +13,7 @@
|
||||||
#include "sched.h" // struct timer
|
#include "sched.h" // struct timer
|
||||||
#include "stepper.h" // command_config_stepper
|
#include "stepper.h" // command_config_stepper
|
||||||
|
|
||||||
DECL_CONSTANT(STEP_DELAY, CONFIG_STEP_DELAY);
|
DECL_CONSTANT("STEP_DELAY", CONFIG_STEP_DELAY);
|
||||||
|
|
||||||
|
|
||||||
/****************************************************************
|
/****************************************************************
|
||||||
|
|
|
@ -14,7 +14,7 @@
|
||||||
#include "stm32f1xx_ll_gpio.h" // LL_GPIO_SetPinMode
|
#include "stm32f1xx_ll_gpio.h" // LL_GPIO_SetPinMode
|
||||||
#include "sched.h" // sched_shutdown
|
#include "sched.h" // sched_shutdown
|
||||||
|
|
||||||
DECL_CONSTANT(ADC_MAX, 4095);
|
DECL_CONSTANT("ADC_MAX", 4095);
|
||||||
|
|
||||||
#define ADC_DELAY (240 * 8)
|
#define ADC_DELAY (240 * 8)
|
||||||
|
|
||||||
|
|
|
@ -19,7 +19,7 @@
|
||||||
#include "stm32f1xx_ll_spi.h"
|
#include "stm32f1xx_ll_spi.h"
|
||||||
#include "sched.h" // sched_main
|
#include "sched.h" // sched_main
|
||||||
|
|
||||||
DECL_CONSTANT(MCU, "stm32f103");
|
DECL_CONSTANT_STR("MCU", "stm32f103");
|
||||||
|
|
||||||
|
|
||||||
/****************************************************************
|
/****************************************************************
|
||||||
|
|
Loading…
Reference in New Issue