Skip to content

Commit

Permalink
Merge pull request #335 from Paciente8159/esp32-gpio-idf
Browse files Browse the repository at this point in the history
Migrate ESP32 to IDF
  • Loading branch information
Paciente8159 committed Nov 25, 2022
2 parents f10c39a + baa8661 commit 0d5da2e
Show file tree
Hide file tree
Showing 26 changed files with 2,951 additions and 811 deletions.
Binary file modified docs/mcumap_gen.xlsx
Binary file not shown.
2 changes: 1 addition & 1 deletion uCNC/cnc_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -333,7 +333,7 @@ extern "C"
/**
* Runs a check for state change inside the scheduler. This is a failsafe
* check to pin ISR checking The value sets the frequency of this safety
* check that is executed every 2^(CONTROLS_SCHEDULE_CHECK) milliseconds. A
* check that is executed every 2^(CTRL_SCHED_CHECK) milliseconds. A
* negative value will disable this feature. The maximum is 7
* */

Expand Down
2 changes: 1 addition & 1 deletion uCNC/src/cnc.c
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ MCU_CALLBACK void mcu_rtc_cb(uint32_t millis)
#endif

// checks any limit or control input state change (every 16ms)
#if !defined(FORCE_SOFT_POLLING) && CONTROLS_SCHEDULE_CHECK >= 0
#if (!defined(FORCE_SOFT_POLLING) && CTRL_SCHED_CHECK >= 0)
uint8_t mls = (uint8_t)(0xff & millis);
if ((mls & CTRL_SCHED_CHECK_MASK) == CTRL_SCHED_CHECK_VAL)
{
Expand Down
28 changes: 22 additions & 6 deletions uCNC/src/core/parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,10 @@
#define NUMBER_ISFLOAT 0x40
#define NUMBER_ISNEGATIVE 0x80

#ifndef GRBL_CMD_MAX_LEN
#define GRBL_CMD_MAX_LEN 32
#endif

static parser_state_t parser_state;
static parser_parameters_t parser_parameters;
static uint8_t parser_wco_counter;
Expand Down Expand Up @@ -347,8 +351,8 @@ void parser_update_probe_pos(void)
static uint8_t parser_grbl_command(void)
{
serial_getc(); // eat $
unsigned char c = serial_getc();
unsigned char grbl_cmd_str[32];
unsigned char c = serial_peek();
unsigned char grbl_cmd_str[GRBL_CMD_MAX_LEN + 1];
uint8_t grbl_cmd_len = 0;

// if not IDLE
Expand All @@ -367,16 +371,21 @@ static uint8_t parser_grbl_command(void)
}
}

while ((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z'))
do
{
c = serial_getc();
// toupper
if (c >= 'a' && c <= 'z')
{
c -= 32;
}

if (!(c >= 'A' && c <= 'Z'))
{
break;
}
grbl_cmd_str[grbl_cmd_len++] = c;
c = serial_getc();
}
} while ((grbl_cmd_len < GRBL_CMD_MAX_LEN));

grbl_cmd_str[grbl_cmd_len] = 0;

Expand Down Expand Up @@ -570,8 +579,15 @@ static uint8_t parser_grbl_command(void)
break;
}

#ifdef BOARD_HAS_CUSTOM_SYSTEM_COMMANDS
if (mcu_custom_grbl_cmd((char*)grbl_cmd_str, grbl_cmd_len, c) == STATUS_OK)
{
return STATUS_OK;
}
#endif

#ifdef ENABLE_PARSER_MODULES
grbl_cmd_args_t args = {grbl_cmd_str, grbl_cmd_len};
grbl_cmd_args_t args = {grbl_cmd_str, grbl_cmd_len, c};
uint8_t newerror = EVENT_INVOKE(grbl_cmd, &args);
if (newerror >= GRBL_SYSTEM_CMD)
{
Expand Down
1 change: 1 addition & 0 deletions uCNC/src/core/parser.h
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,7 @@ extern "C"
{
unsigned char *cmd;
uint8_t len;
char next_char;
} grbl_cmd_args_t;
DECL_EVENT_HANDLER(grbl_cmd);

Expand Down
4 changes: 1 addition & 3 deletions uCNC/src/hal/boards/esp32/boardmap_mks_dlc32.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,7 @@ extern "C"
// Timer 1 is used by default
//#define ITP_TIMER 1

// Setup the RTC Timer used by µCNC to provide an (mostly) accurate time base for all time dependent functions
// Timer 0 is set by default
//#define RTC_TIMER 0
// RTC Timer on ESP32 is granteed by a FreeRTOS

#define ONESHOT_TIMER 2

Expand Down
16 changes: 12 additions & 4 deletions uCNC/src/hal/boards/esp32/boardmap_mks_tinybee.h
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,14 @@ extern "C"
#define DOUT6_BIT 26
// uses 3 x 74HS595
#define IC74HC595_COUNT 3
#define IC74HC595_DELAY_CYCLES 0
// #define IC74HC595_DELAY_CYCLES 0

//Use I2S to shift data in ESP32
#define IC74HC595_CUSTOM_SHIFT_IO //Enables custom MCU data shift transmission. In ESP32 that is via I2S
#define IC74HC595_I2S_WS 26
#define IC74HC595_I2S_CLK 25
#define IC74HC595_I2S_DATA 27
// #define IC74HC595_I2S_PORT 0

#define STEP0_EN_IO_OFFSET 0
#define STEP0_IO_OFFSET 1
Expand Down Expand Up @@ -76,9 +83,7 @@ extern "C"
// Timer 1 is used by default
//#define ITP_TIMER 1

// Setup the RTC Timer used by µCNC to provide an (mostly) accurate time base for all time dependent functions
// Timer 0 is set by default
//#define RTC_TIMER 0
// RTC Timer on ESP32 is granteed by a FreeRTOS

#define ONESHOT_TIMER 2

Expand All @@ -87,6 +92,9 @@ extern "C"
#define SPI_SDI_BIT 19
#define SPI_CS_BIT 5

//sd card detect
#define DIN19_BIT 34

// include the IO expander
#include "../../../modules/ic74hc595.h"

Expand Down
26 changes: 16 additions & 10 deletions uCNC/src/hal/boards/esp32/boardmap_wemos_d1_r32.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,26 +41,26 @@ extern "C"

// Setup control input pins
#define ESTOP_BIT 2
// #define ESTOP_ISR
#define ESTOP_ISR
#define ESTOP_PULLUP
#define FHOLD_BIT 4
// #define FHOLD_ISR
#define FHOLD_ISR
#define FHOLD_PULLUP
#define CS_RES_BIT 36
// #define CS_RES_ISR
#define CS_RES_ISR
#define CS_RES_PULLUP

// Setup limit pins
#define LIMIT_Z_BIT 19 // assigns LIMIT_Z pin
// #define LIMIT_Z_ISR // assigns LIMIT_Z ISR
#define LIMIT_Z_ISR // assigns LIMIT_Z ISR
#define LIMIT_Y_BIT 5 // assigns LIMIT_Y pin
// #define LIMIT_Y_ISR // assigns LIMIT_Y ISR
#define LIMIT_Y_ISR // assigns LIMIT_Y ISR
#define LIMIT_X_BIT 13 // assigns LIMIT_X pin
// #define LIMIT_X_ISR // assigns LIMIT_X ISR
#define LIMIT_X_ISR // assigns LIMIT_X ISR

// Setup probe pin
#define PROBE_BIT 39
// #define PROBE_ISR
#define PROBE_ISR

// Setup com pins
#define RX_BIT 3
Expand All @@ -70,6 +70,8 @@ extern "C"

// Setup PWM
#define PWM0_BIT 23 // assigns PWM0 pin
#define PWM0_TIMER 0
#define PWM0_CHANNEL 0

// Setup generic IO Pins
// spindle dir
Expand All @@ -85,12 +87,16 @@ extern "C"
// Timer 1 is used by default
//#define ITP_TIMER 1

// Setup the RTC Timer used by µCNC to provide an (mostly) accurate time base for all time dependent functions
// Timer 0 is set by default
//#define RTC_TIMER 0
// RTC Timer on ESP32 is granteed by a FreeRTOS

#define ONESHOT_TIMER 2

// #define ANALOG0_BIT 2
// #define ANALOG0_CHANNEL 2
// #define ANALOG0_ADC 2

// #define SERVO0_BIT 33

#ifdef __cplusplus
}
#endif
Expand Down
33 changes: 8 additions & 25 deletions uCNC/src/hal/boards/esp32/esp32.ini
Original file line number Diff line number Diff line change
Expand Up @@ -2,39 +2,22 @@
# ESP32 Boards #
################

[common_esp32_wifi]
[common_esp32]
platform = espressif32
framework = arduino
board = wemos_d1_uno32
build_src_filter = +<*>-<src/tinyusb>
lib_deps =
https://github.com/tzapu/WiFiManager/archive/refs/heads/master.zip
build_flags = -Os -DENABLE_WIFI
# -DENABLE_BLUETOOTH
upload_speed = 256000
board_build.f_cpu = 240000000L
# board_build.partitions = huge_app.csv

[common_esp32_bt]
platform = espressif32
framework = arduino
board = wemos_d1_uno32
build_src_filter = +<*>-<src/tinyusb>
build_flags = -Os -DENABLE_BLUETOOTH
upload_speed = 256000
build_flags = -mlongcalls -Wno-frame-address -ffunction-sections -fdata-sections -ggdb -Os -freorder-blocks -Wwrite-strings -fstack-protector -fstrict-volatile-bitfields -Wall -fno-jump-tables -fno-tree-switch-conversion -std=gnu++11 -fexceptions -MMD -c -DENABLE_WIFI -DENABLE_BLUETOOTH -DCORE_DEBUG_LEVEL=ARDUHAL_LOG_LEVEL_NONE
board_build.f_flash = 80000000L
board_build.f_cpu = 240000000L
board_build.partitions = huge_app.csv

[env:d1_r32]
extends = common_esp32_wifi
board = wemos_d1_uno32
build_flags = ${common_esp32_wifi.build_flags} -DBOARD=BOARD_WEMOS_D1_R32

[env:d1_r32_bt]
extends = common_esp32_bt
extends = common_esp32
board = wemos_d1_uno32
build_flags = ${common_esp32_bt.build_flags} -DBOARD=BOARD_WEMOS_D1_R32
build_flags = ${common_esp32.build_flags} -DBOARD=BOARD_WEMOS_D1_R32

[env:mks_tinybee]
extends = common_esp32_wifi
extends = common_esp32
board = esp32dev
build_flags = ${common_esp32_wifi.build_flags} -DBOARD=BOARD_MKS_TINYBEE
build_flags = ${common_esp32.build_flags} -DBOARD=BOARD_MKS_TINYBEE
6 changes: 0 additions & 6 deletions uCNC/src/hal/mcus/avr/mcu_avr.c
Original file line number Diff line number Diff line change
Expand Up @@ -522,12 +522,6 @@ void mcu_putc(char c)
#endif
}

char mcu_getc(void)
{
loop_until_bit_is_set(UCSRA, RXC);
return COM_INREG;
}

// RealTime
void mcu_freq_to_clocks(float frequency, uint16_t *ticks, uint16_t *prescaller)
{
Expand Down
34 changes: 0 additions & 34 deletions uCNC/src/hal/mcus/esp32/esp32_eeprom.cpp

This file was deleted.

25 changes: 0 additions & 25 deletions uCNC/src/hal/mcus/esp32/esp32_spi.cpp

This file was deleted.

Loading

0 comments on commit 0d5da2e

Please sign in to comment.