/* ###################################################################
**     This component module is generated by Processor Expert. Do not modify it.
**     Filename    : McuExtRTC.h
**     Project     : FRDM-K64F_Generator
**     Processor   : MK64FN1M0VLL12
**     Component   : RTC_Maxim
**     Version     : Component 01.026, Driver 01.00, CPU db: 3.00.000
**     Compiler    : GNU C Compiler
**     Date/Time   : 2022-07-05, 20:46, # CodeGen: 776
**     Abstract    :
**          Driver for external I2C based realtime clocks (RTC)
**     Settings    :
**          Component name                                 : McuExtRTC
**          Device                                         : DS3232
**          I2C                                            : McuGenericI2C
**          Utility                                        : McuUtility
**          SDK                                            : McuLib
**          Shell                                          : Enabled
**            Shell                                        : McuShell
**     Contents    :
**         GetRTCTimeDate - uint8_t McuExtRTC_GetRTCTimeDate(McuExtRTC_TTIME *time, McuExtRTC_TDATE *date);
**         SetRTCTimeDate - uint8_t McuExtRTC_SetRTCTimeDate(McuExtRTC_TTIME *time, McuExtRTC_TDATE *date);
**         GetRTCTime     - uint8_t McuExtRTC_GetRTCTime(McuExtRTC_TTIME *time);
**         SetRTCTime     - uint8_t McuExtRTC_SetRTCTime(McuExtRTC_TTIME *time);
**         GetRTCDate     - uint8_t McuExtRTC_GetRTCDate(McuExtRTC_TDATE *date);
**         SetRTCDate     - uint8_t McuExtRTC_SetRTCDate(McuExtRTC_TDATE *date);
**         GetTime        - uint8_t McuExtRTC_GetTime(TIMEREC *time);
**         SetTime        - uint8_t McuExtRTC_SetTime(uint8_t Hour, uint8_t Min, uint8_t Sec, uint8_t...
**         GetDate        - uint8_t McuExtRTC_GetDate(DATEREC *date);
**         SetDate        - uint8_t McuExtRTC_SetDate(uint16_t Year, uint8_t Month, uint8_t Day);
**         GetTemperature - uint8_t McuExtRTC_GetTemperature(float *temperature);
**         Read           - uint8_t McuExtRTC_Read(uint8_t addr, uint8_t *buf, uint8_t bufSize);
**         Write          - uint8_t McuExtRTC_Write(uint8_t addr, uint8_t *buf, uint8_t bufSize);
**         ReadByte       - uint8_t McuExtRTC_ReadByte(uint8_t addr, uint8_t *buf);
**         WriteByte      - uint8_t McuExtRTC_WriteByte(uint8_t addr, uint8_t buf);
**         ReadBlock      - uint8_t McuExtRTC_ReadBlock(uint8_t addr, uint8_t *buf, uint8_t bufSize);
**         WriteBlock     - uint8_t McuExtRTC_WriteBlock(uint8_t addr, uint8_t *buf, uint8_t bufSize);
**         ParseCommand   - uint8_t McuExtRTC_ParseCommand(const unsigned char *cmd, bool *handled, const...
**         Init           - void McuExtRTC_Init(void);
**         Deinit         - void McuExtRTC_Deinit(void);
**
** * Copyright (c) 2014-2022, Erich Styger
**  * Web:         https://mcuoneclipse.com
**  * SourceForge: https://sourceforge.net/projects/mcuoneclipse
**  * Git:         https://github.com/ErichStyger/McuOnEclipse_PEx
**  * All rights reserved.
**  *
**  * Redistribution and use in source and binary forms, with or without modification,
**  * are permitted provided that the following conditions are met:
**  *
**  * - Redistributions of source code must retain the above copyright notice, this list
**  *   of conditions and the following disclaimer.
**  *
**  * - Redistributions in binary form must reproduce the above copyright notice, this
**  *   list of conditions and the following disclaimer in the documentation and/or
**  *   other materials provided with the distribution.
**  *
**  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
**  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
**  * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
**  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
**  * ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
**  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
**  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
**  * ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
**  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
**  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
** ###################################################################*/
/*!
** @file McuExtRTC.h
** @version 01.00
** @brief
**          Driver for external I2C based realtime clocks (RTC)
*/         
/*!
**  @addtogroup McuExtRTC_module McuExtRTC module documentation
**  @{
*/         

#ifndef __McuExtRTC_H
#define __McuExtRTC_H

/* MODULE McuExtRTC. */
#include "McuLib.h" /* SDK and API used */
#include "McuExtRTCconfig.h" /* configuration */

/* Include inherited beans */
#include "McuGenericI2C.h"
#include "McuUtility.h"
#include "McuLib.h"
#include "McuShell.h"


#ifndef __BWUserType_McuExtRTC_TTIME
#define __BWUserType_McuExtRTC_TTIME
  typedef struct {                     /* Time in binary format */
    uint8_t hour;                      /* hours */
    uint8_t min;                       /* minutes */
    uint8_t sec;                       /* seconds */
    bool mode;                         /* clock mode, 0 for 12-hour mode, otherwise 0-24 hour mode */
    uint8_t am_pm;                     /* 0: AM, otherwise PM */
  } McuExtRTC_TTIME;
#endif
#ifndef __BWUserType_McuExtRTC_TDATE
#define __BWUserType_McuExtRTC_TDATE
  typedef struct {                     /* Date in binary format */
    uint8_t year;                      /* year */
    uint8_t month;                     /* month */
    uint8_t day;                       /* day */
    uint8_t dayOfWeek;                 /* Day of week, where 0 is the first day. In the range of 0..6 */
  } McuExtRTC_TDATE;
#endif


#ifndef __BWUserType_TIMEREC
#define __BWUserType_TIMEREC
  typedef struct {                     /* It contains actual number of hours, minutes, seconds and hundreth of seconds. */
    uint8_t Hour;                      /* hours (0 - 23) */
    uint8_t Min;                       /* minutes (0 - 59) */
    uint8_t Sec;                       /* seconds (0 - 59) */
    uint8_t Sec100;                    /* hundredth of seconds (0 - 99) */
  } TIMEREC;
#endif
#ifndef __BWUserType_DATEREC
#define __BWUserType_DATEREC
  typedef struct {                     /* It contains actual year, month, and day description. */
    uint16_t Year;                     /* years (1998 - 2099) */
    uint8_t Month;                     /* months (1 - 12) */
    uint8_t Day;                       /* days (1 - 31) */
  } DATEREC;
#endif

#define McuExtRTC_PARSE_COMMAND_ENABLED  1  /* set to 1 if method ParseCommand() is present, 0 otherwise */

/* device memory addresses */
#if McuExtRTC_CONFIG_DEVICE==3231 || McuExtRTC_CONFIG_DEVICE==3232
  #define McuExtRTC_MEM_SECONDS_ADDR       0x00  /* Seconds */
  #define McuExtRTC_MEM_MINUTES_ADDR       0x01  /* Minutes */
  #define McuExtRTC_MEM_HOURS_ADDR         0x02  /* Hours */
  #define McuExtRTC_MEM_DAY_ADDR           0x03  /* Day */
  #define McuExtRTC_MEM_DATE_ADDR          0x04  /* Date */
  #define McuExtRTC_MEM_MONTH_ADDR         0x05  /* Month */
  #define McuExtRTC_MEM_YEAR_ADDR          0x06  /* Year */
  #define McuExtRTC_MEM_CTRL_ADDR          0x0E  /* Control */
  #define McuExtRTC_MEM_CTRL_STATUS_ADDR   0x0F  /* Control/Status */
  #define McuExtRTC_MEM_AGING_OFFSET_ADDR  0x10  /* Aging offset */
  #define McuExtRTC_MEM_MSB_TEMP_ADDR      0x11  /* MSB of Temp */
  #define McuExtRTC_MEM_LSB_TEMP_ADDR      0x12  /* LSB of Temp */
  /* Address 0x13 is reserved */
  #if McuExtRTC_CONFIG_DEVICE==3232 /* 3231 has no RAM */
    #define McuExtRTC_MEM_RAM_START_ADDR     0x14  /* device memory start address of non-volatile RAM */
    #define McuExtRTC_MEM_RAM_END_ADDR       0xFF  /* device memory end address of non-volatile RAM */
  #endif
#elif McuExtRTC_CONFIG_DEVICE==1307
  #define McuExtRTC_MEM_SECONDS_ADDR       0x00  /* Seconds */
  #define McuExtRTC_MEM_MINUTES_ADDR       0x01  /* Minutes */
  #define McuExtRTC_MEM_HOURS_ADDR         0x02  /* Hours */
  #define McuExtRTC_MEM_DAY_ADDR           0x03  /* Day */
  #define McuExtRTC_MEM_DATE_ADDR          0x04  /* Date */
  #define McuExtRTC_MEM_MONTH_ADDR         0x05  /* Month */
  #define McuExtRTC_MEM_YEAR_ADDR          0x06  /* Year */
  #define McuExtRTC_MEM_CTRL_ADDR          0x07  /* Control */
  #define McuExtRTC_MEM_RAM_START_ADDR     0x08  /* device memory start address of non-volatile RAM */
  #define McuExtRTC_MEM_RAM_END_ADDR       0x3F  /* device memory end address of non-volatile RAM */
#elif McuExtRTC_CONFIG_DEVICE==1342
  #define McuExtRTC_MEM_SECONDS_ADDR       0x00  /* Seconds */
  #define McuExtRTC_MEM_MINUTES_ADDR       0x01  /* Minutes */
  #define McuExtRTC_MEM_HOURS_ADDR         0x02  /* Hours */
  #define McuExtRTC_MEM_DAY_ADDR           0x03  /* Day */
  #define McuExtRTC_MEM_DATE_ADDR          0x04  /* Date */
  #define McuExtRTC_MEM_MONTH_ADDR         0x05  /* Month */
  #define McuExtRTC_MEM_YEAR_ADDR          0x06  /* Year */
  #define McuExtRTC_MEM_CTRL_ADDR          0x0E  /* Control */
#else
  #error "unknown device?"
#endif

#if McuExtRTC_CONFIG_DEVICE==1342
  #define McuExtRTC_MEM_SIZE               (0)  /* no memory for DS1342 */
#elif McuExtRTC_CONFIG_DEVICE==3231
  #define McuExtRTC_MEM_SIZE               (0)  /* no memory for DS3231*/
#else
  #define McuExtRTC_MEM_SIZE               (McuExtRTC_MEM_RAM_END_ADDR-McuExtRTC_MEM_RAM_START_ADDR+1)  /* device memory start address of non-volatile RAM, in bytes */
  #define McuExtRTC_MAX_ADDRESS            (McuExtRTC_MEM_SIZE-1)  /* maximum RAM address of device */
#endif

#define McuExtRTC_MEM_TIME_STRUCT_ADDR      McuExtRTC_MEM_SECONDS_ADDR  /* device memory start address for time */
#define McuExtRTC_MEM_TIME_STRUCT_SIZE      0x03  /* device memory size for time */

#define McuExtRTC_MEM_DATE_STRUCT_ADDR      McuExtRTC_MEM_DAY_ADDR  /* device memory start address for date */
#define McuExtRTC_MEM_DATE_STRUCT_SIZE      0x04  /* device memory size for date */

#define McuExtRTC_MEM_TIME_DATE_STRUCT_ADDR (McuExtRTC_MEM_TIME_STRUCT_ADDR)  /* device memory start address for time and date */
#define McuExtRTC_MEM_TIME_DATE_STRUCT_SIZE (McuExtRTC_MEM_TIME_STRUCT_SIZE+McuExtRTC_MEM_DATE_STRUCT_SIZE)  /* device memory size for time and date */

#define McuExtRTC_TTIME_AMPM_AM   0  /* AM */
#define McuExtRTC_TTIME_AMPM_PM   1  /* PM */
#define McuExtRTC_TTIME_MODE_12H  0  /* 12 hour clock mode */
#define McuExtRTC_TTIME_MODE_24H  1  /* 14 hour clock mode */


uint8_t McuExtRTC_GetRTCTimeDate(McuExtRTC_TTIME *time, McuExtRTC_TDATE *date);
/*
** ===================================================================
**     Method      :  GetRTCTimeDate (component RTC_Maxim)
**
**     Description :
**         Returns the time and date from the device.
**     Parameters  :
**         NAME            - DESCRIPTION
**       * time            - Pointer to time
**       * date            - Pointer to date
**     Returns     :
**         ---             - Error code
** ===================================================================
*/

uint8_t McuExtRTC_SetRTCTimeDate(McuExtRTC_TTIME *time, McuExtRTC_TDATE *date);
/*
** ===================================================================
**     Method      :  SetRTCTimeDate (component RTC_Maxim)
**
**     Description :
**         Sets the date and time.
**     Parameters  :
**         NAME            - DESCRIPTION
**       * time            - Pointer to time to be set
**       * date            - Pointer to date to be set
**     Returns     :
**         ---             - Error code
** ===================================================================
*/

uint8_t McuExtRTC_SetRTCTime(McuExtRTC_TTIME *time);
/*
** ===================================================================
**     Method      :  SetRTCTime (component RTC_Maxim)
**
**     Description :
**         Sets the time using the RTC low level information.
**     Parameters  :
**         NAME            - DESCRIPTION
**       * time            - Pointer to time to be set
**     Returns     :
**         ---             - Error code
** ===================================================================
*/

uint8_t McuExtRTC_GetRTCTime(McuExtRTC_TTIME *time);
/*
** ===================================================================
**     Method      :  GetRTCTime (component RTC_Maxim)
**
**     Description :
**         Returns the time using the RTC low level information.
**     Parameters  :
**         NAME            - DESCRIPTION
**       * time            - Pointer to time
**     Returns     :
**         ---             - Error code
** ===================================================================
*/

uint8_t McuExtRTC_GetRTCDate(McuExtRTC_TDATE *date);
/*
** ===================================================================
**     Method      :  GetRTCDate (component RTC_Maxim)
**
**     Description :
**         Returns the date from the device using the RTC low level
**         information.
**     Parameters  :
**         NAME            - DESCRIPTION
**       * date            - Pointer to date
**     Returns     :
**         ---             - Error code
** ===================================================================
*/

uint8_t McuExtRTC_SetRTCDate(McuExtRTC_TDATE *date);
/*
** ===================================================================
**     Method      :  SetRTCDate (component RTC_Maxim)
**
**     Description :
**         Sets the date using the RTC low level information.
**     Parameters  :
**         NAME            - DESCRIPTION
**       * date            - Pointer to date to be set
**     Returns     :
**         ---             - Error code
** ===================================================================
*/

void McuExtRTC_Init(void);
/*
** ===================================================================
**     Method      :  Init (component RTC_Maxim)
**
**     Description :
**         Initializes the driver.
**     Parameters  : None
**     Returns     : Nothing
** ===================================================================
*/

void McuExtRTC_Deinit(void);
/*
** ===================================================================
**     Method      :  Deinit (component RTC_Maxim)
**
**     Description :
**         Deinitializes the driver.
**     Parameters  : None
**     Returns     : Nothing
** ===================================================================
*/

uint8_t McuExtRTC_Read(uint8_t addr, uint8_t *buf, uint8_t bufSize);
/*
** ===================================================================
**     Method      :  Read (component RTC_Maxim)
**
**     Description :
**         Read from the device
**     Parameters  :
**         NAME            - DESCRIPTION
**         addr            - device memory address
**       * buf             - Pointer to read buffer
**         bufSize         - Size of read buffer
**     Returns     :
**         ---             - Error code
** ===================================================================
*/

uint8_t McuExtRTC_Write(uint8_t addr, uint8_t *buf, uint8_t bufSize);
/*
** ===================================================================
**     Method      :  Write (component RTC_Maxim)
**
**     Description :
**         Write from the device
**     Parameters  :
**         NAME            - DESCRIPTION
**         addr            - device memory address
**       * buf             - Pointer to read buffer
**         bufSize         - 
**     Returns     :
**         ---             - Error code
** ===================================================================
*/

uint8_t McuExtRTC_ParseCommand(const unsigned char *cmd, bool *handled, const McuShell_StdIOType *io);
/*
** ===================================================================
**     Method      :  ParseCommand (component RTC_Maxim)
**
**     Description :
**         Shell Command Line parser
**     Parameters  :
**         NAME            - DESCRIPTION
**       * cmd             - Pointer to command line
**       * handled         - Pointer to variable which tells if
**                           the command has been handled or not
**       * io              - Pointer to I/O structure
**     Returns     :
**         ---             - Error code
** ===================================================================
*/

uint8_t McuExtRTC_ReadByte(uint8_t addr, uint8_t *buf);
/*
** ===================================================================
**     Method      :  ReadByte (component RTC_Maxim)
**
**     Description :
**         Read from the device RAM
**     Parameters  :
**         NAME            - DESCRIPTION
**         addr            - device memory address, with zero as the
**                           RAM start address
**       * buf             - Pointer to read buffer
**     Returns     :
**         ---             - Error code
** ===================================================================
*/

uint8_t McuExtRTC_WriteByte(uint8_t addr, uint8_t buf);
/*
** ===================================================================
**     Method      :  WriteByte (component RTC_Maxim)
**
**     Description :
**         Read from the device RAM
**     Parameters  :
**         NAME            - DESCRIPTION
**         addr            - device memory address, with zero as the
**                           RAM memory start address
**         buf             - value to write
**     Returns     :
**         ---             - Error code
** ===================================================================
*/

uint8_t McuExtRTC_ReadBlock(uint8_t addr, uint8_t *buf, uint8_t bufSize);
/*
** ===================================================================
**     Method      :  ReadBlock (component RTC_Maxim)
**
**     Description :
**         Read from the device RAM
**     Parameters  :
**         NAME            - DESCRIPTION
**         addr            - device memory address, with zero as the
**                           RAM start address
**       * buf             - Pointer to read buffer
**         bufSize         - Size of read buffer
**     Returns     :
**         ---             - Error code
** ===================================================================
*/

uint8_t McuExtRTC_WriteBlock(uint8_t addr, uint8_t *buf, uint8_t bufSize);
/*
** ===================================================================
**     Method      :  WriteBlock (component RTC_Maxim)
**
**     Description :
**         Read from the device RAM
**     Parameters  :
**         NAME            - DESCRIPTION
**         addr            - device memory address, with zero as the
**                           RAM memory start address
**       * buf             - Pointer to read buffer
**         bufSize         - 
**     Returns     :
**         ---             - Error code
** ===================================================================
*/

uint8_t McuExtRTC_GetTime(TIMEREC *time);
/*
** ===================================================================
**     Method      :  GetTime (component RTC_Maxim)
**
**     Description :
**         Returns the time.
**     Parameters  :
**         NAME            - DESCRIPTION
**       * time            - Pointer to time
**     Returns     :
**         ---             - Error code
** ===================================================================
*/

uint8_t McuExtRTC_SetTime(uint8_t Hour, uint8_t Min, uint8_t Sec, uint8_t Sec100);
/*
** ===================================================================
**     Method      :  SetTime (component RTC_Maxim)
**
**     Description :
**         Sets the time.
**     Parameters  :
**         NAME            - DESCRIPTION
**         Hour            - Hours (0 - 23)
**         Min             - Minutes (0 - 59)
**         Sec             - Seconds (0 - 59)
**         Sec100          - Hundredths of seconds (0 - 99)
**     Returns     :
**         ---             - Error code
** ===================================================================
*/

uint8_t McuExtRTC_GetDate(DATEREC *date);
/*
** ===================================================================
**     Method      :  GetDate (component RTC_Maxim)
**
**     Description :
**         Returns the time and date from the device.
**     Parameters  :
**         NAME            - DESCRIPTION
**       * date            - Pointer to date
**     Returns     :
**         ---             - Error code
** ===================================================================
*/

uint8_t McuExtRTC_SetDate(uint16_t Year, uint8_t Month, uint8_t Day);
/*
** ===================================================================
**     Method      :  SetDate (component RTC_Maxim)
**
**     Description :
**         Sets the date.
**     Parameters  :
**         NAME            - DESCRIPTION
**         Year            - Year in 2000 format
**         Month           - Month number (1..12)
**         Day             - Day number (1..31)
**     Returns     :
**         ---             - Error code
** ===================================================================
*/

uint8_t McuExtRTC_GetTemperature(float *temperature);
/*
** ===================================================================
**     Method      :  GetTemperature (component RTC_Maxim)
**
**     Description :
**         Returns the temperature from the device internal temperature
**         sensor. Only available on DS3231 and DS3232.
**     Parameters  :
**         NAME            - DESCRIPTION
**       * temperature     - Pointer to store the
**                           temperature
**     Returns     :
**         ---             - Error code
** ===================================================================
*/

/* END McuExtRTC. */

#endif
/* ifndef __McuExtRTC_H */
/*!
** @}
*/
