diff --git a/Devices/btt-panda-touch/bigtreetech,panda-touch.dts b/Devices/btt-panda-touch/bigtreetech,panda-touch.dts index 1b829a08..0c42d851 100644 --- a/Devices/btt-panda-touch/bigtreetech,panda-touch.dts +++ b/Devices/btt-panda-touch/bigtreetech,panda-touch.dts @@ -18,15 +18,15 @@ compatible = "espressif,esp32-i2c"; port = ; clock-frequency = <400000>; - pin-sda = <2>; - pin-scl = <1>; + pin-sda = <&gpio0 2 GPIO_FLAG_NONE>; + pin-scl = <&gpio0 1 GPIO_FLAG_NONE>; }; i2c_external: i2c1 { compatible = "espressif,esp32-i2c"; port = ; clock-frequency = <400000>; - pin-sda = <4>; - pin-scl = <3>; + pin-sda = <&gpio0 4 GPIO_FLAG_NONE>; + pin-scl = <&gpio0 3 GPIO_FLAG_NONE>; }; }; diff --git a/Devices/cyd-2432s024c/cyd,2432s024c.dts b/Devices/cyd-2432s024c/cyd,2432s024c.dts index 6c3fe31f..eaf0f478 100644 --- a/Devices/cyd-2432s024c/cyd,2432s024c.dts +++ b/Devices/cyd-2432s024c/cyd,2432s024c.dts @@ -18,8 +18,8 @@ compatible = "espressif,esp32-i2c"; port = ; clock-frequency = <400000>; - pin-sda = <33>; - pin-scl = <32>; + pin-sda = <&gpio0 33 GPIO_FLAG_NONE>; + pin-scl = <&gpio0 32 GPIO_FLAG_NONE>; }; display_spi: spi0 { diff --git a/Devices/cyd-2432s028r/cyd,2432s028r.dts b/Devices/cyd-2432s028r/cyd,2432s028r.dts index d85ec1e0..963465c8 100644 --- a/Devices/cyd-2432s028r/cyd,2432s028r.dts +++ b/Devices/cyd-2432s028r/cyd,2432s028r.dts @@ -19,8 +19,8 @@ compatible = "espressif,esp32-i2c"; port = ; clock-frequency = <400000>; - pin-sda = <27>; - pin-scl = <22>; + pin-sda = <&gpio0 27 GPIO_FLAG_NONE>; + pin-scl = <&gpio0 22 GPIO_FLAG_NONE>; }; display_spi: spi0 { diff --git a/Devices/cyd-2432s028rv3/cyd,2432s028rv3.dts b/Devices/cyd-2432s028rv3/cyd,2432s028rv3.dts index 950fc49d..d8fcf6cb 100644 --- a/Devices/cyd-2432s028rv3/cyd,2432s028rv3.dts +++ b/Devices/cyd-2432s028rv3/cyd,2432s028rv3.dts @@ -19,8 +19,8 @@ compatible = "espressif,esp32-i2c"; port = ; clock-frequency = <400000>; - pin-sda = <27>; - pin-scl = <22>; + pin-sda = <&gpio0 27 GPIO_FLAG_NONE>; + pin-scl = <&gpio0 22 GPIO_FLAG_NONE>; }; display_spi: spi0 { diff --git a/Devices/cyd-2432s032c/cyd,2432s032c.dts b/Devices/cyd-2432s032c/cyd,2432s032c.dts index 078215ae..71dc8fac 100644 --- a/Devices/cyd-2432s032c/cyd,2432s032c.dts +++ b/Devices/cyd-2432s032c/cyd,2432s032c.dts @@ -18,8 +18,8 @@ compatible = "espressif,esp32-i2c"; port = ; clock-frequency = <400000>; - pin-sda = <33>; - pin-scl = <32>; + pin-sda = <&gpio1 33 GPIO_FLAG_NONE>; + pin-scl = <&gpio1 32 GPIO_FLAG_NONE>; }; display_spi: spi0 { diff --git a/Devices/cyd-4848s040c/cyd,4848s040c.dts b/Devices/cyd-4848s040c/cyd,4848s040c.dts index 39e08ddc..c970bf8b 100644 --- a/Devices/cyd-4848s040c/cyd,4848s040c.dts +++ b/Devices/cyd-4848s040c/cyd,4848s040c.dts @@ -18,8 +18,8 @@ compatible = "espressif,esp32-i2c"; port = ; clock-frequency = <400000>; - pin-sda = <19>; - pin-scl = <45>; + pin-sda = <&gpio0 19 GPIO_FLAG_NONE>; + pin-scl = <&gpio0 45 GPIO_FLAG_NONE>; }; spi0 { diff --git a/Devices/cyd-8048s043c/cyd,8048s043c.dts b/Devices/cyd-8048s043c/cyd,8048s043c.dts index 3382fb88..286a4871 100644 --- a/Devices/cyd-8048s043c/cyd,8048s043c.dts +++ b/Devices/cyd-8048s043c/cyd,8048s043c.dts @@ -19,16 +19,16 @@ compatible = "espressif,esp32-i2c"; port = ; clock-frequency = <400000>; - pin-sda = <19>; - pin-scl = <20>; + pin-sda = <&gpio0 19 GPIO_FLAG_NONE>; + pin-scl = <&gpio0 20 GPIO_FLAG_NONE>; }; i2c_external { compatible = "espressif,esp32-i2c"; port = ; clock-frequency = <400000>; - pin-sda = <17>; - pin-scl = <18>; + pin-sda = <&gpio0 17 GPIO_FLAG_NONE>; + pin-scl = <&gpio0 18 GPIO_FLAG_NONE>; }; spi0 { diff --git a/Devices/cyd-e32r32p/cyd,e32r32p.dts b/Devices/cyd-e32r32p/cyd,e32r32p.dts index 100bc526..569f7d15 100644 --- a/Devices/cyd-e32r32p/cyd,e32r32p.dts +++ b/Devices/cyd-e32r32p/cyd,e32r32p.dts @@ -18,8 +18,8 @@ compatible = "espressif,esp32-i2c"; port = ; clock-frequency = <400000>; - pin-sda = <32>; - pin-scl = <25>; + pin-sda = <&gpio0 32 GPIO_FLAG_NONE>; + pin-scl = <&gpio0 25 GPIO_FLAG_NONE>; }; display_spi: spi0 { diff --git a/Devices/elecrow-crowpanel-advance-28/elecrow,crowpanel-advance-28.dts b/Devices/elecrow-crowpanel-advance-28/elecrow,crowpanel-advance-28.dts index ecccc467..38109d0a 100644 --- a/Devices/elecrow-crowpanel-advance-28/elecrow,crowpanel-advance-28.dts +++ b/Devices/elecrow-crowpanel-advance-28/elecrow,crowpanel-advance-28.dts @@ -19,8 +19,8 @@ compatible = "espressif,esp32-i2c"; port = ; clock-frequency = <400000>; - pin-sda = <15>; - pin-scl = <16>; + pin-sda = <&gpio0 15 GPIO_FLAG_NONE>; + pin-scl = <&gpio0 16 GPIO_FLAG_NONE>; }; display_spi: spi0 { diff --git a/Devices/elecrow-crowpanel-advance-35/elecrow,crowpanel-advance-35.dts b/Devices/elecrow-crowpanel-advance-35/elecrow,crowpanel-advance-35.dts index cd034a61..2b1069a0 100644 --- a/Devices/elecrow-crowpanel-advance-35/elecrow,crowpanel-advance-35.dts +++ b/Devices/elecrow-crowpanel-advance-35/elecrow,crowpanel-advance-35.dts @@ -19,8 +19,8 @@ compatible = "espressif,esp32-i2c"; port = ; clock-frequency = <400000>; - pin-sda = <15>; - pin-scl = <16>; + pin-sda = <&gpio0 15 GPIO_FLAG_NONE>; + pin-scl = <&gpio0 16 GPIO_FLAG_NONE>; }; display_spi: spi0 { diff --git a/Devices/elecrow-crowpanel-advance-50/elecrow,crowpanel-advance-50.dts b/Devices/elecrow-crowpanel-advance-50/elecrow,crowpanel-advance-50.dts index 53a7ab72..ae65de5b 100644 --- a/Devices/elecrow-crowpanel-advance-50/elecrow,crowpanel-advance-50.dts +++ b/Devices/elecrow-crowpanel-advance-50/elecrow,crowpanel-advance-50.dts @@ -19,8 +19,8 @@ compatible = "espressif,esp32-i2c"; port = ; clock-frequency = <400000>; - pin-sda = <15>; - pin-scl = <16>; + pin-sda = <&gpio0 15 GPIO_FLAG_NONE>; + pin-scl = <&gpio0 16 GPIO_FLAG_NONE>; }; sdcard_spi: spi0 { diff --git a/Devices/elecrow-crowpanel-basic-28/elecrow,crowpanel-basic-28.dts b/Devices/elecrow-crowpanel-basic-28/elecrow,crowpanel-basic-28.dts index 21d5e7ac..2542c941 100644 --- a/Devices/elecrow-crowpanel-basic-28/elecrow,crowpanel-basic-28.dts +++ b/Devices/elecrow-crowpanel-basic-28/elecrow,crowpanel-basic-28.dts @@ -19,8 +19,8 @@ compatible = "espressif,esp32-i2c"; port = ; clock-frequency = <400000>; - pin-sda = <22>; - pin-scl = <21>; + pin-sda = <&gpio0 22 GPIO_FLAG_NONE>; + pin-scl = <&gpio0 21 GPIO_FLAG_NONE>; }; display_spi: spi0 { diff --git a/Devices/elecrow-crowpanel-basic-35/elecrow,crowpanel-basic-35.dts b/Devices/elecrow-crowpanel-basic-35/elecrow,crowpanel-basic-35.dts index e9f160d1..18038d83 100644 --- a/Devices/elecrow-crowpanel-basic-35/elecrow,crowpanel-basic-35.dts +++ b/Devices/elecrow-crowpanel-basic-35/elecrow,crowpanel-basic-35.dts @@ -19,8 +19,8 @@ compatible = "espressif,esp32-i2c"; port = ; clock-frequency = <400000>; - pin-sda = <22>; - pin-scl = <21>; + pin-sda = <&gpio0 22 GPIO_FLAG_NONE>; + pin-scl = <&gpio0 21 GPIO_FLAG_NONE>; }; display_spi: spi0 { diff --git a/Devices/elecrow-crowpanel-basic-50/elecrow,crowpanel-basic-50.dts b/Devices/elecrow-crowpanel-basic-50/elecrow,crowpanel-basic-50.dts index 3a28c118..c20b6d1a 100644 --- a/Devices/elecrow-crowpanel-basic-50/elecrow,crowpanel-basic-50.dts +++ b/Devices/elecrow-crowpanel-basic-50/elecrow,crowpanel-basic-50.dts @@ -19,8 +19,8 @@ compatible = "espressif,esp32-i2c"; port = ; clock-frequency = <400000>; - pin-sda = <19>; - pin-scl = <20>; + pin-sda = <&gpio0 19 GPIO_FLAG_NONE>; + pin-scl = <&gpio0 20 GPIO_FLAG_NONE>; }; sdcard_spi: spi0 { diff --git a/Devices/guition-jc1060p470ciwy/guition,jc1060p470ciwy.dts b/Devices/guition-jc1060p470ciwy/guition,jc1060p470ciwy.dts index 6df073fd..bdbb8612 100644 --- a/Devices/guition-jc1060p470ciwy/guition,jc1060p470ciwy.dts +++ b/Devices/guition-jc1060p470ciwy/guition,jc1060p470ciwy.dts @@ -26,8 +26,8 @@ compatible = "espressif,esp32-i2c"; port = ; clock-frequency = <400000>; - pin-sda = <7>; - pin-scl = <8>; + pin-sda = <&gpio0 7 GPIO_FLAG_NONE>; + pin-scl = <&gpio0 8 GPIO_FLAG_NONE>; }; i2s0 { diff --git a/Devices/guition-jc2432w328c/guition,jc2432w328c.dts b/Devices/guition-jc2432w328c/guition,jc2432w328c.dts index 99c77be9..0c76444f 100644 --- a/Devices/guition-jc2432w328c/guition,jc2432w328c.dts +++ b/Devices/guition-jc2432w328c/guition,jc2432w328c.dts @@ -19,8 +19,8 @@ compatible = "espressif,esp32-i2c"; port = ; clock-frequency = <400000>; - pin-sda = <33>; - pin-scl = <32>; + pin-sda = <&gpio0 33 GPIO_FLAG_NONE>; + pin-scl = <&gpio0 32 GPIO_FLAG_NONE>; }; // CN1 header @@ -28,8 +28,8 @@ compatible = "espressif,esp32-i2c"; port = ; clock-frequency = <400000>; - pin-sda = <21>; - pin-scl = <22>; + pin-sda = <&gpio0 21 GPIO_FLAG_NONE>; + pin-scl = <&gpio0 22 GPIO_FLAG_NONE>; }; display_spi: spi0 { diff --git a/Devices/guition-jc3248w535c/guition,jc3248w535c.dts b/Devices/guition-jc3248w535c/guition,jc3248w535c.dts index 5cc09026..952d1a31 100644 --- a/Devices/guition-jc3248w535c/guition,jc3248w535c.dts +++ b/Devices/guition-jc3248w535c/guition,jc3248w535c.dts @@ -19,16 +19,16 @@ compatible = "espressif,esp32-i2c"; port = ; clock-frequency = <400000>; - pin-sda = <4>; - pin-scl = <8>; + pin-sda = <&gpio0 4 GPIO_FLAG_NONE>; + pin-scl = <&gpio0 8 GPIO_FLAG_NONE>; }; i2c_external: i2c1 { compatible = "espressif,esp32-i2c"; port = ; clock-frequency = <400000>; - pin-sda = <17>; - pin-scl = <18>; + pin-sda = <&gpio0 17 GPIO_FLAG_NONE>; + pin-scl = <&gpio0 18 GPIO_FLAG_NONE>; }; display_spi: spi0 { diff --git a/Devices/guition-jc8048w550c/guition,jc8048w550c.dts b/Devices/guition-jc8048w550c/guition,jc8048w550c.dts index 28d867d7..33e5bfd2 100644 --- a/Devices/guition-jc8048w550c/guition,jc8048w550c.dts +++ b/Devices/guition-jc8048w550c/guition,jc8048w550c.dts @@ -19,16 +19,16 @@ compatible = "espressif,esp32-i2c"; port = ; clock-frequency = <400000>; - pin-sda = <19>; - pin-scl = <20>; + pin-sda = <&gpio0 19 GPIO_FLAG_NONE>; + pin-scl = <&gpio0 20 GPIO_FLAG_NONE>; }; i2c_external: i2c1 { compatible = "espressif,esp32-i2c"; port = ; clock-frequency = <400000>; - pin-sda = <17>; - pin-scl = <18>; + pin-sda = <&gpio0 17 GPIO_FLAG_NONE>; + pin-scl = <&gpio0 18 GPIO_FLAG_NONE>; }; spi0 { diff --git a/Devices/heltec-wifi-lora-32-v3/heltec,wifi-lora-32-v3.dts b/Devices/heltec-wifi-lora-32-v3/heltec,wifi-lora-32-v3.dts index 8a5cd882..16296e3d 100644 --- a/Devices/heltec-wifi-lora-32-v3/heltec,wifi-lora-32-v3.dts +++ b/Devices/heltec-wifi-lora-32-v3/heltec,wifi-lora-32-v3.dts @@ -17,7 +17,7 @@ compatible = "espressif,esp32-i2c"; port = ; clock-frequency = <200000>; - pin-sda = <17>; - pin-scl = <18>; + pin-sda = <&gpio0 17 GPIO_FLAG_NONE>; + pin-scl = <&gpio0 18 GPIO_FLAG_NONE>; }; }; diff --git a/Devices/lilygo-tdeck/lilygo,tdeck.dts b/Devices/lilygo-tdeck/lilygo,tdeck.dts index 12d26280..96a0dfd7 100644 --- a/Devices/lilygo-tdeck/lilygo,tdeck.dts +++ b/Devices/lilygo-tdeck/lilygo,tdeck.dts @@ -21,16 +21,16 @@ compatible = "espressif,esp32-i2c"; port = ; clock-frequency = <400000>; - pin-sda = <18>; - pin-scl = <8>; + pin-sda = <&gpio0 18 GPIO_FLAG_NONE>; + pin-scl = <&gpio0 8 GPIO_FLAG_NONE>; }; i2c_external: i2c1 { compatible = "espressif,esp32-i2c"; port = ; clock-frequency = <400000>; - pin-sda = <43>; - pin-scl = <44>; + pin-sda = <&gpio0 43 GPIO_FLAG_NONE>; + pin-scl = <&gpio0 44 GPIO_FLAG_NONE>; }; i2s0 { diff --git a/Devices/lilygo-tdisplay-s3/lilygo,tdisplay-s3.dts b/Devices/lilygo-tdisplay-s3/lilygo,tdisplay-s3.dts index 27a7261f..4713d519 100644 --- a/Devices/lilygo-tdisplay-s3/lilygo,tdisplay-s3.dts +++ b/Devices/lilygo-tdisplay-s3/lilygo,tdisplay-s3.dts @@ -17,7 +17,7 @@ spi0 { compatible = "espressif,esp32-spi"; host = ; - pin-mosi = <7>; - pin-sclk = <6>; + pin-mosi = <&gpio0 7 GPIO_FLAG_NONE>; + pin-sclk = <&gpio0 6 GPIO_FLAG_NONE>; }; }; diff --git a/Devices/lilygo-tdisplay/lilygo,tdisplay.dts b/Devices/lilygo-tdisplay/lilygo,tdisplay.dts index 87da67c7..ecf6ca86 100644 --- a/Devices/lilygo-tdisplay/lilygo,tdisplay.dts +++ b/Devices/lilygo-tdisplay/lilygo,tdisplay.dts @@ -17,7 +17,7 @@ spi0 { compatible = "espressif,esp32-spi"; host = ; - pin-mosi = <19>; - pin-sclk = <18>; + pin-mosi = <&gpio0 19 GPIO_FLAG_NONE>; + pin-sclk = <&gpio0 18 GPIO_FLAG_NONE>; }; }; diff --git a/Devices/lilygo-tdongle-s3/lilygo,tdongle-s3.dts b/Devices/lilygo-tdongle-s3/lilygo,tdongle-s3.dts index 73ff6285..88a929fb 100644 --- a/Devices/lilygo-tdongle-s3/lilygo,tdongle-s3.dts +++ b/Devices/lilygo-tdongle-s3/lilygo,tdongle-s3.dts @@ -19,8 +19,8 @@ compatible = "espressif,esp32-i2c"; port = ; clock-frequency = <400000>; - pin-sda = <44>; - pin-scl = <43>; + pin-sda = <&gpio0 44 GPIO_FLAG_NONE>; + pin-scl = <&gpio0 43 GPIO_FLAG_NONE>; }; spi0 { diff --git a/Devices/lilygo-tlora-pager/lilygo,tlora-pager.dts b/Devices/lilygo-tlora-pager/lilygo,tlora-pager.dts index ade37809..bb39459f 100644 --- a/Devices/lilygo-tlora-pager/lilygo,tlora-pager.dts +++ b/Devices/lilygo-tlora-pager/lilygo,tlora-pager.dts @@ -21,8 +21,8 @@ compatible = "espressif,esp32-i2c"; port = ; clock-frequency = <100000>; - pin-sda = <3>; - pin-scl = <2>; + pin-sda = <&gpio0 3 GPIO_FLAG_NONE>; + pin-scl = <&gpio0 2 GPIO_FLAG_NONE>; }; spi0 { diff --git a/Devices/m5stack-cardputer-adv/m5stack,cardputer-adv.dts b/Devices/m5stack-cardputer-adv/m5stack,cardputer-adv.dts index 41d8db19..d8fe1f4d 100644 --- a/Devices/m5stack-cardputer-adv/m5stack,cardputer-adv.dts +++ b/Devices/m5stack-cardputer-adv/m5stack,cardputer-adv.dts @@ -21,16 +21,16 @@ compatible = "espressif,esp32-i2c"; port = ; clock-frequency = <400000>; - pin-sda = <8>; - pin-scl = <9>; + pin-sda = <&gpio0 8 GPIO_FLAG_NONE>; + pin-scl = <&gpio0 9 GPIO_FLAG_NONE>; }; i2c_port_a { compatible = "espressif,esp32-i2c"; port = ; clock-frequency = <400000>; - pin-sda = <2>; - pin-scl = <1>; + pin-sda = <&gpio0 2 GPIO_FLAG_NONE>; + pin-scl = <&gpio0 1 GPIO_FLAG_NONE>; }; display_spi: spi0 { diff --git a/Devices/m5stack-cardputer/m5stack,cardputer.dts b/Devices/m5stack-cardputer/m5stack,cardputer.dts index 55914b5f..3fa64500 100644 --- a/Devices/m5stack-cardputer/m5stack,cardputer.dts +++ b/Devices/m5stack-cardputer/m5stack,cardputer.dts @@ -21,8 +21,8 @@ compatible = "espressif,esp32-i2c"; port = ; clock-frequency = <400000>; - pin-sda = <2>; - pin-scl = <1>; + pin-sda = <&gpio0 2 GPIO_FLAG_NONE>; + pin-scl = <&gpio0 1 GPIO_FLAG_NONE>; }; display_spi: spi0 { diff --git a/Devices/m5stack-core2/m5stack,core2.dts b/Devices/m5stack-core2/m5stack,core2.dts index b45df25e..15000470 100644 --- a/Devices/m5stack-core2/m5stack,core2.dts +++ b/Devices/m5stack-core2/m5stack,core2.dts @@ -21,16 +21,16 @@ compatible = "espressif,esp32-i2c"; port = ; clock-frequency = <400000>; - pin-sda = <21>; - pin-scl = <22>; + pin-sda = <&gpio0 21 GPIO_FLAG_NONE>; + pin-scl = <&gpio0 22 GPIO_FLAG_NONE>; }; i2c_port_a { compatible = "espressif,esp32-i2c"; port = ; clock-frequency = <400000>; - pin-sda = <32>; - pin-scl = <33>; + pin-sda = <&gpio0 32 GPIO_FLAG_NONE>; + pin-scl = <&gpio0 33 GPIO_FLAG_NONE>; }; spi0 { diff --git a/Devices/m5stack-cores3/m5stack,cores3.dts b/Devices/m5stack-cores3/m5stack,cores3.dts index 0745584b..bba0dfd8 100644 --- a/Devices/m5stack-cores3/m5stack,cores3.dts +++ b/Devices/m5stack-cores3/m5stack,cores3.dts @@ -21,32 +21,32 @@ compatible = "espressif,esp32-i2c"; port = ; clock-frequency = <400000>; - pin-sda = <12>; - pin-scl = <11>; + pin-sda = <&gpio0 12 GPIO_FLAG_NONE>; + pin-scl = <&gpio0 11 GPIO_FLAG_NONE>; }; i2c_port_a { compatible = "espressif,esp32-i2c"; port = ; clock-frequency = <400000>; - pin-sda = <2>; - pin-scl = <1>; + pin-sda = <&gpio0 2 GPIO_FLAG_NONE>; + pin-scl = <&gpio0 1 GPIO_FLAG_NONE>; }; /* i2c_port_b { compatible = "espressif,esp32-i2c"; port = ; clock-frequency = <400000>; - pin-sda = <9>; - pin-scl = <8>; + pin-sda = <&gpio0 9 GPIO_FLAG_NONE>; + pin-scl = <&gpio0 8 GPIO_FLAG_NONE>; }; i2c_port_c { compatible = "espressif,esp32-i2c"; port = ; clock-frequency = <400000>; - pin-sda = <18>; - pin-scl = <17>; + pin-sda = <&gpio0 18 GPIO_FLAG_NONE>; + pin-scl = <&gpio0 17 GPIO_FLAG_NONE>; }; */ spi0 { diff --git a/Devices/m5stack-papers3/m5stack,papers3.dts b/Devices/m5stack-papers3/m5stack,papers3.dts index 6e1ff50f..97a6a515 100644 --- a/Devices/m5stack-papers3/m5stack,papers3.dts +++ b/Devices/m5stack-papers3/m5stack,papers3.dts @@ -18,8 +18,8 @@ compatible = "espressif,esp32-i2c"; port = ; clock-frequency = <400000>; - pin-sda = <41>; - pin-scl = <42>; + pin-sda = <&gpio0 41 GPIO_FLAG_NONE>; + pin-scl = <&gpio0 42 GPIO_FLAG_NONE>; }; spi0 { diff --git a/Devices/m5stack-stickc-plus/m5stack,stickc-plus.dts b/Devices/m5stack-stickc-plus/m5stack,stickc-plus.dts index f50a41d3..854fee71 100644 --- a/Devices/m5stack-stickc-plus/m5stack,stickc-plus.dts +++ b/Devices/m5stack-stickc-plus/m5stack,stickc-plus.dts @@ -19,16 +19,16 @@ compatible = "espressif,esp32-i2c"; port = ; clock-frequency = <400000>; - pin-sda = <21>; - pin-scl = <22>; + pin-sda = <&gpio0 21 GPIO_FLAG_NONE>; + pin-scl = <&gpio0 22 GPIO_FLAG_NONE>; }; i2c_grove { compatible = "espressif,esp32-i2c"; port = ; clock-frequency = <400000>; - pin-sda = <32>; - pin-scl = <33>; + pin-sda = <&gpio0 32 GPIO_FLAG_NONE>; + pin-scl = <&gpio0 33 GPIO_FLAG_NONE>; }; spi0 { diff --git a/Devices/m5stack-stickc-plus2/m5stack,stickc-plus2.dts b/Devices/m5stack-stickc-plus2/m5stack,stickc-plus2.dts index ac7dad3d..dac5c5f5 100644 --- a/Devices/m5stack-stickc-plus2/m5stack,stickc-plus2.dts +++ b/Devices/m5stack-stickc-plus2/m5stack,stickc-plus2.dts @@ -18,16 +18,16 @@ compatible = "espressif,esp32-i2c"; port = ; clock-frequency = <400000>; - pin-sda = <21>; - pin-scl = <22>; + pin-sda = <&gpio0 21 GPIO_FLAG_NONE>; + pin-scl = <&gpio0 22 GPIO_FLAG_NONE>; }; i2c_grove { compatible = "espressif,esp32-i2c"; port = ; clock-frequency = <400000>; - pin-sda = <32>; - pin-scl = <33>; + pin-sda = <&gpio0 32 GPIO_FLAG_NONE>; + pin-scl = <&gpio0 33 GPIO_FLAG_NONE>; }; spi0 { diff --git a/Devices/m5stack-tab5/m5stack,tab5.dts b/Devices/m5stack-tab5/m5stack,tab5.dts index e160e631..dd2064a2 100644 --- a/Devices/m5stack-tab5/m5stack,tab5.dts +++ b/Devices/m5stack-tab5/m5stack,tab5.dts @@ -18,16 +18,16 @@ compatible = "espressif,esp32-i2c"; port = ; clock-frequency = <400000>; - pin-sda = <31>; - pin-scl = <32>; + pin-sda = <&gpio0 31 GPIO_FLAG_NONE>; + pin-scl = <&gpio0 32 GPIO_FLAG_NONE>; }; i2c_port_a { compatible = "espressif,esp32-i2c"; port = ; clock-frequency = <400000>; - pin-sda = <53>; - pin-scl = <54>; + pin-sda = <&gpio0 53 GPIO_FLAG_NONE>; + pin-scl = <&gpio0 54 GPIO_FLAG_NONE>; }; sdcard_spi: spi0 { diff --git a/Devices/unphone/unphone.dts b/Devices/unphone/unphone.dts index 6a4de1df..c717a5d3 100644 --- a/Devices/unphone/unphone.dts +++ b/Devices/unphone/unphone.dts @@ -18,8 +18,8 @@ compatible = "espressif,esp32-i2c"; port = ; clock-frequency = <400000>; - pin-sda = <3>; - pin-scl = <4>; + pin-sda = <&gpio0 3 GPIO_FLAG_NONE>; + pin-scl = <&gpio0 4 GPIO_FLAG_NONE>; }; sdcard_spi: spi0 { diff --git a/Devices/waveshare-esp32-s3-geek/waveshare,esp32-s3-geek.dts b/Devices/waveshare-esp32-s3-geek/waveshare,esp32-s3-geek.dts index 53cc5778..42e2bfd2 100644 --- a/Devices/waveshare-esp32-s3-geek/waveshare,esp32-s3-geek.dts +++ b/Devices/waveshare-esp32-s3-geek/waveshare,esp32-s3-geek.dts @@ -19,8 +19,8 @@ compatible = "espressif,esp32-i2c"; port = ; clock-frequency = <400000>; - pin-sda = <16>; - pin-scl = <17>; + pin-sda = <&gpio0 16 GPIO_FLAG_NONE>; + pin-scl = <&gpio0 17 GPIO_FLAG_NONE>; }; spi0 { diff --git a/Devices/waveshare-s3-lcd-13/waveshare,s3-lcd-13.dts b/Devices/waveshare-s3-lcd-13/waveshare,s3-lcd-13.dts index 4879e6d9..dde80877 100644 --- a/Devices/waveshare-s3-lcd-13/waveshare,s3-lcd-13.dts +++ b/Devices/waveshare-s3-lcd-13/waveshare,s3-lcd-13.dts @@ -19,8 +19,8 @@ compatible = "espressif,esp32-i2c"; port = ; clock-frequency = <400000>; - pin-sda = <47>; - pin-scl = <48>; + pin-sda = <&gpio0 47 GPIO_FLAG_NONE>; + pin-scl = <&gpio0 48 GPIO_FLAG_NONE>; }; spi0 { diff --git a/Devices/waveshare-s3-touch-lcd-128/waveshare,s3-touch-lcd-128.dts b/Devices/waveshare-s3-touch-lcd-128/waveshare,s3-touch-lcd-128.dts index a4a8c1cf..add0b361 100644 --- a/Devices/waveshare-s3-touch-lcd-128/waveshare,s3-touch-lcd-128.dts +++ b/Devices/waveshare-s3-touch-lcd-128/waveshare,s3-touch-lcd-128.dts @@ -19,8 +19,8 @@ compatible = "espressif,esp32-i2c"; port = ; clock-frequency = <400000>; - pin-sda = <6>; - pin-scl = <7>; + pin-sda = <&gpio0 6 GPIO_FLAG_NONE>; + pin-scl = <&gpio0 7 GPIO_FLAG_NONE>; }; display_spi: spi0 { diff --git a/Devices/waveshare-s3-touch-lcd-147/waveshare,s3-touch-lcd-147.dts b/Devices/waveshare-s3-touch-lcd-147/waveshare,s3-touch-lcd-147.dts index cdb67db7..e53c6e44 100644 --- a/Devices/waveshare-s3-touch-lcd-147/waveshare,s3-touch-lcd-147.dts +++ b/Devices/waveshare-s3-touch-lcd-147/waveshare,s3-touch-lcd-147.dts @@ -19,8 +19,8 @@ compatible = "espressif,esp32-i2c"; port = ; clock-frequency = <400000>; - pin-sda = <42>; - pin-scl = <41>; + pin-sda = <&gpio0 42 GPIO_FLAG_NONE>; + pin-scl = <&gpio0 41 GPIO_FLAG_NONE>; }; display_spi: spi0 { diff --git a/Devices/waveshare-s3-touch-lcd-43/waveshare,s3-touch-lcd-43.dts b/Devices/waveshare-s3-touch-lcd-43/waveshare,s3-touch-lcd-43.dts index 957eb36d..817ac91c 100644 --- a/Devices/waveshare-s3-touch-lcd-43/waveshare,s3-touch-lcd-43.dts +++ b/Devices/waveshare-s3-touch-lcd-43/waveshare,s3-touch-lcd-43.dts @@ -19,8 +19,8 @@ compatible = "espressif,esp32-i2c"; port = ; clock-frequency = <400000>; - pin-sda = <8>; - pin-scl = <9>; + pin-sda = <&gpio0 8 GPIO_FLAG_NONE>; + pin-scl = <&gpio0 9 GPIO_FLAG_NONE>; }; spi0 { diff --git a/Devices/wireless-tag-wt32-sc01-plus/wireless-tag,wt32-sc01-plus.dts b/Devices/wireless-tag-wt32-sc01-plus/wireless-tag,wt32-sc01-plus.dts index ca014450..51ef5434 100644 --- a/Devices/wireless-tag-wt32-sc01-plus/wireless-tag,wt32-sc01-plus.dts +++ b/Devices/wireless-tag-wt32-sc01-plus/wireless-tag,wt32-sc01-plus.dts @@ -18,8 +18,8 @@ compatible = "espressif,esp32-i2c"; port = ; clock-frequency = <400000>; - pin-sda = <6>; - pin-scl = <5>; + pin-sda = <&gpio0 6 GPIO_FLAG_NONE>; + pin-scl = <&gpio0 5 GPIO_FLAG_NONE>; }; spi0 { diff --git a/Firmware/CMakeLists.txt b/Firmware/CMakeLists.txt index 2327ea82..82d9c788 100644 --- a/Firmware/CMakeLists.txt +++ b/Firmware/CMakeLists.txt @@ -52,8 +52,10 @@ add_custom_command( OUTPUT "${GENERATED_DIR}/devicetree.c" "${GENERATED_DIR}/devicetree.h" COMMAND pip install lark==1.3.1 pyyaml==6.0.3 + COMMAND echo python "${CMAKE_SOURCE_DIR}/Buildscripts/DevicetreeCompiler/compile.py" + "${DEVICETREE_LOCATION}" "${GENERATED_DIR}" COMMAND python "${CMAKE_SOURCE_DIR}/Buildscripts/DevicetreeCompiler/compile.py" - "${DEVICETREE_LOCATION}" "${GENERATED_DIR}" + "${DEVICETREE_LOCATION}" "${GENERATED_DIR}" WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}" DEPENDS AlwaysRun "${DEVICETREE_LOCATION}/devicetree.yaml" # AlwaysRun ensures it always gets built COMMENT "Generating devicetree source files..." diff --git a/Platforms/PlatformEsp32/Bindings/espressif,esp32-i2c.yaml b/Platforms/PlatformEsp32/Bindings/espressif,esp32-i2c.yaml index fff784b7..a996f831 100644 --- a/Platforms/PlatformEsp32/Bindings/espressif,esp32-i2c.yaml +++ b/Platforms/PlatformEsp32/Bindings/espressif,esp32-i2c.yaml @@ -21,9 +21,3 @@ properties: pin-scl: type: int required: true - pin-sda-pull-up: - type: bool - description: enable internal pull-up resistor for SDA pin - pin-scl-pull-up: - type: bool - description: enable internal pull-up resistor for SCL pin diff --git a/Platforms/PlatformEsp32/Include/tactility/bindings/esp32_gpio.h b/Platforms/PlatformEsp32/Include/tactility/bindings/esp32_gpio.h index 2b09708a..e5efc291 100644 --- a/Platforms/PlatformEsp32/Include/tactility/bindings/esp32_gpio.h +++ b/Platforms/PlatformEsp32/Include/tactility/bindings/esp32_gpio.h @@ -9,6 +9,16 @@ extern "C" { #endif +#define GPIO_ACTIVE_HIGH GPIO_FLAG_ACTIVE_HIGH +#define GPIO_ACTIVE_LOW GPIO_FLAG_ACTIVE_LOW + +#define GPIO_DIRECTION_INPUT GPIO_FLAG_DIRECTION_INPUT +#define GPIO_DIRECTION_OUTPUT GPIO_FLAG_DIRECTION_OUTPUT +#define GPIO_DIRECTION_INPUT_OUTPUT GPIO_FLAG_DIRECTION_INPUT_OUTPUT + +#define GPIO_PULL_UP GPIO_FLAG_PULL_UP +#define GPIO_PULL_DOWN GPIO_FLAG_PULL_DOWN + DEFINE_DEVICETREE(esp32_gpio, struct Esp32GpioConfig) #ifdef __cplusplus diff --git a/Platforms/PlatformEsp32/Include/tactility/drivers/esp32_i2c.h b/Platforms/PlatformEsp32/Include/tactility/drivers/esp32_i2c.h index b754fa96..364198b1 100644 --- a/Platforms/PlatformEsp32/Include/tactility/drivers/esp32_i2c.h +++ b/Platforms/PlatformEsp32/Include/tactility/drivers/esp32_i2c.h @@ -11,13 +11,10 @@ extern "C" { struct Esp32I2cConfig { i2c_port_t port; uint32_t clockFrequency; - gpio_pin_t pinSda; - gpio_pin_t pinScl; - bool pinSdaPullUp; - bool pinSclPullUp; + struct GpioPinSpec pinSda; + struct GpioPinSpec pinScl; }; - #ifdef __cplusplus } #endif diff --git a/Platforms/PlatformEsp32/Source/drivers/esp32_gpio.cpp b/Platforms/PlatformEsp32/Source/drivers/esp32_gpio.cpp index 274d1d99..dd9085ce 100644 --- a/Platforms/PlatformEsp32/Source/drivers/esp32_gpio.cpp +++ b/Platforms/PlatformEsp32/Source/drivers/esp32_gpio.cpp @@ -26,7 +26,7 @@ static error_t get_level(GpioDescriptor* descriptor, bool* high) { return ERROR_NONE; } -static error_t set_options(GpioDescriptor* descriptor, gpio_flags_t options) { +static error_t set_flags(GpioDescriptor* descriptor, gpio_flags_t flags) { const Esp32GpioConfig* config = GET_CONFIG(descriptor->controller); if (descriptor->pin >= config->gpioCount) { @@ -34,11 +34,11 @@ static error_t set_options(GpioDescriptor* descriptor, gpio_flags_t options) { } gpio_mode_t mode; - if ((options & GPIO_DIRECTION_INPUT_OUTPUT) == GPIO_DIRECTION_INPUT_OUTPUT) { + if ((flags & GPIO_FLAG_DIRECTION_INPUT_OUTPUT) == GPIO_FLAG_DIRECTION_INPUT_OUTPUT) { mode = GPIO_MODE_INPUT_OUTPUT; - } else if (options & GPIO_DIRECTION_INPUT) { + } else if (flags & GPIO_FLAG_DIRECTION_INPUT) { mode = GPIO_MODE_INPUT; - } else if (options & GPIO_DIRECTION_OUTPUT) { + } else if (flags & GPIO_FLAG_DIRECTION_OUTPUT) { mode = GPIO_MODE_OUTPUT; } else { return ERROR_INVALID_ARGUMENT; @@ -47,9 +47,9 @@ static error_t set_options(GpioDescriptor* descriptor, gpio_flags_t options) { const gpio_config_t esp_config = { .pin_bit_mask = 1ULL << descriptor->pin, .mode = mode, - .pull_up_en = (options & GPIO_PULL_UP) ? GPIO_PULLUP_ENABLE : GPIO_PULLUP_DISABLE, - .pull_down_en = (options & GPIO_PULL_DOWN) ? GPIO_PULLDOWN_ENABLE : GPIO_PULLDOWN_DISABLE, - .intr_type = GPIO_INTERRUPT_FROM_OPTIONS(options), + .pull_up_en = (flags & GPIO_FLAG_PULL_UP) ? GPIO_PULLUP_ENABLE : GPIO_PULLUP_DISABLE, + .pull_down_en = (flags & GPIO_FLAG_PULL_DOWN) ? GPIO_PULLDOWN_ENABLE : GPIO_PULLDOWN_DISABLE, + .intr_type = GPIO_FLAG_INTERRUPT_FROM_OPTIONS(flags), #if SOC_GPIO_SUPPORT_PIN_HYS_FILTER .hys_ctrl_mode = GPIO_HYS_SOFT_DISABLE #endif @@ -59,7 +59,7 @@ static error_t set_options(GpioDescriptor* descriptor, gpio_flags_t options) { return esp_err_to_error(esp_error); } -static error_t get_options(GpioDescriptor* descriptor, gpio_flags_t* options) { +static error_t get_flags(GpioDescriptor* descriptor, gpio_flags_t* flags) { gpio_io_config_t esp_config; if (gpio_get_io_config(static_cast(descriptor->pin), &esp_config) != ESP_OK) { return ERROR_RESOURCE; @@ -68,32 +68,32 @@ static error_t get_options(GpioDescriptor* descriptor, gpio_flags_t* options) { gpio_flags_t output = 0; if (esp_config.pu) { - output |= GPIO_PULL_UP; + output |= GPIO_FLAG_PULL_UP; } if (esp_config.pd) { - output |= GPIO_PULL_DOWN; + output |= GPIO_FLAG_PULL_DOWN; } if (esp_config.ie) { - output |= GPIO_DIRECTION_INPUT; + output |= GPIO_FLAG_DIRECTION_INPUT; } if (esp_config.oe) { - output |= GPIO_DIRECTION_OUTPUT; + output |= GPIO_FLAG_DIRECTION_OUTPUT; } if (esp_config.oe_inv) { - output |= GPIO_ACTIVE_LOW; + output |= GPIO_FLAG_ACTIVE_LOW; } - *options = output; + *flags = output; return ERROR_NONE; } -static error_t get_pin_number(struct GpioDescriptor* descriptor, gpio_pin_t* pin) { - if (!descriptor) return ERROR_INVALID_ARGUMENT; - *pin = descriptor->pin; +static error_t get_native_pin_number(GpioDescriptor* descriptor, void* pin_number) { + auto* esp_pin_number = static_cast(pin_number); + *esp_pin_number = static_cast(descriptor->pin); return ERROR_NONE; } @@ -109,13 +109,11 @@ static error_t stop(Device* device) { } const static GpioControllerApi esp32_gpio_api = { - .acquire_descriptor = acquire_descriptor, - .release_descriptor = release_descriptor, - .get_pin_number = get_pin_number, .set_level = set_level, .get_level = get_level, - .set_options = set_options, - .get_options = get_options + .set_flags = set_flags, + .get_flags = get_flags, + .get_native_pin_number = get_native_pin_number }; extern struct Module platform_module; diff --git a/Platforms/PlatformEsp32/Source/drivers/esp32_i2c.cpp b/Platforms/PlatformEsp32/Source/drivers/esp32_i2c.cpp index 36186f37..3dd567c7 100644 --- a/Platforms/PlatformEsp32/Source/drivers/esp32_i2c.cpp +++ b/Platforms/PlatformEsp32/Source/drivers/esp32_i2c.cpp @@ -1,21 +1,26 @@ // SPDX-License-Identifier: Apache-2.0 #include -#include -#include -#include - -#include #include +#include +#include +#include #include +#include +#include #define TAG "esp32_i2c" #define ACK_CHECK_EN 1 struct Esp32SpiInternal { Mutex mutex { 0 }; + GpioDescriptor* sda_descriptor = nullptr; + GpioDescriptor* scl_descriptor = nullptr; - Esp32SpiInternal() { + Esp32SpiInternal(GpioDescriptor* sda_descriptor, GpioDescriptor* scl_descriptor) : + sda_descriptor(sda_descriptor), + scl_descriptor(scl_descriptor) + { mutex_construct(&mutex); } @@ -149,12 +154,35 @@ static error_t start(Device* device) { ESP_LOGI(TAG, "start %s", device->name); auto dts_config = GET_CONFIG(device); + auto& sda_spec = dts_config->pinSda; + auto& scl_spec = dts_config->pinScl; + auto* sda_descriptor = gpio_descriptor_acquire(sda_spec.gpio_controller, sda_spec.pin, GPIO_OWNER_GPIO); + if (!sda_descriptor) { + LOG_E(TAG, "Failed to acquire pin %u", sda_spec.pin); + return ERROR_RESOURCE; + } + + auto* scl_descriptor = gpio_descriptor_acquire(scl_spec.gpio_controller, scl_spec.pin, GPIO_OWNER_GPIO); + if (!scl_descriptor) { + LOG_E(TAG, "Failed to acquire pin %u", sda_spec.pin); + gpio_descriptor_release(sda_descriptor); + return ERROR_RESOURCE; + } + + gpio_num_t sda_pin, scl_pin; + check(gpio_descriptor_get_native_pin_number(sda_descriptor, &sda_pin) == ERROR_NONE); + check(gpio_descriptor_get_native_pin_number(scl_descriptor, &scl_pin) == ERROR_NONE); + + gpio_flags_t sda_flags, scl_flags;; + check(gpio_descriptor_get_flags(sda_descriptor, &sda_flags) == ERROR_NONE); + check(gpio_descriptor_get_flags(scl_descriptor, &scl_flags) == ERROR_NONE); + i2c_config_t esp_config = { .mode = I2C_MODE_MASTER, - .sda_io_num = dts_config->pinSda, - .scl_io_num = dts_config->pinScl, - .sda_pullup_en = dts_config->pinSdaPullUp, - .scl_pullup_en = dts_config->pinSclPullUp, + .sda_io_num = sda_pin, + .scl_io_num = scl_pin, + .sda_pullup_en = (sda_flags & GPIO_FLAG_PULL_UP) != 0, + .scl_pullup_en = (scl_flags & GPIO_FLAG_PULL_UP) != 0, .master { .clk_speed = dts_config->clockFrequency }, @@ -172,7 +200,9 @@ static error_t start(Device* device) { LOG_E(TAG, "Failed to install driver at port %d: %s", static_cast(dts_config->port), esp_err_to_name(error)); return ERROR_RESOURCE; } - auto* data = new Esp32SpiInternal(); + + auto* data = new Esp32SpiInternal(sda_descriptor, scl_descriptor); + device_set_driver_data(device, data); return ERROR_NONE; } @@ -188,6 +218,9 @@ static error_t stop(Device* device) { return ERROR_RESOURCE; } + check(gpio_descriptor_release(driver_data->sda_descriptor) == ERROR_NONE); + check(gpio_descriptor_release(driver_data->scl_descriptor) == ERROR_NONE); + device_set_driver_data(device, nullptr); delete driver_data; return ERROR_NONE; diff --git a/Platforms/PlatformEsp32/Source/drivers/esp32_spi.cpp b/Platforms/PlatformEsp32/Source/drivers/esp32_spi.cpp index e1982eb7..54266711 100644 --- a/Platforms/PlatformEsp32/Source/drivers/esp32_spi.cpp +++ b/Platforms/PlatformEsp32/Source/drivers/esp32_spi.cpp @@ -3,6 +3,7 @@ #include #include +#include "tactility/drivers/gpio_descriptor.h" #include #include #include @@ -19,7 +20,7 @@ struct Esp32SpiInternal { RecursiveMutex mutex = {}; bool initialized = false; - Esp32SpiInternal() { + Esp32SpiInternal(GpioDescriptor* pDescriptor, GpioDescriptor* pGpioDescriptor) { recursive_mutex_construct(&mutex); } @@ -50,7 +51,7 @@ static error_t unlock(Device* device) { static error_t start(Device* device) { ESP_LOGI(TAG, "start %s", device->name); - auto* data = new(std::nothrow) Esp32SpiInternal(); + auto* data = new (std::nothrow) Esp32SpiInternal(nullptr, nullptr); if (!data) return ERROR_OUT_OF_MEMORY; device_set_driver_data(device, data); diff --git a/TactilityC/Source/tt_init.cpp b/TactilityC/Source/tt_init.cpp index 27e63a4d..8a56c17b 100644 --- a/TactilityC/Source/tt_init.cpp +++ b/TactilityC/Source/tt_init.cpp @@ -53,6 +53,7 @@ #include #include +#include extern "C" { @@ -374,7 +375,11 @@ const esp_elfsym main_symbols[] { ESP_ELFSYM_EXPORT(esp_netif_get_handle_from_ifkey), // Locale ESP_ELFSYM_EXPORT(localeconv), - //i2s_common.h + // driver/gpio.h + ESP_ELFSYM_EXPORT(gpio_config), + ESP_ELFSYM_EXPORT(gpio_get_level), + ESP_ELFSYM_EXPORT(gpio_set_level), + // driver/i2s_common.h ESP_ELFSYM_EXPORT(i2s_new_channel), ESP_ELFSYM_EXPORT(i2s_del_channel), ESP_ELFSYM_EXPORT(i2s_channel_enable), @@ -385,7 +390,7 @@ const esp_elfsym main_symbols[] { ESP_ELFSYM_EXPORT(i2s_channel_register_event_callback), ESP_ELFSYM_EXPORT(i2s_channel_preload_data), ESP_ELFSYM_EXPORT(i2s_channel_tune_rate), - //i2s_std.h + // driver/i2s_std.h ESP_ELFSYM_EXPORT(i2s_channel_init_std_mode), ESP_ELFSYM_EXPORT(i2s_channel_reconfig_std_clock), ESP_ELFSYM_EXPORT(i2s_channel_reconfig_std_slot), diff --git a/TactilityKernel/Include/tactility/drivers/gpio.h b/TactilityKernel/Include/tactility/drivers/gpio.h index 8ac772f6..9a408cd7 100644 --- a/TactilityKernel/Include/tactility/drivers/gpio.h +++ b/TactilityKernel/Include/tactility/drivers/gpio.h @@ -10,21 +10,22 @@ extern "C" { #include #include -#define GPIO_OPTIONS_MASK 0x1f +#define GPIO_FLAGS_MASK 0x1f -#define GPIO_ACTIVE_HIGH (0 << 0) -#define GPIO_ACTIVE_LOW (1 << 0) +#define GPIO_FLAG_NONE 0 +#define GPIO_FLAG_ACTIVE_HIGH (0 << 0) +#define GPIO_FLAG_ACTIVE_LOW (1 << 0) -#define GPIO_DIRECTION_INPUT (1 << 1) -#define GPIO_DIRECTION_OUTPUT (1 << 2) -#define GPIO_DIRECTION_INPUT_OUTPUT (GPIO_DIRECTION_INPUT | GPIO_DIRECTION_OUTPUT) +#define GPIO_FLAG_DIRECTION_INPUT (1 << 1) +#define GPIO_FLAG_DIRECTION_OUTPUT (1 << 2) +#define GPIO_FLAG_DIRECTION_INPUT_OUTPUT (GPIO_FLAG_DIRECTION_INPUT | GPIO_FLAG_DIRECTION_OUTPUT) -#define GPIO_PULL_UP (0 << 3) -#define GPIO_PULL_DOWN (1 << 4) +#define GPIO_FLAG_PULL_UP (0 << 3) +#define GPIO_FLAG_PULL_DOWN (1 << 4) -#define GPIO_INTERRUPT_BITMASK (0b111 << 5) // 3 bits to hold the values [0, 5] -#define GPIO_INTERRUPT_FROM_OPTIONS(options) (gpio_int_type_t)((options & GPIO_INTERRUPT_BITMASK) >> 5) -#define GPIO_INTERRUPT_TO_OPTIONS(options, interrupt) (options | (interrupt << 5)) +#define GPIO_FLAG_INTERRUPT_BITMASK (0b111 << 5) // 3 bits to hold the values [0, 5] +#define GPIO_FLAG_INTERRUPT_FROM_OPTIONS(options) (gpio_int_type_t)((options & GPIO_FLAG_INTERRUPT_BITMASK) >> 5) +#define GPIO_FLAG_INTERRUPT_TO_OPTIONS(options, interrupt) (options | (interrupt << 5)) #define GPIO_PIN_NONE -1 @@ -35,7 +36,7 @@ typedef enum { GPIO_INTERRUPT_ANY_EDGE = 3, GPIO_INTERRUPT_LOW_LEVEL = 4, GPIO_INTERRUPT_HIGH_LEVEL = 5, - GPIO__MAX, + GPIO_MAX, } GpioInterruptType; enum GpioOwnerType { @@ -55,28 +56,19 @@ typedef uint8_t gpio_pin_t; /** Specifies the configuration flags for a GPIO pin (or set of pins) */ typedef uint16_t gpio_flags_t; -typedef uint8_t gpio_level_t; - -/** A configuration for a single GPIO pin */ -struct GpioPinConfig { +/** + * Specifies a pin and its properties for a specific GPIO controller. + * Used by the devicetree, drivers and application code to refer to GPIO pins and acquire them via the gpio_controller API. + */ +struct GpioPinSpec { /** GPIO device controlling the pin */ - const struct Device* port; + struct Device* gpio_controller; /** The pin's number on the device */ gpio_pin_t pin; /** The pin's configuration flags as specified in devicetree */ gpio_flags_t flags; }; -/** - * Check if the pin is ready to be used. - * - * @param pinConfig the specifications of the pin - * @return true if the pin is ready to be used - */ -static inline bool gpio_is_ready(const struct GpioPinConfig* pinConfig) { - return device_is_ready(pinConfig->port); -} - #ifdef __cplusplus } #endif diff --git a/TactilityKernel/Include/tactility/drivers/gpio_controller.h b/TactilityKernel/Include/tactility/drivers/gpio_controller.h index 674eb323..1b3e5170 100644 --- a/TactilityKernel/Include/tactility/drivers/gpio_controller.h +++ b/TactilityKernel/Include/tactility/drivers/gpio_controller.h @@ -10,25 +10,9 @@ extern "C" { #include struct Device; +struct GpioDescriptor; struct GpioControllerApi { - struct GpioDescriptor* (*acquire_descriptor)( - struct Device* controller, - gpio_pin_t pin_number, - enum GpioOwnerType owner, - void* owner_context - ); - - error_t (*release_descriptor)(struct GpioDescriptor* descriptor); - - /** - * @brief Gets the pin number associated with a descriptor. - * @param[in] descriptor the pin descriptor - * @param[out] pin pointer to store the pin number - * @return ERROR_NONE if successful - */ - error_t (*get_pin_number)(struct GpioDescriptor* descriptor, gpio_pin_t* pin); - /** * @brief Sets the logical level of a GPIO pin. * @param[in,out] descriptor the pin descriptor @@ -51,7 +35,7 @@ struct GpioControllerApi { * @param[in] options configuration flags (direction, pull-up/down, etc.) * @return ERROR_NONE if successful */ - error_t (*set_options)(struct GpioDescriptor* descriptor, gpio_flags_t options); + error_t (*set_flags)(struct GpioDescriptor* descriptor, gpio_flags_t flags); /** * @brief Gets the configuration options for a GPIO pin. @@ -59,25 +43,24 @@ struct GpioControllerApi { * @param[out] options pointer to store the configuration flags * @return ERROR_NONE if successful */ - error_t (*get_options)(struct GpioDescriptor* descriptor, gpio_flags_t* options); + error_t (*get_flags)(struct GpioDescriptor* descriptor, gpio_flags_t* flags); + + /** + * @brief Gets the native pin number associated with a descriptor. + * @param[in] descriptor the pin descriptor + * @param[out] pin_number pointer to store the pin number + * @return ERROR_NONE if successful + */ + error_t (*get_native_pin_number)(struct GpioDescriptor* descriptor, void* pin_number); }; -struct GpioDescriptor* acquire_descriptor( +struct GpioDescriptor* gpio_descriptor_acquire( struct Device* controller, gpio_pin_t pin_number, - enum GpioOwnerType owner, - void* owner_context + enum GpioOwnerType owner ); -error_t release_descriptor(struct GpioDescriptor* descriptor); - -/** - * @brief Gets the number of pins supported by the controller. - * @param[in] device the GPIO controller device - * @param[out] count pointer to store the number of pins - * @return ERROR_NONE if successful - */ -error_t gpio_controller_get_pin_count(struct Device* device, uint32_t* count); +error_t gpio_descriptor_release(struct GpioDescriptor* descriptor); /** * @brief Gets the pin number associated with a descriptor. @@ -85,7 +68,15 @@ error_t gpio_controller_get_pin_count(struct Device* device, uint32_t* count); * @param[out] pin pointer to store the pin number * @return ERROR_NONE if successful */ -error_t gpio_descriptor_pin_number(struct GpioDescriptor* descriptor, gpio_pin_t* pin); +error_t gpio_descriptor_get_pin_number(struct GpioDescriptor* descriptor, gpio_pin_t* pin); + +/** + * @brief Gets the pin owner type associated with a descriptor. + * @param[in] descriptor the pin descriptor + * @param[out] owner_type pointer to output owner type + * @return ERROR_NONE if successful + */ +error_t gpio_descriptor_get_owner_type(struct GpioDescriptor* descriptor, enum GpioOwnerType* owner_type); /** * @brief Sets the logical level of a GPIO pin. @@ -106,26 +97,42 @@ error_t gpio_descriptor_get_level(struct GpioDescriptor* descriptor, bool* high) /** * @brief Configures the options for a GPIO pin. * @param[in] descriptor the pin descriptor - * @param[in] options configuration flags (direction, pull-up/down, etc.) + * @param[in] flags configuration flags (direction, pull-up/down, etc.) * @return ERROR_NONE if successful */ -error_t gpio_descriptor_set_options(struct GpioDescriptor* descriptor, gpio_flags_t options); +error_t gpio_descriptor_set_flags(struct GpioDescriptor* descriptor, gpio_flags_t flags); /** * @brief Gets the configuration options for a GPIO pin. * @param[in] descriptor the pin descriptor - * @param[out] options pointer to store the configuration flags + * @param[out] flags pointer to store the configuration flags * @return ERROR_NONE if successful */ -error_t gpio_descriptor_get_options(struct GpioDescriptor* descriptor, gpio_flags_t* options); +error_t gpio_descriptor_get_flags(struct GpioDescriptor* descriptor, gpio_flags_t* flags); + +/** + * @brief Gets the native pin number associated with a descriptor. + * @param[in] descriptor the pin descriptor + * @param[out] pin_number pointer to store the pin number + * @return ERROR_NONE if successful + */ +error_t gpio_descriptor_get_native_pin_number(struct GpioDescriptor* descriptor, void* pin_number); + +/** + * @brief Gets the number of pins supported by the controller. + * @param[in] device the GPIO controller device + * @param[out] count pointer to store the number of pins + * @return ERROR_NONE if successful + */ +error_t gpio_controller_get_pin_count(struct Device* device, uint32_t* count); /** * @brief Initializes GPIO descriptors for a controller. * @param[in,out] device the GPIO controller device - * @param[in] owner_data pointer to store in the descriptor's owner_data field + * @param[in] controller_context pointer to store in the controller's internal data * @return ERROR_NONE if successful */ -error_t gpio_controller_init_descriptors(struct Device* device, uint32_t pin_count, void* owner_data); +error_t gpio_controller_init_descriptors(struct Device* device, uint32_t pin_count, void* controller_context); /** * @brief Deinitializes GPIO descriptors for a controller. diff --git a/TactilityKernel/Include/tactility/drivers/gpio_descriptor.h b/TactilityKernel/Include/tactility/drivers/gpio_descriptor.h index 2f972c97..f7dfeb79 100644 --- a/TactilityKernel/Include/tactility/drivers/gpio_descriptor.h +++ b/TactilityKernel/Include/tactility/drivers/gpio_descriptor.h @@ -9,12 +9,6 @@ struct GpioDescriptor { gpio_pin_t pin; /** @brief Current owner */ enum GpioOwnerType owner_type; - /** @brief Owner identity for validation */ - void* owner_context; - /** @brief Pin level */ - gpio_level_t level; - /** @brief Pin configuration flags */ - gpio_flags_t flags; /** @brief Implementation-specific context (e.g. from esp32 controller internally) */ void* controller_context; }; diff --git a/TactilityKernel/Source/drivers/gpio_controller.cpp b/TactilityKernel/Source/drivers/gpio_controller.cpp index 9ddba628..72572cd7 100644 --- a/TactilityKernel/Source/drivers/gpio_controller.cpp +++ b/TactilityKernel/Source/drivers/gpio_controller.cpp @@ -6,21 +6,41 @@ #include #include +#include +#include + #define GPIO_INTERNAL_API(driver) ((struct GpioControllerApi*)driver->api) extern "C" { struct GpioControllerData { - struct Mutex mutex; + struct Mutex mutex {}; uint32_t pin_count; struct GpioDescriptor* descriptors; + + explicit GpioControllerData(Device* device, uint32_t pin_count, void* controller_context) : pin_count(pin_count) { + mutex_construct(&mutex); + descriptors = (struct GpioDescriptor*)calloc(pin_count, sizeof(struct GpioDescriptor)); + check(descriptors); + + for (uint32_t i = 0; i < pin_count; ++i) { + descriptors[i].controller = device; + descriptors[i].pin = (gpio_pin_t)i; + descriptors[i].owner_type = GPIO_OWNER_NONE; + descriptors[i].controller_context = controller_context; + } + } + + ~GpioControllerData() { + free(descriptors); + mutex_destruct(&mutex); + } }; -struct GpioDescriptor* acquire_descriptor( +struct GpioDescriptor* gpio_descriptor_acquire( struct Device* controller, gpio_pin_t pin_number, - enum GpioOwnerType owner, - void* owner_context + enum GpioOwnerType owner ) { auto* data = (struct GpioControllerData*)device_get_driver_data(controller); @@ -37,15 +57,13 @@ struct GpioDescriptor* acquire_descriptor( } desc->owner_type = owner; - desc->owner_context = owner_context; mutex_unlock(&data->mutex); return desc; } -error_t release_descriptor(struct GpioDescriptor* descriptor) { +error_t gpio_descriptor_release(struct GpioDescriptor* descriptor) { descriptor->owner_type = GPIO_OWNER_NONE; - descriptor->owner_context = nullptr; return ERROR_NONE; } @@ -56,37 +74,16 @@ error_t gpio_controller_get_pin_count(struct Device* device, uint32_t* count) { } error_t gpio_controller_init_descriptors(struct Device* device, uint32_t pin_count, void* controller_context) { - auto* data = (struct GpioControllerData*)malloc(sizeof(struct GpioControllerData)); + auto* data = new(std::nothrow) GpioControllerData(device, pin_count, controller_context); if (!data) return ERROR_OUT_OF_MEMORY; - - data->pin_count = pin_count; - data->descriptors = (struct GpioDescriptor*)calloc(pin_count, sizeof(struct GpioDescriptor)); - if (!data->descriptors) { - free(data); - return ERROR_OUT_OF_MEMORY; - } - - for (uint32_t i = 0; i < pin_count; ++i) { - data->descriptors[i].controller = device; - data->descriptors[i].pin = (gpio_pin_t)i; - data->descriptors[i].owner_type = GPIO_OWNER_NONE; - data->descriptors[i].controller_context = controller_context; - } - - mutex_construct(&data->mutex); device_set_driver_data(device, data); - return ERROR_NONE; } error_t gpio_controller_deinit_descriptors(struct Device* device) { - auto* data = (struct GpioControllerData*)device_get_driver_data(device); - - free(data->descriptors); - mutex_destruct(&data->mutex); - free(data); + auto* data = static_cast(device_get_driver_data(device)); + delete data; device_set_driver_data(device, nullptr); - return ERROR_NONE; } @@ -100,19 +97,29 @@ error_t gpio_descriptor_get_level(struct GpioDescriptor* descriptor, bool* high) return GPIO_INTERNAL_API(driver)->get_level(descriptor, high); } -error_t gpio_descriptor_set_options(struct GpioDescriptor* descriptor, gpio_flags_t options) { +error_t gpio_descriptor_set_flags(struct GpioDescriptor* descriptor, gpio_flags_t flags) { const auto* driver = device_get_driver(descriptor->controller); - return GPIO_INTERNAL_API(driver)->set_options(descriptor, options); + return GPIO_INTERNAL_API(driver)->set_flags(descriptor, flags); } -error_t gpio_descriptor_get_options(struct GpioDescriptor* descriptor, gpio_flags_t* options) { +error_t gpio_descriptor_get_flags(struct GpioDescriptor* descriptor, gpio_flags_t* flags) { const auto* driver = device_get_driver(descriptor->controller); - return GPIO_INTERNAL_API(driver)->get_options(descriptor, options); + return GPIO_INTERNAL_API(driver)->get_flags(descriptor, flags); } error_t gpio_descriptor_get_pin_number(struct GpioDescriptor* descriptor, gpio_pin_t* pin) { + *pin = descriptor->pin; + return ERROR_NONE; +} + +error_t gpio_descriptor_get_native_pin_number(struct GpioDescriptor* descriptor, void* pin_number) { const auto* driver = device_get_driver(descriptor->controller); - return GPIO_INTERNAL_API(driver)->get_pin_number(descriptor, pin); + return GPIO_INTERNAL_API(driver)->get_native_pin_number(descriptor, pin_number); +} + +error_t gpio_descriptor_get_owner_type(struct GpioDescriptor* descriptor, GpioOwnerType* owner_type) { + *owner_type = descriptor->owner_type; + return ERROR_NONE; } const struct DeviceType GPIO_CONTROLLER_TYPE { diff --git a/TactilityKernel/Source/kernel_symbols.c b/TactilityKernel/Source/kernel_symbols.c index 8d1a1aec..904fbb2c 100644 --- a/TactilityKernel/Source/kernel_symbols.c +++ b/TactilityKernel/Source/kernel_symbols.c @@ -59,10 +59,15 @@ const struct ModuleSymbol KERNEL_SYMBOLS[] = { DEFINE_MODULE_SYMBOL(driver_find_compatible), DEFINE_MODULE_SYMBOL(driver_get_device_type), // drivers/gpio_controller + DEFINE_MODULE_SYMBOL(gpio_descriptor_acquire), + DEFINE_MODULE_SYMBOL(gpio_descriptor_release), DEFINE_MODULE_SYMBOL(gpio_descriptor_set_level), DEFINE_MODULE_SYMBOL(gpio_descriptor_get_level), - DEFINE_MODULE_SYMBOL(gpio_descriptor_set_options), - DEFINE_MODULE_SYMBOL(gpio_descriptor_get_options), + DEFINE_MODULE_SYMBOL(gpio_descriptor_set_flags), + DEFINE_MODULE_SYMBOL(gpio_descriptor_get_flags), + DEFINE_MODULE_SYMBOL(gpio_descriptor_get_native_pin_number), + DEFINE_MODULE_SYMBOL(gpio_descriptor_get_pin_number), + DEFINE_MODULE_SYMBOL(gpio_descriptor_get_owner_type), DEFINE_MODULE_SYMBOL(gpio_controller_get_pin_count), DEFINE_MODULE_SYMBOL(gpio_controller_init_descriptors), DEFINE_MODULE_SYMBOL(gpio_controller_deinit_descriptors),