Jerry Bradshaw
/
HSP_Release
This is a mbed 5.2 Release
Fork of mbed-os-test by
Embed:
(wiki syntax)
Show/hide line numbers
HspLed.cpp
00001 /******************************************************************************* 00002 * Copyright (C) 2016 Maxim Integrated Products, Inc., All Rights Reserved. 00003 * 00004 * Permission is hereby granted, free of charge, to any person obtaining a 00005 * copy of this software and associated documentation files (the "Software"), 00006 * to deal in the Software without restriction, including without limitation 00007 * the rights to use, copy, modify, merge, publish, distribute, sublicense, 00008 * and/or sell copies of the Software, and to permit persons to whom the 00009 * Software is furnished to do so, subject to the following conditions: 00010 * 00011 * The above copyright notice and this permission notice shall be included 00012 * in all copies or substantial portions of the Software. 00013 * 00014 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS 00015 * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 00016 * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 00017 * IN NO EVENT SHALL MAXIM INTEGRATED BE LIABLE FOR ANY CLAIM, DAMAGES 00018 * OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 00019 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 00020 * OTHER DEALINGS IN THE SOFTWARE. 00021 * 00022 * Except as contained in this notice, the name of Maxim Integrated 00023 * Products, Inc. shall not be used except as stated in the Maxim Integrated 00024 * Products, Inc. Branding Policy. 00025 * 00026 * The mere transfer of this software does not imply any licenses 00027 * of trade secrets, proprietary technology, copyrights, patents, 00028 * trademarks, maskwork rights, or any other form of intellectual 00029 * property whatsoever. Maxim Integrated Products, Inc. retains all 00030 * ownership rights. 00031 ******************************************************************************* 00032 */ 00033 00034 #include "HspLed.h" 00035 #include "Peripherals.h" 00036 00037 void hspled_int_handler(void); 00038 00039 //******************************************************************************* 00040 HspLed::HspLed(PinName ledPin) : 00041 redLed(LED_RED, 0), isStarted(false), timerIntervalLast(-1), timerInterval(500) { 00042 } 00043 00044 00045 //******************************************************************************* 00046 void HspLed::state(int state) { 00047 redLed.write(state); 00048 } 00049 00050 00051 //******************************************************************************* 00052 void HspLed::toggle(void) { 00053 state(!redLed.read()); 00054 } 00055 00056 00057 //******************************************************************************* 00058 void HspLed::setMode(eMode mode) { 00059 this->mode = mode; 00060 } 00061 00062 //******************************************************************************* 00063 void HspLed::blink(uint32_t mSeconds) { 00064 mode = eLedPeriod; 00065 this->timerInterval = (float)mSeconds / 1000.0f; 00066 start(); 00067 } 00068 00069 //******************************************************************************* 00070 void HspLed::pattern(uint32_t bitPattern, uint32_t mSeconds) { 00071 mode = eLedPattern; 00072 this->bitPattern = bitPattern; 00073 this->timerInterval = (float)mSeconds / 1000.0f; 00074 start(); 00075 } 00076 00077 //******************************************************************************* 00078 void HspLed::on(void) { 00079 mode = eLedOn; 00080 state(HSP_LED_ON); 00081 start(); 00082 } 00083 00084 00085 //******************************************************************************* 00086 void HspLed::off(void) { 00087 mode = eLedOff; 00088 state(HSP_LED_OFF); 00089 start(); 00090 } 00091 00092 00093 //******************************************************************************* 00094 void HspLed::patternToLed(void) { 00095 uint32_t bit; 00096 bit = bitPattern & 1; 00097 state(bit); 00098 // rotate the pattern 00099 bitPattern = bitPattern >> 1; 00100 bitPattern = bitPattern | (bit << 31); 00101 } 00102 00103 00104 //******************************************************************************* 00105 void HspLed::service(void) { 00106 switch (mode) { 00107 case eLedOn: 00108 state(HSP_LED_ON); 00109 break; 00110 case eLedOff: 00111 state(HSP_LED_OFF); 00112 break; 00113 case eLedPeriod: 00114 toggle(); 00115 break; 00116 case eLedPattern: 00117 patternToLed(); 00118 break; 00119 } 00120 } 00121 00122 //******************************************************************************* 00123 void HspLed::start(void) { 00124 if (timerInterval != timerIntervalLast && isStarted == true) { 00125 stop(); 00126 } 00127 ticker.attach(&hspled_int_handler, timerInterval); 00128 timerIntervalLast = timerInterval; 00129 00130 isStarted = true; 00131 } 00132 00133 //******************************************************************************* 00134 void HspLed::stop(void) { 00135 ticker.detach(); 00136 isStarted = false; 00137 } 00138 00139 //******************************************************************************* 00140 void hspled_int_handler(void) { 00141 HspLed *hspLed = Peripherals::hspLed(); 00142 hspLed->service(); 00143 }
Generated on Wed Jul 13 2022 17:00:35 by 1.7.2