Skip to content
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

New EEPROM library. #2794

Merged
merged 6 commits into from
Mar 24, 2015
Merged

New EEPROM library. #2794

merged 6 commits into from
Mar 24, 2015

Conversation

Chris--A
Copy link
Contributor

EEPROM Library V 2.0

This is a new, not just updated, version of the EEPROM library ready for review.

Might as well start with the most important thing first: Yes, this is 100% backwards compatible with the previous version. The new features it provides come with no additional overhead yet provide a huge level of convenience to the end user.

There are a few advanced things I would like to add to this library, however to avoid obfuscating the benefits of this initial proposal, I will add a separate pull request later if this library becomes integrated within the Arduino package.

I can also write a complete documentation up in the form of a readme.md. Then it'll just need copying into the library reference (http://arduino.cc/en/Reference/EEPROM).

Cheers.

New Methods

EEPROM.update( addr, val )

    This function is similar to EEPROM.write() however this
    method only writes data if the cell contents is different.

EEPROM.get( addr, obj )

    This function will retrieve any item from the EEPROM located
    at the address specified. It takes a reference to the object
    which is filled with the data. Its reference is also returned.

EEPROM.put( addr, obj )

    This function will write any item to the EEPROM at the address
    specified. This function uses the 'update' method to write its
    data, and therefore only rewrites changed cells.

EEPROM.length()

    This function returns the number of cells in the EEPROM.
    Some AVR processors have larger EEPROM's than others.

EEPROM.begin()

    This function returns an EEPtr pointing to the first cell
    in the EEPROM. This is used for iteration by STL objects,
    custom iteration and C++11 ranged for loops.

EEPROM.end()

    This function returns an EEPtr pointing to the location
    after the last EEPROM cell. Used with begin() to provide
    custom iteration and C++11 ranged for loops.

Subscript operator: EEPROM[x]

    This allows using the identifier EEPROM like an array.
    EEPROM cells can be read and written directly
    using this method. This operator returns an EERef object.

New Interfaces

EERef class

    This object references an EEPROM cell.
    Its purpose is to mimic a typical byte of RAM, however its storage is the EEPROM.
    This class has an overhead of two bytes, similar to storing a pointer to an EEPROM cell.
    See example eeprom_reference for usage instructions.

EEPtr class

    This object is a bidirectional pointer to EEPROM cells represented by EERef objects.
    Just like a normal pointer type, this type can be dereferenced and repositioned using
    increment/decrement operators. See example eeprom_pointer for usage instructions.

New examples

  • eeprom_update: Sample usage of EEPROM.update()
  • eeprom_put: Sample usage of EEPROM.put()
  • eeprom_get: Sample usage of EEPROM.get()
  • eeprom_iteration: Various methods for looping though EEPROM cells.
  • eeprom_pointer: Explanation and examples for EEPtr class.
  • eeprom_reference: Explanation and examples for EERef class.
  • eeprom_crc: A small app showing the EEPROM object directly used in calculations (CRC algorithm).

Future.

  • I would like to add a clear function, to reset the entire EEPROM to an optional value (or default 0).

Thanks for reading, let me know what your thoughts are.

To avoid having a .cpp just for an extern variable definition, `static`
has been chosen over `extern`.

As the `EEPROMClass` class simply wraps functionality located elsewhere,
it is completely compiled away. Even though each translation unit which
includes the header will get a copy with internal linkage, there is no
associated overhead.

More info
[here](http://stackoverflow.com/questions/29098518/extern-variable-only-in-header-unexpectedly-working-why)
@ffissore
Copy link
Contributor

@ArduinoBot build this please

@ffissore ffissore added Component: Core Related to the code for the standard Arduino API feature request A request to make an enhancement (not a bug fix) labels Mar 19, 2015
@Chris--A
Copy link
Contributor Author

This pull request resolves #178

Removed hard coded lengths, which were incorrect for standard Arduino's
now.
@facchinm
Copy link
Member

Hi @Chris--A ,
this new version seems really good!
update(), put() and get() functions are very handy, but I don't know how many people will use iterators and pointers, so maybe it's better to hide their usage under the hood.
Also, the examples are not very convincing:

  • eeprom_read and eeprom_put do not compile OOTB
  • eeprom_crc seems to perform the calculation on all the EEPROM but it only uses first 32 cells
  • C++11 specific code should be commented until Enable C++11 and C11 #2175 is not merged

I prepared a patch (https://gist.github.com/facchinm/93f52a9092d02b010d69) to address these issues, if you believe it's ok I'll merge with that patch applied.

@matthijskooijman
Copy link
Collaborator

C++11 specific code should be commented until #2175 is not merged

Probably better to use ifdef guards, like https://github.com/matthijskooijman/Arduino/blob/b85c0bf59812ebba27beb0744758be63632f76b3/hardware/arduino/avr/cores/arduino/WString.h#L62

@facchinm
Copy link
Member

I'd prefer not to use ifdefs in the examples, but of course it's better than an example that does not compile 😉

@ffissore
Copy link
Contributor

Indeed examples should be as simple as possible. Less noise there is, the easier to explain/understand

@facchinm facchinm added the Waiting for feedback More information must be provided before we can proceed label Mar 23, 2015
@Chris--A
Copy link
Contributor Author

Hi everyone.

Thanks for taking the time to respond. As a hobby programmer trying to build a bit of a reputable background, its quite satisfying to see interest in one of my projects so quickly 😄.


I do agree, the C++11 functionality should be left until applicable. I'm happy for it to be removed. I do admit the examples were quite rushed. As for the use of EERef & EEPtr, I think this should be something to embrace rather than hide.

Once my version is released as part of the IDE, I plan on starting a forum thread for support, reference and discussion. Not only to inform and help new users with the library, but to get the wider community knowledgeable in it too. It will help create a documentation for all levels of knowledge, or at least provide tips on how to improve the library reference.

As a member of the forums for over three years, I have seen how newbies have changed from being artists and photographers. Compared to now, where a large portion of new users have programming experience in other languages, and being able to use things like references and pointer arithmetic while having the technical things like hardware concepts abstracted away could be deemed quite useful.

I will take some time after work today and add some improvements. I would like to add a readme and document the new functions (old methods included). As for the pointer and reference examples go, maybe they would be better suited rewritten as documentation, and eventually, some examples that actually use them appropriately, so I'll remove them too.

I'm sure some convincing examples will arise once I put it to the forum, I've got a few nice ideas myself, like basic wear leveling.

Anyway, I should be able to get something done before Italy wakes up (if this is where you are).

Cheers, Chris Andrews.

@Chris--A
Copy link
Contributor Author

I have applied the contents of the patch and added a readme. If you are happy with it, feel free to merge.

You can view the readme on my branch here: https://github.com/Chris--A/Arduino/blob/updated_eeprom/hardware/arduino/avr/libraries/EEPROM/README.md

Branch deleted, now available in Arduino repo: https://github.com/arduino/Arduino/blob/master/hardware/arduino/avr/libraries/EEPROM/README.md

@facchinm facchinm merged commit bd2b9d1 into arduino:master Mar 24, 2015
@facchinm
Copy link
Member

Hi @Chris--A ,
I'm very happy to feel all your enthusiasm!
I've merged the patchset with a small fix for Leonardo boards

Cheers!

@Chris--A Chris--A deleted the updated_eeprom branch March 24, 2015 12:53
@Chris--A
Copy link
Contributor Author

Absolutely awesome,

Any forecast on when 1.6.2 is scheduled to be released, I'm assuming at least a few weeks maybe months?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Component: Core Related to the code for the standard Arduino API feature request A request to make an enhancement (not a bug fix) Waiting for feedback More information must be provided before we can proceed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants