Skip to content

Commit

Permalink
Merge pull request #435 from bdring/Devt
Browse files Browse the repository at this point in the history
Devt
  • Loading branch information
bdring authored May 19, 2022
2 parents bb927a2 + 8eff57d commit 74150e7
Show file tree
Hide file tree
Showing 101 changed files with 637 additions and 6,790 deletions.
Binary file modified FluidNC/data/index.html.gz
Binary file not shown.
117 changes: 117 additions & 0 deletions FluidNC/esp32/StepTimer.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
// Copyright 2022 Mitch Bradley
//
// Interface to the ESP32 alarm timer for step timing

#ifdef __cplusplus
extern "C" {
#endif

// #include "../src/Driver/StepTimer.h"
#include "driver/timer.h"
#include "hal/timer_hal.h"

static const uint32_t fTimers = 80000000; // the frequency of ESP32 timers

#define USE_LEGACY_TIMER

#ifdef USE_LEGACY_TIMER
# define TIMER_GROUP_NUM TIMER_GROUP_0, TIMER_0

void stepTimerStart() {
// timer_set_counter_value(TIMER_GROUP_NUM, 0);
// timer_group_enable_alarm_in_isr(TIMER_GROUP_NUM);
timer_set_alarm(TIMER_GROUP_NUM, TIMER_ALARM_EN);
timer_start(TIMER_GROUP_NUM);
}

void IRAM_ATTR stepTimerRestart() {
// Resetting the counter value here si unnecessary because it
// happens automatically via the autoreload hardware.
// The timer framework requires autoreload.
// If you set autoreload to false, the ISR wrapper will
// disable the alarm after our ISR function returns, so
// an attempt to enable the alarm here is ineffective.
// timer_set_counter_value(TIMER_GROUP_NUM, 0);
}

uint32_t stepTimerGetTicks() {
uint64_t val;
timer_get_alarm_value(TIMER_GROUP_NUM, &val);
return val;
}

void IRAM_ATTR stepTimerSetTicks(uint32_t ticks) {
timer_group_set_alarm_value_in_isr(TIMER_GROUP_NUM, (uint64_t)ticks);
}

void IRAM_ATTR stepTimerStop() {
timer_pause(TIMER_GROUP_NUM);
// timer_set_auto_reload(TIMER_GROUP_NUM, TIMER_AUTORELOAD_DIS);
timer_set_alarm(TIMER_GROUP_NUM, TIMER_ALARM_DIS);
}

void stepTimerInit(uint32_t frequency, bool (*fn)(void)) {
timer_config_t config = {
.alarm_en = TIMER_ALARM_DIS,
.counter_en = TIMER_PAUSE,
.counter_dir = TIMER_COUNT_UP,
.auto_reload = TIMER_AUTORELOAD_EN,
// .clk_src = TIMER_SRC_CLK_DEFAULT,
.divider = fTimers / frequency,
};
timer_init(TIMER_GROUP_NUM, &config);
timer_set_counter_value(TIMER_GROUP_NUM, 0);
timer_isr_callback_add(TIMER_GROUP_NUM, (timer_isr_t)fn, NULL, ESP_INTR_FLAG_IRAM);
//timer_pause(TIMER_GROUP_NUM);
// timer_start(TIMER_GROUP_NUM);
}
#else
# include "driver/gptimer.h"

static gptimer_handle_t gptimer = NULL;
void stepTimerInit(uint32_t frequency, bool (*fn)(void)) {
gptimer_config_t timer_config = {
.clk_src = GPTIMER_CLK_SRC_DEFAULT,
.direction = GPTIMER_COUNT_UP,
.resolution_hz = frequency,
};
gptimer_new_timer(&timer_config, &gptimer);

gptimer_event_callbacks_t cbs = {
.on_alarm = step_timer_cb,
};
gptimer_register_event_callbacks(gptimer, &cbs, NULL);

gptimer_alarm_config_t alarm_config = {
.alarm_count = 1000000, // period = 1s
};
gptimer_set_alarm_action(gptimer, &alarm_config);
gptimer_pause(gptimer);
}

void IRAM_ATTR stepTimerStart() {
gptimer_alarm_config_t alarm_config = {
.reload_count = 0,
.alarm_count = 1, // Trigger immediately for first pulse
.flags.auto_reload_on_alarm = false,
};
gptimer_set_alarm_action(gptimer, &alarm_config);
}

void IRAM_ATTR stepTimerSetTicks(uint32_t ticks) {
gptimer_alarm_config_t alarm_config = {
.reload_count = 0,
.alarm_count = ticks, // Trigger immediately for first pulse
.flags.auto_reload_on_alarm = true,
};
gptimer_set_alarm_action(gptimer, &alarm_config);
}

void IRAM_ATTR stepTimerStop() {
gptimer_stop(gptimer);
}
#endif

#ifdef __cplusplus
}
#endif
20 changes: 20 additions & 0 deletions FluidNC/include/Driver/StepTimer.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#pragma once

#ifdef __cplusplus
extern "C" {
#endif

#include <stdint.h>
#include <stdbool.h>

void stepTimerInit(uint32_t frequency, bool (*fn)(void));
void stepTimerStop();
void stepTimerSetTicks(uint32_t ticks);
void stepTimerStart();
void stepTimerRestart();

uint32_t stepTimerGetTicks();

#ifdef __cplusplus
}
#endif
7 changes: 0 additions & 7 deletions FluidNC/src/Config.h
Original file line number Diff line number Diff line change
Expand Up @@ -57,11 +57,6 @@ const char* const DEFAULT_ADMIN_LOGIN = "admin";
const char* const DEFAULT_USER_LOGIN = "user";
#endif

// Number of homing cycles performed after when the machine initially jogs to limit switches.
// This help in preventing overshoot and should improve repeatability. This value should be one or
// greater.
static const uint8_t NHomingLocateCycle = 1; // Integer (1-128)

// Upon a successful probe cycle, this option provides immediately feedback of the probe coordinates
// through an automatically generated message. If disabled, users can still access the last probe
// coordinates through the '$#' print parameters command.
Expand Down Expand Up @@ -220,5 +215,3 @@ const double PARKING_PULLOUT_INCREMENT = 5.0; // Spindle pull-out and plunge

// INCLUDE_OLED_BASIC includes a driver for a modest sized OLED display
// #define INCLUDE_OLED_BASIC

// #define DEBUG_STEPPING
2 changes: 1 addition & 1 deletion FluidNC/src/Configuration/ConfigurationHandlers.md
Original file line number Diff line number Diff line change
Expand Up @@ -123,4 +123,4 @@ At this point, this is simply not implemented.
The generator basically traverses the complete tree, and generates a
yaml file. The main point of this is to create a `config.yaml` file
in SPIFFS, which holds the main startup configuration.
in LocalFS, which holds the main startup configuration.
1 change: 0 additions & 1 deletion FluidNC/src/Configuration/RuntimeSetting.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ namespace Configuration {
out_ << "$/" << setting_ << "=" << (value ? "true" : "false") << '\n';
} else {
value = (!strcasecmp(newValue_, "true") || !strcasecmp(newValue_, "yes") || !strcasecmp(newValue_, "1"));
log_info("Bool value:" << value);
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions FluidNC/src/Configuration/_Overview.md
Original file line number Diff line number Diff line change
Expand Up @@ -106,9 +106,9 @@ trigger a link-time name collision.
## Getting started with Yaml settings
During startup, `MachineConfig::load` is called, with the
default filename `/spiffs/config.yaml`.
default filename `/localfs/config.yaml`.
You can upload a new config file to spiffs by putting it in the
You can upload a new config file to localfs by putting it in the
data folder, and calling `pio run -t uploadfs`. Another option
is to upload it using WiFi.
Expand Down
18 changes: 13 additions & 5 deletions FluidNC/src/FileStream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,15 @@
#include "Machine/MachineConfig.h" // config->
#include "SDCard.h"
#include "Logging.h"
#include "LocalFS.h"
#include <sys/stat.h>

String FileStream::path() {
String retval = _path;
retval.replace(LOCALFS_PREFIX, "/localfs/");
return retval;
}

int FileStream::available() {
return 1;
}
Expand Down Expand Up @@ -49,7 +56,7 @@ static void replaceInitialSubstring(String& s, const char* replaced, const char*
}

FileStream::FileStream(const char* filename, const char* mode, const char* defaultFs) : Channel("file") {
const char* actualLocalFs = "/spiffs/";
const char* actualLocalFs = LOCALFS_PREFIX;
const char* sdPrefix = "/sd/";
const char* localFsPrefix = "/localfs/";

Expand All @@ -69,6 +76,8 @@ FileStream::FileStream(const char* filename, const char* mode, const char* defau
replaceInitialSubstring(_path, "/LOCALFS/", actualLocalFs);
} else if (_path.startsWith("/SPIFFS/")) {
replaceInitialSubstring(_path, "/SPIFFS/", actualLocalFs);
} else if (_path.startsWith("/LITTLEFS/")) {
replaceInitialSubstring(_path, "/LITTLEFS/", actualLocalFs);
} else {
if (*filename != '/') {
_path = '/' + _path;
Expand All @@ -92,15 +101,14 @@ FileStream::FileStream(const char* filename, const char* mode, const char* defau
}
_isSD = true;
}
if (_path.startsWith(actualLocalFs) && _path.length() > (30 + strlen(actualLocalFs))) {
log_info("Filename too long: " << _path);
}
_fd = fopen(_path.c_str(), mode);
if (!_fd) {
bool opening = strcmp(mode, "w");
log_debug("Cannot " << (opening ? "open" : "create") << " file " << _path);
if (_isSD) {
config->_sdCard->end();
}
throw strcmp(mode, "w") ? Error::FsFailedOpenFile : Error::FsFailedCreateFile;
throw opening ? Error::FsFailedOpenFile : Error::FsFailedCreateFile;
}
}

Expand Down
6 changes: 1 addition & 5 deletions FluidNC/src/FileStream.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,11 +25,7 @@ class FileStream : public Channel {
FileStream(String filename, const char* mode, const char* defaultFs = "");
FileStream(const char* filename, const char* mode, const char* defaultFs = "");

String path() {
String retval = _path;
retval.replace("/spiffs/", "/localfs/");
return retval;
}
String path();
int available() override;
int read() override;
int peek() override;
Expand Down
16 changes: 8 additions & 8 deletions FluidNC/src/GCode.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ void gc_init() {
// Sets g-code parser position in mm. Input in steps. Called by the system abort and hard
// limit pull-off routines.
void gc_sync_position() {
motor_steps_to_mpos(gc_state.position, motor_steps);
motor_steps_to_mpos(gc_state.position, get_motor_steps());
}

static void gcode_comment_msg(char* comment) {
Expand Down Expand Up @@ -906,7 +906,7 @@ Error gc_execute_line(char* line, Channel& channel) {
// future versions on processors with enough memory, all coordinate data should be stored
// in memory and written to non-volatile storage only when there is not a cycle active.
float block_coord_system[MAX_N_AXIS];
memcpy(block_coord_system, gc_state.coord_system, sizeof(gc_state.coord_system));
copyAxes(block_coord_system, gc_state.coord_system);
if (bitnum_is_true(command_words, ModalGroup::MG12)) { // Check if called in block
// This error probably cannot happen because preceding code sets
// gc_block.modal.coord_select only to specific supported values
Expand Down Expand Up @@ -1324,7 +1324,7 @@ Error gc_execute_line(char* line, Channel& channel) {
bool cancelledInflight = false;
Error status = jog_execute(pl_data, &gc_block, &cancelledInflight);
if (status == Error::Ok && !cancelledInflight) {
memcpy(gc_state.position, gc_block.values.xyz, sizeof(gc_block.values.xyz));
copyAxes(gc_state.position, gc_block.values.xyz);
}
// JogCancelled is not reported as a GCode error
return status == Error::JogCancelled ? Error::Ok : status;
Expand Down Expand Up @@ -1510,7 +1510,7 @@ Error gc_execute_line(char* line, Channel& channel) {
// [15. Coordinate system selection ]:
if (gc_state.modal.coord_select != gc_block.modal.coord_select) {
gc_state.modal.coord_select = gc_block.modal.coord_select;
memcpy(gc_state.coord_system, block_coord_system, sizeof(gc_state.coord_system));
copyAxes(gc_state.coord_system, block_coord_system);
gc_wco_changed();
}
// [16. Set path control mode ]: G61.1/G64 NOT SUPPORTED
Expand All @@ -1524,7 +1524,7 @@ Error gc_execute_line(char* line, Channel& channel) {
coords[coord_select]->set(coord_data);
// Update system coordinate system if currently active.
if (gc_state.modal.coord_select == coord_select) {
memcpy(gc_state.coord_system, coord_data, sizeof(gc_state.coord_system));
copyAxes(gc_state.coord_system, coord_data);
gc_wco_changed();
}
break;
Expand All @@ -1537,7 +1537,7 @@ Error gc_execute_line(char* line, Channel& channel) {
mc_linear(gc_block.values.xyz, pl_data, gc_state.position);
}
mc_linear(coord_data, pl_data, gc_state.position);
memcpy(gc_state.position, coord_data, sizeof(gc_state.position));
copyAxes(gc_state.position, coord_data);
break;
case NonModal::SetHome0:
coords[CoordIndex::G28]->set(gc_state.position);
Expand All @@ -1546,7 +1546,7 @@ Error gc_execute_line(char* line, Channel& channel) {
coords[CoordIndex::G30]->set(gc_state.position);
break;
case NonModal::SetCoordinateOffset:
memcpy(gc_state.coord_offset, gc_block.values.xyz, sizeof(gc_block.values.xyz));
copyAxes(gc_state.coord_offset, gc_block.values.xyz);
gc_wco_changed();
break;
case NonModal::ResetCoordinateOffset:
Expand Down Expand Up @@ -1590,7 +1590,7 @@ Error gc_execute_line(char* line, Channel& channel) {
// motion control system might still be processing the action and the real tool position
// in any intermediate location.
if (gc_update_pos == GCUpdatePos::Target) {
memcpy(gc_state.position, gc_block.values.xyz, sizeof(gc_block.values.xyz)); // gc_state.position[] = gc_block.values.xyz[]
copyAxes(gc_state.position, gc_block.values.xyz);
} else if (gc_update_pos == GCUpdatePos::System) {
gc_sync_position();
} // == GCUpdatePos::None
Expand Down
Loading

0 comments on commit 74150e7

Please sign in to comment.