Skip to content

Commit

Permalink
Updated for simplified keypad and MPG symbol handling.
Browse files Browse the repository at this point in the history
  • Loading branch information
terjeio committed Aug 17, 2024
1 parent a897da4 commit ce4d9b0
Show file tree
Hide file tree
Showing 7 changed files with 58 additions and 53 deletions.
7 changes: 5 additions & 2 deletions main/boards/cnc_boosterpack_map.h
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@
#endif

#ifdef ADD_SERIAL2
#if MPG_MODE == 1
#if MPG_ENABLE == 1
#define MPG_ENABLE_PIN GPIO_NUM_25
#else
#define UART2_TX_PIN GPIO_NUM_25
Expand All @@ -131,9 +131,12 @@
#define MODBUS_DIRECTION_PIN GPIO_NUM_25 //??
#endif
#else
#define AUXOUTPUT0_PIN GPIO_NUM_25
//#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
Expand Down
2 changes: 1 addition & 1 deletion main/boards/cnc_boosterpack_s3_map.h
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@
#endif
#endif

#if MPG_MODE == 1
#if MPG_ENABLE == 1
#define UART2_RX_PIN GPIO_NUM_33
#define MPG_ENABLE_PIN GPIO_NUM_25
#endif
Expand Down
2 changes: 1 addition & 1 deletion main/boards/mks_tinybee_1_0_map.h
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@

#if MODBUS_ENABLE & MODBUS_RTU_DIR_ENABLED
#define MODBUS_DIRECTION_PIN GPIO_NUM_13 // EXP_1
#elif MPG_MODE == 1
#elif MPG_ENABLE == 1
#define MPG_ENABLE_PIN GPIO_NUM_13 // EXP_1
#endif

Expand Down
39 changes: 26 additions & 13 deletions main/boards/root_cnc_pro_map.h
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@
Part of grblHAL
Copyright (c) 2024 NEWTech Creative 2024
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
Expand All @@ -28,6 +30,10 @@
#error No free pins for I2C keypad!
#endif

#if TRINAMIC_ENABLE != 5160
#error BOARD_ROOTCNC_PRO has soldered TMC5160 drivers.
#endif

#define USE_I2S_OUT
#define I2S_OUT_PIN_BASE 64

Expand All @@ -39,13 +45,15 @@

// 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
#define PIN_NUM_MISO GPIO_NUM_19
#define PIN_NUM_MOSI GPIO_NUM_23
#define PIN_NUM_CLK GPIO_NUM_18
#define MOTOR_CS_PIN GPIO_NUM_17
#if SDCARD_ENABLE
#define PIN_NUM_CS GPIO_NUM_5
#endif

#endif // SDCARD_ENABLE || TRINAMIC_SPI_ENABLE

#define I2S_OUT_BCK GPIO_NUM_22
Expand All @@ -55,16 +63,19 @@
#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 X_CS_PIN I2SO(2)
#define X_LIMIT_PIN GPIO_NUM_39

#define Y_STEP_PIN I2SO(21)
#define Y_DIRECTION_PIN I2SO(20)
#define Y_ENABLE_PIN I2SO(19)
#define Y_CS_PIN I2SO(2)
#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_CS_PIN I2SO(30)
#define Z_LIMIT_PIN GPIO_NUM_36

// Define ganged axis or A axis step pulse and step direction output pins.
Expand All @@ -73,7 +84,7 @@
#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
#define M3_CS_PIN I2SO(14)
#endif

// Define ganged axis or B axis step pulse and step direction output pins.
Expand All @@ -82,7 +93,7 @@
#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
#define M4_CS_PIN I2SO(10)
#endif

// Define ganged axis or B axis step pulse and step direction output pins.
Expand All @@ -91,6 +102,7 @@
#define M5_STEP_PIN I2SO(17)
#define M5_DIRECTION_PIN I2SO(16)
#define M5_ENABLE_PIN I2SO(31)
#define M5_CS_PIN I2SO(18)
#endif

// Define driver spindle pins
Expand Down Expand Up @@ -128,17 +140,18 @@
#define AUXINPUT0_PIN GPIO_NUM_33
#define AUXINPUT1_PIN GPIO_NUM_26
#define AUXINPUT2_PIN GPIO_NUM_2
#define AUXINPUT3_PIN GPIO_NUM_15

#if PROBE_ENABLE
#define PROBE_PIN AUXINPUT0_PIN
#define PROBE_PIN AUXINPUT3_PIN
#endif

#if SAFETY_DOOR_ENABLE
#define SAFETY_DOOR_PIN AUXINPUT1_PIN
#define SAFETY_DOOR_PIN AUXINPUT2_PIN
#endif

#if CYCLE_START_ENABLE
#define SAFETY_DOOR_PIN AUXINPUT2_PIN
#define SAFETY_DOOR_PIN AUXINPUT1_PIN
#endif
// N/A

Expand Down
48 changes: 19 additions & 29 deletions main/driver.c
Original file line number Diff line number Diff line change
Expand Up @@ -88,10 +88,6 @@
#include "sdcard/fs_littlefs.h"
#endif

#if KEYPAD_ENABLE == 2
#include "keypad/keypad.h"
#endif

#if IOEXPAND_ENABLE
#include "ioexpand.h"
#endif
Expand Down Expand Up @@ -233,7 +229,7 @@ static input_signal_t inputpin[] = {
#ifdef PROBE_PIN
{ .id = Input_Probe, .pin = PROBE_PIN, .group = PinGroup_Probe },
#endif
#if MPG_MODE == 1
#if MPG_ENABLE == 1
{ .id = Input_ModeSelect, .pin = MPG_ENABLE_PIN, .group = PinGroup_MPG },
#endif
#ifdef I2C_STROBE_PIN
Expand Down Expand Up @@ -481,7 +477,7 @@ static bool irq_claim (irq_type_t irq, uint_fast8_t id, irq_callback_ptr handler
static void gpio_limit_isr (void *signal);
static void gpio_control_isr (void *signal);
static void gpio_aux_isr (void *signal);
#if MPG_MODE == 1
#if MPG_ENABLE == 1
static void gpio_mpg_isr (void *signal);
#endif
#if I2C_STROBE_ENABLE
Expand Down Expand Up @@ -1548,7 +1544,7 @@ inline IRAM_ATTR static control_signals_t systemGetState (void)
return signals;
}

#if MPG_MODE == 1
#if MPG_ENABLE == 1

static void modeChange (void *data)
{
Expand All @@ -1561,7 +1557,7 @@ static void mpg_enable (void *data)
stream_mpg_enable(true);
}

#endif // MPG_MODE == 1
#endif // MPG_ENABLE == 1

#ifdef PROBE_PIN

Expand Down Expand Up @@ -2193,7 +2189,7 @@ static void settings_changed (settings_t *settings, settings_changed_flags_t cha
signal->mode.inverted = false;
break;

#if MPG_MODE == 1
#if MPG_ENABLE == 1
case Input_ModeSelect:
signal->mode.pull_mode = PullMode_Up;
signal->mode.inverted = false;
Expand Down Expand Up @@ -2657,7 +2653,7 @@ static bool driver_setup (settings_t *settings)
}
} while(idx);

#if MPG_MODE == 1
#if MPG_ENABLE == 1

/************************
* MPG mode (pre)init *
Expand Down Expand Up @@ -2819,7 +2815,7 @@ bool driver_init (void)
#else
hal.info = "ESP32";
#endif
hal.driver_version = "240719";
hal.driver_version = "240817";
hal.driver_url = GRBL_URL "/ESP32";
#ifdef BOARD_NAME
hal.board = BOARD_NAME;
Expand Down Expand Up @@ -3103,22 +3099,6 @@ bool driver_init (void)
board_init();
#endif

#if MPG_MODE == 1
#if KEYPAD_ENABLE == 2
if((hal.driver_cap.mpg_mode = stream_mpg_register(stream_open_instance(MPG_STREAM, 115200, NULL, NULL), false, keypad_enqueue_keycode)))
protocol_enqueue_foreground_task(mpg_enable, NULL);
#else
if((hal.driver_cap.mpg_mode = stream_mpg_register(stream_open_instance(MPG_STREAM, 115200, NULL, NULL), false, NULL)))
protocol_enqueue_foreground_task(mpg_enable, NULL);
#endif
#elif MPG_MODE == 2
hal.driver_cap.mpg_mode = stream_mpg_register(stream_open_instance(MPG_STREAM, 115200, NULL, NULL), false, keypad_enqueue_keycode);
#elif MPG_MODE == 3
hal.driver_cap.mpg_mode = stream_mpg_register(stream_open_instance(MPG_STREAM, 115200, NULL, NULL), false, stream_mpg_check_enable);
#elif KEYPAD_ENABLE == 2
stream_open_instance(KEYPAD_STREAM, 115200, keypad_enqueue_keycode, "Keypad");
#endif

#if WIFI_ENABLE
wifi_init();
#endif
Expand All @@ -3133,6 +3113,16 @@ bool driver_init (void)

#include "grbl/plugins_init.h"

#if MPG_ENABLE == 1
if(!hal.driver_cap.mpg_mode)
hal.driver_cap.mpg_mode = stream_mpg_register(stream_open_instance(MPG_STREAM, 115200, NULL, NULL), false, NULL);
if(hal.driver_cap.mpg_mode)
protocol_enqueue_foreground_task(mpg_enable, NULL);
#elif MPG_ENABLE == 2
if(!hal.driver_cap.mpg_mode)
hal.driver_cap.mpg_mode = stream_mpg_register(stream_open_instance(MPG_STREAM, 115200, NULL, NULL), false, stream_mpg_check_enable);
#endif

// no need to move version check before init - compiler will fail any mismatch for existing entries
return hal.version == 10;
}
Expand Down Expand Up @@ -3208,7 +3198,7 @@ IRAM_ATTR static void gpio_aux_isr (void *signal)
ioports_event((input_signal_t *)signal);
}

#if MPG_MODE == 1
#if MPG_ENABLE == 1

IRAM_ATTR static void gpio_mpg_isr (void *signal)
{
Expand Down Expand Up @@ -3267,7 +3257,7 @@ IRAM_ATTR static void gpio_isr (void *arg)

#if !AUX_CONTROLS_ENABLED

#if MPG_MODE == 1
#if MPG_ENABLE == 1

static bool mpg_mutex = false;

Expand Down
4 changes: 2 additions & 2 deletions main/driver.h
Original file line number Diff line number Diff line change
Expand Up @@ -253,7 +253,7 @@ extern SemaphoreHandle_t i2cBusy;

#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 (MODBUS_TEST + KEYPAD_TEST + MPG_TEST + TRINAMIC_TEST + DEBUG_TEST) || SERIAL_STREAM == 1
#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
Expand Down Expand Up @@ -286,7 +286,7 @@ extern SemaphoreHandle_t i2cBusy;
#endif
#endif

#if MPG_MODE == 1
#if MPG_ENABLE == 1
#ifndef MPG_ENABLE_PIN
#error "MPG_ENABLE_PIN must be defined when MPG mode is enabled!"
#endif
Expand Down
9 changes: 4 additions & 5 deletions main/my_machine.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,12 +67,11 @@
//#define ETHERNET_ENABLE 1 // Ethernet streaming. Uses networking plugin.
//#define BLUETOOTH_ENABLE 1 // Set to 1 for native radio, 2 for HC-05 module.
//#define SDCARD_ENABLE 1 // Run gcode programs from SD card. Set to 2 to enable YModem upload.
//#define MPG_ENABLE 1 // Enable MPG interface. Requires a serial port and means to switch between normal and MPG mode.
// 1: Mode switching is by handshake pin input unless the keypad plugin is enabled in mode 2 which
// uses mode switching by the CMD_MPG_MODE_TOGGLE (0x8B) command character.
// 2: Mode switching is by the CMD_MPG_MODE_TOGGLE command character. The keypad plugin is not required.
//#define MPG_ENABLE 1 // Enable MPG interface. Requires a serial stream and means to switch between normal and MPG mode.
// 1: Mode switching is by handshake pin.
// 2: Mode switching is by the CMD_MPG_ENABLE_TOGGLE (0x8B) command character.
//#define KEYPAD_ENABLE 1 // 1: uses a I2C keypad for input.
// 2: uses a serial port for input. If MPG_ENABLE is set to 1 the serial stream is shared with the MPG.
// 2: uses a serial stream for input. If MPG_ENABLE is set > 0 the serial stream is shared with the MPG.
//#define PPI_ENABLE 1 // Laser PPI plugin. To be completed.
//#define LASER_COOLANT_ENABLE 1 // Laser coolant plugin. To be completed.
//#define LB_CLUSTERS_ENABLE 1 // LaserBurn cluster support.
Expand Down

0 comments on commit ce4d9b0

Please sign in to comment.