Merge pull request #3 from Miceuz/master
[hackover2013-badge-firmware.git] / project / commands / cmd_pwm.c
1 /**************************************************************************/
2 /*!
3 @file cmd_sysinfo.c
4 @author K. Townsend (microBuilder.eu)
5
6 @brief Code to execute for cmd_sysinfo in the 'core/cmd'
7 command-line interpretter.
8
9 @section LICENSE
10
11 Software License Agreement (BSD License)
12
13 Copyright (c) 2010, microBuilder SARL
14 All rights reserved.
15
16 Redistribution and use in source and binary forms, with or without
17 modification, are permitted provided that the following conditions are met:
18 1. Redistributions of source code must retain the above copyright
19 notice, this list of conditions and the following disclaimer.
20 2. Redistributions in binary form must reproduce the above copyright
21 notice, this list of conditions and the following disclaimer in the
22 documentation and/or other materials provided with the distribution.
23 3. Neither the name of the copyright holders nor the
24 names of its contributors may be used to endorse or promote products
25 derived from this software without specific prior written permission.
26
27 THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS ''AS IS'' AND ANY
28 EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
29 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
30 DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER BE LIABLE FOR ANY
31 DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
32 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
33 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
34 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
35 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
36 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
37 */
38 /**************************************************************************/
39 #include <stdio.h>
40
41 #include "projectconfig.h"
42 #include "core/cmd/cmd.h"
43 #include "core/systick/systick.h"
44 #include "core/iap/iap.h"
45 #include "project/commands.h" // Generic helper functions
46 #include "core/pwm/pwm.h"
47
48 #ifdef CFG_PRINTF_UART
49 #include "core/uart/uart.h"
50 #endif
51
52 /**************************************************************************/
53 /*!
54 PWM command handler
55 */
56 /**************************************************************************/
57 uint8_t pwmStarted = 0;
58
59 void cmd_pwm(uint8_t argc, char **argv) {
60 int32_t frequencyTicks = 65535;
61 int32_t dutyCycle = 25;
62
63 if(argc > 0) {
64 getNumber (argv[0], &dutyCycle);
65 if(dutyCycle < 1 || dutyCycle > 100) {
66 printf("Invalid duty cycle. Duty cycle must be [1 .. 65535]%s", CFG_PRINTF_NEWLINE);
67 return;
68 }
69
70 if(argc > 1) {
71 getNumber (argv[1], &frequencyTicks);
72 if(frequencyTicks < 0 || frequencyTicks > 0xffff) {
73 printf("Invalid frequency. Frequency must be [1 .. 65535]%s", CFG_PRINTF_NEWLINE);
74 return;
75 }
76 } else {
77 frequencyTicks = 65535;
78 }
79 } else {
80 dutyCycle = 25;
81
82 }
83
84 if(! pwmStarted) {
85 printf("Initializing PWM%s", CFG_PRINTF_NEWLINE);
86 pwmInit();
87 }
88
89 printf("Setting frequency ticks to %u%s", (uint16_t) frequencyTicks, CFG_PRINTF_NEWLINE);
90 pwmSetFrequencyInTicks(frequencyTicks);
91 printf("Setting duty cycle to %u%s", (uint16_t) dutyCycle, CFG_PRINTF_NEWLINE);
92 pwmSetDutyCycle(dutyCycle);
93 if(! pwmStarted) {
94 pwmStart();
95 pwmStarted = 1;
96 }
97 }
This page took 0.057193 seconds and 5 git commands to generate.