mirror of
https://github.com/ByteWelder/Tactility.git
synced 2026-04-21 19:05:06 +00:00
Compare commits
No commits in common. "0042ce6d327f8ea56c417dc40923d76452548039" and "1757af859c503ed10696b92ded93c86de02ced80" have entirely different histories.
0042ce6d32
...
1757af859c
14
.github/actions/build-sdk/action.yml
vendored
14
.github/actions/build-sdk/action.yml
vendored
@ -30,20 +30,6 @@ runs:
|
||||
# NOTE: Update with ESP-IDF!
|
||||
ESP_IDF_VERSION: '5.5'
|
||||
run: python Buildscripts/release-sdk.py release/TactilitySDK
|
||||
- name: 'Test Integration Prep'
|
||||
shell: bash
|
||||
# The manifest.properties of our integration test uses version 0.0.0 to indicate that it is not using a normal SDK
|
||||
# This way, it only works with our custom build. That means we have to create a copy of the SDK with the correct folder structure:
|
||||
run: |
|
||||
TACTILITY_SDK_NAME="0.0.0-${{ inputs.arch }}"
|
||||
mkdir -p test_sdk/$TACTILITY_SDK_NAME
|
||||
cp -r release/TactilitySDK test_sdk/$TACTILITY_SDK_NAME
|
||||
- name: 'Test Integration'
|
||||
uses: espressif/esp-idf-ci-action@v1
|
||||
with:
|
||||
esp_idf_version: v5.5
|
||||
target: ${{ inputs.arch }}
|
||||
command: export TACTILITY_SDK_PATH=../../test_sdk && cd Tests/SdkIntegration && python tactility.py build ${{ inputs.arch }} --local-sdk
|
||||
- name: 'Upload Artifact'
|
||||
uses: actions/upload-artifact@v4
|
||||
with:
|
||||
|
||||
5
.gitignore
vendored
5
.gitignore
vendored
@ -3,6 +3,7 @@
|
||||
|
||||
build/
|
||||
buildsim/
|
||||
build-*/
|
||||
cmake-*/
|
||||
CMakeCache.txt
|
||||
*.cbp
|
||||
@ -20,6 +21,4 @@ dependencies.lock
|
||||
*.code-workspace
|
||||
.gitpod.yml
|
||||
|
||||
sdkconfig.board.*.dev
|
||||
|
||||
.tactility/
|
||||
sdkconfig.board.*.dev
|
||||
@ -134,7 +134,6 @@ def write_device_structs(file, device: Device, parent_device: Device, bindings:
|
||||
file.write(f"\t.name = \"{device.node_name}\",\n") # Use original name
|
||||
file.write(f"\t.config = &{config_variable_name},\n")
|
||||
file.write(f"\t.parent = {parent_value},\n")
|
||||
file.write("\t.internal = NULL\n")
|
||||
file.write("};\n\n")
|
||||
# Child devices
|
||||
for child_device in device.devices:
|
||||
|
||||
@ -92,10 +92,10 @@ def main():
|
||||
{'src': 'Modules/lvgl-module/CMakeLists.txt', 'dst': 'Libraries/lvgl-module/'},
|
||||
{'src': 'Modules/lvgl-module/LICENSE*.*', 'dst': 'Libraries/lvgl-module/'},
|
||||
# lvgl (basics)
|
||||
{'src': 'build/esp-idf/lvgl__lvgl/liblvgl__lvgl.a', 'dst': 'Libraries/lvgl/Binary/liblvgl.a'},
|
||||
{'src': 'build/esp-idf/lvgl/liblvgl.a', 'dst': 'Libraries/lvgl/Binary/'},
|
||||
{'src': 'Libraries/lvgl/lvgl.h', 'dst': 'Libraries/lvgl/Include/'},
|
||||
{'src': 'Libraries/lvgl/lv_version.h', 'dst': 'Libraries/lvgl/Include/'},
|
||||
{'src': 'Libraries/lvgl/LICENCE*.*', 'dst': 'Libraries/lvgl/'},
|
||||
{'src': 'Libraries/lvgl/LICENCE.txt', 'dst': 'Libraries/lvgl/LICENSE.txt'},
|
||||
{'src': 'Libraries/lvgl/src/lv_conf_kconfig.h', 'dst': 'Libraries/lvgl/Include/lv_conf.h'},
|
||||
{'src': 'Libraries/lvgl/src/**/*.h', 'dst': 'Libraries/lvgl/Include/src/'},
|
||||
# elf_loader
|
||||
|
||||
@ -17,8 +17,7 @@ struct Module device_module = {
|
||||
.name = "btt-panda-touch",
|
||||
.start = start,
|
||||
.stop = stop,
|
||||
.symbols = nullptr,
|
||||
.internal = nullptr
|
||||
.symbols = nullptr
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@ -17,8 +17,7 @@ struct Module device_module = {
|
||||
.name = "cyd-2432s024c",
|
||||
.start = start,
|
||||
.stop = stop,
|
||||
.symbols = nullptr,
|
||||
.internal = nullptr
|
||||
.symbols = nullptr
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@ -17,8 +17,7 @@ struct Module device_module = {
|
||||
.name = "cyd-2432s028r",
|
||||
.start = start,
|
||||
.stop = stop,
|
||||
.symbols = nullptr,
|
||||
.internal = nullptr
|
||||
.symbols = nullptr
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@ -17,8 +17,7 @@ struct Module device_module = {
|
||||
.name = "cyd-2432s028rv3",
|
||||
.start = start,
|
||||
.stop = stop,
|
||||
.symbols = nullptr,
|
||||
.internal = nullptr
|
||||
.symbols = nullptr
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@ -17,8 +17,7 @@ struct Module device_module = {
|
||||
.name = "cyd-2432s032c",
|
||||
.start = start,
|
||||
.stop = stop,
|
||||
.symbols = nullptr,
|
||||
.internal = nullptr
|
||||
.symbols = nullptr
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@ -17,8 +17,7 @@ struct Module device_module = {
|
||||
.name = "cyd-4848s040c",
|
||||
.start = start,
|
||||
.stop = stop,
|
||||
.symbols = nullptr,
|
||||
.internal = nullptr
|
||||
.symbols = nullptr
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@ -17,8 +17,7 @@ struct Module device_module = {
|
||||
.name = "cyd-8048s043c",
|
||||
.start = start,
|
||||
.stop = stop,
|
||||
.symbols = nullptr,
|
||||
.internal = nullptr
|
||||
.symbols = nullptr
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@ -17,8 +17,7 @@ struct Module device_module = {
|
||||
.name = "cyd-e32r28t",
|
||||
.start = start,
|
||||
.stop = stop,
|
||||
.symbols = nullptr,
|
||||
.internal = nullptr
|
||||
.symbols = nullptr
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@ -17,8 +17,7 @@ struct Module device_module = {
|
||||
.name = "cyd-e32r32p",
|
||||
.start = start,
|
||||
.stop = stop,
|
||||
.symbols = nullptr,
|
||||
.internal = nullptr
|
||||
.symbols = nullptr
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@ -17,8 +17,7 @@ struct Module device_module = {
|
||||
.name = "elecrow-crowpanel-advance-35",
|
||||
.start = start,
|
||||
.stop = stop,
|
||||
.symbols = nullptr,
|
||||
.internal = nullptr
|
||||
.symbols = nullptr
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@ -17,8 +17,7 @@ struct Module device_module = {
|
||||
.name = "elecrow-crowpanel-advance-50",
|
||||
.start = start,
|
||||
.stop = stop,
|
||||
.symbols = nullptr,
|
||||
.internal = nullptr
|
||||
.symbols = nullptr
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@ -17,8 +17,7 @@ struct Module device_module = {
|
||||
.name = "elecrow-crowpanel-basic-28",
|
||||
.start = start,
|
||||
.stop = stop,
|
||||
.symbols = nullptr,
|
||||
.internal = nullptr
|
||||
.symbols = nullptr
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@ -17,8 +17,7 @@ struct Module device_module = {
|
||||
.name = "elecrow-crowpanel-basic-35",
|
||||
.start = start,
|
||||
.stop = stop,
|
||||
.symbols = nullptr,
|
||||
.internal = nullptr
|
||||
.symbols = nullptr
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@ -17,8 +17,7 @@ struct Module device_module = {
|
||||
.name = "elecrow-crowpanel-basic-50",
|
||||
.start = start,
|
||||
.stop = stop,
|
||||
.symbols = nullptr,
|
||||
.internal = nullptr
|
||||
.symbols = nullptr
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@ -17,8 +17,7 @@ struct Module device_module = {
|
||||
.name = "generic-esp32",
|
||||
.start = start,
|
||||
.stop = stop,
|
||||
.symbols = nullptr,
|
||||
.internal = nullptr
|
||||
.symbols = nullptr
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@ -17,8 +17,7 @@ struct Module device_module = {
|
||||
.name = "generic-esp32c6",
|
||||
.start = start,
|
||||
.stop = stop,
|
||||
.symbols = nullptr,
|
||||
.internal = nullptr
|
||||
.symbols = nullptr
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@ -17,8 +17,7 @@ struct Module device_module = {
|
||||
.name = "generic-esp32p4",
|
||||
.start = start,
|
||||
.stop = stop,
|
||||
.symbols = nullptr,
|
||||
.internal = nullptr
|
||||
.symbols = nullptr
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@ -17,8 +17,7 @@ struct Module device_module = {
|
||||
.name = "generic-esp32s3",
|
||||
.start = start,
|
||||
.stop = stop,
|
||||
.symbols = nullptr,
|
||||
.internal = nullptr
|
||||
.symbols = nullptr
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@ -17,8 +17,7 @@ struct Module device_module = {
|
||||
.name = "guition-jc1060p470ciwy",
|
||||
.start = start,
|
||||
.stop = stop,
|
||||
.symbols = nullptr,
|
||||
.internal = nullptr
|
||||
.symbols = nullptr
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@ -17,8 +17,7 @@ struct Module device_module = {
|
||||
.name = "guition-jc2432w328c",
|
||||
.start = start,
|
||||
.stop = stop,
|
||||
.symbols = nullptr,
|
||||
.internal = nullptr
|
||||
.symbols = nullptr
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@ -17,8 +17,7 @@ struct Module device_module = {
|
||||
.name = "guition-jc3248w535c",
|
||||
.start = start,
|
||||
.stop = stop,
|
||||
.symbols = nullptr,
|
||||
.internal = nullptr
|
||||
.symbols = nullptr
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@ -17,8 +17,7 @@ struct Module device_module = {
|
||||
.name = "guition-jc8048w550c",
|
||||
.start = start,
|
||||
.stop = stop,
|
||||
.symbols = nullptr,
|
||||
.internal = nullptr
|
||||
.symbols = nullptr
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@ -17,8 +17,7 @@ struct Module device_module = {
|
||||
.name = "heltec-wifi-lora-32-v3",
|
||||
.start = start,
|
||||
.stop = stop,
|
||||
.symbols = nullptr,
|
||||
.internal = nullptr
|
||||
.symbols = nullptr
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@ -17,8 +17,7 @@ struct Module device_module = {
|
||||
.name = "lilygo-tdeck",
|
||||
.start = start,
|
||||
.stop = stop,
|
||||
.symbols = nullptr,
|
||||
.internal = nullptr
|
||||
.symbols = nullptr
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@ -17,8 +17,7 @@ struct Module device_module = {
|
||||
.name = "lilygo-tdisplay-s3",
|
||||
.start = start,
|
||||
.stop = stop,
|
||||
.symbols = nullptr,
|
||||
.internal = nullptr
|
||||
.symbols = nullptr
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@ -17,8 +17,7 @@ struct Module device_module = {
|
||||
.name = "lilygo-tdisplay",
|
||||
.start = start,
|
||||
.stop = stop,
|
||||
.symbols = nullptr,
|
||||
.internal = nullptr
|
||||
.symbols = nullptr
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@ -17,8 +17,7 @@ struct Module device_module = {
|
||||
.name = "lilygo-tdongle-s3",
|
||||
.start = start,
|
||||
.stop = stop,
|
||||
.symbols = nullptr,
|
||||
.internal = nullptr
|
||||
.symbols = nullptr
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@ -24,7 +24,7 @@ Driver tlora_pager_driver = {
|
||||
.api = nullptr,
|
||||
.device_type = nullptr,
|
||||
.owner = &device_module,
|
||||
.internal = nullptr
|
||||
.driver_private = nullptr
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@ -25,8 +25,7 @@ struct Module device_module = {
|
||||
.name = "lilygo-tlora-pager",
|
||||
.start = start,
|
||||
.stop = stop,
|
||||
.symbols = nullptr,
|
||||
.internal = nullptr
|
||||
.symbols = nullptr
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@ -17,8 +17,7 @@ struct Module device_module = {
|
||||
.name = "m5stack-cardputer-adv",
|
||||
.start = start,
|
||||
.stop = stop,
|
||||
.symbols = nullptr,
|
||||
.internal = nullptr
|
||||
.symbols = nullptr
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@ -17,8 +17,7 @@ struct Module device_module = {
|
||||
.name = "m5stack-cardputer",
|
||||
.start = start,
|
||||
.stop = stop,
|
||||
.symbols = nullptr,
|
||||
.internal = nullptr
|
||||
.symbols = nullptr
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@ -17,8 +17,7 @@ struct Module device_module = {
|
||||
.name = "m5stack-core2",
|
||||
.start = start,
|
||||
.stop = stop,
|
||||
.symbols = nullptr,
|
||||
.internal = nullptr
|
||||
.symbols = nullptr
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@ -17,8 +17,7 @@ struct Module device_module = {
|
||||
.name = "m5stack-cores3",
|
||||
.start = start,
|
||||
.stop = stop,
|
||||
.symbols = nullptr,
|
||||
.internal = nullptr
|
||||
.symbols = nullptr
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@ -55,8 +55,8 @@
|
||||
scl-pullup;
|
||||
};
|
||||
|
||||
// TODO: Enable speaker via ES7210 I2C: https://github.com/m5stack/M5Unified/blob/a6256725481f1bc366655fa48cf03b6095e30ad1/src/M5Unified.cpp#L417
|
||||
// TODO: Enable microphone via ES7210 I2C: https://github.com/m5stack/M5Unified/blob/a6256725481f1bc366655fa48cf03b6095e30ad1/src/M5Unified.cpp#L616
|
||||
// TODO: Enable speaker via I2C: https://github.com/m5stack/M5Unified/blob/a6256725481f1bc366655fa48cf03b6095e30ad1/src/M5Unified.cpp#L417
|
||||
// TODO: Enable microphone via I2C: https://github.com/m5stack/M5Unified/blob/a6256725481f1bc366655fa48cf03b6095e30ad1/src/M5Unified.cpp#L616
|
||||
i2s0 {
|
||||
// Note: M5Unified sets the following for speaker: magnification = 2, oversampling = 1
|
||||
// Note: M5Unified sets the following for microphone: magnification = 4
|
||||
|
||||
@ -17,8 +17,7 @@ struct Module device_module = {
|
||||
.name = "m5stack-papers3",
|
||||
.start = start,
|
||||
.stop = stop,
|
||||
.symbols = nullptr,
|
||||
.internal = nullptr
|
||||
.symbols = nullptr
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@ -17,8 +17,7 @@ struct Module device_module = {
|
||||
.name = "m5stack-stickc-plus",
|
||||
.start = start,
|
||||
.stop = stop,
|
||||
.symbols = nullptr,
|
||||
.internal = nullptr
|
||||
.symbols = nullptr
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@ -17,8 +17,7 @@ struct Module device_module = {
|
||||
.name = "m5stack-stickc-plus2",
|
||||
.start = start,
|
||||
.stop = stop,
|
||||
.symbols = nullptr,
|
||||
.internal = nullptr
|
||||
.symbols = nullptr
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@ -17,8 +17,7 @@ struct Module device_module = {
|
||||
.name = "m5stack-tab5",
|
||||
.start = start,
|
||||
.stop = stop,
|
||||
.symbols = nullptr,
|
||||
.internal = nullptr
|
||||
.symbols = nullptr
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@ -17,8 +17,7 @@ struct Module device_module = {
|
||||
.name = "simulator",
|
||||
.start = start,
|
||||
.stop = stop,
|
||||
.symbols = nullptr,
|
||||
.internal = nullptr
|
||||
.symbols = nullptr
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@ -17,8 +17,7 @@ struct Module device_module = {
|
||||
.name = "unphone",
|
||||
.start = start,
|
||||
.stop = stop,
|
||||
.symbols = nullptr,
|
||||
.internal = nullptr
|
||||
.symbols = nullptr
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@ -17,8 +17,7 @@ struct Module device_module = {
|
||||
.name = "waveshare-esp32-s3-geek",
|
||||
.start = start,
|
||||
.stop = stop,
|
||||
.symbols = nullptr,
|
||||
.internal = nullptr
|
||||
.symbols = nullptr
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@ -17,8 +17,7 @@ struct Module device_module = {
|
||||
.name = "waveshare-s3-lcd-13",
|
||||
.start = start,
|
||||
.stop = stop,
|
||||
.symbols = nullptr,
|
||||
.internal = nullptr
|
||||
.symbols = nullptr
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@ -17,8 +17,7 @@ struct Module device_module = {
|
||||
.name = "waveshare-s3-touch-lcd-128",
|
||||
.start = start,
|
||||
.stop = stop,
|
||||
.symbols = nullptr,
|
||||
.internal = nullptr
|
||||
.symbols = nullptr
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@ -17,8 +17,7 @@ struct Module device_module = {
|
||||
.name = "waveshare-s3-touch-lcd-147",
|
||||
.start = start,
|
||||
.stop = stop,
|
||||
.symbols = nullptr,
|
||||
.internal = nullptr
|
||||
.symbols = nullptr
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@ -17,8 +17,7 @@ struct Module device_module = {
|
||||
.name = "waveshare-s3-touch-lcd-43",
|
||||
.start = start,
|
||||
.stop = stop,
|
||||
.symbols = nullptr,
|
||||
.internal = nullptr
|
||||
.symbols = nullptr
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@ -17,8 +17,7 @@ struct Module device_module = {
|
||||
.name = "wireless-tag-wt32-sc01-plus",
|
||||
.start = start,
|
||||
.stop = stop,
|
||||
.symbols = nullptr,
|
||||
.internal = nullptr
|
||||
.symbols = nullptr
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@ -11,7 +11,6 @@
|
||||
|
||||
## Higher Priority
|
||||
|
||||
- Add font design tokens such as "regular", "title" and "smaller". Perhaps via the LVGL kernel module.
|
||||
- Add kernel listening mechanism so that the root device init can be notified when a device becomes available:
|
||||
Callback for device/start stop with filtering on device type:
|
||||
- on_before_start: e.g. to do the CS pin hack for SD card on a shared bus
|
||||
|
||||
@ -14,7 +14,7 @@ struct HalDevicePrivate {
|
||||
std::shared_ptr<tt::hal::Device> halDevice;
|
||||
};
|
||||
|
||||
#define GET_DATA(device) ((HalDevicePrivate*)device_get_driver_data(device))
|
||||
#define GET_DATA(device) ((struct HalDevicePrivate*)device->internal.driver_data)
|
||||
|
||||
static enum HalDeviceType getHalDeviceType(tt::hal::Device::Type type) {
|
||||
switch (type) {
|
||||
@ -94,9 +94,7 @@ void hal_device_set_device(::Device* kernelDevice, std::shared_ptr<Device> halDe
|
||||
|
||||
static error_t start(Device* device) {
|
||||
LOG_I(TAG, "start %s", device->name);
|
||||
auto hal_device_data = new(std::nothrow) HalDevicePrivate();
|
||||
if (hal_device_data == nullptr) return ERROR_OUT_OF_MEMORY;
|
||||
device_set_driver_data(device, hal_device_data);
|
||||
device->internal.driver_data = new HalDevicePrivate();
|
||||
return ERROR_NONE;
|
||||
}
|
||||
|
||||
@ -122,7 +120,7 @@ Driver hal_device_driver = {
|
||||
.api = nullptr,
|
||||
.device_type = &HAL_DEVICE_TYPE,
|
||||
.owner = &hal_device_module,
|
||||
.internal = nullptr
|
||||
.driver_private = nullptr
|
||||
};
|
||||
|
||||
}
|
||||
@ -25,8 +25,7 @@ struct Module hal_device_module = {
|
||||
.name = "hal-device",
|
||||
.start = start,
|
||||
.stop = stop,
|
||||
.symbols = nullptr,
|
||||
.internal = nullptr
|
||||
.symbols = nullptr
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@ -64,6 +64,5 @@ struct Module lvgl_module = {
|
||||
.name = "lvgl",
|
||||
.start = start,
|
||||
.stop = stop,
|
||||
.symbols = (const struct ModuleSymbol*)lvgl_module_symbols,
|
||||
.internal = NULL
|
||||
.symbols = (const struct ModuleSymbol*)lvgl_module_symbols
|
||||
};
|
||||
|
||||
@ -123,7 +123,7 @@ Driver esp32_gpio_driver = {
|
||||
.api = (void*)&esp32_gpio_api,
|
||||
.device_type = &GPIO_CONTROLLER_TYPE,
|
||||
.owner = &platform_module,
|
||||
.internal = nullptr
|
||||
.driver_private = nullptr
|
||||
};
|
||||
|
||||
} // extern "C"
|
||||
|
||||
@ -25,7 +25,7 @@ struct InternalData {
|
||||
};
|
||||
|
||||
#define GET_CONFIG(device) ((Esp32I2cConfig*)device->config)
|
||||
#define GET_DATA(device) ((InternalData*)device_get_driver_data(device))
|
||||
#define GET_DATA(device) ((InternalData*)device->internal.driver_data)
|
||||
|
||||
#define lock(data) mutex_lock(&data->mutex);
|
||||
#define unlock(data) mutex_unlock(&data->mutex);
|
||||
@ -216,7 +216,7 @@ Driver esp32_i2c_driver = {
|
||||
.api = (void*)&esp32_i2c_api,
|
||||
.device_type = &I2C_CONTROLLER_TYPE,
|
||||
.owner = &platform_module,
|
||||
.internal = nullptr
|
||||
.driver_private = nullptr
|
||||
};
|
||||
|
||||
} // extern "C"
|
||||
|
||||
@ -31,7 +31,7 @@ struct InternalData {
|
||||
};
|
||||
|
||||
#define GET_CONFIG(device) ((Esp32I2sConfig*)device->config)
|
||||
#define GET_DATA(device) ((InternalData*)device_get_driver_data(device))
|
||||
#define GET_DATA(device) ((InternalData*)device->internal.driver_data)
|
||||
|
||||
#define lock(data) mutex_lock(&data->mutex);
|
||||
#define unlock(data) mutex_unlock(&data->mutex);
|
||||
@ -236,7 +236,7 @@ Driver esp32_i2s_driver = {
|
||||
.api = (void*)&esp32_i2s_api,
|
||||
.device_type = &I2S_CONTROLLER_TYPE,
|
||||
.owner = &platform_module,
|
||||
.internal = nullptr
|
||||
.driver_private = nullptr
|
||||
};
|
||||
|
||||
} // extern "C"
|
||||
|
||||
@ -31,8 +31,7 @@ struct Module platform_module = {
|
||||
.name = "platform-esp32",
|
||||
.start = start,
|
||||
.stop = stop,
|
||||
.symbols = nullptr,
|
||||
.internal = nullptr
|
||||
.symbols = nullptr
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@ -18,8 +18,7 @@ struct Module platform_module = {
|
||||
.name = "platform-posix",
|
||||
.start = start,
|
||||
.stop = stop,
|
||||
.symbols = nullptr,
|
||||
.internal = nullptr
|
||||
.symbols = nullptr
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
@ -18,10 +18,12 @@ struct Mutex {
|
||||
};
|
||||
|
||||
inline static void mutex_construct(struct Mutex* mutex) {
|
||||
assert(mutex->handle == NULL);
|
||||
mutex->handle = xSemaphoreCreateMutex();
|
||||
}
|
||||
|
||||
inline static void mutex_destruct(struct Mutex* mutex) {
|
||||
assert(mutex->handle != NULL);
|
||||
vPortAssertIfInISR();
|
||||
vSemaphoreDelete(mutex->handle);
|
||||
mutex->handle = NULL;
|
||||
|
||||
@ -16,30 +16,39 @@ extern "C" {
|
||||
#endif
|
||||
|
||||
struct Driver;
|
||||
struct DeviceInternal;
|
||||
struct DevicePrivate;
|
||||
|
||||
/** Enables discovering devices of the same type */
|
||||
struct DeviceType {
|
||||
const char* name;
|
||||
/* Placeholder because empty structs have a different size with C vs C++ compilers */
|
||||
uint8_t _;
|
||||
};
|
||||
|
||||
/** Represents a piece of hardware */
|
||||
struct Device {
|
||||
/** The name of the device. Valid characters: a-z a-Z 0-9 - _ . */
|
||||
const char* name;
|
||||
|
||||
/** The configuration data for the device's driver */
|
||||
const void* config;
|
||||
|
||||
/** The parent device that this device belongs to. Can be NULL, but only the root device should have a NULL parent. */
|
||||
struct Device* parent;
|
||||
|
||||
/**
|
||||
* Internal state managed by the kernel.
|
||||
* Device implementers should initialize this to NULL.
|
||||
* Do not access or modify directly; use device_* functions.
|
||||
*/
|
||||
struct DeviceInternal* internal;
|
||||
/** Internal data */
|
||||
struct {
|
||||
/** Address of the API exposed by the device instance. */
|
||||
struct Driver* driver;
|
||||
/** The driver data for this device (e.g. a mutex) */
|
||||
void* driver_data;
|
||||
/** The mutex for device operations */
|
||||
struct Mutex mutex;
|
||||
/** The device state */
|
||||
struct {
|
||||
int start_result;
|
||||
bool started : 1;
|
||||
bool added : 1;
|
||||
} state;
|
||||
/** Private data */
|
||||
struct DevicePrivate* device_private;
|
||||
} internal;
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
@ -12,7 +12,7 @@ extern "C" {
|
||||
struct Device;
|
||||
struct DeviceType;
|
||||
struct Module;
|
||||
struct DriverInternal;
|
||||
struct DriverPrivate;
|
||||
|
||||
struct Driver {
|
||||
/** The driver name */
|
||||
@ -29,12 +29,8 @@ struct Driver {
|
||||
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.
|
||||
* Do not access or modify directly; use driver_* functions.
|
||||
*/
|
||||
struct DriverInternal* internal;
|
||||
/** Internal data */
|
||||
struct DriverPrivate* driver_private;
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
@ -25,8 +25,6 @@ struct ModuleSymbol {
|
||||
const void* symbol;
|
||||
};
|
||||
|
||||
struct ModuleInternal;
|
||||
|
||||
/**
|
||||
* A module is a collection of drivers or other functionality that can be loaded and unloaded at runtime.
|
||||
*/
|
||||
@ -38,6 +36,7 @@ struct Module {
|
||||
* Desirable format "platform-esp32", "lilygo-tdeck", etc.
|
||||
*/
|
||||
const char* name;
|
||||
|
||||
/**
|
||||
* A function to initialize the module.
|
||||
* Should never be NULL.
|
||||
@ -45,24 +44,24 @@ struct Module {
|
||||
* @return ERROR_NONE if successful
|
||||
*/
|
||||
error_t (*start)(void);
|
||||
|
||||
/**
|
||||
* Deinitializes the module.
|
||||
* Should never be NULL.
|
||||
* @return ERROR_NONE if successful
|
||||
*/
|
||||
error_t (*stop)(void);
|
||||
|
||||
/**
|
||||
* A list of symbols exported by the module.
|
||||
* Should be terminated by MODULE_SYMBOL_TERMINATOR.
|
||||
* Can be a NULL value.
|
||||
*/
|
||||
const struct ModuleSymbol* symbols;
|
||||
/**
|
||||
* Internal state managed by the kernel.
|
||||
* Module implementers should initialize this to NULL.
|
||||
* Do not access or modify directly; use module_* functions.
|
||||
*/
|
||||
struct ModuleInternal* internal;
|
||||
|
||||
struct {
|
||||
bool started;
|
||||
} internal;
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
@ -13,21 +13,8 @@
|
||||
|
||||
#define TAG "device"
|
||||
|
||||
struct DeviceInternal {
|
||||
/** Address of the API exposed by the device instance. */
|
||||
struct Driver* driver = nullptr;
|
||||
/** The driver data for this device (e.g. a mutex) */
|
||||
void* driver_data = nullptr;
|
||||
/** The mutex for device operations */
|
||||
struct Mutex mutex {};
|
||||
/** The device state */
|
||||
struct {
|
||||
int start_result = 0;
|
||||
bool started : 1 = false;
|
||||
bool added : 1 = false;
|
||||
} state;
|
||||
/** Attached child devices */
|
||||
std::vector<Device*> children {};
|
||||
struct DevicePrivate {
|
||||
std::vector<Device*> children;
|
||||
};
|
||||
|
||||
struct DeviceLedger {
|
||||
@ -55,55 +42,47 @@ extern "C" {
|
||||
#define ledger_lock() mutex_lock(&ledger.mutex)
|
||||
#define ledger_unlock() mutex_unlock(&ledger.mutex)
|
||||
|
||||
#define lock_internal(internal) mutex_lock(&internal->mutex)
|
||||
#define unlock_internal(internal) mutex_unlock(&internal->mutex)
|
||||
#define get_device_private(device) static_cast<DevicePrivate*>(device->internal.device_private)
|
||||
|
||||
error_t device_construct(Device* device) {
|
||||
device->internal = new(std::nothrow) DeviceInternal;
|
||||
if (device->internal == nullptr) {
|
||||
device->internal.device_private = new(std::nothrow) DevicePrivate;
|
||||
if (device->internal.device_private == nullptr) {
|
||||
return ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
LOG_D(TAG, "construct %s", device->name);
|
||||
mutex_construct(&device->internal->mutex);
|
||||
mutex_construct(&device->internal.mutex);
|
||||
return ERROR_NONE;
|
||||
}
|
||||
|
||||
error_t device_destruct(Device* device) {
|
||||
lock_internal(device->internal);
|
||||
|
||||
auto* internal = device->internal;
|
||||
|
||||
if (internal->state.started || internal->state.added) {
|
||||
unlock_internal(device->internal);
|
||||
if (device->internal.state.started || device->internal.state.added) {
|
||||
return ERROR_INVALID_STATE;
|
||||
}
|
||||
if (!internal->children.empty()) {
|
||||
unlock_internal(device->internal);
|
||||
if (!get_device_private(device)->children.empty()) {
|
||||
return ERROR_INVALID_STATE;
|
||||
}
|
||||
LOG_D(TAG, "destruct %s", device->name);
|
||||
|
||||
device->internal = nullptr;
|
||||
mutex_unlock(&internal->mutex);
|
||||
delete internal;
|
||||
|
||||
mutex_destruct(&device->internal.mutex);
|
||||
delete get_device_private(device);
|
||||
device->internal.device_private = nullptr;
|
||||
return ERROR_NONE;
|
||||
}
|
||||
|
||||
/** Add a child to the list of children */
|
||||
static void device_add_child(struct Device* device, struct Device* child) {
|
||||
device_lock(device);
|
||||
check(device->internal->state.added);
|
||||
device->internal->children.push_back(child);
|
||||
assert(device->internal.state.added);
|
||||
get_device_private(device)->children.push_back(child);
|
||||
device_unlock(device);
|
||||
}
|
||||
|
||||
/** Remove a child from the list of children */
|
||||
static void device_remove_child(struct Device* device, struct Device* child) {
|
||||
device_lock(device);
|
||||
const auto iterator = std::ranges::find(device->internal->children, child);
|
||||
if (iterator != device->internal->children.end()) {
|
||||
device->internal->children.erase(iterator);
|
||||
auto* parent_data = get_device_private(device);
|
||||
const auto iterator = std::ranges::find(parent_data->children, child);
|
||||
if (iterator != parent_data->children.end()) {
|
||||
parent_data->children.erase(iterator);
|
||||
}
|
||||
device_unlock(device);
|
||||
}
|
||||
@ -112,7 +91,7 @@ error_t device_add(Device* device) {
|
||||
LOG_D(TAG, "add %s", device->name);
|
||||
|
||||
// Already added
|
||||
if (device->internal->state.started || device->internal->state.added) {
|
||||
if (device->internal.state.started || device->internal.state.added) {
|
||||
return ERROR_INVALID_STATE;
|
||||
}
|
||||
|
||||
@ -127,14 +106,14 @@ error_t device_add(Device* device) {
|
||||
device_add_child(parent, device);
|
||||
}
|
||||
|
||||
device->internal->state.added = true;
|
||||
device->internal.state.added = true;
|
||||
return ERROR_NONE;
|
||||
}
|
||||
|
||||
error_t device_remove(Device* device) {
|
||||
LOG_D(TAG, "remove %s", device->name);
|
||||
|
||||
if (device->internal->state.started || !device->internal->state.added) {
|
||||
if (device->internal.state.started || !device->internal.state.added) {
|
||||
return ERROR_INVALID_STATE;
|
||||
}
|
||||
|
||||
@ -153,7 +132,7 @@ error_t device_remove(Device* device) {
|
||||
ledger.devices.erase(iterator);
|
||||
ledger_unlock();
|
||||
|
||||
device->internal->state.added = false;
|
||||
device->internal.state.added = false;
|
||||
return ERROR_NONE;
|
||||
|
||||
failed_ledger_lookup:
|
||||
@ -168,41 +147,41 @@ failed_ledger_lookup:
|
||||
|
||||
error_t device_start(Device* device) {
|
||||
LOG_I(TAG, "start %s", device->name);
|
||||
if (!device->internal->state.added) {
|
||||
if (!device->internal.state.added) {
|
||||
return ERROR_INVALID_STATE;
|
||||
}
|
||||
|
||||
if (device->internal->driver == nullptr) {
|
||||
if (device->internal.driver == nullptr) {
|
||||
return ERROR_INVALID_STATE;
|
||||
}
|
||||
|
||||
// Already started
|
||||
if (device->internal->state.started) {
|
||||
if (device->internal.state.started) {
|
||||
return ERROR_NONE;
|
||||
}
|
||||
|
||||
error_t bind_error = driver_bind(device->internal->driver, device);
|
||||
device->internal->state.started = (bind_error == ERROR_NONE);
|
||||
device->internal->state.start_result = bind_error;
|
||||
error_t bind_error = driver_bind(device->internal.driver, device);
|
||||
device->internal.state.started = (bind_error == ERROR_NONE);
|
||||
device->internal.state.start_result = bind_error;
|
||||
return bind_error == ERROR_NONE ? ERROR_NONE : ERROR_RESOURCE;
|
||||
}
|
||||
|
||||
error_t device_stop(struct Device* device) {
|
||||
LOG_I(TAG, "stop %s", device->name);
|
||||
if (!device->internal->state.added) {
|
||||
if (!device->internal.state.added) {
|
||||
return ERROR_INVALID_STATE;
|
||||
}
|
||||
|
||||
if (!device->internal->state.started) {
|
||||
if (!device->internal.state.started) {
|
||||
return ERROR_NONE;
|
||||
}
|
||||
|
||||
if (driver_unbind(device->internal->driver, device) != ERROR_NONE) {
|
||||
if (driver_unbind(device->internal.driver, device) != ERROR_NONE) {
|
||||
return ERROR_RESOURCE;
|
||||
}
|
||||
|
||||
device->internal->state.started = false;
|
||||
device->internal->state.start_result = 0;
|
||||
device->internal.state.started = false;
|
||||
device->internal.state.start_result = 0;
|
||||
return ERROR_NONE;
|
||||
}
|
||||
|
||||
@ -257,7 +236,7 @@ on_construct_add_error:
|
||||
}
|
||||
|
||||
void device_set_parent(Device* device, Device* parent) {
|
||||
assert(!device->internal->state.started);
|
||||
assert(!device->internal.state.started);
|
||||
device->parent = parent;
|
||||
}
|
||||
|
||||
@ -266,43 +245,43 @@ Device* device_get_parent(struct Device* device) {
|
||||
}
|
||||
|
||||
void device_set_driver(struct Device* device, struct Driver* driver) {
|
||||
device->internal->driver = driver;
|
||||
device->internal.driver = driver;
|
||||
}
|
||||
|
||||
struct Driver* device_get_driver(struct Device* device) {
|
||||
return device->internal->driver;
|
||||
return device->internal.driver;
|
||||
}
|
||||
|
||||
bool device_is_ready(const struct Device* device) {
|
||||
return device->internal->state.started;
|
||||
return device->internal.state.started;
|
||||
}
|
||||
|
||||
void device_set_driver_data(struct Device* device, void* driver_data) {
|
||||
device->internal->driver_data = driver_data;
|
||||
device->internal.driver_data = driver_data;
|
||||
}
|
||||
|
||||
void* device_get_driver_data(struct Device* device) {
|
||||
return device->internal->driver_data;
|
||||
return device->internal.driver_data;
|
||||
}
|
||||
|
||||
bool device_is_added(const struct Device* device) {
|
||||
return device->internal->state.added;
|
||||
return device->internal.state.added;
|
||||
}
|
||||
|
||||
void device_lock(struct Device* device) {
|
||||
mutex_lock(&device->internal->mutex);
|
||||
mutex_lock(&device->internal.mutex);
|
||||
}
|
||||
|
||||
bool device_try_lock(struct Device* device) {
|
||||
return mutex_try_lock(&device->internal->mutex);
|
||||
return mutex_try_lock(&device->internal.mutex);
|
||||
}
|
||||
|
||||
void device_unlock(struct Device* device) {
|
||||
mutex_unlock(&device->internal->mutex);
|
||||
mutex_unlock(&device->internal.mutex);
|
||||
}
|
||||
|
||||
const struct DeviceType* device_get_type(struct Device* device) {
|
||||
return device->internal->driver ? device->internal->driver->device_type : NULL;
|
||||
return device->internal.driver ? device->internal.driver->device_type : NULL;
|
||||
}
|
||||
|
||||
void device_for_each(void* callback_context, bool(*on_device)(Device* device, void* context)) {
|
||||
@ -316,7 +295,8 @@ void device_for_each(void* callback_context, bool(*on_device)(Device* device, vo
|
||||
}
|
||||
|
||||
void device_for_each_child(Device* device, void* callbackContext, bool(*on_device)(struct Device* device, void* context)) {
|
||||
for (auto* child_device : device->internal->children) {
|
||||
auto* data = get_device_private(device);
|
||||
for (auto* child_device : data->children) {
|
||||
if (!on_device(child_device, callbackContext)) {
|
||||
break;
|
||||
}
|
||||
@ -326,7 +306,7 @@ void device_for_each_child(Device* device, void* callbackContext, bool(*on_devic
|
||||
void device_for_each_of_type(const DeviceType* type, void* callbackContext, bool(*on_device)(Device* device, void* context)) {
|
||||
ledger_lock();
|
||||
for (auto* device : ledger.devices) {
|
||||
auto* driver = device->internal->driver;
|
||||
auto* driver = device->internal.driver;
|
||||
if (driver != nullptr) {
|
||||
if (driver->device_type == type) {
|
||||
if (!on_device(device, callbackContext)) {
|
||||
|
||||
@ -12,14 +12,23 @@
|
||||
|
||||
#define TAG "driver"
|
||||
|
||||
struct DriverInternal {
|
||||
struct DriverPrivate {
|
||||
Mutex mutex { 0 };
|
||||
int use_count = 0;
|
||||
bool destroying = false;
|
||||
|
||||
DriverPrivate() {
|
||||
mutex_construct(&mutex);
|
||||
}
|
||||
|
||||
~DriverPrivate() {
|
||||
mutex_destruct(&mutex);
|
||||
}
|
||||
};
|
||||
|
||||
struct DriverLedger {
|
||||
std::vector<Driver*> drivers;
|
||||
Mutex mutex {};
|
||||
Mutex mutex { 0 };
|
||||
|
||||
DriverLedger() { mutex_construct(&mutex); }
|
||||
~DriverLedger() { mutex_destruct(&mutex); }
|
||||
@ -28,32 +37,43 @@ struct DriverLedger {
|
||||
void unlock() { mutex_unlock(&mutex); }
|
||||
};
|
||||
|
||||
static DriverLedger ledger;
|
||||
static DriverLedger& get_ledger() {
|
||||
static DriverLedger ledger;
|
||||
return ledger;
|
||||
}
|
||||
|
||||
#define ledger get_ledger()
|
||||
|
||||
#define get_driver_private(driver) static_cast<DriverPrivate*>(driver->driver_private)
|
||||
#define driver_lock(driver) mutex_lock(&get_driver_private(driver)->mutex);
|
||||
#define driver_unlock(driver) mutex_unlock(&get_driver_private(driver)->mutex);
|
||||
|
||||
extern "C" {
|
||||
|
||||
error_t driver_construct(Driver* driver) {
|
||||
driver->internal = new(std::nothrow) DriverInternal;
|
||||
if (driver->internal == nullptr) {
|
||||
driver->driver_private = new(std::nothrow) DriverPrivate;
|
||||
if (driver->driver_private == nullptr) {
|
||||
return ERROR_OUT_OF_MEMORY;
|
||||
}
|
||||
return ERROR_NONE;
|
||||
}
|
||||
|
||||
error_t driver_destruct(Driver* driver) {
|
||||
auto* internal = driver->internal;
|
||||
|
||||
driver_lock(driver);
|
||||
// No module means the system owns it and it cannot be destroyed
|
||||
if (driver->owner == nullptr) {
|
||||
driver_unlock(driver);
|
||||
return ERROR_NOT_ALLOWED;
|
||||
}
|
||||
if (internal->use_count != 0 || internal->destroying) {
|
||||
if (get_driver_private(driver)->use_count != 0 || get_driver_private(driver)->destroying) {
|
||||
driver_unlock(driver);
|
||||
return ERROR_INVALID_STATE;
|
||||
}
|
||||
internal->destroying = true;
|
||||
get_driver_private(driver)->destroying = true;
|
||||
|
||||
// Nullify internal reference before deletion to prevent use-after-free
|
||||
driver->internal = nullptr;
|
||||
delete internal;
|
||||
driver_unlock(driver);
|
||||
delete get_driver_private(driver);
|
||||
driver->driver_private = nullptr;
|
||||
|
||||
return ERROR_NONE;
|
||||
}
|
||||
@ -123,8 +143,10 @@ Driver* driver_find_compatible(const char* compatible) {
|
||||
}
|
||||
|
||||
error_t driver_bind(Driver* driver, Device* device) {
|
||||
driver_lock(driver);
|
||||
|
||||
error_t error = ERROR_NONE;
|
||||
if (driver->internal->destroying || !device_is_added(device)) {
|
||||
if (get_driver_private(driver)->destroying || !device_is_added(device)) {
|
||||
error = ERROR_INVALID_STATE;
|
||||
goto error;
|
||||
}
|
||||
@ -136,18 +158,23 @@ error_t driver_bind(Driver* driver, Device* device) {
|
||||
}
|
||||
}
|
||||
|
||||
driver->internal->use_count++;
|
||||
get_driver_private(driver)->use_count++;
|
||||
driver_unlock(driver);
|
||||
|
||||
LOG_I(TAG, "bound %s to %s", driver->name, device->name);
|
||||
return ERROR_NONE;
|
||||
|
||||
error:
|
||||
|
||||
driver_unlock(driver);
|
||||
return error;
|
||||
}
|
||||
|
||||
error_t driver_unbind(Driver* driver, Device* device) {
|
||||
driver_lock(driver);
|
||||
|
||||
error_t error = ERROR_NONE;
|
||||
if (driver->internal->destroying || !device_is_added(device)) {
|
||||
if (get_driver_private(driver)->destroying || !device_is_added(device)) {
|
||||
error = ERROR_INVALID_STATE;
|
||||
goto error;
|
||||
}
|
||||
@ -159,13 +186,16 @@ error_t driver_unbind(Driver* driver, Device* device) {
|
||||
}
|
||||
}
|
||||
|
||||
driver->internal->use_count--;
|
||||
get_driver_private(driver)->use_count--;
|
||||
driver_unlock(driver);
|
||||
|
||||
LOG_I(TAG, "unbound %s from %s", driver->name, device->name);
|
||||
|
||||
return ERROR_NONE;
|
||||
|
||||
error:
|
||||
|
||||
driver_unlock(driver);
|
||||
return error;
|
||||
}
|
||||
|
||||
|
||||
@ -32,8 +32,6 @@ error_t gpio_controller_get_pin_count(struct Device* device, uint32_t* count) {
|
||||
return GPIO_DRIVER_API(driver)->get_pin_count(device, count);
|
||||
}
|
||||
|
||||
extern const struct DeviceType GPIO_CONTROLLER_TYPE {
|
||||
.name = "gpio-controller"
|
||||
};
|
||||
extern const struct DeviceType GPIO_CONTROLLER_TYPE { 0 };
|
||||
|
||||
}
|
||||
|
||||
@ -49,8 +49,6 @@ error_t i2c_controller_has_device_at_address(Device* device, uint8_t address, Ti
|
||||
return I2C_DRIVER_API(driver)->write(device, address, message, 2, timeout);
|
||||
}
|
||||
|
||||
extern const struct DeviceType I2C_CONTROLLER_TYPE {
|
||||
.name = "i2c-controller"
|
||||
};
|
||||
extern const struct DeviceType I2C_CONTROLLER_TYPE { 0 };
|
||||
|
||||
}
|
||||
|
||||
@ -32,8 +32,6 @@ error_t i2s_controller_reset(struct Device* device) {
|
||||
return I2S_DRIVER_API(driver)->reset(device);
|
||||
}
|
||||
|
||||
extern const struct DeviceType I2S_CONTROLLER_TYPE {
|
||||
.name = "i2s-controller"
|
||||
};
|
||||
extern const struct DeviceType I2S_CONTROLLER_TYPE { 0 };
|
||||
|
||||
}
|
||||
|
||||
@ -23,8 +23,7 @@ struct Module root_module = {
|
||||
.name = "kernel",
|
||||
.start = start,
|
||||
.stop = stop,
|
||||
.symbols = (const struct ModuleSymbol*)KERNEL_SYMBOLS,
|
||||
.internal = nullptr
|
||||
.symbols = (const struct ModuleSymbol*)KERNEL_SYMBOLS
|
||||
};
|
||||
|
||||
error_t kernel_init(struct Module* platform_module, struct Module* device_module, struct CompatibleDevice devicetree_devices[]) {
|
||||
|
||||
@ -1,19 +1,14 @@
|
||||
#include <cstring>
|
||||
#include <vector>
|
||||
#include <string.h>
|
||||
#include <algorithm>
|
||||
#include <new>
|
||||
#include <tactility/concurrent/mutex.h>
|
||||
#include <tactility/module.h>
|
||||
#include <vector>
|
||||
|
||||
#define TAG "module"
|
||||
|
||||
struct ModuleInternal {
|
||||
bool started = false;
|
||||
};
|
||||
|
||||
struct ModuleLedger {
|
||||
std::vector<struct Module*> modules;
|
||||
struct Mutex mutex {};
|
||||
struct Mutex mutex = { 0 };
|
||||
|
||||
ModuleLedger() { mutex_construct(&mutex); }
|
||||
~ModuleLedger() { mutex_destruct(&mutex); }
|
||||
@ -24,14 +19,11 @@ static ModuleLedger ledger;
|
||||
extern "C" {
|
||||
|
||||
error_t module_construct(struct Module* module) {
|
||||
module->internal = new (std::nothrow) ModuleInternal();
|
||||
if (module->internal == nullptr) return ERROR_OUT_OF_MEMORY;
|
||||
module->internal.started = false;
|
||||
return ERROR_NONE;
|
||||
}
|
||||
|
||||
error_t module_destruct(struct Module* module) {
|
||||
delete static_cast<ModuleInternal*>(module->internal);
|
||||
module->internal = nullptr;
|
||||
return ERROR_NONE;
|
||||
}
|
||||
|
||||
@ -52,30 +44,28 @@ error_t module_remove(struct Module* module) {
|
||||
error_t module_start(struct Module* module) {
|
||||
LOG_I(TAG, "start %s", module->name);
|
||||
|
||||
auto* internal = static_cast<ModuleInternal*>(module->internal);
|
||||
if (internal->started) return ERROR_NONE;
|
||||
if (module->internal.started) return ERROR_NONE;
|
||||
|
||||
error_t error = module->start();
|
||||
internal->started = (error == ERROR_NONE);
|
||||
module->internal.started = (error == ERROR_NONE);
|
||||
return error;
|
||||
}
|
||||
|
||||
bool module_is_started(struct Module* module) {
|
||||
return static_cast<ModuleInternal*>(module->internal)->started;
|
||||
return module->internal.started;
|
||||
}
|
||||
|
||||
error_t module_stop(struct Module* module) {
|
||||
LOG_I(TAG, "stop %s", module->name);
|
||||
|
||||
auto* internal = static_cast<ModuleInternal*>(module->internal);
|
||||
if (!internal->started) return ERROR_NONE;
|
||||
if (!module->internal.started) return ERROR_NONE;
|
||||
|
||||
error_t error = module->stop();
|
||||
if (error != ERROR_NONE) {
|
||||
return error;
|
||||
}
|
||||
|
||||
internal->started = false;
|
||||
module->internal.started = false;
|
||||
return error;
|
||||
}
|
||||
|
||||
@ -116,3 +106,4 @@ bool module_resolve_symbol_global(const char* symbol_name, uintptr_t* symbol_add
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
project(tests)
|
||||
|
||||
set(DOCTESTINC ${PROJECT_SOURCE_DIR}/Doctest/Include)
|
||||
set(DOCTESTINC ${PROJECT_SOURCE_DIR}/Include)
|
||||
|
||||
enable_testing()
|
||||
add_subdirectory(TactilityCore)
|
||||
|
||||
@ -1,16 +0,0 @@
|
||||
cmake_minimum_required(VERSION 3.20)
|
||||
|
||||
include($ENV{IDF_PATH}/tools/cmake/project.cmake)
|
||||
|
||||
if (DEFINED ENV{TACTILITY_SDK_PATH})
|
||||
set(TACTILITY_SDK_PATH $ENV{TACTILITY_SDK_PATH})
|
||||
else()
|
||||
set(TACTILITY_SDK_PATH "../../release/TactilitySDK")
|
||||
message(WARNING "⚠️ TACTILITY_SDK_PATH environment variable is not set, defaulting to ${TACTILITY_SDK_PATH}")
|
||||
endif()
|
||||
|
||||
include("${TACTILITY_SDK_PATH}/TactilitySDK.cmake")
|
||||
set(EXTRA_COMPONENT_DIRS ${TACTILITY_SDK_PATH})
|
||||
|
||||
project(SdkTest)
|
||||
tactility_project(SdkTest)
|
||||
@ -1,6 +0,0 @@
|
||||
file(GLOB_RECURSE SOURCE_FILES Source/*.c)
|
||||
|
||||
idf_component_register(
|
||||
SRCS ${SOURCE_FILES}
|
||||
REQUIRES TactilitySDK
|
||||
)
|
||||
@ -1,41 +0,0 @@
|
||||
#include <tt_app.h>
|
||||
#include <tt_lvgl_toolbar.h>
|
||||
|
||||
#include <tactility/concurrent/dispatcher.h>
|
||||
#include <tactility/concurrent/event_group.h>
|
||||
#include <tactility/concurrent/mutex.h>
|
||||
#include <tactility/concurrent/recursive_mutex.h>
|
||||
#include <tactility/concurrent/thread.h>
|
||||
#include <tactility/concurrent/timer.h>
|
||||
#include <tactility/drivers/gpio.h>
|
||||
#include <tactility/drivers/gpio_controller.h>
|
||||
#include <tactility/drivers/i2c_controller.h>
|
||||
#include <tactility/drivers/i2s_controller.h>
|
||||
#include <tactility/drivers/root.h>
|
||||
#include <tactility/check.h>
|
||||
#include <tactility/defines.h>
|
||||
#include <tactility/delay.h>
|
||||
#include <tactility/device.h>
|
||||
#include <tactility/driver.h>
|
||||
#include <tactility/error.h>
|
||||
#include <tactility/log.h>
|
||||
#include <tactility/module.h>
|
||||
#include <tactility/time.h>
|
||||
|
||||
#include <tactility/lvgl_module.h>
|
||||
|
||||
static void onShowApp(AppHandle app, void* data, lv_obj_t* parent) {
|
||||
lv_obj_t* toolbar = tt_lvgl_toolbar_create_for_app(parent, app);
|
||||
lv_obj_align(toolbar, LV_ALIGN_TOP_MID, 0, 0);
|
||||
|
||||
lv_obj_t* label = lv_label_create(parent);
|
||||
lv_label_set_text(label, "Hello, world!");
|
||||
lv_obj_align(label, LV_ALIGN_CENTER, 0, 0);
|
||||
}
|
||||
|
||||
int main(int argc, char* argv[]) {
|
||||
tt_app_register((AppRegistration) {
|
||||
.onShow = onShowApp
|
||||
});
|
||||
return 0;
|
||||
}
|
||||
@ -1,10 +0,0 @@
|
||||
[manifest]
|
||||
version=0.1
|
||||
[target]
|
||||
sdk=0.0.0
|
||||
platforms=esp32,esp32s3,esp32c6,esp32p4
|
||||
[app]
|
||||
id=one.tactility.sdktest
|
||||
versionName=0.1.0
|
||||
versionCode=1
|
||||
name=SDK Test
|
||||
@ -1,712 +0,0 @@
|
||||
import configparser
|
||||
import json
|
||||
import os
|
||||
import re
|
||||
import shutil
|
||||
import sys
|
||||
import subprocess
|
||||
import time
|
||||
import urllib.request
|
||||
import zipfile
|
||||
import requests
|
||||
import tarfile
|
||||
from urllib.parse import urlparse
|
||||
|
||||
ttbuild_path = ".tactility"
|
||||
ttbuild_version = "3.3.0"
|
||||
ttbuild_cdn = "https://cdn.tactilityproject.org"
|
||||
ttbuild_sdk_json_validity = 3600 # seconds
|
||||
ttport = 6666
|
||||
verbose = False
|
||||
use_local_sdk = False
|
||||
local_base_path = None
|
||||
http_timeout_seconds = 10
|
||||
|
||||
shell_color_red = "\033[91m"
|
||||
shell_color_orange = "\033[93m"
|
||||
shell_color_green = "\033[32m"
|
||||
shell_color_purple = "\033[35m"
|
||||
shell_color_cyan = "\033[36m"
|
||||
shell_color_reset = "\033[m"
|
||||
|
||||
def print_help():
|
||||
print("Usage: python tactility.py [action] [options]")
|
||||
print("")
|
||||
print("Actions:")
|
||||
print(" build [platform] Build the app. Optionally specify a platform.")
|
||||
print(" Supported platforms are lower case. Example: esp32s3")
|
||||
print(" Supported platforms are read from manifest.properties")
|
||||
print(" clean Clean the build folders")
|
||||
print(" clearcache Clear the SDK cache")
|
||||
print(" updateself Update this tool")
|
||||
print(" run [ip] Run the application")
|
||||
print(" install [ip] Install the application")
|
||||
print(" uninstall [ip] Uninstall the application")
|
||||
print(" bir [ip] [platform] Build, install then run. Optionally specify a platform.")
|
||||
print(" brrr [ip] [platform] Functionally the same as \"bir\", but \"app goes brrr\" meme variant.")
|
||||
print("")
|
||||
print("Options:")
|
||||
print(" --help Show this commandline info")
|
||||
print(" --local-sdk Use SDK specified by environment variable TACTILITY_SDK_PATH with platform subfolders matching target platforms.")
|
||||
print(" --skip-build Run everything except the idf.py/CMake commands")
|
||||
print(" --verbose Show extra console output")
|
||||
|
||||
# region Core
|
||||
|
||||
def download_file(url, filepath):
|
||||
global verbose
|
||||
if verbose:
|
||||
print(f"Downloading from {url} to {filepath}")
|
||||
parsed = urlparse(url)
|
||||
if parsed.scheme not in ("http", "https"):
|
||||
print_error(f"Unsupported URL scheme: {parsed.scheme}")
|
||||
return False
|
||||
request = urllib.request.Request(
|
||||
url,
|
||||
data=None,
|
||||
headers={
|
||||
"User-Agent": f"Tactility Build Tool {ttbuild_version}"
|
||||
}
|
||||
)
|
||||
try:
|
||||
with urllib.request.urlopen(request, timeout=30) as response, open(filepath, mode="wb") as file:
|
||||
file.write(response.read())
|
||||
return True
|
||||
except OSError as error:
|
||||
if verbose:
|
||||
print_error(f"Failed to fetch URL {url}\n{error}")
|
||||
return False
|
||||
|
||||
def print_warning(message):
|
||||
print(f"{shell_color_orange}WARNING: {message}{shell_color_reset}")
|
||||
|
||||
def print_error(message):
|
||||
print(f"{shell_color_red}ERROR: {message}{shell_color_reset}")
|
||||
|
||||
def print_status_busy(status):
|
||||
sys.stdout.write(f"⌛ {status}\r")
|
||||
|
||||
def print_status_success(status):
|
||||
# Trailing spaces are to overwrite previously written characters by a potentially shorter print_status_busy() text
|
||||
print(f"✅ {shell_color_green}{status}{shell_color_reset} ")
|
||||
|
||||
def print_status_error(status):
|
||||
# Trailing spaces are to overwrite previously written characters by a potentially shorter print_status_busy() text
|
||||
print(f"❌ {shell_color_red}{status}{shell_color_reset} ")
|
||||
|
||||
def exit_with_error(message):
|
||||
print_error(message)
|
||||
sys.exit(1)
|
||||
|
||||
def get_url(ip, path):
|
||||
return f"http://{ip}:{ttport}{path}"
|
||||
|
||||
def read_properties_file(path):
|
||||
config = configparser.RawConfigParser()
|
||||
config.read(path)
|
||||
return config
|
||||
|
||||
#endregion Core
|
||||
|
||||
#region SDK helpers
|
||||
|
||||
def read_sdk_json():
|
||||
json_file_path = os.path.join(ttbuild_path, "tool.json")
|
||||
with open(json_file_path) as json_file:
|
||||
return json.load(json_file)
|
||||
|
||||
def get_sdk_dir(version, platform):
|
||||
global use_local_sdk, local_base_path
|
||||
if use_local_sdk:
|
||||
base_path = local_base_path
|
||||
if base_path is None:
|
||||
exit_with_error("TACTILITY_SDK_PATH environment variable is not set")
|
||||
sdk_parent_dir = os.path.join(base_path, f"{version}-{platform}")
|
||||
sdk_dir = os.path.join(sdk_parent_dir, "TactilitySDK")
|
||||
if not os.path.isdir(sdk_dir):
|
||||
exit_with_error(f"Local SDK folder not found for platform {platform}: {sdk_dir}")
|
||||
return sdk_dir
|
||||
else:
|
||||
return os.path.join(ttbuild_path, f"{version}-{platform}", "TactilitySDK")
|
||||
|
||||
def validate_local_sdks(platforms, version):
|
||||
if not use_local_sdk:
|
||||
return
|
||||
global local_base_path
|
||||
base_path = local_base_path
|
||||
for platform in platforms:
|
||||
sdk_parent_dir = os.path.join(base_path, f"{version}-{platform}")
|
||||
sdk_dir = os.path.join(sdk_parent_dir, "TactilitySDK")
|
||||
if not os.path.isdir(sdk_dir):
|
||||
exit_with_error(f"Local SDK folder missing for {platform}: {sdk_dir}")
|
||||
|
||||
def get_sdk_root_dir(version, platform):
|
||||
global ttbuild_cdn
|
||||
return os.path.join(ttbuild_path, f"{version}-{platform}")
|
||||
|
||||
def get_sdk_url(version, file):
|
||||
global ttbuild_cdn
|
||||
return f"{ttbuild_cdn}/sdk/{version}/{file}"
|
||||
|
||||
def sdk_exists(version, platform):
|
||||
sdk_dir = get_sdk_dir(version, platform)
|
||||
return os.path.isdir(sdk_dir)
|
||||
|
||||
def should_update_tool_json():
|
||||
global ttbuild_cdn
|
||||
json_filepath = os.path.join(ttbuild_path, "tool.json")
|
||||
if os.path.exists(json_filepath):
|
||||
json_modification_time = os.path.getmtime(json_filepath)
|
||||
now = time.time()
|
||||
global ttbuild_sdk_json_validity
|
||||
minimum_seconds_difference = ttbuild_sdk_json_validity
|
||||
return (now - json_modification_time) > minimum_seconds_difference
|
||||
else:
|
||||
return True
|
||||
|
||||
def update_tool_json():
|
||||
global ttbuild_cdn, ttbuild_path
|
||||
json_url = f"{ttbuild_cdn}/sdk/tool.json"
|
||||
json_filepath = os.path.join(ttbuild_path, "tool.json")
|
||||
return download_file(json_url, json_filepath)
|
||||
|
||||
def should_fetch_sdkconfig_files(platform_targets):
|
||||
for platform in platform_targets:
|
||||
sdkconfig_filename = f"sdkconfig.app.{platform}"
|
||||
if not os.path.exists(os.path.join(ttbuild_path, sdkconfig_filename)):
|
||||
return True
|
||||
return False
|
||||
|
||||
def fetch_sdkconfig_files(platform_targets):
|
||||
for platform in platform_targets:
|
||||
sdkconfig_filename = f"sdkconfig.app.{platform}"
|
||||
target_path = os.path.join(ttbuild_path, sdkconfig_filename)
|
||||
if not download_file(f"{ttbuild_cdn}/{sdkconfig_filename}", target_path):
|
||||
exit_with_error(f"Failed to download sdkconfig file for {platform}")
|
||||
|
||||
#endregion SDK helpers
|
||||
|
||||
#region Validation
|
||||
|
||||
def validate_environment():
|
||||
if os.environ.get("IDF_PATH") is None:
|
||||
if sys.platform == "win32":
|
||||
exit_with_error("Cannot find the Espressif IDF SDK. Ensure it is installed and that it is activated via %IDF_PATH%\\export.ps1")
|
||||
else:
|
||||
exit_with_error("Cannot find the Espressif IDF SDK. Ensure it is installed and that it is activated via $PATH_TO_IDF_SDK/export.sh")
|
||||
if not os.path.exists("manifest.properties"):
|
||||
exit_with_error("manifest.properties not found")
|
||||
if use_local_sdk == False and os.environ.get("TACTILITY_SDK_PATH") is not None:
|
||||
print_warning("TACTILITY_SDK_PATH is set, but will be ignored by this command.")
|
||||
print_warning("If you want to use it, use the '--local-sdk' parameter")
|
||||
elif use_local_sdk == True and os.environ.get("TACTILITY_SDK_PATH") is None:
|
||||
exit_with_error("local build was requested, but TACTILITY_SDK_PATH environment variable is not set.")
|
||||
|
||||
def validate_self(sdk_json):
|
||||
if not "toolVersion" in sdk_json:
|
||||
exit_with_error("Server returned invalid SDK data format (toolVersion not found)")
|
||||
if not "toolCompatibility" in sdk_json:
|
||||
exit_with_error("Server returned invalid SDK data format (toolCompatibility not found)")
|
||||
if not "toolDownloadUrl" in sdk_json:
|
||||
exit_with_error("Server returned invalid SDK data format (toolDownloadUrl not found)")
|
||||
tool_version = sdk_json["toolVersion"]
|
||||
tool_compatibility = sdk_json["toolCompatibility"]
|
||||
if tool_version != ttbuild_version:
|
||||
print_warning(f"New version available: {tool_version} (currently using {ttbuild_version})")
|
||||
print_warning(f"Run 'tactility.py updateself' to update.")
|
||||
if re.search(tool_compatibility, ttbuild_version) is None:
|
||||
print_error("The tool is not compatible anymore.")
|
||||
print_error("Run 'tactility.py updateself' to update.")
|
||||
sys.exit(1)
|
||||
|
||||
#endregion Validation
|
||||
|
||||
#region Manifest
|
||||
|
||||
def read_manifest():
|
||||
return read_properties_file("manifest.properties")
|
||||
|
||||
def validate_manifest(manifest):
|
||||
# [manifest]
|
||||
if not "manifest" in manifest:
|
||||
exit_with_error("Invalid manifest format: [manifest] not found")
|
||||
if not "version" in manifest["manifest"]:
|
||||
exit_with_error("Invalid manifest format: [manifest] version not found")
|
||||
# [target]
|
||||
if not "target" in manifest:
|
||||
exit_with_error("Invalid manifest format: [target] not found")
|
||||
if not "sdk" in manifest["target"]:
|
||||
exit_with_error("Invalid manifest format: [target] sdk not found")
|
||||
if not "platforms" in manifest["target"]:
|
||||
exit_with_error("Invalid manifest format: [target] platforms not found")
|
||||
# [app]
|
||||
if not "app" in manifest:
|
||||
exit_with_error("Invalid manifest format: [app] not found")
|
||||
if not "id" in manifest["app"]:
|
||||
exit_with_error("Invalid manifest format: [app] id not found")
|
||||
if not "versionName" in manifest["app"]:
|
||||
exit_with_error("Invalid manifest format: [app] versionName not found")
|
||||
if not "versionCode" in manifest["app"]:
|
||||
exit_with_error("Invalid manifest format: [app] versionCode not found")
|
||||
if not "name" in manifest["app"]:
|
||||
exit_with_error("Invalid manifest format: [app] name not found")
|
||||
|
||||
def is_valid_manifest_platform(manifest, platform):
|
||||
manifest_platforms = manifest["target"]["platforms"].split(",")
|
||||
return platform in manifest_platforms
|
||||
|
||||
def validate_manifest_platform(manifest, platform):
|
||||
if not is_valid_manifest_platform(manifest, platform):
|
||||
exit_with_error(f"Platform {platform} is not available in the manifest.")
|
||||
|
||||
def get_manifest_target_platforms(manifest, requested_platform):
|
||||
if requested_platform == "" or requested_platform is None:
|
||||
return manifest["target"]["platforms"].split(",")
|
||||
else:
|
||||
validate_manifest_platform(manifest, requested_platform)
|
||||
return [requested_platform]
|
||||
|
||||
#endregion Manifest
|
||||
|
||||
#region SDK download
|
||||
|
||||
def safe_extract_zip(zip_ref, target_dir):
|
||||
target_dir = os.path.realpath(target_dir)
|
||||
for member in zip_ref.infolist():
|
||||
dest = os.path.realpath(os.path.join(target_dir, member.filename))
|
||||
if not dest.startswith(target_dir + os.sep):
|
||||
raise ValueError(f"Invalid zip entry: {member.filename}")
|
||||
zip_ref.extractall(target_dir)
|
||||
|
||||
def sdk_download(version, platform):
|
||||
sdk_root_dir = get_sdk_root_dir(version, platform)
|
||||
os.makedirs(sdk_root_dir, exist_ok=True)
|
||||
sdk_index_url = get_sdk_url(version, "index.json")
|
||||
print(f"Downloading SDK version {version} for {platform}")
|
||||
sdk_index_filepath = os.path.join(sdk_root_dir, "index.json")
|
||||
if verbose:
|
||||
print(f"Downloading {sdk_index_url} to {sdk_index_filepath}")
|
||||
if not download_file(sdk_index_url, sdk_index_filepath):
|
||||
# TODO: 404 check, print a more accurate error
|
||||
print_error(f"Failed to download SDK version {version}. Check your internet connection and make sure this release exists.")
|
||||
return False
|
||||
with open(sdk_index_filepath) as sdk_index_json_file:
|
||||
sdk_index_json = json.load(sdk_index_json_file)
|
||||
sdk_platforms = sdk_index_json["platforms"]
|
||||
if platform not in sdk_platforms:
|
||||
print_error(f"Platform {platform} not found in {sdk_platforms} for version {version}")
|
||||
return False
|
||||
sdk_platform_file = sdk_platforms[platform]
|
||||
sdk_zip_source_url = get_sdk_url(version, sdk_platform_file)
|
||||
sdk_zip_target_filepath = os.path.join(sdk_root_dir, f"{version}-{platform}.zip")
|
||||
if verbose:
|
||||
print(f"Downloading {sdk_zip_source_url} to {sdk_zip_target_filepath}")
|
||||
if not download_file(sdk_zip_source_url, sdk_zip_target_filepath):
|
||||
print_error(f"Failed to download {sdk_zip_source_url} to {sdk_zip_target_filepath}")
|
||||
return False
|
||||
with zipfile.ZipFile(sdk_zip_target_filepath, "r") as zip_ref:
|
||||
safe_extract_zip(zip_ref, os.path.join(sdk_root_dir, "TactilitySDK"))
|
||||
return True
|
||||
|
||||
def sdk_download_all(version, platforms):
|
||||
for platform in platforms:
|
||||
if not sdk_exists(version, platform):
|
||||
if not sdk_download(version, platform):
|
||||
return False
|
||||
else:
|
||||
if verbose:
|
||||
print(f"Using cached download for SDK version {version} and platform {platform}")
|
||||
return True
|
||||
|
||||
#endregion SDK download
|
||||
|
||||
#region Building
|
||||
|
||||
def get_cmake_path(platform):
|
||||
return os.path.join("build", f"cmake-build-{platform}")
|
||||
|
||||
def find_elf_file(platform):
|
||||
cmake_dir = get_cmake_path(platform)
|
||||
if os.path.exists(cmake_dir):
|
||||
for file in os.listdir(cmake_dir):
|
||||
if file.endswith(".app.elf"):
|
||||
return os.path.join(cmake_dir, file)
|
||||
return None
|
||||
|
||||
def build_all(version, platforms, skip_build):
|
||||
for platform in platforms:
|
||||
# First build command must be "idf.py build", otherwise it fails to execute "idf.py elf"
|
||||
# We check if the ELF file exists and run the correct command
|
||||
# This can lead to code caching issues, so sometimes a clean build is required
|
||||
if find_elf_file(platform) is None:
|
||||
if not build_first(version, platform, skip_build):
|
||||
return False
|
||||
else:
|
||||
if not build_consecutively(version, platform, skip_build):
|
||||
return False
|
||||
return True
|
||||
|
||||
def wait_for_process(process):
|
||||
buffer = []
|
||||
if sys.platform != "win32":
|
||||
os.set_blocking(process.stdout.fileno(), False)
|
||||
while process.poll() is None:
|
||||
while True:
|
||||
line = process.stdout.readline()
|
||||
if line:
|
||||
decoded_line = line.decode("UTF-8")
|
||||
if decoded_line != "":
|
||||
buffer.append(decoded_line)
|
||||
else:
|
||||
break
|
||||
else:
|
||||
break
|
||||
# Read any remaining output
|
||||
for line in process.stdout:
|
||||
decoded_line = line.decode("UTF-8")
|
||||
if decoded_line:
|
||||
buffer.append(decoded_line)
|
||||
return buffer
|
||||
|
||||
# The first build must call "idf.py build" and consecutive builds must call "idf.py elf" as it finishes faster.
|
||||
# The problem is that the "idf.py build" always results in an error, even though the elf file is created.
|
||||
# The solution is to suppress the error if we find that the elf file was created.
|
||||
def build_first(version, platform, skip_build):
|
||||
sdk_dir = get_sdk_dir(version, platform)
|
||||
if verbose:
|
||||
print(f"Using SDK at {sdk_dir}")
|
||||
os.environ["TACTILITY_SDK_PATH"] = sdk_dir
|
||||
sdkconfig_path = os.path.join(ttbuild_path, f"sdkconfig.app.{platform}")
|
||||
shutil.copy(sdkconfig_path, "sdkconfig")
|
||||
elf_path = find_elf_file(platform)
|
||||
# Remove previous elf file: re-creation of the file is used to measure if the build succeeded,
|
||||
# as the actual build job will always fail due to technical issues with the elf cmake script
|
||||
if elf_path is not None:
|
||||
os.remove(elf_path)
|
||||
if skip_build:
|
||||
return True
|
||||
print(f"Building first {platform} build")
|
||||
cmake_path = get_cmake_path(platform)
|
||||
print_status_busy(f"Building {platform} ELF")
|
||||
shell_needed = sys.platform == "win32"
|
||||
build_command = ["idf.py", "-B", cmake_path, "build"]
|
||||
if verbose:
|
||||
print(f"Running command: {' '.join(build_command)}")
|
||||
with subprocess.Popen(build_command, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, shell=shell_needed) as process:
|
||||
build_output = wait_for_process(process)
|
||||
# The return code is never expected to be 0 due to a bug in the elf cmake script, but we keep it just in case
|
||||
if process.returncode == 0:
|
||||
print(f"{shell_color_green}Building for {platform} ✅{shell_color_reset}")
|
||||
return True
|
||||
else:
|
||||
if find_elf_file(platform) is None:
|
||||
for line in build_output:
|
||||
print(line, end="")
|
||||
print_status_error(f"Building {platform} ELF")
|
||||
return False
|
||||
else:
|
||||
print_status_success(f"Building {platform} ELF")
|
||||
return True
|
||||
|
||||
def build_consecutively(version, platform, skip_build):
|
||||
sdk_dir = get_sdk_dir(version, platform)
|
||||
if verbose:
|
||||
print(f"Using SDK at {sdk_dir}")
|
||||
os.environ["TACTILITY_SDK_PATH"] = sdk_dir
|
||||
sdkconfig_path = os.path.join(ttbuild_path, f"sdkconfig.app.{platform}")
|
||||
shutil.copy(sdkconfig_path, "sdkconfig")
|
||||
if skip_build:
|
||||
return True
|
||||
cmake_path = get_cmake_path(platform)
|
||||
print_status_busy(f"Building {platform} ELF")
|
||||
shell_needed = sys.platform == "win32"
|
||||
build_command = ["idf.py", "-B", cmake_path, "elf"]
|
||||
if verbose:
|
||||
print(f"Running command: {" ".join(build_command)}")
|
||||
with subprocess.Popen(build_command, stdout=subprocess.PIPE, stderr=subprocess.STDOUT, shell=shell_needed) as process:
|
||||
build_output = wait_for_process(process)
|
||||
if process.returncode == 0:
|
||||
print_status_success(f"Building {platform} ELF")
|
||||
return True
|
||||
else:
|
||||
for line in build_output:
|
||||
print(line, end="")
|
||||
print_status_error(f"Building {platform} ELF")
|
||||
return False
|
||||
|
||||
#endregion Building
|
||||
|
||||
#region Packaging
|
||||
|
||||
def package_intermediate_manifest(target_path):
|
||||
if not os.path.isfile("manifest.properties"):
|
||||
print_error("manifest.properties not found")
|
||||
return False
|
||||
shutil.copy("manifest.properties", os.path.join(target_path, "manifest.properties"))
|
||||
return True
|
||||
|
||||
def package_intermediate_binaries(target_path, platforms):
|
||||
elf_dir = os.path.join(target_path, "elf")
|
||||
os.makedirs(elf_dir, exist_ok=True)
|
||||
for platform in platforms:
|
||||
elf_path = find_elf_file(platform)
|
||||
if elf_path is None:
|
||||
print_error(f"ELF file not found at {elf_path}")
|
||||
return False
|
||||
shutil.copy(elf_path, os.path.join(elf_dir, f"{platform}.elf"))
|
||||
return True
|
||||
|
||||
def package_intermediate_assets(target_path):
|
||||
if os.path.isdir("assets"):
|
||||
shutil.copytree("assets", os.path.join(target_path, "assets"), dirs_exist_ok=True)
|
||||
|
||||
def package_intermediate(platforms):
|
||||
target_path = os.path.join("build", "package-intermediate")
|
||||
if os.path.isdir(target_path):
|
||||
shutil.rmtree(target_path)
|
||||
os.makedirs(target_path, exist_ok=True)
|
||||
if not package_intermediate_manifest(target_path):
|
||||
return False
|
||||
if not package_intermediate_binaries(target_path, platforms):
|
||||
return False
|
||||
package_intermediate_assets(target_path)
|
||||
return True
|
||||
|
||||
def package_name(platforms):
|
||||
elf_path = find_elf_file(platforms[0])
|
||||
elf_base_name = os.path.basename(elf_path).removesuffix(".app.elf")
|
||||
return os.path.join("build", f"{elf_base_name}.app")
|
||||
|
||||
def package_all(platforms):
|
||||
status = f"Building package with {platforms}"
|
||||
print_status_busy(status)
|
||||
if not package_intermediate(platforms):
|
||||
print_status_error("Building package failed: missing inputs")
|
||||
return False
|
||||
# Create build/something.app
|
||||
try:
|
||||
tar_path = package_name(platforms)
|
||||
tar = tarfile.open(tar_path, mode="w", format=tarfile.USTAR_FORMAT)
|
||||
tar.add(os.path.join("build", "package-intermediate"), arcname="")
|
||||
tar.close()
|
||||
print_status_success(status)
|
||||
return True
|
||||
except Exception as e:
|
||||
print_status_error(f"Building package failed: {e}")
|
||||
return False
|
||||
|
||||
#endregion Packaging
|
||||
|
||||
def setup_environment():
|
||||
global ttbuild_path
|
||||
os.makedirs(ttbuild_path, exist_ok=True)
|
||||
|
||||
def build_action(manifest, platform_arg, skip_build):
|
||||
# Environment validation
|
||||
validate_environment()
|
||||
platforms_to_build = get_manifest_target_platforms(manifest, platform_arg)
|
||||
|
||||
if use_local_sdk:
|
||||
global local_base_path
|
||||
local_base_path = os.environ.get("TACTILITY_SDK_PATH")
|
||||
validate_local_sdks(platforms_to_build, manifest["target"]["sdk"])
|
||||
|
||||
if should_fetch_sdkconfig_files(platforms_to_build):
|
||||
fetch_sdkconfig_files(platforms_to_build)
|
||||
|
||||
if not use_local_sdk:
|
||||
sdk_json = read_sdk_json()
|
||||
validate_self(sdk_json)
|
||||
# Build
|
||||
sdk_version = manifest["target"]["sdk"]
|
||||
if not use_local_sdk:
|
||||
if not sdk_download_all(sdk_version, platforms_to_build):
|
||||
exit_with_error("Failed to download one or more SDKs")
|
||||
if not build_all(sdk_version, platforms_to_build, skip_build): # Environment validation
|
||||
return False
|
||||
if not skip_build:
|
||||
if not package_all(platforms_to_build):
|
||||
return False
|
||||
return True
|
||||
|
||||
def clean_action():
|
||||
if os.path.exists("build"):
|
||||
print_status_busy("Removing build/")
|
||||
shutil.rmtree("build")
|
||||
print_status_success("Removed build/")
|
||||
else:
|
||||
print("Nothing to clean")
|
||||
|
||||
def clear_cache_action():
|
||||
if os.path.exists(ttbuild_path):
|
||||
print_status_busy(f"Removing {ttbuild_path}/")
|
||||
shutil.rmtree(ttbuild_path)
|
||||
print_status_success(f"Removed {ttbuild_path}/")
|
||||
else:
|
||||
print("Nothing to clear")
|
||||
|
||||
def update_self_action():
|
||||
sdk_json = read_sdk_json()
|
||||
tool_download_url = sdk_json["toolDownloadUrl"]
|
||||
if download_file(tool_download_url, "tactility.py"):
|
||||
print("Updated")
|
||||
else:
|
||||
exit_with_error("Update failed")
|
||||
|
||||
def get_device_info(ip):
|
||||
print_status_busy(f"Requesting device info")
|
||||
url = get_url(ip, "/info")
|
||||
try:
|
||||
response = requests.get(url, timeout=http_timeout_seconds)
|
||||
if response.status_code != 200:
|
||||
print_error("Run failed")
|
||||
else:
|
||||
print_status_success(f"Received device info:")
|
||||
print(response.json())
|
||||
except requests.RequestException as e:
|
||||
print_status_error(f"Device info request failed: {e}")
|
||||
|
||||
def run_action(manifest, ip):
|
||||
app_id = manifest["app"]["id"]
|
||||
print_status_busy("Running")
|
||||
url = get_url(ip, "/app/run")
|
||||
params = {'id': app_id}
|
||||
try:
|
||||
response = requests.post(url, params=params, timeout=http_timeout_seconds)
|
||||
if response.status_code != 200:
|
||||
print_error("Run failed")
|
||||
else:
|
||||
print_status_success("Running")
|
||||
except requests.RequestException as e:
|
||||
print_status_error(f"Running request failed: {e}")
|
||||
|
||||
def install_action(ip, platforms):
|
||||
print_status_busy("Installing")
|
||||
for platform in platforms:
|
||||
elf_path = find_elf_file(platform)
|
||||
if elf_path is None:
|
||||
print_status_error(f"ELF file not built for {platform}")
|
||||
return False
|
||||
package_path = package_name(platforms)
|
||||
# print(f"Installing {package_path} to {ip}")
|
||||
url = get_url(ip, "/app/install")
|
||||
try:
|
||||
# Prepare multipart form data
|
||||
with open(package_path, 'rb') as file:
|
||||
files = {
|
||||
'elf': file
|
||||
}
|
||||
response = requests.put(url, files=files, timeout=http_timeout_seconds)
|
||||
if response.status_code != 200:
|
||||
print_status_error("Install failed")
|
||||
return False
|
||||
else:
|
||||
print_status_success("Installing")
|
||||
return True
|
||||
except requests.RequestException as e:
|
||||
print_status_error(f"Install request failed: {e}")
|
||||
return False
|
||||
except IOError as e:
|
||||
print_status_error(f"Install file error: {e}")
|
||||
return False
|
||||
|
||||
def uninstall_action(manifest, ip):
|
||||
app_id = manifest["app"]["id"]
|
||||
print_status_busy("Uninstalling")
|
||||
url = get_url(ip, "/app/uninstall")
|
||||
params = {'id': app_id}
|
||||
try:
|
||||
response = requests.put(url, params=params, timeout=http_timeout_seconds)
|
||||
if response.status_code != 200:
|
||||
print_status_error("Server responded that uninstall failed")
|
||||
else:
|
||||
print_status_success("Uninstalled")
|
||||
except requests.RequestException as e:
|
||||
print_status_error(f"Uninstall request failed: {e}")
|
||||
|
||||
#region Main
|
||||
|
||||
if __name__ == "__main__":
|
||||
print(f"Tactility Build System v{ttbuild_version}")
|
||||
if "--help" in sys.argv:
|
||||
print_help()
|
||||
sys.exit()
|
||||
# Argument validation
|
||||
if len(sys.argv) == 1:
|
||||
print_help()
|
||||
sys.exit(1)
|
||||
if "--verbose" in sys.argv:
|
||||
verbose = True
|
||||
sys.argv.remove("--verbose")
|
||||
skip_build = False
|
||||
if "--skip-build" in sys.argv:
|
||||
skip_build = True
|
||||
sys.argv.remove("--skip-build")
|
||||
if "--local-sdk" in sys.argv:
|
||||
use_local_sdk = True
|
||||
sys.argv.remove("--local-sdk")
|
||||
action_arg = sys.argv[1]
|
||||
|
||||
# Environment setup
|
||||
setup_environment()
|
||||
if not os.path.isfile("manifest.properties"):
|
||||
exit_with_error("manifest.properties not found")
|
||||
manifest = read_manifest()
|
||||
validate_manifest(manifest)
|
||||
all_platform_targets = manifest["target"]["platforms"].split(",")
|
||||
# Update SDK cache (tool.json)
|
||||
if not use_local_sdk and should_update_tool_json() and not update_tool_json():
|
||||
exit_with_error("Failed to retrieve SDK info")
|
||||
# Actions
|
||||
if action_arg == "build":
|
||||
if len(sys.argv) < 2:
|
||||
print_help()
|
||||
exit_with_error("Commandline parameter missing")
|
||||
platform = None
|
||||
if len(sys.argv) > 2:
|
||||
platform = sys.argv[2]
|
||||
if not build_action(manifest, platform, skip_build):
|
||||
sys.exit(1)
|
||||
elif action_arg == "clean":
|
||||
clean_action()
|
||||
elif action_arg == "clearcache":
|
||||
clear_cache_action()
|
||||
elif action_arg == "updateself":
|
||||
update_self_action()
|
||||
elif action_arg == "run":
|
||||
if len(sys.argv) < 3:
|
||||
print_help()
|
||||
exit_with_error("Commandline parameter missing")
|
||||
run_action(manifest, sys.argv[2])
|
||||
elif action_arg == "install":
|
||||
if len(sys.argv) < 3:
|
||||
print_help()
|
||||
exit_with_error("Commandline parameter missing")
|
||||
platform = None
|
||||
platforms_to_install = all_platform_targets
|
||||
if len(sys.argv) >= 4:
|
||||
platform = sys.argv[3]
|
||||
platforms_to_install = [platform]
|
||||
install_action(sys.argv[2], platforms_to_install)
|
||||
elif action_arg == "uninstall":
|
||||
if len(sys.argv) < 3:
|
||||
print_help()
|
||||
exit_with_error("Commandline parameter missing")
|
||||
uninstall_action(manifest, sys.argv[2])
|
||||
elif action_arg == "bir" or action_arg == "brrr":
|
||||
if len(sys.argv) < 3:
|
||||
print_help()
|
||||
exit_with_error("Commandline parameter missing")
|
||||
platform = None
|
||||
platforms_to_install = all_platform_targets
|
||||
if len(sys.argv) >= 4:
|
||||
platform = sys.argv[3]
|
||||
platforms_to_install = [platform]
|
||||
if build_action(manifest, platform, skip_build):
|
||||
if install_action(sys.argv[2], platforms_to_install):
|
||||
run_action(manifest, sys.argv[2])
|
||||
else:
|
||||
print_help()
|
||||
exit_with_error("Unknown commandline parameter")
|
||||
|
||||
#endregion Main
|
||||
@ -4,12 +4,16 @@ enable_language(C CXX ASM)
|
||||
|
||||
set(CMAKE_CXX_COMPILER g++)
|
||||
|
||||
file(GLOB_RECURSE TEST_SOURCES ${PROJECT_SOURCE_DIR}/Source/*.cpp)
|
||||
file(GLOB_RECURSE TEST_SOURCES ${PROJECT_SOURCE_DIR}/*.cpp)
|
||||
add_executable(TactilityTests EXCLUDE_FROM_ALL ${TEST_SOURCES})
|
||||
|
||||
target_include_directories(TactilityTests PRIVATE ${DOCTESTINC})
|
||||
target_include_directories(TactilityTests PRIVATE
|
||||
${DOCTESTINC}
|
||||
)
|
||||
|
||||
add_test(NAME TactilityTests COMMAND TactilityTests)
|
||||
add_test(NAME TactilityTests
|
||||
COMMAND TactilityTests
|
||||
)
|
||||
|
||||
target_link_libraries(TactilityTests PRIVATE
|
||||
Tactility
|
||||
|
||||
@ -1,8 +1,8 @@
|
||||
#include "../../TactilityCore/Source/TestFile.h"
|
||||
#include "../../Tactility/Include/Tactility/file/PropertiesFile.h"
|
||||
|
||||
#include "../TactilityCore/TestFile.h"
|
||||
#include "doctest.h"
|
||||
|
||||
#include <../../Tactility/Include/Tactility/file/PropertiesFile.h>
|
||||
|
||||
using namespace tt;
|
||||
|
||||
TEST_CASE("loadPropertiesFile() should return false when the file does not exist") {
|
||||
@ -4,12 +4,16 @@ enable_language(C CXX ASM)
|
||||
|
||||
set(CMAKE_CXX_COMPILER g++)
|
||||
|
||||
file(GLOB_RECURSE TEST_SOURCES ${PROJECT_SOURCE_DIR}/Source/*.cpp)
|
||||
file(GLOB_RECURSE TEST_SOURCES ${PROJECT_SOURCE_DIR}/*.cpp)
|
||||
add_executable(TactilityCoreTests EXCLUDE_FROM_ALL ${TEST_SOURCES})
|
||||
|
||||
target_include_directories(TactilityCoreTests PRIVATE ${DOCTESTINC})
|
||||
target_include_directories(TactilityCoreTests PRIVATE
|
||||
${DOCTESTINC}
|
||||
)
|
||||
|
||||
add_test(NAME TactilityCoreTests COMMAND TactilityCoreTests)
|
||||
add_test(NAME TactilityCoreTests
|
||||
COMMAND TactilityCoreTests
|
||||
)
|
||||
|
||||
target_link_libraries(TactilityCoreTests PUBLIC
|
||||
TactilityCore
|
||||
|
||||
@ -4,12 +4,16 @@ enable_language(C CXX ASM)
|
||||
|
||||
set(CMAKE_CXX_COMPILER g++)
|
||||
|
||||
file(GLOB_RECURSE TEST_SOURCES ${PROJECT_SOURCE_DIR}/Source/*.cpp)
|
||||
file(GLOB_RECURSE TEST_SOURCES ${PROJECT_SOURCE_DIR}/*.cpp)
|
||||
add_executable(TactilityFreeRtosTests EXCLUDE_FROM_ALL ${TEST_SOURCES})
|
||||
|
||||
target_include_directories(TactilityFreeRtosTests PRIVATE ${DOCTESTINC})
|
||||
target_include_directories(TactilityFreeRtosTests PRIVATE
|
||||
${DOCTESTINC}
|
||||
)
|
||||
|
||||
add_test(NAME TactilityFreeRtosTests COMMAND TactilityFreeRtosTests)
|
||||
add_test(NAME TactilityFreeRtosTests
|
||||
COMMAND TactilityFreeRtosTests
|
||||
)
|
||||
|
||||
target_link_libraries(TactilityFreeRtosTests PUBLIC
|
||||
TactilityFreeRtos
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
x
Reference in New Issue
Block a user