Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

boards/stm32: Fix ds1307 and move it to stm32/common #12166

Merged
merged 2 commits into from
Apr 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
83 changes: 83 additions & 0 deletions boards/arm/stm32/common/include/stm32_ds1307.h
Original file line number Diff line number Diff line change
@@ -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:https://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 */
4 changes: 4 additions & 0 deletions boards/arm/stm32/common/src/Make.defs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand Down Expand Up @@ -33,79 +33,63 @@

#include "stm32.h"
#include "stm32_i2c.h"
#include "stm32f4discovery.h"

#if defined(CONFIG_I2C) && defined(CONFIG_RTC_DS1307)

/****************************************************************************
* 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? */

if (!initialized)
{
/* 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;
}
rtcinfo("Initialize I2C%d\n", DS1307_I2C_BUS);

/* Now bind the I2C interface to the DS1307 RTC driver */
/* Initialize I2C */

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;
}

#ifdef CONFIG_I2C_DRIVER
/* Register the I2C to get the "nsh> i2c bus" command working */
i2c = stm32_i2cbus_initialize(busno);
if (!i2c)
{
rtcerr("ERROR: Failed to initialize I2C%d\n", busno);
return -ENODEV;
}

ret = i2c_register(i2c, DS1307_I2C_BUS);
if (ret < 0)
{
rtcerr("ERROR: Failed to register I2C%d driver: %d\n", bus, ret);
return -ENODEV;
}
#endif
/* Now bind the I2C interface to the DS1307 RTC driver */

/* Synchronize the system time to the RTC time */
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;
}

clock_synchronize(NULL);
/* Synchronize the system time to the RTC time */

/* Now we are initialized */
clock_synchronize(NULL);

initialized = true;
}
/* Now we are initialized */

return OK;
}
Expand Down
4 changes: 0 additions & 4 deletions boards/arm/stm32/stm32f4discovery/src/Make.defs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
6 changes: 5 additions & 1 deletion boards/arm/stm32/stm32f4discovery/src/stm32_bringup.c
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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);
Expand Down
12 changes: 0 additions & 12 deletions boards/arm/stm32/stm32f4discovery/src/stm32f4discovery.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
*
Expand Down
Loading