Commit | Line | Data |
---|---|---|
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 | ||
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 | ||
93694d6b | 17 | // This is an interface to the mbed.org ADC library you can find in libs/ADC/adc.h |
d337942a | 18 | // TODO : Having the same name is confusing, should change that |
93694d6b | 19 | |
3c132bd0 AW |
20 | Adc::Adc(){ |
21 | this->adc = new ADC(1000, 1); | |
22 | } | |
23 | ||
93694d6b | 24 | // Enables ADC on a given pin |
3c132bd0 AW |
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 | ||
93694d6b | 32 | // Read the last value ( burst mode ) on a given pin |
3c132bd0 AW |
33 | unsigned int Adc::read(Pin* pin){ |
34 | return this->adc->read(this->_pin_to_pinname(pin)); | |
35 | } | |
36 | ||
93694d6b | 37 | // Convert a smoothie Pin into a mBed Pin |
3c132bd0 | 38 | PinName Adc::_pin_to_pinname(Pin* pin){ |
7b49793d | 39 | if( pin->port == LPC_GPIO0 && pin->pin == 23 ){ |
3c132bd0 | 40 | return p15; |
7b49793d | 41 | }else if( pin->port == LPC_GPIO0 && pin->pin == 24 ){ |
3c132bd0 | 42 | return p16; |
7b49793d | 43 | }else if( pin->port == LPC_GPIO0 && pin->pin == 25 ){ |
3c132bd0 | 44 | return p17; |
7b49793d | 45 | }else if( pin->port == LPC_GPIO0 && pin->pin == 26 ){ |
3c132bd0 | 46 | return p18; |
7b49793d | 47 | }else if( pin->port == LPC_GPIO1 && pin->pin == 30 ){ |
3c132bd0 | 48 | return p19; |
7b49793d | 49 | }else if( pin->port == LPC_GPIO1 && pin->pin == 31 ){ |
3c132bd0 AW |
50 | return p20; |
51 | }else{ | |
7b49793d | 52 | //TODO: Error |
69735c09 | 53 | return NC; |
3c132bd0 AW |
54 | } |
55 | } | |
56 |