Skip to content

Commit 2ad32a6

Browse files
committed
firmware: move led logic to leds.h|c
1 parent 8b74872 commit 2ad32a6

11 files changed

Lines changed: 129 additions & 71 deletions

File tree

firmware/blinky/blinky.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
#include "platform_detect.h"
2424
#include "delay.h"
2525
#include "power.h"
26+
#include "leds.h"
2627

2728
int main(void)
2829
{

firmware/common/hackrf_core.c

Lines changed: 1 addition & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
#include "gpio.h"
3030
#include "hackrf_core.h"
3131
#include "i2c_lpc.h"
32+
#include "leds.h"
3233
#include "max283x.h"
3334
#include "max5864_target.h"
3435
#include "platform_detect.h"
@@ -449,48 +450,6 @@ void pin_setup(void)
449450
sgpio_configure_pin_functions(&sgpio_config);
450451
}
451452

452-
#ifdef PRALINE
453-
void led_on(const led_t led)
454-
{
455-
gpio_clear(platform_gpio()->led[led]);
456-
}
457-
458-
void led_off(const led_t led)
459-
{
460-
gpio_set(platform_gpio()->led[led]);
461-
}
462-
#else
463-
void led_on(const led_t led)
464-
{
465-
gpio_set(platform_gpio()->led[led]);
466-
}
467-
468-
void led_off(const led_t led)
469-
{
470-
gpio_clear(platform_gpio()->led[led]);
471-
}
472-
#endif
473-
474-
void led_toggle(const led_t led)
475-
{
476-
gpio_toggle(platform_gpio()->led[led]);
477-
}
478-
479-
void set_leds(const uint8_t state)
480-
{
481-
int num_leds = 3;
482-
#if (defined RAD1O || defined PRALINE)
483-
num_leds = 4;
484-
#endif
485-
for (int i = 0; i < num_leds; i++) {
486-
#ifdef PRALINE
487-
gpio_write(platform_gpio()->led[i], ((state >> i) & 1) == 0);
488-
#else
489-
gpio_write(platform_gpio()->led[i], ((state >> i) & 1) == 1);
490-
#endif
491-
}
492-
}
493-
494453
void trigger_enable(const bool enable)
495454
{
496455
#ifndef PRALINE
@@ -500,21 +459,6 @@ void trigger_enable(const bool enable)
500459
#endif
501460
}
502461

503-
void halt_and_flash(const uint32_t duration)
504-
{
505-
/* blink LED1, LED2, and LED3 */
506-
while (1) {
507-
led_on(LED1);
508-
led_on(LED2);
509-
led_on(LED3);
510-
delay(duration);
511-
led_off(LED1);
512-
led_off(LED2);
513-
led_off(LED3);
514-
delay(duration);
515-
}
516-
}
517-
518462
#ifdef PRALINE
519463
void clkin_ctrl_set(const clkin_signal_t signal)
520464
{

firmware/common/hackrf_core.h

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -74,22 +74,8 @@ void ssp1_set_mode_ice40(void);
7474
void pin_shutdown(void);
7575
void pin_setup(void);
7676

77-
typedef enum {
78-
LED1 = 0,
79-
LED2 = 1,
80-
LED3 = 2,
81-
LED4 = 3,
82-
} led_t;
83-
84-
void led_on(const led_t led);
85-
void led_off(const led_t led);
86-
void led_toggle(const led_t led);
87-
void set_leds(const uint8_t state);
88-
8977
void trigger_enable(const bool enable);
9078

91-
void halt_and_flash(const uint32_t duration);
92-
9379
#ifdef PRALINE
9480
typedef enum {
9581
CLKIN_SIGNAL_P1 = 0,

firmware/common/leds.c

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
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+
}

firmware/common/leds.h

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
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+
#pragma once
23+
24+
#include <stdint.h>
25+
26+
typedef enum {
27+
LED1 = 0,
28+
LED2 = 1,
29+
LED3 = 2,
30+
LED4 = 3,
31+
} led_t;
32+
33+
void led_on(const led_t led);
34+
void led_off(const led_t led);
35+
void led_toggle(const led_t led);
36+
void set_leds(const uint8_t state);
37+
38+
void halt_and_flash(const uint32_t duration);

firmware/common/platform_detect.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include "gpio.h"
2828
#include "gpio_lpc.h"
2929
#include "hackrf_core.h"
30+
#include "leds.h"
3031
#include "platform_detect.h"
3132
#include "platform_scu.h"
3233

firmware/hackrf-common.cmake

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,7 @@ macro(DeclareTargets)
172172
${PATH_HACKRF_FIRMWARE_COMMON}/cpu_clock.c
173173
${PATH_HACKRF_FIRMWARE_COMMON}/delay.c
174174
${PATH_HACKRF_FIRMWARE_COMMON}/hackrf_core.c
175+
${PATH_HACKRF_FIRMWARE_COMMON}/leds.c
175176
${PATH_HACKRF_FIRMWARE_COMMON}/sgpio.c
176177
${PATH_HACKRF_FIRMWARE_COMMON}/rf_path.c
177178
${PATH_HACKRF_FIRMWARE_COMMON}/si5351c.c

firmware/hackrf_usb/hackrf_usb.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
#include <delay.h>
3737
#include <hackrf_core.h>
3838
#include <hackrf_ui.h>
39+
#include <leds.h>
3940
#include <operacake.h>
4041
#include <platform_detect.h>
4142
#include <power.h>

firmware/hackrf_usb/usb_api_cpld.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#include <cpld_jtag.h>
3131
#include <cpld_xc2c.h>
3232
#include <hackrf_core.h>
33+
#include <leds.h>
3334
#include <usb_queue.h>
3435
#include <usb_request.h>
3536
#include <usb_type.h>

firmware/hackrf_usb/usb_api_register.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,9 @@
2828
#include <stddef.h>
2929
#include <stdint.h>
3030

31+
#include <clock_gen.h>
3132
#include <hackrf_core.h>
33+
#include <leds.h>
3234
#include <max283x.h>
3335
#include <radio.h>
3436
#include <si5351c.h>

0 commit comments

Comments
 (0)