|
| 1 | +/* |
| 2 | + * Copyright 2026 Great Scott Gadgets <info@greatscottgadgets.com> |
| 3 | + * |
| 4 | + * This file is part of HackRF. |
| 5 | + * |
| 6 | + * This program is free software; you can redistribute it and/or modify |
| 7 | + * it under the terms of the GNU General Public License as published by |
| 8 | + * the Free Software Foundation; either version 2, or (at your option) |
| 9 | + * any later version. |
| 10 | + * |
| 11 | + * This program is distributed in the hope that it will be useful, |
| 12 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | + * GNU General Public License for more details. |
| 15 | + * |
| 16 | + * You should have received a copy of the GNU General Public License |
| 17 | + * along with this program; see the file COPYING. If not, write to |
| 18 | + * the Free Software Foundation, Inc., 51 Franklin Street, |
| 19 | + * Boston, MA 02110-1301, USA. |
| 20 | + */ |
| 21 | + |
| 22 | +#include "leds.h" |
| 23 | + |
| 24 | +#include <stdint.h> |
| 25 | + |
| 26 | +#include "delay.h" |
| 27 | +#include "gpio.h" |
| 28 | +#include "platform_gpio.h" |
| 29 | + |
| 30 | +void led_on(const led_t led) |
| 31 | +{ |
| 32 | +#if defined(PRALINE) |
| 33 | + gpio_clear(platform_gpio()->led[led]); |
| 34 | +#else |
| 35 | + gpio_set(platform_gpio()->led[led]); |
| 36 | +#endif |
| 37 | +} |
| 38 | + |
| 39 | +void led_off(const led_t led) |
| 40 | +{ |
| 41 | +#if defined(PRALINE) |
| 42 | + gpio_set(platform_gpio()->led[led]); |
| 43 | +#else |
| 44 | + gpio_clear(platform_gpio()->led[led]); |
| 45 | +#endif |
| 46 | +} |
| 47 | + |
| 48 | +void led_toggle(const led_t led) |
| 49 | +{ |
| 50 | + gpio_toggle(platform_gpio()->led[led]); |
| 51 | +} |
| 52 | + |
| 53 | +void set_leds(const uint8_t state) |
| 54 | +{ |
| 55 | + int num_leds = 3; |
| 56 | +#if (defined RAD1O || defined PRALINE) |
| 57 | + num_leds = 4; |
| 58 | +#endif |
| 59 | + for (int i = 0; i < num_leds; i++) { |
| 60 | +#ifdef PRALINE |
| 61 | + gpio_write(platform_gpio()->led[i], ((state >> i) & 1) == 0); |
| 62 | +#else |
| 63 | + gpio_write(platform_gpio()->led[i], ((state >> i) & 1) == 1); |
| 64 | +#endif |
| 65 | + } |
| 66 | +} |
| 67 | + |
| 68 | +void halt_and_flash(const uint32_t duration) |
| 69 | +{ |
| 70 | + /* blink LED1, LED2, and LED3 */ |
| 71 | + while (1) { |
| 72 | + led_on(LED1); |
| 73 | + led_on(LED2); |
| 74 | + led_on(LED3); |
| 75 | + delay(duration); |
| 76 | + led_off(LED1); |
| 77 | + led_off(LED2); |
| 78 | + led_off(LED3); |
| 79 | + delay(duration); |
| 80 | + } |
| 81 | +} |
0 commit comments