Squashed 'third_party/pico-sdk/' content from commit 2062372d2
Change-Id: Ic20f199d3ed0ea8d3a6a1bbf513f875ec7500cc6
git-subtree-dir: third_party/pico-sdk
git-subtree-split: 2062372d203b372849d573f252cf7c6dc2800c0a
Signed-off-by: Austin Schuh <austin.linux@gmail.com>
diff --git a/src/common/pico_base/CMakeLists.txt b/src/common/pico_base/CMakeLists.txt
new file mode 100644
index 0000000..3555dc0
--- /dev/null
+++ b/src/common/pico_base/CMakeLists.txt
@@ -0,0 +1,13 @@
+if (NOT TARGET pico_base_headers)
+ add_library(pico_base_headers INTERFACE)
+ target_include_directories(pico_base_headers INTERFACE include ${CMAKE_BINARY_DIR}/generated/pico_base)
+
+ # PICO_BUILD_DEFINE: PICO_BOARD, Name of board, type=string, default=CMake PICO_BOARD variable, group=pico_base
+ target_compile_definitions(pico_base_headers INTERFACE
+ PICO_BOARD="${PICO_BOARD}")
+
+ target_link_libraries(pico_base_headers INTERFACE pico_platform_headers)
+
+ list(APPEND PICO_SDK_POST_LIST_FILES ${CMAKE_CURRENT_LIST_DIR}/generate_config_header.cmake)
+ pico_promote_common_scope_vars()
+endif()
\ No newline at end of file
diff --git a/src/common/pico_base/generate_config_header.cmake b/src/common/pico_base/generate_config_header.cmake
new file mode 100644
index 0000000..333dfa7
--- /dev/null
+++ b/src/common/pico_base/generate_config_header.cmake
@@ -0,0 +1,29 @@
+# build the auto gen config headers
+
+set(header_content "// AUTOGENERATED FROM PICO_CONFIG_HEADER_FILES and then PICO_<PLATFORM>_CONFIG_HEADER_FILES\n// DO NOT EDIT!\n")
+string(TOUPPER ${PICO_PLATFORM} PICO_PLATFORM_UPPER)
+
+macro(add_header_content_from_var VAR)
+ set(header_content "${header_content}\n\n// based on ${VAR}:\n")
+ foreach(var IN LISTS ${VAR})
+ set(header_content "${header_content}\n#include \"${var}\"")
+ endforeach()
+endmacro()
+
+# PICO_CMAKE_CONFIG: PICO_CONFIG_HEADER_FILES, List of extra header files to include from pico/config.h for all platforms, type=list, default="", group=pico_base
+add_header_content_from_var(PICO_CONFIG_HEADER_FILES)
+
+# PICO_CMAKE_CONFIG: PICO_CONFIG_RP2040_HEADER_FILES, List of extra header files to include from pico/config.h for rp2040 platform, type=list, default="", group=pico_base
+# PICO_CMAKE_CONFIG: PICO_CONFIG_HOST_HEADER_FILES, List of extra header files to include from pico/config.h for host platform, type=list, default="", group=pico_base
+add_header_content_from_var(PICO_${PICO_PLATFORM_UPPER}_CONFIG_HEADER_FILES)
+
+file(GENERATE
+ OUTPUT ${CMAKE_BINARY_DIR}/generated/pico_base/pico/config_autogen.h
+ CONTENT "${header_content}"
+ )
+
+configure_file( ${CMAKE_CURRENT_LIST_DIR}/include/pico/version.h.in ${CMAKE_BINARY_DIR}/generated/pico_base/pico/version.h)
+
+foreach(DIR IN LISTS PICO_INCLUDE_DIRS)
+ target_include_directories(pico_base_headers INTERFACE ${DIR})
+endforeach()
\ No newline at end of file
diff --git a/src/common/pico_base/include/pico.h b/src/common/pico_base/include/pico.h
new file mode 100644
index 0000000..1b73651
--- /dev/null
+++ b/src/common/pico_base/include/pico.h
@@ -0,0 +1,25 @@
+/*
+ * Copyright (c) 2020 Raspberry Pi (Trading) Ltd.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ */
+
+#ifndef PICO_H_
+#define PICO_H_
+
+/** \file pico.h
+ * \defgroup pico_base pico_base
+ *
+ * Core types and macros for the Raspberry Pi Pico SDK. This header is intended to be included by all source code
+ * as it includes configuration headers and overrides in the correct order
+ *
+ * This header may be included by assembly code
+*/
+
+#include "pico/types.h"
+#include "pico/version.h"
+#include "pico/config.h"
+#include "pico/platform.h"
+#include "pico/error.h"
+
+#endif
diff --git a/src/common/pico_base/include/pico/assert.h b/src/common/pico_base/include/pico/assert.h
new file mode 100644
index 0000000..8910ebd
--- /dev/null
+++ b/src/common/pico_base/include/pico/assert.h
@@ -0,0 +1,51 @@
+/*
+ * Copyright (c) 2020 Raspberry Pi (Trading) Ltd.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ */
+
+#ifndef _PICO_ASSERT_H
+#define _PICO_ASSERT_H
+
+#include <stdbool.h>
+
+#ifdef __cplusplus
+
+#include <cassert>
+
+extern "C" {
+#else
+#include <assert.h>
+#endif
+
+// PICO_CONFIG: PARAM_ASSERTIONS_ENABLE_ALL, Global assert enable, type=bool, default=0, group=pico_base
+// PICO_CONFIG: PARAM_ASSERTIONS_DISABLE_ALL, Global assert disable, type=bool, default=0, group=pico_base
+
+#ifndef PARAM_ASSERTIONS_ENABLE_ALL
+#define PARAM_ASSERTIONS_ENABLE_ALL 0
+#endif
+
+#ifndef PARAM_ASSERTIONS_DISABLE_ALL
+#define PARAM_ASSERTIONS_DISABLE_ALL 0
+#endif
+
+#define PARAM_ASSERTIONS_ENABLED(x) ((PARAM_ASSERTIONS_ENABLED_ ## x || PARAM_ASSERTIONS_ENABLE_ALL) && !PARAM_ASSERTIONS_DISABLE_ALL)
+
+#define invalid_params_if(x, test) ({if (PARAM_ASSERTIONS_ENABLED(x)) assert(!(test));})
+#define valid_params_if(x, test) ({if (PARAM_ASSERTIONS_ENABLED(x)) assert(test);})
+#define hard_assert_if(x, test) ({if (PARAM_ASSERTIONS_ENABLED(x)) hard_assert(!(test));})
+
+#ifdef NDEBUG
+extern void hard_assertion_failure(void);
+static inline void hard_assert(bool condition, ...) {
+ if (!condition)
+ hard_assertion_failure();
+}
+#else
+#define hard_assert assert
+#endif
+
+#ifdef __cplusplus
+}
+#endif
+#endif
diff --git a/src/common/pico_base/include/pico/config.h b/src/common/pico_base/include/pico/config.h
new file mode 100644
index 0000000..8d69269
--- /dev/null
+++ b/src/common/pico_base/include/pico/config.h
@@ -0,0 +1,21 @@
+/*
+ * Copyright (c) 2020 Raspberry Pi (Trading) Ltd.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ */
+
+#ifndef PICO_CONFIG_H_
+#define PICO_CONFIG_H_
+
+// -----------------------------------------------------
+// NOTE: THIS HEADER IS ALSO INCLUDED BY ASSEMBLY CODE SO
+// SHOULD ONLY CONSIST OF PREPROCESSOR DIRECTIVES
+// OR USE #ifndef __ASSEMBLER__ guards
+// -------------
+
+// PICO_CONFIG_HEADER_FILES and then PICO_SDK_<PLATFORM>_CONFIG_INCLUDE_FILES
+// entries are dumped in order at build time into this generated header
+
+#include "pico/config_autogen.h"
+
+#endif
\ No newline at end of file
diff --git a/src/common/pico_base/include/pico/error.h b/src/common/pico_base/include/pico/error.h
new file mode 100644
index 0000000..fadb45e
--- /dev/null
+++ b/src/common/pico_base/include/pico/error.h
@@ -0,0 +1,25 @@
+/*
+ * Copyright (c) 2020 Raspberry Pi (Trading) Ltd.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ */
+
+#ifndef _PICO_ERROR_H
+#define _PICO_ERROR_H
+
+#ifndef __ASSEMBLER__
+
+/*!
+ * Common return codes from pico_sdk methods that return a status
+ */
+enum {
+ PICO_OK = 0,
+ PICO_ERROR_NONE = 0,
+ PICO_ERROR_TIMEOUT = -1,
+ PICO_ERROR_GENERIC = -2,
+ PICO_ERROR_NO_DATA = -3,
+};
+
+#endif // !__ASSEMBLER__
+
+#endif
\ No newline at end of file
diff --git a/src/common/pico_base/include/pico/types.h b/src/common/pico_base/include/pico/types.h
new file mode 100644
index 0000000..8e1627c
--- /dev/null
+++ b/src/common/pico_base/include/pico/types.h
@@ -0,0 +1,94 @@
+/*
+ * Copyright (c) 2020 Raspberry Pi (Trading) Ltd.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ */
+
+#ifndef _PICO_TYPES_H
+#define _PICO_TYPES_H
+
+#ifndef __ASSEMBLER__
+
+#include "pico/assert.h"
+
+#include <stdint.h>
+#include <stdbool.h>
+#include <stddef.h>
+
+typedef unsigned int uint;
+
+/*! \typedef absolute_time_t
+ \brief An opaque 64 bit timestamp in microseconds
+
+ The type is used instead of a raw uint64_t to prevent accidentally passing relative times or times in the wrong
+ time units where an absolute time is required. It is equivalent to uint64_t in release builds.
+
+ \see to_us_since_boot()
+ \see update_us_since_boot()
+ \ingroup timestamp
+*/
+#ifdef NDEBUG
+typedef uint64_t absolute_time_t;
+#else
+typedef struct {
+ uint64_t _private_us_since_boot;
+} absolute_time_t;
+#endif
+
+/*! fn to_us_since_boot
+ * \brief convert an absolute_time_t into a number of microseconds since boot.
+ * \param t the absolute time to convert
+ * \return a number of microseconds since boot, equivalent to t
+ * \ingroup timestamp
+ */
+static inline uint64_t to_us_since_boot(absolute_time_t t) {
+#ifdef NDEBUG
+ return t;
+#else
+ return t._private_us_since_boot;
+#endif
+}
+
+/*! fn update_us_since_boot
+ * \brief update an absolute_time_t value to represent a given number of microseconds since boot
+ * \param t the absolute time value to update
+ * \param us_since_boot the number of microseconds since boot to represent. Note this should be representable
+ * as a signed 64 bit integer
+ * \ingroup timestamp
+ */
+static inline void update_us_since_boot(absolute_time_t *t, uint64_t us_since_boot) {
+#ifdef NDEBUG
+ *t = us_since_boot;
+#else
+ assert(us_since_boot <= INT64_MAX);
+ t->_private_us_since_boot = us_since_boot;
+#endif
+}
+
+#ifdef NDEBUG
+#define ABSOLUTE_TIME_INITIALIZED_VAR(name, value) name = value
+#else
+#define ABSOLUTE_TIME_INITIALIZED_VAR(name, value) name = {value}
+#endif
+
+/** \struct datetime_t
+ * \ingroup util_datetime
+ * \brief Structure containing date and time information
+ *
+ * When setting an RTC alarm, set a field to -1 tells
+ * the RTC to not match on this field
+ */
+typedef struct {
+ int16_t year; ///< 0..4095
+ int8_t month; ///< 1..12, 1 is January
+ int8_t day; ///< 1..28,29,30,31 depending on month
+ int8_t dotw; ///< 0..6, 0 is Sunday
+ int8_t hour; ///< 0..23
+ int8_t min; ///< 0..59
+ int8_t sec; ///< 0..59
+} datetime_t;
+
+#define bool_to_bit(x) ((uint)!!(x))
+
+#endif
+#endif
diff --git a/src/common/pico_base/include/pico/version.h.in b/src/common/pico_base/include/pico/version.h.in
new file mode 100644
index 0000000..08fbfb5
--- /dev/null
+++ b/src/common/pico_base/include/pico/version.h.in
@@ -0,0 +1,19 @@
+/*
+ * Copyright (c) 2020 Raspberry Pi (Trading) Ltd.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ */
+
+// ---------------------------------------
+// THIS FILE IS AUTOGENERATED; DO NOT EDIT
+// ---------------------------------------
+
+#ifndef _PICO_VERSION_H
+#define _PICO_VERSION_H
+
+#define PICO_SDK_VERSION_MAJOR ${PICO_SDK_VERSION_MAJOR}
+#define PICO_SDK_VERSION_MINOR ${PICO_SDK_VERSION_MINOR}
+#define PICO_SDK_VERSION_REVISION ${PICO_SDK_VERSION_REVISION}
+#define PICO_SDK_VERSION_STRING "${PICO_SDK_VERSION_STRING}"
+
+#endif