diff options
author | Guy Shapira <gayuha@gmail.com> | 2020-09-07 13:31:35 +0300 |
---|---|---|
committer | Kevin O'Connor <kevin@koconnor.net> | 2020-09-26 20:51:38 -0400 |
commit | 27cefb2b388b668a3747451ab28b9b2a544bb242 (patch) | |
tree | df5c639f03452477381d9d7d564a97b73a968c76 /src/gpiocmds.c | |
parent | a79c57ab298eca18ef9b0d363e782c708968ffcb (diff) | |
download | kutter-27cefb2b388b668a3747451ab28b9b2a544bb242.tar.gz kutter-27cefb2b388b668a3747451ab28b9b2a544bb242.tar.xz kutter-27cefb2b388b668a3747451ab28b9b2a544bb242.zip |
gpiocmds: Add soft-pwm frequency modulation support
Signed-off-by: Guy Shapira <gayuha@gmail.com>
Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Diffstat (limited to 'src/gpiocmds.c')
-rw-r--r-- | src/gpiocmds.c | 19 |
1 files changed, 9 insertions, 10 deletions
diff --git a/src/gpiocmds.c b/src/gpiocmds.c index 91d97b75..e6bf4671 100644 --- a/src/gpiocmds.c +++ b/src/gpiocmds.c @@ -110,7 +110,7 @@ struct soft_pwm_s { struct timer timer; uint32_t on_duration, off_duration, end_time; uint32_t next_on_duration, next_off_duration; - uint32_t max_duration, cycle_time; + uint32_t max_duration; struct gpio_out pin; uint8_t default_value, flags; }; @@ -172,32 +172,31 @@ soft_pwm_load_event(struct timer *timer) void command_config_soft_pwm_out(uint32_t *args) { - struct gpio_out pin = gpio_out_setup(args[1], !!args[3]); + struct gpio_out pin = gpio_out_setup(args[1], !!args[2]); struct soft_pwm_s *s = oid_alloc(args[0], command_config_soft_pwm_out , sizeof(*s)); s->pin = pin; - s->cycle_time = args[2]; - s->default_value = !!args[4]; - s->max_duration = args[5]; + s->default_value = !!args[3]; + s->max_duration = args[4]; s->flags = s->default_value ? SPF_ON : 0; } DECL_COMMAND(command_config_soft_pwm_out, - "config_soft_pwm_out oid=%c pin=%u cycle_ticks=%u value=%c" + "config_soft_pwm_out oid=%c pin=%u value=%c" " default_value=%c max_duration=%u"); void command_schedule_soft_pwm_out(uint32_t *args) { struct soft_pwm_s *s = oid_lookup(args[0], command_config_soft_pwm_out); - uint32_t time = args[1], next_on_duration = args[2], next_off_duration; + uint32_t time = args[1], next_on_duration = args[2], + next_off_duration = args[3]; uint8_t next_flags = SPF_CHECK_END | SPF_HAVE_NEXT; - if (next_on_duration == 0 || next_on_duration >= s->cycle_time) { + if (next_on_duration == 0 || next_off_duration == 0) { next_flags |= next_on_duration ? SPF_NEXT_ON : 0; if (!!next_on_duration != s->default_value && s->max_duration) next_flags |= SPF_NEXT_CHECK_END; next_on_duration = next_off_duration = 0; } else { - next_off_duration = s->cycle_time - next_on_duration; next_flags |= SPF_NEXT_ON | SPF_NEXT_TOGGLING; if (s->max_duration) next_flags |= SPF_NEXT_CHECK_END; @@ -221,7 +220,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 on_ticks=%u"); + "schedule_soft_pwm_out oid=%c clock=%u on_ticks=%u off_ticks=%u"); void soft_pwm_shutdown(void) |