Overhaul UART to support single wire transmitters/receivers#164
Conversation
ivmarkov
left a comment
There was a problem hiding this comment.
Just one key question. The rest looks great.
| pub struct UartDriver<'d>(Port<'d, Owned>); | ||
| pub struct UartDriver<'d> { | ||
| port: u8, | ||
| _p: PhantomData<&'d mut ()>, |
There was a problem hiding this comment.
Don't we need an Owner here as well? My rust knowledge falls short here: will drop still be called on UartDriver if I do into_split(self)?
- if yes, we need
Ownerhere - if not, we are good to go
There was a problem hiding this comment.
I think drop WILL be called, and the only reason Rust allows us to implement into_split in the presence of drop is because - in fact - we are not moving anything out of UartDriver? :) Everything that we push into RX/TX is Copy...
There was a problem hiding this comment.
@ivmarkov absolutely right, I stepped into this rake again.
pushed something to fix it, probably better than having an owner enum, what do you think?
There was a problem hiding this comment.
Yep, LGTM. Shall I merge or will you bang on it a bit more? How do you feel about it?
There was a problem hiding this comment.
I'll probably look over it some more tomorrow, as I did this in quite a hurry today.
There was a problem hiding this comment.
OK. Will wait for a green-light from you.
There was a problem hiding this comment.
@ivmarkov yeah so I went over it and found some issues.
I accidentally removed the count function from UartRxDriver, which I promptly restored. Then I noticed that uart_get_buffered_data_len and uart_get_tx_buffer_free_size can return 256 (SOC_UART_FIFO_LEN * 2), when the rx buffer is completely filled up, or the tx buffer is empty, which won't fit in u8. So the solution is either to reduce the buffers to length of 255, or to increase the return word width. In the future I imagine we'll make the tx/rx ring buffer size user tweakable, so it's better to future proof than restrict, IMHO.
I also updated the example to not require mut, and removed pub from Owner, as it's an internal implementation detail.
And lastly, I made a very much useless "optimization" (I'm pretty sure the compiler should be able to infer this by itself), whereas the internal tx()/rx() return a ManuallyDrop instead, which won't run the destructor (which obviously does nothing). This is the change I feel the most weakly about.
… to be able to fit the maximum allowed value, don't run `drop` on temporary internal borrows, update example
No description provided.