From 3dfb02550816ee0dbae1abe9b9af782968d8fe87 Mon Sep 17 00:00:00 2001 From: Terje Io Date: Wed, 24 Jan 2024 18:42:45 +0100 Subject: [PATCH] Added support for new features in the ioports API. Added Neopixel driver code exposed via the core RGB API. --- driver.json | 157 ++++++++++++++--------------- main/driver.c | 38 ++++++-- main/i2c.c | 2 +- main/ioports.c | 42 +++++++- main/ioports_analog.c | 222 +++++++++++++++++++++--------------------- main/wifi.c | 10 +- platformio.tpl | 2 +- 7 files changed, 258 insertions(+), 215 deletions(-) diff --git a/driver.json b/driver.json index bfe8d2a..56f83fc 100644 --- a/driver.json +++ b/driver.json @@ -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" }, @@ -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, @@ -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": { @@ -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, @@ -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 } }, { @@ -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 } }, { @@ -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 } }, { @@ -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 } }, { @@ -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 } }, @@ -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 } @@ -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 } }, @@ -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 } }, { @@ -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 } }, { @@ -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 } }, { @@ -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 } } ] diff --git a/main/driver.c b/main/driver.c index f0569b4..a74ce65 100644 --- a/main/driver.c +++ b/main/driver.c @@ -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, @@ -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) @@ -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 }; diff --git a/main/i2c.c b/main/i2c.c index 44d43de..1288211 100644 --- a/main/i2c.c +++ b/main/i2c.c @@ -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); diff --git a/main/ioports.c b/main/ioports.c index 3609d19..8c332a9 100644 --- a/main/ioports.c +++ b/main/ioports.c @@ -48,6 +48,27 @@ static void digital_out (uint8_t port, bool on) } } +static float digital_out_state (xbar_t *pin) +{ + float value = -1.0f; + + uint8_t port = pin->function - Output_Aux0; + if(port < digital.out.n_ports) + value = (float)(DIGITAL_IN(aux_out[port].pin) ^ aux_out[port].mode.inverted); + + return value; +} + +static float digital_in_state (xbar_t *pin) +{ + float value = -1.0f; + + uint8_t port = pin->function - Input_Aux0; + if(port < digital.in.n_ports) + value = (float)(DIGITAL_IN(aux_in[port].pin) ^ aux_in[port].mode.inverted); + + return value; +} inline static __attribute__((always_inline)) int32_t get_input (const input_signal_t *input, bool invert, wait_mode_t wait_mode, float timeout) { if(wait_mode == WaitMode_Immediate) @@ -176,23 +197,28 @@ static xbar_t *get_pin_info (io_port_type_t type, io_port_direction_t dir, uint8 pin.mode = aux_in[port].mode; pin.mode.input = On; pin.cap = aux_in[port].cap; + pin.cap.invert = On; pin.cap.claimable = !pin.mode.claimed; pin.function = aux_in[port].id; pin.group = aux_in[port].group; pin.pin = aux_in[port].pin; pin.description = aux_in[port].description; + pin.get_value = digital_in_state; info = &pin; } if(dir == Port_Output && port < digital.out.n_ports) { port = ioports_map(digital.out, port); pin.mode = aux_out[port].mode; - pin.mode.output = pin.cap.output = On; - pin.cap.claimable = !pin.mode.claimed; + pin.mode.output = On; + XBAR_SET_CAP(pin.cap, pin.mode); + pin.cap.invert = On; + pin.mode.inverted = (settings.ioport.invert_out.mask >> port) & 0x01; pin.function = aux_out[port].id; pin.group = aux_out[port].group; pin.pin = aux_out[port].pin; pin.description = aux_out[port].description; + pin.get_value = digital_out_state; info = &pin; } } @@ -302,9 +328,11 @@ static void on_setting_changed (setting_id_t id) case Settings_IoPort_InvertIn: port = digital.in.n_ports; do { - if(aux_in[--port].aux_ctrl) { + port--; + aux_in[port].mode.inverted = !!(settings.ioport.invert_in.mask & (1 << port)); + if(aux_in[port].aux_ctrl) { write = true; - if(settings.ioport.invert_in.mask & (1 << port)) + if(aux_in[port].mode.inverted) settings.control_invert.mask |= aux_in[port].aux_ctrl->cap.mask; else settings.control_invert.mask &= ~aux_in[port].aux_ctrl->cap.mask; @@ -317,6 +345,7 @@ static void on_setting_changed (setting_id_t id) port = digital.out.n_ports; do { port--; + aux_out[port].mode.inverted = !!(settings.ioport.invert_out.mask & (1 << port)); if(((settings.ioport.invert_out.mask >> port) & 0x01) != ((invert_digital_out.mask >> port) & 0x01)) DIGITAL_OUT(aux_out[port].pin, !DIGITAL_IN(aux_out[port].pin)); } while(port); @@ -334,6 +363,7 @@ static void on_setting_changed (setting_id_t id) settings.ioport.invert_in.mask |= (1 << port); else settings.ioport.invert_in.mask &= ~(1 << port); + aux_in[port].mode.inverted = !!(settings.ioport.invert_in.mask & (1 << port)); } } while(port); break; @@ -355,7 +385,8 @@ static void on_settings_loaded (void) if(digital.out.n_ports) do { port--; - DIGITAL_OUT(aux_out[port].pin, (settings.ioport.invert_out.mask >> port) & 0x01); + aux_out[port].mode.inverted = !!(settings.ioport.invert_out.mask & (1 << port)); + DIGITAL_OUT(aux_out[port].pin, aux_out[port].mode.inverted); } while(port); port = digital.in.n_ports; @@ -369,6 +400,7 @@ static void on_settings_loaded (void) else settings.ioport.invert_in.mask &= ~(1 << port); } + aux_in[port].mode.inverted = !!(settings.ioport.invert_in.mask & (1 << port)); } while(port); if(write) diff --git a/main/ioports_analog.c b/main/ioports_analog.c index 71c5ca3..096687e 100644 --- a/main/ioports_analog.c +++ b/main/ioports_analog.c @@ -23,12 +23,20 @@ #include "grbl/ioports.h" -#if defined(AUXOUTPUT0_PWM_PIN) || defined(AUXOUTPUT1_PWM_PIN) -#define AUX_ANALOG_OUT 1 +#ifdef AUXOUTPUT0_PWM_PIN +#define PWM_OUT0 1 +#else +#define PWM_OUT0 0 +#endif + +#ifdef AUXOUTPUT1_PWM_PIN +#define PWM_OUT1 1 #else -#define AUX_ANALOG_OUT 0 +#define PWM_OUT1 0 #endif +#define AUX_ANALOG_OUT (PWM_OUT0 + PWM_OUT1) + #if defined(AUXINPUT0_ANALOG_PIN) || defined(AUXINPUT1_ANALOG_PIN) #define AUX_ANALOG_IN 1 #else @@ -102,59 +110,68 @@ static void enumerate_pins (bool low_level, pin_info_ptr pin_info, void *data) #if AUX_ANALOG_OUT -static void set_pwm_cap (xbar_t *output, bool servo_pwm) +typedef struct { + uint32_t max_value; + ledc_channel_config_t ch_config; + ioports_pwm_t data; + float value; + void (*set_value)(uint_fast8_t ch, float value); +} pwm_out_t; + +static pwm_out_t pwm_out[AUX_ANALOG_OUT] = {0}; + +static float pwm_get_value (struct xbar *output) { - uint_fast8_t i = analog.out.n_ports; + int_fast8_t ch = output->function - Output_Analog_Aux0; - if(output) do { - i--; - if(aux_out_analog[i].pin == output->pin) { - aux_out_analog[i].mode.pwm = !servo_pwm; - aux_out_analog[i].mode.servo_pwm = servo_pwm; - break; - } - } while(i); + return ch >= 0 && ch < analog.out.n_ports ? pwm_out[ch].value : -1.0f; } -#endif -#ifdef AUXOUTPUT0_PWM_PIN +static bool analog_out (uint8_t port, float value) +{ + if(port < analog.out.n_ports) { -static ioports_pwm_t pwm0; -static uint32_t pwm0_max_value; -static ledc_channel_config_t pwm0_ch = { - .gpio_num = AUXOUTPUT0_PWM_PIN, -#if CONFIG_IDF_TARGET_ESP32S3 - .speed_mode = LEDC_SPEED_MODE_MAX, -#else - .speed_mode = LEDC_HIGH_SPEED_MODE, -#endif - .channel = LEDC_CHANNEL_1, - .intr_type = LEDC_INTR_DISABLE, - .timer_sel = LEDC_TIMER_1, - .duty = 0, - .hpoint = 0 -}; + port = ioports_map(analog.out, port); + + uint_fast8_t ch = aux_out_analog[port].id - Output_Analog_Aux0; -static void pwm0_out (float value) + pwm_out[ch].set_value(ch, value); + } + + return port < analog.out.n_ports; +} + +static void pwm_set_value (uint_fast8_t ch, float value) { - uint_fast16_t pwm_value = ioports_compute_pwm_value(&pwm0, value); + uint_fast16_t pwm_value = ioports_compute_pwm_value(&pwm_out[ch].data, value); - if(pwm_value == pwm0.off_value) { - if(pwm0.always_on) { - ledc_set_duty(pwm0_ch.speed_mode, pwm0_ch.channel, pwm0.off_value); - ledc_update_duty(pwm0_ch.speed_mode, pwm0_ch.channel); + pwm_out[ch].value = value; + + if(pwm_value == pwm_out[ch].data.off_value) { + if(pwm_out[ch].data.always_on) { + ledc_set_duty(pwm_out[ch].ch_config.speed_mode, pwm_out[ch].ch_config.channel, pwm_out[ch].data.off_value); + ledc_update_duty(pwm_out[ch].ch_config.speed_mode, pwm_out[ch].ch_config.channel); } else - ledc_stop(pwm0_ch.speed_mode, pwm0_ch.channel, 0); + ledc_stop(pwm_out[ch].ch_config.speed_mode, pwm_out[ch].ch_config.channel, 0); } else { - ledc_set_duty(pwm0_ch.speed_mode, pwm0_ch.channel, pwm_value); - ledc_update_duty(pwm0_ch.speed_mode, pwm0_ch.channel); + ledc_set_duty(pwm_out[ch].ch_config.speed_mode, pwm_out[ch].ch_config.channel, pwm_value); + ledc_update_duty(pwm_out[ch].ch_config.speed_mode, pwm_out[ch].ch_config.channel); } } +#endif + +#ifdef AUXOUTPUT0_PWM_PIN + static bool init_pwm0 (xbar_t *pin, pwm_config_t *config) { static bool init_ok = false; + bool ok; + uint_fast8_t ch = pin->function - Output_Analog_Aux0; + ioports_pwm_t *pwm_data = &pwm_out[ch].data; + ledc_channel_config_t *ch_config = &pwm_out[ch].ch_config; + static ledc_timer_config_t pwm_timer = { #if CONFIG_IDF_TARGET_ESP32S3 .speed_mode = LEDC_LOW_SPEED_MODE, @@ -170,9 +187,21 @@ static bool init_pwm0 (xbar_t *pin, pwm_config_t *config) init_ok = true; - pwm0_ch.speed_mode = pwm_timer.speed_mode; + ch_config->gpio_num = AUXOUTPUT0_PWM_PIN, +#if CONFIG_IDF_TARGET_ESP32S3 + ch_config->speed_mode = LEDC_SPEED_MODE_MAX; +#else + ch_config->speed_mode = LEDC_HIGH_SPEED_MODE; +#endif + ch_config->channel = LEDC_CHANNEL_1; + ch_config->intr_type = LEDC_INTR_DISABLE; + ch_config->timer_sel = pwm_timer.timer_num; + ch_config->speed_mode = pwm_timer.speed_mode; + ledc_timer_config(&pwm_timer); - ledc_channel_config(&pwm0_ch); + ledc_channel_config(ch_config); + + pwm_out[ch].set_value = pwm_set_value; } if(pwm_timer.freq_hz != (uint32_t)config->freq_hz) { @@ -195,54 +224,33 @@ static bool init_pwm0 (xbar_t *pin, pwm_config_t *config) } } - pwm0_max_value = (1UL << pwm_timer.duty_resolution) - 1; - ioports_precompute_pwm_values(config, &pwm0, pwm0_max_value * config->freq_hz); + if((ok = ledc_set_freq(pwm_timer.speed_mode, pwm_timer.timer_num, pwm_timer.freq_hz) == ESP_OK)) { + + pwm_out[ch].max_value = (1UL << pwm_timer.duty_resolution) - 1; + ioports_precompute_pwm_values(config, pwm_data, pwm_out[ch].max_value * config->freq_hz); - set_pwm_cap(pin, config->servo_mode); + aux_out_analog[ch].mode.pwm = !config->servo_mode; + aux_out_analog[ch].mode.servo_pwm = config->servo_mode; - return ledc_set_freq(pwm_timer.speed_mode, pwm_timer.timer_num, pwm_timer.freq_hz) == ESP_OK; + pwm_set_value(ch, config->min); + } + + return ok; } #endif // AUXOUTPUT0_PWM_PIN #ifdef AUXOUTPUT1_PWM_PIN -static ioports_pwm_t pwm1; -static uint32_t pwm1_max_value; -static ledc_channel_config_t pwm1_ch = { - .gpio_num = AUXOUTPUT1_PWM_PIN, -#if CONFIG_IDF_TARGET_ESP32S3 - .speed_mode = LEDC_SPEED_MODE_MAX, -#else - .speed_mode = LEDC_HIGH_SPEED_MODE, -#endif - .channel = LEDC_CHANNEL_2, - .intr_type = LEDC_INTR_DISABLE, - .timer_sel = LEDC_TIMER_2, - .duty = 0, - .hpoint = 0 -}; - -static void pwm1_out (float value) -{ - uint_fast16_t pwm_value = ioports_compute_pwm_value(&pwm1, value); - - if(pwm_value == pwm1.off_value) { - if(pwm1.always_on) { - ledc_set_duty(pwm1_ch.speed_mode, pwm1_ch.channel, pwm1.off_value); - ledc_update_duty(pwm1_ch.speed_mode, pwm1_ch.channel); - } else - ledc_stop(pwm1_ch.speed_mode, pwm1_ch.channel, 0); - } else { - ledc_set_duty(pwm1_ch.speed_mode, pwm1_ch.channel, pwm_value); - ledc_update_duty(pwm1_ch.speed_mode, pwm1_ch.channel); - } -} - static bool init_pwm1 (xbar_t *pin, pwm_config_t *config) { static bool init_ok = false; + bool ok; + uint_fast8_t ch = pin->function - Output_Analog_Aux0; + ioports_pwm_t *pwm_data = &pwm_out[ch].data; + ledc_channel_config_t *ch_config = &pwm_out[ch].ch_config; + static ledc_timer_config_t pwm_timer = { #if CONFIG_IDF_TARGET_ESP32S3 .speed_mode = LEDC_LOW_SPEED_MODE, @@ -258,9 +266,21 @@ static bool init_pwm1 (xbar_t *pin, pwm_config_t *config) init_ok = true; - pwm1_ch.speed_mode = pwm_timer.speed_mode; + ch_config->gpio_num = AUXOUTPUT1_PWM_PIN, +#if CONFIG_IDF_TARGET_ESP32S3 + ch_config->speed_mode = LEDC_SPEED_MODE_MAX; +#else + ch_config->speed_mode = LEDC_HIGH_SPEED_MODE; +#endif + ch_config->channel = LEDC_CHANNEL_2; + ch_config->intr_type = LEDC_INTR_DISABLE; + ch_config->timer_sel = pwm_timer.timer_num; + ch_config->speed_mode = pwm_timer.speed_mode; + ledc_timer_config(&pwm_timer); - ledc_channel_config(&pwm1_ch); + ledc_channel_config(ch_config); + + pwm_out[ch].set_value = pwm_set_value; } if(pwm_timer.freq_hz != (uint32_t)config->freq_hz) { @@ -283,36 +303,21 @@ static bool init_pwm1 (xbar_t *pin, pwm_config_t *config) } } - pwm1_max_value = (1UL << pwm_timer.duty_resolution) - 1; - ioports_precompute_pwm_values(config, &pwm1, pwm1_max_value * config->freq_hz); - - set_pwm_cap(pin, config->servo_mode); - - return ledc_set_freq(pwm_timer.speed_mode, pwm_timer.timer_num, pwm_timer.freq_hz) == ESP_OK; -} + if((ok = ledc_set_freq(pwm_timer.speed_mode, pwm_timer.timer_num, pwm_timer.freq_hz) == ESP_OK)) { -#endif // AUXOUTPUT1_PWM_PIN + pwm_out[ch].max_value = (1UL << pwm_timer.duty_resolution) - 1; + ioports_precompute_pwm_values(config, pwm_data, pwm_out[ch].max_value * config->freq_hz); -#if AUX_ANALOG_OUT + aux_out_analog[ch].mode.pwm = !config->servo_mode; + aux_out_analog[ch].mode.servo_pwm = config->servo_mode; -static bool analog_out (uint8_t port, float value) -{ - if(port < analog.out.n_ports) { - port = ioports_map(analog.out, port); -#ifdef AUXOUTPUT0_PWM_PIN - if(aux_out_analog[port].pin == AUXOUTPUT0_PWM_PIN) - pwm0_out(value); -#endif -#ifdef AUXOUTPUT1_PWM_PIN - if(aux_out_analog[port].pin == AUXOUTPUT1_PWM_PIN) - pwm1_out(value); -#endif + pwm_set_value(ch, config->min); } - return port < analog.out.n_ports; + return ok; } -#endif +#endif // AUXOUTPUT1_PWM_PIN #if AUX_ANALOG_IN @@ -390,6 +395,7 @@ static xbar_t *get_pin_info (io_port_type_t type, io_port_direction_t dir, uint8 pin.pin = aux_out_analog[port].pin; pin.bit = 1 << aux_out_analog[port].pin; pin.description = aux_out_analog[port].description; + pin.get_value = pwm_get_value; #ifdef AUXOUTPUT0_PWM_PIN if(aux_out_analog[port].pin == AUXOUTPUT0_PWM_PIN) pin.config = (xbar_config_ptr)init_pwm0; @@ -571,8 +577,8 @@ void ioports_init_analog (pin_group_pins_t *aux_inputs, pin_group_pins_t *aux_ou if(analog.out.n_ports) { + xbar_t *pin; uint_fast8_t i; - pwm_config_t config = { .freq_hz = 5000.0f, .min = 0.0f, @@ -586,14 +592,8 @@ void ioports_init_analog (pin_group_pins_t *aux_inputs, pin_group_pins_t *aux_ou hal.port.analog_out = analog_out; for(i = 0; i < analog.out.n_ports; i++) { -#ifdef AUXOUTPUT0_PWM_PIN - if(aux_out_analog[i].pin == AUXOUTPUT0_PWM_PIN) - init_pwm0(NULL, &config); -#endif -#ifdef AUXOUTPUT1_PWM_PIN - if(aux_out_analog[i].pin == AUXOUTPUT1_PWM_PIN) - init_pwm1(NULL, &config); -#endif + if((pin = get_pin_info(Port_Analog, Port_Output, i))) + pin->config(pin, &config); } } diff --git a/main/wifi.c b/main/wifi.c index 3c4ad21..f46cde4 100644 --- a/main/wifi.c +++ b/main/wifi.c @@ -669,6 +669,8 @@ bool wifi_start (void) if(ap_netif == NULL) ap_netif = esp_netif_create_default_wifi_ap(); + esp_netif_set_hostname(ap_netif, wifi.ap.network.hostname); + esp_netif_dhcps_stop(ap_netif); wifi.ap.network.ip_mode = IpMode_Static; // Only mode supported @@ -713,6 +715,8 @@ bool wifi_start (void) if(sta_netif == NULL) sta_netif = esp_netif_create_default_wifi_sta(); + esp_netif_set_hostname(sta_netif, wifi.sta.network.hostname); + esp_netif_dhcps_stop(sta_netif); wifi.sta.network.ip_mode = IpMode_DHCP; // For now... @@ -744,12 +748,6 @@ bool wifi_start (void) if(esp_wifi_start() != ESP_OK) return false; - if(wifi.mode == WiFiMode_AP || wifi.mode == WiFiMode_APSTA) - esp_netif_set_hostname(ap_netif, wifi.ap.network.hostname); - - if(wifi.mode == WiFiMode_STA || wifi.mode == WiFiMode_APSTA) - esp_netif_set_hostname(sta_netif, wifi.sta.network.hostname); - if(wifi.mode == WiFiMode_APSTA) wifi_ap_scan(); diff --git a/platformio.tpl b/platformio.tpl index a362c0d..30dbfda 100644 --- a/platformio.tpl +++ b/platformio.tpl @@ -14,7 +14,7 @@ platform = espressif32 @ ~4.0.0 framework = espidf board =%board% board_build.partitions = partitions.csv -board_build.cmake_extra_args = %cmake_flags% +#board_build.cmake_extra_args = %cmake_flags% board_build.embed_files = main/embedded/favicon.ico main/embedded/ap_login.html