Skip to content

Commit

Permalink
Merge pull request #800 from Paciente8159/ESP8266-direct-GPIO
Browse files Browse the repository at this point in the history
faster GPIO using direct IO registers for ESP8266
  • Loading branch information
Paciente8159 authored Jan 22, 2025
2 parents de6bd2a + e854418 commit fe906d4
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 14 deletions.
7 changes: 2 additions & 5 deletions uCNC/src/hal/mcus/esp8266/esp8266_arduino.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@ extern "C"
bool mcu_custom_grbl_cmd(void *args)
{
grbl_cmd_args_t *cmd_params = (grbl_cmd_args_t *)args;
uint8_t str[64];
char arg[ARG_MAX_LEN];
uint8_t has_arg = (cmd_params->next_char == '=');
memset(arg, 0, sizeof(arg));
Expand Down Expand Up @@ -310,7 +309,6 @@ extern "C"
#ifdef ENABLE_WIFI
static uint32_t next_info = 30000;
static bool connected = false;
uint8_t str[64];

if (!wifi_settings.wifi_on)
{
Expand Down Expand Up @@ -730,8 +728,6 @@ extern "C"

if (wifi_settings.wifi_on)
{
uint8_t str[64];

switch (wifi_settings.wifi_mode)
{
case 1:
Expand Down Expand Up @@ -981,7 +977,7 @@ extern "C"

bool mcu_spi_bulk_transfer(const uint8_t *out, uint8_t *in, uint16_t len)
{
SPI.transferBytes(out, int, len);
SPI.transferBytes(out, in, len);
return false;
}

Expand Down Expand Up @@ -1031,6 +1027,7 @@ extern "C"
if (NVM_STORAGE_SIZE <= address)
{
DBGMSG("EEPROM invalid address @ %u", address);
return;
}
EEPROM.write(address, value);
}
Expand Down
10 changes: 5 additions & 5 deletions uCNC/src/hal/mcus/esp8266/mcumap_esp8266.h
Original file line number Diff line number Diff line change
Expand Up @@ -1233,11 +1233,11 @@ extern "C"
#define mcu_config_pullup(X) pinMode(__indirect__(X, BIT), INPUT_PULLUP)
#define mcu_config_input_isr(X) attachInterrupt(digitalPinToInterrupt(__indirect__(X, BIT)), __indirect__(X, ISRCALLBACK), CHANGE)

#define mcu_get_input(X) digitalRead(__indirect__(X, BIT))
#define mcu_get_output(X) digitalRead(__indirect__(X, BIT))
#define mcu_set_output(X) digitalWrite(__indirect__(X, BIT), 1)
#define mcu_clear_output(X) digitalWrite(__indirect__(X, BIT), 0)
#define mcu_toggle_output(X) digitalWrite(__indirect__(X, BIT), !digitalRead(__indirect__(X, BIT)))
#define mcu_get_input(X) ((__indirect__(X, BIT) != 16) ? GPIP(__indirect__(X, BIT)) : (GP16I & 0x01))
#define mcu_get_output(X) ((__indirect__(X, BIT) != 16) ? GPIP(__indirect__(X, BIT)) : (GP16I & 0x01))
#define mcu_set_output(X) ({if(__indirect__(X, BIT)!=16){GPOS=(1<<__indirect__(X, BIT));}else{GP16O |= 1;} })
#define mcu_clear_output(X) ({if(__indirect__(X, BIT)!=16){GPOC=(1<<__indirect__(X, BIT));}else{GP16O &= ~1;} })
#define mcu_toggle_output(X) ((!!mcu_get_output(X)) ? mcu_clear_output(X) : mcu_set_output(X))

#define mcu_get_analog(X) analogRead(__indirect__(X, BIT))

Expand Down
31 changes: 27 additions & 4 deletions uCNC/src/hal/mcus/mcu.c
Original file line number Diff line number Diff line change
Expand Up @@ -877,16 +877,16 @@ void __attribute__((weak)) mcu_io_init(void)
#endif
#endif
#if ASSERT_PIN_IO(SPI2_CLK)
mcu_config_output(SPI2_CLK);
mcu_config_output(SPI2_CLK);
#endif
#if ASSERT_PIN_IO(SPI2_SDI)
mcu_config_output(SPI2_SDI);
mcu_config_output(SPI2_SDI);
#endif
#if ASSERT_PIN_IO(SPI2_SDO)
mcu_config_output(SPI2_SDO);
mcu_config_output(SPI2_SDO);
#endif
#if ASSERT_PIN(SPI2_CS)
mcu_config_output(SPI2_CS);
mcu_config_output(SPI2_CS);
#endif

#ifdef MCU_HAS_UART
Expand Down Expand Up @@ -932,6 +932,29 @@ void __attribute__((weak)) mcu_io_reset(void)
}
#endif

// Non volatile memory
/**
* gets a byte at the given EEPROM (or other non volatile memory) address of the MCU.
* */
uint8_t __attribute__((weak)) mcu_eeprom_getc(uint16_t address)
{
return 0;
}

/**
* sets a byte at the given EEPROM (or other non volatile memory) address of the MCU.
* */
void __attribute__((weak)) mcu_eeprom_putc(uint16_t address, uint8_t value)
{
}

/**
* flushes all recorded registers into the eeprom.
* */
void __attribute__((weak)) mcu_eeprom_flush(void)
{
}

// ISR
// New uint8_t handle strategy
// All ascii will be sent to buffer and processed later (including comments)
Expand Down

0 comments on commit fe906d4

Please sign in to comment.