ESP_TIMER - Declaration issue

Lancsrick
Posts: 41
Joined: Mon Apr 10, 2023 5:48 pm

ESP_TIMER - Declaration issue

Postby Lancsrick » Sun Apr 26, 2026 10:06 pm

I've made a right mess of migrating from 5.5 to 6.0 and have lost track of edits that I've done. My current issue is that I cannot get rid of an error being thrown every time I pass arguments to esp_timer_create. The IDE only seems happy when it's esp_timer_create() with no arguments, which clearly isn't helpful.

Error flags on the ampersand of each pointer being passed and reads as "expected declaration specifiers or '...' before '&' token".

I've included the code up to and including the relevant section below, who knows what else I'll find after fixing this issue, but that's not today's issue.

Thanks in advance for any help.

Code: Select all

#include <inttypes.h>
#include <stdint.h>
#include <stdio.h>
#include <freertos/FreeRTOS.h>
#include <freertos/task.h>
#include <sys/time.h>
#include <pcf8574/pcf8574.h>
#include <esp_idf_version.h>
#include <dirent.h>
#include "driver/gpio.h"
#include "freertos/queue.h"
#include "esp_timer.h"
#include <max7219/max7219.h>
#include <string.h>

#ifndef APP_CPU_NUM
#define APP_CPU_NUM PRO_CPU_NUM 
#endif


#define HOST    SPI2_HOST

#pragma region PCF8574_1_DEFINITIONS
const uint8_t RF1_POSITION = 0x01; //Pin P0
const uint8_t RF2_POSITION = 0x02; //Pin P1
const uint8_t RF3_POSITION = 0x04; //Pin P2
const uint8_t RF4_POSITION = 0x08; //Pin P3
const uint8_t BF1_POSITION = 0x10; //Pin P4
const uint8_t BF2_POSITION = 0x20; //Pin P5
const uint8_t BF3_POSITION = 0x40; //Pin P6
const uint8_t BF4_POSITION = 0x80; //Pin P7
#pragma endregion PCF8574_1_DEFINITIONS

#pragma region PCF8574_2_DEFINITIONS
const uint8_t A1_POSITION = 0x01; //Pin P0
const uint8_t A2_POSITION = 0x02; //Pin P1
const uint8_t A3_POSITION = 0x04; //Pin P2
const uint8_t GS_POSITION = 0x08; //Pin P3
const uint8_t RFF_POSITION = 0x10; //Pin P4
const uint8_t BFF_POSITION = 0x20; //Pin P5
#pragma endregion PCF8574_2_DEFINITIONS

#pragma region Global_Variables

QueueHandle_t q_red_queue; //creates a queue to capture the sensor trigger events for the red lane
QueueHandle_t q_blue_queue; //creates a queue to capture the sensor trigger events for the blue lane
QueueHandle_t q_start_pressed; 
QueueHandle_t q_stop_pressed; 
QueueHandle_t q_twomin;
QueueHandle_t q_reset;


    static i2c_dev_t pcf8574_1; //define the i2c device for the first expander
    static i2c_dev_t pcf8574_2; //define the i2c device for the second expander

     uint8_t pcf8574_1_value = 0x00; //ensure the starting lights condition is fully off
  uint8_t pcf8574_2_value = 0x00; //ensure the starting lights condition is fully off
    


struct st_events //defines the structure of each element in the red/blue lane queue
{
  int64_t timestamp; //in microseconds
  char current_state; //will be A, a, B, b
};


struct st_events blue_array[1000]; //arbitrary size of 1000 events for a race, may need to refine this
int blue_index=0; //create and initialise index counter for the array

struct st_events red_array[1000]; //arbitrary size of 1000 events for a race, may need to refine this
int red_index=0; //create and initialise index counter for the array

#pragma endregion Global_Variables


esp_timer_handle_t rsafe_timer;
esp_timer_handle_t bflash_timer;
esp_timer_handle_t bsafe_timer;
esp_timer_handle_t gs_timer;
esp_timer_handle_t a1_timer;
esp_timer_handle_t a2_timer;
esp_timer_handle_t a3_timer;
esp_timer_handle_t rflash_timer;

#pragma region Timer_Callbacks




void red_flash_callback(void* arg)
{
  pcf8574_port_write(&pcf8574_1,pcf8574_1_value & ~RFF_POSITION);
}

void blue_flash_callback(void* arg)
{
  pcf8574_port_write(&pcf8574_1,pcf8574_1_value & ~BFF_POSITION);
}

void a1_callback(void* arg)
{
  pcf8574_port_write(&pcf8574_2,pcf8574_2_value & ~A1_POSITION);
  esp_timer_start_once(a2_timer, 1000000);
  pcf8574_port_write(&pcf8574_2,pcf8574_2_value | A2_POSITION);
}

void a2_callback(void* arg)
{
  pcf8574_port_write(&pcf8574_2,pcf8574_2_value & ~A2_POSITION);
  esp_timer_start_once(a2_timer, 1000000);
  pcf8574_port_write(&pcf8574_2,pcf8574_2_value | A3_POSITION);
}

void a3_callback(void* arg)
{
  pcf8574_port_write(&pcf8574_2,pcf8574_2_value & ~A3_POSITION);
  esp_timer_start_once(a2_timer, 1000000);
  pcf8574_port_write(&pcf8574_2,pcf8574_2_value | GS_POSITION);
}

void gs_callback(void* arg)
{
  pcf8574_port_write(&pcf8574_2,pcf8574_2_value & ~GS_POSITION);
  esp_timer_start_once(rsafe_timer, 2000000);
  esp_timer_start_once(bsafe_timer, 2000000);          
}


void red_safe_callback(void* arg) 
{

}

void blue_safe_callback(void* arg)
{
 
}

#pragma endregion Timer_Callbacks

#pragma region TIMER_CREATION
    const esp_timer_create_args_t red_safe_timer_args = {
    .callback = &red_safe_callback,
    .dispatch_method = ESP_TIMER_ISR
    };
    
    esp_timer_create( &red_safe_timer_args, &rsafe_timer);

    const esp_timer_create_args_t blue_safe_timer_args = {
      .callback = &blue_safe_callback,
      .dispatch_method = ESP_TIMER_ISR
    };
    
    esp_timer_create(&blue_safe_timer_args, &bsafe_timer);

    const esp_timer_create_args_t red_flash_timer_args = {
      .callback = &red_flash_callback,
      .dispatch_method = ESP_TIMER_ISR
    };
    
    esp_timer_create(&red_flash_timer_args, &rflash_timer);

    const esp_timer_create_args_t blue_flash_timer_args = {
      .callback = &blue_flash_callback,
      .dispatch_method = ESP_TIMER_ISR
    };
    
    esp_timer_create(&blue_flash_timer_args, &bflash_timer);

    const esp_timer_create_args_t a1_timer_args = {
      .callback = &a1_callback,
      .dispatch_method = ESP_TIMER_ISR
    };
    
    esp_timer_create(&a1_timer_args, &a1_timer);

    const esp_timer_create_args_t a2_timer_args = {
      .callback = &a2_callback,
      .dispatch_method = ESP_TIMER_ISR
    };
    
    esp_timer_create(&a2_timer_args, &a2_timer);

    const esp_timer_create_args_t a3_timer_args = {
      .callback = &a3_callback,
      .dispatch_method = ESP_TIMER_ISR
    };
    
    esp_timer_create(&a3_timer_args, &a3_timer);

    const esp_timer_create_args_t gs_timer_args = {
      .callback = &gs_callback,
      .dispatch_method = ESP_TIMER_ISR
    };

    esp_timer_create(&gs_timer_args, &gs_timer);


  #pragma endregion TIMER_CREATION



MicroController
Posts: 2669
Joined: Mon Oct 17, 2022 7:38 pm
Location: Europe, Germany

Re: ESP_TIMER - Declaration issue

Postby MicroController » Mon Apr 27, 2026 6:43 am

The calls to esp_timer_create(...) must be made from inside some other function.

Lancsrick
Posts: 41
Joined: Mon Apr 10, 2023 5:48 pm

Re: ESP_TIMER - Declaration issue

Postby Lancsrick » Mon Apr 27, 2026 8:06 am

Thank you, I'd gone blind! Much appreciated.

Who is online

Users browsing this forum: No registered users and 8 guests