aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorKevin O'Connor <kevin@koconnor.net>2017-05-07 17:48:23 -0400
committerKevin O'Connor <kevin@koconnor.net>2017-05-15 14:02:59 -0400
commitc292006421fccc001b3cb74dffa82b72c2eb46a0 (patch)
treee90c7ea4ed29ec212e89184d6982337fa0e7a039 /src
parent5c4cc0d64637363aaeb46e2b65bb1b1f99e9e434 (diff)
downloadkutter-c292006421fccc001b3cb74dffa82b72c2eb46a0.tar.gz
kutter-c292006421fccc001b3cb74dffa82b72c2eb46a0.tar.xz
kutter-c292006421fccc001b3cb74dffa82b72c2eb46a0.zip
gpiocmds: Change MAX_SOFT_PWM from 255 to 256
Change the range of values used for software PWM to avoid doing an integer division in the main code. Signed-off-by: Kevin O'Connor <kevin@koconnor.net>
Diffstat (limited to 'src')
-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)