2017-01-20 11:18:38 +01:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2017 Freie Universität Berlin
|
2017-09-09 09:47:44 +02:00
|
|
|
* 2017 Kaspar Schleiser <kaspar@schleiser.de>
|
2017-01-20 11:18:38 +01:00
|
|
|
*
|
|
|
|
* This file is subject to the terms and conditions of the GNU Lesser General
|
|
|
|
* Public License v2.1. See the file LICENSE in the top level directory for more
|
|
|
|
* details.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @ingroup drivers_periph_init
|
|
|
|
* @{
|
|
|
|
*
|
|
|
|
* @file
|
|
|
|
* @brief Common static peripheral driver initialization implementation
|
|
|
|
*
|
|
|
|
* @author Hauke Petersen <hauke.petersen@fu-berlin.de>
|
2017-09-09 09:47:44 +02:00
|
|
|
* @author Kaspar Schleiser <kaspar@schleiser.de>
|
2017-01-20 11:18:38 +01:00
|
|
|
*
|
|
|
|
* @}
|
|
|
|
*/
|
|
|
|
|
2020-01-16 18:59:04 +01:00
|
|
|
#define USB_H_USER_IS_RIOT_INTERNAL
|
|
|
|
|
2022-01-28 11:18:41 +01:00
|
|
|
#include "kernel_defines.h"
|
2021-12-16 15:05:28 +01:00
|
|
|
#include "periph_conf.h"
|
2020-05-06 00:11:29 +02:00
|
|
|
#include "periph_cpu.h"
|
|
|
|
|
2020-02-28 17:19:11 +01:00
|
|
|
#ifdef MODULE_PERIPH_INIT
|
|
|
|
#ifdef MODULE_PERIPH_INIT_I2C
|
2017-02-08 13:21:06 +01:00
|
|
|
#include "periph/i2c.h"
|
|
|
|
#endif
|
2020-02-28 17:19:11 +01:00
|
|
|
#ifdef MODULE_PERIPH_INIT_SPI
|
2017-01-20 11:18:38 +01:00
|
|
|
#include "periph/spi.h"
|
2017-09-09 09:47:44 +02:00
|
|
|
#endif
|
2020-02-28 17:19:11 +01:00
|
|
|
#ifdef MODULE_PERIPH_INIT_RTC
|
2017-04-13 14:29:32 +02:00
|
|
|
#include "periph/rtc.h"
|
|
|
|
#endif
|
2020-02-28 17:19:11 +01:00
|
|
|
#ifdef MODULE_PERIPH_INIT_RTT
|
2018-02-09 15:51:30 +01:00
|
|
|
#include "periph/rtt.h"
|
|
|
|
#endif
|
2020-02-28 17:19:11 +01:00
|
|
|
#ifdef MODULE_PERIPH_INIT_HWRNG
|
2017-12-08 04:52:37 +01:00
|
|
|
#include "periph/hwrng.h"
|
|
|
|
#endif
|
2020-02-28 17:19:11 +01:00
|
|
|
#ifdef MODULE_PERIPH_INIT_USBDEV
|
2019-03-19 20:16:28 +01:00
|
|
|
#include "periph/usbdev.h"
|
|
|
|
#endif
|
2020-02-28 17:19:11 +01:00
|
|
|
#ifdef MODULE_PERIPH_INIT_WDT
|
2019-09-12 17:44:38 +02:00
|
|
|
#include "periph/wdt.h"
|
|
|
|
#endif
|
2020-07-15 17:18:07 +02:00
|
|
|
#ifdef MODULE_PERIPH_INIT_PTP
|
|
|
|
#include "periph/ptp.h"
|
|
|
|
#endif
|
2021-10-07 21:08:27 +02:00
|
|
|
#ifdef MODULE_PERIPH_INIT_VBAT
|
|
|
|
#include "periph/vbat.h"
|
|
|
|
#endif
|
2021-12-16 14:51:31 +01:00
|
|
|
#ifdef MODULE_PERIPH_INIT_PIO
|
|
|
|
#include "periph/pio.h"
|
|
|
|
#endif
|
2023-06-08 09:51:28 +02:00
|
|
|
#ifdef MODULE_PERIPH_INIT_SDMMC
|
|
|
|
#include "sdmmc/sdmmc.h"
|
|
|
|
#endif
|
2020-02-28 17:19:11 +01:00
|
|
|
#endif /* MODULE_PERIPH_INIT */
|
2017-01-20 11:18:38 +01:00
|
|
|
|
|
|
|
void periph_init(void)
|
|
|
|
{
|
2020-02-28 17:19:11 +01:00
|
|
|
#ifdef MODULE_PERIPH_INIT
|
2022-02-26 22:45:46 +01:00
|
|
|
/* initialize buttonss */
|
|
|
|
if (IS_USED(MODULE_PERIPH_INIT_BUTTONS)) {
|
|
|
|
extern void button_init(void);
|
|
|
|
button_init();
|
2022-01-28 11:18:41 +01:00
|
|
|
}
|
2017-02-08 13:21:06 +01:00
|
|
|
/* initialize configured I2C devices */
|
2020-02-28 17:19:11 +01:00
|
|
|
#ifdef MODULE_PERIPH_INIT_I2C
|
2017-02-08 13:21:06 +01:00
|
|
|
for (unsigned i = 0; i < I2C_NUMOF; i++) {
|
|
|
|
i2c_init(I2C_DEV(i));
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2017-01-20 11:18:38 +01:00
|
|
|
/* initialize configured SPI devices */
|
2020-02-28 17:19:11 +01:00
|
|
|
#ifdef MODULE_PERIPH_INIT_SPI
|
2017-01-20 11:18:38 +01:00
|
|
|
for (unsigned i = 0; i < SPI_NUMOF; i++) {
|
|
|
|
spi_init(SPI_DEV(i));
|
|
|
|
}
|
|
|
|
#endif
|
2017-04-13 14:29:32 +02:00
|
|
|
|
2020-03-16 13:20:12 +01:00
|
|
|
/* Initialize RTT before RTC to allow for RTT based RTC implementations */
|
|
|
|
#ifdef MODULE_PERIPH_INIT_RTT
|
|
|
|
rtt_init();
|
|
|
|
#endif
|
|
|
|
|
2017-04-13 14:29:32 +02:00
|
|
|
/* Initialize RTC */
|
2020-02-28 17:19:11 +01:00
|
|
|
#ifdef MODULE_PERIPH_INIT_RTC
|
2017-04-13 14:29:32 +02:00
|
|
|
rtc_init();
|
|
|
|
#endif
|
2017-12-08 04:52:37 +01:00
|
|
|
|
2020-05-06 00:11:29 +02:00
|
|
|
/* Initialize Tamper Detection */
|
|
|
|
#ifdef MODULE_PERIPH_INIT_GPIO_TAMPER_WAKE
|
|
|
|
rtc_tamper_init();
|
|
|
|
#endif
|
|
|
|
|
2020-02-28 17:19:11 +01:00
|
|
|
#ifdef MODULE_PERIPH_INIT_HWRNG
|
2017-12-08 04:52:37 +01:00
|
|
|
hwrng_init();
|
|
|
|
#endif
|
2019-03-19 20:16:28 +01:00
|
|
|
|
2020-02-28 17:19:11 +01:00
|
|
|
#ifdef MODULE_PERIPH_INIT_USBDEV
|
2019-03-19 20:16:28 +01:00
|
|
|
usbdev_init_lowlevel();
|
|
|
|
#endif
|
2019-09-12 17:44:38 +02:00
|
|
|
|
2020-02-28 17:19:11 +01:00
|
|
|
#if defined(MODULE_PERIPH_INIT_WDT) && WDT_HAS_INIT
|
2019-09-12 17:44:38 +02:00
|
|
|
wdt_init();
|
2022-06-24 14:04:28 +02:00
|
|
|
|
|
|
|
if (IS_ACTIVE(MODULE_PERIPH_WDT_AUTO_START)) {
|
|
|
|
wdt_setup_reboot(CONFIG_PERIPH_WDT_WIN_MIN_MS, CONFIG_PERIPH_WDT_WIN_MAX_MS);
|
|
|
|
wdt_start();
|
|
|
|
}
|
2019-09-12 17:44:38 +02:00
|
|
|
#endif
|
2020-02-28 17:19:11 +01:00
|
|
|
|
2020-07-15 17:18:07 +02:00
|
|
|
#if defined(MODULE_PERIPH_INIT_PTP)
|
|
|
|
ptp_init();
|
|
|
|
#endif
|
|
|
|
|
2023-07-21 17:05:41 +02:00
|
|
|
#if defined(MODULE_PERIPH_INIT_FMC)
|
|
|
|
extern void fmc_init(void);
|
|
|
|
fmc_init();
|
|
|
|
#endif
|
|
|
|
|
2021-10-07 21:08:27 +02:00
|
|
|
#if defined(MODULE_PERIPH_INIT_VBAT)
|
|
|
|
vbat_init();
|
|
|
|
#endif
|
|
|
|
|
2021-12-16 14:51:31 +01:00
|
|
|
#ifdef MODULE_PERIPH_INIT_PIO
|
|
|
|
for (int i = 0; i < (int)PIO_NUMOF; i++) {
|
|
|
|
pio_init(PIO_DEV(i));
|
|
|
|
}
|
2021-12-16 15:05:28 +01:00
|
|
|
#if defined(MODULE_PERIPH_INIT_I2C) && defined(PIO_I2C_NUMOF)
|
|
|
|
for (unsigned i = 0; i < PIO_I2C_NUMOF; i++) {
|
|
|
|
i2c_init(I2C_DEV(I2C_NUMOF + i));
|
|
|
|
}
|
|
|
|
#endif
|
2021-12-16 14:51:31 +01:00
|
|
|
pio_start_programs();
|
|
|
|
#endif
|
|
|
|
|
2023-06-08 09:51:28 +02:00
|
|
|
#if defined(MODULE_PERIPH_INIT_SDMMC)
|
|
|
|
for (unsigned i = 0; i < SDMMC_NUMOF; i++) {
|
|
|
|
sdmmc_init(sdmmc_get_dev(i));
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2020-02-28 17:19:11 +01:00
|
|
|
#endif /* MODULE_PERIPH_INIT */
|
2017-01-20 11:18:38 +01:00
|
|
|
}
|