Refactor: Move pulse control initialization to seperate function
parent
422b8edd60
commit
531cb9b0a9
|
|
@ -22,6 +22,8 @@ static QueueHandle_t pcnt_queue = NULL;
|
|||
|
||||
static const char *TAG = "RE Demo"; /* logging tag */
|
||||
|
||||
pcnt_unit_handle_t pcnt_unit;
|
||||
|
||||
/* Pulse Counter Callback */
|
||||
static bool pcnt_cb(pcnt_unit_handle_t unit, const pcnt_watch_event_data_t *edata, void *user_ctx) {
|
||||
BaseType_t high_task_wakeup;
|
||||
|
|
@ -30,16 +32,14 @@ static bool pcnt_cb(pcnt_unit_handle_t unit, const pcnt_watch_event_data_t *edat
|
|||
return (high_task_wakeup == pdTRUE);
|
||||
}
|
||||
|
||||
/* Main Loop */
|
||||
void app_main(void){
|
||||
|
||||
/* Initialize the pulse counter peripheral */
|
||||
static void pcnt_init() {
|
||||
/* Configure the PCNT unit and get a handle */
|
||||
ESP_LOGI(TAG, "Setting up Pulse Counter Unit");
|
||||
pcnt_unit_config_t pcnt_unit_config = {
|
||||
.high_limit = PCNT_HIGH_LIMIT,
|
||||
.low_limit = PCNT_LOW_LIMIT
|
||||
};
|
||||
pcnt_unit_handle_t pcnt_unit = NULL;
|
||||
ESP_ERROR_CHECK(pcnt_new_unit(&pcnt_unit_config, &pcnt_unit));
|
||||
|
||||
/* Setup glitch filter */
|
||||
|
|
@ -91,6 +91,14 @@ void app_main(void){
|
|||
ESP_ERROR_CHECK(pcnt_unit_enable(pcnt_unit));
|
||||
ESP_ERROR_CHECK(pcnt_unit_clear_count(pcnt_unit));
|
||||
ESP_ERROR_CHECK(pcnt_unit_start(pcnt_unit));
|
||||
}
|
||||
|
||||
|
||||
/* Main Loop */
|
||||
void app_main(void){
|
||||
|
||||
/* Initialize pulse counter */
|
||||
pcnt_init();
|
||||
|
||||
/* Log counter value */
|
||||
int pulse_count = 0;
|
||||
|
|
|
|||
Loading…
Reference in New Issue