Skip to content

Commit d84f011

Browse files
committed
adc CLI command
(cherry picked from commit a8821b8)
1 parent a93cde1 commit d84f011

3 files changed

Lines changed: 82 additions & 1 deletion

File tree

Makefile

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ OBJS += cmd_chibi_addr.o cmd_chibi_tx.o
4141
OBJS += cmd_i2ceeprom_read.o cmd_i2ceeprom_write.o cmd_lm75b_gettemp.o
4242
OBJS += cmd_reset.o cmd_sd_dir.o cmd_sysinfo.o cmd_uart.o
4343
OBJS += cmd_roundedcorner.o cmd_pwm.o
44+
OBJS += cmd_adc.o
4445

4546
VPATH += project/commands/drawing
4647
OBJS += cmd_backlight.o cmd_bmp.o cmd_button.o cmd_calibrate.o

project/cmd_tbl.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,8 @@ void cmd_sd_dir(uint8_t argc, char **argv);
9797
void cmd_pwm(uint8_t argc, char **argv);
9898
#endif
9999

100+
void cmd_adc_read(uint8_t argc, char **argv);
101+
100102
#define CMD_NOPARAMS "This command has no parameters"
101103

102104
/**************************************************************************/
@@ -114,7 +116,7 @@ cmd_t cmd_tbl[] =
114116
{ "?", 0, 0, 0, cmd_help , "Help" , CMD_NOPARAMS },
115117
{ "V", 0, 0, 0, cmd_sysinfo , "System Info" , CMD_NOPARAMS },
116118
{ "Z", 0, 0, 0, cmd_reset , "Reset" , CMD_NOPARAMS },
117-
119+
{ "adc", 1, 2, 0, cmd_adc_read , "ADC read" , "adc <channel> <num reads>" },
118120
#ifdef CFG_I2CEEPROM
119121
{ "e", 1, 1, 0, cmd_i2ceeprom_read , "EEPROM Read" , "'e <addr>'" },
120122
{ "w", 2, 2, 0, cmd_i2ceeprom_write , "EEPROM Write" , "'w <addr> <val>'" },

project/commands/cmd_adc.c

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
/**************************************************************************/
2+
/*!
3+
@file cmd_sysinfo.c
4+
@author Miceuz
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) 2012, 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 "project/commands.h" // Generic helper functions
44+
45+
#include "core/adc/adc.h"
46+
47+
/**************************************************************************/
48+
/*!
49+
PWM command handler
50+
*/
51+
/**************************************************************************/
52+
53+
void cmd_adc_read(uint8_t argc, char **argv) {
54+
int32_t channel = 0;
55+
int32_t numReads = 1;
56+
57+
getNumber (argv[0], &channel);
58+
if(channel < 0)
59+
{
60+
printf("Invalid duty channel, only channels [0..2] avalable%s", CFG_PRINTF_NEWLINE);
61+
return;
62+
}
63+
64+
if(argc > 1) {
65+
getNumber (argv[1], &numReads);
66+
if(numReads < 1)
67+
{
68+
printf("Invalid number of reads [1..65535]%s", CFG_PRINTF_NEWLINE);
69+
return;
70+
}
71+
}
72+
adcInit();
73+
int i = 0;
74+
for(i = 0; i < numReads; i++) {
75+
uint32_t result = adcReadSingle(channel);
76+
printf("%d%s", (uint16_t)result, CFG_PRINTF_NEWLINE);
77+
}
78+
}

0 commit comments

Comments
 (0)