smoothie port to mbed online compiler (smoothieware.org)

Dependencies:   mbed

For documentation, license, ..., please check http://smoothieware.org/

This version has been tested with a 3 axis machine

Committer:
scachat
Date:
Tue Jul 31 21:11:18 2012 +0000
Revision:
0:31e91bb0ef3c
smoothie port to mbed online compiler

Who changed what in which revision?

UserRevisionLine numberNew contents of line
scachat 0:31e91bb0ef3c 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.
scachat 0:31e91bb0ef3c 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
scachat 0:31e91bb0ef3c 17 Adc::Adc(){
scachat 0:31e91bb0ef3c 18 this->adc = new ADC(1000, 1);
scachat 0:31e91bb0ef3c 19 }
scachat 0:31e91bb0ef3c 20
scachat 0:31e91bb0ef3c 21 void Adc::enable_pin(Pin* pin){
scachat 0:31e91bb0ef3c 22 PinName pin_name = this->_pin_to_pinname(pin);
scachat 0:31e91bb0ef3c 23 this->adc->burst(1);
scachat 0:31e91bb0ef3c 24 this->adc->setup(pin_name,1);
scachat 0:31e91bb0ef3c 25 this->adc->interrupt_state(pin_name,1);
scachat 0:31e91bb0ef3c 26 }
scachat 0:31e91bb0ef3c 27
scachat 0:31e91bb0ef3c 28 unsigned int Adc::read(Pin* pin){
scachat 0:31e91bb0ef3c 29 return this->adc->read(this->_pin_to_pinname(pin));
scachat 0:31e91bb0ef3c 30 }
scachat 0:31e91bb0ef3c 31
scachat 0:31e91bb0ef3c 32 PinName Adc::_pin_to_pinname(Pin* pin){
scachat 0:31e91bb0ef3c 33 if( pin->port == LPC_GPIO0 && pin->pin == 23 ){
scachat 0:31e91bb0ef3c 34 return p15;
scachat 0:31e91bb0ef3c 35 }else if( pin->port == LPC_GPIO0 && pin->pin == 24 ){
scachat 0:31e91bb0ef3c 36 return p16;
scachat 0:31e91bb0ef3c 37 }else if( pin->port == LPC_GPIO0 && pin->pin == 25 ){
scachat 0:31e91bb0ef3c 38 return p17;
scachat 0:31e91bb0ef3c 39 }else if( pin->port == LPC_GPIO0 && pin->pin == 26 ){
scachat 0:31e91bb0ef3c 40 return p18;
scachat 0:31e91bb0ef3c 41 }else if( pin->port == LPC_GPIO1 && pin->pin == 30 ){
scachat 0:31e91bb0ef3c 42 return p19;
scachat 0:31e91bb0ef3c 43 }else if( pin->port == LPC_GPIO1 && pin->pin == 31 ){
scachat 0:31e91bb0ef3c 44 return p20;
scachat 0:31e91bb0ef3c 45 }else{
scachat 0:31e91bb0ef3c 46 //TODO: Error
scachat 0:31e91bb0ef3c 47 error("Bad adc pin");
scachat 0:31e91bb0ef3c 48
scachat 0:31e91bb0ef3c 49 }
scachat 0:31e91bb0ef3c 50 }
scachat 0:31e91bb0ef3c 51