Add GPIO input configuration

This commit is contained in:
maddiebaka
2025-11-25 17:31:28 -05:00
parent 1ebf753862
commit 6156dc3466
2 changed files with 23 additions and 5 deletions

View File

@@ -1,3 +1,3 @@
idf_component_register(SRCS "spincoat-plater-firmware.c" "dshot_esc_encoder.c" idf_component_register(SRCS "spincoat-plater-firmware.c" "dshot_esc_encoder.c"
PRIV_REQUIRES esp_driver_rmt PRIV_REQUIRES esp_driver_rmt esp_driver_gpio
INCLUDE_DIRS ".") INCLUDE_DIRS ".")

View File

@@ -8,6 +8,7 @@
#include "freertos/task.h" #include "freertos/task.h"
#include "esp_log.h" #include "esp_log.h"
#include "driver/rmt_tx.h" #include "driver/rmt_tx.h"
#include "driver/gpio.h"
#include "dshot_esc_encoder.h" #include "dshot_esc_encoder.h"
#if CONFIG_IDF_TARGET_ESP32H2 #if CONFIG_IDF_TARGET_ESP32H2
@@ -15,7 +16,8 @@
#else #else
#define DSHOT_ESC_RESOLUTION_HZ 40000000 // 40MHz resolution, DSHot protocol needs a relative high resolution #define DSHOT_ESC_RESOLUTION_HZ 40000000 // 40MHz resolution, DSHot protocol needs a relative high resolution
#endif #endif
#define DSHOT_ESC_GPIO_NUM 22 #define DSHOT_ESC_GPIO_NUM 22
#define DSHOT_ESC_TELEMETRY_GPIO_NUM 27
static const char *TAG = "spincoat-plater-firmware"; static const char *TAG = "spincoat-plater-firmware";
@@ -61,7 +63,7 @@ void initialize_esc_throttle(void) {
xTaskCreate(&v_initialize_esc_throttle_func, "v_init_throttle_func", 2048, NULL, 5, &v_init_throttle_handle); xTaskCreate(&v_initialize_esc_throttle_func, "v_init_throttle_func", 2048, NULL, 5, &v_init_throttle_handle);
vTaskDelay(pdMS_TO_TICKS(5000)); vTaskDelay(pdMS_TO_TICKS(5000));
vTaskDelete(v_init_throttle_handle); vTaskDelete(v_init_throttle_handle);
vTaskDelay(pdMS_TO_TICKS(1000)); //vTaskDelay(pdMS_TO_TICKS(1000));
} }
/** /**
@@ -102,16 +104,32 @@ void send_dshot_packet(void) {
if(throttle.telemetry_req == true) { if(throttle.telemetry_req == true) {
throttle.telemetry_req = false; throttle.telemetry_req = false;
printf("Set telemetry to false.\n");
} }
} }
void app_main(void) { void app_main(void) {
init_rmt_esc_tx(); init_rmt_esc_tx();
throttle.throttle = 100; throttle.throttle = 200;
xTaskCreate(&v_telemetry_packet_func, "v_telemetry_packet_func", 2048, NULL, 5, NULL); xTaskCreate(&v_telemetry_packet_func, "v_telemetry_packet_func", 2048, NULL, 5, NULL);
gpio_dump_io_configuration(stdout, (1ULL << 27));
printf("==============================\n\n");
// Testing gpio setup
gpio_config_t io_conf = {};
io_conf.intr_type = GPIO_INTR_DISABLE;
io_conf.mode = GPIO_MODE_INPUT_OUTPUT;
io_conf.pin_bit_mask = (1ULL<<DSHOT_ESC_TELEMETRY_GPIO_NUM);
io_conf.pull_down_en = GPIO_PULLDOWN_ENABLE;
io_conf.pull_up_en = GPIO_PULLUP_DISABLE;
gpio_config(&io_conf);
gpio_dump_io_configuration(stdout, (1ULL << 27));
while(1) { while(1) {
send_dshot_packet(); send_dshot_packet();
} }