Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependents: LedDimming_LED61A1_mbedOS HelloWorld_LED61A1_mbedOS LedDimming_LED61A1 HelloWorld_LED61A1 ... more
Fork of X_NUCLEO_LED61A1 by
Led6001.h
00001 /** 00002 ****************************************************************************** 00003 * @file Led6001.h 00004 * @author Davide Aliprandi, STMicroelectronics 00005 * @version V1.0.0 00006 * @date December 9th, 2015 00007 * @brief This file contains the class of an LED6001 component. 00008 ****************************************************************************** 00009 * @attention 00010 * 00011 * <h2><center>© 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-LED1/trunk/Drivers/BSP/Components/led6001/led6001.h 00047 Revision: 0 00048 */ 00049 00050 00051 /* Define to prevent recursive inclusion -------------------------------------*/ 00052 00053 #ifndef __LED6001_CLASS_H 00054 #define __LED6001_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 "../Common/component_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/Led.h" 00075 00076 00077 /* Definitions ---------------------------------------------------------------*/ 00078 00079 /* Duration of initialization interval in milli-seconds. */ 00080 #define INITIALIZATION_INTERVAL_ms (2E3) 00081 00082 /* Period of PWM and Analog Dimming modes's PWM signal. */ 00083 #define PWM_PERIOD_ms (10) 00084 00085 /* Duty Cycle of PWM and Analog Dimming modes's PWM signal to power the LED on. */ 00086 #define PWM_DIMMING_ON (1.0f) 00087 00088 /* Duty Cycle of PWM and Analog Dimming modes's PWM signal to power the LED off. */ 00089 #define PWM_DIMMING_OFF (0.0f) 00090 00091 /* Duty Cycle Range of Analog Dimming. */ 00092 #define MAX_PWM_ANALOG_DIMMING (1.2f/3.3f) 00093 #define MIN_PWM_ANALOG_DIMMING (0.3f/3.3f) 00094 00095 00096 /* Classes -------------------------------------------------------------------*/ 00097 00098 /** 00099 * @brief Class representing a LED6001 component. 00100 */ 00101 class Led6001 : public Led 00102 { 00103 public: 00104 00105 /*** Constructor and Destructor Methods ***/ 00106 00107 /** 00108 * @brief Constructor. 00109 * @param xfault_irq pin name of the XFAULT pin of the component. 00110 * @param current pin name of the ADC pin of the component responsible 00111 * for sensing the current flowing through the LED. 00112 * @param pwm pin name of the PWM pin of the component. 00113 * @param analog pin name of the Analog pin of the component. 00114 */ 00115 Led6001(PinName xfault_irq, PinName current, PinName pwm, PinName analog) : Led(), xfault_irq(xfault_irq), current(current), pwm(pwm), analog(analog) 00116 { 00117 /* ACTION 4 ----------------------------------------------------------* 00118 * Initialize here the component's member variables, one variable per * 00119 * line. * 00120 * * 00121 * Example: * 00122 * measure = 0; * 00123 * instance_id = number_of_instances++; * 00124 *--------------------------------------------------------------------*/ 00125 this->xfault_irq.mode(PullUp); 00126 } 00127 00128 /** 00129 * @brief Destructor. 00130 */ 00131 virtual ~Led6001(void) {} 00132 00133 00134 /*** Public Component Related Methods ***/ 00135 00136 /* ACTION 5 --------------------------------------------------------------* 00137 * Implement here the component's public methods, as wrappers of the C * 00138 * component's functions. * 00139 * They should be: * 00140 * + Methods with the same name of the C component's virtual table's * 00141 * functions (1); * 00142 * + Methods with the same name of the C component's extended virtual * 00143 * table's functions, if any (2). * 00144 * * 00145 * Example: * 00146 * virtual int get_value(float *p_data) //(1) * 00147 * { * 00148 * return COMPONENT_get_value(float *pf_data); * 00149 * } * 00150 * * 00151 * virtual int enable_feature(void) //(2) * 00152 * { * 00153 * return COMPONENT_enable_feature(); * 00154 * } * 00155 *------------------------------------------------------------------------*/ 00156 /** 00157 * @brief Initializing the component. 00158 * @param init Pointer to device specific initalization structure. 00159 * @retval "0" in case of success, an error code otherwise. 00160 */ 00161 virtual int init(void *init = NULL) 00162 { 00163 /* Setting defaults. */ 00164 pwm.period_ms(PWM_PERIOD_ms); 00165 analog.period_ms(PWM_PERIOD_ms); 00166 00167 return (int) COMPONENT_OK; 00168 } 00169 00170 /** 00171 * @brief Getting the ID of the component. 00172 * @param id Pointer to an allocated variable to store the ID into. 00173 * @retval "0" in case of success, an error code otherwise. 00174 */ 00175 virtual int read_id(uint8_t *id = NULL) 00176 { 00177 return (int) COMPONENT_OK; 00178 } 00179 00180 /** 00181 * @brief Getting the current flowing through the LED. 00182 * @param None. 00183 * @retval The current flowing through the LED, represented as a floating 00184 * point number in the range [0.0, 1.0]. 00185 */ 00186 virtual float get_current(void) 00187 { 00188 return current.read(); 00189 } 00190 00191 /** 00192 * @brief Setting PWM dimming value. 00193 * @param dimming PWM dimming value, represented as a floating 00194 * point number in the range [0.0, 1.0]. 00195 * @retval None. 00196 */ 00197 virtual void set_pwm_dimming(float dimming) 00198 { 00199 if (dimming >= 0.0f && dimming <= 1.0f) { 00200 pwm.write(dimming); 00201 } 00202 } 00203 00204 /** 00205 * @brief Setting Analog dimming value. 00206 * @param dimming Analog dimming value, represented as a floating 00207 * point number in the range [0.0, 1.0]. 00208 * @retval None. 00209 */ 00210 virtual void set_analog_dimming(float dimming) 00211 { 00212 if (dimming >= 0.0f && dimming <= 1.0f) { 00213 analog.write(dimming * (MAX_PWM_ANALOG_DIMMING - MIN_PWM_ANALOG_DIMMING) + MIN_PWM_ANALOG_DIMMING); 00214 } 00215 } 00216 00217 /** 00218 * @brief Powering ON at maximum light intensity. 00219 * @param None. 00220 * @retval None. 00221 */ 00222 virtual void power_on(void) 00223 { 00224 pwm.write(PWM_DIMMING_ON); 00225 analog.write(PWM_DIMMING_ON); 00226 } 00227 00228 /** 00229 * @brief Powering OFF. 00230 * @param None. 00231 * @retval None. 00232 */ 00233 virtual void power_off(void) 00234 { 00235 pwm.write(PWM_DIMMING_OFF); 00236 analog.write(PWM_DIMMING_OFF); 00237 } 00238 00239 /** 00240 * @brief Starting-up the component. 00241 * @param None. 00242 * @retval None. 00243 */ 00244 virtual void start_up(void) 00245 { 00246 /* Start-up sequence. */ 00247 power_off(); 00248 wait_ms(INITIALIZATION_INTERVAL_ms); 00249 power_on(); 00250 } 00251 00252 00253 /*** Public Interrupt Related Methods ***/ 00254 00255 /* ACTION 6 --------------------------------------------------------------* 00256 * Implement here interrupt related methods, if any. * 00257 * Note that interrupt handling is platform dependent, e.g.: * 00258 * + mbed: * 00259 * InterruptIn feature_irq(pin); //Interrupt object. * 00260 * feature_irq.rise(callback); //Attach a callback. * 00261 * feature_irq.mode(PullNone); //Set interrupt mode. * 00262 * feature_irq.enable_irq(); //Enable interrupt. * 00263 * feature_irq.disable_irq(); //Disable interrupt. * 00264 * + Arduino: * 00265 * attachInterrupt(pin, callback, RISING); //Attach a callback. * 00266 * detachInterrupt(pin); //Detach a callback. * 00267 * * 00268 * Example (mbed): * 00269 * void attach_feature_irq(void (*fptr) (void)) * 00270 * { * 00271 * feature_irq.rise(fptr); * 00272 * } * 00273 * * 00274 * void enable_feature_irq(void) * 00275 * { * 00276 * feature_irq.enable_irq(); * 00277 * } * 00278 * * 00279 * void disable_feature_irq(void) * 00280 * { * 00281 * feature_irq.disable_irq(); * 00282 * } * 00283 *------------------------------------------------------------------------*/ 00284 /** 00285 * @brief Attaching an interrupt handler to the XFAULT interrupt. 00286 * @param fptr An interrupt handler. 00287 * @retval None. 00288 */ 00289 void attach_xfault_irq(void (*fptr)(void)) 00290 { 00291 xfault_irq.fall(fptr); 00292 } 00293 00294 /** 00295 * @brief Enabling the XFAULT interrupt handling. 00296 * @param None. 00297 * @retval None. 00298 */ 00299 void enable_xfault_irq(void) 00300 { 00301 xfault_irq.enable_irq(); 00302 } 00303 00304 /** 00305 * @brief Disabling the XFAULT interrupt handling. 00306 * @param None. 00307 * @retval None. 00308 */ 00309 void disable_xfault_irq(void) 00310 { 00311 xfault_irq.disable_irq(); 00312 } 00313 00314 00315 protected: 00316 00317 /*** Protected Component Related Methods ***/ 00318 00319 /* ACTION 7 --------------------------------------------------------------* 00320 * Declare here the component's specific methods. * 00321 * They should be: * 00322 * + Methods with the same name of the C component's virtual table's * 00323 * functions (1); * 00324 * + Methods with the same name of the C component's extended virtual * 00325 * table's functions, if any (2); * 00326 * + Helper methods, if any, like functions declared in the component's * 00327 * source files but not pointed by the component's virtual table (3). * 00328 * * 00329 * Example: * 00330 * status_t COMPONENT_get_value(float *f); //(1) * 00331 * status_t COMPONENT_enable_feature(void); //(2) * 00332 * status_t COMPONENT_compute_average(void); //(3) * 00333 *------------------------------------------------------------------------*/ 00334 00335 00336 /*** Component's I/O Methods ***/ 00337 00338 /* ACTION 8 --------------------------------------------------------------* 00339 * Implement here other I/O methods beyond those already implemented * 00340 * above, which are declared extern within the component's header file. * 00341 *------------------------------------------------------------------------*/ 00342 00343 00344 /*** Component's Instance Variables ***/ 00345 00346 /* ACTION 9 --------------------------------------------------------------* 00347 * Declare here interrupt related variables, if needed. * 00348 * Note that interrupt handling is platform dependent, see * 00349 * "Interrupt Related Methods" above. * 00350 * * 00351 * Example: * 00352 * + mbed: * 00353 * InterruptIn feature_irq; * 00354 *------------------------------------------------------------------------*/ 00355 /* XFault Interrupt. */ 00356 InterruptIn xfault_irq; 00357 00358 /* ACTION 10 -------------------------------------------------------------* 00359 * Declare here other pin related variables, if needed. * 00360 * * 00361 * Example: * 00362 * + mbed: * 00363 * DigitalOut standby_reset; * 00364 *------------------------------------------------------------------------*/ 00365 /* Pin to sense the current flowing through the LED. */ 00366 AnalogIn current; 00367 00368 /* Pulse Width Modulation dimming pin. */ 00369 PwmOut pwm; 00370 00371 /* Analog dimming pin. */ 00372 PwmOut analog; 00373 00374 /* ACTION 11 -------------------------------------------------------------* 00375 * Declare here communication related variables, if needed. * 00376 * * 00377 * Example: * 00378 * + mbed: * 00379 * DigitalOut address; * 00380 * DevI2C &dev_i2c; * 00381 *------------------------------------------------------------------------*/ 00382 00383 /* ACTION 12 -------------------------------------------------------------* 00384 * Declare here identity related variables, if needed. * 00385 * Note that there should be only a unique identifier for each component, * 00386 * which should be the "who_am_i" parameter. * 00387 *------------------------------------------------------------------------*/ 00388 00389 /* ACTION 13 -------------------------------------------------------------* 00390 * Declare here the component's static and non-static data, one variable * 00391 * per line. * 00392 * * 00393 * Example: * 00394 * float measure; * 00395 * int instance_id; * 00396 * static int number_of_instances; * 00397 *------------------------------------------------------------------------*/ 00398 }; 00399 00400 #endif // __LED6001_CLASS_H 00401 00402 /************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
Generated on Mon Jul 18 2022 02:55:00 by
1.7.2

X-NUCLEO-LED61A1 LED Driver