diff --git a/configs/samv71-xult/src/sam_bringup.c b/configs/samv71-xult/src/sam_bringup.c index 49b00ced58d..760ee92bd61 100644 --- a/configs/samv71-xult/src/sam_bringup.c +++ b/configs/samv71-xult/src/sam_bringup.c @@ -70,10 +70,14 @@ # include "sam_progmem.h" #endif -#ifdef HAVE_RTC_DSXXXX +#if defined(HAVE_RTC_DSXXXX) || defined(HAVE_RTC_PCF85263) # include # include +#ifdef HAVE_RTC_DSXXXX # include +#else +# include +#endif # include "sam_twihs.h" #endif @@ -117,7 +121,7 @@ int sam_bringup(void) #if defined(HAVE_S25FL1) || defined(HAVE_PROGMEM_CHARDEV) FAR struct mtd_dev_s *mtd; #endif -#ifdef HAVE_RTC_DSXXXX +#if defined(HAVE_RTC_DSXXXX) || defined(HAVE_RTC_PCF85263) FAR struct i2c_dev_s *i2c; #endif #if defined(HAVE_S25FL1_CHARDEV) || defined(HAVE_PROGMEM_CHARDEV) @@ -126,7 +130,32 @@ int sam_bringup(void) #endif int ret; -#ifdef HAVE_RTC_DSXXXX +#if defined(HAVE_RTC_PCF85263) + /* Get an instance of the TWIHS0 I2C interface */ + + i2c = up_i2cinitialize(PCF85263_TWI_BUS); + if (i2c == NULL) + { + SYSLOG("ERROR: up_i2cinitialize(%d) failed\n", PCF85263_TWI_BUS); + } + else + { + /* Use the I2C interface to initialize the PCF2863 timer */ + + ret = pcf85263_rtc_initialize(i2c); + if (ret < 0) + { + SYSLOG("ERROR: pcf85263_rtc_initialize() failed: %d\n", ret); + } + else + { + /* Synchronize the system time to the RTC time */ + + clock_synchronize(); + } + } + +#else /* if defined(HAVE_RTC_DSXXXX) */ /* Get an instance of the TWIHS0 I2C interface */ i2c = up_i2cinitialize(DSXXXX_TWI_BUS); @@ -150,7 +179,6 @@ int sam_bringup(void) clock_synchronize(); } } - #endif #ifdef HAVE_MACADDR diff --git a/configs/samv71-xult/src/samv71-xult.h b/configs/samv71-xult/src/samv71-xult.h index cbbfd268277..060bc458ee3 100644 --- a/configs/samv71-xult/src/samv71-xult.h +++ b/configs/samv71-xult/src/samv71-xult.h @@ -69,6 +69,7 @@ #define HAVE_WM8904 1 #define HAVE_AUDIO_NULL 1 #define HAVE_RTC_DSXXXX 1 +#define HAVE_RTC_PCF85263 1 /* HSMCI */ /* Can't support MMC/SD if the card interface is not enabled */ @@ -301,23 +302,44 @@ /* DS3231/DS1307 RTC * - * For testing purposes, I have connected a Maximum Integrated I2C RTC TWIHS0 - * (available on either EXT or EXT2 pins 11 and 12). + * For testing purposes, I have connected Maximum Integrated DS1307 and NXP + * PCF85263 I2C RTC TWIHS0 (available on either EXT or EXT2 pins 11 and 12). */ -#if !defined(CONFIG_SAMV7_TWIHS0) || !defined(CONFIG_RTC_DSXXXX) +#ifndef CONFIG_RTC_DSXXXX # undef HAVE_RTC_DSXXXX #endif +#ifndef CONFIG_RTC_PCF85263 +# undef HAVE_RTC_PCF85263 +#endif + +#ifndef CONFIG_SAMV7_TWIHS0 +# undef HAVE_RTC_DSXXXX +# undef HAVE_RTC_PCF85263 +#endif + #if !defined(CONFIG_RTC) || !defined(CONFIG_RTC_DATETIME) # undef HAVE_RTC_DSXXXX +# undef HAVE_RTC_PCF85263 +#endif + +#if defined(HAVE_RTC_DSXXXX) && defined(HAVE_RTC_PCF85263) +# undef HAVE_RTC_DSXXXX #endif #ifdef HAVE_RTC_DSXXXX /* The DS3231/1307 RTC communicates on TWI0, I2C address 0x68 */ -# define DSXXXX_TWI_BUS 0 -# define DSXXXX_I2C_ADDRESS 0x68 +# define DSXXXX_TWI_BUS 0 +# define DSXXXX_I2C_ADDRESS 0x68 +#endif + +#ifdef HAVE_RTC_PCF85263 +/* The PCF85263 RTC communicates on TWI0, I2C address 0x51 */ + +# define PCF85263_TWI_BUS 0 +# define PCF85263_I2C_ADDRESS 0x51 #endif /* SAMV71-XULT GPIO Pin Definitions *************************************************/