Various improvements#6
Open
matthijskooijman wants to merge 15 commits into
Open
Conversation
Previously, this would look at the device type selected and for CAT25040 only, put A8 in the command byte rather than in a second address byte. However, it seems that all compatible EEPROMs with 4kbit capacity also use this same exception (e.g. also the ST M95040 or the Microchip AT25040B). With this commit, this exception is made for all devices with a capacity of 4kbit, which makes the code a bit more generic and making it easier to support more chips in the future (this prepares for fixing mattairtech#4).
This variabele is now no longer used, so it can be removed. This means that only the capacity and page size is used to determine how to talk to the chip, which prepares for fixing mattairtech#4.
Previously there was a predefined enum of supported devices, that was translated to a capacity and pageSize value using a switch, which makes it hard to support devices with different settings. Now, the device is specified as a struct containing capacity and pageSize, which makes it trivial to define a new device in the sketch if it is not yet explicitly supported by the library. By making this struct have the same name as the original enum type and predefining variables with the same name as the original enum constants, existing code will continue to work without changes. This fixes mattairtech#4.
Previously, only support for avr, sam and samd was advertised, but there is nothing in this library that is architecture-specific, so it should run on any architecture that properly implements the Arduino API and SPI library. This fixes mattairtech#3
For the write methods, this makes the buffer argument pointer-to-const, so callers know that the buffer passed will not be modified (and the compiler can check this). Where possible, all argument themselves are also made const (including the buffer arguments, which are now const-pointer-to-const). This was already done for most of the arguments, so things are bit more consistent now. This fixes mattairtech#2.
This moves some duplicated code into this new method, and prepares for fixing mattairtech#5.
Previously, when the end of the block aligns with the end of a page, thelast writePage would be called with zero length. This would be a no-op, but better to check beforehand. This also makes it easier to check the writePage result in the next commit.
This prevents an infinite loop when the device is not responding and only 1 bits are read (e.g. connections problems, not powered, etc.). The timeout is fixed to 11ms, which is the 10ms max write time with some margin. Although most chips have max 5ms write time, some (especially larger ones like M95M02) have 10ms. To allow using all of them, use a bigger timeout. This waits a bit longer than needed on other chips, but since this should only be an exception, that is ok. All methods that have the timeout now return 0 to indicate the timeout. This makes it impossible to distinguish between timeouts or invalid parameters, without proper error codes, this is otherwise tricky to distinguish. This fixes mattairtech#5.
This adds the ST M95xxx range, as well as the 2Mbit CAT25M02 that was still missing. The M95xxx devices are essentially essential to the CAT25xxx, except for the M95640, which has a different page size. These settings were based on the datasheets, only the M95640 was actually tested.
This simplifies the code and makes it easier to add an updateByte (consistent with writeByte) later. Also, the compiler might use inlining and/or constant propagation to produce very similar code anyway.
These methods work like writeByte(), writeBlock() and writePage(), but check to see if bytes changed first. See the README and comments for more details on how exactly.
This makes it more explicit what the range is. In addition, on smaller architectures like AVR, size_t is 16-bit which is insufficient to store the capacity of 512kbit and larger EEPROMs.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR makes various improvements, mostly implementing suggestions or fixing bugs I previously submitted as issues. These changes have been running in our firmware for a while now, working well.
For a description of the individual changes, see the commit messages.