forked from EngineerGuy314/pico-WSPRer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
utilities.c
73 lines (61 loc) · 2.08 KB
/
utilities.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
/////////////////////////////////////////////////////////////////////////////
// Other functions used in pico-WSPRer
// Jakub Serych [email protected]
//
// PROJECT PAGE
// https://github.com/EngineerGuy314/pico-WSPRer
/////////////////////////////////////////////////////////////////////////////
#include <stdio.h>
#include <string.h>
#include <ctype.h>
#include <defines.h>
#include "pico/stdlib.h"
#include "hardware/clocks.h"
#include "hardware/gpio.h"
#include "hardware/adc.h"
#include <piodco.h>
#include "TxChannel.h"
static TxChannelContext *spOsc = NULL;
/**
* @brief Improoved user input function
*
* @param prompt Prompt to display to user
* @param input_variable Variable to which we want to read input
* @param max_length Maximum length of input string
*/
void get_user_input(const char *prompt, char *input_variable, int max_length) {
int index = 0;
int ch;
printf("%s", prompt); // Display the prompt to the user
fflush(stdout);
while (1) {
ch = getchar();
if (ch == '\n' || ch == '\r') { // Enter key pressed
break;
} else if (ch == 127 || ch == 8) { // Backspace key pressed (127 for most Unix, 8 for Windows)
if (index > 0) {
index--;
printf("\b \b"); // Move back, print space, move back again
}
} else if (isprint(ch)) {
if (index < max_length - 1) { // Ensure room for null terminator
input_variable[index++] = ch;
printf("%c", ch); // Echo character
}
}
fflush(stdout);
}
input_variable[index] = '\0'; // Null-terminate the string
printf("\n");
}
/// @brief Initializes Pi pico clock.
void InitPicoClock(int PLL_SYS_MHZ)
{
const uint32_t clkhz = PLL_SYS_MHZ * 1000000L;
printf("\n ABOUT TO SET SYSTEM KLOCK TO %dMhz\n", PLL_SYS_MHZ);
set_sys_clock_khz(clkhz / kHz, true);
clock_configure(clk_peri, 0,
CLOCKS_CLK_PERI_CTRL_AUXSRC_VALUE_CLKSRC_PLL_SYS,
PLL_SYS_MHZ * MHZ,
PLL_SYS_MHZ * MHZ);
}