X-Git-Url: https://git.rohieb.name/hackover2013-badge-firmware.git/blobdiff_plain/b5e1d01dc3ef67418901a4d43b5f78c879663a9d..4292be14c78b8f30075c9e4837dd026f6fec532e:/project/commands/cmd_pwm.c diff --git a/project/commands/cmd_pwm.c b/project/commands/cmd_pwm.c index 00e7de4..3d070d5 100644 --- a/project/commands/cmd_pwm.c +++ b/project/commands/cmd_pwm.c @@ -1,7 +1,7 @@ /**************************************************************************/ /*! @file cmd_sysinfo.c - @author K. Townsend (microBuilder.eu) + @author Miceuz @brief Code to execute for cmd_sysinfo in the 'core/cmd' command-line interpretter. @@ -10,7 +10,7 @@ Software License Agreement (BSD License) - Copyright (c) 2010, microBuilder SARL + Copyright (c) 2012, microBuilder SARL All rights reserved. Redistribution and use in source and binary forms, with or without @@ -40,14 +40,10 @@ #include "projectconfig.h" #include "core/cmd/cmd.h" -#include "core/systick/systick.h" -#include "core/iap/iap.h" #include "project/commands.h" // Generic helper functions -#include "core/pwm/pwm.h" -#ifdef CFG_PRINTF_UART - #include "core/uart/uart.h" -#endif +#ifdef CFG_PWM + #include "core/pwm/pwm.h" /**************************************************************************/ /*! @@ -58,40 +54,31 @@ uint8_t pwmStarted = 0; void cmd_pwm(uint8_t argc, char **argv) { int32_t frequencyTicks = 65535; - int32_t dutyCycle = 25; + int32_t dutyCycle = CFG_PWM_DEFAULT_DUTYCYCLE; - if(argc > 0) { - getNumber (argv[0], &dutyCycle); - if(dutyCycle < 1 || dutyCycle > 100) { - printf("Invalid duty cycle. Duty cycle must be [1 .. 65535]%s", CFG_PRINTF_NEWLINE); - return; - } - - if(argc > 1) { - getNumber (argv[1], &frequencyTicks); - if(frequencyTicks < 0 || frequencyTicks > 0xffff) { - printf("Invalid frequency. Frequency must be [1 .. 65535]%s", CFG_PRINTF_NEWLINE); - return; - } - } else { - frequencyTicks = 65535; - } - } else { - dutyCycle = 25; - + getNumber (argv[0], &dutyCycle); + if(dutyCycle < 1 || dutyCycle > 100) + { + printf("Invalid duty cycle [1..65535]%s", CFG_PRINTF_NEWLINE); + return; } - if(! pwmStarted) { - printf("Initializing PWM%s", CFG_PRINTF_NEWLINE); - pwmInit(); + getNumber (argv[1], &frequencyTicks); + if(frequencyTicks < 0 || frequencyTicks > 0xffff) + { + printf("Invalid frequency [1..65535]%s", CFG_PRINTF_NEWLINE); + return; } - - printf("Setting frequency ticks to %u%s", (uint16_t) frequencyTicks, CFG_PRINTF_NEWLINE); + + printf("Setting frequency: %u ticks%s", (uint16_t) frequencyTicks, CFG_PRINTF_NEWLINE); pwmSetFrequencyInTicks(frequencyTicks); - printf("Setting duty cycle to %u%s", (uint16_t) dutyCycle, CFG_PRINTF_NEWLINE); + printf("Setting duty cycle: %u%%%s", (uint16_t) dutyCycle, CFG_PRINTF_NEWLINE); pwmSetDutyCycle(dutyCycle); - if(! pwmStarted) { - pwmStart(); - pwmStarted = 1; + if(! pwmStarted) + { + printf("Initializing PWM%s", CFG_PRINTF_NEWLINE); + pwmStart(); + pwmStarted = 1; } -} \ No newline at end of file +} +#endif