mbed library for STMicroelectronics' X-NUCLEO-IKA01A1 expansion board.

Dependents:   HelloWorld_IKA01A1

Fork of X_NUCLEO_IKA01A1 by ST Expansion SW Team

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers TSU104.h Source File

TSU104.h

Go to the documentation of this file.
00001 /**
00002  ******************************************************************************
00003  * @file    TSU104.h
00004  * @author  Central Labs
00005  * @version 1.0.0
00006  * @date    11-February-2016
00007  * @brief   Portable architecture for TSU104
00008  ******************************************************************************
00009  * @attention
00010  *
00011  * <h2><center>&copy; COPYRIGHT(c) 2015 STMicroelectronics</center></h2>
00012  *
00013  * Redistribution and use in source and binary forms, with or without modification,
00014  * are permitted provided that the following conditions are met:
00015  *   1. Redistributions of source code must retain the above copyright notice,
00016  *      this list of conditions and the following disclaimer.
00017  *   2. Redistributions in binary form must reproduce the above copyright notice,
00018  *      this list of conditions and the following disclaimer in the documentation
00019  *      and/or other materials provided with the distribution.
00020  *   3. Neither the name of STMicroelectronics nor the names of its contributors
00021  *      may be used to endorse or promote products derived from this software
00022  *      without specific prior written permission.
00023  *
00024  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
00025  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00026  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
00027  * DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
00028  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00029  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
00030  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
00031  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
00032  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
00033  * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
00034  *
00035  ******************************************************************************
00036  */
00037 
00038 
00039 /* Generated with STM32CubeTOO -----------------------------------------------*/
00040 
00041 
00042 /* Revision ------------------------------------------------------------------*/
00043 /*
00044     Repository:       http://svn.x-nucleodev.codex.cro.st.com/svnroot/X-NucleoDev
00045     Branch/Trunk/Tag: trunk
00046     Based on:         X-CUBE-IKA01A1/trunk/Drivers/BSP/Components/tsu104/tsu104.h
00047     Revision:         402
00048 */
00049 
00050 
00051 /* Define to prevent recursive inclusion -------------------------------------*/
00052 
00053 #ifndef __TSU104_CLASS_H
00054 #define __TSU104_CLASS_H
00055 
00056 
00057 /* Includes ------------------------------------------------------------------*/
00058 
00059 /* ACTION 1 ------------------------------------------------------------------*
00060  * Include here platform specific header files.                               *
00061  *----------------------------------------------------------------------------*/        
00062 #include "mbed.h"
00063 /* ACTION 2 ------------------------------------------------------------------*
00064  * Include here component specific header files.                              *
00065  *----------------------------------------------------------------------------*/        
00066 #include "TSU104_def.h"
00067 /* ACTION 3 ------------------------------------------------------------------*
00068  * Include here interface specific header files.                              *
00069  *                                                                            *
00070  * Example:                                                                   *
00071  *   #include "HumiditySensor.h"                                              *
00072  *   #include "TemperatureSensor.h"                                           *
00073  *----------------------------------------------------------------------------*/
00074 #include "../Interfaces/Windcomp.h"
00075 #include "../Interfaces/PhotoSensor.h"
00076 
00077 
00078 /* Classes -------------------------------------------------------------------*/
00079 
00080 /**
00081  * @brief Class representing a TSU104 operational amplifier component. The window comparator 
00082  * configuration allows the user to compare a signal to two threshold voltages. When the signal
00083  * is out of the required voltage range, the output of the operational amplifier toggles
00084  */
00085 class TSU104 : public Windcomp, public PhotoSensor
00086 {
00087 public:
00088 
00089     /*** Constructor and Destructor Methods ***/
00090 
00091     /**
00092      * @brief Constructor.
00093      */
00094     TSU104(PinName photoSensorPin, PinName windCmpSignalPin_1,PinName windCmpSignalPin_2) : Windcomp()
00095     {
00096         photo_sensor_pin = photoSensorPin;
00097         windCmp_signal_pin_1 = windCmpSignalPin_1;
00098         windCmp_signal_pin_2 = windCmpSignalPin_2;      
00099     }
00100     
00101     /**
00102      * @brief Destructor.
00103      */
00104     virtual ~TSU104(void) {}
00105     
00106 
00107     /*** Public Component Related Methods ***/
00108 
00109     /* ACTION 5 --------------------------------------------------------------*
00110      * Implement here the component's public methods, as wrappers of the C    *
00111      * component's functions.                                                 *
00112      * They should be:                                                        *
00113      *   + Methods with the same name of the C component's virtual table's    *
00114      *     functions (1);                                                     *
00115      *   + Methods with the same name of the C component's extended virtual   *
00116      *     table's functions, if any (2).                                     *
00117      *                                                                        *
00118      * Example:                                                               *
00119      *   virtual int get_value(float *p_data) //(1)                           *
00120      *   {                                                                    *
00121      *     return COMPONENT_get_value(float *pf_data);                        *
00122      *   }                                                                    *
00123      *                                                                        *
00124      *   virtual int enable_feature(void) //(2)                               *
00125      *   {                                                                    *
00126      *     return COMPONENT_enable_feature();                                 *
00127      *   }                                                                    *
00128      *------------------------------------------------------------------------*/
00129 
00130     /**
00131      * @brief Public functions inherited from the Component Class
00132      */
00133 
00134     /**
00135      * @brief initialize the class for TSU104 operational amplifier component
00136      * @retval COMPONENT_OK if initialization is successfull
00137      * @retval suitable error code otherwise     
00138      */ 
00139     virtual int init(void *init = NULL)
00140     {
00141         return (int) TSU104_Init((void *) init);
00142     }
00143     
00144     /**
00145      * @brief  obtain component ID for TSU104 perational amplifier
00146      * @retval component ID for TSU104 operational amplifier
00147      */     
00148     virtual int read_id(uint8_t *id = NULL)
00149     {
00150         return (int) TSU104_ReadID((uint8_t *) id);
00151     }
00152 
00153     /**
00154      * @brief Public functions inherited from the LedDriver Class
00155      */
00156 
00157     /**
00158      * @brief  get digital signal value 1 in windows comparator configuration
00159      * @retval digital signal value 1
00160      */         
00161     virtual unsigned int get_signal1(void)
00162     {
00163         DigitalIn windowsCompD2(windCmp_signal_pin_1);
00164         return windowsCompD2.read();
00165     }
00166 
00167     /**
00168      * @brief  get digital signal value 2 in windows comparator configuration
00169      * @retval digital signal value 2
00170      */         
00171     virtual unsigned int get_signal2(void)
00172     {
00173         DigitalIn windowsCompD4(windCmp_signal_pin_2);
00174         return windowsCompD4.read();
00175     }
00176     
00177     
00178     /**
00179      * @brief  obtain the output voltage detected by photo sensor
00180      * @param  pin AnalogIn pin to use for detecting the voltage
00181      * @retval voltage detected by photo sensor
00182      */     
00183     virtual unsigned int get_voltage(void)
00184     {
00185         AnalogIn photoSensor(photo_sensor_pin);
00186         double voltage = photoSensor.read();
00187         voltage = voltage*3.3*1000.0;   // voltage in mV
00188         return voltage;
00189     }
00190 
00191 
00192     /*** Public Interrupt Related Methods ***/
00193 
00194     /* ACTION 6 --------------------------------------------------------------*
00195      * Implement here interrupt related methods, if any.                      *
00196      * Note that interrupt handling is platform dependent, e.g.:              *
00197      *   + mbed:                                                              *
00198      *     InterruptIn feature_irq(pin);           //Interrupt object.        *
00199      *     feature_irq.fall(callback);             //Attach a callback.       *
00200      *     feature_irq.mode(PullNone);             //Set interrupt mode.      *
00201      *     feature_irq.enable_irq();               //Enable interrupt.        *
00202      *     feature_irq.disable_irq();              //Disable interrupt.       *
00203      *   + Arduino:                                                           *
00204      *     attachInterrupt(pin, callback, RISING); //Attach a callback.       *
00205      *     detachInterrupt(pin);                   //Detach a callback.       *
00206      *                                                                        *
00207      * Example (mbed):                                                        *
00208      *   void attach_feature_irq(void (*fptr) (void))                         *
00209      *   {                                                                    *
00210      *     feature_irq.rise(fptr);                                            *
00211      *   }                                                                    *
00212      *                                                                        *
00213      *   void enable_feature_irq(void)                                        *
00214      *   {                                                                    *
00215      *     feature_irq.enable_irq();                                          *
00216      *   }                                                                    *
00217      *                                                                        *
00218      *   void disable_feature_irq(void)                                       *
00219      *   {                                                                    *
00220      *     feature_irq.disable_irq();                                         *
00221      *   }                                                                    *
00222      *------------------------------------------------------------------------*/
00223 
00224 
00225 protected:
00226 
00227     /*** Protected Component Related Methods ***/
00228 
00229     /**
00230      * arduino pin for photosensor output voltage
00231      */
00232     PinName photo_sensor_pin;
00233     
00234     /**
00235      * arduino pin for signal 1 of windows comparator configuration
00236      */ 
00237     PinName windCmp_signal_pin_1;
00238     
00239     /**
00240      * arduino pin for signal 1 of windows comparator configuration
00241      */     
00242     PinName windCmp_signal_pin_2;
00243 
00244     /* ACTION 7 --------------------------------------------------------------*
00245      * Declare here the component's specific methods.                         *
00246      * They should be:                                                        *
00247      *   + Methods with the same name of the C component's virtual table's    *
00248      *     functions (1);                                                     *
00249      *   + Methods with the same name of the C component's extended virtual   *
00250      *     table's functions, if any (2);                                     *
00251      *   + Helper methods, if any, like functions declared in the component's *
00252      *     source files but not pointed by the component's virtual table (3). *
00253      *                                                                        *
00254      * Example:                                                               *
00255      *   status_t COMPONENT_get_value(float *f);   //(1)                      *
00256      *   status_t COMPONENT_enable_feature(void);  //(2)                      *
00257      *   status_t COMPONENT_compute_average(void); //(3)                      *
00258      *------------------------------------------------------------------------*/
00259     /* TSU104's generic functions. */
00260     status_t TSU104_Init(void *init);
00261     status_t TSU104_ReadID(void *id);
00262 
00263     /* TSU104's interrupts related functions. */
00264     status_t TSU104_ConfigIT(void* a);
00265 
00266 
00267     /*** Component's I/O Methods ***/
00268 
00269     /*** Component's Instance Variables ***/
00270 
00271     /* ACTION 9 --------------------------------------------------------------*
00272      * Declare here interrupt related variables, if needed.                   *
00273      * Note that interrupt handling is platform dependent, see                *
00274      * "Interrupt Related Methods" above.                                     *
00275      *                                                                        *
00276      * Example:                                                               *
00277      *   + mbed:                                                              *
00278      *     InterruptIn feature_irq;                                           *
00279      *------------------------------------------------------------------------*/
00280 
00281     /* ACTION 10 -------------------------------------------------------------*
00282      * Declare here other pin related variables, if needed.                   *
00283      *                                                                        *
00284      * Example:                                                               *
00285      *   + mbed:                                                              *
00286      *     DigitalOut standby_reset;                                          *
00287      *------------------------------------------------------------------------*/
00288 
00289     /* ACTION 11 -------------------------------------------------------------*
00290      * Declare here communication related variables, if needed.               *
00291      *                                                                        *
00292      * Example:                                                               *
00293      *   + mbed:                                                              *
00294      *     DigitalOut address;                                                *
00295      *     DevI2C &dev_i2c;                                                   *
00296      *------------------------------------------------------------------------*/
00297 
00298     /* ACTION 12 -------------------------------------------------------------*
00299      * Declare here identity related variables, if needed.                    *
00300      * Note that there should be only a unique identifier for each component, *
00301      * which should be the "who_am_i" parameter.                              *
00302      *------------------------------------------------------------------------*/
00303     /* Identity */
00304     uint8_t who_am_i;
00305 
00306     /* ACTION 13 -------------------------------------------------------------*
00307      * Declare here the component's static and non-static data, one variable  *
00308      * per line.                                                              *
00309      *                                                                        *
00310      * Example:                                                               *
00311      *   float measure;                                                       *
00312      *   int instance_id;                                                     *
00313      *   static int number_of_instances;                                      *
00314      *------------------------------------------------------------------------*/
00315 };
00316 
00317 #endif /* __TSU104_CLASS_H */
00318 
00319 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/