esp-open-rtos/extras/ds1307/ds1307.h

118 lines
2.6 KiB
C
Raw Normal View History

2016-10-09 09:14:17 +00:00
/*
* Driver for DS1307 RTC
*
* Part of esp-open-rtos
* Copyright (C) 2016 Ruslan V. Uss <unclerus@gmail.com>
* BSD Licensed as described in the file LICENSE
*/
#ifndef EXTRAS_DS1307_H_
#define EXTRAS_DS1307_H_
#include <stdint.h>
#include <stdbool.h>
#include <time.h>
2017-09-01 09:29:32 +00:00
#include <i2c/i2c.h>
2016-10-09 09:14:17 +00:00
#ifdef __cplusplus
extern "C" {
#endif
2017-10-18 19:25:48 +00:00
#define DS1307_ADDR 0x68
2016-10-09 09:14:17 +00:00
/**
* Squarewave frequency
*/
2017-10-18 19:25:48 +00:00
typedef enum
2016-10-09 09:14:17 +00:00
{
DS1307_1HZ = 0, //!< 1 Hz
DS1307_4096HZ, //!< 4096 Hz
DS1307_8192HZ, //!< 8192 Hz
DS1307_32768HZ //!< 32768 Hz
} ds1307_squarewave_freq_t;
/**
* \brief Start/stop clock
* \param start Start clock if true
*/
2017-10-18 19:25:48 +00:00
void ds1307_start(i2c_dev_t *dev, bool start);
2016-10-09 09:14:17 +00:00
/**
* \brief Get current clock state
* \return true if clock running
*/
2017-10-18 19:25:48 +00:00
bool ds1307_is_running(i2c_dev_t *dev);
2016-10-09 09:14:17 +00:00
/**
* \brief Get current time
* \param time Pointer to the time struct to fill
*/
2017-10-18 19:25:48 +00:00
void ds1307_get_time(i2c_dev_t *dev, struct tm *time);
2016-10-09 09:14:17 +00:00
/**
* \brief Set time to RTC
* \param time Pointer to the time struct
*/
2017-10-18 19:25:48 +00:00
void ds1307_set_time(i2c_dev_t *dev, const struct tm *time);
2016-10-09 09:14:17 +00:00
/**
* \brief Enable or disable square-wave oscillator output
* \param enable Enable oscillator if true
*/
2017-10-18 19:25:48 +00:00
void ds1307_enable_squarewave(i2c_dev_t *dev, bool enable);
2016-10-09 09:14:17 +00:00
/**
* \brief Get square-wave oscillator output
* \return true if square-wave oscillator enabled
*/
2017-10-18 19:25:48 +00:00
bool ds1307_is_squarewave_enabled(i2c_dev_t *dev);
2016-10-09 09:14:17 +00:00
/**
* \brief Set square-wave oscillator frequency
* \param freq Frequency
*/
2017-10-18 19:25:48 +00:00
void ds1307_set_squarewave_freq(i2c_dev_t *dev, ds1307_squarewave_freq_t freq);
2016-10-09 09:14:17 +00:00
/**
* \brief Get current square-wave oscillator frequency
* \return Frequency
*/
2017-10-18 19:25:48 +00:00
ds1307_squarewave_freq_t ds1307_get_squarewave_freq(i2c_dev_t *dev);
2016-10-09 09:14:17 +00:00
/**
* \brief Get current output level of the SQW/OUT pin
* \return true if high
*/
2017-10-18 19:25:48 +00:00
bool ds1307_get_output(i2c_dev_t *dev);
2016-10-09 09:14:17 +00:00
/**
* \brief Set output level of the SQW/OUT pin
* Set output level if square-wave output is disabled
* \param value High level if true
*/
2017-10-18 19:25:48 +00:00
void ds1307_set_output(i2c_dev_t *dev, bool value);
2016-10-09 09:14:17 +00:00
/**
* \brief Read RAM contents into the buffer
* \param offset Start byte, 0..55
* \param buf Buffer
* \param len Bytes to read, 1..56
* \return Non-zero if error occured
2016-10-09 09:14:17 +00:00
*/
2017-10-18 19:25:48 +00:00
int ds1307_read_ram(i2c_dev_t *dev, uint8_t offset, uint8_t *buf, uint8_t len);
2016-10-09 09:14:17 +00:00
/**
* \brief Write buffer to RTC RAM
* \param offset Start byte, 0..55
* \param buf Buffer
* \param len Bytes to write, 1..56
* \return Non-zero if error occured
2016-10-09 09:14:17 +00:00
*/
2017-10-18 19:25:48 +00:00
int ds1307_write_ram(i2c_dev_t *dev, uint8_t offset, uint8_t *buf, uint8_t len);
2016-10-09 09:14:17 +00:00
#ifdef __cplusplus
}
#endif
#endif /* EXTRAS_DS1307_H_ */