|
| 1 | +/** |
| 2 | + * @file leds.c |
| 3 | + * |
| 4 | + * @brief Leds driver implementation. |
| 5 | + * |
| 6 | + * Revised BSD License |
| 7 | + * Copyright Semtech Corporation 2020. All rights reserved. |
| 8 | + * |
| 9 | + * Redistribution and use in source and binary forms, with or without |
| 10 | + * modification, are permitted provided that the following conditions are met: |
| 11 | + * * Redistributions of source code must retain the above copyright |
| 12 | + * notice, this list of conditions and the following disclaimer. |
| 13 | + * * Redistributions in binary form must reproduce the above copyright |
| 14 | + * notice, this list of conditions and the following disclaimer in the |
| 15 | + * documentation and/or other materials provided with the distribution. |
| 16 | + * * Neither the name of the Semtech corporation nor the |
| 17 | + * names of its contributors may be used to endorse or promote products |
| 18 | + * derived from this software without specific prior written permission. |
| 19 | + * |
| 20 | + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
| 21 | + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 22 | + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 23 | + * ARE DISCLAIMED. IN NO EVENT SHALL SEMTECH CORPORATION BE LIABLE FOR ANY |
| 24 | + * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
| 25 | + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
| 26 | + * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
| 27 | + * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 28 | + * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
| 29 | + * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 30 | + */ |
| 31 | + |
| 32 | +/* |
| 33 | + * ----------------------------------------------------------------------------- |
| 34 | + * --- DEPENDENCIES ------------------------------------------------------------ |
| 35 | + */ |
| 36 | + |
| 37 | +#include "smtc_hal.h" |
| 38 | +#include "leds.h" |
| 39 | + |
| 40 | +/* |
| 41 | + * ----------------------------------------------------------------------------- |
| 42 | + * --- PRIVATE MACROS----------------------------------------------------------- |
| 43 | + */ |
| 44 | + |
| 45 | +/* |
| 46 | + * ----------------------------------------------------------------------------- |
| 47 | + * --- PRIVATE CONSTANTS ------------------------------------------------------- |
| 48 | + */ |
| 49 | + |
| 50 | +/* |
| 51 | + * ----------------------------------------------------------------------------- |
| 52 | + * --- PRIVATE TYPES ----------------------------------------------------------- |
| 53 | + */ |
| 54 | + |
| 55 | +/* |
| 56 | + * ----------------------------------------------------------------------------- |
| 57 | + * --- PRIVATE VARIABLES ------------------------------------------------------- |
| 58 | + */ |
| 59 | + |
| 60 | +/* |
| 61 | + * ----------------------------------------------------------------------------- |
| 62 | + * --- PRIVATE FUNCTIONS DECLARATION ------------------------------------------- |
| 63 | + */ |
| 64 | + |
| 65 | +/* |
| 66 | + * ----------------------------------------------------------------------------- |
| 67 | + * --- PUBLIC FUNCTIONS DEFINITION --------------------------------------------- |
| 68 | + */ |
| 69 | + |
| 70 | +void leds_init( void ) |
| 71 | +{ |
| 72 | + hal_gpio_init_out( LED_TX, 0 ); |
| 73 | + hal_gpio_init_out( LED_RX, 0 ); |
| 74 | + hal_gpio_init_out( LED_SCAN, 0 ); |
| 75 | +} |
| 76 | + |
| 77 | +void leds_deinit( void ) |
| 78 | +{ |
| 79 | + hal_gpio_deinit( LED_TX ); |
| 80 | + hal_gpio_deinit( LED_RX ); |
| 81 | + hal_gpio_deinit( LED_SCAN ); |
| 82 | +} |
| 83 | + |
| 84 | +void leds_on( uint8_t leds ) |
| 85 | +{ |
| 86 | + if( leds & LED_TX_MASK ) |
| 87 | + { |
| 88 | + /* LED TX */ |
| 89 | + hal_gpio_set_value( LED_TX, GPIO_PIN_SET ); |
| 90 | + } |
| 91 | + if( leds & LED_RX_MASK ) |
| 92 | + { |
| 93 | + /* LED RX */ |
| 94 | + hal_gpio_set_value( LED_RX, GPIO_PIN_SET ); |
| 95 | + } |
| 96 | + if( leds & LED_SCAN_MASK ) |
| 97 | + { |
| 98 | + /* LED SCAN */ |
| 99 | + hal_gpio_set_value( LED_SCAN, GPIO_PIN_SET ); |
| 100 | + } |
| 101 | +} |
| 102 | + |
| 103 | +void leds_off( uint8_t leds ) |
| 104 | +{ |
| 105 | + if( leds & LED_TX_MASK ) |
| 106 | + { |
| 107 | + /* LED TX */ |
| 108 | + hal_gpio_set_value( LED_TX, GPIO_PIN_RESET ); |
| 109 | + } |
| 110 | + if( leds & LED_RX_MASK ) |
| 111 | + { |
| 112 | + /* LED RX */ |
| 113 | + hal_gpio_set_value( LED_RX, GPIO_PIN_RESET ); |
| 114 | + } |
| 115 | + if( leds & LED_SCAN_MASK ) |
| 116 | + { |
| 117 | + /* LED SCAN */ |
| 118 | + hal_gpio_set_value( LED_SCAN, GPIO_PIN_RESET ); |
| 119 | + } |
| 120 | +} |
| 121 | + |
| 122 | +void leds_toggle( uint8_t leds ) |
| 123 | +{ |
| 124 | + if( leds & LED_TX_MASK ) |
| 125 | + { |
| 126 | + /* LED TX */ |
| 127 | + hal_gpio_toggle( LED_TX ); |
| 128 | + } |
| 129 | + if( leds & LED_RX_MASK ) |
| 130 | + { |
| 131 | + /* LED RX */ |
| 132 | + hal_gpio_toggle( LED_RX ); |
| 133 | + } |
| 134 | + if( leds & LED_SCAN_MASK ) |
| 135 | + { |
| 136 | + /* LED SCAN */ |
| 137 | + hal_gpio_toggle( LED_SCAN ); |
| 138 | + } |
| 139 | +} |
| 140 | + |
| 141 | +void leds_blink( uint8_t leds, uint32_t delay, uint8_t nb_blink, bool reset_leds ) |
| 142 | +{ |
| 143 | + uint8_t i = 0; |
| 144 | + |
| 145 | + if( reset_leds == true ) |
| 146 | + { |
| 147 | + leds_off( LED_ALL_MASK ); |
| 148 | + } |
| 149 | + |
| 150 | + while( i < nb_blink ) |
| 151 | + { |
| 152 | + i++; |
| 153 | + leds_on( leds ); |
| 154 | + HAL_Delay( delay / 2 ); |
| 155 | + leds_off( leds ); |
| 156 | + HAL_Delay( delay / 2 ); |
| 157 | + } |
| 158 | +} |
| 159 | + |
| 160 | +/* |
| 161 | + * ----------------------------------------------------------------------------- |
| 162 | + * --- PRIVATE FUNCTIONS DEFINITION -------------------------------------------- |
| 163 | + */ |
| 164 | + |
| 165 | +/* --- EOF ------------------------------------------------------------------ */ |
0 commit comments