{"id":16237755,"url":"https://github.com/pschatzmann/logic-analyzer","last_synced_at":"2025-03-16T12:32:33.421Z","repository":{"id":37968223,"uuid":"359147384","full_name":"pschatzmann/logic-analyzer","owner":"pschatzmann","description":"Arduino Logic Analyzer API supporting the SUMP protocol (for sigrok, pulseview)","archived":false,"fork":false,"pushed_at":"2023-01-16T21:05:10.000Z","size":526,"stargazers_count":112,"open_issues_count":8,"forks_count":15,"subscribers_count":9,"default_branch":"main","last_synced_at":"2025-02-27T09:12:25.388Z","etag":null,"topics":["arduino-library","logic-analyzer"],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/pschatzmann.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"License.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2021-04-18T13:14:39.000Z","updated_at":"2025-02-24T04:29:21.000Z","dependencies_parsed_at":"2023-01-21T00:46:45.092Z","dependency_job_id":null,"html_url":"https://github.com/pschatzmann/logic-analyzer","commit_stats":null,"previous_names":[],"tags_count":3,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pschatzmann%2Flogic-analyzer","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pschatzmann%2Flogic-analyzer/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pschatzmann%2Flogic-analyzer/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/pschatzmann%2Flogic-analyzer/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/pschatzmann","download_url":"https://codeload.github.com/pschatzmann/logic-analyzer/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":243814893,"owners_count":20352038,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["arduino-library","logic-analyzer"],"created_at":"2024-10-10T13:36:53.018Z","updated_at":"2025-03-16T12:32:33.132Z","avatar_url":"https://github.com/pschatzmann.png","language":"C++","funding_links":[],"categories":["C++"],"sub_categories":[],"readme":"# A flexible Arduino SUMP Logic Analyzer Library\n\nRecently, when I started to research the topic of [Logic Analyzers](https://en.wikipedia.org/wiki/Logic_analyzer), I found the incredible [PulseView Project](https://sigrok.org/wiki/PulseView). However, I did not want to invest in additional hardware but just use one of my favorite microprocessors (ESP32, Raspberry Pico) as capturing device.\n\nThere are quite a few logic analyzer projects with a similar goal:\n\n- [gillham/logic_analyzer](https://github.com/gillham/logic_analyzer)\n- [gamblor21/rp2040-logic-analyzer](https://github.com/gamblor21/rp2040-logic-analyzer)\n- [EUA/ESP32_LogicAnalyzer](https://github.com/EUA/ESP32_LogicAnalyzer)\n- [Ebiroll/esp32_sigrok](https://github.com/Ebiroll/esp32_sigrok)\n\nHowerver all of them are geared for __one specific architecture__ and therfore are __not portable__.\n\nI wanted to come up with a better design and provide a [simple Arduino C++ Library](https://pschatzmann.github.io/logic-analyzer/html/annotated.html) that implements the [SUMP protocol](https://www.sump.org/projects/analyzer/protocol/) and clearly separates the generic functionality from the processor specific in order to support an __easy rollout to new architectures__: The only common precondition is the Arduino API. \n\nI am currently providing implementations for\n\n- AVR Processors\n- ESP32\n- ESP8266\n- Raspberry Pico\n\n# The Basic Arduino Sketch\n\nThe basic Arduino Sketch for the __logic-analyzer__ is quite simple. We just need create a [LogicAnalyzer](https://pschatzmann.github.io/logic-analyzer/html/classlogic__analyzer_1_1_logic_analyzer.html) and a [Capture](https://pschatzmann.github.io/logic-analyzer/html/classlogic__analyzer_1_1_capture.html) object.\nIn the setup we call the __begin method__ on the LogicAnalyzer object which provides all mandatory parameters. The provided implementation just uses the default values which are defined in the config.\nFinally we add the __command handler__ in the loop():\n\n```c++\n#include \"Arduino.h\"\n#include \"logic_analyzer.h\"\n\nusing namespace logic_analyzer;  \n\nint pinStart=START_PIN;\nint numberOfPins=PIN_COUNT;\nLogicAnalyzer logicAnalyzer;\nCapture capture(MAX_FREQ, MAX_FREQ_THRESHOLD);\n\n\nvoid setup() {\n    Serial.begin(SERIAL_SPEED);  \n    Serial.setTimeout(SERIAL_TIMEOUT);\n    logicAnalyzer.begin(Serial, \u0026capture, MAX_CAPTURE_SIZE, pinStart, numberOfPins);\n}\n\nvoid loop() {\n    if (Serial) logicAnalyzer.processCommand();\n}\n```\n\n# Adding Additional Functionality\n\n## Logging\n\nYou can actvate the logging by assigning a Stream to the LogicAnalyzer object by calling logicAnalyzer.setLogger():\n\n```c++\n// setup logger\nSerial1.begin(115200, SERIAL_8N1, 16, 17);\nlogicAnalyzer.setLogger(Serial1);\n```\n\n## Using Events\n\nAn easy way to extend the functionalty is by adding an event handler. The following acts on a status change event by activating the LED dependent on the actual status:\n\n```c++\n// Use Event handler to control the LED\nvoid onEvent(Event event) {\n    if (event == STATUS) {\n        switch (logicAnalyzer.status()) {\n            case ARMED:\n                digitalWrite(LED_BUILTIN, LOW);\n                break;\n            case STOPPED:\n                digitalWrite(LED_BUILTIN, LOW);\n                break;\n        }\n    }\n}\n```\n\nand we can just activate it by calling:\n\n```c++\nlogicAnalyzer.setEventHandler(\u0026onEvent);\n```\n\n## Custom Capturing\n\nI am providing a default implementation for the capturing with the [Capture](https://pschatzmann.github.io/logic-analyzer/html/classlogic__analyzer_1_1_capture.html) class. It's main goal is portability because it should work on all Arduino Boards. To come up with a dedicated improved capturing is easy. Just implement your own class:\n\n```c++\nclass YourFastCapture : public AbstractCapture {\n    public:\n        /// Default Constructor\n        YourFastCapture() : AbstractCapture(){\n        }\n\n        /// starts the capturing of the data\n        virtual void capture(){\n            /// your implementation\n        }\n}\n```\n\n## Supporting new Architectures\n\nIn order to support a new architecture you need to implement a simple config file, that must contains the following information: \n\n- Defines for the __processor specific (resource) settings__ (e.g. MAX_CAPTURE_SIZE, SERIAL_SPEED ...)\n- A __typedef of the PinBitArray__ which defines the recorded data size\n- An implementation of the __class PinReader__ which reads all pins in one shot \n\nHere is the [config_esp32.h](https://github.com/pschatzmann/logic-analyzer/blob/main/src/config_esp32.h).\n\n\n# Class Documentation\n\nThe complete [generated class documentation](https://pschatzmann.github.io/logic-analyzer/html/annotated.html) can be found on Github.\n\n\n# Connecting to Pulseview\n\n- Start the Arduino __\"logic-analyzer\"__ Sketch\n- Start __Pulseview__\n- Select \"Connect to a Device\":\n    - Choose the Driver: __Openbentch Logic Sniffer \u0026 SUMP Compatibles__\n    - Choose the Interface: Select __Serial Port__ with the Port to your Arduino Device and the frequency defined in the config\u003cDevice\u003e.h (e.g. the ESP32 uses 921600)\n    - Click on __\"Scan for Devices using driver above\"__ button\n    - Select the Device - __\"Arduino\"__ which should be available and confirm with OK\n\n\n# Installation\n\nYou can download the library as zip and call include Library -\u003e zip library. Or you can git clone this project into the Arduino libraries folder e.g. with\n\n```shell\ncd  ~/Documents/Arduino/libraries\ngit clone pschatzmann/logic-analyzer.git\n```\n\n\n# Supported Boards\n\n\n| Processor               | Max Freq  | Max Samples | Pins | GPIO      |\n|-------------------------|-----------|-------------|------|-----------|\n| ESP32                   |   2940052 |       65535 |   8  | GPIO19-26 |\n| ESP8266                 |   1038680 |       50000 |   4  | GPIO12-15 |\n| AVR Processors (Nano)   |    109170 |         500 |   8  | GPIO0-7   |\n| Raspberry Pico          |   2508420 |       65535 |   8  | GPIO6-13  |\n| Raspberry Pico - PIO    | 125000000 |       65535 |   8  | GPIO6-13  |\n\n\nPlease note, that SUMP supports only max 65535 samples.\n\n\n# Summary\n\nThe basic implementation is only using a single core. While capturing is in process we do not support any cancellation triggered from Pulseview. In order to support this, we would just need to extend the functionality in a specific sketch to run the capturing on one core and the command handling on the second core. And this is exactly the purpose of this library: to be able to build a custom optimized logic analyzer implementation with minimal effort!\n\nPlease check out the [examples directory](https://github.com/pschatzmann/logic-analyzer/tree/main/examples) for some dedicated implementations. And if you come up with your own implementation, please share it with the community...\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpschatzmann%2Flogic-analyzer","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpschatzmann%2Flogic-analyzer","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpschatzmann%2Flogic-analyzer/lists"}