diff --git a/Grbl_Esp32/config.h b/Grbl_Esp32/config.h index d6be8eb6..b0057328 100644 --- a/Grbl_Esp32/config.h +++ b/Grbl_Esp32/config.h @@ -44,11 +44,11 @@ Some features should not be changed. See notes below. // The CPU map is the main definition of the machine/controller you want to use // These are typically found in the cpu_map.h file. // See Github repo wiki for more details -#define CPU_MAP_TEST_DRIVE // these are defined in cpu_map.h +#define CPU_MAP_ESP32 // these are defined in cpu_map.h // Number of axes defined (steppers, servos, etc) (valid range: 3 to 6) -// Even if your machine only uses less than the minimum of 3, you should select 3 -#define N_AXIS 3 +// Even if your machine only uses less than the minimum of 3, you should select 3 +#define N_AXIS 3 #define VERBOSE_HELP // Currently this doesn't do anything #define GRBL_MSG_LEVEL MSG_LEVEL_INFO // what level of [MSG:....] do you want to see 0=all off @@ -288,7 +288,7 @@ Some features should not be changed. See notes below. #define IGNORE_CONTROL_PINS #define ENABLE_CONTROL_SW_DEBOUNCE // Default disabled. Uncomment to enable. -#define CONTROL_SW_DEBOUNCE_PERIOD 32 // in milliseconds default 32 microseconds +#define CONTROL_SW_DEBOUNCE_PERIOD 32 // in milliseconds default 32 microseconds // Inverts select limit pin states based on the following mask. This effects all limit pin functions, diff --git a/Grbl_Esp32/cpu_map.h b/Grbl_Esp32/cpu_map.h index 3a188f60..7cc4fefe 100644 --- a/Grbl_Esp32/cpu_map.h +++ b/Grbl_Esp32/cpu_map.h @@ -585,19 +585,20 @@ #endif #define USE_GANGED_AXES // allow two motors on an axis + #define USE_RMT_STEPS #define X_STEP_PIN GPIO_NUM_12 - #define X_STEP_B_PIN GPIO_NUM_22 // ganged motor + #define X2_STEP_PIN GPIO_NUM_22 // ganged motor #define X_AXIS_SQUARING #define Y_STEP_PIN GPIO_NUM_14 - #define Y_STEP_B_PIN GPIO_NUM_21 // ganged motor + #define Y2_STEP_PIN GPIO_NUM_21 // ganged motor #define Y_AXIS_SQUARING #define Z_STEP_PIN GPIO_NUM_27 #define X_DIRECTION_PIN GPIO_NUM_26 - #define Y_DIRECTION_PIN GPIO_NUM_25 + #define Y_DIRECTION_PIN GPIO_NUM_25 #define Z_DIRECTION_PIN GPIO_NUM_33 // OK to comment out to use pin for other features @@ -736,14 +737,14 @@ #define X_DIRECTION_PIN GPIO_NUM_33 // use Z labeled connector #define Y_STEP_PIN GPIO_NUM_14 - #define Y_STEP_B_PIN GPIO_NUM_21 // ganged motor + #define Y2_STEP_PIN GPIO_NUM_21 // ganged motor #define Y_DIRECTION_PIN GPIO_NUM_25 #define Y_AXIS_SQUARING #define Z_STEP_PIN GPIO_NUM_12 // use X labeled connector - #define Z_STEP_B_PIN GPIO_NUM_22 // use X labeled connector + #define Z2_STEP_PIN GPIO_NUM_22 // use X labeled connector #define Z_DIRECTION_PIN GPIO_NUM_26 // use X labeled connector - #define Z_AXIS_SQUARING + #define Z_AXIS_SQUARING // OK to comment out to use pin for other features #define STEPPERS_DISABLE_PIN GPIO_NUM_13 @@ -1082,6 +1083,52 @@ #endif +#ifdef EXTERNAL_DRIVER_4X + #define CPU_MAP_NAME "External Driver Board V1.1" + + #ifdef N_AXIS + #undef N_AXIS + #endif + #define N_AXIS 4 + + #define USE_RMT_STEPS + #define X_STEP_PIN GPIO_NUM_0 + #define X_DIRECTION_PIN GPIO_NUM_2 + #define Y_STEP_PIN GPIO_NUM_26 + #define Y_DIRECTION_PIN GPIO_NUM_15 + #define Z_STEP_PIN GPIO_NUM_27 + #define Z_DIRECTION_PIN GPIO_NUM_33 + #define A_STEP_PIN GPIO_NUM_14 + #define A_DIRECTION_PIN GPIO_NUM_12 + #define STEPPERS_DISABLE_PIN GPIO_NUM_13 + + + #define SPINDLE_PWM_PIN GPIO_NUM_25 + #define SPINDLE_PWM_CHANNEL 0 + #define SPINDLE_PWM_BIT_PRECISION 8 + #define SPINDLE_ENABLE_PIN GPIO_NUM_22 + + #define MODBUS_TX GPIO_NUM_17 + #define MODBUS_RX GPIO_NUM_4 + #define MODBUS_CTRL GPIO_NUM_16 + + #define X_LIMIT_PIN GPIO_NUM_34 + #define Y_LIMIT_PIN GPIO_NUM_35 + #define Z_LIMIT_PIN GPIO_NUM_36 + + #if (N_AXIS == 3) + #define LIMIT_MASK B0111 + #else + #define A_LIMIT_PIN GPIO_NUM_39 + #define LIMIT_MASK B1111 + #endif + + #define PROBE_PIN GPIO_NUM_32 + #define COOLANT_MIST_PIN GPIO_NUM_21 + + +#endif + #ifdef CPU_MAP_ATARI_1020 #include "atari_1020.h" #endif diff --git a/Grbl_Esp32/grbl.h b/Grbl_Esp32/grbl.h index 1d23575c..519f469f 100644 --- a/Grbl_Esp32/grbl.h +++ b/Grbl_Esp32/grbl.h @@ -20,7 +20,7 @@ // Grbl versioning system #define GRBL_VERSION "1.1f" -#define GRBL_VERSION_BUILD "20200219" +#define GRBL_VERSION_BUILD "20200221" //#include #include diff --git a/Grbl_Esp32/stepper.cpp b/Grbl_Esp32/stepper.cpp index 9c4ba830..29a1f718 100644 --- a/Grbl_Esp32/stepper.cpp +++ b/Grbl_Esp32/stepper.cpp @@ -152,6 +152,21 @@ typedef struct { } st_prep_t; static st_prep_t prep; +// RMT channel numbers. These are assigned dynamically as needed via the CPU MAP +// Only 8 are available (0-7) +// They are Initialized with an invalid number to prevent unitended consequences +uint8_t X_rmt_chan_num = 255; +uint8_t X2_rmt_chan_num = 255; // Ganged axes have the "2" +uint8_t Y_rmt_chan_num = 255; +uint8_t Y2_rmt_chan_num = 255; +uint8_t Z_rmt_chan_num = 255; +uint8_t Z2_rmt_chan_num = 255; +uint8_t A_rmt_chan_num = 255; +uint8_t A2_rmt_chan_num = 255; +uint8_t B_rmt_chan_num = 255; +uint8_t B2_rmt_chan_num = 255; +uint8_t C_rmt_chan_num = 255; +uint8_t C2_rmt_chan_num = 255; /* "The Stepper Driver Interrupt" - This timer interrupt is the workhorse of Grbl. Grbl employs the venerable Bresenham line algorithm to manage and exactly synchronize multi-axis moves. @@ -458,22 +473,22 @@ void stepper_init() #ifdef X_STEP_PIN pinMode(X_STEP_PIN, OUTPUT); #endif - #ifdef X_STEP_B_PIN // ganged motor - pinMode(X_STEP_B_PIN, OUTPUT); + #ifdef X2_STEP_PIN // ganged motor + pinMode(X2_STEP_PIN, OUTPUT); #endif #ifdef Y_STEP_PIN pinMode(Y_STEP_PIN, OUTPUT); #endif - #ifdef Y_STEP_B_PIN - pinMode(Y_STEP_B_PIN, OUTPUT); + #ifdef Y2_STEP_PIN + pinMode(Y2_STEP_PIN, OUTPUT); #endif #ifdef Z_STEP_PIN pinMode(Z_STEP_PIN, OUTPUT); #endif - #ifdef Z_STEP_B_PIN - pinMode(Z_STEP_B_PIN, OUTPUT); + #ifdef Z2_STEP_PIN + pinMode(Z2_STEP_PIN, OUTPUT); #endif #ifdef A_STEP_PIN @@ -536,8 +551,6 @@ void stepper_init() timer_set_counter_value(STEP_TIMER_GROUP, STEP_TIMER_INDEX, 0x00000000ULL); timer_enable_intr(STEP_TIMER_GROUP, STEP_TIMER_INDEX); timer_isr_register(STEP_TIMER_GROUP, STEP_TIMER_INDEX, onStepperDriverTimer, NULL, 0, NULL); - - } #ifdef USE_RMT_STEPS @@ -567,8 +580,9 @@ void initRMT() rmtItem[1].duration1 = 0; #ifdef X_STEP_PIN - rmt_set_source_clk( (rmt_channel_t)X_RMT_CHANNEL, RMT_BASECLK_APB); - rmtConfig.channel = (rmt_channel_t)X_RMT_CHANNEL; + X_rmt_chan_num = sys_get_next_RMT_chan_num(); + rmt_set_source_clk( (rmt_channel_t)X_rmt_chan_num, RMT_BASECLK_APB); + rmtConfig.channel = (rmt_channel_t)X_rmt_chan_num; rmtConfig.tx_config.idle_level = bit_istrue(settings.step_invert_mask, X_AXIS) ? RMT_IDLE_LEVEL_HIGH : RMT_IDLE_LEVEL_LOW; rmtConfig.gpio_num = X_STEP_PIN; rmtItem[0].level0 = rmtConfig.tx_config.idle_level; @@ -577,11 +591,12 @@ void initRMT() rmt_fill_tx_items(rmtConfig.channel, &rmtItem[0], rmtConfig.mem_block_num, 0); #endif -#ifdef X_STEP_B_PIN - rmt_set_source_clk( (rmt_channel_t)X_B_RMT_CHANNEL, RMT_BASECLK_APB); - rmtConfig.channel = (rmt_channel_t)X_B_RMT_CHANNEL; +#ifdef X2_STEP_PIN + X2_rmt_chan_num = sys_get_next_RMT_chan_num(); + rmt_set_source_clk( (rmt_channel_t)X2_rmt_chan_num, RMT_BASECLK_APB); + rmtConfig.channel = (rmt_channel_t)X2_rmt_chan_num; rmtConfig.tx_config.idle_level = bit_istrue(settings.step_invert_mask, X_AXIS) ? RMT_IDLE_LEVEL_HIGH : RMT_IDLE_LEVEL_LOW; - rmtConfig.gpio_num = X_STEP_B_PIN; + rmtConfig.gpio_num = X2_STEP_PIN; rmtItem[0].level0 = rmtConfig.tx_config.idle_level; rmtItem[0].level1 = !rmtConfig.tx_config.idle_level; rmt_config(&rmtConfig); @@ -589,8 +604,9 @@ void initRMT() #endif #ifdef Y_STEP_PIN - rmt_set_source_clk( (rmt_channel_t)Y_RMT_CHANNEL, RMT_BASECLK_APB); - rmtConfig.channel = (rmt_channel_t)Y_RMT_CHANNEL; + Y_rmt_chan_num = sys_get_next_RMT_chan_num(); + rmt_set_source_clk( (rmt_channel_t)Y_rmt_chan_num, RMT_BASECLK_APB); + rmtConfig.channel = (rmt_channel_t)Y_rmt_chan_num; rmtConfig.tx_config.idle_level = bit_istrue(settings.step_invert_mask, Y_AXIS) ? RMT_IDLE_LEVEL_HIGH : RMT_IDLE_LEVEL_LOW; rmtConfig.gpio_num = Y_STEP_PIN; rmtItem[0].level0 = rmtConfig.tx_config.idle_level; @@ -599,11 +615,12 @@ void initRMT() rmt_fill_tx_items(rmtConfig.channel, &rmtItem[0], rmtConfig.mem_block_num, 0); #endif -#ifdef Y_STEP_B_PIN - rmt_set_source_clk( (rmt_channel_t)Y_B_RMT_CHANNEL, RMT_BASECLK_APB); - rmtConfig.channel = (rmt_channel_t)Y_B_RMT_CHANNEL; +#ifdef Y2_STEP_PIN + Y2_rmt_chan_num = sys_get_next_RMT_chan_num(); + rmt_set_source_clk( (rmt_channel_t)Y2_rmt_chan_num, RMT_BASECLK_APB); + rmtConfig.channel = (rmt_channel_t)Y2_rmt_chan_num; rmtConfig.tx_config.idle_level = bit_istrue(settings.step_invert_mask, Y_AXIS) ? RMT_IDLE_LEVEL_HIGH : RMT_IDLE_LEVEL_LOW; - rmtConfig.gpio_num = Y_STEP_B_PIN; + rmtConfig.gpio_num = Y2_STEP_PIN; rmtItem[0].level0 = rmtConfig.tx_config.idle_level; rmtItem[0].level1 = !rmtConfig.tx_config.idle_level; rmt_config(&rmtConfig); @@ -611,8 +628,9 @@ void initRMT() #endif #ifdef Z_STEP_PIN - rmt_set_source_clk( (rmt_channel_t)Z_RMT_CHANNEL, RMT_BASECLK_APB); - rmtConfig.channel = (rmt_channel_t)Z_RMT_CHANNEL; + Z_rmt_chan_num = sys_get_next_RMT_chan_num(); + rmt_set_source_clk( (rmt_channel_t)Z_rmt_chan_num, RMT_BASECLK_APB); + rmtConfig.channel = (rmt_channel_t)Z_rmt_chan_num; rmtConfig.tx_config.idle_level = bit_istrue(settings.step_invert_mask, Z_AXIS) ? RMT_IDLE_LEVEL_HIGH : RMT_IDLE_LEVEL_LOW; rmtConfig.gpio_num = Z_STEP_PIN; rmtItem[0].level0 = rmtConfig.tx_config.idle_level; @@ -622,8 +640,9 @@ void initRMT() #endif #ifdef A_STEP_PIN - rmt_set_source_clk( (rmt_channel_t)A_RMT_CHANNEL, RMT_BASECLK_APB); - rmtConfig.channel = (rmt_channel_t)A_RMT_CHANNEL; + A_rmt_chan_num = sys_get_next_RMT_chan_num(); + rmt_set_source_clk( (rmt_channel_t)A_rmt_chan_num, RMT_BASECLK_APB); + rmtConfig.channel = (rmt_channel_t)A_rmt_chan_num; rmtConfig.tx_config.idle_level = bit_istrue(settings.step_invert_mask, A_AXIS) ? RMT_IDLE_LEVEL_HIGH : RMT_IDLE_LEVEL_LOW; rmtConfig.gpio_num = A_STEP_PIN; // TODO rmtItem[0].level0 = rmtConfig.tx_config.idle_level; @@ -633,8 +652,9 @@ void initRMT() #endif #ifdef B_STEP_PIN - rmt_set_source_clk( (rmt_channel_t)B_RMT_CHANNEL, RMT_BASECLK_APB); - rmtConfig.channel = (rmt_channel_t)B_RMT_CHANNEL; + B_rmt_chan_num = sys_get_next_RMT_chan_num(); + rmt_set_source_clk( (rmt_channel_t)B_rmt_chan_num, RMT_BASECLK_APB); + rmtConfig.channel = (rmt_channel_t)B_rmt_chan_num; rmtConfig.tx_config.idle_level = bit_istrue(settings.step_invert_mask, B_AXIS) ? RMT_IDLE_LEVEL_HIGH : RMT_IDLE_LEVEL_LOW; rmtConfig.gpio_num = B_STEP_PIN; // TODO rmtItem[0].level0 = rmtConfig.tx_config.idle_level; @@ -644,8 +664,9 @@ void initRMT() #endif #ifdef C_STEP_PIN - rmt_set_source_clk( (rmt_channel_t)C_RMT_CHANNEL, RMT_BASECLK_APB); - rmtConfig.channel = (rmt_channel_t)C_RMT_CHANNEL; + C_rmt_chan_num = sys_get_next_RMT_chan_num(); + rmt_set_source_clk( (rmt_channel_t)C_rmt_chan_num, RMT_BASECLK_APB); + rmtConfig.channel = (rmt_channel_t)C_rmt_chan_num; rmtConfig.tx_config.idle_level = bit_istrue(settings.step_invert_mask, C_AXIS) ? RMT_IDLE_LEVEL_HIGH : RMT_IDLE_LEVEL_LOW; rmtConfig.gpio_num = C_STEP_PIN; // TODO rmtItem[0].level0 = rmtConfig.tx_config.idle_level; @@ -725,97 +746,117 @@ void set_direction_pins_on(uint8_t onMask) #ifdef X_DIRECTION_PIN digitalWrite(X_DIRECTION_PIN, (onMask & (1<