Skip to content

Commit

Permalink
Merge pull request #222 from Paciente8159/ESP8266
Browse files Browse the repository at this point in the history
ESP8266 core integration
  • Loading branch information
Paciente8159 authored Jul 29, 2022
2 parents 43675ce + 54ade0d commit d561c97
Show file tree
Hide file tree
Showing 28 changed files with 2,911 additions and 48 deletions.
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,18 @@

# Changelog

## [1.5.b] - Unreleased

### Added

- added core support for ESP8266 with limitied functionalities (#222)

### Changed

- configurable RX serial buffer size (#222)

### Fixed

## [1.4.7] - 2022-07-29

### Added
Expand Down Expand Up @@ -926,6 +938,7 @@ Version 1.1.0 comes with many added features and improvements over the previous

### Initial release

[1.5.b]: https://github.com/Paciente8159/uCNC/releases/tag/v1.5.b
[1.4.7]: https://github.com/Paciente8159/uCNC/releases/tag/v1.4.7
[1.4.6]: https://github.com/Paciente8159/uCNC/releases/tag/v1.4.6
[1.4.5]: https://github.com/Paciente8159/uCNC/releases/tag/v1.4.5
Expand Down
1 change: 1 addition & 0 deletions platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ extra_configs =
uCNC/src/hal/boards/avr/avr.ini
uCNC/src/hal/boards/samd21/samd21.ini
uCNC/src/hal/boards/stm32/stm32.ini
uCNC/src/hal/boards/esp8266/esp8266.ini
; uCNC/src/hal/mcus/virtual/virtual.ini

[common]
Expand Down
31 changes: 28 additions & 3 deletions uCNC/cnc_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ extern "C"
{
#endif

#define INTERFACE_USART 0
#define INTERFACE_UART 0
#define INTERFACE_USB 1

/**
Expand All @@ -39,7 +39,11 @@ extern "C"
#endif

#ifndef INTERFACE
#define INTERFACE INTERFACE_USART
#define INTERFACE INTERFACE_UART
#endif

#ifndef ENABLE_WIFI
// #define ENABLE_WIFI
#endif

/**
Expand Down Expand Up @@ -94,7 +98,7 @@ extern "C"
* Uncomment to enable G92 storring on non volatile memory
* If disabled G92 will be stored in RAM only. Soft-reset will not erase stored value.
* */
// #define G92_STORE_NONVOLATILE
// #define G92_STORE_NONVOLATILE

/**
* Number of segments of an arc computed with aprox. of sin/cos math
Expand Down Expand Up @@ -417,6 +421,27 @@ extern "C"
// #define ENABLE_FAST_MATH

/**
*
* HAL offsets
*
* */
#ifndef PWM_PINS_OFFSET
#define PWM_PINS_OFFSET 24
#endif
#ifndef SERVO_PINS_OFFSET
#define SERVO_PINS_OFFSET 40
#endif
#ifndef DOUT_PINS_OFFSET
#define DOUT_PINS_OFFSET 46
#endif
#ifndef ANALOG_PINS_OFFSET
#define ANALOG_PINS_OFFSET 114
#endif
#ifndef DIN_PINS_OFFSET
#define DIN_PINS_OFFSET 130
#endif

#ifdef __cplusplus
}
#endif
Expand Down
2 changes: 1 addition & 1 deletion uCNC/src/cnc.c
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,7 @@ bool cnc_dotasks(void)
}

// this function is executed every millisecond
void mcu_rtc_cb(uint32_t millis)
MCU_CALLBACK void mcu_rtc_cb(uint32_t millis)
{
static bool running = false;

Expand Down
4 changes: 2 additions & 2 deletions uCNC/src/cnc_build.h
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ extern "C"
{
#endif

#define CNC_MAJOR_MINOR_VERSION "1.4"
#define CNC_PATCH_VERSION ".7"
#define CNC_MAJOR_MINOR_VERSION "1.5"
#define CNC_PATCH_VERSION ".beta"

#define CNC_VERSION CNC_MAJOR_MINOR_VERSION CNC_PATCH_VERSION

Expand Down
4 changes: 2 additions & 2 deletions uCNC/src/core/interpolator.c
Original file line number Diff line number Diff line change
Expand Up @@ -1080,13 +1080,13 @@ uint32_t itp_get_rt_line_number(void)
#endif

// always fires after pulse
void mcu_step_reset_cb(void)
MCU_CALLBACK void mcu_step_reset_cb(void)
{
// always resets all stepper pins
io_set_steps(g_settings.step_invert_mask);
}

void mcu_step_cb(void)
MCU_CALLBACK void mcu_step_cb(void)
{
static uint8_t stepbits = 0;
static bool itp_busy = false;
Expand Down
8 changes: 4 additions & 4 deletions uCNC/src/core/io_control.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ static volatile uint8_t io_spindle_speed;
static uint8_t io_lock_limits_mask;
static uint8_t io_invert_limits_mask;

void mcu_limits_changed_cb(void)
MCU_IO_CALLBACK void mcu_limits_changed_cb(void)
{
#ifndef DISABLE_ALL_LIMITS

Expand Down Expand Up @@ -112,7 +112,7 @@ void mcu_limits_changed_cb(void)
#endif
}

void mcu_controls_changed_cb(void)
MCU_IO_CALLBACK void mcu_controls_changed_cb(void)
{
#ifdef DISABLE_ALL_CONTROLS
return;
Expand Down Expand Up @@ -157,7 +157,7 @@ void mcu_controls_changed_cb(void)
#endif
}

void mcu_probe_changed_cb(void)
MCU_IO_CALLBACK void mcu_probe_changed_cb(void)
{
#ifdef DISABLE_PROBE
return;
Expand All @@ -183,7 +183,7 @@ void mcu_probe_changed_cb(void)

// overridable
// for now if encoders are enabled this will be override by the encoder call
void __attribute__((weak)) mcu_inputs_changed_cb(void)
MCU_IO_CALLBACK void __attribute__((weak)) mcu_inputs_changed_cb(void)
{
#ifdef ENABLE_IO_MODULES
mod_input_change_hook();
Expand Down
10 changes: 10 additions & 0 deletions uCNC/src/hal/boards/boarddefs.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,16 @@ extern "C"
#include "samd21/boardmap_zero.h"
#endif

#if (BOARD == BOARD_RE_ARM)
#define MCU MCU_LPC176X
#include "lpc176x/boardmap_re_arm.h"
#endif

#if (BOARD == BOARD_WEMOS_D1)
#define MCU MCU_ESP8266
#include "esp8266/boardmap_wemos_d1.h"
#endif

#if (BOARD == BOARD_VIRTUAL)
#ifndef __linux__
#define MCU MCU_VIRTUAL_WIN
Expand Down
2 changes: 2 additions & 0 deletions uCNC/src/hal/boards/boards.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ extern "C"
#define BOARD_BLACKPILL 11
#define BOARD_MZERO 20
#define BOARD_ZERO 21
#define BOARD_RE_ARM 30
#define BOARD_WEMOS_D1 40
#define BOARD_VIRTUAL 99

// special purpose board
Expand Down
80 changes: 80 additions & 0 deletions uCNC/src/hal/boards/esp8266/boardmap_wemos_d1.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
/*
Name: boardmap_wemos_d1.h
Description: Contains all MCU and PIN definitions for Arduino WeMos D1 to run µCNC.
Copyright: Copyright (c) João Martins
Author: João Martins
Date: 17/06/2022
µCNC 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. Please see <http://www.gnu.org/licenses/>
µCNC is distributed WITHOUT ANY WARRANTY;
Also without the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU General Public License for more details.
*/

#ifndef BOARDMAP_WEMOS_D1_H
#define BOARDMAP_WEMOS_D1_H

#ifdef __cplusplus
extern "C"
{
#endif

#ifndef BOARD_NAME
#define BOARD_NAME "WEMOS D1"
#endif

// SAME AS GRBL for test purposes
// Setup step pins
#define STEP2_BIT 4 // assigns STEP2 pin
#define STEP2_PORT D // assigns STEP2 port
#define STEP1_BIT 5 // assigns STEP1 pin
#define STEP1_PORT D // assigns STEP1 port
#define STEP0_BIT 16 // assigns STEP0 pin
#define STEP0_PORT D // assigns STEP0 port

// Setup dir pins
#define DIR2_BIT 13 // assigns DIR2 pin
#define DIR2_PORT D // assigns DIR2 port
#define DIR1_BIT 12 // assigns DIR1 pin
#define DIR1_PORT D // assigns DIR1 port
#define DIR0_BIT 14 // assigns DIR0 pin
#define DIR0_PORT D // assigns DIR0 port

// Setup control input pins
// #define ESTOP_BIT 0
// #define ESTOP_PORT A
//#define ESTOP_ISR

// Setup com pins
#if (INTERFACE == INTERFACE_UART)
#define RX_BIT 3
#define TX_BIT 1
#define RX_PORT D
#define TX_PORT D
// only uncomment this if other port other then 0 is used
// #define COM_PORT 0
#endif

// Setup PWM
#define PWM0_BIT 2 // assigns PWM0 pin
#define PWM0_PORT D // assigns PWM0 pin

// Setup generic IO Pins
// spindle dir
#define DOUT0_BIT 15
#define DOUT0_PORT D

// Stepper enable pin. For Grbl on Uno board a single pin is used
#define STEP0_EN_BIT 0
#define STEP0_EN_PORT D

#ifdef __cplusplus
}
#endif

#endif
14 changes: 14 additions & 0 deletions uCNC/src/hal/boards/esp8266/esp8266.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
################
# STM32 Boards #
################

[env:d1]
platform = espressif8266
framework = arduino
board = d1
build_src_filter = +<*>-<src/tinyusb>
lib_deps =
https://github.com/tzapu/WiFiManager/archive/refs/heads/master.zip
build_flags = -DBOARD=BOARD_WEMOS_D1 -DINTERFACE=0 -DENABLE_WIFI
upload_speed = 256000
board_build.f_cpu = 160000000L
34 changes: 34 additions & 0 deletions uCNC/src/hal/mcus/esp8266/esp8266_eeprom.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#include "../../../../cnc_config.h"
#ifdef ESP8266
#ifndef RAM_ONLY_SETTINGS
#include <Arduino.h>
#include <EEPROM.h>
#include <stdint.h>
extern "C"
{
void esp8266_eeprom_init(int size)
{
EEPROM.begin(size);
}

uint8_t esp8266_eeprom_read(uint16_t address)
{
return EEPROM.read(address);
}

void esp8266_eeprom_write(uint16_t address, uint8_t value)
{
EEPROM.write(address, value);
}

void esp8266_eeprom_flush(void)
{
if (!EEPROM.commit())
{
Serial.println("[MSG: EEPROM write error]");
}
}
}

#endif
#endif
Loading

0 comments on commit d561c97

Please sign in to comment.