Commit | Line | Data |
---|---|---|
3c132bd0 AW |
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> | |
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 | ||
17 | Adc::Adc(){ | |
18 | this->adc = new ADC(1000, 1); | |
19 | } | |
20 | ||
21 | void 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 | ||
28 | unsigned int Adc::read(Pin* pin){ | |
29 | return this->adc->read(this->_pin_to_pinname(pin)); | |
30 | } | |
31 | ||
32 | PinName Adc::_pin_to_pinname(Pin* pin){ | |
33 | if( pin->port == LPC_GPIO0 && pin->pin == 23 ){ | |
34 | return p15; | |
35 | }else if( pin->port == LPC_GPIO0 && pin->pin == 24 ){ | |
36 | return p16; | |
37 | }else if( pin->port == LPC_GPIO0 && pin->pin == 25 ){ | |
38 | return p17; | |
39 | }else if( pin->port == LPC_GPIO0 && pin->pin == 26 ){ | |
40 | return p18; | |
41 | }else if( pin->port == LPC_GPIO1 && pin->pin == 30 ){ | |
42 | return p19; | |
43 | }else if( pin->port == LPC_GPIO1 && pin->pin == 31 ){ | |
44 | return p20; | |
45 | }else{ | |
46 | //TODO: Error | |
47 | } | |
48 | } | |
49 |