diff options
author | Kevin O'Connor <kevin@koconnor.net> | 2017-05-07 17:33:45 -0400 |
---|---|---|
committer | Kevin O'Connor <kevin@koconnor.net> | 2017-05-15 14:02:59 -0400 |
commit | 5c4cc0d64637363aaeb46e2b65bb1b1f99e9e434 (patch) | |
tree | 3e05557f40fd73c2d8bebed6afbf7719c701a952 /src | |
parent | a361b921849b4e23f7a41feb2a7c011ee6d794b1 (diff) | |
download | kutter-5c4cc0d64637363aaeb46e2b65bb1b1f99e9e434.tar.gz kutter-5c4cc0d64637363aaeb46e2b65bb1b1f99e9e434.tar.xz kutter-5c4cc0d64637363aaeb46e2b65bb1b1f99e9e434.zip |
pwmcmds: Export the maximum PWM value
Instead of assuming the maximum PWM value is 255, export a constant
from the firmware to the host with the maximum value.
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Diffstat (limited to 'src')
-rw-r--r-- | src/avr/gpio.c | 2 | ||||
-rw-r--r-- | src/gpiocmds.c | 9 | ||||
-rw-r--r-- | src/pwmcmds.c | 6 |
3 files changed, 11 insertions, 6 deletions
diff --git a/src/avr/gpio.c b/src/avr/gpio.c index aa39f957..9d7e5148 100644 --- a/src/avr/gpio.c +++ b/src/avr/gpio.c @@ -162,6 +162,8 @@ static const uint8_t pwm_pins[ARRAY_SIZE(pwm_regs)] PROGMEM = { #endif }; +DECL_CONSTANT(PWM_MAX, 255); + struct gpio_pwm gpio_pwm_setup(uint8_t pin, uint32_t cycle_time, uint8_t val) { diff --git a/src/gpiocmds.c b/src/gpiocmds.c index 6dd29059..9262f6d6 100644 --- a/src/gpiocmds.c +++ b/src/gpiocmds.c @@ -90,6 +90,9 @@ DECL_COMMAND(command_set_digital_out, "set_digital_out pin=%u value=%c"); * Soft PWM output pins ****************************************************************/ +#define MAX_SOFT_PWM 255 +DECL_CONSTANT(SOFT_PWM_MAX, MAX_SOFT_PWM); + struct soft_pwm_s { struct timer timer; uint32_t on_duration, off_duration, end_time; @@ -159,7 +162,7 @@ command_config_soft_pwm_out(uint32_t *args) struct soft_pwm_s *s = oid_alloc(args[0], command_config_soft_pwm_out , sizeof(*s)); s->cycle_time = args[2]; - s->pulse_time = s->cycle_time / 255; + s->pulse_time = s->cycle_time / MAX_SOFT_PWM; s->default_value = !!args[3]; s->max_duration = args[4]; s->flags = s->default_value ? SPF_ON : 0; @@ -177,7 +180,7 @@ command_schedule_soft_pwm_out(uint32_t *args) uint8_t value = args[2]; uint8_t next_flags = SPF_CHECK_END | SPF_HAVE_NEXT; uint32_t next_on_duration, next_off_duration; - if (value == 0 || value == 255) { + if (value == 0 || value == MAX_SOFT_PWM) { next_on_duration = next_off_duration = 0; next_flags |= value ? SPF_NEXT_ON : 0; if (!!value != s->default_value && s->max_duration) @@ -208,7 +211,7 @@ command_schedule_soft_pwm_out(uint32_t *args) irq_enable(); } DECL_COMMAND(command_schedule_soft_pwm_out, - "schedule_soft_pwm_out oid=%c clock=%u value=%c"); + "schedule_soft_pwm_out oid=%c clock=%u value=%hu"); static void soft_pwm_shutdown(void) diff --git a/src/pwmcmds.c b/src/pwmcmds.c index e8de0a3b..f5a289d2 100644 --- a/src/pwmcmds.c +++ b/src/pwmcmds.c @@ -43,7 +43,7 @@ command_config_pwm_out(uint32_t *args) p->max_duration = args[4]; } DECL_COMMAND(command_config_pwm_out, - "config_pwm_out oid=%c pin=%u cycle_ticks=%u default_value=%c" + "config_pwm_out oid=%c pin=%u cycle_ticks=%u default_value=%hu" " max_duration=%u"); void @@ -57,7 +57,7 @@ command_schedule_pwm_out(uint32_t *args) sched_add_timer(&p->timer); } DECL_COMMAND(command_schedule_pwm_out, - "schedule_pwm_out oid=%c clock=%u value=%c"); + "schedule_pwm_out oid=%c clock=%u value=%hu"); static void pwm_shutdown(void) @@ -75,4 +75,4 @@ command_set_pwm_out(uint32_t *args) { gpio_pwm_setup(args[0], args[1], args[2]); } -DECL_COMMAND(command_set_pwm_out, "set_pwm_out pin=%u cycle_ticks=%u value=%c"); +DECL_COMMAND(command_set_pwm_out, "set_pwm_out pin=%u cycle_ticks=%u value=%hu"); |