From c36e32f03c753ae39ab2c72bbb3034d19cf08935 Mon Sep 17 00:00:00 2001 From: Terje Io Date: Fri, 19 Apr 2024 21:43:18 +0200 Subject: [PATCH] Updated Root CNC v3 map and added Root CNC Pro map. Ref. issue #102. Added missing comma. Ref. ioSender issue 367. Added tentative support for additional I2C API functions. --- driver.json | 17 +++- main/boards/root_cnc_pro_map.h | 151 +++++++++++++++++++++++++++++++++ main/boards/root_cnc_v3_map.h | 8 +- main/driver.h | 2 + main/i2c.c | 49 +++++++++-- main/my_machine.h | 1 + main/uart_serial.c | 2 +- 7 files changed, 220 insertions(+), 10 deletions(-) create mode 100644 main/boards/root_cnc_pro_map.h diff --git a/driver.json b/driver.json index 333f27b..e65ce47 100644 --- a/driver.json +++ b/driver.json @@ -223,7 +223,6 @@ }, { "name": "Root CNC v3", - "notes": "Not tested!", "symbol": "BOARD_ROOTCNC_V3", "URL": "https://wiki.rootcnc.com/en/Root-Controller-ISO/DetailedInfo", "MAP": "main/boards/root_cnc_v3_map.h", @@ -237,6 +236,22 @@ "bluetooth": 1 } }, + { + "name": "Root CNC PRO", + "notes": "For verification!", + "symbol": "BOARD_ROOTCNC_PRO", + "URL": "https://wiki.rootcnc.com/en/Root-Controller-pro/DetailedInfo", + "MAP": "main/boards/root_cnc_pro_map.h", + "caps": { + "axes": 6, + "digital_in": 1, + "serial_ports": 2, + "estop": 0, + "sdcard": 1, + "wifi": 1, + "bluetooth": 1 + } + }, { "name": "CNC 3040", "symbol": "BOARD_CNC3040", diff --git a/main/boards/root_cnc_pro_map.h b/main/boards/root_cnc_pro_map.h new file mode 100644 index 0000000..1336ca6 --- /dev/null +++ b/main/boards/root_cnc_pro_map.h @@ -0,0 +1,151 @@ +/* + root_cnc_pro_map.h - An embedded CNC Controller with rs274/ngc (g-code) support + + Driver code for ESP32 + + Part of grblHAL + + Copyright (c) 2024 NEWTech Creative 2024 + + 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 . +*/ + +#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 + +#define USE_I2S_OUT +#define I2S_OUT_PIN_BASE 64 + +// timer definitions +#define STEP_TIMER_GROUP TIMER_GROUP_0 +#define STEP_TIMER_INDEX TIMER_0 + +#if SDCARD_ENABLE || TRINAMIC_SPI_ENABLE + +// Pin mapping when using SPI mode. +// With this mapping, SD card can be used both in SPI and 1-line SD mode. +#define PIN_NUM_MISO 19 +#define PIN_NUM_MOSI 23 +#define PIN_NUM_CLK 18 +#if SDCARD_ENABLE +// Note that a pull-up on CS line is required in SD mode. +#define PIN_NUM_CS 5 +#endif // SDCARD_ENABLE +#endif // SDCARD_ENABLE || TRINAMIC_SPI_ENABLE + +#define I2S_OUT_BCK GPIO_NUM_22 +#define I2S_OUT_WS GPIO_NUM_21 +#define I2S_OUT_DATA GPIO_NUM_12 + +#define X_STEP_PIN I2SO(1) +#define X_DIRECTION_PIN I2SO(0) +#define X_ENABLE_PIN I2SO(15) +#define X_LIMIT_PIN GPIO_NUM_36 + +#define Y_STEP_PIN I2SO(21) +#define Y_DIRECTION_PIN I2SO(20) +#define Y_ENABLE_PIN I2SO(19) +#define Y_LIMIT_PIN GPIO_NUM_32 + +#define Z_STEP_PIN I2SO(29) +#define Z_DIRECTION_PIN I2SO(28) +#define Z_ENABLE_PIN I2SO(27) +#define Z_LIMIT_PIN GPIO_NUM_36 + +// Define ganged axis or A axis step pulse and step direction output pins. +#if N_ABC_MOTORS >= 1 +#define M3_AVAILABLE +#define M3_STEP_PIN I2SO(13) +#define M3_DIRECTION_PIN I2SO(12) +#define M3_ENABLE_PIN I2SO(11) +#define M3_LIMIT_PIN GPIO_NUM_35 +#endif + +// Define ganged axis or B axis step pulse and step direction output pins. +#if N_ABC_MOTORS >= 2 +#define M4_AVAILABLE +#define M4_STEP_PIN I2SO(9) +#define M4_DIRECTION_PIN I2SO(8) +#define M4_ENABLE_PIN I2SO(23) +#define M4_LIMIT_PIN GPIO_NUM_34 +#endif + +// Define ganged axis or B axis step pulse and step direction output pins. +#if N_ABC_MOTORS == 3 +#define M5_AVAILABLE +#define M5_STEP_PIN I2SO(17) +#define M5_DIRECTION_PIN I2SO(16) +#define M5_ENABLE_PIN I2SO(31) +#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 user-control CONTROLs (cycle start, reset, feed hold) input pins. + +#define AUXINPUT0_PIN GPIO_NUM_33 +#define AUXINPUT1_PIN GPIO_NUM_26 +#define AUXINPUT2_PIN GPIO_NUM_2 + +#if PROBE_ENABLE + #define PROBE_PIN AUXINPUT0_PIN +#endif + +#if SAFETY_DOOR_ENABLE + #define SAFETY_DOOR_PIN AUXINPUT1_PIN +#endif + +#if CYCLE_START_ENABLE + #define SAFETY_DOOR_PIN AUXINPUT2_PIN +#endif +// N/A + +#ifdef ADD_SERIAL2 +#define UART2_RX_PIN GPIO_NUM_16 +#define UART2_TX_PIN GPIO_NUM_17 +#if MODBUS_ENABLE & MODBUS_RTU_DIR_ENABLED +#define MODBUS_DIRECTION_PIN GPIO_NUM_4 +#endif +#endif diff --git a/main/boards/root_cnc_v3_map.h b/main/boards/root_cnc_v3_map.h index 4bff6ad..9f5640c 100644 --- a/main/boards/root_cnc_v3_map.h +++ b/main/boards/root_cnc_v3_map.h @@ -19,6 +19,8 @@ You should have received a copy of the GNU General Public License along with grblHAL. If not, see . + + Tested by NEWTech Creative */ #define BOARD_NAME "Root CNC v3" @@ -49,7 +51,7 @@ #endif // SDCARD_ENABLE || TRINAMIC_SPI_ENABLE #define I2S_OUT_BCK GPIO_NUM_22 -#define I2S_OUT_WS GPIO_NUM_17 +#define I2S_OUT_WS GPIO_NUM_21 #define I2S_OUT_DATA GPIO_NUM_12 #define X_STEP_PIN I2SO(7) @@ -116,8 +118,8 @@ // Define flood and mist coolant enable output pins. -#define COOLANT_MIST_PIN I2SO(20) -#define COOLANT_FLOOD_PIN I2SO(21) +#define COOLANT_MIST_PIN I2SO(22) +#define COOLANT_FLOOD_PIN I2SO(13) // Define user-control CONTROLs (cycle start, reset, feed hold) input pins. diff --git a/main/driver.h b/main/driver.h index 8e71edf..cc6f1b4 100644 --- a/main/driver.h +++ b/main/driver.h @@ -142,6 +142,8 @@ typedef struct { #include "boards/root_cnc_v2_map.h" #elif defined(BOARD_ROOTCNC_V3) #include "boards/root_cnc_v3_map.h" +#elif defined(BOARD_ROOTCNC_PRO) + #include "boards/root_cnc_pro_map.h" #elif defined(BOARD_BLOX) #include "boards/blox_map.h" #elif defined(BOARD_CNC3040) diff --git a/main/i2c.c b/main/i2c.c index 1288211..e6cd5b4 100644 --- a/main/i2c.c +++ b/main/i2c.c @@ -3,20 +3,20 @@ Part of grblHAL driver for ESP32 - Copyright (c) 2018-2023 Terje Io + Copyright (c) 2018-2024 Terje Io - Grbl is free software: you can redistribute it and/or modify + 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. - Grbl is distributed in the hope that it will be useful, + 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 + 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 Grbl. If not, see . + along with grblHAL. If not, see . */ #include "i2c.h" @@ -124,6 +124,45 @@ void I2CInit (void) } } +bool i2c_probe (uint_fast16_t i2c_address) +{ + esp_err_t ret = ESP_FAIL; + + if(i2cBusy != NULL && xSemaphoreTake(i2cBusy, 5 / portTICK_PERIOD_MS) == pdTRUE) { + i2c_cmd_handle_t cmd = i2c_cmd_link_create(); + i2c_master_start(cmd); + i2c_master_write_byte(cmd, (i2c_address << 1)|I2C_MASTER_WRITE, true); + i2c_master_stop(cmd); + ret = i2c_master_cmd_begin(I2C_PORT, cmd, 1000 / portTICK_PERIOD_MS); + i2c_cmd_link_delete(cmd); + + xSemaphoreGive(i2cBusy); + } + + return ret == ESP_OK; +} + +bool i2c_send (uint_fast16_t i2c_address, uint8_t *data, size_t size, bool block) +{ + esp_err_t ret = ESP_FAIL; + + // always blocking... TODO: post non-blocking to I2CTask() + + if(i2cBusy != NULL && xSemaphoreTake(i2cBusy, 5 / portTICK_PERIOD_MS) == pdTRUE) { + i2c_cmd_handle_t cmd = i2c_cmd_link_create(); + i2c_master_start(cmd); + i2c_master_write_byte(cmd, (i2c_address << 1)|I2C_MASTER_WRITE, true); + i2c_master_write(cmd, data, size, true); + i2c_master_stop(cmd); + ret = i2c_master_cmd_begin(I2C_PORT, cmd, 1000 / portTICK_PERIOD_MS); + i2c_cmd_link_delete(cmd); + + xSemaphoreGive(i2cBusy); + } + + return ret == ESP_OK; +} + void i2c_get_keycode (uint_fast16_t i2cAddr, keycode_callback_ptr callback) { static i2c_task_t i2c_task = { diff --git a/main/my_machine.h b/main/my_machine.h index aa62bf4..b0eeac0 100644 --- a/main/my_machine.h +++ b/main/my_machine.h @@ -35,6 +35,7 @@ //#define BOARD_BLACKBOX_X32 // NOTE: Enable in CMakeLists.txt to set board specific defaults for the core! //#define BOARD_ROOTCNC_V2 // //#define BOARD_ROOTCNC_V3 // +#define BOARD_ROOTCNC_PRO // //#define BOARD_JACKPOT // Uses TMC2209 drivers, untested! //#define BOARD_CNC_BOOSTERPACK // //#define BOARD_GENERIC_I2S_S3 // Generic map for ESP32-S3 with I2S shift registers for I/O expansion diff --git a/main/uart_serial.c b/main/uart_serial.c index 0acc511..ca83fba 100644 --- a/main/uart_serial.c +++ b/main/uart_serial.c @@ -144,7 +144,7 @@ static io_stream_properties_t serial[] = { .flags.rx_only = On, #endif .claim = serial2Init - } + }, #endif // SERIAL2_ENABLE #if SERIAL3_ENABLE {