From 48c0209b01931b609ce258a4c1699221c7bdf3bc Mon Sep 17 00:00:00 2001 From: Malia Labor <99438964+MaliaLabor@users.noreply.github.com> Date: Fri, 9 Aug 2024 09:56:00 -0700 Subject: [PATCH] Initial commit --- .clang-format | 10 ++ .clangd | 8 + .github/workflows/ci.yml | 78 +++++++++ .github/workflows/deploy.yml | 12 ++ .github/workflows/take.yml | 30 ++++ .github/workflows/update_name.yml | 57 +++++++ .gitignore | 60 +++++++ ARCHITECTURE.md | 174 ++++++++++++++++++++ CMakeLists.txt | 27 +++ CODE_OF_CONDUCT.md | 85 ++++++++++ CONTRIBUTING.md | 28 ++++ LICENSE | 201 +++++++++++++++++++++++ README.md | 82 +++++++++ conanfile.py | 40 +++++ datasheets/put_datasheets_here.md | 1 + demos/CMakeLists.txt | 31 ++++ demos/applications/__device__.cpp | 36 ++++ demos/conanfile.py | 24 +++ demos/main.cpp | 77 +++++++++ demos/platforms/lpc4074.cpp | 2 + demos/platforms/lpc4078.cpp | 53 ++++++ demos/platforms/micromod.cpp | 31 ++++ demos/platforms/stm32f103c8.cpp | 52 ++++++ demos/resource_list.hpp | 35 ++++ include/libhal-__device__/__device__.hpp | 20 +++ src/__device__.cpp | 18 ++ test_package/CMakeLists.txt | 24 +++ test_package/conanfile.py | 24 +++ test_package/main.cpp | 20 +++ tests/__device__.test.cpp | 31 ++++ tests/main.test.cpp | 22 +++ 31 files changed, 1393 insertions(+) create mode 100644 .clang-format create mode 100644 .clangd create mode 100644 .github/workflows/ci.yml create mode 100644 .github/workflows/deploy.yml create mode 100644 .github/workflows/take.yml create mode 100644 .github/workflows/update_name.yml create mode 100644 .gitignore create mode 100644 ARCHITECTURE.md create mode 100644 CMakeLists.txt create mode 100644 CODE_OF_CONDUCT.md create mode 100644 CONTRIBUTING.md create mode 100644 LICENSE create mode 100644 README.md create mode 100644 conanfile.py create mode 100644 datasheets/put_datasheets_here.md create mode 100644 demos/CMakeLists.txt create mode 100644 demos/applications/__device__.cpp create mode 100644 demos/conanfile.py create mode 100644 demos/main.cpp create mode 100644 demos/platforms/lpc4074.cpp create mode 100644 demos/platforms/lpc4078.cpp create mode 100644 demos/platforms/micromod.cpp create mode 100644 demos/platforms/stm32f103c8.cpp create mode 100644 demos/resource_list.hpp create mode 100644 include/libhal-__device__/__device__.hpp create mode 100644 src/__device__.cpp create mode 100644 test_package/CMakeLists.txt create mode 100644 test_package/conanfile.py create mode 100644 test_package/main.cpp create mode 100644 tests/__device__.test.cpp create mode 100644 tests/main.test.cpp diff --git a/.clang-format b/.clang-format new file mode 100644 index 0000000..c9c00d1 --- /dev/null +++ b/.clang-format @@ -0,0 +1,10 @@ +BasedOnStyle: Mozilla +Language: Cpp +UseTab: Never +AlwaysBreakAfterReturnType: None +AlwaysBreakAfterDefinitionReturnType: None +AllowShortFunctionsOnASingleLine: None +FixNamespaceComments: true +SpacesBeforeTrailingComments: 2 +ColumnLimit: 80 +QualifierAlignment: Right diff --git a/.clangd b/.clangd new file mode 100644 index 0000000..f02151c --- /dev/null +++ b/.clangd @@ -0,0 +1,8 @@ +If: + PathMatch: demos/.* + CompileFlags: + CompilationDatabase: demos +Else: + CompileFlags: + CompilationDatabase: . + diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..e72d001 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,78 @@ +# Copyright 2024 Khalil Estell +# +# 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. + +name: โœ… CI + +on: + workflow_dispatch: + pull_request: + push: + branches: + - main + schedule: + - cron: "0 12 * * 0" + +jobs: + ci: + uses: libhal/ci/.github/workflows/library_check.yml@5.x.y + secrets: inherit + + deploy_all_check: + uses: libhal/ci/.github/workflows/deploy_all.yml@5.x.y + secrets: inherit + + demo_check_lpc4074: + uses: libhal/ci/.github/workflows/demo_builder.yml@5.x.y + with: + compiler_profile_url: https://github.com/libhal/arm-gnu-toolchain.git + compiler_profile: v1/arm-gcc-12.3 + platform_profile_url: https://github.com/libhal/libhal-arm-mcu.git + platform_profile: v1/lpc4074 + secrets: inherit + + demo_check_lpc4078: + uses: libhal/ci/.github/workflows/demo_builder.yml@5.x.y + with: + compiler_profile_url: https://github.com/libhal/arm-gnu-toolchain.git + compiler_profile: v1/arm-gcc-12.3 + platform_profile_url: https://github.com/libhal/libhal-arm-mcu.git + platform_profile: v1/lpc4078 + secrets: inherit + + demo_check_stm32f103c8: + uses: libhal/ci/.github/workflows/demo_builder.yml@5.x.y + with: + compiler_profile_url: https://github.com/libhal/arm-gnu-toolchain.git + compiler_profile: v1/arm-gcc-12.3 + platform_profile_url: https://github.com/libhal/libhal-arm-mcu.git + platform_profile: v1/stm32f103c8 + secrets: inherit + + demo_check_mod-stm32f1-v4: + uses: libhal/ci/.github/workflows/demo_builder.yml@5.x.y + with: + compiler_profile_url: https://github.com/libhal/arm-gnu-toolchain.git + compiler_profile: v1/arm-gcc-12.3 + platform_profile_url: https://github.com/libhal/libhal-micromod.git + platform_profile: v1/mod-stm32f1-v4 + secrets: inherit + + demo_check_mod-lpc40-v5: + uses: libhal/ci/.github/workflows/demo_builder.yml@5.x.y + with: + compiler_profile_url: https://github.com/libhal/arm-gnu-toolchain.git + compiler_profile: v1/arm-gcc-12.3 + platform_profile_url: https://github.com/libhal/libhal-micromod.git + platform_profile: v1/mod-lpc40-v5 + secrets: inherit diff --git a/.github/workflows/deploy.yml b/.github/workflows/deploy.yml new file mode 100644 index 0000000..f1d660a --- /dev/null +++ b/.github/workflows/deploy.yml @@ -0,0 +1,12 @@ +name: ๐Ÿš€ Deploy + +on: + workflow_dispatch: + +jobs: + deploy: + if: startsWith(github.ref, 'refs/tags/') + uses: libhal/ci/.github/workflows/deploy_all.yml@5.x.y + with: + version: ${{ github.ref_name }} + secrets: inherit diff --git a/.github/workflows/take.yml b/.github/workflows/take.yml new file mode 100644 index 0000000..45c0417 --- /dev/null +++ b/.github/workflows/take.yml @@ -0,0 +1,30 @@ +# Copyright 2024 Khalil Estell +# +# 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. + +# .github/workflows/take.yml +name: ๐Ÿ“› assign issue to contributor +on: + issue_comment: + +jobs: + assign: + name: Take an issue + runs-on: ubuntu-latest + steps: + - name: take the issue + uses: bdougie/take-action@main + env: + GITHUB_TOKEN: ${{ github.token }} + with: + message: Thanks for taking this issue! Let us know if you have any questions! diff --git a/.github/workflows/update_name.yml b/.github/workflows/update_name.yml new file mode 100644 index 0000000..606457f --- /dev/null +++ b/.github/workflows/update_name.yml @@ -0,0 +1,57 @@ +# Copyright 2024 Khalil Estell +# +# 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. + +name: ๐Ÿ–‹๏ธ Update package name + +on: + workflow_dispatch: + push: + branches: + - main + +jobs: + update_name: + name: ๐Ÿ–‹๏ธ Update package name + runs-on: ubuntu-latest + if: github.repository != 'libhal/libhal-__device__' + steps: + - uses: actions/checkout@v2 + with: + submodules: true + + - run: sudo apt install rename + + - name: Get device name from repo name + id: device_name + run: echo ${{ github.event.repository.name }} | sed -En "s/libhal-(.*)/device_name=\1/p" >> $GITHUB_ENV + + - name: Replace placeholder's in files + run: find . -type f -not -path '*/\.git/*' -exec sed -i "s/__device__/${{ env.device_name }}/g" {} + + + - name: Replace "// NOLINT" in files + run: find . -type f -not -path '*/\.git/*' -exec sed -i "s/[ ]*\/\/ NOLINT//g" {} + + + - name: Replace placeholder's in directory names + run: find . -type d -not -path '*/\.git/*' | xargs -r rename "s/__device__/${{ env.device_name }}/g" + + - name: Replace placeholder's in file names + run: find . -type f -not -path '*/\.git/*' | xargs -r rename "s/__device__/${{ env.device_name }}/g" + + - name: Remove update_name.yml file + run: rm .github/workflows/update_name.yml + + - name: Create Pull Request + uses: peter-evans/create-pull-request@v6 + with: + title: "Rename device package to libhal-${{ env.device_name }}" diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..aeab307 --- /dev/null +++ b/.gitignore @@ -0,0 +1,60 @@ +# Prerequisites +*.d + +# Compiled Object files +*.slo +*.lo +*.o +*.obj + +# Precompiled Headers +*.gch +*.pch + +# Compiled Dynamic libraries +*.so +*.dylib +*.dll + +# Fortran module files +*.mod +*.smod + +# Compiled Static libraries +*.lai +*.la +*.a +*.lib + +# Executables +*.exe +*.out +*.app + +# IDEs +.vscode/ +archives/ + +# GDB +.gdb_history + +# Artifacts +build/ +tools/ + +# lint artifacts +compile_commands.json +.cache/ + +# OS files +.DS_Store + +# Conan Files +graph_info.json +conaninfo.txt +conan.lock +conanbuildinfo.txt + +# CMake +CMakeUserPresets.json + diff --git a/ARCHITECTURE.md b/ARCHITECTURE.md new file mode 100644 index 0000000..e101692 --- /dev/null +++ b/ARCHITECTURE.md @@ -0,0 +1,174 @@ +# libhal device library architecture + +Version: 1 + +This document goes over the layout and architecture of a libhal device library. +libhal device libraries implement device drivers by utilizing libhal +interfaces. For example, a typical accelerometer (acceleration sensor), +communicates with a host CPU via the protocol I2C. In order for that driver to +be able to communicate over i2c it must be provided with an i2c driver +controlling the port the sensor is connected to. This is done like so: + +```C++ +class some_accelerometer { + some_accelerometer(hal::i2c& p_i2c, hal::byte p_address); +}; +``` + +## Making a new Device Driver + +To make your own libhal library: + +1. Press the green "Use this Template" button then press the "Create a new + repository". +2. Name it `libhal-` and replace `` with + the name of the device's family. For exmaple, if you want to make a library + for the MPU series of IMUs then call it `libhal-mpu`. +3. Choose where to put the repo under, +4. Go to `settings` > `Pages` > `Build and deployment` > `Source` and set the + source to `Github Actions`. +5. Go to `Pull Requests` and merge the library rename pull request. +6. Done! + +## Layout of the Directory + +### `.github/workflows/` + +This directory contains GitHub Actions workflow files for continuous integration +(CI) and other automated tasks. The workflows currently included are: + +- `deploy.yml`: This workflow is used for deploy released versions of the code + to the JFrog artifactory. See the section: +- `ci.yml`: This workflow runs the CI pipeline, which includes building the + project, running tests, and deploying the library to the `libhal-trunk` + package repository. +- `take.yml`: This workflow is responsible for the "take" action, which assigns + commits to +- `update_name.yml`: This workflow updates the name of the repository when it's + used as a template for a new repository. + +### `conanfile.py` + +This is a [Conan](https://conan.io/) recipe file. Conan is a package manager for +C and C++ that helps manage dependencies in your project. This file defines how +Conan should build your project and its dependencies. + +This conan file utilizes the +[`libhal-bootstrap`](https://github.com/libhal/libhal-bootstrap) extension +library to reduce the amount of replicated code for libhal libraries. This conanfile extends the `libhal-bootstrap.library` class. That class implements: + +- `def validate(self)` +- `def layout(self)` +- `def generate(self)` +- `def build(self)` +- `def package(self)` +- `def build_requirements(self)`: which adds the tool packages for `cmake`, + `libhal-cmake-util`, `libhal-mock`, `boost-ext-ut` + +The class methods can be extended by implementing your own. The base class +implementations simply get called first. The derived class can then extend +these even further, but in general, most of these should be left untouched. + +### `CMakeList.txt` + +The root CMake build script for the library. It contains a call to the +[`libhal-cmake-util`](https://github.com/libhal/libhal-cmake-util) function +[`libhal_test_and_make_library()`](https://github.com/libhal/libhal-cmake-util?tab=readme-ov-file#libhal_test_and_make_library). + +### `datasheets/` + +This directory is intended for storing data sheets related to the device that +the library is being built for. By default this will contain a placeholder file, +`put_datasheets_here.md`. This directory is meant to be a reference for library +developers and potentially users of the library, to gain information about how +the device behaves. + +Many data sheets are subject to copyright and that must be considered when +adding the datasheet to a libhal repo. If the datasheet cannot be redistributed +on the repo for copyright and/or license reasons, then a markdown file with a +link to the datasheet (and potentially mirrors of it) is an acceptable +alternative. + +### `demos/` + +This directory contains demonstration applications showing how to use the device +library. It includes: + +- `resource_list.hpp`: A header file defining the resource list required for + the demo applications. +- `main.cpp`: The main entry point for the demo applications. +- `platforms/lpc4074.cpp` and `platforms/lpc4078.cpp`: Platform-specific + implementations for the demo applications. +- `CMakeLists.txt`: Build file using the + [`libhal_build_demos`](https://github.com/libhal/libhal-cmake-util?tab=readme-ov-file#libhal_test_and_make_library) + function from + [`libhal-cmake-util`](https://github.com/libhal/libhal-cmake-util). + +The `demos/conanfile.py` utilizes the +[`libhal-bootstrap`](https://github.com/libhal/libhal-bootstrap) extension +library and extends the `libhal-bootstrap.demos` class. This class provides the +basic building blocks for a demo. The requirements from the base class are not +transitive so: + +```python +bootstrap = self.python_requires["libhal-bootstrap"] +bootstrap.module.add_demo_requirements(self) +``` + +Must be invoked in order to add the appropriate platform libraries to the +`ConanFile` class. These platform libraries are usually `libhal-lpc40`, +`libhal-stm32f1` and `libhal-micromod`. Note that bootstrap must be updated to +support additional platforms. If you attempt to use a profile with a platform +name outside of what is supported by `libhal-bootstrap` then this API does +nothing except include `libhal-util`. + +Additional requirements and dependencies can be added after calling +`add_demo_requirements`. + +### `include/libhal-__device__/` + +This directory contains the header files for the device library. This contains +the public APIs. Try and keep the public APIs as minimal as possible as +removing or changing something from this area will result in either an API or +ABI break. + +### `src/` + +This directory contains the source files for the device library. Implementation +details for the device library and any other private support libraries are +written here. + +### `test_package/` + +This directory contains a test package for the Conan recipe. This tests that +the Conan recipe is working correctly. The test package doesn't have to do +anything fancy. It just exists to ensure that the device library can be a +dependency of an application and successfully build. Make sure to at least +include one file from the public includes of this repo in order to determine +that your headers work. If possible, create an object or run a function in the +code to ensure that your APIs and types can be used in the package. + +### `tests/` + +This directory contains tests for the device library. It will always contain a `main.test.cpp` which is the entry point for the tests. + +## How to Deploy Binaries for a Release + +1. On Github, click on the "Releases" button +2. Press "Draft a newย release" +3. For the tag drop down, provide a version. This version should be in the + [SEMVER](https://semver.org/) format like so "1.0.0". No "v1.0.0" or "1.0. + 0v" or anything like that. +4. Press "Create New Tag" on the bottom of the drop down to create a tag for + this release. +5. Press "Generate Notes" to add release notes to the release. Feel free to add + additional notes you believe are useful to developers reading over these + changes. +6. Press "Public Release" +7. The release should now exist in the "releases" section of the repo. +8. Go to Actions and on the left hand bar, press "๐Ÿš€ Deploy" +9. Press "Run Workflow" +10. For the "Use workflow from" drop down, press it and select "tag" then the + "tag" version of your release. +11. Finally press "Run Workflow" and the `deploy.yml` action will build your + device driver for all of the available libhal platforms and deploy to the JFrog Artifactory binary repository. diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..f211ba8 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,27 @@ +# Copyright 2024 Khalil Estell +# +# 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. +cmake_minimum_required(VERSION 3.15) + +project(libhal-__device__ LANGUAGES CXX) + +libhal_test_and_make_library( + LIBRARY_NAME libhal-__device__ + + SOURCES + src/__device__.cpp + + TEST_SOURCES + tests/__device__.test.cpp + tests/main.test.cpp +) diff --git a/CODE_OF_CONDUCT.md b/CODE_OF_CONDUCT.md new file mode 100644 index 0000000..a57947b --- /dev/null +++ b/CODE_OF_CONDUCT.md @@ -0,0 +1,85 @@ +# Code of Conduct + +## Our Pledge + +In the interest of fostering an open and welcoming environment, we as +contributors and maintainers pledge to making participation in our project and +our community a harassment-free experience for everyone, regardless of age, body +size, disability, ethnicity, gender identity and expression, level of +experience, education, socio-economic status, nationality, personal appearance, +race, religion, or sexual identity and orientation. + +## Our Standards + +Examples of behavior that contributes to creating a positive environment +include: + +* Using welcoming and inclusive language +* Being respectful of differing viewpoints and experiences +* Gracefully accepting constructive criticism +* Focusing on what is best for the community +* Showing empathy towards other community members + +Examples of unacceptable behavior by participants include: + +* The use of sexualized language or imagery and unwelcome sexual attention or + advances +* Trolling, insulting/derogatory comments, and personal or political attacks +* Public or private harassment +* Publishing others' private information, such as a physical or electronic + address, without explicit permission +* Other conduct which could reasonably be considered inappropriate in a + professional setting + +## Our Responsibilities + +Project maintainers are responsible for clarifying the standards of acceptable +behavior and are expected to take appropriate and fair corrective action in +response to any instances of unacceptable behavior. + +Project maintainers have the right and responsibility to remove, edit, or reject +comments, commits, code, wiki edits, issues, and other contributions that are +not aligned to this Code of Conduct, or to ban temporarily or permanently any +contributor for other behaviors that they deem inappropriate, threatening, +offensive, or harmful. + +## Scope + +This Code of Conduct applies both within project spaces and in public spaces +when an individual is representing the project or its community. Examples of +representing a project or community include using an official project e-mail +address, posting via an official social media account, or acting as an appointed +representative at an online or offline event. Representation of a project may be +further defined and clarified by project maintainers. + +This Code of Conduct also applies outside the project spaces when the Project +Steward has a reasonable belief that an individual's behavior may have a +negative impact on the project or its community. + +## Conflict Resolution + +We do not believe that all conflict is bad; healthy debate and disagreement +often yield positive results. However, it is never okay to be disrespectful or +to engage in behavior that violates the projectโ€™s code of conduct. + +If you see someone violating the code of conduct, you are encouraged to address +the behavior directly with those involved. Many issues can be resolved quickly +and easily, and this gives people more control over the outcome of their +dispute. If you are unable to resolve the matter for any reason, or if the +behavior is threatening or harassing, report it. We are dedicated to providing +an environment where participants feel welcome and safe. + +We will investigate every complaint, but you may not receive a direct response. +We will use our discretion in determining when and how to follow up on reported +incidents, which may range from not taking action to permanent expulsion from +the project and project-sponsored spaces. We will notify the accused of the +report and provide them an opportunity to discuss it before any action is taken. +The identity of the reporter will be omitted from the details of the report +supplied to the accused. In potentially harmful situations, such as ongoing +harassment or threats to anyone's safety, we may take action without notice. + +## Attribution + +This Code of Conduct is adapted from the Contributor Covenant, version 1.4, +available at +https://www.contributor-covenant.org/version/1/4/code-of-conduct/ diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 0000000..561ff1b --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,28 @@ +# How to Contribute + +We would love to accept your patches and contributions to this project. + +## Contribution process + +### :raised_hand: Self Assigning to an Issue + +If you find an issue you'd like to work on, simply type and submit a comment +with the phrase `.take` in it to get assigned by our github actions. + +### :pencil2: Pull Request Guidelines + +1. Code must finish continuous integration steps before it will be reviewed. +2. Commit messages should follow these guidelines here + https://cbea.ms/git-commit/. +3. Pull requests should contain a single commit +4. Pull requests should be small and implement a single feature where possible. + If it can be broken up into separate parts it most likely should be. +5. Each PR should have an associated issue with it. Exceptions are made for very + small PRs such as fixing typos, fixing up documentation or removing + unnecessary headers. + +### Code Reviews + +All submissions, including submissions by project members, require review. We +use [GitHub pull requests](https://docs.github.com/articles/about-pull-requests) +for this purpose. diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..261eeb9 --- /dev/null +++ b/LICENSE @@ -0,0 +1,201 @@ + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + 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/README.md b/README.md new file mode 100644 index 0000000..ac4fe91 --- /dev/null +++ b/README.md @@ -0,0 +1,82 @@ +# libhal-__device__ + +[![โœ… Checks](https://github.com/libhal/libhal-__device__/actions/workflows/ci.yml/badge.svg)](https://github.com/libhal/libhal-__device__/actions/workflows/ci.yml) +[![GitHub stars](https://img.shields.io/github/stars/libhal/libhal-__device__.svg)](https://github.com/libhal/libhal-__device__/stargazers) +[![GitHub forks](https://img.shields.io/github/forks/libhal/libhal-__device__.svg)](https://github.com/libhal/libhal-__device__/network) +[![GitHub issues](https://img.shields.io/github/issues/libhal/libhal-__device__.svg)](https://github.com/libhal/libhal-__device__/issues) + +libhal compatible device library for the __device__ family of devices. + +## ๐Ÿ—๏ธ Building Demos + +To build demos, start at the root of the repo and execute the following command: + +```bash +conan build demos -pr lpc4078 -pr arm-gcc-12.3 +``` + +or for the `lpc4074` + +```bash +conan build demos -pr lpc4074 -pr arm-gcc-12.3 +``` + +or for the `stm32f103c8` + +```bash +conan build demos -pr stm32f103c8 -pr arm-gcc-12.3 +``` + +## ๐Ÿ“ฆ Building The Library Package Demos + +To build demos, start at the root of the repo and execute the following command: + +```bash +conan create . -pr lpc4078 -pr arm-gcc-12.3 --version=latest +``` + +To compile the package for the `stm32f103c8` or `lpc4074`, simply replace the `lpc4078` profile with the appropriate profile name. For example: + +```bash +conan create . -pr stm32f103c8 -pr arm-gcc-12.3 --version=latest +``` + +> [!NOTE] +> If you are developing the code, and simply need to test that it builds and +> that tests pass, use `conan build .` vs `conan create .`. This will build the +> package locally in the current directory. You'll find the contents in the +> `build/` directory at the root of the repo. Now links will point to the code +> in the repo and NOT the conan package directory. + +## ๐Ÿ“‹ Adding `libhal-__device__` to your project + +Add the following to your `requirements()` method within your application or +library's `conanfile.py`: + +```python + def requirements(self): + self.requires("libhal-__device__/[^1.0.0]") +``` + +Replace version `1.0.0` with the desired version of the library. + +Assuming you are using CMake, you'll need to find and link the package to your +executable: + +```cmake +find_package(libhal-__device__ REQUIRED CONFIG) +target_link_libraries(app.elf PRIVATE libhal::__device__) +``` + +Replace `app.elf` with the name of your executable. + +The available headers for your app or library will exist in the +[`include/libhal-__device__/`](./include/libhal-__device__) directory. + +## Contributing + +See [`CONTRIBUTING.md`](CONTRIBUTING.md) for details. + +## License + +Apache 2.0; see [`LICENSE`](LICENSE) for details. diff --git a/conanfile.py b/conanfile.py new file mode 100644 index 0000000..9efc429 --- /dev/null +++ b/conanfile.py @@ -0,0 +1,40 @@ +# Copyright 2024 Khalil Estell +# +# 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. + +from conan import ConanFile + + +required_conan_version = ">=2.0.14" + + +class libhal___device___conan(ConanFile): + name = "libhal-__device__" + license = "Apache-2.0" + homepage = "https://github.com/libhal/libhal-__device__" + description = ("A collection of drivers for the __device__") + topics = ("__device__", "libhal", "driver") + settings = "compiler", "build_type", "os", "arch" + + python_requires = "libhal-bootstrap/[^4.0.0]" + python_requires_extend = "libhal-bootstrap.library" + + def requirements(self): + # Adds libhal and libhal-util as transitive headers, meaning library + # consumers get the libhal and libhal-util headers downstream. + bootstrap = self.python_requires["libhal-bootstrap"] + bootstrap.module.add_library_requirements(self) + + def package_info(self): + self.cpp_info.libs = ["libhal-__device__"] + self.cpp_info.set_property("cmake_target_name", "libhal::__device__") diff --git a/datasheets/put_datasheets_here.md b/datasheets/put_datasheets_here.md new file mode 100644 index 0000000..a5b5ac9 --- /dev/null +++ b/datasheets/put_datasheets_here.md @@ -0,0 +1 @@ +# Put data sheets here diff --git a/demos/CMakeLists.txt b/demos/CMakeLists.txt new file mode 100644 index 0000000..462fd3e --- /dev/null +++ b/demos/CMakeLists.txt @@ -0,0 +1,31 @@ +# Copyright 2024 Khalil Estell +# +# 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. + +cmake_minimum_required(VERSION 3.20) + +project(demos LANGUAGES CXX) + +libhal_build_demos( + DEMOS + __device__ + + INCLUDES + . + + PACKAGES + libhal-__device__ + + LINK_LIBRARIES + libhal::__device__ +) diff --git a/demos/applications/__device__.cpp b/demos/applications/__device__.cpp new file mode 100644 index 0000000..f6529cd --- /dev/null +++ b/demos/applications/__device__.cpp @@ -0,0 +1,36 @@ +// Copyright 2024 Khalil Estell +// +// 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. + +#include +#include + +#include "../resource_list.hpp" + +void application(resource_list& p_map) +{ + using namespace std::chrono_literals; + using namespace hal::literals; + + auto& clock = *p_map.clock.value(); + auto& console = *p_map.console.value(); + auto& led = *p_map.status_led.value(); + + hal::print(console, "Demo Application Starting...\n\n"); + + while (true) { + hal::print(console, "Hello, world\n"); + led.level(!led.level()); // Toggle LED + hal::delay(clock, 500ms); + } +} diff --git a/demos/conanfile.py b/demos/conanfile.py new file mode 100644 index 0000000..11cd04f --- /dev/null +++ b/demos/conanfile.py @@ -0,0 +1,24 @@ +# Copyright 2024 Khalil Estell +# +# 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. +from conan import ConanFile + + +class demos(ConanFile): + python_requires = "libhal-bootstrap/[^4.0.0]" + python_requires_extend = "libhal-bootstrap.demo" + + def requirements(self): + bootstrap = self.python_requires["libhal-bootstrap"] + bootstrap.module.add_demo_requirements(self) + self.requires("libhal-__device__/[^1.0.0 || latest]") diff --git a/demos/main.cpp b/demos/main.cpp new file mode 100644 index 0000000..3f761a1 --- /dev/null +++ b/demos/main.cpp @@ -0,0 +1,77 @@ +// Copyright 2024 Khalil Estell +// +// 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. + +#include +#include +#include +#include + +#include + +resource_list resources{}; + +[[noreturn]] void terminate_handler() noexcept +{ + + if (not resources.status_led && not resources.console) { + // spin here until debugger is connected + while (true) { + continue; + } + } + + // Otherwise, blink the led in a pattern + + auto& led = *resources.status_led.value(); + auto& clock = *resources.clock.value(); + + while (true) { + using namespace std::chrono_literals; + led.level(false); + hal::delay(clock, 100ms); + led.level(true); + hal::delay(clock, 100ms); + led.level(false); + hal::delay(clock, 100ms); + led.level(true); + hal::delay(clock, 1000ms); + } +} + +int main() +{ + try { + resources = initialize_platform(); + } catch (...) { + while (true) { + // halt here and wait for a debugger to connect + continue; + } + } + + hal::set_terminate(terminate_handler); + + try { + application(resources); + } catch (std::bad_optional_access const& e) { + if (resources.console) { + hal::print(*resources.console.value(), + "A resource required by the application was not available!\n" + "Calling terminate!\n"); + } + } // Allow any other exceptions to terminate the application + + // Terminate if the code reaches this point. + std::terminate(); +} diff --git a/demos/platforms/lpc4074.cpp b/demos/platforms/lpc4074.cpp new file mode 100644 index 0000000..6e816c9 --- /dev/null +++ b/demos/platforms/lpc4074.cpp @@ -0,0 +1,2 @@ +// Reuse lpc4078 implementation +#include "lpc4078.cpp" diff --git a/demos/platforms/lpc4078.cpp b/demos/platforms/lpc4078.cpp new file mode 100644 index 0000000..46770f8 --- /dev/null +++ b/demos/platforms/lpc4078.cpp @@ -0,0 +1,53 @@ +// Copyright 2024 Khalil Estell +// +// 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. + +#include +#include +#include +#include +#include +#include +#include +#include + +#include "../resource_list.hpp" + +resource_list initialize_platform() +{ + using namespace hal::literals; + + // Set the MCU to the maximum clock speed + hal::lpc40::maximum(10.0_MHz); + + // Create a hardware counter + static hal::cortex_m::dwt_counter counter( + hal::lpc40::get_frequency(hal::lpc40::peripheral::cpu)); + + static std::array uart0_buffer{}; + // Get and initialize UART0 for UART based logging + static hal::lpc40::uart uart0(0, + uart0_buffer, + hal::serial::settings{ + .baud_rate = 115200, + }); + + static hal::lpc40::output_pin led(1, 10); + + return { + .reset = []() { hal::cortex_m::reset(); }, + .console = &uart0, + .clock = &counter, + .status_led = &led, + }; +} diff --git a/demos/platforms/micromod.cpp b/demos/platforms/micromod.cpp new file mode 100644 index 0000000..eb2b70e --- /dev/null +++ b/demos/platforms/micromod.cpp @@ -0,0 +1,31 @@ +// Copyright 2024 Khalil Estell +// +// 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. + +#include + +#include + +resource_list initialize_platform() +{ + using namespace hal::literals; + + hal::micromod::v1::initialize_platform(); + + return { + .reset = +[]() { hal::micromod::v1::reset(); }, + .console = &hal::micromod::v1::console(hal::buffer<128>), + .clock = &hal::micromod::v1::uptime_clock(), + .status_led = &hal::micromod::v1::led(), + }; +} diff --git a/demos/platforms/stm32f103c8.cpp b/demos/platforms/stm32f103c8.cpp new file mode 100644 index 0000000..bd8f4ee --- /dev/null +++ b/demos/platforms/stm32f103c8.cpp @@ -0,0 +1,52 @@ +// Copyright 2024 Khalil Estell +// +// 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. + +#include + +#include +#include +#include + +#include +#include +#include +#include + +#include + +resource_list initialize_platform() +{ + using namespace hal::literals; + + // Set the MCU to the maximum clock speed + hal::stm32f1::maximum_speed_using_internal_oscillator(); + + static hal::cortex_m::dwt_counter counter( + hal::stm32f1::frequency(hal::stm32f1::peripheral::cpu)); + + static hal::stm32f1::uart uart1(hal::port<1>, + hal::buffer<128>, + hal::serial::settings{ + .baud_rate = 115200, + }); + + static hal::stm32f1::output_pin led('C', 13); + + return { + .reset = +[]() { hal::cortex_m::reset(); }, + .console = &uart1, + .clock = &counter, + .status_led = &led, + }; +} diff --git a/demos/resource_list.hpp b/demos/resource_list.hpp new file mode 100644 index 0000000..2800a9c --- /dev/null +++ b/demos/resource_list.hpp @@ -0,0 +1,35 @@ +// Copyright 2024 Khalil Estell +// +// 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. + +#pragma once + +#include + +#include +#include +#include +#include + +struct resource_list +{ + hal::callback reset; + std::optional console; + std::optional clock; + std::optional status_led; + // Add more driver interfaces here ... +}; + +// Application function is implemented by one of the .cpp files. +resource_list initialize_platform(); +void application(resource_list& p_map); diff --git a/include/libhal-__device__/__device__.hpp b/include/libhal-__device__/__device__.hpp new file mode 100644 index 0000000..60c9344 --- /dev/null +++ b/include/libhal-__device__/__device__.hpp @@ -0,0 +1,20 @@ +// Copyright 2024 Khalil Estell +// +// 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. + +#pragma once + +namespace hal::__device__ { // NOLINT +struct __device___replace_me // NOLINT +{}; +} // namespace hal::__device__ diff --git a/src/__device__.cpp b/src/__device__.cpp new file mode 100644 index 0000000..c0d3b65 --- /dev/null +++ b/src/__device__.cpp @@ -0,0 +1,18 @@ +// Copyright 2024 Khalil Estell +// +// 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. + +#include "libhal-__device__/__device__.hpp" + +namespace hal::__device__ { // NOLINT +} // namespace hal::__device__ diff --git a/test_package/CMakeLists.txt b/test_package/CMakeLists.txt new file mode 100644 index 0000000..886091a --- /dev/null +++ b/test_package/CMakeLists.txt @@ -0,0 +1,24 @@ +# Copyright 2024 Khalil Estell +# +# 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. + +cmake_minimum_required(VERSION 3.15) +project(test_package LANGUAGES CXX) + +find_package(libhal-__device__ REQUIRED CONFIG) + +add_executable(${PROJECT_NAME} main.cpp) +target_include_directories(${PROJECT_NAME} PUBLIC .) +target_compile_features(${PROJECT_NAME} PRIVATE cxx_std_20) +set_target_properties(${PROJECT_NAME} PROPERTIES CXX_EXTENSIONS OFF) +target_link_libraries(${PROJECT_NAME} PRIVATE libhal::__device__) diff --git a/test_package/conanfile.py b/test_package/conanfile.py new file mode 100644 index 0000000..ad581a2 --- /dev/null +++ b/test_package/conanfile.py @@ -0,0 +1,24 @@ +# Copyright 2024 Khalil Estell +# +# 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. + +from conan import ConanFile + + +class TestPackageConan(ConanFile): + settings = "os", "arch", "compiler", "build_type" + python_requires = "libhal-bootstrap/[^4.0.0]" + python_requires_extend = "libhal-bootstrap.library_test_package" + + def requirements(self): + self.requires(self.tested_reference_str) diff --git a/test_package/main.cpp b/test_package/main.cpp new file mode 100644 index 0000000..6d7d30c --- /dev/null +++ b/test_package/main.cpp @@ -0,0 +1,20 @@ +// Copyright 2024 Khalil Estell +// +// 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. + +#include + +int main() +{ + hal::__device__::__device___replace_me bar; +} diff --git a/tests/__device__.test.cpp b/tests/__device__.test.cpp new file mode 100644 index 0000000..c12bf8a --- /dev/null +++ b/tests/__device__.test.cpp @@ -0,0 +1,31 @@ +// Copyright 2024 Khalil Estell +// +// 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. + +#include + +#include + +namespace hal::__device__ { // NOLINT +void __device___test() // NOLINT +{ + using namespace boost::ut; + using namespace std::literals; + + "__device__::create()"_test = []() { + // Setup + // Exercise + // Verify + }; +}; +} // namespace hal::__device__ diff --git a/tests/main.test.cpp b/tests/main.test.cpp new file mode 100644 index 0000000..5b8c9f3 --- /dev/null +++ b/tests/main.test.cpp @@ -0,0 +1,22 @@ +// Copyright 2024 Khalil Estell +// +// 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. + +namespace hal::__device__ { // NOLINT +extern void __device___test(); // NOLINT +} // namespace hal::__device__ + +int main() +{ + hal::__device__::__device___test(); +} \ No newline at end of file