boards: Move DS1307 initialization to stm32/common
The DS1307 was used as board specific, but it is better move it to stm32/common to be easily used by other boards as well. Signed-off-by: Alan C. Assis <acassis@gmail.com>
This commit is contained in:
parent
96dd39ba2e
commit
9009cd6f2d
83
boards/arm/stm32/common/include/stm32_ds1307.h
Normal file
83
boards/arm/stm32/common/include/stm32_ds1307.h
Normal file
@ -0,0 +1,83 @@
|
||||
/****************************************************************************
|
||||
* boards/arm/stm32/common/include/stm32_ds1307.h
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
* this work for additional information regarding copyright ownership. The
|
||||
* ASF licenses this file to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance with the
|
||||
* License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
|
||||
* WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
|
||||
* License for the specific language governing permissions and limitations
|
||||
* under the License.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef __BOARDS_ARM_STM32_COMMON_INCLUDE_STM32_DS1307_H
|
||||
#define __BOARDS_ARM_STM32_COMMON_INCLUDE_STM32_DS1307_H
|
||||
|
||||
/****************************************************************************
|
||||
* Included Files
|
||||
****************************************************************************/
|
||||
|
||||
#include <nuttx/config.h>
|
||||
|
||||
/****************************************************************************
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Type Definitions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Public Types
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Public Data
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef __cplusplus
|
||||
#define EXTERN extern "C"
|
||||
extern "C"
|
||||
{
|
||||
#else
|
||||
#define EXTERN extern
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Inline Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Public Function Prototypes
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: board_ds1307_initialize
|
||||
*
|
||||
* Description:
|
||||
* Initialize and configure the DS1307 RTC
|
||||
*
|
||||
* Input Parameters:
|
||||
* busno - The I2C bus number where DS1307 is connected.
|
||||
*
|
||||
* Returned Value:
|
||||
* Zero (OK) on success; a negated errno value on failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int board_ds1307_initialize(int busno);
|
||||
|
||||
#undef EXTERN
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
||||
#endif /* __BOARDS_ARM_STM32_COMMON_INCLUDE_STM32_DS1307_H */
|
@ -60,6 +60,10 @@ ifeq ($(CONFIG_LCD_SSD1306),y)
|
||||
CSRCS += stm32_ssd1306.c
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_RTC_DS1307),y)
|
||||
CSRCS += stm32_ds1307.c
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_SENSORS_LM75),y)
|
||||
CSRCS += stm32_lm75.c
|
||||
endif
|
||||
|
@ -1,5 +1,5 @@
|
||||
/****************************************************************************
|
||||
* boards/arm/stm32/stm32f4discovery/src/stm32_ds1307.c
|
||||
* boards/arm/stm32/common/src/stm32_ds1307.c
|
||||
*
|
||||
* Licensed to the Apache Software Foundation (ASF) under one or more
|
||||
* contributor license agreements. See the NOTICE file distributed with
|
||||
@ -33,7 +33,6 @@
|
||||
|
||||
#include "stm32.h"
|
||||
#include "stm32_i2c.h"
|
||||
#include "stm32f4discovery.h"
|
||||
|
||||
#if defined(CONFIG_I2C) && defined(CONFIG_RTC_DS1307)
|
||||
|
||||
@ -41,61 +40,57 @@
|
||||
* Pre-processor Definitions
|
||||
****************************************************************************/
|
||||
|
||||
#define DS1307_I2C_ADDR 0x6f /* DS1307 I2C Address */
|
||||
#define DS1307_I2C_BUS 1 /* DS1307 is on I2C1 */
|
||||
|
||||
/****************************************************************************
|
||||
* Public Functions
|
||||
****************************************************************************/
|
||||
|
||||
/****************************************************************************
|
||||
* Name: stm32_ds1307_init
|
||||
* Name: board_ds1307_initialize
|
||||
*
|
||||
* Description:
|
||||
* Initialize and configure the DS1307 RTC
|
||||
*
|
||||
* Input Parameters:
|
||||
* busno - The I2C bus number where DS1307 is connected.
|
||||
*
|
||||
* Returned Value:
|
||||
* Zero (OK) on success; a negated errno value on failure.
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
int stm32_ds1307_init(void)
|
||||
int board_ds1307_initialize(int busno)
|
||||
{
|
||||
struct i2c_master_s *i2c;
|
||||
static bool initialized = false;
|
||||
int ret;
|
||||
|
||||
/* Have we already initialized? */
|
||||
rtcinfo("Initialize I2C%d\n", DS1307_I2C_BUS);
|
||||
|
||||
if (!initialized)
|
||||
/* Initialize I2C */
|
||||
|
||||
i2c = stm32_i2cbus_initialize(busno);
|
||||
if (!i2c)
|
||||
{
|
||||
/* No.. Get the I2C bus driver */
|
||||
|
||||
rtcinfo("Initialize I2C%d\n", DS1307_I2C_BUS);
|
||||
i2c = stm32_i2cbus_initialize(DS1307_I2C_BUS);
|
||||
if (!i2c)
|
||||
{
|
||||
rtcerr("ERROR: Failed to initialize I2C%d\n", DS1307_I2C_BUS);
|
||||
return -ENODEV;
|
||||
}
|
||||
|
||||
/* Now bind the I2C interface to the DS1307 RTC driver */
|
||||
|
||||
rtcinfo("Bind the DS1307 RTC driver to I2C%d\n", DS1307_I2C_BUS);
|
||||
ret = dsxxxx_rtc_initialize(i2c);
|
||||
if (ret < 0)
|
||||
{
|
||||
rtcerr("ERROR: Failed to bind I2C%d to the DS1307 RTC driver\n",
|
||||
DS1307_I2C_BUS);
|
||||
return -ENODEV;
|
||||
}
|
||||
|
||||
/* Synchronize the system time to the RTC time */
|
||||
|
||||
clock_synchronize(NULL);
|
||||
|
||||
/* Now we are initialized */
|
||||
|
||||
initialized = true;
|
||||
rtcerr("ERROR: Failed to initialize I2C%d\n", busno);
|
||||
return -ENODEV;
|
||||
}
|
||||
|
||||
/* Now bind the I2C interface to the DS1307 RTC driver */
|
||||
|
||||
rtcinfo("Bind the DS1307 RTC driver to I2C%d\n", busno);
|
||||
ret = dsxxxx_rtc_initialize(i2c);
|
||||
if (ret < 0)
|
||||
{
|
||||
rtcerr("ERROR: Failed to bind I2C%d to the DS1307 RTC driver\n",
|
||||
DS1307_I2C_BUS);
|
||||
return -ENODEV;
|
||||
}
|
||||
|
||||
/* Synchronize the system time to the RTC time */
|
||||
|
||||
clock_synchronize(NULL);
|
||||
|
||||
/* Now we are initialized */
|
||||
|
||||
return OK;
|
||||
}
|
||||
|
@ -88,10 +88,6 @@ ifeq ($(CONFIG_RGBLED),y)
|
||||
CSRCS += stm32_rgbled.c
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_RTC_DS1307),y)
|
||||
CSRCS += stm32_ds1307.c
|
||||
endif
|
||||
|
||||
ifeq ($(CONFIG_PWM),y)
|
||||
CSRCS += stm32_pwm.c
|
||||
endif
|
||||
|
@ -76,6 +76,10 @@
|
||||
#include "stm32_bmp180.h"
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_RTC_DS1307
|
||||
#include "stm32_ds1307.h"
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_SENSORS_MS56XX
|
||||
#include "stm32_ms5611.h"
|
||||
#endif
|
||||
@ -454,7 +458,7 @@ int stm32_bringup(void)
|
||||
#endif
|
||||
|
||||
#ifdef CONFIG_RTC_DS1307
|
||||
ret = stm32_ds1307_init();
|
||||
ret = board_ds1307_initialize(1);
|
||||
if (ret < 0)
|
||||
{
|
||||
syslog(LOG_ERR, "Failed to initialize DS1307 RTC driver: %d\n", ret);
|
||||
|
@ -522,18 +522,6 @@ int nunchuck_initialize(char *devname);
|
||||
int stm32_max7219init(const char *devpath);
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Name: stm32_ds1307_init
|
||||
*
|
||||
* Description:
|
||||
* Initialize and register the DS1307 RTC
|
||||
*
|
||||
****************************************************************************/
|
||||
|
||||
#ifdef CONFIG_RTC_DS1307
|
||||
int stm32_ds1307_init(void);
|
||||
#endif
|
||||
|
||||
/****************************************************************************
|
||||
* Name: stm32_st7032init
|
||||
*
|
||||
|
Loading…
Reference in New Issue
Block a user