/*
AMiRo-OS is an operating system designed for the Autonomous Mini Robot (AMiRo) platform.
Copyright (C) 2016..2020 Thomas Schöpping et al.
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see .
*/
/**
* @file
* @brief Structures and constant for the NUCLEO-L476RG module.
*
* @addtogroup NUCLEO-L476RG_module
* @{
*/
#ifndef AMIROOS_MODULE_H
#define AMIROOS_MODULE_H
#include
#if (BOARD_MPU6050_CONNECTED == true)
#include
#endif /* BOARD_MPU6050_CONNECTED == true */
/*===========================================================================*/
/**
* @name Module specific functions
* @{
*/
/*===========================================================================*/
/** @} */
/*===========================================================================*/
/**
* @name ChibiOS/HAL configuration
* @{
*/
/*===========================================================================*/
/**
* @brief Serial driver of the programmer interface.
*/
#define MODULE_HAL_PROGIF SD2
/**
* @brief Configuration for the programmer serial interface driver.
*/
extern SerialConfig moduleHalProgIfConfig;
/**
* @brief Real-Time Clock driver.
*/
#define MODULE_HAL_RTC RTCD1
/**
* @brief Default I2C interface for the NUCLEO I/O.
*/
#define MODULE_HAL_I2C I2CD1
/**
* @brief Configuration for the I2C driver #1.
*/
extern I2CConfig moduleHalI2cConfig;
/** @} */
/*===========================================================================*/
/**
* @name GPIO definitions
* @{
*/
/*===========================================================================*/
/**
* @brief LED output signal GPIO.
*/
extern ROMCONST apalControlGpio_t moduleGpioLed;
/**
* @brief User button input signal.
*/
extern ROMCONST apalControlGpio_t moduleGpioUserButton;
#if (BOARD_VL53L1X_CONNECTED == true)
/**
* @brief VL53L1X interrupt signal (GPIO1).
*/
extern ROMCONST apalControlGpio_t moduleGpioVl53l1xINT;
/**
* @brief VL53L1X XSHUT signal.
*/
extern ROMCONST apalControlGpio_t moduleGpioVl53l1xXSHUT;
#endif /* (BOARD_VL53L1X_CONNECTED == true) */
/** @} */
/*===========================================================================*/
/**
* @name AMiRo-OS core configurations
* @{
*/
/*===========================================================================*/
/**
* @brief Event flag to be set on a USER_BUTTON interrupt.
*/
#define MODULE_OS_GPIOEVENTFLAG_USERBUTTON AOS_GPIOEVENT_FLAG(PAL_PAD(LINE_BUTTON))
#if (AMIROOS_CFG_SHELL_ENABLE == true) || defined(__DOXYGEN__)
/**
* @brief Shell prompt text.
*/
extern ROMCONST char* moduleShellPrompt;
#endif /* (AMIROOS_CFG_SHELL_ENABLE == true) */
/**
* @brief Interrupt initialization macro.
*/
#define MODULE_INIT_INTERRUPTS() { \
/* user button */ \
palSetLineCallback(moduleGpioUserButton.gpio->line, aosSysGetStdGpioCallback(), &moduleGpioUserButton.gpio->line); \
palEnableLineEvent(moduleGpioUserButton.gpio->line, APAL2CH_EDGE(moduleGpioUserButton.meta.edge)); \
MODULE_INIT_INTERRUPTS_VL53L1X(); \
}
#if (BOARD_VL53L1X_CONNECTED == true)
#define MODULE_INIT_INTERRUPTS_VL53L1X() { \
palSetLineCallback(moduleGpioVl53l1xINT.gpio->line, aosSysGetStdGpioCallback(), &moduleGpioVl53l1xINT.gpio->line); \
palEnableLineEvent(moduleGpioVl53l1xINT.gpio->line, APAL2CH_EDGE(moduleGpioVl53l1xINT.meta.edge)); \
}
#else /* (BOARD_VL53L1X_CONNECTED == true) */
#define MODULE_INIT_INTERRUPTS_VL53L1X() {}
#endif /* (BOARD_VL53L1X_CONNECTED == true) */
/**
* @brief Test initialization hook.
*/
#define MODULE_INIT_TESTS() { \
/* add test commands to shell */ \
aosShellAddCommand(&aos.shell, &moduleTestLedShellCmd); \
aosShellAddCommand(&aos.shell, &moduleTestButtonShellCmd); \
MODULE_INIT_TEST_MPU6050(); \
MODULE_INIT_TEST_VL53L1X(); \
aosShellAddCommand(&aos.shell, &moduleTestAllShellCmd); \
}
#if (BOARD_MPU6050_CONNECTED == true)
#define MODULE_INIT_TEST_MPU6050() { \
aosShellAddCommand(&aos.shell, &moduleTestMpu6050ShellCmd); \
}
#else /* (BOARD_MPU6050_CONNECTED == true) */
#define MODULE_INIT_TEST_MPU6050() {}
#endif /* (BOARD_MPU6050_CONNECTED == true) */
#if (BOARD_VL53L1X_CONNECTED == true)
#define MODULE_INIT_TEST_VL53L1X() { \
aosShellAddCommand(&aos.shell, &moduleTestVL53L1XShellCmd); \
}
#else /* (BOARD_VL53L1X_CONNECTED == true) */
#define MODULE_INIT_TEST_VL53L1X() {}
#endif /* (BOARD_VL53L1X_CONNECTED == true) */
/**
* @brief Periphery communication interfaces initialization hook.
*/
#define MODULE_INIT_PERIPHERY_IF() { \
/* serial driver */ \
sdStart(&MODULE_HAL_PROGIF, &moduleHalProgIfConfig); \
/* I2C */ \
uint32_t i2c_freq = 1000000; /* maximum I2C frequency supported for this MCU */ \
MODULE_INIT_PERIPHERY_IF_MPU6050(i2c_freq); \
MODULE_INIT_PERIPHERY_IF_VL53L1X(i2c_freq); \
if (i2c_freq == 100000) /* standard-mode @ 100 kHz */ { \
moduleHalI2cConfig.timingr = 0x10909CEC; /* obtained via STM32CubeMX with STM32_I2CxCLK = 80 MHz */ \
} else if (i2c_freq == 400000) /* fast-mode @ 400 kHz */ { \
moduleHalI2cConfig.timingr = 0x00702991; /* obtained via STM32CubeMX with STM32_I2CxCLK = 80 MHz */ \
} else if (i2c_freq == 1000000) /* fast-mode-plus @ 10000 kHz */ { \
moduleHalI2cConfig.timingr = 0x00300F33; /* obtained via STM32CubeMX with STM32_I2CxCLK = 80 MHz */ \
} else { \
aosDbgAssertMsg(false, "I2C frequency not supported"); \
} \
i2cStart(&MODULE_HAL_I2C, &moduleHalI2cConfig); \
}
/**
* @brief Limits I2C frequency to maximum value supported by MPU6050.
*/
#if (BOARD_MPU6050_CONNECTED == true) || defined(__DOXYGEN__)
#define MODULE_INIT_PERIPHERY_IF_MPU6050(freq) {freq = (MPU6050_LLD_I2C_MAXFREQUENCY < freq) ? MPU6050_LLD_I2C_MAXFREQUENCY : freq;}
#else
#define MODULE_INIT_PERIPHERY_IF_MPU6050(freq) {}
#endif
/**
* @brief Limits I2C frequency to maximum value supported by VL53L1X and configures required GPIOs.
*/
#if (BOARD_VL53L1X_CONNECTED == true) || defined(__DOXYGEN__)
#define MODULE_INIT_PERIPHERY_IF_VL53L1X(freq) { \
freq = (VL53L1X_LLD_I2C_MAXFREQUENCY < freq) ? VL53L1X_LLD_I2C_MAXFREQUENCY : freq; \
chSysLock(); \
/* set XSHUT GPIO as output in open-drain configuration with internal pull-up, but initially pulled-down signal */ \
PAL_PORT(moduleLldVl53l1x.Interface.xshut->gpio->line)->OTYPER &= ~(1U << PAL_PAD(moduleLldVl53l1x.Interface.xshut->gpio->line)); \
PAL_PORT(moduleLldVl53l1x.Interface.xshut->gpio->line)->OTYPER |= PIN_OTYPE_OPENDRAIN(PAL_PAD(moduleLldVl53l1x.Interface.xshut->gpio->line)); \
PAL_PORT(moduleLldVl53l1x.Interface.xshut->gpio->line)->PUPDR &= ~(3U << (PAL_PAD(moduleLldVl53l1x.Interface.xshut->gpio->line) * 2U)); \
PAL_PORT(moduleLldVl53l1x.Interface.xshut->gpio->line)->PUPDR |= PIN_PUPDR_PULLUP(PAL_PAD(moduleLldVl53l1x.Interface.xshut->gpio->line)); \
PAL_PORT(moduleLldVl53l1x.Interface.xshut->gpio->line)->ODR &= ~(1U << PAL_PAD(moduleLldVl53l1x.Interface.xshut->gpio->line)); \
PAL_PORT(moduleLldVl53l1x.Interface.xshut->gpio->line)->ODR |= PIN_ODR_LOW(PAL_PAD(moduleLldVl53l1x.Interface.xshut->gpio->line)); \
PAL_PORT(moduleLldVl53l1x.Interface.xshut->gpio->line)->MODER &= ~(3U << (PAL_PAD(moduleLldVl53l1x.Interface.xshut->gpio->line) * 2U)); \
PAL_PORT(moduleLldVl53l1x.Interface.xshut->gpio->line)->MODER |= PIN_MODE_OUTPUT(PAL_PAD(moduleLldVl53l1x.Interface.xshut->gpio->line)); \
/* set GPIO1 (interrupt) GPIO as input with internal pull-up */ \
PAL_PORT(moduleLldVl53l1x.Interface.gpio1->gpio->line)->PUPDR &= ~(3U << (PAL_PAD(moduleLldVl53l1x.Interface.gpio1->gpio->line) * 2U)); \
PAL_PORT(moduleLldVl53l1x.Interface.gpio1->gpio->line)->PUPDR |= PIN_PUPDR_PULLUP(PAL_PAD(moduleLldVl53l1x.Interface.gpio1->gpio->line)); \
PAL_PORT(moduleLldVl53l1x.Interface.gpio1->gpio->line)->MODER &= ~(3U << (PAL_PAD(moduleLldVl53l1x.Interface.gpio1->gpio->line) * 2U)); \
PAL_PORT(moduleLldVl53l1x.Interface.gpio1->gpio->line)->MODER |= PIN_MODE_INPUT(PAL_PAD(moduleLldVl53l1x.Interface.gpio1->gpio->line)); \
chSysUnlock(); \
}
#else
#define MODULE_INIT_PERIPHERY_IF_VL53L1X(freq) {}
#endif
/**
* @brief Periphery communication interface deinitialization hook.
*/
#define MODULE_SHUTDOWN_PERIPHERY_IF() { \
/* I2C */ \
i2cStop(&MODULE_HAL_I2C); \
/* don't stop the serial driver so messages can still be printed */ \
}
/**
* @brief HOOK to toggle the LEDs when the user button is pressed.
*/
#define MODULE_MAIN_LOOP_GPIOEVENT(eventflags) { \
if (eventflags & MODULE_OS_GPIOEVENTFLAG_USERBUTTON) { \
button_lld_state_t buttonstate; \
button_lld_get(&moduleLldUserButton, &buttonstate); \
led_lld_set(&moduleLldLed, (buttonstate == BUTTON_LLD_STATE_PRESSED) ? LED_LLD_STATE_ON : LED_LLD_STATE_OFF); \
} \
}
/** @} */
/*===========================================================================*/
/**
* @name Startup Shutdown Synchronization Protocol (SSSP)
* @{
*/
/*===========================================================================*/
#if (AMIROOS_CFG_SSSP_ENABLE == true) || defined(__DOXYGEN__)
#error "SSSP is not supported on this module."
#endif /* (AMIROOS_CFG_SSSP_ENABLE == true) */
/** @} */
/*===========================================================================*/
/**
* @name Low-level drivers
* @{
*/
/*===========================================================================*/
#include
#include
/**
* @brief LED driver.
*/
extern LEDDriver moduleLldLed;
/**
* @brief Button driver.
*/
extern ButtonDriver moduleLldUserButton;
#if (BOARD_MPU6050_CONNECTED == true) || defined(__DOXYGEN__)
#include
/**
* @brief Accelerometer (MPU6050) driver.
*/
extern MPU6050Driver moduleLldMpu6050;
#endif /* (BOARD_MPU6050_CONNECTED == true) */
#if (BOARD_VL53L1X_CONNECTED == true) || defined(__DOXYGEN__)
#include
/**
* @brief ToF sensor (VL53L1X) driver.
*/
extern VL53L1XDriver moduleLldVl53l1x;
#endif /* (BOARD_VL53L1X_CONNECTED == true) */
/** @} */
/*===========================================================================*/
/**
* @name Tests
* @{
*/
/*===========================================================================*/
#if (AMIROOS_CFG_TESTS_ENABLE == true) || defined(__DOXYGEN__)
/**
* @brief LED test command.
*/
extern aos_shellcommand_t moduleTestLedShellCmd;
/**
* @brief User button test command.
*/
extern aos_shellcommand_t moduleTestButtonShellCmd;
#if (BOARD_MPU6050_CONNECTED == true) || defined(__DOXYGEN__)
/**
* @brief MPU6050 (Accelerometer & Gyroscope) test command.
*/
extern aos_shellcommand_t moduleTestMpu6050ShellCmd;
#endif /* (BOARD_MPU6050_CONNECTED == true) */
#if (BOARD_VL53L1X_CONNECTED == true) || defined(__DOXYGEN__)
/**
* @brief VL53L1X (ToF sonsor) test command.
*/
extern aos_shellcommand_t moduleTestVL53L1XShellCmd;
#endif /* (BOARD_VL53L1X_CONNECTED == true) */
/**
* @brief Entire module test command.
*/
extern aos_shellcommand_t moduleTestAllShellCmd;
#endif /* (AMIROOS_CFG_TESTS_ENABLE == true) */
/** @} */
#endif /* AMIROOS_MODULE_H */
/** @} */