stdlib.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2020 Raspberry Pi (Trading) Ltd.
3  *
4  * SPDX-License-Identifier: BSD-3-Clause
5  */
6 
7 #ifndef _PICO_STDLIB_H
8 #define _PICO_STDLIB_H
9 
10 #include "pico.h"
11 #include "pico/stdio.h"
12 #include "pico/time.h"
13 #include "hardware/gpio.h"
14 #include "hardware/uart.h"
15 
16 #ifdef __cplusplus
17 extern "C" {
18 #endif
19 
43 // Note PICO_STDIO_UART, PICO_STDIO_USB, PICO_STDIO_SEMIHOSTING are set by the
44 // respective INTERFACE libraries, so these defines are set if the library
45 // is included for the target executable
46 
47 #if LIB_PICO_STDIO_UART
48 #include "pico/stdio_uart.h"
49 #endif
50 
51 #if LIB_PICO_STDIO_USB
52 #include "pico/stdio_usb.h"
53 #endif
54 
55 #if LIB_PICO_STDIO_SEMIHOSTING
56 #include "pico/stdio_semihosting.h"
57 #endif
58 
59 // PICO_CONFIG: PICO_DEFAULT_LED_PIN, Optionally define a pin that drives a regular LED on the board, group=pico_stdlib
60 
61 // PICO_CONFIG: PICO_DEFAULT_LED_PIN_INVERTED, 1 if LED is inverted or 0 if not, type=int, default=0, group=pico_stdlib
62 #ifndef PICO_DEFAULT_LED_PIN_INVERTED
63 #define PICO_DEFAULT_LED_PIN_INVERTED 0
64 #endif
65 
66 // PICO_CONFIG: PICO_DEFAULT_WS2812_PIN, Optionally define a pin that controls data to a WS2812 compatible LED on the board, group=pico_stdlib
67 // PICO_CONFIG: PICO_DEFAULT_WS2812_POWER_PIN, Optionally define a pin that controls power to a WS2812 compatible LED on the board, group=pico_stdlib
68 
84 void setup_default_uart(void);
85 
91 void set_sys_clock_48mhz(void);
92 
102 void set_sys_clock_pll(uint32_t vco_freq, uint post_div1, uint post_div2);
103 
113 bool check_sys_clock_khz(uint32_t freq_khz, uint *vco_freq_out, uint *post_div1_out, uint *post_div2_out);
114 
126 static inline bool set_sys_clock_khz(uint32_t freq_khz, bool required) {
127  uint vco, postdiv1, postdiv2;
128  if (check_sys_clock_khz(freq_khz, &vco, &postdiv1, &postdiv2)) {
129  set_sys_clock_pll(vco, postdiv1, postdiv2);
130  return true;
131  } else if (required) {
132  panic("System clock of %u kHz cannot be exactly achieved", freq_khz);
133  }
134  return false;
135 }
136 
137 #ifdef __cplusplus
138 }
139 #endif
140 #endif
void panic(const char *fmt,...)
Displays a panic message and halts execution.
void set_sys_clock_pll(uint32_t vco_freq, uint post_div1, uint post_div2)
Initialise the system clock.
Definition: stdlib.c:39
bool check_sys_clock_khz(uint32_t freq_khz, uint *vco_freq_out, uint *post_div1_out, uint *post_div2_out)
Check if a given system clock frequency is valid/attainable.
Definition: stdlib.c:72
void set_sys_clock_48mhz(void)
Initialise the system clock to 48MHz.
Definition: stdlib.c:17
static bool set_sys_clock_khz(uint32_t freq_khz, bool required)
Attempt to set a system clock frequency in khz.
Definition: stdlib.h:126
void setup_default_uart(void)
Set up the default UART and assign it to the default GPIO's.
Definition: stdlib.c:92