{"id":20316033,"url":"https://github.com/lupyuen/nuttx-embedded-hal","last_synced_at":"2025-04-11T17:35:54.113Z","repository":{"id":57647484,"uuid":"470848101","full_name":"lupyuen/nuttx-embedded-hal","owner":"lupyuen","description":"Rust Embedded HAL for Apache NuttX RTOS","archived":false,"fork":false,"pushed_at":"2022-05-09T02:21:20.000Z","size":31,"stargazers_count":14,"open_issues_count":0,"forks_count":3,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-25T13:39:39.531Z","etag":null,"topics":["bl602","bl604","embedded","gpio","i2c","nuttx","pinecone","pinedio","rtos","rust","spi"],"latest_commit_sha":null,"homepage":"https://crates.io/crates/nuttx-embedded-hal","language":"Rust","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/lupyuen.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null},"funding":{"github":["lupyuen"],"patreon":null,"open_collective":null,"ko_fi":null,"tidelift":null,"community_bridge":null,"liberapay":null,"issuehunt":null,"otechie":null,"custom":["paypal.me/lupyuen"]}},"created_at":"2022-03-17T04:30:58.000Z","updated_at":"2024-10-20T00:11:47.000Z","dependencies_parsed_at":"2022-08-25T08:10:42.388Z","dependency_job_id":null,"html_url":"https://github.com/lupyuen/nuttx-embedded-hal","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lupyuen%2Fnuttx-embedded-hal","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lupyuen%2Fnuttx-embedded-hal/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lupyuen%2Fnuttx-embedded-hal/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lupyuen%2Fnuttx-embedded-hal/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lupyuen","download_url":"https://codeload.github.com/lupyuen/nuttx-embedded-hal/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248450503,"owners_count":21105687,"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":["bl602","bl604","embedded","gpio","i2c","nuttx","pinecone","pinedio","rtos","rust","spi"],"created_at":"2024-11-14T18:23:49.234Z","updated_at":"2025-04-11T17:35:54.091Z","avatar_url":"https://github.com/lupyuen.png","language":"Rust","funding_links":["https://github.com/sponsors/lupyuen","paypal.me/lupyuen"],"categories":[],"sub_categories":[],"readme":"# Rust Embedded HAL for Apache NuttX RTOS\n\nThis crate provides Rust Embedded HAL interfaces (GPIO, I2C, SPI and Delay) for Apache NuttX RTOS.\n\nFor sample NuttX Rust apps, see [rust-i2c-nuttx](https://github.com/lupyuen/rust-i2c-nuttx) and [rust_test](https://github.com/lupyuen/rust_test)\n\nIf you find this crate useful, please support me on [GitHub Sponsors](https://github.com/sponsors/lupyuen)\n\nMore about NuttX Embedded HAL...\n\n-   [\"Rust talks I2C on Apache NuttX RTOS\"](https://lupyuen.github.io/articles/rusti2c)\n\n-   [\"Rust on Apache NuttX OS\"](https://lupyuen.github.io/articles/rust2)\n\n# GPIO Output\n\n```rust\n//  Import Output Pin Trait\nuse embedded_hal::digital::v2::OutputPin;\n\n//  Open /dev/gpio1 for GPIO Output\nlet mut gpio = nuttx_embedded_hal::OutputPin\n    ::new(\"/dev/gpio1\")\n    .expect(\"open gpio failed\");\n\n//  Set Chip Select to Low\ngpio.set_low()\n    .expect(\"set gpio failed\");\n\n//  Set Chip Select to High\ngpio.set_high()\n    .expect(\"set gpio failed\");\n```\n\n[(Documentation)](https://docs.rs/nuttx-embedded-hal/latest/nuttx_embedded_hal/struct.OutputPin.html)\n\n[(Implementation)](https://lupyuen.github.io/articles/rust2#gpio-hal)\n\n# GPIO Input\n\n```rust\n//  Import Input Pin Trait\nuse embedded_hal::digital::v2::InputPin;\n\n//  Open /dev/gpio0 for GPIO Input\nlet gpio = nuttx_embedded_hal::InputPin\n    ::new(\"/dev/gpio0\")\n    .expect(\"open gpio failed\");\n\n//  True if GPIO is High\nlet is_high = gpio.is_high()\n    .expect(\"read gpio failed\");\n\n//  True if GPIO is Low\nlet is_low = gpio.is_low()\n    .expect(\"read gpio failed\");\n```\n\n[(Documentation)](https://docs.rs/nuttx-embedded-hal/latest/nuttx_embedded_hal/struct.InputPin.html)\n\n# GPIO Interrupt\n\nInterrupt callbacks are not supported yet.\n\n```rust\n//  Import Input Pin Trait\nuse embedded_hal::digital::v2::InputPin;\n\n//  Open /dev/gpio2 for GPIO Interrupt\nlet gpio = nuttx_hal::InterruptPin\n    ::new(\"/dev/gpio2\");\n    .expect(\"open gpio failed\");\n\n//  True if GPIO is High\nlet is_high = gpio.is_high()\n    .expect(\"read gpio failed\");\n\n//  True if GPIO is Low\nlet is_low = gpio.is_low()\n    .expect(\"read gpio failed\");\n```\n\n[(Documentation)](https://docs.rs/nuttx-embedded-hal/latest/nuttx_embedded_hal/struct.InterruptPin.html)\n\n# I2C\n\n```rust\n//  Import I2C Trait\nuse embedded_hal::blocking::i2c;\n\n//  Open I2C Port /dev/i2c0\nlet mut i2c = nuttx_embedded_hal::I2c::new(\n    \"/dev/i2c0\",  //  I2C Port\n    400000,       //  I2C Frequency: 400 kHz\n).expect(\"open failed\");\n\n//  Buffer for received I2C data\nlet mut buf = [0 ; 1];\n\n//  Read register 0xD0 from I2C Address 0x77\ni2c.write_read(\n    0x77,     //  I2C Address\n    \u0026[0xD0],  //  Register ID\n    \u0026mut buf  //  Buffer to be received\n).expect(\"read register failed\");\n\n//  Print the register value\nprintln!(\"Register value is 0x{:02x}\", buf[0]);\n\n//  Write 0xA0 to Register 0xF5\ni2c.write(\n    0x77,          //  I2C Address\n    \u0026[0xF5, 0xA0]  //  Register ID and value\n).expect(\"write register failed\");\n```\n\n[(Documentation)](https://docs.rs/nuttx-embedded-hal/latest/nuttx_embedded_hal/struct.I2c.html)\n\n[(Implementation)](https://lupyuen.github.io/articles/rusti2c#nuttx-embedded-hal)\n\n# SPI\n\nThe SPI interface requires the SPI Test Driver (/dev/spitest0) to be installed:\n\n-   [SPI Test Driver](https://github.com/lupyuen/incubator-nuttx/tree/master/drivers/rf)\n\nSPI settings are configured in the [SPI Test Driver](https://github.com/lupyuen/incubator-nuttx/blob/master/drivers/rf/spi_test_driver.c#L39-L58).\n\n```rust\n//  Import SPI Trait\nuse embedded_hal::blocking::spi;\n\n//  Open SPI Bus /dev/spitest0\nlet mut spi = nuttx_embedded_hal::Spi\n    ::new(\"/dev/spitest0\")\n    .expect(\"open spi failed\");\n\n//  Open GPIO Output /dev/gpio1 for Chip Select\nlet mut cs = nuttx_embedded_hal::OutputPin\n    ::new(\"/dev/gpio1\")\n    .expect(\"open gpio failed\");\n\n//  Set Chip Select to Low\ncs.set_low()\n    .expect(\"cs failed\");\n\n//  Transmit and receive SPI data\nlet mut data: [ u8; 5 ] = [ 0x1d, 0x00, 0x08, 0x00, 0x00 ];\nspi.transfer(\u0026mut data)\n    .expect(\"spi failed\");\n\n//  Show the received SPI data\nfor i in 0..data.len() {\n    println!(\"{:02x}\", data[i as usize]);\n}\n\n//  Set Chip Select to High\ncs.set_high()\n    .expect(\"cs failed\");\n```\n\n[(Documentation)](https://docs.rs/nuttx-embedded-hal/latest/nuttx_embedded_hal/struct.Spi.html)\n\n[(Implementation)](https://lupyuen.github.io/articles/rust2#spi-hal)\n\n# Delay\n\n```rust\n//  Import Delay Trait (milliseconds)\nuse embedded_hal::blocking::delay::DelayMs;\n\n//  Get a Delay Interface\nlet mut delay = nuttx_embedded_hal::Delay;\n\n//  Wait 500 milliseconds\ndelay.delay_ms(500_u32);\n```\n\n[(Documentation)](https://docs.rs/nuttx-embedded-hal/latest/nuttx_embedded_hal/struct.Delay.html)","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flupyuen%2Fnuttx-embedded-hal","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flupyuen%2Fnuttx-embedded-hal","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flupyuen%2Fnuttx-embedded-hal/lists"}