Skip to content

Commit

Permalink
Merge pull request #818 from bdring/Devt
Browse files Browse the repository at this point in the history
Devt
  • Loading branch information
bdring authored Mar 1, 2023
2 parents c0c5397 + a6989ff commit 468fee9
Show file tree
Hide file tree
Showing 56 changed files with 1,724 additions and 752 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -28,3 +28,5 @@ v*.zip
/FluidNC/data/config.yaml
build/
dist/
*.cppx
*.hx
Binary file modified FluidNC/data/index.html.gz
Binary file not shown.
11 changes: 7 additions & 4 deletions FluidNC/esp32/gpio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,13 @@

#include <vector>

void gpio_write(pinnum_t pin, bool value) {
gpio_set_level((gpio_num_t)pin, value);
static gpio_dev_t* _gpio_dev = GPIO_HAL_GET_HW(GPIO_PORT_0);

void IRAM_ATTR gpio_write(pinnum_t pin, bool value) {
gpio_ll_set_level(_gpio_dev, (gpio_num_t)pin, value);
}
bool gpio_read(pinnum_t pin) {
return gpio_get_level((gpio_num_t)pin);
bool IRAM_ATTR gpio_read(pinnum_t pin) {
return gpio_ll_get_level(_gpio_dev, (gpio_num_t)pin);
}
void gpio_mode(pinnum_t pin, bool input, bool output, bool pullup, bool pulldown, bool opendrain) {
gpio_config_t conf = { .pin_bit_mask = (1ULL << pin), .intr_type = GPIO_INTR_DISABLE };
Expand Down Expand Up @@ -401,6 +403,7 @@ void show_matrix(Print& out) {
}
}

#include <Print.h>
void gpio_dump(Print& out) {
for (int gpio = 0; gpio < SOC_GPIO_PIN_COUNT; ++gpio) {
gpio_num_t gpio_num = static_cast<gpio_num_t>(gpio);
Expand Down
77 changes: 77 additions & 0 deletions FluidNC/esp32/i2c.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
// Copyright 2022 - Mitch Bradley
// Use of this source code is governed by a GPLv3 license that can be found in the LICENSE file.

#include "driver/i2c.h"

#include "Driver/fluidnc_i2c.h"
#include "src/Logging.h"

bool i2c_master_init(int bus_number, pinnum_t sda_pin, pinnum_t scl_pin, uint32_t frequency) {
i2c_config_t conf = {
.mode = I2C_MODE_MASTER,
.sda_io_num = (gpio_num_t)sda_pin,
.scl_io_num = (gpio_num_t)scl_pin,
.sda_pullup_en = GPIO_PULLUP_ENABLE,
.scl_pullup_en = GPIO_PULLUP_ENABLE,
.master = { .clk_speed = frequency },
};

esp_err_t ret = i2c_param_config((i2c_port_t)bus_number, &conf);
if (ret != ESP_OK) {
log_error("i2c_param_config failed");
return true;
}
ret = i2c_driver_install((i2c_port_t)bus_number, conf.mode, 0, 0, 0);
if (ret != ESP_OK) {
log_error("i2c_driver_install failed");
return true;
}
//Clock Stretching Timeout: 20b:esp32, 5b:esp32-c3, 24b:esp32-s2
i2c_set_timeout((i2c_port_t)bus_number, 0xfffff);
return false;
}

int i2c_write(int bus_number, uint8_t address, const uint8_t* data, size_t count) {
#if 0
esp_err_t ret = ESP_FAIL;
i2c_cmd_handle_t cmd = NULL;

//short implementation does not support zero size writes (example when scanning) PR in IDF?
//ret = i2c_master_write_to_device((i2c_port_t)bus_number, address, buff, size, timeOutMillis / portTICK_RATE_MS);

uint8_t cmd_buff[I2C_LINK_RECOMMENDED_SIZE(1)] = { 0 };

cmd = i2c_cmd_link_create_static(cmd_buff, I2C_LINK_RECOMMENDED_SIZE(1));
ret = i2c_master_start(cmd);
if (ret != ESP_OK) {
goto end;
}
ret = i2c_master_write_byte(cmd, (address << 1) | I2C_MASTER_WRITE, true);
if (ret != ESP_OK) {
goto end;
}
if (count) {
ret = i2c_master_write(cmd, data, count, true);
if (ret != ESP_OK) {
goto end;
}
}
ret = i2c_master_stop(cmd);
if (ret != ESP_OK) {
goto end;
}
ret = i2c_master_cmd_begin((i2c_port_t)bus_number, cmd, 10 / portTICK_RATE_MS);

end:
if (cmd != NULL) {
i2c_cmd_link_delete_static(cmd);
}
return ret ? -1 : count;
#else
return i2c_master_write_to_device((i2c_port_t)bus_number, address, data, count, 10 / portTICK_RATE_MS) ? -1 : count;
#endif
}

int i2c_read(int bus_number, uint8_t address, uint8_t* data, size_t count) {
return i2c_master_read_from_device((i2c_port_t)bus_number, address, data, count, 10 / portTICK_RATE_MS) ? -1 : count;
}
2 changes: 2 additions & 0 deletions FluidNC/include/Driver/fluidnc_gpio.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ void gpio_set_interrupt_type(pinnum_t pin, int mode);
void gpio_add_interrupt(pinnum_t pin, int mode, void (*callback)(void*), void* arg);
void gpio_remove_interrupt(pinnum_t pin);
void gpio_route(pinnum_t pin, uint32_t signal);

class Print;
void gpio_dump(Print& out);

typedef void (*gpio_dispatch_t)(int, void*, bool);
Expand Down
12 changes: 12 additions & 0 deletions FluidNC/include/Driver/fluidnc_i2c.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
// Copyright 2022 - Mitch Bradley
// Use of this source code is governed by a GPLv3 license that can be found in the LICENSE file.

#pragma once

#include "src/Pins/PinDetail.h" // pinnum_t

// I2C interface

bool i2c_master_init(int bus_number, pinnum_t sda_pin, pinnum_t scl_pin, uint32_t frequency);
int i2c_write(int bus_number, uint8_t address, const uint8_t* data, size_t count);
int i2c_read(int bus_number, uint8_t address, uint8_t* data, size_t count);
11 changes: 1 addition & 10 deletions FluidNC/src/Config.h
Original file line number Diff line number Diff line change
Expand Up @@ -214,15 +214,6 @@ const bool FORCE_BUFFER_SYNC_DURING_WCO_CHANGE = true; // Default enabled. Comm
// repeatable. If needed, you can disable this behavior by uncommenting the define below.
const bool ALLOW_FEED_OVERRIDE_DURING_PROBE_CYCLES = false;

// INCLUDE_OLED_IO enables access to a basic OLED library. To use it you must uncomment the
// "thingpulse/ESP8266 and ESP32 OLED driver for SSD1306 displays" line in platformio.ini
// You must uncomment it if you use either INCLUDE_OLED_TINY or INCLUDE_OLED_BASIC
// #define INCLUDE_OLED_IO

// INCLUDE_OLED_TINY includes a driver for a very small 64x48 OLED display
// #define INCLUDE_OLED_TINY

// INCLUDE_OLED_BASIC includes a driver for a modest sized OLED display
// #define INCLUDE_OLED_BASIC
const int MAX_N_I2C = 2;

#include "NutsBolts.h"
1 change: 1 addition & 0 deletions FluidNC/src/Configuration/GenericFactory.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#pragma once

#include <vector>
#include "../Logging.h"

#include "HandlerBase.h"

Expand Down
Loading

0 comments on commit 468fee9

Please sign in to comment.