-
Notifications
You must be signed in to change notification settings - Fork 155
Implement the ability to work with W
outside of write
#708
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
Comments
W
outside of `write'W
outside of write
Thanks for suggesting this! We discussed it at the end of today's meeting (here) though didn't really come to any conclusions yet. I think one problem is that even if we added a const let mut w: stm32f405::tim2::cr1::W = unsafe { core::mem::transmute(0) };
w.opm().enabled();
tim2.cr1.write(|_| w.cen().enabled());
Making a whole new function that takes It's worth noting that |
Thank you for considering the proposal! Let me clarify a little how I imagine it:
After that, instead of write(|w| w.f1().a1().f2().a2()); you can write write_value(*pac::peripheral::register::INITIAL_VALUE.f1().a1().f2().a2()); or for example let mut val = pac::peripheral::register::INITIAL_VALUE;
val.f1().a1();
val.f2().a2();
write_value(val);
const VAL: pac::peripheral::register::W = *pac::peripheral::register::INITIAL_VALUE.f1().a1().f2().a2();
write_value(VAL); Instead of reset(); you can write write_value(pac::peripheral::register::INITIAL_VALUE); |
I have a different use case for this. The SPI peripheral of the ESP32 chips support changing its registers via DMA. To use the feature, I basically need to write the intended value of the registers into a |
Could you show example of code you blocked on? |
The (pseudo) code would look something like this. (The PAC for reference) let mut registers = [0u32; 8];
registers[0] = spi2::USR2::create(|w| {
w.usr_command_bitlen().bits(4);
w.usr_command_value().bits(0x20))
});
register[1] = spi2::USER1::create(|w| {
unsafe { w.usr_dummy_cyclelen().bits(dummy - 1) };
w.usr_addr_bitlen().bits((address.width() - 1) as u8)
});
// .... register[n] = ...;
let dma_buffer = DmaBuffer::new(descriptors, ®isters);
let transfer = spi_dma.segmented_transfer(dma_buffer); |
So you just need a |
Pretty much! Couldn't have said it better myself. |
I think we could add such method. The only moment. I'm not a fan of the name. "create" does not describe its purposes. |
Here's what I'm come up with so far.
|
Ah, I'm going on a tangent here but maybe we could have a let reg_value: <some new type> = spi2::USR2::prepare(|w| {
w.usr_command_bitlen().bits(4);
w.usr_command_value().bits(0x20))
});
// For me
registers[0] = reg_value.bits();
// For the author of this issue.
spi_reg_block.usr2().write(|w| {
w.safe_bits(reg_value);
w.usr_command_value().bits(5)
}) |
There is no sense in new type as you can always pass bits in writer with "create_value" is good for me. "prepare" is also good name/part of name. Could you open a PR and we discuss it on next meeting? |
Yeah that's fair enough I didn't know there was already a solution for that. I can open a PR but not any time soon, definitely not in time for Tuesday 😄 |
I want for example instead of this
to do so
Or for example like this
Is it possible to change
svd2rust
to allow this?The text was updated successfully, but these errors were encountered: