From 7e2682c0e801e6b3f4edaeb291db221a1df7056a Mon Sep 17 00:00:00 2001 From: Giovanni Di Sirio Date: Tue, 15 Mar 2016 14:48:56 +0000 Subject: git-svn-id: svn://svn.code.sf.net/p/chibios/svn/trunk@9114 35acf78f-673a-0410-8e92-d51de3d6d3f4 --- os/hal/lib/peripherals/include/hal_accelerometer.h | 145 ----------------- os/hal/lib/peripherals/include/hal_compass.h | 144 ----------------- os/hal/lib/peripherals/include/hal_gyroscope.h | 177 --------------------- os/hal/lib/peripherals/include/hal_sensors.h | 147 ----------------- os/hal/lib/peripherals/sensors/hal_accelerometer.h | 145 +++++++++++++++++ os/hal/lib/peripherals/sensors/hal_compass.h | 144 +++++++++++++++++ os/hal/lib/peripherals/sensors/hal_gyroscope.h | 177 +++++++++++++++++++++ os/hal/lib/peripherals/sensors/hal_sensors.h | 147 +++++++++++++++++ 8 files changed, 613 insertions(+), 613 deletions(-) delete mode 100644 os/hal/lib/peripherals/include/hal_accelerometer.h delete mode 100644 os/hal/lib/peripherals/include/hal_compass.h delete mode 100644 os/hal/lib/peripherals/include/hal_gyroscope.h delete mode 100644 os/hal/lib/peripherals/include/hal_sensors.h create mode 100644 os/hal/lib/peripherals/sensors/hal_accelerometer.h create mode 100644 os/hal/lib/peripherals/sensors/hal_compass.h create mode 100644 os/hal/lib/peripherals/sensors/hal_gyroscope.h create mode 100644 os/hal/lib/peripherals/sensors/hal_sensors.h (limited to 'os/hal/lib') diff --git a/os/hal/lib/peripherals/include/hal_accelerometer.h b/os/hal/lib/peripherals/include/hal_accelerometer.h deleted file mode 100644 index 7cd296e2f..000000000 --- a/os/hal/lib/peripherals/include/hal_accelerometer.h +++ /dev/null @@ -1,145 +0,0 @@ -/* - ChibiOS - Copyright (C) 2016 Rocco Marco Guglielmi - - Licensed 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. -*/ - -/** - * @file hal_accelerometer.h - * @brief Generic accelerometer interface header. - * - * @addtogroup HAL_ACCELEROMETER - * @{ - */ - -#ifndef _HAL_ACCELEROMETER_H_ -#define _HAL_ACCELEROMETER_H_ - -#include "hal_sensors.h" - -/*===========================================================================*/ -/* Driver constants. */ -/*===========================================================================*/ - -/*===========================================================================*/ -/* Driver pre-compile time settings. */ -/*===========================================================================*/ - -/*===========================================================================*/ -/* Derived constants and error checks. */ -/*===========================================================================*/ - -/*===========================================================================*/ -/* Driver data structures and types. */ -/*===========================================================================*/ - -/** - * @brief BaseAccelerometer specific methods. - */ -#define _base_accelerometer_methods_alone - -/** - * @brief BaseAccelerometer specific methods with inherited ones. - */ -#define _base_accelerometer_methods \ - _base_sensor_methods \ - _base_accelerometer_methods_alone - -/** - * @brief @p BaseAccelerometer virtual methods table. - */ -struct BaseAccelerometerVMT { - _base_accelerometer_methods -}; - -/** - * @brief @p BaseAccelerometer specific data. - */ -#define _base_accelerometer_data \ - _base_sensor_data - -/** - * @brief Base accelerometer class. - * @details This class represents a generic a generic accelerometer. - */ -typedef struct { - /** @brief Virtual Methods Table.*/ - const struct BaseAccelerometerVMT *vmt_baseaccelerometer; - _base_sensor_data -} BaseAccelerometer; - -/*===========================================================================*/ -/* Driver macros. */ -/*===========================================================================*/ - -/** - * @name Macro Functions (BaseAccelerometer) - * @{ - */ -/** - * @brief Accelerometer get axes number. - * - * @param[in] ip pointer to a @p BaseAccelerometer class. - * @return The number of axes of the BaseSensor - * - * @api - */ -#define accelerometerGetAxesNumber(ip) \ - (ip)->vmt_baseaccelerometer->get_axes_number(ip) - -/** - * @brief Accelerometer read raw data. - * - * @param[in] ip pointer to a @p BaseAccelerometer class. - * @param[in] dp pointer to a data array. - * - * @return The operation status. - * @retval MSG_OK if the function succeeded. - * @retval MSG_RESET if one or more errors occurred. - * - * @api - */ -#define accelerometerReadRaw(ip, dp) \ - (ip)->vmt_baseaccelerometer->read_raw(ip, dp) - -/** - * @brief Accelerometer read cooked data. - * - * @param[in] ip pointer to a @p BaseAccelerometer class. - * @param[in] dp pointer to a data array. - * - * @return The operation status. - * @retval MSG_OK if the function succeeded. - * @retval MSG_RESET if one or more errors occurred. - * - * @api - */ -#define accelerometerReadCooked(ip, dp) \ - (ip)->vmt_baseaccelerometer->read_cooked(ip, dp) -/** @} */ - -/*===========================================================================*/ -/* External declarations. */ -/*===========================================================================*/ - -#ifdef __cplusplus -extern "C" { -#endif - -#ifdef __cplusplus -} -#endif - -#endif /* _HAL_ACCELEROMETER_H_ */ - -/** @} */ diff --git a/os/hal/lib/peripherals/include/hal_compass.h b/os/hal/lib/peripherals/include/hal_compass.h deleted file mode 100644 index 6ae9a9735..000000000 --- a/os/hal/lib/peripherals/include/hal_compass.h +++ /dev/null @@ -1,144 +0,0 @@ -/* - ChibiOS - Copyright (C) 2016 Rocco Marco Guglielmi - - Licensed 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. -*/ - -/** - * @file hal_compass.h - * @brief Generic compass interface header. - * - * @addtogroup HAL_COMPASS - * @{ - */ - -#ifndef _HAL_COMPASS_H_ -#define _HAL_COMPASS_H_ - -#include "hal_sensors.h" - -/*===========================================================================*/ -/* Driver constants. */ -/*===========================================================================*/ - -/*===========================================================================*/ -/* Driver pre-compile time settings. */ -/*===========================================================================*/ - -/*===========================================================================*/ -/* Derived constants and error checks. */ -/*===========================================================================*/ - -/*===========================================================================*/ -/* Driver data structures and types. */ -/*===========================================================================*/ - -/** - * @brief BaseCompass specific methods. - */ -#define _base_compass_methods_alone - -/** - * @brief BaseCompass specific methods with inherited ones. - */ -#define _base_compass_methods \ - _base_sensor_methods \ - _base_compass_methods_alone - -/** - * @brief @p BaseCompass virtual methods table. - */ -struct BaseCompassVMT { - _base_compass_methods -}; - -/** - * @brief @p BaseCompass specific data. - */ -#define _base_compass_data \ - _base_sensor_data - -/** - * @brief Base compass class. - * @details This class represents a generic compass. - */ -typedef struct { - /** @brief Virtual Methods Table.*/ - const struct BaseCompassVMT *vmt_basecompass; - _base_compass_data -} BaseCompass; - -/*===========================================================================*/ -/* Driver macros. */ -/*===========================================================================*/ -/** - * @name Macro Functions (BaseCompass) - * @{ - */ -/** - * @brief Compass get axes number. - * - * @param[in] ip pointer to a @p BaseCompass class. - * @return The number of axes of the BaseSensor - * - * @api - */ -#define compassGetAxesNumber(ip) \ - (ip)->vmt_basecompass->get_axes_number(ip) - -/** - * @brief Compass read raw data. - * - * @param[in] ip pointer to a @p BaseCompass class. - * @param[in] dp pointer to a data array. - * - * @return The operation status. - * @retval MSG_OK if the function succeeded. - * @retval MSG_RESET if one or more errors occurred. - * - * @api - */ -#define compassReadRaw(ip, dp) \ - (ip)->vmt_basecompass->read_raw(ip, dp) - -/** - * @brief Compass read cooked data. - * - * @param[in] ip pointer to a @p BaseCompass class. - * @param[in] dp pointer to a data array. - * - * @return The operation status. - * @retval MSG_OK if the function succeeded. - * @retval MSG_RESET if one or more errors occurred. - * - * @api - */ -#define compassReadCooked(ip, dp) \ - (ip)->vmt_basecompass->read_cooked(ip, dp) -/** @} */ - -/*===========================================================================*/ -/* External declarations. */ -/*===========================================================================*/ - -#ifdef __cplusplus -extern "C" { -#endif - -#ifdef __cplusplus -} -#endif - -#endif /* _HAL_COMPASS_H_ */ - -/** @} */ diff --git a/os/hal/lib/peripherals/include/hal_gyroscope.h b/os/hal/lib/peripherals/include/hal_gyroscope.h deleted file mode 100644 index 06ec8644a..000000000 --- a/os/hal/lib/peripherals/include/hal_gyroscope.h +++ /dev/null @@ -1,177 +0,0 @@ -/* - ChibiOS - Copyright (C) 2016 Rocco Marco Guglielmi - - Licensed 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. -*/ - -/** - * @file hal_gyroscope.h - * @brief Generic gyroscope interface header. - * - * @addtogroup HAL_GYROSCOPE - * @{ - */ - -#ifndef _HAL_GYROSCOPE_H_ -#define _HAL_GYROSCOPE_H_ - -#include "hal_sensors.h" - -/*===========================================================================*/ -/* Driver constants. */ -/*===========================================================================*/ - -/*===========================================================================*/ -/* Driver pre-compile time settings. */ -/*===========================================================================*/ - -/*===========================================================================*/ -/* Derived constants and error checks. */ -/*===========================================================================*/ - -/*===========================================================================*/ -/* Driver data structures and types. */ -/*===========================================================================*/ - -/** - * @brief BaseGyroscope specific methods. - */ -#define _base_gyroscope_methods_alone \ - /* Remove the calibration data.*/ \ - msg_t (*reset_calibration)(void *instance); \ - /* Invokes the calibration procedure.*/ \ - msg_t (*calibrate)(void *instance); - -/** - * @brief BaseGyroscope specific methods with inherited ones. - */ -#define _base_gyroscope_methods \ - _base_sensor_methods \ - _base_gyroscope_methods_alone - -/** - * @brief @p BaseGyroscope virtual methods table. - */ -struct BaseGyroscopeVMT { - _base_gyroscope_methods -}; - -/** - * @brief @p BaseGyroscope specific data. - */ -#define _base_gyroscope_data \ - _base_sensor_data - -/** - * @brief Base gyroscope class. - * @details This class represents a generic gyroscope. - */ -typedef struct { - /** @brief Virtual Methods Table.*/ - const struct BaseGyroscopeVMT *vmt_basegyroscope; - _base_gyroscope_data -} BaseGyroscope; - -/*===========================================================================*/ -/* Driver macros. */ -/*===========================================================================*/ - -/** - * @name Macro Functions (BaseGyroscope) - * @{ - */ -/** - * @brief Gyroscope get axes number. - * - * @param[in] ip pointer to a @p BaseGyroscope class. - * @return The number of axes of the BaseSensor - * - * @api - */ -#define gyroscopeGetAxesNumber(ip) \ - (ip)->vmt_basegyroscope->get_axes_number(ip) - -/** - * @brief Gyroscope read raw data. - * - * @param[in] ip pointer to a @p BaseGyroscope class. - * @param[in] dp pointer to a data array. - * - * @return The operation status. - * @retval MSG_OK if the function succeeded. - * @retval MSG_RESET if one or more errors occurred. - * - * @api - */ -#define gyroscopeReadRaw(ip, dp) \ - (ip)->vmt_basegyroscope->read_raw(ip, dp) - -/** - * @brief Gyroscope read cooked data. - * - * @param[in] ip pointer to a @p BaseGyroscope class. - * @param[in] dp pointer to a data array. - * - * @return The operation status. - * @retval MSG_OK if the function succeeded. - * @retval MSG_RESET if one or more errors occurred. - * - * @api - */ -#define gyroscopeReadCooked(ip, dp) \ - (ip)->vmt_basegyroscope->read_cooked(ip, dp) - -/** - * @brief Delete calibration data. - * - * @param[in] ip pointer to a @p BaseGyroscope class. - * - * @return The operation status. - * @retval MSG_OK if the function succeeded. - * @retval MSG_RESET if one or more errors occurred. - * - * @api - */ -#define gyroscopeResetCalibration(ip) \ - (ip)->vmt_basegyroscope->reset_calibration(ip) - -/** - * @brief Gyroscope calibration procedure. - * - * @param[in] ip pointer to a @p BaseGyroscope class. - * - * @return The operation status. - * @retval MSG_OK if the function succeeded. - * @retval MSG_RESET if one or more errors occurred. - * - * @api - */ -#define gyroscopeCalibrate(ip) \ - (ip)->vmt_basegyroscope->calibrate(ip) -/** @} */ - -/*===========================================================================*/ -/* External declarations. */ -/*===========================================================================*/ - -#ifdef __cplusplus -extern "C" { -#endif - -#ifdef __cplusplus -} -#endif - -#endif /* _HAL_GYROSCOPE_H_ */ - -/** @} */ diff --git a/os/hal/lib/peripherals/include/hal_sensors.h b/os/hal/lib/peripherals/include/hal_sensors.h deleted file mode 100644 index fc2766d64..000000000 --- a/os/hal/lib/peripherals/include/hal_sensors.h +++ /dev/null @@ -1,147 +0,0 @@ -/* - ChibiOS - Copyright (C) 2016 Rocco Marco Guglielmi - - Licensed 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. -*/ - -/** - * @file hal_sensors.h - * @brief Generic sensors interface header. - * - * @addtogroup HAL_SENSORS - * @{ - */ - -#ifndef _HAL_SENSORS_H_ -#define _HAL_SENSORS_H_ - -/*===========================================================================*/ -/* Driver constants. */ -/*===========================================================================*/ - -/*===========================================================================*/ -/* Driver pre-compile time settings. */ -/*===========================================================================*/ - -/*===========================================================================*/ -/* Derived constants and error checks. */ -/*===========================================================================*/ - -/*===========================================================================*/ -/* Driver data structures and types. */ -/*===========================================================================*/ - -/** - * @brief BaseSensor specific methods. - */ -#define _base_sensor_methods_alone \ - /* Get number of axes.*/ \ - size_t (*get_axes_number)(void *instance); \ - /* Reads the sensor raw data.*/ \ - msg_t (*read_raw)(void *instance, int32_t axes[]); \ - /* Reads the sensor returning normalized data.*/ \ - msg_t (*read_cooked)(void *instance, float axes[]); - -/** - * @brief BaseSensor specific methods with inherited ones. - */ -#define _base_sensor_methods \ - _base_sensor_methods_alone - -/** - * @brief @p BaseSensor virtual methods table. - */ -struct BaseSensorVMT { - _base_sensor_methods -}; - -/** - * @brief @p BaseSensor specific data. - * @note It is empty because @p BaseSensor is only an interface - * without implementation. - */ -#define _base_sensor_data - -/** - * @brief Base stream class. - * @details This class represents a generic blocking unbuffered sequential - * data stream. - */ -typedef struct { - /** @brief Virtual Methods Table.*/ - const struct BaseSensorVMT *vmt_basesensor; - _base_sensor_data -} BaseSensor; - -/*===========================================================================*/ -/* Driver macros. */ -/*===========================================================================*/ - -/** - * @name Macro Functions (BaseSensor) - * @{ - */ -/** - * @brief Sensors get axes number. - * - * @param[in] ip pointer to a @p BaseSensor or derived class. - * @return The number of axes of the BaseSensor - * - * @api - */ -#define sensorGetAxesNumber(ip) (ip)->vmt_basesensor->get_axes_number(ip) - -/** - * @brief Sensors read raw data. - * - * @param[in] ip pointer to a @p BaseSensor or derived class. - * @param[in] dp pointer to a data array. - * - * @return The operation status. - * @retval MSG_OK if the function succeeded. - * @retval MSG_RESET if one or more errors occurred. - * - * @api - */ -#define sensorReadRaw(ip, dp) (ip)->vmt_basesensor->read_raw(ip, dp) - -/** - * @brief Sensors read cooked data. - * - * @param[in] ip pointer to a @p BaseSensor or derived class. - * @param[in] dp pointer to a data array. - * - * @return The operation status. - * @retval MSG_OK if the function succeeded. - * @retval MSG_RESET if one or more errors occurred. - * - * @api - */ -#define sensorReadCooked(ip, dp) (ip)->vmt_basesensor->read_cooked(ip, dp) -/** @} */ - -/*===========================================================================*/ -/* External declarations. */ -/*===========================================================================*/ - -#ifdef __cplusplus -extern "C" { -#endif - -#ifdef __cplusplus -} -#endif - -#endif /* _HAL_SENSORS_H_ */ - -/** @} */ diff --git a/os/hal/lib/peripherals/sensors/hal_accelerometer.h b/os/hal/lib/peripherals/sensors/hal_accelerometer.h new file mode 100644 index 000000000..7cd296e2f --- /dev/null +++ b/os/hal/lib/peripherals/sensors/hal_accelerometer.h @@ -0,0 +1,145 @@ +/* + ChibiOS - Copyright (C) 2016 Rocco Marco Guglielmi + + Licensed 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. +*/ + +/** + * @file hal_accelerometer.h + * @brief Generic accelerometer interface header. + * + * @addtogroup HAL_ACCELEROMETER + * @{ + */ + +#ifndef _HAL_ACCELEROMETER_H_ +#define _HAL_ACCELEROMETER_H_ + +#include "hal_sensors.h" + +/*===========================================================================*/ +/* Driver constants. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Driver pre-compile time settings. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Derived constants and error checks. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Driver data structures and types. */ +/*===========================================================================*/ + +/** + * @brief BaseAccelerometer specific methods. + */ +#define _base_accelerometer_methods_alone + +/** + * @brief BaseAccelerometer specific methods with inherited ones. + */ +#define _base_accelerometer_methods \ + _base_sensor_methods \ + _base_accelerometer_methods_alone + +/** + * @brief @p BaseAccelerometer virtual methods table. + */ +struct BaseAccelerometerVMT { + _base_accelerometer_methods +}; + +/** + * @brief @p BaseAccelerometer specific data. + */ +#define _base_accelerometer_data \ + _base_sensor_data + +/** + * @brief Base accelerometer class. + * @details This class represents a generic a generic accelerometer. + */ +typedef struct { + /** @brief Virtual Methods Table.*/ + const struct BaseAccelerometerVMT *vmt_baseaccelerometer; + _base_sensor_data +} BaseAccelerometer; + +/*===========================================================================*/ +/* Driver macros. */ +/*===========================================================================*/ + +/** + * @name Macro Functions (BaseAccelerometer) + * @{ + */ +/** + * @brief Accelerometer get axes number. + * + * @param[in] ip pointer to a @p BaseAccelerometer class. + * @return The number of axes of the BaseSensor + * + * @api + */ +#define accelerometerGetAxesNumber(ip) \ + (ip)->vmt_baseaccelerometer->get_axes_number(ip) + +/** + * @brief Accelerometer read raw data. + * + * @param[in] ip pointer to a @p BaseAccelerometer class. + * @param[in] dp pointer to a data array. + * + * @return The operation status. + * @retval MSG_OK if the function succeeded. + * @retval MSG_RESET if one or more errors occurred. + * + * @api + */ +#define accelerometerReadRaw(ip, dp) \ + (ip)->vmt_baseaccelerometer->read_raw(ip, dp) + +/** + * @brief Accelerometer read cooked data. + * + * @param[in] ip pointer to a @p BaseAccelerometer class. + * @param[in] dp pointer to a data array. + * + * @return The operation status. + * @retval MSG_OK if the function succeeded. + * @retval MSG_RESET if one or more errors occurred. + * + * @api + */ +#define accelerometerReadCooked(ip, dp) \ + (ip)->vmt_baseaccelerometer->read_cooked(ip, dp) +/** @} */ + +/*===========================================================================*/ +/* External declarations. */ +/*===========================================================================*/ + +#ifdef __cplusplus +extern "C" { +#endif + +#ifdef __cplusplus +} +#endif + +#endif /* _HAL_ACCELEROMETER_H_ */ + +/** @} */ diff --git a/os/hal/lib/peripherals/sensors/hal_compass.h b/os/hal/lib/peripherals/sensors/hal_compass.h new file mode 100644 index 000000000..6ae9a9735 --- /dev/null +++ b/os/hal/lib/peripherals/sensors/hal_compass.h @@ -0,0 +1,144 @@ +/* + ChibiOS - Copyright (C) 2016 Rocco Marco Guglielmi + + Licensed 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. +*/ + +/** + * @file hal_compass.h + * @brief Generic compass interface header. + * + * @addtogroup HAL_COMPASS + * @{ + */ + +#ifndef _HAL_COMPASS_H_ +#define _HAL_COMPASS_H_ + +#include "hal_sensors.h" + +/*===========================================================================*/ +/* Driver constants. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Driver pre-compile time settings. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Derived constants and error checks. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Driver data structures and types. */ +/*===========================================================================*/ + +/** + * @brief BaseCompass specific methods. + */ +#define _base_compass_methods_alone + +/** + * @brief BaseCompass specific methods with inherited ones. + */ +#define _base_compass_methods \ + _base_sensor_methods \ + _base_compass_methods_alone + +/** + * @brief @p BaseCompass virtual methods table. + */ +struct BaseCompassVMT { + _base_compass_methods +}; + +/** + * @brief @p BaseCompass specific data. + */ +#define _base_compass_data \ + _base_sensor_data + +/** + * @brief Base compass class. + * @details This class represents a generic compass. + */ +typedef struct { + /** @brief Virtual Methods Table.*/ + const struct BaseCompassVMT *vmt_basecompass; + _base_compass_data +} BaseCompass; + +/*===========================================================================*/ +/* Driver macros. */ +/*===========================================================================*/ +/** + * @name Macro Functions (BaseCompass) + * @{ + */ +/** + * @brief Compass get axes number. + * + * @param[in] ip pointer to a @p BaseCompass class. + * @return The number of axes of the BaseSensor + * + * @api + */ +#define compassGetAxesNumber(ip) \ + (ip)->vmt_basecompass->get_axes_number(ip) + +/** + * @brief Compass read raw data. + * + * @param[in] ip pointer to a @p BaseCompass class. + * @param[in] dp pointer to a data array. + * + * @return The operation status. + * @retval MSG_OK if the function succeeded. + * @retval MSG_RESET if one or more errors occurred. + * + * @api + */ +#define compassReadRaw(ip, dp) \ + (ip)->vmt_basecompass->read_raw(ip, dp) + +/** + * @brief Compass read cooked data. + * + * @param[in] ip pointer to a @p BaseCompass class. + * @param[in] dp pointer to a data array. + * + * @return The operation status. + * @retval MSG_OK if the function succeeded. + * @retval MSG_RESET if one or more errors occurred. + * + * @api + */ +#define compassReadCooked(ip, dp) \ + (ip)->vmt_basecompass->read_cooked(ip, dp) +/** @} */ + +/*===========================================================================*/ +/* External declarations. */ +/*===========================================================================*/ + +#ifdef __cplusplus +extern "C" { +#endif + +#ifdef __cplusplus +} +#endif + +#endif /* _HAL_COMPASS_H_ */ + +/** @} */ diff --git a/os/hal/lib/peripherals/sensors/hal_gyroscope.h b/os/hal/lib/peripherals/sensors/hal_gyroscope.h new file mode 100644 index 000000000..06ec8644a --- /dev/null +++ b/os/hal/lib/peripherals/sensors/hal_gyroscope.h @@ -0,0 +1,177 @@ +/* + ChibiOS - Copyright (C) 2016 Rocco Marco Guglielmi + + Licensed 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. +*/ + +/** + * @file hal_gyroscope.h + * @brief Generic gyroscope interface header. + * + * @addtogroup HAL_GYROSCOPE + * @{ + */ + +#ifndef _HAL_GYROSCOPE_H_ +#define _HAL_GYROSCOPE_H_ + +#include "hal_sensors.h" + +/*===========================================================================*/ +/* Driver constants. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Driver pre-compile time settings. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Derived constants and error checks. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Driver data structures and types. */ +/*===========================================================================*/ + +/** + * @brief BaseGyroscope specific methods. + */ +#define _base_gyroscope_methods_alone \ + /* Remove the calibration data.*/ \ + msg_t (*reset_calibration)(void *instance); \ + /* Invokes the calibration procedure.*/ \ + msg_t (*calibrate)(void *instance); + +/** + * @brief BaseGyroscope specific methods with inherited ones. + */ +#define _base_gyroscope_methods \ + _base_sensor_methods \ + _base_gyroscope_methods_alone + +/** + * @brief @p BaseGyroscope virtual methods table. + */ +struct BaseGyroscopeVMT { + _base_gyroscope_methods +}; + +/** + * @brief @p BaseGyroscope specific data. + */ +#define _base_gyroscope_data \ + _base_sensor_data + +/** + * @brief Base gyroscope class. + * @details This class represents a generic gyroscope. + */ +typedef struct { + /** @brief Virtual Methods Table.*/ + const struct BaseGyroscopeVMT *vmt_basegyroscope; + _base_gyroscope_data +} BaseGyroscope; + +/*===========================================================================*/ +/* Driver macros. */ +/*===========================================================================*/ + +/** + * @name Macro Functions (BaseGyroscope) + * @{ + */ +/** + * @brief Gyroscope get axes number. + * + * @param[in] ip pointer to a @p BaseGyroscope class. + * @return The number of axes of the BaseSensor + * + * @api + */ +#define gyroscopeGetAxesNumber(ip) \ + (ip)->vmt_basegyroscope->get_axes_number(ip) + +/** + * @brief Gyroscope read raw data. + * + * @param[in] ip pointer to a @p BaseGyroscope class. + * @param[in] dp pointer to a data array. + * + * @return The operation status. + * @retval MSG_OK if the function succeeded. + * @retval MSG_RESET if one or more errors occurred. + * + * @api + */ +#define gyroscopeReadRaw(ip, dp) \ + (ip)->vmt_basegyroscope->read_raw(ip, dp) + +/** + * @brief Gyroscope read cooked data. + * + * @param[in] ip pointer to a @p BaseGyroscope class. + * @param[in] dp pointer to a data array. + * + * @return The operation status. + * @retval MSG_OK if the function succeeded. + * @retval MSG_RESET if one or more errors occurred. + * + * @api + */ +#define gyroscopeReadCooked(ip, dp) \ + (ip)->vmt_basegyroscope->read_cooked(ip, dp) + +/** + * @brief Delete calibration data. + * + * @param[in] ip pointer to a @p BaseGyroscope class. + * + * @return The operation status. + * @retval MSG_OK if the function succeeded. + * @retval MSG_RESET if one or more errors occurred. + * + * @api + */ +#define gyroscopeResetCalibration(ip) \ + (ip)->vmt_basegyroscope->reset_calibration(ip) + +/** + * @brief Gyroscope calibration procedure. + * + * @param[in] ip pointer to a @p BaseGyroscope class. + * + * @return The operation status. + * @retval MSG_OK if the function succeeded. + * @retval MSG_RESET if one or more errors occurred. + * + * @api + */ +#define gyroscopeCalibrate(ip) \ + (ip)->vmt_basegyroscope->calibrate(ip) +/** @} */ + +/*===========================================================================*/ +/* External declarations. */ +/*===========================================================================*/ + +#ifdef __cplusplus +extern "C" { +#endif + +#ifdef __cplusplus +} +#endif + +#endif /* _HAL_GYROSCOPE_H_ */ + +/** @} */ diff --git a/os/hal/lib/peripherals/sensors/hal_sensors.h b/os/hal/lib/peripherals/sensors/hal_sensors.h new file mode 100644 index 000000000..fc2766d64 --- /dev/null +++ b/os/hal/lib/peripherals/sensors/hal_sensors.h @@ -0,0 +1,147 @@ +/* + ChibiOS - Copyright (C) 2016 Rocco Marco Guglielmi + + Licensed 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. +*/ + +/** + * @file hal_sensors.h + * @brief Generic sensors interface header. + * + * @addtogroup HAL_SENSORS + * @{ + */ + +#ifndef _HAL_SENSORS_H_ +#define _HAL_SENSORS_H_ + +/*===========================================================================*/ +/* Driver constants. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Driver pre-compile time settings. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Derived constants and error checks. */ +/*===========================================================================*/ + +/*===========================================================================*/ +/* Driver data structures and types. */ +/*===========================================================================*/ + +/** + * @brief BaseSensor specific methods. + */ +#define _base_sensor_methods_alone \ + /* Get number of axes.*/ \ + size_t (*get_axes_number)(void *instance); \ + /* Reads the sensor raw data.*/ \ + msg_t (*read_raw)(void *instance, int32_t axes[]); \ + /* Reads the sensor returning normalized data.*/ \ + msg_t (*read_cooked)(void *instance, float axes[]); + +/** + * @brief BaseSensor specific methods with inherited ones. + */ +#define _base_sensor_methods \ + _base_sensor_methods_alone + +/** + * @brief @p BaseSensor virtual methods table. + */ +struct BaseSensorVMT { + _base_sensor_methods +}; + +/** + * @brief @p BaseSensor specific data. + * @note It is empty because @p BaseSensor is only an interface + * without implementation. + */ +#define _base_sensor_data + +/** + * @brief Base stream class. + * @details This class represents a generic blocking unbuffered sequential + * data stream. + */ +typedef struct { + /** @brief Virtual Methods Table.*/ + const struct BaseSensorVMT *vmt_basesensor; + _base_sensor_data +} BaseSensor; + +/*===========================================================================*/ +/* Driver macros. */ +/*===========================================================================*/ + +/** + * @name Macro Functions (BaseSensor) + * @{ + */ +/** + * @brief Sensors get axes number. + * + * @param[in] ip pointer to a @p BaseSensor or derived class. + * @return The number of axes of the BaseSensor + * + * @api + */ +#define sensorGetAxesNumber(ip) (ip)->vmt_basesensor->get_axes_number(ip) + +/** + * @brief Sensors read raw data. + * + * @param[in] ip pointer to a @p BaseSensor or derived class. + * @param[in] dp pointer to a data array. + * + * @return The operation status. + * @retval MSG_OK if the function succeeded. + * @retval MSG_RESET if one or more errors occurred. + * + * @api + */ +#define sensorReadRaw(ip, dp) (ip)->vmt_basesensor->read_raw(ip, dp) + +/** + * @brief Sensors read cooked data. + * + * @param[in] ip pointer to a @p BaseSensor or derived class. + * @param[in] dp pointer to a data array. + * + * @return The operation status. + * @retval MSG_OK if the function succeeded. + * @retval MSG_RESET if one or more errors occurred. + * + * @api + */ +#define sensorReadCooked(ip, dp) (ip)->vmt_basesensor->read_cooked(ip, dp) +/** @} */ + +/*===========================================================================*/ +/* External declarations. */ +/*===========================================================================*/ + +#ifdef __cplusplus +extern "C" { +#endif + +#ifdef __cplusplus +} +#endif + +#endif /* _HAL_SENSORS_H_ */ + +/** @} */ -- cgit v1.2.3