ds1307 - Driver for DS1307 RTC module

group ds1307

ESP-IDF driver for DS1307 real-time clock.

Ported from esp-open-rtos

Copyright (C) 2016, 2018 Ruslan V. Uss unclerus@gmail.com

BSD Licensed as described in the file LICENSE

Defines

DS1307_ADDR

I2C address.

Enums

enum ds1307_squarewave_freq_t

Squarewave frequency.

Values:

enumerator DS1307_1HZ

1 Hz

enumerator DS1307_4096HZ

4096 Hz

enumerator DS1307_8192HZ

8192 Hz

enumerator DS1307_32768HZ

32768 Hz

Functions

esp_err_t ds1307_init_desc(i2c_dev_t *dev, i2c_port_t port, gpio_num_t sda_gpio, gpio_num_t scl_gpio)

Initialize device descriptor.

Return

ESP_OK on success

Parameters
  • dev: Device descriptor

  • port: I2C port

  • sda_gpio: SDA GPIO

  • scl_gpio: SCL GPIO

esp_err_t ds1307_free_desc(i2c_dev_t *dev)

Free device descriptor.

Return

ESP_OK on success

Parameters
  • dev: Device descriptor

esp_err_t ds1307_start(i2c_dev_t *dev, bool start)

Start/stop clock.

Return

ESP_OK on success

Parameters
  • dev: Device descriptor

  • start: Start clock if true

esp_err_t ds1307_is_running(i2c_dev_t *dev, bool *running)

Get current clock state.

Return

ESP_OK on success

Parameters
  • dev: Device descriptor

  • [out] running: true if clock running

esp_err_t ds1307_get_time(i2c_dev_t *dev, struct tm *time)

Get current time.

Return

ESP_OK on success

Parameters
  • dev: Device descriptor

  • [out] time: Pointer to the time struct to fill

esp_err_t ds1307_set_time(i2c_dev_t *dev, const struct tm *time)

Set time to RTC.

Return

ESP_OK on success

Parameters
  • dev: Device descriptor

  • [in] time: Pointer to the time struct

esp_err_t ds1307_enable_squarewave(i2c_dev_t *dev, bool enable)

Enable or disable square-wave oscillator output.

Return

ESP_OK on success

Parameters
  • dev: Device descriptor

  • enable: Enable oscillator if true

esp_err_t ds1307_is_squarewave_enabled(i2c_dev_t *dev, bool *sqw_en)

Get square-wave oscillator output.

Return

ESP_OK on success

Parameters
  • dev: Device descriptor

  • [out] sqw_en: true if square-wave oscillator enabled

esp_err_t ds1307_set_squarewave_freq(i2c_dev_t *dev, ds1307_squarewave_freq_t freq)

Set square-wave oscillator frequency.

Return

ESP_OK on success

Parameters
  • dev: Device descriptor

  • freq: Frequency

esp_err_t ds1307_get_squarewave_freq(i2c_dev_t *dev, ds1307_squarewave_freq_t *sqw_freq)

Get current square-wave oscillator frequency.

Return

ESP_OK on success

Parameters
  • dev: Device descriptor

  • [out] sqw_freq: Frequency

esp_err_t ds1307_get_output(i2c_dev_t *dev, bool *out)

Get current output level of the SQW/OUT pin.

Return

ESP_OK on success

Parameters
  • dev: Device descriptor

  • [out] out: current output level of the SQW/OUT pin, true if high

esp_err_t ds1307_set_output(i2c_dev_t *dev, bool value)

Set output level of the SQW/OUT pin Set output level if square-wave output is disabled.

Return

ESP_OK on success

Parameters
  • dev: Device descriptor

  • value: High level if true

esp_err_t ds1307_read_ram(i2c_dev_t *dev, uint8_t offset, uint8_t *buf, uint8_t len)

Read RAM contents into the buffer.

Return

ESP_OK on success

Parameters
  • dev: Device descriptor

  • offset: Start byte, 0..55

  • [out] buf: Buffer to store data

  • len: Bytes to read, 1..56

esp_err_t ds1307_write_ram(i2c_dev_t *dev, uint8_t offset, uint8_t *buf, uint8_t len)

Write buffer to RTC RAM.

Return

ESP_OK on success

Parameters
  • dev: Device descriptor

  • offset: Start byte, 0..55

  • [in] buf: Buffer

  • len: Bytes to write, 1..56