Fork of Smoothie to port to mbed non-LPC targets.

Dependencies:   mbed

Fork of Smoothie by Stéphane Cachat

Committer:
Michael J. Spencer
Date:
Fri Feb 28 18:52:52 2014 -0800
Revision:
2:1df0b61d3b5a
Parent:
0:31e91bb0ef3c
Update to latest Smoothie.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Michael J. Spencer 2:1df0b61d3b5a 1 /*
scachat 0:31e91bb0ef3c 2 This file is part of Smoothie (http://smoothieware.org/). The motion control part is heavily based on Grbl (https://github.com/simen/grbl).
scachat 0:31e91bb0ef3c 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.
scachat 0:31e91bb0ef3c 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.
Michael J. Spencer 2:1df0b61d3b5a 5 You should have received a copy of the GNU General Public License along with Smoothie. If not, see <http://www.gnu.org/licenses/>.
scachat 0:31e91bb0ef3c 6 */
scachat 0:31e91bb0ef3c 7
scachat 0:31e91bb0ef3c 8 using namespace std;
scachat 0:31e91bb0ef3c 9 #include <vector>
scachat 0:31e91bb0ef3c 10 #include "libs/nuts_bolts.h"
scachat 0:31e91bb0ef3c 11 #include "libs/Module.h"
scachat 0:31e91bb0ef3c 12 #include "libs/Kernel.h"
scachat 0:31e91bb0ef3c 13 #include "Adc.h"
scachat 0:31e91bb0ef3c 14 #include "libs/ADC/adc.h"
scachat 0:31e91bb0ef3c 15 #include "libs/Pin.h"
scachat 0:31e91bb0ef3c 16
Michael J. Spencer 2:1df0b61d3b5a 17 // This is an interface to the mbed.org ADC library you can find in libs/ADC/adc.h
Michael J. Spencer 2:1df0b61d3b5a 18 // TODO : Having the same name is confusing, should change that
Michael J. Spencer 2:1df0b61d3b5a 19
scachat 0:31e91bb0ef3c 20 Adc::Adc(){
scachat 0:31e91bb0ef3c 21 this->adc = new ADC(1000, 1);
scachat 0:31e91bb0ef3c 22 }
scachat 0:31e91bb0ef3c 23
Michael J. Spencer 2:1df0b61d3b5a 24 // Enables ADC on a given pin
scachat 0:31e91bb0ef3c 25 void Adc::enable_pin(Pin* pin){
scachat 0:31e91bb0ef3c 26 PinName pin_name = this->_pin_to_pinname(pin);
scachat 0:31e91bb0ef3c 27 this->adc->burst(1);
scachat 0:31e91bb0ef3c 28 this->adc->setup(pin_name,1);
scachat 0:31e91bb0ef3c 29 this->adc->interrupt_state(pin_name,1);
scachat 0:31e91bb0ef3c 30 }
scachat 0:31e91bb0ef3c 31
Michael J. Spencer 2:1df0b61d3b5a 32 // Read the last value ( burst mode ) on a given pin
scachat 0:31e91bb0ef3c 33 unsigned int Adc::read(Pin* pin){
scachat 0:31e91bb0ef3c 34 return this->adc->read(this->_pin_to_pinname(pin));
scachat 0:31e91bb0ef3c 35 }
scachat 0:31e91bb0ef3c 36
Michael J. Spencer 2:1df0b61d3b5a 37 // Convert a smoothie Pin into a mBed Pin
scachat 0:31e91bb0ef3c 38 PinName Adc::_pin_to_pinname(Pin* pin){
Michael J. Spencer 2:1df0b61d3b5a 39 if( pin->port == LPC_GPIO0 && pin->pin == 23 ){
scachat 0:31e91bb0ef3c 40 return p15;
Michael J. Spencer 2:1df0b61d3b5a 41 }else if( pin->port == LPC_GPIO0 && pin->pin == 24 ){
scachat 0:31e91bb0ef3c 42 return p16;
Michael J. Spencer 2:1df0b61d3b5a 43 }else if( pin->port == LPC_GPIO0 && pin->pin == 25 ){
scachat 0:31e91bb0ef3c 44 return p17;
Michael J. Spencer 2:1df0b61d3b5a 45 }else if( pin->port == LPC_GPIO0 && pin->pin == 26 ){
scachat 0:31e91bb0ef3c 46 return p18;
Michael J. Spencer 2:1df0b61d3b5a 47 }else if( pin->port == LPC_GPIO1 && pin->pin == 30 ){
scachat 0:31e91bb0ef3c 48 return p19;
Michael J. Spencer 2:1df0b61d3b5a 49 }else if( pin->port == LPC_GPIO1 && pin->pin == 31 ){
scachat 0:31e91bb0ef3c 50 return p20;
scachat 0:31e91bb0ef3c 51 }else{
Michael J. Spencer 2:1df0b61d3b5a 52 //TODO: Error
Michael J. Spencer 2:1df0b61d3b5a 53 return NC;
scachat 0:31e91bb0ef3c 54 }
scachat 0:31e91bb0ef3c 55 }
scachat 0:31e91bb0ef3c 56