File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 2525#if defined(ARDUINO)
2626
2727namespace {
28+
29+ // The input-signal selection field of gpio_func_in_sel_cfg_reg_t differs by chip generation
30+ // (independent of the ESP-IDF version):
31+ // Older chips (ESP32/S2/S3/C3): func_sel
32+ // Newer chips (C6/H2/P4 and later): in_sel
33+ // Detect which member exists at compile time and read whichever is present (no chip defines needed).
34+ template <class T >
35+ auto read_func_in_sel (const volatile T& reg, int ) -> decltype(+reg.in_sel)
36+ {
37+ return reg.in_sel ;
38+ }
39+ template <class T >
40+ auto read_func_in_sel (const volatile T& reg, long ) -> decltype(+reg.func_sel)
41+ {
42+ return reg.func_sel ;
43+ }
44+
2845int16_t search_pin_number (const int peripheral_sig)
2946{
3047 int16_t no{-1 };
31- #if defined(CONFIG_IDF_TARGET_ESP32C6)
32- // C6
3348 no = (peripheral_sig >= 0 && peripheral_sig < m5::stl::size (GPIO .func_in_sel_cfg ))
34- ? GPIO .func_in_sel_cfg [peripheral_sig]. in_sel
49+ ? static_cast < int16_t >( read_func_in_sel ( GPIO .func_in_sel_cfg [peripheral_sig], 0 ))
3550 : -1 ;
36- #elif defined(CONFIG_IDF_TARGET_ESP32P4)
37- // P4
38- no = (peripheral_sig >= 0 && peripheral_sig < m5::stl::size (GPIO .func_in_sel_cfg ))
39- ? GPIO .func_in_sel_cfg [peripheral_sig].in_sel
40- : -1 ;
41- #else
42- // Others
43- no = (peripheral_sig >= 0 && peripheral_sig < m5::stl::size (GPIO .func_in_sel_cfg ))
44- ? GPIO .func_in_sel_cfg [peripheral_sig].func_sel
45- : -1 ;
46- #endif
47-
4851 return (no < GPIO_NUM_MAX ) ? no : -1 ;
4952}
5053
You can’t perform that action at this time.
0 commit comments