|
@@ -0,0 +1,79 @@
|
|
|
|
+#include "freertos/FreeRTOS.h"
|
|
|
|
+#include "freertos/task.h"
|
|
|
|
+#include "freertos/queue.h"
|
|
|
|
+#include "driver/ledc.h"
|
|
|
|
+#include "driver/pcnt.h"
|
|
|
|
+#include "esp_attr.h"
|
|
|
|
+#include "esp_log.h"
|
|
|
|
+#include "config.h"
|
|
|
|
+
|
|
|
|
+/* Decode what PCNT's unit originated an interrupt
|
|
|
|
+ * and pass this information together with the event type
|
|
|
|
+ * the main program using a queue.
|
|
|
|
+ */
|
|
|
|
+static void IRAM_ATTR pcnt_example_intr_handler(void *arg)
|
|
|
|
+{
|
|
|
|
+ int pcnt_unit = (int)arg;
|
|
|
|
+}
|
|
|
|
+
|
|
|
|
+/* Initialize PCNT functions:
|
|
|
|
+ * - configure and initialize PCNT
|
|
|
|
+ * - set up the input filter
|
|
|
|
+ * - set up the counter events to watch
|
|
|
|
+ */
|
|
|
|
+void init_pcnt_unit(int unit)
|
|
|
|
+{
|
|
|
|
+ /* Prepare configuration for the PCNT unit */
|
|
|
|
+ pcnt_config_t pcnt_config = {
|
|
|
|
+ // Set PCNT input signal and control GPIOs
|
|
|
|
+ .pulse_gpio_num = PCNT_INPUT_SIG_IO,
|
|
|
|
+ .ctrl_gpio_num = PCNT_INPUT_CTRL_IO,
|
|
|
|
+ .channel = PCNT_CHANNEL_0,
|
|
|
|
+ .unit = unit,
|
|
|
|
+ // What to do on the positive / negative edge of pulse input?
|
|
|
|
+ .pos_mode = PCNT_COUNT_INC, // Count up on the positive edge
|
|
|
|
+ .neg_mode = PCNT_COUNT_DIS, // Keep the counter value on the negative edge
|
|
|
|
+ // What to do when control input is low or high?
|
|
|
|
+ .lctrl_mode = PCNT_MODE_REVERSE, // Reverse counting direction if low
|
|
|
|
+ .hctrl_mode = PCNT_MODE_KEEP, // Keep the primary counter mode if high
|
|
|
|
+ // Set the maximum and minimum limit values to watch
|
|
|
|
+ .counter_h_lim = 0,
|
|
|
|
+ .counter_l_lim = 0,
|
|
|
|
+ };
|
|
|
|
+ /* Initialize PCNT unit */
|
|
|
|
+ pcnt_unit_config(&pcnt_config);
|
|
|
|
+
|
|
|
|
+ pcnt_event_disable(unit, PCNT_EVT_H_LIM);
|
|
|
|
+ pcnt_event_disable(unit, PCNT_EVT_L_LIM);
|
|
|
|
+ pcnt_event_disable(unit, PCNT_EVT_ZERO);
|
|
|
|
+ pcnt_filter_disable(unit);
|
|
|
|
+
|
|
|
|
+ //uint32_t c = p_pcnt_obj->hal.dev.hw.conf_unit[unit];
|
|
|
|
+
|
|
|
|
+
|
|
|
|
+ /* Configure and enable the input filter */
|
|
|
|
+
|
|
|
|
+ //pcnt_set_filter_value(unit, 100);
|
|
|
|
+ //pcnt_filter_enable(unit);
|
|
|
|
+
|
|
|
|
+ /* Set threshold 0 and 1 values and enable events to watch */
|
|
|
|
+ //pcnt_set_event_value(unit, PCNT_EVT_THRES_1, PCNT_THRESH1_VAL);
|
|
|
|
+ //pcnt_event_enable(unit, PCNT_EVT_THRES_1);
|
|
|
|
+ //pcnt_set_event_value(unit, PCNT_EVT_THRES_0, PCNT_THRESH0_VAL);
|
|
|
|
+ //pcnt_event_enable(unit, PCNT_EVT_THRES_0);
|
|
|
|
+ /* Enable events on zero, maximum and minimum limit values */
|
|
|
|
+ //pcnt_event_enable(unit, PCNT_EVT_ZERO);
|
|
|
|
+ //pcnt_event_enable(unit, PCNT_EVT_H_LIM);
|
|
|
|
+ //pcnt_event_enable(unit, PCNT_EVT_L_LIM);
|
|
|
|
+
|
|
|
|
+ /* Initialize PCNT's counter */
|
|
|
|
+ pcnt_counter_pause(unit);
|
|
|
|
+ pcnt_counter_clear(unit);
|
|
|
|
+
|
|
|
|
+ /* Install interrupt service and add isr callback handler */
|
|
|
|
+ //pcnt_isr_service_install(0);
|
|
|
|
+ //pcnt_isr_handler_add(unit, pcnt_example_intr_handler, (void *)unit);
|
|
|
|
+
|
|
|
|
+ /* Everything is set up, now go to counting */
|
|
|
|
+ pcnt_counter_resume(unit);
|
|
|
|
+}
|