|
| 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 "power.h" |
| 23 | + |
| 24 | +#if defined(HACKRF_ONE) |
| 25 | + #include <stdint.h> |
| 26 | +#endif |
| 27 | +#if defined(HACKRF_ONE) || defined(RAD1O) || defined(JAWBREAKER) |
| 28 | + #include "platform_detect.h" |
| 29 | +#endif |
| 30 | +#if defined(PRALINE) || defined(RAD1O) |
| 31 | + #include "delay.h" |
| 32 | +#endif |
| 33 | + |
| 34 | +#include "gpio.h" |
| 35 | +#include "platform_gpio.h" |
| 36 | + |
| 37 | +#if defined(PRALINE) |
| 38 | +void enable_1v2_power(void) |
| 39 | +{ |
| 40 | + gpio_set(platform_gpio()->gpio_1v2_enable); |
| 41 | +} |
| 42 | + |
| 43 | +void disable_1v2_power(void) |
| 44 | +{ |
| 45 | + gpio_clear(platform_gpio()->gpio_1v2_enable); |
| 46 | +} |
| 47 | + |
| 48 | +void enable_3v3aux_power(void) |
| 49 | +{ |
| 50 | + gpio_clear(platform_gpio()->gpio_3v3aux_enable_n); |
| 51 | +} |
| 52 | + |
| 53 | +void disable_3v3aux_power(void) |
| 54 | +{ |
| 55 | + gpio_set(platform_gpio()->gpio_3v3aux_enable_n); |
| 56 | +} |
| 57 | + |
| 58 | +#else |
| 59 | +void enable_1v8_power(void) |
| 60 | +{ |
| 61 | + if (detected_platform() == BOARD_ID_HACKRF1_R9) { |
| 62 | + #ifdef HACKRF_ONE |
| 63 | + gpio_set(platform_gpio()->h1r9_1v8_enable); |
| 64 | + #endif |
| 65 | + } else { |
| 66 | + gpio_set(platform_gpio()->gpio_1v8_enable); |
| 67 | + } |
| 68 | +} |
| 69 | + |
| 70 | +void disable_1v8_power(void) |
| 71 | +{ |
| 72 | + if (detected_platform() == BOARD_ID_HACKRF1_R9) { |
| 73 | + #ifdef HACKRF_ONE |
| 74 | + gpio_clear(platform_gpio()->h1r9_1v8_enable); |
| 75 | + #endif |
| 76 | + } else { |
| 77 | + gpio_clear(platform_gpio()->gpio_1v8_enable); |
| 78 | + } |
| 79 | +} |
| 80 | +#endif |
| 81 | + |
| 82 | +#if defined(HACKRF_ONE) |
| 83 | +void enable_rf_power(void) |
| 84 | +{ |
| 85 | + const platform_gpio_t* gpio = platform_gpio(); |
| 86 | + uint32_t i; |
| 87 | + |
| 88 | + /* many short pulses to avoid one big voltage glitch */ |
| 89 | + for (i = 0; i < 1000; i++) { |
| 90 | + if (detected_platform() == BOARD_ID_HACKRF1_R9) { |
| 91 | + gpio_set(gpio->h1r9_vaa_disable); |
| 92 | + gpio_clear(gpio->h1r9_vaa_disable); |
| 93 | + } else { |
| 94 | + gpio_set(gpio->vaa_disable); |
| 95 | + gpio_clear(gpio->vaa_disable); |
| 96 | + } |
| 97 | + } |
| 98 | +} |
| 99 | + |
| 100 | +void disable_rf_power(void) |
| 101 | +{ |
| 102 | + if (detected_platform() == BOARD_ID_HACKRF1_R9) { |
| 103 | + gpio_set(platform_gpio()->h1r9_vaa_disable); |
| 104 | + } else { |
| 105 | + gpio_set(platform_gpio()->vaa_disable); |
| 106 | + } |
| 107 | +} |
| 108 | + |
| 109 | +#elif defined(PRALINE) |
| 110 | +void enable_rf_power(void) |
| 111 | +{ |
| 112 | + gpio_clear(platform_gpio()->vaa_disable); |
| 113 | + |
| 114 | + /* Let the voltage stabilize */ |
| 115 | + delay(1000000); |
| 116 | +} |
| 117 | + |
| 118 | +void disable_rf_power(void) |
| 119 | +{ |
| 120 | + gpio_set(platform_gpio()->vaa_disable); |
| 121 | +} |
| 122 | + |
| 123 | +#elif defined(RAD1O) |
| 124 | +void enable_rf_power(void) |
| 125 | +{ |
| 126 | + gpio_set(platform_gpio()->vaa_enable); |
| 127 | + |
| 128 | + /* Let the voltage stabilize */ |
| 129 | + delay(1000000); |
| 130 | +} |
| 131 | + |
| 132 | +void disable_rf_power(void) |
| 133 | +{ |
| 134 | + gpio_clear(platform_gpio()->vaa_enable); |
| 135 | +} |
| 136 | +#endif |
0 commit comments