Skip to content

Commit

Permalink
wire change to better handle writes exceeding buffer size.
Browse files Browse the repository at this point in the history
  • Loading branch information
SpenceKonde committed Jan 17, 2022
1 parent 9aa1eb1 commit 924086b
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 3 deletions.
2 changes: 1 addition & 1 deletion ChangeLog.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ Changes listed here are checked in to GitHub ("master" branch unless specificall
* Different (better) fix for the wire library issue fixed in 2.5.6, from @MX682X (#593), we no longer use the ring buffer, simplifying the code and saving flash
* A bug in SerialUPDI which had been present since it's introduction but went unnoticed has been fixed. One of the last changes that went into Serial UPDI after almost all testing was done, was a "read chunking" option to work around an issue found in a serial adapter that was very flaky (it was a D11C programmed for serial adapter operation, with bugs). That particular buggy serial adapter however is used in the curiculum of a professor who had been driving the push to improve SerialUPDI, and getting uploads to work using that as a UPDI adapter was the entire reason for his and Quentin's involvement in this, so when we discovered that the issue was still there, -rc was added and we then confirmed that it could now upload and verify code successfully (note that the bug in the D11C serial firmware was corrected a few days later - there was a specific amount of data that when sent or received would crash it due to a bug in the USB library, which eventually was corrected) However, the standalone read functionality was not retested. Turns out it was TOTALLY BUSTED whether or not read chunks were requested. There were two issues here: First, the variable was called max_read_chunk in some places, and max_chunk_size in others. Second, when it finally filtered down to the read function, if read-chunk was specified, it only worked up to 256 bytes, because it would only ever use words if read-chunking was not requested, which imposed an unnecessary and incoherent limit, since not specifying it would use the maximum of 512b.
* Serial UPDI: Change warning level of spammiest messages. Verbose output can now be enabled from the IDE, and the volume of output it generates is sane.
* Add somed comments in optiboot_x.c including prospective new version of flash_led which ensures that the led blinks at the correct speed regardless of OSCCFG fuse.
* Add some comments in optiboot_x.c including prospective new version of flash_led which ensures that the led blinks at the correct speed regardless of OSCCFG fuse.
* Not a change we made, just an observation: There is no more stylechecking on code because the tool we used has vanished from the internet and it's URL doesn't even resolve now.


Expand Down
4 changes: 2 additions & 2 deletions megaavr/libraries/Wire/src/Wire.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -398,8 +398,8 @@ size_t TwoWire::write(uint8_t data) {
*/
size_t TwoWire::write(const uint8_t *data, size_t quantity) {
uint8_t i = 0; // uint8_t since we don't use bigger buffers

for (; i < (uint8_t)quantity; i++) { // limit quantity to 255 to avoid lock up
uint8_t qty = quantity > BUFFER_LENGTH ? BUFFER_LENGTH : quantity; //Don't overfill the buffer.
for (; i < qty; i++) {
if (write(*(data + i)) == 0) break; // break if buffer full
}

Expand Down

0 comments on commit 924086b

Please sign in to comment.