Organizational updates. Mega2560 support moved.

- Mega2560 support has been moved to the Grbl-Mega
[project](http://github.com/gnea/grbl-Mega/) to clean up the code and
make future developments easier with increased flash and RAM. All new
developments between the 328p and Mega2560 will be synced when it makes
sense to.

- OEM single file compile configuration option. Before OEMs needed to
alter three files. Provided a way to just alter the config.h file to
contain everything for a particular Grbl build. See config.h for more
details.

- Removed defaults and cpu_map directories and reverted back to
defaults.h and cpu_map.h to contain all definitions. This should help
reduce some headaches and the previous implementation inadvertently
created. Also, it makes the single file config.h possible.

- Moved (and tweaked) the invert control pin mask define and placed
into config.h, rather than in the cpu_map.h file. Makes more sense
there.
This commit is contained in:
Sonny Jeon
2016-03-30 11:58:47 -06:00
parent 5bfc3a1945
commit 0746a5a1d7
20 changed files with 533 additions and 1040 deletions

View File

@ -29,19 +29,13 @@ void spindle_init()
// Configure variable spindle PWM and enable pin, if requried. On the Uno, PWM and enable are
// combined unless configured otherwise.
SPINDLE_PWM_DDR |= (1<<SPINDLE_PWM_BIT); // Configure as PWM output pin.
TCCRA_REGISTER = TCCRA_INIT_MASK; // Configure PWM output compare timer
TCCRB_REGISTER = TCCRB_INIT_MASK;
#ifdef CPU_MAP_ATMEGA2560
OCRA_REGISTER = OCRA_TOP_VALUE; // Set the top value for 16-bit fast PWM mode
SPINDLE_TCCRA_REGISTER = SPINDLE_TCCRA_INIT_MASK; // Configure PWM output compare timer
SPINDLE_TCCRB_REGISTER = SPINDLE_TCCRB_INIT_MASK;
#ifdef USE_SPINDLE_DIR_AS_ENABLE_PIN
SPINDLE_ENABLE_DDR |= (1<<SPINDLE_ENABLE_BIT); // Configure as output pin.
#else
SPINDLE_DIRECTION_DDR |= (1<<SPINDLE_DIRECTION_BIT); // Configure as output pin.
#else // Otherwise 328p
#ifdef USE_SPINDLE_DIR_AS_ENABLE_PIN
SPINDLE_ENABLE_DDR |= (1<<SPINDLE_ENABLE_BIT); // Configure as output pin.
#else
SPINDLE_DIRECTION_DDR |= (1<<SPINDLE_DIRECTION_BIT); // Configure as output pin.
#endif
#endif
#endif
#else
@ -59,7 +53,7 @@ void spindle_stop()
{
// On the Uno, spindle enable and PWM are shared. Other CPUs have seperate enable pin.
#ifdef VARIABLE_SPINDLE
TCCRA_REGISTER &= ~(1<<COMB_BIT); // Disable PWM. Output voltage is zero.
SPINDLE_TCCRA_REGISTER &= ~(1<<SPINDLE_COMB_BIT); // Disable PWM. Output voltage is zero.
#if defined(CPU_MAP_ATMEGA2560) || defined(USE_SPINDLE_DIR_AS_ENABLE_PIN)
#ifdef INVERT_SPINDLE_ENABLE_PIN
SPINDLE_ENABLE_PORT |= (1<<SPINDLE_ENABLE_BIT); // Set pin to high
@ -99,35 +93,31 @@ void spindle_set_state(uint8_t state, float rpm)
#ifdef VARIABLE_SPINDLE
// TODO: Install the optional capability for frequency-based output for servos.
#ifdef CPU_MAP_ATMEGA2560
uint16_t current_pwm; // 2560 PWM register is 16-bit.
#else
uint8_t current_pwm; // 328p PWM register is 8-bit.
#endif
uint8_t current_pwm; // 328p PWM register is 8-bit.
// Calculate PWM register value based on rpm max/min settings and programmed rpm.
if (rpm <= 0.0) { spindle_stop(); } // RPM should never be negative, but check anyway.
else {
if (settings.rpm_max <= settings.rpm_min) {
// No PWM range possible. Set simple on/off spindle control pin state.
current_pwm = PWM_MAX_VALUE;
current_pwm = SPINDLE_PWM_MAX_VALUE;
} else {
if (rpm > settings.rpm_max) { rpm = settings.rpm_max; }
if (rpm < settings.rpm_min) { rpm = settings.rpm_min; }
#ifdef SPINDLE_MINIMUM_PWM
float pwm_gradient = (PWM_MAX_VALUE-SPINDLE_MINIMUM_PWM)/(settings.rpm_max-settings.rpm_min);
float pwm_gradient = (SPINDLE_PWM_MAX_VALUE-SPINDLE_MINIMUM_PWM)/(settings.rpm_max-settings.rpm_min);
current_pwm = floor( (rpm-settings.rpm_min)*pwm_gradient + (SPINDLE_MINIMUM_PWM+0.5));
#else
float pwm_gradient = (PWM_MAX_VALUE)/(settings.rpm_max-settings.rpm_min);
float pwm_gradient = (SPINDLE_PWM_MAX_VALUE)/(settings.rpm_max-settings.rpm_min);
current_pwm = floor( (rpm-settings.rpm_min)*pwm_gradient + 0.5);
#endif
}
OCR_REGISTER = current_pwm; // Set PWM output level.
TCCRA_REGISTER |= (1<<COMB_BIT); // Ensure PWM output is enabled.
SPINDLE_OCR_REGISTER = current_pwm; // Set PWM output level.
SPINDLE_TCCRA_REGISTER |= (1<<SPINDLE_COMB_BIT); // Ensure PWM output is enabled.
// On the Uno, spindle enable and PWM are shared, unless otherwise specified.
#if defined(CPU_MAP_ATMEGA2560) || defined(USE_SPINDLE_DIR_AS_ENABLE_PIN)
#if defined(USE_SPINDLE_DIR_AS_ENABLE_PIN)
#ifdef INVERT_SPINDLE_ENABLE_PIN
SPINDLE_ENABLE_PORT &= ~(1<<SPINDLE_ENABLE_BIT);
#else