Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Fork of ds3231 by
ds3231.cpp
- Committer:
- j3
- Date:
- 2014-11-19
- Revision:
- 1:c814af60fdbf
- Parent:
- 0:b00c4699ae6f
- Child:
- 2:4e6e761c60f2
File content as of revision 1:c814af60fdbf:
/******************************************************************//** * @file ds3231.cpp * * @author Justin Jordan * * @version 0.0 * * Started: 11NOV14 * * Updated: * * @brief Source file for DS3231 class * *********************************************************************** * * @copyright * Copyright (C) 2013 Maxim Integrated Products, Inc., All Rights Reserved. * * Permission is hereby granted, free of charge, to any person obtaining a * copy of this software and associated documentation files (the "Software"), * to deal in the Software without restriction, including without limitation * the rights to use, copy, modify, merge, publish, distribute, sublicense, * and/or sell copies of the Software, and to permit persons to whom the * Software is furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included * in all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR * OTHER DEALINGS IN THE SOFTWARE. * * Except as contained in this notice, the name of Maxim Integrated * Products, Inc. shall not be used except as stated in the Maxim Integrated * Products, Inc. Branding Policy. * * The mere transfer of this software does not imply any licenses * of trade secrets, proprietary technology, copyrights, patents, * trademarks, maskwork rights, or any other form of intellectual * property whatsoever. Maxim Integrated Products, Inc. retains all * ownership rights. **********************************************************************/ #include "ds3231.h" /**********************************************************//** * Constructor for Ds3231 Class * * On Entry: * @param[in] sda - sda pin of I2C bus * @param[in] scl - scl pin of I2C bus * * On Exit: * @return none * * Example: * @code * * //instantiate rtc object * Ds3231 rtc(D14, D15); * * @endcode **************************************************************/ Ds3231::Ds3231(PinName sda, PinName scl) : I2C(sda, scl) { w_adrs = ((DS3231_I2C_ADRS << 1) | I2C_WRITE); r_adrs = ((DS3231_I2C_ADRS << 1) | I2C_READ); } /**********************************************************//** * Sets the time on DS3231 * * On Entry: * @param[in] time - struct cotaining time data; * seconds, minutes and hours * * On Exit: * @return return value = 0 on success, non-0 on failure * * Example: * @code * * //instantiate rtc object * Ds3231 rtc(D14, D15); * * ds3231_time_t time = {0, 0, 0} // time = 0:0:0 24hr format * uint16_t rtn_val; * * rtn_val = rtc.set_time(time); * * @endcode **************************************************************/ uint16_t Ds3231::set_time(ds3231_time_t time) { return 0; } /**********************************************************//** * Sets the calendar on DS3231 * * On Entry: * @param[in] calendar - struct cotaining calendar data; * day, date, month, year * * On Exit: * @return return value = 0 on success, non-0 on failure * * Example: * @code * * //instantiate rtc object * Ds3231 rtc(D14, D15); * * //see datasheet for calendar format * ds3231_calendar_t calendar = {1, 1, 1, 0}; * uint16_t rtn_val; * * rtn_val = rtc.set_calendar(calendar); * * @endcode **************************************************************/ uint16_t Ds3231::set_calendar(ds3231_calendar_t calendar) { return 0; } /**********************************************************//** * Set either Alarm1 or Alarm2 of DS3231 * * On Entry: * @param[in] alarm - struct cotaining alarm data * seconds, minutes, hours, day, date * seconds used on Alarm1 only * @param[in] one_r_two - TRUE for Alarm1 and FALSE for * Alarm2 * * On Exit: * @return return value = 0 on success, non-0 on failure * * Example: * @code * * //instantiate rtc object * Ds3231 rtc(D14, D15); * * //see datasheet for alarm format * ds3231_alrm_t alarm = {0, 0, 0, 0, 0}; * uint16_t rtn_val; * * rtn_val = rtc.set_alarm(alarm, FALSE); * * @endcode **************************************************************/ uint16_t Ds3231::set_alarm(ds3231_alrm_t alarm, bool one_r_two) { return 0; } /**********************************************************//** * Set control and status registers of DS3231 * * On Entry: * @param[in] data - Struct containing control and status * register data * * On Exit: * @return return value = 0 on success, non-0 on failure * * Example: * @code * * //instantiate rtc object * Ds3231 rtc(D14, D15); * * //do not use 0xAA, see datasheet for appropriate data * ds3231_cntl_stat_t data = {0xAA, 0xAA}; * * rtn_val = rtc.set_cntl_stat_reg(data); * * @endcode **************************************************************/ uint16_t Ds3231::set_cntl_stat_reg(ds3231_cntl_stat_t data) { return 0; } /**********************************************************//** * Gets the time on DS3231 * * On Entry: * @param[in] time - struct for storing time data; * seconds, minutes and hours * * On Exit: * @param[out] time - contains current rtc time data * @return return value = 0 on success, non-0 on failure * * Example: * @code * * //instantiate rtc object * Ds3231 rtc(D14, D15); * * ds3231_time_t time = {0, 0, 0} // time = 0:0:0 24hr format * uint16_t rtn_val; * * rtn_val = rtc.get_time(time); * * @endcode **************************************************************/ uint16_t Ds3231::get_time(ds3231_time_t time) { return 0; } /**********************************************************//** * Gets the calendar on DS3231 * * On Entry: * @param[in] calendar - struct for storing calendar data; * day, date, month, year * * On Exit: * @param[out] calendar - contains current rtc calendar * @return return value = 0 on success, non-0 on failure * * Example: * @code * * //instantiate rtc object * Ds3231 rtc(D14, D15); * * //see datasheet for calendar format * ds3231_calendar_t calendar = {1, 1, 1, 0}; * uint16_t rtn_val; * * rtn_val = rtc.get_calendar(calendar); * * @endcode **************************************************************/ uint16_t Ds3231::get_calendar(ds3231_calendar_t calendar) { return 0; } /**********************************************************//** * Get either Alarm1 or Alarm2 of DS3231 * * On Entry: * @param[in] alarm - struct for storing alarm data * seconds, minutes, hours, day, date * seconds used on Alarm1 only * @param[in] one_r_two - TRUE for Alarm1 and FALSE for * Alarm2 * * On Exit: * @param[out] alarm - contains alarm register data * @return return value = 0 on success, non-0 on failure * * Example: * @code * * //instantiate rtc object * Ds3231 rtc(D14, D15); * * //see datasheet for alarm format * ds3231_alrm_t alarm = {0, 0, 0, 0, 0}; * uint16_t rtn_val; * * rtn_val = rtc.get_alarm(alarm, FALSE); * * @endcode **************************************************************/ uint16_t Ds3231::get_alarm(ds3231_alrm_t alarm, bool one_r_two) { return 0; } /**********************************************************//** * Get control and status registers of DS3231 * * On Entry: * @param[in] data - Struct for storing control and status * register data * * On Exit: * @param[out] data - contains control and status registers * data * @return return value = 0 on success, non-0 on failure * * Example: * @code * * //instantiate rtc object * Ds3231 rtc(D14, D15); * * //do not use 0xAA, see datasheet for appropriate data * ds3231_cntl_stat_t data = {0xAA, 0xAA}; * * rtn_val = rtc.get_cntl_stat_reg(data); * * @endcode **************************************************************/ uint16_t Ds3231::get_cntl_stat_reg(ds3231_cntl_stat_t data) { return 0; } /**********************************************************//** * Get temperature data of DS3231 * * On Entry: * @param[in] temp - Integer for storing temperature data * * On Exit: * @param[out] temp - contains temperature data * @return return value = 0 on success, non-0 on failure * * Example: * @code * * //instantiate rtc object * Ds3231 rtc(D14, D15); * * //do not use 0xAA, see datasheet for appropriate data * uint16_t temp; * * rtn_val = rtc.get_temperature(temp); * * @endcode **************************************************************/ uint16_t Ds3231::get_temperature(uint16_t temp) { return 0; }