Skip to content

Commit

Permalink
WIP for modules
Browse files Browse the repository at this point in the history
  • Loading branch information
MitchBradley committed Jul 13, 2024
1 parent 7a16565 commit 241fed5
Show file tree
Hide file tree
Showing 28 changed files with 395 additions and 719 deletions.
400 changes: 200 additions & 200 deletions FluidNC/esp32/gpio.cpp

Large diffs are not rendered by default.

16 changes: 8 additions & 8 deletions FluidNC/src/Channel.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,14 @@

#pragma once

#include "Error.h" // Error
#include "GCode.h" // gc_modal_t
#include "Types.h" // State
#include "RealtimeCmd.h" // Cmd
#include "UTF8.h"

#include "Pins/PinAttributes.h"
#include "Machine/EventPin.h"
#include "src/Error.h" // Error
#include "src/GCode.h" // gc_modal_t
#include "src/Types.h" // State
#include "src/RealtimeCmd.h" // Cmd
#include "src/UTF8.h"

#include "src/Pins/PinAttributes.h"
#include "src/Machine/EventPin.h"

#include <Stream.h>
#include <freertos/FreeRTOS.h> // TickType_T
Expand Down
2 changes: 1 addition & 1 deletion FluidNC/src/Configuration/Generator.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ namespace Configuration {
class Configurable;

class Generator : public HandlerBase {
Generator(const Generator&) = delete;
Generator(const Generator&) = delete;
Generator& operator=(const Generator&) = delete;

int indent_;
Expand Down
4 changes: 2 additions & 2 deletions FluidNC/src/Configuration/JsonGenerator.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@
#include "../Pin.h"
#include "HandlerBase.h"

#include "../WebUI/JSONEncoder.h"
#include "src/JSONEncoder.h"

namespace Configuration {
class Configurable;

class JsonGenerator : public HandlerBase {
JsonGenerator(const JsonGenerator&) = delete;
JsonGenerator(const JsonGenerator&) = delete;
JsonGenerator& operator=(const JsonGenerator&) = delete;

char _currentPath[256]; // 256 = max size of configuration string.
Expand Down
24 changes: 8 additions & 16 deletions FluidNC/src/I2SOut.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ void i2s_out_write(pinnum_t pin, uint8_t val) {}
void i2s_out_push_sample(uint32_t usec) {}
void i2s_out_push() {}
void i2s_out_delay() {}
int i2s_out_set_passthrough() {

int i2s_out_set_passthrough() {
return 0;
}
i2s_out_pulser_status_t i2s_out_get_pulser_status() {
Expand Down Expand Up @@ -169,15 +170,6 @@ static portMUX_TYPE i2s_out_pulser_spinlock = portMUX_INITIALIZER_UNLOCKED;
//
// Internal functions
//
static inline void gpio_matrix_out_check(pinnum_t gpio, uint32_t signal_idx, bool out_inv, bool oen_inv) {
//if pin == 255, do not need to configure
if (gpio != 255) {
PIN_FUNC_SELECT(GPIO_PIN_MUX_REG[gpio], PIN_FUNC_GPIO);
gpio_set_direction((gpio_num_t)gpio, (gpio_mode_t)GPIO_MODE_DEF_OUTPUT);
gpio_matrix_out(gpio, signal_idx, out_inv, oen_inv);
}
}

static void IRAM_ATTR set_single_data(uint32_t portData) {
// Apply port data in real-time (static I2S)
I2S0.conf_single_data = portData << DATA_SHIFT;
Expand Down Expand Up @@ -225,19 +217,19 @@ static int i2s_clear_o_dma_buffers(uint32_t port_data) {

static int i2s_out_gpio_attach(pinnum_t ws, pinnum_t bck, pinnum_t data) {
// Route the i2s pins to the appropriate GPIO
gpio_matrix_out_check(data, I2S0O_DATA_OUT23_IDX, 0, 0);
gpio_matrix_out_check(bck, I2S0O_BCK_OUT_IDX, 0, 0);
gpio_matrix_out_check(ws, I2S0O_WS_OUT_IDX, 0, 0);
gpio_route(data, I2S0O_DATA_OUT23_IDX);
gpio_route(bck, I2S0O_BCK_OUT_IDX);
gpio_route(ws, I2S0O_WS_OUT_IDX);
return 0;
}

const int I2S_OUT_DETACH_PORT_IDX = 0x100;

static int i2s_out_gpio_detach(pinnum_t ws, pinnum_t bck, pinnum_t data) {
// Route the i2s pins to the appropriate GPIO
gpio_matrix_out_check(ws, I2S_OUT_DETACH_PORT_IDX, 0, 0);
gpio_matrix_out_check(bck, I2S_OUT_DETACH_PORT_IDX, 0, 0);
gpio_matrix_out_check(data, I2S_OUT_DETACH_PORT_IDX, 0, 0);
gpio_route(ws, I2S_OUT_DETACH_PORT_IDX);
gpio_route(bck, I2S_OUT_DETACH_PORT_IDX);
gpio_route(data, I2S_OUT_DETACH_PORT_IDX);
return 0;
}

Expand Down
1 change: 1 addition & 0 deletions FluidNC/src/I2SOut.h
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
#include <stdint.h>

#include "Pin.h"
#include "Driver/fluidnc_gpio.h"

/* Assert */
#if defined(I2S_OUT_NUM_BITS)
Expand Down
8 changes: 6 additions & 2 deletions FluidNC/src/Kinematics/Kinematics.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,9 @@ namespace Kinematics {
return _system->transform_cartesian_to_motors(motors, cartesian);
}

void Kinematics::group(Configuration::HandlerBase& handler) { ::Kinematics::KinematicsFactory::factory(handler, _system); }
void Kinematics::group(Configuration::HandlerBase& handler) {
::Kinematics::KinematicsFactory::factory(handler, _system);
}

void Kinematics::afterParse() {
if (_system == nullptr) {
Expand All @@ -77,5 +79,7 @@ namespace Kinematics {
_system->init_position();
}

Kinematics::~Kinematics() { delete _system; }
Kinematics::~Kinematics() {
delete _system;
}
};
14 changes: 3 additions & 11 deletions FluidNC/src/Kinematics/Kinematics.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,17 +15,9 @@ You can add your own type of kinematics by adding 2 new files to the Kinematics
my_delta.h
my_delta.cpp
Use some of the others as an example. Be sure to have the code for the config file.
Use some of the others as an example.
Surround all the code in both files with
#ifdef my_delta_kinematics
#endif
Add a #define to this file for your kinematic
#define my_delta_kinematics
You will be ablr to add your kinematic using the config file.
You will be able to add your kinematics using the config file.
*/

Expand All @@ -41,8 +33,8 @@ namespace Kinematics {
void group(Configuration::HandlerBase& handler) override;
void afterParse() override;
void init();

void init_position();
void config_kinematics();

bool cartesian_to_motors(float* target, plan_line_data_t* pl_data, float* position);
void motors_to_cartesian(float* cartesian, float* motors, int n_axis);
Expand Down
3 changes: 1 addition & 2 deletions FluidNC/src/Machine/MachineConfig.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,7 @@ namespace Machine {

handler.section("user_outputs", _userOutputs);

handler.section("oled", _oled);
handler.section("status_outputs", _stat_out);
ModuleFactory::factory(handler, _modules);

Spindles::SpindleFactory::factory(handler, _spindles);

Expand Down
36 changes: 17 additions & 19 deletions FluidNC/src/Machine/MachineConfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,24 +4,23 @@

#pragma once

#include "../Assert.h"
#include "../Configuration/GenericFactory.h"
#include "../Configuration/HandlerBase.h"
#include "../Configuration/Configurable.h"
#include "../CoolantControl.h"
#include "../Kinematics/Kinematics.h"
#include "../WebUI/BTConfig.h"
#include "../Control.h"
#include "../Probe.h"
#include "src/Assert.h"
#include "src/Configuration/GenericFactory.h"
#include "src/Configuration/HandlerBase.h"
#include "src/Configuration/Configurable.h"
#include "src/CoolantControl.h"
#include "src/Kinematics/Kinematics.h"
#include "src/WebUI/BTConfig.h"
#include "src/Control.h"
#include "src/Probe.h"
#include "src/Parking.h"
#include "../SDCard.h"
#include "../Spindles/Spindle.h"
#include "../Stepping.h"
#include "../Stepper.h"
#include "../Config.h"
#include "../OLED.h"
#include "../Status_outputs.h"
#include "../UartChannel.h"
#include "src/SDCard.h"
#include "src/Spindles/Spindle.h"
#include "src/Stepping.h"
#include "src/Stepper.h"
#include "src/Config.h"
#include "src/UartChannel.h"
#include "src/Module.h"
#include "Axes.h"
#include "SPIBus.h"
#include "I2CBus.h"
Expand Down Expand Up @@ -75,9 +74,8 @@ namespace Machine {
Macros* _macros = nullptr;
Start* _start = nullptr;
Parking* _parking = nullptr;
OLED* _oled = nullptr;
Status_Outputs* _stat_out = nullptr;
Spindles::SpindleList _spindles;
ModuleList _modules;

UartChannel* _uart_channels[MAX_N_UARTS] = { nullptr };
Uart* _uarts[MAX_N_UARTS] = { nullptr };
Expand Down
15 changes: 6 additions & 9 deletions FluidNC/src/Main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
# include "MotionControl.h"
# include "Platform.h"
# include "StartupLog.h"
# include "Module.h"

# include "WebUI/TelnetServer.h"

Expand Down Expand Up @@ -91,14 +92,6 @@ void setup() {
}
}

if (config->_oled) {
config->_oled->init();
}

if (config->_stat_out) {
config->_stat_out->init();
}

config->_stepping->init(); // Configure stepper interrupt timers

plan_init();
Expand All @@ -115,7 +108,7 @@ void setup() {

// Initialize system state.
if (!state_is(State::ConfigAlarm)) {
for (auto s : config->_spindles) {
for (auto const& s : config->_spindles) {
s->init();
}
Spindles::Spindle::switchSpindle(0, config->_spindles, spindle);
Expand All @@ -124,6 +117,10 @@ void setup() {
config->_probe->init();
}

for (auto const& m : config->_modules) {
m->init_module();
}

} catch (const AssertionFailed& ex) {
// This means something is terribly broken:
log_config_error("Critical error in main_init: " << ex.what());
Expand Down
13 changes: 10 additions & 3 deletions FluidNC/src/OLED.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include "OLED.h"
#if 0
# include "OLED.h"

#include "Machine/MachineConfig.h"
# include "Machine/MachineConfig.h"

void OLED::show(Layout& layout, const char* msg) {
if (_width < layout._width_required) {
Expand Down Expand Up @@ -63,7 +64,7 @@ void OLED::afterParse() {
}
}

void OLED::init() {
void OLED::init_module() {
if (_error) {
return;
}
Expand Down Expand Up @@ -557,3 +558,9 @@ void OLED::draw_checkbox(int16_t x, int16_t y, int16_t width, int16_t height, bo
_oled->drawRect(x, y, width, height); // If log.1
}
}

// Configuration registration
namespace {
ModuleFactory::InstanceBuilder<OLED> registration("oled");
}
#endif
24 changes: 12 additions & 12 deletions FluidNC/src/OLED.h
Original file line number Diff line number Diff line change
@@ -1,15 +1,16 @@
#pragma once

#include "Config.h"
#include "src/Config.h"

#include "Configuration/Configurable.h"
#include "src/Configuration/Configurable.h"

#include "Channel.h"
#include "src/Channel.h"
#include "src/Module.h"
#include "SSD1306_I2C.h"

typedef const uint8_t* font_t;

class OLED : public Channel, public Configuration::Configurable {
class OLED : public Channel, public Module {
public:
struct Layout {
uint8_t _x;
Expand Down Expand Up @@ -79,16 +80,16 @@ class OLED : public Channel, public Configuration::Configurable {
bool _error = false;

public:
OLED() : Channel("oled") {}
OLED() : Channel("oled"), Module("oled") {}

OLED(const OLED&) = delete;
OLED(OLED&&) = delete;
OLED(const OLED&) = delete;
OLED(OLED&&) = delete;
OLED& operator=(const OLED&) = delete;
OLED& operator=(OLED&&) = delete;
OLED& operator=(OLED&&) = delete;

virtual ~OLED() = default;

void init();
void init_module() override;

OLEDDisplay* _oled;

Expand All @@ -97,11 +98,10 @@ class OLED : public Channel, public Configuration::Configurable {
uint8_t _address = 0x3c;
int _width = 64;
int _height = 48;
bool _flip = true;
bool _mirror = false;
bool _flip = true;
bool _mirror = false;

// Channel method overrides

size_t write(uint8_t data) override;

int read(void) override { return -1; }
Expand Down
24 changes: 5 additions & 19 deletions FluidNC/src/Report.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,6 @@ std::string report_pin_string;

portMUX_TYPE mmux = portMUX_INITIALIZER_UNLOCKED;

void _notify(const char* title, const char* msg) {
WebUI::notificationsService.sendMSG(title, msg);
}

void _notifyf(const char* title, const char* format, ...) {
char loc_buf[64];
char* temp = loc_buf;
Expand Down Expand Up @@ -420,21 +416,8 @@ void report_build_info(const char* line, Channel& channel) {

log_msg_to(channel, "Machine: " << config->_name);

std::string station_info = WebUI::wifi_config.station_info();
if (station_info.length()) {
log_msg_to(channel, station_info);
}
std::string ap_info = WebUI::wifi_config.ap_info();
if (ap_info.length()) {
log_msg_to(channel, ap_info);
}
if (!station_info.length() && !ap_info.length()) {
log_msg_to(channel, "No Wifi");
}
std::string bt_info = WebUI::bt_config.info();
if (bt_info.length()) {
log_msg_to(channel, bt_info);
}
report_wifi_info(channel);
report_bt_info(channel);
}

// Prints the character string line that was received, which has been pre-parsed,
Expand Down Expand Up @@ -668,3 +651,6 @@ void reportTaskStackSize(UBaseType_t& saved) {
}

void WEAK_LINK display_init() {}
void WEAK_LINK _notify(const char* title, const char* msg) {}
void WEAK_LINK report_wifi_info(Channel& channel) {}
void WEAK_LINK report_bt_info(Channel& channel) {}
3 changes: 3 additions & 0 deletions FluidNC/src/Report.h
Original file line number Diff line number Diff line change
Expand Up @@ -101,3 +101,6 @@ extern bool readyNext;

extern std::string report_pin_string;
void report_recompute_pin_string();

void report_wifi_info(Channel& channel);
void report_bt_info(Channel& channel);
Loading

0 comments on commit 241fed5

Please sign in to comment.