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

Added RAM access functions, removed overloaded begin() function #6

Open
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

kgmossey
Copy link

Bug fix: The Wire.h in the ESP32 library has the ability to set the SDA and SCL pins, but the Arduino Wire.h does not. Anyone trying to use this on an Arduino will get the "no matching function for call to 'TwoWire::begin..." as mentioned in the one issue on this library. I've removed that function so that it will compile properly on Arduino/AVR chips as well as ESP32. When the Arduino library is updated we can replace this function (which is super cool).

Feature add: I've added functions to read and write to RAM. The functions are fairly intuitive, I think.

void getRam() reads the contents of the DS1307 chip into a variable called "ram" which is publicly accessible.
void setRam() writes the contents of "ram" to the DS1307 chip.

If you only need to read/write an address, you can individually set each address to a specific 8 bit value (this saves time over reading/writing the entire ram buffer):

void setRamAddress(uint8_t _addr, uint8_t _value) sets a specific address (_addr) to a value (_value). It also updates the ram buffer.
uint8_t getRamAddress(uint8_t _addr) returns the value at a specific address (_addr)

RAM addresses are 0 indexed.

@kgmossey
Copy link
Author

Added doxygen style function descriptors and a conditional compilation to keep the changes by Saffarofski in the code, but they won't compile since Arduino_h will always be defined. This way for those that want to use them they can just by removing the conditional compilation declarations, but the compile won't fail on Arduino builds.

Copy link

@isidromv isidromv left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for fixing the bug with begin(), I have left a minor comment on your implementation of RAM management.

uint8_t second;
uint8_t minute;
uint8_t hour;
uint8_t dayOfWeek;// day of week, 1 = Monday
uint8_t dayOfMonth;
uint8_t month;
uint16_t year;
uint8_t ram[56];

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This blocks 56 bytes of precious memory, even if the user doesn't plan to manipulate the RAM directly. What about setRam and getRam accepting this as a parameter instead of an internal variable? In this way, only the users requiring it need to allocate the 56 bytes beforehand.

@MatthewJeffson MatthewJeffson added RTC_DS1307 Label for RTC_DS1307 UAY Unassigned yet Pull request Label for pull requests labels Oct 12, 2024
@Lesords Lesords assigned Lesords and ackPeng and unassigned Lesords Oct 15, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Pull request Label for pull requests RTC_DS1307 Label for RTC_DS1307 UAY Unassigned yet
Projects
Status: Todo
Development

Successfully merging this pull request may close these issues.

5 participants