enabled specifying numeric config values using all strtof capabilities
[clinton/Smoothieware.git] / src / libs / Adc.cpp
1 /*
2 This file is part of Smoothie (http://smoothieware.org/). The motion control part is heavily based on Grbl (https://github.com/simen/grbl).
3 Smoothie is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
4 Smoothie is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
5 You should have received a copy of the GNU General Public License along with Smoothie. If not, see <http://www.gnu.org/licenses/>.
6 */
7
8 using namespace std;
9 #include <vector>
10 #include "libs/nuts_bolts.h"
11 #include "libs/Module.h"
12 #include "libs/Kernel.h"
13 #include "Adc.h"
14 #include "libs/ADC/adc.h"
15 #include "libs/Pin.h"
16
17 // This is an interface to the mbed.org ADC library you can find in libs/ADC/adc.h
18 // TODO : Having the same name is confusing, should change that
19
20 Adc::Adc(){
21 this->adc = new ADC(1000, 1);
22 }
23
24 // Enables ADC on a given pin
25 void Adc::enable_pin(Pin* pin){
26 PinName pin_name = this->_pin_to_pinname(pin);
27 this->adc->burst(1);
28 this->adc->setup(pin_name,1);
29 this->adc->interrupt_state(pin_name,1);
30 }
31
32 // Read the last value ( burst mode ) on a given pin
33 unsigned int Adc::read(Pin* pin){
34 return this->adc->read(this->_pin_to_pinname(pin));
35 }
36
37 // Convert a smoothie Pin into a mBed Pin
38 PinName Adc::_pin_to_pinname(Pin* pin){
39 if( pin->port == LPC_GPIO0 && pin->pin == 23 ){
40 return p15;
41 }else if( pin->port == LPC_GPIO0 && pin->pin == 24 ){
42 return p16;
43 }else if( pin->port == LPC_GPIO0 && pin->pin == 25 ){
44 return p17;
45 }else if( pin->port == LPC_GPIO0 && pin->pin == 26 ){
46 return p18;
47 }else if( pin->port == LPC_GPIO1 && pin->pin == 30 ){
48 return p19;
49 }else if( pin->port == LPC_GPIO1 && pin->pin == 31 ){
50 return p20;
51 }else{
52 //TODO: Error
53 return NC;
54 }
55 }
56