From 55165a7908a1a7f18c7630adad96962397644c23 Mon Sep 17 00:00:00 2001 From: Luc Date: Thu, 29 Aug 2019 16:25:17 +0200 Subject: [PATCH] Add SPI pin customization support --- Grbl_Esp32/cpu_map.h | 8 ++++++++ Grbl_Esp32/grbl.h | 2 +- Grbl_Esp32/grbl_sd.cpp | 2 +- Grbl_Esp32/system.cpp | 4 ++++ 4 files changed, 14 insertions(+), 2 deletions(-) diff --git a/Grbl_Esp32/cpu_map.h b/Grbl_Esp32/cpu_map.h index de56ae2f5..001750f18 100644 --- a/Grbl_Esp32/cpu_map.h +++ b/Grbl_Esp32/cpu_map.h @@ -36,6 +36,14 @@ */ +//Set your pine definition +//let -1 to use default board pin +#define GRBL_SPI_SS -1 +#define GRBL_SPI_MOSI -1 +#define GRBL_SPI_MIS0 -1 +#define GRBL_SPI_SCK -1 +//Set you frequency +#define GRBL_SPI_FREQ 4000000 #ifdef CPU_MAP_ESP32 // This is the CPU Map for the ESP32 CNC Controller R2 diff --git a/Grbl_Esp32/grbl.h b/Grbl_Esp32/grbl.h index b78a1e7e5..586286b27 100644 --- a/Grbl_Esp32/grbl.h +++ b/Grbl_Esp32/grbl.h @@ -20,7 +20,7 @@ // Grbl versioning system #define GRBL_VERSION "1.1f" -#define GRBL_VERSION_BUILD "20190708" +#define GRBL_VERSION_BUILD "20190829" //#include #include diff --git a/Grbl_Esp32/grbl_sd.cpp b/Grbl_Esp32/grbl_sd.cpp index 550bb2468..a843dc1bb 100644 --- a/Grbl_Esp32/grbl_sd.cpp +++ b/Grbl_Esp32/grbl_sd.cpp @@ -200,7 +200,7 @@ uint8_t get_sd_state(bool refresh) sd_state = SDCARD_NOT_PRESENT; //using default value for speed ? should be parameter //refresh content if card was removed - if (SD.begin()) { + if (SD.begin((GRBL_SPI_SS == -1)?SS:GRBL_SPI_SS, SPI, GRBL_SPI_FREQ)) { if ( SD.cardSize() > 0 )sd_state = SDCARD_IDLE; } return sd_state; diff --git a/Grbl_Esp32/system.cpp b/Grbl_Esp32/system.cpp index f842f3f64..a2ce3245b 100644 --- a/Grbl_Esp32/system.cpp +++ b/Grbl_Esp32/system.cpp @@ -44,6 +44,10 @@ void system_ini() // Renamed from system_init() due to conflict with esp32 files #endif #endif + //customize pin definition if needed +#if (GRBL_SPI_SS != -1) || (GRBL_SPI_MIS0 != -1) || (GRBL_SPI_MOSI != -1) || (GRBL_SPI_SCK != -1) + SPI.begin(GRBL_SPI_SCK, GRBL_SPI_MIS0, GRBL_SPI_MOSI, GRBL_SPI_SS); +#endif } void IRAM_ATTR isr_control_inputs()