/* This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . * */ /** @brief library to communicate with the Maxim DS1307 I2C RTC IC (API) * @file rtc_ds1307.h * @author King Kévin * @date 2016 * @todo user RAM is not handled * @note peripherals used: I2C @ref rtc_ds1307_i2c, GPIO @ref rtc_ds1307_square_wave */ #pragma once /** @defgroup rtc_ds1307_square_wave connect Maxim DS1307 square wave output (on PB10) * @{ */ #define SQUARE_WAVE_RCC RCC_GPIOB /**< GPIO peripheral clock (port B) */ #define SQUARE_WAVE_PORT GPIOB /**< GPIO port (port B) */ #define SQUARE_WAVE_PIN GPIO10 /**< GPIO pin (pin PA10) */ #define SQUARE_WAVE_EXTI EXTI10 /**< GPIO external interrupt (exti 10 for pin 12) */ //#define SQUARE_WAVE_IRQ NVIC_EXTI15_10_IRQ /**< GPIO line interrupt (interrupt for line 15 to 10 for pin 10) */ //#define SQUARE_WAVE_ISR exti15_10_isr /**< GPIO line interrupt service routine (isr for line 15 to 10 for pin 10) */ //#define SQUARE_WAVE_HANDLING true /**< to to have the library handle the square wave interrupt (setting square_wave_flag) */ /** @} */ #if defined(SQUARE_WAVE_EXTI) && defined(SQUARE_WAVE_IRQ) && defined(SQUARE_WAVE_ISR) && defined(SQUARE_WAVE_HANDLING) && SQUARE_WAVE_HANDLING extern volatile bool square_wave_flag; /**< set on square wave output */ #endif /** @brief setup communication with RTC IC * configure the I2C port defined in the sources */ void rtc_setup(void); /** @brief verify if oscillator is disabled * @return if oscillator is disabled */ bool rtc_oscillator_disabled(void); /** @brief read square wave output frequency (in Hz) * @return square wave output frequency in Hz, 0 if disabled */ uint16_t rtc_read_square_wave(void); /** @brief read seconds from RTC IC * @return number of seconds (0-59) of the current time */ uint8_t rtc_read_seconds(void); /** @brief read minutes from RTC IC * @return number of minutes (0-59) of the current time */ uint8_t rtc_read_minutes(void); /** @brief read hours from RTC IC * @return number of hours (0-23) of the current time */ uint8_t rtc_read_hours(void); /** @brief read day from RTC IC * @return day of the week (1-7, 1 is Sunday) of the current time, 1 being Sunday */ uint8_t rtc_read_day(void); /** @brief read date from RTC IC * @return day of the month (1-31) of the current time */ uint8_t rtc_read_date(void); /** @brief read month from RTC IC * @return month of the year (1-12) of the current time */ uint8_t rtc_read_month(void); /** @brief read year from RTC IC * @return year (2000-2099) of the current time */ uint16_t rtc_read_year(void); /** @brief read time from RTC IC * @return array of {seconds, minutes, hours, day, date, month, year} as defined above */ uint16_t* rtc_read_time(void); /** @brief disable RTC IC oscillator * @return if disabling oscillator succeeded */ bool rtc_oscillator_disable(void); /** @brief enable RTC IC oscillator * @return if enabling oscillator succeeded */ bool rtc_oscillator_enable(void); /** @brief write square wave output frequency (in Hz) * @param[in] frequency square wave output frequency in Hz (0 to disable, 1, 4096, 8192, 32768) * @return if write succeeded */ bool rtc_write_square_wave(uint16_t frequency); /** @brief write seconds into RTC IC * @param[in] seconds number of seconds (0-59) * @return if write succeeded */ bool rtc_write_seconds(uint8_t seconds); /** @brief write minutes into RTC IC * @param[in] minutes number of minutes (0-59) * @return if write succeeded */ bool rtc_write_minutes(uint8_t minutes); /** @brief write hours into RTC IC * @param[in] hours number of hours (0-23) * @return if write succeeded */ bool rtc_write_hours(uint8_t hours); /** @brief write day into RTC IC * @param[in] day day of the week (1-7, 1 is Sunday) * @return if write succeeded */ bool rtc_write_day(uint8_t day); /** @brief write date into RTC IC * @param[in] date day of the month (1-31) * @return if write succeeded */ bool rtc_write_date(uint8_t date); /** @brief write month into RTC IC * @param[in] month month of the year (1-12) * @return if write succeeded */ bool rtc_write_month(uint8_t month); /** @brief write year into RTC IC * @param[in] year year (2000-2099) * @return if write succeeded */ bool rtc_write_year(uint16_t year); /** @brief write time into RTC IC * @param[in] seconds number of seconds (0-59) * @param[in] minutes number of minutes (0-59) * @param[in] hours number of hours (0-23) * @param[in] day day of the week (1-7, 1 is Sunday) * @param[in] date day of the month (1-31) * @param[in] month month of the year (1-12) * @param[in] year year (2000-2099) * @return if write succeeded */ bool rtc_write_time(uint8_t seconds, uint8_t minutes, uint8_t hours, uint8_t day, uint8_t date, uint8_t month, uint16_t year);