GPIO refactored (#495)

* **Refactor**
  * GPIO subsystem moved to a descriptor-based model for per-pin ownership and runtime pin management; many platform drivers now acquire/release descriptors.
  * Device trees and drivers now use GPIO phandle-style pin specifications across all boards and all drivers.

* **Behavior**
  * Device list now encodes per-device status (ok/disabled); boot will skip disabled devices accordingly.

* **Deprecation**
  * Legacy GPIO HAL marked deprecated and replaced with descriptor-based interfaces.

* **Chores**
  * Bindings and platform configs updated to the new GPIO pin-spec format.
This commit is contained in:
Ken Van Hoeylandt 2026-02-11 20:34:54 +01:00 committed by GitHub
parent dff93cb655
commit 26c17986c6
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
80 changed files with 1129 additions and 665 deletions

View File

@ -57,7 +57,7 @@ def find_phandle(devices: list[Device], phandle: str):
for device in devices: for device in devices:
if device.node_name == phandle or device.node_alias == phandle: if device.node_name == phandle or device.node_alias == phandle:
return f"&{get_device_node_name_safe(device)}" return f"&{get_device_node_name_safe(device)}"
raise DevicetreeException(f"phandle '{phandle}' not found in device tree") raise DevicetreeException(f"phandle '{phandle}' not found in devicetree")
def property_to_string(property: DeviceProperty, devices: list[Device]) -> str: def property_to_string(property: DeviceProperty, devices: list[Device]) -> str:
type = property.type type = property.type
@ -77,6 +77,20 @@ def property_to_string(property: DeviceProperty, devices: list[Device]) -> str:
return "{ " + ",".join(value_list) + " }" return "{ " + ",".join(value_list) + " }"
elif type == "phandle": elif type == "phandle":
return find_phandle(devices, property.value) return find_phandle(devices, property.value)
elif type == "phandle-array":
value_list = list()
if isinstance(property.value, list):
for item in property.value:
if isinstance(item, PropertyValue):
value_list.append(property_to_string(DeviceProperty(name="", type=item.type, value=item.value), devices))
else:
value_list.append(str(item))
return "{ " + ",".join(value_list) + " }"
elif isinstance(property.value, str):
# If it's a string, assume it's a #define and show it as-is
return property.value
else:
raise Exception(f"Unsupported phandle-array type for {property.value}")
else: else:
raise DevicetreeException(f"property_to_string() has an unsupported type: {type}") raise DevicetreeException(f"property_to_string() has an unsupported type: {type}")
@ -167,7 +181,15 @@ def write_device_structs(file, device: Device, parent_device: Device, bindings:
for child_device in device.devices: for child_device in device.devices:
write_device_structs(file, child_device, device, bindings, devices, verbose) write_device_structs(file, child_device, device, bindings, devices, verbose)
def write_device_init(file, device: Device, bindings: list[Binding], verbose: bool): def get_device_status_variable(device: Device):
if device.status == "okay" or device.status is None:
return "DTS_DEVICE_STATUS_OKAY"
elif device.status == "disabled":
return "DTS_DEVICE_STATUS_DISABLED"
else:
raise DevicetreeException(f"Unsupported device status '{device.status}'")
def write_device_list_entry(file, device: Device, bindings: list[Binding], verbose: bool):
if verbose: if verbose:
print(f"Processing device init code for '{device.node_name}'") print(f"Processing device init code for '{device.node_name}'")
# Assemble some pre-requisites # Assemble some pre-requisites
@ -177,11 +199,12 @@ def write_device_init(file, device: Device, bindings: list[Binding], verbose: bo
# Type & instance names # Type & instance names
node_name = get_device_node_name_safe(device) node_name = get_device_node_name_safe(device)
device_variable = node_name device_variable = node_name
status = get_device_status_variable(device)
# Write device struct # Write device struct
file.write("\t{ " f"&{device_variable}, \"{compatible_property.value}\"" " },\n") file.write("\t{ " f"&{device_variable}, \"{compatible_property.value}\", {status}" " },\n")
# Write children # Write children
for child_device in device.devices: for child_device in device.devices:
write_device_init(file, child_device, bindings, verbose) write_device_list_entry(file, child_device, bindings, verbose)
# Walk the tree and gather all devices # Walk the tree and gather all devices
def gather_devices(device: Device, output: list[Device]): def gather_devices(device: Device, output: list[Device]):
@ -201,6 +224,7 @@ def generate_devicetree_c(filename: str, items: list[object], bindings: list[Bin
file.write(dedent('''\ file.write(dedent('''\
// Default headers // Default headers
#include <tactility/device.h> #include <tactility/device.h>
#include <tactility/dts.h>
// DTS headers // DTS headers
''')) '''))
@ -216,14 +240,11 @@ def generate_devicetree_c(filename: str, items: list[object], bindings: list[Bin
for item in items: for item in items:
if type(item) is Device: if type(item) is Device:
write_device_structs(file, item, None, bindings, devices, verbose) write_device_structs(file, item, None, bindings, devices, verbose)
# Init function body start file.write("struct DtsDevice dts_devices[] = {\n")
file.write("struct CompatibleDevice devicetree_devices[] = {\n")
# Init function body logic
for item in items: for item in items:
if type(item) is Device: if type(item) is Device:
write_device_init(file, item, bindings, verbose) write_device_list_entry(file, item, bindings, verbose)
# Init function body end file.write("\tDTS_DEVICE_TERMINATOR\n")
file.write("\t{ NULL, NULL },\n")
file.write("};\n") file.write("};\n")
def generate_devicetree_h(filename: str): def generate_devicetree_h(filename: str):
@ -231,12 +252,13 @@ def generate_devicetree_h(filename: str):
file.write(dedent('''\ file.write(dedent('''\
#pragma once #pragma once
#include <tactility/error.h> #include <tactility/error.h>
#include <tactility/dts.h>
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
#endif #endif
extern struct CompatibleDevice devicetree_devices[]; extern struct DtsDevice dts_devices[];
#ifdef __cplusplus #ifdef __cplusplus
} }

View File

@ -8,6 +8,7 @@ class DtsVersion:
class Device: class Device:
node_name: str node_name: str
node_alias: str node_alias: str
status: str
properties: list properties: list
devices: list devices: list

View File

@ -29,6 +29,7 @@ class DtsTransformer(Transformer):
def device(self, tokens: list): def device(self, tokens: list):
node_name = None node_name = None
node_alias = None node_alias = None
status = None
properties = list() properties = list()
child_devices = list() child_devices = list()
for index, item in enumerate(tokens): for index, item in enumerate(tokens):
@ -37,10 +38,13 @@ class DtsTransformer(Transformer):
elif type(item) is Token and item.type == 'NODE_ALIAS': elif type(item) is Token and item.type == 'NODE_ALIAS':
node_alias = item.value node_alias = item.value
elif type(item) is DeviceProperty: elif type(item) is DeviceProperty:
properties.append(item) if item.name == "status":
status = item.value
else:
properties.append(item)
elif type(item) is Device: elif type(item) is Device:
child_devices.append(item) child_devices.append(item)
return Device(node_name, node_alias, properties, child_devices) return Device(node_name, node_alias, status, properties, child_devices)
def device_property(self, objects: List[object]): def device_property(self, objects: List[object]):
name = objects[0] name = objects[0]
# Boolean property has no value as the value is implied to be true # Boolean property has no value as the value is implied to be true

View File

@ -4,11 +4,9 @@ properties:
reg: reg:
type: int type: int
required: true required: true
status:
type: string
boolean-prop: boolean-prop:
type: boolean type: boolean
int-prop: int-prop:
type: int type: int
string-prop: string-prop:
type: string type: string

View File

@ -6,7 +6,7 @@
compatible = "test,root"; compatible = "test,root";
model = "Test Model"; model = "Test Model";
test_device: test-device@0 { test_device1: test-device@0 {
compatible = "test,device"; compatible = "test,device";
reg = <0>; reg = <0>;
status = "okay"; status = "okay";

View File

@ -27,7 +27,7 @@ def test_compile_success():
result = run_compiler(TEST_DATA_DIR, output_dir) result = run_compiler(TEST_DATA_DIR, output_dir)
if result.returncode != 0: if result.returncode != 0:
print(f"FAILED: Compilation failed: {result.stderr}") print(f"FAILED: Compilation failed: {result.stderr} {result.stdout}")
return False return False
if not os.path.exists(os.path.join(output_dir, "devicetree.c")): if not os.path.exists(os.path.join(output_dir, "devicetree.c")):

View File

@ -18,15 +18,15 @@
compatible = "espressif,esp32-i2c"; compatible = "espressif,esp32-i2c";
port = <I2C_NUM_0>; port = <I2C_NUM_0>;
clock-frequency = <400000>; clock-frequency = <400000>;
pin-sda = <2>; pin-sda = <&gpio0 2 GPIO_FLAG_NONE>;
pin-scl = <1>; pin-scl = <&gpio0 1 GPIO_FLAG_NONE>;
}; };
i2c_external: i2c1 { i2c_external: i2c1 {
compatible = "espressif,esp32-i2c"; compatible = "espressif,esp32-i2c";
port = <I2C_NUM_1>; port = <I2C_NUM_1>;
clock-frequency = <400000>; clock-frequency = <400000>;
pin-sda = <4>; pin-sda = <&gpio0 4 GPIO_FLAG_NONE>;
pin-scl = <3>; pin-scl = <&gpio0 3 GPIO_FLAG_NONE>;
}; };
}; };

View File

@ -18,23 +18,22 @@
compatible = "espressif,esp32-i2c"; compatible = "espressif,esp32-i2c";
port = <I2C_NUM_0>; port = <I2C_NUM_0>;
clock-frequency = <400000>; clock-frequency = <400000>;
pin-sda = <33>; pin-sda = <&gpio0 33 GPIO_FLAG_NONE>;
pin-scl = <32>; pin-scl = <&gpio0 32 GPIO_FLAG_NONE>;
}; };
display_spi: spi0 { display_spi: spi0 {
compatible = "espressif,esp32-spi"; compatible = "espressif,esp32-spi";
host = <SPI2_HOST>; host = <SPI2_HOST>;
pin-mosi = <13>; pin-mosi = <&gpio0 13 GPIO_FLAG_NONE>;
pin-miso = <GPIO_PIN_NONE>; pin-sclk = <&gpio0 14 GPIO_FLAG_NONE>;
pin-sclk = <14>;
}; };
sdcard_spi: spi1 { sdcard_spi: spi1 {
compatible = "espressif,esp32-spi"; compatible = "espressif,esp32-spi";
host = <SPI3_HOST>; host = <SPI3_HOST>;
pin-mosi = <23>; pin-mosi = <&gpio0 23 GPIO_FLAG_NONE>;
pin-miso = <19>; pin-miso = <&gpio0 19 GPIO_FLAG_NONE>;
pin-sclk = <18>; pin-sclk = <&gpio0 18 GPIO_FLAG_NONE>;
}; };
}; };

View File

@ -19,30 +19,30 @@
compatible = "espressif,esp32-i2c"; compatible = "espressif,esp32-i2c";
port = <I2C_NUM_0>; port = <I2C_NUM_0>;
clock-frequency = <400000>; clock-frequency = <400000>;
pin-sda = <27>; pin-sda = <&gpio0 27 GPIO_FLAG_NONE>;
pin-scl = <22>; pin-scl = <&gpio0 22 GPIO_FLAG_NONE>;
}; };
display_spi: spi0 { display_spi: spi0 {
compatible = "espressif,esp32-spi"; compatible = "espressif,esp32-spi";
host = <SPI2_HOST>; host = <SPI2_HOST>;
pin-mosi = <13>; pin-mosi = <&gpio0 13 GPIO_FLAG_NONE>;
pin-miso = <12>; pin-miso = <&gpio0 12 GPIO_FLAG_NONE>;
pin-sclk = <14>; pin-sclk = <&gpio0 14 GPIO_FLAG_NONE>;
}; };
sdcard_spi: spi1 { sdcard_spi: spi1 {
compatible = "espressif,esp32-spi"; compatible = "espressif,esp32-spi";
host = <SPI3_HOST>; host = <SPI3_HOST>;
pin-mosi = <23>; pin-mosi = <&gpio0 23 GPIO_FLAG_NONE>;
pin-miso = <19>; pin-miso = <&gpio0 19 GPIO_FLAG_NONE>;
pin-sclk = <18>; pin-sclk = <&gpio0 18 GPIO_FLAG_NONE>;
}; };
uart1 { uart1 {
compatible = "espressif,esp32-uart"; compatible = "espressif,esp32-uart";
port = <UART_NUM_1>; port = <UART_NUM_1>;
pin-tx = <3>; pin-tx = <&gpio0 3 GPIO_FLAG_NONE>;
pin-rx = <1>; pin-rx = <&gpio0 1 GPIO_FLAG_NONE>;
}; };
}; };

View File

@ -19,30 +19,30 @@
compatible = "espressif,esp32-i2c"; compatible = "espressif,esp32-i2c";
port = <I2C_NUM_0>; port = <I2C_NUM_0>;
clock-frequency = <400000>; clock-frequency = <400000>;
pin-sda = <27>; pin-sda = <&gpio0 27 GPIO_FLAG_NONE>;
pin-scl = <22>; pin-scl = <&gpio0 22 GPIO_FLAG_NONE>;
}; };
display_spi: spi0 { display_spi: spi0 {
compatible = "espressif,esp32-spi"; compatible = "espressif,esp32-spi";
host = <SPI2_HOST>; host = <SPI2_HOST>;
pin-mosi = <13>; pin-mosi = <&gpio0 13 GPIO_FLAG_NONE>;
pin-miso = <12>; pin-miso = <&gpio0 12 GPIO_FLAG_NONE>;
pin-sclk = <14>; pin-sclk = <&gpio0 14 GPIO_FLAG_NONE>;
}; };
sdcard_spi: spi1 { sdcard_spi: spi1 {
compatible = "espressif,esp32-spi"; compatible = "espressif,esp32-spi";
host = <SPI3_HOST>; host = <SPI3_HOST>;
pin-mosi = <23>; pin-mosi = <&gpio0 23 GPIO_FLAG_NONE>;
pin-miso = <19>; pin-miso = <&gpio0 19 GPIO_FLAG_NONE>;
pin-sclk = <18>; pin-sclk = <&gpio0 18 GPIO_FLAG_NONE>;
}; };
uart1 { uart1 {
compatible = "espressif,esp32-uart"; compatible = "espressif,esp32-uart";
port = <UART_NUM_1>; port = <UART_NUM_1>;
pin-tx = <3>; pin-tx = <&gpio0 3 GPIO_FLAG_NONE>;
pin-rx = <1>; pin-rx = <&gpio0 1 GPIO_FLAG_NONE>;
}; };
}; };

View File

@ -18,23 +18,22 @@
compatible = "espressif,esp32-i2c"; compatible = "espressif,esp32-i2c";
port = <I2C_NUM_0>; port = <I2C_NUM_0>;
clock-frequency = <400000>; clock-frequency = <400000>;
pin-sda = <33>; pin-sda = <&gpio1 33 GPIO_FLAG_NONE>;
pin-scl = <32>; pin-scl = <&gpio1 32 GPIO_FLAG_NONE>;
}; };
display_spi: spi0 { display_spi: spi0 {
compatible = "espressif,esp32-spi"; compatible = "espressif,esp32-spi";
host = <SPI2_HOST>; host = <SPI2_HOST>;
pin-mosi = <13>; pin-mosi = <&gpio1 13 GPIO_FLAG_NONE>;
pin-miso = <GPIO_PIN_NONE>; pin-sclk = <&gpio1 14 GPIO_FLAG_NONE>;
pin-sclk = <14>;
}; };
sdcard_spi: spi1 { sdcard_spi: spi1 {
compatible = "espressif,esp32-spi"; compatible = "espressif,esp32-spi";
host = <SPI3_HOST>; host = <SPI3_HOST>;
pin-mosi = <23>; pin-mosi = <&gpio1 23 GPIO_FLAG_NONE>;
pin-miso = <19>; pin-miso = <&gpio1 19 GPIO_FLAG_NONE>;
pin-sclk = <18>; pin-sclk = <&gpio1 18 GPIO_FLAG_NONE>;
}; };
}; };

View File

@ -18,16 +18,16 @@
compatible = "espressif,esp32-i2c"; compatible = "espressif,esp32-i2c";
port = <I2C_NUM_0>; port = <I2C_NUM_0>;
clock-frequency = <400000>; clock-frequency = <400000>;
pin-sda = <19>; pin-sda = <&gpio0 19 GPIO_FLAG_NONE>;
pin-scl = <45>; pin-scl = <&gpio0 45 GPIO_FLAG_NONE>;
}; };
spi0 { spi0 {
compatible = "espressif,esp32-spi"; compatible = "espressif,esp32-spi";
host = <SPI2_HOST>; host = <SPI2_HOST>;
pin-mosi = <47>; pin-mosi = <&gpio0 47 GPIO_FLAG_NONE>;
pin-miso = <41>; pin-miso = <&gpio0 41 GPIO_FLAG_NONE>;
pin-sclk = <48>; pin-sclk = <&gpio0 48 GPIO_FLAG_NONE>;
pin-hd = <42>; pin-hd = <&gpio0 42 GPIO_FLAG_NONE>;
}; };
}; };

View File

@ -19,30 +19,31 @@
compatible = "espressif,esp32-i2c"; compatible = "espressif,esp32-i2c";
port = <I2C_NUM_0>; port = <I2C_NUM_0>;
clock-frequency = <400000>; clock-frequency = <400000>;
pin-sda = <19>; pin-sda = <&gpio0 19 GPIO_FLAG_NONE>;
pin-scl = <20>; pin-scl = <&gpio0 20 GPIO_FLAG_NONE>;
}; };
i2c_external { i2c_external {
compatible = "espressif,esp32-i2c"; compatible = "espressif,esp32-i2c";
port = <I2C_NUM_1>; port = <I2C_NUM_1>;
clock-frequency = <400000>; clock-frequency = <400000>;
pin-sda = <17>; pin-sda = <&gpio0 17 GPIO_FLAG_NONE>;
pin-scl = <18>; pin-scl = <&gpio0 18 GPIO_FLAG_NONE>;
}; };
spi0 { spi0 {
compatible = "espressif,esp32-spi"; compatible = "espressif,esp32-spi";
host = <SPI2_HOST>; host = <SPI2_HOST>;
pin-mosi = <11>; pin-mosi = <&gpio0 11 GPIO_FLAG_NONE>;
pin-miso = <13>; pin-miso = <&gpio0 13 GPIO_FLAG_NONE>;
pin-sclk = <12>; pin-sclk = <&gpio0 12 GPIO_FLAG_NONE>;
}; };
uart1 { uart1 {
compatible = "espressif,esp32-uart"; compatible = "espressif,esp32-uart";
status = "disabled";
port = <UART_NUM_1>; port = <UART_NUM_1>;
pin-tx = <18>; pin-tx = <&gpio0 18 GPIO_FLAG_NONE>;
pin-rx = <17>; pin-rx = <&gpio0 17 GPIO_FLAG_NONE>;
}; };
}; };

View File

@ -16,16 +16,16 @@
display_spi: spi0 { display_spi: spi0 {
compatible = "espressif,esp32-spi"; compatible = "espressif,esp32-spi";
host = <SPI2_HOST>; host = <SPI2_HOST>;
pin-mosi = <13>; pin-mosi = <&gpio0 13 GPIO_FLAG_NONE>;
pin-miso = <12>; pin-miso = <&gpio0 12 GPIO_FLAG_NONE>;
pin-sclk = <14>; pin-sclk = <&gpio0 14 GPIO_FLAG_NONE>;
}; };
sdcard_spi: spi1 { sdcard_spi: spi1 {
compatible = "espressif,esp32-spi"; compatible = "espressif,esp32-spi";
host = <SPI3_HOST>; host = <SPI3_HOST>;
pin-mosi = <23>; pin-mosi = <&gpio0 23 GPIO_FLAG_NONE>;
pin-miso = <19>; pin-miso = <&gpio0 19 GPIO_FLAG_NONE>;
pin-sclk = <18>; pin-sclk = <&gpio0 18 GPIO_FLAG_NONE>;
}; };
}; };

View File

@ -18,23 +18,23 @@
compatible = "espressif,esp32-i2c"; compatible = "espressif,esp32-i2c";
port = <I2C_NUM_0>; port = <I2C_NUM_0>;
clock-frequency = <400000>; clock-frequency = <400000>;
pin-sda = <32>; pin-sda = <&gpio0 32 GPIO_FLAG_NONE>;
pin-scl = <25>; pin-scl = <&gpio0 25 GPIO_FLAG_NONE>;
}; };
display_spi: spi0 { display_spi: spi0 {
compatible = "espressif,esp32-spi"; compatible = "espressif,esp32-spi";
host = <SPI2_HOST>; host = <SPI2_HOST>;
pin-mosi = <13>; pin-mosi = <&gpio0 13 GPIO_FLAG_NONE>;
pin-miso = <12>; pin-miso = <&gpio0 12 GPIO_FLAG_NONE>;
pin-sclk = <14>; pin-sclk = <&gpio0 14 GPIO_FLAG_NONE>;
}; };
sdcard_spi: spi1 { sdcard_spi: spi1 {
compatible = "espressif,esp32-spi"; compatible = "espressif,esp32-spi";
host = <SPI3_HOST>; host = <SPI3_HOST>;
pin-mosi = <23>; pin-mosi = <&gpio0 23 GPIO_FLAG_NONE>;
pin-miso = <19>; pin-miso = <&gpio0 19 GPIO_FLAG_NONE>;
pin-sclk = <18>; pin-sclk = <&gpio0 18 GPIO_FLAG_NONE>;
}; };
}; };

View File

@ -19,36 +19,36 @@
compatible = "espressif,esp32-i2c"; compatible = "espressif,esp32-i2c";
port = <I2C_NUM_0>; port = <I2C_NUM_0>;
clock-frequency = <400000>; clock-frequency = <400000>;
pin-sda = <15>; pin-sda = <&gpio0 15 GPIO_FLAG_NONE>;
pin-scl = <16>; pin-scl = <&gpio0 16 GPIO_FLAG_NONE>;
}; };
display_spi: spi0 { display_spi: spi0 {
compatible = "espressif,esp32-spi"; compatible = "espressif,esp32-spi";
host = <SPI2_HOST>; host = <SPI2_HOST>;
pin-mosi = <39>; pin-mosi = <&gpio0 39 GPIO_FLAG_NONE>;
pin-sclk = <42>; pin-sclk = <&gpio0 42 GPIO_FLAG_NONE>;
}; };
sdcard_spi: spi1 { sdcard_spi: spi1 {
compatible = "espressif,esp32-spi"; compatible = "espressif,esp32-spi";
host = <SPI3_HOST>; host = <SPI3_HOST>;
pin-mosi = <6>; pin-mosi = <&gpio0 6 GPIO_FLAG_NONE>;
pin-miso = <4>; pin-miso = <&gpio0 4 GPIO_FLAG_NONE>;
pin-sclk = <5>; pin-sclk = <&gpio0 5 GPIO_FLAG_NONE>;
}; };
uart0 { uart0 {
compatible = "espressif,esp32-uart"; compatible = "espressif,esp32-uart";
port = <UART_NUM_0>; port = <UART_NUM_0>;
pin-tx = <43>; pin-tx = <&gpio0 43 GPIO_FLAG_NONE>;
pin-rx = <44>; pin-rx = <&gpio0 44 GPIO_FLAG_NONE>;
}; };
uart1 { uart1 {
compatible = "espressif,esp32-uart"; compatible = "espressif,esp32-uart";
port = <UART_NUM_1>; port = <UART_NUM_1>;
pin-tx = <17>; pin-tx = <&gpio0 17 GPIO_FLAG_NONE>;
pin-rx = <18>; pin-rx = <&gpio0 18 GPIO_FLAG_NONE>;
}; };
}; };

View File

@ -19,37 +19,36 @@
compatible = "espressif,esp32-i2c"; compatible = "espressif,esp32-i2c";
port = <I2C_NUM_0>; port = <I2C_NUM_0>;
clock-frequency = <400000>; clock-frequency = <400000>;
pin-sda = <15>; pin-sda = <&gpio0 15 GPIO_FLAG_NONE>;
pin-scl = <16>; pin-scl = <&gpio0 16 GPIO_FLAG_NONE>;
}; };
display_spi: spi0 { display_spi: spi0 {
compatible = "espressif,esp32-spi"; compatible = "espressif,esp32-spi";
host = <SPI2_HOST>; host = <SPI2_HOST>;
pin-mosi = <39>; pin-mosi = <&gpio0 39 GPIO_FLAG_NONE>;
pin-miso = <GPIO_PIN_NONE>; pin-sclk = <&gpio0 42 GPIO_FLAG_NONE>;
pin-sclk = <42>;
}; };
sdcard_spi: spi1 { sdcard_spi: spi1 {
compatible = "espressif,esp32-spi"; compatible = "espressif,esp32-spi";
host = <SPI3_HOST>; host = <SPI3_HOST>;
pin-mosi = <6>; pin-mosi = <&gpio0 6 GPIO_FLAG_NONE>;
pin-miso = <4>; pin-miso = <&gpio0 4 GPIO_FLAG_NONE>;
pin-sclk = <5>; pin-sclk = <&gpio0 5 GPIO_FLAG_NONE>;
}; };
uart0 { uart0 {
compatible = "espressif,esp32-uart"; compatible = "espressif,esp32-uart";
port = <UART_NUM_0>; port = <UART_NUM_0>;
pin-tx = <43>; pin-tx = <&gpio0 43 GPIO_FLAG_NONE>;
pin-rx = <44>; pin-rx = <&gpio0 44 GPIO_FLAG_NONE>;
}; };
uart1 { uart1 {
compatible = "espressif,esp32-uart"; compatible = "espressif,esp32-uart";
port = <UART_NUM_1>; port = <UART_NUM_1>;
pin-tx = <17>; pin-tx = <&gpio0 17 GPIO_FLAG_NONE>;
pin-rx = <18>; pin-rx = <&gpio0 18 GPIO_FLAG_NONE>;
}; };
}; };

View File

@ -19,29 +19,29 @@
compatible = "espressif,esp32-i2c"; compatible = "espressif,esp32-i2c";
port = <I2C_NUM_0>; port = <I2C_NUM_0>;
clock-frequency = <400000>; clock-frequency = <400000>;
pin-sda = <15>; pin-sda = <&gpio0 15 GPIO_FLAG_NONE>;
pin-scl = <16>; pin-scl = <&gpio0 16 GPIO_FLAG_NONE>;
}; };
sdcard_spi: spi0 { sdcard_spi: spi0 {
compatible = "espressif,esp32-spi"; compatible = "espressif,esp32-spi";
host = <SPI2_HOST>; host = <SPI2_HOST>;
pin-mosi = <6>; pin-mosi = <&gpio0 6 GPIO_FLAG_NONE>;
pin-miso = <4>; pin-miso = <&gpio0 4 GPIO_FLAG_NONE>;
pin-sclk = <5>; pin-sclk = <&gpio0 5 GPIO_FLAG_NONE>;
}; };
uart0 { uart0 {
compatible = "espressif,esp32-uart"; compatible = "espressif,esp32-uart";
port = <UART_NUM_0>; port = <UART_NUM_0>;
pin-tx = <43>; pin-tx = <&gpio0 43 GPIO_FLAG_NONE>;
pin-rx = <44>; pin-rx = <&gpio0 44 GPIO_FLAG_NONE>;
}; };
uart1 { uart1 {
compatible = "espressif,esp32-uart"; compatible = "espressif,esp32-uart";
port = <UART_NUM_1>; port = <UART_NUM_1>;
pin-tx = <20>; pin-tx = <&gpio0 20 GPIO_FLAG_NONE>;
pin-rx = <19>; pin-rx = <&gpio0 19 GPIO_FLAG_NONE>;
}; };
}; };

View File

@ -19,31 +19,31 @@
compatible = "espressif,esp32-i2c"; compatible = "espressif,esp32-i2c";
port = <I2C_NUM_0>; port = <I2C_NUM_0>;
clock-frequency = <400000>; clock-frequency = <400000>;
pin-sda = <22>; pin-sda = <&gpio0 22 GPIO_FLAG_NONE>;
pin-scl = <21>; pin-scl = <&gpio0 21 GPIO_FLAG_NONE>;
}; };
display_spi: spi0 { display_spi: spi0 {
compatible = "espressif,esp32-spi"; compatible = "espressif,esp32-spi";
host = <SPI2_HOST>; host = <SPI2_HOST>;
pin-mosi = <13>; pin-mosi = <&gpio0 13 GPIO_FLAG_NONE>;
pin-miso = <12>; pin-miso = <&gpio0 12 GPIO_FLAG_NONE>;
pin-sclk = <14>; pin-sclk = <&gpio0 14 GPIO_FLAG_NONE>;
max-transfer-size = <65536>; max-transfer-size = <65536>;
}; };
sdcard_spi: spi1 { sdcard_spi: spi1 {
compatible = "espressif,esp32-spi"; compatible = "espressif,esp32-spi";
host = <SPI3_HOST>; host = <SPI3_HOST>;
pin-mosi = <23>; pin-mosi = <&gpio0 23 GPIO_FLAG_NONE>;
pin-miso = <19>; pin-miso = <&gpio0 19 GPIO_FLAG_NONE>;
pin-sclk = <18>; pin-sclk = <&gpio0 18 GPIO_FLAG_NONE>;
}; };
uart1 { uart1 {
compatible = "espressif,esp32-uart"; compatible = "espressif,esp32-uart";
port = <UART_NUM_1>; port = <UART_NUM_1>;
pin-tx = <17>; pin-tx = <&gpio0 17 GPIO_FLAG_NONE>;
pin-rx = <16>; pin-rx = <&gpio0 16 GPIO_FLAG_NONE>;
}; };
}; };

View File

@ -19,31 +19,31 @@
compatible = "espressif,esp32-i2c"; compatible = "espressif,esp32-i2c";
port = <I2C_NUM_0>; port = <I2C_NUM_0>;
clock-frequency = <400000>; clock-frequency = <400000>;
pin-sda = <22>; pin-sda = <&gpio0 22 GPIO_FLAG_NONE>;
pin-scl = <21>; pin-scl = <&gpio0 21 GPIO_FLAG_NONE>;
}; };
display_spi: spi0 { display_spi: spi0 {
compatible = "espressif,esp32-spi"; compatible = "espressif,esp32-spi";
host = <SPI2_HOST>; host = <SPI2_HOST>;
pin-mosi = <13>; pin-mosi = <&gpio0 13 GPIO_FLAG_NONE>;
pin-miso = <33>; pin-miso = <&gpio0 33 GPIO_FLAG_NONE>;
pin-sclk = <14>; pin-sclk = <&gpio0 14 GPIO_FLAG_NONE>;
max-transfer-size = <65536>; max-transfer-size = <65536>;
}; };
sdcard_spi: spi1 { sdcard_spi: spi1 {
compatible = "espressif,esp32-spi"; compatible = "espressif,esp32-spi";
host = <SPI3_HOST>; host = <SPI3_HOST>;
pin-mosi = <23>; pin-mosi = <&gpio0 23 GPIO_FLAG_NONE>;
pin-miso = <19>; pin-miso = <&gpio0 19 GPIO_FLAG_NONE>;
pin-sclk = <18>; pin-sclk = <&gpio0 18 GPIO_FLAG_NONE>;
}; };
uart1 { uart1 {
compatible = "espressif,esp32-uart"; compatible = "espressif,esp32-uart";
port = <UART_NUM_1>; port = <UART_NUM_1>;
pin-tx = <1>; pin-tx = <&gpio0 1 GPIO_FLAG_NONE>;
pin-rx = <3>; pin-rx = <&gpio0 3 GPIO_FLAG_NONE>;
}; };
}; };

View File

@ -19,22 +19,22 @@
compatible = "espressif,esp32-i2c"; compatible = "espressif,esp32-i2c";
port = <I2C_NUM_0>; port = <I2C_NUM_0>;
clock-frequency = <400000>; clock-frequency = <400000>;
pin-sda = <19>; pin-sda = <&gpio0 19 GPIO_FLAG_NONE>;
pin-scl = <20>; pin-scl = <&gpio0 20 GPIO_FLAG_NONE>;
}; };
sdcard_spi: spi0 { sdcard_spi: spi0 {
compatible = "espressif,esp32-spi"; compatible = "espressif,esp32-spi";
host = <SPI2_HOST>; host = <SPI2_HOST>;
pin-mosi = <11>; pin-mosi = <&gpio0 11 GPIO_FLAG_NONE>;
pin-miso = <13>; pin-miso = <&gpio0 13 GPIO_FLAG_NONE>;
pin-sclk = <12>; pin-sclk = <&gpio0 12 GPIO_FLAG_NONE>;
}; };
uart0 { uart0 {
compatible = "espressif,esp32-uart"; compatible = "espressif,esp32-uart";
port = <UART_NUM_0>; port = <UART_NUM_0>;
pin-tx = <43>; pin-tx = <&gpio0 43 GPIO_FLAG_NONE>;
pin-rx = <44>; pin-rx = <&gpio0 44 GPIO_FLAG_NONE>;
}; };
}; };

View File

@ -26,17 +26,17 @@
compatible = "espressif,esp32-i2c"; compatible = "espressif,esp32-i2c";
port = <I2C_NUM_0>; port = <I2C_NUM_0>;
clock-frequency = <400000>; clock-frequency = <400000>;
pin-sda = <7>; pin-sda = <&gpio0 7 GPIO_FLAG_NONE>;
pin-scl = <8>; pin-scl = <&gpio0 8 GPIO_FLAG_NONE>;
}; };
i2s0 { i2s0 {
compatible = "espressif,esp32-i2s"; compatible = "espressif,esp32-i2s";
port = <I2S_NUM_0>; port = <I2S_NUM_0>;
pin-bclk = <12>; pin-bclk = <&gpio0 12 GPIO_FLAG_NONE>;
pin-ws = <10>; pin-ws = <&gpio0 10 GPIO_FLAG_NONE>;
pin-data-out = <9>; pin-data-out = <&gpio0 9 GPIO_FLAG_NONE>;
pin-data-in = <48>; pin-data-in = <&gpio0 48 GPIO_FLAG_NONE>;
pin-mclk = <13>; pin-mclk = <&gpio0 13 GPIO_FLAG_NONE>;
}; };
}; };

View File

@ -19,8 +19,8 @@
compatible = "espressif,esp32-i2c"; compatible = "espressif,esp32-i2c";
port = <I2C_NUM_0>; port = <I2C_NUM_0>;
clock-frequency = <400000>; clock-frequency = <400000>;
pin-sda = <33>; pin-sda = <&gpio0 33 GPIO_FLAG_NONE>;
pin-scl = <32>; pin-scl = <&gpio0 32 GPIO_FLAG_NONE>;
}; };
// CN1 header // CN1 header
@ -28,30 +28,31 @@
compatible = "espressif,esp32-i2c"; compatible = "espressif,esp32-i2c";
port = <I2C_NUM_1>; port = <I2C_NUM_1>;
clock-frequency = <400000>; clock-frequency = <400000>;
pin-sda = <21>; pin-sda = <&gpio0 21 GPIO_FLAG_NONE>;
pin-scl = <22>; pin-scl = <&gpio0 22 GPIO_FLAG_NONE>;
}; };
display_spi: spi0 { display_spi: spi0 {
compatible = "espressif,esp32-spi"; compatible = "espressif,esp32-spi";
host = <SPI2_HOST>; host = <SPI2_HOST>;
pin-mosi = <13>; pin-mosi = <&gpio0 13 GPIO_FLAG_NONE>;
pin-sclk = <14>; pin-sclk = <&gpio0 14 GPIO_FLAG_NONE>;
}; };
sdcard_spi: spi1 { sdcard_spi: spi1 {
compatible = "espressif,esp32-spi"; compatible = "espressif,esp32-spi";
host = <SPI3_HOST>; host = <SPI3_HOST>;
pin-mosi = <23>; pin-mosi = <&gpio0 23 GPIO_FLAG_NONE>;
pin-miso = <19>; pin-miso = <&gpio0 19 GPIO_FLAG_NONE>;
pin-sclk = <18>; pin-sclk = <&gpio0 18 GPIO_FLAG_NONE>;
}; };
// CN1 header, JST SH 1.25, GND / IO22 / IO21 / 3.3V // CN1 header, JST SH 1.25, GND / IO22 / IO21 / 3.3V
uart1 { uart1 {
compatible = "espressif,esp32-uart"; compatible = "espressif,esp32-uart";
status = "disabled";
port = <UART_NUM_1>; port = <UART_NUM_1>;
pin-tx = <22>; pin-tx = <&gpio0 22 GPIO_FLAG_NONE>;
pin-rx = <21>; pin-rx = <&gpio0 21 GPIO_FLAG_NONE>;
}; };
}; };

View File

@ -19,41 +19,41 @@
compatible = "espressif,esp32-i2c"; compatible = "espressif,esp32-i2c";
port = <I2C_NUM_0>; port = <I2C_NUM_0>;
clock-frequency = <400000>; clock-frequency = <400000>;
pin-sda = <4>; pin-sda = <&gpio0 4 GPIO_FLAG_NONE>;
pin-scl = <8>; pin-scl = <&gpio0 8 GPIO_FLAG_NONE>;
}; };
i2c_external: i2c1 { i2c_external: i2c1 {
compatible = "espressif,esp32-i2c"; compatible = "espressif,esp32-i2c";
port = <I2C_NUM_1>; port = <I2C_NUM_1>;
clock-frequency = <400000>; clock-frequency = <400000>;
pin-sda = <17>; pin-sda = <&gpio0 17 GPIO_FLAG_NONE>;
pin-scl = <18>; pin-scl = <&gpio0 18 GPIO_FLAG_NONE>;
}; };
display_spi: spi0 { display_spi: spi0 {
compatible = "espressif,esp32-spi"; compatible = "espressif,esp32-spi";
host = <SPI2_HOST>; host = <SPI2_HOST>;
pin-mosi = <21>; pin-mosi = <&gpio0 21 GPIO_FLAG_NONE>;
pin-miso = <48>; pin-miso = <&gpio0 48 GPIO_FLAG_NONE>;
pin-sclk = <47>; pin-sclk = <&gpio0 47 GPIO_FLAG_NONE>;
pin-wp = <40>; pin-wp = <&gpio0 40 GPIO_FLAG_NONE>;
pin-hd = <39>; pin-hd = <&gpio0 39 GPIO_FLAG_NONE>;
}; };
sdcard_spi: spi1 { sdcard_spi: spi1 {
compatible = "espressif,esp32-spi"; compatible = "espressif,esp32-spi";
host = <SPI3_HOST>; host = <SPI3_HOST>;
pin-mosi = <11>; pin-mosi = <&gpio0 11 GPIO_FLAG_NONE>;
pin-miso = <13>; pin-miso = <&gpio0 13 GPIO_FLAG_NONE>;
pin-sclk = <12>; pin-sclk = <&gpio0 12 GPIO_FLAG_NONE>;
}; };
// P1 header // P1 header
uart0 { uart0 {
compatible = "espressif,esp32-uart"; compatible = "espressif,esp32-uart";
port = <UART_NUM_0>; port = <UART_NUM_0>;
pin-tx = <43>; pin-tx = <&gpio0 43 GPIO_FLAG_NONE>;
pin-rx = <44>; pin-rx = <&gpio0 44 GPIO_FLAG_NONE>;
}; };
}; };

View File

@ -19,30 +19,31 @@
compatible = "espressif,esp32-i2c"; compatible = "espressif,esp32-i2c";
port = <I2C_NUM_0>; port = <I2C_NUM_0>;
clock-frequency = <400000>; clock-frequency = <400000>;
pin-sda = <19>; pin-sda = <&gpio0 19 GPIO_FLAG_NONE>;
pin-scl = <20>; pin-scl = <&gpio0 20 GPIO_FLAG_NONE>;
}; };
i2c_external: i2c1 { i2c_external: i2c1 {
compatible = "espressif,esp32-i2c"; compatible = "espressif,esp32-i2c";
port = <I2C_NUM_1>; port = <I2C_NUM_1>;
clock-frequency = <400000>; clock-frequency = <400000>;
pin-sda = <17>; pin-sda = <&gpio0 17 GPIO_FLAG_NONE>;
pin-scl = <18>; pin-scl = <&gpio0 18 GPIO_FLAG_NONE>;
}; };
spi0 { spi0 {
compatible = "espressif,esp32-spi"; compatible = "espressif,esp32-spi";
host = <SPI2_HOST>; host = <SPI2_HOST>;
pin-mosi = <11>; pin-mosi = <&gpio0 11 GPIO_FLAG_NONE>;
pin-miso = <13>; pin-miso = <&gpio0 13 GPIO_FLAG_NONE>;
pin-sclk = <12>; pin-sclk = <&gpio0 12 GPIO_FLAG_NONE>;
}; };
uart1 { uart1 {
compatible = "espressif,esp32-uart"; compatible = "espressif,esp32-uart";
status = "disabled";
port = <UART_NUM_1>; port = <UART_NUM_1>;
pin-tx = <18>; pin-tx = <&gpio0 18 GPIO_FLAG_NONE>;
pin-rx = <17>; pin-rx = <&gpio0 17 GPIO_FLAG_NONE>;
}; };
}; };

View File

@ -17,7 +17,7 @@
compatible = "espressif,esp32-i2c"; compatible = "espressif,esp32-i2c";
port = <I2C_NUM_0>; port = <I2C_NUM_0>;
clock-frequency = <200000>; clock-frequency = <200000>;
pin-sda = <17>; pin-sda = <&gpio0 17 GPIO_FLAG_NONE>;
pin-scl = <18>; pin-scl = <&gpio0 18 GPIO_FLAG_NONE>;
}; };
}; };

View File

@ -21,38 +21,39 @@
compatible = "espressif,esp32-i2c"; compatible = "espressif,esp32-i2c";
port = <I2C_NUM_0>; port = <I2C_NUM_0>;
clock-frequency = <400000>; clock-frequency = <400000>;
pin-sda = <18>; pin-sda = <&gpio0 18 GPIO_FLAG_NONE>;
pin-scl = <8>; pin-scl = <&gpio0 8 GPIO_FLAG_NONE>;
}; };
i2c_external: i2c1 { i2c_external: i2c1 {
compatible = "espressif,esp32-i2c"; compatible = "espressif,esp32-i2c";
status = "disabled";
port = <I2C_NUM_1>; port = <I2C_NUM_1>;
clock-frequency = <400000>; clock-frequency = <400000>;
pin-sda = <43>; pin-sda = <&gpio0 43 GPIO_FLAG_NONE>;
pin-scl = <44>; pin-scl = <&gpio0 44 GPIO_FLAG_NONE>;
}; };
i2s0 { i2s0 {
compatible = "espressif,esp32-i2s"; compatible = "espressif,esp32-i2s";
port = <I2S_NUM_0>; port = <I2S_NUM_0>;
pin-bclk = <7>; pin-bclk = <&gpio0 7 GPIO_FLAG_NONE>;
pin-ws = <5>; pin-ws = <&gpio0 5 GPIO_FLAG_NONE>;
pin-data-out = <6>; pin-data-out = <&gpio0 6 GPIO_FLAG_NONE>;
}; };
spi0 { spi0 {
compatible = "espressif,esp32-spi"; compatible = "espressif,esp32-spi";
host = <SPI2_HOST>; host = <SPI2_HOST>;
pin-mosi = <41>; pin-mosi = <&gpio0 41 GPIO_FLAG_NONE>;
pin-miso = <38>; pin-miso = <&gpio0 38 GPIO_FLAG_NONE>;
pin-sclk = <40>; pin-sclk = <&gpio0 40 GPIO_FLAG_NONE>;
}; };
uart1 { uart1 {
compatible = "espressif,esp32-uart"; compatible = "espressif,esp32-uart";
port = <UART_NUM_1>; port = <UART_NUM_1>;
pin-tx = <43>; pin-tx = <&gpio0 43 GPIO_FLAG_NONE>;
pin-rx = <44>; pin-rx = <&gpio0 44 GPIO_FLAG_NONE>;
}; };
}; };

View File

@ -17,7 +17,7 @@
spi0 { spi0 {
compatible = "espressif,esp32-spi"; compatible = "espressif,esp32-spi";
host = <SPI2_HOST>; host = <SPI2_HOST>;
pin-mosi = <7>; pin-mosi = <&gpio0 7 GPIO_FLAG_NONE>;
pin-sclk = <6>; pin-sclk = <&gpio0 6 GPIO_FLAG_NONE>;
}; };
}; };

View File

@ -17,7 +17,7 @@
spi0 { spi0 {
compatible = "espressif,esp32-spi"; compatible = "espressif,esp32-spi";
host = <SPI2_HOST>; host = <SPI2_HOST>;
pin-mosi = <19>; pin-mosi = <&gpio0 19 GPIO_FLAG_NONE>;
pin-sclk = <18>; pin-sclk = <&gpio0 18 GPIO_FLAG_NONE>;
}; };
}; };

View File

@ -19,21 +19,21 @@
compatible = "espressif,esp32-i2c"; compatible = "espressif,esp32-i2c";
port = <I2C_NUM_0>; port = <I2C_NUM_0>;
clock-frequency = <400000>; clock-frequency = <400000>;
pin-sda = <44>; pin-sda = <&gpio0 44 GPIO_FLAG_NONE>;
pin-scl = <43>; pin-scl = <&gpio0 43 GPIO_FLAG_NONE>;
}; };
spi0 { spi0 {
compatible = "espressif,esp32-spi"; compatible = "espressif,esp32-spi";
host = <SPI2_HOST>; host = <SPI2_HOST>;
pin-mosi = <3>; pin-mosi = <&gpio0 3 GPIO_FLAG_NONE>;
pin-sclk = <5>; pin-sclk = <&gpio0 5 GPIO_FLAG_NONE>;
}; };
stemma_qt: uart1 { stemma_qt: uart1 {
compatible = "espressif,esp32-uart"; compatible = "espressif,esp32-uart";
port = <UART_NUM_1>; port = <UART_NUM_1>;
pin-tx = <43>; pin-tx = <&gpio0 43 GPIO_FLAG_NONE>;
pin-rx = <44>; pin-rx = <&gpio0 44 GPIO_FLAG_NONE>;
}; };
}; };

View File

@ -21,16 +21,16 @@
compatible = "espressif,esp32-i2c"; compatible = "espressif,esp32-i2c";
port = <I2C_NUM_0>; port = <I2C_NUM_0>;
clock-frequency = <100000>; clock-frequency = <100000>;
pin-sda = <3>; pin-sda = <&gpio0 3 GPIO_FLAG_NONE>;
pin-scl = <2>; pin-scl = <&gpio0 2 GPIO_FLAG_NONE>;
}; };
spi0 { spi0 {
compatible = "espressif,esp32-spi"; compatible = "espressif,esp32-spi";
host = <SPI2_HOST>; host = <SPI2_HOST>;
pin-mosi = <34>; pin-mosi = <&gpio0 34 GPIO_FLAG_NONE>;
pin-miso = <33>; pin-miso = <&gpio0 33 GPIO_FLAG_NONE>;
pin-sclk = <35>; pin-sclk = <&gpio0 35 GPIO_FLAG_NONE>;
}; };
// ES8311 // ES8311
@ -38,24 +38,24 @@
i2s0 { i2s0 {
compatible = "espressif,esp32-i2s"; compatible = "espressif,esp32-i2s";
port = <I2S_NUM_0>; port = <I2S_NUM_0>;
pin-bclk = <11>; pin-bclk = <&gpio0 11 GPIO_FLAG_NONE>;
pin-ws = <18>; pin-ws = <&gpio0 18 GPIO_FLAG_NONE>;
pin-data-out = <45>; pin-data-out = <&gpio0 45 GPIO_FLAG_NONE>;
pin-data-in = <17>; pin-data-in = <&gpio0 17 GPIO_FLAG_NONE>;
pin-mclk = <10>; pin-mclk = <&gpio0 10 GPIO_FLAG_NONE>;
}; };
uart_internal: uart0 { uart_internal: uart0 {
compatible = "espressif,esp32-uart"; compatible = "espressif,esp32-uart";
port = <UART_NUM_0>; port = <UART_NUM_0>;
pin-tx = <12>; pin-tx = <&gpio0 12 GPIO_FLAG_NONE>;
pin-rx = <4>; pin-rx = <&gpio0 4 GPIO_FLAG_NONE>;
}; };
uart_external: uart1 { uart_external: uart1 {
compatible = "espressif,esp32-uart"; compatible = "espressif,esp32-uart";
port = <UART_NUM_1>; port = <UART_NUM_1>;
pin-tx = <43>; pin-tx = <&gpio0 43 GPIO_FLAG_NONE>;
pin-rx = <44>; pin-rx = <&gpio0 44 GPIO_FLAG_NONE>;
}; };
}; };

View File

@ -21,47 +21,48 @@
compatible = "espressif,esp32-i2c"; compatible = "espressif,esp32-i2c";
port = <I2C_NUM_0>; port = <I2C_NUM_0>;
clock-frequency = <400000>; clock-frequency = <400000>;
pin-sda = <8>; pin-sda = <&gpio0 8 GPIO_FLAG_NONE>;
pin-scl = <9>; pin-scl = <&gpio0 9 GPIO_FLAG_NONE>;
}; };
i2c_port_a { i2c_port_a {
compatible = "espressif,esp32-i2c"; compatible = "espressif,esp32-i2c";
port = <I2C_NUM_1>; port = <I2C_NUM_1>;
clock-frequency = <400000>; clock-frequency = <400000>;
pin-sda = <2>; pin-sda = <&gpio0 2 GPIO_FLAG_NONE>;
pin-scl = <1>; pin-scl = <&gpio0 1 GPIO_FLAG_NONE>;
}; };
display_spi: spi0 { display_spi: spi0 {
compatible = "espressif,esp32-spi"; compatible = "espressif,esp32-spi";
host = <SPI2_HOST>; host = <SPI2_HOST>;
pin-mosi = <35>; pin-mosi = <&gpio0 35 GPIO_FLAG_NONE>;
pin-sclk = <36>; pin-sclk = <&gpio0 36 GPIO_FLAG_NONE>;
}; };
sdcard_spi: spi1 { sdcard_spi: spi1 {
compatible = "espressif,esp32-spi"; compatible = "espressif,esp32-spi";
host = <SPI3_HOST>; host = <SPI3_HOST>;
pin-mosi = <14>; pin-mosi = <&gpio0 14 GPIO_FLAG_NONE>;
pin-miso = <39>; pin-miso = <&gpio0 39 GPIO_FLAG_NONE>;
pin-sclk = <40>; pin-sclk = <&gpio0 40 GPIO_FLAG_NONE>;
}; };
// Speaker and microphone (ES8311) // Speaker and microphone (ES8311)
i2s0 { i2s0 {
compatible = "espressif,esp32-i2s"; compatible = "espressif,esp32-i2s";
port = <I2S_NUM_0>; port = <I2S_NUM_0>;
pin-bclk = <41>; pin-bclk = <&gpio0 41 GPIO_FLAG_NONE>;
pin-ws = <43>; pin-ws = <&gpio0 43 GPIO_FLAG_NONE>;
pin-data-out = <42>; pin-data-out = <&gpio0 42 GPIO_FLAG_NONE>;
pin-data-in = <46>; pin-data-in = <&gpio0 46 GPIO_FLAG_NONE>;
}; };
uart_port_a: uart1 { uart_port_a: uart1 {
compatible = "espressif,esp32-uart"; compatible = "espressif,esp32-uart";
status = "disabled";
port = <UART_NUM_1>; port = <UART_NUM_1>;
pin-tx = <1>; pin-tx = <&gpio0 1 GPIO_FLAG_NONE>;
pin-rx = <2>; pin-rx = <&gpio0 2 GPIO_FLAG_NONE>;
}; };
}; };

View File

@ -21,23 +21,23 @@
compatible = "espressif,esp32-i2c"; compatible = "espressif,esp32-i2c";
port = <I2C_NUM_0>; port = <I2C_NUM_0>;
clock-frequency = <400000>; clock-frequency = <400000>;
pin-sda = <2>; pin-sda = <&gpio0 2 GPIO_FLAG_NONE>;
pin-scl = <1>; pin-scl = <&gpio0 1 GPIO_FLAG_NONE>;
}; };
display_spi: spi0 { display_spi: spi0 {
compatible = "espressif,esp32-spi"; compatible = "espressif,esp32-spi";
host = <SPI2_HOST>; host = <SPI2_HOST>;
pin-mosi = <35>; pin-mosi = <&gpio0 35 GPIO_FLAG_NONE>;
pin-sclk = <36>; pin-sclk = <&gpio0 36 GPIO_FLAG_NONE>;
}; };
sdcard_spi: spi1 { sdcard_spi: spi1 {
compatible = "espressif,esp32-spi"; compatible = "espressif,esp32-spi";
host = <SPI3_HOST>; host = <SPI3_HOST>;
pin-mosi = <14>; pin-mosi = <&gpio0 14 GPIO_FLAG_NONE>;
pin-miso = <39>; pin-miso = <&gpio0 39 GPIO_FLAG_NONE>;
pin-sclk = <40>; pin-sclk = <&gpio0 40 GPIO_FLAG_NONE>;
}; };
// Speaker and microphone // Speaker and microphone
@ -45,16 +45,17 @@
i2s0 { i2s0 {
compatible = "espressif,esp32-i2s"; compatible = "espressif,esp32-i2s";
port = <I2S_NUM_0>; port = <I2S_NUM_0>;
pin-bclk = <41>; pin-bclk = <&gpio0 41 GPIO_FLAG_NONE>;
pin-ws = <43>; pin-ws = <&gpio0 43 GPIO_FLAG_NONE>;
pin-data-out = <42>; pin-data-out = <&gpio0 42 GPIO_FLAG_NONE>;
pin-data-in = <46>; pin-data-in = <&gpio0 46 GPIO_FLAG_NONE>;
}; };
uart_port_a: uart1 { uart_port_a: uart1 {
compatible = "espressif,esp32-uart"; compatible = "espressif,esp32-uart";
status = "disabled";
port = <UART_NUM_1>; port = <UART_NUM_1>;
pin-tx = <1>; pin-tx = <&gpio0 1 GPIO_FLAG_NONE>;
pin-rx = <2>; pin-rx = <&gpio0 2 GPIO_FLAG_NONE>;
}; };
}; };

View File

@ -21,24 +21,24 @@
compatible = "espressif,esp32-i2c"; compatible = "espressif,esp32-i2c";
port = <I2C_NUM_0>; port = <I2C_NUM_0>;
clock-frequency = <400000>; clock-frequency = <400000>;
pin-sda = <21>; pin-sda = <&gpio0 21 GPIO_FLAG_NONE>;
pin-scl = <22>; pin-scl = <&gpio0 22 GPIO_FLAG_NONE>;
}; };
i2c_port_a { i2c_port_a {
compatible = "espressif,esp32-i2c"; compatible = "espressif,esp32-i2c";
port = <I2C_NUM_1>; port = <I2C_NUM_1>;
clock-frequency = <400000>; clock-frequency = <400000>;
pin-sda = <32>; pin-sda = <&gpio0 32 GPIO_FLAG_NONE>;
pin-scl = <33>; pin-scl = <&gpio0 33 GPIO_FLAG_NONE>;
}; };
spi0 { spi0 {
compatible = "espressif,esp32-spi"; compatible = "espressif,esp32-spi";
host = <SPI2_HOST>; host = <SPI2_HOST>;
pin-mosi = <23>; pin-mosi = <&gpio0 23 GPIO_FLAG_NONE>;
pin-miso = <38>; pin-miso = <&gpio0 38 GPIO_FLAG_NONE>;
pin-sclk = <18>; pin-sclk = <&gpio0 18 GPIO_FLAG_NONE>;
}; };
// NS4168: Speaker and microphone // NS4168: Speaker and microphone
@ -46,16 +46,17 @@
i2s0 { i2s0 {
compatible = "espressif,esp32-i2s"; compatible = "espressif,esp32-i2s";
port = <I2S_NUM_0>; port = <I2S_NUM_0>;
pin-bclk = <12>; pin-bclk = <&gpio0 12 GPIO_FLAG_NONE>;
pin-ws = <0>; pin-ws = <&gpio0 0 GPIO_FLAG_NONE>;
pin-data-out = <2>; pin-data-out = <&gpio0 2 GPIO_FLAG_NONE>;
pin-data-in = <34>; pin-data-in = <&gpio0 34 GPIO_FLAG_NONE>;
}; };
uart_port_a: uart1 { uart_port_a: uart1 {
compatible = "espressif,esp32-uart"; compatible = "espressif,esp32-uart";
status = "disabled";
port = <UART_NUM_1>; port = <UART_NUM_1>;
pin-tx = <33>; pin-tx = <&gpio0 33 GPIO_FLAG_NONE>;
pin-rx = <32>; pin-rx = <&gpio0 32 GPIO_FLAG_NONE>;
}; };
}; };

View File

@ -21,40 +21,42 @@
compatible = "espressif,esp32-i2c"; compatible = "espressif,esp32-i2c";
port = <I2C_NUM_0>; port = <I2C_NUM_0>;
clock-frequency = <400000>; clock-frequency = <400000>;
pin-sda = <12>; pin-sda = <&gpio0 12 GPIO_FLAG_NONE>;
pin-scl = <11>; pin-scl = <&gpio0 11 GPIO_FLAG_NONE>;
}; };
i2c_port_a { i2c_port_a {
compatible = "espressif,esp32-i2c"; compatible = "espressif,esp32-i2c";
port = <I2C_NUM_1>; port = <I2C_NUM_1>;
clock-frequency = <400000>; clock-frequency = <400000>;
pin-sda = <2>; pin-sda = <&gpio0 2 GPIO_FLAG_NONE>;
pin-scl = <1>; pin-scl = <&gpio0 1 GPIO_FLAG_NONE>;
}; };
/*
i2c_port_b { i2c_port_b {
compatible = "espressif,esp32-i2c"; compatible = "espressif,esp32-i2c";
status = "disabled";
port = <I2C_NUM_1>; port = <I2C_NUM_1>;
clock-frequency = <400000>; clock-frequency = <400000>;
pin-sda = <9>; pin-sda = <&gpio0 9 GPIO_FLAG_NONE>;
pin-scl = <8>; pin-scl = <&gpio0 8 GPIO_FLAG_NONE>;
}; };
i2c_port_c { i2c_port_c {
compatible = "espressif,esp32-i2c"; compatible = "espressif,esp32-i2c";
status = "disabled";
port = <I2C_NUM_1>; port = <I2C_NUM_1>;
clock-frequency = <400000>; clock-frequency = <400000>;
pin-sda = <18>; pin-sda = <&gpio0 18 GPIO_FLAG_NONE>;
pin-scl = <17>; pin-scl = <&gpio0 17 GPIO_FLAG_NONE>;
}; };
*/
spi0 { spi0 {
compatible = "espressif,esp32-spi"; compatible = "espressif,esp32-spi";
host = <SPI2_HOST>; host = <SPI2_HOST>;
pin-mosi = <37>; pin-mosi = <&gpio0 37 GPIO_FLAG_NONE>;
pin-miso = <35>; pin-miso = <&gpio0 35 GPIO_FLAG_NONE>;
pin-sclk = <36>; pin-sclk = <&gpio0 36 GPIO_FLAG_NONE>;
}; };
// TODO: Enable speaker via ES7210 I2C: https://github.com/m5stack/M5Unified/blob/a6256725481f1bc366655fa48cf03b6095e30ad1/src/M5Unified.cpp#L417 // TODO: Enable speaker via ES7210 I2C: https://github.com/m5stack/M5Unified/blob/a6256725481f1bc366655fa48cf03b6095e30ad1/src/M5Unified.cpp#L417
@ -64,17 +66,18 @@
// Note: M5Unified sets the following for microphone: magnification = 4 // Note: M5Unified sets the following for microphone: magnification = 4
compatible = "espressif,esp32-i2s"; compatible = "espressif,esp32-i2s";
port = <I2S_NUM_0>; port = <I2S_NUM_0>;
pin-bclk = <34>; pin-bclk = <&gpio0 34 GPIO_FLAG_NONE>;
pin-ws = <33>; pin-ws = <&gpio0 33 GPIO_FLAG_NONE>;
pin-data-out = <13>; pin-data-out = <&gpio0 13 GPIO_FLAG_NONE>;
pin-data-in = <14>; pin-data-in = <&gpio0 14 GPIO_FLAG_NONE>;
pin-mclk = <0>; pin-mclk = <&gpio0 0 GPIO_FLAG_NONE>;
}; };
uart_port_a: uart1 { uart_port_a: uart1 {
compatible = "espressif,esp32-uart"; compatible = "espressif,esp32-uart";
status = "disabled";
port = <UART_NUM_1>; port = <UART_NUM_1>;
pin-tx = <1>; pin-tx = <&gpio0 1 GPIO_FLAG_NONE>;
pin-rx = <2>; pin-rx = <&gpio0 2 GPIO_FLAG_NONE>;
}; };
}; };

View File

@ -18,16 +18,16 @@
compatible = "espressif,esp32-i2c"; compatible = "espressif,esp32-i2c";
port = <I2C_NUM_0>; port = <I2C_NUM_0>;
clock-frequency = <400000>; clock-frequency = <400000>;
pin-sda = <41>; pin-sda = <&gpio0 41 GPIO_FLAG_NONE>;
pin-scl = <42>; pin-scl = <&gpio0 42 GPIO_FLAG_NONE>;
}; };
spi0 { spi0 {
compatible = "espressif,esp32-spi"; compatible = "espressif,esp32-spi";
host = <SPI2_HOST>; host = <SPI2_HOST>;
pin-mosi = <38>; pin-mosi = <&gpio0 38 GPIO_FLAG_NONE>;
pin-miso = <40>; pin-miso = <&gpio0 40 GPIO_FLAG_NONE>;
pin-sclk = <39>; pin-sclk = <&gpio0 39 GPIO_FLAG_NONE>;
max-transfer-size = <4096>; max-transfer-size = <4096>;
}; };
}; };

View File

@ -19,29 +19,30 @@
compatible = "espressif,esp32-i2c"; compatible = "espressif,esp32-i2c";
port = <I2C_NUM_0>; port = <I2C_NUM_0>;
clock-frequency = <400000>; clock-frequency = <400000>;
pin-sda = <21>; pin-sda = <&gpio0 21 GPIO_FLAG_NONE>;
pin-scl = <22>; pin-scl = <&gpio0 22 GPIO_FLAG_NONE>;
}; };
i2c_grove { i2c_grove {
compatible = "espressif,esp32-i2c"; compatible = "espressif,esp32-i2c";
port = <I2C_NUM_1>; port = <I2C_NUM_1>;
clock-frequency = <400000>; clock-frequency = <400000>;
pin-sda = <32>; pin-sda = <&gpio0 32 GPIO_FLAG_NONE>;
pin-scl = <33>; pin-scl = <&gpio0 33 GPIO_FLAG_NONE>;
}; };
spi0 { spi0 {
compatible = "espressif,esp32-spi"; compatible = "espressif,esp32-spi";
host = <SPI2_HOST>; host = <SPI2_HOST>;
pin-mosi = <15>; pin-mosi = <&gpio0 15 GPIO_FLAG_NONE>;
pin-sclk = <13>; pin-sclk = <&gpio0 13 GPIO_FLAG_NONE>;
}; };
uart_grove: uart1 { uart_grove: uart1 {
compatible = "espressif,esp32-uart"; compatible = "espressif,esp32-uart";
status = "disabled";
port = <UART_NUM_1>; port = <UART_NUM_1>;
pin-tx = <33>; pin-tx = <&gpio0 33 GPIO_FLAG_NONE>;
pin-rx = <32>; pin-rx = <&gpio0 32 GPIO_FLAG_NONE>;
}; };
}; };

View File

@ -18,29 +18,30 @@
compatible = "espressif,esp32-i2c"; compatible = "espressif,esp32-i2c";
port = <I2C_NUM_0>; port = <I2C_NUM_0>;
clock-frequency = <400000>; clock-frequency = <400000>;
pin-sda = <21>; pin-sda = <&gpio0 21 GPIO_FLAG_NONE>;
pin-scl = <22>; pin-scl = <&gpio0 22 GPIO_FLAG_NONE>;
}; };
i2c_grove { i2c_grove {
compatible = "espressif,esp32-i2c"; compatible = "espressif,esp32-i2c";
port = <I2C_NUM_1>; port = <I2C_NUM_1>;
clock-frequency = <400000>; clock-frequency = <400000>;
pin-sda = <32>; pin-sda = <&gpio0 32 GPIO_FLAG_NONE>;
pin-scl = <33>; pin-scl = <&gpio0 33 GPIO_FLAG_NONE>;
}; };
spi0 { spi0 {
compatible = "espressif,esp32-spi"; compatible = "espressif,esp32-spi";
host = <SPI2_HOST>; host = <SPI2_HOST>;
pin-mosi = <15>; pin-mosi = <&gpio0 15 GPIO_FLAG_NONE>;
pin-sclk = <13>; pin-sclk = <&gpio0 13 GPIO_FLAG_NONE>;
}; };
uart_grove: uart1 { uart_grove: uart1 {
compatible = "espressif,esp32-uart"; compatible = "espressif,esp32-uart";
status = "disabled";
port = <UART_NUM_1>; port = <UART_NUM_1>;
pin-tx = <33>; pin-tx = <&gpio0 33 GPIO_FLAG_NONE>;
pin-rx = <32>; pin-rx = <&gpio0 32 GPIO_FLAG_NONE>;
}; };
}; };

View File

@ -18,23 +18,23 @@
compatible = "espressif,esp32-i2c"; compatible = "espressif,esp32-i2c";
port = <I2C_NUM_0>; port = <I2C_NUM_0>;
clock-frequency = <400000>; clock-frequency = <400000>;
pin-sda = <31>; pin-sda = <&gpio0 31 GPIO_FLAG_NONE>;
pin-scl = <32>; pin-scl = <&gpio0 32 GPIO_FLAG_NONE>;
}; };
i2c_port_a { i2c_port_a {
compatible = "espressif,esp32-i2c"; compatible = "espressif,esp32-i2c";
port = <I2C_NUM_1>; port = <I2C_NUM_1>;
clock-frequency = <400000>; clock-frequency = <400000>;
pin-sda = <53>; pin-sda = <&gpio0 53 GPIO_FLAG_NONE>;
pin-scl = <54>; pin-scl = <&gpio0 54 GPIO_FLAG_NONE>;
}; };
sdcard_spi: spi0 { sdcard_spi: spi0 {
compatible = "espressif,esp32-spi"; compatible = "espressif,esp32-spi";
host = <SPI2_HOST>; host = <SPI2_HOST>;
pin-mosi = <44>; pin-mosi = <&gpio0 44 GPIO_FLAG_NONE>;
pin-miso = <39>; pin-miso = <&gpio0 39 GPIO_FLAG_NONE>;
pin-sclk = <43>; pin-sclk = <&gpio0 43 GPIO_FLAG_NONE>;
}; };
}; };

View File

@ -18,16 +18,16 @@
compatible = "espressif,esp32-i2c"; compatible = "espressif,esp32-i2c";
port = <I2C_NUM_0>; port = <I2C_NUM_0>;
clock-frequency = <400000>; clock-frequency = <400000>;
pin-sda = <3>; pin-sda = <&gpio0 3 GPIO_FLAG_NONE>;
pin-scl = <4>; pin-scl = <&gpio0 4 GPIO_FLAG_NONE>;
}; };
sdcard_spi: spi0 { sdcard_spi: spi0 {
compatible = "espressif,esp32-spi"; compatible = "espressif,esp32-spi";
host = <SPI2_HOST>; host = <SPI2_HOST>;
pin-mosi = <40>; pin-mosi = <&gpio0 40 GPIO_FLAG_NONE>;
pin-miso = <41>; pin-miso = <&gpio0 41 GPIO_FLAG_NONE>;
pin-sclk = <39>; pin-sclk = <&gpio0 39 GPIO_FLAG_NONE>;
max-transfer-size = <65536>; max-transfer-size = <65536>;
}; };
}; };

View File

@ -19,21 +19,21 @@
compatible = "espressif,esp32-i2c"; compatible = "espressif,esp32-i2c";
port = <I2C_NUM_0>; port = <I2C_NUM_0>;
clock-frequency = <400000>; clock-frequency = <400000>;
pin-sda = <16>; pin-sda = <&gpio0 16 GPIO_FLAG_NONE>;
pin-scl = <17>; pin-scl = <&gpio0 17 GPIO_FLAG_NONE>;
}; };
spi0 { spi0 {
compatible = "espressif,esp32-spi"; compatible = "espressif,esp32-spi";
host = <SPI2_HOST>; host = <SPI2_HOST>;
pin-mosi = <11>; pin-mosi = <&gpio0 11 GPIO_FLAG_NONE>;
pin-sclk = <12>; pin-sclk = <&gpio0 12 GPIO_FLAG_NONE>;
}; };
uart0 { uart0 {
compatible = "espressif,esp32-uart"; compatible = "espressif,esp32-uart";
port = <UART_NUM_0>; port = <UART_NUM_0>;
pin-tx = <43>; pin-tx = <&gpio0 43 GPIO_FLAG_NONE>;
pin-rx = <44>; pin-rx = <&gpio0 44 GPIO_FLAG_NONE>;
}; };
}; };

View File

@ -19,22 +19,22 @@
compatible = "espressif,esp32-i2c"; compatible = "espressif,esp32-i2c";
port = <I2C_NUM_0>; port = <I2C_NUM_0>;
clock-frequency = <400000>; clock-frequency = <400000>;
pin-sda = <47>; pin-sda = <&gpio0 47 GPIO_FLAG_NONE>;
pin-scl = <48>; pin-scl = <&gpio0 48 GPIO_FLAG_NONE>;
}; };
spi0 { spi0 {
compatible = "espressif,esp32-spi"; compatible = "espressif,esp32-spi";
host = <SPI2_HOST>; host = <SPI2_HOST>;
pin-mosi = <41>; pin-mosi = <&gpio0 41 GPIO_FLAG_NONE>;
pin-sclk = <40>; pin-sclk = <&gpio0 40 GPIO_FLAG_NONE>;
}; };
spi1 { spi1 {
compatible = "espressif,esp32-spi"; compatible = "espressif,esp32-spi";
host = <SPI3_HOST>; host = <SPI3_HOST>;
pin-mosi = <18>; pin-mosi = <&gpio0 18 GPIO_FLAG_NONE>;
pin-miso = <16>; pin-miso = <&gpio0 16 GPIO_FLAG_NONE>;
pin-sclk = <21>; pin-sclk = <&gpio0 21 GPIO_FLAG_NONE>;
}; };
}; };

View File

@ -19,23 +19,23 @@
compatible = "espressif,esp32-i2c"; compatible = "espressif,esp32-i2c";
port = <I2C_NUM_0>; port = <I2C_NUM_0>;
clock-frequency = <400000>; clock-frequency = <400000>;
pin-sda = <6>; pin-sda = <&gpio0 6 GPIO_FLAG_NONE>;
pin-scl = <7>; pin-scl = <&gpio0 7 GPIO_FLAG_NONE>;
}; };
display_spi: spi0 { display_spi: spi0 {
compatible = "espressif,esp32-spi"; compatible = "espressif,esp32-spi";
host = <SPI2_HOST>; host = <SPI2_HOST>;
pin-mosi = <11>; pin-mosi = <&gpio0 11 GPIO_FLAG_NONE>;
pin-miso = <12>; pin-miso = <&gpio0 12 GPIO_FLAG_NONE>;
pin-sclk = <10>; pin-sclk = <&gpio0 10 GPIO_FLAG_NONE>;
}; };
sdcard_spi: spi1 { sdcard_spi: spi1 {
compatible = "espressif,esp32-spi"; compatible = "espressif,esp32-spi";
host = <SPI3_HOST>; host = <SPI3_HOST>;
pin-mosi = <16>; pin-mosi = <&gpio0 16 GPIO_FLAG_NONE>;
pin-miso = <15>; pin-miso = <&gpio0 15 GPIO_FLAG_NONE>;
pin-sclk = <17>; pin-sclk = <&gpio0 17 GPIO_FLAG_NONE>;
}; };
}; };

View File

@ -19,23 +19,22 @@
compatible = "espressif,esp32-i2c"; compatible = "espressif,esp32-i2c";
port = <I2C_NUM_0>; port = <I2C_NUM_0>;
clock-frequency = <400000>; clock-frequency = <400000>;
pin-sda = <42>; pin-sda = <&gpio0 42 GPIO_FLAG_NONE>;
pin-scl = <41>; pin-scl = <&gpio0 41 GPIO_FLAG_NONE>;
}; };
display_spi: spi0 { display_spi: spi0 {
compatible = "espressif,esp32-spi"; compatible = "espressif,esp32-spi";
host = <SPI2_HOST>; host = <SPI2_HOST>;
pin-mosi = <39>; pin-mosi = <&gpio0 39 GPIO_FLAG_NONE>;
pin-miso = <GPIO_PIN_NONE>; pin-sclk = <&gpio0 38 GPIO_FLAG_NONE>;
pin-sclk = <38>;
}; };
sdcard_spi: spi1 { sdcard_spi: spi1 {
compatible = "espressif,esp32-spi"; compatible = "espressif,esp32-spi";
host = <SPI3_HOST>; host = <SPI3_HOST>;
pin-mosi = <15>; pin-mosi = <&gpio0 15 GPIO_FLAG_NONE>;
pin-miso = <17>; pin-miso = <&gpio0 17 GPIO_FLAG_NONE>;
pin-sclk = <16>; pin-sclk = <&gpio0 16 GPIO_FLAG_NONE>;
}; };
}; };

View File

@ -19,22 +19,22 @@
compatible = "espressif,esp32-i2c"; compatible = "espressif,esp32-i2c";
port = <I2C_NUM_0>; port = <I2C_NUM_0>;
clock-frequency = <400000>; clock-frequency = <400000>;
pin-sda = <8>; pin-sda = <&gpio0 8 GPIO_FLAG_NONE>;
pin-scl = <9>; pin-scl = <&gpio0 9 GPIO_FLAG_NONE>;
}; };
spi0 { spi0 {
compatible = "espressif,esp32-spi"; compatible = "espressif,esp32-spi";
host = <SPI2_HOST>; host = <SPI2_HOST>;
pin-mosi = <11>; pin-mosi = <&gpio0 11 GPIO_FLAG_NONE>;
pin-miso = <13>; pin-miso = <&gpio0 13 GPIO_FLAG_NONE>;
pin-sclk = <12>; pin-sclk = <&gpio0 12 GPIO_FLAG_NONE>;
}; };
uart1 { uart1 {
compatible = "espressif,esp32-uart"; compatible = "espressif,esp32-uart";
port = <UART_NUM_1>; port = <UART_NUM_1>;
pin-tx = <43>; pin-tx = <&gpio0 43 GPIO_FLAG_NONE>;
pin-rx = <44>; pin-rx = <&gpio0 44 GPIO_FLAG_NONE>;
}; };
}; };

View File

@ -18,15 +18,15 @@
compatible = "espressif,esp32-i2c"; compatible = "espressif,esp32-i2c";
port = <I2C_NUM_0>; port = <I2C_NUM_0>;
clock-frequency = <400000>; clock-frequency = <400000>;
pin-sda = <6>; pin-sda = <&gpio0 6 GPIO_FLAG_NONE>;
pin-scl = <5>; pin-scl = <&gpio0 5 GPIO_FLAG_NONE>;
}; };
spi0 { spi0 {
compatible = "espressif,esp32-spi"; compatible = "espressif,esp32-spi";
host = <SPI2_HOST>; host = <SPI2_HOST>;
pin-mosi = <40>; pin-mosi = <&gpio0 40 GPIO_FLAG_NONE>;
pin-miso = <38>; pin-miso = <&gpio0 38 GPIO_FLAG_NONE>;
pin-sclk = <39>; pin-sclk = <&gpio0 39 GPIO_FLAG_NONE>;
}; };
}; };

View File

@ -53,7 +53,7 @@ add_custom_command(
"${GENERATED_DIR}/devicetree.h" "${GENERATED_DIR}/devicetree.h"
COMMAND pip install lark==1.3.1 pyyaml==6.0.3 COMMAND pip install lark==1.3.1 pyyaml==6.0.3
COMMAND python "${CMAKE_SOURCE_DIR}/Buildscripts/DevicetreeCompiler/compile.py" COMMAND python "${CMAKE_SOURCE_DIR}/Buildscripts/DevicetreeCompiler/compile.py"
"${DEVICETREE_LOCATION}" "${GENERATED_DIR}" "${DEVICETREE_LOCATION}" "${GENERATED_DIR}"
WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}" WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}"
DEPENDS AlwaysRun "${DEVICETREE_LOCATION}/devicetree.yaml" # AlwaysRun ensures it always gets built DEPENDS AlwaysRun "${DEVICETREE_LOCATION}/devicetree.yaml" # AlwaysRun ensures it always gets built
COMMENT "Generating devicetree source files..." COMMENT "Generating devicetree source files..."

View File

@ -32,7 +32,7 @@ void app_main() {
tt_init_tactility_c(); // ELF bindings for side-loading on ESP32 tt_init_tactility_c(); // ELF bindings for side-loading on ESP32
#endif #endif
tt::run(config, &platform_module, &device_module, devicetree_devices); tt::run(config, &platform_module, &device_module, dts_devices);
} }
} // extern } // extern

View File

@ -16,14 +16,8 @@ properties:
required: true required: true
description: Initial clock frequency in Hz description: Initial clock frequency in Hz
pin-sda: pin-sda:
type: int type: phandle-array
required: true required: true
pin-scl: pin-scl:
type: int type: phandle-array
required: true 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

View File

@ -12,23 +12,22 @@ properties:
The port number, defined by i2s_port_t. The port number, defined by i2s_port_t.
Depending on the hardware, these values are available: I2S_NUM_0, I2S_NUM_1 Depending on the hardware, these values are available: I2S_NUM_0, I2S_NUM_1
pin-bclk: pin-bclk:
type: int type: phandle-array
required: true required: true
description: BCK pin description: Bit clock pin
pin-ws: pin-ws:
type: int type: phandle-array
required: true required: true
description: WS pin description: Word (slot) select pin
pin-data-out: pin-data-out:
type: int type: phandle-array
default: GPIO_PIN_NONE default: GPIO_PIN_SPEC_NONE
description: DATA OUT pin description: Data output pin
pin-data-in: pin-data-in:
type: int type: phandle-array
default: GPIO_PIN_NONE default: GPIO_PIN_SPEC_NONE
description: DATA IN pin description: Data input pin
pin-mclk: pin-mclk:
type: int type: phandle-array
required: false default: GPIO_PIN_SPEC_NONE
default: GPIO_PIN_NONE description: Master clock pin
description: MCLK pin

View File

@ -11,25 +11,24 @@ properties:
description: | description: |
The SPI host (controller) to use. The SPI host (controller) to use.
Defined by spi_host_device_t (e.g. SPI2_HOST, SPI3_HOST). Defined by spi_host_device_t (e.g. SPI2_HOST, SPI3_HOST).
pin-sclk:
type: phandle-array
default: GPIO_PIN_SPEC_NONE
pin-mosi: pin-mosi:
type: int type: phandle-array
default: GPIO_PIN_NONE default: GPIO_PIN_SPEC_NONE
description: MOSI (Data 0) pin description: MOSI (Data 0) pin
pin-miso: pin-miso:
type: int type: phandle-array
default: GPIO_PIN_NONE default: GPIO_PIN_SPEC_NONE
description: MISO (Data 1) pin description: MISO (Data 1) pin
pin-sclk:
type: int
required: true
description: Clock pin
pin-wp: pin-wp:
type: int type: phandle-array
default: GPIO_PIN_NONE default: GPIO_PIN_SPEC_NONE
description: WP (Data 2) pin description: WP (Data 2) pin
pin-hd: pin-hd:
type: int type: phandle-array
default: GPIO_PIN_NONE default: GPIO_PIN_SPEC_NONE
description: HD (Data 3) pin description: HD (Data 3) pin
max-transfer-size: max-transfer-size:
type: int type: int

View File

@ -12,18 +12,18 @@ properties:
The port number, defined by uart_port_t. The port number, defined by uart_port_t.
Depending on the hardware, these values are available: UART_NUM_0, UART_NUM_1, UART_NUM_2 Depending on the hardware, these values are available: UART_NUM_0, UART_NUM_1, UART_NUM_2
pin-tx: pin-tx:
type: int type: phandle-array
required: true required: true
description: TX pin description: TX pin
pin-rx: pin-rx:
type: int type: phandle-array
required: true required: true
description: RX pin description: RX pin
pin-cts: pin-cts:
type: int type: phandle-array
default: GPIO_PIN_NONE default: GPIO_PIN_SPEC_NONE
description: CTS pin description: CTS pin
pin-rts: pin-rts:
type: int type: phandle-array
default: GPIO_PIN_NONE default: GPIO_PIN_SPEC_NONE
description: RTS pin description: RTS pin

View File

@ -5,5 +5,6 @@ file(GLOB_RECURSE SOURCES "Source/*.c**")
idf_component_register( idf_component_register(
SRCS ${SOURCES} SRCS ${SOURCES}
INCLUDE_DIRS "Include/" INCLUDE_DIRS "Include/"
PRIV_INCLUDE_DIRS "Private/"
REQUIRES TactilityKernel driver REQUIRES TactilityKernel driver
) )

View File

@ -9,6 +9,16 @@
extern "C" { extern "C" {
#endif #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) DEFINE_DEVICETREE(esp32_gpio, struct Esp32GpioConfig)
#ifdef __cplusplus #ifdef __cplusplus

View File

@ -3,6 +3,7 @@
#include <tactility/bindings/bindings.h> #include <tactility/bindings/bindings.h>
#include <tactility/drivers/esp32_i2s.h> #include <tactility/drivers/esp32_i2s.h>
#include <tactility/drivers/esp32_gpio.h>
#include <driver/i2s_common.h> #include <driver/i2s_common.h>
#ifdef __cplusplus #ifdef __cplusplus

View File

@ -11,13 +11,10 @@ extern "C" {
struct Esp32I2cConfig { struct Esp32I2cConfig {
i2c_port_t port; i2c_port_t port;
uint32_t clockFrequency; uint32_t clockFrequency;
gpio_pin_t pinSda; struct GpioPinSpec pinSda;
gpio_pin_t pinScl; struct GpioPinSpec pinScl;
bool pinSdaPullUp;
bool pinSclPullUp;
}; };
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif

View File

@ -2,6 +2,7 @@
#pragma once #pragma once
#include <tactility/drivers/i2s_controller.h> #include <tactility/drivers/i2s_controller.h>
#include <tactility/drivers/gpio.h>
#include <driver/i2s_common.h> #include <driver/i2s_common.h>
#ifdef __cplusplus #ifdef __cplusplus
@ -10,11 +11,11 @@ extern "C" {
struct Esp32I2sConfig { struct Esp32I2sConfig {
i2s_port_t port; i2s_port_t port;
int pin_bclk; struct GpioPinSpec pin_bclk;
int pin_ws; struct GpioPinSpec pin_ws;
int pin_data_out; struct GpioPinSpec pin_data_out;
int pin_data_in; struct GpioPinSpec pin_data_in;
int pin_mclk; struct GpioPinSpec pin_mclk;
}; };
#ifdef __cplusplus #ifdef __cplusplus

View File

@ -3,6 +3,7 @@
#include <driver/spi_common.h> #include <driver/spi_common.h>
#include <tactility/drivers/spi_controller.h> #include <tactility/drivers/spi_controller.h>
#include <tactility/drivers/gpio.h>
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
@ -10,16 +11,16 @@ extern "C" {
struct Esp32SpiConfig { struct Esp32SpiConfig {
spi_host_device_t host; spi_host_device_t host;
/** Data 0 pin */
int pin_mosi;
/** Data 1 pin */
int pin_miso;
/** Clock pin */ /** Clock pin */
int pin_sclk; struct GpioPinSpec pin_sclk;
/** Data 0 pin */
struct GpioPinSpec pin_mosi;
/** Data 1 pin */
struct GpioPinSpec pin_miso;
/** Data 2 pin */ /** Data 2 pin */
int pin_wp; struct GpioPinSpec pin_wp;
/** Data 3 pin */ /** Data 3 pin */
int pin_hd; struct GpioPinSpec pin_hd;
/** Data transfer size limit in bytes. 0 means the platform decides the limit. */ /** Data transfer size limit in bytes. 0 means the platform decides the limit. */
int max_transfer_size; int max_transfer_size;
}; };

View File

@ -3,6 +3,7 @@
#include <driver/uart.h> #include <driver/uart.h>
#include <tactility/drivers/uart_controller.h> #include <tactility/drivers/uart_controller.h>
#include <tactility/drivers/gpio.h>
#ifdef __cplusplus #ifdef __cplusplus
extern "C" { extern "C" {
@ -10,10 +11,10 @@ extern "C" {
struct Esp32UartConfig { struct Esp32UartConfig {
uart_port_t port; uart_port_t port;
int pinTx; struct GpioPinSpec pin_tx;
int pinRx; struct GpioPinSpec pin_rx;
int pinCts; struct GpioPinSpec pin_cts;
int pinRts; struct GpioPinSpec pin_rts;
}; };
#ifdef __cplusplus #ifdef __cplusplus

View File

@ -0,0 +1,32 @@
#pragma once
#include <tactility/drivers/gpio_descriptor.h>
#include <driver/gpio.h>
/**
* Releases the given pin descriptor and sets the pointer value to NULL.
* If the descriptor pointer is null, do nothing.
*/
void release_pin(GpioDescriptor** gpio_descriptor);
/**
* Acquires the pin descriptor for the given pin spec.
* If the pin spec is invalid, the pointer is set to null.
* @return true if the pin was acquired successfully
*/
bool acquire_pin_or_set_null(const GpioPinSpec& pin_spec, GpioDescriptor** gpio_descriptor);
/**
* Safely acquire the native pin value.
* Set to GPIO_NUM_NC if the descriptor is null.
* @param[in] descriptor Pin descriptor to acquire
* @return Native pin number
*/
gpio_num_t get_native_pin(GpioDescriptor* descriptor);
/**
* Returns true if the given pin is inverted.
* @param[in] descriptor Pin descriptor to check, nullable
*/
bool is_pin_inverted(GpioDescriptor* descriptor);

View File

@ -8,6 +8,7 @@
#include <tactility/log.h> #include <tactility/log.h>
#include <tactility/drivers/gpio.h> #include <tactility/drivers/gpio.h>
#include <tactility/drivers/gpio_controller.h> #include <tactility/drivers/gpio_controller.h>
#include <tactility/drivers/gpio_descriptor.h>
#define TAG "esp32_gpio" #define TAG "esp32_gpio"
@ -15,40 +16,40 @@
extern "C" { extern "C" {
static error_t set_level(Device* device, gpio_pin_t pin, bool high) { static error_t set_level(GpioDescriptor* descriptor, bool high) {
auto esp_error = gpio_set_level(static_cast<gpio_num_t>(pin), high); auto esp_error = gpio_set_level(static_cast<gpio_num_t>(descriptor->pin), high);
return esp_err_to_error(esp_error); return esp_err_to_error(esp_error);
} }
static error_t get_level(Device* device, gpio_pin_t pin, bool* high) { static error_t get_level(GpioDescriptor* descriptor, bool* high) {
*high = gpio_get_level(static_cast<gpio_num_t>(pin)) != 0; *high = gpio_get_level(static_cast<gpio_num_t>(descriptor->pin)) != 0;
return ERROR_NONE; return ERROR_NONE;
} }
static error_t set_options(Device* device, gpio_pin_t pin, gpio_flags_t options) { static error_t set_flags(GpioDescriptor* descriptor, gpio_flags_t flags) {
const Esp32GpioConfig* config = GET_CONFIG(device); const Esp32GpioConfig* config = GET_CONFIG(descriptor->controller);
if (pin >= config->gpioCount) { if (descriptor->pin >= config->gpioCount) {
return ERROR_INVALID_ARGUMENT; return ERROR_INVALID_ARGUMENT;
} }
gpio_mode_t mode; 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; mode = GPIO_MODE_INPUT_OUTPUT;
} else if (options & GPIO_DIRECTION_INPUT) { } else if (flags & GPIO_FLAG_DIRECTION_INPUT) {
mode = GPIO_MODE_INPUT; mode = GPIO_MODE_INPUT;
} else if (options & GPIO_DIRECTION_OUTPUT) { } else if (flags & GPIO_FLAG_DIRECTION_OUTPUT) {
mode = GPIO_MODE_OUTPUT; mode = GPIO_MODE_OUTPUT;
} else { } else {
return ERROR_INVALID_ARGUMENT; return ERROR_INVALID_ARGUMENT;
} }
const gpio_config_t esp_config = { const gpio_config_t esp_config = {
.pin_bit_mask = 1ULL << pin, .pin_bit_mask = 1ULL << descriptor->pin,
.mode = mode, .mode = mode,
.pull_up_en = (options & GPIO_PULL_UP) ? GPIO_PULLUP_ENABLE : GPIO_PULLUP_DISABLE, .pull_up_en = (flags & GPIO_FLAG_PULL_UP) ? GPIO_PULLUP_ENABLE : GPIO_PULLUP_DISABLE,
.pull_down_en = (options & GPIO_PULL_DOWN) ? GPIO_PULLDOWN_ENABLE : GPIO_PULLDOWN_DISABLE, .pull_down_en = (flags & GPIO_FLAG_PULL_DOWN) ? GPIO_PULLDOWN_ENABLE : GPIO_PULLDOWN_DISABLE,
.intr_type = GPIO_INTERRUPT_FROM_OPTIONS(options), .intr_type = GPIO_FLAG_INTERRUPT_FROM_OPTIONS(flags),
#if SOC_GPIO_SUPPORT_PIN_HYS_FILTER #if SOC_GPIO_SUPPORT_PIN_HYS_FILTER
.hys_ctrl_mode = GPIO_HYS_SOFT_DISABLE .hys_ctrl_mode = GPIO_HYS_SOFT_DISABLE
#endif #endif
@ -58,59 +59,61 @@ static error_t set_options(Device* device, gpio_pin_t pin, gpio_flags_t options)
return esp_err_to_error(esp_error); return esp_err_to_error(esp_error);
} }
static int get_options(Device* device, gpio_pin_t pin, gpio_flags_t* options) { static error_t get_flags(GpioDescriptor* descriptor, gpio_flags_t* flags) {
gpio_io_config_t esp_config; gpio_io_config_t esp_config;
if (gpio_get_io_config(static_cast<gpio_num_t>(pin), &esp_config) != ESP_OK) { if (gpio_get_io_config(static_cast<gpio_num_t>(descriptor->pin), &esp_config) != ESP_OK) {
return ERROR_RESOURCE; return ERROR_RESOURCE;
} }
gpio_flags_t output = 0; gpio_flags_t output = 0;
if (esp_config.pu) { if (esp_config.pu) {
output |= GPIO_PULL_UP; output |= GPIO_FLAG_PULL_UP;
} }
if (esp_config.pd) { if (esp_config.pd) {
output |= GPIO_PULL_DOWN; output |= GPIO_FLAG_PULL_DOWN;
} }
if (esp_config.ie) { if (esp_config.ie) {
output |= GPIO_DIRECTION_INPUT; output |= GPIO_FLAG_DIRECTION_INPUT;
} }
if (esp_config.oe) { if (esp_config.oe) {
output |= GPIO_DIRECTION_OUTPUT; output |= GPIO_FLAG_DIRECTION_OUTPUT;
} }
if (esp_config.oe_inv) { if (esp_config.oe_inv) {
output |= GPIO_ACTIVE_LOW; output |= GPIO_FLAG_ACTIVE_LOW;
} }
*options = output; *flags = output;
return ERROR_NONE; return ERROR_NONE;
} }
error_t get_pin_count(struct Device* device, uint32_t* count) { static error_t get_native_pin_number(GpioDescriptor* descriptor, void* pin_number) {
*count = GET_CONFIG(device)->gpioCount; auto* esp_pin_number = reinterpret_cast<gpio_num_t*>(pin_number);
*esp_pin_number = static_cast<gpio_num_t>(descriptor->pin);
return ERROR_NONE; return ERROR_NONE;
} }
static error_t start(Device* device) { static error_t start(Device* device) {
ESP_LOGI(TAG, "start %s", device->name); ESP_LOGI(TAG, "start %s", device->name);
return ERROR_NONE; auto pin_count = GET_CONFIG(device)->gpioCount;
return gpio_controller_init_descriptors(device, pin_count, nullptr);
} }
static error_t stop(Device* device) { static error_t stop(Device* device) {
ESP_LOGI(TAG, "stop %s", device->name); ESP_LOGI(TAG, "stop %s", device->name);
return ERROR_NONE; return gpio_controller_deinit_descriptors(device);
} }
const static GpioControllerApi esp32_gpio_api = { const static GpioControllerApi esp32_gpio_api = {
.set_level = set_level, .set_level = set_level,
.get_level = get_level, .get_level = get_level,
.set_options = set_options, .set_flags = set_flags,
.get_options = get_options, .get_flags = get_flags,
.get_pin_count = get_pin_count .get_native_pin_number = get_native_pin_number
}; };
extern struct Module platform_module; extern struct Module platform_module;

View File

@ -0,0 +1,40 @@
#include <tactility/drivers/esp32_gpio_helpers.h>
#include <tactility/drivers/gpio_controller.h>
#define TAG "gpio"
void release_pin(GpioDescriptor** gpio_descriptor) {
if (*gpio_descriptor == nullptr) return;
check(gpio_descriptor_release(*gpio_descriptor) == ERROR_NONE);
*gpio_descriptor = nullptr;
}
bool acquire_pin_or_set_null(const GpioPinSpec& pin_spec, GpioDescriptor** gpio_descriptor) {
if (pin_spec.gpio_controller == nullptr) {
*gpio_descriptor = nullptr;
return true;
}
*gpio_descriptor = gpio_descriptor_acquire(pin_spec.gpio_controller, pin_spec.pin, GPIO_OWNER_GPIO);
if (*gpio_descriptor == nullptr) {
LOG_E(TAG, "Failed to acquire pin %u from %s", pin_spec.pin, pin_spec.gpio_controller->name);
}
return *gpio_descriptor != nullptr;
}
gpio_num_t get_native_pin(GpioDescriptor* descriptor) {
if (descriptor != nullptr) {
gpio_num_t pin;
check(gpio_descriptor_get_native_pin_number(descriptor, &pin) == ERROR_NONE);
return pin;
} else {
return GPIO_NUM_NC;
}
}
bool is_pin_inverted(GpioDescriptor* descriptor) {
if (!descriptor) return false;
gpio_flags_t flags;
check(gpio_descriptor_get_flags(descriptor, &flags) == ERROR_NONE);
return (flags & GPIO_FLAG_ACTIVE_LOW) != 0;
}

View File

@ -1,31 +1,38 @@
// SPDX-License-Identifier: Apache-2.0 // SPDX-License-Identifier: Apache-2.0
#include <driver/i2c.h> #include <driver/i2c.h>
#include <tactility/driver.h> #include <new>
#include <tactility/drivers/i2c_controller.h>
#include <tactility/log.h>
#include <tactility/time.h>
#include <tactility/error_esp32.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/drivers/esp32_i2c.h>
#include <tactility/log.h>
#include <tactility/time.h>
#define TAG "esp32_i2c" #define TAG "esp32_i2c"
#define ACK_CHECK_EN 1 #define ACK_CHECK_EN 1
struct Esp32SpiInternal { struct Esp32I2cInternal {
Mutex mutex { 0 }; Mutex mutex {};
GpioDescriptor* sda_descriptor = nullptr;
GpioDescriptor* scl_descriptor = nullptr;
Esp32SpiInternal() { Esp32I2cInternal(GpioDescriptor* sda_descriptor, GpioDescriptor* scl_descriptor) :
sda_descriptor(sda_descriptor),
scl_descriptor(scl_descriptor)
{
mutex_construct(&mutex); mutex_construct(&mutex);
} }
~Esp32SpiInternal() { ~Esp32I2cInternal() {
mutex_destruct(&mutex); mutex_destruct(&mutex);
} }
}; };
#define GET_CONFIG(device) ((Esp32I2cConfig*)device->config) #define GET_CONFIG(device) ((Esp32I2cConfig*)device->config)
#define GET_DATA(device) ((Esp32SpiInternal*)device_get_driver_data(device)) #define GET_DATA(device) ((Esp32I2cInternal*)device_get_driver_data(device))
#define lock(data) mutex_lock(&data->mutex); #define lock(data) mutex_lock(&data->mutex);
#define unlock(data) mutex_unlock(&data->mutex); #define unlock(data) mutex_unlock(&data->mutex);
@ -149,12 +156,35 @@ static error_t start(Device* device) {
ESP_LOGI(TAG, "start %s", device->name); ESP_LOGI(TAG, "start %s", device->name);
auto dts_config = GET_CONFIG(device); 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", scl_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 = { i2c_config_t esp_config = {
.mode = I2C_MODE_MASTER, .mode = I2C_MODE_MASTER,
.sda_io_num = dts_config->pinSda, .sda_io_num = sda_pin,
.scl_io_num = dts_config->pinScl, .scl_io_num = scl_pin,
.sda_pullup_en = dts_config->pinSdaPullUp, .sda_pullup_en = (sda_flags & GPIO_FLAG_PULL_UP) != 0,
.scl_pullup_en = dts_config->pinSclPullUp, .scl_pullup_en = (scl_flags & GPIO_FLAG_PULL_UP) != 0,
.master { .master {
.clk_speed = dts_config->clockFrequency .clk_speed = dts_config->clockFrequency
}, },
@ -164,22 +194,33 @@ static error_t start(Device* device) {
esp_err_t error = i2c_param_config(dts_config->port, &esp_config); esp_err_t error = i2c_param_config(dts_config->port, &esp_config);
if (error != ESP_OK) { if (error != ESP_OK) {
LOG_E(TAG, "Failed to configure port %d: %s", static_cast<int>(dts_config->port), esp_err_to_name(error)); LOG_E(TAG, "Failed to configure port %d: %s", static_cast<int>(dts_config->port), esp_err_to_name(error));
check(gpio_descriptor_release(sda_descriptor) == ERROR_NONE);
check(gpio_descriptor_release(scl_descriptor) == ERROR_NONE);
return ERROR_RESOURCE; return ERROR_RESOURCE;
} }
error = i2c_driver_install(dts_config->port, esp_config.mode, 0, 0, 0); error = i2c_driver_install(dts_config->port, esp_config.mode, 0, 0, 0);
if (error != ESP_OK) { if (error != ESP_OK) {
LOG_E(TAG, "Failed to install driver at port %d: %s", static_cast<int>(dts_config->port), esp_err_to_name(error)); LOG_E(TAG, "Failed to install driver at port %d: %s", static_cast<int>(dts_config->port), esp_err_to_name(error));
check(gpio_descriptor_release(sda_descriptor) == ERROR_NONE);
check(gpio_descriptor_release(scl_descriptor) == ERROR_NONE);
return ERROR_RESOURCE; return ERROR_RESOURCE;
} }
auto* data = new Esp32SpiInternal();
auto* data = new(std::nothrow) Esp32I2cInternal(sda_descriptor, scl_descriptor);
if (data == nullptr) {
check(gpio_descriptor_release(sda_descriptor) == ERROR_NONE);
check(gpio_descriptor_release(scl_descriptor) == ERROR_NONE);
return ERROR_OUT_OF_MEMORY;
}
device_set_driver_data(device, data); device_set_driver_data(device, data);
return ERROR_NONE; return ERROR_NONE;
} }
static error_t stop(Device* device) { static error_t stop(Device* device) {
ESP_LOGI(TAG, "stop %s", device->name); ESP_LOGI(TAG, "stop %s", device->name);
auto* driver_data = static_cast<Esp32SpiInternal*>(device_get_driver_data(device)); auto* driver_data = static_cast<Esp32I2cInternal*>(device_get_driver_data(device));
i2c_port_t port = GET_CONFIG(device)->port; i2c_port_t port = GET_CONFIG(device)->port;
esp_err_t result = i2c_driver_delete(port); esp_err_t result = i2c_driver_delete(port);
@ -188,6 +229,9 @@ static error_t stop(Device* device) {
return ERROR_RESOURCE; 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); device_set_driver_data(device, nullptr);
delete driver_data; delete driver_data;
return ERROR_NONE; return ERROR_NONE;

View File

@ -3,11 +3,14 @@
#include <driver/i2s_common.h> #include <driver/i2s_common.h>
#include <tactility/driver.h> #include <tactility/driver.h>
#include <tactility/drivers/gpio_controller.h>
#include <tactility/drivers/gpio_descriptor.h>
#include <tactility/drivers/i2s_controller.h> #include <tactility/drivers/i2s_controller.h>
#include <tactility/log.h> #include <tactility/log.h>
#include <tactility/time.h> #include <tactility/time.h>
#include <tactility/error_esp32.h> #include <tactility/error_esp32.h>
#include <tactility/drivers/esp32_gpio_helpers.h>
#include <tactility/drivers/esp32_i2s.h> #include <tactility/drivers/esp32_i2s.h>
#include <new> #include <new>
@ -16,21 +19,58 @@
struct Esp32I2sInternal { struct Esp32I2sInternal {
Mutex mutex {}; Mutex mutex {};
i2s_chan_handle_t tx_handle = nullptr;
i2s_chan_handle_t rx_handle = nullptr;
I2sConfig config {}; I2sConfig config {};
bool config_set = false; bool config_set = false;
GpioDescriptor* bclk_descriptor = nullptr;
GpioDescriptor* ws_descriptor = nullptr;
GpioDescriptor* data_out_descriptor = nullptr;
GpioDescriptor* data_in_descriptor = nullptr;
GpioDescriptor* mclk_descriptor = nullptr;
i2s_chan_handle_t tx_handle = nullptr;
i2s_chan_handle_t rx_handle = nullptr;
Esp32I2sInternal() { Esp32I2sInternal() {
mutex_construct(&mutex); mutex_construct(&mutex);
} }
~Esp32I2sInternal() { ~Esp32I2sInternal() {
cleanup_pins();
mutex_destruct(&mutex); mutex_destruct(&mutex);
} }
void cleanup_pins() {
release_pin(&bclk_descriptor);
release_pin(&ws_descriptor);
release_pin(&data_out_descriptor);
release_pin(&data_in_descriptor);
release_pin(&mclk_descriptor);
}
bool init_pins(Esp32I2sConfig* dts_config) {
check (!ws_descriptor && !bclk_descriptor && !data_out_descriptor && !data_in_descriptor && !mclk_descriptor);
auto& ws_spec = dts_config->pin_ws;
auto& bclk_spec = dts_config->pin_bclk;
auto& data_in_spec = dts_config->pin_data_in;
auto& data_out_spec = dts_config->pin_data_out;
auto& mclk_spec = dts_config->pin_mclk;
bool success = acquire_pin_or_set_null(ws_spec, &ws_descriptor) &&
acquire_pin_or_set_null(bclk_spec, &bclk_descriptor) &&
acquire_pin_or_set_null(data_in_spec, &data_in_descriptor) &&
acquire_pin_or_set_null(data_out_spec, &data_out_descriptor) &&
acquire_pin_or_set_null(mclk_spec, &mclk_descriptor);
if (!success) {
cleanup_pins();
LOG_E(TAG, "Failed to acquire all pins");
return false;
}
return true;
}
}; };
#define GET_CONFIG(device) ((Esp32I2sConfig*)device->config) #define GET_CONFIG(device) ((Esp32I2sConfig*)(device)->config)
#define GET_DATA(device) ((Esp32I2sInternal*)device_get_driver_data(device)) #define GET_DATA(device) ((Esp32I2sInternal*)device_get_driver_data(device))
#define lock(data) mutex_lock(&data->mutex); #define lock(data) mutex_lock(&data->mutex);
@ -63,10 +103,10 @@ static i2s_data_bit_width_t to_esp32_bits_per_sample(uint8_t bits) {
} }
} }
static void get_esp32_std_config(const I2sConfig* config, const Esp32I2sConfig* dts_config, i2s_std_config_t* std_cfg) { static void get_esp32_std_config(Esp32I2sInternal* internal, const I2sConfig* config, i2s_std_config_t* std_cfg) {
std_cfg->clk_cfg = I2S_STD_CLK_DEFAULT_CONFIG(config->sample_rate); std_cfg->clk_cfg = I2S_STD_CLK_DEFAULT_CONFIG(config->sample_rate);
std_cfg->slot_cfg = I2S_STD_PHILIPS_SLOT_DEFAULT_CONFIG(to_esp32_bits_per_sample(config->bits_per_sample), I2S_SLOT_MODE_STEREO); std_cfg->slot_cfg = I2S_STD_PHILIPS_SLOT_DEFAULT_CONFIG(to_esp32_bits_per_sample(config->bits_per_sample), I2S_SLOT_MODE_STEREO);
if (config->communication_format & I2S_FORMAT_STAND_MSB) { if (config->communication_format & I2S_FORMAT_STAND_MSB) {
std_cfg->slot_cfg = I2S_STD_MSB_SLOT_DEFAULT_CONFIG(to_esp32_bits_per_sample(config->bits_per_sample), I2S_SLOT_MODE_STEREO); std_cfg->slot_cfg = I2S_STD_MSB_SLOT_DEFAULT_CONFIG(to_esp32_bits_per_sample(config->bits_per_sample), I2S_SLOT_MODE_STEREO);
} else if (config->communication_format & (I2S_FORMAT_STAND_PCM_SHORT | I2S_FORMAT_STAND_PCM_LONG)) { } else if (config->communication_format & (I2S_FORMAT_STAND_PCM_SHORT | I2S_FORMAT_STAND_PCM_LONG)) {
@ -81,16 +121,28 @@ static void get_esp32_std_config(const I2sConfig* config, const Esp32I2sConfig*
std_cfg->slot_cfg.slot_mask = I2S_STD_SLOT_BOTH; std_cfg->slot_cfg.slot_mask = I2S_STD_SLOT_BOTH;
} }
gpio_num_t mclk_pin = get_native_pin(internal->mclk_descriptor);
gpio_num_t bclk_pin = get_native_pin(internal->bclk_descriptor);
gpio_num_t ws_pin = get_native_pin(internal->ws_descriptor);
gpio_num_t data_out_pin = get_native_pin(internal->data_out_descriptor);
gpio_num_t data_in_pin = get_native_pin(internal->data_in_descriptor);
LOG_I(TAG, "Configuring I2S pins: MCLK=%d, BCLK=%d, WS=%d, DATA_OUT=%d, DATA_IN=%d", mclk_pin, bclk_pin, ws_pin, data_out_pin, data_in_pin);
bool mclk_inverted = is_pin_inverted(internal->mclk_descriptor);
bool bclk_inverted = is_pin_inverted(internal->bclk_descriptor);
bool ws_inverted = is_pin_inverted(internal->ws_descriptor);
LOG_I(TAG, "Inverted pins: MCLK=%u, BCLK=%u, WS=%u", mclk_inverted, bclk_inverted, ws_inverted);
std_cfg->gpio_cfg = { std_cfg->gpio_cfg = {
.mclk = (gpio_num_t)dts_config->pin_mclk, .mclk = mclk_pin,
.bclk = (gpio_num_t)dts_config->pin_bclk, .bclk = bclk_pin,
.ws = (gpio_num_t)dts_config->pin_ws, .ws = ws_pin,
.dout = (gpio_num_t)dts_config->pin_data_out, .dout = data_out_pin,
.din = (gpio_num_t)dts_config->pin_data_in, .din = data_in_pin,
.invert_flags = { .invert_flags = {
.mclk_inv = false, .mclk_inv = mclk_inverted,
.bclk_inv = false, .bclk_inv = bclk_inverted,
.ws_inv = false .ws_inv = ws_inverted
} }
}; };
} }
@ -129,46 +181,46 @@ static error_t set_config(Device* device, const struct I2sConfig* config) {
return ERROR_INVALID_ARGUMENT; return ERROR_INVALID_ARGUMENT;
} }
auto* driver_data = GET_DATA(device); auto* internal = GET_DATA(device);
auto* dts_config = GET_CONFIG(device); auto* dts_config = GET_CONFIG(device);
lock(driver_data); lock(internal);
cleanup_channel_handles(driver_data); cleanup_channel_handles(internal);
driver_data->config_set = false; internal->config_set = false;
// Create new channel handles // Create new channel handles
i2s_chan_config_t chan_cfg = I2S_CHANNEL_DEFAULT_CONFIG(dts_config->port, I2S_ROLE_MASTER); i2s_chan_config_t chan_cfg = I2S_CHANNEL_DEFAULT_CONFIG(dts_config->port, I2S_ROLE_MASTER);
esp_err_t esp_error = i2s_new_channel(&chan_cfg, &driver_data->tx_handle, &driver_data->rx_handle); esp_err_t esp_error = i2s_new_channel(&chan_cfg, &internal->tx_handle, &internal->rx_handle);
if (esp_error != ESP_OK) { if (esp_error != ESP_OK) {
LOG_E(TAG, "Failed to create I2S channels: %s", esp_err_to_name(esp_error)); LOG_E(TAG, "Failed to create I2S channels: %s", esp_err_to_name(esp_error));
unlock(driver_data); unlock(internal);
return ERROR_RESOURCE; return ERROR_RESOURCE;
} }
i2s_std_config_t std_cfg; i2s_std_config_t std_cfg = {};
get_esp32_std_config(config, dts_config, &std_cfg); get_esp32_std_config(internal, config, &std_cfg);
if (driver_data->tx_handle) { if (internal->tx_handle) {
esp_error = i2s_channel_init_std_mode(driver_data->tx_handle, &std_cfg); esp_error = i2s_channel_init_std_mode(internal->tx_handle, &std_cfg);
if (esp_error == ESP_OK) esp_error = i2s_channel_enable(driver_data->tx_handle); if (esp_error == ESP_OK) esp_error = i2s_channel_enable(internal->tx_handle);
} }
if (esp_error == ESP_OK && driver_data->rx_handle) { if (esp_error == ESP_OK && internal->rx_handle) {
esp_error = i2s_channel_init_std_mode(driver_data->rx_handle, &std_cfg); esp_error = i2s_channel_init_std_mode(internal->rx_handle, &std_cfg);
if (esp_error == ESP_OK) esp_error = i2s_channel_enable(driver_data->rx_handle); if (esp_error == ESP_OK) esp_error = i2s_channel_enable(internal->rx_handle);
} }
if (esp_error != ESP_OK) { if (esp_error != ESP_OK) {
LOG_E(TAG, "Failed to initialize/enable I2S channels: %s", esp_err_to_name(esp_error)); LOG_E(TAG, "Failed to initialize/enable I2S channels: %s", esp_err_to_name(esp_error));
cleanup_channel_handles(driver_data); cleanup_channel_handles(internal);
unlock(driver_data); unlock(internal);
return esp_err_to_error(esp_error); return esp_err_to_error(esp_error);
} }
// Update runtime config to reflect current state // Update runtime config to reflect current state
memcpy(&driver_data->config, config, sizeof(I2sConfig)); memcpy(&internal->config, config, sizeof(I2sConfig));
driver_data->config_set = true; internal->config_set = true;
unlock(driver_data); unlock(internal);
return ERROR_NONE; return ERROR_NONE;
} }
@ -188,9 +240,18 @@ static error_t get_config(Device* device, struct I2sConfig* config) {
static error_t start(Device* device) { static error_t start(Device* device) {
ESP_LOGI(TAG, "start %s", device->name); ESP_LOGI(TAG, "start %s", device->name);
auto* dts_config = GET_CONFIG(device);
auto* data = new(std::nothrow) Esp32I2sInternal(); auto* data = new(std::nothrow) Esp32I2sInternal();
if (!data) return ERROR_OUT_OF_MEMORY; if (!data) return ERROR_OUT_OF_MEMORY;
if (!data->init_pins(dts_config)) {
LOG_E(TAG, "Failed to init one or more pins");
delete data;
return ERROR_RESOURCE;
}
device_set_driver_data(device, data); device_set_driver_data(device, data);
return ERROR_NONE; return ERROR_NONE;

View File

@ -3,6 +3,8 @@
#include <tactility/drivers/esp32_spi.h> #include <tactility/drivers/esp32_spi.h>
#include <tactility/concurrent/recursive_mutex.h> #include <tactility/concurrent/recursive_mutex.h>
#include "tactility/drivers/gpio_descriptor.h"
#include <tactility/drivers/esp32_gpio_helpers.h>
#include <cstring> #include <cstring>
#include <esp_log.h> #include <esp_log.h>
#include <new> #include <new>
@ -19,13 +21,29 @@ struct Esp32SpiInternal {
RecursiveMutex mutex = {}; RecursiveMutex mutex = {};
bool initialized = false; bool initialized = false;
Esp32SpiInternal() { // Pin descriptors
GpioDescriptor* sclk_descriptor = nullptr;
GpioDescriptor* mosi_descriptor = nullptr;
GpioDescriptor* miso_descriptor = nullptr;
GpioDescriptor* wp_descriptor = nullptr;
GpioDescriptor* hd_descriptor = nullptr;
explicit Esp32SpiInternal() {
recursive_mutex_construct(&mutex); recursive_mutex_construct(&mutex);
} }
~Esp32SpiInternal() { ~Esp32SpiInternal() {
cleanup_pins();
recursive_mutex_destruct(&mutex); recursive_mutex_destruct(&mutex);
} }
void cleanup_pins() {
release_pin(&sclk_descriptor);
release_pin(&mosi_descriptor);
release_pin(&miso_descriptor);
release_pin(&wp_descriptor);
release_pin(&hd_descriptor);
}
}; };
static error_t lock(Device* device) { static error_t lock(Device* device) {
@ -50,19 +68,35 @@ static error_t unlock(Device* device) {
static error_t start(Device* device) { static error_t start(Device* device) {
ESP_LOGI(TAG, "start %s", device->name); ESP_LOGI(TAG, "start %s", device->name);
auto* data = new(std::nothrow) Esp32SpiInternal(); auto* data = new (std::nothrow) Esp32SpiInternal();
if (!data) return ERROR_OUT_OF_MEMORY; if (!data) return ERROR_OUT_OF_MEMORY;
device_set_driver_data(device, data); device_set_driver_data(device, data);
auto* dts_config = GET_CONFIG(device); auto* dts_config = GET_CONFIG(device);
// Acquire pins from the specified GPIO pin specs. Optional pins are allowed.
bool pins_ok =
acquire_pin_or_set_null(dts_config->pin_sclk, &data->sclk_descriptor) &&
acquire_pin_or_set_null(dts_config->pin_mosi, &data->mosi_descriptor) &&
acquire_pin_or_set_null(dts_config->pin_miso, &data->miso_descriptor) &&
acquire_pin_or_set_null(dts_config->pin_wp, &data->wp_descriptor) &&
acquire_pin_or_set_null(dts_config->pin_hd, &data->hd_descriptor);
if (!pins_ok) {
ESP_LOGE(TAG, "Failed to acquire required SPI pins");
data->cleanup_pins();
device_set_driver_data(device, nullptr);
delete data;
return ERROR_RESOURCE;
}
spi_bus_config_t buscfg = { spi_bus_config_t buscfg = {
.mosi_io_num = dts_config->pin_mosi, .mosi_io_num = get_native_pin(data->mosi_descriptor),
.miso_io_num = dts_config->pin_miso, .miso_io_num = get_native_pin(data->miso_descriptor),
.sclk_io_num = dts_config->pin_sclk, .sclk_io_num = get_native_pin(data->sclk_descriptor),
.data2_io_num = dts_config->pin_wp, .data2_io_num = get_native_pin(data->wp_descriptor),
.data3_io_num = dts_config->pin_hd, .data3_io_num = get_native_pin(data->hd_descriptor),
.data4_io_num = GPIO_NUM_NC, .data4_io_num = GPIO_NUM_NC,
.data5_io_num = GPIO_NUM_NC, .data5_io_num = GPIO_NUM_NC,
.data6_io_num = GPIO_NUM_NC, .data6_io_num = GPIO_NUM_NC,
@ -76,8 +110,9 @@ static error_t start(Device* device) {
esp_err_t ret = spi_bus_initialize(dts_config->host, &buscfg, SPI_DMA_CH_AUTO); esp_err_t ret = spi_bus_initialize(dts_config->host, &buscfg, SPI_DMA_CH_AUTO);
if (ret != ESP_OK) { if (ret != ESP_OK) {
delete data; data->cleanup_pins();
device_set_driver_data(device, nullptr); device_set_driver_data(device, nullptr);
delete data;
ESP_LOGE(TAG, "Failed to initialize SPI bus: %s", esp_err_to_name(ret)); ESP_LOGE(TAG, "Failed to initialize SPI bus: %s", esp_err_to_name(ret));
return ERROR_RESOURCE; return ERROR_RESOURCE;
} }
@ -95,6 +130,7 @@ static error_t stop(Device* device) {
spi_bus_free(dts_config->host); spi_bus_free(dts_config->host);
} }
driver_data->cleanup_pins();
device_set_driver_data(device, nullptr); device_set_driver_data(device, nullptr);
delete driver_data; delete driver_data;
return ERROR_NONE; return ERROR_NONE;

View File

@ -9,6 +9,8 @@
#include <tactility/error_esp32.h> #include <tactility/error_esp32.h>
#include <tactility/log.h> #include <tactility/log.h>
#include <tactility/time.h> #include <tactility/time.h>
#include <tactility/drivers/gpio_descriptor.h>
#include <tactility/drivers/esp32_gpio_helpers.h>
#include <new> #include <new>
@ -20,13 +22,27 @@ struct Esp32UartInternal {
bool config_set = false; bool config_set = false;
bool is_open = false; bool is_open = false;
// Pin descriptors
GpioDescriptor* tx_descriptor = nullptr;
GpioDescriptor* rx_descriptor = nullptr;
GpioDescriptor* cts_descriptor = nullptr;
GpioDescriptor* rts_descriptor = nullptr;
Esp32UartInternal() { Esp32UartInternal() {
mutex_construct(&mutex); mutex_construct(&mutex);
} }
~Esp32UartInternal() { ~Esp32UartInternal() {
cleanup_pins();
mutex_destruct(&mutex); mutex_destruct(&mutex);
} }
void cleanup_pins() {
release_pin(&tx_descriptor);
release_pin(&rx_descriptor);
release_pin(&cts_descriptor);
release_pin(&rts_descriptor);
}
}; };
#define GET_CONFIG(device) ((Esp32UartConfig*)device->config) #define GET_CONFIG(device) ((Esp32UartConfig*)device->config)
@ -254,7 +270,7 @@ static error_t open(Device* device) {
} }
}; };
if (dts_config->pinCts != UART_PIN_NO_CHANGE || dts_config->pinRts != UART_PIN_NO_CHANGE) { if (dts_config->pin_cts.gpio_controller != nullptr || dts_config->pin_rts.gpio_controller != nullptr) {
LOG_W(TAG, "%s: CTS/RTS pins are defined but hardware flow control is disabled (not supported in UartConfig)", device->name); LOG_W(TAG, "%s: CTS/RTS pins are defined but hardware flow control is disabled (not supported in UartConfig)", device->name);
} }
@ -266,9 +282,31 @@ static error_t open(Device* device) {
return ERROR_RESOURCE; return ERROR_RESOURCE;
} }
esp_error = uart_set_pin(dts_config->port, dts_config->pinTx, dts_config->pinRx, dts_config->pinCts, dts_config->pinRts); // Acquire pins from the specified GPIO pin specs. Optional pins are allowed.
bool pins_ok =
acquire_pin_or_set_null(dts_config->pin_tx, &driver_data->tx_descriptor) &&
acquire_pin_or_set_null(dts_config->pin_rx, &driver_data->rx_descriptor) &&
acquire_pin_or_set_null(dts_config->pin_cts, &driver_data->cts_descriptor) &&
acquire_pin_or_set_null(dts_config->pin_rts, &driver_data->rts_descriptor);
if (!pins_ok) {
LOG_E(TAG, "%s failed to acquire UART pins", device->name);
driver_data->cleanup_pins();
uart_driver_delete(dts_config->port);
unlock(driver_data);
return ERROR_RESOURCE;
}
esp_error = uart_set_pin(dts_config->port,
get_native_pin(driver_data->tx_descriptor),
get_native_pin(driver_data->rx_descriptor),
get_native_pin(driver_data->rts_descriptor),
get_native_pin(driver_data->cts_descriptor)
);
if (esp_error != ESP_OK) { if (esp_error != ESP_OK) {
LOG_E(TAG, "%s failed to set uart pins: %s", device->name, esp_err_to_name(esp_error)); LOG_E(TAG, "%s failed to set uart pins: %s", device->name, esp_err_to_name(esp_error));
driver_data->cleanup_pins();
uart_driver_delete(dts_config->port); uart_driver_delete(dts_config->port);
unlock(driver_data); unlock(driver_data);
return ERROR_RESOURCE; return ERROR_RESOURCE;
@ -293,6 +331,7 @@ static error_t close(Device* device) {
return ERROR_INVALID_STATE; return ERROR_INVALID_STATE;
} }
uart_driver_delete(dts_config->port); uart_driver_delete(dts_config->port);
driver_data->cleanup_pins();
driver_data->is_open = false; driver_data->is_open = false;
unlock(driver_data); unlock(driver_data);

View File

@ -7,6 +7,10 @@
#include <Tactility/hal/Configuration.h> #include <Tactility/hal/Configuration.h>
#include <Tactility/service/ServiceManifest.h> #include <Tactility/service/ServiceManifest.h>
extern "C" {
struct DtsDevice;
}
namespace tt { namespace tt {
/** @brief The configuration for the operating system /** @brief The configuration for the operating system
@ -21,9 +25,9 @@ struct Configuration {
* @brief Main entry point for Tactility. * @brief Main entry point for Tactility.
* @param platformModule Platform module to start (non-null). * @param platformModule Platform module to start (non-null).
* @param deviceModule Device module to start (non-null). * @param deviceModule Device module to start (non-null).
* @param devicetreeDevices Null-terminated array where an entry { NULL, NULL } marks the end of the list. * @param dtsDevices Array that is terminated with DTS_DEVICE_TERMINATOR
*/ */
void run(const Configuration& config, Module* platformModule, Module* deviceModule, CompatibleDevice devicetreeDevices[]); void run(const Configuration& config, Module* platformModule, Module* deviceModule, struct DtsDevice dtsDevices[]);
/** /**
* While technically nullable, this instance is always set if tt_init() succeeds. * While technically nullable, this instance is always set if tt_init() succeeds.

View File

@ -32,7 +32,7 @@
#include <tactility/lvgl_module.h> #include <tactility/lvgl_module.h>
#ifdef ESP_PLATFORM #ifdef ESP_PLATFORM
#include "tactility/drivers/root.h" #include <tactility/drivers/root.h>
#include <Tactility/InitEsp.h> #include <Tactility/InitEsp.h>
#endif #endif
@ -320,13 +320,13 @@ void registerApps() {
registerInstalledAppsFromSdCards(); registerInstalledAppsFromSdCards();
} }
void run(const Configuration& config, Module* platformModule, Module* deviceModule, CompatibleDevice devicetreeDevices[]) { void run(const Configuration& config, Module* platformModule, Module* deviceModule, DtsDevice dtsDevices[]) {
LOGGER.info("Tactility v{} on {} ({})", TT_VERSION, CONFIG_TT_DEVICE_NAME, CONFIG_TT_DEVICE_ID); LOGGER.info("Tactility v{} on {} ({})", TT_VERSION, CONFIG_TT_DEVICE_NAME, CONFIG_TT_DEVICE_ID);
assert(config.hardware); assert(config.hardware);
LOGGER.info(R"(Calling kernel_init with modules: "{}" and "{}")", platformModule->name, deviceModule->name); LOGGER.info(R"(Calling kernel_init with modules: "{}" and "{}")", platformModule->name, deviceModule->name);
if (kernel_init(platformModule, deviceModule, devicetreeDevices) != ERROR_NONE) { if (kernel_init(platformModule, deviceModule, dtsDevices) != ERROR_NONE) {
LOGGER.error("Failed to initialize kernel"); LOGGER.error("Failed to initialize kernel");
return; return;
} }

View File

@ -7,22 +7,16 @@
extern "C" { extern "C" {
#endif #endif
/** Logical GPIO pin identifier used by the HAL. Typically maps to the SoC GPIO number. */ /** @deprecated NON-FUNCTIONAL - WILL BE REMOVED SOON */
typedef unsigned int GpioPin; typedef unsigned int GpioPin;
/** Value indicating that no GPIO pin is used/applicable. */
/** @deprecated NON-FUNCTIONAL - WILL BE REMOVED SOON */
#define GPIO_NO_PIN -1 #define GPIO_NO_PIN -1
/** Read the current logic level of a pin. /** @deprecated NON-FUNCTIONAL - WILL BE REMOVED SOON */
* The pin should be configured for input or input/output.
* @param[in] pin The pin to read.
* @return true if the level is high, false if low. If the pin is invalid, the
* behavior is implementation-defined and may return false.
*/
bool tt_hal_gpio_get_level(GpioPin pin); bool tt_hal_gpio_get_level(GpioPin pin);
/** Get the number of GPIO pins available on this platform. /** @deprecated NON-FUNCTIONAL - WILL BE REMOVED SOON */
* @return The count of valid GPIO pins.
*/
int tt_hal_gpio_get_pin_count(); int tt_hal_gpio_get_pin_count();
#ifdef __cplusplus #ifdef __cplusplus

View File

@ -7,33 +7,12 @@ extern "C" {
using namespace tt::hal; using namespace tt::hal;
static Device* find_first_gpio_controller() {
Device* device_result = nullptr;
device_for_each_of_type(&GPIO_CONTROLLER_TYPE, &device_result, [](Device* device, void* context) {
if (device_is_ready(device)) {
auto** device_result_ptr = static_cast<Device**>(context);
*device_result_ptr = device;
return false;
}
return true;
});
return device_result;
}
bool tt_hal_gpio_get_level(GpioPin pin) { bool tt_hal_gpio_get_level(GpioPin pin) {
Device* device_result = find_first_gpio_controller(); return false;
if (device_result == nullptr) return false;
bool pin_state = false;
if (gpio_controller_get_level(device_result, pin, &pin_state) != ERROR_NONE) return false;
return pin_state;
} }
int tt_hal_gpio_get_pin_count() { int tt_hal_gpio_get_pin_count() {
Device* device_result = find_first_gpio_controller(); return 0;
if (device_result == nullptr) return 0;
uint32_t pin_count = 0;
if (gpio_controller_get_pin_count(device_result, &pin_count) != ERROR_NONE) return 0;
return (int)pin_count;
} }
} }

View File

@ -53,6 +53,7 @@
#include <driver/i2s_common.h> #include <driver/i2s_common.h>
#include <driver/i2s_std.h> #include <driver/i2s_std.h>
#include <driver/gpio.h>
extern "C" { extern "C" {
@ -374,7 +375,11 @@ const esp_elfsym main_symbols[] {
ESP_ELFSYM_EXPORT(esp_netif_get_handle_from_ifkey), ESP_ELFSYM_EXPORT(esp_netif_get_handle_from_ifkey),
// Locale // Locale
ESP_ELFSYM_EXPORT(localeconv), 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_new_channel),
ESP_ELFSYM_EXPORT(i2s_del_channel), ESP_ELFSYM_EXPORT(i2s_del_channel),
ESP_ELFSYM_EXPORT(i2s_channel_enable), 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_register_event_callback),
ESP_ELFSYM_EXPORT(i2s_channel_preload_data), ESP_ELFSYM_EXPORT(i2s_channel_preload_data),
ESP_ELFSYM_EXPORT(i2s_channel_tune_rate), 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_init_std_mode),
ESP_ELFSYM_EXPORT(i2s_channel_reconfig_std_clock), ESP_ELFSYM_EXPORT(i2s_channel_reconfig_std_clock),
ESP_ELFSYM_EXPORT(i2s_channel_reconfig_std_slot), ESP_ELFSYM_EXPORT(i2s_channel_reconfig_std_slot),

View File

@ -43,16 +43,6 @@ struct Device {
struct DeviceInternal* internal; struct DeviceInternal* internal;
}; };
/**
* Holds a device pointer and a compatible string.
* The device must not be constructed, added or started yet.
* This is used by the devicetree code generator and the application init sequence.
*/
struct CompatibleDevice {
struct Device* device;
const char* compatible;
};
/** /**
* Initialize the properties of a device. * Initialize the properties of a device.
* *

View File

@ -10,24 +10,24 @@ extern "C" {
#include <stdbool.h> #include <stdbool.h>
#include <stdint.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_DIRECTION_INPUT (1 << 1)
#define GPIO_DIRECTION_OUTPUT (1 << 2)
#define GPIO_DIRECTION_INPUT_OUTPUT (GPIO_DIRECTION_INPUT | GPIO_DIRECTION_OUTPUT)
#define GPIO_PULL_UP (0 << 3)
#define GPIO_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_PIN_NONE -1 #define GPIO_PIN_NONE -1
#define GPIO_PIN_SPEC_NONE ((struct GpioPinSpec) { NULL, 0, GPIO_FLAG_NONE })
#define GPIO_FLAG_NONE 0
#define GPIO_FLAG_ACTIVE_HIGH (0 << 0)
#define GPIO_FLAG_ACTIVE_LOW (1 << 0)
#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_FLAG_PULL_UP (0 << 3)
#define GPIO_FLAG_PULL_DOWN (1 << 4)
#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))
typedef enum { typedef enum {
GPIO_INTERRUPT_DISABLE = 0, GPIO_INTERRUPT_DISABLE = 0,
GPIO_INTERRUPT_POS_EDGE = 1, GPIO_INTERRUPT_POS_EDGE = 1,
@ -35,35 +35,39 @@ typedef enum {
GPIO_INTERRUPT_ANY_EDGE = 3, GPIO_INTERRUPT_ANY_EDGE = 3,
GPIO_INTERRUPT_LOW_LEVEL = 4, GPIO_INTERRUPT_LOW_LEVEL = 4,
GPIO_INTERRUPT_HIGH_LEVEL = 5, GPIO_INTERRUPT_HIGH_LEVEL = 5,
GPIO__MAX, GPIO_MAX,
} GpioInterruptType; } GpioInterruptType;
enum GpioOwnerType {
/** @brief Pin is unclaimed/free */
GPIO_OWNER_NONE,
/** @brief Pin is owned by a hog */
GPIO_OWNER_HOG,
/** @brief Pin is claimed by a regular consumer */
GPIO_OWNER_GPIO,
/** @brief Pin is owned by SPI. This is a special case because of CS pin transfer from hog to SPI controller. */
GPIO_OWNER_SPI
};
/** The index of a GPIO pin on a GPIO Controller */ /** The index of a GPIO pin on a GPIO Controller */
typedef uint8_t gpio_pin_t; typedef uint8_t gpio_pin_t;
/** Specifies the configuration flags for a GPIO pin (or set of pins) */ /** Specifies the configuration flags for a GPIO pin (or set of pins) */
typedef uint16_t gpio_flags_t; typedef uint16_t gpio_flags_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 */ /** GPIO device controlling the pin */
const struct Device* port; struct Device* gpio_controller;
/** The pin's number on the device */ /** The pin's number on the device */
gpio_pin_t pin; gpio_pin_t pin;
/** The pin's configuration flags as specified in devicetree */ /** The pin's configuration flags as specified in devicetree */
gpio_flags_t flags; 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 #ifdef __cplusplus
} }
#endif #endif

View File

@ -10,106 +10,136 @@ extern "C" {
#include <tactility/error.h> #include <tactility/error.h>
struct Device; struct Device;
struct GpioDescriptor;
struct GpioControllerApi { struct GpioControllerApi {
/** /**
* @brief Sets the logical level of a GPIO pin. * @brief Sets the logical level of a GPIO pin.
* @param[in] device the GPIO controller device * @param[in,out] descriptor the pin descriptor
* @param[in] pin the pin index
* @param[in] high true to set the pin high, false to set it low * @param[in] high true to set the pin high, false to set it low
* @return ERROR_NONE if successful * @return ERROR_NONE if successful
*/ */
error_t (*set_level)(struct Device* device, gpio_pin_t pin, bool high); error_t (*set_level)(struct GpioDescriptor* descriptor, bool high);
/** /**
* @brief Gets the logical level of a GPIO pin. * @brief Gets the logical level of a GPIO pin.
* @param[in] device the GPIO controller device * @param[in] descriptor the pin descriptor
* @param[in] pin the pin index
* @param[out] high pointer to store the pin level * @param[out] high pointer to store the pin level
* @return ERROR_NONE if successful * @return ERROR_NONE if successful
*/ */
error_t (*get_level)(struct Device* device, gpio_pin_t pin, bool* high); error_t (*get_level)(struct GpioDescriptor* descriptor, bool* high);
/** /**
* @brief Configures the options for a GPIO pin. * @brief Configures the options for a GPIO pin.
* @param[in] device the GPIO controller device * @param[in,out] descriptor the pin descriptor
* @param[in] pin the pin index * @param[in] flags configuration flags (direction, pull-up/down, etc.)
* @param[in] options configuration flags (direction, pull-up/down, etc.)
* @return ERROR_NONE if successful * @return ERROR_NONE if successful
*/ */
error_t (*set_options)(struct Device* device, gpio_pin_t pin, gpio_flags_t options); error_t (*set_flags)(struct GpioDescriptor* descriptor, gpio_flags_t flags);
/** /**
* @brief Gets the configuration options for a GPIO pin. * @brief Gets the configuration options for a GPIO pin.
* @param[in] device the GPIO controller device * @param[in] descriptor the pin descriptor
* @param[in] pin the pin index * @param[out] flags pointer to store the configuration flags
* @param[out] options pointer to store the configuration flags
* @return ERROR_NONE if successful * @return ERROR_NONE if successful
*/ */
error_t (*get_options)(struct Device* device, gpio_pin_t pin, gpio_flags_t* options); error_t (*get_flags)(struct GpioDescriptor* descriptor, gpio_flags_t* flags);
/** /**
* @brief Gets the number of pins supported by the controller. * @brief Gets the native pin number associated with a descriptor.
* @param[in] device the GPIO controller device * @param[in] descriptor the pin descriptor
* @param[out] count pointer to store the number of pins * @param[out] pin_number pointer to store the pin number
* @return ERROR_NONE if successful * @return ERROR_NONE if successful
*/ */
error_t (*get_pin_count)(struct Device* device, uint32_t* count); error_t (*get_native_pin_number)(struct GpioDescriptor* descriptor, void* pin_number);
}; };
struct GpioDescriptor* gpio_descriptor_acquire(
struct Device* controller,
gpio_pin_t pin_number,
enum GpioOwnerType owner
);
error_t gpio_descriptor_release(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 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. * @brief Sets the logical level of a GPIO pin.
* @param[in] device the GPIO controller device * @param[in] descriptor the pin descriptor
* @param[in] pin the pin index
* @param[in] high true to set the pin high, false to set it low * @param[in] high true to set the pin high, false to set it low
* @return ERROR_NONE if successful * @return ERROR_NONE if successful
*/ */
error_t gpio_controller_set_level(struct Device* device, gpio_pin_t pin, bool high); error_t gpio_descriptor_set_level(struct GpioDescriptor* descriptor, bool high);
/** /**
* @brief Gets the logical level of a GPIO pin. * @brief Gets the logical level of a GPIO pin.
* @param[in] device the GPIO controller device * @param[in] descriptor the pin descriptor
* @param[in] pin the pin index
* @param[out] high pointer to store the pin level * @param[out] high pointer to store the pin level
* @return ERROR_NONE if successful * @return ERROR_NONE if successful
*/ */
error_t gpio_controller_get_level(struct Device* device, gpio_pin_t pin, bool* high); error_t gpio_descriptor_get_level(struct GpioDescriptor* descriptor, bool* high);
/** /**
* @brief Configures the options for a GPIO pin. * @brief Configures the options for a GPIO pin.
* @param[in] device the GPIO controller device * @param[in] descriptor the pin descriptor
* @param[in] pin the pin index * @param[in] flags configuration flags (direction, pull-up/down, etc.)
* @param[in] options configuration flags (direction, pull-up/down, etc.)
* @return ERROR_NONE if successful * @return ERROR_NONE if successful
*/ */
error_t gpio_controller_set_options(struct Device* device, gpio_pin_t pin, 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. * @brief Gets the configuration options for a GPIO pin.
* @param[in] device the GPIO controller device * @param[in] descriptor the pin descriptor
* @param[in] pin the pin index * @param[out] flags pointer to store the configuration flags
* @param[out] options pointer to store the configuration flags
* @return ERROR_NONE if successful * @return ERROR_NONE if successful
*/ */
error_t gpio_controller_get_options(struct Device* device, gpio_pin_t pin, gpio_flags_t* options); error_t gpio_descriptor_get_flags(struct GpioDescriptor* descriptor, gpio_flags_t* flags);
/** /**
* @brief Gets the number of pins supported by the controller. * @brief Gets the native pin number associated with a descriptor.
* @param[in] device the GPIO controller device * @param[in] descriptor the pin descriptor
* @param[out] count pointer to store the number of pins * @param[out] pin_number pointer to store the pin number
* @return ERROR_NONE if successful * @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); error_t gpio_controller_get_pin_count(struct Device* device, uint32_t* count);
/** /**
* @brief Configures the options for a GPIO pin using a pin configuration structure. * @brief Initializes GPIO descriptors for a controller.
* @param[in] device the GPIO controller device * @param[in,out] device the GPIO controller device
* @param[in] config the pin configuration structure * @param[in] controller_context pointer to store in the controller's internal data
* @return ERROR_NONE if successful * @return ERROR_NONE if successful
*/ */
static inline error_t gpio_set_options_config(struct Device* device, const struct GpioPinConfig* config) { error_t gpio_controller_init_descriptors(struct Device* device, uint32_t pin_count, void* controller_context);
return gpio_controller_set_options(device, config->pin, config->flags);
} /**
* @brief Deinitializes GPIO descriptors for a controller.
* @param[in,out] device the GPIO controller device
* @return ERROR_NONE if successful
*/
error_t gpio_controller_deinit_descriptors(struct Device* device);
extern const struct DeviceType GPIO_CONTROLLER_TYPE; extern const struct DeviceType GPIO_CONTROLLER_TYPE;

View File

@ -0,0 +1,16 @@
#pragma once
#include "gpio.h"
struct Device;
struct GpioDescriptor {
/** @brief The controller that owns this pin */
struct Device* controller;
/** @brief Physical pin number */
gpio_pin_t pin;
/** @brief Current owner */
enum GpioOwnerType owner_type;
/** @brief Implementation-specific context (e.g. from esp32 controller internally) */
void* controller_context;
};

View File

@ -0,0 +1,30 @@
#pragma once
#include <stddef.h>
struct Device;
/** Signals the intended state of a device. */
enum DtsDeviceStatus {
/** Device should be constructed, added and started. */
DTS_DEVICE_STATUS_OKAY,
/** Device should be constructed and added, but not started. */
DTS_DEVICE_STATUS_DISABLED
};
/**
* Holds a device pointer and a compatible string.
* The device must not be constructed, added or started yet.
* This is used by the devicetree code generator and the application init sequence.
*/
struct DtsDevice {
/** A pointer to a device. */
struct Device* device;
/** The compatible string contains the identifier of the driver that this device is compatible with. */
const char* compatible;
/** The intended state of the device. */
const enum DtsDeviceStatus status;
};
/** Signals the end of the device array in the generated dts code. */
#define DTS_DEVICE_TERMINATOR { NULL, NULL, DTS_DEVICE_STATUS_DISABLED }

View File

@ -12,10 +12,10 @@ extern "C" {
* Initialize the kernel with platform and device modules, and a device tree. * Initialize the kernel with platform and device modules, and a device tree.
* @param platform_module The platform module to start. This module should not be constructed yet. * @param platform_module The platform module to start. This module should not be constructed yet.
* @param device_module The device module to start. This module should not be constructed yet. This parameter can be NULL. * @param device_module The device module to start. This module should not be constructed yet. This parameter can be NULL.
* @param devicetree_devices The list of generated devices from the devicetree. The array must be terminated by an entry { NULL, NULL }. This parameter can be NULL. * @param dts_devices The list of generated devices from the devicetree. The array must be terminated with DTS_DEVICE_TERMINATOR. This parameter can be NULL.
* @return ERROR_NONE on success, otherwise an error code * @return ERROR_NONE on success, otherwise an error code
*/ */
error_t kernel_init(struct Module* platform_module, struct Module* device_module, struct CompatibleDevice devicetree_devices[]); error_t kernel_init(struct Module* platform_module, struct Module* device_module, struct DtsDevice dts_devices[]);
#ifdef __cplusplus #ifdef __cplusplus
} }

View File

@ -3,33 +3,136 @@
#include <tactility/driver.h> #include <tactility/driver.h>
#include <tactility/drivers/gpio_controller.h> #include <tactility/drivers/gpio_controller.h>
#define GPIO_DRIVER_API(driver) ((struct GpioControllerApi*)driver->api) #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" { extern "C" {
error_t gpio_controller_set_level(Device* device, gpio_pin_t pin, bool high) { struct GpioControllerData {
const auto* driver = device_get_driver(device); struct Mutex mutex {};
return GPIO_DRIVER_API(driver)->set_level(device, pin, high); uint32_t pin_count;
struct GpioDescriptor* descriptors = nullptr;
explicit GpioControllerData(uint32_t pin_count) : pin_count(pin_count) {
mutex_construct(&mutex);
}
error_t init_descriptors(Device* device, void* controller_context) {
descriptors = (struct GpioDescriptor*)calloc(pin_count, sizeof(struct GpioDescriptor));
if (!descriptors) return ERROR_OUT_OF_MEMORY;
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;
}
return ERROR_NONE;
}
~GpioControllerData() {
if (descriptors != nullptr) {
free(descriptors);
}
mutex_destruct(&mutex);
}
};
struct GpioDescriptor* gpio_descriptor_acquire(
struct Device* controller,
gpio_pin_t pin_number,
enum GpioOwnerType owner
) {
check(owner != GPIO_OWNER_NONE);
auto* data = (struct GpioControllerData*)device_get_driver_data(controller);
mutex_lock(&data->mutex);
if (pin_number >= data->pin_count) {
mutex_unlock(&data->mutex);
return nullptr;
}
struct GpioDescriptor* desc = &data->descriptors[pin_number];
if (desc->owner_type != GPIO_OWNER_NONE) {
mutex_unlock(&data->mutex);
return nullptr;
}
desc->owner_type = owner;
mutex_unlock(&data->mutex);
return desc;
} }
error_t gpio_controller_get_level(Device* device, gpio_pin_t pin, bool* high) { error_t gpio_descriptor_release(struct GpioDescriptor* descriptor) {
const auto* driver = device_get_driver(device); descriptor->owner_type = GPIO_OWNER_NONE;
return GPIO_DRIVER_API(driver)->get_level(device, pin, high); return ERROR_NONE;
}
error_t gpio_controller_set_options(Device* device, gpio_pin_t pin, gpio_flags_t options) {
const auto* driver = device_get_driver(device);
return GPIO_DRIVER_API(driver)->set_options(device, pin, options);
}
error_t gpio_controller_get_options(Device* device, gpio_pin_t pin, gpio_flags_t* options) {
const auto* driver = device_get_driver(device);
return GPIO_DRIVER_API(driver)->get_options(device, pin, options);
} }
error_t gpio_controller_get_pin_count(struct Device* device, uint32_t* count) { error_t gpio_controller_get_pin_count(struct Device* device, uint32_t* count) {
const auto* driver = device_get_driver(device); auto* data = (struct GpioControllerData*)device_get_driver_data(device);
return GPIO_DRIVER_API(driver)->get_pin_count(device, count); *count = data->pin_count;
return ERROR_NONE;
}
error_t gpio_controller_init_descriptors(struct Device* device, uint32_t pin_count, void* controller_context) {
auto* data = new(std::nothrow) GpioControllerData(pin_count);
if (!data) return ERROR_OUT_OF_MEMORY;
if (data->init_descriptors(device, controller_context) != ERROR_NONE) {
delete data;
return ERROR_OUT_OF_MEMORY;
}
device_set_driver_data(device, data);
return ERROR_NONE;
}
error_t gpio_controller_deinit_descriptors(struct Device* device) {
auto* data = static_cast<struct GpioControllerData*>(device_get_driver_data(device));
delete data;
device_set_driver_data(device, nullptr);
return ERROR_NONE;
}
error_t gpio_descriptor_set_level(struct GpioDescriptor* descriptor, bool high) {
const auto* driver = device_get_driver(descriptor->controller);
return GPIO_INTERNAL_API(driver)->set_level(descriptor, high);
}
error_t gpio_descriptor_get_level(struct GpioDescriptor* descriptor, bool* high) {
const auto* driver = device_get_driver(descriptor->controller);
return GPIO_INTERNAL_API(driver)->get_level(descriptor, high);
}
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_flags(descriptor, flags);
}
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_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_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 { const struct DeviceType GPIO_CONTROLLER_TYPE {

View File

@ -1,3 +1,4 @@
#include "tactility/dts.h"
#include <tactility/kernel_init.h> #include <tactility/kernel_init.h>
#include <tactility/log.h> #include <tactility/log.h>
@ -27,7 +28,7 @@ struct Module root_module = {
.internal = nullptr .internal = nullptr
}; };
error_t kernel_init(struct Module* platform_module, struct Module* device_module, struct CompatibleDevice devicetree_devices[]) { error_t kernel_init(struct Module* platform_module, struct Module* device_module, struct DtsDevice dts_devices[]) {
LOG_I(TAG, "init"); LOG_I(TAG, "init");
if (module_construct_add_start(&root_module) != ERROR_NONE) { if (module_construct_add_start(&root_module) != ERROR_NONE) {
@ -47,14 +48,23 @@ error_t kernel_init(struct Module* platform_module, struct Module* device_module
} }
} }
if (devicetree_devices) { if (dts_devices) {
CompatibleDevice* compatible_device = devicetree_devices; DtsDevice* dts_device = dts_devices;
while (compatible_device->device != nullptr) { while (dts_device->device != nullptr) {
if (device_construct_add_start(compatible_device->device, compatible_device->compatible) != ERROR_NONE) { if (dts_device->status == DTS_DEVICE_STATUS_OKAY) {
LOG_E(TAG, "kernel_init failed to construct device: %s (%s)", compatible_device->device->name, compatible_device->compatible); if (device_construct_add_start(dts_device->device, dts_device->compatible) != ERROR_NONE) {
return ERROR_RESOURCE; LOG_E(TAG, "kernel_init failed to construct+add+start device: %s (%s)", dts_device->device->name, dts_device->compatible);
return ERROR_RESOURCE;
}
} else if (dts_device->status == DTS_DEVICE_STATUS_DISABLED) {
if (device_construct_add(dts_device->device, dts_device->compatible) != ERROR_NONE) {
LOG_E(TAG, "kernel_init failed to construct+add device: %s (%s)", dts_device->device->name, dts_device->compatible);
return ERROR_RESOURCE;
}
} else {
check(false, "DTS status not implemented");
} }
compatible_device++; dts_device++;
} }
} }

View File

@ -59,11 +59,18 @@ const struct ModuleSymbol KERNEL_SYMBOLS[] = {
DEFINE_MODULE_SYMBOL(driver_find_compatible), DEFINE_MODULE_SYMBOL(driver_find_compatible),
DEFINE_MODULE_SYMBOL(driver_get_device_type), DEFINE_MODULE_SYMBOL(driver_get_device_type),
// drivers/gpio_controller // drivers/gpio_controller
DEFINE_MODULE_SYMBOL(gpio_controller_set_level), DEFINE_MODULE_SYMBOL(gpio_descriptor_acquire),
DEFINE_MODULE_SYMBOL(gpio_controller_get_level), DEFINE_MODULE_SYMBOL(gpio_descriptor_release),
DEFINE_MODULE_SYMBOL(gpio_controller_set_options), DEFINE_MODULE_SYMBOL(gpio_descriptor_set_level),
DEFINE_MODULE_SYMBOL(gpio_controller_get_options), DEFINE_MODULE_SYMBOL(gpio_descriptor_get_level),
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_get_pin_count),
DEFINE_MODULE_SYMBOL(gpio_controller_init_descriptors),
DEFINE_MODULE_SYMBOL(gpio_controller_deinit_descriptors),
DEFINE_MODULE_SYMBOL(GPIO_CONTROLLER_TYPE), DEFINE_MODULE_SYMBOL(GPIO_CONTROLLER_TYPE),
// drivers/i2c_controller // drivers/i2c_controller
DEFINE_MODULE_SYMBOL(i2c_controller_read), DEFINE_MODULE_SYMBOL(i2c_controller_read),