aboutsummaryrefslogtreecommitdiffstats
path: root/src/gpiocmds.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/gpiocmds.c')
-rw-r--r--src/gpiocmds.c11
1 files changed, 5 insertions, 6 deletions
diff --git a/src/gpiocmds.c b/src/gpiocmds.c
index 9262f6d6..a0e476b9 100644
--- a/src/gpiocmds.c
+++ b/src/gpiocmds.c
@@ -90,14 +90,14 @@ DECL_COMMAND(command_set_digital_out, "set_digital_out pin=%u value=%c");
* Soft PWM output pins
****************************************************************/
-#define MAX_SOFT_PWM 255
+#define MAX_SOFT_PWM 256
DECL_CONSTANT(SOFT_PWM_MAX, MAX_SOFT_PWM);
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, pulse_time;
+ uint32_t max_duration, cycle_time;
struct gpio_out pin;
uint8_t default_value, flags;
};
@@ -162,7 +162,6 @@ 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 / MAX_SOFT_PWM;
s->default_value = !!args[3];
s->max_duration = args[4];
s->flags = s->default_value ? SPF_ON : 0;
@@ -177,16 +176,16 @@ 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];
- uint8_t value = args[2];
+ uint16_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 == MAX_SOFT_PWM) {
+ 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)
next_flags |= SPF_NEXT_CHECK_END;
} else {
- next_on_duration = s->pulse_time * value;
+ next_on_duration = (s->cycle_time / MAX_SOFT_PWM) * value;
next_off_duration = s->cycle_time - next_on_duration;
next_flags |= SPF_NEXT_ON | SPF_NEXT_TOGGLING;
if (s->max_duration)