{"id":27366812,"url":"https://github.com/peterkrull/dshot-pio","last_synced_at":"2025-04-13T06:40:08.255Z","repository":{"id":155110608,"uuid":"600462469","full_name":"peterkrull/dshot-pio","owner":"peterkrull","description":"DShot implementation for the RP2040 using a single PIO block, for up to 4 ESCs","archived":false,"fork":false,"pushed_at":"2025-04-12T22:09:28.000Z","size":24,"stargazers_count":21,"open_issues_count":2,"forks_count":3,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-04-12T22:30:44.643Z","etag":null,"topics":["bldc","driver","drone","dshot","embassy","embassy-rp","esc","pio","rp-hal","rp2040","rp2040-hal","rp2350","rust"],"latest_commit_sha":null,"homepage":"","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/peterkrull.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2023-02-11T15:17:11.000Z","updated_at":"2025-03-07T01:09:05.000Z","dependencies_parsed_at":"2025-01-29T12:21:10.032Z","dependency_job_id":"100086ee-6671-4467-9e3d-78d7ebbd2d5b","html_url":"https://github.com/peterkrull/dshot-pio","commit_stats":null,"previous_names":["peterkrull/dshot-pio"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/peterkrull%2Fdshot-pio","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/peterkrull%2Fdshot-pio/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/peterkrull%2Fdshot-pio/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/peterkrull%2Fdshot-pio/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/peterkrull","download_url":"https://codeload.github.com/peterkrull/dshot-pio/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248675434,"owners_count":21143763,"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":["bldc","driver","drone","dshot","embassy","embassy-rp","esc","pio","rp-hal","rp2040","rp2040-hal","rp2350","rust"],"created_at":"2025-04-13T06:40:07.559Z","updated_at":"2025-04-13T06:40:08.225Z","avatar_url":"https://github.com/peterkrull.png","language":"Rust","funding_links":[],"categories":[],"sub_categories":[],"readme":"# DShot implementation for RP2040 using PIO\n\nThis crate utilizes a single PIO block of the RP2040, enable it to send up to four DShot ESC commands (per PIO block, there are 2 of them) simultaneously, making it a great fit for quad-copters. The crate supports both the `embassy-rp` and  `rp2040-hal` hardware abstraction layers (HAL). To use either HAL, the corresponding feature *must* be enabled, using either feature below.\n\n```toml\ndshot-pio = { git = \"https://github.com/peterkrull/dshot-pio\", features = [\"embassy-rp\"] }\ndshot-pio = { git = \"https://github.com/peterkrull/dshot-pio\", features = [\"rp2040-hal\"] }\n```\nCreating the `DshotPio` struct is then a matter of passing into the constructor the PIO block to use, a single HAL-specific item, and the four pins to use as DShot ouputs. The last argument is the clock divider. In order to get reliable transmission to the ESCs, it is important to set the clock divider correctly. The formula for doing so is the following, where *dshot speed* is the number indicating speed, eg 150, 300, 600 and so on. The system clock can vary from board to board, but generally 120 Mhz to 133 Mhz is common for RP2040 boards.\n\n$$\\text{clock divider} = \\frac { \\text{system clock} }{8 \\cdot \\text{dshot speed} \\cdot 1000} $$\n\nThis clock divider is passed to the constructor in two parts, consisting of the integer part, and the fraction. Generally stuff after the decimal point of the *clock divider* can be ignored, meaning that is should be good enough to pass only the integer part. Otherwise the remainder should be passed as `(remainder * 256 ) as u8`\n\n---\n\n## Construction\n\nConstructing the motor struct looks slightly different, depending on whether the `rp2040-hal` or `embassy-rp`  HAL is used. The functionality of the resulting struct is however shared through a trait. The number of DShot drivers needed can be changed using the first number in the turbofish. \n\n```rust\nuse dshot_pio::rp2040_hal::*;\nlet dshot_rp2040_hal = DshotPio::\u003c4,_\u003e::new(\n    pac.PIO0,\n    \u0026mut pac.RESETS,\n    pins.gpio13.into_mode(),\n    pins.gpio7.into_mode(),\n    pins.gpio6.into_mode(),\n    pins.gpio12.into_mode(),\n    (52, 0) // clock divider\n);\n```\nFor embassy, it is currently necessary to use a macro to correctly bind an interrupt.\n\n```rust\nbind_interrupts!( struct Pio0Irqs {\n    PIO0_IRQ_0 =\u003e InterruptHandler\u003cPIO0\u003e;\n});\n\nuse dshot_pio::embassy_rp::*;\nlet dshot_embassy = DshotPio::\u003c4,_\u003e::new(\n    p.PIO0,\n    Pio0Irqs,\n    p.PIN_13,\n    p.PIN_7,\n    p.PIN_6,\n    p.PIN_12,\n    (52, 0) // clock divider\n);\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpeterkrull%2Fdshot-pio","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fpeterkrull%2Fdshot-pio","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fpeterkrull%2Fdshot-pio/lists"}