diff --git a/main/boards/BlackBoxX32_map.h b/main/boards/BlackBoxX32_map.h index 21bac11..e2b7b9c 100644 --- a/main/boards/BlackBoxX32_map.h +++ b/main/boards/BlackBoxX32_map.h @@ -43,65 +43,71 @@ #endif // Stepper Driver Pins -#define STEPPERS_ENABLE_PIN GPIO_NUM_17 +#define STEPPERS_ENABLE_PIN GPIO_NUM_17 -#define X_STEP_PIN GPIO_NUM_12 -#define X_DIRECTION_PIN GPIO_NUM_14 +#define X_STEP_PIN GPIO_NUM_12 +#define X_DIRECTION_PIN GPIO_NUM_14 -#define Y_STEP_PIN GPIO_NUM_27 -#define Y_DIRECTION_PIN GPIO_NUM_26 +#define Y_STEP_PIN GPIO_NUM_27 +#define Y_DIRECTION_PIN GPIO_NUM_26 -#define Z_STEP_PIN GPIO_NUM_15 -#define Z_DIRECTION_PIN GPIO_NUM_2 +#define Z_STEP_PIN GPIO_NUM_15 +#define Z_DIRECTION_PIN GPIO_NUM_2 // Define ganged axis or A axis step pulse and step direction output pins. #if N_ABC_MOTORS > 0 #define M3_AVAILABLE - #define M3_STEP_PIN GPIO_NUM_33 - #define M3_DIRECTION_PIN GPIO_NUM_32 + #define M3_STEP_PIN GPIO_NUM_33 + #define M3_DIRECTION_PIN GPIO_NUM_32 #if N_AUTO_SQUARED // add limit pin definitions to stop compiler complaints (from preprocessor). #if X_AUTO_SQUARE - #define M3_LIMIT_PIN GPIO_NUM_35 // Same as X limit, switched to Z by board code during homing. + #define M3_LIMIT_PIN GPIO_NUM_35 // Same as X limit, switched to Z by board code during homing. #elif Y_AUTO_SQUARE - #define M3_LIMIT_PIN GPIO_NUM_34 // Same as Y limit, switched to Z by board code during homing. + #define M3_LIMIT_PIN GPIO_NUM_34 // Same as Y limit, switched to Z by board code during homing. #else - #define M3_LIMIT_PIN GPIO_NUM_39 // Same as Z limit, switched to X by board code during homing. + #define M3_LIMIT_PIN GPIO_NUM_39 // Same as Z limit, switched to X by board code during homing. #endif #endif #endif // Endstops -#define X_LIMIT_PIN GPIO_NUM_35 -#define Y_LIMIT_PIN GPIO_NUM_34 -#define Z_LIMIT_PIN GPIO_NUM_39 +#define X_LIMIT_PIN GPIO_NUM_35 +#define Y_LIMIT_PIN GPIO_NUM_34 +#define Z_LIMIT_PIN GPIO_NUM_39 -// Define driver spindle pins +#define AUXOUTPUT0_PIN GPIO_NUM_25 // Spindle PWM +#define AUXOUTPUT1_PIN GPIO_NUM_4 // Spindle direction +#define AUXOUTPUT2_PIN GPIO_NUM_13 // Spindle enable +#define AUXOUTPUT3_PIN GPIO_NUM_21 // Coolant flood -#if DRIVER_SPINDLE_PWM_ENABLE -#define SPINDLE_PWM_PIN GPIO_NUM_25 -#else -#define AUXOUTPUT0_PIN GPIO_NUM_25 +// Define driver spindle pins +#if DRIVER_SPINDLE_ENABLE & SPINDLE_PWM +#define SPINDLE_PWM_PIN AUXOUTPUT0_PIN #endif - -#if DRIVER_SPINDLE_DIR_ENABLE -#define SPINDLE_DIRECTION_PIN GPIO_NUM_4 -#else -#define AUXOUTPUT1_PIN GPIO_NUM_4 +#if DRIVER_SPINDLE_ENABLE & SPINDLE_DIR +#define SPINDLE_DIRECTION_PIN AUXOUTPUT1_PIN #endif - -#if DRIVER_SPINDLE_ENABLE -#define SPINDLE_ENABLE_PIN GPIO_NUM_13 -#else -#define AUXOUTPUT2_PIN GPIO_NUM_13 +#if DRIVER_SPINDLE_ENABLE & SPINDLE_ENA +#define SPINDLE_ENABLE_PIN AUXOUTPUT2_PIN #endif // Define flood and mist coolant enable output pins. -// Only one can be enabled! -#define COOLANT_FLOOD_PIN GPIO_NUM_21 // coolant -//#define COOLANT_MIST_PIN GPIO_NUM_21 // or mist +#if COOLANT_ENABLE & COOLANT_FLOOD +#define COOLANT_FLOOD_PIN AUXOUTPUT3_PIN +#endif +#if COOLANT_ENABLE & COOLANT_MIST +#undef COOLANT_ENABLE +#ifdef COOLANT_FLOOD_PIN +#define COOLANT_ENABLE COOLANT_FLOOD +#else +#define COOLANT_ENABLE 0 +#endif +#endif // Define user-control CONTROLs (cycle start, reset, feed hold) input pins. +#undef CONTROL_ENABLE +#define CONTROL_ENABLE 0 // No control inputs #define AUXINPUT0_PIN GPIO_NUM_0 // Mode button on front panel #define AUXINPUT1_PIN GPIO_NUM_16 diff --git a/main/boards/bdring_i2s_6_axis_map.h b/main/boards/bdring_i2s_6_axis_map.h index b675611..4718665 100644 --- a/main/boards/bdring_i2s_6_axis_map.h +++ b/main/boards/bdring_i2s_6_axis_map.h @@ -27,8 +27,7 @@ #error No free pins for I2C keypad! #endif -#define USE_I2S_OUT -#define I2S_OUT_PIN_BASE 64 +#include "use_i2s_out.h" #if SDCARD_ENABLE || TRINAMIC_SPI_ENABLE @@ -89,33 +88,38 @@ #define M5_LIMIT_PIN GPIO_NUM_33 #endif -// Define driver spindle pins +#define AUXOUTPUT0_PIN GPIO_NUM_26 // Spindle PWM +#define AUXOUTPUT1_PIN GPIO_NUM_16 // Spindle direction +#define AUXOUTPUT2_PIN GPIO_NUM_4 // Spindle enable +#define AUXOUTPUT3_PIN GPIO_NUM_2 // Coolant mist -#if DRIVER_SPINDLE_PWM_ENABLE -#define SPINDLE_PWM_PIN GPIO_NUM_26 -#else -#define AUXOUTPUT0_PIN GPIO_NUM_26 +// Define driver spindle pins +#if DRIVER_SPINDLE_ENABLE & SPINDLE_PWM +#define SPINDLE_PWM_PIN AUXOUTPUT0_PIN #endif - -#if DRIVER_SPINDLE_DIR_ENABLE -#define SPINDLE_DIRECTION_PIN GPIO_NUM_16 -#else -#define AUXOUTPUT1_PIN GPIO_NUM_16 +#if DRIVER_SPINDLE_ENABLE & SPINDLE_DIR +#define SPINDLE_DIRECTION_PIN AUXOUTPUT1_PIN #endif - -#if DRIVER_SPINDLE_ENABLE -#define SPINDLE_ENABLE_PIN GPIO_NUM_4 -#else -#define AUXOUTPUT2_PIN GPIO_NUM_4 +#if DRIVER_SPINDLE_ENABLE & SPINDLE_ENA +#define SPINDLE_ENABLE_PIN AUXOUTPUT2_PIN #endif // Define flood and mist coolant enable output pins. - -#define COOLANT_MIST_PIN GPIO_NUM_2 +#if COOLANT_ENABLE & COOLANT_MIST +#define COOLANT_MIST_PIN AUXOUTPUT3_PIN +#endif +#if COOLANT_ENABLE & COOLANT_FLOOD +#undef COOLANT_ENABLE +#ifdef COOLANT_MIST_PIN +#define COOLANT_ENABLE COOLANT_MIST +#else +#define COOLANT_ENABLE 0 +#endif +#endif // Define user-control CONTROLs (cycle start, reset, feed hold) input pins. - -// N/A +#undef CONTROL_ENABLE +#define CONTROL_ENABLE 0 // No control inputs #define AUXINPUT0_PIN GPIO_NUM_25 diff --git a/main/boards/bdring_i2s_6pack_ext_v2_map.h b/main/boards/bdring_i2s_6pack_ext_v2_map.h index 836cf5b..2211be7 100644 --- a/main/boards/bdring_i2s_6pack_ext_v2_map.h +++ b/main/boards/bdring_i2s_6pack_ext_v2_map.h @@ -21,10 +21,9 @@ along with grblHAL. If not, see . */ -#define BOARD_NAME "BDRING 6-Pack External drives V2.0" +#include "use_i2s_out.h" -#define USE_I2S_OUT -#define I2S_OUT_PIN_BASE 64 +#define BOARD_NAME "BDRING 6-Pack External drives V2.0" #if SDCARD_ENABLE @@ -81,30 +80,31 @@ #define M5_STEP_PIN I2SO(21) #define M5_DIRECTION_PIN I2SO(20) #define M5_ENABLE_PIN I2SO(23) -#define M5_LIMIT_PIN GPIO_NUM_34 #endif -// Define driver spindle pins +#define AUXOUTPUT0_PIN GPIO_NUM_26 // Spindle PWM +#define AUXOUTPUT1_PIN GPIO_NUM_16 // Spindle direction +#define AUXOUTPUT2_PIN GPIO_NUM_4 // Spindle enable +#define AUXOUTPUT3_PIN GPIO_NUM_2 // Coolant mist -#if DRIVER_SPINDLE_PWM_ENABLE -#define SPINDLE_PWM_PIN GPIO_NUM_26 +// Define driver spindle pins +#if DRIVER_SPINDLE_ENABLE & SPINDLE_PWM +#define SPINDLE_PWM_PIN AUXOUTPUT0_PIN #endif - -#if DRIVER_SPINDLE_DIR_ENABLE -#define SPINDLE_DIRECTION_PIN GPIO_NUM_16 +#if DRIVER_SPINDLE_ENABLE & SPINDLE_DIR +#define SPINDLE_DIRECTION_PIN AUXOUTPUT1_PIN #endif - -#if DRIVER_SPINDLE_ENABLE -#define SPINDLE_ENABLE_PIN GPIO_NUM_4 +#if DRIVER_SPINDLE_ENABLE & SPINDLE_ENA +#define SPINDLE_ENABLE_PIN AUXOUTPUT2_PIN #endif // Define flood and mist coolant enable output pins. - -//#define COOLANT_MIST_PIN ? +#undef COOLANT_ENABLE +#define COOLANT_ENABLE 0 // No coolant outputs // Define user-control CONTROLs (cycle start, reset, feed hold) input pins. - -// N/A +#undef CONTROL_ENABLE +#define CONTROL_ENABLE 0 // No control inputs #define AUXINPUT0_PIN GPIO_NUM_25 diff --git a/main/boards/bdring_i2s_6x_v1_map.h b/main/boards/bdring_i2s_6x_v1_map.h index f4f24a7..aba38e1 100644 --- a/main/boards/bdring_i2s_6x_v1_map.h +++ b/main/boards/bdring_i2s_6x_v1_map.h @@ -21,10 +21,9 @@ along with grblHAL. If not, see . */ -#define BOARD_NAME "BDRING 6x External Drives V1.1" +#include "use_i2s_out.h" -#define USE_I2S_OUT -#define I2S_OUT_PIN_BASE 64 +#define BOARD_NAME "BDRING 6x External Drives V1.1" #if SDCARD_ENABLE // Pin mapping when using SPI mode. @@ -82,20 +81,26 @@ #define M5_LIMIT_PIN GPIO_NUM_34 #endif -// Define driver spindle pins +#define AUXOUTPUT0_PIN GPIO_NUM_13 // Spindle PWM +#define AUXOUTPUT1_PIN GPIO_NUM_15 // Spindle enable -#if DRIVER_SPINDLE_PWM_ENABLE -#define SPINDLE_PWM_PIN GPIO_NUM_13 -#else -#define AUXOUTPUT0_PIN GPIO_NUM_13 +// Define driver spindle pins +#if DRIVER_SPINDLE_ENABLE & SPINDLE_PWM +#define SPINDLE_PWM_PIN AUXOUTPUT0_PIN #endif - -#if DRIVER_SPINDLE_ENABLE -#define SPINDLE_ENABLE_PIN GPIO_NUM_15 +#if DRIVER_SPINDLE_ENABLE & SPINDLE_ENA +#define SPINDLE_ENABLE_PIN AUXOUTPUT1_PIN #endif -// Define MODBUS spindle pins (exclusive use - can use PWM or modbus since they share output pins) +// Define flood and mist coolant enable output pins. +#undef COOLANT_ENABLE +#define COOLANT_ENABLE 0 // No coolant outputs +// Define user-control CONTROLs (cycle start, reset, feed hold) input pins. +#undef CONTROL_ENABLE +#define CONTROL_ENABLE 0 // No control inputs + +// Define MODBUS spindle pins (exclusive use - can use PWM or modbus since they share output pins) #if MODBUS_ENABLE & MODBUS_RTU_ENABLED #define UART1_RX_PIN GPIO_NUM_16 #define UART1_TX_PIN GPIO_NUM_15 @@ -105,25 +110,17 @@ #endif // If neither PWM nor modbus, gpio14 is aux output - -#if !MODBUS_ENABLE & !DRIVER_SPINDLE_PWM_ENABLE -#define AUXOUTPUT1_PIN GPIO_NUM_14 +#if !MODBUS_ENABLE && !(DRIVER_SPINDLE_ENABLE & SPINDLE_PWM) +#define AUXOUTPUT2_PIN GPIO_NUM_14 #endif +#define AUXINPUT0_PIN GPIO_NUM_2 + // Define probe switch input pin. #if PROBE_ENABLE -#define PROBE_PIN GPIO_NUM_2 +#define PROBE_PIN AUXINPUT0_PIN #endif #if KEYPAD_ENABLE #error No free pins for keypad! #endif - - -// Define flood and mist coolant enable output pins. - -//#define COOLANT_MIST_PIN ? - -// Define user-control CONTROLs (cycle start, reset, feed hold) input pins. - -// N/A diff --git a/main/boards/bdring_v3.5_map.h b/main/boards/bdring_v3.5_map.h index f3c988c..0d68bd6 100644 --- a/main/boards/bdring_v3.5_map.h +++ b/main/boards/bdring_v3.5_map.h @@ -49,23 +49,20 @@ #define Y_LIMIT_PIN GPIO_NUM_4 #define Z_LIMIT_PIN GPIO_NUM_15 -// Define driver spindle pins +#define AUXOUTPUT0_PIN GPIO_NUM_17 // Spindle PWM +#define AUXOUTPUT1_PIN GPIO_NUM_22 // Spindle enable -#if DRIVER_SPINDLE_PWM_ENABLE -#define SPINDLE_PWM_PIN GPIO_NUM_17 -#else -#define AUXOUTPUT0_PIN GPIO_NUM_17 +// Define driver spindle pins +#if DRIVER_SPINDLE_ENABLE & SPINDLE_PWM +#define SPINDLE_PWM_PIN AUXOUTPUT0_PIN #endif - -#if DRIVER_SPINDLE_ENABLE -#define SPINDLE_ENABLE_PIN GPIO_NUM_22 -#else -#define AUXOUTPUT1_PIN GPIO_NUM_22 +#if DRIVER_SPINDLE_ENABLE & SPINDLE_ENA +#define SPINDLE_ENABLE_PIN AUXOUTPUT1_PIN #endif // Define flood and mist coolant enable output pins. - -// N/A +#undef COOLANT_ENABLE +#define COOLANT_ENABLE 0 // No coolant outputs // Define user-control CONTROLs (cycle start, reset, feed hold) input pins. #define RESET_PIN GPIO_NUM_34 diff --git a/main/boards/bdring_v4_map.h b/main/boards/bdring_v4_map.h index 329a266..3f0b0fd 100644 --- a/main/boards/bdring_v4_map.h +++ b/main/boards/bdring_v4_map.h @@ -49,21 +49,34 @@ #define Y_LIMIT_PIN GPIO_NUM_4 #define Z_LIMIT_PIN GPIO_NUM_16 -// Define driver spindle pins - -#if DRIVER_SPINDLE_PWM_ENABLE && !(MODBUS_ENABLE & MODBUS_RTU_ENABLED) -#define SPINDLE_PWM_PIN GPIO_NUM_2 +#define AUXOUTPUT0_PIN GPIO_NUM_2 // Spindle PWM +#define AUXOUTPUT1_PIN GPIO_NUM_22 // Spindle enable +#define AUXOUTPUT2_PIN GPIO_NUM_25 // Coolant flood +#ifndef ADD_SERIAL1 +#define AUXOUTPUT3_PIN GPIO_NUM_21 // Coolant mist #endif -#if DRIVER_SPINDLE_ENABLE && !(MODBUS_ENABLE & MODBUS_RTU_ENABLED) -#define SPINDLE_ENABLE_PIN GPIO_NUM_22 +// Define driver spindle pins +#if DRIVER_SPINDLE_ENABLE & SPINDLE_PWM +#define SPINDLE_PWM_PIN AUXOUTPUT0_PIN +#endif +#if DRIVER_SPINDLE_ENABLE & SPINDLE_ENA +#define SPINDLE_ENABLE_PIN AUXOUTPUT1_PIN #endif // Define flood and mist coolant enable output pins. - -#define COOLANT_FLOOD_PIN GPIO_NUM_25 -#if DRIVER_SPINDLE_ENABLE -#define COOLANT_MIST_PIN GPIO_NUM_21 +#if COOLANT_ENABLE & COOLANT_FLOOD +#define COOLANT_FLOOD_PIN AUXOUTPUT2_PIN +#endif +#if (COOLANT_ENABLE & COOLANT_MIST) && defined(AUXOUTPUT3_PIN) +#define COOLANT_MIST_PIN AUXOUTPUT3_PIN +#else +#undef COOLANT_ENABLE +#ifdef COOLANT_FLOOD_PIN +#define COOLANT_ENABLE COOLANT_FLOOD +#else +#define COOLANT_ENABLE 0 +#endif #endif // Define user-control CONTROLs (cycle start, reset, feed hold) input pins. diff --git a/main/boards/btt_rodent_map.h b/main/boards/btt_rodent_map.h index 3f24fa9..5bf0328 100644 --- a/main/boards/btt_rodent_map.h +++ b/main/boards/btt_rodent_map.h @@ -21,10 +21,6 @@ along with grblHAL. If not, see . */ -#define BOARD_NAME "BTT Rodent" -#define BOARD_URL "https://github.com/bigtreetech/Rodent/tree/master" -// https://bttwiki.com/Rodent.html - #if N_ABC_MOTORS > 2 #error "Axis configuration is not supported!" #endif @@ -34,13 +30,16 @@ #endif #if TRINAMIC_ENABLE != 5160 -#error BOARD_BTT_RODENT has soldered TMC2160 drivers. +//#error BOARD_BTT_RODENT has soldered TMC2160 drivers. #endif -//#define TRINAMIC_MIXED_DRIVERS 0 Uncomment when board verified +#include "use_i2s_out.h" -#define USE_I2S_OUT -#define I2S_OUT_PIN_BASE 64 +#define BOARD_NAME "BTT Rodent" +#define BOARD_URL "https://github.com/bigtreetech/Rodent/tree/master" +// https://bttwiki.com/Rodent.html + +//#define TRINAMIC_MIXED_DRIVERS 0 Uncomment when board verified #define I2S_OUT_BCK GPIO_NUM_22 #define I2S_OUT_WS GPIO_NUM_17 @@ -78,34 +77,35 @@ #define M4_ENABLE_PIN I2SO(16) #define M4_LIMIT_PIN GPIO_NUM_37 #endif -// Define driver spindle pins -#if DRIVER_SPINDLE_PWM_ENABLE -#define SPINDLE_PWM_PIN GPIO_NUM_13 -#else -#define AUXOUTPUT1_PIN GPIO_NUM_13 -#endif +#define AUXOUTPUT0_PIN GPIO_NUM_25 // Spindle enable +#define AUXOUTPUT1_PIN GPIO_NUM_13 // Spindle PWM +#define AUXOUTPUT2_PIN GPIO_NUM_15 // Spindle direction +#define AUXOUTPUT3_PIN GPIO_NUM_2 // Coolant flood +#define AUXOUTPUT4_PIN GPIO_NUM_4 // Coolant mist -#if DRIVER_SPINDLE_DIR_ENABLE -#define SPINDLE_DIRECTION_PIN GPIO_NUM_15 -#else -#define AUXOUTPUT3_PIN GPIO_NUM_15 +// Define driver spindle pins +#if DRIVER_SPINDLE_ENABLE & SPINDLE_PWM +#define SPINDLE_PWM_PIN AUXOUTPUT1_PIN #endif - -#if DRIVER_SPINDLE_ENABLE -#define SPINDLE_ENABLE_PIN GPIO_NUM_25 -#else -#define AUXOUTPUT4_PIN GPIO_NUM_25 +#if DRIVER_SPINDLE_ENABLE & SPINDLE_DIR +#define SPINDLE_DIRECTION_PIN AUXOUTPUT2_PIN +#endif +#if DRIVER_SPINDLE_ENABLE & SPINDLE_ENA +#define SPINDLE_ENABLE_PIN AUXOUTPUT0_PIN #endif // Define flood and mist coolant enable output pins. - -#define COOLANT_MIST_PIN GPIO_NUM_2 -#define COOLANT_FLOOD_PIN GPIO_NUM_4 +#if COOLANT_ENABLE & COOLANT_FLOOD +#define COOLANT_FLOOD_PIN AUXOUTPUT3_PIN +#endif +#if COOLANT_ENABLE & COOLANT_MIST +#define COOLANT_MIST_PIN AUXOUTPUT4_PIN +#endif // Define user-control CONTROLs (cycle start, reset, feed hold) input pins. - -// N/A +#undef CONTROL_ENABLE +#define CONTROL_ENABLE 0 // No control inputs #define AUXINPUT0_PIN GPIO_NUM_36 diff --git a/main/boards/cnc3040_map.h b/main/boards/cnc3040_map.h index 99c1ccb..b6e7f28 100644 --- a/main/boards/cnc3040_map.h +++ b/main/boards/cnc3040_map.h @@ -65,27 +65,30 @@ #define M3_DIRECTION_PIN GPIO_NUM_4 #endif -// Define driver spindle pins +#define AUXOUTPUT0_PIN GPIO_NUM_2 // Spindle enable +#define AUXOUTPUT1_PIN GPIO_NUM_21 // Spindle PWM +#define AUXOUTPUT2_PIN GPIO_NUM_22 // Coolant flood +#define AUXOUTPUT3_PIN GPIO_NUM_23 // Coolant mist -#if DRIVER_SPINDLE_PWM_ENABLE -#define SPINDLE_PWM_PIN GPIO_NUM_21 -#else -#define AUXOUTPUT0_PIN GPIO_NUM_21 +// Define driver spindle pins +#if DRIVER_SPINDLE_ENABLE & SPINDLE_PWM +#define SPINDLE_PWM_PIN AUXOUTPUT1_PIN #endif - #if DRIVER_SPINDLE_ENABLE -#define SPINDLE_ENABLE_PIN GPIO_NUM_2 -#else -#define AUXOUTPUT1_PIN GPIO_NUM_2 +#define SPINDLE_ENABLE_PIN AUXOUTPUT0_PIN #endif // Define flood and mist coolant enable output pins. - -#define COOLANT_FLOOD_PIN GPIO_NUM_22 -#define COOLANT_MIST_PIN GPIO_NUM_23 +#if COOLANT_ENABLE & COOLANT_FLOOD +#define COOLANT_FLOOD_PIN AUXOUTPUT2_PIN +#endif +#if COOLANT_ENABLE & COOLANT_MIST +#define COOLANT_MIST_PIN AUXOUTPUT3_PIN +#endif // Define user-control CONTROLs (cycle start, reset, feed hold) input pins. -// N/A +#undef CONTROL_ENABLE +#define CONTROL_ENABLE 0 // No control inputs #define AUXINPUT0_PIN GPIO_NUM_35 // ATC Door #define AUXINPUT1_PIN GPIO_NUM_25 diff --git a/main/boards/cnc_boosterpack_map.h b/main/boards/cnc_boosterpack_map.h index d268998..da9f47a 100644 --- a/main/boards/cnc_boosterpack_map.h +++ b/main/boards/cnc_boosterpack_map.h @@ -66,25 +66,26 @@ #define Y_LIMIT_PIN GPIO_NUM_16 #define Z_LIMIT_PIN GPIO_NUM_32 -// Define driver spindle pins - -#if DRIVER_SPINDLE_PWM_ENABLE -#define SPINDLE_PWM_PIN GPIO_NUM_17 -#else #define AUXOUTPUT0_PIN GPIO_NUM_17 -#endif - -#if DRIVER_SPINDLE_DIR_ENABLE -#define SPINDLE_DIRECTION_PIN IOEXPAND -#endif +// Define driver spindle pins #if DRIVER_SPINDLE_ENABLE #define SPINDLE_ENABLE_PIN IOEXPAND #endif +#if DRIVER_SPINDLE_ENABLE & SPINDLE_PWM +#define SPINDLE_PWM_PIN AUXOUTPUT0_PIN +#endif +#if DRIVER_SPINDLE_ENABLE & SPINDLE_DIR +#define SPINDLE_DIRECTION_PIN IOEXPAND +#endif // Define flood and mist coolant enable output pins. +#if COOLANT_ENABLE & COOLANT_FLOOD #define COOLANT_FLOOD_PIN IOEXPAND +#endif +#if COOLANT_ENABLE & COOLANT_MIST #define COOLANT_MIST_PIN IOEXPAND +#endif #ifdef ADD_SERIAL1 #define SERIAL1_PORT @@ -131,9 +132,6 @@ //#define AUXOUTPUT0_PIN GPIO_NUM_25 #endif -#define NEOPIXELS_NUM 2 -#define NEOPIXELS_PIN GPIO_NUM_25 - // Define I2C port/pins #define I2C_PORT I2C_NUM_1 #define I2C_SDA GPIO_NUM_21 diff --git a/main/boards/cnc_boosterpack_s3_map.h b/main/boards/cnc_boosterpack_s3_map.h index cfa269f..b31e470 100644 --- a/main/boards/cnc_boosterpack_s3_map.h +++ b/main/boards/cnc_boosterpack_s3_map.h @@ -66,19 +66,21 @@ #define Y_LIMIT_PIN GPIO_NUM_16 #define Z_LIMIT_PIN GPIO_NUM_32 +#define AUXOUTPUT0_PIN GPIO_NUM_25 // Spindle enable +#define AUXOUTPUT1_PIN GPIO_NUM_17 // Spindle PWM +#define AUXOUTPUT2_PIN GPIO_NUM_15 // Spindle direction +#define AUXOUTPUT3_PIN GPIO_NUM_2 // Coolant flood +#define AUXOUTPUT4_PIN GPIO_NUM_4 // Coolant mist + // Define driver spindle pins -#if DRIVER_SPINDLE_PWM_ENABLE +#if DRIVER_SPINDLE_ENABLE & SPINDLE_PWM #define SPINDLE_PWM_PIN GPIO_NUM_17 -#else -#define AUXOUTPUT0_PIN GPIO_NUM_17 #endif - -#if DRIVER_SPINDLE_DIR_ENABLE +#if DRIVER_SPINDLE_ENABLE & SPINDLE_DIR #define SPINDLE_DIRECTION_PIN IOEXPAND #endif - -#if DRIVER_SPINDLE_ENABLE +#if DRIVER_SPINDLE_ENABLE & SPINDLE_ENA #define SPINDLE_ENABLE_PIN IOEXPAND #endif diff --git a/main/boards/espduino-32_wemos_d1_r32_uno_map.h b/main/boards/espduino-32_wemos_d1_r32_uno_map.h index e4ea45e..b9a14c0 100644 --- a/main/boards/espduino-32_wemos_d1_r32_uno_map.h +++ b/main/boards/espduino-32_wemos_d1_r32_uno_map.h @@ -57,23 +57,36 @@ #define Y_LIMIT_PIN GPIO_NUM_5 #define Z_LIMIT_PIN GPIO_NUM_23 +#define AUXOUTPUT0_PIN GPIO_NUM_19 // Spindle PWM +#define AUXOUTPUT1_PIN GPIO_NUM_18 // Spindle enable +#if !(MODBUS_ENABLE & MODBUS_RTU_ENABLED) +#define AUXOUTPUT2_PIN GPIO_NUM_32 // Coolant flood +#endif + // Define driver spindle pins +#if DRIVER_SPINDLE_ENABLE & SPINDLE_PWM +#define SPINDLE_PWM_PIN AUXOUTPUT0_PIN +#endif +#if DRIVER_SPINDLE_ENABLE & SPINDLE_ENA +#define SPINDLE_ENABLE_PIN AUXOUTPUT1_PIN +#endif -#if DRIVER_SPINDLE_PWM_ENABLE -#define SPINDLE_PWM_PIN GPIO_NUM_19 +// Define flood and mist coolant enable output pins. +#if (COOLANT_ENABLE & COOLANT_MIST) +#undef COOLANT_ENABLE +#ifdef AUXOUTPUT2_PIN +#define COOLANT_ENABLE COOLANT_FLOOD #else -#define AUXOUTPUT0_PIN GPIO_NUM_19 +#define COOLANT_ENABLE 0 #endif - -#if DRIVER_SPINDLE_ENABLE -#define SPINDLE_ENABLE_PIN GPIO_NUM_18 +#endif +#if (COOLANT_ENABLE & COOLANT_FLOOD) +#ifdef AUXOUTPUT2_PIN +#define COOLANT_FLOOD_PIN AUXOUTPUT2_PIN #else -#define AUXOUTPUT1_PIN GPIO_NUM_18 +#undef COOLANT_ENABLE +#define COOLANT_ENABLE 0 #endif - -// Define flood enable output pin. -#if !(MODBUS_ENABLE & MODBUS_RTU_ENABLED) -#define COOLANT_FLOOD_PIN GPIO_NUM_32 #endif // Define user-control CONTROLs (cycle start, reset, feed hold) input pins. diff --git a/main/boards/fysetc_e4_map.h b/main/boards/fysetc_e4_map.h index d9597c0..1c8efd9 100644 --- a/main/boards/fysetc_e4_map.h +++ b/main/boards/fysetc_e4_map.h @@ -59,29 +59,30 @@ //#define M3_LIMIT_PIN GPIO_NUM_36 #endif -// Define driver spindle pins +#define AUXOUTPUT0_PIN GPIO_NUM_13 // Spindle PWM +#define AUXOUTPUT1_PIN GPIO_NUM_4 // Spindle enable +#define AUXOUTPUT2_PIN GPIO_NUM_2 // Coolant flood -#if DRIVER_SPINDLE_PWM_ENABLE -#define SPINDLE_PWM_PIN GPIO_NUM_13 -#else -#define AUXOUTPUT0_PIN GPIO_NUM_13 +// Define driver spindle pins +#if DRIVER_SPINDLE_ENABLE & SPINDLE_PWM +#define SPINDLE_PWM_PIN AUXOUTPUT0_PIN #endif - -#if DRIVER_SPINDLE_DIR_ENABLE -//#define SPINDLE_DIRECTION_PIN GPIO_NUM_5 -#else -//#define AUXOUTPUT2_PIN GPIO_NUM_5 +#if DRIVER_SPINDLE_ENABLE & SPINDLE_ENA +#define SPINDLE_ENABLE_PIN AUXOUTPUT1_PIN #endif -#if DRIVER_SPINDLE_ENABLE -#define SPINDLE_ENABLE_PIN GPIO_NUM_4 +// Define flood and mist coolant enable output pins. +#if COOLANT_ENABLE & COOLANT_FLOOD +#define COOLANT_FLOOD_PIN AUXOUTPUT2_PIN +#endif +#if COOLANT_ENABLE & COOLANT_MIST +#undef COOLANT_ENABLE +#ifdef COOLANT_FLOOD_PIN +#define COOLANT_ENABLE COOLANT_FLOOD #else -#define AUXOUTPUT1_PIN GPIO_NUM_4 +#define COOLANT_ENABLE 0 +#endif #endif - -// Define flood and mist coolant enable output pins. - -#define COOLANT_FLOOD_PIN GPIO_NUM_2 // Define user-control CONTROLs (cycle start, reset, feed hold) input pins. #define RESET_PIN GPIO_NUM_34 diff --git a/main/boards/generic_i2s_s3_map.h b/main/boards/generic_i2s_s3_map.h index 4edd482..ee0f05e 100644 --- a/main/boards/generic_i2s_s3_map.h +++ b/main/boards/generic_i2s_s3_map.h @@ -25,15 +25,14 @@ #error "This board has ESP32-S3 processor, select a corresponding build!" #endif +#include "use_i2s_out.h" + #define BOARD_NAME "Generic I2S ESP32-S3" #if KEYPAD_ENABLE == 1 #error No free pins for I2C keypad! #endif -#define USE_I2S_OUT -#define I2S_OUT_PIN_BASE 64 - #if SDCARD_ENABLE || TRINAMIC_SPI_ENABLE // Pin mapping when using SPI mode. @@ -93,34 +92,34 @@ #define M5_LIMIT_PIN GPIO_NUM_33 #endif -// Define driver spindle pins +#define AUXOUTPUT0_PIN GPIO_NUM_26 // Spindle PWM +#define AUXOUTPUT1_PIN GPIO_NUM_4 // Spindle enable +#define AUXOUTPUT2_PIN GPIO_NUM_16 // Spindle direction +#define AUXOUTPUT3_PIN I2SO(15) // Coolant flood +#define AUXOUTPUT4_PIN I2SO(12) // Coolant mist -#if DRIVER_SPINDLE_PWM_ENABLE -#define SPINDLE_PWM_PIN GPIO_NUM_26 -#else -#define AUXOUTPUT0_PIN GPIO_NUM_26 +// Define driver spindle pins +#if DRIVER_SPINDLE_ENABLE & SPINDLE_PWM +#define SPINDLE_PWM_PIN AUXOUTPUT0_PIN #endif - -#if DRIVER_SPINDLE_DIR_ENABLE -#define SPINDLE_DIRECTION_PIN GPIO_NUM_16 -#else -#define AUXOUTPUT1_PIN GPIO_NUM_16 +#if DRIVER_SPINDLE_ENABLE & SPINDLE_DIR +#define SPINDLE_DIRECTION_PIN AUXOUTPUT2_PIN #endif - -#if DRIVER_SPINDLE_ENABLE -#define SPINDLE_ENABLE_PIN GPIO_NUM_4 -#else -#define AUXOUTPUT2_PIN GPIO_NUM_4 +#if DRIVER_SPINDLE_ENABLE & SPINDLE_ENA +#define SPINDLE_ENABLE_PIN AUXOUTPUT1_PIN #endif // Define flood and mist coolant enable output pins. - -#define COOLANT_FLOOD_PIN I2SO(15) -#define COOLANT_MIST_PIN I2SO(12) +#if COOLANT_ENABLE & COOLANT_FLOOD +#define COOLANT_FLOOD_PIN AUXOUTPUT3_PIN +#endif +#if COOLANT_ENABLE & COOLANT_MIST +#define COOLANT_MIST_PIN AUXOUTPUT4_PIN +#endif // Define user-control CONTROLs (cycle start, reset, feed hold) input pins. - -// N/A +#undef CONTROL_ENABLE +#define CONTROL_ENABLE 0 // No control inputs #if TRINAMIC_SPI_ENABLE #define MOTOR_CS_PIN I2SO(3) diff --git a/main/boards/generic_map.h b/main/boards/generic_map.h index f6f416b..b4c3b1f 100644 --- a/main/boards/generic_map.h +++ b/main/boards/generic_map.h @@ -49,37 +49,30 @@ #define Y_LIMIT_PIN GPIO_NUM_4 #define Z_LIMIT_PIN GPIO_NUM_15 -#if DRIVER_SPINDLE_ENABLE -// Define spindle enable and spindle direction output pins. -#define SPINDLE_ENABLE_PIN GPIO_NUM_18 -#define SPINDLE_DIRECTION_PIN GPIO_NUM_5 -#define SPINDLEPWMPIN GPIO_NUM_17 -#endif +#define AUXOUTPUT0_PIN GPIO_NUM_17 // Spindle PWM +#define AUXOUTPUT1_PIN GPIO_NUM_18 // Spindle enable +#define AUXOUTPUT2_PIN GPIO_NUM_5 // Spindle direction +#define AUXOUTPUT3_PIN GPIO_NUM_16 // Coolant flood +#define AUXOUTPUT4_PIN GPIO_NUM_21 // Coolant mist // Define driver spindle pins - -#if DRIVER_SPINDLE_PWM_ENABLE -#define SPINDLE_PWM_PIN GPIO_NUM_17 -#else -#define AUXOUTPUT0_PIN GPIO_NUM_17 +#if DRIVER_SPINDLE_ENABLE & SPINDLE_PWM +#define SPINDLE_PWM_PIN AUXOUTPUT0_PIN #endif - -#if DRIVER_SPINDLE_DIR_ENABLE -#define SPINDLE_DIRECTION_PIN GPIO_NUM_5 -#else -#define AUXOUTPUT1_PIN GPIO_NUM_5 +#if DRIVER_SPINDLE_ENABLE & SPINDLE_DIR +#define SPINDLE_DIRECTION_PIN AUXOUTPUT2_PIN #endif - -#if DRIVER_SPINDLE_ENABLE -#define SPINDLE_ENABLE_PIN GPIO_NUM_18 -#else -#define AUXOUTPUT2_PIN GPIO_NUM_18 +#if DRIVER_SPINDLE_ENABLE & SPINDLE_ENA +#define SPINDLE_ENABLE_PIN AUXOUTPUT1_PIN #endif // Define flood and mist coolant enable output pins. - -#define COOLANT_FLOOD_PIN GPIO_NUM_16 -#define COOLANT_MIST_PIN GPIO_NUM_21 +#if COOLANT_ENABLE & COOLANT_FLOOD +#define COOLANT_FLOOD_PIN AUXOUTPUT3_PIN +#endif +#if COOLANT_ENABLE & COOLANT_MIST +#define COOLANT_MIST_PIN AUXOUTPUT4_PIN +#endif // Define user-control CONTROLs (cycle start, reset, feed hold) input pins. #define RESET_PIN GPIO_NUM_34 diff --git a/main/boards/generic_s3_map.h b/main/boards/generic_s3_map.h index e0cc670..569a943 100644 --- a/main/boards/generic_s3_map.h +++ b/main/boards/generic_s3_map.h @@ -55,31 +55,30 @@ #define Y_LIMIT_PIN GPIO_NUM_6 #define Z_LIMIT_PIN GPIO_NUM_7 -// Define driver spindle pins -#if DRIVER_SPINDLE_ENABLE - -#define SPINDLE_ENABLE_PIN GPIO_NUM_46 +#define AUXOUTPUT0_PIN GPIO_NUM_47 // Spindle PWM +#define AUXOUTPUT1_PIN GPIO_NUM_46 // Spindle enable +#define AUXOUTPUT2_PIN GPIO_NUM_45 // Spindle direction +#define AUXOUTPUT3_PIN GPIO_NUM_16 // Coolant flood +#define AUXOUTPUT4_PIN GPIO_NUM_15 // Coolant mist -#if DRIVER_SPINDLE_PWM_ENABLE -#define SPINDLE_PWM_PIN GPIO_NUM_47 -#else -#define AUXOUTPUT0_PIN GPIO_NUM_47 +// Define driver spindle pins +#if DRIVER_SPINDLE_ENABLE & SPINDLE_PWM +#define SPINDLE_PWM_PIN AUXOUTPUT0_PIN #endif - -#if DRIVER_SPINDLE_DIR_ENABLE -#define SPINDLE_DIRECTION_PIN GPIO_NUM_45 -#else -#define AUXOUTPUT1_PIN GPIO_NUM_45 +#if DRIVER_SPINDLE_ENABLE & SPINDLE_DIR +#define SPINDLE_DIRECTION_PIN AUXOUTPUT2_PIN +#endif +#if DRIVER_SPINDLE_ENABLE & SPINDLE_ENA +#define SPINDLE_ENABLE_PIN AUXOUTPUT1_PIN #endif - -#else -#define AUXOUTPUT2_PIN GPIO_NUM_46 -#endif // DRIVER_SPINDLE_ENABLE // Define flood and mist coolant enable output pins. - -#define COOLANT_FLOOD_PIN GPIO_NUM_16 -#define COOLANT_MIST_PIN GPIO_NUM_15 +#if COOLANT_ENABLE & COOLANT_FLOOD +#define COOLANT_FLOOD_PIN AUXOUTPUT3_PIN +#endif +#if COOLANT_ENABLE & COOLANT_MIST +#define COOLANT_MIST_PIN AUXOUTPUT4_PIN +#endif // Define user-control CONTROLs (cycle start, reset, feed hold) input pins. #if !SDCARD_ENABLE diff --git a/main/boards/jackpot_map.h b/main/boards/jackpot_map.h index 88f30f8..0c0efaf 100644 --- a/main/boards/jackpot_map.h +++ b/main/boards/jackpot_map.h @@ -21,6 +21,8 @@ along with grblHAL. If not, see . */ +#include "use_i2s_out.h" + #define BOARD_NAME "Jackpot" #define BOARD_URL "https://docs.v1e.com/electronics/jackpot/" @@ -28,9 +30,6 @@ #error No free pins for I2C keypad! #endif -#define USE_I2S_OUT -#define I2S_OUT_PIN_BASE 64 - #define I2S_OUT_BCK GPIO_NUM_22 #define I2S_OUT_WS GPIO_NUM_17 #define I2S_OUT_DATA GPIO_NUM_21 @@ -80,36 +79,35 @@ #define M5_UART_CS I2SO(22) #endif -// Define driver spindle pins - #define AUXOUTPUT0_PIN GPIO_NUM_27 +#define AUXOUTPUT1_PIN GPIO_NUM_26 // Spindle PWM +#define AUXOUTPUT2_PIN GPIO_NUM_4 // Spindle enable +#define AUXOUTPUT3_PIN GPIO_NUM_16 // Spindle direction +#define AUXOUTPUT4_PIN GPIO_NUM_2 // Coolant flood +#define AUXOUTPUT5_PIN GPIO_NUM_16 // Coolant mist -#if DRIVER_SPINDLE_PWM_ENABLE -#define SPINDLE_PWM_PIN GPIO_NUM_26 -#else -#define AUXOUTPUT1_PIN GPIO_NUM_26 +// Define driver spindle pins +#if DRIVER_SPINDLE1_ENABLE & SPINDLE_PWM +#define SPINDLE_PWM_PIN AUXOUTPUT1_PIN #endif - -#if DRIVER_SPINDLE_DIR_ENABLE -#define SPINDLE_DIRECTION_PIN GPIO_NUM_16 -#else -#define AUXOUTPUT3_PIN GPIO_NUM_16 +#if DRIVER_SPINDLE_ENABLE & SPINDLE_DIR +#define SPINDLE_DIRECTION_PIN AUXOUTPUT3_PIN #endif - -#if DRIVER_SPINDLE_ENABLE -#define SPINDLE_ENABLE_PIN GPIO_NUM_4 -#else -#define AUXOUTPUT4_PIN GPIO_NUM_4 +#if DRIVER_SPINDLE_ENABLE & SPINDLE_ENA +#define SPINDLE_ENABLE_PIN AUXOUTPUT2_PIN #endif // Define flood and mist coolant enable output pins. - -#define COOLANT_MIST_PIN GPIO_NUM_16 -#define COOLANT_FLOOD_PIN GPIO_NUM_2 +#if COOLANT_ENABLE & COOLANT_FLOOD +#define COOLANT_FLOOD_PIN AUXOUTPUT4_PIN +#endif +#if COOLANT_ENABLE & COOLANT_MIST +#define COOLANT_MIST_PIN AUXOUTPUT5_PIN +#endif // Define user-control CONTROLs (cycle start, reset, feed hold) input pins. - -// N/A +#undef CONTROL_ENABLE +#define CONTROL_ENABLE 0 // No control inputs #define AUXINPUT0_PIN GPIO_NUM_36 diff --git a/main/boards/mks_dlc32_2_0_map.h b/main/boards/mks_dlc32_2_0_map.h index b291bff..febe024 100644 --- a/main/boards/mks_dlc32_2_0_map.h +++ b/main/boards/mks_dlc32_2_0_map.h @@ -26,11 +26,12 @@ #error "Board BOARD_MKS_DLC32_V2P0 does not have support for VFD spindle." #endif +#include "use_i2s_out.h" + #define BOARD_NAME "MKS DLC32 2.x" #define BOARD_URL "https://github.com/makerbase-mks/MKS-DLC32" -#define USE_I2S_OUT -#define I2S_OUT_PIN_BASE 64 +#define AUX_CONTROLS_OUT #if SDCARD_ENABLE @@ -67,32 +68,44 @@ #error "Board BOARD_MKS_DLC32_V2P0 does not have support for ABC Motors" #endif -// Define driver spindle pins - -#if DRIVER_SPINDLE_PWM_ENABLE -#define SPINDLE_PWM_PIN GPIO_NUM_32 -#else -#if DRIVER_SPINDLE_ENABLE -#define AUXOUTPUT4_PIN GPIO_NUM_27 +#define AUXOUTPUT0_PIN GPIO_NUM_25 // EXP_1,7 (LCD_CS_0) +#if PWM_SERVO_ENABLE || (SPINDLE_ENABLE & ((1<. */ +#include "use_i2s_out.h" + #define BOARD_NAME "MKS Tinybee V1.0" #define BOARD_URL "https://github.com/makerbase-mks/MKS-TinyBee" @@ -33,9 +35,6 @@ #error "No free pins for I2C keypad!" #endif -#define USE_I2S_OUT -#define I2S_OUT_PIN_BASE 64 - #define SERIAL1_PORT // RX: 16, TX: 17 #define I2S_OUT_BCK GPIO_NUM_25 @@ -87,32 +86,32 @@ #endif #endif -#define AUXINPUT0_PIN GPIO_NUM_39 // TB +#define AUXOUTPUT0_PIN GPIO_NUM_2 // Spindle PWM +#define AUXOUTPUT1_PIN I2SO(18) // Spindle direction, HE1 +#define AUXOUTPUT2_PIN I2SO(17) // Spindle enable, HE0 +#define AUXOUTPUT3_PIN I2SO(19) // Coolant flood, FAN1 +#define AUXOUTPUT4_PIN I2SO(20) // Coolant mist, FAN2 // Define driver spindle pins - -#if DRIVER_SPINDLE_PWM_ENABLE -#define SPINDLE_PWM_PIN GPIO_NUM_2 -#else -#define AUXOUTPUT0_PIN GPIO_NUM_2 +#if DRIVER_SPINDLE_ENABLE & SPINDLE_PWM +#define SPINDLE_PWM_PIN AUXOUTPUT0_PIN #endif - -#if DRIVER_SPINDLE_DIR_ENABLE -#define SPINDLE_DIRECTION_PIN I2SO(18) // HE1 -#else -#define AUXOUTPUT1_PIN I2SO(18) // HE1 +#if DRIVER_SPINDLE_ENABLE & SPINDLE_DIR +#define SPINDLE_DIRECTION_PIN AUXOUTPUT1_PIN #endif - -#if DRIVER_SPINDLE_ENABLE -#define SPINDLE_ENABLE_PIN I2SO(17) // HE0 -#else -#define AUXOUTPUT2_PIN I2SO(17) // HE0 +#if DRIVER_SPINDLE_ENABLE & SPINDLE_ENA +#define SPINDLE_ENABLE_PIN AUXOUTPUT2_PIN #endif // Define flood and mist coolant enable output pins. +#if COOLANT_ENABLE & COOLANT_FLOOD +#define COOLANT_FLOOD_PIN AUXOUTPUT3_PIN +#endif +#if COOLANT_ENABLE & COOLANT_MIST +#define COOLANT_MIST_PIN AUXOUTPUT4_PIN +#endif -#define COOLANT_FLOOD_PIN I2SO(19) // FAN1 -#define COOLANT_MIST_PIN I2SO(20) // FAN2 +#define AUXINPUT0_PIN GPIO_NUM_39 // TB // Define user-control CONTROLs (cycle start, reset, feed hold) input pins. #define CYCLE_START_PIN GPIO_NUM_36 // TH1 @@ -120,7 +119,7 @@ //#define RESET_PIN (use board hardware) // Define probe switch input pin. -#if PROBE_ENABLE +#if PROBE_ENABLE && defined(AUXINPUT1_PIN) #define PROBE_PIN AUXINPUT1_PIN // MT_DET #endif diff --git a/main/boards/protoneer_3.xx_map.h b/main/boards/protoneer_3.xx_map.h index 15dc044..74078d1 100644 --- a/main/boards/protoneer_3.xx_map.h +++ b/main/boards/protoneer_3.xx_map.h @@ -57,24 +57,26 @@ #define Y_LIMIT_PIN GPIO_NUM_5 // D10 #define Z_LIMIT_PIN GPIO_NUM_23 // D11 -// Define driver spindle pins +#define AUXOUTPUT0_PIN GPIO_NUM_19 // Spindle PWM +#define AUXOUTPUT1_PIN GPIO_NUM_18 // Spindle enable +#define AUXOUTPUT2_PIN GPIO_NUM_34 // Coolant flood, A3 +#define AUXOUTPUT3_PIN GPIO_NUM_36 // Coolant mist, A4 -#if DRIVER_SPINDLE_PWM_ENABLE // D12 -#define SPINDLE_PWM_PIN GPIO_NUM_19 -#else -#define AUXOUTPUT0_PIN GPIO_NUM_19 +// Define driver spindle pins +#if DRIVER_SPINDLE_ENABLE & SPINDLE_PWM +#define SPINDLE_PWM_PIN AUXOUTPUT0_PIN #endif - -#if DRIVER_SPINDLE_ENABLE // D13 -#define SPINDLE_ENABLE_PIN GPIO_NUM_18 -#else -#define AUXOUTPUT1_PIN GPIO_NUM_18 +#if DRIVER_SPINDLE_ENABLE & SPINDLE_ENA +#define SPINDLE_ENABLE_PIN AUXOUTPUT1_PIN #endif // Define flood and mist coolant enable output pins. - -#define COOLANT_FLOOD_PIN GPIO_NUM_34 // A3 -#define COOLANT_MIST_PIN GPIO_NUM_36 // A4 +#if COOLANT_ENABLE & COOLANT_FLOOD +#define COOLANT_FLOOD_PIN AUXOUTPUT2_PIN +#endif +#if COOLANT_ENABLE & COOLANT_MIST +#define COOLANT_MIST_PIN AUXOUTPUT3_PIN +#endif // Define user-control CONTROLs (cycle start, reset, feed hold) input pins. #define RESET_PIN GPIO_NUM_2 // A0 diff --git a/main/boards/root_cnc_pro_map.h b/main/boards/root_cnc_pro_map.h index 61730e1..6671f4a 100644 --- a/main/boards/root_cnc_pro_map.h +++ b/main/boards/root_cnc_pro_map.h @@ -23,9 +23,6 @@ along with grblHAL. If not, see . */ -#define BOARD_NAME "Root CNC Pro" -#define BOARD_URL "https://wiki.rootcnc.com/en/Root-Controller-pro/DetailedInfo" - #if KEYPAD_ENABLE == 1 #error No free pins for I2C keypad! #endif @@ -34,8 +31,10 @@ #error BOARD_ROOTCNC_PRO has soldered TMC5160 drivers. #endif -#define USE_I2S_OUT -#define I2S_OUT_PIN_BASE 64 +#include "use_i2s_out.h" + +#define BOARD_NAME "Root CNC Pro" +#define BOARD_URL "https://wiki.rootcnc.com/en/Root-Controller-pro/DetailedInfo" #if SDCARD_ENABLE || TRINAMIC_SPI_ENABLE @@ -101,37 +100,39 @@ #define M5_CS_PIN I2SO(18) #endif -// Define driver spindle pins - -#if DRIVER_SPINDLE_PWM_ENABLE -#define SPINDLE_PWM_PIN GPIO_NUM_33 -#else -#define AUXOUTPUT0_PIN GPIO_NUM_33 -#endif - -#if DRIVER_SPINDLE_DIR_ENABLE -#define SPINDLE_DIRECTION_PIN I2SO(0) -#else -#define AUXOUTPUT1_PIN I2SO(0) -#endif - -#if DRIVER_SPINDLE_ENABLE -#define SPINDLE_ENABLE_PIN I2SO(1) -#else -#define AUXOUTPUT2_PIN I2SO(1) -#endif - -// Define flood and mist coolant and aux enable output pins. - -#define COOLANT_MIST_PIN I2SO(20) -#define COOLANT_FLOOD_PIN I2SO(21) #define AUXOUTPUT0_PIN GPIO_NUM_13 #define AUXOUTPUT1_PIN I2SO(5) #define AUXOUTPUT2_PIN I2SO(6) #define AUXOUTPUT3_PIN I2SO(7) #define AUXOUTPUT4_PIN I2SO(3) +#define AUXOUTPUT5_PIN GPIO_NUM_33 // Spindle PWM +#define AUXOUTPUT6_PIN I2SO(0) // Spindle direction +#define AUXOUTPUT7_PIN I2SO(1) // Spindle enable +#define AUXOUTPUT8_PIN I2SO(21) // Coolant flood +#define AUXOUTPUT9_PIN I2SO(20) // Coolant mist + +// Define driver spindle pins +#if DRIVER_SPINDLE_ENABLE & SPINDLE_PWM +#define SPINDLE_PWM_PIN AUXOUTPUT5_PIN +#endif +#if DRIVER_SPINDLE_ENABLE & SPINDLE_DIR +#define SPINDLE_DIRECTION_PIN AUXOUTPUT6_PIN +#endif +#if DRIVER_SPINDLE_ENABLE & SPINDLE_ENA +#define SPINDLE_ENABLE_PIN AUXOUTPUT7_PIN +#endif + +// Define flood and mist coolant enable output pins. +#if COOLANT_ENABLE & COOLANT_FLOOD +#define COOLANT_FLOOD_PIN AUXOUTPUT8_PIN +#endif +#if COOLANT_ENABLE & COOLANT_MIST +#define COOLANT_MIST_PIN AUXOUTPUT9_PIN +#endif // Define user-control CONTROLs (cycle start, reset, feed hold) input pins. +#undef CONTROL_ENABLE +#define CONTROL_ENABLE 0 // No control inputs #define AUXINPUT0_PIN GPIO_NUM_33 #define AUXINPUT1_PIN GPIO_NUM_26 diff --git a/main/boards/root_cnc_v2_map.h b/main/boards/root_cnc_v2_map.h index 405d3e8..fd4e6c8 100644 --- a/main/boards/root_cnc_v2_map.h +++ b/main/boards/root_cnc_v2_map.h @@ -21,6 +21,16 @@ along with grblHAL. If not, see . */ +#if KEYPAD_ENABLE == 1 +#error No free pins for I2C keypad! +#endif + +#if TRINAMIC_ENABLE != 5160 +#error BOARD_ROOTCNC_PRO has soldered TMC5160 drivers. +#endif + +#include "use_i2s_out.h" + #define BOARD_NAME "Root CNC v2.x" #define BOARD_URL "https://wiki.rootcnc.com/en/Root-Controller-ISO/DetailedInfo" @@ -28,9 +38,6 @@ #error No free pins for I2C keypad! #endif -#define USE_I2S_OUT -#define I2S_OUT_PIN_BASE 64 - #if SDCARD_ENABLE || TRINAMIC_SPI_ENABLE // Pin mapping when using SPI mode. @@ -90,34 +97,34 @@ #define M5_LIMIT_PIN GPIO_NUM_14 #endif -// Define driver spindle pins +#define AUXOUTPUT0_PIN GPIO_NUM_25 // Spindle PWM +#define AUXOUTPUT1_PIN I2SO(17) // Spindle direction +#define AUXOUTPUT2_PIN I2SO(16) // Spindle enable +#define AUXOUTPUT3_PIN I2SO(14) // Coolant flood +#define AUXOUTPUT4_PIN I2SO(13) // Coolant mist -#if DRIVER_SPINDLE_PWM_ENABLE -#define SPINDLE_PWM_PIN GPIO_NUM_25 -#else -#define AUXOUTPUT0_PIN GPIO_NUM_25 +// Define driver spindle pins +#if DRIVER_SPINDLE_ENABLE & SPINDLE_PWM +#define SPINDLE_PWM_PIN AUXOUTPUT0_PIN #endif - -#if DRIVER_SPINDLE_DIR_ENABLE -#define SPINDLE_DIRECTION_PIN I2SO(17) -#else -#define AUXOUTPUT1_PIN I2SO(17) +#if DRIVER_SPINDLE_ENABLE & SPINDLE_DIR +#define SPINDLE_DIRECTION_PIN AUXOUTPUT1_PIN #endif - -#if DRIVER_SPINDLE_ENABLE -#define SPINDLE_ENABLE_PIN I2SO(16) -#else -#define AUXOUTPUT2_PIN I2SO(16) +#if DRIVER_SPINDLE_ENABLE & SPINDLE_ENA +#define SPINDLE_ENABLE_PIN AUXOUTPUT2_PIN #endif // Define flood and mist coolant enable output pins. - -#define COOLANT_MIST_PIN I2SO(13) -#define COOLANT_FLOOD_PIN I2SO(14) +#if COOLANT_ENABLE & COOLANT_FLOOD +#define COOLANT_FLOOD_PIN AUXOUTPUT3_PIN +#endif +#if COOLANT_ENABLE & COOLANT_MIST +#define COOLANT_MIST_PIN AUXOUTPUT4_PIN +#endif // Define user-control CONTROLs (cycle start, reset, feed hold) input pins. - -// N/A +#undef CONTROL_ENABLE +#define CONTROL_ENABLE 0 // No control inputs #ifdef ADD_SERIAL1 #define SERIAL1_PORT diff --git a/main/boards/root_cnc_v3_map.h b/main/boards/root_cnc_v3_map.h index cc5be58..5ee1ec2 100644 --- a/main/boards/root_cnc_v3_map.h +++ b/main/boards/root_cnc_v3_map.h @@ -23,15 +23,14 @@ Tested by NEWTech Creative */ -#define BOARD_NAME "Root CNC v3" -#define BOARD_URL "https://wiki.rootcnc.com/en/Root-Controller-ISO/DetailedInfo" - #if KEYPAD_ENABLE == 1 #error No free pins for I2C keypad! #endif -#define USE_I2S_OUT -#define I2S_OUT_PIN_BASE 64 +#include "use_i2s_out.h" + +#define BOARD_NAME "Root CNC v3" +#define BOARD_URL "https://wiki.rootcnc.com/en/Root-Controller-ISO/DetailedInfo" #if SDCARD_ENABLE || TRINAMIC_SPI_ENABLE @@ -92,34 +91,34 @@ #define M5_LIMIT_PIN GPIO_NUM_14 #endif -// Define driver spindle pins +#define AUXOUTPUT0_PIN GPIO_NUM_33 // Spindle PWM +#define AUXOUTPUT1_PIN I2SO(0) // Spindle direction +#define AUXOUTPUT2_PIN I2SO(1) // Spindle enable +#define AUXOUTPUT3_PIN I2SO(22) // Coolant flood +#define AUXOUTPUT4_PIN I2SO(13) // Coolant mist -#if DRIVER_SPINDLE_PWM_ENABLE -#define SPINDLE_PWM_PIN GPIO_NUM_33 -#else -#define AUXOUTPUT0_PIN GPIO_NUM_33 +// Define driver spindle pins +#if DRIVER_SPINDLE_ENABLE & SPINDLE_PWM +#define SPINDLE_PWM_PIN AUXOUTPUT0_PIN #endif - -#if DRIVER_SPINDLE_DIR_ENABLE -#define SPINDLE_DIRECTION_PIN I2SO(0) -#else -#define AUXOUTPUT1_PIN I2SO(0) +#if DRIVER_SPINDLE_ENABLE & SPINDLE_DIR +#define SPINDLE_DIRECTION_PIN AUXOUTPUT1_PIN #endif - -#if DRIVER_SPINDLE_ENABLE -#define SPINDLE_ENABLE_PIN I2SO(1) -#else -#define AUXOUTPUT2_PIN I2SO(1) +#if DRIVER_SPINDLE_ENABLE & SPINDLE_ENA +#define SPINDLE_ENABLE_PIN AUXOUTPUT2_PIN #endif // Define flood and mist coolant enable output pins. - -#define COOLANT_MIST_PIN I2SO(22) -#define COOLANT_FLOOD_PIN I2SO(13) +#if COOLANT_ENABLE & COOLANT_FLOOD +#define COOLANT_FLOOD_PIN AUXOUTPUT3_PIN +#endif +#if COOLANT_ENABLE & COOLANT_MIST +#define COOLANT_MIST_PIN AUXOUTPUT4_PIN +#endif // Define user-control CONTROLs (cycle start, reset, feed hold) input pins. - -// N/A +#undef CONTROL_ENABLE +#define CONTROL_ENABLE 0 // No control inputs #ifdef ADD_SERIAL1 #define SERIAL1_PORT // RX: 16, TX: 17 diff --git a/main/boards/sourcerabbit_4axis.h b/main/boards/sourcerabbit_4axis.h index a52d28c..e1392be 100644 --- a/main/boards/sourcerabbit_4axis.h +++ b/main/boards/sourcerabbit_4axis.h @@ -69,43 +69,60 @@ #define M3_DIRECTION_PIN GPIO_NUM_13 #endif -// Define driver spindle pins +#ifdef BOARD_SOURCERABBIT_4AXIS_12 -#if DRIVER_SPINDLE_PWM_ENABLE -#define SPINDLE_PWM_PIN GPIO_NUM_21 -#else -#define AUXOUTPUT2_PIN GPIO_NUM_21 +#define AUXINPUT1_PIN GPIO_NUM_5 // ATC Door +#define AUXOUTPUT0_PIN GPIO_NUM_19 // ATC Lock +#define AUXOUTPUT1_PIN GPIO_NUM_18 // ATC Blow +#define AUXOUTPUT2_PIN GPIO_NUM_21 // Spindle PWM +#define AUXOUTPUT3_PIN GPIO_NUM_2 // Spindle direction +#define AUXOUTPUT4_PIN GPIO_NUM_22 // Coolant flood +#define AUXOUTPUT5_PIN GPIO_NUM_23 // Coolant mist + +/ Define driver spindle pins +#if DRIVER_SPINDLE_ENABLE & SPINDLE_PWM +#define SPINDLE_PWM_PIN AUXOUTPUT2_PIN +#endif +#if DRIVER_SPINDLE_ENABLE & SPINDLE_DIR +#define SPINDLE_DIRECTION_PIN AUXOUTPUT3_PIN #endif -#ifdef BOARD_SOURCERABBIT_4AXIS_12 -#if DRIVER_SPINDLE_DIR_ENABLE -#define SPINDLE_DIRECTION_PIN GPIO_NUM_2 -#else -#define AUXOUTPUT3_PIN GPIO_NUM_2 +// Define flood and mist coolant enable output pins. +#if COOLANT_ENABLE & COOLANT_FLOOD +#define COOLANT_FLOOD_PIN AUXOUTPUT4_PIN #endif +#if COOLANT_ENABLE & COOLANT_MIST +#define COOLANT_MIST_PIN AUXOUTPUT5_PIN #endif -#ifndef BOARD_SOURCERABBIT_4AXIS_12 -#if DRIVER_SPINDLE_ENABLE -#define SPINDLE_ENABLE_PIN GPIO_NUM_2 #else -#define AUXOUTPUT3_PIN GPIO_NUM_2 -#endif -#endif -#ifdef BOARD_SOURCERABBIT_4AXIS_12 -#define AUXINPUT1_PIN GPIO_NUM_5 // ATC Door -#define AUXOUTPUT0_PIN GPIO_NUM_19 // ATC Lock -#define AUXOUTPUT1_PIN GPIO_NUM_18 // ATC Blow +#define AUXOUTPUT0_PIN GPIO_NUM_21 // Spindle PWM +#define AUXOUTPUT1_PIN GPIO_NUM_2 // Spindle enable +#define AUXOUTPUT3_PIN GPIO_NUM_22 // Coolant flood +#define AUXOUTPUT4_PIN GPIO_NUM_23 // Coolant mist + +// Define driver spindle pins +#if DRIVER_SPINDLE1_ENABLE & SPINDLE_PWM +#define SPINDLE_PWM_PIN AUXOUTPUT0_PIN +#endif +#if DRIVER_SPINDLE_ENABLE & SPINDLE_ENA +#define SPINDLE_ENABLE_PIN AUXOUTPUT1_PIN #endif // Define flood and mist coolant enable output pins. +#if COOLANT_ENABLE & COOLANT_FLOOD +#define COOLANT_FLOOD_PIN AUXOUTPUT3_PIN +#endif +#if COOLANT_ENABLE & COOLANT_MIST +#define COOLANT_MIST_PIN AUXOUTPUT4_PIN +#endif -#define COOLANT_FLOOD_PIN GPIO_NUM_22 -#define COOLANT_MIST_PIN GPIO_NUM_23 +#endif // BOARD_SOURCERABBIT_4AXIS_12 // Define user-control CONTROLs (cycle start, reset, feed hold) input pins. -// N/A +#undef CONTROL_ENABLE +#define CONTROL_ENABLE 0 // No control inputs #define AUXINPUT0_PIN GPIO_NUM_32 diff --git a/main/boards/xPro_v5_map.h b/main/boards/xPro_v5_map.h index 6c37162..2a7ae41 100644 --- a/main/boards/xPro_v5_map.h +++ b/main/boards/xPro_v5_map.h @@ -66,33 +66,63 @@ //#define M3_LIMIT_PIN GPIO_NUM_36 #endif -// Define driver spindle pins +#ifdef ADD_SERIAL1 -#if DRIVER_SPINDLE_PWM_ENABLE -#define SPINDLE_PWM_PIN GPIO_NUM_25 -#define SPINDLE_ENABLE_PIN GPIO_NUM_4 -#elif defined(ADD_SERIAL1) #define SERIAL1_PORT #define UART1_RX_PIN GPIO_NUM_25 #define UART1_TX_PIN GPIO_NUM_4 + +#define AUXOUTPUT0_PIN GPIO_NUM_21 // Coolant mist + +// Define flood and mist coolant enable output pins. +#if COOLANT_ENABLE & COOLANT_MIST +#define COOLANT_MIST_PIN AUXOUTPUT0_PIN +#endif +#if COOLANT_ENABLE & COOLANT_FLOOD +#undef COOLANT_ENABLE +#ifdef COOLANT_MIST_PIN +#define COOLANT_ENABLE COOLANT_MIST #else -#define AUXOUTPUT0_PIN GPIO_NUM_25 -#define AUXOUTPUT1_PIN GPIO_NUM_4 +#define COOLANT_ENABLE 0 +#endif #endif -#define AUXINPUT0_PIN GPIO_NUM_13 -//#define AUXINPUT1_PIN GPIO_NUM_0 -#define AUXINPUT2_PIN GPIO_NUM_22 +#else + +#define AUXOUTPUT0_PIN GPIO_NUM_25 // Spindle PWM +#define AUXOUTPUT1_PIN GPIO_NUM_4 // Spindle enable +#define AUXOUTPUT2_PIN GPIO_NUM_21 // Coolant mist + +// Define driver spindle pins +#if DRIVER_SPINDLE_ENABLE & SPINDLE_PWM +#define SPINDLE_PWM_PIN AUXOUTPUT0_PIN +#endif +#if DRIVER_SPINDLE_ENABLE & SPINDLE_ENA +#define SPINDLE_ENABLE_PIN AUXOUTPUT1_PIN +#endif // Define flood and mist coolant enable output pins. -// Only one can be enabled! +#if COOLANT_ENABLE & COOLANT_MIST +#define COOLANT_MIST_PIN AUXOUTPUT2_PIN +#endif +#if COOLANT_ENABLE & COOLANT_FLOOD +#undef COOLANT_ENABLE +#ifdef COOLANT_MIST_PIN +#define COOLANT_ENABLE COOLANT_MIST +#else +#define COOLANT_ENABLE 0 +#endif +#endif -#define COOLANT_MIST_PIN GPIO_NUM_21 -//#define COOLANT_FLOOD_PIN GPIO_NUM_21 -// Define user-control CONTROLs (cycle start, reset, feed hold) input pins. +#endif // ADD_SERIAL1 +// Define user-control CONTROLs (cycle start, reset, feed hold) input pins. #define RESET_PIN GPIO_NUM_16 +#define AUXINPUT0_PIN GPIO_NUM_13 +//#define AUXINPUT1_PIN GPIO_NUM_0 +#define AUXINPUT2_PIN GPIO_NUM_22 + // Define probe switch input pin. #if PROBE_ENABLE #define PROBE_PIN AUXINPUT2_PIN diff --git a/main/driver.c b/main/driver.c index 7f852f3..11fbb2b 100644 --- a/main/driver.c +++ b/main/driver.c @@ -51,6 +51,9 @@ #include "xtensa/core-macros.h" #define AUX_DEVICES // until all drivers are converted? +#ifndef AUX_CONTROLS +#define AUX_CONTROLS (AUX_CONTROL_SPINDLE|AUX_CONTROL_COOLANT) +#endif #include "grbl/protocol.h" #include "grbl/state_machine.h" @@ -66,10 +69,6 @@ #include "usb_serial.h" #endif -#if USE_I2S_OUT -#include "i2s_out.h" -#endif - #if WIFI_ENABLE #include "wifi.h" #endif @@ -105,43 +104,104 @@ #include "i2c.h" #endif +#if PWM_RAMPED + +#define SPINDLE_RAMP_STEP_INCR 20 // timer compare register change per ramp step +#define SPINDLE_RAMP_STEP_TIME 2 // ms + +typedef struct { + volatile uint32_t ms_cfg; + volatile uint32_t ms_count; + uint32_t pwm_current; + uint32_t pwm_target; + uint32_t pwm_step; +} pwm_ramp_t; + +#endif + +typedef struct { + uint32_t pwm_max_value; + bool pwm_enabled; + spindle_pwm_t spindle_pwm; + ledc_timer_config_t timer; + ledc_channel_config_t channel; +#if PWM_RAMPED + pwm_ramp_t ramp; +#endif + spindle1_pwm_settings_t *config; +} pwm_spindle_t; + #if DRIVER_SPINDLE_ENABLE static spindle_id_t spindle_id = -1; -#if DRIVER_SPINDLE_PWM_ENABLE +#if DRIVER_SPINDLE_ENABLE & SPINDLE_PWM -static uint32_t pwm_max_value; -static bool pwmEnabled = false; -static spindle_pwm_t spindle_pwm; - -static ledc_timer_config_t spindle_pwm_timer = { +static pwm_spindle_t pwm_spindle = { + .pwm_enabled = false, + .timer = { +#if CONFIG_IDF_TARGET_ESP32S3 + .speed_mode = LEDC_LOW_SPEED_MODE, +#else + .speed_mode = LEDC_HIGH_SPEED_MODE, +#endif + .duty_resolution = LEDC_TIMER_10_BIT, + .timer_num = LEDC_TIMER_0, + .freq_hz = 5000 + }, + .channel = { + .gpio_num = SPINDLE_PWM_PIN, #if CONFIG_IDF_TARGET_ESP32S3 - .speed_mode = LEDC_LOW_SPEED_MODE, + .speed_mode = LEDC_SPEED_MODE_MAX, #else - .speed_mode = LEDC_HIGH_SPEED_MODE, + .speed_mode = LEDC_HIGH_SPEED_MODE, #endif - .duty_resolution = LEDC_TIMER_10_BIT, - .timer_num = LEDC_TIMER_0, - .freq_hz = 5000 + .channel = LEDC_CHANNEL_0, + .intr_type = LEDC_INTR_DISABLE, + .timer_sel = LEDC_TIMER_0, + .duty = 0, /*!< LEDC channel duty, the range of duty setting is [0, (2**duty_resolution)] */ + .hpoint = 0 + } }; -static ledc_channel_config_t spindle_pwm_channel = { - .gpio_num = SPINDLE_PWM_PIN, +#endif // DRIVER_SPINDLE_ENABLE & SPINDLE_PWM +#endif // DRIVER_SPINDLE_ENABLE + +#if DRIVER_SPINDLE1_ENABLE + +static spindle_id_t spindle1_id = -1; + +#if DRIVER_SPINDLE1_ENABLE & SPINDLE_PWM + +static pwm_spindle_t pwm_spindle1 = { + .pwm_enabled = false, + .timer = { #if CONFIG_IDF_TARGET_ESP32S3 - .speed_mode = LEDC_SPEED_MODE_MAX, + .speed_mode = LEDC_LOW_SPEED_MODE, #else - .speed_mode = LEDC_HIGH_SPEED_MODE, + .speed_mode = LEDC_HIGH_SPEED_MODE, +#endif + .duty_resolution = LEDC_TIMER_10_BIT, + .timer_num = LEDC_TIMER_1, + .freq_hz = 5000 + }, + .channel = { + .gpio_num = SPINDLE1_PWM_PIN, +#if CONFIG_IDF_TARGET_ESP32S3 + .speed_mode = LEDC_SPEED_MODE_MAX, +#else + .speed_mode = LEDC_HIGH_SPEED_MODE, #endif - .channel = LEDC_CHANNEL_0, - .intr_type = LEDC_INTR_DISABLE, - .timer_sel = LEDC_TIMER_0, - .duty = 0, /*!< LEDC channel duty, the range of duty setting is [0, (2**duty_resolution)] */ - .hpoint = 0 + .channel = LEDC_CHANNEL_1, + .intr_type = LEDC_INTR_DISABLE, + .timer_sel = LEDC_TIMER_1, + .duty = 0, /*!< LEDC channel duty, the range of duty setting is [0, (2**duty_resolution)] */ + .hpoint = 0 + } }; -#endif // DRIVER_SPINDLE_PWM_ENABLE -#endif // DRIVER_SPINDLE_ENABLE +#endif // DRIVER_SPINDLE1_ENABLE & SPINDLE_PWM +#endif // DRIVER_SPINDLE1_ENABLE #include "freertos/FreeRTOS.h" #include "freertos/task.h" @@ -150,22 +210,6 @@ static ledc_channel_config_t spindle_pwm_channel = { // prescale step counter to 20Mhz #define STEPPER_DRIVER_PRESCALER 4 -#if PWM_RAMPED - -#define SPINDLE_RAMP_STEP_INCR 20 // timer compare register change per ramp step -#define SPINDLE_RAMP_STEP_TIME 2 // ms - -typedef struct { - volatile uint32_t ms_cfg; - volatile uint32_t ms_count; - uint32_t pwm_current; - uint32_t pwm_target; - uint32_t pwm_step; -} pwm_ramp_t; - -static pwm_ramp_t pwm_ramp; -#endif - static periph_signal_t *periph_pins = NULL; static input_signal_t inputpin[] = { @@ -330,20 +374,28 @@ static output_signal_t outputpin[] = { #if defined(Z2_ENABLE_PIN) && Z2_ENABLE_PIN != IOEXPAND { .id = Output_StepperEnableZ, .pin = Z2_ENABLE_PIN, .group = PinGroup_StepperEnable }, #endif -#if DRIVER_SPINDLE_ENABLE +#if !(AUX_CONTROLS & AUX_CONTROL_SPINDLE) #if defined(SPINDLE_ENABLE_PIN) && SPINDLE_ENABLE_PIN != IOEXPAND { .id = Output_SpindleOn, .pin = SPINDLE_ENABLE_PIN, .group = PinGroup_SpindleControl }, #endif #if defined(SPINDLE_DIRECTION_PIN) && SPINDLE_DIRECTION_PIN != IOEXPAND { .id = Output_SpindleDir, .pin = SPINDLE_DIRECTION_PIN, .group = PinGroup_SpindleControl }, #endif -#endif // DRIVER_SPINDLE_ENABLE + #if defined(SPINDLE1_ENABLE_PIN) && SPINDLE1_ENABLE_PIN != IOEXPAND + { .id = Output_SpindleOn, .pin = SPINDLE1_ENABLE_PIN, .group = PinGroup_SpindleControl }, + #endif + #if defined(SPINDLE1_DIRECTION_PIN) && SPINDLE1_DIRECTION_PIN != IOEXPAND + { .id = Output_SpindleDir, .pin = SPINDLE1_DIRECTION_PIN, .group = PinGroup_SpindleControl }, + #endif +#endif // AUX_CONTROL_SPINDLE +#if !(AUX_CONTROLS & AUX_CONTROL_COOLANT) #if defined(COOLANT_FLOOD_PIN) && COOLANT_FLOOD_PIN != IOEXPAND { .id = Output_CoolantFlood, .pin = COOLANT_FLOOD_PIN, .group = PinGroup_Coolant }, #endif #if defined(COOLANT_MIST_PIN) && COOLANT_MIST_PIN != IOEXPAND { .id = Output_CoolantMist, .pin = COOLANT_MIST_PIN, .group = PinGroup_Coolant }, #endif +#endif // AUX_CONTROL_COOLANT { .id = Output_DirX, .pin = X_DIRECTION_PIN, .group = PinGroup_StepperDir }, { .id = Output_DirY, .pin = Y_DIRECTION_PIN, .group = PinGroup_StepperDir }, #ifdef Z_DIRECTION_PIN @@ -415,7 +467,13 @@ static output_signal_t outputpin[] = { { .id = Output_Aux6, .pin = AUXOUTPUT6_PIN, .group = PinGroup_AuxOutput }, #endif #ifdef AUXOUTPUT7_PIN - { .id = Output_Aux7, .pin = AUXOUTPUT7_PIN, .group = PinGroup_AuxOutput } + { .id = Output_Aux7, .pin = AUXOUTPUT7_PIN, .group = PinGroup_AuxOutput }, +#endif +#ifdef AUXOUTPUT8_PIN + { .id = Output_Aux8, .pin = AUXOUTPUT8_PIN, .group = PinGroup_AuxOutput }, +#endif +#ifdef AUXOUTPUT9_PIN + { .id = Output_Aux9, .pin = AUXOUTPUT9_PIN, .group = PinGroup_AuxOutput }, #endif #ifdef AUXOUTPUT0_PWM_PIN { .id = Output_Analog_Aux0, .pin = AUXOUTPUT0_PWM_PIN, .group = PinGroup_AuxOutputAnalog, .mode = {PINMODE_PWM} }, @@ -1833,6 +1891,42 @@ static bool aux_claim_explicit (aux_ctrl_t *aux_ctrl) #endif // AUX_CONTROLS_ENABLED +#if AUX_CONTROLS + +bool aux_out_claim_explicit (aux_ctrl_out_t *aux_ctrl) +{ + if(ioport_claim(Port_Digital, Port_Output, &aux_ctrl->aux_port, NULL)) { + ioport_assign_out_function(aux_ctrl, &((output_signal_t *)aux_ctrl->output)->id); + } else + aux_ctrl->aux_port = 0xFF; + + return aux_ctrl->aux_port != 0xFF; +} + +#endif // AUX_CONTROLS + +#if PPI_ENABLE && (DRIVER_SPINDLE_ENABLE || DRIVER_SPINDLE1_ENABLE) + +#include "laser/ppi.h" + +static void (*ppi_spindle_on)(void) = NULL; +static void (*ppi_spindle_off)(void) = NULL; +static spindle_ptrs_t *ppi_spindle = NULL; +static hal_timer_t ppi_timer; + +static void spindlePulseOff (void *context) +{ + ppi_spindle_off(); +} + +static void spindlePulseOn (uint_fast16_t pulse_length) +{ + hal.timer.start(ppi_timer, pulse_length); + ppi_spindle_on(); +} + +#endif // PPI_ENABLE + #if DRIVER_SPINDLE_ENABLE // Static spindle (off, on cw & on ccw) @@ -1884,7 +1978,7 @@ IRAM_ATTR static void spindleSetState (spindle_ptrs_t *spindle, spindle_state_t } } -#if DRIVER_SPINDLE_PWM_ENABLE +#if DRIVER_SPINDLE_ENABLE & SPINDLE_PWM // Variable spindle control functions @@ -1899,30 +1993,30 @@ IRAM_ATTR static void spindleSetSpeed (spindle_ptrs_t *spindle, uint_fast16_t pw spindle_off(); } #if PWM_RAMPED - pwm_ramp.pwm_target = pwm_value; - ledc_set_fade_step_and_start(spindle_pwm_channel.speed_mode, spindle_pwm_channel.channel, pwm_ramp.pwm_target, 1, 4, LEDC_FADE_NO_WAIT); + pwm_spindle.ramp.pwm_target = pwm_value; + ledc_set_fade_step_and_start(pwm_spindle.channel.speed_mode, pwm_spindle.channel.channel, pwm_spindle.ramp.pwm_target, 1, 4, LEDC_FADE_NO_WAIT); #else if(spindle->context.pwm->flags.always_on) { - ledc_set_duty(spindle_pwm_channel.speed_mode, spindle_pwm_channel.channel, spindle->context.pwm->off_value); - ledc_update_duty(spindle_pwm_channel.speed_mode, spindle_pwm_channel.channel); + ledc_set_duty(pwm_spindle.channel.speed_mode, pwm_spindle.channel.channel, spindle->context.pwm->off_value); + ledc_update_duty(pwm_spindle.channel.speed_mode, pwm_spindle.channel.channel); } else - ledc_stop(spindle_pwm_channel.speed_mode, spindle_pwm_channel.channel, spindle->context.pwm->settings->invert.pwm ? 1 : 0); + ledc_stop(pwm_spindle.channel.speed_mode, pwm_spindle.channel.channel, spindle->context.pwm->settings->invert.pwm ? 1 : 0); #endif - pwmEnabled = false; + pwm_spindle.pwm_enabled = false; } else { #if PWM_RAMPED - pwm_ramp.pwm_target = pwm_value; - ledc_set_fade_step_and_start(spindle_pwm_channel.speed_mode, spindle_pwm_channel.channel, pwm_ramp.pwm_target, 1, 4, LEDC_FADE_NO_WAIT); + pwm_spindle.ramp.pwm_target = pwm_value; + ledc_set_fade_step_and_start(pwm_spindle.channel.speed_mode, pwm_spindle.channel.channel, pwm_spindle.ramp.pwm_target, 1, 4, LEDC_FADE_NO_WAIT); #else - ledc_set_duty(spindle_pwm_channel.speed_mode, spindle_pwm_channel.channel, spindle->context.pwm->settings->invert.pwm ? pwm_max_value - pwm_value : pwm_value); - ledc_update_duty(spindle_pwm_channel.speed_mode, spindle_pwm_channel.channel); + ledc_set_duty(pwm_spindle.channel.speed_mode, pwm_spindle.channel.channel, spindle->context.pwm->settings->invert.pwm ? pwm_spindle.pwm_max_value - pwm_value : pwm_value); + ledc_update_duty(pwm_spindle.channel.speed_mode, pwm_spindle.channel.channel); #endif - if(!pwmEnabled) { + if(!pwm_spindle.pwm_enabled) { if(spindle->context.pwm->flags.cloned) spindle_dir(true); else spindle_on(); - pwmEnabled = true; + pwm_spindle.pwm_enabled = true; } } } @@ -1969,40 +2063,52 @@ bool spindleConfig (spindle_ptrs_t *spindle) spindle->esp32_off = spindleOff; spindle->set_state = spindleSetStateVariable; - if(spindle_pwm_timer.freq_hz != (uint32_t)settings.pwm_spindle.pwm_freq) { - spindle_pwm_timer.freq_hz = (uint32_t)settings.pwm_spindle.pwm_freq; - if(spindle_pwm_timer.freq_hz <= 100) { + if(pwm_spindle.timer.freq_hz != (uint32_t)settings.pwm_spindle.pwm_freq) { + pwm_spindle.timer.freq_hz = (uint32_t)settings.pwm_spindle.pwm_freq; + if(pwm_spindle.timer.freq_hz <= 100) { #if SOC_LEDC_TIMER_BIT_WIDE_NUM > 14 - if(spindle_pwm_timer.duty_resolution != LEDC_TIMER_16_BIT) { - spindle_pwm_timer.duty_resolution = LEDC_TIMER_16_BIT; - ledc_timer_config(&spindle_pwm_timer); + if(pwm_spindle.timer.duty_resolution != LEDC_TIMER_16_BIT) { + pwm_spindle.timer.duty_resolution = LEDC_TIMER_16_BIT; + ledc_timer_config(&pwm_spindle.timer); } #else - if(spindle_pwm_timer.duty_resolution != LEDC_TIMER_14_BIT) { - spindle_pwm_timer.duty_resolution = LEDC_TIMER_14_BIT; - ledc_timer_config(&spindle_pwm_timer); + if(pwm_spindle.timer.duty_resolution != LEDC_TIMER_14_BIT) { + pwm_spindle.timer.duty_resolution = LEDC_TIMER_14_BIT; + ledc_timer_config(&pwm_spindle.timer); } #endif - } else if(spindle_pwm_timer.duty_resolution != LEDC_TIMER_10_BIT) { - spindle_pwm_timer.duty_resolution = LEDC_TIMER_10_BIT; - ledc_timer_config(&spindle_pwm_timer); + } else if(pwm_spindle.timer.duty_resolution != LEDC_TIMER_10_BIT) { + pwm_spindle.timer.duty_resolution = LEDC_TIMER_10_BIT; + ledc_timer_config(&pwm_spindle.timer); } } - pwm_max_value = (1UL << spindle_pwm_timer.duty_resolution) - 1; - spindle_pwm.offset = (settings.pwm_spindle.invert.pwm ? -1 : 1); - spindle_precompute_pwm_values(spindle, &spindle_pwm, &settings.pwm_spindle, pwm_max_value * settings.pwm_spindle.pwm_freq); + pwm_spindle.pwm_max_value = (1UL << pwm_spindle.timer.duty_resolution) - 1; + pwm_spindle.spindle_pwm.offset = (settings.pwm_spindle.invert.pwm ? -1 : 1); + spindle_precompute_pwm_values(spindle, &pwm_spindle.spindle_pwm, &settings.pwm_spindle, pwm_spindle.pwm_max_value * settings.pwm_spindle.pwm_freq); - ledc_set_freq(spindle_pwm_timer.speed_mode, spindle_pwm_timer.timer_num, spindle_pwm_timer.freq_hz); + ledc_set_freq(pwm_spindle.timer.speed_mode, pwm_spindle.timer.timer_num, pwm_spindle.timer.freq_hz); + if((pwm_spindle.spindle_pwm.flags.laser_mode_disable = settings.pwm_spindle.flags.laser_mode_disable)) { +#if PPI_ENABLE + if(ppi_spindle == spindle) + ppi_spindle = NULL; + spindle->pulse_on = NULL; + } else if(ppi_timer) { + spindle->pulse_on = spindlePulseOn; + ppi_spindle = spindle; + ppi_spindle_on = spindle_on; + ppi_spindle_off = spindle_off; +#endif + } } else { - if(pwmEnabled) + if(pwm_spindle.pwm_enabled) spindle->set_state(spindle, (spindle_state_t){0}, 0.0f); spindle->esp32_off = spindleOffBasic; spindle->set_state = spindleSetState; } - spindle_update_caps(spindle, spindle->cap.variable ? &spindle_pwm : NULL); + spindle_update_caps(spindle, spindle->cap.variable ? &pwm_spindle.spindle_pwm : NULL); #if USE_I2S_OUT if(spindle->id == spindle_get_default()) @@ -2012,58 +2118,261 @@ bool spindleConfig (spindle_ptrs_t *spindle) return true; } -#if PPI_ENABLE +#endif // DRIVER_SPINDLE_ENABLE & SPINDLE_PWM -#include "laser/ppi.h" +// Returns spindle state in a spindle_state_t variable +static spindle_state_t spindleGetState (spindle_ptrs_t *spindle) +{ + spindle_state_t state = {0}; -static hal_timer_t ppi_timer; + UNUSED(spindle); -static void spindlePulseOff (void *context) +#if IOEXPAND_ENABLE // TODO: read from expander? + state.on = iopins.spindle_on; + state.ccw = iopins.spindle_dir; +#else + #if defined(SPINDLE_ENABLE_PIN) + state.on = DIGITAL_IN(SPINDLE_ENABLE_PIN) != 0; + #endif + #if defined(SPINDLE_DIRECTION_PIN) + state.ccw = DIGITAL_IN(SPINDLE_DIRECTION_PIN) != 0; + #endif +#endif + state.value ^= settings.pwm_spindle.invert.mask; +#if DRIVER_SPINDLE_ENABLE & SPINDLE_PWM + state.on |= pwm_spindle.pwm_enabled; + #if PWM_RAMPED + state.at_speed = ledc_get_duty(pwm_spindle.channel.speed_mode, pwm_spindle.channel.channel) == pwm_spindle.ramp.pwm_target; + #endif +#endif + + return state; +} + +#endif // DRIVER_SPINDLE_ENABLE + +#if DRIVER_SPINDLE1_ENABLE + +// Static spindle (off, on cw & on ccw) +IRAM_ATTR inline static void spindle1_off (void) { - spindle_off(); +#if xIOEXPAND_ENABLE + iopins.spindle_on = settings.pwm_spindle.invert.on ? On : Off; + ioexpand_out(iopins); +#elif defined(SPINDLE1_ENABLE_PIN) + DIGITAL_OUT(SPINDLE1_ENABLE_PIN, pwm_spindle1.config->cfg.invert.on ? 1 : 0); +#endif } -static void spindlePulseOn (uint_fast16_t pulse_length) +IRAM_ATTR static void spindle1OffBasic (spindle_ptrs_t *spindle) { - hal.timer.start(ppi_timer, pulse_length); + UNUSED(spindle); - spindle_on(); + spindle1_off(); } -#endif // PPI_ENABLE +IRAM_ATTR inline static void spindle1_on (void) +{ +#if xIOEXPAND_ENABLE + iopins.spindle_on = settings.pwm_spindle.invert.on ? Off : On; + ioexpand_out(iopins); +#elif defined(SPINDLE_ENABLE_PIN) + DIGITAL_OUT(SPINDLE1_ENABLE_PIN, pwm_spindle1.config->cfg.invert.on ? 0 : 1); +#endif +} + +IRAM_ATTR inline static void spindle1_dir (bool ccw) +{ +#if xIOEXPAND_ENABLE + iopins.spindle_dir = (ccw ^ settings.pwm_spindle.invert.ccw) ? On : Off; + ioexpand_out(iopins); +#elif defined(SPINDLE_DIRECTION_PIN) + DIGITAL_OUT(SPINDLE_DIRECTION_PIN, (ccw ^ pwm_spindle1.config->cfg.invert.ccw) ? 1 : 0); +#endif +} + +// Start or stop spindle +IRAM_ATTR static void spindle1SetState (spindle_ptrs_t *spindle, spindle_state_t state, float rpm) +{ + if(!state.on) + spindle1_off(); + else { + spindle1_dir(state.ccw); + spindle1_on(); + } +} + +#if DRIVER_SPINDLE_ENABLE & SPINDLE_PWM + +// Variable spindle control functions + +// Sets spindle speed +IRAM_ATTR static void spindle1SetSpeed (spindle_ptrs_t *spindle, uint_fast16_t pwm_value) +{ + if(pwm_value == spindle->context.pwm->off_value) { + if(spindle->context.pwm->settings->flags.enable_rpm_controlled) + spindle1_off(); +#if PWM_RAMPED + pwm_spindle1.ramp.pwm_target = pwm_value; + ledc_set_fade_step_and_start(pwm_spindle1.channel.speed_mode, pwm_spindle1.channel.channel, pwm_spindle1.ramp.pwm_target, 1, 4, LEDC_FADE_NO_WAIT); +#else + if(spindle->context.pwm->flags.always_on) { + ledc_set_duty(pwm_spindle1.channel.speed_mode, pwm_spindle1.channel.channel, spindle->context.pwm->off_value); + ledc_update_duty(pwm_spindle1.channel.speed_mode, pwm_spindle1.channel.channel); + } else + ledc_stop(pwm_spindle1.channel.speed_mode, pwm_spindle1.channel.channel, spindle->context.pwm->settings->invert.pwm ? 1 : 0); +#endif + pwm_spindle1.pwm_enabled = false; + } else { +#if PWM_RAMPED + pwm_spindle1.ramp.pwm_target = pwm_value; + ledc_set_fade_step_and_start(pwm_spindle1.channel.speed_mode, pwm_spindle1.channel.channel, pwm_spindle1.ramp.pwm_target, 1, 4, LEDC_FADE_NO_WAIT); +#else + ledc_set_duty(pwm_spindle1.channel.speed_mode, pwm_spindle1.channel.channel, spindle->context.pwm->settings->invert.pwm ? pwm_spindle1.pwm_max_value - pwm_value : pwm_value); + ledc_update_duty(pwm_spindle1.channel.speed_mode, pwm_spindle1.channel.channel); +#endif + if(!pwm_spindle1.pwm_enabled) { + spindle1_on(); + pwm_spindle1.pwm_enabled = true; + } + } +} + +static uint_fast16_t spindle1GetPWM (spindle_ptrs_t *spindle, float rpm) +{ + return spindle->context.pwm->compute_value(spindle->context.pwm, rpm, false); +} + +// Start or stop spindle, variable version -#endif // DRIVER_SPINDLE_PWM_ENABLE +IRAM_ATTR static void spindle1Off (spindle_ptrs_t *spindle) +{ + spindle1_off(); + if(spindle) + spindle1SetSpeed(spindle, spindle->context.pwm->off_value); +} + +IRAM_ATTR static void spindle1SetStateVariable (spindle_ptrs_t *spindle, spindle_state_t state, float rpm) +{ +#ifdef SPINDLE_DIRECTION_PIN + if(state.on || spindle->context.pwm->flags.cloned) + spindl1e_dir(state.ccw); +#endif + if(!spindle->context.pwm->settings->flags.enable_rpm_controlled) { + if(state.on) + spindle1_on(); + else + spindle1_off(); + } + + spindle1SetSpeed(spindle, state.on || (state.ccw && spindle->context.pwm->flags.cloned) + ? spindle->context.pwm->compute_value(spindle->context.pwm, rpm, false) + : spindle->context.pwm->off_value); +} + +bool spindle1Config (spindle_ptrs_t *spindle) +{ + if(spindle == NULL) + return false; + + if((spindle->cap.variable = !pwm_spindle1.config->cfg.flags.pwm_disable && pwm_spindle1.config->cfg.rpm_max > pwm_spindle1.config->cfg.rpm_min)) { + + spindle->esp32_off = spindle1Off; + spindle->set_state = spindle1SetStateVariable; + + if(pwm_spindle1.timer.freq_hz != (uint32_t)pwm_spindle1.config->cfg.pwm_freq) { + pwm_spindle1.timer.freq_hz = (uint32_t)pwm_spindle1.config->cfg.pwm_freq; + if(pwm_spindle1.timer.freq_hz <= 100) { +#if SOC_LEDC_TIMER_BIT_WIDE_NUM > 14 + if(pwm_spindle1.timer.duty_resolution != LEDC_TIMER_16_BIT) { + pwm_spindle1.timer.duty_resolution = LEDC_TIMER_16_BIT; + ledc_timer_config(&pwm_spindle1.timer); + } +#else + if(pwm_spindle1.timer.duty_resolution != LEDC_TIMER_14_BIT) { + pwm_spindle1.timer.duty_resolution = LEDC_TIMER_14_BIT; + ledc_timer_config(&pwm_spindle1.timer); + } +#endif + } else if(pwm_spindle1.timer.duty_resolution != LEDC_TIMER_10_BIT) { + pwm_spindle1.timer.duty_resolution = LEDC_TIMER_10_BIT; + ledc_timer_config(&pwm_spindle1.timer); + } + } + + pwm_spindle1.pwm_max_value = (1UL << pwm_spindle1.timer.duty_resolution) - 1; + pwm_spindle1.spindle_pwm.offset = (pwm_spindle1.config->cfg.invert.pwm ? -1 : 1); + spindle_precompute_pwm_values(spindle, &pwm_spindle1.spindle_pwm, &pwm_spindle1.config->cfg, pwm_spindle1.pwm_max_value * pwm_spindle1.config->cfg.pwm_freq); + + ledc_set_freq(pwm_spindle1.timer.speed_mode, pwm_spindle1.timer.timer_num, pwm_spindle1.timer.freq_hz); + +#if PPI_ENABLE + if(ppi_spindle == NULL && ppi_timer) { + spindle->pulse_on = spindlePulseOn; + ppi_spindle = spindle; + ppi_spindle_on = spindle1_on; + ppi_spindle_off = spindle1_off; + } else if(ppi_spindle != spindle) + spindle->pulse_on = NULL; +#endif + } else { + if(pwm_spindle1.pwm_enabled) + spindle->set_state(spindle, (spindle_state_t){0}, 0.0f); + spindle->esp32_off = spindle1OffBasic; + spindle->set_state = spindle1SetState; + } + + spindle_update_caps(spindle, spindle->cap.variable ? &pwm_spindle1.spindle_pwm : NULL); + +#if USE_I2S_OUT + if(spindle->id == spindle_get_default()) + i2s_set_streaming_mode(!(laser_mode = spindle->cap.laser)); +#endif + + return true; +} + +#endif // DRIVER_SPINDLE1_ENABLE & SPINDLE_PWM // Returns spindle state in a spindle_state_t variable -static spindle_state_t spindleGetState (spindle_ptrs_t *spindle) +static spindle_state_t spindle1GetState (spindle_ptrs_t *spindle) { spindle_state_t state = {0}; UNUSED(spindle); -#if IOEXPAND_ENABLE // TODO: read from expander? +#if xIOEXPAND_ENABLE // TODO: read from expander? state.on = iopins.spindle_on; state.ccw = iopins.spindle_dir; #else - #if defined(SPINDLE_ENABLE_PIN) - state.on = DIGITAL_IN(SPINDLE_ENABLE_PIN) != 0; + #if defined(SPINDLE1_ENABLE_PIN) + state.on = DIGITAL_IN(SPINDLE1_ENABLE_PIN) != 0; #endif #if defined(SPINDLE_DIRECTION_PIN) - state.ccw = DIGITAL_IN(SPINDLE_DIRECTION_PIN) != 0; + state.ccw = DIGITAL_IN(SPINDLE1_DIRECTION_PIN) != 0; #endif #endif - state.value ^= settings.pwm_spindle.invert.mask; -#if DRIVER_SPINDLE_PWM_ENABLE - state.on |= pwmEnabled; + state.value ^= pwm_spindle1.config->cfg.invert.mask; +#if DRIVER_SPINDLE1_ENABLE & SPINDLE_PWM + state.on |= pwm_spindle1.pwm_enabled; #if PWM_RAMPED - state.at_speed = ledc_get_duty(spindle_pwm_channel.speed_mode, spindle_pwm_channel.channel) == pwm_ramp.pwm_target; + state.at_speed = ledc_get_duty(pwm_spindle1.channel.speed_mode, pwm_spindle1.channel.channel) == pwm_spindle1.ramp.pwm_target; #endif #endif return state; } -#endif // DRIVER_SPINDLE_ENABLE +#if DRIVER_SPINDLE1_ENABLE & SPINDLE_PWM + +static void spindle1_settings_changed (spindle1_pwm_settings_t *settings) +{ + spindle1Config(spindle_get_hal(spindle1_id, SpindleHAL_Configured)); +} + +#endif + +#endif // DRIVER_SPINDLE1_ENABLE // Start/stop coolant (and mist if enabled) IRAM_ATTR static void coolantSetState (coolant_state_t mode) @@ -2204,7 +2513,7 @@ static void settings_changed (settings_t *settings, settings_changed_flags_t cha #endif -#if DRIVER_SPINDLE_PWM_ENABLE +#if DRIVER_SPINDLE_ENABLE & SPINDLE_PWM if(changed.spindle) { spindleConfig(spindle_get_hal(spindle_id, SpindleHAL_Configured)); if(spindle_id == spindle_get_default()) @@ -2826,18 +3135,21 @@ static bool driver_setup (settings_t *settings) gpio_isr_register(gpio_isr, NULL, (int)ESP_INTR_FLAG_IRAM, NULL); #endif -#if DRIVER_SPINDLE_PWM_ENABLE +#if PWM_RAMPED + ledc_fade_func_install(ESP_INTR_FLAG_IRAM); +#endif + +#if DRIVER_SPINDLE_ENABLE & SPINDLE_PWM /****************** * Spindle init * ******************/ -#if PWM_RAMPED - ledc_fade_func_install(ESP_INTR_FLAG_IRAM); -#endif - spindle_pwm_channel.speed_mode = spindle_pwm_timer.speed_mode; - ledc_timer_config(&spindle_pwm_timer); - ledc_channel_config(&spindle_pwm_channel); + pwm_spindle.channel.speed_mode = pwm_spindle.timer.speed_mode; + ledc_timer_config(&pwm_spindle.timer); + ledc_channel_config(&pwm_spindle.channel); + + #if !(AUX_CONTROLS & AUX_CONTROL_SPINDLE) static const periph_pin_t pwm = { .function = Output_SpindlePWM, @@ -2848,9 +3160,36 @@ static bool driver_setup (settings_t *settings) hal.periph_port.register_pin(&pwm); + #endif + /**/ -#endif // DRIVER_SPINDLE_PWM_ENABLE +#endif // DRIVER_SPINDLE_ENABLE & SPINDLE_PWM + +#if DRIVER_SPINDLE1_ENABLE & SPINDLE_PWM + + /****************** + * Spindle 1 init * + ******************/ + + pwm_spindle1.channel.speed_mode = pwm_spindle1.timer.speed_mode; + ledc_timer_config(&pwm_spindle1.timer); + ledc_channel_config(&pwm_spindle1.channel); + + #if !(AUX_CONTROLS & AUX_CONTROL_SPINDLE) + + static const periph_pin_t pwm1 = { + .function = Output_SpindlePWM, + .group = PinGroup_SpindlePWM, + .pin = SPINDLE1_PWM_PIN, + .mode = { .mask = PINMODE_OUTPUT } + }; + + hal.periph_port.register_pin(&pwm1); + + #endif + +#endif // DRIVER_SPINDLE1_ENABLE & SPINDLE_PWM #if IOEXPAND_ENABLE ioexpand_init(); @@ -2927,7 +3266,7 @@ bool driver_init (void) #else hal.info = "ESP32"; #endif - hal.driver_version = "241213"; + hal.driver_version = "241215"; hal.driver_url = GRBL_URL "/ESP32"; #ifdef BOARD_NAME hal.board = BOARD_NAME; @@ -3046,11 +3385,11 @@ bool driver_init (void) #if DRIVER_SPINDLE_ENABLE - #if DRIVER_SPINDLE_PWM_ENABLE + #if DRIVER_SPINDLE_ENABLE & SPINDLE_PWM static const spindle_ptrs_t spindle = { .type = SpindleType_PWM, -#if DRIVER_SPINDLE_DIR_ENABLE +#if DRIVER_SPINDLE_ENABLE & SPINDLE_DIR .ref_id = SPINDLE_PWM0, #else .ref_id = SPINDLE_PWM0_NODIR, @@ -3069,7 +3408,7 @@ bool driver_init (void) .variable = On, .laser = On, .pwm_invert = On, - #if IOEXPAND_ENABLE || DRIVER_SPINDLE_DIR_ENABLE + #if IOEXPAND_ENABLE || DRIVER_SPINDLE_ENABLE & SPINDLE_DIR .direction = On, #endif #if PWM_RAMPED @@ -3096,7 +3435,7 @@ bool driver_init (void) static const spindle_ptrs_t spindle = { .type = SpindleType_Basic, -#if DRIVER_SPINDLE_DIR_ENABLE +#if DRIVER_SPINDLE_ENABLE & SPINDLE_DIR .ref_id = SPINDLE_ONOFF0_DIR, #else .ref_id = SPINDLE_ONOFF0, @@ -3106,7 +3445,7 @@ bool driver_init (void) .esp32_off = spindleOffBasic, .cap = { .gpio_controlled = On, - #if IOEXPAND_ENABLE || DRIVER_SPINDLE_DIR_ENABLE + #if IOEXPAND_ENABLE || (DRIVER_SPINDLE_ENABLE & SPINDLE_DIR) .direction = On #endif } @@ -3116,6 +3455,87 @@ bool driver_init (void) spindle_id = spindle_register(&spindle, DRIVER_SPINDLE_NAME); +#endif // DRIVER_SPINDLE_ENABLE + +#if DRIVER_SPINDLE1_ENABLE + + #if DRIVER_SPINDLE1_ENABLE & SPINDLE_PWM + static const spindle_ptrs_t spindle1 = { + .type = SpindleType_PWM, + #if DRIVER_SPINDLE1_ENABLE & SPINDLE_DIR + .ref_id = SPINDLE_PWM1, + #else + .ref_id = SPINDLE_PWM1_NODIR, + #endif + .config = spindle1Config, + .set_state = spindle1SetStateVariable, + .get_state = spindle1GetState, + .get_pwm = spindle1GetPWM, + .update_pwm = spindle1SetSpeed, + .esp32_off = spindle1Off, + #if PPI_ENABLE + .pulse_on = spindlePulseOn, + #endif + .cap = { + .gpio_controlled = On, + .variable = On, + .laser = On, + .pwm_invert = On, + #if IOEXPAND_ENABLE || DRIVER_SPINDLE1_ENABLE & SPINDLE_DIR + .direction = On, + #endif + #if PWM_RAMPED + .at_speed = On + #endif + } + }; + + #if PPI_ENABLE + + static timer_cfg_t cfg1 = { + .single_shot = On, + .timeout_callback = spindlePulseOff + }; + + if((ppi_timer = hal.timer.claim((timer_cap_t){ .periodic = Off }, 1000))) { + hal.timer.configure(ppi_timer, &cfg1); + ppi_init(); + } + + #endif + + if((pwm_spindle1.config = spindle1_settings_add(false))) { + if((spindle1_id = spindle_register(&spindle1, DRIVER_SPINDLE1_NAME)) != -1) + spindle1_settings_register(spindle1.cap, spindle1_settings_changed); + else + protocol_enqueue_foreground_task(report_warning, "PWM2 spindle failed to initialize!"); + } + + #else + + static const spindle_ptrs_t spindle1 = { + .type = SpindleType_Basic, +#if DRIVER_SPINDLE1_ENABLE & SPINDLE_DIR + .ref_id = SPINDLE_ONOFF1_DIR, +#else + .ref_id = SPINDLE_ONOFF1, +#endif + .set_state = spindle1SetState, + .get_state = spindle1GetState, + .esp32_off = spindle1OffBasic, + .cap = { + .gpio_controlled = On, + #if IOEXPAND_ENABLE || (DRIVER_SPINDLE1_ENABLE & SPINDLE_DIR) + .direction = On + #endif + } + }; + + if((pwm_spindle1.config = spindle1_settings_add(false)) && (spindle1_id = spindle_register(&spindle1, DRIVER_SPINDLE1_NAME)) != -1) + spindle1_settings_register(spindle1.cap, NULL); + + #endif + #endif // DRIVER_SPINDLE_ENABLE // driver capabilities, used for announcing and negotiating (with the core) driver functionality @@ -3185,6 +3605,10 @@ bool driver_init (void) if(output->group == PinGroup_AuxOutput) { if(aux_outputs.pins.outputs == NULL) aux_outputs.pins.outputs = output; + output->id = (pin_function_t)(Output_Aux0 + aux_outputs.n_pins); +#if AUX_CONTROLS + aux_out_remap_explicit(NULL, output->pin, aux_outputs.n_pins, output); +#endif aux_outputs.n_pins++; } else if(output->group == PinGroup_AuxOutputAnalog) { if(aux_analog_out.pins.outputs == NULL) @@ -3204,6 +3628,10 @@ bool driver_init (void) hal.signals_cap.safety_door_ajar = On; #endif +#if AUX_CONTROLS + aux_ctrl_claim_out_ports(aux_out_claim_explicit, NULL); +#endif + #ifdef LED_PIN neo_config.clk_div = 2; diff --git a/main/driver.h b/main/driver.h index 14d1046..c2739c1 100644 --- a/main/driver.h +++ b/main/driver.h @@ -235,12 +235,7 @@ extern SemaphoreHandle_t i2cBusy; #define I2S_OUT_PIN_BASE 64 #endif -#ifdef USE_I2S_OUT -#undef USE_I2S_OUT -#define USE_I2S_OUT 1 -#define DIGITAL_IN(pin) (pin >= I2S_OUT_PIN_BASE ? i2s_out_state(pin - I2S_OUT_PIN_BASE) : gpio_ll_get_level(&GPIO, pin)) -#define DIGITAL_OUT(pin, state) { if(pin >= I2S_OUT_PIN_BASE) i2s_out_write(pin - I2S_OUT_PIN_BASE, state); else gpio_ll_set_level(&GPIO, pin, state); } -#else +#ifndef USE_I2S_OUT #define USE_I2S_OUT 0 #define DIGITAL_IN(pin) gpio_ll_get_level(&GPIO, pin) #define DIGITAL_OUT(pin, state) gpio_ll_set_level(&GPIO, pin, (state)) diff --git a/main/ioports.c b/main/ioports.c index 025d0b6..931e5ba 100644 --- a/main/ioports.c +++ b/main/ioports.c @@ -28,10 +28,6 @@ #include "grbl/protocol.h" #include "grbl/settings.h" -#if USE_I2S_OUT -#include "i2s_out.h" -#endif - static io_ports_data_t digital; static input_signal_t *aux_in; static output_signal_t *aux_out; diff --git a/main/tmc_spi.c b/main/tmc_spi.c index 8a7525e..151f471 100644 --- a/main/tmc_spi.c +++ b/main/tmc_spi.c @@ -27,7 +27,6 @@ #include #include "spi.h" -#include "i2s_out.h" #include "grbl/protocol.h" #include "grbl/settings.h" diff --git a/main/tmc_uart.c b/main/tmc_uart.c index 81e0f47..c8d1f0e 100644 --- a/main/tmc_uart.c +++ b/main/tmc_uart.c @@ -25,10 +25,6 @@ #include -#if USE_I2S_OUT -#include "i2s_out.h" -#endif - static io_stream_t tmc_uart = {0}; TMC_uart_write_datagram_t *tmc_uart_read (trinamic_motor_t driver, TMC_uart_read_datagram_t *dgr) diff --git a/main/use_i2s_out.h b/main/use_i2s_out.h new file mode 100644 index 0000000..b25932f --- /dev/null +++ b/main/use_i2s_out.h @@ -0,0 +1,33 @@ +/* + use_i2s_out.h - An embedded CNC Controller with rs274/ngc (g-code) support + + Driver code for ESP32 + + Part of grblHAL + + Copyright (c) 2024 Terje Io + + grblHAL 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. + + grblHAL 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. + + You should have received a copy of the GNU General Public License + along with grblHAL. If not, see . +*/ + +#pragma once + +#define USE_I2S_OUT 1 + +#include "i2s_out.h" + +#define DIGITAL_IN(pin) (pin >= I2S_OUT_PIN_BASE ? i2s_out_state(pin - I2S_OUT_PIN_BASE) : gpio_ll_get_level(&GPIO, pin)) +#define DIGITAL_OUT(pin, state) { if(pin >= I2S_OUT_PIN_BASE) i2s_out_write(pin - I2S_OUT_PIN_BASE, state); else gpio_ll_set_level(&GPIO, pin, state); } + +/**/