MicroForce Sensors, Compensated/Amplified

Revision:
0:e4146617a5fc
Child:
1:4b8a700b3f5c
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/MicroForce_FMA.h	Wed Jun 30 12:54:49 2021 +0000
@@ -0,0 +1,157 @@
+/**
+ * @brief       MicroForce_FMA.h
+ * @details     MicroForce Sensors, Compensated/Amplified.
+ *              Header file.
+ *
+ *
+ * @return      N/A
+ *
+ * @author      Manuel Caballero
+ * @date        29/June/2021
+ * @version     29/June/2021    The ORIGIN
+ * @pre         N/A.
+ * @warning     N/A
+ * @pre         This code belongs to Nimbus Centre ( https://www.nimbus.cit.ie ).
+ */
+#ifndef MicroForce_FMA_H
+#define MicroForce_FMA_H
+
+#include "mbed.h"
+/**
+    Example:
+@code
+
+@endcode
+*/
+
+
+/*!
+ Library for the MicroForce_FMA. MicroForce Sensors, Compensated/Amplified.
+*/
+class MicroForce_FMA
+{
+public:
+    /**
+    * @brief   STATUS BITS
+    */
+    typedef enum {
+        MicroForce_FMA_STATUS_BITS_MASK                   =   ( 0b11 << 6 ),      /*!<   STATUS BITS mask                 */
+        MicroForce_FMA_STATUS_BITS_NORMAL_OPERATION       =   ( 0b00 << 6 ),      /*!<   Normal operation, valid data     */
+        MicroForce_FMA_STATUS_BITS_DEVICE_IN_COMMAND_MODE =   ( 0b01 << 6 ),      /*!<   Device in command mode           */
+        MicroForce_FMA_STATUS_BITS_STALE_DATA             =   ( 0b10 << 6 ),      /*!<   Stale data                       */
+        MicroForce_FMA_STATUS_BITS_DIAGNOSTIC_CONDITION   =   ( 0b11 << 6 )       /*!<   Diagnostic condition             */
+    } MicroForce_FMA_status_bits_t;
+
+
+    /**
+      * @brief   TRANSFER FUCNTION
+      */
+    typedef enum {
+        MicroForce_FMA_TRANSFER_FUNCTION_10_TO_90         =   0U,                 /*!<   Tranfer function A: 10% to 90%   */
+        MicroForce_FMA_TRANSFER_FUNCTION_20_TO_80         =   1U                  /*!<   Tranfer function C: 20% to 80%   */
+    } MicroForce_FMA_transfer_function_t;
+
+
+    /**
+      * @brief   FORCE RANGE
+      */
+    const FMA_FORCE_RANGE_5_N   =  5U;                 /*!<   Force range:  5N                 */
+    const FMA_FORCE_RANGE_15_N  = 15U;                 /*!<   Force range: 15N                 */
+    const FMA_FORCE_RANGE_25_N  = 25U;                 /*!<   Force range: 25N                 */
+
+
+
+#ifndef MicroForce_FMA_STRUCT_H
+#define MicroForce_FMA_STRUCT_H
+    typedef struct {
+        MicroForce_FMA_status_bits_t status_bits;
+    } MicroForce_FMA_status_bits_data_t;
+
+
+    typedef struct {
+        uint16_t  raw_bridge_data;
+        float     bridge_data;                                              /*!<   Force data in Newton (N)           */
+    } MicroForce_FMA_bridge_data_t;
+
+
+    typedef struct {
+        uint8_t   raw_8bit_temperature;
+        uint16_t  raw_11bit_temperature;
+        float     temperature_data;                                         /*!<   Temperature data in Celsius degree */
+    } MicroForce_FMA_temperature_data_t;
+
+
+    /* User's data   */
+    typedef struct {
+        MicroForce_FMA_transfer_function_t  transfer_function;              /*!<   Transfer function. Calibration     */
+        uint8_t                             force_range;                    /*!<   Force Range                        */
+
+        MicroForce_FMA_status_bits_data_t   status;                         /*!<   Status bits. Device condition      */
+
+        MicroForce_FMA_bridge_data_t        force;                          /*!<   Force data                         */
+        MicroForce_FMA_temperature_data_t   temperature;                    /*!<   Temperature data                   */
+    } MicroForce_FMA_data_t;
+#endif
+
+
+
+    /**
+      * @brief   INTERNAL CONSTANTS
+      */
+    typedef enum {
+        MicroForce_FMA_SUCCESS     =       0,
+        MicroForce_FMA_FAILURE     =       1,
+        SPI_SUCCESS                =       1
+    } MicroForce_FMA_status_t;
+
+
+
+
+    /** Create an MicroForce_FMA object connected to the specified SPI pins.
+      *
+      * @param mosi     SPI Master Output Slave Input
+      * @param miso     SPI Master Input Slave Output
+      * @param sclk     SPI clock
+      * @param cs       SPI Chip Select
+      * @param freq     SPI frequency in Hz.
+      */
+    MicroForce_FMA ( PinName mosi, PinName miso, PinName sclk, PinName cs, uint32_t freq );
+
+    /** Delete MicroForce_FMA object.
+     */
+    ~MicroForce_FMA();
+
+    /** It gets the raw force data.
+    */
+    MicroForce_FMA_status_t  MicroForce_FMA_GetRawForce               ( MicroForce_FMA_status_bits_data_t* myStatus, uint16_t* myRawBridgeData                            );
+
+    /** It calculates the force data in Newton (N).
+        */
+    float                    MicroForce_FMA_CalculateForce            ( MicroForce_FMA_transfer_function_t myCalibration, uint8_t myForceRange, uint16_t myRawBridgeData                                    );
+
+    /** It gets the raw 8-bit temperature.
+        */
+    MicroForce_FMA_status_t  MicroForce_FMA_GetRaw8bitTemperature     ( MicroForce_FMA_status_bits_data_t* myStatus, uint8_t* myRaw8bitTemp                               );
+
+    /** It gets the raw 11-bit temperature.
+        */
+    MicroForce_FMA_status_t  MicroForce_FMA_GetRaw11bitTemperature    ( MicroForce_FMA_status_bits_data_t* myStatus, uint16_t* myRaw11bitTemp                             );
+
+    /** It calculates the 8-bit temperature in Celsius degree.
+        */
+    float                    MicroForce_FMA_Calculate8bitTemperature  ( uint8_t myRawTemperature                                                                                                            );
+
+    /** It calculates the 11-bit temperature in Celsius degree.
+        */
+    float                    MicroForce_FMA_Calculate11bitTemperature ( uint16_t myRawTemperature                                                                                                           );
+
+    /** It gets the all raw data ( bridge data and 11-bit temperature ).
+        */
+    MicroForce_FMA_status_t  MicroForce_FMA_GetAllRawData             ( MicroForce_FMA_status_bits_data_t* myStatus, uint16_t* myRawBridgeData, uint16_t* myRaw11bitTemp  );
+
+private:
+    SPI         _spi;
+    DigitalOut  _cs;
+};
+
+#endif