From 8c4bfc2260e3387e294eb902da338d99498037f1 Mon Sep 17 00:00:00 2001 From: Ken Van Hoeylandt Date: Sun, 11 Oct 2026 01:20:13 +0200 Subject: [PATCH] posix drivers, mock drivers and struct Driver changes --- CMakeLists.txt | 1 + Devices/cl32-v04/source/cl32_v4_keyboard.cpp | 1 - Devices/cl32-v04/source/cl32_v4_light.cpp | 1 - Devices/cl32-v04/source/cl32_v4_power.cpp | 2 - .../source/drivers/papers3_display.cpp | 1 - .../source/drivers/papers3_power.cpp | 3 +- .../Source/devices/tab5_keyboard.cpp | 1 - .../Source/devices/tab5_power_control.cpp | 1 - .../simulator/Source/drivers/sdl_display.cpp | 4 +- .../simulator/Source/drivers/sdl_keyboard.cpp | 4 +- .../simulator/Source/drivers/sdl_pointer.cpp | 4 +- Devices/simulator/module.yaml | 1 + Devices/simulator/simulator.dts | 5 + .../source/drivers/unphone_nav_buttons.cpp | 1 - .../source/drivers/unphone_power_switch.cpp | 1 - Documentation/ideas.md | 2 +- Drivers/ads1115-module/source/ads1115.cpp | 2 - .../source/audio_stream.cpp | 1 - .../source/audio_stream_open_race_test.cpp | 1 - Drivers/aw88298-module/source/aw88298.cpp | 1 - Drivers/aw9523b-module/source/aw9523b.cpp | 2 - Drivers/axp192-module/source/axp192.cpp | 5 - .../axp192-module/source/axp192_backlight.cpp | 2 - Drivers/axp2101-module/source/axp2101.cpp | 5 - .../source/axp2101_backlight.cpp | 2 - Drivers/axs5106-module/source/axs5106.cpp | 3 - Drivers/bm8563-module/source/bm8563.cpp | 2 - Drivers/bmi270-module/source/bmi270.cpp | 2 - Drivers/bq24295-module/source/bq24295.cpp | 5 - Drivers/bq25896-module/source/bq25896.cpp | 3 - Drivers/bq27220-module/source/bq27220.cpp | 3 - .../source/button_control.cpp | 3 - Drivers/ch422g-module/source/ch422g.cpp | 2 - Drivers/cst328-module/source/cst328.cpp | 3 - Drivers/cst66xx-module/source/cst66xx.cpp | 3 - Drivers/cst816s-module/source/cst816s.cpp | 2 - Drivers/cst816t-module/source/cst816t.cpp | 3 - Drivers/drv2605-module/source/drv2605.cpp | 2 - .../source/dummy_i2s_amp.cpp | 1 - Drivers/es7210-module/source/es7210.cpp | 1 - Drivers/es7243e-module/source/es7243e.cpp | 2 - Drivers/es8311-module/source/es8311.cpp | 1 - Drivers/es8388-module/source/es8388.cpp | 1 - .../esp-epaper-module/source/esp_epaper.cpp | 2 - .../source/esp32_dac_speaker.cpp | 1 - .../source/esp32_led_strip.cpp | 4 - Drivers/ft5x06-module/source/ft5x06.cpp | 2 - Drivers/ft6x36-module/source/ft6x36.cpp | 3 - Drivers/gc0308-module/source/gc0308.cpp | 2 - Drivers/gc9a01-module/source/gc9a01.cpp | 2 - .../gdeq031t10-module/source/gdeq031t10.cpp | 2 - .../source/gpio_encoder.cpp | 3 - .../source/gpio_trackball.cpp | 3 - .../source/gps_meshtastic.cpp | 1 - Drivers/gt911-module/source/gt911.cpp | 2 - Drivers/hx8357-module/source/hx8357.cpp | 2 - Drivers/ili9341-module/source/ili9341.cpp | 2 - Drivers/ili9488-module/source/ili9488.cpp | 2 - Drivers/ili9881c-module/source/ili9881c.cpp | 2 - Drivers/ina226-module/source/ina226.cpp | 3 - Drivers/jd9165-module/source/jd9165.cpp | 2 - Drivers/jd9853-module/source/jd9853.cpp | 2 - .../lilygo-module/source/tdeck_keyboard.cpp | 3 - .../source/tdeck_keyboard_backlight.cpp | 3 - .../source/t5s3_display.cpp | 2 - Drivers/lp5814-module/source/lp5814.cpp | 2 - Drivers/m5pm1-module/source/m5pm1.cpp | 3 - .../source/cardputer_adv_keyboard.cpp | 2 - .../source/cardputer_keyboard.cpp | 3 - Drivers/mock-drivers-module/CMakeLists.txt | 11 + .../mock-drivers-module/LICENSE-Apache-2.0.md | 195 ++++++++++ .../bindings/mock,wifi.yaml | 8 + .../include/bindings/mock_wifi.h | 7 + .../include/mock/mock_wifi.h | 14 + .../include/mock_drivers_module.h | 14 + Drivers/mock-drivers-module/module.yaml | 3 + .../mock-drivers-module/source}/mock_wifi.cpp | 19 +- Drivers/mock-drivers-module/source/module.cpp | 23 ++ Drivers/mpu6886-module/source/mpu6886.cpp | 2 - Drivers/nv3031b-module/source/nv3031b.cpp | 2 - Drivers/pdm-mic-module/source/pdm_mic.cpp | 1 - .../source/pi4ioe5v6408.cpp | 2 - .../source/py32ioexpander.cpp | 2 - Drivers/qmi8658-module/source/qmi8658.cpp | 2 - .../rgb-display-module/source/rgb_display.cpp | 2 - Drivers/rx8130ce-module/source/rx8130ce.cpp | 2 - Drivers/sc2356-module/source/sc2356.cpp | 2 - Drivers/ssd1306-module/source/ssd1306.cpp | 2 - Drivers/st7121-module/source/st7121.cpp | 2 - Drivers/st7123-module/source/st7123.cpp | 2 - Drivers/st7123-module/source/st7123_touch.cpp | 2 - Drivers/st7305-module/source/st7305.cpp | 2 - Drivers/st7701-module/source/st7701.cpp | 2 - Drivers/st7735-module/source/st7735.cpp | 2 - .../source/st7789_i8080.cpp | 2 - Drivers/st7789-module/source/st7789.cpp | 2 - .../source/st7789_soft_i8080.cpp | 2 - .../source/st7796_i8080.cpp | 2 - Drivers/st7796-module/source/st7796.cpp | 2 - Drivers/sx126x-module/source/sx1262.cpp | 3 - Drivers/sy6970-module/source/sy6970.cpp | 3 - Drivers/tca8418-module/source/tca8418.cpp | 3 - Drivers/tca9534-module/source/tca9534.cpp | 2 - .../tca95xx-16bit-module/source/tca95xx.cpp | 1 - Drivers/xl9555-module/source/xl9555.cpp | 2 - Drivers/xpt2046-module/source/xpt2046.cpp | 3 - .../source/xpt2046_softspi.cpp | 4 - .../source/drivers/bluetooth/esp32_ble.cpp | 1 - .../drivers/bluetooth/esp32_ble_hid.cpp | 1 - .../drivers/bluetooth/esp32_ble_midi.cpp | 1 - .../drivers/bluetooth/esp32_ble_spp.cpp | 1 - .../source/drivers/esp32_adc_oneshot.cpp | 3 - .../source/drivers/esp32_gpio.cpp | 3 - .../source/drivers/esp32_grove.cpp | 3 - .../source/drivers/esp32_i2c_master.cpp | 3 - .../source/drivers/esp32_i2s.cpp | 3 - .../source/drivers/esp32_i8080.cpp | 3 - .../source/drivers/esp32_pwm_ledc.cpp | 3 - .../source/drivers/esp32_sdmmc.cpp | 3 - .../source/drivers/esp32_sdspi.cpp | 3 - .../source/drivers/esp32_spi.cpp | 3 - .../source/drivers/esp32_uart.cpp | 3 - .../source/drivers/esp32_wifi.cpp | 3 - .../source/drivers/esp32_wifi_pinned.cpp | 3 - .../drivers/usb/esp32_usb_cdc_device.cpp | 1 - .../usb/esp32_usb_device_controller.cpp | 1 - .../drivers/usb/esp32_usb_device_msc.cpp | 1 - .../drivers/usb/esp32_usb_hid_device.cpp | 1 - .../drivers/usb/esp32_usb_midi_device.cpp | 1 - .../source/drivers/usb/esp32_usbhost.cpp | 1 - .../source/drivers/usb/esp32_usbhost_hid.cpp | 2 - .../source/drivers/usb/esp32_usbhost_midi.cpp | 1 - .../source/drivers/usb/esp32_usbhost_msc.cpp | 1 - .../source/drivers/usb/esp32_usbhost_uac.cpp | 1 - Platforms/platform-posix/CMakeLists.txt | 2 +- .../platform-posix/bindings/posix,i2c.yaml | 11 + .../platform-posix/bindings/posix,uart.yaml | 11 + .../include/tactility/bindings/posix_i2c.h | 15 + .../include/tactility/bindings/posix_uart.h | 15 + .../include/tactility/drivers/posix_i2c.h | 17 + .../include/tactility/drivers/posix_uart.h | 16 + Platforms/platform-posix/module.yaml | 1 + .../source/drivers/posix_i2c.cpp | 171 +++++++++ .../source/drivers/posix_uart.cpp | 363 ++++++++++++++++++ Platforms/platform-posix/source/module.cpp | 6 +- .../Source/bluetooth/BluetoothHidHost.cpp | 1 - TactilityKernel/include/tactility/driver.h | 12 +- .../private/tactility/driver_internal.h | 20 + TactilityKernel/source/driver.cpp | 15 +- .../source/drivers/battery_sense.cpp | 2 - .../source/drivers/gpio_backlight.cpp | 3 - TactilityKernel/source/drivers/gpio_hog.cpp | 3 - .../source/drivers/pwm_backlight.cpp | 3 - .../source/drivers/rgb_led_gpio.cpp | 3 - .../source/drivers/rgb_led_pwm.cpp | 3 - TactilityKernel/source/drivers/root.cpp | 1 - TactilityKernel/source/module.cpp | 5 +- TactilityKernel/source/symbols.c | 1 + .../tests/source/device_get_put_test.cpp | 8 - .../tests/source/device_hotplug_test.cpp | 9 - TactilityKernel/tests/source/device_test.cpp | 8 - .../tests/source/driver_integration_test.cpp | 8 - TactilityKernel/tests/source/driver_test.cpp | 25 +- .../tests/source/keyboard_test.cpp | 9 - TactilityKernel/tests/source/module_test.cpp | 17 + 165 files changed, 997 insertions(+), 353 deletions(-) create mode 100644 Drivers/mock-drivers-module/CMakeLists.txt create mode 100644 Drivers/mock-drivers-module/LICENSE-Apache-2.0.md create mode 100644 Drivers/mock-drivers-module/bindings/mock,wifi.yaml create mode 100644 Drivers/mock-drivers-module/include/bindings/mock_wifi.h create mode 100644 Drivers/mock-drivers-module/include/mock/mock_wifi.h create mode 100644 Drivers/mock-drivers-module/include/mock_drivers_module.h create mode 100644 Drivers/mock-drivers-module/module.yaml rename {Platforms/platform-posix/source/drivers => Drivers/mock-drivers-module/source}/mock_wifi.cpp (96%) create mode 100644 Drivers/mock-drivers-module/source/module.cpp create mode 100644 Platforms/platform-posix/bindings/posix,i2c.yaml create mode 100644 Platforms/platform-posix/bindings/posix,uart.yaml create mode 100644 Platforms/platform-posix/include/tactility/bindings/posix_i2c.h create mode 100644 Platforms/platform-posix/include/tactility/bindings/posix_uart.h create mode 100644 Platforms/platform-posix/include/tactility/drivers/posix_i2c.h create mode 100644 Platforms/platform-posix/include/tactility/drivers/posix_uart.h create mode 100644 Platforms/platform-posix/source/drivers/posix_i2c.cpp create mode 100644 Platforms/platform-posix/source/drivers/posix_uart.cpp create mode 100644 TactilityKernel/private/tactility/driver_internal.h diff --git a/CMakeLists.txt b/CMakeLists.txt index 2a6948362..7a89c78a7 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -182,6 +182,7 @@ if (NOT DEFINED ENV{ESP_IDF_VERSION}) add_subdirectory(Modules/lvgl-window-manager-module) add_subdirectory(Drivers/gps-generic-module) add_subdirectory(Drivers/gps-meshtastic-module) + add_subdirectory(Drivers/mock-drivers-module) # Kernel-only software aggregate; built on sim so its device-lifecycle behavior # is covered by Drivers/audio-stream-module/tests. add_subdirectory(Drivers/audio-stream-module) diff --git a/Devices/cl32-v04/source/cl32_v4_keyboard.cpp b/Devices/cl32-v04/source/cl32_v4_keyboard.cpp index 229098eb2..e5a349ce3 100644 --- a/Devices/cl32-v04/source/cl32_v4_keyboard.cpp +++ b/Devices/cl32-v04/source/cl32_v4_keyboard.cpp @@ -324,6 +324,5 @@ Driver cl32_v4_keyboard_driver = { .probe = nullptr, .api = &cl32_v4_keyboard_api, .device_type = &KEYBOARD_TYPE, - .owner = &cl32_v04_module, .internal = nullptr, }; diff --git a/Devices/cl32-v04/source/cl32_v4_light.cpp b/Devices/cl32-v04/source/cl32_v4_light.cpp index e7fdeb050..d6ca8b5c4 100644 --- a/Devices/cl32-v04/source/cl32_v4_light.cpp +++ b/Devices/cl32-v04/source/cl32_v4_light.cpp @@ -70,6 +70,5 @@ Driver cl32_v4_light_driver = { .probe = nullptr, .api = &CL32_V4_LIGHT_API, .device_type = &BACKLIGHT_TYPE, - .owner = &cl32_v04_module, .internal = nullptr, }; diff --git a/Devices/cl32-v04/source/cl32_v4_power.cpp b/Devices/cl32-v04/source/cl32_v4_power.cpp index 0f1d4a2ed..6aea97207 100644 --- a/Devices/cl32-v04/source/cl32_v4_power.cpp +++ b/Devices/cl32-v04/source/cl32_v4_power.cpp @@ -101,7 +101,6 @@ Driver cl32_v4_power_supply_driver = { .stop_device = nullptr, .api = &CL32_V4_POWER_SUPPLY_API, .device_type = &POWER_SUPPLY_TYPE, - .owner = &cl32_v04_module, .internal = nullptr }; @@ -192,6 +191,5 @@ Driver cl32_v4_power_driver = { .probe = nullptr, .api = nullptr, .device_type = nullptr, - .owner = &cl32_v04_module, .internal = nullptr, }; diff --git a/Devices/m5stack-papers3/source/drivers/papers3_display.cpp b/Devices/m5stack-papers3/source/drivers/papers3_display.cpp index b3c3f596d..876d3c9be 100644 --- a/Devices/m5stack-papers3/source/drivers/papers3_display.cpp +++ b/Devices/m5stack-papers3/source/drivers/papers3_display.cpp @@ -422,7 +422,6 @@ Driver papers3_display_driver = { .stop_device = stop, .api = &papers3_display_api, .device_type = &DISPLAY_TYPE, - .owner = &m5stack_papers3_module, .internal = nullptr }; diff --git a/Devices/m5stack-papers3/source/drivers/papers3_power.cpp b/Devices/m5stack-papers3/source/drivers/papers3_power.cpp index 83faf20dc..9e2b20208 100644 --- a/Devices/m5stack-papers3/source/drivers/papers3_power.cpp +++ b/Devices/m5stack-papers3/source/drivers/papers3_power.cpp @@ -144,7 +144,6 @@ Driver papers3_power_supply_driver = { .stop_device = nullptr, .api = &PAPERS3_POWER_SUPPLY_API, .device_type = &POWER_SUPPLY_TYPE, - .owner = &m5stack_papers3_module, .internal = nullptr }; @@ -259,9 +258,9 @@ Driver papers3_power_driver = { .compatible = (const char*[]) { "m5stack,papers3-power", nullptr }, .start_device = start, .stop_device = stop, + .probe = nullptr, .api = nullptr, .device_type = nullptr, - .owner = &m5stack_papers3_module, .internal = nullptr }; diff --git a/Devices/m5stack-tab5/Source/devices/tab5_keyboard.cpp b/Devices/m5stack-tab5/Source/devices/tab5_keyboard.cpp index 098e5eb07..1e0e7a19b 100644 --- a/Devices/m5stack-tab5/Source/devices/tab5_keyboard.cpp +++ b/Devices/m5stack-tab5/Source/devices/tab5_keyboard.cpp @@ -672,7 +672,6 @@ Driver tab5_keyboard_driver = { .probe = probe, .api = &tab5_keyboard_api, .device_type = &KEYBOARD_TYPE, - .owner = &m5stack_tab5_module, .internal = nullptr }; diff --git a/Devices/m5stack-tab5/Source/devices/tab5_power_control.cpp b/Devices/m5stack-tab5/Source/devices/tab5_power_control.cpp index 8788b7bba..cd417f161 100644 --- a/Devices/m5stack-tab5/Source/devices/tab5_power_control.cpp +++ b/Devices/m5stack-tab5/Source/devices/tab5_power_control.cpp @@ -190,6 +190,5 @@ Driver tab5_power_control_driver = { .stop_device = stop, .api = &TAB5_POWER_CONTROL_API, .device_type = &POWER_SUPPLY_TYPE, - .owner = &m5stack_tab5_module, .internal = nullptr }; diff --git a/Devices/simulator/Source/drivers/sdl_display.cpp b/Devices/simulator/Source/drivers/sdl_display.cpp index 6f613138f..1c1fa2da0 100644 --- a/Devices/simulator/Source/drivers/sdl_display.cpp +++ b/Devices/simulator/Source/drivers/sdl_display.cpp @@ -225,8 +225,8 @@ Driver sdl_display_driver = { .compatible = (const char*[]) { "tactility,sdl-display", nullptr }, .start_device = start, .stop_device = stop, + .probe = nullptr, .api = &sdl_display_api, .device_type = &DISPLAY_TYPE, - .owner = &simulator_module, - .internal = nullptr + .internal = nullptr, }; diff --git a/Devices/simulator/Source/drivers/sdl_keyboard.cpp b/Devices/simulator/Source/drivers/sdl_keyboard.cpp index 82e1bbef3..c03ad978c 100644 --- a/Devices/simulator/Source/drivers/sdl_keyboard.cpp +++ b/Devices/simulator/Source/drivers/sdl_keyboard.cpp @@ -44,8 +44,8 @@ Driver sdl_keyboard_driver = { .compatible = (const char*[]) { "tactility,sdl-keyboard", nullptr }, .start_device = start, .stop_device = stop, + .probe = nullptr, .api = &sdl_keyboard_api, .device_type = &KEYBOARD_TYPE, - .owner = &simulator_module, - .internal = nullptr + .internal = nullptr, }; diff --git a/Devices/simulator/Source/drivers/sdl_pointer.cpp b/Devices/simulator/Source/drivers/sdl_pointer.cpp index 0ca628c00..152f4a9ae 100644 --- a/Devices/simulator/Source/drivers/sdl_pointer.cpp +++ b/Devices/simulator/Source/drivers/sdl_pointer.cpp @@ -59,8 +59,8 @@ Driver sdl_pointer_driver = { .compatible = (const char*[]) { "tactility,sdl-pointer", nullptr }, .start_device = start, .stop_device = stop, + .probe = nullptr, .api = &sdl_pointer_api, .device_type = &POINTER_TYPE, - .owner = &simulator_module, - .internal = nullptr + .internal = nullptr, }; diff --git a/Devices/simulator/module.yaml b/Devices/simulator/module.yaml index b6a0ebdab..0e7f3941c 100644 --- a/Devices/simulator/module.yaml +++ b/Devices/simulator/module.yaml @@ -1,3 +1,4 @@ dependencies: - Platforms/platform-posix + - Drivers/mock-drivers-module dts: simulator.dts diff --git a/Devices/simulator/simulator.dts b/Devices/simulator/simulator.dts index d3c0fe018..42d00b266 100644 --- a/Devices/simulator/simulator.dts +++ b/Devices/simulator/simulator.dts @@ -1,8 +1,13 @@ /dts-v1/; #include +#include / { model = "Simulator"; compatible = "root"; + + wifi0 { + compatible = "mock,wifi"; + }; }; diff --git a/Devices/unphone/source/drivers/unphone_nav_buttons.cpp b/Devices/unphone/source/drivers/unphone_nav_buttons.cpp index a14e4c56a..cacb291ad 100644 --- a/Devices/unphone/source/drivers/unphone_nav_buttons.cpp +++ b/Devices/unphone/source/drivers/unphone_nav_buttons.cpp @@ -199,7 +199,6 @@ Driver unphone_nav_buttons_driver = { .stop_device = stop, .api = nullptr, .device_type = nullptr, - .owner = &unphone_module, .internal = nullptr }; diff --git a/Devices/unphone/source/drivers/unphone_power_switch.cpp b/Devices/unphone/source/drivers/unphone_power_switch.cpp index fdfcb26ab..80b2e2198 100644 --- a/Devices/unphone/source/drivers/unphone_power_switch.cpp +++ b/Devices/unphone/source/drivers/unphone_power_switch.cpp @@ -76,7 +76,6 @@ Driver unphone_power_switch_driver = { .stop_device = stop, .api = nullptr, .device_type = nullptr, - .owner = &unphone_module, .internal = nullptr }; diff --git a/Documentation/ideas.md b/Documentation/ideas.md index 2fde4e2f7..f7a477c2d 100644 --- a/Documentation/ideas.md +++ b/Documentation/ideas.md @@ -8,7 +8,7 @@ ## Higher Priority - esp_lvgl_port settings has a large stack size (~9kB) to fix stackoverflow when LVGL events (e.g. button click) do actions like file operations do actions like file operations. Can we reduce the callstack? -- Improve posix support: use user home path and system /tmp folder. implement uart/i2c drivers properly. +- Improve posix support: use user home path and system /tmp folder. - NimBLE looses pairing key after reboot - Pick different font to improve monochrome screen readability (or change the weight). - Drivers/audio-codec-module is not a module. Move it somewhere else. Or make it an actual module. diff --git a/Drivers/ads1115-module/source/ads1115.cpp b/Drivers/ads1115-module/source/ads1115.cpp index b07806d85..d21e3481e 100644 --- a/Drivers/ads1115-module/source/ads1115.cpp +++ b/Drivers/ads1115-module/source/ads1115.cpp @@ -1,6 +1,5 @@ // SPDX-License-Identifier: Apache-2.0 #include -#include #include #include @@ -131,7 +130,6 @@ Driver ads1115_driver = { .probe = nullptr, .api = &ADS1115_API, .device_type = &ADC_CONTROLLER_TYPE, - .owner = &ads1115_module, .internal = nullptr }; diff --git a/Drivers/audio-stream-module/source/audio_stream.cpp b/Drivers/audio-stream-module/source/audio_stream.cpp index eb0c2bd92..04971d3c8 100644 --- a/Drivers/audio-stream-module/source/audio_stream.cpp +++ b/Drivers/audio-stream-module/source/audio_stream.cpp @@ -995,7 +995,6 @@ Driver audio_stream_driver = { .stop_device = stop_device, .api = &API, .device_type = &AUDIO_STREAM_TYPE, - .owner = nullptr, .internal = nullptr, }; diff --git a/Drivers/audio-stream-module/tests/source/audio_stream_open_race_test.cpp b/Drivers/audio-stream-module/tests/source/audio_stream_open_race_test.cpp index d5d998ab5..73bc6c7d8 100644 --- a/Drivers/audio-stream-module/tests/source/audio_stream_open_race_test.cpp +++ b/Drivers/audio-stream-module/tests/source/audio_stream_open_race_test.cpp @@ -137,7 +137,6 @@ static Driver mock_codec_driver = { .stop_device = mock_stop, .api = &MOCK_API, .device_type = &AUDIO_CODEC_TYPE, - .owner = nullptr, .internal = nullptr, }; diff --git a/Drivers/aw88298-module/source/aw88298.cpp b/Drivers/aw88298-module/source/aw88298.cpp index 8175d5b28..cab8456ec 100644 --- a/Drivers/aw88298-module/source/aw88298.cpp +++ b/Drivers/aw88298-module/source/aw88298.cpp @@ -356,7 +356,6 @@ Driver aw88298_driver = { .stop_device = stop_device, .api = &API, .device_type = &AUDIO_CODEC_TYPE, - .owner = nullptr, .internal = nullptr, }; diff --git a/Drivers/aw9523b-module/source/aw9523b.cpp b/Drivers/aw9523b-module/source/aw9523b.cpp index b04ec9271..86a0f6d70 100644 --- a/Drivers/aw9523b-module/source/aw9523b.cpp +++ b/Drivers/aw9523b-module/source/aw9523b.cpp @@ -1,6 +1,5 @@ // SPDX-License-Identifier: Apache-2.0 #include -#include #include #include @@ -181,7 +180,6 @@ Driver aw9523b_driver = { .stop_device = stop, .api = static_cast(&aw9523b_gpio_api), .device_type = &GPIO_CONTROLLER_TYPE, - .owner = &aw9523b_module, .internal = nullptr }; diff --git a/Drivers/axp192-module/source/axp192.cpp b/Drivers/axp192-module/source/axp192.cpp index 4d4119086..fe2b156f3 100644 --- a/Drivers/axp192-module/source/axp192.cpp +++ b/Drivers/axp192-module/source/axp192.cpp @@ -1,6 +1,5 @@ // SPDX-License-Identifier: Apache-2.0 #include -#include #include #include @@ -41,8 +40,6 @@ static constexpr TickType_t TIMEOUT = pdMS_TO_TICKS(50); extern "C" { -extern Module axp192_module; - // region Register helpers /** Reads a 2-byte ADC register in AXP192's packed 12-bit format: raw = (high << 4) + low. */ @@ -354,7 +351,6 @@ Driver axp192_power_supply_driver = { .stop_device = nullptr, .api = &AXP192_POWER_SUPPLY_API, .device_type = &POWER_SUPPLY_TYPE, - .owner = &axp192_module, .internal = nullptr }; @@ -502,7 +498,6 @@ Driver axp192_driver = { .stop_device = stop, .api = nullptr, .device_type = nullptr, - .owner = &axp192_module, .internal = nullptr }; diff --git a/Drivers/axp192-module/source/axp192_backlight.cpp b/Drivers/axp192-module/source/axp192_backlight.cpp index 0532cd731..1d54a2ae2 100644 --- a/Drivers/axp192-module/source/axp192_backlight.cpp +++ b/Drivers/axp192-module/source/axp192_backlight.cpp @@ -1,6 +1,5 @@ // SPDX-License-Identifier: Apache-2.0 #include -#include #include #include @@ -118,7 +117,6 @@ Driver axp192_backlight_driver = { .probe = nullptr, .api = &AXP192_BACKLIGHT_API, .device_type = &BACKLIGHT_TYPE, - .owner = &axp192_module, .internal = nullptr }; diff --git a/Drivers/axp2101-module/source/axp2101.cpp b/Drivers/axp2101-module/source/axp2101.cpp index 6c162560e..13243f85d 100644 --- a/Drivers/axp2101-module/source/axp2101.cpp +++ b/Drivers/axp2101-module/source/axp2101.cpp @@ -1,6 +1,5 @@ // SPDX-License-Identifier: Apache-2.0 #include -#include #include #include @@ -38,8 +37,6 @@ static constexpr TickType_t TIMEOUT = pdMS_TO_TICKS(50); extern "C" { -extern Module axp2101_module; - // region Voltage encoding struct Axp2101VoltRange { @@ -464,7 +461,6 @@ Driver axp2101_power_supply_driver = { .stop_device = nullptr, .api = &AXP2101_POWER_SUPPLY_API, .device_type = &POWER_SUPPLY_TYPE, - .owner = &axp2101_module, .internal = nullptr }; @@ -597,7 +593,6 @@ Driver axp2101_driver = { .stop_device = stop, .api = nullptr, .device_type = nullptr, - .owner = &axp2101_module, .internal = nullptr }; diff --git a/Drivers/axp2101-module/source/axp2101_backlight.cpp b/Drivers/axp2101-module/source/axp2101_backlight.cpp index 8a5d6d642..5b6692528 100644 --- a/Drivers/axp2101-module/source/axp2101_backlight.cpp +++ b/Drivers/axp2101-module/source/axp2101_backlight.cpp @@ -1,6 +1,5 @@ // SPDX-License-Identifier: Apache-2.0 #include -#include #include #include @@ -126,7 +125,6 @@ Driver axp2101_backlight_driver = { .probe = nullptr, .api = &AXP2101_BACKLIGHT_API, .device_type = &BACKLIGHT_TYPE, - .owner = &axp2101_module, .internal = nullptr, }; diff --git a/Drivers/axs5106-module/source/axs5106.cpp b/Drivers/axs5106-module/source/axs5106.cpp index f01b03fa4..995c1e9e9 100644 --- a/Drivers/axs5106-module/source/axs5106.cpp +++ b/Drivers/axs5106-module/source/axs5106.cpp @@ -1,8 +1,6 @@ // SPDX-License-Identifier: Apache-2.0 #include -#include - #include #include #include @@ -235,6 +233,5 @@ Driver axs5106_driver = { .stop_device = stop, .api = &axs5106_pointer_api, .device_type = &POINTER_TYPE, - .owner = &axs5106_module, .internal = nullptr }; diff --git a/Drivers/bm8563-module/source/bm8563.cpp b/Drivers/bm8563-module/source/bm8563.cpp index a86bf725b..0b77eae87 100644 --- a/Drivers/bm8563-module/source/bm8563.cpp +++ b/Drivers/bm8563-module/source/bm8563.cpp @@ -1,6 +1,5 @@ // SPDX-License-Identifier: Apache-2.0 #include -#include #include #include #include @@ -116,7 +115,6 @@ Driver bm8563_driver = { .stop_device = stop, .api = &bm8563_rtc_api, .device_type = &RTC_TYPE, - .owner = &bm8563_module, .internal = nullptr }; diff --git a/Drivers/bmi270-module/source/bmi270.cpp b/Drivers/bmi270-module/source/bmi270.cpp index b3b52b71a..40c3b94a5 100644 --- a/Drivers/bmi270-module/source/bmi270.cpp +++ b/Drivers/bmi270-module/source/bmi270.cpp @@ -1,6 +1,5 @@ // SPDX-License-Identifier: Apache-2.0 #include -#include #include #include #include @@ -234,7 +233,6 @@ Driver bmi270_driver = { .stop_device = stop, .api = &bmi270_imu_api, .device_type = &IMU_TYPE, - .owner = &bmi270_module, .internal = nullptr }; diff --git a/Drivers/bq24295-module/source/bq24295.cpp b/Drivers/bq24295-module/source/bq24295.cpp index 7d096956d..f3da816df 100644 --- a/Drivers/bq24295-module/source/bq24295.cpp +++ b/Drivers/bq24295-module/source/bq24295.cpp @@ -1,6 +1,5 @@ // SPDX-License-Identifier: Apache-2.0 #include -#include #include #include @@ -27,8 +26,6 @@ static constexpr TickType_t TIMEOUT = pdMS_TO_TICKS(50); extern "C" { -extern Module bq24295_module; - static error_t read_charge_termination(Device* device, uint8_t* out) { auto* parent = device_get_parent(device); auto address = GET_CONFIG(device)->address; @@ -178,7 +175,6 @@ Driver bq24295_power_supply_driver = { .stop_device = nullptr, .api = &BQ24295_POWER_SUPPLY_API, .device_type = &POWER_SUPPLY_TYPE, - .owner = &bq24295_module, .internal = nullptr }; @@ -263,7 +259,6 @@ Driver bq24295_driver = { .stop_device = stop, .api = nullptr, .device_type = nullptr, - .owner = &bq24295_module, .internal = nullptr }; diff --git a/Drivers/bq25896-module/source/bq25896.cpp b/Drivers/bq25896-module/source/bq25896.cpp index 75dc4f3b0..10c6ed768 100644 --- a/Drivers/bq25896-module/source/bq25896.cpp +++ b/Drivers/bq25896-module/source/bq25896.cpp @@ -1,6 +1,5 @@ // SPDX-License-Identifier: Apache-2.0 #include -#include #include #include @@ -72,7 +71,6 @@ Driver bq25896_power_supply_driver = { .stop_device = nullptr, .api = &BQ25896_POWER_SUPPLY_API, .device_type = &POWER_SUPPLY_TYPE, - .owner = &bq25896_module, .internal = nullptr }; @@ -166,7 +164,6 @@ Driver bq25896_driver = { .stop_device = stop, .api = nullptr, .device_type = nullptr, - .owner = &bq25896_module, .internal = nullptr }; diff --git a/Drivers/bq27220-module/source/bq27220.cpp b/Drivers/bq27220-module/source/bq27220.cpp index d928942be..934c08448 100644 --- a/Drivers/bq27220-module/source/bq27220.cpp +++ b/Drivers/bq27220-module/source/bq27220.cpp @@ -1,6 +1,5 @@ // SPDX-License-Identifier: Apache-2.0 #include -#include #include #include @@ -118,7 +117,6 @@ Driver bq27220_power_supply_driver = { .stop_device = nullptr, .api = &BQ27220_POWER_SUPPLY_API, .device_type = &POWER_SUPPLY_TYPE, - .owner = &bq27220_module, .internal = nullptr }; @@ -205,7 +203,6 @@ Driver bq27220_driver = { .stop_device = stop, .api = nullptr, .device_type = nullptr, - .owner = &bq27220_module, .internal = nullptr }; diff --git a/Drivers/button-control-module/source/button_control.cpp b/Drivers/button-control-module/source/button_control.cpp index 868a164c6..0be1fea03 100644 --- a/Drivers/button-control-module/source/button_control.cpp +++ b/Drivers/button-control-module/source/button_control.cpp @@ -1,8 +1,6 @@ // SPDX-License-Identifier: Apache-2.0 #include -#include - #include #include #include @@ -217,6 +215,5 @@ Driver button_control_driver = { .stop_device = stop, .api = &button_control_api, .device_type = &KEYBOARD_TYPE, - .owner = &button_control_module, .internal = nullptr }; diff --git a/Drivers/ch422g-module/source/ch422g.cpp b/Drivers/ch422g-module/source/ch422g.cpp index 43e284a6f..5e858ba34 100644 --- a/Drivers/ch422g-module/source/ch422g.cpp +++ b/Drivers/ch422g-module/source/ch422g.cpp @@ -1,6 +1,5 @@ // SPDX-License-Identifier: Apache-2.0 #include -#include #include #include #include @@ -156,7 +155,6 @@ Driver ch422g_driver = { .stop_device = stop, .api = static_cast(&ch422g_gpio_api), .device_type = &GPIO_CONTROLLER_TYPE, - .owner = &ch422g_module, .internal = nullptr }; diff --git a/Drivers/cst328-module/source/cst328.cpp b/Drivers/cst328-module/source/cst328.cpp index 9cd0563c7..3bd83523a 100644 --- a/Drivers/cst328-module/source/cst328.cpp +++ b/Drivers/cst328-module/source/cst328.cpp @@ -1,8 +1,6 @@ // SPDX-License-Identifier: Apache-2.0 #include -#include - #include #include #include @@ -289,6 +287,5 @@ Driver cst328_driver = { .stop_device = stop, .api = &cst328_pointer_api, .device_type = &POINTER_TYPE, - .owner = &cst328_module, .internal = nullptr }; diff --git a/Drivers/cst66xx-module/source/cst66xx.cpp b/Drivers/cst66xx-module/source/cst66xx.cpp index 736be7d4c..c36bd1380 100644 --- a/Drivers/cst66xx-module/source/cst66xx.cpp +++ b/Drivers/cst66xx-module/source/cst66xx.cpp @@ -1,8 +1,6 @@ // SPDX-License-Identifier: Apache-2.0 #include -#include - #include #include #include @@ -265,6 +263,5 @@ Driver cst66xx_driver = { .stop_device = stop, .api = &cst66xx_pointer_api, .device_type = &POINTER_TYPE, - .owner = &cst66xx_module, .internal = nullptr }; diff --git a/Drivers/cst816s-module/source/cst816s.cpp b/Drivers/cst816s-module/source/cst816s.cpp index a4f80306b..54152feab 100644 --- a/Drivers/cst816s-module/source/cst816s.cpp +++ b/Drivers/cst816s-module/source/cst816s.cpp @@ -1,6 +1,5 @@ // SPDX-License-Identifier: Apache-2.0 #include -#include #include #include @@ -229,6 +228,5 @@ Driver cst816s_driver = { .stop_device = stop, .api = &cst816s_pointer_api, .device_type = &POINTER_TYPE, - .owner = &cst816s_module, .internal = nullptr }; diff --git a/Drivers/cst816t-module/source/cst816t.cpp b/Drivers/cst816t-module/source/cst816t.cpp index c66ed825f..ccbf7aa91 100644 --- a/Drivers/cst816t-module/source/cst816t.cpp +++ b/Drivers/cst816t-module/source/cst816t.cpp @@ -1,8 +1,6 @@ // SPDX-License-Identifier: Apache-2.0 #include -#include - #include #include #include @@ -247,6 +245,5 @@ Driver cst816t_driver = { .stop_device = stop, .api = &cst816t_pointer_api, .device_type = &POINTER_TYPE, - .owner = &cst816t_module, .internal = nullptr }; diff --git a/Drivers/drv2605-module/source/drv2605.cpp b/Drivers/drv2605-module/source/drv2605.cpp index 5b3c4f7b5..e4ad45aae 100644 --- a/Drivers/drv2605-module/source/drv2605.cpp +++ b/Drivers/drv2605-module/source/drv2605.cpp @@ -1,6 +1,5 @@ // SPDX-License-Identifier: Apache-2.0 #include -#include #include #include @@ -144,7 +143,6 @@ Driver drv2605_driver = { .stop_device = stop, .api = &DRV2605_HAPTIC_API, .device_type = &HAPTIC_TYPE, - .owner = &drv2605_module, .internal = nullptr }; diff --git a/Drivers/dummy-i2s-amp-module/source/dummy_i2s_amp.cpp b/Drivers/dummy-i2s-amp-module/source/dummy_i2s_amp.cpp index c049a3235..f4bd9c9c3 100644 --- a/Drivers/dummy-i2s-amp-module/source/dummy_i2s_amp.cpp +++ b/Drivers/dummy-i2s-amp-module/source/dummy_i2s_amp.cpp @@ -378,7 +378,6 @@ Driver dummy_i2s_amp_driver = { .stop_device = stop_device, .api = &API, .device_type = &AUDIO_CODEC_TYPE, - .owner = nullptr, .internal = nullptr, }; diff --git a/Drivers/es7210-module/source/es7210.cpp b/Drivers/es7210-module/source/es7210.cpp index 267622319..5f5be4e04 100644 --- a/Drivers/es7210-module/source/es7210.cpp +++ b/Drivers/es7210-module/source/es7210.cpp @@ -428,7 +428,6 @@ Driver es7210_driver = { .stop_device = stop_device, .api = &API, .device_type = &AUDIO_CODEC_TYPE, - .owner = nullptr, .internal = nullptr, }; diff --git a/Drivers/es7243e-module/source/es7243e.cpp b/Drivers/es7243e-module/source/es7243e.cpp index f4be594ae..01994e57f 100644 --- a/Drivers/es7243e-module/source/es7243e.cpp +++ b/Drivers/es7243e-module/source/es7243e.cpp @@ -1,6 +1,5 @@ // SPDX-License-Identifier: Apache-2.0 #include -#include #include #include @@ -321,7 +320,6 @@ Driver es7243e_driver = { .probe = nullptr, .api = &API, .device_type = &AUDIO_CODEC_TYPE, - .owner = &es7243e_module, .internal = nullptr, }; diff --git a/Drivers/es8311-module/source/es8311.cpp b/Drivers/es8311-module/source/es8311.cpp index 6b3c0ebc9..de21b178a 100644 --- a/Drivers/es8311-module/source/es8311.cpp +++ b/Drivers/es8311-module/source/es8311.cpp @@ -393,7 +393,6 @@ Driver es8311_driver = { .stop_device = stop_device, .api = &API, .device_type = &AUDIO_CODEC_TYPE, - .owner = nullptr, .internal = nullptr, }; diff --git a/Drivers/es8388-module/source/es8388.cpp b/Drivers/es8388-module/source/es8388.cpp index 20b0f6fc3..acd2f639d 100644 --- a/Drivers/es8388-module/source/es8388.cpp +++ b/Drivers/es8388-module/source/es8388.cpp @@ -387,7 +387,6 @@ Driver es8388_driver = { .stop_device = stop_device, .api = &API, .device_type = &AUDIO_CODEC_TYPE, - .owner = nullptr, .internal = nullptr, }; diff --git a/Drivers/esp-epaper-module/source/esp_epaper.cpp b/Drivers/esp-epaper-module/source/esp_epaper.cpp index d430cf988..647043c46 100644 --- a/Drivers/esp-epaper-module/source/esp_epaper.cpp +++ b/Drivers/esp-epaper-module/source/esp_epaper.cpp @@ -1,6 +1,5 @@ // SPDX-License-Identifier: Apache-2.0 #include -#include #include "esp_epaper_rotate.h" #include @@ -428,6 +427,5 @@ Driver esp_epaper_driver = { .stop_device = stop, .api = &esp_epaper_display_api, .device_type = &DISPLAY_TYPE, - .owner = &esp_epaper_module, .internal = nullptr }; diff --git a/Drivers/esp32-dac-speaker-module/source/esp32_dac_speaker.cpp b/Drivers/esp32-dac-speaker-module/source/esp32_dac_speaker.cpp index 40a544e77..b6690d740 100644 --- a/Drivers/esp32-dac-speaker-module/source/esp32_dac_speaker.cpp +++ b/Drivers/esp32-dac-speaker-module/source/esp32_dac_speaker.cpp @@ -456,7 +456,6 @@ Driver esp32_dac_speaker_driver = { .stop_device = stop_device, .api = &API, .device_type = &AUDIO_CODEC_TYPE, - .owner = nullptr, .internal = nullptr, }; diff --git a/Drivers/esp32-led-strip-module/source/esp32_led_strip.cpp b/Drivers/esp32-led-strip-module/source/esp32_led_strip.cpp index e7f82bbb2..aa433e937 100644 --- a/Drivers/esp32-led-strip-module/source/esp32_led_strip.cpp +++ b/Drivers/esp32-led-strip-module/source/esp32_led_strip.cpp @@ -3,7 +3,6 @@ #include #include #include -#include #include #include @@ -241,8 +240,6 @@ static constexpr LedStripApi LED_STRIP_API = { .get_length = esp32_led_strip_get_length, }; -extern Module esp32_led_strip_module; - Driver esp32_led_strip_driver = { .name = "esp32_led_strip", .compatible = (const char*[]) { "espressif,esp32-led-strip", nullptr }, @@ -251,7 +248,6 @@ Driver esp32_led_strip_driver = { .probe = nullptr, .api = &LED_STRIP_API, .device_type = &LED_STRIP_TYPE, - .owner = &esp32_led_strip_module, .internal = nullptr, }; diff --git a/Drivers/ft5x06-module/source/ft5x06.cpp b/Drivers/ft5x06-module/source/ft5x06.cpp index f347ecffb..05af2afbf 100644 --- a/Drivers/ft5x06-module/source/ft5x06.cpp +++ b/Drivers/ft5x06-module/source/ft5x06.cpp @@ -1,6 +1,5 @@ // SPDX-License-Identifier: Apache-2.0 #include -#include #include #include @@ -266,6 +265,5 @@ Driver ft5x06_driver = { .stop_device = stop, .api = &ft5x06_pointer_api, .device_type = &POINTER_TYPE, - .owner = &ft5x06_module, .internal = nullptr }; diff --git a/Drivers/ft6x36-module/source/ft6x36.cpp b/Drivers/ft6x36-module/source/ft6x36.cpp index 6f052ba54..f010e9343 100644 --- a/Drivers/ft6x36-module/source/ft6x36.cpp +++ b/Drivers/ft6x36-module/source/ft6x36.cpp @@ -1,8 +1,6 @@ // SPDX-License-Identifier: Apache-2.0 #include -#include - #include #include #include @@ -268,6 +266,5 @@ Driver ft6x36_driver = { .stop_device = stop, .api = &ft6x36_pointer_api, .device_type = &POINTER_TYPE, - .owner = &ft6x36_module, .internal = nullptr }; diff --git a/Drivers/gc0308-module/source/gc0308.cpp b/Drivers/gc0308-module/source/gc0308.cpp index e7bf98ac6..5e1f1d125 100644 --- a/Drivers/gc0308-module/source/gc0308.cpp +++ b/Drivers/gc0308-module/source/gc0308.cpp @@ -1,6 +1,5 @@ // SPDX-License-Identifier: Apache-2.0 #include -#include #include #include @@ -545,7 +544,6 @@ Driver gc0308_driver = { .stop_device = stop, .api = &gc0308_camera_api, .device_type = &CAMERA_TYPE, - .owner = &gc0308_module, .internal = nullptr }; diff --git a/Drivers/gc9a01-module/source/gc9a01.cpp b/Drivers/gc9a01-module/source/gc9a01.cpp index a2d956c2a..877f63935 100644 --- a/Drivers/gc9a01-module/source/gc9a01.cpp +++ b/Drivers/gc9a01-module/source/gc9a01.cpp @@ -1,6 +1,5 @@ // SPDX-License-Identifier: Apache-2.0 #include -#include #include #include @@ -358,6 +357,5 @@ Driver gc9a01_driver = { .stop_device = stop, .api = &gc9a01_display_api, .device_type = &DISPLAY_TYPE, - .owner = &gc9a01_module, .internal = nullptr }; diff --git a/Drivers/gdeq031t10-module/source/gdeq031t10.cpp b/Drivers/gdeq031t10-module/source/gdeq031t10.cpp index 0cc3bd186..5c54b4718 100644 --- a/Drivers/gdeq031t10-module/source/gdeq031t10.cpp +++ b/Drivers/gdeq031t10-module/source/gdeq031t10.cpp @@ -1,6 +1,5 @@ // SPDX-License-Identifier: Apache-2.0 #include -#include #include #include @@ -722,7 +721,6 @@ Driver gdeq031t10_driver = { .stop_device = stop, .api = &gdeq031t10_display_api, .device_type = &DISPLAY_TYPE, - .owner = &gdeq031t10_module, .internal = nullptr }; diff --git a/Drivers/gpio-encoder-module/source/gpio_encoder.cpp b/Drivers/gpio-encoder-module/source/gpio_encoder.cpp index ef9594742..0fc261192 100644 --- a/Drivers/gpio-encoder-module/source/gpio_encoder.cpp +++ b/Drivers/gpio-encoder-module/source/gpio_encoder.cpp @@ -321,8 +321,6 @@ static constexpr KeyboardApi GPIO_ENCODER_API = { .read_key = gpio_encoder_read_key, }; -extern Module gpio_encoder_module; - Driver gpio_encoder_driver = { .name = "gpio_encoder", .compatible = (const char*[]) { "tactility,gpio-encoder", nullptr }, @@ -330,7 +328,6 @@ Driver gpio_encoder_driver = { .stop_device = stop, .api = &GPIO_ENCODER_API, .device_type = &KEYBOARD_TYPE, - .owner = &gpio_encoder_module, .internal = nullptr }; diff --git a/Drivers/gpio-trackball-module/source/gpio_trackball.cpp b/Drivers/gpio-trackball-module/source/gpio_trackball.cpp index 895ecdee9..74d0e2f23 100644 --- a/Drivers/gpio-trackball-module/source/gpio_trackball.cpp +++ b/Drivers/gpio-trackball-module/source/gpio_trackball.cpp @@ -167,8 +167,6 @@ static constexpr TrackballApi GPIO_TRACKBALL_API = { .get_button_pressed = get_button_pressed, }; -extern Module gpio_trackball_module; - Driver gpio_trackball_driver = { .name = "gpio_trackball", .compatible = (const char*[]) { "tactility,gpio-trackball", nullptr }, @@ -176,7 +174,6 @@ Driver gpio_trackball_driver = { .stop_device = stop, .api = &GPIO_TRACKBALL_API, .device_type = &TRACKBALL_TYPE, - .owner = &gpio_trackball_module, .internal = nullptr }; diff --git a/Drivers/gps-meshtastic-module/source/gps_meshtastic.cpp b/Drivers/gps-meshtastic-module/source/gps_meshtastic.cpp index 495e0a621..5fe0875e8 100644 --- a/Drivers/gps-meshtastic-module/source/gps_meshtastic.cpp +++ b/Drivers/gps-meshtastic-module/source/gps_meshtastic.cpp @@ -340,6 +340,5 @@ Driver meshtastic_gps_driver = { .stop_device = stop, .api = &generic_gps_api, .device_type = &GPS_TYPE, - .owner = &gps_meshtastic_module, .internal = nullptr }; diff --git a/Drivers/gt911-module/source/gt911.cpp b/Drivers/gt911-module/source/gt911.cpp index 3e74f78c3..21f4d105a 100644 --- a/Drivers/gt911-module/source/gt911.cpp +++ b/Drivers/gt911-module/source/gt911.cpp @@ -1,6 +1,5 @@ // SPDX-License-Identifier: Apache-2.0 #include -#include #include #include @@ -380,6 +379,5 @@ Driver gt911_driver = { .stop_device = stop, .api = >911_pointer_api, .device_type = &POINTER_TYPE, - .owner = >911_module, .internal = nullptr }; diff --git a/Drivers/hx8357-module/source/hx8357.cpp b/Drivers/hx8357-module/source/hx8357.cpp index f52242924..2ee17eef7 100644 --- a/Drivers/hx8357-module/source/hx8357.cpp +++ b/Drivers/hx8357-module/source/hx8357.cpp @@ -1,6 +1,5 @@ // SPDX-License-Identifier: Apache-2.0 #include -#include #include #include @@ -467,6 +466,5 @@ Driver hx8357_driver = { .stop_device = stop, .api = &hx8357_display_api, .device_type = &DISPLAY_TYPE, - .owner = &hx8357_module, .internal = nullptr }; diff --git a/Drivers/ili9341-module/source/ili9341.cpp b/Drivers/ili9341-module/source/ili9341.cpp index bf2f1411f..bb52bffa6 100644 --- a/Drivers/ili9341-module/source/ili9341.cpp +++ b/Drivers/ili9341-module/source/ili9341.cpp @@ -1,6 +1,5 @@ // SPDX-License-Identifier: Apache-2.0 #include -#include #include #include @@ -457,6 +456,5 @@ Driver ili9341_driver = { .stop_device = stop, .api = &ili9341_display_api, .device_type = &DISPLAY_TYPE, - .owner = &ili9341_module, .internal = nullptr }; diff --git a/Drivers/ili9488-module/source/ili9488.cpp b/Drivers/ili9488-module/source/ili9488.cpp index 949061677..63ea2da9f 100644 --- a/Drivers/ili9488-module/source/ili9488.cpp +++ b/Drivers/ili9488-module/source/ili9488.cpp @@ -1,6 +1,5 @@ // SPDX-License-Identifier: Apache-2.0 #include -#include #include #include @@ -382,6 +381,5 @@ Driver ili9488_driver = { .stop_device = stop, .api = &ili9488_display_api, .device_type = &DISPLAY_TYPE, - .owner = &ili9488_module, .internal = nullptr }; diff --git a/Drivers/ili9881c-module/source/ili9881c.cpp b/Drivers/ili9881c-module/source/ili9881c.cpp index 74f7b3ba6..c1d686762 100644 --- a/Drivers/ili9881c-module/source/ili9881c.cpp +++ b/Drivers/ili9881c-module/source/ili9881c.cpp @@ -3,7 +3,6 @@ #if SOC_MIPI_DSI_SUPPORTED #include -#include #include #include @@ -594,7 +593,6 @@ Driver ili9881c_driver = { .stop_device = stop, .api = &ili9881c_display_api, .device_type = &DISPLAY_TYPE, - .owner = &ili9881c_module, .internal = nullptr }; diff --git a/Drivers/ina226-module/source/ina226.cpp b/Drivers/ina226-module/source/ina226.cpp index fec59dfbc..5d871839b 100644 --- a/Drivers/ina226-module/source/ina226.cpp +++ b/Drivers/ina226-module/source/ina226.cpp @@ -1,6 +1,5 @@ // SPDX-License-Identifier: Apache-2.0 #include -#include #include #include #include @@ -108,7 +107,6 @@ Driver ina226_power_supply_driver = { .stop_device = nullptr, .api = &INA226_POWER_SUPPLY_API, .device_type = &POWER_SUPPLY_TYPE, - .owner = &ina226_module, .internal = nullptr }; @@ -280,7 +278,6 @@ Driver ina226_driver = { .stop_device = stop, .api = nullptr, .device_type = nullptr, - .owner = &ina226_module, .internal = nullptr }; diff --git a/Drivers/jd9165-module/source/jd9165.cpp b/Drivers/jd9165-module/source/jd9165.cpp index f37888782..299e3f407 100644 --- a/Drivers/jd9165-module/source/jd9165.cpp +++ b/Drivers/jd9165-module/source/jd9165.cpp @@ -3,7 +3,6 @@ #if SOC_MIPI_DSI_SUPPORTED #include -#include #include #include @@ -527,7 +526,6 @@ Driver jd9165_driver = { .stop_device = stop, .api = &jd9165_display_api, .device_type = &DISPLAY_TYPE, - .owner = &jd9165_module, .internal = nullptr }; diff --git a/Drivers/jd9853-module/source/jd9853.cpp b/Drivers/jd9853-module/source/jd9853.cpp index 03cf9a92b..4237e0e91 100644 --- a/Drivers/jd9853-module/source/jd9853.cpp +++ b/Drivers/jd9853-module/source/jd9853.cpp @@ -1,6 +1,5 @@ // SPDX-License-Identifier: Apache-2.0 #include -#include #include #include @@ -371,6 +370,5 @@ Driver jd9853_driver = { .stop_device = stop, .api = &jd9853_display_api, .device_type = &DISPLAY_TYPE, - .owner = &jd9853_module, .internal = nullptr }; diff --git a/Drivers/lilygo-module/source/tdeck_keyboard.cpp b/Drivers/lilygo-module/source/tdeck_keyboard.cpp index 1b94fc166..f80b6d6f2 100644 --- a/Drivers/lilygo-module/source/tdeck_keyboard.cpp +++ b/Drivers/lilygo-module/source/tdeck_keyboard.cpp @@ -87,8 +87,6 @@ static const KeyboardApi tdeck_keyboard_api = { .read_key = tdeck_keyboard_read_key, }; -extern Module lilygo_module; - Driver tdeck_keyboard_driver = { .name = "tdeck_keyboard", .compatible = (const char*[]) { "lilygo,tdeck-keyboard", nullptr }, @@ -96,6 +94,5 @@ Driver tdeck_keyboard_driver = { .stop_device = stop, .api = &tdeck_keyboard_api, .device_type = &KEYBOARD_TYPE, - .owner = &lilygo_module, .internal = nullptr }; diff --git a/Drivers/lilygo-module/source/tdeck_keyboard_backlight.cpp b/Drivers/lilygo-module/source/tdeck_keyboard_backlight.cpp index 852227686..a1f6477ef 100644 --- a/Drivers/lilygo-module/source/tdeck_keyboard_backlight.cpp +++ b/Drivers/lilygo-module/source/tdeck_keyboard_backlight.cpp @@ -98,8 +98,6 @@ static const BacklightApi tdeck_keyboard_backlight_api = { .get_max_brightness = nullptr, }; -extern struct Module lilygo_module; - Driver tdeck_keyboard_backlight_driver = { .name = "tdeck_keyboard_backlight", .compatible = (const char*[]) { "lilygo,tdeck-keyboard-backlight", nullptr }, @@ -108,6 +106,5 @@ Driver tdeck_keyboard_backlight_driver = { .probe = nullptr, .api = &tdeck_keyboard_backlight_api, .device_type = &BACKLIGHT_TYPE, - .owner = &lilygo_module, .internal = nullptr }; diff --git a/Drivers/lilygo-t5s3-epd-module/source/t5s3_display.cpp b/Drivers/lilygo-t5s3-epd-module/source/t5s3_display.cpp index 0d9b27572..b6ea56976 100644 --- a/Drivers/lilygo-t5s3-epd-module/source/t5s3_display.cpp +++ b/Drivers/lilygo-t5s3-epd-module/source/t5s3_display.cpp @@ -1,6 +1,5 @@ // SPDX-License-Identifier: Apache-2.0 #include -#include #include #include @@ -302,7 +301,6 @@ Driver t5s3_display_driver = { .probe = nullptr, .api = &t5s3_display_api, .device_type = &DISPLAY_TYPE, - .owner = &lilygo_t5s3_epd_module, .internal = nullptr }; diff --git a/Drivers/lp5814-module/source/lp5814.cpp b/Drivers/lp5814-module/source/lp5814.cpp index 7d2420525..5ce57939d 100644 --- a/Drivers/lp5814-module/source/lp5814.cpp +++ b/Drivers/lp5814-module/source/lp5814.cpp @@ -1,6 +1,5 @@ // SPDX-License-Identifier: Apache-2.0 #include -#include #include #include @@ -150,7 +149,6 @@ Driver lp5814_driver = { .probe = nullptr, .api = &LP5814_BACKLIGHT_API, .device_type = &BACKLIGHT_TYPE, - .owner = &lp5814_module, .internal = nullptr, }; diff --git a/Drivers/m5pm1-module/source/m5pm1.cpp b/Drivers/m5pm1-module/source/m5pm1.cpp index 3eb11b38d..84e8418d3 100644 --- a/Drivers/m5pm1-module/source/m5pm1.cpp +++ b/Drivers/m5pm1-module/source/m5pm1.cpp @@ -1,6 +1,5 @@ // SPDX-License-Identifier: Apache-2.0 #include -#include #include #include #include @@ -138,7 +137,6 @@ Driver m5pm1_power_supply_driver = { .stop_device = nullptr, .api = &M5PM1_POWER_SUPPLY_API, .device_type = &POWER_SUPPLY_TYPE, - .owner = &m5pm1_module, .internal = nullptr }; @@ -468,7 +466,6 @@ Driver m5pm1_driver = { .stop_device = stop, .api = nullptr, .device_type = nullptr, - .owner = &m5pm1_module, .internal = nullptr }; diff --git a/Drivers/m5stack-module/source/cardputer_adv_keyboard.cpp b/Drivers/m5stack-module/source/cardputer_adv_keyboard.cpp index 03b0b22bc..86d1645f0 100644 --- a/Drivers/m5stack-module/source/cardputer_adv_keyboard.cpp +++ b/Drivers/m5stack-module/source/cardputer_adv_keyboard.cpp @@ -4,7 +4,6 @@ // Drivers/TCA8418/Source/Tca8418.cpp (itself ported from // https://github.com/adafruit/Adafruit_TCA8418, MIT licensed). #include -#include #include #include @@ -276,6 +275,5 @@ Driver cardputer_adv_keyboard_driver = { .stop_device = stop, .api = &cardputer_adv_keyboard_api, .device_type = &KEYBOARD_TYPE, - .owner = &m5stack_module, .internal = nullptr }; diff --git a/Drivers/m5stack-module/source/cardputer_keyboard.cpp b/Drivers/m5stack-module/source/cardputer_keyboard.cpp index 0537adc4a..51304386a 100644 --- a/Drivers/m5stack-module/source/cardputer_keyboard.cpp +++ b/Drivers/m5stack-module/source/cardputer_keyboard.cpp @@ -3,8 +3,6 @@ // https://github.com/m5stack/M5Cardputer-UserDemo/tree/main/main/hal/keyboard (MIT licensed). #include -#include - #include #include #include @@ -308,6 +306,5 @@ Driver cardputer_keyboard_driver = { .stop_device = stop, .api = &cardputer_keyboard_api, .device_type = &KEYBOARD_TYPE, - .owner = &m5stack_module, .internal = nullptr }; diff --git a/Drivers/mock-drivers-module/CMakeLists.txt b/Drivers/mock-drivers-module/CMakeLists.txt new file mode 100644 index 000000000..96e3a0ff2 --- /dev/null +++ b/Drivers/mock-drivers-module/CMakeLists.txt @@ -0,0 +1,11 @@ +cmake_minimum_required(VERSION 3.20) + +include("${CMAKE_CURRENT_LIST_DIR}/../../Buildscripts/module.cmake") + +file(GLOB_RECURSE SOURCE_FILES "source/*.c*") + +tactility_add_module(mock-drivers-module + SRCS ${SOURCE_FILES} + INCLUDE_DIRS include/ + REQUIRES TactilityKernel +) diff --git a/Drivers/mock-drivers-module/LICENSE-Apache-2.0.md b/Drivers/mock-drivers-module/LICENSE-Apache-2.0.md new file mode 100644 index 000000000..f5f4b8b5e --- /dev/null +++ b/Drivers/mock-drivers-module/LICENSE-Apache-2.0.md @@ -0,0 +1,195 @@ +Apache License +============== + +_Version 2.0, January 2004_ +_<>_ + +### Terms and Conditions for use, reproduction, and distribution + +#### 1. Definitions + +“License” shall mean the terms and conditions for use, reproduction, and +distribution as defined by Sections 1 through 9 of this document. + +“Licensor” shall mean the copyright owner or entity authorized by the copyright +owner that is granting the License. + +“Legal Entity” shall mean the union of the acting entity and all other entities +that control, are controlled by, or are under common control with that entity. +For the purposes of this definition, “control” means **(i)** the power, direct or +indirect, to cause the direction or management of such entity, whether by +contract or otherwise, or **(ii)** ownership of fifty percent (50%) or more of the +outstanding shares, or **(iii)** beneficial ownership of such entity. + +“You” (or “Your”) shall mean an individual or Legal Entity exercising +permissions granted by this License. + +“Source” form shall mean the preferred form for making modifications, including +but not limited to software source code, documentation source, and configuration +files. + +“Object” form shall mean any form resulting from mechanical transformation or +translation of a Source form, including but not limited to compiled object code, +generated documentation, and conversions to other media types. + +“Work” shall mean the work of authorship, whether in Source or Object form, made +available under the License, as indicated by a copyright notice that is included +in or attached to the work (an example is provided in the Appendix below). + +“Derivative Works” shall mean any work, whether in Source or Object form, that +is based on (or derived from) the Work and for which the editorial revisions, +annotations, elaborations, or other modifications represent, as a whole, an +original work of authorship. For the purposes of this License, Derivative Works +shall not include works that remain separable from, or merely link (or bind by +name) to the interfaces of, the Work and Derivative Works thereof. + +“Contribution” shall mean any work of authorship, including the original version +of the Work and any modifications or additions to that Work or Derivative Works +thereof, that is intentionally submitted to Licensor for inclusion in the Work +by the copyright owner or by an individual or Legal Entity authorized to submit +on behalf of the copyright owner. For the purposes of this definition, +“submitted” means any form of electronic, verbal, or written communication sent +to the Licensor or its representatives, including but not limited to +communication on electronic mailing lists, source code control systems, and +issue tracking systems that are managed by, or on behalf of, the Licensor for +the purpose of discussing and improving the Work, but excluding communication +that is conspicuously marked or otherwise designated in writing by the copyright +owner as “Not a Contribution.” + +“Contributor” shall mean Licensor and any individual or Legal Entity on behalf +of whom a Contribution has been received by Licensor and subsequently +incorporated within the Work. + +#### 2. Grant of Copyright License + +Subject to the terms and conditions of this License, each Contributor hereby +grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, +irrevocable copyright license to reproduce, prepare Derivative Works of, +publicly display, publicly perform, sublicense, and distribute the Work and such +Derivative Works in Source or Object form. + +#### 3. Grant of Patent License + +Subject to the terms and conditions of this License, each Contributor hereby +grants to You a perpetual, worldwide, non-exclusive, no-charge, royalty-free, +irrevocable (except as stated in this section) patent license to make, have +made, use, offer to sell, sell, import, and otherwise transfer the Work, where +such license applies only to those patent claims licensable by such Contributor +that are necessarily infringed by their Contribution(s) alone or by combination +of their Contribution(s) with the Work to which such Contribution(s) was +submitted. If You institute patent litigation against any entity (including a +cross-claim or counterclaim in a lawsuit) alleging that the Work or a +Contribution incorporated within the Work constitutes direct or contributory +patent infringement, then any patent licenses granted to You under this License +for that Work shall terminate as of the date such litigation is filed. + +#### 4. Redistribution + +You may reproduce and distribute copies of the Work or Derivative Works thereof +in any medium, with or without modifications, and in Source or Object form, +provided that You meet the following conditions: + +* **(a)** You must give any other recipients of the Work or Derivative Works a copy of +this License; and +* **(b)** You must cause any modified files to carry prominent notices stating that You +changed the files; and +* **(c)** You must retain, in the Source form of any Derivative Works that You distribute, +all copyright, patent, trademark, and attribution notices from the Source form +of the Work, excluding those notices that do not pertain to any part of the +Derivative Works; and +* **(d)** If the Work includes a “NOTICE” text file as part of its distribution, then any +Derivative Works that You distribute must include a readable copy of the +attribution notices contained within such NOTICE file, excluding those notices +that do not pertain to any part of the Derivative Works, in at least one of the +following places: within a NOTICE text file distributed as part of the +Derivative Works; within the Source form or documentation, if provided along +with the Derivative Works; or, within a display generated by the Derivative +Works, if and wherever such third-party notices normally appear. The contents of +the NOTICE file are for informational purposes only and do not modify the +License. You may add Your own attribution notices within Derivative Works that +You distribute, alongside or as an addendum to the NOTICE text from the Work, +provided that such additional attribution notices cannot be construed as +modifying the License. + +You may add Your own copyright statement to Your modifications and may provide +additional or different license terms and conditions for use, reproduction, or +distribution of Your modifications, or for any such Derivative Works as a whole, +provided Your use, reproduction, and distribution of the Work otherwise complies +with the conditions stated in this License. + +#### 5. Submission of Contributions + +Unless You explicitly state otherwise, any Contribution intentionally submitted +for inclusion in the Work by You to the Licensor shall be under the terms and +conditions of this License, without any additional terms or conditions. +Notwithstanding the above, nothing herein shall supersede or modify the terms of +any separate license agreement you may have executed with Licensor regarding +such Contributions. + +#### 6. Trademarks + +This License does not grant permission to use the trade names, trademarks, +service marks, or product names of the Licensor, except as required for +reasonable and customary use in describing the origin of the Work and +reproducing the content of the NOTICE file. + +#### 7. Disclaimer of Warranty + +Unless required by applicable law or agreed to in writing, Licensor provides the +Work (and each Contributor provides its Contributions) on an “AS IS” BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied, +including, without limitation, any warranties or conditions of TITLE, +NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A PARTICULAR PURPOSE. You are +solely responsible for determining the appropriateness of using or +redistributing the Work and assume any risks associated with Your exercise of +permissions under this License. + +#### 8. Limitation of Liability + +In no event and under no legal theory, whether in tort (including negligence), +contract, or otherwise, unless required by applicable law (such as deliberate +and grossly negligent acts) or agreed to in writing, shall any Contributor be +liable to You for damages, including any direct, indirect, special, incidental, +or consequential damages of any character arising as a result of this License or +out of the use or inability to use the Work (including but not limited to +damages for loss of goodwill, work stoppage, computer failure or malfunction, or +any and all other commercial damages or losses), even if such Contributor has +been advised of the possibility of such damages. + +#### 9. Accepting Warranty or Additional Liability + +While redistributing the Work or Derivative Works thereof, You may choose to +offer, and charge a fee for, acceptance of support, warranty, indemnity, or +other liability obligations and/or rights consistent with this License. However, +in accepting such obligations, You may act only on Your own behalf and on Your +sole responsibility, not on behalf of any other Contributor, and only if You +agree to indemnify, defend, and hold each Contributor harmless for any liability +incurred by, or claims asserted against, such Contributor by reason of your +accepting any such warranty or additional liability. + +_END OF TERMS AND CONDITIONS_ + +### APPENDIX: How to apply the Apache License to your work + +To apply the Apache License to your work, attach the following boilerplate +notice, with the fields enclosed by brackets `[]` replaced with your own +identifying information. (Don't include the brackets!) The text should be +enclosed in the appropriate comment syntax for the file format. We also +recommend that a file or class name and description of purpose be included on +the same “printed page” as the copyright notice for easier identification within +third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + diff --git a/Drivers/mock-drivers-module/bindings/mock,wifi.yaml b/Drivers/mock-drivers-module/bindings/mock,wifi.yaml new file mode 100644 index 000000000..8734aa58a --- /dev/null +++ b/Drivers/mock-drivers-module/bindings/mock,wifi.yaml @@ -0,0 +1,8 @@ +description: Mock WiFi driver with a fixed list of access points + +compatible: "mock,wifi" + +properties: + _unused: + type: int + default: 0 diff --git a/Drivers/mock-drivers-module/include/bindings/mock_wifi.h b/Drivers/mock-drivers-module/include/bindings/mock_wifi.h new file mode 100644 index 000000000..ecded7835 --- /dev/null +++ b/Drivers/mock-drivers-module/include/bindings/mock_wifi.h @@ -0,0 +1,7 @@ +// SPDX-License-Identifier: Apache-2.0 +#pragma once + +#include +#include + +DEFINE_DEVICETREE(wifi, struct MockWifiConfig) diff --git a/Drivers/mock-drivers-module/include/mock/mock_wifi.h b/Drivers/mock-drivers-module/include/mock/mock_wifi.h new file mode 100644 index 000000000..056b5df6e --- /dev/null +++ b/Drivers/mock-drivers-module/include/mock/mock_wifi.h @@ -0,0 +1,14 @@ +// SPDX-License-Identifier: Apache-2.0 +#pragma once + +#ifdef __cplusplus +extern "C" { +#endif + +struct MockWifiConfig { + int _unused; +}; + +#ifdef __cplusplus +} +#endif diff --git a/Drivers/mock-drivers-module/include/mock_drivers_module.h b/Drivers/mock-drivers-module/include/mock_drivers_module.h new file mode 100644 index 000000000..e9c406cdf --- /dev/null +++ b/Drivers/mock-drivers-module/include/mock_drivers_module.h @@ -0,0 +1,14 @@ +// SPDX-License-Identifier: Apache-2.0 +#pragma once + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +extern struct Module mock_drivers_module; + +#ifdef __cplusplus +} +#endif diff --git a/Drivers/mock-drivers-module/module.yaml b/Drivers/mock-drivers-module/module.yaml new file mode 100644 index 000000000..a07d6f334 --- /dev/null +++ b/Drivers/mock-drivers-module/module.yaml @@ -0,0 +1,3 @@ +dependencies: + - TactilityKernel +bindings: bindings diff --git a/Platforms/platform-posix/source/drivers/mock_wifi.cpp b/Drivers/mock-drivers-module/source/mock_wifi.cpp similarity index 96% rename from Platforms/platform-posix/source/drivers/mock_wifi.cpp rename to Drivers/mock-drivers-module/source/mock_wifi.cpp index 92e40589b..81b693f64 100644 --- a/Platforms/platform-posix/source/drivers/mock_wifi.cpp +++ b/Drivers/mock-drivers-module/source/mock_wifi.cpp @@ -38,7 +38,7 @@ constexpr size_t MOCK_SCAN_RESULT_COUNT = sizeof(MOCK_SCAN_RESULTS) / sizeof(MOC constexpr int8_t MOCK_CONNECTED_RSSI = -30; constexpr const char* MOCK_IPV4_ADDRESS = "192.168.1.2"; -struct PosixWifiCtx { +struct MockWifiCtx { Device* device = nullptr; Mutex mutex {}; @@ -51,9 +51,9 @@ struct PosixWifiCtx { WifiEventSubscription* subscriptions = nullptr; }; -#define GET_CTX(device) (static_cast(device_get_driver_data(device))) +#define GET_CTX(device) (static_cast(device_get_driver_data(device))) -void fireEvent(PosixWifiCtx* ctx, WifiEvent event) { +void fireEvent(MockWifiCtx* ctx, WifiEvent event) { mutex_lock(&ctx->subscriptionsMutex); for (WifiEventSubscription* sub = ctx->subscriptions; sub != nullptr; sub = sub->internal.next) { mutex_lock(&sub->internal.ring_mutex); @@ -339,7 +339,7 @@ error_t apiEventUnsubscribe(Device* device, WifiEventSubscription* sub) { return result; } -const WifiApi posix_wifi_api = { +const WifiApi mock_wifi_api = { .set_radio_on = apiSetRadioOn, .set_radio_off = apiSetRadioOff, .get_radio_state = apiGetRadioState, @@ -363,7 +363,7 @@ const WifiApi posix_wifi_api = { // itself is only touched by apiSetRadioOn()/apiSetRadioOff(). error_t startDevice(Device* device) { - auto* ctx = new(std::nothrow) PosixWifiCtx(); + auto* ctx = new(std::nothrow) MockWifiCtx(); if (ctx == nullptr) return ERROR_OUT_OF_MEMORY; ctx->device = device; @@ -411,16 +411,13 @@ error_t stopDevice(Device* device) { extern "C" { -extern Module platform_posix_module; - -Driver posix_wifi_driver = { +Driver mock_wifi_driver = { .name = "mock_wifi", - .compatible = (const char*[]) { "posix,mock-wifi", nullptr }, + .compatible = (const char*[]) { "mock,wifi", nullptr }, .start_device = startDevice, .stop_device = stopDevice, - .api = (const void*)&posix_wifi_api, + .api = (const void*)&mock_wifi_api, .device_type = &WIFI_TYPE, - .owner = &platform_posix_module, .internal = nullptr }; diff --git a/Drivers/mock-drivers-module/source/module.cpp b/Drivers/mock-drivers-module/source/module.cpp new file mode 100644 index 000000000..6a37afd29 --- /dev/null +++ b/Drivers/mock-drivers-module/source/module.cpp @@ -0,0 +1,23 @@ +// SPDX-License-Identifier: Apache-2.0 +#include +#include + +extern "C" { + +extern Driver mock_wifi_driver; + +static Driver* const mock_drivers[] = { + &mock_wifi_driver, + nullptr +}; + +Module mock_drivers_module = { + .name = "mock-drivers", + .start = nullptr, + .stop = nullptr, + .drivers = mock_drivers, + .symbols = nullptr, + .internal = nullptr +}; + +} diff --git a/Drivers/mpu6886-module/source/mpu6886.cpp b/Drivers/mpu6886-module/source/mpu6886.cpp index 32e272803..35806aa51 100644 --- a/Drivers/mpu6886-module/source/mpu6886.cpp +++ b/Drivers/mpu6886-module/source/mpu6886.cpp @@ -1,6 +1,5 @@ // SPDX-License-Identifier: Apache-2.0 #include -#include #include #include #include @@ -207,7 +206,6 @@ Driver mpu6886_driver = { .stop_device = stop, .api = &mpu6886_imu_api, .device_type = &IMU_TYPE, - .owner = &mpu6886_module, .internal = nullptr }; diff --git a/Drivers/nv3031b-module/source/nv3031b.cpp b/Drivers/nv3031b-module/source/nv3031b.cpp index 2aeb207af..c076fb7c0 100644 --- a/Drivers/nv3031b-module/source/nv3031b.cpp +++ b/Drivers/nv3031b-module/source/nv3031b.cpp @@ -1,6 +1,5 @@ // SPDX-License-Identifier: Apache-2.0 #include -#include #include #include @@ -374,6 +373,5 @@ Driver nv3031b_driver = { .probe = nullptr, .api = &nv3031b_display_api, .device_type = &DISPLAY_TYPE, - .owner = &nv3031b_module, .internal = nullptr }; diff --git a/Drivers/pdm-mic-module/source/pdm_mic.cpp b/Drivers/pdm-mic-module/source/pdm_mic.cpp index 088b649b2..2d9d4cff5 100644 --- a/Drivers/pdm-mic-module/source/pdm_mic.cpp +++ b/Drivers/pdm-mic-module/source/pdm_mic.cpp @@ -330,7 +330,6 @@ Driver pdm_mic_driver = { .stop_device = stop_device, .api = &API, .device_type = &AUDIO_CODEC_TYPE, - .owner = nullptr, .internal = nullptr, }; diff --git a/Drivers/pi4ioe5v6408-module/source/pi4ioe5v6408.cpp b/Drivers/pi4ioe5v6408-module/source/pi4ioe5v6408.cpp index 2e4796efd..11f5a9328 100644 --- a/Drivers/pi4ioe5v6408-module/source/pi4ioe5v6408.cpp +++ b/Drivers/pi4ioe5v6408-module/source/pi4ioe5v6408.cpp @@ -1,6 +1,5 @@ // SPDX-License-Identifier: Apache-2.0 #include -#include #include #include #include @@ -210,7 +209,6 @@ Driver pi4ioe5v6408_driver = { .stop_device = stop, .api = static_cast(&pi4_gpio_api), .device_type = &GPIO_CONTROLLER_TYPE, - .owner = &pi4ioe5v6408_module, .internal = nullptr }; diff --git a/Drivers/py32ioexpander-module/source/py32ioexpander.cpp b/Drivers/py32ioexpander-module/source/py32ioexpander.cpp index 5584a7add..c3e898e45 100644 --- a/Drivers/py32ioexpander-module/source/py32ioexpander.cpp +++ b/Drivers/py32ioexpander-module/source/py32ioexpander.cpp @@ -1,7 +1,6 @@ // SPDX-License-Identifier: Apache-2.0 // Reference: https://github.com/m5stack/StackChan/tree/main/firmware/main/hal/drivers/PY32IOExpander_Class #include -#include #include #include #include @@ -147,7 +146,6 @@ Driver py32ioexpander_driver = { .stop_device = stop, .api = nullptr, .device_type = nullptr, - .owner = &py32ioexpander_module, .internal = nullptr }; diff --git a/Drivers/qmi8658-module/source/qmi8658.cpp b/Drivers/qmi8658-module/source/qmi8658.cpp index 619669144..3708f42eb 100644 --- a/Drivers/qmi8658-module/source/qmi8658.cpp +++ b/Drivers/qmi8658-module/source/qmi8658.cpp @@ -1,6 +1,5 @@ // SPDX-License-Identifier: Apache-2.0 #include -#include #include #include #include @@ -175,7 +174,6 @@ Driver qmi8658_driver = { .stop_device = stop, .api = &qmi8658_imu_api, .device_type = &IMU_TYPE, - .owner = &qmi8658_module, .internal = nullptr }; diff --git a/Drivers/rgb-display-module/source/rgb_display.cpp b/Drivers/rgb-display-module/source/rgb_display.cpp index 49ec423d7..f3cbdc187 100644 --- a/Drivers/rgb-display-module/source/rgb_display.cpp +++ b/Drivers/rgb-display-module/source/rgb_display.cpp @@ -3,7 +3,6 @@ #if SOC_LCD_RGB_SUPPORTED #include -#include #include #include @@ -508,7 +507,6 @@ Driver rgb_display_driver = { .stop_device = stop, .api = &rgb_display_api, .device_type = &DISPLAY_TYPE, - .owner = &rgb_display_module, .internal = nullptr }; diff --git a/Drivers/rx8130ce-module/source/rx8130ce.cpp b/Drivers/rx8130ce-module/source/rx8130ce.cpp index 13df61574..9b7ebe80e 100644 --- a/Drivers/rx8130ce-module/source/rx8130ce.cpp +++ b/Drivers/rx8130ce-module/source/rx8130ce.cpp @@ -1,6 +1,5 @@ // SPDX-License-Identifier: Apache-2.0 #include -#include #include #include #include @@ -163,7 +162,6 @@ Driver rx8130ce_driver = { .stop_device = stop, .api = &rx8130ce_rtc_api, .device_type = &RTC_TYPE, - .owner = &rx8130ce_module, .internal = nullptr }; diff --git a/Drivers/sc2356-module/source/sc2356.cpp b/Drivers/sc2356-module/source/sc2356.cpp index 2f7e9086c..d3d9f8e4c 100644 --- a/Drivers/sc2356-module/source/sc2356.cpp +++ b/Drivers/sc2356-module/source/sc2356.cpp @@ -1,6 +1,5 @@ // SPDX-License-Identifier: Apache-2.0 #include -#include #include #include @@ -596,7 +595,6 @@ Driver sc2356_driver = { .stop_device = stop, .api = &sc2356_camera_api, .device_type = &CAMERA_TYPE, - .owner = &sc2356_module, .internal = nullptr }; diff --git a/Drivers/ssd1306-module/source/ssd1306.cpp b/Drivers/ssd1306-module/source/ssd1306.cpp index fc73af700..41622789e 100644 --- a/Drivers/ssd1306-module/source/ssd1306.cpp +++ b/Drivers/ssd1306-module/source/ssd1306.cpp @@ -1,6 +1,5 @@ // SPDX-License-Identifier: Apache-2.0 #include -#include #include #include @@ -346,6 +345,5 @@ Driver ssd1306_driver = { .stop_device = stop, .api = &ssd1306_display_api, .device_type = &DISPLAY_TYPE, - .owner = &ssd1306_module, .internal = nullptr }; diff --git a/Drivers/st7121-module/source/st7121.cpp b/Drivers/st7121-module/source/st7121.cpp index c834ab31c..57b10dba4 100644 --- a/Drivers/st7121-module/source/st7121.cpp +++ b/Drivers/st7121-module/source/st7121.cpp @@ -3,7 +3,6 @@ #if SOC_MIPI_DSI_SUPPORTED #include -#include #include #include @@ -593,7 +592,6 @@ Driver st7121_driver = { .stop_device = stop, .api = &st7121_display_api, .device_type = &DISPLAY_TYPE, - .owner = &st7121_module, .internal = nullptr }; diff --git a/Drivers/st7123-module/source/st7123.cpp b/Drivers/st7123-module/source/st7123.cpp index 9c6e45ce8..9967e1894 100644 --- a/Drivers/st7123-module/source/st7123.cpp +++ b/Drivers/st7123-module/source/st7123.cpp @@ -3,7 +3,6 @@ #if SOC_MIPI_DSI_SUPPORTED #include -#include #include #include @@ -593,7 +592,6 @@ Driver st7123_driver = { .stop_device = stop, .api = &st7123_display_api, .device_type = &DISPLAY_TYPE, - .owner = &st7123_module, .internal = nullptr }; diff --git a/Drivers/st7123-module/source/st7123_touch.cpp b/Drivers/st7123-module/source/st7123_touch.cpp index b7e6c140e..b2adf7135 100644 --- a/Drivers/st7123-module/source/st7123_touch.cpp +++ b/Drivers/st7123-module/source/st7123_touch.cpp @@ -1,6 +1,5 @@ // SPDX-License-Identifier: Apache-2.0 #include -#include #include #include @@ -201,6 +200,5 @@ Driver st7123_touch_driver = { .stop_device = stop, .api = &st7123_touch_pointer_api, .device_type = &POINTER_TYPE, - .owner = &st7123_module, .internal = nullptr }; diff --git a/Drivers/st7305-module/source/st7305.cpp b/Drivers/st7305-module/source/st7305.cpp index 2d6b7769c..9252be813 100644 --- a/Drivers/st7305-module/source/st7305.cpp +++ b/Drivers/st7305-module/source/st7305.cpp @@ -1,6 +1,5 @@ // SPDX-License-Identifier: Apache-2.0 #include -#include #include #include @@ -416,6 +415,5 @@ Driver st7305_driver = { .stop_device = stop, .api = &st7305_display_api, .device_type = &DISPLAY_TYPE, - .owner = &st7305_module, .internal = nullptr }; diff --git a/Drivers/st7701-module/source/st7701.cpp b/Drivers/st7701-module/source/st7701.cpp index 18cbdb9b5..6c32163ee 100644 --- a/Drivers/st7701-module/source/st7701.cpp +++ b/Drivers/st7701-module/source/st7701.cpp @@ -3,7 +3,6 @@ #if SOC_LCD_RGB_SUPPORTED #include -#include #include #include @@ -553,7 +552,6 @@ Driver st7701_driver = { .stop_device = stop, .api = &st7701_display_api, .device_type = &DISPLAY_TYPE, - .owner = &st7701_module, .internal = nullptr }; diff --git a/Drivers/st7735-module/source/st7735.cpp b/Drivers/st7735-module/source/st7735.cpp index e017ce2bc..a0078eb61 100644 --- a/Drivers/st7735-module/source/st7735.cpp +++ b/Drivers/st7735-module/source/st7735.cpp @@ -1,6 +1,5 @@ // SPDX-License-Identifier: Apache-2.0 #include -#include #include #include @@ -384,6 +383,5 @@ Driver st7735_driver = { .stop_device = stop, .api = &st7735_display_api, .device_type = &DISPLAY_TYPE, - .owner = &st7735_module, .internal = nullptr }; diff --git a/Drivers/st7789-i8080-module/source/st7789_i8080.cpp b/Drivers/st7789-i8080-module/source/st7789_i8080.cpp index a59825ed8..1de4a1222 100644 --- a/Drivers/st7789-i8080-module/source/st7789_i8080.cpp +++ b/Drivers/st7789-i8080-module/source/st7789_i8080.cpp @@ -1,6 +1,5 @@ // SPDX-License-Identifier: Apache-2.0 #include -#include #include #include @@ -373,6 +372,5 @@ Driver st7789_i8080_driver = { .stop_device = stop, .api = &st7789_i8080_display_api, .device_type = &DISPLAY_TYPE, - .owner = &st7789_i8080_module, .internal = nullptr }; diff --git a/Drivers/st7789-module/source/st7789.cpp b/Drivers/st7789-module/source/st7789.cpp index ff6b95842..16ec94ab2 100644 --- a/Drivers/st7789-module/source/st7789.cpp +++ b/Drivers/st7789-module/source/st7789.cpp @@ -1,6 +1,5 @@ // SPDX-License-Identifier: Apache-2.0 #include -#include #include #include @@ -384,6 +383,5 @@ Driver st7789_driver = { .stop_device = stop, .api = &st7789_display_api, .device_type = &DISPLAY_TYPE, - .owner = &st7789_module, .internal = nullptr }; diff --git a/Drivers/st7789-soft-i8080-module/source/st7789_soft_i8080.cpp b/Drivers/st7789-soft-i8080-module/source/st7789_soft_i8080.cpp index a309e08f6..ba94f0044 100644 --- a/Drivers/st7789-soft-i8080-module/source/st7789_soft_i8080.cpp +++ b/Drivers/st7789-soft-i8080-module/source/st7789_soft_i8080.cpp @@ -1,6 +1,5 @@ // SPDX-License-Identifier: Apache-2.0 #include -#include #include #include @@ -429,6 +428,5 @@ Driver st7789_soft_i8080_driver = { .probe = nullptr, .api = &st7789_soft_i8080_display_api, .device_type = &DISPLAY_TYPE, - .owner = &st7789_soft_i8080_module, .internal = nullptr }; \ No newline at end of file diff --git a/Drivers/st7796-i8080-module/source/st7796_i8080.cpp b/Drivers/st7796-i8080-module/source/st7796_i8080.cpp index 76d958508..fb5ffac16 100644 --- a/Drivers/st7796-i8080-module/source/st7796_i8080.cpp +++ b/Drivers/st7796-i8080-module/source/st7796_i8080.cpp @@ -1,6 +1,5 @@ // SPDX-License-Identifier: Apache-2.0 #include -#include #include #include @@ -328,6 +327,5 @@ Driver st7796_i8080_driver = { .stop_device = stop, .api = &st7796_i8080_display_api, .device_type = &DISPLAY_TYPE, - .owner = &st7796_i8080_module, .internal = nullptr }; diff --git a/Drivers/st7796-module/source/st7796.cpp b/Drivers/st7796-module/source/st7796.cpp index b719606a1..6f8e595e3 100644 --- a/Drivers/st7796-module/source/st7796.cpp +++ b/Drivers/st7796-module/source/st7796.cpp @@ -1,6 +1,5 @@ // SPDX-License-Identifier: Apache-2.0 #include -#include #include #include @@ -384,6 +383,5 @@ Driver st7796_driver = { .stop_device = stop, .api = &st7796_display_api, .device_type = &DISPLAY_TYPE, - .owner = &st7796_module, .internal = nullptr }; diff --git a/Drivers/sx126x-module/source/sx1262.cpp b/Drivers/sx126x-module/source/sx1262.cpp index 85aec9a44..3dd2ccc08 100644 --- a/Drivers/sx126x-module/source/sx1262.cpp +++ b/Drivers/sx126x-module/source/sx1262.cpp @@ -326,8 +326,6 @@ static const struct LoraApi sx1262_lora_api = { // endregion -extern Module sx126x_module; - Driver sx1262_driver = { .name = "sx1262", .compatible = (const char*[]) { "semtech,sx1262", nullptr }, @@ -335,7 +333,6 @@ Driver sx1262_driver = { .stop_device = stop, .api = &sx1262_lora_api, .device_type = &LORA_TYPE, - .owner = &sx126x_module, .internal = nullptr }; diff --git a/Drivers/sy6970-module/source/sy6970.cpp b/Drivers/sy6970-module/source/sy6970.cpp index 3e915f4ff..b7acf615d 100644 --- a/Drivers/sy6970-module/source/sy6970.cpp +++ b/Drivers/sy6970-module/source/sy6970.cpp @@ -1,6 +1,5 @@ // SPDX-License-Identifier: Apache-2.0 #include -#include #include #include @@ -152,7 +151,6 @@ Driver sy6970_power_supply_driver = { .stop_device = nullptr, .api = &SY6970_POWER_SUPPLY_API, .device_type = &POWER_SUPPLY_TYPE, - .owner = &sy6970_module, .internal = nullptr }; @@ -242,7 +240,6 @@ Driver sy6970_driver = { .stop_device = stop, .api = nullptr, .device_type = nullptr, - .owner = &sy6970_module, .internal = nullptr }; diff --git a/Drivers/tca8418-module/source/tca8418.cpp b/Drivers/tca8418-module/source/tca8418.cpp index 55db1729d..5d485cc37 100644 --- a/Drivers/tca8418-module/source/tca8418.cpp +++ b/Drivers/tca8418-module/source/tca8418.cpp @@ -1,8 +1,6 @@ // SPDX-License-Identifier: Apache-2.0 #include -#include - #include #include #include @@ -290,6 +288,5 @@ Driver tca8418_driver = { .stop_device = stop, .api = &tca8418_api, .device_type = &KEYBOARD_TYPE, - .owner = &tca8418_module, .internal = nullptr }; diff --git a/Drivers/tca9534-module/source/tca9534.cpp b/Drivers/tca9534-module/source/tca9534.cpp index 3fc5eb97c..40de8aea9 100644 --- a/Drivers/tca9534-module/source/tca9534.cpp +++ b/Drivers/tca9534-module/source/tca9534.cpp @@ -1,6 +1,5 @@ // SPDX-License-Identifier: Apache-2.0 #include -#include #include #include #include @@ -162,7 +161,6 @@ Driver tca9534_driver = { .stop_device = stop, .api = static_cast(&tca9534_gpio_api), .device_type = &GPIO_CONTROLLER_TYPE, - .owner = &tca9534_module, .internal = nullptr }; diff --git a/Drivers/tca95xx-16bit-module/source/tca95xx.cpp b/Drivers/tca95xx-16bit-module/source/tca95xx.cpp index 59e618f91..1101b7366 100644 --- a/Drivers/tca95xx-16bit-module/source/tca95xx.cpp +++ b/Drivers/tca95xx-16bit-module/source/tca95xx.cpp @@ -182,7 +182,6 @@ Driver tca95xx_driver = { .stop_device = stop, .api = static_cast(&tca95xx_gpio_api), .device_type = &GPIO_CONTROLLER_TYPE, - .owner = &tca95xx_16bit_module, .internal = nullptr }; diff --git a/Drivers/xl9555-module/source/xl9555.cpp b/Drivers/xl9555-module/source/xl9555.cpp index 4756fea05..98a1ab660 100644 --- a/Drivers/xl9555-module/source/xl9555.cpp +++ b/Drivers/xl9555-module/source/xl9555.cpp @@ -1,6 +1,5 @@ // SPDX-License-Identifier: Apache-2.0 #include -#include #include #include #include @@ -187,7 +186,6 @@ Driver xl9555_driver = { .stop_device = stop, .api = static_cast(&xl9555_gpio_api), .device_type = &GPIO_CONTROLLER_TYPE, - .owner = &xl9555_module, .internal = nullptr }; diff --git a/Drivers/xpt2046-module/source/xpt2046.cpp b/Drivers/xpt2046-module/source/xpt2046.cpp index 259491e81..ee81979e8 100644 --- a/Drivers/xpt2046-module/source/xpt2046.cpp +++ b/Drivers/xpt2046-module/source/xpt2046.cpp @@ -1,6 +1,5 @@ // SPDX-License-Identifier: Apache-2.0 #include -#include #include #include @@ -117,7 +116,6 @@ Driver xpt2046_power_supply_driver = { .stop_device = nullptr, .api = &XPT2046_POWER_SUPPLY_API, .device_type = &POWER_SUPPLY_TYPE, - .owner = &xpt2046_module, .internal = nullptr }; @@ -368,6 +366,5 @@ Driver xpt2046_driver = { .stop_device = stop, .api = &xpt2046_pointer_api, .device_type = &POINTER_TYPE, - .owner = &xpt2046_module, .internal = nullptr }; diff --git a/Drivers/xpt2046-softspi-module/source/xpt2046_softspi.cpp b/Drivers/xpt2046-softspi-module/source/xpt2046_softspi.cpp index e148e1d9b..1e01491fd 100644 --- a/Drivers/xpt2046-softspi-module/source/xpt2046_softspi.cpp +++ b/Drivers/xpt2046-softspi-module/source/xpt2046_softspi.cpp @@ -1,8 +1,6 @@ // SPDX-License-Identifier: Apache-2.0 #include -#include - #include #include #include @@ -245,7 +243,6 @@ Driver xpt2046_softspi_power_supply_driver = { .stop_device = nullptr, .api = &XPT2046_SOFTSPI_POWER_SUPPLY_API, .device_type = &POWER_SUPPLY_TYPE, - .owner = &xpt2046_softspi_module, .internal = nullptr }; @@ -434,6 +431,5 @@ Driver xpt2046_softspi_driver = { .stop_device = stop, .api = &xpt2046_softspi_pointer_api, .device_type = &POINTER_TYPE, - .owner = &xpt2046_softspi_module, .internal = nullptr }; diff --git a/Platforms/platform-esp32/source/drivers/bluetooth/esp32_ble.cpp b/Platforms/platform-esp32/source/drivers/bluetooth/esp32_ble.cpp index bf5179bac..f9295d433 100644 --- a/Platforms/platform-esp32/source/drivers/bluetooth/esp32_ble.cpp +++ b/Platforms/platform-esp32/source/drivers/bluetooth/esp32_ble.cpp @@ -1280,7 +1280,6 @@ Driver esp32_bluetooth_driver = { .stop_device = esp32_ble_stop_device, .api = &nimble_bluetooth_api, .device_type = &BLUETOOTH_TYPE, - .owner = nullptr, .internal = nullptr, }; diff --git a/Platforms/platform-esp32/source/drivers/bluetooth/esp32_ble_hid.cpp b/Platforms/platform-esp32/source/drivers/bluetooth/esp32_ble_hid.cpp index aa4f1ac6d..89322ce06 100644 --- a/Platforms/platform-esp32/source/drivers/bluetooth/esp32_ble_hid.cpp +++ b/Platforms/platform-esp32/source/drivers/bluetooth/esp32_ble_hid.cpp @@ -526,7 +526,6 @@ Driver esp32_ble_hid_device_driver = { .stop_device = esp32_ble_hid_device_stop_device, .api = &nimble_hid_device_api, .device_type = &BLUETOOTH_HID_DEVICE_TYPE, - .owner = nullptr, .internal = nullptr, }; diff --git a/Platforms/platform-esp32/source/drivers/bluetooth/esp32_ble_midi.cpp b/Platforms/platform-esp32/source/drivers/bluetooth/esp32_ble_midi.cpp index 67cfcd4a7..458c5b1f8 100644 --- a/Platforms/platform-esp32/source/drivers/bluetooth/esp32_ble_midi.cpp +++ b/Platforms/platform-esp32/source/drivers/bluetooth/esp32_ble_midi.cpp @@ -263,7 +263,6 @@ Driver esp32_ble_midi_driver = { .stop_device = esp32_ble_midi_stop_device, .api = &nimble_midi_api, .device_type = &BLUETOOTH_MIDI_TYPE, - .owner = nullptr, .internal = nullptr, }; diff --git a/Platforms/platform-esp32/source/drivers/bluetooth/esp32_ble_spp.cpp b/Platforms/platform-esp32/source/drivers/bluetooth/esp32_ble_spp.cpp index a3ee4fcd2..3d3332d07 100644 --- a/Platforms/platform-esp32/source/drivers/bluetooth/esp32_ble_spp.cpp +++ b/Platforms/platform-esp32/source/drivers/bluetooth/esp32_ble_spp.cpp @@ -238,7 +238,6 @@ Driver esp32_ble_serial_driver = { .stop_device = esp32_ble_serial_stop_device, .api = &nimble_serial_api, .device_type = &BLUETOOTH_SERIAL_TYPE, - .owner = nullptr, .internal = nullptr, }; diff --git a/Platforms/platform-esp32/source/drivers/esp32_adc_oneshot.cpp b/Platforms/platform-esp32/source/drivers/esp32_adc_oneshot.cpp index 51f115237..c55ae42c0 100644 --- a/Platforms/platform-esp32/source/drivers/esp32_adc_oneshot.cpp +++ b/Platforms/platform-esp32/source/drivers/esp32_adc_oneshot.cpp @@ -86,8 +86,6 @@ static constexpr AdcControllerApi ESP32_ADC_ONESHOT_API = { .read_raw = read_raw }; -extern Module platform_esp32_module; - Driver esp32_adc_oneshot_driver = { .name = "esp32_adc_oneshot", .compatible = (const char*[]) { "espressif,esp32-adc-oneshot", nullptr }, @@ -95,7 +93,6 @@ Driver esp32_adc_oneshot_driver = { .stop_device = stop, .api = &ESP32_ADC_ONESHOT_API, .device_type = &ADC_CONTROLLER_TYPE, - .owner = &platform_esp32_module, .internal = nullptr }; diff --git a/Platforms/platform-esp32/source/drivers/esp32_gpio.cpp b/Platforms/platform-esp32/source/drivers/esp32_gpio.cpp index d2b42876d..166d99326 100644 --- a/Platforms/platform-esp32/source/drivers/esp32_gpio.cpp +++ b/Platforms/platform-esp32/source/drivers/esp32_gpio.cpp @@ -192,8 +192,6 @@ const static GpioControllerApi esp32_gpio_api = { .disable_interrupt = disable_interrupt }; -extern Module platform_esp32_module; - Driver esp32_gpio_driver = { .name = "esp32_gpio", .compatible = (const char*[]) { "espressif,esp32-gpio", nullptr }, @@ -201,7 +199,6 @@ Driver esp32_gpio_driver = { .stop_device = stop, .api = static_cast(&esp32_gpio_api), .device_type = &GPIO_CONTROLLER_TYPE, - .owner = &platform_esp32_module, .internal = nullptr }; diff --git a/Platforms/platform-esp32/source/drivers/esp32_grove.cpp b/Platforms/platform-esp32/source/drivers/esp32_grove.cpp index edb7955b3..47e1d6b80 100644 --- a/Platforms/platform-esp32/source/drivers/esp32_grove.cpp +++ b/Platforms/platform-esp32/source/drivers/esp32_grove.cpp @@ -211,8 +211,6 @@ static const GroveApi esp32_grove_api = { .get_mode = esp32_grove_get_mode }; -extern Module platform_esp32_module; - Driver esp32_grove_driver = { .name = "esp32_grove", .compatible = (const char*[]) { "espressif,esp32-grove", nullptr }, @@ -220,7 +218,6 @@ Driver esp32_grove_driver = { .stop_device = stop_device, .api = &esp32_grove_api, .device_type = &GROVE_TYPE, - .owner = &platform_esp32_module, .internal = nullptr }; diff --git a/Platforms/platform-esp32/source/drivers/esp32_i2c_master.cpp b/Platforms/platform-esp32/source/drivers/esp32_i2c_master.cpp index c573dc359..0a17059d1 100644 --- a/Platforms/platform-esp32/source/drivers/esp32_i2c_master.cpp +++ b/Platforms/platform-esp32/source/drivers/esp32_i2c_master.cpp @@ -272,8 +272,6 @@ static constexpr I2cControllerApi ESP32_I2C_MASTER_API = { .probe = probe, }; -extern Module platform_esp32_module; - Driver esp32_i2c_master_driver = { .name = "esp32_i2c_master", .compatible = (const char*[]) { "espressif,esp32-i2c-master", nullptr }, @@ -281,7 +279,6 @@ Driver esp32_i2c_master_driver = { .stop_device = stop, .api = &ESP32_I2C_MASTER_API, .device_type = &I2C_CONTROLLER_TYPE, - .owner = &platform_esp32_module, .internal = nullptr, }; diff --git a/Platforms/platform-esp32/source/drivers/esp32_i2s.cpp b/Platforms/platform-esp32/source/drivers/esp32_i2s.cpp index 336091bb7..c1ccb1df9 100644 --- a/Platforms/platform-esp32/source/drivers/esp32_i2s.cpp +++ b/Platforms/platform-esp32/source/drivers/esp32_i2s.cpp @@ -544,8 +544,6 @@ const static I2sControllerApi esp32_i2s_api = { .disable_direction = disable_direction, }; -extern struct Module platform_esp32_module; - Driver esp32_i2s_driver = { .name = "esp32_i2s", .compatible = (const char*[]) { "espressif,esp32-i2s", nullptr }, @@ -553,7 +551,6 @@ Driver esp32_i2s_driver = { .stop_device = stop, .api = (void*)&esp32_i2s_api, .device_type = &I2S_CONTROLLER_TYPE, - .owner = &platform_esp32_module, .internal = nullptr }; diff --git a/Platforms/platform-esp32/source/drivers/esp32_i8080.cpp b/Platforms/platform-esp32/source/drivers/esp32_i8080.cpp index d49f597fe..2dc530d63 100644 --- a/Platforms/platform-esp32/source/drivers/esp32_i8080.cpp +++ b/Platforms/platform-esp32/source/drivers/esp32_i8080.cpp @@ -172,8 +172,6 @@ error_t esp32_i8080_get_bus_handle(Device* child_device, esp_lcd_i80_bus_handle_ return ERROR_NONE; } -extern struct Module platform_esp32_module; - Driver esp32_i8080_driver = { .name = "esp32_i8080", .compatible = (const char*[]) { "espressif,esp32-i8080", nullptr }, @@ -181,7 +179,6 @@ Driver esp32_i8080_driver = { .stop_device = stop, .api = nullptr, .device_type = &I8080_CONTROLLER_TYPE, - .owner = &platform_esp32_module, .internal = nullptr }; diff --git a/Platforms/platform-esp32/source/drivers/esp32_pwm_ledc.cpp b/Platforms/platform-esp32/source/drivers/esp32_pwm_ledc.cpp index 612836ad5..ae264872d 100644 --- a/Platforms/platform-esp32/source/drivers/esp32_pwm_ledc.cpp +++ b/Platforms/platform-esp32/source/drivers/esp32_pwm_ledc.cpp @@ -245,8 +245,6 @@ static const PwmApi esp32_pwm_ledc_api = { .is_enabled = esp32_pwm_ledc_is_enabled, }; -extern Module platform_esp32_module; - Driver esp32_pwm_ledc_driver = { .name = "esp32_pwm_ledc", .compatible = (const char*[]) { "espressif,esp32-pwm-ledc", nullptr }, @@ -254,6 +252,5 @@ Driver esp32_pwm_ledc_driver = { .stop_device = stop, .api = &esp32_pwm_ledc_api, .device_type = &PWM_TYPE, - .owner = &platform_esp32_module, .internal = nullptr }; diff --git a/Platforms/platform-esp32/source/drivers/esp32_sdmmc.cpp b/Platforms/platform-esp32/source/drivers/esp32_sdmmc.cpp index 9d0578449..af9a1e886 100644 --- a/Platforms/platform-esp32/source/drivers/esp32_sdmmc.cpp +++ b/Platforms/platform-esp32/source/drivers/esp32_sdmmc.cpp @@ -170,8 +170,6 @@ sdmmc_card_t* esp32_sdmmc_get_card(Device* device) { return card; } -extern Module platform_esp32_module; - Driver esp32_sdmmc_driver = { .name = "esp32_sdmmc", .compatible = (const char*[]) { "espressif,esp32-sdmmc", nullptr }, @@ -179,7 +177,6 @@ Driver esp32_sdmmc_driver = { .stop_device = stop, .api = nullptr, .device_type = &SDCARD_TYPE, - .owner = &platform_esp32_module, .internal = nullptr }; diff --git a/Platforms/platform-esp32/source/drivers/esp32_sdspi.cpp b/Platforms/platform-esp32/source/drivers/esp32_sdspi.cpp index 085026200..316ad87e5 100644 --- a/Platforms/platform-esp32/source/drivers/esp32_sdspi.cpp +++ b/Platforms/platform-esp32/source/drivers/esp32_sdspi.cpp @@ -177,8 +177,6 @@ sdmmc_card_t* esp32_sdspi_get_card(Device* device) { return card; } -extern Module platform_esp32_module; - Driver esp32_sdspi_driver = { .name = "esp32_sdspi", .compatible = (const char*[]) { "espressif,esp32-sdspi", nullptr }, @@ -186,7 +184,6 @@ Driver esp32_sdspi_driver = { .stop_device = stop, .api = nullptr, .device_type = &SDCARD_TYPE, - .owner = &platform_esp32_module, .internal = nullptr }; diff --git a/Platforms/platform-esp32/source/drivers/esp32_spi.cpp b/Platforms/platform-esp32/source/drivers/esp32_spi.cpp index e4cc2ee97..bdb2617c3 100644 --- a/Platforms/platform-esp32/source/drivers/esp32_spi.cpp +++ b/Platforms/platform-esp32/source/drivers/esp32_spi.cpp @@ -191,8 +191,6 @@ const static struct SpiControllerApi esp32_spi_api = { .unlock = unlock }; -extern struct Module platform_esp32_module; - Driver esp32_spi_driver = { .name = "esp32_spi", .compatible = (const char*[]) { "espressif,esp32-spi", nullptr }, @@ -200,7 +198,6 @@ Driver esp32_spi_driver = { .stop_device = stop, .api = (void*)&esp32_spi_api, .device_type = &SPI_CONTROLLER_TYPE, - .owner = &platform_esp32_module, .internal = nullptr }; diff --git a/Platforms/platform-esp32/source/drivers/esp32_uart.cpp b/Platforms/platform-esp32/source/drivers/esp32_uart.cpp index be6071432..951e1985f 100644 --- a/Platforms/platform-esp32/source/drivers/esp32_uart.cpp +++ b/Platforms/platform-esp32/source/drivers/esp32_uart.cpp @@ -403,8 +403,6 @@ const static UartControllerApi esp32_uart_api = { .flush_input = flush_input }; -extern struct Module platform_esp32_module; - Driver esp32_uart_driver = { .name = "esp32_uart", .compatible = (const char*[]) { "espressif,esp32-uart", nullptr }, @@ -412,7 +410,6 @@ Driver esp32_uart_driver = { .stop_device = stop, .api = (void*)&esp32_uart_api, .device_type = &UART_CONTROLLER_TYPE, - .owner = &platform_esp32_module, .internal = nullptr }; diff --git a/Platforms/platform-esp32/source/drivers/esp32_wifi.cpp b/Platforms/platform-esp32/source/drivers/esp32_wifi.cpp index cd6e25e44..4d2d79e82 100644 --- a/Platforms/platform-esp32/source/drivers/esp32_wifi.cpp +++ b/Platforms/platform-esp32/source/drivers/esp32_wifi.cpp @@ -712,8 +712,6 @@ void esp32_wifi_radio_release(wifi_mode_t mode_bit) { mutex_unlock(&g_radioMutex); } -extern Module platform_esp32_module; - Driver esp32_wifi_driver = { .name = "esp32_wifi", .compatible = (const char*[]) { "espressif,esp32-wifi", nullptr }, @@ -721,7 +719,6 @@ Driver esp32_wifi_driver = { .stop_device = stop_device, .api = (const void*)&esp32_wifi_api, .device_type = &WIFI_TYPE, - .owner = &platform_esp32_module, .internal = nullptr }; diff --git a/Platforms/platform-esp32/source/drivers/esp32_wifi_pinned.cpp b/Platforms/platform-esp32/source/drivers/esp32_wifi_pinned.cpp index 963cba34a..c8ee8e2dd 100644 --- a/Platforms/platform-esp32/source/drivers/esp32_wifi_pinned.cpp +++ b/Platforms/platform-esp32/source/drivers/esp32_wifi_pinned.cpp @@ -351,8 +351,6 @@ error_t stop_device(Device* device) { extern "C" { -extern Module platform_esp32_module; - Driver esp32_wifi_pinned_driver = { .name = "esp32_wifi_pinned", .compatible = (const char*[]) { "espressif,esp32-wifi-pinned", nullptr }, @@ -360,7 +358,6 @@ Driver esp32_wifi_pinned_driver = { .stop_device = stop_device, .api = (const void*)&esp32_wifi_pinned_api, .device_type = &WIFI_TYPE, - .owner = &platform_esp32_module, .internal = nullptr }; diff --git a/Platforms/platform-esp32/source/drivers/usb/esp32_usb_cdc_device.cpp b/Platforms/platform-esp32/source/drivers/usb/esp32_usb_cdc_device.cpp index b83548161..0617c47c1 100644 --- a/Platforms/platform-esp32/source/drivers/usb/esp32_usb_cdc_device.cpp +++ b/Platforms/platform-esp32/source/drivers/usb/esp32_usb_cdc_device.cpp @@ -176,7 +176,6 @@ Driver esp32_usb_cdc_device_driver = { .stop_device = stop_device, .api = &esp32_usb_cdc_device_api, .device_type = &USB_CDC_DEVICE_TYPE, - .owner = nullptr, .internal = nullptr, }; diff --git a/Platforms/platform-esp32/source/drivers/usb/esp32_usb_device_controller.cpp b/Platforms/platform-esp32/source/drivers/usb/esp32_usb_device_controller.cpp index 06703af50..7914fb769 100644 --- a/Platforms/platform-esp32/source/drivers/usb/esp32_usb_device_controller.cpp +++ b/Platforms/platform-esp32/source/drivers/usb/esp32_usb_device_controller.cpp @@ -406,7 +406,6 @@ Driver esp32_usb_device_controller_driver = { .stop_device = stop_device, .api = &usb_device_controller_api, .device_type = &USB_DEVICE_CONTROLLER_TYPE, - .owner = nullptr, .internal = nullptr, }; diff --git a/Platforms/platform-esp32/source/drivers/usb/esp32_usb_device_msc.cpp b/Platforms/platform-esp32/source/drivers/usb/esp32_usb_device_msc.cpp index 2e68aa44d..1ee92fa48 100644 --- a/Platforms/platform-esp32/source/drivers/usb/esp32_usb_device_msc.cpp +++ b/Platforms/platform-esp32/source/drivers/usb/esp32_usb_device_msc.cpp @@ -289,7 +289,6 @@ Driver esp32_usb_msc_device_driver = { .stop_device = stop_device, .api = &esp32_usb_msc_device_api, .device_type = &USB_MSC_DEVICE_TYPE, - .owner = nullptr, .internal = nullptr, }; diff --git a/Platforms/platform-esp32/source/drivers/usb/esp32_usb_hid_device.cpp b/Platforms/platform-esp32/source/drivers/usb/esp32_usb_hid_device.cpp index bd5e5919a..fe9147cba 100644 --- a/Platforms/platform-esp32/source/drivers/usb/esp32_usb_hid_device.cpp +++ b/Platforms/platform-esp32/source/drivers/usb/esp32_usb_hid_device.cpp @@ -343,7 +343,6 @@ Driver esp32_usb_hid_device_driver = { .stop_device = stop_device, .api = &esp32_usb_hid_device_api, .device_type = &USB_HID_DEVICE_TYPE, - .owner = nullptr, .internal = nullptr, }; diff --git a/Platforms/platform-esp32/source/drivers/usb/esp32_usb_midi_device.cpp b/Platforms/platform-esp32/source/drivers/usb/esp32_usb_midi_device.cpp index 17e77665b..25f2b1278 100644 --- a/Platforms/platform-esp32/source/drivers/usb/esp32_usb_midi_device.cpp +++ b/Platforms/platform-esp32/source/drivers/usb/esp32_usb_midi_device.cpp @@ -186,7 +186,6 @@ Driver esp32_usb_midi_device_driver = { .stop_device = stop_device, .api = &esp32_usb_midi_device_api, .device_type = &USB_MIDI_DEVICE_TYPE, - .owner = nullptr, .internal = nullptr, }; diff --git a/Platforms/platform-esp32/source/drivers/usb/esp32_usbhost.cpp b/Platforms/platform-esp32/source/drivers/usb/esp32_usbhost.cpp index 1f278c05a..0ade1ef58 100644 --- a/Platforms/platform-esp32/source/drivers/usb/esp32_usbhost.cpp +++ b/Platforms/platform-esp32/source/drivers/usb/esp32_usbhost.cpp @@ -535,7 +535,6 @@ Driver esp32_usbhost_driver = { .probe = nullptr, .api = &usb_host_api, .device_type = &USB_HOST_TYPE, - .owner = nullptr, .internal = nullptr, }; diff --git a/Platforms/platform-esp32/source/drivers/usb/esp32_usbhost_hid.cpp b/Platforms/platform-esp32/source/drivers/usb/esp32_usbhost_hid.cpp index 2087e2947..060a02de4 100644 --- a/Platforms/platform-esp32/source/drivers/usb/esp32_usbhost_hid.cpp +++ b/Platforms/platform-esp32/source/drivers/usb/esp32_usbhost_hid.cpp @@ -510,7 +510,6 @@ Driver esp32_usbhost_hid_keyboard_driver = { .probe = nullptr, .api = &esp32_usbhost_hid_keyboard_api, .device_type = &KEYBOARD_TYPE, - .owner = nullptr, .internal = nullptr, }; @@ -712,7 +711,6 @@ Driver esp32_usbhost_hid_driver = { .stop_device = hid_device_stop, .api = &hid_api, .device_type = &USB_HOST_HID_TYPE, - .owner = nullptr, .internal = nullptr, }; diff --git a/Platforms/platform-esp32/source/drivers/usb/esp32_usbhost_midi.cpp b/Platforms/platform-esp32/source/drivers/usb/esp32_usbhost_midi.cpp index 3ef03f812..05ca6f0fa 100644 --- a/Platforms/platform-esp32/source/drivers/usb/esp32_usbhost_midi.cpp +++ b/Platforms/platform-esp32/source/drivers/usb/esp32_usbhost_midi.cpp @@ -327,7 +327,6 @@ Driver esp32_usbhost_midi_driver = { .stop_device = midi_device_stop, .api = nullptr, .device_type = &USB_HOST_MIDI_TYPE, - .owner = nullptr, .internal = nullptr, }; diff --git a/Platforms/platform-esp32/source/drivers/usb/esp32_usbhost_msc.cpp b/Platforms/platform-esp32/source/drivers/usb/esp32_usbhost_msc.cpp index 159796da0..70d8c2f13 100644 --- a/Platforms/platform-esp32/source/drivers/usb/esp32_usbhost_msc.cpp +++ b/Platforms/platform-esp32/source/drivers/usb/esp32_usbhost_msc.cpp @@ -429,7 +429,6 @@ Driver esp32_usbhost_msc_driver = { .stop_device = msc_device_stop, .api = &msc_api, .device_type = &USB_HOST_MSC_TYPE, - .owner = nullptr, .internal = nullptr, }; diff --git a/Platforms/platform-esp32/source/drivers/usb/esp32_usbhost_uac.cpp b/Platforms/platform-esp32/source/drivers/usb/esp32_usbhost_uac.cpp index 3bc74b096..21eb8788a 100644 --- a/Platforms/platform-esp32/source/drivers/usb/esp32_usbhost_uac.cpp +++ b/Platforms/platform-esp32/source/drivers/usb/esp32_usbhost_uac.cpp @@ -580,7 +580,6 @@ Driver usb_uac_codec_driver = { .stop_device = codec_stop_device, .api = &codec_api, .device_type = &AUDIO_CODEC_TYPE, - .owner = nullptr, .internal = nullptr, }; diff --git a/Platforms/platform-posix/CMakeLists.txt b/Platforms/platform-posix/CMakeLists.txt index 4f6c929b7..c0bd284d8 100644 --- a/Platforms/platform-posix/CMakeLists.txt +++ b/Platforms/platform-posix/CMakeLists.txt @@ -4,7 +4,7 @@ file(GLOB_RECURSE SOURCES "source/*.c**") add_library(platform-posix OBJECT) target_sources(platform-posix PRIVATE ${SOURCES}) -#target_include_directories(platform-posix PUBLIC include/) +target_include_directories(platform-posix PUBLIC include/) target_link_libraries(platform-posix PUBLIC TactilityKernel) # Routes every pthread_attr_setstack() call to __wrap_pthread_attr_setstack() in source/pthread_stack_wrap.c, diff --git a/Platforms/platform-posix/bindings/posix,i2c.yaml b/Platforms/platform-posix/bindings/posix,i2c.yaml new file mode 100644 index 000000000..9fef249ca --- /dev/null +++ b/Platforms/platform-posix/bindings/posix,i2c.yaml @@ -0,0 +1,11 @@ +description: POSIX I2C Controller that wraps a Linux i2c-dev device file (e.g. /dev/i2c-1) + +include: ["i2c-controller.yaml"] + +compatible: "posix,i2c" + +properties: + path: + type: string + required: true + description: Path to the i2c-dev device file diff --git a/Platforms/platform-posix/bindings/posix,uart.yaml b/Platforms/platform-posix/bindings/posix,uart.yaml new file mode 100644 index 000000000..b6fb13d34 --- /dev/null +++ b/Platforms/platform-posix/bindings/posix,uart.yaml @@ -0,0 +1,11 @@ +description: POSIX UART Controller that wraps a serial device file (e.g. /dev/ttyUSB0) + +include: ["uart-controller.yaml"] + +compatible: "posix,uart" + +properties: + path: + type: string + required: true + description: Path to the serial device file diff --git a/Platforms/platform-posix/include/tactility/bindings/posix_i2c.h b/Platforms/platform-posix/include/tactility/bindings/posix_i2c.h new file mode 100644 index 000000000..bae2ec165 --- /dev/null +++ b/Platforms/platform-posix/include/tactility/bindings/posix_i2c.h @@ -0,0 +1,15 @@ +// SPDX-License-Identifier: Apache-2.0 +#pragma once + +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +DEFINE_DEVICETREE(posix_i2c, struct PosixI2cConfig) + +#ifdef __cplusplus +} +#endif diff --git a/Platforms/platform-posix/include/tactility/bindings/posix_uart.h b/Platforms/platform-posix/include/tactility/bindings/posix_uart.h new file mode 100644 index 000000000..d0331e793 --- /dev/null +++ b/Platforms/platform-posix/include/tactility/bindings/posix_uart.h @@ -0,0 +1,15 @@ +// SPDX-License-Identifier: Apache-2.0 +#pragma once + +#include +#include + +#ifdef __cplusplus +extern "C" { +#endif + +DEFINE_DEVICETREE(posix_uart, struct PosixUartConfig) + +#ifdef __cplusplus +} +#endif diff --git a/Platforms/platform-posix/include/tactility/drivers/posix_i2c.h b/Platforms/platform-posix/include/tactility/drivers/posix_i2c.h new file mode 100644 index 000000000..7b50cf348 --- /dev/null +++ b/Platforms/platform-posix/include/tactility/drivers/posix_i2c.h @@ -0,0 +1,17 @@ +// SPDX-License-Identifier: Apache-2.0 +#pragma once + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/** Requires Linux i2c-dev. Starting the device fails with ERROR_NOT_SUPPORTED on other systems. */ +struct PosixI2cConfig { + const char* path; +}; + +#ifdef __cplusplus +} +#endif diff --git a/Platforms/platform-posix/include/tactility/drivers/posix_uart.h b/Platforms/platform-posix/include/tactility/drivers/posix_uart.h new file mode 100644 index 000000000..07966e337 --- /dev/null +++ b/Platforms/platform-posix/include/tactility/drivers/posix_uart.h @@ -0,0 +1,16 @@ +// SPDX-License-Identifier: Apache-2.0 +#pragma once + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +struct PosixUartConfig { + const char* path; +}; + +#ifdef __cplusplus +} +#endif diff --git a/Platforms/platform-posix/module.yaml b/Platforms/platform-posix/module.yaml index 6bbb24367..a07d6f334 100644 --- a/Platforms/platform-posix/module.yaml +++ b/Platforms/platform-posix/module.yaml @@ -1,2 +1,3 @@ dependencies: - TactilityKernel +bindings: bindings diff --git a/Platforms/platform-posix/source/drivers/posix_i2c.cpp b/Platforms/platform-posix/source/drivers/posix_i2c.cpp new file mode 100644 index 000000000..9208e7fc9 --- /dev/null +++ b/Platforms/platform-posix/source/drivers/posix_i2c.cpp @@ -0,0 +1,171 @@ +// SPDX-License-Identifier: Apache-2.0 + +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include + +#ifdef __linux__ +#include +#include +#include +#endif + +#define TAG "posix_i2c" + +namespace { + +struct PosixI2cInternal { + Mutex mutex {}; + int fd = -1; + + PosixI2cInternal() { + mutex_construct(&mutex); + } + + ~PosixI2cInternal() { + mutex_destruct(&mutex); + } +}; + +#define GET_CONFIG(device) ((const PosixI2cConfig*)device->config) +#define GET_DATA(device) ((PosixI2cInternal*)device_get_driver_data(device)) + +#define lock(data) mutex_lock(&data->mutex) +#define unlock(data) mutex_unlock(&data->mutex) + +#ifdef __linux__ + +// The kernel adapter applies its own timeout, so the TickType_t timeouts of the API are not used. +error_t transfer(Device* device, i2c_msg* messages, uint32_t message_count) { + auto* data = GET_DATA(device); + i2c_rdwr_ioctl_data request = { .msgs = messages, .nmsgs = message_count }; + lock(data); + int result = ioctl(data->fd, I2C_RDWR, &request); + int error_number = errno; + unlock(data); + if (result >= 0) return ERROR_NONE; + if (error_number == ETIMEDOUT) return ERROR_TIMEOUT; + if (error_number == ENXIO || error_number == EREMOTEIO) return ERROR_NOT_FOUND; + return ERROR_RESOURCE; +} + +i2c_msg write_message(uint8_t address, const uint8_t* data, uint16_t size) { + return { .addr = address, .flags = 0, .len = size, .buf = const_cast(data) }; +} + +i2c_msg read_message(uint8_t address, uint8_t* data, uint16_t size) { + return { .addr = address, .flags = I2C_M_RD, .len = size, .buf = data }; +} + +// ---- I2cControllerApi ---- + +error_t read(Device* device, uint8_t address, uint8_t* data, size_t dataSize, TickType_t timeout) { + if (dataSize > UINT16_MAX) return ERROR_INVALID_ARGUMENT; + i2c_msg messages[] = { read_message(address, data, dataSize) }; + return transfer(device, messages, 1); +} + +error_t write(Device* device, uint8_t address, const uint8_t* data, uint16_t dataSize, TickType_t timeout) { + i2c_msg messages[] = { write_message(address, data, dataSize) }; + return transfer(device, messages, 1); +} + +error_t write_read(Device* device, uint8_t address, const uint8_t* writeData, size_t writeDataSize, uint8_t* readData, size_t readDataSize, TickType_t timeout) { + if (writeDataSize > UINT16_MAX || readDataSize > UINT16_MAX) return ERROR_INVALID_ARGUMENT; + i2c_msg messages[] = { + write_message(address, writeData, writeDataSize), + read_message(address, readData, readDataSize) + }; + return transfer(device, messages, 2); +} + +error_t read_register(Device* device, uint8_t address, uint8_t reg, uint8_t* data, size_t dataSize, TickType_t timeout) { + return write_read(device, address, ®, 1, data, dataSize, timeout); +} + +error_t write_register(Device* device, uint8_t address, uint8_t reg, const uint8_t* data, uint16_t dataSize, TickType_t timeout) { + if (dataSize == UINT16_MAX) return ERROR_INVALID_ARGUMENT; + auto* buffer = new(std::nothrow) uint8_t[dataSize + 1]; + if (buffer == nullptr) return ERROR_OUT_OF_MEMORY; + buffer[0] = reg; + memcpy(buffer + 1, data, dataSize); + error_t error = write(device, address, buffer, dataSize + 1, timeout); + delete[] buffer; + return error; +} + +error_t probe(Device* device, uint8_t address, TickType_t timeout) { + uint8_t byte; + return read(device, address, &byte, 1, timeout); +} + +#endif + +const I2cControllerApi posix_i2c_api = { +#ifdef __linux__ + .read = read, + .write = write, + .write_read = write_read, + .read_register = read_register, + .write_register = write_register, + .probe = probe +#endif +}; + +// ---- Driver lifecycle ---- + +error_t start_device(Device* device) { +#ifdef __linux__ + const char* path = GET_CONFIG(device)->path; + int fd = open(path, O_RDWR | O_CLOEXEC); + if (fd < 0) { + LOG_E(TAG, "%s failed to open %s: %s", device->name, path, strerror(errno)); + return ERROR_RESOURCE; + } + + auto* data = new(std::nothrow) PosixI2cInternal(); + if (data == nullptr) { + close(fd); + return ERROR_OUT_OF_MEMORY; + } + data->fd = fd; + device_set_driver_data(device, data); + return ERROR_NONE; +#else + LOG_E(TAG, "%s: I2C requires Linux i2c-dev", device->name); + return ERROR_NOT_SUPPORTED; +#endif +} + +error_t stop_device(Device* device) { + auto* data = GET_DATA(device); + device_set_driver_data(device, nullptr); + close(data->fd); + delete data; + return ERROR_NONE; +} + +} // namespace + +extern "C" { + +Driver posix_i2c_driver = { + .name = "posix_i2c", + .compatible = (const char*[]) { "posix,i2c", nullptr }, + .start_device = start_device, + .stop_device = stop_device, + .api = (const void*)&posix_i2c_api, + .device_type = &I2C_CONTROLLER_TYPE, + .internal = nullptr +}; + +} // extern "C" diff --git a/Platforms/platform-posix/source/drivers/posix_uart.cpp b/Platforms/platform-posix/source/drivers/posix_uart.cpp new file mode 100644 index 000000000..07a7156b2 --- /dev/null +++ b/Platforms/platform-posix/source/drivers/posix_uart.cpp @@ -0,0 +1,363 @@ +// SPDX-License-Identifier: Apache-2.0 + +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#define TAG "posix_uart" + +namespace { + +struct PosixUartInternal { + Mutex mutex {}; + UartConfig config {}; + bool config_set = false; + int fd = -1; + + PosixUartInternal() { + mutex_construct(&mutex); + } + + ~PosixUartInternal() { + mutex_destruct(&mutex); + } +}; + +#define GET_CONFIG(device) ((const PosixUartConfig*)device->config) +#define GET_DATA(device) ((PosixUartInternal*)device_get_driver_data(device)) + +#define lock(data) mutex_lock(&data->mutex) +#define unlock(data) mutex_unlock(&data->mutex) + +using Clock = std::chrono::steady_clock; + +Clock::time_point to_deadline(TickType_t timeout) { + if (timeout == portMAX_DELAY) return Clock::time_point::max(); + return Clock::now() + std::chrono::milliseconds((uint64_t)timeout * portTICK_PERIOD_MS); +} + +int remaining_poll_ms(Clock::time_point deadline) { + if (deadline == Clock::time_point::max()) return -1; + auto remaining = std::chrono::duration_cast(deadline - Clock::now()).count(); + return remaining > 0 ? (int)remaining : 0; +} + +/** @return true when the fd became ready before the deadline */ +bool wait_for(int fd, short events, Clock::time_point deadline) { + while (true) { + pollfd pfd = { .fd = fd, .events = events, .revents = 0 }; + int result = poll(&pfd, 1, remaining_poll_ms(deadline)); + if (result > 0) return true; + if (result == 0) return false; + if (errno != EINTR) return false; + } +} + +bool to_speed(uint32_t baud_rate, speed_t* speed) { + switch (baud_rate) { + case 1200: *speed = B1200; return true; + case 2400: *speed = B2400; return true; + case 4800: *speed = B4800; return true; + case 9600: *speed = B9600; return true; + case 19200: *speed = B19200; return true; + case 38400: *speed = B38400; return true; + case 57600: *speed = B57600; return true; + case 115200: *speed = B115200; return true; + case 230400: *speed = B230400; return true; +#ifdef B460800 + case 460800: *speed = B460800; return true; +#endif +#ifdef B921600 + case 921600: *speed = B921600; return true; +#endif +#ifdef B1000000 + case 1000000: *speed = B1000000; return true; +#endif +#ifdef B2000000 + case 2000000: *speed = B2000000; return true; +#endif + default: return false; + } +} + +error_t apply_termios(int fd, const UartConfig& config) { + speed_t speed; + if (!to_speed(config.baud_rate, &speed)) return ERROR_NOT_SUPPORTED; + if (config.stop_bits == UART_CONTROLLER_STOP_BITS_1_5) return ERROR_NOT_SUPPORTED; + + termios tty {}; + if (tcgetattr(fd, &tty) != 0) return ERROR_RESOURCE; + + cfmakeraw(&tty); + tty.c_cflag |= CLOCAL | CREAD; + tty.c_cflag &= ~CRTSCTS; + + tty.c_cflag &= ~CSIZE; + switch (config.data_bits) { + case UART_CONTROLLER_DATA_5_BITS: tty.c_cflag |= CS5; break; + case UART_CONTROLLER_DATA_6_BITS: tty.c_cflag |= CS6; break; + case UART_CONTROLLER_DATA_7_BITS: tty.c_cflag |= CS7; break; + default: tty.c_cflag |= CS8; break; + } + + switch (config.parity) { + case UART_CONTROLLER_PARITY_EVEN: tty.c_cflag |= PARENB; tty.c_cflag &= ~PARODD; break; + case UART_CONTROLLER_PARITY_ODD: tty.c_cflag |= PARENB | PARODD; break; + default: tty.c_cflag &= ~PARENB; break; + } + + if (config.stop_bits == UART_CONTROLLER_STOP_BITS_2) { + tty.c_cflag |= CSTOPB; + } else { + tty.c_cflag &= ~CSTOPB; + } + + tty.c_cc[VMIN] = 0; + tty.c_cc[VTIME] = 0; + + if (cfsetispeed(&tty, speed) != 0 || cfsetospeed(&tty, speed) != 0) return ERROR_NOT_SUPPORTED; + if (tcsetattr(fd, TCSANOW, &tty) != 0) return ERROR_RESOURCE; + tcflush(fd, TCIOFLUSH); + return ERROR_NONE; +} + +error_t read_locked(PosixUartInternal* data, uint8_t* buffer, size_t buffer_size, TickType_t timeout) { + auto deadline = to_deadline(timeout); + size_t total = 0; + while (total < buffer_size) { + ssize_t result = read(data->fd, buffer + total, buffer_size - total); + if (result > 0) { + total += result; + } else if (result < 0 && errno != EAGAIN && errno != EWOULDBLOCK && errno != EINTR) { + return ERROR_RESOURCE; + } else if (!wait_for(data->fd, POLLIN, deadline)) { + return ERROR_TIMEOUT; + } + } + return ERROR_NONE; +} + +error_t write_locked(PosixUartInternal* data, const uint8_t* buffer, size_t buffer_size, TickType_t timeout) { + auto deadline = to_deadline(timeout); + size_t total = 0; + while (total < buffer_size) { + ssize_t result = write(data->fd, buffer + total, buffer_size - total); + if (result > 0) { + total += result; + } else if (result < 0 && errno != EAGAIN && errno != EWOULDBLOCK && errno != EINTR) { + return ERROR_RESOURCE; + } else if (!wait_for(data->fd, POLLOUT, deadline)) { + return ERROR_TIMEOUT; + } + } + return ERROR_NONE; +} + +// ---- UartControllerApi ---- + +error_t read_bytes(Device* device, uint8_t* buffer, size_t buffer_size, TickType_t timeout) { + auto* data = GET_DATA(device); + lock(data); + if (data->fd < 0) { + unlock(data); + return ERROR_INVALID_STATE; + } + error_t error = read_locked(data, buffer, buffer_size, timeout); + unlock(data); + return error; +} + +error_t read_byte(Device* device, uint8_t* out, TickType_t timeout) { + return read_bytes(device, out, 1, timeout); +} + +error_t write_bytes(Device* device, const uint8_t* buffer, size_t buffer_size, TickType_t timeout) { + auto* data = GET_DATA(device); + lock(data); + if (data->fd < 0) { + unlock(data); + return ERROR_INVALID_STATE; + } + error_t error = write_locked(data, buffer, buffer_size, timeout); + unlock(data); + return error; +} + +error_t write_byte(Device* device, uint8_t out, TickType_t timeout) { + return write_bytes(device, &out, 1, timeout); +} + +error_t get_available(Device* device, size_t* available) { + auto* data = GET_DATA(device); + lock(data); + if (data->fd < 0) { + unlock(data); + return ERROR_INVALID_STATE; + } + int count = 0; + int result = ioctl(data->fd, FIONREAD, &count); + unlock(data); + if (result != 0) return ERROR_RESOURCE; + *available = (size_t)count; + return ERROR_NONE; +} + +error_t set_config(Device* device, const UartConfig* config) { + auto* data = GET_DATA(device); + lock(data); + if (data->fd >= 0) { + unlock(data); + return ERROR_INVALID_STATE; + } + data->config = *config; + data->config_set = true; + unlock(data); + return ERROR_NONE; +} + +error_t get_config(Device* device, UartConfig* config) { + auto* data = GET_DATA(device); + lock(data); + if (!data->config_set) { + unlock(data); + return ERROR_RESOURCE; + } + *config = data->config; + unlock(data); + return ERROR_NONE; +} + +error_t open_device(Device* device) { + auto* data = GET_DATA(device); + const char* path = GET_CONFIG(device)->path; + + lock(data); + if (data->fd >= 0) { + unlock(data); + LOG_W(TAG, "%s is already open", device->name); + return ERROR_INVALID_STATE; + } + if (!data->config_set) { + unlock(data); + LOG_E(TAG, "%s open failed: config not set", device->name); + return ERROR_INVALID_STATE; + } + + int fd = open(path, O_RDWR | O_NOCTTY | O_NONBLOCK | O_CLOEXEC); + if (fd < 0) { + unlock(data); + LOG_E(TAG, "%s failed to open %s: %s", device->name, path, strerror(errno)); + return ERROR_RESOURCE; + } + + error_t error = apply_termios(fd, data->config); + if (error != ERROR_NONE) { + close(fd); + unlock(data); + LOG_E(TAG, "%s failed to configure %s: %s", device->name, path, error_to_string(error)); + return error; + } + + data->fd = fd; + unlock(data); + return ERROR_NONE; +} + +error_t close_device(Device* device) { + auto* data = GET_DATA(device); + lock(data); + if (data->fd < 0) { + unlock(data); + LOG_W(TAG, "%s is already closed", device->name); + return ERROR_INVALID_STATE; + } + close(data->fd); + data->fd = -1; + unlock(data); + return ERROR_NONE; +} + +bool is_open(Device* device) { + auto* data = GET_DATA(device); + lock(data); + bool status = data->fd >= 0; + unlock(data); + return status; +} + +error_t flush_input(Device* device) { + auto* data = GET_DATA(device); + lock(data); + if (data->fd < 0) { + unlock(data); + return ERROR_INVALID_STATE; + } + int result = tcflush(data->fd, TCIFLUSH); + unlock(data); + return result == 0 ? ERROR_NONE : ERROR_RESOURCE; +} + +const UartControllerApi posix_uart_api = { + .read_byte = read_byte, + .write_byte = write_byte, + .write_bytes = write_bytes, + .read_bytes = read_bytes, + .get_available = get_available, + .set_config = set_config, + .get_config = get_config, + .open = open_device, + .close = close_device, + .is_open = is_open, + .flush_input = flush_input +}; + +// ---- Driver lifecycle ---- + +error_t start_device(Device* device) { + auto* data = new(std::nothrow) PosixUartInternal(); + if (data == nullptr) return ERROR_OUT_OF_MEMORY; + device_set_driver_data(device, data); + return ERROR_NONE; +} + +error_t stop_device(Device* device) { + auto* data = GET_DATA(device); + lock(data); + if (data->fd >= 0) { + unlock(data); + return ERROR_INVALID_STATE; + } + unlock(data); + device_set_driver_data(device, nullptr); + delete data; + return ERROR_NONE; +} + +} // namespace + +extern "C" { + +Driver posix_uart_driver = { + .name = "posix_uart", + .compatible = (const char*[]) { "posix,uart", nullptr }, + .start_device = start_device, + .stop_device = stop_device, + .api = (const void*)&posix_uart_api, + .device_type = &UART_CONTROLLER_TYPE, + .internal = nullptr +}; + +} // extern "C" diff --git a/Platforms/platform-posix/source/module.cpp b/Platforms/platform-posix/source/module.cpp index b260bad77..73f60e80b 100644 --- a/Platforms/platform-posix/source/module.cpp +++ b/Platforms/platform-posix/source/module.cpp @@ -5,10 +5,12 @@ error_t platform_posix_start_partitions(); extern "C" { -extern Driver posix_wifi_driver; +extern Driver posix_uart_driver; +extern Driver posix_i2c_driver; static Driver* const platform_posix_drivers[] = { - &posix_wifi_driver, + &posix_uart_driver, + &posix_i2c_driver, nullptr }; diff --git a/Tactility/Source/bluetooth/BluetoothHidHost.cpp b/Tactility/Source/bluetooth/BluetoothHidHost.cpp index 2e98cf4a4..cd659606a 100644 --- a/Tactility/Source/bluetooth/BluetoothHidHost.cpp +++ b/Tactility/Source/bluetooth/BluetoothHidHost.cpp @@ -140,7 +140,6 @@ static Driver s_ble_kb_driver = { .stop_device = bleKbDeviceStop, .api = &s_ble_kb_api, .device_type = &KEYBOARD_TYPE, - .owner = nullptr, .internal = nullptr, }; diff --git a/TactilityKernel/include/tactility/driver.h b/TactilityKernel/include/tactility/driver.h index 67858330a..99a3b4ca5 100644 --- a/TactilityKernel/include/tactility/driver.h +++ b/TactilityKernel/include/tactility/driver.h @@ -35,8 +35,6 @@ struct Driver { const void* api; /** Which type of devices this driver creates (can be NULL) */ const struct DeviceType* device_type; - /** The module that owns this driver. When it is NULL, the system owns the driver and it cannot be removed from registration. */ - const struct Module* owner; /** * Internal state managed by the kernel. * Driver implementers should initialize this to NULL. @@ -101,6 +99,16 @@ error_t driver_construct_add(struct Driver* driver); */ error_t driver_remove_destruct(struct Driver* driver); +/** + * @brief Get the module that owns a driver. + * + * A module sets itself as owner of the drivers it registers in module_start(). + * + * @param driver The constructed driver. + * @return The owning module, or NULL when the driver has no owner. + */ +const struct Module* driver_get_owner(const struct Driver* driver); + /** * @brief Bind a driver to a device. * diff --git a/TactilityKernel/private/tactility/driver_internal.h b/TactilityKernel/private/tactility/driver_internal.h new file mode 100644 index 000000000..c2ee4c994 --- /dev/null +++ b/TactilityKernel/private/tactility/driver_internal.h @@ -0,0 +1,20 @@ +// SPDX-License-Identifier: Apache-2.0 +#pragma once + +#include + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @brief Set the module that owns a driver. + * + * @param driver The constructed driver. + * @param owner The owning module, or NULL. + */ +void driver_set_owner(struct Driver* driver, const struct Module* owner); + +#ifdef __cplusplus +} +#endif diff --git a/TactilityKernel/source/driver.cpp b/TactilityKernel/source/driver.cpp index 31a18a867..b9b743664 100644 --- a/TactilityKernel/source/driver.cpp +++ b/TactilityKernel/source/driver.cpp @@ -5,6 +5,7 @@ #include #include +#include #include #include #include @@ -18,6 +19,7 @@ constexpr TickType_t SLOW_START_WARNING_TICKS = pdMS_TO_TICKS(100); struct DriverInternal { int use_count = 0; bool destroying = false; + const Module* owner = nullptr; }; struct DriverLedger { @@ -46,9 +48,6 @@ error_t driver_construct(Driver* driver) { error_t driver_destruct(Driver* driver) { auto* internal = driver->internal; - if (driver->owner == nullptr) { - return ERROR_NOT_ALLOWED; - } if (internal->use_count != 0 || internal->destroying) { return ERROR_INVALID_STATE; } @@ -72,8 +71,6 @@ error_t driver_add(Driver* driver) { error_t driver_remove(Driver* driver) { LOG_D(TAG, "remove %s", driver->name); - if (driver->owner == nullptr) return ERROR_NOT_ALLOWED; - ledger.lock(); const auto iterator = std::ranges::find(ledger.drivers, driver); if (iterator == ledger.drivers.end()) { @@ -98,6 +95,14 @@ error_t driver_remove_destruct(struct Driver* driver) { return ERROR_NONE; } +void driver_set_owner(Driver* driver, const Module* owner) { + driver->internal->owner = owner; +} + +const Module* driver_get_owner(const Driver* driver) { + return driver->internal->owner; +} + bool driver_is_compatible(Driver* driver, const char* compatible) { if (compatible == nullptr || driver->compatible == nullptr) { return false; diff --git a/TactilityKernel/source/drivers/battery_sense.cpp b/TactilityKernel/source/drivers/battery_sense.cpp index c692f22c5..665ae7368 100644 --- a/TactilityKernel/source/drivers/battery_sense.cpp +++ b/TactilityKernel/source/drivers/battery_sense.cpp @@ -90,7 +90,6 @@ Driver battery_sense_power_supply_driver = { .stop_device = nullptr, .api = &BATTERY_SENSE_POWER_SUPPLY_API, .device_type = &POWER_SUPPLY_TYPE, - .owner = nullptr, .internal = nullptr, }; @@ -178,7 +177,6 @@ Driver battery_sense_driver = { .stop_device = stop, .api = nullptr, .device_type = nullptr, - .owner = nullptr, .internal = nullptr }; diff --git a/TactilityKernel/source/drivers/gpio_backlight.cpp b/TactilityKernel/source/drivers/gpio_backlight.cpp index 9884b7084..462bf0c40 100644 --- a/TactilityKernel/source/drivers/gpio_backlight.cpp +++ b/TactilityKernel/source/drivers/gpio_backlight.cpp @@ -121,8 +121,6 @@ static error_t stop(Device* device) { // endregion -extern Module kernel_module; - Driver gpio_backlight_driver = { .name = "gpio_backlight", .compatible = (const char*[]) { "gpio-backlight", nullptr }, @@ -131,7 +129,6 @@ Driver gpio_backlight_driver = { .probe = nullptr, .api = &GPIO_BACKLIGHT_API, .device_type = &BACKLIGHT_TYPE, - .owner = &kernel_module, .internal = nullptr, }; diff --git a/TactilityKernel/source/drivers/gpio_hog.cpp b/TactilityKernel/source/drivers/gpio_hog.cpp index f66f0218d..7974041a4 100644 --- a/TactilityKernel/source/drivers/gpio_hog.cpp +++ b/TactilityKernel/source/drivers/gpio_hog.cpp @@ -57,8 +57,6 @@ static error_t stop(Device* device) { return ERROR_NONE; } -extern Module kernel_module; - Driver gpio_hog_driver = { .name = "gpio_hog", .compatible = (const char*[]) { "gpio-hog", nullptr }, @@ -66,6 +64,5 @@ Driver gpio_hog_driver = { .stop_device = stop, .api = nullptr, .device_type = &GPIO_HOG_TYPE, - .owner = &kernel_module, .internal = nullptr }; diff --git a/TactilityKernel/source/drivers/pwm_backlight.cpp b/TactilityKernel/source/drivers/pwm_backlight.cpp index 59cba1248..e8fc358c3 100644 --- a/TactilityKernel/source/drivers/pwm_backlight.cpp +++ b/TactilityKernel/source/drivers/pwm_backlight.cpp @@ -126,8 +126,6 @@ static error_t stop(Device* device) { // endregion -extern Module kernel_module; - Driver pwm_backlight_driver = { .name = "pwm_backlight", .compatible = (const char*[]) { "pwm-backlight", nullptr }, @@ -135,7 +133,6 @@ Driver pwm_backlight_driver = { .stop_device = stop, .api = &PWM_BACKLIGHT_API, .device_type = &BACKLIGHT_TYPE, - .owner = &kernel_module, .internal = nullptr }; diff --git a/TactilityKernel/source/drivers/rgb_led_gpio.cpp b/TactilityKernel/source/drivers/rgb_led_gpio.cpp index 982325625..e4942538e 100644 --- a/TactilityKernel/source/drivers/rgb_led_gpio.cpp +++ b/TactilityKernel/source/drivers/rgb_led_gpio.cpp @@ -146,8 +146,6 @@ static error_t stop(Device* device) { // endregion -extern Module kernel_module; - Driver rgb_led_gpio_driver = { .name = "rgb_led_gpio", .compatible = (const char*[]) { "rgb-led-gpio", nullptr }, @@ -155,7 +153,6 @@ Driver rgb_led_gpio_driver = { .stop_device = stop, .api = &RGB_LED_GPIO_API, .device_type = &RGB_LED_TYPE, - .owner = &kernel_module, .internal = nullptr }; diff --git a/TactilityKernel/source/drivers/rgb_led_pwm.cpp b/TactilityKernel/source/drivers/rgb_led_pwm.cpp index c5ebb8fb0..df3664855 100644 --- a/TactilityKernel/source/drivers/rgb_led_pwm.cpp +++ b/TactilityKernel/source/drivers/rgb_led_pwm.cpp @@ -141,8 +141,6 @@ static error_t stop(Device* device) { // endregion -extern Module kernel_module; - Driver rgb_led_pwm_driver = { .name = "rgb_led_pwm", .compatible = (const char*[]) { "rgb-led-pwm", nullptr }, @@ -150,7 +148,6 @@ Driver rgb_led_pwm_driver = { .stop_device = stop, .api = &RGB_LED_PWM_API, .device_type = &RGB_LED_TYPE, - .owner = &kernel_module, .internal = nullptr }; diff --git a/TactilityKernel/source/drivers/root.cpp b/TactilityKernel/source/drivers/root.cpp index 0e2d21ad5..70a6d2731 100644 --- a/TactilityKernel/source/drivers/root.cpp +++ b/TactilityKernel/source/drivers/root.cpp @@ -19,7 +19,6 @@ Driver root_driver = { .stop_device = nullptr, .api = nullptr, .device_type = nullptr, - .owner = nullptr, .internal = nullptr }; diff --git a/TactilityKernel/source/module.cpp b/TactilityKernel/source/module.cpp index 3fb5f2dff..3aa675530 100644 --- a/TactilityKernel/source/module.cpp +++ b/TactilityKernel/source/module.cpp @@ -5,6 +5,7 @@ #include #include "tactility/driver.h" +#include #include @@ -88,7 +89,9 @@ error_t module_start(Module* module) { auto* driver_location = module->drivers; while (*driver_location != nullptr) { auto driver = *driver_location; - check(driver_construct_add(driver) == ERROR_NONE); + check(driver_construct(driver) == ERROR_NONE); + driver_set_owner(driver, module); + check(driver_add(driver) == ERROR_NONE); driver_location++; } internal->drivers_ready = true; diff --git a/TactilityKernel/source/symbols.c b/TactilityKernel/source/symbols.c index fe01c4add..9317bcc48 100644 --- a/TactilityKernel/source/symbols.c +++ b/TactilityKernel/source/symbols.c @@ -107,6 +107,7 @@ const struct ModuleSymbol KERNEL_SYMBOLS[] = { DEFINE_MODULE_SYMBOL(driver_remove), DEFINE_MODULE_SYMBOL(driver_construct_add), DEFINE_MODULE_SYMBOL(driver_remove_destruct), + DEFINE_MODULE_SYMBOL(driver_get_owner), DEFINE_MODULE_SYMBOL(driver_bind), DEFINE_MODULE_SYMBOL(driver_unbind), DEFINE_MODULE_SYMBOL(driver_is_compatible), diff --git a/TactilityKernel/tests/source/device_get_put_test.cpp b/TactilityKernel/tests/source/device_get_put_test.cpp index a837fb61c..458b8514f 100644 --- a/TactilityKernel/tests/source/device_get_put_test.cpp +++ b/TactilityKernel/tests/source/device_get_put_test.cpp @@ -6,16 +6,9 @@ #include #include #include -#include namespace { -Module module = { - .name = "device_get_put_test_module", - .start = nullptr, - .stop = nullptr -}; - int start(Device*) { return ERROR_NONE; } int stop(Device*) { return ERROR_NONE; } @@ -26,7 +19,6 @@ Driver test_driver = { .stop_device = stop, .api = nullptr, .device_type = nullptr, - .owner = &module, .internal = nullptr, }; diff --git a/TactilityKernel/tests/source/device_hotplug_test.cpp b/TactilityKernel/tests/source/device_hotplug_test.cpp index c23230308..8b1db9745 100644 --- a/TactilityKernel/tests/source/device_hotplug_test.cpp +++ b/TactilityKernel/tests/source/device_hotplug_test.cpp @@ -1,13 +1,6 @@ #include "doctest.h" #include #include -#include - -static Module hotplug_test_module = { - .name = "hotplug_test_module", - .start = nullptr, - .stop = nullptr -}; static bool probe_present = false; static int probe_driver_start_called = 0; @@ -25,7 +18,6 @@ static Driver probe_driver = { .probe = probe_driver_probe, .api = nullptr, .device_type = nullptr, - .owner = &hotplug_test_module, .internal = nullptr, }; @@ -96,7 +88,6 @@ static Driver mandatory_driver = { .probe = nullptr, .api = nullptr, .device_type = nullptr, - .owner = &hotplug_test_module, .internal = nullptr, }; diff --git a/TactilityKernel/tests/source/device_test.cpp b/TactilityKernel/tests/source/device_test.cpp index 3b5d94e81..9765d0754 100644 --- a/TactilityKernel/tests/source/device_test.cpp +++ b/TactilityKernel/tests/source/device_test.cpp @@ -4,13 +4,6 @@ #include #include -#include - -static Module module = { - .name = "test_module", - .start = nullptr, - .stop = nullptr -}; TEST_CASE("device_construct and device_destruct should set and unset the constructed state") { Device device = { 0 }; @@ -213,7 +206,6 @@ TEST_CASE("device_is_ready should return true only when it is started") { .stop_device = nullptr, .api = nullptr, .device_type = nullptr, - .owner = &module, .internal = nullptr }; diff --git a/TactilityKernel/tests/source/driver_integration_test.cpp b/TactilityKernel/tests/source/driver_integration_test.cpp index 0d7f33fe2..79fc57848 100644 --- a/TactilityKernel/tests/source/driver_integration_test.cpp +++ b/TactilityKernel/tests/source/driver_integration_test.cpp @@ -1,13 +1,6 @@ #include "doctest.h" #include #include -#include - -static Module module = { - .name = "test_module", - .start = nullptr, - .stop = nullptr -}; struct IntegrationDriverConfig { int startResult; @@ -37,7 +30,6 @@ static Driver integration_driver = { .stop_device = stop, .api = nullptr, .device_type = nullptr, - .owner = &module, .internal = nullptr, }; diff --git a/TactilityKernel/tests/source/driver_test.cpp b/TactilityKernel/tests/source/driver_test.cpp index 6b364c83f..a7f7aa674 100644 --- a/TactilityKernel/tests/source/driver_test.cpp +++ b/TactilityKernel/tests/source/driver_test.cpp @@ -1,17 +1,9 @@ #include "doctest.h" #include -#include - -static Module module = { - .name = "test_module", - .start = nullptr, - .stop = nullptr -}; TEST_CASE("driver_construct and driver_destruct should set and unset the correct fields") { Driver driver = { 0 }; - driver.owner = &module; CHECK_EQ(driver_construct(&driver), ERROR_NONE); CHECK_EQ(driver_add(&driver), ERROR_NONE); @@ -21,12 +13,21 @@ TEST_CASE("driver_construct and driver_destruct should set and unset the correct CHECK_EQ(driver.internal, nullptr); } -TEST_CASE("a driver without a module should not be destructible") { +TEST_CASE("a driver without a module can be added, removed and destructed") { Driver driver = { 0 }; CHECK_EQ(driver_construct(&driver), ERROR_NONE); - CHECK_EQ(driver_destruct(&driver), ERROR_NOT_ALLOWED); - driver.owner = &module; + CHECK_EQ(driver_add(&driver), ERROR_NONE); + CHECK_EQ(driver_remove(&driver), ERROR_NONE); + CHECK_EQ(driver_destruct(&driver), ERROR_NONE); + CHECK_EQ(driver.internal, nullptr); +} + +TEST_CASE("a constructed driver should have no owner") { + Driver driver = { 0 }; + + CHECK_EQ(driver_construct(&driver), ERROR_NONE); + CHECK_EQ(driver_get_owner(&driver), nullptr); CHECK_EQ(driver_destruct(&driver), ERROR_NONE); } @@ -39,7 +40,6 @@ TEST_CASE("driver_is_compatible should return true if a compatible value is foun .stop_device = nullptr, .api = nullptr, .device_type = nullptr, - .owner = &module, .internal = nullptr }; CHECK_EQ(driver_is_compatible(&driver, "test_compatible"), true); @@ -56,7 +56,6 @@ TEST_CASE("driver_find should only find a compatible driver when the driver was .stop_device = nullptr, .api = nullptr, .device_type = nullptr, - .owner = &module, .internal = nullptr }; diff --git a/TactilityKernel/tests/source/keyboard_test.cpp b/TactilityKernel/tests/source/keyboard_test.cpp index c64904181..3e11d142a 100644 --- a/TactilityKernel/tests/source/keyboard_test.cpp +++ b/TactilityKernel/tests/source/keyboard_test.cpp @@ -3,7 +3,6 @@ #include #include #include -#include TEST_CASE("keyboard_key_from_hid_usage maps letters and digits") { CHECK_EQ(keyboard_key_from_hid_usage(0, 0x04, false, false), (uint32_t)'a'); @@ -60,12 +59,6 @@ TEST_CASE("keyboard_key_from_hid_usage returns 0 for unmapped keys") { CHECK_EQ(keyboard_key_from_hid_usage(0, 0xE0, false, false), 0u); // Left Ctrl itself } -static Module keyboard_test_module = { - .name = "keyboard_test_module", - .start = nullptr, - .stop = nullptr -}; - static int read_key_call_count = 0; // First call reports a key press, every call after that reports nothing pending (key == 0), @@ -97,7 +90,6 @@ static Driver fake_keyboard_driver = { .stop_device = nullptr, .api = &fake_keyboard_api, .device_type = &KEYBOARD_TYPE, - .owner = &keyboard_test_module, .internal = nullptr, }; @@ -115,7 +107,6 @@ static Driver fake_emit_only_keyboard_driver = { .stop_device = nullptr, .api = &fake_emit_only_keyboard_api, .device_type = &KEYBOARD_TYPE, - .owner = &keyboard_test_module, .internal = nullptr, }; diff --git a/TactilityKernel/tests/source/module_test.cpp b/TactilityKernel/tests/source/module_test.cpp index f6e0e0447..4ee591e82 100644 --- a/TactilityKernel/tests/source/module_test.cpp +++ b/TactilityKernel/tests/source/module_test.cpp @@ -1,4 +1,5 @@ #include "doctest.h" +#include #include static void symbol_test_function() { /* NO-OP */ } @@ -116,6 +117,22 @@ TEST_CASE("Module lifecycle") { CHECK_EQ(module_destruct(&module), ERROR_NONE); } +TEST_CASE("module_start sets itself as owner of its drivers") { + Driver driver = { .name = "owned_driver" }; + Driver* const drivers[] = { &driver, nullptr }; + struct Module module = { + .name = "owner_test", + .drivers = drivers + }; + + CHECK_EQ(module_construct(&module), ERROR_NONE); + CHECK_EQ(module_start(&module), ERROR_NONE); + CHECK_EQ(driver_get_owner(&driver), &module); + CHECK_EQ(module_stop(&module), ERROR_NONE); + CHECK_EQ(driver.internal, nullptr); + CHECK_EQ(module_destruct(&module), ERROR_NONE); +} + TEST_CASE("Global symbol resolution") { static const struct ModuleSymbol test_symbols[] = { DEFINE_MODULE_SYMBOL(symbol_test_function),