pcf8563 - Driver for PCF8563 real-time clock/calendar

group pcf8563

ESP-IDF driver for PCF8563 real-time clock/calendar.

Copyright (C) 2020 Ruslan V. Uss unclerus@gmail.com

BSD Licensed as described in the file LICENSE

Defines

PCF8563_I2C_ADDR

Enums

enum pcf8563_clkout_freq_t

Frequency output at pin CLKOUT.

Values:

enumerator PCF8563_DISABLED

CLKOUT output is inhibited and set high-impedance.

enumerator PCF8563_32768HZ

32768 Hz

enumerator PCF8563_1024HZ

1024 Hz

enumerator PCF8563_32HZ

32 Hz

enumerator PCF8563_1HZ

1 Hz

enum pcf8563_timer_clock_t

Timer clock.

Values:

enumerator PCF8563_TIMER_4096HZ

4096 Hz

enumerator PCF8563_TIMER_64HZ

64 Hz

enumerator PCF8563_TIMER_1HZ

1 Hz

enumerator PCF8563_TIMER_1_60HZ

1/60 Hz

enum pcf8563_alarm_flags_t

Flags to setup alarm.

Values:

enumerator PCF8563_ALARM_MATCH_MIN

Alarm when minute matched.

enumerator PCF8563_ALARM_MATCH_HOUR

Alarm when hour matched.

enumerator PCF8563_ALARM_MATCH_DAY

Alarm when day matched.

enumerator PCF8563_ALARM_MATCH_WEEKDAY

Alarm when weekday matched.

Functions

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

Initialize device descriptor.

Parameters
  • dev – I2C device descriptor

  • port – I2C port

  • sda_gpio – SDA GPIO

  • scl_gpio – SCL GPIO

Returns

ESP_OK on success

esp_err_t pcf8563_free_desc(i2c_dev_t *dev)

Free device descriptor.

Parameters

dev – I2C device descriptor

Returns

ESP_OK on success

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

Set the time on the RTC.

Parameters
  • dev – I2C device descriptor

  • time – Pointer to time struct

Returns

ESP_OK on success

esp_err_t pcf8563_get_time(i2c_dev_t *dev, struct tm *time, bool *valid)

Get the time from the RTC.

Parameters
  • dev – I2C device descriptor

  • [out] time – Pointer to time struct

  • [out] valid – Time validity, false when RTC had power failures

Returns

ESP_OK on success

esp_err_t pcf8563_set_clkout(i2c_dev_t *dev, pcf8563_clkout_freq_t freq)

Set output frequency on CLKOUT pin.

Parameters
  • dev – I2C device descriptor

  • freq – Frequency

Returns

ESP_OK on success

esp_err_t pcf8563_get_clkout(i2c_dev_t *dev, pcf8563_clkout_freq_t *freq)

Get current frequency on CLKOUT pin.

Parameters
  • dev – I2C device descriptor

  • [out] freq – Frequency

Returns

ESP_OK on success

esp_err_t pcf8563_set_timer_settings(i2c_dev_t *dev, bool int_enable, pcf8563_timer_clock_t clock)

Setup timer.

Parameters
  • dev – I2C device descriptor

  • int_enable – true for enable interrupt on timer

  • clock – Timer frequency

Returns

ESP_OK on success

esp_err_t pcf8563_get_timer_settings(i2c_dev_t *dev, bool *int_enabled, pcf8563_timer_clock_t *clock)

Get timer settings.

Parameters
  • dev – I2C device descriptor

  • [out] int_enabled – true if timer interrupt is enabled

  • [out] clock – Timer frequency

Returns

ESP_OK on success

esp_err_t pcf8563_set_timer_value(i2c_dev_t *dev, uint8_t value)

Set timer register value.

Parameters
  • dev – I2C device descriptor

  • value – Value to set int timer register

Returns

ESP_OK on success

esp_err_t pcf8563_get_timer_value(i2c_dev_t *dev, uint8_t *value)

Get timer register value.

Parameters
  • dev – I2C device descriptor

  • [out] value – Timer value

Returns

ESP_OK on success

esp_err_t pcf8563_start_timer(i2c_dev_t *dev)

Start timer.

Parameters

dev – I2C device descriptor

Returns

ESP_OK on success

esp_err_t pcf8563_stop_timer(i2c_dev_t *dev)

Stop timer.

Parameters

dev – I2C device descriptor

Returns

ESP_OK on success

esp_err_t pcf8563_get_timer_flag(i2c_dev_t *dev, bool *timer)

Get state of the timer flag.

Parameters
  • dev – I2C device descriptor

  • [out] timer – true when flag is set

Returns

ESP_OK on success

esp_err_t pcf8563_clear_timer_flag(i2c_dev_t *dev)

Clear timer flag.

Parameters

dev – I2C device descriptor

Returns

ESP_OK on success

esp_err_t pcf8563_set_alarm(i2c_dev_t *dev, bool int_enable, uint32_t flags, struct tm *time)

Setup alarm.

Parameters
  • dev – I2C device descriptor

  • int_enable – true to enable alarm interrupt

  • flags – Alarm types, combination of pcf8563_alarm_flags_t values

  • time – Alarm time. Only tm_min, tm_hour, tm_mday and tm_wday are used

Returns

ESP_OK on success

esp_err_t pcf8563_get_alarm(i2c_dev_t *dev, bool *int_enabled, uint32_t *flags, struct tm *time)

Get alarm settings.

Parameters
  • dev – I2C device descriptor

  • [out] int_enabled – true if alarm interrupt is enabled

  • [out] flags – Selected alarm types, combination of pcf8563_alarm_flags_t values

  • [out] time – Alarm time. Only tm_min, tm_hour, tm_mday and tm_wday are used

Returns

ESP_OK on success

esp_err_t pcf8563_get_alarm_flag(i2c_dev_t *dev, bool *alarm)

Get alarm flag.

Parameters
  • dev – I2C device descriptor

  • [out] alarm – true if alarm occurred

Returns

ESP_OK on success

esp_err_t pcf8563_clear_alarm_flag(i2c_dev_t *dev)

Clear alarm flag.

Parameters

dev – I2C device descriptor

Returns

ESP_OK on success