diff --git a/driver.json b/driver.json
index 0b90787..f44cb61 100644
--- a/driver.json
+++ b/driver.json
@@ -304,7 +304,7 @@
"URL": "https://docs.v1e.com/electronics/jackpot/",
"MAP": "main/boards/jackpot_map.h",
"caps": {
- "axes": 4,
+ "axes": 6,
"digital_in": 0,
"digital_out": 1,
"serial_ports": 2,
diff --git a/main/CMakeLists.txt b/main/CMakeLists.txt
index 3a3a8a7..4ed475d 100644
--- a/main/CMakeLists.txt
+++ b/main/CMakeLists.txt
@@ -179,7 +179,7 @@ set(NETWORKING_SOURCE
set(TRINAMIC_SPI_SOURCE
spi.c
- trinamic_if.c
+ tmc_spi.c
motors/trinamic.c
trinamic/common.c
trinamic/tmc_interface.c
@@ -192,7 +192,7 @@ set(TRINAMIC_SPI_SOURCE
)
set(TRINAMIC_UART_SOURCE
- trinamic_if.c
+ tmc_uart.c
motors/trinamic.c
trinamic/common.c
trinamic/tmc_interface.c
diff --git a/main/boards/BlackBoxX32_map.h b/main/boards/BlackBoxX32_map.h
index e56ed58..21bac11 100644
--- a/main/boards/BlackBoxX32_map.h
+++ b/main/boards/BlackBoxX32_map.h
@@ -42,10 +42,6 @@
#define HAS_BOARD_INIT
#endif
-// timer definitions
-#define STEP_TIMER_GROUP TIMER_GROUP_0
-#define STEP_TIMER_INDEX TIMER_0
-
// Stepper Driver Pins
#define STEPPERS_ENABLE_PIN GPIO_NUM_17
diff --git a/main/boards/bdring_i2s_6_axis_map.h b/main/boards/bdring_i2s_6_axis_map.h
index 70401eb..b675611 100644
--- a/main/boards/bdring_i2s_6_axis_map.h
+++ b/main/boards/bdring_i2s_6_axis_map.h
@@ -30,10 +30,6 @@
#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.
@@ -131,9 +127,10 @@
#define MOTOR_CS_PIN I2SO(3)
#endif
-#ifdef ADD_SERIAL2
-#define UART2_RX_PIN GPIO_NUM_15
-#define UART2_TX_PIN GPIO_NUM_14
+#ifdef ADD_SERIAL1
+#define SERIAL1_PORT
+#define UART1_RX_PIN GPIO_NUM_15
+#define UART1_TX_PIN GPIO_NUM_14
#if MODBUS_ENABLE & MODBUS_RTU_DIR_ENABLED
#define MODBUS_DIRECTION_PIN GPIO_NUM_13
#endif
diff --git a/main/boards/bdring_i2s_6pack_ext_v2_map.h b/main/boards/bdring_i2s_6pack_ext_v2_map.h
index 42375d0..836cf5b 100644
--- a/main/boards/bdring_i2s_6pack_ext_v2_map.h
+++ b/main/boards/bdring_i2s_6pack_ext_v2_map.h
@@ -26,10 +26,6 @@
#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
// Pin mapping when using SPI mode.
@@ -116,9 +112,10 @@
#define PROBE_PIN AUXINPUT0_PIN
#endif
-#ifdef ADD_SERIAL2
-#define UART2_RX_PIN GPIO_NUM_15
-#define UART2_TX_PIN GPIO_NUM_14
+#ifdef ADD_SERIAL1
+#define SERIAL1_PORT
+#define UART1_RX_PIN GPIO_NUM_15
+#define UART1_TX_PIN GPIO_NUM_14
#if MODBUS_ENABLE & MODBUS_RTU_DIR_ENABLED
#define MODBUS_DIRECTION_PIN GPIO_NUM_13
#endif
diff --git a/main/boards/bdring_i2s_6x_v1_map.h b/main/boards/bdring_i2s_6x_v1_map.h
index 838cf62..f4f24a7 100644
--- a/main/boards/bdring_i2s_6x_v1_map.h
+++ b/main/boards/bdring_i2s_6x_v1_map.h
@@ -7,18 +7,18 @@
Copyright (c) 2020-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 .
*/
#define BOARD_NAME "BDRING 6x External Drives V1.1"
@@ -26,10 +26,6 @@
#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
// Pin mapping when using SPI mode.
// With this mapping, SD card can be used both in SPI and 1-line SD mode.
@@ -101,8 +97,8 @@
// Define MODBUS spindle pins (exclusive use - can use PWM or modbus since they share output pins)
#if MODBUS_ENABLE & MODBUS_RTU_ENABLED
-#define UART2_RX_PIN GPIO_NUM_16
-#define UART2_TX_PIN GPIO_NUM_15
+#define UART1_RX_PIN GPIO_NUM_16
+#define UART1_TX_PIN GPIO_NUM_15
#if MODBUS_ENABLE & MODBUS_RTU_DIR_ENABLED
#define MODBUS_DIRECTION_PIN GPIO_NUM_14
#endif
@@ -130,4 +126,4 @@
// Define user-control CONTROLs (cycle start, reset, feed hold) input pins.
-// N/A
\ No newline at end of file
+// N/A
diff --git a/main/boards/bdring_v3.5_map.h b/main/boards/bdring_v3.5_map.h
index 54d2363..f3c988c 100644
--- a/main/boards/bdring_v3.5_map.h
+++ b/main/boards/bdring_v3.5_map.h
@@ -31,10 +31,6 @@
#define BOARD_NAME "BDRING v3.5"
-// timer definitions
-#define STEP_TIMER_GROUP TIMER_GROUP_0
-#define STEP_TIMER_INDEX TIMER_0
-
// Define step pulse output pins.
#define X_STEP_PIN GPIO_NUM_12
#define Y_STEP_PIN GPIO_NUM_14
diff --git a/main/boards/bdring_v4_map.h b/main/boards/bdring_v4_map.h
index 675f06b..329a266 100644
--- a/main/boards/bdring_v4_map.h
+++ b/main/boards/bdring_v4_map.h
@@ -31,10 +31,6 @@
#define BOARD_NAME "BDRING v4"
-// timer definitions
-#define STEP_TIMER_GROUP TIMER_GROUP_0
-#define STEP_TIMER_INDEX TIMER_0
-
// Define step pulse output pins.
#define X_STEP_PIN GPIO_NUM_12
#define Y_STEP_PIN GPIO_NUM_26
@@ -96,9 +92,10 @@
#define PIN_NUM_CS GPIO_NUM_5
#endif
-#ifdef ADD_SERIAL2
-#define UART2_RX_PIN GPIO_NUM_22
-#define UART2_TX_PIN GPIO_NUM_21
+#ifdef ADD_SERIAL1
+#define SERIAL1_PORT
+#define UART1_RX_PIN GPIO_NUM_22
+#define UART1_TX_PIN GPIO_NUM_21
#if MODBUS_ENABLE & MODBUS_RTU_DIR_ENABLED
#define MODBUS_DIRECTION_PIN GPIO_NUM_2
#endif
diff --git a/main/boards/btt_rodent_map.h b/main/boards/btt_rodent_map.h
new file mode 100644
index 0000000..90ad2f1
--- /dev/null
+++ b/main/boards/btt_rodent_map.h
@@ -0,0 +1,131 @@
+/*
+ btt_rodent_map.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 .
+*/
+
+#define BOARD_NAME "BTT Rodent"
+#define BOARD_URL "https://github.com/bigtreetech/Rodent/tree/master"
+// https://bttwiki.com/Rodent.html
+
+#if KEYPAD_ENABLE == 1
+#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
+
+#define X_STEP_PIN I2SO(2)
+#define X_DIRECTION_PIN I2SO(1)
+#define X_ENABLE_PIN I2SO(0)
+#define X_LIMIT_PIN GPIO_NUM_35
+
+#define Y_STEP_PIN I2SO(5)
+#define Y_DIRECTION_PIN I2SO(4)
+#define Y_ENABLE_PIN I2SO(7)
+#define Y_LIMIT_PIN GPIO_NUM_34
+
+#define Z_STEP_PIN I2SO(10)
+#define Z_DIRECTION_PIN I2SO(9)
+#define Z_ENABLE_PIN I2SO(8)
+#define Z_LIMIT_PIN GPIO_NUM_33
+
+// 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(15)
+#define M3_LIMIT_PIN GPIO_NUM_32
+#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(18)
+#define M4_DIRECTION_PIN I2SO(17)
+#define M4_ENABLE_PIN I2SO(16)
+#define M4_LIMIT_PIN GPIO_NUM_34
+#endif
+// Define driver spindle pins
+
+#define AUXOUTPUT0_PIN I2SO(11)
+#define AUXOUTPUT0_PIN I2SO(14)
+#define AUXOUTPUT0_PIN I2SO(3)
+
+#if DRIVER_SPINDLE_PWM_ENABLE
+#define SPINDLE_PWM_PIN GPIO_NUM_13
+#else
+#define AUXOUTPUT1_PIN GPIO_NUM_13
+#endif
+
+#if DRIVER_SPINDLE_DIR_ENABLE
+#define SPINDLE_DIRECTION_PIN GPIO_NUM_15
+#else
+#define AUXOUTPUT3_PIN GPIO_NUM_15
+#endif
+
+#if DRIVER_SPINDLE_ENABLE
+#define SPINDLE_ENABLE_PIN GPIO_NUM_25
+#else
+#define AUXOUTPUT4_PIN GPIO_NUM_25
+#endif
+
+// Define flood and mist coolant enable output pins.
+
+#define COOLANT_MIST_PIN GPIO_NUM_2
+#define COOLANT_FLOOD_PIN GPIO_NUM_3
+
+// Define user-control CONTROLs (cycle start, reset, feed hold) input pins.
+
+// N/A
+
+#define AUXINPUT0_PIN GPIO_NUM_5
+
+#if PROBE_ENABLE
+#define PROBE_PIN AUXINPUT0_PIN
+#endif
+
+// Define I2C port/pins
+#define I2C_PORT I2C_NUM_1
+#define I2C_SDA GPIO_NUM_27
+#define I2C_SCL GPIO_NUM_26
+#define I2C_CLOCK 100000
+
+// Pin mapping when using SPI mode.
+// With this mapping, SD card can be used both in SPI and 1-line SD mode.
+// Note that a pull-up on CS line is required in SD mode.
+#define PIN_NUM_MISO GPIO_NUM_19
+#define PIN_NUM_MOSI GPIO_NUM_23
+#define PIN_NUM_CLK GPIO_NUM_18
+#if SDCARD_ENABLE
+#define PIN_NUM_CS GPIO_NUM_0
+#endif
+
+#ifdef ADD_SERIAL1
+#define SERIAL1_PORT
+#define UART1_RX_PIN GPIO_NUM_16
+#define UART1_TX_PIN GPIO_NUM_15
+//#define UART1_RTS_PIN GPIO_NUM_14
+#endif
diff --git a/main/boards/cnc3040_map.h b/main/boards/cnc3040_map.h
index c12ebba..99c1ccb 100644
--- a/main/boards/cnc3040_map.h
+++ b/main/boards/cnc3040_map.h
@@ -36,13 +36,8 @@
#define BOARD_NAME "CNC3040 4-axis CNC"
#define BOARD_URL "https://github.com/shaise/GrblCNC/tree/master/Hardware/GrblCnc3040"
-// timer definitions
-#define STEP_TIMER_GROUP TIMER_GROUP_0
-#define STEP_TIMER_INDEX TIMER_0
-
-#ifdef ADD_SERIAL2
-#define UART2_TX_PIN GPIO_NUM_17
-#define UART2_RX_PIN GPIO_NUM_16
+#ifdef ADD_SERIAL1
+#define SERIAL1_PORT // RX: 16, TX: 17
#endif
// Define step pulse output pins.
diff --git a/main/boards/cnc_boosterpack_map.h b/main/boards/cnc_boosterpack_map.h
index fafb1b3..d268998 100644
--- a/main/boards/cnc_boosterpack_map.h
+++ b/main/boards/cnc_boosterpack_map.h
@@ -48,10 +48,6 @@
#define IOEXPAND_ENABLE 1 // I2C IO expander for some output signals.
#endif
-// timer definitions
-#define STEP_TIMER_GROUP TIMER_GROUP_0
-#define STEP_TIMER_INDEX TIMER_0
-
// Define step pulse output pins.
#define X_STEP_PIN GPIO_NUM_26
#define Y_STEP_PIN GPIO_NUM_27
@@ -90,8 +86,9 @@
#define COOLANT_FLOOD_PIN IOEXPAND
#define COOLANT_MIST_PIN IOEXPAND
-#ifdef ADD_SERIAL2
-#define UART2_RX_PIN GPIO_NUM_33
+#ifdef ADD_SERIAL1
+#define SERIAL1_PORT
+#define UART1_RX_PIN GPIO_NUM_33
#else
#define AUXINPUT0_PIN GPIO_NUM_33
#endif
@@ -121,11 +118,11 @@
#define NEOPIXELS_NUM NEOPIXELS_ENABLE
#endif
-#ifdef ADD_SERIAL2
+#ifdef ADD_SERIAL1
#if MPG_ENABLE == 1
#define MPG_ENABLE_PIN GPIO_NUM_25
#else
-#define UART2_TX_PIN GPIO_NUM_25
+#define UART1_TX_PIN GPIO_NUM_25
#endif
#if MODBUS_ENABLE & MODBUS_RTU_DIR_ENABLED
#define MODBUS_DIRECTION_PIN GPIO_NUM_25 //??
diff --git a/main/boards/cnc_boosterpack_s3_map.h b/main/boards/cnc_boosterpack_s3_map.h
index 22031cc..cfa269f 100644
--- a/main/boards/cnc_boosterpack_s3_map.h
+++ b/main/boards/cnc_boosterpack_s3_map.h
@@ -21,6 +21,10 @@
along with grblHAL. If not, see .
*/
+#ifndef CONFIG_IDF_TARGET_ESP32S3
+#error "This board has ESP32-S3 processor, select a corresponding build!"
+#endif
+
#if N_ABC_MOTORS > 0
#error "Axis configuration is not supported!"
#endif
@@ -44,10 +48,6 @@
#define EEPROM_ENABLE 1 // I2C EEPROM (24LC16) support.
#endif
-// timer definitions
-#define STEP_TIMER_GROUP TIMER_GROUP_0
-#define STEP_TIMER_INDEX TIMER_0
-
// Define step pulse output pins.
#define X_STEP_PIN GPIO_NUM_26
#define Y_STEP_PIN GPIO_NUM_27
@@ -105,16 +105,17 @@
#define AUXINPUT0_PIN GPIO_NUM_33
#endif
-#ifdef ADD_SERIAL2
-#define UART2_RX_PIN GPIO_NUM_33
-#define UART2_TX_PIN GPIO_NUM_25
+#ifdef ADD_SERIAL1
+#define SERIAL1_PORT
+#define UART1_RX_PIN GPIO_NUM_33
+#define UART1_TX_PIN GPIO_NUM_25
#if MODBUS_ENABLE & MODBUS_RTU_DIR_ENABLED
#define MODBUS_DIRECTION_PIN GPIO_NUM_25
#endif
#endif
#if MPG_ENABLE == 1
-#define UART2_RX_PIN GPIO_NUM_33
+#define UART1_RX_PIN GPIO_NUM_33
#define MPG_ENABLE_PIN GPIO_NUM_25
#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 a3743cf..1d47fd7 100644
--- a/main/boards/espduino-32_wemos_d1_r32_uno_map.h
+++ b/main/boards/espduino-32_wemos_d1_r32_uno_map.h
@@ -7,25 +7,25 @@
Copyright (c) 2020-2023 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 .
*/
/*
This map is for relatively common ESP32 boards replicating the form factor of Arduino UNO.
This map allows use of such uno-compatible board with very popular
"Protoneer Arduino CNC shield" and is based on its pinout.
- This makes perfect match for retrofiting older Arduino+GRBL based machines
+ This makes perfect match for retrofiting older Arduino+grblHAL based machines
with 32b microcontroler capable of running grblHAL and providing few extra IO pins (eg. for modbus).
These boards are sold under several names, for instance:
@@ -91,9 +91,10 @@
#define PROBE_PIN AUXINPUT0_PIN
#endif
-#ifdef ADD_SERIAL2
-#define UART2_RX_PIN GPIO_NUM_33
-#define UART2_TX_PIN GPIO_NUM_32
+#ifdef ADD_SERIAL1
+#define SERIAL1_PORT
+#define UART1_RX_PIN GPIO_NUM_33
+#define UART1_TX_PIN GPIO_NUM_32
#if MODBUS_ENABLE & MODBUS_RTU_DIR_ENABLED
#define MODBUS_DIRECTION_PIN GPIO_NUM_15
#endif
diff --git a/main/boards/fysetc_e4_map.h b/main/boards/fysetc_e4_map.h
index 156327e..d9597c0 100644
--- a/main/boards/fysetc_e4_map.h
+++ b/main/boards/fysetc_e4_map.h
@@ -33,10 +33,6 @@
#define BOARD_NAME "Fysetc E4 v1.0"
-// timer definitions
-#define STEP_TIMER_GROUP TIMER_GROUP_0
-#define STEP_TIMER_INDEX TIMER_0
-
// Define step pulse output pins.
#define X_STEP_PIN GPIO_NUM_27
#define Y_STEP_PIN GPIO_NUM_33
diff --git a/main/boards/generic_i2s_s3_map.h b/main/boards/generic_i2s_s3_map.h
new file mode 100644
index 0000000..d855f9c
--- /dev/null
+++ b/main/boards/generic_i2s_s3_map.h
@@ -0,0 +1,150 @@
+/*
+ generic_i2s_s3_map.h - An embedded CNC Controller with rs274/ngc (g-code) support
+
+ Driver code for ESP32
+
+ Part of grblHAL
+
+ Copyright (c) 2020-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 .
+*/
+
+#ifndef CONFIG_IDF_TARGET_ESP32S3
+#error "This board has ESP32-S3 processor, select a corresponding build!"
+#endif
+
+#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
+
+// 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 GPIO_NUM_13
+#define PIN_NUM_MOSI GPIO_NUM_11
+#define PIN_NUM_CLK GPIO_NUM_12
+#if SDCARD_ENABLE
+// Note that a pull-up on CS line is required in SD mode.
+#define PIN_NUM_CS GPIO_NUM_10
+#endif // SDCARD_ENABLE
+#endif // SDCARD_ENABLE || TRINAMIC_SPI_ENABLE
+
+#define I2S_OUT_BCK GPIO_NUM_36
+#define I2S_OUT_WS GPIO_NUM_35
+#define I2S_OUT_DATA GPIO_NUM_37
+
+#define X_STEP_PIN I2SO(2)
+#define X_DIRECTION_PIN I2SO(1)
+#define X_ENABLE_PIN I2SO(0)
+#define X_LIMIT_PIN GPIO_NUM_40
+
+#define Y_STEP_PIN I2SO(5)
+#define Y_DIRECTION_PIN I2SO(4)
+#define Y_ENABLE_PIN I2SO(7)
+#define Y_LIMIT_PIN GPIO_NUM_41
+
+#define Z_STEP_PIN I2SO(10)
+#define Z_DIRECTION_PIN I2SO(9)
+#define Z_ENABLE_PIN I2SO(8)
+#define Z_LIMIT_PIN GPIO_NUM_42
+
+// 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(15)
+#define M3_LIMIT_PIN GPIO_NUM_2
+#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(18)
+#define M4_DIRECTION_PIN I2SO(17)
+#define M4_ENABLE_PIN I2SO(16)
+#define M4_LIMIT_PIN GPIO_NUM_32
+#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(21)
+#define M5_DIRECTION_PIN I2SO(20)
+#define M5_ENABLE_PIN I2SO(23)
+#define M5_LIMIT_PIN GPIO_NUM_33
+#endif
+
+// Define driver spindle pins
+
+#if DRIVER_SPINDLE_PWM_ENABLE
+#define SPINDLE_PWM_PIN GPIO_NUM_26
+#else
+#define AUXOUTPUT0_PIN GPIO_NUM_26
+#endif
+
+#if DRIVER_SPINDLE_DIR_ENABLE
+#define SPINDLE_DIRECTION_PIN GPIO_NUM_16
+#else
+#define AUXOUTPUT1_PIN GPIO_NUM_16
+#endif
+
+#if DRIVER_SPINDLE_ENABLE
+#define SPINDLE_ENABLE_PIN GPIO_NUM_4
+#else
+#define AUXOUTPUT2_PIN GPIO_NUM_4
+#endif
+
+// Define flood and mist coolant enable output pins.
+
+#define COOLANT_FLOOD_PIN I2SO(15)
+#define COOLANT_MIST_PIN I2SO(12)
+
+// Define user-control CONTROLs (cycle start, reset, feed hold) input pins.
+
+// N/A
+
+#if TRINAMIC_SPI_ENABLE
+#define MOTOR_CS_PIN I2SO(3)
+#endif
+
+#ifdef ADD_SERIAL1
+#define SERIAL1_PORT
+#define UART1_RX_PIN GPIO_NUM_15
+#define UART1_TX_PIN GPIO_NUM_14
+#if MODBUS_ENABLE & MODBUS_RTU_DIR_ENABLED
+#define MODBUS_DIRECTION_PIN GPIO_NUM_13
+#endif
+#endif
+
+#define AUXINPUT0_PIN GPIO_NUM_26
+
+#if PROBE_ENABLE
+#define PROBE_PIN AUXINPUT0_PIN
+#endif
+
+#if N_AXIS <= 3
+#define LED_PIN GPIO_NUM_48 // for ESP32-S3-DevKit
+#endif
diff --git a/main/boards/generic_s3_map.h b/main/boards/generic_s3_map.h
new file mode 100644
index 0000000..e0cc670
--- /dev/null
+++ b/main/boards/generic_s3_map.h
@@ -0,0 +1,122 @@
+/*
+ generic_s3_map.h - 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 .
+*/
+
+#ifndef CONFIG_IDF_TARGET_ESP32S3
+#error "This board has ESP32-S3 processor, select a corresponding build!"
+#endif
+
+#if N_ABC_MOTORS > 0
+#error "Axis configuration is not supported!"
+#endif
+
+#if VFD_SPINDLE
+#error "Generic map does not have support for VFD spindle."
+#endif
+
+#if KEYPAD_ENABLE == 1
+#error No free pins for I2C keypad!
+#endif
+
+#define SERIAL1_PORT // RX: GPIO_NUM_18, TX: GPIO_NUM_17
+
+// Define step pulse output pins.
+#define X_STEP_PIN GPIO_NUM_12
+#define Y_STEP_PIN GPIO_NUM_13
+#define Z_STEP_PIN GPIO_NUM_14
+
+// Define step direction output pins. NOTE: All direction pins must be on the same port.
+#define X_DIRECTION_PIN GPIO_NUM_9
+#define Y_DIRECTION_PIN GPIO_NUM_10
+#define Z_DIRECTION_PIN GPIO_NUM_11
+
+// Define stepper driver enable/disable output pin(s).
+#define STEPPERS_ENABLE_PIN GPIO_NUM_8
+
+// Define homing/hard limit switch input pins and limit interrupt vectors.
+#define X_LIMIT_PIN GPIO_NUM_5
+#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
+
+#if DRIVER_SPINDLE_PWM_ENABLE
+#define SPINDLE_PWM_PIN GPIO_NUM_47
+#else
+#define AUXOUTPUT0_PIN GPIO_NUM_47
+#endif
+
+#if DRIVER_SPINDLE_DIR_ENABLE
+#define SPINDLE_DIRECTION_PIN GPIO_NUM_45
+#else
+#define AUXOUTPUT1_PIN GPIO_NUM_45
+#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
+
+// Define user-control CONTROLs (cycle start, reset, feed hold) input pins.
+#if !SDCARD_ENABLE
+#define RESET_PIN GPIO_NUM_38
+#define FEED_HOLD_PIN GPIO_NUM_37
+#endif
+#define CYCLE_START_PIN GPIO_NUM_36
+
+#define AUXINPUT0_PIN GPIO_NUM_1
+#define AUXINPUT1_PIN GPIO_NUM_2
+
+#if RGB_LED_ENABLE
+#define LED_PIN GPIO_NUM_48 // for ESP32-S3-DevKit
+#endif
+
+#if PROBE_ENABLE
+#define PROBE_PIN AUXINPUT1_PIN
+#endif
+
+#if SAFETY_DOOR_ENABLE
+#define SAFETY_DOOR_PIN AUXINPUT0_PIN
+#endif
+
+// Define I2C port/pins
+#if I2C_ENABLE
+#define I2C_PORT I2C_NUM_1
+#define I2C_SDA GPIO_NUM_3
+#define I2C_SCL GPIO_NUM_4
+#define I2C_CLOCK 100000
+#endif
+
+#if SDCARD_ENABLE
+// Pin mapping when using SPI mode.
+// With this mapping, SD card can be used both in SPI and 1-line SD mode.
+// Note that a pull-up on CS line is required in SD mode.
+#define PIN_NUM_MISO GPIO_NUM_37
+#define PIN_NUM_MOSI GPIO_NUM_35
+#define PIN_NUM_CLK GPIO_NUM_36
+#define PIN_NUM_CS GPIO_NUM_21
+#endif
diff --git a/main/boards/jackpot_map.h b/main/boards/jackpot_map.h
index 02be479..88f30f8 100644
--- a/main/boards/jackpot_map.h
+++ b/main/boards/jackpot_map.h
@@ -31,10 +31,6 @@
#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
-
#define I2S_OUT_BCK GPIO_NUM_22
#define I2S_OUT_WS GPIO_NUM_17
#define I2S_OUT_DATA GPIO_NUM_21
@@ -61,6 +57,7 @@
#define M3_DIRECTION_PIN I2SO(12)
#define M3_ENABLE_PIN I2SO(15)
#define M3_LIMIT_PIN GPIO_NUM_35
+#define M3_UART_CS I2SO(14)
#endif
// Define ganged axis or B axis step pulse and step direction output pins.
@@ -70,6 +67,7 @@
#define M4_DIRECTION_PIN I2SO(17)
#define M4_ENABLE_PIN I2SO(16)
#define M4_LIMIT_PIN GPIO_NUM_34
+#define M4_UART_CS I2SO(19)
#endif
// Define ganged axis or B axis step pulse and step direction output pins.
@@ -79,6 +77,7 @@
#define M5_DIRECTION_PIN I2SO(20)
#define M5_ENABLE_PIN I2SO(23)
#define M5_LIMIT_PIN GPIO_NUM_39
+#define M5_UART_CS I2SO(22)
#endif
// Define driver spindle pins
@@ -128,7 +127,8 @@
#define PIN_NUM_CS GPIO_NUM_5
#endif
-#ifdef ADD_SERIAL2
-#define UART2_RX_PIN GPIO_NUM_4
-#define UART2_TX_PIN GPIO_NUM_0
+#ifdef ADD_SERIAL1
+#define SERIAL1_PORT
+#define UART1_RX_PIN GPIO_NUM_4
+#define UART1_TX_PIN GPIO_NUM_0
#endif
diff --git a/main/boards/mks_dlc32_2_0_map.h b/main/boards/mks_dlc32_2_0_map.h
index 1772b58..b291bff 100644
--- a/main/boards/mks_dlc32_2_0_map.h
+++ b/main/boards/mks_dlc32_2_0_map.h
@@ -32,10 +32,6 @@
#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
// Pin mapping when using SPI mode.
diff --git a/main/boards/mks_tinybee_1_0_map.h b/main/boards/mks_tinybee_1_0_map.h
index d45b1fc..eb21264 100644
--- a/main/boards/mks_tinybee_1_0_map.h
+++ b/main/boards/mks_tinybee_1_0_map.h
@@ -36,12 +36,7 @@
#define USE_I2S_OUT
#define I2S_OUT_PIN_BASE 64
-#define UART2_RX_PIN GPIO_NUM_16 // EXP_1
-#define UART2_TX_PIN GPIO_NUM_17 // EXP_1
-
-// timer definitions
-#define STEP_TIMER_GROUP TIMER_GROUP_0
-#define STEP_TIMER_INDEX TIMER_0
+#define SERIAL1_PORT // RX: 16, TX: 17
#define I2S_OUT_BCK GPIO_NUM_25
#define I2S_OUT_WS GPIO_NUM_26
diff --git a/main/boards/protoneer_3.xx_map.h b/main/boards/protoneer_3.xx_map.h
index 256f1a1..15dc044 100644
--- a/main/boards/protoneer_3.xx_map.h
+++ b/main/boards/protoneer_3.xx_map.h
@@ -27,10 +27,6 @@
#define BOARD_NAME "Protoneer v3"
-// timer definitions
-#define STEP_TIMER_GROUP TIMER_GROUP_0
-#define STEP_TIMER_INDEX TIMER_0
-
#if VFD_SPINDLE
#error VFD Spindle not supported!
#endif
diff --git a/main/boards/root_cnc_pro_map.h b/main/boards/root_cnc_pro_map.h
index a5d5ffd..61730e1 100644
--- a/main/boards/root_cnc_pro_map.h
+++ b/main/boards/root_cnc_pro_map.h
@@ -37,10 +37,6 @@
#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.
@@ -155,9 +151,8 @@
#endif
// N/A
-#ifdef ADD_SERIAL2
-#define UART2_RX_PIN GPIO_NUM_16
-#define UART2_TX_PIN GPIO_NUM_17
+#ifdef ADD_SERIAL1
+#define SERIAL1_PORT // RX: 16, TX: 17
#if MODBUS_ENABLE & MODBUS_RTU_DIR_ENABLED
#define MODBUS_DIRECTION_PIN GPIO_NUM_4
#endif
diff --git a/main/boards/root_cnc_v2_map.h b/main/boards/root_cnc_v2_map.h
index 5db27fe..405d3e8 100644
--- a/main/boards/root_cnc_v2_map.h
+++ b/main/boards/root_cnc_v2_map.h
@@ -31,10 +31,6 @@
#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.
@@ -123,9 +119,10 @@
// N/A
-#ifdef ADD_SERIAL2
-#define UART2_RX_PIN GPIO_NUM_16
-#define UART2_TX_PIN GPIO_NUM_17
+#ifdef ADD_SERIAL1
+#define SERIAL1_PORT
+#define UART1_RX_PIN GPIO_NUM_16
+#define UART1_TX_PIN GPIO_NUM_17
#if MODBUS_ENABLE & MODBUS_RTU_DIR_ENABLED
#define MODBUS_DIRECTION_PIN GPIO_NUM_4
#endif
diff --git a/main/boards/root_cnc_v3_map.h b/main/boards/root_cnc_v3_map.h
index 9f5640c..cc5be58 100644
--- a/main/boards/root_cnc_v3_map.h
+++ b/main/boards/root_cnc_v3_map.h
@@ -33,10 +33,6 @@
#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.
@@ -125,9 +121,8 @@
// N/A
-#ifdef ADD_SERIAL2
-#define UART2_RX_PIN GPIO_NUM_16
-#define UART2_TX_PIN GPIO_NUM_17
+#ifdef ADD_SERIAL1
+#define SERIAL1_PORT // RX: 16, TX: 17
#if MODBUS_ENABLE & MODBUS_RTU_DIR_ENABLED
#define MODBUS_DIRECTION_PIN GPIO_NUM_4
#endif
diff --git a/main/boards/sourcerabbit_4axis.h b/main/boards/sourcerabbit_4axis.h
index b39f207..a52d28c 100644
--- a/main/boards/sourcerabbit_4axis.h
+++ b/main/boards/sourcerabbit_4axis.h
@@ -32,10 +32,6 @@
#endif
#define BOARD_URL "https://www.sourcerabbit.com/Shop/pr-i-86-t-4-axis-cnc-motherboard.htm"
-// timer definitions
-#define STEP_TIMER_GROUP TIMER_GROUP_0
-#define STEP_TIMER_INDEX TIMER_0
-
#if MODBUS_ENABLE & MODBUS_RTU_ENABLED
#error VFD Spindle not supported!
#endif
diff --git a/main/boards/xPro_v5_map.h b/main/boards/xPro_v5_map.h
index 01ca18a..fa0b502 100644
--- a/main/boards/xPro_v5_map.h
+++ b/main/boards/xPro_v5_map.h
@@ -31,14 +31,14 @@
#define BOARD_NAME "x-Pro v5"
#define BOARD_URL "https://www.spark-concepts.com/cnc-xpro-v5/"
-#define HAS_BOARD_INIT
+
#if TRINAMIC_ENABLE != 5160
#error BOARD_XPRO_V5 has soldered TMC5160 drivers.
#endif
#define TRINAMIC_MIXED_DRIVERS 0
-#ifdef ADD_SERIAL2 // ModBus
+#ifdef ADD_SERIAL1 // ModBus
#undef DRIVER_SPINDLE_ENABLE
#define DRIVER_SPINDLE_ENABLE 0
#endif
@@ -75,9 +75,10 @@
#if DRIVER_SPINDLE_PWM_ENABLE
#define SPINDLE_PWM_PIN GPIO_NUM_25
#define SPINDLE_ENABLE_PIN GPIO_NUM_4
-#elif defined(ADD_SERIAL2)
-#define UART2_RX_PIN GPIO_NUM_25
-#define UART2_TX_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
#else
#define AUXOUTPUT0_PIN GPIO_NUM_25
#define AUXOUTPUT1_PIN GPIO_NUM_4
diff --git a/main/driver.c b/main/driver.c
index 2c5eda2..1f214cd 100644
--- a/main/driver.c
+++ b/main/driver.c
@@ -462,7 +462,7 @@ static probe_state_t probe = {
static ioexpand_t iopins = {0};
#endif
-#ifdef NEOPIXELS_PIN
+#ifdef LED_PIN
neopixel_cfg_t neopixel = { .intensity = 255 };
void neopixels_write (void);
#endif
@@ -2180,7 +2180,7 @@ static void settings_changed (settings_t *settings, settings_changed_flags_t cha
{
if(IOInitDone) {
-#ifdef NEOPIXELS_PIN
+#ifdef LED_PIN
if(neopixel.leds == NULL || hal.rgb0.num_devices != settings->rgb_strip.length0) {
@@ -2584,7 +2584,7 @@ static char *sdcard_mount (FATFS **fs)
#endif
-#ifdef NEOPIXELS_PIN
+#ifdef LED_PIN
// https://github.com/adafruit/Adafruit_NeoPixel/blob/master/esp.c
@@ -2593,9 +2593,9 @@ static char *sdcard_mount (FATFS **fs)
#endif
#if CONFIG_IDF_TARGET_ESP32S3
-static rmt_config_t neo_config = RMT_DEFAULT_CONFIG_TX(NEOPIXELS_PIN, 3);
+static rmt_config_t neo_config = RMT_DEFAULT_CONFIG_TX(LED_PIN, 3);
#else
-static rmt_config_t neo_config = RMT_DEFAULT_CONFIG_TX(NEOPIXELS_PIN, 7);
+static rmt_config_t neo_config = RMT_DEFAULT_CONFIG_TX(LED_PIN, 7);
#endif
#define WS2812_T0H_NS (450)
@@ -2715,7 +2715,7 @@ uint8_t neopixels_set_intensity (uint8_t value)
return prev;
}
-#endif // NEOPIXELS_PIN
+#endif // LED_PIN
// Initializes MCU peripherals for grblHAL use
static bool driver_setup (settings_t *settings)
@@ -2928,7 +2928,7 @@ bool driver_init (void)
#else
hal.info = "ESP32";
#endif
- hal.driver_version = "241208";
+ hal.driver_version = "241212";
hal.driver_url = GRBL_URL "/ESP32";
#ifdef BOARD_NAME
hal.board = BOARD_NAME;
@@ -3205,7 +3205,7 @@ bool driver_init (void)
hal.signals_cap.safety_door_ajar = On;
#endif
-#ifdef NEOPIXELS_PIN
+#ifdef LED_PIN
neo_config.clk_div = 2;
@@ -3238,15 +3238,22 @@ bool driver_init (void)
const periph_pin_t neopixels = {
.function = Output_LED_Adressable,
.group = PinGroup_LED,
- .pin = NEOPIXELS_PIN,
- .mode = { .mask = PINMODE_OUTPUT },
- .description = "NeoPixels"
+ .pin = LED_PIN,
+ .mode = { .mask = PINMODE_OUTPUT }
};
hal.periph_port.register_pin(&neopixels);
#endif
+#if TRINAMIC_SPI_ENABLE
+ extern void tmc_spi_init (void);
+ tmc_spi_init();
+#elif TRINAMIC_UART_ENABLE
+ extern void tmc_uart_init (void);
+ tmc_uart_init();
+#endif
+
#ifdef HAS_BOARD_INIT
board_init();
#endif
diff --git a/main/driver.h b/main/driver.h
index 8b6d9c3..719badf 100644
--- a/main/driver.h
+++ b/main/driver.h
@@ -26,6 +26,8 @@
#ifndef __DRIVER_H__
#define __DRIVER_H__
+#include "sdkconfig.h"
+
#ifndef OVERRIDE_MY_MACHINE
#include "my_machine.h"
@@ -110,8 +112,8 @@ typedef struct {
// End configuration
-#if !USB_SERIAL_CDC && ((MODBUS_ENABLE & MODBUS_RTU_ENABLED) || TRINAMIC_UART_ENABLE || MPG_ENABLE || (KEYPAD_ENABLE == 2 && MPG_ENABLE == 0))
-#define ADD_SERIAL2
+#if (MODBUS_ENABLE & MODBUS_RTU_ENABLED) || TRINAMIC_UART_ENABLE==1 || MPG_ENABLE || (KEYPAD_ENABLE == 2 && MPG_ENABLE == 0)
+#define ADD_SERIAL1
#endif
#ifdef BOARD_CNC_BOOSTERPACK
@@ -156,6 +158,8 @@ typedef struct {
#include "boards/jackpot_map.h"
#elif defined(BOARD_MY_MACHINE)
#include "boards/my_machine_map.h"
+#elif defined(BOARD_GENERIC_S3)
+ #include "boards/generic_s3_map.h"
#elif defined(BOARD_GENERIC_I2S_S3)
#include "boards/generic_i2s_s3_map.h"
#else // default board - NOTE: NOT FINAL VERSION!
@@ -210,103 +214,16 @@ extern SemaphoreHandle_t i2cBusy;
#error "I2C port not available!"
#endif
-#if TRINAMIC_ENABLE
-#ifndef TRINAMIC_MIXED_DRIVERS
-#define TRINAMIC_MIXED_DRIVERS 1
-#endif
-#include "motors/trinamic.h"
-#include "trinamic/common.h"
-#endif
-
-#if USB_SERIAL_CDC
-#define SP0 1
-#else
-#define SP0 0
-#endif
-
-#ifdef UART2_RX_PIN
-#define SP1 1
-#else
-#define SP1 0
-#endif
-
-#ifdef UART3_RX_PIN
-#define SP2 1
-#else
-#define SP2 0
-#endif
-
-#if MODBUS_ENABLE & MODBUS_RTU_ENABLED
-#define MODBUS_TEST 1
-#else
-#define MODBUS_TEST 0
-#endif
-
-#if TRINAMIC_UART_ENABLE
-#define TRINAMIC_TEST 1
-#else
-#define TRINAMIC_TEST 0
-#endif
-
-#if MPG_ENABLE
-#define MPG_TEST 1
-#else
-#define MPG_TEST 0
-#endif
-
-#if KEYPAD_ENABLE == 2 && MPG_ENABLE == 0
-#define KEYPAD_TEST 1
-#else
-#define KEYPAD_TEST 0
-#endif
-
-#ifdef DEBUGOUT
-#define DEBUG_TEST 1
-#else
-#define DEBUG_TEST 0
-#endif
-
-#if (MODBUS_TEST + KEYPAD_TEST + MPG_TEST + TRINAMIC_TEST + DEBUG_TEST) > (SP0 + SP1 + SP2)
-#error "Too many options that requires a serial port are enabled!"
-#elif (SP0 == 0 && (MODBUS_TEST + KEYPAD_TEST + MPG_TEST + TRINAMIC_TEST + DEBUG_TEST)) || SERIAL_STREAM == 1
-#define SERIAL2_ENABLE 1
-#else
-#define SERIAL2_ENABLE 0
-#endif
+// NOTE: #define SERIAL_PORT in map file if USB_SERIAL_CDC is enabled and the primary UART is not connected to a USB <> UART chip
-#undef SP0
-#undef SP1
-#undef SP2
-#undef MODBUS_TEST
-#undef KEYPAD_TEST
-#undef MPG_TEST
-#undef TRINAMIC_TEST
-#undef DEBUG_TEST
-
-#if MPG_ENABLE
-#if MPG_STREAM == 0
-#define MPG_STREAM_DUPLEX 1
-#elif MPG_STREAM == 1
-#ifdef UART2_TX_PIN
-#define MPG_STREAM_DUPLEX 1
-#else
-#define MPG_STREAM_DUPLEX 0
-#endif
-#elif MPG_STREAM == 2
-#ifdef UART3_TX_PIN
-#define MPG_STREAM_DUPLEX 1
-#else
-#define MPG_STREAM_DUPLEX 0
-#endif
-#endif
-#endif
+#include "grbl/driver_opts2.h"
#if MPG_ENABLE == 1
#ifndef MPG_ENABLE_PIN
#error "MPG_ENABLE_PIN must be defined when MPG mode is enabled!"
#endif
- #ifndef UART2_RX_PIN
- #error "UART2_RX_PIN must be defined when MPG mode is enabled!"
+ #ifndef UART1_RX_PIN
+ #error "UART1_RX_PIN must be defined when MPG mode is enabled!"
#endif
#endif
diff --git a/main/my_machine.h b/main/my_machine.h
index da05137..76114ab 100644
--- a/main/my_machine.h
+++ b/main/my_machine.h
@@ -38,9 +38,10 @@
//#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
+//#define BOARD_GENERIC_S3 // Generic map for ESP32-S3, untested - WIP!
+//#define BOARD_GENERIC_I2S_S3 // Generic map for ESP32-S3 with I2S shift registers for I/O expansion, untested - WIP!
//#define BOARD_MY_MACHINE // Add my_machine_map.h in the boards directory before enabling this!
-//#define BOARD_BLOX
+
// Configuration
// Uncomment to enable, for some a value > 1 may be assigned, if so the default value is shown.
@@ -78,12 +79,13 @@
//#define FANS_ENABLE 1 // Enable fan control via M106/M107. Enables fans plugin.
//#define EMBROIDERY_ENABLE 1 // Embroidery plugin. To be completed.
//#define TRINAMIC_ENABLE 2130 // Trinamic TMC2130 stepper driver support. NOTE: work in progress.
+//#define TRINAMIC_ENABLE 2209 // Trinamic TMC2209 stepper driver support. NOTE: work in progress.
//#define TRINAMIC_ENABLE 5160 // Trinamic TMC5160 stepper driver support. NOTE: work in progress.
//#define TRINAMIC_I2C 1 // Trinamic I2C - SPI bridge interface.
//#define TRINAMIC_DEV 1 // Development mode, adds a few M-codes to aid debugging. Do not enable in production code.
//#define EEPROM_ENABLE 16 // I2C EEPROM/FRAM support. Set to 16 for 2K, 32 for 4K, 64 for 8K, 128 for 16K and 256 for 16K capacity.
//#define EEPROM_IS_FRAM 1 // Uncomment when EEPROM is enabled and chip is FRAM, this to remove write delay.
-#define ESTOP_ENABLE 0 // When enabled only real-time report requests will be executed when the reset pin is asserted.
+//#define ESTOP_ENABLE 0 // When enabled only real-time report requests will be executed when the reset pin is asserted.
// NOTE: if left commented out the default setting is determined from COMPATIBILITY_LEVEL.
//#define RGB_LED_ENABLE 2 // Set to 1 to enable strip length settings $536 and $537, set to 2 to also enable M150 LED strip control.
//#define PWM_SERVO_ENABLE 1 // Enable M280 PWM servo support, requires at least one PWM capable auxiliary output.
diff --git a/main/trinamic_if.c b/main/tmc_spi.c
similarity index 57%
rename from main/trinamic_if.c
rename to main/tmc_spi.c
index c9ca113..8a7525e 100644
--- a/main/trinamic_if.c
+++ b/main/tmc_spi.c
@@ -1,27 +1,27 @@
/*
- trinamic_if.c - driver code for ESP32
+ tmc_spi.c - driver code for ESP32
Part of grblHAL
Copyright (c) 2020-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 "driver.h"
-#if defined(BOARD_XPRO_V5)
+#if TRINAMIC_SPI_ENABLE
#include
#include
@@ -31,8 +31,6 @@
#include "grbl/protocol.h"
#include "grbl/settings.h"
-#if TRINAMIC_SPI_ENABLE
-
#include "driver/spi_master.h"
static struct {
@@ -157,85 +155,8 @@ static void if_init (uint8_t motors, axes_signals_t axisflags)
hal.enumerate_pins(true, add_cs_pin, NULL);
}
-#endif
-
-#if TRINAMIC_UART_ENABLE
-
-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)
+void tmc_spi_init (void)
{
- static TMC_uart_write_datagram_t wdgr = {0};
- volatile uint32_t dly = 50, ms = hal.get_elapsed_ticks();
-
- if(tmc_uart.write_n == NULL)
- return &wdgr;
-
- vTaskSuspendAll();
-
- tmc_uart.reset_write_buffer();
- tmc_uart.write_n((char *)dgr->data, sizeof(TMC_uart_read_datagram_t));
-
- while(tmc_uart.get_tx_buffer_count());
-
- while(--dly);
-
- tmc_uart.reset_read_buffer();
- tmc_uart.disable_rx(false);
-
- xTaskResumeAll();
-
- // Wait for response with 10 ms timeout
- while(tmc_uart.get_rx_buffer_count() < 8) {
- if(hal.get_elapsed_ticks() - ms >= 11)
- break;
- }
-
- if(tmc_uart.get_rx_buffer_count() >= 8) {
-
- wdgr.data[0] = tmc_uart.read();
- wdgr.data[1] = tmc_uart.read();
- wdgr.data[2] = tmc_uart.read();
- wdgr.data[3] = tmc_uart.read();
- wdgr.data[4] = tmc_uart.read();
- wdgr.data[5] = tmc_uart.read();
- wdgr.data[6] = tmc_uart.read();
- wdgr.data[7] = tmc_uart.read();
-
- } else
- wdgr.msg.addr.value = 0xFF;
-
- tmc_uart.disable_rx(true);
-
- dly = 5000;
- while(--dly);
-
- return &wdgr;
-}
-
-void tmc_uart_write (trinamic_motor_t driver, TMC_uart_write_datagram_t *dgr)
-{
- if(tmc_uart.write_n == NULL)
- return;
-
- tmc_uart.reset_read_buffer();
- tmc_uart.write_n((char *)dgr->data, sizeof(TMC_uart_write_datagram_t));
-
- while(tmc_uart.get_tx_buffer_count());
-}
-
-#if TRINAMIC_UART_ENABLE == 2
-static void driver_preinit (motor_map_t motor, trinamic_driver_config_t *config)
-{
- config->address = 0;
-}
-#endif
-
-#endif // TRINAMIC_UART_ENABLE
-
-void board_init (void)
-{
-#if TRINAMIC_SPI_ENABLE
trinamic_driver_if_t driver = {
.on_drivers_init = if_init
@@ -249,29 +170,6 @@ void board_init (void)
} while(idx);
trinamic_if_init(&driver);
-
-#elif TRINAMIC_UART_ENABLE
-
-#if TRINAMIC_UART_ENABLE == 2
- static trinamic_driver_if_t driver_if = {
- .on_driver_preinit = driver_preinit
- };
-
- trinamic_if_init(&driver_if);
-#endif
-
- const io_stream_t *stream;
-
- if((stream = stream_open_instance(TRINAMIC_STREAM, 230400, NULL, "Trinamic UART")) == NULL)
- stream = stream_null_init(230400);
-
- if(stream) {
- memcpy(&tmc_uart, stream, sizeof(io_stream_t));
- tmc_uart.disable_rx(true);
- tmc_uart.set_enqueue_rt_handler(stream_buffer_all);
- } // else output POS failure?
-
-#endif
}
-#endif
+#endif // TRINAMIC_SPI_ENABLE
diff --git a/main/tmc_uart.c b/main/tmc_uart.c
new file mode 100644
index 0000000..81e0f47
--- /dev/null
+++ b/main/tmc_uart.c
@@ -0,0 +1,166 @@
+/*
+ tmc_uart.c - driver code for ESP32
+
+ Part of grblHAL
+
+ Copyright (c) 2020-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 .
+*/
+
+#include "driver.h"
+
+#if TRINAMIC_UART_ENABLE == 1
+
+#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)
+{
+ static TMC_uart_write_datagram_t wdgr = {0};
+ volatile uint32_t dly = 50, ms = hal.get_elapsed_ticks();
+
+ if(tmc_uart.write_n == NULL)
+ return &wdgr;
+
+#if defined(BOARD_JACKPOT) && defined(M3_UART_CS)
+
+ if(driver.id >= 3) {
+ DIGITAL_OUT(M3_UART_CS, driver.id == 3);
+#if defined(M4_UART_CS)
+ DIGITAL_OUT(M4_UART_CS, driver.id == 4);
+#endif
+#if defined(M5_UART_CS)
+ DIGITAL_OUT(M5_UART_CS, driver.id == 5);
+#endif
+ }
+
+// add delay?
+
+#endif // BOARD_JACKPOT
+
+ vTaskSuspendAll();
+
+ tmc_uart.reset_write_buffer();
+ tmc_uart.write_n((char *)dgr->data, sizeof(TMC_uart_read_datagram_t));
+
+ while(tmc_uart.get_tx_buffer_count());
+
+ while(--dly);
+
+ tmc_uart.reset_read_buffer();
+ tmc_uart.disable_rx(false);
+
+ xTaskResumeAll();
+
+ // Wait for response with 10 ms timeout
+ while(tmc_uart.get_rx_buffer_count() < 8) {
+ if(hal.get_elapsed_ticks() - ms >= 11)
+ break;
+ }
+
+ if(tmc_uart.get_rx_buffer_count() >= 8) {
+
+ wdgr.data[0] = tmc_uart.read();
+ wdgr.data[1] = tmc_uart.read();
+ wdgr.data[2] = tmc_uart.read();
+ wdgr.data[3] = tmc_uart.read();
+ wdgr.data[4] = tmc_uart.read();
+ wdgr.data[5] = tmc_uart.read();
+ wdgr.data[6] = tmc_uart.read();
+ wdgr.data[7] = tmc_uart.read();
+
+ } else
+ wdgr.msg.addr.value = 0xFF;
+
+ tmc_uart.disable_rx(true);
+
+ dly = 5000;
+ while(--dly);
+
+ return &wdgr;
+}
+
+void tmc_uart_write (trinamic_motor_t driver, TMC_uart_write_datagram_t *dgr)
+{
+ if(tmc_uart.write_n == NULL)
+ return;
+
+#if defined(BOARD_JACKPOT) && defined(M3_UART_CS)
+
+ if(driver.id >= 3) {
+ DIGITAL_OUT(M3_UART_CS, driver.id == 3);
+#if defined(M4_UART_CS)
+ DIGITAL_OUT(M4_UART_CS, driver.id == 4);
+#endif
+#if defined(M5_UART_CS)
+ DIGITAL_OUT(M5_UART_CS, driver.id == 5);
+#endif
+ }
+
+// add delay?
+
+#endif // BOARD_JACKPOT
+
+ tmc_uart.reset_read_buffer();
+ tmc_uart.write_n((char *)dgr->data, sizeof(TMC_uart_write_datagram_t));
+
+ while(tmc_uart.get_tx_buffer_count());
+}
+
+#if defined(BOARD_JACKPOT) && defined(M3_UART_CS)
+
+static void driver_preinit (motor_map_t motor, trinamic_driver_config_t *config)
+{
+ if(motor.id > 3)
+ config->address = 3;
+}
+
+#endif // BOARD_JACKPOT
+
+void tmc_uart_init (void)
+{
+#if defined(BOARD_JACKPOT) && defined(M3_UART_CS)
+
+ static trinamic_driver_if_t driver_if = {
+ .on_driver_preinit = driver_preinit
+ };
+
+ trinamic_if_init(&driver_if);
+
+#endif // BOARD_JACKPOT
+
+ const io_stream_t *stream;
+
+ if((stream = stream_open_instance(TRINAMIC_STREAM, 230400, NULL, "Trinamic UART")) == NULL)
+ stream = stream_null_init(230400);
+
+ memcpy(&tmc_uart, stream, sizeof(io_stream_t));
+ tmc_uart.disable_rx(true);
+ tmc_uart.set_enqueue_rt_handler(stream_buffer_all);
+
+// if no stream output -> POS failure?
+
+}
+
+#elif TRINAMIC_UART_ENABLE
+
+#error "Soft UART Trinamic driver not available!"
+
+#endif
diff --git a/main/uart_serial.c b/main/uart_serial.c
index b739282..5599355 100644
--- a/main/uart_serial.c
+++ b/main/uart_serial.c
@@ -55,7 +55,6 @@
#define UART_TXD_IDX(u) ((u==0)?U0TXD_OUT_IDX:( (u==1)?U1TXD_OUT_IDX:( (u==2)?U2TXD_OUT_IDX:0)))
#define UART_INTR_SOURCE(u) ((u==0)?ETS_UART0_INTR_SOURCE:( (u==1)?ETS_UART1_INTR_SOURCE:((u==2)?ETS_UART2_INTR_SOURCE:0)))
-
#if CONFIG_IDF_TARGET_ESP32S3
#ifndef UART_RX_PIN
#define UART_RX_PIN 44
@@ -63,13 +62,29 @@
#ifndef UART_TX_PIN
#define UART_TX_PIN 43
#endif
-#else
+#ifdef SERIAL1_PORT
+#ifndef UART1_RX_PIN
+#define UART1_RX_PIN 18
+#endif
+#ifndef UART1_TX_PIN
+#define UART1_TX_PIN 17
+#endif
+#endif
+#else // ESP32
#ifndef UART_RX_PIN
#define UART_RX_PIN 34
#endif
#ifndef UART_TX_PIN
#define UART_TX_PIN 35
#endif
+#ifdef SERIAL1_PORT
+#ifndef UART1_RX_PIN
+#define UART1_RX_PIN 16
+#endif
+#ifndef UART1_TX_PIN
+#define UART1_TX_PIN 17
+#endif
+#endif
#endif
typedef void (*uart_isr_ptr)(void *arg);
@@ -117,23 +132,23 @@ static const uart_t _uart_bus_array[3] = {
static const DRAM_ATTR uint16_t RX_BUFFER_SIZE_MASK = RX_BUFFER_SIZE - 1;
static const DRAM_ATTR uint32_t rx_int_flags = UART_INTR_RXFIFO_FULL|UART_INTR_RXFIFO_OVF|UART_INTR_RXFIFO_TOUT|UART_INTR_FRAM_ERR;
-static uart_t uart1;
+static uart_t uart0;
static stream_rx_buffer_t rxbuffer = {0};
static enqueue_realtime_command_ptr enqueue_realtime_command = protocol_enqueue_realtime_command;
static const io_stream_t *serialInit (uint32_t baud_rate);
-#if SERIAL2_ENABLE
-static uart_t uart2;
-static stream_rx_buffer_t rxbuffer2 = {0};
+#ifdef SERIAL1_PORT
+static uart_t uart1;
+static stream_rx_buffer_t rxbuffer1 = {0};
static enqueue_realtime_command_ptr enqueue_realtime_command2 = protocol_enqueue_realtime_command;
-static const io_stream_t *serial2Init (uint32_t baud_rate);
+static const io_stream_t *serial1Init (uint32_t baud_rate);
#endif
-#if SERIAL3_ENABLE
-static uart_t uart3;
-static stream_rx_buffer_t rxbuffer3 = {0};
+#ifdef SERIAL2_PORT
+static uart_t uart2;
+static stream_rx_buffer_t rxbuffer2 = {0};
static enqueue_realtime_command_ptr enqueue_realtime_command3 = protocol_enqueue_realtime_command;
-static const io_stream_t *serial3Init (uint32_t baud_rate);
+static const io_stream_t *serial2Init (uint32_t baud_rate);
#endif
static io_stream_properties_t serial[] = {
@@ -146,36 +161,36 @@ static io_stream_properties_t serial[] = {
.flags.modbus_ready = On,
.claim = serialInit
},
-#if SERIAL2_ENABLE
+#ifdef SERIAL1_PORT
{
.type = StreamType_Serial,
.instance = 1,
.flags.claimable = On,
.flags.claimed = Off,
.flags.can_set_baud = On,
- #ifdef UART2_TX_PIN
+ #ifdef UART1_TX_PIN
.flags.modbus_ready = On,
#else
.flags.rx_only = On,
#endif
- .claim = serial2Init
+ .claim = serial1Init
},
-#endif // SERIAL2_ENABLE
-#if SERIAL3_ENABLE
+#endif // SERIAL1_PORT
+#ifdef SERIAL2_PORT
{
.type = StreamType_Serial,
.instance = 2,
.flags.claimable = On,
.flags.claimed = Off,
.flags.can_set_baud = On,
- #ifdef UART3_TX_PIN
+ #ifdef UART2_TX_PIN
.flags.modbus_ready = On,
#else
.flags.rx_only = On,
#endif
- .claim = serial3Init
+ .claim = serial2Init
}
-#endif // SERIAL3_ENABLE
+#endif // SERIAL2_PORT
};
void serialRegisterStreams (void)
@@ -204,13 +219,13 @@ void serialRegisterStreams (void)
hal.periph_port.register_pin(&rx0);
hal.periph_port.register_pin(&tx0);
-#if SERIAL2_ENABLE
+#ifdef SERIAL1_PORT
- #ifdef UART2_TX_PIN
+ #ifdef UART1_TX_PIN
static const periph_pin_t tx1 = {
.function = Output_TX,
.group = PinGroup_UART2,
- .pin = UART2_TX_PIN,
+ .pin = UART1_TX_PIN,
.mode = { .mask = PINMODE_OUTPUT },
.description = "Secondary UART"
};
@@ -221,22 +236,22 @@ void serialRegisterStreams (void)
static const periph_pin_t rx1 = {
.function = Input_RX,
.group = PinGroup_UART2,
- .pin = UART2_RX_PIN,
+ .pin = UART1_RX_PIN,
.mode = { .mask = PINMODE_NONE },
.description = "Secondary UART"
};
hal.periph_port.register_pin(&rx1);
-#endif // SERIAL2_ENABLE
+#endif // SERIAL1_PORT
-#if SERIAL3_ENABLE
+#ifdef SERIAL2_PORT
- #ifdef UART3_TX_PIN
+ #ifdef UART2_TX_PIN
static const periph_pin_t tx2 = {
.function = Output_TX,
.group = PinGroup_UART3,
- .pin = UART3_TX_PIN,
+ .pin = UART2_TX_PIN,
.mode = { .mask = PINMODE_OUTPUT },
.description = "Tertiary UART"
};
@@ -247,14 +262,14 @@ void serialRegisterStreams (void)
static const periph_pin_t rx2 = {
.function = Input_RX,
.group = PinGroup_UART3,
- .pin = UART3_RX_PIN,
+ .pin = UART2_RX_PIN,
.mode = { .mask = PINMODE_NONE },
.description = "Tertiary UART"
};
hal.periph_port.register_pin(&rx2);
-#endif // SERIAL3_ENABLE
+#endif // SERIAL2_PORT
stream_register_streams(&streams);
}
@@ -327,7 +342,7 @@ static void uartConfig (uart_t *uart, uint32_t baud_rate)
#endif
#endif
-#if SERIAL2_ENABLE || SERIAL3_ENABLE || defined(UART0_PINS_REDEFINED)
+#if defined(SERIAL1_PORT) || defined(SERIAL2_PORT) || defined(UART0_PINS_REDEFINED)
switch(uart->num) {
#ifdef UART0_PINS_REDEFINED
@@ -335,26 +350,26 @@ static void uartConfig (uart_t *uart, uint32_t baud_rate)
uart_set_pin(uart->num, UART_TX_PIN, UART_RX_PIN, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE);
break;
#endif
- #if SERIAL2_ENABLE
+ #ifdef SERIAL1_PORT
case 1:
- #ifdef UART2_TX_PIN
- uart_set_pin(uart->num, UART2_TX_PIN, UART2_RX_PIN, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE);
+ #ifdef UART1_TX_PIN
+ uart_set_pin(uart->num, UART1_TX_PIN, UART1_RX_PIN, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE);
#else
- uart_set_pin(uart->num, UART_PIN_NO_CHANGE, UART2_RX_PIN, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE);
+ uart_set_pin(uart->num, UART_PIN_NO_CHANGE, UART1_RX_PIN, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE);
#endif
break;
#endif
- #if SERIAL3_ENABLE
+ #ifdef SERIAL2_PORT
case 2:
- #ifdef UART3_TX_PIN
- uart_set_pin(uart->num, UART3_TX_PIN, UART3_RX_PIN, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE);
+ #ifdef UART2_TX_PIN
+ uart_set_pin(uart->num, UART2_TX_PIN, UART2_RX_PIN, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE);
#else
- uart_set_pin(uart->num, UART_PIN_NO_CHANGE, UART3_RX_PIN, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE);
+ uart_set_pin(uart->num, UART_PIN_NO_CHANGE, UART2_RX_PIN, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE);
#endif
break;
#endif
}
-#endif // SERIAL2_ENABLE || SERIAL3_ENABLE
+#endif // SERIAL1_PORT || SERIAL2_PORT
UART_MUTEX_UNLOCK(uart);
}
@@ -415,11 +430,11 @@ FORCE_INLINE_ATTR uint32_t _uart_ll_get_txfifo_count (uart_dev_t *hw)
// UART0
-IRAM_ATTR static void _uart1_isr (void *arg)
+IRAM_ATTR static void _uart0_isr (void *arg)
{
- uint32_t c, cnt = uart_ll_get_rxfifo_len(uart1.dev), iflags = uart_ll_get_intsts_mask(uart1.dev);
+ uint32_t c, cnt = uart_ll_get_rxfifo_len(uart0.dev), iflags = uart_ll_get_intsts_mask(uart0.dev);
- uart_ll_clr_intsts_mask(uart1.dev, iflags);
+ uart_ll_clr_intsts_mask(uart0.dev, iflags);
if(iflags & UART_INTR_RXFIFO_OVF)
rxbuffer.overflow = On;
@@ -427,7 +442,7 @@ IRAM_ATTR static void _uart1_isr (void *arg)
while(cnt) {
cnt--;
- c = _uart_ll_read_rxfifo(uart1.dev);
+ c = _uart_ll_read_rxfifo(uart0.dev);
if(!enqueue_realtime_command(c)) {
@@ -452,7 +467,7 @@ static uint16_t serialAvailable (void)
uint16_t static serialTxCount (void)
{
- return uart_ll_is_tx_idle(uart1.dev) ? 0 : (uint16_t)_uart_ll_get_txfifo_count(uart1.dev) + 1;
+ return uart_ll_is_tx_idle(uart0.dev) ? 0 : (uint16_t)_uart_ll_get_txfifo_count(uart0.dev) + 1;
}
static uint16_t serialRXFree (void)
@@ -478,12 +493,12 @@ static int16_t serialRead (void)
static bool serialPutC (const char c)
{
- while(_uart_ll_get_txfifo_count(uart1.dev) == uart1.tx_len) {
+ while(_uart_ll_get_txfifo_count(uart0.dev) == uart0.tx_len) {
if(!hal.stream_blocking_callback())
return false;
}
- _uart_ll_write_txfifo(uart1.dev, c);
+ _uart_ll_write_txfifo(uart0.dev, c);
return true;
}
@@ -509,69 +524,69 @@ void static serialWrite (const char *s, uint16_t length)
IRAM_ATTR static void serialFlush (void)
{
- UART_MUTEX_LOCK(&uart1);
+ UART_MUTEX_LOCK(&uart0);
- _uart_flush(&uart1, false);
+ _uart_flush(&uart0, false);
rxbuffer.tail = rxbuffer.head;
rxbuffer.overflow = Off;
- UART_MUTEX_UNLOCK(&uart1);
+ UART_MUTEX_UNLOCK(&uart0);
}
IRAM_ATTR static void serialTxFlush (void)
{
- UART_MUTEX_LOCK(&uart1);
+ UART_MUTEX_LOCK(&uart0);
- _uart_flush(&uart1, true);
+ _uart_flush(&uart0, true);
- UART_MUTEX_UNLOCK(&uart1);
+ UART_MUTEX_UNLOCK(&uart0);
}
IRAM_ATTR static void serialCancel (void)
{
- UART_MUTEX_LOCK(&uart1);
+ UART_MUTEX_LOCK(&uart0);
rxbuffer.data[rxbuffer.head] = ASCII_CAN;
rxbuffer.tail = rxbuffer.head;
rxbuffer.head = (rxbuffer.tail + 1) & (RX_BUFFER_SIZE - 1);
- UART_MUTEX_UNLOCK(&uart1);
+ UART_MUTEX_UNLOCK(&uart0);
}
IRAM_ATTR static bool serialSuspendInput (bool suspend)
{
- UART_MUTEX_LOCK(&uart1);
+ UART_MUTEX_LOCK(&uart0);
bool ok = stream_rx_suspend(&rxbuffer, suspend);
- UART_MUTEX_UNLOCK(&uart1);
+ UART_MUTEX_UNLOCK(&uart0);
return ok;
}
IRAM_ATTR static bool serialDisable (bool disable)
{
- UART_MUTEX_LOCK(&uart1);
+ UART_MUTEX_LOCK(&uart0);
- uart_ll_disable_intr_mask(uart1.dev, rx_int_flags);
+ uart_ll_disable_intr_mask(uart0.dev, rx_int_flags);
if(!disable) {
// Clear and enable interrupts
- _uart_flush(&uart1, false);
+ _uart_flush(&uart0, false);
rxbuffer.tail = rxbuffer.head;
- uart_ll_clr_intsts_mask(uart1.dev, rx_int_flags);
- uart_ll_ena_intr_mask(uart1.dev, rx_int_flags);
+ uart_ll_clr_intsts_mask(uart0.dev, rx_int_flags);
+ uart_ll_ena_intr_mask(uart0.dev, rx_int_flags);
}
- UART_MUTEX_UNLOCK(&uart1);
+ UART_MUTEX_UNLOCK(&uart0);
return true;
}
static bool serialSetBaudRate (uint32_t baud_rate)
{
- uartSetBaudRate(&uart1, baud_rate);
+ uartSetBaudRate(&uart0, baud_rate);
return true;
}
@@ -618,197 +633,197 @@ static const io_stream_t *serialInit (uint32_t baud_rate)
serial[0].flags.claimed = On;
- memcpy(&uart1, &_uart_bus_array[0], sizeof(uart_t)); // use UART 0
+ memcpy(&uart0, &_uart_bus_array[0], sizeof(uart_t)); // use UART 0
- uartConfig(&uart1, baud_rate);
+ uartConfig(&uart0, baud_rate);
serialFlush();
- uartEnableInterrupt(&uart1, _uart1_isr, true);
+ uartEnableInterrupt(&uart0, _uart0_isr, true);
return &stream;
}
-#if SERIAL2_ENABLE
+#ifdef SERIAL1_PORT
-static void IRAM_ATTR _uart2_isr (void *arg)
+static void IRAM_ATTR _uart1_isr (void *arg)
{
- uint32_t c, cnt = uart_ll_get_rxfifo_len(uart2.dev), iflags = uart_ll_get_intsts_mask(uart2.dev);
+ uint32_t c, cnt = uart_ll_get_rxfifo_len(uart1.dev), iflags = uart_ll_get_intsts_mask(uart1.dev);
- uart_ll_clr_intsts_mask(uart2.dev, iflags);
+ uart_ll_clr_intsts_mask(uart1.dev, iflags);
if(iflags & UART_INTR_RXFIFO_OVF)
- rxbuffer2.overflow = On;
+ rxbuffer1.overflow = On;
while(cnt) {
cnt--;
- c = _uart_ll_read_rxfifo(uart2.dev);
+ c = _uart_ll_read_rxfifo(uart1.dev);
if(!enqueue_realtime_command2(c)) {
- uint32_t bptr = (rxbuffer2.head + 1) & RX_BUFFER_SIZE_MASK; // Get next head pointer
+ uint32_t bptr = (rxbuffer1.head + 1) & RX_BUFFER_SIZE_MASK; // Get next head pointer
- if(bptr == rxbuffer2.tail) // If buffer full
- rxbuffer2.overflow = On; // flag overflow,
+ if(bptr == rxbuffer1.tail) // If buffer full
+ rxbuffer1.overflow = On; // flag overflow,
else {
- rxbuffer2.data[rxbuffer2.head] = (char)c; // else add data to buffer
- rxbuffer2.head = bptr; // and update pointer
+ rxbuffer1.data[rxbuffer1.head] = (char)c; // else add data to buffer
+ rxbuffer1.head = bptr; // and update pointer
}
}
}
}
-uint16_t static serial2Available (void)
+uint16_t static serial1Available (void)
{
- uint16_t head = rxbuffer2.head, tail = rxbuffer2.tail;
+ uint16_t head = rxbuffer1.head, tail = rxbuffer1.tail;
return BUFCOUNT(head, tail, RX_BUFFER_SIZE);
}
-uint16_t static serial2TxCount (void)
+uint16_t static serial1TxCount (void)
{
- return uart_ll_is_tx_idle(uart2.dev) ? 0 : (uint16_t)_uart_ll_get_txfifo_count(uart2.dev) + 1;
+ return uart_ll_is_tx_idle(uart1.dev) ? 0 : (uint16_t)_uart_ll_get_txfifo_count(uart1.dev) + 1;
}
-uint16_t static serial2RXFree (void)
+uint16_t static serial1RXFree (void)
{
- uint16_t head = rxbuffer2.head, tail = rxbuffer2.tail;
+ uint16_t head = rxbuffer1.head, tail = rxbuffer1.tail;
return (RX_BUFFER_SIZE - 1) - BUFCOUNT(head, tail, RX_BUFFER_SIZE);
}
-bool static serial2PutC (const char c)
+bool static serial1PutC (const char c)
{
- UART_MUTEX_LOCK(&uart2);
+ UART_MUTEX_LOCK(&uart1);
- while(_uart_ll_get_txfifo_count(uart2.dev) == uart2.tx_len) {
+ while(_uart_ll_get_txfifo_count(uart1.dev) == uart1.tx_len) {
if(!hal.stream_blocking_callback())
return false;
}
- _uart_ll_write_txfifo(uart2.dev, c);
+ _uart_ll_write_txfifo(uart1.dev, c);
- UART_MUTEX_UNLOCK(&uart2);
+ UART_MUTEX_UNLOCK(&uart1);
return true;
}
-void static serial2WriteS (const char *data)
+void static serial1WriteS (const char *data)
{
char c, *ptr = (char *)data;
while((c = *ptr++) != '\0')
- serial2PutC(c);
+ serial1PutC(c);
}
//
// Writes a number of characters from a buffer to the serial output stream, blocks if buffer full
//
-void static serial2Write (const char *s, uint16_t length)
+void static serial1Write (const char *s, uint16_t length)
{
char *ptr = (char *)s;
while(length--)
- serial2PutC(*ptr++);
+ serial1PutC(*ptr++);
}
-int16_t static serial2Read (void)
+int16_t static serial1Read (void)
{
- UART_MUTEX_LOCK(&uart2);
+ UART_MUTEX_LOCK(&uart1);
int16_t data;
- uint16_t bptr = rxbuffer2.tail;
+ uint16_t bptr = rxbuffer1.tail;
- if(bptr == rxbuffer2.head) {
- UART_MUTEX_UNLOCK(&uart2);
+ if(bptr == rxbuffer1.head) {
+ UART_MUTEX_UNLOCK(&uart1);
return -1; // no data available else EOF
}
- data = rxbuffer2.data[bptr++]; // Get next character, increment tmp pointer
- rxbuffer2.tail = bptr & (RX_BUFFER_SIZE - 1); // and update pointer
+ data = rxbuffer1.data[bptr++]; // Get next character, increment tmp pointer
+ rxbuffer1.tail = bptr & (RX_BUFFER_SIZE - 1); // and update pointer
- UART_MUTEX_UNLOCK(&uart2);
+ UART_MUTEX_UNLOCK(&uart1);
return data;
}
-IRAM_ATTR static void serial2Flush (void)
+IRAM_ATTR static void serial1Flush (void)
{
- UART_MUTEX_LOCK(&uart2);
+ UART_MUTEX_LOCK(&uart1);
- _uart_flush(&uart2, false);
+ _uart_flush(&uart1, false);
- rxbuffer2.tail = rxbuffer2.head;
- rxbuffer2.overflow = Off;
+ rxbuffer1.tail = rxbuffer1.head;
+ rxbuffer1.overflow = Off;
- UART_MUTEX_UNLOCK(&uart2);
+ UART_MUTEX_UNLOCK(&uart1);
}
-IRAM_ATTR static void serial2TxFlush (void)
+IRAM_ATTR static void serial1TxFlush (void)
{
- UART_MUTEX_LOCK(&uart2);
+ UART_MUTEX_LOCK(&uart1);
- _uart_flush(&uart2, true);
+ _uart_flush(&uart1, true);
- UART_MUTEX_UNLOCK(&uart2);
+ UART_MUTEX_UNLOCK(&uart1);
}
-IRAM_ATTR static void serial2Cancel (void)
+IRAM_ATTR static void serial1Cancel (void)
{
- UART_MUTEX_LOCK(&uart2);
+ UART_MUTEX_LOCK(&uart1);
- rxbuffer2.data[rxbuffer2.head] = ASCII_CAN;
- rxbuffer2.tail = rxbuffer2.head;
- rxbuffer2.head = (rxbuffer2.tail + 1) & (RX_BUFFER_SIZE - 1);
+ rxbuffer1.data[rxbuffer1.head] = ASCII_CAN;
+ rxbuffer1.tail = rxbuffer1.head;
+ rxbuffer1.head = (rxbuffer1.tail + 1) & (RX_BUFFER_SIZE - 1);
- UART_MUTEX_UNLOCK(&uart2);
+ UART_MUTEX_UNLOCK(&uart1);
}
-static bool serial2SuspendInput (bool suspend)
+static bool serial1SuspendInput (bool suspend)
{
bool ok;
- UART_MUTEX_LOCK(&uart2);
+ UART_MUTEX_LOCK(&uart1);
- ok = stream_rx_suspend(&rxbuffer2, suspend);
+ ok = stream_rx_suspend(&rxbuffer1, suspend);
- UART_MUTEX_UNLOCK(&uart2);
+ UART_MUTEX_UNLOCK(&uart1);
return ok;
}
-IRAM_ATTR static bool serial2Disable (bool disable)
+IRAM_ATTR static bool serial1Disable (bool disable)
{
- UART_MUTEX_LOCK(&uart2);
+ UART_MUTEX_LOCK(&uart1);
- uart_ll_disable_intr_mask(uart2.dev, rx_int_flags);
+ uart_ll_disable_intr_mask(uart1.dev, rx_int_flags);
if(!disable) {
// Clear and enable interrupts
- _uart_flush(&uart2, false);
- rxbuffer2.tail = rxbuffer2.head;
- uart_ll_clr_intsts_mask(uart2.dev, rx_int_flags);
- uart_ll_ena_intr_mask(uart2.dev, rx_int_flags);
+ _uart_flush(&uart1, false);
+ rxbuffer1.tail = rxbuffer1.head;
+ uart_ll_clr_intsts_mask(uart1.dev, rx_int_flags);
+ uart_ll_ena_intr_mask(uart1.dev, rx_int_flags);
}
- UART_MUTEX_UNLOCK(&uart2);
+ UART_MUTEX_UNLOCK(&uart1);
return true;
}
-static bool serial2SetBaudRate (uint32_t baud_rate)
+static bool serial1SetBaudRate (uint32_t baud_rate)
{
- uartSetBaudRate(&uart2, baud_rate);
+ uartSetBaudRate(&uart1, baud_rate);
return true;
}
-static bool serial2EnqueueRtCommand (char c)
+static bool serial1EnqueueRtCommand (char c)
{
return enqueue_realtime_command2(c);
}
-static enqueue_realtime_command_ptr serial2SetRtHandler (enqueue_realtime_command_ptr handler)
+static enqueue_realtime_command_ptr serial1SetRtHandler (enqueue_realtime_command_ptr handler)
{
enqueue_realtime_command_ptr prev = enqueue_realtime_command2;
@@ -818,27 +833,27 @@ static enqueue_realtime_command_ptr serial2SetRtHandler (enqueue_realtime_comman
return prev;
}
-static const io_stream_t *serial2Init (uint32_t baud_rate)
+static const io_stream_t *serial1Init (uint32_t baud_rate)
{
static const io_stream_t stream = {
.type = StreamType_Serial,
.instance = 1,
.is_connected = stream_connected,
- .read = serial2Read,
- .write = serial2WriteS,
- .write_n = serial2Write,
- .write_char = serial2PutC,
- .enqueue_rt_command = serial2EnqueueRtCommand,
- .get_rx_buffer_free = serial2RXFree,
- .get_rx_buffer_count = serial2Available,
- .get_tx_buffer_count = serial2TxCount,
- .reset_write_buffer = serial2TxFlush,
- .reset_read_buffer = serial2Flush,
- .cancel_read_buffer = serial2Cancel,
- .suspend_read = serial2SuspendInput,
- .set_baud_rate = serial2SetBaudRate,
- .disable_rx = serial2Disable,
- .set_enqueue_rt_handler = serial2SetRtHandler
+ .read = serial1Read,
+ .write = serial1WriteS,
+ .write_n = serial1Write,
+ .write_char = serial1PutC,
+ .enqueue_rt_command = serial1EnqueueRtCommand,
+ .get_rx_buffer_free = serial1RXFree,
+ .get_rx_buffer_count = serial1Available,
+ .get_tx_buffer_count = serial1TxCount,
+ .reset_write_buffer = serial1TxFlush,
+ .reset_read_buffer = serial1Flush,
+ .cancel_read_buffer = serial1Cancel,
+ .suspend_read = serial1SuspendInput,
+ .set_baud_rate = serial1SetBaudRate,
+ .disable_rx = serial1Disable,
+ .set_enqueue_rt_handler = serial1SetRtHandler
};
if(serial[1].flags.claimed)
@@ -846,203 +861,203 @@ static const io_stream_t *serial2Init (uint32_t baud_rate)
serial[1].flags.claimed = On;
- memcpy(&uart2, &_uart_bus_array[1], sizeof(uart_t)); // use UART 1
+ memcpy(&uart1, &_uart_bus_array[1], sizeof(uart_t)); // use UART 1
- uartConfig(&uart2, baud_rate);
+ uartConfig(&uart1, baud_rate);
- serial2Flush();
-#ifdef UART2_TX_PIN
- uartEnableInterrupt(&uart2, _uart2_isr, true);
+ serial1Flush();
+#ifdef UART1_TX_PIN
+ uartEnableInterrupt(&uart1, _uart1_isr, true);
#else
- uartEnableInterrupt(&uart2, _uart2_isr, false);
+ uartEnableInterrupt(&uart1, _uart1_isr, false);
#endif
return &stream;
}
-#endif // SERIAL2_ENABLE
+#endif // SERIAL1_PORT
-#if SERIAL3_ENABLE
+#ifdef SERIAL2_PORT
-static void IRAM_ATTR _uart3_isr (void *arg)
+static void IRAM_ATTR _uart2_isr (void *arg)
{
- uint32_t c, cnt = uart_ll_get_rxfifo_len(uart3.dev), iflags = uart_ll_get_intsts_mask(uart3.dev);
+ uint32_t c, cnt = uart_ll_get_rxfifo_len(uart2.dev), iflags = uart_ll_get_intsts_mask(uart2.dev);
- uart_ll_clr_intsts_mask(uart3.dev, iflags);
+ uart_ll_clr_intsts_mask(uart2.dev, iflags);
if(iflags & UART_INTR_RXFIFO_OVF)
- rxbuffer3.overflow = On;
+ rxbuffer2.overflow = On;
while(cnt) {
cnt--;
- c = _uart_ll_read_rxfifo(uart3.dev);
+ c = _uart_ll_read_rxfifo(uart2.dev);
if(!enqueue_realtime_command3(c)) {
- uint32_t bptr = (rxbuffer3.head + 1) & RX_BUFFER_SIZE_MASK; // Get next head pointer
+ uint32_t bptr = (rxbuffer2.head + 1) & RX_BUFFER_SIZE_MASK; // Get next head pointer
- if(bptr == rxbuffer3.tail) // If buffer full
- rxbuffer3.overflow = On; // flag overflow,
+ if(bptr == rxbuffer2.tail) // If buffer full
+ rxbuffer2.overflow = On; // flag overflow,
else {
- rxbuffer3.data[rxbuffer3.head] = (char)c; // else add data to buffer
- rxbuffer3.head = bptr; // and update pointer
+ rxbuffer2.data[rxbuffer2.head] = (char)c; // else add data to buffer
+ rxbuffer2.head = bptr; // and update pointer
}
}
}
}
-uint16_t static serial3Available (void)
+uint16_t static serial2Available (void)
{
- uint16_t head = rxbuffer3.head, tail = rxbuffer3.tail;
+ uint16_t head = rxbuffer2.head, tail = rxbuffer2.tail;
return BUFCOUNT(head, tail, RX_BUFFER_SIZE);
}
-uint16_t static serial3TxCount (void)
+uint16_t static serial2TxCount (void)
{
- return uart_ll_is_tx_idle(uart3.dev) ? 0 : (uint16_t)_uart_ll_get_txfifo_count(uart3.dev) + 1;
+ return uart_ll_is_tx_idle(uart2.dev) ? 0 : (uint16_t)_uart_ll_get_txfifo_count(uart2.dev) + 1;
}
-uint16_t static serial3RXFree (void)
+uint16_t static serial2RXFree (void)
{
- uint16_t head = rxbuffer3.head, tail = rxbuffer3.tail;
+ uint16_t head = rxbuffer2.head, tail = rxbuffer2.tail;
return (RX_BUFFER_SIZE - 1) - BUFCOUNT(head, tail, RX_BUFFER_SIZE);
}
-bool static serial3PutC (const char c)
+bool static serial2PutC (const char c)
{
- UART_MUTEX_LOCK(&uart3);
+ UART_MUTEX_LOCK(&uart2);
serialPutC(c);
- while(_uart_ll_get_txfifo_count(uart3.dev) == uart3.tx_len) {
+ while(_uart_ll_get_txfifo_count(uart2.dev) == uart2.tx_len) {
if(!hal.stream_blocking_callback())
return false;
}
- _uart_ll_write_txfifo(uart3.dev, c);
+ _uart_ll_write_txfifo(uart2.dev, c);
- UART_MUTEX_UNLOCK(&uart3);
+ UART_MUTEX_UNLOCK(&uart2);
return true;
}
-void static serial3WriteS (const char *data)
+void static serial2WriteS (const char *data)
{
char c, *ptr = (char *)data;
while((c = *ptr++) != '\0')
- serial3PutC(c);
+ serial2PutC(c);
}
//
// Writes a number of characters from a buffer to the serial output stream, blocks if buffer full
//
-void static serial3Write (const char *s, uint16_t length)
+void static serial2Write (const char *s, uint16_t length)
{
char *ptr = (char *)s;
while(length--)
- serial3PutC(*ptr++);
+ serial2PutC(*ptr++);
}
-int16_t static serial3Read (void)
+int16_t static serial2Read (void)
{
- UART_MUTEX_LOCK(&uart3);
+ UART_MUTEX_LOCK(&uart2);
int16_t data;
- uint16_t bptr = rxbuffer3.tail;
+ uint16_t bptr = rxbuffer2.tail;
- if(bptr == rxbuffer3.head) {
- UART_MUTEX_UNLOCK(&uart3);
+ if(bptr == rxbuffer2.head) {
+ UART_MUTEX_UNLOCK(&uart2);
return -1; // no data available else EOF
}
- data = rxbuffer3.data[bptr++]; // Get next character, increment tmp pointer
- rxbuffer3.tail = bptr & (RX_BUFFER_SIZE - 1); // and update pointer
+ data = rxbuffer2.data[bptr++]; // Get next character, increment tmp pointer
+ rxbuffer2.tail = bptr & (RX_BUFFER_SIZE - 1); // and update pointer
- UART_MUTEX_UNLOCK(&uart3);
+ UART_MUTEX_UNLOCK(&uart2);
return data;
}
-IRAM_ATTR static void serial3Flush (void)
+IRAM_ATTR static void serial2Flush (void)
{
- UART_MUTEX_LOCK(&uart3);
+ UART_MUTEX_LOCK(&uart2);
- _uart_flush(&uart3, false);
+ _uart_flush(&uart2, false);
- rxbuffer3.tail = rxbuffer3.head;
- rxbuffer3.overflow = Off;
+ rxbuffer2.tail = rxbuffer2.head;
+ rxbuffer2.overflow = Off;
- UART_MUTEX_UNLOCK(&uart3);
+ UART_MUTEX_UNLOCK(&uart2);
}
-IRAM_ATTR static void serial3TxFlush (void)
+IRAM_ATTR static void serial2TxFlush (void)
{
- UART_MUTEX_LOCK(&uart3);
+ UART_MUTEX_LOCK(&uart2);
- _uart_flush(&uart3, true);
+ _uart_flush(&uart2, true);
- UART_MUTEX_UNLOCK(&uart3);
+ UART_MUTEX_UNLOCK(&uart2);
}
-IRAM_ATTR static void serial3Cancel (void)
+IRAM_ATTR static void serial2Cancel (void)
{
- UART_MUTEX_LOCK(&uart3);
+ UART_MUTEX_LOCK(&uart2);
- rxbuffer3.data[rxbuffer3.head] = ASCII_CAN;
- rxbuffer3.tail = rxbuffer3.head;
- rxbuffer3.head = (rxbuffer3.tail + 1) & (RX_BUFFER_SIZE - 1);
+ rxbuffer2.data[rxbuffer2.head] = ASCII_CAN;
+ rxbuffer2.tail = rxbuffer2.head;
+ rxbuffer2.head = (rxbuffer2.tail + 1) & (RX_BUFFER_SIZE - 1);
- UART_MUTEX_UNLOCK(&uart3);
+ UART_MUTEX_UNLOCK(&uart2);
}
-static bool serial3SuspendInput (bool suspend)
+static bool serial2SuspendInput (bool suspend)
{
bool ok;
- UART_MUTEX_LOCK(&uart3);
+ UART_MUTEX_LOCK(&uart2);
- ok = stream_rx_suspend(&rxbuffer3, suspend);
+ ok = stream_rx_suspend(&rxbuffer2, suspend);
- UART_MUTEX_UNLOCK(&uart3);
+ UART_MUTEX_UNLOCK(&uart2);
return ok;
}
-IRAM_ATTR static bool serial3Disable (bool disable)
+IRAM_ATTR static bool serial2Disable (bool disable)
{
- UART_MUTEX_LOCK(&uart3);
+ UART_MUTEX_LOCK(&uart2);
- uart_ll_disable_intr_mask(uart3.dev, rx_int_flags);
+ uart_ll_disable_intr_mask(uart2.dev, rx_int_flags);
if(!disable) {
// Clear and enable interrupts
- _uart_flush(&uart3, false);
- rxbuffer3.tail = rxbuffer3.head;
- uart_ll_clr_intsts_mask(uart3.dev, rx_int_flags);
- uart_ll_ena_intr_mask(uart3.dev, rx_int_flags);
+ _uart_flush(&uart2, false);
+ rxbuffer2.tail = rxbuffer2.head;
+ uart_ll_clr_intsts_mask(uart2.dev, rx_int_flags);
+ uart_ll_ena_intr_mask(uart2.dev, rx_int_flags);
}
- UART_MUTEX_UNLOCK(&uart3);
+ UART_MUTEX_UNLOCK(&uart2);
return true;
}
-static bool serial3SetBaudRate (uint32_t baud_rate)
+static bool serial2SetBaudRate (uint32_t baud_rate)
{
- uartSetBaudRate(&uart3, baud_rate);
+ uartSetBaudRate(&uart2, baud_rate);
return true;
}
-static bool serial3EnqueueRtCommand (char c)
+static bool serial2EnqueueRtCommand (char c)
{
return enqueue_realtime_command3(c);
}
-static enqueue_realtime_command_ptr serial3SetRtHandler (enqueue_realtime_command_ptr handler)
+static enqueue_realtime_command_ptr serial2SetRtHandler (enqueue_realtime_command_ptr handler)
{
enqueue_realtime_command_ptr prev = enqueue_realtime_command3;
@@ -1052,27 +1067,27 @@ static enqueue_realtime_command_ptr serial3SetRtHandler (enqueue_realtime_comman
return prev;
}
-static const io_stream_t *serial3Init (uint32_t baud_rate)
+static const io_stream_t *serial2Init (uint32_t baud_rate)
{
static const io_stream_t stream = {
.type = StreamType_Serial,
.instance = 2,
.is_connected = stream_connected,
- .read = serial3Read,
- .write = serial3WriteS,
- .write_n = serial3Write,
- .write_char = serial3PutC,
- .enqueue_rt_command = serial3EnqueueRtCommand,
- .get_rx_buffer_free = serial3RXFree,
- .get_rx_buffer_count = serial3Available,
- .get_tx_buffer_count = serial3TxCount,
- .reset_write_buffer = serial3TxFlush,
- .reset_read_buffer = serial3Flush,
- .cancel_read_buffer = serial3Cancel,
- .suspend_read = serial3SuspendInput,
- .set_baud_rate = serial3SetBaudRate,
- .disable_rx = serial3Disable,
- .set_enqueue_rt_handler = serial3SetRtHandler
+ .read = serial2Read,
+ .write = serial2WriteS,
+ .write_n = serial2Write,
+ .write_char = serial2PutC,
+ .enqueue_rt_command = serial2EnqueueRtCommand,
+ .get_rx_buffer_free = serial2RXFree,
+ .get_rx_buffer_count = serial2Available,
+ .get_tx_buffer_count = serial2TxCount,
+ .reset_write_buffer = serial2TxFlush,
+ .reset_read_buffer = serial2Flush,
+ .cancel_read_buffer = serial2Cancel,
+ .suspend_read = serial2SuspendInput,
+ .set_baud_rate = serial2SetBaudRate,
+ .disable_rx = serial2Disable,
+ .set_enqueue_rt_handler = serial2SetRtHandler
};
if(serial[2].flags.claimed)
@@ -1080,18 +1095,18 @@ static const io_stream_t *serial3Init (uint32_t baud_rate)
serial[2].flags.claimed = On;
- memcpy(&uart3, &_uart_bus_array[2], sizeof(uart_t)); // use UART 2
+ memcpy(&uart2, &_uart_bus_array[2], sizeof(uart_t)); // use UART 2
- uartConfig(&uart3, baud_rate);
+ uartConfig(&uart2, baud_rate);
- serial3Flush();
-#ifdef UART3_TX_PIN
- uartEnableInterrupt(&uart3, _uart3_isr, true);
+ serial2Flush();
+#ifdef UART2_TX_PIN
+ uartEnableInterrupt(&uart2, _uart2_isr, true);
#else
- uartEnableInterrupt(&uart3, _uart3_isr, false);
+ uartEnableInterrupt(&uart2, _uart2_isr, false);
#endif
return &stream;
}
-#endif // SERIAL3_ENABLE
+#endif // SERIAL2_PORT