Skip to content

Commit

Permalink
Added support for new features in the ioports API.
Browse files Browse the repository at this point in the history
Added Neopixel driver code exposed via the core RGB API.
  • Loading branch information
terjeio committed Jan 24, 2024
1 parent f598f9d commit 3dfb025
Show file tree
Hide file tree
Showing 7 changed files with 258 additions and 215 deletions.
157 changes: 74 additions & 83 deletions driver.json
Original file line number Diff line number Diff line change
@@ -1,23 +1,15 @@
{
"caps": {
"axes": 6,
"usb_cdc": 0,
"uart": 1,
"serial_ports": 1,
"eeprom": 1,
"ganged_axes": 1,
"auto_square": 1,
"littlefs": 1,
"digital_in": 2,
"digital_out": 2,
"probe": 1,
"safety_door": 1,
"estop": 0,
"mpg_mode": 1,
"sdcard": 1,
"estop": 1,
"wifi": 1,
"ethernet": 0,
"bluetooth": 1,
"pwm_spindle_aux": 3,
"pio_board": "esp32dev",
"plugins": [
{ "id": "bluetooth" },
Expand All @@ -36,8 +28,10 @@
{ "id": "embroidery" }
]
},
"symbols": {
"OVERRIDE_MY_MACHINE": 1
},
"symbols_networking": {
"STDIO_FS": " ",
"LWIP_HTTPD_CUSTOM_FILES": 0,
"LWIP_HTTPD_DYNAMIC_HEADERS": 1,
"LWIP_HTTPD_SUPPORT_V09": 0,
Expand All @@ -53,12 +47,9 @@
"MAP": "main/boards/BlackBoxX32_map.h",
"caps": {
"axes": 4,
"digital_in": 0,
"digital_out": 0,
"auto_square": 1,
"digital_in": 2,
"safety_door": 1,
"eeprom": 0,
"fram": 0,
"i2c": 0,
"sdcard": 1
},
"symbols": {
Expand All @@ -77,13 +68,7 @@
"MAP": "main/boards/bdring_i2s_6_axis_map.h",
"caps": {
"axes": 6,
"digital_in": 0,
"digital_out": 0,
"serial_ports": 2,
"eeprom": 0,
"fram": 0,
"i2c": 0,
"sdcard": 0,
"trinamic_spi_cs": 1,
"trinamic_spi_chain": 1,
"trinamic_uart_n": 0,
Expand All @@ -97,12 +82,11 @@
"URL": "",
"caps": {
"axes": 3,
"digital_in": 0,
"digital_out": 0,
"serial_ports": 2,
"sdcard": 1,
"probe": 1,
"safety_door": 0,
"eeprom": 0,
"fram": 0,
"i2c": 0
"pwm_spindle_aux": 2
}
},
{
Expand All @@ -112,13 +96,9 @@
"MAP": "main/boards/mks_tinybee_1_0_map.h",
"caps": {
"axes": 5,
"digital_in": 0,
"digital_out": 0,
"serial_ports": 2,
"eeprom": 0,
"fram": 0,
"i2c": 0,
"sdcard": 1
"sdcard": 1,
"estop": 0
}
},
{
Expand All @@ -129,13 +109,21 @@
"caps": {
"axes": 4,
"auto_square": 0,
"digital_in": 0,
"digital_out": 0,
"safety_door": 0,
"eeprom": 0,
"fram": 0,
"i2c": 0,
"sdcard": 0
"estop": 0,
"pwm_spindle_aux": 1
}
},
{
"name": "SourceRabbit 4-axis CNC v1.2",
"symbol": "BOARD_SOURCERABBIT_4AXIS_12",
"URL": "https://www.sourcerabbit.com/",
"MAP": "main/boards/sourcerabbit_4axis.h",
"caps": {
"axes": 4,
"auto_square": 0,
"safety_door": 0,
"estop": 0
}
},
{
Expand All @@ -145,13 +133,7 @@
"MAP": "main/boards/protoneer_3.xx_map.h",
"caps": {
"axes": 3,
"digital_in": 0,
"digital_out": 0,
"safety_door": 0,
"eeprom": 0,
"fram": 0,
"i2c": 0,
"sdcard": 0
"pwm_spindle_aux": 2
}
},
{
Expand All @@ -161,11 +143,9 @@
"MAP": "main/boards/fysetc_e4_map.h",
"caps": {
"axes": 4,
"digital_in": 0,
"digital_out": 0,
"safety_door": 0,
"eeprom": 0,
"fram": 0,
"auto_square": 0,
"pwm_spindle_aux": 2,
"sdcard": 1,
"i2c": 1
}
},
Expand All @@ -175,13 +155,10 @@
"URL": "https://www.spark-concepts.com/cnc-xpro-v5/",
"MAP": "main/boards/xPro_v5_map.h",
"caps": {
"axes": 3,
"axes": 4,
"digital_in": 2,
"digital_out": 0,
"serial_ports": 2,
"eeprom": 0,
"fram": 0,
"i2c": 0,
"sdcard": 1,
"trinamic": 5160,
"trinamic_spi_chain": 1
}
Expand All @@ -195,10 +172,36 @@
"axes": 3,
"digital_in": 1,
"digital_out": 4,
"safety_door": 0,
"eeprom": 0,
"fram": 0,
"i2c": 0,
"pwm_spindle_aux": 2,
"sdcard": 1,
"i2c": 1
}
},
{
"name": "Root CNC v2.x",
"notes": "Not tested!",
"symbol": "BOARD_ROOTCNC_V2",
"URL": "https://wiki.rootcnc.com/en/Root-Controller-ISO/DetailedInfo",
"MAP": "main/boards/root_cnc_v2_map.h",
"caps": {
"axes": 6,
"digital_in": 1,
"serial_ports": 2,
"estop": 0,
"sdcard": 1
}
},
{
"name": "Root CNC v3",
"notes": "Not tested!",
"symbol": "BOARD_ROOTCNC_V3",
"URL": "https://wiki.rootcnc.com/en/Root-Controller-ISO/DetailedInfo",
"MAP": "main/boards/root_cnc_v3_map.h",
"caps": {
"axes": 6,
"digital_in": 1,
"serial_ports": 2,
"estop": 0,
"sdcard": 1
}
},
Expand All @@ -209,17 +212,11 @@
"MAP": "main/boards/cnc3040_map.h",
"caps": {
"axes": 4,
"auto_square": 0,
"serial_ports": 2,
"eeprom": 1,
"digital_in": 0,
"digital_out": 0,
"probe": 1,
"safety_door": 1,
"mpg_mode": 0,
"sdcard": 0,
"wifi": 1,
"fram": 1,
"i2c": 0
"estop": 0,
"pwm_spindle_aux": 2,
"safety_door": 1
}
},
{
Expand All @@ -229,12 +226,9 @@
"MAP": "main/boards/bdring_v3.5_map.h",
"caps": {
"axes": 3,
"digital_in": 0,
"digital_out": 0,
"digital_in": 1,
"serial_ports": 1,
"eeprom": 0,
"fram": 0,
"i2c": 0
"sdcard": 1
}
},
{
Expand All @@ -244,12 +238,9 @@
"MAP": "main/boards/bdring_v4_map.h",
"caps": {
"axes": 3,
"digital_in": 0,
"digital_out": 0,
"serial_ports": 2,
"eeprom": 0,
"fram": 0,
"i2c": 0
"digital_in": 1,
"sdcard": 1
}
},
{
Expand All @@ -259,12 +250,12 @@
"MAP": "main/boards/boosterpack_map.h",
"caps": {
"axes": 3,
"digital_in": 0,
"digital_out": 0,
"serial_ports": 2,
"digital_in": 1,
"eeprom": 1,
"fram": 1,
"i2c": 1
"i2c": 1,
"sdcard": 1
}
}
]
Expand Down
38 changes: 30 additions & 8 deletions main/driver.c
Original file line number Diff line number Diff line change
Expand Up @@ -2425,6 +2425,8 @@ static rmt_config_t neo_config = RMT_DEFAULT_CONFIG_TX(NEOPIXELS_PIN, 3); // TOD
#define WS2812_T1H_NS (1200)
#define WS2812_T1L_NS (1300)
*/

static uint8_t pixels[NEOPIXELS_NUM * 3] = {0};
static uint32_t t0h_ticks = 0, t1h_ticks = 0, t0l_ticks = 0, t1l_ticks = 0;

static void IRAM_ATTR ws2812_rmt_adapter (const void *src, rmt_item32_t *dest, size_t src_size,
Expand Down Expand Up @@ -2459,23 +2461,39 @@ static void IRAM_ATTR ws2812_rmt_adapter (const void *src, rmt_item32_t *dest, s
*item_num = num;
}

static void rgb_out (uint8_t device, rgb_color_t color)
void neopixels_write (void)
{
static uint8_t pixels[NEOPIXELS_NUM * 3] = {0};
rmt_write_sample(neo_config.channel, pixels, sizeof(pixels), true);
}

static void neopixel_out_masked (uint16_t device, rgb_color_t color, rgb_color_mask_t mask)
{
if(device < NEOPIXELS_NUM) {

device *= 3;
pixels[device++] = color.G;
pixels[device++] = color.R;
pixels[device] = color.B;

if(mask.G)
pixels[device++] = color.G;
else
device++;
if(mask.R)
pixels[device++] = color.R;
else
device++;
if(mask.B)
pixels[device] = color.B;
#if NEOPIXELS_NUM == 1
rmt_write_sample(neo_config.channel, pixels, sizeof(pixels), true);
#endif
//?? rmt_wait_tx_done(neo_config.channel, pdMS_TO_TICKS(100));
}
}

#endif
static void neopixel_out (uint8_t device, rgb_color_t color)
{
neopixel_out_masked(device, color, (rgb_color_mask_t){ .mask = 0xFF });
}

#endif // NEOPIXELS_PIN

// Initializes MCU peripherals for Grbl use
static bool driver_setup (settings_t *settings)
Expand Down Expand Up @@ -3006,7 +3024,11 @@ bool driver_init (void)
// Initialize automatic timing translator
rmt_translator_init(neo_config.channel, ws2812_rmt_adapter);

hal.rgb.out = rgb_out;
hal.rgb.out = neopixel_out;
hal.rgb.out_masked = neopixel_out_masked;
#if NEOPIXELS_NUM > 1
hal.rgb.write = neopixels_write;
#endif
hal.rgb.num_devices = NEOPIXELS_NUM;
hal.rgb.cap = (rgb_color_t){ .R = 255, .G = 255, .B = 255 };

Expand Down
2 changes: 1 addition & 1 deletion main/i2c.c
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ void I2CInit (void)

TaskHandle_t I2CTaskHandle;

xTaskCreatePinnedToCore(I2CTask, "I2C", 2048, (void *)i2cQueue, configMAX_PRIORITIES - 1, &I2CTaskHandle, 1);
xTaskCreatePinnedToCore(I2CTask, "I2C", 2048, (void *)i2cQueue, GRBLHAL_TASK_PRIORITY + 1, &I2CTaskHandle, 1);

xSemaphoreGive(i2cBusy);

Expand Down
Loading

0 comments on commit 3dfb025

Please sign in to comment.