-
Notifications
You must be signed in to change notification settings - Fork 1k
Change Wire Rx/Tx buffers managements #152
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
Conversation
Signed-off-by: fpr <fabien.perroquin@wi6labs.com>
Signed-off-by: fpr <fabien.perroquin@wi6labs.com>
Buffers are now dynamically allocated (min size: BUFFER_LENGTH) Signed-off-by: fpr <fabien.perroquin@wi6labs.com>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Minor comments and question - concept and overall implementation is good to go for me
libraries/Wire/src/Wire.cpp
Outdated
/* Reset rx buffer when no more data available */ | ||
/*if(rxBufferIndex == rxBufferLength) { | ||
resetRxBuffer(); | ||
}*/ | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why keeping commented source code ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Just to show it is possible to reset the Rx buffer here. But thought it is not required.
libraries/Wire/src/Wire.cpp
Outdated
} | ||
return buffer; | ||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why moving to .h file ? maybe you can simply move it up in the C file ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Move it as inline
function in the class to avoid function call
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
inline is fine - but why not keep it in wire.cpp file ?
libraries/Wire/src/Wire.h
Outdated
uint8_t *allocateBuffer(uint8_t *buffer, size_t length); | ||
uint8_t *resetBuffer(uint8_t *buffer); | ||
inline void allocateRxBuffer(size_t length){ if(rxBufferAllocated < length) { | ||
// By default we allocate BUFFER_LENGTH bytes. It is the min size of the buffer. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
missing return lines
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It was a choice but I can add one.
libraries/Wire/src/Wire.h
Outdated
inline void allocateRxBuffer(size_t length){ if(rxBufferAllocated < length) { | ||
// By default we allocate BUFFER_LENGTH bytes. It is the min size of the buffer. | ||
if(length < BUFFER_LENGTH) { length = BUFFER_LENGTH; } | ||
rxBuffer = (uint8_t *)realloc(rxBuffer, length * sizeof(uint8_t)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
should't you check for a MAX SIZE somewhere to report an error rather than allocating all the available heap memory ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I thought about it but I would not add more check.
If all heap is used then buffer will be at nullptr then an error will be raised.
- Do not call realloc each time, only if needed - Assume that user will use more than one time the same buffer size so avoid the call to realloc to decrease size - write: avoid copy byte/byte in the buffer Signed-off-by: Frederic.Pillon <frederic.pillon@st.com>
Change Wire Rx/Tx buffers managements
Rx/Tx Buffers are now dynamically allocated (min size: BUFFER_LENGTH)
TwoWire::write(const uint8_t *data, size_t quantity)
avoid copy byte/byte in the bufferReplace #131 to solve issue #124