Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Sharing a SpiDriver between multiple Devices with different configs #476

Closed
agmes4 opened this issue Aug 28, 2024 · 5 comments
Closed

Sharing a SpiDriver between multiple Devices with different configs #476

agmes4 opened this issue Aug 28, 2024 · 5 comments

Comments

@agmes4
Copy link

agmes4 commented Aug 28, 2024

Im currently trying to get multiple SpiDeviceDrivers out of SpiDriver cause the devices have different configs. Borrowing worked for compiling but all the time I try to create the second DeviceDriver the esp get stuck in execution.

Is there first an easy way to share to share a SpiBus here with out these issues and is there additional documentation for such cases?
I tryed

let mut spi_device_driver =
        SpiBusDriver::new(&mut spi, &config).expect("Failed to init spi flash!");
spi_device_driver.write(b"as");
spi_device_driver.write(b"as");
spi_device_driver.write(b"as");
spi_device_driver.write(b"as");
spi_device_driver.write(b"as");
info!("have send");
let config = config::Config::new()
        .baudrate(4000000.into())
        .bit_order(config::BitOrder::MsbFirst)
        .write_only(true)
        .input_delay_ns(0)
        .data_mode(MODE_0);
    
let mut spi_device_driver2 =
        SpiBusDriver::new(&mut spi, &config).expect("Failed to init spi flash!");
spi_device_driver2.write(b"as");
@Vollbrecht
Copy link
Collaborator

not using a SpiBusDriver but directly creating multiple SpiDevice instance's with different configs for each? You can have a look at the loopback example where we create two SpiDeviceDrivers with two different clock speeds.

@agmes4
Copy link
Author

agmes4 commented Aug 28, 2024

the Problem here is that my display needs to have a minor delay between 2 bytes what I do in the device via manually pulling the CS to high and the later again to low. I think I found a way by passing Option::::None as cs it is possible to create without setting a pin thanks.

@agmes4
Copy link
Author

agmes4 commented Aug 28, 2024

is this thread safe this way and can use this in different task each for a spi device?

@Vollbrecht
Copy link
Collaborator

you can have SpiDeviceDriver A in thread A and SpiDeviceDriver B in thread B yes. Though if you want to share SpiDeviceDriver A in thread A and B you have to lock that yourself.

@agmes4
Copy link
Author

agmes4 commented Aug 28, 2024

Thanks

@agmes4 agmes4 closed this as completed Aug 28, 2024
@github-project-automation github-project-automation bot moved this from Todo to Done in esp-rs Aug 28, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Archived in project
Development

No branches or pull requests

2 participants