RockPro64 programing GPIO by Rust
#1
Hello,
For the Rust developer, I show the gpio led blinking program code for RockPro64.
You can use GPIO pin number or BCM number.

In project
cargo build --release
sudo target/release/gpio

LED connected Pin 16 blinks.

cargo.toml

------------------------------------
[dependencies]
sysfs_gpio = "0.6"

------------------------------------
main.rs
-----------------------------------------------------------------------------------
use sysfs_gpio::{Direction, Pin};
use std::thread:Confusedleep;
use std::time:Big Grinuration;

// Define GPIO arrays
static BOARD_TO_ROCK: &'static [u8] = &[0, 0, 0, 52, 0, 53, 0, 152, 148, 0, 147, 54, 120, 50, 0, 33, 36, 0, 149, 40, 0, 39, 153, 41, 42, 0, 45, 43, 44, 155, 0, 156, 124, 125, 0, 122, 126, 121, 123, 0, 127];
static ROCK_VALID_CHANNELS: &'static [u8] = &[52, 53, 152, 54, 50, 33, 40, 39, 41, 43, 155, 156, 125, 122, 121, 148, 147, 120, 36, 149, 153, 42, 45, 44, 124, 126, 123, 127];
static BCM_TO_ROCK: &'static [u8] = &[43, 44, 52, 53, 152, 155, 156, 45, 42, 39, 40, 41, 124, 125, 148, 147, 124, 54, 120, 122, 123, 127, 33, 36, 149, 153, 121, 50];

fn main() {
    let my_pin_num = 16;//gpio number: 36
    let my_led = Pin::new(BOARD_TO_ROCK[my_pin_num].into()); // Pin 16 GPIO1_A4 gpio number 36 depends on chip, etc.
    //let my_bcm_num = 23;//gpio number: 36
    //let my_led = Pin::new(BCM_TO_ROCK[my_bcm_num].into()); // Pin 16 GPIO1_A4 gpio number 36 depends on chip, etc.
    my_led.with_exported(|| {
        my_led.set_direction(Direction::Out).unwrap();
        loop {
            my_led.set_value(0).unwrap();
            sleep(Duration::from_millis(100));
            my_led.set_value(1).unwrap();
            sleep(Duration::from_millis(100));
            println!("Blinking GPIO1_A4(36) Pin 16");
        }
    }).unwrap();
}

-------------------------------------------------------------------------------------------------
  Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
Brick Logical Extensible Gizmo Organizing RockPro64 Enclosure hoarfrosty 0 440 08-06-2023, 09:32 PM
Last Post: hoarfrosty
Photo RockPro64 programing GPIO, I2C,UART and SPI madhuks 3 6,323 08-06-2020, 09:07 AM
Last Post: Gienek
  RockPro64 as PATA/SATA bridge? Count Omega 1 4,192 12-07-2019, 02:25 PM
Last Post: Count Omega
Question HOW TO fix Wifi on RockPro64 - Recalbox OS and upload roms on SSD External Gouki 6 8,510 08-25-2019, 05:13 AM
Last Post: Gouki
  ROCKPRO64 for SCRAPING Ulthor_31 4 7,348 08-01-2019, 05:19 AM
Last Post: Ulthor_31
  RockPro64 as PVR/DVR bm_00 1 3,793 02-27-2019, 04:46 AM
Last Post: mabs

Forum Jump:


Users browsing this thread: 1 Guest(s)