Skip to content

Commit aff4241

Browse files
committed
[PWM] add proper op-code verification and error checking.
1 parent 439d768 commit aff4241

File tree

1 file changed

+11
-4
lines changed

1 file changed

+11
-4
lines changed

src/pwm_handler.c

+11-4
Original file line numberDiff line numberDiff line change
@@ -32,19 +32,26 @@
3232

3333
int pwm_handler(uint8_t opcode, uint8_t *data, uint16_t size)
3434
{
35-
if (opcode & CAPTURE) {
35+
if (opcode == CAPTURE)
36+
{
3637
uint8_t const channel = opcode & 0x0F;
3738
if (isValidPwmChannelNumber(channel))
3839
capturePwm(channel);
3940
else
40-
dbg_printf("Invalid PWM channel number provided for mode CAPTURE: %d\n", channel);
41-
} else {
41+
dbg_printf("pwm_handler: invalid PWM channel number provided for mode CAPTURE: %d\n", channel);
42+
}
43+
else if (opcode == CONFIGURE)
44+
{
4245
uint8_t const channel = opcode;
4346
struct pwmPacket config = *((struct pwmPacket*)data);
4447
if (isValidPwmChannelNumber(channel))
4548
configurePwm(channel, config.enable, config.polarity, config.duty, config.period);
4649
else
47-
dbg_printf("Invalid PWM channel number provided for mode PWM: %d\n", channel);
50+
dbg_printf("pwm_handler: invalid PWM channel number provided for mode PWM: %d\n", channel);
51+
}
52+
else
53+
{
54+
dbg_printf("pwm_handler: error invalid opcode (:%d)\n", opcode);
4855
}
4956
return 0;
5057
}

0 commit comments

Comments
 (0)