├── .DS_Store ├── .gitignore ├── .gitmodules ├── .vscode └── settings.json ├── CONTRIBUTING.md ├── LICENSE ├── README.md ├── cloudbuild-deploy.yaml ├── cloudbuild.yaml ├── cyanobyte-spec ├── __init__.py └── cyanobyte.schema.json ├── cyanobyte-templates ├── __init__.py ├── arduino.cpp ├── arduino.h ├── base.c.jinja2 ├── base.javascript.jinja2 ├── base.python.jinja2 ├── circuitpython.py ├── cmsis.svd ├── datasheet.tex ├── doc.md ├── esp32.options.yaml ├── espruino.js ├── i2c-device.py ├── kubos.c ├── kubos.h ├── macros.jinja2 ├── mcu.c ├── mcu.h ├── mcu.jinja2 ├── micropython.py ├── python-unittest.py ├── raspberrypi-spi-emboss.py ├── raspberrypi-spi-register.py ├── raspberrypi.py └── webpage.html ├── cyanobyte.egg-info ├── MANIFEST.in ├── PKG-INFO ├── SOURCES.txt ├── dependency_links.txt ├── entry_points.txt ├── requires.txt └── top_level.txt ├── cyanobyte ├── __init__.py ├── codegen.py ├── convert_json_to_yaml.py └── validator.py ├── cyanobyte_logo.png ├── cyanobyte_logo_x32.png ├── docs ├── .firebaserc ├── archetypes │ └── default.md ├── config.toml ├── content │ ├── _index.html │ ├── blocks.png │ ├── blog │ │ ├── _index.md │ │ └── news │ │ │ ├── 2019-09 │ │ │ └── live.md │ │ │ ├── 2020-04 │ │ │ └── datasheet.md │ │ │ ├── 2021-02 │ │ │ └── webpage.md │ │ │ └── 2021-03 │ │ │ └── callbacks.md │ ├── community │ │ └── _index.md │ ├── docs │ │ ├── Generate These Docs │ │ │ └── _index.md │ │ ├── Open Source │ │ │ ├── _index.md │ │ │ ├── lint.md │ │ │ └── unittest.md │ │ ├── Principle Philosophies │ │ │ ├── _index.md │ │ │ ├── cujs.md │ │ │ ├── get-started.md │ │ │ ├── philosophy.md │ │ │ ├── pseudoyaml.md │ │ │ ├── roadmap.md │ │ │ └── sample_spec.md │ │ ├── Reference │ │ │ ├── Draft Specs │ │ │ │ └── _index.md │ │ │ ├── Peripheral Docs │ │ │ │ └── _index.md │ │ │ ├── _index.md │ │ │ ├── emboss.md │ │ │ ├── pseudoyaml.md │ │ │ ├── quirks.md │ │ │ ├── specification.md │ │ │ ├── templates.md │ │ │ └── unanswered.md │ │ ├── Toolchain │ │ │ ├── _index.md │ │ │ ├── codegen.md │ │ │ └── validator.md │ │ └── _index.md │ ├── featured-background.jpg │ └── search.md └── firebase.json ├── emboss.md ├── get-pip.py ├── peripherals ├── ADS1015.yaml ├── BH1750FVI.yaml ├── BMP180.yaml ├── BMP280.yaml ├── LSM303D.yaml ├── MCP4725.yaml ├── MCP9808.yaml ├── TCS3472.yaml ├── bits.emb ├── enum.emb ├── example.yaml ├── examplespi-emboss.yaml ├── examplespi-register.yaml └── float.emb ├── requirements-dev.txt ├── requirements.txt ├── setup.py ├── spec └── __init__.py └── test ├── __init__.py ├── pylintrc ├── sampleData ├── arduino │ ├── ADS1015.cpp │ ├── ADS1015.h │ ├── BH1750FVI.cpp │ ├── BH1750FVI.h │ ├── BMP180.cpp │ ├── BMP180.h │ ├── BMP280.cpp │ ├── BMP280.h │ ├── Example.cpp │ ├── Example.h │ ├── LSM303D.cpp │ ├── LSM303D.h │ ├── MCP4725.cpp │ ├── MCP4725.h │ ├── MCP9808.cpp │ ├── MCP9808.h │ ├── TCS3472.cpp │ ├── TCS3472.h │ └── arduino.ino ├── circuitpython │ ├── ADS1015.py │ ├── BH1750FVI.py │ ├── BMP180.py │ ├── BMP280.py │ ├── Example.py │ ├── LSM303D.py │ ├── MCP4725.py │ ├── MCP9808.py │ └── TCS3472.py ├── cmsis-svd │ ├── ADS1015.svd │ ├── BH1750FVI.svd │ ├── BMP180.svd │ ├── BMP280.svd │ ├── Example.svd │ ├── LSM303D.svd │ ├── MCP4725.svd │ ├── MCP9808.svd │ └── TCS3472.svd ├── datasheet │ ├── ADS1015.tex │ ├── BH1750FVI.tex │ ├── BMP180.tex │ ├── BMP280.tex │ ├── Example.tex │ ├── LSM303D.tex │ ├── MCP4725.tex │ ├── MCP9808.tex │ └── TCS3472.tex ├── embedded-c │ ├── ADS1015.c │ ├── ADS1015.h │ ├── BH1750FVI.c │ ├── BH1750FVI.h │ ├── BMP180.c │ ├── BMP180.h │ ├── BMP280.c │ ├── BMP280.h │ ├── Example.c │ ├── Example.h │ ├── LSM303D.c │ ├── LSM303D.h │ ├── MCP4725.c │ ├── MCP4725.h │ ├── MCP9808.c │ ├── MCP9808.h │ ├── TCS3472.c │ └── TCS3472.h ├── esp32 │ ├── ADS1015.cpp │ ├── ADS1015.h │ ├── BH1750FVI.cpp │ ├── BH1750FVI.h │ ├── BMP180.cpp │ ├── BMP180.h │ ├── BMP280.cpp │ ├── BMP280.h │ ├── Example.cpp │ ├── Example.h │ ├── LSM303D.cpp │ ├── LSM303D.h │ ├── MCP4725.cpp │ ├── MCP4725.h │ ├── MCP9808.cpp │ ├── MCP9808.h │ ├── TCS3472.cpp │ └── TCS3472.h ├── espruino │ ├── ADS1015.js │ ├── BH1750FVI.js │ ├── BMP180.js │ ├── BMP280.js │ ├── Example.js │ ├── LSM303D.js │ ├── MCP4725.js │ ├── MCP9808.js │ └── TCS3472.js ├── i2c-device │ ├── ADS1015.py │ ├── BH1750FVI.py │ ├── BMP180.py │ ├── BMP280.py │ ├── Example.py │ ├── LSM303D.py │ ├── MCP4725.py │ ├── MCP9808.py │ └── TCS3472.py ├── kubos │ ├── ADS1015.c │ ├── ADS1015.h │ ├── BH1750FVI.c │ ├── BH1750FVI.h │ ├── BMP180.c │ ├── BMP180.h │ ├── BMP280.c │ ├── BMP280.h │ ├── Example.c │ ├── Example.h │ ├── LSM303D.c │ ├── LSM303D.h │ ├── MCP4725.c │ ├── MCP4725.h │ ├── MCP9808.c │ ├── MCP9808.h │ ├── TCS3472.c │ └── TCS3472.h ├── markdown │ ├── ADS1015.md │ ├── BH1750FVI.md │ ├── BMP180.md │ ├── BMP280.md │ ├── Example.md │ ├── LSM303D.md │ ├── MCP4725.md │ ├── MCP9808.md │ └── TCS3472.md ├── micropython │ ├── ADS1015.py │ ├── BH1750FVI.py │ ├── BMP180.py │ ├── BMP280.py │ ├── Example.py │ ├── LSM303D.py │ ├── MCP4725.py │ ├── MCP9808.py │ └── TCS3472.py ├── raspberrypi │ ├── ADS1015.py │ ├── BH1750FVI.py │ ├── BMP180.py │ ├── BMP280.py │ ├── Example.py │ ├── ExampleSpiEmboss.py │ ├── ExampleSpiRegister.py │ ├── LSM303D.py │ ├── MCP4725.py │ ├── MCP9808.py │ └── TCS3472.py ├── validator │ ├── blank.yaml │ ├── i2c │ │ ├── missing_address.yaml │ │ ├── missing_address_mask.yaml │ │ ├── missing_address_type.yaml │ │ └── valid.yaml │ └── info │ │ ├── missing_contact.yaml │ │ ├── missing_contact_email.yaml │ │ ├── missing_contact_name.yaml │ │ ├── missing_contact_url.yaml │ │ ├── missing_cyanobyte_version.yaml │ │ ├── missing_description.yaml │ │ ├── missing_info.yaml │ │ ├── missing_license.yaml │ │ ├── missing_license_name.yaml │ │ ├── missing_license_url.yaml │ │ ├── missing_title.yaml │ │ ├── missing_version.yaml │ │ └── valid.yaml └── webpage │ ├── ADS1015.html │ ├── BH1750FVI.html │ ├── BMP180.html │ ├── BMP280.html │ ├── Example.html │ ├── LSM303D.html │ ├── MCP4725.html │ ├── MCP9808.html │ └── TCS3472.html ├── test_cmsis_svd.py ├── test_codegen.py └── test_validator.py /.DS_Store: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/google/cyanobyte/5a6e90440e386dd478084a6c0946fdb88eb8c5a8/.DS_Store -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Build files 2 | /build/ 3 | __pycache__/ 4 | *.pyc 5 | tmp/ 6 | tmpKubos/ 7 | node_modules/ 8 | docs/public/ 9 | docs/resources/ 10 | package-lock.json 11 | **/.DS_Store 12 | .vscode/ 13 | .eggs/ 14 | dist/ -------------------------------------------------------------------------------- /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "docs/themes/docsy"] 2 | path = docs/themes/docsy 3 | url = https://github.com/google/docsy.git -------------------------------------------------------------------------------- /.vscode/settings.json: -------------------------------------------------------------------------------- 1 | { 2 | "python.pythonPath": "C:\\Users\\Nick\\AppData\\Local\\Programs\\Python\\Python38\\python.exe" 3 | } -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # How to Contribute 2 | 3 | We'd love to accept your patches and contributions to this project. There are 4 | just a few small guidelines you need to follow. 5 | 6 | ## Contributor License Agreement 7 | 8 | Contributions to this project must be accompanied by a Contributor License 9 | Agreement. You (or your employer) retain the copyright to your contribution; 10 | this simply gives us permission to use and redistribute your contributions as 11 | part of the project. Head over to to see 12 | your current agreements on file or to sign a new one. 13 | 14 | You generally only need to submit a CLA once, so if you've already submitted one 15 | (even if it was for a different project), you probably don't need to do it 16 | again. 17 | 18 | ## Code reviews 19 | 20 | All submissions, including submissions by project members, require review. We 21 | use GitHub pull requests for this purpose. Consult 22 | [GitHub Help](https://help.github.com/articles/about-pull-requests/) for more 23 | information on using pull requests. -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Cyanobyte - Machine readable datasheets for documentation & codegen 2 | 3 | ![logo](https://github.com/google/cyanobyte/raw/master/cyanobyte_logo.png) 4 | 5 | This project is an example of how to describe peripherals with an intermediary layer (YAML files) which can be used to generate library files for a peripheral. 6 | 7 | It can also generate reference documentation for a peripheral, useful for embedding into datasheets. 8 | 9 | The tool works well for I2C devices, while SPI support is in progress. 10 | 11 | This is not an official Google product. 12 | 13 | ## Setup 14 | Note: This project requires Python3. You can install using pip 15 | 16 | `pip install cyanobyte` 17 | 18 | ## Run Codegen 19 | `cyanobyte-codegen -t templates/doc.md -o ./build peripherals/MCP4725.yaml` 20 | 21 | ### Options 22 | * `-t` - A template file. You can provide multiple template files. 23 | * `-o` - The output directory where files will be generated. 24 | * `-e` - The directory that emboss folder is stored. 25 | * `-d` - Debug flag to print out additional information. 26 | * `-c` - Clean the output directory before generating files. 27 | 28 | One or multiple files can be passed as an argument. 29 | 30 | ### Clean 31 | `rm -rf ./build` 32 | 33 | ## Run Validator 34 | `cyanobyte-validator peripherals/MCP9808.yaml` 35 | 36 | One or multiple files can be passed as an argument. 37 | 38 | ## Peripheral YAML file 39 | The current spec is described in `docs/cyanobyte.md`. You can find all examples in the `peripherals/` directory. 40 | 41 | ## Test 42 | ### Lint 43 | `python3 -m pylint --rcfile=test/pylintrc cyanobyte/*.py` 44 | `python3 -m pylint --rcfile=test/pylintrc test/sampleData/*.py` 45 | 46 | ### Unit test 47 | `python3 -m unittest test.test_codegen` 48 | 49 | ## Templates 50 | The [templates](templates) directory includes a set of canonical templates which can be used with this codegen tool. 51 | 52 | The [peripherals](peripherals) directory includes a set of peripheral description files that have been created along with 53 | the project. It is not an exhaustive list. 54 | 55 | ## Development setup 56 | `pip install -r requirements.txt --user` 57 | 58 | 59 | For more advanced development, also install the dev list. 60 | `pip install -r requirements-dev.txt --user` 61 | 62 | ## Projects using Cyanobyte 63 | 64 | [File an issue or pull request](https://github.com/google/cyanobyte/issues) to add your project to the list. 65 | 66 | ## Contributors 67 | Contributions are welcome! See [CONTRIBUTING.md](CONTRIBUTING.md) for more information. 68 | 69 | When a pull request is submitted, a continuous integration task is run. The CI task must 70 | be completed successfully before a patch is merged. You can see the specific rules run in 71 | [cloudbuild.yaml](cloudbuild.yaml). 72 | 73 | ## License 74 | See [LICENSE](LICENSE) 75 | -------------------------------------------------------------------------------- /cloudbuild-deploy.yaml: -------------------------------------------------------------------------------- 1 | substitutions: 2 | _HUGO: 0.57.2 3 | steps: 4 | - name: gcr.io/cloud-builders/git 5 | entrypoint: bash 6 | id: Clone Docsy theme 7 | args: ['-c', 'git clone --recurse-submodules --depth 1 https://github.com/google/docsy.git docs/themes/docsy'] 8 | 9 | - name: node:10.15.1 10 | entrypoint: npm 11 | args: ['install', 'autoprefixer', 'postcss-cli', 'postcss'] 12 | id: Install PostCSS for final CSS assets 13 | 14 | - name: gcr.io/cloud-builders/wget 15 | entrypoint: bash 16 | args: ['-c', 'wget -O- https://github.com/gohugoio/hugo/releases/download/v${_HUGO}/hugo_extended_${_HUGO}_Linux-64bit.tar.gz | tar zx'] 17 | id: Install Hugo manually 18 | 19 | - name: docker.io/library/python:3.7 20 | args: ['pip3', 'install', '-r', 'requirements.txt', '--user'] 21 | id: Install dependencies for Python execution 22 | 23 | - name: docker.io/library/python:3.7 24 | entrypoint: python3 25 | id: Generate Hugo-compatible Markdown for our peripherals 26 | args: 27 | - 'cyanobyte/codegen.py' 28 | - '-t' 29 | - 'cyanobyte-templates/doc.md' 30 | - '-o' 31 | - './docs/content/docs/Reference/Peripheral Docs' 32 | - 'peripherals/ADS1015.yaml' 33 | - 'peripherals/BH1750FVI.yaml' 34 | - 'peripherals/BMP180.yaml' 35 | - 'peripherals/BMP280.yaml' 36 | - 'peripherals/LSM303D.yaml' 37 | - 'peripherals/MCP4725.yaml' 38 | - 'peripherals/MCP9808.yaml' 39 | - 'peripherals/TCS3472.yaml' 40 | 41 | - name: gcr.io/cloud-builders/git 42 | entrypoint: bash 43 | id: Move up content directory 44 | args: ['-c', 'mv docs/* .'] 45 | 46 | - name: node:10.15.1 47 | entrypoint: bash 48 | args: ['-c', './hugo'] 49 | id: Run Hugo manually 50 | 51 | # Setup https://github.com/GoogleCloudPlatform/cloud-builders-community/tree/master/firebase 52 | - name: gcr.io/$PROJECT_ID/firebase 53 | args: ['deploy', '--project', '$PROJECT_ID'] 54 | id: Deploy to Firebase 55 | -------------------------------------------------------------------------------- /cloudbuild.yaml: -------------------------------------------------------------------------------- 1 | steps: 2 | - name: docker.io/library/python:3.7 3 | args: ['pip3', 'install', '-r', 'requirements.txt', '--user'] 4 | id: Install dependencies 5 | - name: docker.io/library/python:3.7 6 | args: ['pip3', 'install', '-r', 'requirements-dev.txt', '--user'] 7 | id: Install dev dependencies 8 | - name: gcr.io/cloud-builders/git 9 | entrypoint: bash 10 | id: Clone Emboss 11 | args: ['-c', 'git clone https://github.com/google/emboss.git'] 12 | - name: docker.io/library/python:3.7 13 | entrypoint: bash 14 | args: ['-c', 'python3 -m pylint --rcfile=test/pylintrc ./cyanobyte/*.py'] 15 | id: Lint source code 16 | waitFor: ['Install dependencies'] 17 | - name: docker.io/library/python:3.7 18 | entrypoint: bash 19 | args: ['-c', 'python3 -m pylint --rcfile=test/pylintrc ./test/sampleData/raspberrypi/*.py'] 20 | id: Lint autogenerated files 21 | waitFor: ['Install dependencies', 'Install dev dependencies'] 22 | - name: docker.io/library/python:3.7 23 | entrypoint: python 24 | args: ['-m', 'unittest', 'discover', 'test'] 25 | id: Run unit tests 26 | waitFor: ['Lint source code', 'Lint autogenerated files', 'Install dev dependencies'] 27 | - name: docker.io/library/python:3.7 28 | entrypoint: python3 29 | args: 30 | - 'cyanobyte/codegen.py' 31 | - '-t' 32 | - 'cyanobyte-templates/raspberrypi.py' 33 | - '-t' 34 | - 'cyanobyte-templates/arduino.cpp' 35 | - '-t' 36 | - 'cyanobyte-templates/arduino.h' 37 | - '-t' 38 | - 'cyanobyte-templates/kubos.c' 39 | - '-t' 40 | - 'cyanobyte-templates/cmsis.svg' 41 | - '-t' 42 | - 'cyanobyte-templates/datasheet.tex' 43 | - '-e' 44 | - '/workspace/emboss' 45 | - '-o' 46 | - './build' 47 | - 'peripherals/ADS1015.yaml' 48 | - 'peripherals/BH1750FVI.yaml' 49 | - 'peripherals/BMP180.yaml' 50 | - 'peripherals/BMP280.yaml' 51 | - 'peripherals/LSM303D.yaml' 52 | - 'peripherals/MCP4725.yaml' 53 | - 'peripherals/MCP9808.yaml' 54 | - 'peripherals/TCS3472.yaml' 55 | - 'peripherals/examplespi-emboss.yaml' 56 | id: Sample codegen 57 | - name: wokwi/arduino-cli 58 | args: ['arduino-cli', 'compile', '-o', '/home/wokwi/ci.hex', '-b', 'arduino:avr:uno', 'test/sampleData/arduino'] 59 | id: Arduino CI 60 | waitFor: ['Sample codegen'] 61 | env: 62 | - 'HOME=/home/wokwi' 63 | artifacts: 64 | objects: 65 | # Store generated files in a Cloud Storage bucket with the commit hash as directory 66 | location: 'gs://cyanobyte-235018-githubci/$SHORT_SHA' 67 | paths: ['build/com/cyanobyte/*'] 68 | -------------------------------------------------------------------------------- /cyanobyte-spec/__init__.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # Copyright (C) 2021 Google Inc. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. -------------------------------------------------------------------------------- /cyanobyte-templates/__init__.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # Copyright (C) 2021 Google Inc. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | -------------------------------------------------------------------------------- /cyanobyte-templates/doc.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: "{{info.title}}" 3 | linkTitle: "{{info.title}}" 4 | weight: 4 5 | description: > 6 | {{info.description}} 7 | --- 8 | 9 | {# Create a dictionary linking a register to its associated fields #} 10 | {% set template = namespace(registersToFields=dict()) %} 11 | {% if fields %} 12 | {# for hierarchical display #} 13 | {% for key,field in fields|dictsort %} 14 | {% set rkey = field.register %} 15 | {% if rkey in template.registersToFields %} 16 | {% set _dummy = field.update({ 'key': key }) %} 17 | {{- template.registersToFields[rkey].append(field) or "" -}} 18 | {% else %} 19 | {% set _dummy = field.update({ 'key': key }) %} 20 | {% set _dummy = template.registersToFields.update({ rkey: [] }) %} 21 | {{- template.registersToFields[rkey].append(field) or "" -}} 22 | {% endif %} 23 | {% endfor %} 24 | {% endif %} 25 | 26 | ## Device Details 27 | 28 | {% if i2c.address is iterable and i2c.address is not string %} 29 | * Device addresses: 30 | {% for address in i2c.address %} 31 | {{address}}{{ "," if not loop.last }} 32 | {% endfor %} 33 | {% else %} 34 | * Device address {{ i2c.address }} 35 | {% endif %} 36 | * Address type {{ i2c.addressType }} 37 | {% if i2c.endian == 'little' %} 38 | * Little Endian 39 | {% endif %} 40 | 41 | ## Registers 42 | {% for key,register in registers|dictsort %} 43 | 44 | ### {{ key }} 45 | **{{ register.title }}** 46 | * Address {{register.address}} 47 | * {{register.length}}-bytes 48 | {% if register.readWrite == "R" %} 49 | * Read-only 50 | {% endif %} 51 | {% if register.readWrite == "W" %} 52 | * Write-only 53 | {% endif %} 54 | {% if register.readWrite == "n" %} 55 | * Inaccessible 56 | {% endif %} 57 | {% if register.signed %} 58 | * Signed value 59 | {% endif %} 60 | {% if 'example' in register %} 61 | * Example value: `{{ register.example.valid[0] }}` 62 | {% endif %} 63 | 64 | {{ register.description }} 65 | {% endfor %} 66 | 67 | {% if fields %} 68 | ## Fields 69 | {% for key in template.registersToFields.keys() %} 70 | {% set register = template.registersToFields[key] %} 71 | {% for field in register %} 72 | ### {{ key }}/{{field.key}} 73 | **{{ field.title }}** 74 | 75 | {% if field.bitStart == field.bitEnd %} 76 | * Bit {{field.bitStart}} 77 | {% else %} 78 | * Bits {{field.bitStart}}:{{field.bitEnd}} 79 | {% endif %} 80 | 81 | {% if field.enum %} 82 | 83 | #### Field values 84 | 85 | {% for key,enum in field.enum|dictsort %} 86 | * **{{ enum.value }}**: {{ enum.title }} 87 | {% endfor %} 88 | {% endif %} 89 | 90 | {{ field.description }} 91 | 92 | {% endfor %} 93 | {% endfor %} 94 | {% endif %} 95 | 96 | {% if functions %} 97 | ## Functions 98 | 99 | {% for key,function in functions|dictsort %} 100 | * **{{key}}**: {{function.description}} 101 | {% endfor %} 102 | {% endif %} 103 | 104 | ## License 105 | 106 | _{{ info.title }} version {{ info.version }}. Generated from Cyanobyte Codegen version {{ version }}._ 107 | 108 | Contact [{{ info.contact.name }}](mailto:{{ info.contact.email }}). 109 | 110 | Copyright {{info.copyright.name}} {{info.copyright.date}}. Published under 111 | [{{ info.license.name }}](https://spdx.org/licenses/{{ info.license.name }}.html#licenseText). 112 | -------------------------------------------------------------------------------- /cyanobyte-templates/esp32.options.yaml: -------------------------------------------------------------------------------- 1 | esp32: 2 | end: false -------------------------------------------------------------------------------- /cyanobyte-templates/i2c-device.py: -------------------------------------------------------------------------------- 1 | {% set template = namespace(registersToFields=dict()) %} 2 | {% import 'macros.jinja2' as utils %} 3 | {{ utils.pad_string('# ', utils.license(info.copyright.name, info.copyright.date, info.license.name)) -}} 4 | # 5 | # Auto-generated file for {{ info.title }} v{{ info.version }}. 6 | # Generated from {{ fileName }} using Cyanobyte Codegen v{{ version }} 7 | from i2cdevice import Device, Register, BitField 8 | 9 | {% if i2c.address is iterable and i2c.address is not string %} 10 | {% for address in i2c.address %} 11 | I2C_ADDR_{{address}} = {{address}} 12 | {% endfor %} 13 | I2C_ADDR = [{% for address in i2c.address %}I2C_ADDR_{{address}}{{', ' if not loop.last}}{% endfor %}] 14 | 15 | {% else %} 16 | I2C_ADDR = {{i2c.address}} 17 | 18 | {% endif %} 19 | {# Create a dictionary linking a register to its associated fields #} 20 | {# for hierarchical display #} 21 | {% if fields %} 22 | {% for key,field in fields|dictsort %} 23 | {% set rkey = field.register[12:] %} 24 | {% if rkey in template.registersToFields %} 25 | {% set _dummy = field.update({ 'key': key }) %} 26 | {{- template.registersToFields[rkey].append(field) or "" -}} 27 | {% else %} 28 | {% set _dummy = field.update({ 'key': key }) %} 29 | {% set _dummy = template.registersToFields.update({ rkey: [] }) %} 30 | {{- template.registersToFields[rkey].append(field) or "" -}} 31 | {% endif %} 32 | {% endfor %} 33 | {% endif %} 34 | {% macro values_map(field) %} 35 | {% if field.type == 'enum' %} 36 | { 37 | {% for ekey, enum in field.enum|dictsort %} 38 | {{ekey}}: {{enum.value}}{{',' if not loop.last }} 39 | {% endfor %} 40 | }{% endif %} 41 | {%- endmacro %} 42 | {% for key,register in registers|dictsort %} 43 | {% if key in template.registersToFields %} 44 | {{key.upper()}} = Register('{{key.upper()}}', {{register.address}}, fields=( 45 | {% for field in template.registersToFields[key] %} 46 | BitField('{{field.key}}', {{utils.mask(field.bitStart, field.bitEnd)}}, bitwidth={{field.bitStart - field.bitEnd + 1}}{% if i2c.endian == 'little' %}, values_in=_byte_swap, values_out=_byte_swap{% endif %}{% if field.type == 'enum' %}, values_map={{values_map(field)}}{% endif %}){{',' if not loop.last }} 47 | {% endfor %} 48 | ), read_only={{register.readWrite == 'R'}}, bitwidth={{register.length}}) 49 | {% else %} 50 | {{key.upper()}} = Register('{{key.upper()}}', {{register.address}}, read_only={{register.readWrite == 'R'}}, bitwidth={{register.length}}) 51 | {% endif %} 52 | {% endfor %} 53 | 54 | {{info.title.lower()}} = Device(I2C_ADDR, registers=( 55 | {% for key,register in registers|dictsort %} 56 | {{key.upper()}}{{',' if not loop.last}} 57 | {% endfor %} 58 | )) 59 | -------------------------------------------------------------------------------- /cyanobyte-templates/macros.jinja2: -------------------------------------------------------------------------------- 1 | {# 2 | Macro objectKey 3 | 4 | For a YAML object, this will get the key. 5 | ex. 6 | 7 | - key: 8 | foo: bar 9 | fez: baz 10 | 11 | Loaded in a Python dict, this is interpreted as: 12 | 13 | { 14 | "key": None, 15 | "foo": "bar", 16 | "fez": "baz" 17 | } 18 | 19 | This macro gets "key" by checking for any 20 | property that has a value of `None`. 21 | #} 22 | 23 | {% macro object_key(yamlObject) %} 24 | {% for prop, val in yamlObject.items() %} 25 | {% if val == None -%} 26 | {{prop}} 27 | {%- endif %} 28 | {% endfor %} 29 | {% endmacro %} 30 | 31 | {# 32 | Macro padString 33 | 34 | This can be useful to pad a string with comments or 35 | a given number of spaces. 36 | 37 | x = """lorem 38 | ipsum""" 39 | 40 | {{ pad_string("# ", x) }} 41 | #} 42 | 43 | {% macro pad_string(padding, contentString) %} 44 | {% for line in contentString.splitlines() %} 45 | {% if line|length > 0 %} 46 | {{padding}}{{line|trim}} 47 | {% else %} 48 | {{padding|trim}} 49 | {% endif %} 50 | {% endfor %} 51 | {% endmacro %} 52 | 53 | {# 54 | Macro license 55 | 56 | This produces a license header based on the 57 | license parameter. It generates the header 58 | for a provided company and copyright year. 59 | #} 60 | 61 | {% macro license(company, year, license) %} 62 | {% if license == "Apache-2.0" %} 63 | Copyright (C) {{year}} {{company}} 64 | 65 | Licensed under the Apache License, Version 2.0 (the "License"); 66 | you may not use this file except in compliance with the License. 67 | You may obtain a copy of the License at 68 | 69 | http://www.apache.org/licenses/LICENSE-2.0 70 | 71 | Unless required by applicable law or agreed to in writing, software 72 | distributed under the License is distributed on an "AS IS" BASIS, 73 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 74 | See the License for the specific language governing permissions and 75 | limitations under the License. 76 | {% endif %} 77 | {% endmacro %} 78 | 79 | {# 80 | Macro mask 81 | 82 | Generates a bitmask based on the start and end bits 83 | #} 84 | 85 | {% macro mask(startBit, endBit) -%} 86 | 0b 87 | {%- for bit in range(15, -1, -1) -%} 88 | {% if bit > startBit or bit < endBit -%} 89 | 0 90 | {%- else -%} 91 | 1 92 | {%- endif %} 93 | {%- endfor %} 94 | {%- endmacro %} 95 | -------------------------------------------------------------------------------- /cyanobyte-templates/mcu.jinja2: -------------------------------------------------------------------------------- 1 | {% macro doRecursion(functions, compute, rw) %} 2 | {% for step in compute.logic %} 3 | {% for key in step.keys() %} 4 | {% if step[key] is string and step[key][:12] == '#/functions/' %} 5 | {{ recursiveReadWrite(functions, step[key][12:], rw) }} 6 | {% endif %} 7 | {% if step[key] is string and step[key][:12] == '#/registers/' and rw == 'r' %} 8 | True 9 | {% endif %} 10 | {% if key == '$cmdWrite' and rw == 'w' %} 11 | True 12 | {% endif %} 13 | {% if key == 'send' and rw == 'w' %} 14 | True 15 | {% endif %} 16 | {% endfor %} 17 | {% endfor %} 18 | {% endmacro %} 19 | 20 | {% macro recursiveReadWrite(functions, name, rw) %} 21 | {% set split = name.split('/') %} 22 | {% set fname = split[0] %} 23 | {% set cname = split[1] %} 24 | {% set compute = functions[fname].computed[cname] %} 25 | {{ doRecursion(functions, compute, rw) }} 26 | {% endmacro %} 27 | 28 | {% macro functionParams(cpp, functions, compute, isCallback) %} 29 | {% set doread = doRecursion(functions, compute, 'r') %} 30 | {% set dowrite = doRecursion(functions, compute, 'w') %} 31 | {% if 'return' in compute and isCallback == false %} 32 | {% set int_t = cpp.returnType(compute) %} 33 | {{int_t}}* val, 34 | {% endif %} 35 | {% if 'input' in compute %} 36 | {{cpp.params(compute)}}{% if 'True' in dowrite %}, 37 | {% endif %} 38 | {% endif %} 39 | {% if 'True' in doread %} 40 | int (*read)(uint8_t, uint8_t, int*, uint8_t){% if 'True' in dowrite %}, 41 | {% endif %} 42 | {%- endif %} 43 | {% if 'True' in dowrite %} 44 | int (*write)(uint8_t, uint8_t, int*, uint8_t) 45 | 46 | {%- endif %} 47 | {%- endmacro %} -------------------------------------------------------------------------------- /cyanobyte.egg-info/MANIFEST.in: -------------------------------------------------------------------------------- 1 | include cyanobyte-templates/*.* 2 | include cyanobyte-spec/cyanobyte.schema.json 3 | -------------------------------------------------------------------------------- /cyanobyte.egg-info/PKG-INFO: -------------------------------------------------------------------------------- 1 | Metadata-Version: 2.1 2 | Name: cyanobyte 3 | Version: 0.0.2 4 | Summary: A package that generates library files for a peripheral given an intermediary layer (YAML files) 5 | Home-page: https://github.com/google/cyanobyte 6 | Author: Google Inc. 7 | Author-email: fleker+cyanobyte@google.com 8 | License: UNKNOWN 9 | Description: # Cyanobyte - Machine readable datasheets for documentation & codegen 10 | 11 | ![logo](https://github.com/google/cyanobyte/raw/master/cyanobyte_logo.png) 12 | 13 | This project is an example of how to describe peripherals with an intermediary layer (YAML files) which can be used to generate library files for a peripheral. 14 | 15 | It can also generate reference documentation for a peripheral, useful for embedding into datasheets. 16 | 17 | The tool works well for I2C devices, while SPI support is in progress. 18 | 19 | This is not an official Google product. 20 | 21 | ## Setup 22 | Note: This project requires Python3. You can install using pip 23 | 24 | `pip install cyanobyte` 25 | 26 | ## Run Codegen 27 | `cyanobyte-codegen -t templates/doc.md -o ./build peripherals/MCP4725.yaml` 28 | 29 | ### Options 30 | * `-t` - A template file. You can provide multiple template files. 31 | * `-o` - The output directory where files will be generated. 32 | * `-e` - The directory that emboss folder is stored. 33 | * `-d` - Debug flag to print out additional information. 34 | * `-c` - Clean the output directory before generating files. 35 | 36 | One or multiple files can be passed as an argument. 37 | 38 | ### Clean 39 | `rm -rf ./build` 40 | 41 | ## Run Validator 42 | `cyanobyte-validator peripherals/MCP9808.yaml` 43 | 44 | One or multiple files can be passed as an argument. 45 | 46 | ## Peripheral YAML file 47 | The current spec is described in `docs/cyanobyte.md`. You can find all examples in the `peripherals/` directory. 48 | 49 | ## Test 50 | ### Lint 51 | `python3 -m pylint --rcfile=test/pylintrc cyanobyte/*.py` 52 | `python3 -m pylint --rcfile=test/pylintrc test/sampleData/*.py` 53 | 54 | ### Unit test 55 | `python3 -m unittest test.test_codegen` 56 | 57 | ## Templates 58 | The [templates](templates) directory includes a set of canonical templates which can be used with this codegen tool. 59 | 60 | The [peripherals](peripherals) directory includes a set of peripheral description files that have been created along with 61 | the project. It is not an exhaustive list. 62 | 63 | ## Development setup 64 | `pip install -r requirements.txt --user` 65 | 66 | 67 | For more advanced development, also install the dev list. 68 | `pip install -r requirements-dev.txt --user` 69 | 70 | ## Projects using Cyanobyte 71 | 72 | [File an issue or pull request](https://github.com/google/cyanobyte/issues) to add your project to the list. 73 | 74 | ## Contributors 75 | Contributions are welcome! See [CONTRIBUTING.md](CONTRIBUTING.md) for more information. 76 | 77 | When a pull request is submitted, a continuous integration task is run. The CI task must 78 | be completed successfully before a patch is merged. You can see the specific rules run in 79 | [cloudbuild.yaml](cloudbuild.yaml). 80 | 81 | ## License 82 | See [LICENSE](LICENSE) 83 | 84 | Platform: UNKNOWN 85 | Classifier: Programming Language :: Python :: 3 86 | Classifier: License :: OSI Approved :: Apache Software License 87 | Classifier: Operating System :: OS Independent 88 | Requires-Python: >=3.7 89 | Description-Content-Type: text/markdown 90 | -------------------------------------------------------------------------------- /cyanobyte.egg-info/dependency_links.txt: -------------------------------------------------------------------------------- 1 | 2 | -------------------------------------------------------------------------------- /cyanobyte.egg-info/entry_points.txt: -------------------------------------------------------------------------------- 1 | [console_scripts] 2 | cyanobyte-codegen = cyanobyte.codegen:gen 3 | cyanobyte-validator = cyanobyte.validator:click_validate 4 | 5 | -------------------------------------------------------------------------------- /cyanobyte.egg-info/requires.txt: -------------------------------------------------------------------------------- 1 | click 2 | pylint 3 | pyyaml 4 | Jinja2 5 | jsonschema 6 | importlib_metadata 7 | importlib_resources 8 | pathlib2 9 | -------------------------------------------------------------------------------- /cyanobyte.egg-info/top_level.txt: -------------------------------------------------------------------------------- 1 | cyanobyte 2 | cyanobyte-spec 3 | cyanobyte-templates 4 | -------------------------------------------------------------------------------- /cyanobyte/__init__.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # Copyright (C) 2019 Google Inc. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | 16 | __version__ = "0.0.2" 17 | -------------------------------------------------------------------------------- /cyanobyte_logo.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/google/cyanobyte/5a6e90440e386dd478084a6c0946fdb88eb8c5a8/cyanobyte_logo.png -------------------------------------------------------------------------------- /cyanobyte_logo_x32.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/google/cyanobyte/5a6e90440e386dd478084a6c0946fdb88eb8c5a8/cyanobyte_logo_x32.png -------------------------------------------------------------------------------- /docs/.firebaserc: -------------------------------------------------------------------------------- 1 | { 2 | "projects": { 3 | "default": "cyanobyte-235018" 4 | } 5 | } -------------------------------------------------------------------------------- /docs/archetypes/default.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: "{{ replace .Name "-" " " | title }}" 3 | date: {{ .Date }} 4 | draft: true 5 | --- 6 | -------------------------------------------------------------------------------- /docs/config.toml: -------------------------------------------------------------------------------- 1 | baseURL = "https://cyanobyte.dev" 2 | languageCode = "en-us" 3 | title = "Cyanobyte" 4 | theme = "docsy" 5 | enableRobotsTXT = true 6 | rss_sections = ["blog"] 7 | 8 | # Configure how URLs look like per section. 9 | [permalinks] 10 | blog = "/:section/:year/:month/:day/:slug/" 11 | 12 | [params.links] 13 | # Developer relevant links. These will show up on right side of footer and in the community page if you have one. 14 | [[params.links.developer]] 15 | name = "GitHub" 16 | url = "https://github.com/google/docsy" 17 | icon = "fab fa-github" 18 | desc = "Development takes place here!" -------------------------------------------------------------------------------- /docs/content/blocks.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/google/cyanobyte/5a6e90440e386dd478084a6c0946fdb88eb8c5a8/docs/content/blocks.png -------------------------------------------------------------------------------- /docs/content/blog/_index.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: "Cyanobyte Blog" 3 | linkTitle: "Blog" 4 | menu: 5 | main: 6 | weight: 30 7 | --- 8 | 9 | This is the **blog** section. It has two categories: News and Releases. 10 | 11 | Files in these directories will be listed in reverse chronological order. -------------------------------------------------------------------------------- /docs/content/blog/news/2019-09/live.md: -------------------------------------------------------------------------------- 1 | --- 2 | date: 2019-09-06 3 | title: "Cyanobyte.dev published" 4 | linkTitle: "Cyanobyte.dev published" 5 | description: "The Cyanobyte website provides resources and documentation" 6 | author: Nick Felker 7 | --- 8 | 9 | https://cyanobyte.dev is now accessible for developers. -------------------------------------------------------------------------------- /docs/content/community/_index.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Community 3 | menu: 4 | main: 5 | weight: 40 6 | --- 7 | 8 | -------------------------------------------------------------------------------- /docs/content/docs/Generate These Docs/_index.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: "Generate These Docs" 3 | linkTitle: "Generate These Docs" 4 | weight: 99 5 | description: > 6 | How do we build this site? 7 | --- 8 | 9 | Cyanobyte's devsite uses [Docsy](https://www.docsy.dev/) as the theme, with Hugo as the underlying 10 | engine. 11 | 12 | I recommend following the [Docsy Getting Started guide](https://www.docsy.dev/docs/getting-started/) to know how to get started. 13 | 14 | Make sure the theme is setup with `git submodule update --init --recursive` 15 | 16 | Run `cd public && hugo serve` to serve at http://localhost:1313. 17 | 18 | Run `hugo && firebase deploy` to generate and deploy the site. 19 | If not done before, you may need to run `npm install postcss-cli autoprefixer` -------------------------------------------------------------------------------- /docs/content/docs/Open Source/_index.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: "How to Contribute" 3 | linkTitle: "How to Contribute" 4 | weight: 97 5 | description: > 6 | How do I get involved? 7 | --- 8 | 9 | # How to Contribute 10 | 11 | We'd love to accept your patches and contributions to this project. There are 12 | just a few small guidelines you need to follow. 13 | 14 | ## Contributor License Agreement 15 | 16 | Contributions to this project must be accompanied by a Contributor License 17 | Agreement. You (or your employer) retain the copyright to your contribution; 18 | this simply gives us permission to use and redistribute your contributions as 19 | part of the project. Head over to to see 20 | your current agreements on file or to sign a new one. 21 | 22 | You generally only need to submit a CLA once, so if you've already submitted one 23 | (even if it was for a different project), you probably don't need to do it 24 | again. 25 | 26 | ## Code reviews 27 | 28 | All submissions, including submissions by project members, require review. We 29 | use GitHub pull requests for this purpose. Consult 30 | [GitHub Help](https://help.github.com/articles/about-pull-requests/) for more 31 | information on using pull requests. 32 | 33 | ## Contributing new drivers 34 | We welcome new drivers that may help identify holes in the current specification. 35 | If you are adding a new driver, please ensure: 36 | 37 | 1. Your driver works on all available templates in the repository 38 | 1. Your driver passes the the validation tool 39 | 1. There are tests which verify the rendered output 40 | 41 | ## Contributing new platforms 42 | We welcome new templates for new languages and platforms, which may help identify 43 | holes in the current specification. If you are adding a new template, please ensure: 44 | 45 | 1. The output code for each driver compiles on your platform 46 | 1. Your template works on the hardware you specify for all available drivers in the 47 | repository 48 | 1. There are tests which verify the rendered output -------------------------------------------------------------------------------- /docs/content/docs/Open Source/lint.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: "Run lint" 3 | linkTitle: "Run lint" 4 | weight: 3 5 | description: > 6 | Make sure to run linting before you submit a PR 7 | --- 8 | 9 | This requires pylint. 10 | 11 | `python3 -m pylint --rcfile=test/pylintrc src/*.py python3 -m pylint --rcfile=test/pylintrc test/sampleData/*.py` -------------------------------------------------------------------------------- /docs/content/docs/Open Source/unittest.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: "Run unit tests" 3 | linkTitle: "Run unit tests" 4 | weight: 4 5 | description: > 6 | Make sure to run unit tests before you submit a PR 7 | --- 8 | 9 | Run: 10 | 11 | `python3 -m unittest test.test_codegen` -------------------------------------------------------------------------------- /docs/content/docs/Principle Philosophies/_index.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: "Cyanobyte" 3 | linkTitle: "Cyanobyte" 4 | weight: 1 5 | description: > 6 | What is this project? 7 | --- 8 | 9 | This file contains a proposed updated CyanoByte specification. It is currently a work in progress and aimed at spurring a discussion surrounding what the specification should look like. 10 | 11 | While there are some peripheral libraries for some hardware platforms, there is not broad support 12 | for every peripheral on every microcontroller or IoT platform. For engineers, there is an M*N problem 13 | in scaling support. 14 | 15 | The CyanoByte specification is a tool to describe the interface to embedded communications in a machine-readable format. It builds off the successes of OpenAPI for web APIs. This will reduce the 16 | problem to M+N. 17 | 18 | ## Philosophy of CyanoByte 19 | 20 | Throughout this exercise, common principles should be extracted to guide future decision making the project. 21 | 22 | - The spec should be representative of how things are currently done, even if it is less "proper" or correct. 23 | - The spec should properly separate the datasheet values and the underlying software platform, not 24 | making assumptions about runtime or programming language. 25 | 26 | ## Example Usage 27 | 28 | For a sample sensor, like a BMP280 temperature sensor, there are several pieces that need to be 29 | taken into consideration. For example, the basic temperature value in the registers isn't in any 30 | logical unit. You need to go through a series of arithmetic steps to get Celsius. Traditionally, 31 | engineers needed to read the datasheet and translate that into code. This is prone to error and 32 | time-consuming. 33 | 34 | Manufacturers typically host several files alongside their product. One is a CAD file, which may 35 | be used in designing hardware casing. One may be an electrical schematic for circuit board design, 36 | available in programs like KiCad. However, for software engineers, you only get the datasheet. 37 | 38 | What if the manufacturer provided a Cyanobyte file for the part? The software engineer could 39 | download it, and run a command-line tool to get the file they need for their platform: 40 | 41 | `python3 src/codegen.py -t templates/raspberrypi.py -o ./build -i peripherals/Bmp280.yaml` 42 | 43 | This would produce a `Bmp280.py` file. 44 | 45 | On their platform, which in this case is a Raspberry Pi, they can easily instantiate and read a value: 46 | 47 | ``` 48 | from Bmp280 import Bmp280 49 | bmp280 = Bmp280() 50 | print(Bmp280.temperature_ascelsius()) 51 | ``` -------------------------------------------------------------------------------- /docs/content/docs/Principle Philosophies/get-started.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: "Getting Started" 3 | linkTitle: "Getting Started" 4 | weight: 1 5 | description: > 6 | Onboard onto using the project. 7 | --- 8 | 9 | The Cyanobyte Codegen and Verification tools are available to download 10 | via Pip (Python 3.7+). 11 | 12 | ``` 13 | pip install cyanobyte 14 | ``` 15 | 16 | You can run `cyanobyte-codegen --version` to verify your version. 17 | 18 | ## Generate a simple Markdown file 19 | 20 | To get started, create a peripheral.yaml file. You can copy and paste 21 | this one. Save it as `example.yaml` in your working directory. 22 | 23 | ``` 24 | cyanobyte: 0.1.0 25 | info: 26 | contact: 27 | name: Nick Felker 28 | url: https://github.com/google/cyanobyte 29 | email: felker@google.com 30 | package: com.cyanobyte 31 | title: Example 32 | description: Example of a package 33 | copyright: 34 | name: Google Inc. 35 | date: '2019' 36 | license: 37 | name: Apache-2.0 38 | version: 0.1.0 39 | 40 | i2c: 41 | addressType: 7-bit 42 | address: 43 | - 0x10 44 | - 0x20 45 | - 0x30 46 | addressMask: 0xFF 47 | 48 | registers: 49 | RegisterA: 50 | address: 0x00 51 | length: 8 52 | title: First example 53 | description: An 8-bit register 54 | RegisterB: 55 | address: 0x01 56 | length: 16 57 | title: Second example 58 | description: A 16-bit register 59 | RegisterC: 60 | address: 0x02 61 | length: 32 62 | title: Third example 63 | description: A 32-bit register 64 | RegisterD: 65 | address: 0x03 66 | length: 0 67 | title: Fourth example 68 | description: A dummy register that has no data 69 | ``` 70 | 71 | Now, run the codegen tool: 72 | 73 | ``` 74 | cyanobyte-codegen -t doc -c example.yaml 75 | ``` 76 | 77 | In this command, we are generating an output for the file `example.yaml`. With `-t doc`, we are using a built-in Jinja2 template to generate a Markdown output. Alternatively, you can provide a filepath to your own template. The `-c` flag means that we will clean out our build directory before running. 78 | 79 | Once this command runs, you should see the output in the new `build` directory, under the filename `example.md`. Open it. You should see the content of the YAML file now organized in a Markdown format. 80 | 81 | Try out other templates provided by the codegen tool, such as `micropython` or `arduino`. Also, play around with modifying the YAML file and seeing how that affects the output. The documentation provides further, more advanced topics. 82 | -------------------------------------------------------------------------------- /docs/content/docs/Principle Philosophies/philosophy.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: "Philosophy and Goals" 3 | linkTitle: "Philosophy and Goals" 4 | weight: 5 5 | description: > 6 | Philosophy and goals? 7 | --- 8 | 9 | # Philosophy and goals of CyanoByte 10 | 11 | CyanoByte is a project whose goal is to create a standardized specification for representing 12 | hardware peripheral characteristics and functions in a static configuration. This could be 13 | likened to a machine-readable representation of a datasheet. 14 | 15 | Like a datasheet, this intermediate representation (IR) should not just contain a table of registers 16 | and values, but also functionality. This includes a series of steps that represent common 17 | actions like initializing, closing, and other common use-cases. Temperature sensors, for example, 18 | may need to be converted from a raw value to Celsius. This step should be represented in the 19 | IR. 20 | 21 | Everything should be defined so that the client can use this IR as a fully-functioning library. 22 | Anything that a well-developed client library would do, should be automatically generated. Any 23 | device-specific logic should be represented in the IR. 24 | 25 | Platform-specific logic, such as the code to perform hardware connectivity, should be defined in 26 | a platform template (PT) in a flexible way. The IR should be processed and laid into the PT. 27 | 28 | A core goal is minimizing the integration time of hardware peripherals into a specific hardware 29 | platform. As such, one needs to go beyond a simple set of registers and handle flows. Further 30 | efforts to minimize integration time through a static configuration would also be useful to 31 | explore through the development of this project. 32 | 33 | At the moment, the project will only cover I2C. Many I2C devices use SMBus as a common format to 34 | communicate and have straightforward data representation. 35 | 36 | Throughout this exercise, common principles should be extracted to guide future decision 37 | making the project. 38 | 39 | ## Goals 40 | - The spec should be representative of how things are currently done, even if it is less "proper" or correct. 41 | - The spec should provide everything needed to generate and publish a client library, with one-line import and one-line init 42 | - The spec should should contain a way to provide a series of logical steps for computation 43 | - The spec should be flexible enough to represent any hardware peripheral 44 | - The spec should be easily human-readable, so that hardware engineers do not need to learn a complex format 45 | 46 | ## Anti-goals 47 | - The spec should not have dependencies on a specific programming language or reference specific implementations 48 | - An I2C device yaml representation should not have a preference on which I2C library is used on the Raspberry Pi 49 | - The spec should not be concerned about backwards compatibility 50 | - This will change in the future, but during a prototyping phase we should not be concerned about this 51 | - The pseudo-yaml spec should not allow for flexible code functions such as importing libraries 52 | - Libraries then require a package manager, and a public host, and that's major scope creep 53 | - The pseudo-yaml spec should not be developed into a full programming language 54 | - This could result in versioning problems and template incompatibilities -------------------------------------------------------------------------------- /docs/content/docs/Principle Philosophies/roadmap.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: "Roadmap" 3 | linkTitle: "Roadmap" 4 | weight: 4 5 | description: > 6 | And other items to consider? 7 | --- 8 | 9 | See [releases](https://github.com/google/cyanobyte/releases) for a detailed list 10 | of package releases and changelogs. 11 | 12 | ## Current roadmap 13 | - Support Envirophat drivers to identify areas to improve specification 14 | - Add support for a second hardware platform (MSP430? Particle?) to identify areas to improve templates 15 | - Any other I2C changes/improvements 16 | 17 | ## Other Thoughts 18 | - I2C 19 | - How do we deal with addresses that are configurable? 20 | - How do we support sequential register reads for certain chips? 21 | - SPI 22 | - UART 23 | - How do we support the common methods for encoding data sent over UART? Do we make the specification extendable with custom extensions and plugins in the codegen? 24 | - USB 25 | - Do we want to even attempt this? -------------------------------------------------------------------------------- /docs/content/docs/Reference/Draft Specs/_index.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: "Draft Specifications" 3 | linkTitle: "Draft Specifications" 4 | weight: 1 5 | description: > 6 | What is in draft? 7 | --- 8 | 9 | Visit the [Cyanobyte Pull Requests](https://github.com/google/cyanobyte/pulls) to see all of the 10 | pull requests for the repository. 11 | 12 | This directory will host any active Cyanobyte specs, along with [a GitHub issue](https://github.com/google/cyanobyte/issues/) 13 | which can be used for discussion. 14 | 15 | -------------------------------------------------------------------------------- /docs/content/docs/Reference/Peripheral Docs/_index.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: "Auto-generated reference docs" 3 | linkTitle: "Auto-generated reference docs" 4 | weight: 1 5 | description: > 6 | Hosted peripherals 7 | --- 8 | -------------------------------------------------------------------------------- /docs/content/docs/Reference/_index.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: "Reference" 3 | linkTitle: "Reference" 4 | weight: 3 5 | description: > 6 | And other items to consider? 7 | --- -------------------------------------------------------------------------------- /docs/content/docs/Reference/emboss.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: "Custom serialization" 3 | linkTitle: "Custom Serialization" 4 | weight: 5 5 | description: > 6 | This describes how to use Emboss for defining richer serialization 7 | techniques and integrate with communication protocols like SPI. 8 | --- 9 | 10 | 11 | # Support Importing Emboss Files for Serialization/Deserialization Functions 12 | This project is an example of how to import emboss files(emb file), convert the file into essential yaml file and generate cpp code with modified template. 13 | 14 | Note: This feature requires Python3.5+. 15 | 16 | ## Emboss 17 | [Emboss](https://github.com/google/emboss) is a tool for generating code that reads and writes binary data structures. It is designed to help write code that communicates with hardware devices such as GPS receivers, LIDAR scanners, or actuators. 18 | 19 | ## Setup 20 | Note: This project requires Python3 and a modified input yaml file 21 | 1. Put the emboss file under the same directory of input yaml file 22 | 2. Edit import line in the yaml file to the name of emboss file 23 | **Example:** 24 | If float.emb is imported for serialization/deserialization functions, we 25 | need to edit line 33 in the [example.py](peripherals/examplespi-emobss.yaml)file: 26 | 27 | ```yaml 28 | imports: 29 | float: float.emb 30 | ``` 31 | 32 | 3. Set up emboss environment `git clone https://github.com/google/emboss.git` 33 | 4. Run `python3 cyanobyte/codegen.py`. 34 | 35 | ## Options 36 | * `-t` - A template file. You can provide multiple template files. 37 | * `-o` - The output directory where files will be generated. 38 | * `-e` - The directory that emboss folder is stored. 39 | * `-d` - Debug flag to print out additional information. 40 | * `-c` - Clean the output directory before generating files. 41 | -------------------------------------------------------------------------------- /docs/content/docs/Reference/pseudoyaml.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: "Pseduo-YAML" 3 | linkTitle: "Pseduo-YAML" 4 | weight: 2 5 | description: > 6 | Logic defined in YAML 7 | --- 8 | 9 | Pseduo-YAML is a set of operations that are defined in a Cyanobyte specification. 10 | It is not entirely a programming language, but lets one define what is effectively 11 | pseduocode in a YAML format. In writing these operations you define essentially 12 | an abstract syntax tree that can be parsed into specific programming languages 13 | for a particular device platform. 14 | 15 | The features available in Pseduo-YAML are meant to be broadly available across 16 | languages, and should work in ways that respect a variety of platform features 17 | like threads and callbacks. 18 | 19 | The available operations and parameters are defined in [JSON schema](https://github.com/google/cyanobyte/blob/master/spec/cyanobyte.schema.json). 20 | 21 | ## Commands 22 | 23 | All commands are prefixed by a dollar sign rather than a variable name. 24 | 25 | ### Write Operation 26 | 27 | This will write a specific value or variable to a specified register. 28 | 29 | ```yaml 30 | - $cmdWrite: 31 | register: '#/registers/myRegisterName' 32 | value: variableName 33 | ``` 34 | 35 | ## Operations 36 | 37 | ### Common Arithmetic 38 | 39 | These common arithmetic operations can accept variables, numbers, or 40 | nested operations of any size. 41 | 42 | * sum 43 | * difference 44 | * product 45 | * division 46 | 47 | ```yaml 48 | - variableName: 49 | - sum: 50 | - previousVariable 51 | - product: 52 | - otherVariable 53 | - 5 54 | 55 | ``` 56 | 57 | ### Advanced Arithemtic 58 | 59 | These more advanced arithmetic operations accept **2** elements, which may 60 | be variables, numbers, or nested operations. 61 | 62 | * power 63 | * modulus 64 | 65 | ```yaml 66 | - variableName: 67 | - power: 68 | - previousVariable 69 | - sum: 70 | - otherVariable 71 | - 5 72 | ``` 73 | 74 | ## Bitwise Operations 75 | 76 | These bitwise operations can accept variables, numbers, or 77 | nested operations of any size. 78 | 79 | * bitwiseOr 80 | * bitwiseAnd 81 | 82 | ```yaml 83 | - variableName: 84 | - bitwiseOr: 85 | - previousVariable 86 | - bitwiseAnd: 87 | - otherVariable 88 | - 0b11 89 | ``` 90 | 91 | ### Bit Shifting 92 | 93 | These bit shift operations require two properties. The `var` field requires 94 | a variable name. The `bits` field requires an integer number of bits to shift. 95 | 96 | * bitShiftLeft 97 | * bitShiftRight 98 | 99 | ```yaml 100 | - variableName: 101 | - bitShiftLeft: 102 | var: variableName 103 | bits: 2 104 | ``` 105 | 106 | ## Trigonometry 107 | 108 | These operations only accept the string variable name or number for which 109 | the operations should be computed. These are computed in _radians_. 110 | 111 | * arc tangent 112 | 113 | ```yaml 114 | - variableName: 115 | - arc tanget: previousVariable 116 | ``` 117 | 118 | ## I/O Operations 119 | 120 | ### Raw Read 121 | 122 | This operation will directly read a number of bits from the device bus. 123 | 124 | ```yaml 125 | - variableName: 126 | rawRead: 16 127 | ``` 128 | 129 | ## Flow 130 | 131 | ### Delays 132 | 133 | Delays can be defined in terms of milliseconds. A delay should accept 134 | a time, a name for the delay, and an array of logical operations to happen 135 | after the delay. 136 | 137 | The name of the delay will be used in some language templates which require 138 | a callback name as the platform doesn't block. 139 | 140 | Note: A delay must be the last operation in a list of logical operations. Some 141 | language templates do not know how to handle more than one delay. 142 | -------------------------------------------------------------------------------- /docs/content/docs/Reference/quirks.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: "Strange chip quirks" 3 | linkTitle: "Strange chip quirks" 4 | weight: 4 5 | description: > 6 | This is a directory of strange peripheral chip quarks that were unexpected or unintuative. 7 | --- 8 | 9 | ## BMP280 10 | 11 | * Multiple register values can have the same logical interpretation. For the register settings osrs_t[2:0] the following values all mean that the setting is oversampling x16: 0b101, 0b110, and 0b111. This means that they can't be represented as a typical enum in the generated code. It should likely always write one of the values and read all values with the correct interpretation. 12 | * There is an I2C command to enable the SPI interface. -------------------------------------------------------------------------------- /docs/content/docs/Reference/templates.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: "Templates" 3 | linkTitle: "Templates" 4 | weight: 2 5 | description: > 6 | Cyanobyte template files 7 | --- 8 | 9 | A "Cyanobyte template file" is a file that provides an abstract definition of how a Cyanobyte 10 | specification file may be rendered for your language and platform of choice. This file may be provided 11 | off-the-shelf by the platform developer, obtained through an open-source project, or developed in-house. 12 | 13 | For the scope of this project, templates are designed using Jinja2. The specification file is inflated 14 | into the template and the output file should be a fully code executable file. 15 | 16 | This project provides sample templates to show you how to get started with your own. 17 | 18 | * `templates/raspberrypi.py` - For a Raspberry Pi 19 | * `templates/doc.md` - For generating reference documentation -------------------------------------------------------------------------------- /docs/content/docs/Reference/unanswered.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: "Unanswered questions" 3 | linkTitle: "Unanswered questions" 4 | weight: 4 5 | description: > 6 | Open areas of discussion 7 | --- 8 | 9 | * Some peripherals have default values they are set to on reset. Should we include that information in the specification? How? 10 | -------------------------------------------------------------------------------- /docs/content/docs/Toolchain/_index.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: "Toolchain" 3 | linkTitle: "Toolchain" 4 | weight: 2 5 | description: > 6 | How do I get involved? 7 | --- -------------------------------------------------------------------------------- /docs/content/docs/Toolchain/codegen.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: "Codegen" 3 | linkTitle: "Codegen" 4 | weight: 2 5 | description: > 6 | How to generate code from an IR and template 7 | --- 8 | 9 | See [releases](https://github.com/google/cyanobyte/releases) for a detailed list 10 | of package releases and changelogs. 11 | 12 | Here's an example from the project source code: 13 | 14 | `python3 src/codegen.py -t templates/doc.md -o ./build peripherals/Mcp4725.yaml` 15 | 16 | - t - A template file. You can provide multiple template files. 17 | - o - The output directory where files will be generated. 18 | - d - Debug flag to print out additional information 19 | - e - The directory that emboss folder is stored. 20 | - c - Clean the output directory before generating files. 21 | 22 | Usage: codegen.py [OPTIONS] [INPUT_FILES]... 23 | 24 | Takes command line arguments and generates source files for every 25 | peripheral to each template file. 26 | 27 | Args: 28 | template_files: A list of files that are part of the template. 29 | output_dir: The directory to output the generated files. 30 | debug: Print debug messages? 31 | emboss - The directory that emboss folder is stored. 32 | clean: Clean the output directory before output? 33 | input_files: A list of CyanoByte documents to generate. 34 | 35 | Options: 36 | -t, --template TEXT 37 | -o, --output TEXT [default: ./build] 38 | -d, --debug TEXT 39 | -e --emboss TEXT [default: ../emboss] 40 | -c, --clean 41 | --help Show this message and exit. 42 | -------------------------------------------------------------------------------- /docs/content/docs/Toolchain/validator.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: "Validator" 3 | linkTitle: "Validator" 4 | weight: 2 5 | description: > 6 | Validates a Cyanobyte file is correct 7 | --- 8 | 9 | Here's an example from the project source: 10 | 11 | `python3 src/validator.py peripherals/MCP9808.yaml` 12 | 13 | Usage: validator.py [OPTIONS] [INPUT_FILES]... 14 | 15 | Main command line entrypoint 16 | 17 | Args: input_files: A list of CyanoByte documents to validate. 18 | 19 | Options: 20 | --help Show this message and exit. -------------------------------------------------------------------------------- /docs/content/docs/_index.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: "Documentation" 3 | linkTitle: "Documentation" 4 | weight: 20 5 | menu: 6 | main: 7 | weight: 20 8 | --- 9 | 10 | CyanoByte is a YAML based specification for formally defining embedded communications. 11 | It allows for both documentation and code to be generated from the CyanoByte files. 12 | The specification was greatly inspired by the successes of OpenAPI. -------------------------------------------------------------------------------- /docs/content/featured-background.jpg: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/google/cyanobyte/5a6e90440e386dd478084a6c0946fdb88eb8c5a8/docs/content/featured-background.jpg -------------------------------------------------------------------------------- /docs/content/search.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: Search Results 3 | layout: search 4 | 5 | --- -------------------------------------------------------------------------------- /docs/firebase.json: -------------------------------------------------------------------------------- 1 | { 2 | "hosting": { 3 | "public": "public", 4 | "ignore": [ 5 | "firebase.json", 6 | "**/.*", 7 | "**/node_modules/**" 8 | ] 9 | } 10 | } -------------------------------------------------------------------------------- /emboss.md: -------------------------------------------------------------------------------- 1 | # Support Importing Emboss Files for Serialization/Deserialization Functions 2 | This project is an example of how to import emboss files(emb file), convert the file into essential yaml file and generate cpp code with modified template. 3 | 4 | Note: This feature requires Python3.5+. 5 | 6 | ## Emboss 7 | [Emboss](https://github.com/google/emboss) is a tool for generating code that reads and writes binary data structures. It is designed to help write code that communicates with hardware devices such as GPS receivers, LIDAR scanners, or actuators. 8 | 9 | ## Setup 10 | Note: This project requires Python3 and a modified input yaml file 11 | 1. Put the emboss file under the same directory of input yaml file 12 | 2. Edit import line in the yaml file to the name of emboss file 13 | **Example:** 14 | If float.emb is imported for serialization/deserialization functions, we need to edit line 33 in the [example.py](peripherals-yaml/example.yaml) file: 15 | ```yaml 16 | imports: 17 | float: float.emb 18 | ``` 19 | 3. Set up emboss environment `git clone https://github.com/google/emboss.git` 20 | 4. Run `python3 cyanobyte/codegen.py`. 21 | 22 | ## Options 23 | * `-t` - A template file. You can provide multiple template files. 24 | * `-o` - The output directory where files will be generated. 25 | * `-e` - The directory that emboss folder is stored. 26 | * `-d` - Debug flag to print out additional information. 27 | * `-c` - Clean the output directory before generating files. 28 | -------------------------------------------------------------------------------- /peripherals/MCP4725.yaml: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2019 Google Inc. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | cyanobyte: 0.1.0 15 | info: 16 | contact: 17 | name: Nick Felker 18 | url: https://github.com/google/cyanobyte 19 | email: felker@google.com 20 | package: com.cyanobyte 21 | title: MCP4725 22 | description: Microchip Digital-to-Analog Converter 23 | copyright: 24 | name: Google Inc. 25 | date: '2019' 26 | license: 27 | name: Apache-2.0 28 | version: 0.1.0 29 | 30 | i2c: 31 | addressType: 7-bit 32 | address: 0x62 33 | addressMask: 0x60 34 | endian: little 35 | 36 | registers: 37 | VOut: 38 | address: 0x40 39 | length: 12 40 | title: Output voltage 41 | description: | 42 | Sets the output voltage relative to Vcc. 43 | VOut = (Vcc * value) / 4096. 44 | The output is a range between 0 and Vcc with 45 | steps of Vcc/4096. 46 | In a 3.3v system, each step is 800 microvolts. 47 | EEPROM: 48 | address: 0x60 49 | length: 12 50 | title: EEPROM 51 | description: | 52 | If EEPROM is set, the saved voltage output will 53 | be loaded from power-on. 54 | 55 | fields: 56 | digitalOut: 57 | title: Digital (binary) output 58 | description: | 59 | Set output as either fully on or fully off. 60 | register: '#/registers/EEPROM' 61 | readWrite: 'R/W' 62 | bitStart: 12 63 | bitEnd: 0 64 | type: 'enum' 65 | enum: 66 | VCC: 67 | title: Vcc (full power) 68 | value: 0b111111111111 69 | GND: 70 | title: Ground 71 | value: 0b000000000000 72 | functions: 73 | setVOut: 74 | title: Set output voltage 75 | description: Set VOut as a function of Vcc. 76 | type: number 77 | register: '#/registers/EEPROM' 78 | bitStart: 12 79 | bitEnd: 0 80 | computed: 81 | asVoltage: 82 | input: 83 | vcc: float32 84 | output: float32 85 | logic: 86 | - output: = output / vcc * 4096 87 | - send: output 88 | getVOut: 89 | title: Read output voltage 90 | description: Read VOut from EEPROM as a function of Vcc. 91 | type: number 92 | register: '#/registers/EEPROM' 93 | bitStart: 12 94 | bitEnd: 0 95 | computed: 96 | asVoltage: 97 | input: 98 | vcc: float32 99 | value: float32 # automatically pulls value 100 | variables: 101 | voltage: float32 102 | logic: 103 | - voltage: = value / 4096 * vcc 104 | return: voltage 105 | -------------------------------------------------------------------------------- /peripherals/MCP9808.yaml: -------------------------------------------------------------------------------- 1 | cyanobyte: 0.1.0 2 | info: 3 | title: MCP9808 4 | description: Microchip Temperature Sensor 5 | package: com.cyanobyte 6 | contact: 7 | name: Nick Felker 8 | url: https://github.com/google/cyanobyte 9 | email: felker@google.com 10 | copyright: 11 | name: Google Inc. 12 | date: '2019' 13 | license: 14 | name: Apache-2.0 15 | version: 0.1.0 16 | i2c: 17 | addressType: '7-bit' 18 | address: 19 | - 0x18 20 | - 0x19 21 | - 0x1A 22 | - 0x1B 23 | - 0x1C 24 | - 0x1D 25 | - 0x1E 26 | - 0x1F 27 | addressMask: 0x78 28 | 29 | registers: 30 | configuration: 31 | address: 0x01 32 | length: 16 33 | title: Configuration Register 34 | description: | 35 | The MCP9808 has a 16-bit Configuration register (CONFIG) that 36 | allows the user to set various functions for a robust temperature 37 | monitoring system. 38 | Bits 10 through 0 are used to select the temperature alert output 39 | hysteresis, device shutdown or Low-Power mode, temperature boundary 40 | and critical temperature lock, and temperature Alert output 41 | enable/disable. 42 | In addition, Alert output condition (output set for TUPPER and 43 | TLOWER temperature boundary or TCRIT only), Alert output status 44 | and Alert output polarity and mode (Comparator Output or Interrupt 45 | Output mode) are user-configurable. 46 | 47 | fields: 48 | limitHysteresis: 49 | title: TUPPER and TLOWER Limit Hysteresis bits 50 | description: | 51 | This bit can not be altered when either of the Lock bits are set 52 | (bit 6 and bit 7). This bit can be programmed in Shutdown mode. 53 | register: '#/registers/configuration' 54 | readWrite: 'R' 55 | bitStart: 10 56 | bitEnd: 9 57 | type: 'enum' 58 | enum: 59 | Temp_0C: 60 | title: 0°C (power-up default) 61 | value: 0b00 62 | Temp_1C5: 63 | title: +1.5°C 64 | value: 0b01 65 | Temp_3C: 66 | title: +3.0°C 67 | value: 0b10 68 | Temp_6C: 69 | title: +6.0°C 70 | value: 0b11 71 | shutdownMode: 72 | title: Shutdown Mode bit 73 | description: | 74 | In shutdown, all power-consuming activities are disabled, though 75 | all registers can be written to or read. This bit cannot be set 76 | to ‘1’ when either of the Lock bits is set (bit 6 and bit 7). 77 | However, it can be cleared to ‘0’ for continuous conversion while 78 | locked. 79 | register: '#/registers/configuration' 80 | readWrite: 'R' 81 | bitStart: 8 82 | bitEnd: 8 83 | type: 'enum' 84 | enum: 85 | continousConversion: 86 | title: Continuous conversion (power-up default) 87 | value: 0 88 | shutdown: 89 | title: Shutdown (Low-Power mode) 90 | value: 1 -------------------------------------------------------------------------------- /peripherals/TCS3472.yaml: -------------------------------------------------------------------------------- 1 | cyanobyte: 0.1.0 2 | info: 3 | title: TCS3472 4 | description: Color Light-to-Digital Converter with IR Filter 5 | package: com.cyanobyte 6 | contact: 7 | name: Nick Felker 8 | url: https://ams.com/documents/20143/36005/TCS3472_DS000390_2-00.pdf 9 | email: felker@google.com 10 | copyright: 11 | name: Google Inc. 12 | date: '2019' 13 | license: 14 | name: Apache-2.0 15 | version: 0.1.0 16 | 17 | i2c: 18 | addressType: 7-bit 19 | address: 0x29 20 | addressMask: 0xFF 21 | 22 | registers: 23 | # TCS3472 has a Command Register that all commands need to go through: 24 | # 25 | # | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 | 26 | # | 1 | Incre | Address Field | 27 | # 28 | # Hence, the Clear register actually needs to be addressed as: 29 | # 30 | # 0b1000,0000 OR 0b0010,0000 OR 0x14 = 180 = 0xB0 31 | Enable: 32 | address: 0x80 33 | length: 8 34 | title: Enable 35 | description: Enable specific components of the peripheral 36 | Clear: 37 | address: 0xB4 38 | length: 16 39 | readWrite: 'R' 40 | title: Clear channel 41 | description: This is the ambient amount of detected light. 42 | Red: 43 | address: 0xB6 44 | length: 16 45 | readWrite: 'R' 46 | title: Red channel 47 | description: Red light as an int. Divide by ambient light to get scaled number. 48 | # Implementation note: float(light.get_red()) / light.get_clear() * 255 -> Red color value 49 | Green: 50 | address: 0xB8 51 | length: 16 52 | readWrite: 'R' 53 | title: Green channel 54 | description: Green light as an int. Divide by ambient light to get scaled number. 55 | Blue: 56 | address: 0xBA 57 | length: 16 58 | readWrite: 'R' 59 | title: Blue channel 60 | description: Blue light as an int. Divide by ambient light to get scaled number. 61 | 62 | fields: 63 | init: 64 | title: Setup the device configuration 65 | description: Enable RGBC and Power. 66 | register: '#/registers/Enable' 67 | readWrite: 'R/W' 68 | bitStart: 7 # The whole register 69 | bitEnd: 0 70 | type: 'enum' 71 | enum: 72 | Power: 73 | title: Power 74 | value: 1 75 | RGBC: 76 | title: Color 77 | value: 0b10 78 | 79 | functions: 80 | _lifecycle: 81 | title: Code to run when device class is constructed 82 | description: Enables features on device. 83 | register: '#/registers/Enable' 84 | computed: 85 | Begin: 86 | variables: 87 | enables: int8 88 | logic: 89 | # Enable register = ENABLE_RGBC | ENABLE_POWER 90 | - enables: 91 | - sum: 92 | - 1 93 | - 0b10 94 | - send: enables 95 | -------------------------------------------------------------------------------- /peripherals/bits.emb: -------------------------------------------------------------------------------- 1 | # Copyright 2019 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # https://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | -- Test `.emb` for the `bits` construct. 16 | 17 | [$default byte_order: "LittleEndian"] 18 | [(cpp) namespace: "emboss::test"] 19 | 20 | 21 | bits OneByte: 22 | 7 [+1] Flag high_bit 23 | 6 [+1] Flag less_high_bit 24 | 2 [+4] UInt mid_nibble 25 | 1 [+1] Flag less_low_bit 26 | 0 [+1] Flag low_bit 27 | 28 | 29 | bits FourByte: 30 | bits TwoByteWithGaps: 31 | 15 [+1] Flag high_bit 32 | 6 [+4] UInt mid_nibble 33 | 0 [+1] Flag low_bit 34 | 35 | 28 [+4] UInt high_nibble 36 | 20 [+8] OneByte one_byte 37 | 4 [+16] TwoByteWithGaps two_byte 38 | 0 [+4] UInt raw_low_nibble 39 | # Check that the [requires] attribute works on bits fields just like it does 40 | # on struct fields. 41 | [requires: 1 <= this <= 15] 42 | let low_nibble = raw_low_nibble + 100 43 | 44 | 45 | bits ArrayInBits: 46 | 15 [+1] Flag lone_flag 47 | 0 [+12] Flag[] flags 48 | 49 | 50 | struct ArrayInBitsInStruct: 51 | 0 [+2] ArrayInBits array_in_bits 52 | 53 | 54 | struct StructOfBits: 55 | 0 [+1] OneByte one_byte 56 | 1 [+2] FourByte.TwoByteWithGaps two_byte 57 | 3 [+4] FourByte four_byte 58 | one_byte.mid_nibble [+1] UInt located_byte 59 | 60 | 61 | struct BitArray: 62 | 0 [+8] OneByte[8] one_byte 63 | -------------------------------------------------------------------------------- /peripherals/enum.emb: -------------------------------------------------------------------------------- 1 | # Copyright 2019 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # https://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | [$default byte_order: "LittleEndian"] 16 | [(cpp) namespace: "emboss::test"] 17 | 18 | struct Constants: 19 | let sprocket = 1 20 | let geegaw = 2 21 | 22 | enum Kind: 23 | WIDGET = 0 24 | SPROCKET = Constants.sprocket 25 | GEEGAW = Constants.geegaw 26 | COMPUTED = Constants.geegaw+Constants.sprocket 27 | LARGE_VALUE = 2000 28 | DUPLICATE_LARGE_VALUE = LARGE_VALUE 29 | MAX32BIT = 4294967295 30 | MAX64BIT = 0x1_0000_0000_0000_0000-1 31 | 32 | 33 | enum Signed: 34 | MIN64BIT = -0x8000_0000_0000_0000 35 | MAX64BIT = 0x8000_0000_0000_0000-1 36 | 37 | 38 | struct ManifestEntry: 39 | 0 [+1] Kind kind 40 | 1 [+4] UInt count 41 | 5 [+4] Kind wide_kind 42 | 9 [+5] bits: 43 | 4 [+32] Kind wide_kind_in_bits 44 | 45 | struct StructContainingEnum: 46 | enum Status: 47 | OK = 0x00 48 | FAILURE = 0x01 49 | 0 [+1] UInt bar 50 | -------------------------------------------------------------------------------- /peripherals/examplespi-emboss.yaml: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2020 Google Inc. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # Datasheet: http://www.ti.com/lit/ds/symlink/ads1015.pdf 15 | cyanobyte: 0.1.0 16 | info: 17 | contact: 18 | name: Nick Felker 19 | url: https://github.com/google/cyanobyte 20 | email: felker@google.com 21 | package: com.cyanobyte 22 | title: ExampleSpiEmboss 23 | description: Example of a package using SPI with Emboss messages 24 | copyright: 25 | name: Google Inc. 26 | date: '2019' 27 | license: 28 | name: Apache-2.0 29 | version: 0.1.0 30 | 31 | spi: 32 | clockPolarity: high 33 | clockPhase: leading 34 | frequency: 16000 # 16KHz 35 | word: 8 # bits 36 | address: 0x00 37 | format: emboss 38 | 39 | imports: 40 | float: ../peripherals-yaml/float.emb # We'd need to have a `float.emb` file in the same directory 41 | 42 | # We currently need an I2C block for rendering support 43 | # See #212 44 | i2c: 45 | addressType: 7-bit 46 | address: 0x00 47 | addressMask: 0xFF 48 | 49 | # We currently need a registers block for rendering support 50 | # See #212 51 | registers: 52 | placeholder: 53 | address: 0x00 54 | length: 8 55 | title: First example 56 | description: An 8-bit register -------------------------------------------------------------------------------- /peripherals/examplespi-register.yaml: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2020 Google Inc. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # Datasheet: http://www.ti.com/lit/ds/symlink/ads1015.pdf 15 | cyanobyte: 0.1.0 16 | info: 17 | contact: 18 | name: Nick Felker 19 | url: https://github.com/google/cyanobyte 20 | email: felker@google.com 21 | package: com.cyanobyte 22 | title: ExampleSpiRegister 23 | description: Example of a package using SPI with registers 24 | copyright: 25 | name: Google Inc. 26 | date: '2019' 27 | license: 28 | name: Apache-2.0 29 | version: 0.1.0 30 | 31 | spi: 32 | clockPolarity: high 33 | clockPhase: leading 34 | frequency: 16000 # 16KHz 35 | word: 8 # bits 36 | address: 0x00 37 | format: register 38 | 39 | # We currently need an I2C block for rendering support 40 | # See #212 41 | i2c: 42 | addressType: 7-bit 43 | address: 0x00 44 | addressMask: 0xFF 45 | 46 | registers: 47 | RegisterW: 48 | address: 0x00 49 | length: 8 50 | title: First example 51 | description: An 8-bit register 52 | RegisterX: 53 | address: 0x01 54 | length: 16 55 | title: Second example 56 | description: A 16-bit register 57 | RegisterY: 58 | address: 0x02 59 | length: 32 60 | title: Third example 61 | description: A 32-bit register 62 | RegisterZ: 63 | address: 0x03 64 | length: 0 65 | title: Fourth example 66 | description: A dummy register that has no data 67 | -------------------------------------------------------------------------------- /peripherals/float.emb: -------------------------------------------------------------------------------- 1 | # Copyright 2019 Google LLC 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # https://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | 15 | -- Test struct for IEEE floats. 16 | 17 | [(cpp) namespace: "emboss::test"] 18 | 19 | 20 | struct Floats: 21 | 0 [+4] Float float_little_endian 22 | [byte_order: "LittleEndian"] 23 | 24 | 4 [+4] Float float_big_endian 25 | [byte_order: "BigEndian"] 26 | 27 | 28 | struct Doubles: 29 | 0 [+8] Float double_little_endian 30 | [byte_order: "LittleEndian"] 31 | 32 | 8 [+8] Float double_big_endian 33 | [byte_order: "BigEndian"] 34 | -------------------------------------------------------------------------------- /requirements-dev.txt: -------------------------------------------------------------------------------- 1 | cmsis-svd 2 | smbus 3 | spidev 4 | adafruit-circuitpython-busdevice 5 | -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | click 2 | pylint 3 | pyyaml 4 | Jinja2 5 | jsonschema 6 | importlib_metadata 7 | importlib_resources 8 | pathlib2 -------------------------------------------------------------------------------- /setup.py: -------------------------------------------------------------------------------- 1 | import setuptools 2 | from cyanobyte import __version__ 3 | 4 | """ 5 | Run bundler: 6 | $ python3 setup.py sdist 7 | Install via Pip: 8 | $ pip3 install dist/cyanobyte-.tar.gz 9 | Upload via twine: 10 | $ twine check dist/* 11 | $ twine upload dist/* 12 | """ 13 | 14 | with open("README.md", "r") as fh: 15 | long_description = fh.read() 16 | 17 | with open("requirements.txt", "r") as fh: 18 | install_requires = [line.rstrip() for line in fh] 19 | 20 | setuptools.setup( 21 | name="cyanobyte", 22 | version=__version__, 23 | author="Google Inc.", 24 | author_email="fleker+cyanobyte@google.com", 25 | description="A package that generates library files for a peripheral given an intermediary layer (YAML files)", 26 | long_description=long_description, 27 | long_description_content_type="text/markdown", 28 | url="https://github.com/google/cyanobyte", 29 | packages=setuptools.find_packages(exclude=("test",)), 30 | classifiers=[ 31 | "Programming Language :: Python :: 3", 32 | "License :: OSI Approved :: Apache Software License", 33 | "Operating System :: OS Independent", 34 | ], 35 | python_requires=">=3.7", 36 | install_requires=install_requires, 37 | entry_points={ 38 | "console_scripts": [ 39 | "cyanobyte-codegen=cyanobyte.codegen:gen", 40 | "cyanobyte-validator=cyanobyte.validator:click_validate" 41 | ], 42 | }, 43 | setup_requires=['setuptools_scm'], 44 | include_package_data = True, 45 | ) 46 | -------------------------------------------------------------------------------- /spec/__init__.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # Copyright (C) 2021 Google Inc. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. 15 | -------------------------------------------------------------------------------- /test/__init__.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # Copyright (C) 2019 Google Inc. 3 | # 4 | # Licensed under the Apache License, Version 2.0 (the "License"); 5 | # you may not use this file except in compliance with the License. 6 | # You may obtain a copy of the License at 7 | # 8 | # http://www.apache.org/licenses/LICENSE-2.0 9 | # 10 | # Unless required by applicable law or agreed to in writing, software 11 | # distributed under the License is distributed on an "AS IS" BASIS, 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | # See the License for the specific language governing permissions and 14 | # limitations under the License. -------------------------------------------------------------------------------- /test/sampleData/arduino/ADS1015.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2019 Google Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | * Auto-generated file for ADS1015 v0.1.0. 17 | * Generated from peripherals/ADS1015.yaml using Cyanobyte Codegen v0.1.0 18 | * Class for ADS1015 19 | * Texas Instruments Analog-Digital Converter 20 | 21 | */ 22 | 23 | #ifndef _ADS1015_H_ 24 | #define _ADS1015_H_ 25 | #include 26 | #include 27 | 28 | /* 29 | * Valid values for Set the channel to read 30 | 31 | */ 32 | enum Channel { 33 | CHANNEL_CHANNEL_1 = 0, // Channel 1 34 | CHANNEL_CHANNEL_2 = 1, // Channel 2 35 | CHANNEL_CHANNEL_3 = 2, // Channel 3 36 | CHANNEL_CHANNEL_4 = 3 // Channel 4 37 | }; 38 | typedef enum Channel Channel_t; 39 | /* 40 | * Valid values for Set the operating mode 41 | 42 | */ 43 | enum DeviceOperatingMode { 44 | DEVICEOPERATINGMODE_CONTINUOUS_CONVERSION = 0, // Continuous Conversion 45 | DEVICEOPERATINGMODE_SINGLE_SHOT = 1 // Single-shot or power-down state 46 | }; 47 | typedef enum DeviceOperatingMode DeviceOperatingMode_t; 48 | /* 49 | * Valid values for Setup programmable gain 50 | 51 | */ 52 | enum ProgrammableGain { 53 | PROGRAMMABLEGAIN_PGA0_256 = 5, // Plus/minus 0.256V 54 | PROGRAMMABLEGAIN_PGA0_512 = 4, // Plus/minus 0.512V 55 | PROGRAMMABLEGAIN_PGA1_024V = 3, // Plus/minus 1.024V 56 | PROGRAMMABLEGAIN_PGA2_048V = 2, // Plus/minus 2.048V 57 | PROGRAMMABLEGAIN_PGA4_096V = 1, // Plus/minus 4.096V 58 | PROGRAMMABLEGAIN_PGA6_144V = 0 // Plus/minus 6.144V 59 | }; 60 | typedef enum ProgrammableGain ProgrammableGain_t; 61 | /* 62 | * Valid values for Setup sample rate for reading analog voltage 63 | 64 | */ 65 | enum SampleRate { 66 | SAMPLERATE_HZ128 = 0, // 128 samples/second 67 | SAMPLERATE_HZ1600 = 4, // 1600 samples/second 68 | SAMPLERATE_HZ2400 = 5, // 2400 samples/second 69 | SAMPLERATE_HZ250 = 1, // 250 samples/second 70 | SAMPLERATE_HZ3300 = 6, // 3300 samples/second 71 | SAMPLERATE_HZ490 = 2, // 490 samples/second 72 | SAMPLERATE_HZ920 = 3 // 920 samples/second 73 | }; 74 | typedef enum SampleRate SampleRate_t; 75 | 76 | class ADS1015 { 77 | public: 78 | ADS1015(TwoWire& wire); 79 | 80 | void begin(); 81 | void end(); 82 | /** 83 | * Describes the specifics of the sensing implementation 84 | 85 | */ 86 | uint16_t readConfig(); 87 | 88 | /** 89 | * Describes the specifics of the sensing implementation 90 | 91 | */ 92 | int writeConfig(uint16_t data); 93 | /** 94 | * Conversion register contains the result of the last conversion 95 | 96 | */ 97 | uint16_t readConversion(); 98 | 99 | 100 | /** 101 | * This bit controls the operating mode 102 | 103 | */ 104 | int setDeviceOperatingMode(uint8_t data); 105 | /** 106 | * This sets the programmable gain for reading analog voltage 107 | 108 | */ 109 | int setProgrammableGain(uint8_t data); 110 | /** 111 | * This sets the samples-per-second value 112 | 113 | */ 114 | int setSampleRate(uint8_t data); 115 | 116 | /** 117 | * Reads the analog voltage in Volts 118 | 119 | */ 120 | short analogread(char channel); 121 | 122 | 123 | private: 124 | TwoWire* _wire; 125 | }; 126 | 127 | #endif -------------------------------------------------------------------------------- /test/sampleData/arduino/BH1750FVI.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2020 Google Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | * Auto-generated file for BH1750FVI v0.1.0. 17 | * Generated from peripherals/BH1750FVI.yaml using Cyanobyte Codegen v0.1.0 18 | * Class for BH1750FVI 19 | * Rohm Light Sensor 20 | 21 | */ 22 | 23 | #ifndef _BH1750FVI_H_ 24 | #define _BH1750FVI_H_ 25 | #include 26 | #include 27 | 28 | enum deviceAddress { 29 | I2C_ADDRESS_35 = 35, 30 | I2C_ADDRESS_92 = 92 31 | }; 32 | typedef enum deviceAddress deviceAddress_t; 33 | 34 | class BH1750FVI { 35 | public: 36 | BH1750FVI(TwoWire& wire, deviceAddress_t address); 37 | deviceAddress_t DEVICE_ADDRESS; 38 | 39 | void begin(); 40 | void end(); 41 | 42 | /** 43 | * Start measurement at 0.5lx resolution. Typically 120ms. 44 | 45 | */ 46 | int writeContinuousHRes2Mode(); 47 | 48 | /** 49 | * Start measurement at 1lx resolution. Typically 120ms. 50 | 51 | */ 52 | int writeContinuousHResMode(); 53 | 54 | /** 55 | * Start measurement at 4lx resolution. Typically 16ms. 56 | 57 | */ 58 | int writeContinuouslyLResMode(); 59 | 60 | /** 61 | * Start measurement at 0.5lx resolution. Typically 120ms. 62 | * Power Down after measurement. 63 | 64 | */ 65 | int writeOnceHRes2Mode(); 66 | 67 | /** 68 | * Start measurement at 1lx resolution. Typically 120ms. 69 | * Power Down after measurement. 70 | 71 | */ 72 | int writeOnceHResMode(); 73 | 74 | /** 75 | * Start measurement at 4lx resolution. Typically 16ms. 76 | * Power Down after measurement. 77 | 78 | */ 79 | int writeOnceLResMode(); 80 | 81 | /** 82 | * No active state 83 | 84 | */ 85 | int writePowerDown(); 86 | 87 | /** 88 | * Waiting for measurement command 89 | 90 | */ 91 | int writePowerOn(); 92 | 93 | /** 94 | * Reset data register value. Not accepted in Power Down mode. 95 | 96 | */ 97 | int writeReset(); 98 | 99 | /** 100 | * Sends a POWER ON cmd to device 101 | 102 | */ 103 | void _lifecycleBegin(); 104 | 105 | /** 106 | * Things you can do to device 107 | 108 | */ 109 | void commandPowerDown(); 110 | /** 111 | * Things you can do to device 112 | 113 | */ 114 | void commandReset(); 115 | 116 | /** 117 | * Read light intensity from device 118 | 119 | */ 120 | uint16_t readLightIntensity(); 121 | 122 | 123 | private: 124 | TwoWire* _wire; 125 | }; 126 | 127 | #endif -------------------------------------------------------------------------------- /test/sampleData/arduino/BMP180.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2020 Google Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | * Auto-generated file for BMP180 v0.1.0. 17 | * Generated from peripherals/BMP180.yaml using Cyanobyte Codegen v0.0.2 18 | * Class for BMP180 19 | * Bosch Digital Temperature / Pressure Sensor 20 | 21 | */ 22 | 23 | #ifndef _BMP180_H_ 24 | #define _BMP180_H_ 25 | #include 26 | #include 27 | #include 28 | 29 | 30 | class BMP180 { 31 | public: 32 | BMP180(TwoWire& wire); 33 | 34 | void begin(); 35 | void end(); 36 | 37 | /** 38 | * Register stores what the measurement type should be 39 | 40 | */ 41 | int writeControl(uint8_t data); 42 | /** 43 | * For calibration 44 | 45 | */ 46 | uint16_t readPressureCalAC1(); 47 | 48 | 49 | /** 50 | * For calibration 51 | 52 | */ 53 | uint16_t readPressureCalAC2(); 54 | 55 | 56 | /** 57 | * For calibration 58 | 59 | */ 60 | uint16_t readPressureCalVB1(); 61 | 62 | 63 | /** 64 | * For calibration 65 | 66 | */ 67 | uint16_t readPressureCalVB2(); 68 | 69 | 70 | /** 71 | * Register stores most recent measurement result 72 | 73 | */ 74 | uint16_t readResult(); 75 | 76 | 77 | /** 78 | * For calibration 79 | 80 | */ 81 | uint16_t readTempCal3(); 82 | 83 | 84 | /** 85 | * For calibration 86 | 87 | */ 88 | uint16_t readTempCal4(); 89 | 90 | 91 | /** 92 | * For calibration 93 | 94 | */ 95 | uint16_t readTempCal5(); 96 | 97 | 98 | /** 99 | * For calibration 100 | 101 | */ 102 | uint16_t readTempCal6(); 103 | 104 | 105 | /** 106 | * For calibration 107 | 108 | */ 109 | uint16_t readTempCalMC(); 110 | 111 | 112 | /** 113 | * For calibration 114 | 115 | */ 116 | uint16_t readTempCalMD(); 117 | 118 | 119 | 120 | /** 121 | * Reads the pressure in absolute millibars, 122 | * not compensated for sea level 123 | 124 | */ 125 | float pressureasMbars(); 126 | 127 | /** 128 | * Reads the temperature 129 | 130 | */ 131 | float temperatureasCelsius(); 132 | 133 | 134 | private: 135 | TwoWire* _wire; 136 | }; 137 | 138 | #endif -------------------------------------------------------------------------------- /test/sampleData/arduino/Example.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2019 Google Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | * Auto-generated file for Example v0.1.0. 17 | * Generated from peripherals/example.yaml using Cyanobyte Codegen v0.1.0 18 | * Class for Example 19 | * Example of a package 20 | 21 | */ 22 | 23 | #ifndef _Example_H_ 24 | #define _Example_H_ 25 | #include 26 | #include 27 | 28 | /* 29 | * Valid values for Write-only fields for RegisterA 30 | 31 | */ 32 | enum FieldB { 33 | FIELDB_VAL_1 = 1, // Value 1 34 | FIELDB_VAL_2 = 2, // Value 2 35 | FIELDB_VAL_3 = 4, // Value 3 36 | FIELDB_VAL_4 = 8 // Value 4 37 | }; 38 | typedef enum FieldB FieldB_t; 39 | enum deviceAddress { 40 | I2C_ADDRESS_16 = 16, 41 | I2C_ADDRESS_32 = 32, 42 | I2C_ADDRESS_48 = 48 43 | }; 44 | typedef enum deviceAddress deviceAddress_t; 45 | 46 | class Example { 47 | public: 48 | Example(TwoWire& wire, deviceAddress_t address); 49 | deviceAddress_t DEVICE_ADDRESS; 50 | 51 | void begin(); 52 | void end(); 53 | /** 54 | * An 8-bit register 55 | 56 | */ 57 | uint8_t readRegisterA(); 58 | 59 | /** 60 | * An 8-bit register 61 | 62 | */ 63 | int writeRegisterA(uint8_t data); 64 | /** 65 | * A 16-bit register 66 | 67 | */ 68 | uint16_t readRegisterB(); 69 | 70 | /** 71 | * A 16-bit register 72 | 73 | */ 74 | int writeRegisterB(uint16_t data); 75 | /** 76 | * A 32-bit register 77 | 78 | */ 79 | uint32_t readRegisterC(); 80 | 81 | /** 82 | * A 32-bit register 83 | 84 | */ 85 | int writeRegisterC(uint32_t data); 86 | /** 87 | * A dummy register that has no data 88 | 89 | */ 90 | uint8_t readRegisterD(); 91 | 92 | /** 93 | * A dummy register that has no data 94 | 95 | */ 96 | int writeRegisterD(); 97 | /** 98 | * This is a few bits 99 | 100 | */ 101 | uint8_t getFieldA(); 102 | /** 103 | * This is fewer bits 104 | 105 | */ 106 | int setFieldB(uint8_t data); 107 | /** 108 | * A single-bit 109 | 110 | */ 111 | uint8_t getFieldC(); 112 | /** 113 | * A single-bit 114 | 115 | */ 116 | int setFieldC(uint8_t data); 117 | 118 | /** 119 | * Enables features on device 120 | 121 | */ 122 | char _lifecycleBegin(); 123 | /** 124 | * Enables features on device 125 | 126 | */ 127 | char _lifecycleEnd(); 128 | 129 | /** 130 | * Computes and returns 131 | 132 | */ 133 | void ReturnArray(short * returnArray); 134 | /** 135 | * Computes and returns 136 | 137 | */ 138 | short ReturnNumber(); 139 | /** 140 | * Computes and returns 141 | 142 | */ 143 | void ReturnVoid(); 144 | 145 | 146 | private: 147 | TwoWire* _wire; 148 | }; 149 | 150 | #endif -------------------------------------------------------------------------------- /test/sampleData/arduino/MCP4725.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2019 Google Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | * Auto-generated file for MCP4725 v0.1.0. 17 | * Generated from peripherals/MCP4725.yaml using Cyanobyte Codegen v0.1.0 18 | * Class for MCP4725 19 | * Microchip 4725 Digital-to-Analog Converter 20 | 21 | */ 22 | 23 | #ifndef _MCP4725_H_ 24 | #define _MCP4725_H_ 25 | #include 26 | #include 27 | 28 | /* 29 | * Valid values for Digital (binary) output 30 | 31 | */ 32 | enum digitalOut { 33 | DIGITALOUT_GND = 0, // Ground 34 | DIGITALOUT_VCC = 4095 // Vcc (full power) 35 | }; 36 | typedef enum digitalOut digitalOut_t; 37 | 38 | class MCP4725 { 39 | public: 40 | MCP4725(TwoWire& wire); 41 | 42 | void begin(); 43 | void end(); 44 | /** 45 | * If EEPROM is set, the saved voltage output will 46 | * be loaded from power-on. 47 | 48 | */ 49 | uint16_t readEEPROM(); 50 | 51 | /** 52 | * If EEPROM is set, the saved voltage output will 53 | * be loaded from power-on. 54 | 55 | */ 56 | int writeEEPROM(uint16_t data); 57 | /** 58 | * VOut = (Vcc * value) / 4096 59 | * The output is a range between 0 and Vcc with 60 | * steps of Vcc/4096. 61 | * In a 3.3v system, each step is 800 microvolts. 62 | 63 | */ 64 | uint16_t readVOut(); 65 | 66 | /** 67 | * VOut = (Vcc * value) / 4096 68 | * The output is a range between 0 and Vcc with 69 | * steps of Vcc/4096. 70 | * In a 3.3v system, each step is 800 microvolts. 71 | 72 | */ 73 | int writeVOut(uint16_t data); 74 | /** 75 | * Only allows you to send fully on or off 76 | 77 | */ 78 | uint16_t getdigitalOut(); 79 | /** 80 | * Only allows you to send fully on or off 81 | 82 | */ 83 | int setdigitalOut(uint8_t data); 84 | 85 | /** 86 | * get vout 87 | 88 | */ 89 | float getVOutasVoltage(float vcc); 90 | 91 | /** 92 | * set vout 93 | 94 | */ 95 | void setVOutasVoltage(float output, float vcc); 96 | 97 | 98 | private: 99 | TwoWire* _wire; 100 | }; 101 | 102 | #endif -------------------------------------------------------------------------------- /test/sampleData/arduino/MCP9808.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2019 Google Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | * Auto-generated file for MCP9808 v0.1.0. 17 | * Generated from peripherals/MCP9808.yaml using Cyanobyte Codegen v0.1.0 18 | * Class for MCP9808 19 | * This is a test description 20 | 21 | */ 22 | 23 | 24 | 25 | 26 | #include "MCP9808.h" 27 | 28 | #define REGISTER_CONFIGURATION 1 29 | 30 | MCP9808::MCP9808(TwoWire& wire, deviceAddress_t address) : 31 | _wire(&wire), 32 | DEVICE_ADDRESS ( address ) 33 | { 34 | } 35 | 36 | void MCP9808::begin() { 37 | _wire->begin(); 38 | } 39 | 40 | void MCP9808::end() { 41 | _wire->end(); 42 | } 43 | 44 | uint16_t MCP9808::readconfiguration() { 45 | uint8_t datum; 46 | uint16_t value; 47 | _wire->beginTransmission(DEVICE_ADDRESS); 48 | _wire->write(REGISTER_CONFIGURATION); 49 | if (_wire->endTransmission(false) != 0) { 50 | return -1; 51 | } 52 | 53 | if (_wire->requestFrom(DEVICE_ADDRESS, 2) != 2) { 54 | return 0; 55 | } 56 | 57 | datum = _wire->read(); 58 | value = value << 8 | datum; 59 | datum = _wire->read(); 60 | value = value << 8 | datum; 61 | 62 | return value; 63 | } 64 | 65 | int MCP9808::writeconfiguration(uint16_t data) { 66 | _wire->beginTransmission(DEVICE_ADDRESS); 67 | // Put our data into uint8_t buffer 68 | uint8_t buffer[3] = { (uint8_t) REGISTER_CONFIGURATION }; 69 | buffer[1] = (data >> 8) & 0xFF; 70 | buffer[2] = (data >> 0) & 0xFF; 71 | _wire->write(buffer, 3); 72 | if (_wire->endTransmission() != 0) { 73 | return 0; 74 | } 75 | return 1; 76 | } 77 | 78 | 79 | uint16_t MCP9808::getlimitHysteresis() { 80 | // Read register data 81 | // '#/registers/configuration' > 'configuration' 82 | uint8_t val = readconfiguration(); 83 | // Mask register value 84 | val = val & 0b0000011000000000; 85 | // Bitshift value 86 | val = val >> 9; 87 | return val; 88 | } 89 | uint16_t MCP9808::getshutdownMode() { 90 | // Read register data 91 | // '#/registers/configuration' > 'configuration' 92 | uint8_t val = readconfiguration(); 93 | // Mask register value 94 | val = val & 0b0000000100000000; 95 | // Bitshift value 96 | val = val >> 8; 97 | return val; 98 | } 99 | 100 | -------------------------------------------------------------------------------- /test/sampleData/arduino/TCS3472.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2019 Google Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | * Auto-generated file for TCS3472 v0.1.0. 17 | * Generated from peripherals/TCS3472.yaml using Cyanobyte Codegen v0.1.0 18 | * Class for TCS3472 19 | * Color Light-to-Digital Converter with IR Filter 20 | 21 | */ 22 | 23 | #ifndef _TCS3472_H_ 24 | #define _TCS3472_H_ 25 | #include 26 | #include 27 | 28 | /* 29 | * Valid values for Setup the device configuration 30 | 31 | */ 32 | enum init { 33 | INIT_POWER = 1, // Power 34 | INIT_RGBC = 2 // Color 35 | }; 36 | typedef enum init init_t; 37 | 38 | class TCS3472 { 39 | public: 40 | TCS3472(TwoWire& wire); 41 | 42 | void begin(); 43 | void end(); 44 | /** 45 | * Blue light as an int. Divide by ambient light to get scaled number. 46 | 47 | */ 48 | uint16_t readblue(); 49 | 50 | 51 | /** 52 | * This is the ambient amount of detected light. 53 | 54 | */ 55 | uint16_t readclear(); 56 | 57 | 58 | /** 59 | * Enable specific components of the peripheral 60 | 61 | */ 62 | uint8_t readenable(); 63 | 64 | /** 65 | * Enable specific components of the peripheral 66 | 67 | */ 68 | int writeenable(uint8_t data); 69 | /** 70 | * Green light as an int. Divide by ambient light to get scaled number. 71 | 72 | */ 73 | uint16_t readgreen(); 74 | 75 | 76 | /** 77 | * Red light as an int. Divide by ambient light to get scaled number. 78 | 79 | */ 80 | uint16_t readred(); 81 | 82 | 83 | /** 84 | * Enable RGBC and Power 85 | 86 | */ 87 | uint8_t getinit(); 88 | /** 89 | * Enable RGBC and Power 90 | 91 | */ 92 | int setinit(uint8_t data); 93 | 94 | /** 95 | * Enables features on device 96 | 97 | */ 98 | void _lifecycleBegin(); 99 | 100 | 101 | private: 102 | TwoWire* _wire; 103 | }; 104 | 105 | #endif -------------------------------------------------------------------------------- /test/sampleData/arduino/arduino.ino: -------------------------------------------------------------------------------- 1 | void setup() {} 2 | void loop() {} 3 | -------------------------------------------------------------------------------- /test/sampleData/datasheet/BMP180.tex: -------------------------------------------------------------------------------- 1 | \documentclass[a4paper,12pt,oneside,pdflatex,italian,final,twocolumn]{article} 2 | 3 | \usepackage[utf8]{inputenc} 4 | \usepackage{parallel} 5 | \usepackage{siunitx} 6 | \usepackage{booktabs} 7 | \usepackage{fancyhdr} 8 | 9 | \usepackage[export]{adjustbox} 10 | \usepackage[margin=0.5in]{geometry} 11 | \addtolength{\topmargin}{0in} 12 | 13 | \usepackage{libertine} 14 | \renewcommand*\familydefault{\sfdefault} %% Only if the base font of the document is to be sans serif 15 | \usepackage[T1]{fontenc} 16 | 17 | \title{ BMP180 } 18 | \author{ Nick Felker } 19 | \date{ 2020 } 20 | 21 | \begin{document} 22 | 23 | \pagestyle{fancy} 24 | 25 | \lhead{ Nick Felker } 26 | \chead { 2020 } 27 | \rhead{ BMP180 v0.1.0 } 28 | 29 | 30 | \onecolumn 31 | 32 | 33 | \begin{figure} 34 | \begin{minipage}{0.47\textwidth} 35 | 36 | \section{Overview} 37 | Bosch Digital Temperature / Pressure Sensor 38 | \begin{itemize} 39 | \item Device address 119 40 | \item Address type 7-bit 41 | \end{itemize} 42 | 43 | 44 | \end{minipage} 45 | \hfill 46 | 47 | \end{figure} 48 | 49 | 50 | \section{Register Description} 51 | \begin{itemize} 52 | \item Register to write commands - Register stores what the measurement type should be 53 | \item Pressure calibration AC1 - For calibration 54 | \item Pressure calibration AC2 - For calibration 55 | \item Pressure calibration VB1 - For calibration 56 | \item Pressure calibration VB2 - For calibration 57 | \item Register that stores measurement results - Register stores most recent measurement result 58 | \item Temperature calibration 3 - For calibration 59 | \item Temperature calibration 4 - For calibration 60 | \item Temperature calibration 5 - For calibration 61 | \item Temperature calibration 6 - For calibration 62 | \item Temperature calibration MC - For calibration 63 | \item Temperature calibration MD - For calibration 64 | \end{itemize} 65 | 66 | \section{Technical specification} 67 | \centering 68 | \begin{tabular}{lcrr} 69 | \toprule 70 | & Register Name & Register Address & Register Length \\ 71 | \midrule 72 | Control & Register to write commands & 244 & 8 \\ 73 | PressureCalAC1 & Pressure calibration AC1 & 170 & 16 \\ 74 | PressureCalAC2 & Pressure calibration AC2 & 172 & 16 \\ 75 | PressureCalVB1 & Pressure calibration VB1 & 182 & 16 \\ 76 | PressureCalVB2 & Pressure calibration VB2 & 184 & 16 \\ 77 | Result & Register that stores measurement results & 246 & 16 \\ 78 | TempCal3 & Temperature calibration 3 & 174 & 16 \\ 79 | TempCal4 & Temperature calibration 4 & 176 & 16 \\ 80 | TempCal5 & Temperature calibration 5 & 178 & 16 \\ 81 | TempCal6 & Temperature calibration 6 & 180 & 16 \\ 82 | TempCalMC & Temperature calibration MC & 188 & 16 \\ 83 | TempCalMD & Temperature calibration MD & 190 & 16 \\ 84 | \bottomrule 85 | \end{tabular} 86 | 87 | 88 | \raggedright 89 | 90 | \section{Functions} 91 | 92 | \centering 93 | \begin{tabular}{lc} 94 | \toprule 95 | & Description \\ 96 | \midrule 97 | temperature & Reads the temperature \\ 98 | \bottomrule 99 | \end{tabular} 100 | 101 | 102 | \raggedright 103 | \subsection{Function temperature } 104 | Reads the temperature \\ 105 | 106 | \centering 107 | \begin{tabular}{lcr} 108 | \toprule 109 | & Inputs & Return \\ 110 | \midrule 111 | asCelsius & 112 | & 113 | temperature 114 | \\ 115 | \bottomrule 116 | \end{tabular} 117 | 118 | 119 | 120 | \raggedright 121 | 122 | \end{document} -------------------------------------------------------------------------------- /test/sampleData/datasheet/Example.tex: -------------------------------------------------------------------------------- 1 | \documentclass[a4paper,12pt,oneside,pdflatex,italian,final,twocolumn]{article} 2 | 3 | \usepackage[utf8]{inputenc} 4 | \usepackage{parallel} 5 | \usepackage{siunitx} 6 | \usepackage{booktabs} 7 | \usepackage{fancyhdr} 8 | 9 | \usepackage[export]{adjustbox} 10 | \usepackage[margin=0.5in]{geometry} 11 | \addtolength{\topmargin}{0in} 12 | 13 | \usepackage{libertine} 14 | \renewcommand*\familydefault{\sfdefault} %% Only if the base font of the document is to be sans serif 15 | \usepackage[T1]{fontenc} 16 | 17 | \title{ Example } 18 | \author{ Nick Felker } 19 | \date{ 2019 } 20 | 21 | \begin{document} 22 | 23 | \pagestyle{fancy} 24 | 25 | \lhead{ Nick Felker } 26 | \chead { 2019 } 27 | \rhead{ Example v0.1.0 } 28 | 29 | 30 | \onecolumn 31 | 32 | 33 | \begin{figure} 34 | \begin{minipage}{0.47\textwidth} 35 | 36 | \section{Overview} 37 | Example of a package 38 | \begin{itemize} 39 | \item Device addresses: 40 | 16, 41 | 32, 42 | 48 43 | \item Address type 7-bit 44 | \end{itemize} 45 | 46 | 47 | \end{minipage} 48 | \hfill 49 | 50 | \end{figure} 51 | 52 | 53 | \section{Register Description} 54 | \begin{itemize} 55 | \item First example - An 8-bit register 56 | \item Second example - A 16-bit register 57 | \item Third example - A 32-bit register 58 | \item Fourth example - A dummy register that has no data 59 | \end{itemize} 60 | 61 | \section{Technical specification} 62 | \centering 63 | \begin{tabular}{lcrr} 64 | \toprule 65 | & Register Name & Register Address & Register Length \\ 66 | \midrule 67 | RegisterA & First example & 0 & 8 \\ 68 | RegisterB & Second example & 1 & 16 \\ 69 | RegisterC & Third example & 2 & 32 \\ 70 | RegisterD & Fourth example & 3 & 0 \\ 71 | \bottomrule 72 | \end{tabular} 73 | 74 | \raggedright 75 | 76 | \section{Fields} 77 | 78 | 79 | 80 | \raggedright 81 | 82 | \subsection{Register RegisterA} 83 | \centering 84 | \begin{tabular}{lcr} 85 | \toprule 86 | & Field Name & Bits \\ 87 | \midrule 88 | FieldA & Read-only fields for RegisterA & 89 | 7:4 90 | \\ 91 | FieldB & Write-only fields for RegisterA & 92 | 3:2 93 | \\ 94 | FieldC & Read/write field for RegisterA & 95 | 1 96 | \\ 97 | FieldD & This field should never appear & 98 | 0 99 | \\ 100 | \bottomrule 101 | 102 | \end{tabular} 103 | 104 | 105 | \raggedright 106 | 107 | \subsubsection{Field FieldB } 108 | 109 | This is fewer bits 110 | 111 | \begin{itemize} 112 | \item VAL\_1 (1) - Value 1 113 | \item VAL\_2 (2) - Value 2 114 | \item VAL\_3 (4) - Value 3 115 | \item VAL\_4 (8) - Value 4 116 | \end{itemize} 117 | 118 | 119 | 120 | 121 | \raggedright 122 | 123 | \section{Functions} 124 | 125 | \centering 126 | \begin{tabular}{lc} 127 | \toprule 128 | & Description \\ 129 | \midrule 130 | _lifecycle & Enables features on device \\ 131 | Return & Computes and returns \\ 132 | \bottomrule 133 | \end{tabular} 134 | 135 | 136 | \raggedright 137 | \subsection{Function _lifecycle } 138 | Enables features on device \\ 139 | 140 | \centering 141 | \begin{tabular}{lcr} 142 | \toprule 143 | & Inputs & Return \\ 144 | \midrule 145 | Begin & 146 | & 147 | output 148 | \\ 149 | End & 150 | & 151 | output 152 | \\ 153 | \bottomrule 154 | \end{tabular} 155 | 156 | 157 | 158 | \raggedright 159 | \subsection{Function Return } 160 | Computes and returns \\ 161 | 162 | \centering 163 | \begin{tabular}{lcr} 164 | \toprule 165 | & Inputs & Return \\ 166 | \midrule 167 | Array & 168 | & 169 | summation, 170 | summation 171 | \\ 172 | Number & 173 | & 174 | summation 175 | \\ 176 | Void & 177 | & 178 | void 179 | \\ 180 | \bottomrule 181 | \end{tabular} 182 | 183 | 184 | 185 | \raggedright 186 | 187 | \end{document} -------------------------------------------------------------------------------- /test/sampleData/datasheet/MCP4725.tex: -------------------------------------------------------------------------------- 1 | \documentclass[a4paper,12pt,oneside,pdflatex,italian,final,twocolumn]{article} 2 | 3 | \usepackage[utf8]{inputenc} 4 | \usepackage{parallel} 5 | \usepackage{siunitx} 6 | \usepackage{booktabs} 7 | \usepackage{fancyhdr} 8 | 9 | \usepackage[export]{adjustbox} 10 | \usepackage[margin=0.5in]{geometry} 11 | \addtolength{\topmargin}{0in} 12 | 13 | \usepackage{libertine} 14 | \renewcommand*\familydefault{\sfdefault} %% Only if the base font of the document is to be sans serif 15 | \usepackage[T1]{fontenc} 16 | 17 | \title{ MCP4725 } 18 | \author{ Nick Felker, Chris Frederickson } 19 | \date{ 2019 } 20 | 21 | \begin{document} 22 | 23 | \pagestyle{fancy} 24 | 25 | \lhead{ Nick Felker, Chris Frederickson } 26 | \chead { 2019 } 27 | \rhead{ MCP4725 v0.1.0 } 28 | 29 | 30 | \onecolumn 31 | 32 | 33 | \begin{figure} 34 | \begin{minipage}{0.47\textwidth} 35 | 36 | \section{Overview} 37 | Microchip 4725 Digital-to-Analog Converter 38 | \begin{itemize} 39 | \item Device address 98 40 | \item Address type 7-bit 41 | \item Little Endian 42 | \end{itemize} 43 | 44 | 45 | \end{minipage} 46 | \hfill 47 | 48 | \end{figure} 49 | 50 | 51 | \section{Register Description} 52 | \begin{itemize} 53 | \item EEPROM - If EEPROM is set, the saved voltage output will 54 | be loaded from power-on. 55 | 56 | \item Output voltage - VOut = (Vcc * value) / 4096 57 | The output is a range between 0 and Vcc with 58 | steps of Vcc/4096. 59 | In a 3.3v system, each step is 800 microvolts. 60 | 61 | \end{itemize} 62 | 63 | \section{Technical specification} 64 | \centering 65 | \begin{tabular}{lcrr} 66 | \toprule 67 | & Register Name & Register Address & Register Length \\ 68 | \midrule 69 | EEPROM & EEPROM & 96 & 12 \\ 70 | VOut & Output voltage & 64 & 12 \\ 71 | \bottomrule 72 | \end{tabular} 73 | 74 | \raggedright 75 | 76 | \section{Fields} 77 | 78 | 79 | 80 | \raggedright 81 | 82 | \subsection{Register EEPROM} 83 | \centering 84 | \begin{tabular}{lcr} 85 | \toprule 86 | & Field Name & Bits \\ 87 | \midrule 88 | digitalOut & Digital (binary) output & 89 | 12:0 90 | \\ 91 | \bottomrule 92 | 93 | \end{tabular} 94 | 95 | 96 | \raggedright 97 | 98 | \subsubsection{Field digitalOut } 99 | 100 | Only allows you to send fully on or off 101 | 102 | 103 | \begin{itemize} 104 | \item GND (0) - Ground 105 | \item VCC (4095) - Vcc (full power) 106 | \end{itemize} 107 | 108 | 109 | 110 | 111 | \raggedright 112 | 113 | \section{Functions} 114 | 115 | \centering 116 | \begin{tabular}{lc} 117 | \toprule 118 | & Description \\ 119 | \midrule 120 | getVOut & get vout \\ 121 | setVOut & set vout \\ 122 | \bottomrule 123 | \end{tabular} 124 | 125 | 126 | \raggedright 127 | \subsection{Function getVOut } 128 | get vout \\ 129 | 130 | \centering 131 | \begin{tabular}{lcr} 132 | \toprule 133 | & Inputs & Return \\ 134 | \midrule 135 | asVoltage & 136 | value (float32) 137 | , 138 | vcc (float32) 139 | 140 | & 141 | voltage 142 | \\ 143 | \bottomrule 144 | \end{tabular} 145 | 146 | 147 | 148 | \raggedright 149 | \subsection{Function setVOut } 150 | set vout \\ 151 | 152 | \centering 153 | \begin{tabular}{lcr} 154 | \toprule 155 | & Inputs & Return \\ 156 | \midrule 157 | asVoltage & 158 | output (float32) 159 | , 160 | vcc (float32) 161 | 162 | & 163 | void 164 | \\ 165 | \bottomrule 166 | \end{tabular} 167 | 168 | 169 | 170 | \raggedright 171 | 172 | \end{document} -------------------------------------------------------------------------------- /test/sampleData/datasheet/MCP9808.tex: -------------------------------------------------------------------------------- 1 | \documentclass[a4paper,12pt,oneside,pdflatex,italian,final,twocolumn]{article} 2 | 3 | \usepackage[utf8]{inputenc} 4 | \usepackage{parallel} 5 | \usepackage{siunitx} 6 | \usepackage{booktabs} 7 | \usepackage{fancyhdr} 8 | 9 | \usepackage[export]{adjustbox} 10 | \usepackage[margin=0.5in]{geometry} 11 | \addtolength{\topmargin}{0in} 12 | 13 | \usepackage{libertine} 14 | \renewcommand*\familydefault{\sfdefault} %% Only if the base font of the document is to be sans serif 15 | \usepackage[T1]{fontenc} 16 | 17 | \title{ MCP9808 } 18 | \author{ Joe Smith } 19 | \date{ 2019 } 20 | 21 | \begin{document} 22 | 23 | \pagestyle{fancy} 24 | 25 | \lhead{ Joe Smith } 26 | \chead { 2019 } 27 | \rhead{ MCP9808 v0.1.0 } 28 | 29 | 30 | \onecolumn 31 | 32 | 33 | \begin{figure} 34 | \begin{minipage}{0.47\textwidth} 35 | 36 | \section{Overview} 37 | This is a test description 38 | \begin{itemize} 39 | \item Device addresses: 40 | 24, 41 | 25, 42 | 26, 43 | 27, 44 | 28, 45 | 29, 46 | 30, 47 | 31 48 | \item Address type 7-bit 49 | \end{itemize} 50 | 51 | 52 | \end{minipage} 53 | \hfill 54 | 55 | \end{figure} 56 | 57 | 58 | \section{Register Description} 59 | \begin{itemize} 60 | \item Configuration Register - The MCP9808 has a 16-bit Configuration register (CONFIG) that 61 | allows the user to set various functions for a robust temperature 62 | monitoring system. 63 | Bits 10 through 0 are used to select the temperature alert output 64 | hysteresis, device shutdown or Low-Power mode, temperature boundary 65 | and critical temperature lock, and temperature Alert output 66 | enable/disable. 67 | In addition, Alert output condition (output set for TUPPER and 68 | TLOWER temperature boundary or TCRIT only), Alert output status 69 | and Alert output polarity and mode (Comparator Output or Interrupt 70 | Output mode) are user-configurable. 71 | 72 | \end{itemize} 73 | 74 | \section{Technical specification} 75 | \centering 76 | \begin{tabular}{lcrr} 77 | \toprule 78 | & Register Name & Register Address & Register Length \\ 79 | \midrule 80 | configuration & Configuration Register & 1 & 16 \\ 81 | \bottomrule 82 | \end{tabular} 83 | 84 | \raggedright 85 | 86 | \section{Fields} 87 | 88 | 89 | 90 | \raggedright 91 | 92 | \subsection{Register configuration} 93 | \centering 94 | \begin{tabular}{lcr} 95 | \toprule 96 | & Field Name & Bits \\ 97 | \midrule 98 | limitHysteresis & TUPPER and TLOWER Limit Hysteresis bits & 99 | 10:9 100 | \\ 101 | shutdownMode & Shutdown Mode bit & 102 | 8 103 | \\ 104 | \bottomrule 105 | 106 | \end{tabular} 107 | 108 | 109 | \raggedright 110 | 111 | \subsubsection{Field limitHysteresis } 112 | 113 | This bit can not be altered when either of the Lock bits are set 114 | (bit 6 and bit 7). This bit can be programmed in Shutdown mode. 115 | 116 | 117 | \begin{itemize} 118 | \item Temp\_0C (0) - 0°C (power-up default) 119 | \item Temp\_1C5 (1) - +1.5°C 120 | \item Temp\_3C (2) - +3.0°C 121 | \item Temp\_6C (3) - +6.0°C 122 | \end{itemize} 123 | 124 | 125 | \raggedright 126 | 127 | \subsubsection{Field shutdownMode } 128 | 129 | In shutdown, all power-consuming activities are disabled, though 130 | all registers can be written to or read. This bit cannot be set 131 | to ‘1’ when either of the Lock bits is set (bit 6 and bit 7). 132 | However, it can be cleared to ‘0’ for continuous conversion while 133 | locked. 134 | 135 | 136 | \begin{itemize} 137 | \item continousConversion (0) - Continuous conversion (power-up default) 138 | \item shutdown (1) - Shutdown (Low-Power mode) 139 | \end{itemize} 140 | 141 | 142 | 143 | 144 | 145 | \end{document} -------------------------------------------------------------------------------- /test/sampleData/datasheet/TCS3472.tex: -------------------------------------------------------------------------------- 1 | \documentclass[a4paper,12pt,oneside,pdflatex,italian,final,twocolumn]{article} 2 | 3 | \usepackage[utf8]{inputenc} 4 | \usepackage{parallel} 5 | \usepackage{siunitx} 6 | \usepackage{booktabs} 7 | \usepackage{fancyhdr} 8 | 9 | \usepackage[export]{adjustbox} 10 | \usepackage[margin=0.5in]{geometry} 11 | \addtolength{\topmargin}{0in} 12 | 13 | \usepackage{libertine} 14 | \renewcommand*\familydefault{\sfdefault} %% Only if the base font of the document is to be sans serif 15 | \usepackage[T1]{fontenc} 16 | 17 | \title{ TCS3472 } 18 | \author{ Nick Felker } 19 | \date{ 2019 } 20 | 21 | \begin{document} 22 | 23 | \pagestyle{fancy} 24 | 25 | \lhead{ Nick Felker } 26 | \chead { 2019 } 27 | \rhead{ TCS3472 v0.1.0 } 28 | 29 | 30 | \onecolumn 31 | 32 | 33 | \begin{figure} 34 | \begin{minipage}{0.47\textwidth} 35 | 36 | \section{Overview} 37 | Color Light-to-Digital Converter with IR Filter 38 | \begin{itemize} 39 | \item Device address 41 40 | \item Address type 7-bit 41 | \end{itemize} 42 | 43 | 44 | \end{minipage} 45 | \hfill 46 | 47 | \end{figure} 48 | 49 | 50 | \section{Register Description} 51 | \begin{itemize} 52 | \item Blue channel - Blue light as an int. Divide by ambient light to get scaled number. 53 | \item Clear channel - This is the ambient amount of detected light. 54 | \item Enable - Enable specific components of the peripheral 55 | \item Green channel - Green light as an int. Divide by ambient light to get scaled number. 56 | \item Red channel - Red light as an int. Divide by ambient light to get scaled number. 57 | \end{itemize} 58 | 59 | \section{Technical specification} 60 | \centering 61 | \begin{tabular}{lcrr} 62 | \toprule 63 | & Register Name & Register Address & Register Length \\ 64 | \midrule 65 | blue & Blue channel & 186 & 16 \\ 66 | clear & Clear channel & 180 & 16 \\ 67 | enable & Enable & 128 & 8 \\ 68 | green & Green channel & 184 & 16 \\ 69 | red & Red channel & 182 & 16 \\ 70 | \bottomrule 71 | \end{tabular} 72 | 73 | \raggedright 74 | 75 | \section{Fields} 76 | 77 | 78 | 79 | \raggedright 80 | 81 | \subsection{Register enable} 82 | \centering 83 | \begin{tabular}{lcr} 84 | \toprule 85 | & Field Name & Bits \\ 86 | \midrule 87 | init & Setup the device configuration & 88 | 7:0 89 | \\ 90 | \bottomrule 91 | 92 | \end{tabular} 93 | 94 | 95 | \raggedright 96 | 97 | \subsubsection{Field init } 98 | 99 | Enable RGBC and Power 100 | 101 | \begin{itemize} 102 | \item Power (1) - Power 103 | \item RGBC (2) - Color 104 | \end{itemize} 105 | 106 | 107 | 108 | 109 | \raggedright 110 | 111 | \section{Functions} 112 | 113 | \centering 114 | \begin{tabular}{lc} 115 | \toprule 116 | & Description \\ 117 | \midrule 118 | _lifecycle & Enables features on device \\ 119 | \bottomrule 120 | \end{tabular} 121 | 122 | 123 | \raggedright 124 | \subsection{Function _lifecycle } 125 | Enables features on device \\ 126 | 127 | \centering 128 | \begin{tabular}{lcr} 129 | \toprule 130 | & Inputs & Return \\ 131 | \midrule 132 | Begin & 133 | & 134 | void 135 | \\ 136 | \bottomrule 137 | \end{tabular} 138 | 139 | 140 | 141 | \raggedright 142 | 143 | \end{document} -------------------------------------------------------------------------------- /test/sampleData/embedded-c/MCP4725.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2019 Google Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | * Auto-generated file for MCP4725 v0.1.0. 17 | * Generated from peripherals/MCP4725.yaml using Cyanobyte Codegen v0.1.0 18 | * Class for MCP4725 19 | * Microchip 4725 Digital-to-Analog Converter 20 | 21 | */ 22 | 23 | #ifndef _MCP4725_H_ 24 | #define _MCP4725_H_ 25 | 26 | 27 | /* 28 | * Valid values for Digital (binary) output 29 | 30 | */ 31 | enum digitalOut { 32 | DIGITALOUT_GND = 0, // Ground 33 | DIGITALOUT_VCC = 4095 // Vcc (full power) 34 | }; 35 | typedef enum digitalOut digitalOut_t; 36 | 37 | int mcp4725_init(int (*connect)(uint8_t)); 38 | 39 | /** 40 | * If EEPROM is set, the saved voltage output will 41 | * be loaded from power-on. 42 | 43 | */ 44 | int mcp4725_readEEPROM( 45 | uint16_t* val, 46 | int (*read)(uint8_t, uint8_t, uint16_t*, uint8_t) 47 | ); 48 | 49 | /** 50 | * If EEPROM is set, the saved voltage output will 51 | * be loaded from power-on. 52 | 53 | */ 54 | int mcp4725_writeEEPROM( 55 | uint16_t* data, 56 | int (*read)(uint8_t, uint8_t, uint16_t*, uint8_t), 57 | int (*write)(uint8_t, uint8_t, uint16_t*, uint8_t) 58 | ); 59 | /** 60 | * VOut = (Vcc * value) / 4096 61 | * The output is a range between 0 and Vcc with 62 | * steps of Vcc/4096. 63 | * In a 3.3v system, each step is 800 microvolts. 64 | 65 | */ 66 | int mcp4725_readVOut( 67 | uint16_t* val, 68 | int (*read)(uint8_t, uint8_t, uint16_t*, uint8_t) 69 | ); 70 | 71 | /** 72 | * VOut = (Vcc * value) / 4096 73 | * The output is a range between 0 and Vcc with 74 | * steps of Vcc/4096. 75 | * In a 3.3v system, each step is 800 microvolts. 76 | 77 | */ 78 | int mcp4725_writeVOut( 79 | uint16_t* data, 80 | int (*read)(uint8_t, uint8_t, uint16_t*, uint8_t), 81 | int (*write)(uint8_t, uint8_t, uint16_t*, uint8_t) 82 | ); 83 | /** 84 | * Only allows you to send fully on or off 85 | 86 | */ 87 | int mcp4725_get_digitalout( 88 | uint16_t* val, 89 | int (*read)(uint8_t, uint8_t, int*, uint8_t) 90 | ); 91 | /** 92 | * Only allows you to send fully on or off 93 | 94 | */ 95 | int mcp4725_set_digitalout( 96 | uint16_t* data, 97 | int (*read)(uint8_t, uint8_t, int*, uint8_t), 98 | int (*write)(uint8_t, uint8_t, int*, uint8_t) 99 | ); 100 | 101 | /** 102 | * get vout 103 | 104 | */ 105 | void mcp4725_getvout_asvoltage( 106 | float* val, 107 | float vcc 108 | ); 109 | 110 | /** 111 | * set vout 112 | 113 | */ 114 | void mcp4725_setvout_asvoltage( 115 | float output, float vcc, 116 | int (*write)(uint8_t, uint8_t, int*, uint8_t) 117 | ); 118 | 119 | 120 | #endif -------------------------------------------------------------------------------- /test/sampleData/embedded-c/MCP9808.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2019 Google Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | * Auto-generated file for MCP9808 v0.1.0. 17 | * Generated from peripherals/MCP9808.yaml using Cyanobyte Codegen v0.1.0 18 | * Class for MCP9808 19 | * This is a test description 20 | 21 | */ 22 | 23 | 24 | 25 | 26 | #include "MCP9808.h" 27 | 28 | #define REGISTER_CONFIGURATION 1 29 | 30 | // Provide an I2C connect function, return status 31 | static deviceAddress_t DEVICE_ADDRESS; 32 | 33 | int mcp9808_init(deviceAddress_t address, int (*connect)(uint8_t)) { 34 | DEVICE_ADDRESS = address; 35 | // Initialize bus 36 | if (connect(DEVICE_ADDRESS) != 0) { 37 | return -1; 38 | } 39 | } 40 | 41 | int mcp9808_readconfiguration( 42 | uint16_t* val, 43 | int (*read)(uint8_t, uint8_t, uint16_t*, uint8_t) 44 | ) { 45 | if (val == NULL) { 46 | return -1; // Need to provide a valid value pointer 47 | } 48 | if (read(DEVICE_ADDRESS, REGISTER_CONFIGURATION, val, 2) != 0) { 49 | return -2; 50 | } 51 | return 0; 52 | } 53 | 54 | int mcp9808_writeconfiguration( 55 | uint16_t* data, 56 | int (*write)(uint8_t, uint8_t, uint16_t*, uint8_t) 57 | ) { 58 | if (write(DEVICE_ADDRESS, REGISTER_CONFIGURATION, data, 2) != 0) { 59 | return -1; 60 | } 61 | return 0; 62 | } 63 | int mcp9808_get_limithysteresis( 64 | uint16_t* val, 65 | int (*read)(uint8_t, uint8_t, int*, uint8_t) 66 | ) { 67 | // Read register data 68 | // '#/registers/configuration' > 'configuration' 69 | int result = mcp9808_readconfiguration(val, read); 70 | if (result != 0) { 71 | return result; 72 | } 73 | // Mask register value 74 | val = val & 0b0000011000000000; 75 | // Bitshift value 76 | val = val >> 9; 77 | return 0; 78 | } 79 | int mcp9808_get_shutdownmode( 80 | uint16_t* val, 81 | int (*read)(uint8_t, uint8_t, int*, uint8_t) 82 | ) { 83 | // Read register data 84 | // '#/registers/configuration' > 'configuration' 85 | int result = mcp9808_readconfiguration(val, read); 86 | if (result != 0) { 87 | return result; 88 | } 89 | // Mask register value 90 | val = val & 0b0000000100000000; 91 | // Bitshift value 92 | val = val >> 8; 93 | return 0; 94 | } 95 | 96 | -------------------------------------------------------------------------------- /test/sampleData/embedded-c/TCS3472.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2019 Google Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | * Auto-generated file for TCS3472 v0.1.0. 17 | * Generated from peripherals/TCS3472.yaml using Cyanobyte Codegen v0.1.0 18 | * Class for TCS3472 19 | * Color Light-to-Digital Converter with IR Filter 20 | 21 | */ 22 | 23 | #ifndef _TCS3472_H_ 24 | #define _TCS3472_H_ 25 | 26 | 27 | /* 28 | * Valid values for Setup the device configuration 29 | 30 | */ 31 | enum init { 32 | INIT_POWER = 1, // Power 33 | INIT_RGBC = 2 // Color 34 | }; 35 | typedef enum init init_t; 36 | 37 | int tcs3472_init(int (*connect)(uint8_t)); 38 | 39 | /** 40 | * Blue light as an int. Divide by ambient light to get scaled number. 41 | 42 | */ 43 | int tcs3472_readblue( 44 | uint16_t* val, 45 | int (*read)(uint8_t, uint8_t, uint16_t*, uint8_t) 46 | ); 47 | 48 | /** 49 | * This is the ambient amount of detected light. 50 | 51 | */ 52 | int tcs3472_readclear( 53 | uint16_t* val, 54 | int (*read)(uint8_t, uint8_t, uint16_t*, uint8_t) 55 | ); 56 | 57 | /** 58 | * Enable specific components of the peripheral 59 | 60 | */ 61 | int tcs3472_readenable( 62 | uint8_t* val, 63 | int (*read)(uint8_t, uint8_t, uint8_t*, uint8_t) 64 | ); 65 | 66 | /** 67 | * Enable specific components of the peripheral 68 | 69 | */ 70 | int tcs3472_writeenable( 71 | uint8_t* data, 72 | int (*read)(uint8_t, uint8_t, uint8_t*, uint8_t), 73 | int (*write)(uint8_t, uint8_t, uint8_t*, uint8_t) 74 | ); 75 | /** 76 | * Green light as an int. Divide by ambient light to get scaled number. 77 | 78 | */ 79 | int tcs3472_readgreen( 80 | uint16_t* val, 81 | int (*read)(uint8_t, uint8_t, uint16_t*, uint8_t) 82 | ); 83 | 84 | /** 85 | * Red light as an int. Divide by ambient light to get scaled number. 86 | 87 | */ 88 | int tcs3472_readred( 89 | uint16_t* val, 90 | int (*read)(uint8_t, uint8_t, uint16_t*, uint8_t) 91 | ); 92 | 93 | /** 94 | * Enable RGBC and Power 95 | 96 | */ 97 | int tcs3472_get_init( 98 | uint8_t* val, 99 | int (*read)(uint8_t, uint8_t, int*, uint8_t) 100 | ); 101 | /** 102 | * Enable RGBC and Power 103 | 104 | */ 105 | int tcs3472_set_init( 106 | uint8_t* data, 107 | int (*read)(uint8_t, uint8_t, int*, uint8_t), 108 | int (*write)(uint8_t, uint8_t, int*, uint8_t) 109 | ); 110 | 111 | /** 112 | * Enables features on device 113 | 114 | */ 115 | void tcs3472__lifecycle_begin( 116 | int (*write)(uint8_t, uint8_t, int*, uint8_t) 117 | ); 118 | 119 | 120 | #endif -------------------------------------------------------------------------------- /test/sampleData/esp32/ADS1015.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2019 Google Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | * Auto-generated file for ADS1015 v0.1.0. 17 | * Generated from peripherals/ADS1015.yaml using Cyanobyte Codegen v0.1.0 18 | * Class for ADS1015 19 | * Texas Instruments Analog-Digital Converter 20 | 21 | */ 22 | 23 | #ifndef _ADS1015_H_ 24 | #define _ADS1015_H_ 25 | #include 26 | #include 27 | 28 | /* 29 | * Valid values for Set the channel to read 30 | 31 | */ 32 | enum Channel { 33 | CHANNEL_CHANNEL_1 = 0, // Channel 1 34 | CHANNEL_CHANNEL_2 = 1, // Channel 2 35 | CHANNEL_CHANNEL_3 = 2, // Channel 3 36 | CHANNEL_CHANNEL_4 = 3 // Channel 4 37 | }; 38 | typedef enum Channel Channel_t; 39 | /* 40 | * Valid values for Set the operating mode 41 | 42 | */ 43 | enum DeviceOperatingMode { 44 | DEVICEOPERATINGMODE_CONTINUOUS_CONVERSION = 0, // Continuous Conversion 45 | DEVICEOPERATINGMODE_SINGLE_SHOT = 1 // Single-shot or power-down state 46 | }; 47 | typedef enum DeviceOperatingMode DeviceOperatingMode_t; 48 | /* 49 | * Valid values for Setup programmable gain 50 | 51 | */ 52 | enum ProgrammableGain { 53 | PROGRAMMABLEGAIN_PGA0_256 = 5, // Plus/minus 0.256V 54 | PROGRAMMABLEGAIN_PGA0_512 = 4, // Plus/minus 0.512V 55 | PROGRAMMABLEGAIN_PGA1_024V = 3, // Plus/minus 1.024V 56 | PROGRAMMABLEGAIN_PGA2_048V = 2, // Plus/minus 2.048V 57 | PROGRAMMABLEGAIN_PGA4_096V = 1, // Plus/minus 4.096V 58 | PROGRAMMABLEGAIN_PGA6_144V = 0 // Plus/minus 6.144V 59 | }; 60 | typedef enum ProgrammableGain ProgrammableGain_t; 61 | /* 62 | * Valid values for Setup sample rate for reading analog voltage 63 | 64 | */ 65 | enum SampleRate { 66 | SAMPLERATE_HZ128 = 0, // 128 samples/second 67 | SAMPLERATE_HZ1600 = 4, // 1600 samples/second 68 | SAMPLERATE_HZ2400 = 5, // 2400 samples/second 69 | SAMPLERATE_HZ250 = 1, // 250 samples/second 70 | SAMPLERATE_HZ3300 = 6, // 3300 samples/second 71 | SAMPLERATE_HZ490 = 2, // 490 samples/second 72 | SAMPLERATE_HZ920 = 3 // 920 samples/second 73 | }; 74 | typedef enum SampleRate SampleRate_t; 75 | 76 | class ADS1015 { 77 | public: 78 | ADS1015(TwoWire& wire); 79 | 80 | void begin(); 81 | /** 82 | * Describes the specifics of the sensing implementation 83 | 84 | */ 85 | uint16_t readConfig(); 86 | 87 | /** 88 | * Describes the specifics of the sensing implementation 89 | 90 | */ 91 | int writeConfig(uint16_t data); 92 | /** 93 | * Conversion register contains the result of the last conversion 94 | 95 | */ 96 | uint16_t readConversion(); 97 | 98 | 99 | /** 100 | * This bit controls the operating mode 101 | 102 | */ 103 | int setDeviceOperatingMode(uint8_t data); 104 | /** 105 | * This sets the programmable gain for reading analog voltage 106 | 107 | */ 108 | int setProgrammableGain(uint8_t data); 109 | /** 110 | * This sets the samples-per-second value 111 | 112 | */ 113 | int setSampleRate(uint8_t data); 114 | 115 | /** 116 | * Reads the analog voltage in Volts 117 | 118 | */ 119 | short analogread(char channel); 120 | 121 | 122 | private: 123 | TwoWire* _wire; 124 | }; 125 | 126 | #endif -------------------------------------------------------------------------------- /test/sampleData/esp32/BH1750FVI.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2020 Google Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | * Auto-generated file for BH1750FVI v0.1.0. 17 | * Generated from peripherals/BH1750FVI.yaml using Cyanobyte Codegen v0.1.0 18 | * Class for BH1750FVI 19 | * Rohm Light Sensor 20 | 21 | */ 22 | 23 | #ifndef _BH1750FVI_H_ 24 | #define _BH1750FVI_H_ 25 | #include 26 | #include 27 | 28 | enum deviceAddress { 29 | I2C_ADDRESS_35 = 35, 30 | I2C_ADDRESS_92 = 92 31 | }; 32 | typedef enum deviceAddress deviceAddress_t; 33 | 34 | class BH1750FVI { 35 | public: 36 | BH1750FVI(TwoWire& wire, deviceAddress_t address); 37 | deviceAddress_t DEVICE_ADDRESS; 38 | 39 | void begin(); 40 | 41 | /** 42 | * Start measurement at 0.5lx resolution. Typically 120ms. 43 | 44 | */ 45 | int writeContinuousHRes2Mode(); 46 | 47 | /** 48 | * Start measurement at 1lx resolution. Typically 120ms. 49 | 50 | */ 51 | int writeContinuousHResMode(); 52 | 53 | /** 54 | * Start measurement at 4lx resolution. Typically 16ms. 55 | 56 | */ 57 | int writeContinuouslyLResMode(); 58 | 59 | /** 60 | * Start measurement at 0.5lx resolution. Typically 120ms. 61 | * Power Down after measurement. 62 | 63 | */ 64 | int writeOnceHRes2Mode(); 65 | 66 | /** 67 | * Start measurement at 1lx resolution. Typically 120ms. 68 | * Power Down after measurement. 69 | 70 | */ 71 | int writeOnceHResMode(); 72 | 73 | /** 74 | * Start measurement at 4lx resolution. Typically 16ms. 75 | * Power Down after measurement. 76 | 77 | */ 78 | int writeOnceLResMode(); 79 | 80 | /** 81 | * No active state 82 | 83 | */ 84 | int writePowerDown(); 85 | 86 | /** 87 | * Waiting for measurement command 88 | 89 | */ 90 | int writePowerOn(); 91 | 92 | /** 93 | * Reset data register value. Not accepted in Power Down mode. 94 | 95 | */ 96 | int writeReset(); 97 | 98 | /** 99 | * Sends a POWER ON cmd to device 100 | 101 | */ 102 | void _lifecycleBegin(); 103 | 104 | /** 105 | * Things you can do to device 106 | 107 | */ 108 | void commandPowerDown(); 109 | /** 110 | * Things you can do to device 111 | 112 | */ 113 | void commandReset(); 114 | 115 | /** 116 | * Read light intensity from device 117 | 118 | */ 119 | uint16_t readLightIntensity(); 120 | 121 | 122 | private: 123 | TwoWire* _wire; 124 | }; 125 | 126 | #endif -------------------------------------------------------------------------------- /test/sampleData/esp32/BMP180.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2020 Google Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | * Auto-generated file for BMP180 v0.1.0. 17 | * Generated from peripherals/BMP180.yaml using Cyanobyte Codegen v0.1.0 18 | * Class for BMP180 19 | * Bosch Digital Temperature / Pressure Sensor 20 | 21 | */ 22 | 23 | #ifndef _BMP180_H_ 24 | #define _BMP180_H_ 25 | #include 26 | #include 27 | #include 28 | 29 | 30 | class BMP180 { 31 | public: 32 | BMP180(TwoWire& wire); 33 | 34 | void begin(); 35 | 36 | /** 37 | * Register stores what the measurement type should be 38 | 39 | */ 40 | int writeControl(uint8_t data); 41 | /** 42 | * For calibration 43 | 44 | */ 45 | uint16_t readPressureCalAC1(); 46 | 47 | 48 | /** 49 | * For calibration 50 | 51 | */ 52 | uint16_t readPressureCalAC2(); 53 | 54 | 55 | /** 56 | * For calibration 57 | 58 | */ 59 | uint16_t readPressureCalVB1(); 60 | 61 | 62 | /** 63 | * For calibration 64 | 65 | */ 66 | uint16_t readPressureCalVB2(); 67 | 68 | 69 | /** 70 | * Register stores most recent measurement result 71 | 72 | */ 73 | uint16_t readResult(); 74 | 75 | 76 | /** 77 | * For calibration 78 | 79 | */ 80 | uint16_t readTempCal3(); 81 | 82 | 83 | /** 84 | * For calibration 85 | 86 | */ 87 | uint16_t readTempCal4(); 88 | 89 | 90 | /** 91 | * For calibration 92 | 93 | */ 94 | uint16_t readTempCal5(); 95 | 96 | 97 | /** 98 | * For calibration 99 | 100 | */ 101 | uint16_t readTempCal6(); 102 | 103 | 104 | /** 105 | * For calibration 106 | 107 | */ 108 | uint16_t readTempCalMC(); 109 | 110 | 111 | /** 112 | * For calibration 113 | 114 | */ 115 | uint16_t readTempCalMD(); 116 | 117 | 118 | 119 | /** 120 | * Reads the temperature 121 | 122 | */ 123 | float temperatureasCelsius(); 124 | 125 | 126 | private: 127 | TwoWire* _wire; 128 | }; 129 | 130 | #endif -------------------------------------------------------------------------------- /test/sampleData/esp32/Example.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2019 Google Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | * Auto-generated file for Example v0.1.0. 17 | * Generated from peripherals/example.yaml using Cyanobyte Codegen v0.1.0 18 | * Class for Example 19 | * Example of a package 20 | 21 | */ 22 | 23 | #ifndef _Example_H_ 24 | #define _Example_H_ 25 | #include 26 | #include 27 | 28 | /* 29 | * Valid values for Write-only fields for RegisterA 30 | 31 | */ 32 | enum FieldB { 33 | FIELDB_VAL_1 = 1, // Value 1 34 | FIELDB_VAL_2 = 2, // Value 2 35 | FIELDB_VAL_3 = 4, // Value 3 36 | FIELDB_VAL_4 = 8 // Value 4 37 | }; 38 | typedef enum FieldB FieldB_t; 39 | enum deviceAddress { 40 | I2C_ADDRESS_16 = 16, 41 | I2C_ADDRESS_32 = 32, 42 | I2C_ADDRESS_48 = 48 43 | }; 44 | typedef enum deviceAddress deviceAddress_t; 45 | 46 | class Example { 47 | public: 48 | Example(TwoWire& wire, deviceAddress_t address); 49 | deviceAddress_t DEVICE_ADDRESS; 50 | 51 | void begin(); 52 | /** 53 | * An 8-bit register 54 | 55 | */ 56 | uint8_t readRegisterA(); 57 | 58 | /** 59 | * An 8-bit register 60 | 61 | */ 62 | int writeRegisterA(uint8_t data); 63 | /** 64 | * A 16-bit register 65 | 66 | */ 67 | uint16_t readRegisterB(); 68 | 69 | /** 70 | * A 16-bit register 71 | 72 | */ 73 | int writeRegisterB(uint16_t data); 74 | /** 75 | * A 32-bit register 76 | 77 | */ 78 | uint32_t readRegisterC(); 79 | 80 | /** 81 | * A 32-bit register 82 | 83 | */ 84 | int writeRegisterC(uint32_t data); 85 | /** 86 | * A dummy register that has no data 87 | 88 | */ 89 | uint8_t readRegisterD(); 90 | 91 | /** 92 | * A dummy register that has no data 93 | 94 | */ 95 | int writeRegisterD(); 96 | /** 97 | * This is a few bits 98 | 99 | */ 100 | uint8_t getFieldA(); 101 | /** 102 | * This is fewer bits 103 | 104 | */ 105 | int setFieldB(uint8_t data); 106 | /** 107 | * A single-bit 108 | 109 | */ 110 | uint8_t getFieldC(); 111 | /** 112 | * A single-bit 113 | 114 | */ 115 | int setFieldC(uint8_t data); 116 | 117 | /** 118 | * Enables features on device 119 | 120 | */ 121 | char _lifecycleBegin(); 122 | /** 123 | * Enables features on device 124 | 125 | */ 126 | char _lifecycleEnd(); 127 | 128 | /** 129 | * Computes and returns 130 | 131 | */ 132 | void ReturnArray(short * returnArray); 133 | /** 134 | * Computes and returns 135 | 136 | */ 137 | short ReturnNumber(); 138 | /** 139 | * Computes and returns 140 | 141 | */ 142 | void ReturnVoid(); 143 | 144 | 145 | private: 146 | TwoWire* _wire; 147 | }; 148 | 149 | #endif -------------------------------------------------------------------------------- /test/sampleData/esp32/MCP4725.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2019 Google Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | * Auto-generated file for MCP4725 v0.1.0. 17 | * Generated from peripherals/MCP4725.yaml using Cyanobyte Codegen v0.1.0 18 | * Class for MCP4725 19 | * Microchip 4725 Digital-to-Analog Converter 20 | 21 | */ 22 | 23 | #ifndef _MCP4725_H_ 24 | #define _MCP4725_H_ 25 | #include 26 | #include 27 | 28 | /* 29 | * Valid values for Digital (binary) output 30 | 31 | */ 32 | enum digitalOut { 33 | DIGITALOUT_GND = 0, // Ground 34 | DIGITALOUT_VCC = 4095 // Vcc (full power) 35 | }; 36 | typedef enum digitalOut digitalOut_t; 37 | 38 | class MCP4725 { 39 | public: 40 | MCP4725(TwoWire& wire); 41 | 42 | void begin(); 43 | /** 44 | * If EEPROM is set, the saved voltage output will 45 | * be loaded from power-on. 46 | 47 | */ 48 | uint16_t readEEPROM(); 49 | 50 | /** 51 | * If EEPROM is set, the saved voltage output will 52 | * be loaded from power-on. 53 | 54 | */ 55 | int writeEEPROM(uint16_t data); 56 | /** 57 | * VOut = (Vcc * value) / 4096 58 | * The output is a range between 0 and Vcc with 59 | * steps of Vcc/4096. 60 | * In a 3.3v system, each step is 800 microvolts. 61 | 62 | */ 63 | uint16_t readVOut(); 64 | 65 | /** 66 | * VOut = (Vcc * value) / 4096 67 | * The output is a range between 0 and Vcc with 68 | * steps of Vcc/4096. 69 | * In a 3.3v system, each step is 800 microvolts. 70 | 71 | */ 72 | int writeVOut(uint16_t data); 73 | /** 74 | * Only allows you to send fully on or off 75 | 76 | */ 77 | uint16_t getdigitalOut(); 78 | /** 79 | * Only allows you to send fully on or off 80 | 81 | */ 82 | int setdigitalOut(uint8_t data); 83 | 84 | /** 85 | * get vout 86 | 87 | */ 88 | float getVOutasVoltage(float vcc); 89 | 90 | /** 91 | * set vout 92 | 93 | */ 94 | void setVOutasVoltage(float output, float vcc); 95 | 96 | 97 | private: 98 | TwoWire* _wire; 99 | }; 100 | 101 | #endif -------------------------------------------------------------------------------- /test/sampleData/esp32/MCP9808.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2019 Google Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | * Auto-generated file for MCP9808 v0.1.0. 17 | * Generated from peripherals/MCP9808.yaml using Cyanobyte Codegen v0.1.0 18 | * Class for MCP9808 19 | * This is a test description 20 | 21 | */ 22 | 23 | 24 | 25 | 26 | #include "MCP9808.h" 27 | 28 | #define REGISTER_CONFIGURATION 1 29 | 30 | MCP9808::MCP9808(TwoWire& wire, deviceAddress_t address) : 31 | _wire(&wire), 32 | DEVICE_ADDRESS ( address ) 33 | { 34 | } 35 | 36 | void MCP9808::begin() { 37 | _wire->begin(); 38 | } 39 | 40 | 41 | uint16_t MCP9808::readconfiguration() { 42 | uint8_t datum; 43 | uint16_t value; 44 | _wire->beginTransmission(DEVICE_ADDRESS); 45 | _wire->write(REGISTER_CONFIGURATION); 46 | if (_wire->endTransmission(false) != 0) { 47 | return -1; 48 | } 49 | 50 | if (_wire->requestFrom(DEVICE_ADDRESS, 2) != 2) { 51 | return 0; 52 | } 53 | 54 | datum = _wire->read(); 55 | value = value << 8 | datum; 56 | datum = _wire->read(); 57 | value = value << 8 | datum; 58 | 59 | return value; 60 | } 61 | 62 | int MCP9808::writeconfiguration(uint16_t data) { 63 | _wire->beginTransmission(DEVICE_ADDRESS); 64 | // Put our data into uint8_t buffer 65 | uint8_t buffer[3] = { (uint8_t) REGISTER_CONFIGURATION }; 66 | buffer[1] = (data >> 8) & 0xFF; 67 | buffer[2] = (data >> 0) & 0xFF; 68 | _wire->write(buffer, 3); 69 | if (_wire->endTransmission() != 0) { 70 | return 0; 71 | } 72 | return 1; 73 | } 74 | 75 | 76 | uint16_t MCP9808::getlimitHysteresis() { 77 | // Read register data 78 | // '#/registers/configuration' > 'configuration' 79 | uint8_t val = readconfiguration(); 80 | // Mask register value 81 | val = val & 0b0000011000000000; 82 | // Bitshift value 83 | val = val >> 9; 84 | return val; 85 | } 86 | uint16_t MCP9808::getshutdownMode() { 87 | // Read register data 88 | // '#/registers/configuration' > 'configuration' 89 | uint8_t val = readconfiguration(); 90 | // Mask register value 91 | val = val & 0b0000000100000000; 92 | // Bitshift value 93 | val = val >> 8; 94 | return val; 95 | } 96 | 97 | -------------------------------------------------------------------------------- /test/sampleData/esp32/TCS3472.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2019 Google Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | * Auto-generated file for TCS3472 v0.1.0. 17 | * Generated from peripherals/TCS3472.yaml using Cyanobyte Codegen v0.1.0 18 | * Class for TCS3472 19 | * Color Light-to-Digital Converter with IR Filter 20 | 21 | */ 22 | 23 | #ifndef _TCS3472_H_ 24 | #define _TCS3472_H_ 25 | #include 26 | #include 27 | 28 | /* 29 | * Valid values for Setup the device configuration 30 | 31 | */ 32 | enum init { 33 | INIT_POWER = 1, // Power 34 | INIT_RGBC = 2 // Color 35 | }; 36 | typedef enum init init_t; 37 | 38 | class TCS3472 { 39 | public: 40 | TCS3472(TwoWire& wire); 41 | 42 | void begin(); 43 | /** 44 | * Blue light as an int. Divide by ambient light to get scaled number. 45 | 46 | */ 47 | uint16_t readblue(); 48 | 49 | 50 | /** 51 | * This is the ambient amount of detected light. 52 | 53 | */ 54 | uint16_t readclear(); 55 | 56 | 57 | /** 58 | * Enable specific components of the peripheral 59 | 60 | */ 61 | uint8_t readenable(); 62 | 63 | /** 64 | * Enable specific components of the peripheral 65 | 66 | */ 67 | int writeenable(uint8_t data); 68 | /** 69 | * Green light as an int. Divide by ambient light to get scaled number. 70 | 71 | */ 72 | uint16_t readgreen(); 73 | 74 | 75 | /** 76 | * Red light as an int. Divide by ambient light to get scaled number. 77 | 78 | */ 79 | uint16_t readred(); 80 | 81 | 82 | /** 83 | * Enable RGBC and Power 84 | 85 | */ 86 | uint8_t getinit(); 87 | /** 88 | * Enable RGBC and Power 89 | 90 | */ 91 | int setinit(uint8_t data); 92 | 93 | /** 94 | * Enables features on device 95 | 96 | */ 97 | void _lifecycleBegin(); 98 | 99 | 100 | private: 101 | TwoWire* _wire; 102 | }; 103 | 104 | #endif -------------------------------------------------------------------------------- /test/sampleData/i2c-device/ADS1015.py: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2019 Google Inc. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | # Auto-generated file for ADS1015 v0.1.0. 16 | # Generated from peripherals/ADS1015.yaml using Cyanobyte Codegen v0.1.0 17 | from i2cdevice import Device, Register, BitField 18 | 19 | I2C_ADDR = 73 20 | 21 | CONFIG = Register('CONFIG', 1, fields=( 22 | BitField('Channel', 0b0111000000000000, bitwidth=3, values_in=_byte_swap, values_out=_byte_swap, values_map={ 23 | CHANNEL_1: 0, 24 | CHANNEL_2: 1, 25 | CHANNEL_3: 2, 26 | CHANNEL_4: 3 27 | }), 28 | BitField('DeviceOperatingMode', 0b0000000100000000, bitwidth=1, values_in=_byte_swap, values_out=_byte_swap, values_map={ 29 | CONTINUOUS_CONVERSION: 0, 30 | SINGLE_SHOT: 1 31 | }), 32 | BitField('ProgrammableGain', 0b0000111000000000, bitwidth=3, values_in=_byte_swap, values_out=_byte_swap, values_map={ 33 | PGA0_256: 5, 34 | PGA0_512: 4, 35 | PGA1_024V: 3, 36 | PGA2_048V: 2, 37 | PGA4_096V: 1, 38 | PGA6_144V: 0 39 | }), 40 | BitField('SampleRate', 0b0000000011100000, bitwidth=3, values_in=_byte_swap, values_out=_byte_swap, values_map={ 41 | HZ128: 0, 42 | HZ1600: 4, 43 | HZ2400: 5, 44 | HZ250: 1, 45 | HZ3300: 6, 46 | HZ490: 2, 47 | HZ920: 3 48 | }) 49 | ), read_only=False, bitwidth=16) 50 | CONVERSION = Register('CONVERSION', 0, read_only=True, bitwidth=16) 51 | 52 | ads1015 = Device(I2C_ADDR, registers=( 53 | CONFIG, 54 | CONVERSION 55 | )) -------------------------------------------------------------------------------- /test/sampleData/i2c-device/BH1750FVI.py: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2020 Google Inc. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | # Auto-generated file for BH1750FVI v0.1.0. 16 | # Generated from peripherals/BH1750FVI.yaml using Cyanobyte Codegen v0.1.0 17 | from i2cdevice import Device, Register, BitField 18 | 19 | I2C_ADDR_35 = 35 20 | I2C_ADDR_92 = 92 21 | I2C_ADDR = [I2C_ADDR_35, I2C_ADDR_92] 22 | 23 | CONTINUOUSHRES2MODE = Register('CONTINUOUSHRES2MODE', 17, read_only=False, bitwidth=0) 24 | CONTINUOUSHRESMODE = Register('CONTINUOUSHRESMODE', 16, read_only=False, bitwidth=0) 25 | CONTINUOUSLYLRESMODE = Register('CONTINUOUSLYLRESMODE', 19, read_only=False, bitwidth=0) 26 | ONCEHRES2MODE = Register('ONCEHRES2MODE', 33, read_only=False, bitwidth=0) 27 | ONCEHRESMODE = Register('ONCEHRESMODE', 32, read_only=False, bitwidth=0) 28 | ONCELRESMODE = Register('ONCELRESMODE', 35, read_only=False, bitwidth=0) 29 | POWERDOWN = Register('POWERDOWN', 0, read_only=False, bitwidth=0) 30 | POWERON = Register('POWERON', 1, read_only=False, bitwidth=0) 31 | RESET = Register('RESET', 7, read_only=False, bitwidth=0) 32 | 33 | bh1750fvi = Device(I2C_ADDR, registers=( 34 | CONTINUOUSHRES2MODE, 35 | CONTINUOUSHRESMODE, 36 | CONTINUOUSLYLRESMODE, 37 | ONCEHRES2MODE, 38 | ONCEHRESMODE, 39 | ONCELRESMODE, 40 | POWERDOWN, 41 | POWERON, 42 | RESET 43 | )) -------------------------------------------------------------------------------- /test/sampleData/i2c-device/BMP180.py: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2020 Google Inc. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | # Auto-generated file for BMP180 v0.1.0. 16 | # Generated from peripherals/BMP180.yaml using Cyanobyte Codegen v0.0.2 17 | from i2cdevice import Device, Register, BitField 18 | 19 | I2C_ADDR = 119 20 | 21 | CONTROL = Register('CONTROL', 244, read_only=False, bitwidth=8) 22 | PRESSURECALAC1 = Register('PRESSURECALAC1', 170, read_only=True, bitwidth=16) 23 | PRESSURECALAC2 = Register('PRESSURECALAC2', 172, read_only=True, bitwidth=16) 24 | PRESSURECALVB1 = Register('PRESSURECALVB1', 182, read_only=True, bitwidth=16) 25 | PRESSURECALVB2 = Register('PRESSURECALVB2', 184, read_only=True, bitwidth=16) 26 | RESULT = Register('RESULT', 246, read_only=True, bitwidth=16) 27 | TEMPCAL3 = Register('TEMPCAL3', 174, read_only=True, bitwidth=16) 28 | TEMPCAL4 = Register('TEMPCAL4', 176, read_only=True, bitwidth=16) 29 | TEMPCAL5 = Register('TEMPCAL5', 178, read_only=True, bitwidth=16) 30 | TEMPCAL6 = Register('TEMPCAL6', 180, read_only=True, bitwidth=16) 31 | TEMPCALMC = Register('TEMPCALMC', 188, read_only=True, bitwidth=16) 32 | TEMPCALMD = Register('TEMPCALMD', 190, read_only=True, bitwidth=16) 33 | 34 | bmp180 = Device(I2C_ADDR, registers=( 35 | CONTROL, 36 | PRESSURECALAC1, 37 | PRESSURECALAC2, 38 | PRESSURECALVB1, 39 | PRESSURECALVB2, 40 | RESULT, 41 | TEMPCAL3, 42 | TEMPCAL4, 43 | TEMPCAL5, 44 | TEMPCAL6, 45 | TEMPCALMC, 46 | TEMPCALMD 47 | )) -------------------------------------------------------------------------------- /test/sampleData/i2c-device/BMP280.py: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2019 Google Inc. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | # Auto-generated file for BMP280 v0.1.0. 16 | # Generated from peripherals/BMP280.yaml using Cyanobyte Codegen v0.1.0 17 | from i2cdevice import Device, Register, BitField 18 | 19 | I2C_ADDR = 119 20 | 21 | DIGP1 = Register('DIGP1', 142, read_only=True, bitwidth=16) 22 | DIGP2 = Register('DIGP2', 144, read_only=True, bitwidth=16) 23 | DIGP3 = Register('DIGP3', 146, read_only=True, bitwidth=16) 24 | DIGP4 = Register('DIGP4', 148, read_only=True, bitwidth=16) 25 | DIGP5 = Register('DIGP5', 150, read_only=True, bitwidth=16) 26 | DIGP6 = Register('DIGP6', 152, read_only=True, bitwidth=16) 27 | DIGP7 = Register('DIGP7', 154, read_only=True, bitwidth=16) 28 | DIGP8 = Register('DIGP8', 156, read_only=True, bitwidth=16) 29 | DIGP9 = Register('DIGP9', 158, read_only=True, bitwidth=16) 30 | DIGT1 = Register('DIGT1', 136, read_only=True, bitwidth=16) 31 | DIGT2 = Register('DIGT2', 138, read_only=True, bitwidth=16) 32 | DIGT3 = Register('DIGT3', 140, read_only=True, bitwidth=16) 33 | PRESSURELSB = Register('PRESSURELSB', 248, read_only=True, bitwidth=8) 34 | PRESSUREMSB = Register('PRESSUREMSB', 247, read_only=True, bitwidth=8) 35 | PRESSUREXLSB = Register('PRESSUREXLSB', 249, read_only=True, bitwidth=8) 36 | TEMPLSB = Register('TEMPLSB', 251, read_only=True, bitwidth=8) 37 | TEMPMSB = Register('TEMPMSB', 250, read_only=True, bitwidth=8) 38 | TEMPXLSB = Register('TEMPXLSB', 252, read_only=True, bitwidth=8) 39 | 40 | bmp280 = Device(I2C_ADDR, registers=( 41 | DIGP1, 42 | DIGP2, 43 | DIGP3, 44 | DIGP4, 45 | DIGP5, 46 | DIGP6, 47 | DIGP7, 48 | DIGP8, 49 | DIGP9, 50 | DIGT1, 51 | DIGT2, 52 | DIGT3, 53 | PRESSURELSB, 54 | PRESSUREMSB, 55 | PRESSUREXLSB, 56 | TEMPLSB, 57 | TEMPMSB, 58 | TEMPXLSB 59 | )) -------------------------------------------------------------------------------- /test/sampleData/i2c-device/Example.py: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2019 Google Inc. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | # Auto-generated file for Example v0.1.0. 16 | # Generated from peripherals/example.yaml using Cyanobyte Codegen v0.1.0 17 | from i2cdevice import Device, Register, BitField 18 | 19 | I2C_ADDR_16 = 16 20 | I2C_ADDR_32 = 32 21 | I2C_ADDR_48 = 48 22 | I2C_ADDR = [I2C_ADDR_16, I2C_ADDR_32, I2C_ADDR_48] 23 | 24 | REGISTERA = Register('REGISTERA', 0, fields=( 25 | BitField('FieldA', 0b0000000011110000, bitwidth=4), 26 | BitField('FieldB', 0b0000000000001100, bitwidth=2, values_map={ 27 | VAL_1: 1, 28 | VAL_2: 2, 29 | VAL_3: 4, 30 | VAL_4: 8 31 | }), 32 | BitField('FieldC', 0b0000000000000010, bitwidth=1), 33 | BitField('FieldD', 0b0000000000000001, bitwidth=1) 34 | ), read_only=False, bitwidth=8) 35 | REGISTERB = Register('REGISTERB', 1, read_only=False, bitwidth=16) 36 | REGISTERC = Register('REGISTERC', 2, read_only=False, bitwidth=32) 37 | REGISTERD = Register('REGISTERD', 3, read_only=False, bitwidth=0) 38 | 39 | example = Device(I2C_ADDR, registers=( 40 | REGISTERA, 41 | REGISTERB, 42 | REGISTERC, 43 | REGISTERD 44 | )) -------------------------------------------------------------------------------- /test/sampleData/i2c-device/LSM303D.py: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2019 Google Inc. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | # Auto-generated file for LSM303D v0.1.0. 16 | # Generated from peripherals/LSM303D.yaml using Cyanobyte Codegen v0.1.0 17 | from i2cdevice import Device, Register, BitField 18 | 19 | I2C_ADDR = 29 20 | 21 | ACCELEROMETERX_HIGH = Register('ACCELEROMETERX_HIGH', 169, read_only=True, bitwidth=8) 22 | ACCELEROMETERX_LOW = Register('ACCELEROMETERX_LOW', 168, read_only=True, bitwidth=8) 23 | ACCELEROMETERY_HIGH = Register('ACCELEROMETERY_HIGH', 171, read_only=True, bitwidth=8) 24 | ACCELEROMETERY_LOW = Register('ACCELEROMETERY_LOW', 170, read_only=True, bitwidth=8) 25 | ACCELEROMETERZ_HIGH = Register('ACCELEROMETERZ_HIGH', 173, read_only=True, bitwidth=8) 26 | ACCELEROMETERZ_LOW = Register('ACCELEROMETERZ_LOW', 172, read_only=True, bitwidth=8) 27 | MAGNETOMETERX_HIGH = Register('MAGNETOMETERX_HIGH', 137, read_only=True, bitwidth=8) 28 | MAGNETOMETERX_LOW = Register('MAGNETOMETERX_LOW', 136, read_only=True, bitwidth=8) 29 | MAGNETOMETERY_HIGH = Register('MAGNETOMETERY_HIGH', 139, read_only=True, bitwidth=8) 30 | MAGNETOMETERY_LOW = Register('MAGNETOMETERY_LOW', 138, read_only=True, bitwidth=8) 31 | MAGNETOMETERZ_HIGH = Register('MAGNETOMETERZ_HIGH', 141, read_only=True, bitwidth=8) 32 | MAGNETOMETERZ_LOW = Register('MAGNETOMETERZ_LOW', 140, read_only=True, bitwidth=8) 33 | 34 | lsm303d = Device(I2C_ADDR, registers=( 35 | ACCELEROMETERX_HIGH, 36 | ACCELEROMETERX_LOW, 37 | ACCELEROMETERY_HIGH, 38 | ACCELEROMETERY_LOW, 39 | ACCELEROMETERZ_HIGH, 40 | ACCELEROMETERZ_LOW, 41 | MAGNETOMETERX_HIGH, 42 | MAGNETOMETERX_LOW, 43 | MAGNETOMETERY_HIGH, 44 | MAGNETOMETERY_LOW, 45 | MAGNETOMETERZ_HIGH, 46 | MAGNETOMETERZ_LOW 47 | )) -------------------------------------------------------------------------------- /test/sampleData/i2c-device/MCP4725.py: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2019 Google Inc. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | # Auto-generated file for MCP4725 v0.1.0. 16 | # Generated from peripherals/MCP4725.yaml using Cyanobyte Codegen v0.1.0 17 | from i2cdevice import Device, Register, BitField 18 | 19 | I2C_ADDR = 98 20 | 21 | EEPROM = Register('EEPROM', 96, fields=( 22 | BitField('digitalOut', 0b0001111111111111, bitwidth=13, values_in=_byte_swap, values_out=_byte_swap, values_map={ 23 | GND: 0, 24 | VCC: 4095 25 | }) 26 | ), read_only=False, bitwidth=12) 27 | VOUT = Register('VOUT', 64, read_only=False, bitwidth=12) 28 | 29 | mcp4725 = Device(I2C_ADDR, registers=( 30 | EEPROM, 31 | VOUT 32 | )) -------------------------------------------------------------------------------- /test/sampleData/i2c-device/MCP9808.py: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2019 Google Inc. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | # Auto-generated file for MCP9808 v0.1.0. 16 | # Generated from peripherals/MCP9808.yaml using Cyanobyte Codegen v0.1.0 17 | from i2cdevice import Device, Register, BitField 18 | 19 | I2C_ADDR_24 = 24 20 | I2C_ADDR_25 = 25 21 | I2C_ADDR_26 = 26 22 | I2C_ADDR_27 = 27 23 | I2C_ADDR_28 = 28 24 | I2C_ADDR_29 = 29 25 | I2C_ADDR_30 = 30 26 | I2C_ADDR_31 = 31 27 | I2C_ADDR = [I2C_ADDR_24, I2C_ADDR_25, I2C_ADDR_26, I2C_ADDR_27, I2C_ADDR_28, I2C_ADDR_29, I2C_ADDR_30, I2C_ADDR_31] 28 | 29 | CONFIGURATION = Register('CONFIGURATION', 1, fields=( 30 | BitField('limitHysteresis', 0b0000011000000000, bitwidth=2, values_map={ 31 | Temp_0C: 0, 32 | Temp_1C5: 1, 33 | Temp_3C: 2, 34 | Temp_6C: 3 35 | }), 36 | BitField('shutdownMode', 0b0000000100000000, bitwidth=1, values_map={ 37 | continousConversion: 0, 38 | shutdown: 1 39 | }) 40 | ), read_only=False, bitwidth=16) 41 | 42 | mcp9808 = Device(I2C_ADDR, registers=( 43 | CONFIGURATION 44 | )) -------------------------------------------------------------------------------- /test/sampleData/i2c-device/TCS3472.py: -------------------------------------------------------------------------------- 1 | # Copyright (C) 2019 Google Inc. 2 | # 3 | # Licensed under the Apache License, Version 2.0 (the "License"); 4 | # you may not use this file except in compliance with the License. 5 | # You may obtain a copy of the License at 6 | # 7 | # http://www.apache.org/licenses/LICENSE-2.0 8 | # 9 | # Unless required by applicable law or agreed to in writing, software 10 | # distributed under the License is distributed on an "AS IS" BASIS, 11 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 | # See the License for the specific language governing permissions and 13 | # limitations under the License. 14 | # 15 | # Auto-generated file for TCS3472 v0.1.0. 16 | # Generated from peripherals/TCS3472.yaml using Cyanobyte Codegen v0.1.0 17 | from i2cdevice import Device, Register, BitField 18 | 19 | I2C_ADDR = 41 20 | 21 | BLUE = Register('BLUE', 186, read_only=True, bitwidth=16) 22 | CLEAR = Register('CLEAR', 180, read_only=True, bitwidth=16) 23 | ENABLE = Register('ENABLE', 128, fields=( 24 | BitField('init', 0b0000000011111111, bitwidth=8, values_map={ 25 | Power: 1, 26 | RGBC: 2 27 | }) 28 | ), read_only=False, bitwidth=8) 29 | GREEN = Register('GREEN', 184, read_only=True, bitwidth=16) 30 | RED = Register('RED', 182, read_only=True, bitwidth=16) 31 | 32 | tcs3472 = Device(I2C_ADDR, registers=( 33 | BLUE, 34 | CLEAR, 35 | ENABLE, 36 | GREEN, 37 | RED 38 | )) -------------------------------------------------------------------------------- /test/sampleData/kubos/ADS1015.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2019 Google Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | * Auto-generated file for ADS1015 v0.1.0. 17 | * Generated from peripherals/ADS1015.yaml using Cyanobyte Codegen v0.1.0 18 | * Class for ADS1015 19 | * Texas Instruments Analog-Digital Converter 20 | 21 | */ 22 | 23 | #ifndef _ADS1015_H_ 24 | #define _ADS1015_H_ 25 | #include 26 | #include 27 | #include 28 | #include "i2c.h" 29 | 30 | 31 | /* 32 | * Valid values for Set the channel to read 33 | 34 | */ 35 | enum Channel { 36 | CHANNEL_CHANNEL_1 = 0, // Channel 1 37 | CHANNEL_CHANNEL_2 = 1, // Channel 2 38 | CHANNEL_CHANNEL_3 = 2, // Channel 3 39 | CHANNEL_CHANNEL_4 = 3 // Channel 4 40 | }; 41 | typedef enum Channel Channel_t; 42 | /* 43 | * Valid values for Set the operating mode 44 | 45 | */ 46 | enum DeviceOperatingMode { 47 | DEVICEOPERATINGMODE_CONTINUOUS_CONVERSION = 0, // Continuous Conversion 48 | DEVICEOPERATINGMODE_SINGLE_SHOT = 1 // Single-shot or power-down state 49 | }; 50 | typedef enum DeviceOperatingMode DeviceOperatingMode_t; 51 | /* 52 | * Valid values for Setup programmable gain 53 | 54 | */ 55 | enum ProgrammableGain { 56 | PROGRAMMABLEGAIN_PGA0_256 = 5, // Plus/minus 0.256V 57 | PROGRAMMABLEGAIN_PGA0_512 = 4, // Plus/minus 0.512V 58 | PROGRAMMABLEGAIN_PGA1_024V = 3, // Plus/minus 1.024V 59 | PROGRAMMABLEGAIN_PGA2_048V = 2, // Plus/minus 2.048V 60 | PROGRAMMABLEGAIN_PGA4_096V = 1, // Plus/minus 4.096V 61 | PROGRAMMABLEGAIN_PGA6_144V = 0 // Plus/minus 6.144V 62 | }; 63 | typedef enum ProgrammableGain ProgrammableGain_t; 64 | /* 65 | * Valid values for Setup sample rate for reading analog voltage 66 | 67 | */ 68 | enum SampleRate { 69 | SAMPLERATE_HZ128 = 0, // 128 samples/second 70 | SAMPLERATE_HZ1600 = 4, // 1600 samples/second 71 | SAMPLERATE_HZ2400 = 5, // 2400 samples/second 72 | SAMPLERATE_HZ250 = 1, // 250 samples/second 73 | SAMPLERATE_HZ3300 = 6, // 3300 samples/second 74 | SAMPLERATE_HZ490 = 2, // 490 samples/second 75 | SAMPLERATE_HZ920 = 3 // 920 samples/second 76 | }; 77 | typedef enum SampleRate SampleRate_t; 78 | 79 | int ads1015_init(char* bus_name); 80 | void ads1015_terminate(); 81 | /** 82 | * Describes the specifics of the sensing implementation 83 | 84 | */ 85 | int ads1015_readConfig(uint16_t* val); 86 | 87 | /** 88 | * Describes the specifics of the sensing implementation 89 | 90 | */ 91 | int ads1015_writeConfig(uint16_t* data);/** 92 | * Conversion register contains the result of the last conversion 93 | 94 | */ 95 | int ads1015_readConversion(uint16_t* val); 96 | 97 | 98 | /** 99 | * This bit controls the operating mode 100 | 101 | */ 102 | int ads1015_set_deviceoperatingmode(uint16_t* data); 103 | /** 104 | * This sets the programmable gain for reading analog voltage 105 | 106 | */ 107 | int ads1015_set_programmablegain(uint16_t* data); 108 | /** 109 | * This sets the samples-per-second value 110 | 111 | */ 112 | int ads1015_set_samplerate(uint16_t* data); 113 | 114 | /** 115 | * Reads the analog voltage in Volts 116 | 117 | */ 118 | void ads1015_analog_read(short* val, char channel); 119 | 120 | 121 | #endif -------------------------------------------------------------------------------- /test/sampleData/kubos/BH1750FVI.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2020 Google Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | * Auto-generated file for BH1750FVI v0.1.0. 17 | * Generated from peripherals/BH1750FVI.yaml using Cyanobyte Codegen v0.1.0 18 | * Class for BH1750FVI 19 | * Rohm Light Sensor 20 | 21 | */ 22 | 23 | #ifndef _BH1750FVI_H_ 24 | #define _BH1750FVI_H_ 25 | #include 26 | #include 27 | #include 28 | #include "i2c.h" 29 | 30 | 31 | enum deviceAddress { 32 | I2C_ADDRESS_35 = 35, 33 | I2C_ADDRESS_92 = 92 34 | }; 35 | typedef enum deviceAddress deviceAddress_t; 36 | 37 | int bh1750fvi_init(deviceAddress_t address, char* bus_name); 38 | void bh1750fvi_terminate(); 39 | 40 | /** 41 | * Start measurement at 0.5lx resolution. Typically 120ms. 42 | 43 | */ 44 | int bh1750fvi_writeContinuousHRes2Mode(); 45 | /** 46 | * Start measurement at 1lx resolution. Typically 120ms. 47 | 48 | */ 49 | int bh1750fvi_writeContinuousHResMode(); 50 | /** 51 | * Start measurement at 4lx resolution. Typically 16ms. 52 | 53 | */ 54 | int bh1750fvi_writeContinuouslyLResMode(); 55 | /** 56 | * Start measurement at 0.5lx resolution. Typically 120ms. 57 | * Power Down after measurement. 58 | 59 | */ 60 | int bh1750fvi_writeOnceHRes2Mode(); 61 | /** 62 | * Start measurement at 1lx resolution. Typically 120ms. 63 | * Power Down after measurement. 64 | 65 | */ 66 | int bh1750fvi_writeOnceHResMode(); 67 | /** 68 | * Start measurement at 4lx resolution. Typically 16ms. 69 | * Power Down after measurement. 70 | 71 | */ 72 | int bh1750fvi_writeOnceLResMode(); 73 | /** 74 | * No active state 75 | 76 | */ 77 | int bh1750fvi_writePowerDown(); 78 | /** 79 | * Waiting for measurement command 80 | 81 | */ 82 | int bh1750fvi_writePowerOn(); 83 | /** 84 | * Reset data register value. Not accepted in Power Down mode. 85 | 86 | */ 87 | int bh1750fvi_writeReset(); 88 | 89 | /** 90 | * Sends a POWER ON cmd to device 91 | 92 | */ 93 | void bh1750fvi__lifecycle_begin(); 94 | 95 | /** 96 | * Things you can do to device 97 | 98 | */ 99 | void bh1750fvi_command_powerdown(); 100 | /** 101 | * Things you can do to device 102 | 103 | */ 104 | void bh1750fvi_command_reset(); 105 | 106 | /** 107 | * Read light intensity from device 108 | 109 | */ 110 | void bh1750fvi_read_lightintensity(uint16_t* val); 111 | 112 | 113 | #endif -------------------------------------------------------------------------------- /test/sampleData/kubos/BMP180.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2020 Google Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | * Auto-generated file for BMP180 v0.1.0. 17 | * Generated from peripherals/BMP180.yaml using Cyanobyte Codegen v0.0.2 18 | * Class for BMP180 19 | * Bosch Digital Temperature / Pressure Sensor 20 | 21 | */ 22 | 23 | #ifndef _BMP180_H_ 24 | #define _BMP180_H_ 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include "i2c.h" 30 | 31 | #include 32 | 33 | 34 | int bmp180_init(char* bus_name); 35 | void bmp180_terminate(); 36 | 37 | /** 38 | * Register stores what the measurement type should be 39 | 40 | */ 41 | int bmp180_writeControl(uint8_t* data);/** 42 | * For calibration 43 | 44 | */ 45 | int bmp180_readPressureCalAC1(uint16_t* val); 46 | 47 | /** 48 | * For calibration 49 | 50 | */ 51 | int bmp180_readPressureCalAC2(uint16_t* val); 52 | 53 | /** 54 | * For calibration 55 | 56 | */ 57 | int bmp180_readPressureCalVB1(uint16_t* val); 58 | 59 | /** 60 | * For calibration 61 | 62 | */ 63 | int bmp180_readPressureCalVB2(uint16_t* val); 64 | 65 | /** 66 | * Register stores most recent measurement result 67 | 68 | */ 69 | int bmp180_readResult(uint16_t* val); 70 | 71 | /** 72 | * For calibration 73 | 74 | */ 75 | int bmp180_readTempCal3(uint16_t* val); 76 | 77 | /** 78 | * For calibration 79 | 80 | */ 81 | int bmp180_readTempCal4(uint16_t* val); 82 | 83 | /** 84 | * For calibration 85 | 86 | */ 87 | int bmp180_readTempCal5(uint16_t* val); 88 | 89 | /** 90 | * For calibration 91 | 92 | */ 93 | int bmp180_readTempCal6(uint16_t* val); 94 | 95 | /** 96 | * For calibration 97 | 98 | */ 99 | int bmp180_readTempCalMC(uint16_t* val); 100 | 101 | /** 102 | * For calibration 103 | 104 | */ 105 | int bmp180_readTempCalMD(uint16_t* val); 106 | 107 | 108 | 109 | /** 110 | * Reads the pressure in absolute millibars, 111 | * not compensated for sea level 112 | 113 | */ 114 | void bmp180_pressure_asmbars(float* val); 115 | 116 | /** 117 | * Reads the temperature 118 | 119 | */ 120 | void bmp180_temperature_ascelsius(float* val); 121 | 122 | 123 | #endif -------------------------------------------------------------------------------- /test/sampleData/kubos/BMP280.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2019 Google Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | * Auto-generated file for BMP280 v0.1.0. 17 | * Generated from peripherals/BMP280.yaml using Cyanobyte Codegen v0.1.0 18 | * Class for BMP280 19 | * Bosch Digital Pressure Sensor 20 | 21 | */ 22 | 23 | #ifndef _BMP280_H_ 24 | #define _BMP280_H_ 25 | #include 26 | #include 27 | #include 28 | #include "i2c.h" 29 | 30 | 31 | 32 | int bmp280_init(char* bus_name); 33 | void bmp280_terminate(); 34 | /** 35 | * Used for Pascals conversion 36 | 37 | */ 38 | int bmp280_readDigP1(uint16_t* val); 39 | 40 | /** 41 | * Used for Pascals conversion 42 | 43 | */ 44 | int bmp280_readDigP2(uint16_t* val); 45 | 46 | /** 47 | * Used for Pascals conversion 48 | 49 | */ 50 | int bmp280_readDigP3(uint16_t* val); 51 | 52 | /** 53 | * Used for Pascals conversion 54 | 55 | */ 56 | int bmp280_readDigP4(uint16_t* val); 57 | 58 | /** 59 | * Used for Pascals conversion 60 | 61 | */ 62 | int bmp280_readDigP5(uint16_t* val); 63 | 64 | /** 65 | * Used for Pascals conversion 66 | 67 | */ 68 | int bmp280_readDigP6(uint16_t* val); 69 | 70 | /** 71 | * Used for Pascals conversion 72 | 73 | */ 74 | int bmp280_readDigP7(uint16_t* val); 75 | 76 | /** 77 | * Used for Pascals conversion 78 | 79 | */ 80 | int bmp280_readDigP8(uint16_t* val); 81 | 82 | /** 83 | * Used for Pascals conversion 84 | 85 | */ 86 | int bmp280_readDigP9(uint16_t* val); 87 | 88 | /** 89 | * Used for Celcius conversion 90 | 91 | */ 92 | int bmp280_readDigT1(uint16_t* val); 93 | 94 | /** 95 | * Used for Celcius conversion 96 | 97 | */ 98 | int bmp280_readDigT2(uint16_t* val); 99 | 100 | /** 101 | * Used for Celcius conversion 102 | 103 | */ 104 | int bmp280_readDigT3(uint16_t* val); 105 | 106 | /** 107 | * Part 2 of Pressure 108 | 109 | */ 110 | int bmp280_readPressureLsb(uint8_t* val); 111 | 112 | /** 113 | * Part 1 of Pressure 114 | 115 | */ 116 | int bmp280_readPressureMsb(uint8_t* val); 117 | 118 | /** 119 | * Part 3 of Pressure 120 | 121 | */ 122 | int bmp280_readPressureXlsb(uint8_t* val); 123 | 124 | /** 125 | * Part 2 of temperature 126 | 127 | */ 128 | int bmp280_readTempLsb(uint8_t* val); 129 | 130 | /** 131 | * Part 1 of temperature 132 | 133 | */ 134 | int bmp280_readTempMsb(uint8_t* val); 135 | 136 | /** 137 | * Final part of temperature 138 | 139 | */ 140 | int bmp280_readTempXlsb(uint8_t* val); 141 | 142 | 143 | 144 | /** 145 | * Reads the atmospheric pressure 146 | 147 | */ 148 | void bmp280_pressure_ashpa(float* val); 149 | /** 150 | * Reads the atmospheric pressure 151 | 152 | */ 153 | void bmp280_pressure_asraw(long* val); 154 | 155 | /** 156 | * Reads the temperature 157 | 158 | */ 159 | void bmp280_temperature_ascelsius(float* val); 160 | /** 161 | * Reads the temperature 162 | 163 | */ 164 | void bmp280_temperature_asraw(long* val); 165 | 166 | 167 | #endif -------------------------------------------------------------------------------- /test/sampleData/kubos/Example.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2019 Google Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | * Auto-generated file for Example v0.1.0. 17 | * Generated from peripherals/example.yaml using Cyanobyte Codegen v0.1.0 18 | * Class for Example 19 | * Example of a package 20 | 21 | */ 22 | 23 | #ifndef _Example_H_ 24 | #define _Example_H_ 25 | #include 26 | #include 27 | #include 28 | #include "i2c.h" 29 | 30 | 31 | /* 32 | * Valid values for Write-only fields for RegisterA 33 | 34 | */ 35 | enum FieldB { 36 | FIELDB_VAL_1 = 1, // Value 1 37 | FIELDB_VAL_2 = 2, // Value 2 38 | FIELDB_VAL_3 = 4, // Value 3 39 | FIELDB_VAL_4 = 8 // Value 4 40 | }; 41 | typedef enum FieldB FieldB_t; 42 | enum deviceAddress { 43 | I2C_ADDRESS_16 = 16, 44 | I2C_ADDRESS_32 = 32, 45 | I2C_ADDRESS_48 = 48 46 | }; 47 | typedef enum deviceAddress deviceAddress_t; 48 | 49 | int example_init(deviceAddress_t address, char* bus_name); 50 | void example_terminate(); 51 | /** 52 | * An 8-bit register 53 | 54 | */ 55 | int example_readRegisterA(uint8_t* val); 56 | 57 | /** 58 | * An 8-bit register 59 | 60 | */ 61 | int example_writeRegisterA(uint8_t* data);/** 62 | * A 16-bit register 63 | 64 | */ 65 | int example_readRegisterB(uint16_t* val); 66 | 67 | /** 68 | * A 16-bit register 69 | 70 | */ 71 | int example_writeRegisterB(uint16_t* data);/** 72 | * A 32-bit register 73 | 74 | */ 75 | int example_readRegisterC(uint32_t* val); 76 | 77 | /** 78 | * A 32-bit register 79 | 80 | */ 81 | int example_writeRegisterC(uint32_t* data);/** 82 | * A dummy register that has no data 83 | 84 | */ 85 | int example_readRegisterD(uint8_t* val); 86 | 87 | /** 88 | * A dummy register that has no data 89 | 90 | */ 91 | int example_writeRegisterD(); 92 | /** 93 | * This is a few bits 94 | 95 | */ 96 | int example_get_fielda(uint8_t* val); 97 | /** 98 | * This is fewer bits 99 | 100 | */ 101 | int example_set_fieldb(uint8_t* data); 102 | /** 103 | * A single-bit 104 | 105 | */ 106 | int example_get_fieldc(uint8_t* val); 107 | /** 108 | * A single-bit 109 | 110 | */ 111 | int example_set_fieldc(uint8_t* data); 112 | 113 | /** 114 | * Enables features on device 115 | 116 | */ 117 | void example__lifecycle_begin(char* val); 118 | /** 119 | * Enables features on device 120 | 121 | */ 122 | void example__lifecycle_end(char* val); 123 | 124 | /** 125 | * Computes and returns 126 | 127 | */ 128 | void example_return_array(void* val); 129 | /** 130 | * Computes and returns 131 | 132 | */ 133 | void example_return_number(short* val); 134 | /** 135 | * Computes and returns 136 | 137 | */ 138 | void example_return_void(); 139 | 140 | 141 | #endif -------------------------------------------------------------------------------- /test/sampleData/kubos/LSM303D.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2019 Google Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | * Auto-generated file for LSM303D v0.1.0. 17 | * Generated from peripherals/LSM303D.yaml using Cyanobyte Codegen v0.1.0 18 | * Class for LSM303D 19 | * STMicroelectronics accelerometer and magnetometer 20 | 21 | */ 22 | 23 | #ifndef _LSM303D_H_ 24 | #define _LSM303D_H_ 25 | #include 26 | #include 27 | #include 28 | #include "i2c.h" 29 | 30 | #include 31 | 32 | 33 | int lsm303d_init(char* bus_name); 34 | void lsm303d_terminate(); 35 | /** 36 | * Raw accelerometer data on X plane 37 | 38 | */ 39 | int lsm303d_readAccelerometerX_High(uint8_t* val); 40 | 41 | /** 42 | * Raw accelerometer data on X plane 43 | 44 | */ 45 | int lsm303d_readAccelerometerX_Low(uint8_t* val); 46 | 47 | /** 48 | * Raw accelerometer data on Y plane 49 | 50 | */ 51 | int lsm303d_readAccelerometerY_High(uint8_t* val); 52 | 53 | /** 54 | * Raw accelerometer data on Y plane 55 | 56 | */ 57 | int lsm303d_readAccelerometerY_Low(uint8_t* val); 58 | 59 | /** 60 | * Raw accelerometer data on Z plane 61 | 62 | */ 63 | int lsm303d_readAccelerometerZ_High(uint8_t* val); 64 | 65 | /** 66 | * Raw accelerometer data on Z plane 67 | 68 | */ 69 | int lsm303d_readAccelerometerZ_Low(uint8_t* val); 70 | 71 | /** 72 | * Raw magnetometer data on X plane 73 | 74 | */ 75 | int lsm303d_readMagnetometerX_High(uint8_t* val); 76 | 77 | /** 78 | * Raw magnetometer data on X plane 79 | 80 | */ 81 | int lsm303d_readMagnetometerX_Low(uint8_t* val); 82 | 83 | /** 84 | * Raw magnetometer data on Y plane 85 | 86 | */ 87 | int lsm303d_readMagnetometerY_High(uint8_t* val); 88 | 89 | /** 90 | * Raw magnetometer data on Y plane 91 | 92 | */ 93 | int lsm303d_readMagnetometerY_Low(uint8_t* val); 94 | 95 | /** 96 | * Raw magnetometer data on Z plane 97 | 98 | */ 99 | int lsm303d_readMagnetometerZ_High(uint8_t* val); 100 | 101 | /** 102 | * Raw magnetometer data on Z plane 103 | 104 | */ 105 | int lsm303d_readMagnetometerZ_Low(uint8_t* val); 106 | 107 | 108 | 109 | /** 110 | * Measures the current acceleration 111 | 112 | */ 113 | void lsm303d_acceleration_asg(void* val); 114 | /** 115 | * Measures the current acceleration 116 | 117 | */ 118 | void lsm303d_acceleration_xplane(short* val); 119 | /** 120 | * Measures the current acceleration 121 | 122 | */ 123 | void lsm303d_acceleration_yplane(short* val); 124 | /** 125 | * Measures the current acceleration 126 | 127 | */ 128 | void lsm303d_acceleration_zplane(short* val); 129 | 130 | /** 131 | * Reads the magnetic orientation 132 | 133 | */ 134 | void lsm303d_orientation_heading(short* val); 135 | /** 136 | * Reads the magnetic orientation 137 | 138 | */ 139 | void lsm303d_orientation_xplane(short* val); 140 | /** 141 | * Reads the magnetic orientation 142 | 143 | */ 144 | void lsm303d_orientation_yplane(short* val); 145 | /** 146 | * Reads the magnetic orientation 147 | 148 | */ 149 | void lsm303d_orientation_zplane(short* val); 150 | 151 | 152 | #endif -------------------------------------------------------------------------------- /test/sampleData/kubos/MCP4725.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2019 Google Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | * Auto-generated file for MCP4725 v0.1.0. 17 | * Generated from peripherals/MCP4725.yaml using Cyanobyte Codegen v0.1.0 18 | * Class for MCP4725 19 | * Microchip 4725 Digital-to-Analog Converter 20 | 21 | */ 22 | 23 | #ifndef _MCP4725_H_ 24 | #define _MCP4725_H_ 25 | #include 26 | #include 27 | #include 28 | #include "i2c.h" 29 | 30 | 31 | /* 32 | * Valid values for Digital (binary) output 33 | 34 | */ 35 | enum digitalOut { 36 | DIGITALOUT_GND = 0, // Ground 37 | DIGITALOUT_VCC = 4095 // Vcc (full power) 38 | }; 39 | typedef enum digitalOut digitalOut_t; 40 | 41 | int mcp4725_init(char* bus_name); 42 | void mcp4725_terminate(); 43 | /** 44 | * If EEPROM is set, the saved voltage output will 45 | * be loaded from power-on. 46 | 47 | */ 48 | int mcp4725_readEEPROM(uint16_t* val); 49 | 50 | /** 51 | * If EEPROM is set, the saved voltage output will 52 | * be loaded from power-on. 53 | 54 | */ 55 | int mcp4725_writeEEPROM(uint16_t* data);/** 56 | * VOut = (Vcc * value) / 4096 57 | * The output is a range between 0 and Vcc with 58 | * steps of Vcc/4096. 59 | * In a 3.3v system, each step is 800 microvolts. 60 | 61 | */ 62 | int mcp4725_readVOut(uint16_t* val); 63 | 64 | /** 65 | * VOut = (Vcc * value) / 4096 66 | * The output is a range between 0 and Vcc with 67 | * steps of Vcc/4096. 68 | * In a 3.3v system, each step is 800 microvolts. 69 | 70 | */ 71 | int mcp4725_writeVOut(uint16_t* data); 72 | /** 73 | * Only allows you to send fully on or off 74 | 75 | */ 76 | int mcp4725_get_digitalout(uint16_t* val); 77 | /** 78 | * Only allows you to send fully on or off 79 | 80 | */ 81 | int mcp4725_set_digitalout(uint16_t* data); 82 | 83 | /** 84 | * get vout 85 | 86 | */ 87 | void mcp4725_getvout_asvoltage(float* val, float vcc); 88 | 89 | /** 90 | * set vout 91 | 92 | */ 93 | void mcp4725_setvout_asvoltage( float output, float vcc); 94 | 95 | 96 | #endif -------------------------------------------------------------------------------- /test/sampleData/kubos/MCP9808.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2019 Google Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | * Auto-generated file for MCP9808 v0.1.0. 17 | * Generated from peripherals/MCP9808.yaml using Cyanobyte Codegen v0.1.0 18 | * Class for MCP9808 19 | * This is a test description 20 | 21 | */ 22 | 23 | 24 | 25 | 26 | #include "MCP9808.h" 27 | 28 | #define REGISTER_CONFIGURATION 1 29 | 30 | static int i2c_bus = 0; // Pointer to bus 31 | 32 | // Provide `bus_name` based on application specifics. 33 | // For example, you may pass in bus name "/dev/i2c-1" 34 | static deviceAddress_t DEVICE_ADDRESS; 35 | 36 | int mcp9808_init(deviceAddress_t address, char* bus_name) { 37 | DEVICE_ADDRESS = address; 38 | // Initialize bus 39 | if (k_i2c_init(&bus_name, &i2c_bus) != I2C_OK) { 40 | return -1; 41 | } 42 | } 43 | 44 | void mcp9808_terminate() { 45 | k_i2c_terminate(&i2c_bus); 46 | } 47 | 48 | int mcp9808_readconfiguration(uint16_t* val) { 49 | if (val == NULL) { 50 | return -1; // Need to provide a valid value pointer 51 | } 52 | if (k_i2c_read(i2c_bus, DEVICE_ADDRESS, val, 2) != I2C_OK) { 53 | return -2; 54 | } 55 | return 0; 56 | } 57 | 58 | int mcp9808_writeconfiguration(uint16_t* data) { 59 | // Put our data into uint8_t buffer 60 | uint8_t buffer[3] = { (uint8_t) REGISTER_CONFIGURATION }; 61 | uint8_t buffer[1] = (data >> 16) & 0xFF; 62 | uint8_t buffer[2] = (data >> 8) & 0xFF; 63 | // First write our register address 64 | if (k_i2c_write(i2c_bus, DEVICE_ADDRESS, buffer, 3) != I2C_OK) { 65 | return -1; 66 | } 67 | return 0; 68 | } 69 | int mcp9808_get_limithysteresis(uint16_t* val) { 70 | // Read register data 71 | // '#/registers/configuration' > 'configuration' 72 | int result = mcp9808_readconfiguration(val); 73 | if (result != 0) { 74 | return result; 75 | } 76 | // Mask register value 77 | val = val & 0b0000011000000000; 78 | // Bitshift value 79 | val = val >> 9; 80 | return 0; 81 | } 82 | int mcp9808_get_shutdownmode(uint16_t* val) { 83 | // Read register data 84 | // '#/registers/configuration' > 'configuration' 85 | int result = mcp9808_readconfiguration(val); 86 | if (result != 0) { 87 | return result; 88 | } 89 | // Mask register value 90 | val = val & 0b0000000100000000; 91 | // Bitshift value 92 | val = val >> 8; 93 | return 0; 94 | } 95 | 96 | -------------------------------------------------------------------------------- /test/sampleData/kubos/TCS3472.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2019 Google Inc. 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | * 16 | * Auto-generated file for TCS3472 v0.1.0. 17 | * Generated from peripherals/TCS3472.yaml using Cyanobyte Codegen v0.1.0 18 | * Class for TCS3472 19 | * Color Light-to-Digital Converter with IR Filter 20 | 21 | */ 22 | 23 | #ifndef _TCS3472_H_ 24 | #define _TCS3472_H_ 25 | #include 26 | #include 27 | #include 28 | #include "i2c.h" 29 | 30 | 31 | /* 32 | * Valid values for Setup the device configuration 33 | 34 | */ 35 | enum init { 36 | INIT_POWER = 1, // Power 37 | INIT_RGBC = 2 // Color 38 | }; 39 | typedef enum init init_t; 40 | 41 | int tcs3472_init(char* bus_name); 42 | void tcs3472_terminate(); 43 | /** 44 | * Blue light as an int. Divide by ambient light to get scaled number. 45 | 46 | */ 47 | int tcs3472_readblue(uint16_t* val); 48 | 49 | /** 50 | * This is the ambient amount of detected light. 51 | 52 | */ 53 | int tcs3472_readclear(uint16_t* val); 54 | 55 | /** 56 | * Enable specific components of the peripheral 57 | 58 | */ 59 | int tcs3472_readenable(uint8_t* val); 60 | 61 | /** 62 | * Enable specific components of the peripheral 63 | 64 | */ 65 | int tcs3472_writeenable(uint8_t* data);/** 66 | * Green light as an int. Divide by ambient light to get scaled number. 67 | 68 | */ 69 | int tcs3472_readgreen(uint16_t* val); 70 | 71 | /** 72 | * Red light as an int. Divide by ambient light to get scaled number. 73 | 74 | */ 75 | int tcs3472_readred(uint16_t* val); 76 | 77 | 78 | /** 79 | * Enable RGBC and Power 80 | 81 | */ 82 | int tcs3472_get_init(uint8_t* val); 83 | /** 84 | * Enable RGBC and Power 85 | 86 | */ 87 | int tcs3472_set_init(uint8_t* data); 88 | 89 | /** 90 | * Enables features on device 91 | 92 | */ 93 | void tcs3472__lifecycle_begin(); 94 | 95 | 96 | #endif -------------------------------------------------------------------------------- /test/sampleData/markdown/ADS1015.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: "ADS1015" 3 | linkTitle: "ADS1015" 4 | weight: 4 5 | description: > 6 | Texas Instruments Analog-Digital Converter 7 | --- 8 | 9 | 10 | ## Device Details 11 | 12 | * Device address 73 13 | * Address type 7-bit 14 | * Little Endian 15 | 16 | ## Registers 17 | 18 | ### Config 19 | **ADC config** 20 | * Address 1 21 | * 16-bytes 22 | 23 | Defines sensing implementation and options. 24 | 25 | ### Conversion 26 | **ADC Value** 27 | * Address 0 28 | * 16-bytes 29 | * Read-only 30 | 31 | Contains the result of the last conversion. 32 | 33 | ## Fields 34 | ### #/registers/Config/Channel 35 | **Channel to read** 36 | 37 | * Bits 14:12 38 | 39 | 40 | #### Field values 41 | 42 | * **0**: Channel 1 43 | * **1**: Channel 2 44 | * **2**: Channel 3 45 | * **3**: Channel 4 46 | 47 | Sets the channel for reading analog voltage. 48 | 49 | 50 | ### #/registers/Config/DeviceOperatingMode 51 | **Operating mode** 52 | 53 | * Bit 8 54 | 55 | 56 | #### Field values 57 | 58 | * **0**: Continuous Conversion 59 | * **1**: Single-shot or power-down state 60 | 61 | Controls the operating mode for reading analog voltage. 62 | 63 | 64 | ### #/registers/Config/ProgrammableGain 65 | **Programmable gain** 66 | 67 | * Bits 11:9 68 | 69 | 70 | #### Field values 71 | 72 | * **5**: Plus/minus 0.256V 73 | * **4**: Plus/minus 0.512V 74 | * **3**: Plus/minus 1.024V 75 | * **2**: Plus/minus 2.048V 76 | * **1**: Plus/minus 4.096V 77 | * **0**: Plus/minus 6.144V 78 | 79 | Sets the programmable gain for reading analog voltage in voltage. 80 | 81 | 82 | ### #/registers/Config/SampleRate 83 | **Sample rate** 84 | 85 | * Bits 7:5 86 | 87 | 88 | #### Field values 89 | 90 | * **0**: 128 samples/second 91 | * **4**: 1600 samples/second 92 | * **5**: 2400 samples/second 93 | * **1**: 250 samples/second 94 | * **6**: 3300 samples/second 95 | * **2**: 490 samples/second 96 | * **3**: 920 samples/second 97 | 98 | Sets the sample read in samples-per-second for reading analog voltage. 99 | 100 | 101 | 102 | ## Functions 103 | 104 | * **analog**: Reads the analog voltage in Volts. 105 | 106 | ## License 107 | 108 | _ADS1015 version 0.1.0. Generated from Cyanobyte Codegen version 0.0.2._ 109 | 110 | Contact [Nick Felker](mailto:felker@google.com). 111 | 112 | Copyright Google Inc. 2019. Published under 113 | [Apache-2.0](https://spdx.org/licenses/Apache-2.0.html#licenseText). -------------------------------------------------------------------------------- /test/sampleData/markdown/BH1750FVI.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: "BH1750FVI" 3 | linkTitle: "BH1750FVI" 4 | weight: 4 5 | description: > 6 | Rohm Light Sensor 7 | --- 8 | 9 | 10 | ## Device Details 11 | 12 | * Device addresses: 13 | 35, 14 | 92 15 | * Address type 7-bit 16 | 17 | ## Registers 18 | 19 | ### ContinuousHRes2Mode 20 | **Continously High-Resolution Mode 2** 21 | * Address 17 22 | * 0-bytes 23 | * Write-only 24 | 25 | Start measurement at 0.5lx resolution. Typically 120ms. 26 | 27 | ### ContinuousHResMode 28 | **Continuously High-Resolution Mode** 29 | * Address 16 30 | * 0-bytes 31 | * Write-only 32 | 33 | Start measurement at 1lx resolution. Typically 120ms. 34 | 35 | ### ContinuouslyLResMode 36 | **Continuously Low-Resolution Mode** 37 | * Address 19 38 | * 0-bytes 39 | * Write-only 40 | 41 | Start measurement at 4lx resolution. Typically 16ms. 42 | 43 | ### OnceHRes2Mode 44 | **One Time High-Resolution Mode2** 45 | * Address 33 46 | * 0-bytes 47 | * Write-only 48 | 49 | Start measurement at 0.5lx resolution. Typically 120ms. 50 | Power Down after measurement. 51 | 52 | 53 | ### OnceHResMode 54 | **One Time High-Resolution Mode** 55 | * Address 32 56 | * 0-bytes 57 | * Write-only 58 | 59 | Start measurement at 1lx resolution. Typically 120ms. 60 | Power Down after measurement. 61 | 62 | 63 | ### OnceLResMode 64 | **One Time Low-Resolution Mode** 65 | * Address 35 66 | * 0-bytes 67 | * Write-only 68 | 69 | Start measurement at 4lx resolution. Typically 16ms. 70 | Power Down after measurement. 71 | 72 | 73 | ### PowerDown 74 | **Power Down** 75 | * Address 0 76 | * 0-bytes 77 | * Write-only 78 | 79 | State when the device is not active. 80 | 81 | ### PowerOn 82 | **Power On** 83 | * Address 1 84 | * 0-bytes 85 | * Write-only 86 | 87 | State when device is on and waiting measurement command. 88 | 89 | ### Reset 90 | **Reset** 91 | * Address 7 92 | * 0-bytes 93 | * Write-only 94 | 95 | Reset data register value. Not accepted in Power Down mode. 96 | 97 | 98 | ## Functions 99 | 100 | * **_lifecycle**: Sends a POWER ON cmd to device. 101 | * **command**: Commands that can be sent to the device. 102 | * **read**: Read light intensity from device. 103 | 104 | ## License 105 | 106 | _BH1750FVI version 0.1.0. Generated from Cyanobyte Codegen version 0.0.2._ 107 | 108 | Contact [Nick Felker](mailto:felker@google.com). 109 | 110 | Copyright Google Inc. 2020. Published under 111 | [Apache-2.0](https://spdx.org/licenses/Apache-2.0.html#licenseText). -------------------------------------------------------------------------------- /test/sampleData/markdown/BMP180.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: "BMP180" 3 | linkTitle: "BMP180" 4 | weight: 4 5 | description: > 6 | Bosch Digital Temperature / Pressure Sensor 7 | --- 8 | 9 | 10 | ## Device Details 11 | 12 | * Device address 119 13 | * Address type 7-bit 14 | 15 | ## Registers 16 | 17 | ### Control 18 | **Command register.** 19 | * Address 244 20 | * 8-bytes 21 | * Write-only 22 | 23 | Stores the current measurement type. 24 | 25 | ### PressureCalAC1 26 | **Pressure calibration AC1** 27 | * Address 170 28 | * 16-bytes 29 | * Read-only 30 | 31 | Constant register for pressure measurement calibration. 32 | 33 | ### PressureCalAC2 34 | **Pressure calibration AC2** 35 | * Address 172 36 | * 16-bytes 37 | * Read-only 38 | 39 | Constant register for pressure measurement calibration. 40 | 41 | ### PressureCalVB1 42 | **Pressure calibration VB1** 43 | * Address 182 44 | * 16-bytes 45 | * Read-only 46 | 47 | Constant register for pressure measurement calibration. 48 | 49 | ### PressureCalVB2 50 | **Pressure calibration VB2** 51 | * Address 184 52 | * 16-bytes 53 | * Read-only 54 | 55 | Constant register for pressure measurement calibration. 56 | 57 | ### Result 58 | **Measurement results** 59 | * Address 246 60 | * 16-bytes 61 | * Read-only 62 | 63 | Stores the most recent measurement result. 64 | 65 | ### TempCal3 66 | **Temperature calibration 3** 67 | * Address 174 68 | * 16-bytes 69 | * Read-only 70 | 71 | Third constant register for temperature measurement calibration. 72 | 73 | ### TempCal4 74 | **Temperature calibration 4** 75 | * Address 176 76 | * 16-bytes 77 | * Read-only 78 | 79 | Fourth constant register for temperature measurement calibration. 80 | 81 | ### TempCal5 82 | **Temperature calibration 5** 83 | * Address 178 84 | * 16-bytes 85 | * Read-only 86 | 87 | Fifth constant register for temperature measurement calibration. 88 | 89 | ### TempCal6 90 | **Temperature calibration 6** 91 | * Address 180 92 | * 16-bytes 93 | * Read-only 94 | 95 | Sixth constant register for temperature measurement calibration. 96 | 97 | ### TempCalMC 98 | **Temperature calibration MC** 99 | * Address 188 100 | * 16-bytes 101 | * Read-only 102 | 103 | Constant register for temperature measurement calibration. 104 | 105 | ### TempCalMD 106 | **Temperature calibration MD** 107 | * Address 190 108 | * 16-bytes 109 | * Read-only 110 | 111 | Constant register for temperature measurement calibration. 112 | 113 | 114 | ## Functions 115 | 116 | * **temperature**: Reads the temperature as a raw value or in Celsius. 117 | 118 | ## License 119 | 120 | _BMP180 version 0.1.0. Generated from Cyanobyte Codegen version 0.0.2._ 121 | 122 | Contact [Nick Felker](mailto:felker@google.com). 123 | 124 | Copyright Google Inc. 2020. Published under 125 | [Apache-2.0](https://spdx.org/licenses/Apache-2.0.html#licenseText). -------------------------------------------------------------------------------- /test/sampleData/markdown/Example.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: "Example" 3 | linkTitle: "Example" 4 | weight: 4 5 | description: > 6 | Example of a package 7 | --- 8 | 9 | ## Registers 10 | 11 | ### First example 12 | An 8-bit register 13 | 14 | ### Second example 15 | A 16-bit register 16 | 17 | ### Third example 18 | A 32-bit register 19 | 20 | ### Fourth example 21 | A dummy register that has no data 22 | 23 | ## License 24 | Licensed under [Apache-2.0](https://spdx.org/licenses/Apache-2.0.html#licenseText). 25 | 26 | _Example version 0.1.0_ 27 | 28 | _Based on Cyanobyte spec version 0.1.0_ 29 | 30 | _Generated from Cyanobyte Codegen version 0.1.0_ -------------------------------------------------------------------------------- /test/sampleData/markdown/LSM303D.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: "LSM303D" 3 | linkTitle: "LSM303D" 4 | weight: 4 5 | description: > 6 | STMicroelectronics accelerometer and magnetometer 7 | --- 8 | 9 | 10 | ## Device Details 11 | 12 | * Device address 29 13 | * Address type 7-bit 14 | 15 | ## Registers 16 | 17 | ### AccelerometerX_High 18 | **Accelerometer X-Axis MSB** 19 | * Address 169 20 | * 8-bytes 21 | * Read-only 22 | 23 | Most-significant bits for raw accelerometer data on X plane. 24 | 25 | ### AccelerometerX_Low 26 | **Accelerometer X-Axis LSB** 27 | * Address 168 28 | * 8-bytes 29 | * Read-only 30 | 31 | Least-significant bits for raw accelerometer data on X plane. 32 | 33 | ### AccelerometerY_High 34 | **Accelerometer Y-Axis MSB** 35 | * Address 171 36 | * 8-bytes 37 | * Read-only 38 | 39 | Most-significant bits for raw accelerometer data on Y plane. 40 | 41 | ### AccelerometerY_Low 42 | **Accelerometer Y-Axis LSB** 43 | * Address 170 44 | * 8-bytes 45 | * Read-only 46 | 47 | Least-significant bits for raw accelerometer data on Y plane. 48 | 49 | ### AccelerometerZ_High 50 | **Accelerometer Z-Axis MSB** 51 | * Address 173 52 | * 8-bytes 53 | * Read-only 54 | 55 | Most-significant bits for raw accelerometer data on Z plane. 56 | 57 | ### AccelerometerZ_Low 58 | **Accelerometer Z-Axis LSB** 59 | * Address 172 60 | * 8-bytes 61 | * Read-only 62 | 63 | Least-significant bits for raw accelerometer data on Z plane. 64 | 65 | ### MagnetometerX_High 66 | **Magnetometer X-Axis MSB** 67 | * Address 137 68 | * 8-bytes 69 | * Read-only 70 | 71 | Most-significant bits for raw magnetometer data on X plane. 72 | 73 | ### MagnetometerX_Low 74 | **Magnetometer X-Axis LSB** 75 | * Address 136 76 | * 8-bytes 77 | * Read-only 78 | 79 | Least-significant bits for raw magnetometer data on X plane. 80 | 81 | ### MagnetometerY_High 82 | **Magnetometer Y-Axis MSB** 83 | * Address 139 84 | * 8-bytes 85 | * Read-only 86 | 87 | Most-significant bits for raw magnetometer data on Y plane. 88 | 89 | ### MagnetometerY_Low 90 | **Magnetometer Y-Axis LSB** 91 | * Address 138 92 | * 8-bytes 93 | * Read-only 94 | 95 | Least-significant bits for raw magnetometer data on Y plane. 96 | 97 | ### MagnetometerZ_High 98 | **Magnetometer Z-Axis MSB** 99 | * Address 141 100 | * 8-bytes 101 | * Read-only 102 | 103 | Most-significant bits for raw magnetometer data on Z plane. 104 | 105 | ### MagnetometerZ_Low 106 | **Magnetometer Z-Axis LSB** 107 | * Address 140 108 | * 8-bytes 109 | * Read-only 110 | 111 | Least-significant bits for raw magnetometer data on Z plane. 112 | 113 | 114 | ## Functions 115 | 116 | * **acceleration**: Measures the current acceleration for each plane. 117 | * **orientation**: Reads the magnetic orientation for each plane and compass heading. 118 | 119 | ## License 120 | 121 | _LSM303D version 0.1.0. Generated from Cyanobyte Codegen version 0.0.2._ 122 | 123 | Contact [Nick Felker](mailto:felker@google.com). 124 | 125 | Copyright Google Inc. 2019. Published under 126 | [Apache-2.0](https://spdx.org/licenses/Apache-2.0.html#licenseText). -------------------------------------------------------------------------------- /test/sampleData/markdown/MCP4725.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: "MCP4725" 3 | linkTitle: "MCP4725" 4 | weight: 4 5 | description: > 6 | Microchip Digital-to-Analog Converter 7 | --- 8 | 9 | 10 | ## Device Details 11 | 12 | * Device address 98 13 | * Address type 7-bit 14 | * Little Endian 15 | 16 | ## Registers 17 | 18 | ### EEPROM 19 | **EEPROM** 20 | * Address 96 21 | * 12-bytes 22 | 23 | If EEPROM is set, the saved voltage output will 24 | be loaded from power-on. 25 | 26 | 27 | ### VOut 28 | **Output voltage** 29 | * Address 64 30 | * 12-bytes 31 | 32 | Sets the output voltage relative to Vcc. 33 | VOut = (Vcc * value) / 4096. 34 | The output is a range between 0 and Vcc with 35 | steps of Vcc/4096. 36 | In a 3.3v system, each step is 800 microvolts. 37 | 38 | 39 | ## Fields 40 | ### #/registers/EEPROM/digitalOut 41 | **Digital (binary) output** 42 | 43 | * Bits 12:0 44 | 45 | 46 | #### Field values 47 | 48 | * **0**: Ground 49 | * **4095**: Vcc (full power) 50 | 51 | Set output as either fully on or fully off. 52 | 53 | 54 | 55 | ## Functions 56 | 57 | * **getVOut**: Read VOut from EEPROM as a function of Vcc. 58 | * **setVOut**: Set VOut as a function of Vcc. 59 | 60 | ## License 61 | 62 | _MCP4725 version 0.1.0. Generated from Cyanobyte Codegen version 0.0.2._ 63 | 64 | Contact [Nick Felker](mailto:felker@google.com). 65 | 66 | Copyright Google Inc. 2019. Published under 67 | [Apache-2.0](https://spdx.org/licenses/Apache-2.0.html#licenseText). -------------------------------------------------------------------------------- /test/sampleData/markdown/MCP9808.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: "MCP9808" 3 | linkTitle: "MCP9808" 4 | weight: 4 5 | description: > 6 | Microchip Temperature Sensor 7 | --- 8 | 9 | 10 | ## Device Details 11 | 12 | * Device addresses: 13 | 24, 14 | 25, 15 | 26, 16 | 27, 17 | 28, 18 | 29, 19 | 30, 20 | 31 21 | * Address type 7-bit 22 | 23 | ## Registers 24 | 25 | ### configuration 26 | **Configuration Register** 27 | * Address 1 28 | * 16-bytes 29 | 30 | The MCP9808 has a 16-bit Configuration register (CONFIG) that 31 | allows the user to set various functions for a robust temperature 32 | monitoring system. 33 | Bits 10 through 0 are used to select the temperature alert output 34 | hysteresis, device shutdown or Low-Power mode, temperature boundary 35 | and critical temperature lock, and temperature Alert output 36 | enable/disable. 37 | In addition, Alert output condition (output set for TUPPER and 38 | TLOWER temperature boundary or TCRIT only), Alert output status 39 | and Alert output polarity and mode (Comparator Output or Interrupt 40 | Output mode) are user-configurable. 41 | 42 | 43 | ## Fields 44 | ### #/registers/configuration/limitHysteresis 45 | **TUPPER and TLOWER Limit Hysteresis bits** 46 | 47 | * Bits 10:9 48 | 49 | 50 | #### Field values 51 | 52 | * **0**: 0°C (power-up default) 53 | * **1**: +1.5°C 54 | * **2**: +3.0°C 55 | * **3**: +6.0°C 56 | 57 | This bit can not be altered when either of the Lock bits are set 58 | (bit 6 and bit 7). This bit can be programmed in Shutdown mode. 59 | 60 | 61 | ### #/registers/configuration/shutdownMode 62 | **Shutdown Mode bit** 63 | 64 | * Bit 8 65 | 66 | 67 | #### Field values 68 | 69 | * **0**: Continuous conversion (power-up default) 70 | * **1**: Shutdown (Low-Power mode) 71 | 72 | In shutdown, all power-consuming activities are disabled, though 73 | all registers can be written to or read. This bit cannot be set 74 | to ‘1’ when either of the Lock bits is set (bit 6 and bit 7). 75 | However, it can be cleared to ‘0’ for continuous conversion while 76 | locked. 77 | 78 | 79 | 80 | 81 | ## License 82 | 83 | _MCP9808 version 0.1.0. Generated from Cyanobyte Codegen version 0.0.2._ 84 | 85 | Contact [Nick Felker](mailto:felker@google.com). 86 | 87 | Copyright Google Inc. 2019. Published under 88 | [Apache-2.0](https://spdx.org/licenses/Apache-2.0.html#licenseText). -------------------------------------------------------------------------------- /test/sampleData/markdown/TCS3472.md: -------------------------------------------------------------------------------- 1 | --- 2 | title: "TCS3472" 3 | linkTitle: "TCS3472" 4 | weight: 4 5 | description: > 6 | Color Light-to-Digital Converter with IR Filter 7 | --- 8 | 9 | 10 | ## Device Details 11 | 12 | * Device address 41 13 | * Address type 7-bit 14 | 15 | ## Registers 16 | 17 | ### Blue 18 | **Blue channel** 19 | * Address 186 20 | * 16-bytes 21 | * Read-only 22 | 23 | Blue light as an int. Divide by ambient light to get scaled number. 24 | 25 | ### Clear 26 | **Clear channel** 27 | * Address 180 28 | * 16-bytes 29 | * Read-only 30 | 31 | This is the ambient amount of detected light. 32 | 33 | ### Enable 34 | **Enable** 35 | * Address 128 36 | * 8-bytes 37 | 38 | Enable specific components of the peripheral 39 | 40 | ### Green 41 | **Green channel** 42 | * Address 184 43 | * 16-bytes 44 | * Read-only 45 | 46 | Green light as an int. Divide by ambient light to get scaled number. 47 | 48 | ### Red 49 | **Red channel** 50 | * Address 182 51 | * 16-bytes 52 | * Read-only 53 | 54 | Red light as an int. Divide by ambient light to get scaled number. 55 | 56 | ## Fields 57 | ### #/registers/Enable/init 58 | **Setup the device configuration** 59 | 60 | * Bits 7:0 61 | 62 | 63 | #### Field values 64 | 65 | * **1**: Power 66 | * **2**: Color 67 | 68 | Enable RGBC and Power. 69 | 70 | 71 | ## Functions 72 | 73 | * **_lifecycle**: Enables features on device. 74 | 75 | ## License 76 | 77 | _TCS3472 version 0.1.0. Generated from Cyanobyte Codegen version 0.0.2._ 78 | 79 | Contact [Nick Felker](mailto:felker@google.com). 80 | 81 | Copyright Google Inc. 2019. Published under 82 | [Apache-2.0](https://spdx.org/licenses/Apache-2.0.html#licenseText). -------------------------------------------------------------------------------- /test/sampleData/validator/blank.yaml: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/google/cyanobyte/5a6e90440e386dd478084a6c0946fdb88eb8c5a8/test/sampleData/validator/blank.yaml -------------------------------------------------------------------------------- /test/sampleData/validator/i2c/missing_address.yaml: -------------------------------------------------------------------------------- 1 | cyanobyte: 0.1.0 2 | info: 3 | title: Valid Info 4 | description: This is a minimal example with valid info. 5 | contact: 6 | name: 'Joe Smith' 7 | url: 'http://example.com' 8 | email: 'joe@example.com' 9 | license: 10 | name: 'Apache 2.0' 11 | url: 'https://www.apache.org/licenses/LICENSE-2.0.html' 12 | version: 0.1.0 13 | i2c: 14 | addressType: '7-bit' 15 | addressMask: 0x78 -------------------------------------------------------------------------------- /test/sampleData/validator/i2c/missing_address_mask.yaml: -------------------------------------------------------------------------------- 1 | cyanobyte: 0.1.0 2 | info: 3 | title: Valid Info 4 | description: This is a minimal example with valid info. 5 | contact: 6 | name: 'Joe Smith' 7 | url: 'http://example.com' 8 | email: 'joe@example.com' 9 | license: 10 | name: 'Apache 2.0' 11 | url: 'https://www.apache.org/licenses/LICENSE-2.0.html' 12 | version: 0.1.0 13 | i2c: 14 | addressType: '7-bit' 15 | address: 0x18 -------------------------------------------------------------------------------- /test/sampleData/validator/i2c/missing_address_type.yaml: -------------------------------------------------------------------------------- 1 | cyanobyte: 0.1.0 2 | info: 3 | title: Valid Info 4 | description: This is a minimal example with valid info. 5 | contact: 6 | name: 'Joe Smith' 7 | url: 'http://example.com' 8 | email: 'joe@example.com' 9 | license: 10 | name: 'Apache 2.0' 11 | url: 'https://www.apache.org/licenses/LICENSE-2.0.html' 12 | version: 0.1.0 13 | i2c: 14 | address: 0x18 15 | addressMask: 0x78 -------------------------------------------------------------------------------- /test/sampleData/validator/i2c/valid.yaml: -------------------------------------------------------------------------------- 1 | cyanobyte: 0.1.0 2 | info: 3 | title: Valid Info 4 | description: This is a minimal example with valid info. 5 | contact: 6 | name: 'Joe Smith' 7 | url: 'http://example.com' 8 | email: 'joe@example.com' 9 | license: 10 | name: 'Apache 2.0' 11 | url: 'https://www.apache.org/licenses/LICENSE-2.0.html' 12 | version: 0.1.0 13 | i2c: 14 | addressType: '7-bit' 15 | address: 0x18 16 | addressMask: 0x78 -------------------------------------------------------------------------------- /test/sampleData/validator/info/missing_contact.yaml: -------------------------------------------------------------------------------- 1 | cyanobyte: 0.1.0 2 | info: 3 | title: Valid Info 4 | description: This is a minimal example with valid info. 5 | license: 6 | name: 'Apache 2.0' 7 | url: 'https://www.apache.org/licenses/LICENSE-2.0.html' 8 | version: 0.1.0 -------------------------------------------------------------------------------- /test/sampleData/validator/info/missing_contact_email.yaml: -------------------------------------------------------------------------------- 1 | cyanobyte: 0.1.0 2 | info: 3 | title: Valid Info 4 | description: This is a minimal example with valid info. 5 | contact: 6 | name: 'Joe Smith' 7 | url: 'http://example.com' 8 | license: 9 | name: 'Apache 2.0' 10 | url: 'https://www.apache.org/licenses/LICENSE-2.0.html' 11 | version: 0.1.0 -------------------------------------------------------------------------------- /test/sampleData/validator/info/missing_contact_name.yaml: -------------------------------------------------------------------------------- 1 | cyanobyte: 0.1.0 2 | info: 3 | title: Valid Info 4 | description: This is a minimal example with valid info. 5 | contact: 6 | url: 'http://example.com' 7 | email: 'joe@example.com' 8 | license: 9 | name: 'Apache 2.0' 10 | url: 'https://www.apache.org/licenses/LICENSE-2.0.html' 11 | version: 0.1.0 -------------------------------------------------------------------------------- /test/sampleData/validator/info/missing_contact_url.yaml: -------------------------------------------------------------------------------- 1 | cyanobyte: 0.1.0 2 | info: 3 | title: Valid Info 4 | description: This is a minimal example with valid info. 5 | contact: 6 | name: 'Joe Smith' 7 | email: 'joe@example.com' 8 | license: 9 | name: 'Apache 2.0' 10 | url: 'https://www.apache.org/licenses/LICENSE-2.0.html' 11 | version: 0.1.0 -------------------------------------------------------------------------------- /test/sampleData/validator/info/missing_cyanobyte_version.yaml: -------------------------------------------------------------------------------- 1 | info: 2 | title: Valid Info 3 | description: This is a minimal example with valid info. 4 | contact: 5 | name: 'Joe Smith' 6 | url: 'http://example.com' 7 | email: 'joe@example.com' 8 | license: 9 | name: 'Apache 2.0' 10 | url: 'https://www.apache.org/licenses/LICENSE-2.0.html' 11 | version: 0.1.0 -------------------------------------------------------------------------------- /test/sampleData/validator/info/missing_description.yaml: -------------------------------------------------------------------------------- 1 | cyanobyte: 0.1.0 2 | info: 3 | title: Valid Info 4 | contact: 5 | name: 'Joe Smith' 6 | url: 'http://example.com' 7 | email: 'joe@example.com' 8 | license: 9 | name: 'Apache 2.0' 10 | url: 'https://www.apache.org/licenses/LICENSE-2.0.html' 11 | version: 0.1.0 -------------------------------------------------------------------------------- /test/sampleData/validator/info/missing_info.yaml: -------------------------------------------------------------------------------- 1 | cyanobyte: 0.1.0 -------------------------------------------------------------------------------- /test/sampleData/validator/info/missing_license.yaml: -------------------------------------------------------------------------------- 1 | cyanobyte: 0.1.0 2 | info: 3 | title: Valid Info 4 | description: This is a minimal example with valid info. 5 | contact: 6 | name: 'Joe Smith' 7 | url: 'http://example.com' 8 | email: 'joe@example.com' 9 | version: 0.1.0 -------------------------------------------------------------------------------- /test/sampleData/validator/info/missing_license_name.yaml: -------------------------------------------------------------------------------- 1 | cyanobyte: 0.1.0 2 | info: 3 | title: Valid Info 4 | description: This is a minimal example with valid info. 5 | contact: 6 | name: 'Joe Smith' 7 | url: 'http://example.com' 8 | email: 'joe@example.com' 9 | license: 10 | url: 'https://www.apache.org/licenses/LICENSE-2.0.html' 11 | version: 0.1.0 -------------------------------------------------------------------------------- /test/sampleData/validator/info/missing_license_url.yaml: -------------------------------------------------------------------------------- 1 | cyanobyte: 0.1.0 2 | info: 3 | title: Valid Info 4 | description: This is a minimal example with valid info. 5 | contact: 6 | name: 'Joe Smith' 7 | url: 'http://example.com' 8 | email: 'joe@example.com' 9 | license: 10 | url: 'https://www.apache.org/licenses/LICENSE-2.0.html' 11 | version: 0.1.0 -------------------------------------------------------------------------------- /test/sampleData/validator/info/missing_title.yaml: -------------------------------------------------------------------------------- 1 | cyanobyte: 0.1.0 2 | info: 3 | description: This is a minimal example with valid info. 4 | contact: 5 | name: 'Joe Smith' 6 | url: 'http://example.com' 7 | email: 'joe@example.com' 8 | license: 9 | name: 'Apache 2.0' 10 | url: 'https://www.apache.org/licenses/LICENSE-2.0.html' 11 | version: 0.1.0 -------------------------------------------------------------------------------- /test/sampleData/validator/info/missing_version.yaml: -------------------------------------------------------------------------------- 1 | cyanobyte: 0.1.0 2 | info: 3 | title: Valid Info 4 | description: This is a minimal example with valid info. 5 | contact: 6 | name: 'Joe Smith' 7 | url: 'http://example.com' 8 | email: 'joe@example.com' 9 | license: 10 | name: 'Apache 2.0' 11 | url: 'https://www.apache.org/licenses/LICENSE-2.0.html' -------------------------------------------------------------------------------- /test/sampleData/validator/info/valid.yaml: -------------------------------------------------------------------------------- 1 | cyanobyte: 0.1.0 2 | info: 3 | title: Valid Info 4 | description: This is a minimal example with valid info. 5 | contact: 6 | name: 'Joe Smith' 7 | url: 'http://example.com' 8 | email: 'joe@example.com' 9 | license: 10 | name: 'Apache 2.0' 11 | url: 'https://www.apache.org/licenses/LICENSE-2.0.html' 12 | version: 0.1.0 -------------------------------------------------------------------------------- /test/test_cmsis_svd.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python3 2 | # 3 | # Copyright (C) 2020 Google Inc. 4 | # 5 | # Licensed under the Apache License, Version 2.0 (the "License"); 6 | # you may not use this file except in compliance with the License. 7 | # You may obtain a copy of the License at 8 | # 9 | # http://www.apache.org/licenses/LICENSE-2.0 10 | # 11 | # Unless required by applicable law or agreed to in writing, software 12 | # distributed under the License is distributed on an "AS IS" BASIS, 13 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | # See the License for the specific language governing permissions and 15 | # limitations under the License. 16 | 17 | from cmsis_svd.parser import SVDParser 18 | import unittest 19 | import os 20 | 21 | class TestCodegen(unittest.TestCase): 22 | def verify_cmsis_output(self, filename): 23 | filepath = 'test/sampleData/cmsis-svd/' + filename + '.svd' 24 | print('Parsing ' + filepath) 25 | parser = SVDParser.for_xml_file(filepath) 26 | self.assertEqual( 27 | filename, 28 | parser.get_device().peripherals[0].name, 29 | msg="{0} is not the provided name in the CMSIS SVD file" 30 | ) 31 | 32 | def tearDown(self): 33 | print('\n') 34 | 35 | def test_ADS1015(self): 36 | self.verify_cmsis_output('ADS1015') 37 | 38 | def test_BMP280(self): 39 | self.verify_cmsis_output('BMP280') 40 | 41 | def test_Example(self): 42 | self.verify_cmsis_output('Example') 43 | 44 | def test_LSM303D(self): 45 | self.verify_cmsis_output('LSM303D') 46 | 47 | def test_MCP4725(self): 48 | self.verify_cmsis_output('MCP4725') 49 | 50 | def test_MCP9808(self): 51 | self.verify_cmsis_output('MCP9808') 52 | 53 | def test_TCS3472(self): 54 | self.verify_cmsis_output('TCS3472') 55 | 56 | if __name__ == '__main__': 57 | unittest.main() --------------------------------------------------------------------------------