Skip to content

Commit

Permalink
Updated for core changes related to the RGB HAL.
Browse files Browse the repository at this point in the history
  • Loading branch information
terjeio committed Sep 4, 2024
1 parent fd2a3a7 commit b31b72a
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 19 deletions.
21 changes: 12 additions & 9 deletions main/driver.c
Original file line number Diff line number Diff line change
Expand Up @@ -445,6 +445,7 @@ static ioexpand_t iopins = {0};

#ifdef NEOPIXELS_PIN
neopixel_cfg_t neopixel = { .intensity = 255 };
void neopixels_write (void);
#endif

#if AUX_CONTROLS_ENABLED
Expand Down Expand Up @@ -2033,6 +2034,7 @@ static void settings_changed (settings_t *settings, settings_changed_flags_t cha
}

neopixel.num_leds = hal.rgb0.num_devices;
hal.rgb0.write = neopixel.num_leds > 1 ? neopixels_write : NULL;
}

#endif
Expand Down Expand Up @@ -2515,7 +2517,7 @@ static void IRAM_ATTR ws2812_rmt_adapter (const void *src, rmt_item32_t *dest, s
*item_num = num;
}

void neopixels_write (void)
void _neopixels_write (void)
{
uint8_t *buf = neopixel.leds;
size_t size = neopixel.num_bytes;
Expand All @@ -2535,14 +2537,19 @@ void neopixels_write (void)
#endif
}

void neopixels_write (void)
{
_neopixels_write();
}

static void neopixel_out_masked (uint16_t device, rgb_color_t color, rgb_color_mask_t mask)
{
if(neopixel.num_leds && device < neopixel.num_leds) {

rgb_1bpp_assign(&neopixel.leds[device * 3], color, mask);

if(neopixel.num_leds == 1)
neopixels_write();
_neopixels_write();
}
}

Expand All @@ -2558,15 +2565,15 @@ uint8_t neopixels_set_intensity (uint8_t value)
if(neopixel.intensity != value) {

neopixel.intensity = value;
// neopixels_write();
_neopixels_write();
}

return prev;
}

#endif // NEOPIXELS_PIN

// Initializes MCU peripherals for Grbl use
// Initializes MCU peripherals for grblHAL use
static bool driver_setup (settings_t *settings)
{

Expand Down Expand Up @@ -2757,9 +2764,6 @@ static bool driver_setup (settings_t *settings)
enet_start();
#endif

// if(hal.rgb0.out)
// hal.rgb0.out(0, (rgb_color_t){ .R = 5, .G = 100, .B = 5 });

return IOInitDone;
}

Expand Down Expand Up @@ -2815,7 +2819,7 @@ bool driver_init (void)
#else
hal.info = "ESP32";
#endif
hal.driver_version = "240817";
hal.driver_version = "240903";
hal.driver_url = GRBL_URL "/ESP32";
#ifdef BOARD_NAME
hal.board = BOARD_NAME;
Expand Down Expand Up @@ -3078,7 +3082,6 @@ bool driver_init (void)

hal.rgb0.out = neopixel_out;
hal.rgb0.out_masked = neopixel_out_masked;
hal.rgb0.write = neopixels_write;
hal.rgb0.set_intensity = neopixels_set_intensity;
hal.rgb0.num_devices = NEOPIXELS_NUM;
hal.rgb0.cap = (rgb_color_t){ .R = 255, .G = 255, .B = 255 };
Expand Down
7 changes: 6 additions & 1 deletion main/my_machine.h
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@
//#define SPINDLE1_ENABLE SPINDLE_PWM0_NODIR
//#define SPINDLE2_ENABLE SPINDLE_NONE
//#define SPINDLE3_ENABLE SPINDLE_NONE
//#define SPINDLE_OFFSET 1 // Uncomment to enable settings for laser spindle XY-offset.
// **********************
//#define MODBUS_ENABLE 1 // Set to 1 for auto direction, 2 for direction signal on auxillary output pin.
//#define WEBUI_ENABLE 3 // Enable ESP3D-WEBUI plugin along with networking and SD card plugins.
Expand Down Expand Up @@ -85,11 +86,15 @@
//#define EEPROM_IS_FRAM 1 // Uncomment when EEPROM is enabled and chip is FRAM, this to remove write delay.
#define ESTOP_ENABLE 0 // When enabled only real-time report requests will be executed when the reset pin is asserted.
// NOTE: if left commented out the default setting is determined from COMPATIBILITY_LEVEL.
//#define PROBE_ENABLE 0 // Uncomment to disable probe input.
//#define RGB_LED_ENABLE 2 // Set to 1 to enable strip length settings $536 and $537, set to 2 to also enable M150 LED strip control.
//#define PWM_SERVO_ENABLE 1 // Enable PWM servo support, requires at least one PWM capable auxillary output.
//#define BLTOUCH_ENABLE 1 // Enable BLTouch support. Requires and claims one PWM servo output.
//#define EVENTOUT_ENABLE 1 // Enable binding events (triggers) to control auxillary outputs.

// Optional control signals:
// These will be assigned to aux input pins. Use the $pins command to check which pins are assigned.
// NOTE: If not enough pins are available assignment will silently fail.
//#define PROBE_ENABLE 0 // Uncomment to disable probe input.
//#define SAFETY_DOOR_ENABLE 1
//#define MOTOR_FAULT_ENABLE 1
//#define MOTOR_WARNING_ENABLE 1
Expand Down
63 changes: 54 additions & 9 deletions main/usb_serial.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,20 @@
Part of grblHAL
Some parts are copyright (c) 2021-2023 Terje Io
Some parts are copyright (c) 2023-2024 Terje Io
Grbl is free software: you can redistribute it and/or modify
grblHAL 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.
Grbl is distributed in the hope that it will be useful,
grblHAL is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Grbl. If not, see <http://www.gnu.org/licenses/>.
along with grblHAL. If not, see <http://www.gnu.org/licenses/>.
***
Expand All @@ -29,6 +29,8 @@
*/

#if CONFIG_IDF_TARGET_ESP32S3

#include <stdint.h>
#include "esp_log.h"
#include "freertos/FreeRTOS.h"
Expand Down Expand Up @@ -79,17 +81,15 @@ static void usb_out_chars (const char *buf, int length)
}
}

/*
static int32_t usb_in_chars (char *buf, uint32_t length)
{
uint32_t count = 0;

if(usb_connected() && tud_cdc_available())
count = tud_cdc_read(buf, length);
if (usb_connected() && tud_cdc_available())
count = tud_cdc_read(buf, length);

return count ? count : -1;
}
*/

//
// Returns number of characters in USB input buffer
Expand Down Expand Up @@ -310,3 +310,48 @@ const io_stream_t *usb_serialInit (void)

return &stream;
}

//
// This function get called from the foreground process,
// used here to get characters off the USB serial input stream and buffer
// them for processing by grbl. Real time command characters are stripped out
// and submitted for realtime processing.
//
static void execute_realtime (uint_fast16_t state)
{
static volatile bool lock = false;
static char tmpbuf[BLOCK_RX_BUFFER_SIZE];

if(lock)
return;

char c, *dp;
int32_t avail, free;

lock = true;

if(usb_connected() && (avail = (int32_t)tud_cdc_available())) {

dp = tmpbuf;
free = (int32_t)usb_serialRxFree();
free = free > BLOCK_RX_BUFFER_SIZE ? BLOCK_RX_BUFFER_SIZE : free;
avail = usb_in_chars(tmpbuf, (uint32_t)(avail > free ? free : avail));

if(avail > 0) while(avail--) {
c = *dp++;
if(!enqueue_realtime_command(c)) {
uint_fast16_t next_head = BUFNEXT(rxbuf.head, rxbuf); // Get next head pointer
if(next_head == rxbuf.tail) // If buffer full
rxbuf.overflow = On; // flag overflow,
else {
rxbuf.data[rxbuf.head] = c; // else add character data to buffer
rxbuf.head = next_head; // and update pointer
}
}
}
}

lock = false;
}

#endif // GRBL_ESP32S3

0 comments on commit b31b72a

Please sign in to comment.