Accessing registers of esp32 with rust and esp-idf-sys

Viewed 209

I am trying to use a OV2640 camera together with ESP32 (TTGo module) and rust. Unfortunately, there is no driver, yet. So, I started to create one. After some digging it seems to me that the I2S module that can be used for camera image read out, has no matching function support from the esp-idf library for this use case. To configure the peripheral, I need to write some register values by hand. For C you can easily find examples for this, e.g. in the esp32-camera library from espressive (see ll_cam.c, line 256ff.)

Unfortunately, after looking at the esp-idf-sys and -hal documentation and examples, I could not find any examples or hints how to do that. Also searching on the interwebs didn't bring up anything useful until now.

Maybe it is too obvious... Can someone give me a hint where to look at or how to do this?

1 Answers

It won't be easy, but you can access registers in Rust 1.59+ using asm!. You will need to figure out which specific registers each value is bound to. I'm not familiar with Riscv32 so this may or may not be an actual register.

let x1_register: usize;

unsafe {
    // Read register to variable
    asm!("mov {0}, x1", out(reg) x1_register);
    // Write register from variable
    asm!("mov x2, {0}", in(reg) x1_register);
}

println!("x1_register: {:?}", x1_register);

Though to be honest, I'm not sure if it is actually changing any CPU registers. It seems likely based on this header I found that it may just be configuring some data for an SPI (or similar) interface.

Related