mirror of
https://github.com/ByteWelder/Tactility.git
synced 2026-02-18 10:53:17 +00:00
GPIO driver with pin ownership, updated I2C driver
This commit is contained in:
parent
0569c6df1e
commit
d9a39726d1
@ -18,15 +18,15 @@
|
||||
compatible = "espressif,esp32-i2c";
|
||||
port = <I2C_NUM_0>;
|
||||
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 = <I2C_NUM_1>;
|
||||
clock-frequency = <400000>;
|
||||
pin-sda = <4>;
|
||||
pin-scl = <3>;
|
||||
pin-sda = <&gpio0 4 GPIO_FLAG_NONE>;
|
||||
pin-scl = <&gpio0 3 GPIO_FLAG_NONE>;
|
||||
};
|
||||
};
|
||||
|
||||
@ -18,8 +18,8 @@
|
||||
compatible = "espressif,esp32-i2c";
|
||||
port = <I2C_NUM_0>;
|
||||
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 {
|
||||
|
||||
@ -19,8 +19,8 @@
|
||||
compatible = "espressif,esp32-i2c";
|
||||
port = <I2C_NUM_0>;
|
||||
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 {
|
||||
|
||||
@ -19,8 +19,8 @@
|
||||
compatible = "espressif,esp32-i2c";
|
||||
port = <I2C_NUM_0>;
|
||||
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 {
|
||||
|
||||
@ -18,8 +18,8 @@
|
||||
compatible = "espressif,esp32-i2c";
|
||||
port = <I2C_NUM_0>;
|
||||
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 {
|
||||
|
||||
@ -18,8 +18,8 @@
|
||||
compatible = "espressif,esp32-i2c";
|
||||
port = <I2C_NUM_0>;
|
||||
clock-frequency = <400000>;
|
||||
pin-sda = <19>;
|
||||
pin-scl = <45>;
|
||||
pin-sda = <&gpio0 19 GPIO_FLAG_NONE>;
|
||||
pin-scl = <&gpio0 45 GPIO_FLAG_NONE>;
|
||||
};
|
||||
|
||||
spi0 {
|
||||
|
||||
@ -19,16 +19,16 @@
|
||||
compatible = "espressif,esp32-i2c";
|
||||
port = <I2C_NUM_0>;
|
||||
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 = <I2C_NUM_1>;
|
||||
clock-frequency = <400000>;
|
||||
pin-sda = <17>;
|
||||
pin-scl = <18>;
|
||||
pin-sda = <&gpio0 17 GPIO_FLAG_NONE>;
|
||||
pin-scl = <&gpio0 18 GPIO_FLAG_NONE>;
|
||||
};
|
||||
|
||||
spi0 {
|
||||
|
||||
@ -18,8 +18,8 @@
|
||||
compatible = "espressif,esp32-i2c";
|
||||
port = <I2C_NUM_0>;
|
||||
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 {
|
||||
|
||||
@ -19,8 +19,8 @@
|
||||
compatible = "espressif,esp32-i2c";
|
||||
port = <I2C_NUM_0>;
|
||||
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 {
|
||||
|
||||
@ -19,8 +19,8 @@
|
||||
compatible = "espressif,esp32-i2c";
|
||||
port = <I2C_NUM_0>;
|
||||
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 {
|
||||
|
||||
@ -19,8 +19,8 @@
|
||||
compatible = "espressif,esp32-i2c";
|
||||
port = <I2C_NUM_0>;
|
||||
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 {
|
||||
|
||||
@ -19,8 +19,8 @@
|
||||
compatible = "espressif,esp32-i2c";
|
||||
port = <I2C_NUM_0>;
|
||||
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 {
|
||||
|
||||
@ -19,8 +19,8 @@
|
||||
compatible = "espressif,esp32-i2c";
|
||||
port = <I2C_NUM_0>;
|
||||
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 {
|
||||
|
||||
@ -19,8 +19,8 @@
|
||||
compatible = "espressif,esp32-i2c";
|
||||
port = <I2C_NUM_0>;
|
||||
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 {
|
||||
|
||||
@ -26,8 +26,8 @@
|
||||
compatible = "espressif,esp32-i2c";
|
||||
port = <I2C_NUM_0>;
|
||||
clock-frequency = <400000>;
|
||||
pin-sda = <7>;
|
||||
pin-scl = <8>;
|
||||
pin-sda = <&gpio0 7 GPIO_FLAG_NONE>;
|
||||
pin-scl = <&gpio0 8 GPIO_FLAG_NONE>;
|
||||
};
|
||||
|
||||
i2s0 {
|
||||
|
||||
@ -19,8 +19,8 @@
|
||||
compatible = "espressif,esp32-i2c";
|
||||
port = <I2C_NUM_0>;
|
||||
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 = <I2C_NUM_1>;
|
||||
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 {
|
||||
|
||||
@ -19,16 +19,16 @@
|
||||
compatible = "espressif,esp32-i2c";
|
||||
port = <I2C_NUM_0>;
|
||||
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 = <I2C_NUM_1>;
|
||||
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 {
|
||||
|
||||
@ -19,16 +19,16 @@
|
||||
compatible = "espressif,esp32-i2c";
|
||||
port = <I2C_NUM_0>;
|
||||
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 = <I2C_NUM_1>;
|
||||
clock-frequency = <400000>;
|
||||
pin-sda = <17>;
|
||||
pin-scl = <18>;
|
||||
pin-sda = <&gpio0 17 GPIO_FLAG_NONE>;
|
||||
pin-scl = <&gpio0 18 GPIO_FLAG_NONE>;
|
||||
};
|
||||
|
||||
spi0 {
|
||||
|
||||
@ -17,7 +17,7 @@
|
||||
compatible = "espressif,esp32-i2c";
|
||||
port = <I2C_NUM_0>;
|
||||
clock-frequency = <200000>;
|
||||
pin-sda = <17>;
|
||||
pin-scl = <18>;
|
||||
pin-sda = <&gpio0 17 GPIO_FLAG_NONE>;
|
||||
pin-scl = <&gpio0 18 GPIO_FLAG_NONE>;
|
||||
};
|
||||
};
|
||||
|
||||
@ -21,16 +21,16 @@
|
||||
compatible = "espressif,esp32-i2c";
|
||||
port = <I2C_NUM_0>;
|
||||
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 = <I2C_NUM_1>;
|
||||
clock-frequency = <400000>;
|
||||
pin-sda = <43>;
|
||||
pin-scl = <44>;
|
||||
pin-sda = <&gpio0 43 GPIO_FLAG_NONE>;
|
||||
pin-scl = <&gpio0 44 GPIO_FLAG_NONE>;
|
||||
};
|
||||
|
||||
i2s0 {
|
||||
|
||||
@ -17,7 +17,7 @@
|
||||
spi0 {
|
||||
compatible = "espressif,esp32-spi";
|
||||
host = <SPI2_HOST>;
|
||||
pin-mosi = <7>;
|
||||
pin-sclk = <6>;
|
||||
pin-mosi = <&gpio0 7 GPIO_FLAG_NONE>;
|
||||
pin-sclk = <&gpio0 6 GPIO_FLAG_NONE>;
|
||||
};
|
||||
};
|
||||
|
||||
@ -17,7 +17,7 @@
|
||||
spi0 {
|
||||
compatible = "espressif,esp32-spi";
|
||||
host = <SPI2_HOST>;
|
||||
pin-mosi = <19>;
|
||||
pin-sclk = <18>;
|
||||
pin-mosi = <&gpio0 19 GPIO_FLAG_NONE>;
|
||||
pin-sclk = <&gpio0 18 GPIO_FLAG_NONE>;
|
||||
};
|
||||
};
|
||||
|
||||
@ -19,8 +19,8 @@
|
||||
compatible = "espressif,esp32-i2c";
|
||||
port = <I2C_NUM_0>;
|
||||
clock-frequency = <400000>;
|
||||
pin-sda = <44>;
|
||||
pin-scl = <43>;
|
||||
pin-sda = <&gpio0 44 GPIO_FLAG_NONE>;
|
||||
pin-scl = <&gpio0 43 GPIO_FLAG_NONE>;
|
||||
};
|
||||
|
||||
spi0 {
|
||||
|
||||
@ -21,8 +21,8 @@
|
||||
compatible = "espressif,esp32-i2c";
|
||||
port = <I2C_NUM_0>;
|
||||
clock-frequency = <100000>;
|
||||
pin-sda = <3>;
|
||||
pin-scl = <2>;
|
||||
pin-sda = <&gpio0 3 GPIO_FLAG_NONE>;
|
||||
pin-scl = <&gpio0 2 GPIO_FLAG_NONE>;
|
||||
};
|
||||
|
||||
spi0 {
|
||||
|
||||
@ -21,16 +21,16 @@
|
||||
compatible = "espressif,esp32-i2c";
|
||||
port = <I2C_NUM_0>;
|
||||
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 = <I2C_NUM_1>;
|
||||
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 {
|
||||
|
||||
@ -21,8 +21,8 @@
|
||||
compatible = "espressif,esp32-i2c";
|
||||
port = <I2C_NUM_0>;
|
||||
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 {
|
||||
|
||||
@ -21,16 +21,16 @@
|
||||
compatible = "espressif,esp32-i2c";
|
||||
port = <I2C_NUM_0>;
|
||||
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 = <I2C_NUM_1>;
|
||||
clock-frequency = <400000>;
|
||||
pin-sda = <32>;
|
||||
pin-scl = <33>;
|
||||
pin-sda = <&gpio0 32 GPIO_FLAG_NONE>;
|
||||
pin-scl = <&gpio0 33 GPIO_FLAG_NONE>;
|
||||
};
|
||||
|
||||
spi0 {
|
||||
|
||||
@ -21,32 +21,32 @@
|
||||
compatible = "espressif,esp32-i2c";
|
||||
port = <I2C_NUM_0>;
|
||||
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 = <I2C_NUM_1>;
|
||||
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 = <I2C_NUM_1>;
|
||||
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 = <I2C_NUM_1>;
|
||||
clock-frequency = <400000>;
|
||||
pin-sda = <18>;
|
||||
pin-scl = <17>;
|
||||
pin-sda = <&gpio0 18 GPIO_FLAG_NONE>;
|
||||
pin-scl = <&gpio0 17 GPIO_FLAG_NONE>;
|
||||
};
|
||||
*/
|
||||
spi0 {
|
||||
|
||||
@ -18,8 +18,8 @@
|
||||
compatible = "espressif,esp32-i2c";
|
||||
port = <I2C_NUM_0>;
|
||||
clock-frequency = <400000>;
|
||||
pin-sda = <41>;
|
||||
pin-scl = <42>;
|
||||
pin-sda = <&gpio0 41 GPIO_FLAG_NONE>;
|
||||
pin-scl = <&gpio0 42 GPIO_FLAG_NONE>;
|
||||
};
|
||||
|
||||
spi0 {
|
||||
|
||||
@ -19,16 +19,16 @@
|
||||
compatible = "espressif,esp32-i2c";
|
||||
port = <I2C_NUM_0>;
|
||||
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 = <I2C_NUM_1>;
|
||||
clock-frequency = <400000>;
|
||||
pin-sda = <32>;
|
||||
pin-scl = <33>;
|
||||
pin-sda = <&gpio0 32 GPIO_FLAG_NONE>;
|
||||
pin-scl = <&gpio0 33 GPIO_FLAG_NONE>;
|
||||
};
|
||||
|
||||
spi0 {
|
||||
|
||||
@ -18,16 +18,16 @@
|
||||
compatible = "espressif,esp32-i2c";
|
||||
port = <I2C_NUM_0>;
|
||||
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 = <I2C_NUM_1>;
|
||||
clock-frequency = <400000>;
|
||||
pin-sda = <32>;
|
||||
pin-scl = <33>;
|
||||
pin-sda = <&gpio0 32 GPIO_FLAG_NONE>;
|
||||
pin-scl = <&gpio0 33 GPIO_FLAG_NONE>;
|
||||
};
|
||||
|
||||
spi0 {
|
||||
|
||||
@ -18,16 +18,16 @@
|
||||
compatible = "espressif,esp32-i2c";
|
||||
port = <I2C_NUM_0>;
|
||||
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 = <I2C_NUM_1>;
|
||||
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 {
|
||||
|
||||
@ -18,8 +18,8 @@
|
||||
compatible = "espressif,esp32-i2c";
|
||||
port = <I2C_NUM_0>;
|
||||
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 {
|
||||
|
||||
@ -19,8 +19,8 @@
|
||||
compatible = "espressif,esp32-i2c";
|
||||
port = <I2C_NUM_0>;
|
||||
clock-frequency = <400000>;
|
||||
pin-sda = <16>;
|
||||
pin-scl = <17>;
|
||||
pin-sda = <&gpio0 16 GPIO_FLAG_NONE>;
|
||||
pin-scl = <&gpio0 17 GPIO_FLAG_NONE>;
|
||||
};
|
||||
|
||||
spi0 {
|
||||
|
||||
@ -19,8 +19,8 @@
|
||||
compatible = "espressif,esp32-i2c";
|
||||
port = <I2C_NUM_0>;
|
||||
clock-frequency = <400000>;
|
||||
pin-sda = <47>;
|
||||
pin-scl = <48>;
|
||||
pin-sda = <&gpio0 47 GPIO_FLAG_NONE>;
|
||||
pin-scl = <&gpio0 48 GPIO_FLAG_NONE>;
|
||||
};
|
||||
|
||||
spi0 {
|
||||
|
||||
@ -19,8 +19,8 @@
|
||||
compatible = "espressif,esp32-i2c";
|
||||
port = <I2C_NUM_0>;
|
||||
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 {
|
||||
|
||||
@ -19,8 +19,8 @@
|
||||
compatible = "espressif,esp32-i2c";
|
||||
port = <I2C_NUM_0>;
|
||||
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 {
|
||||
|
||||
@ -19,8 +19,8 @@
|
||||
compatible = "espressif,esp32-i2c";
|
||||
port = <I2C_NUM_0>;
|
||||
clock-frequency = <400000>;
|
||||
pin-sda = <8>;
|
||||
pin-scl = <9>;
|
||||
pin-sda = <&gpio0 8 GPIO_FLAG_NONE>;
|
||||
pin-scl = <&gpio0 9 GPIO_FLAG_NONE>;
|
||||
};
|
||||
|
||||
spi0 {
|
||||
|
||||
@ -18,8 +18,8 @@
|
||||
compatible = "espressif,esp32-i2c";
|
||||
port = <I2C_NUM_0>;
|
||||
clock-frequency = <400000>;
|
||||
pin-sda = <6>;
|
||||
pin-scl = <5>;
|
||||
pin-sda = <&gpio0 6 GPIO_FLAG_NONE>;
|
||||
pin-scl = <&gpio0 5 GPIO_FLAG_NONE>;
|
||||
};
|
||||
|
||||
spi0 {
|
||||
|
||||
@ -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..."
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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
|
||||
|
||||
@ -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<gpio_num_t>(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<gpio_num_t*>(pin_number);
|
||||
*esp_pin_number = static_cast<gpio_num_t>(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;
|
||||
|
||||
@ -1,21 +1,26 @@
|
||||
// SPDX-License-Identifier: Apache-2.0
|
||||
#include <driver/i2c.h>
|
||||
|
||||
#include <tactility/driver.h>
|
||||
#include <tactility/drivers/i2c_controller.h>
|
||||
#include <tactility/log.h>
|
||||
|
||||
#include <tactility/time.h>
|
||||
#include <tactility/error_esp32.h>
|
||||
#include <tactility/driver.h>
|
||||
#include <tactility/drivers/gpio_controller.h>
|
||||
#include <tactility/drivers/i2c_controller.h>
|
||||
#include <tactility/drivers/esp32_i2c.h>
|
||||
#include <tactility/log.h>
|
||||
#include <tactility/time.h>
|
||||
|
||||
#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<int>(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;
|
||||
|
||||
@ -3,6 +3,7 @@
|
||||
#include <tactility/drivers/esp32_spi.h>
|
||||
#include <tactility/concurrent/recursive_mutex.h>
|
||||
|
||||
#include "tactility/drivers/gpio_descriptor.h"
|
||||
#include <cstring>
|
||||
#include <esp_log.h>
|
||||
#include <new>
|
||||
@ -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);
|
||||
|
||||
@ -53,6 +53,7 @@
|
||||
|
||||
#include <driver/i2s_common.h>
|
||||
#include <driver/i2s_std.h>
|
||||
#include <driver/gpio.h>
|
||||
|
||||
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),
|
||||
|
||||
@ -10,21 +10,22 @@ extern "C" {
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#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
|
||||
|
||||
@ -10,25 +10,9 @@ extern "C" {
|
||||
#include <tactility/error.h>
|
||||
|
||||
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.
|
||||
|
||||
@ -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;
|
||||
};
|
||||
|
||||
@ -6,21 +6,41 @@
|
||||
#include <tactility/concurrent/mutex.h>
|
||||
#include <tactility/drivers/gpio_descriptor.h>
|
||||
|
||||
#include <cstdlib>
|
||||
#include <new>
|
||||
|
||||
#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<struct GpioControllerData*>(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 {
|
||||
|
||||
@ -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),
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user