]> granicus.if.org Git - esp-idf/commitdiff
PCNT: fix for pcnt_set_pin API, it can now use all pcnt channels
authorNilay <nilay@espressif.com>
Fri, 16 Jun 2017 05:48:00 +0000 (11:18 +0530)
committerNilay <nilay@espressif.com>
Fri, 16 Jun 2017 05:48:00 +0000 (11:18 +0530)
components/driver/pcnt.c

index 907221edfe4434f161408610999b131f60696c86..3f2d866c1c7f5ce61aacf17cca7a8c3112754b25 100644 (file)
@@ -96,8 +96,16 @@ esp_err_t pcnt_set_pin(pcnt_unit_t unit, pcnt_channel_t channel, int pulse_io, i
     PCNT_CHECK(channel < PCNT_CHANNEL_MAX, PCNT_CHANNEL_ERR_STR, ESP_ERR_INVALID_ARG);
     PCNT_CHECK(GPIO_IS_VALID_GPIO(pulse_io) || pulse_io < 0, PCNT_GPIO_ERR_STR, ESP_ERR_INVALID_ARG);
     PCNT_CHECK(GPIO_IS_VALID_GPIO(ctrl_io) || ctrl_io < 0, PCNT_GPIO_ERR_STR, ESP_ERR_INVALID_ARG);
-    int input_sig_index = (channel == 0 ? PCNT_SIG_CH0_IN0_IDX + 4 * unit : PCNT_SIG_CH1_IN0_IDX + 4 * unit);
-    int ctrl_sig_index = (channel == 0 ? PCNT_CTRL_CH0_IN0_IDX + 4 * unit : PCNT_CTRL_CH1_IN0_IDX + 4 * unit);
+    
+    int sig_base  = (channel == 0) ? PCNT_SIG_CH0_IN0_IDX  : PCNT_SIG_CH1_IN0_IDX;
+    int ctrl_base = (channel == 0) ? PCNT_CTRL_CH0_IN0_IDX : PCNT_CTRL_CH1_IN0_IDX;
+    if (unit > 4) {  
+        sig_base  += 12; // GPIO matrix assignments have a gap between units 4 & 5  
+        ctrl_base += 12;
+    }
+    int input_sig_index = sig_base  + (4 * unit);
+    int ctrl_sig_index  = ctrl_base + (4 * unit);
+
     if(pulse_io >= 0) {
         PIN_FUNC_SELECT(GPIO_PIN_MUX_REG[pulse_io], PIN_FUNC_GPIO);
         gpio_set_direction(pulse_io, GPIO_MODE_INPUT);