generate cleaner make output, allow warnings to be easier to spot
[clinton/Smoothieware.git] / src / libs / Adc.cpp
CommitLineData
7b49793d 1/*
3c132bd0
AW
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.
7b49793d 5 You should have received a copy of the GNU General Public License along with Smoothie. If not, see <http://www.gnu.org/licenses/>.
3c132bd0
AW
6*/
7
8using namespace std;
9#include <vector>
3c132bd0
AW
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
17Adc::Adc(){
18 this->adc = new ADC(1000, 1);
19}
20
21void Adc::enable_pin(Pin* pin){
22 PinName pin_name = this->_pin_to_pinname(pin);
23 this->adc->burst(1);
24 this->adc->setup(pin_name,1);
25 this->adc->interrupt_state(pin_name,1);
26}
27
28unsigned int Adc::read(Pin* pin){
29 return this->adc->read(this->_pin_to_pinname(pin));
30}
31
32PinName Adc::_pin_to_pinname(Pin* pin){
7b49793d 33 if( pin->port == LPC_GPIO0 && pin->pin == 23 ){
3c132bd0 34 return p15;
7b49793d 35 }else if( pin->port == LPC_GPIO0 && pin->pin == 24 ){
3c132bd0 36 return p16;
7b49793d 37 }else if( pin->port == LPC_GPIO0 && pin->pin == 25 ){
3c132bd0 38 return p17;
7b49793d 39 }else if( pin->port == LPC_GPIO0 && pin->pin == 26 ){
3c132bd0 40 return p18;
7b49793d 41 }else if( pin->port == LPC_GPIO1 && pin->pin == 30 ){
3c132bd0 42 return p19;
7b49793d 43 }else if( pin->port == LPC_GPIO1 && pin->pin == 31 ){
3c132bd0
AW
44 return p20;
45 }else{
7b49793d 46 //TODO: Error
3c132bd0
AW
47 }
48}
49