Merge remote-tracking branch 'upstream/edge' into fix/trapezoid-symmetry
authorJim Morris <morris@wolfman.com>
Mon, 24 Nov 2014 22:45:48 +0000 (14:45 -0800)
committerJim Morris <morris@wolfman.com>
Mon, 24 Nov 2014 22:45:48 +0000 (14:45 -0800)
Conflicts:
src/libs/Pin.h

1  2 
src/libs/Pin.cpp
src/libs/Pin.h
src/main.cpp

diff --combined src/libs/Pin.cpp
@@@ -1,12 -1,12 +1,15 @@@
  #include "Pin.h"
  #include "utils.h"
  
+ // mbed libraries for hardware pwm
+ #include "PwmOut.h"
+ #include "PinNames.h"
  Pin::Pin(){
      this->inverting= false;
 +    this->valid= false;
 +    this->pin= 32;
 +    this->port= nullptr;
  }
  
  // Make a new pin object from a string
@@@ -17,7 -17,6 +20,7 @@@ Pin* Pin::from_string(std::string value
      const char* cs = value.c_str();
      // cn is the position of the next char after the number we just read
      char* cn = NULL;
 +    valid= true;
  
      // grab first integer as port. pointer to first non-digit goes in cn
      this->port_number = strtol(cs, &cn, 10);
      }
  
      // from_string failed. TODO: some sort of error
 +    valid= false;
      port_number = 0;
      port = gpios[0];
 -    pin = 255;
 +    pin = 32;
      inverting = false;
      return this;
  }
  
  // Configure this pin as OD
  Pin* Pin::as_open_drain(){
 -    if (this->pin >= 32) return this;
 +    if (!this->valid) return this;
      if( this->port_number == 0 ){ LPC_PINCON->PINMODE_OD0 |= (1<<this->pin); }
      if( this->port_number == 1 ){ LPC_PINCON->PINMODE_OD1 |= (1<<this->pin); }
      if( this->port_number == 2 ){ LPC_PINCON->PINMODE_OD2 |= (1<<this->pin); }
  
  // Configure this pin as a repeater
  Pin* Pin::as_repeater(){
 -    if (this->pin >= 32) return this;
 +    if (!this->valid) return this;
      // Set the two bits for this pin as 01
      if( this->port_number == 0 && this->pin < 16  ){ LPC_PINCON->PINMODE0 |= (1<<( this->pin*2)); LPC_PINCON->PINMODE0 &= ~(2<<( this->pin    *2)); }
      if( this->port_number == 0 && this->pin >= 16 ){ LPC_PINCON->PINMODE1 |= (1<<( this->pin*2)); LPC_PINCON->PINMODE1 &= ~(2<<((this->pin-16)*2)); }
  
  // Configure this pin as no pullup or pulldown
  Pin* Pin::pull_none(){
 -      if (this->pin >= 32) return this;
 +      if (!this->valid) return this;
        // Set the two bits for this pin as 10
        if( this->port_number == 0 && this->pin < 16  ){ LPC_PINCON->PINMODE0 |= (2<<( this->pin*2)); LPC_PINCON->PINMODE0 &= ~(1<<( this->pin    *2)); }
        if( this->port_number == 0 && this->pin >= 16 ){ LPC_PINCON->PINMODE1 |= (2<<( this->pin*2)); LPC_PINCON->PINMODE1 &= ~(1<<((this->pin-16)*2)); }
  
  // Configure this pin as a pullup
  Pin* Pin::pull_up(){
 -    if (this->pin >= 32) return this;
 +    if (!this->valid) return this;
      // Set the two bits for this pin as 00
      if( this->port_number == 0 && this->pin < 16  ){ LPC_PINCON->PINMODE0 &= ~(3<<( this->pin    *2)); }
      if( this->port_number == 0 && this->pin >= 16 ){ LPC_PINCON->PINMODE1 &= ~(3<<((this->pin-16)*2)); }
  
  // Configure this pin as a pulldown
  Pin* Pin::pull_down(){
 -    if (this->pin >= 32) return this;
 +    if (!this->valid) return this;
      // Set the two bits for this pin as 11
      if( this->port_number == 0 && this->pin < 16  ){ LPC_PINCON->PINMODE0 |= (3<<( this->pin    *2)); }
      if( this->port_number == 0 && this->pin >= 16 ){ LPC_PINCON->PINMODE1 |= (3<<((this->pin-16)*2)); }
      if( this->port_number == 4 && this->pin >= 16 ){ LPC_PINCON->PINMODE9 |= (3<<((this->pin-16)*2)); }
      return this;
  }
+ // If available on this pin, return mbed hardware pwm class for this pin
+ mbed::PwmOut* Pin::hardware_pwm()
+ {
+     if (port_number == 1)
+     {
+         if (pin == 18) { return new mbed::PwmOut(P1_18); }
+         if (pin == 20) { return new mbed::PwmOut(P1_20); }
+         if (pin == 21) { return new mbed::PwmOut(P1_21); }
+         if (pin == 23) { return new mbed::PwmOut(P1_23); }
+         if (pin == 24) { return new mbed::PwmOut(P1_24); }
+         if (pin == 26) { return new mbed::PwmOut(P1_26); }
+     }
+     else if (port_number == 2)
+     {
+         if (pin == 0) { return new mbed::PwmOut(P2_0); }
+         if (pin == 1) { return new mbed::PwmOut(P2_1); }
+         if (pin == 2) { return new mbed::PwmOut(P2_2); }
+         if (pin == 3) { return new mbed::PwmOut(P2_3); }
+         if (pin == 4) { return new mbed::PwmOut(P2_4); }
+         if (pin == 5) { return new mbed::PwmOut(P2_5); }
+     }
+     else if (port_number == 3)
+     {
+         if (pin == 25) { return new mbed::PwmOut(P3_25); }
+         if (pin == 26) { return new mbed::PwmOut(P3_26); }
+     }
+     return NULL;
+ }
diff --combined src/libs/Pin.h
@@@ -6,6 -6,11 +6,11 @@@
  #include <string>
  
  #include "libs/LPC17xx/sLPC17xx.h" // smoothed mbed.h lib
+ #include "PinNames.h"
+ namespace mbed {
+     class PwmOut;
+ }
  
  class Pin {
      public:
@@@ -14,7 -19,7 +19,7 @@@
          Pin* from_string(std::string value);
  
          inline bool connected(){
 -            return this->pin < 32;
 +            return this->valid;
          }
  
          inline bool equals(const Pin& other) const {
          }
  
          inline Pin* as_output(){
 -            if (this->pin < 32)
 +            if (this->valid)
                  this->port->FIODIR |= 1<<this->pin;
              return this;
          }
  
          inline Pin* as_input(){
 -            if (this->pin < 32)
 +            if (this->valid)
                  this->port->FIODIR &= ~(1<<this->pin);
              return this;
          }
          Pin* pull_none(void);
  
          inline bool get(){
 -
 -            if (this->pin >= 32) return false;
 +            if (!this->valid) return false;
              return this->inverting ^ (( this->port->FIOPIN >> this->pin ) & 1);
          }
  
          inline void set(bool value)
          {
 -            if (this->pin >= 32) return;
 +            if (!this->valid) return;
              if ( this->inverting ^ value )
                  this->port->FIOSET = 1 << this->pin;
              else
                  this->port->FIOCLR = 1 << this->pin;
          }
  
 -        
+         mbed::PwmOut *hardware_pwm();
++
 +        // these should be private, and use getters
          LPC_GPIO_TypeDef* port;
 -        bool inverting;
 -        char port_number;
 +
          unsigned char pin;
 +        char port_number;
 +        struct {
 +            bool inverting:1;
 +            bool valid:1;
 +        };
  };
  
  
diff --combined src/main.cpp
@@@ -8,6 -8,7 +8,7 @@@
  #include "libs/Kernel.h"
  
  #include "modules/tools/laser/Laser.h"
+ #include "modules/tools/spindle/Spindle.h"
  #include "modules/tools/extruder/ExtruderMaker.h"
  #include "modules/tools/temperaturecontrol/TemperatureControlPool.h"
  #include "modules/tools/endstops/Endstops.h"
@@@ -82,15 -83,6 +83,15 @@@ GPIO leds[5] = 
      GPIO(P4_28)
  };
  
 +// debug pins, only used if defined in src/makefile
 +#ifdef BLOCK_DEBUG_PIN
 +GPIO block_debug_pin(BLOCK_DEBUG_PIN);
 +#endif
 +
 +#ifdef STEPTICKER_DEBUG_PIN
 +GPIO stepticker_debug_pin(STEPTICKER_DEBUG_PIN);
 +#endif
 +
  void init() {
  
      // Default pins to low status
          leds[i]= 0;
      }
  
 +#ifdef BLOCK_DEBUG_PIN
 +    block_debug_pin.output();
 +    block_debug_pin= 0;
 +#endif
 +#ifdef STEPTICKER_DEBUG_PIN
 +    stepticker_debug_pin.output();
 +    stepticker_debug_pin= 0;
 +#endif
 +
      Kernel* kernel = new Kernel();
  
      kernel->streams->printf("Smoothie Running @%ldMHz\r\n", SystemCoreClock / 1000000);
      #ifndef NO_TOOLS_LASER
      kernel->add_module( new Laser() );
      #endif
+     #ifndef NO_TOOLS_SPINDLE
+     kernel->add_module( new Spindle() );
+     #endif
      #ifndef NO_UTILS_PANEL
      kernel->add_module( new Panel() );
      #endif