#ifndef RTC_H
#define RTC_H

#include "stm32g0xx_hal.h"
#include <stdbool.h>
#include <stdint.h>

/* Initialize the RV-3028 driver with the I2C peripheral used by the module. */
HAL_StatusTypeDef RTC_Init(I2C_HandleTypeDef *hi2c);

/* Optional communication check. */
HAL_StatusTypeDef RTC_IsReady(void);

/* Read and write the RV-3028 32-bit Unix-time counter. */
HAL_StatusTypeDef RTC_SetUnixTime(uint32_t unix_time);
HAL_StatusTypeDef RTC_GetUnixTime(uint32_t *unix_time);

/*
 * Enable Level Switching Mode and save it in the RV-3028 EEPROM.
 * This normally only needs to be called once for a newly configured module.
 */
HAL_StatusTypeDef RTC_EnableOneTimeBackupBattery(void);

// setting periodic alarm
HAL_StatusTypeDef RV3028_StartPeriodicTimer(uint16_t seconds);
HAL_StatusTypeDef RV3028_ClearTimerFlag(void);

/*
 * Call from the STM32 GPIO EXTI callback when the RTC INT pin goes active.
 * RTC_InterruptPending() consumes and clears the software flag.
 */
void RTC_OnInterrupt(void);
bool RTC_InterruptPending(void);

#endif /* RTC_H */