From b732cac4b3c938a2483f8dd25abfbc5b50b83645 Mon Sep 17 00:00:00 2001
From: William Grant <williamgrantuk@gmail.com>
Date: Sun, 14 May 2023 21:03:01 +0100
Subject: [PATCH] stubs for my challenges

---
 .gitignore                      |  1 +
 buzz_cycle_stubs/CMakeLists.txt | 17 +++++++++
 buzz_cycle_stubs/buzz_cycle.c   | 37 ++++++++++++++++++
 buzz_cycle_stubs/buzzer.h       | 24 ++++++++++++
 fixmath_stubs/fixmath.c         | 28 ++++++++++++++
 fixmath_stubs/fixmath.h         | 66 +++++++++++++++++++++++++++++++++
 6 files changed, 173 insertions(+)
 create mode 100644 buzz_cycle_stubs/CMakeLists.txt
 create mode 100644 buzz_cycle_stubs/buzz_cycle.c
 create mode 100644 buzz_cycle_stubs/buzzer.h
 create mode 100644 fixmath_stubs/fixmath.c
 create mode 100644 fixmath_stubs/fixmath.h

diff --git a/.gitignore b/.gitignore
index b028dd1..5825b1b 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,3 +1,4 @@
 build/**
+submission/**
 *.swp
 
diff --git a/buzz_cycle_stubs/CMakeLists.txt b/buzz_cycle_stubs/CMakeLists.txt
new file mode 100644
index 0000000..3190487
--- /dev/null
+++ b/buzz_cycle_stubs/CMakeLists.txt
@@ -0,0 +1,17 @@
+if (TARGET tinyusb_device)
+
+add_library(buzzer STATIC buzzer.h)
+target_link_libraries(buzzer hardware_pwm picostdlib)
+
+add_executable(buzz_cycle buzz_cycle.c)
+target_link_libraries(buzz_cycle buzzer pico_stdlib)
+
+pico_enable_stdio_usb(buzz_cycle 1)
+pico_enable_stdio_uart(buzz_cycle 0)
+
+pico_add_extra_outputs(buzz_cycle)
+
+elseif(PICO_ON_DEVICE)
+    message(WARNING "cannot build buzz_cycle because TinyUSB submodule is not initialised in the SDK")
+endif()
+
diff --git a/buzz_cycle_stubs/buzz_cycle.c b/buzz_cycle_stubs/buzz_cycle.c
new file mode 100644
index 0000000..2ae9970
--- /dev/null
+++ b/buzz_cycle_stubs/buzz_cycle.c
@@ -0,0 +1,37 @@
+#include <stdint.h>
+#include <stdbool.h>
+#include <stdio.h>
+#include "pico/stdlib.h"
+#include "buzzer.h"
+
+static int64_t period = 1000000;
+static bool alarm_status = false;
+
+// timer callback that controls the buzzer
+static int64_t buzz_isr(alarm_id_t id, void* data) {
+
+}
+
+// initialise stdio and the buzzer
+static inline void init() {
+
+}
+
+static inline void start_timer() {
+
+}
+
+// allow the user to enter a period in microseconds
+int64_t get_period() {
+
+}
+
+int main(void) {
+    init();
+    start_timer();
+
+    while (true) {
+        period = get_period();
+    }
+}
+
diff --git a/buzz_cycle_stubs/buzzer.h b/buzz_cycle_stubs/buzzer.h
new file mode 100644
index 0000000..c84a66f
--- /dev/null
+++ b/buzz_cycle_stubs/buzzer.h
@@ -0,0 +1,24 @@
+#pragma once
+
+#include <stdint.h>
+#include "pico/stdlib.h"
+#include "hardware/pwm.h"
+
+const unsigned int buzzer = 18u;
+
+static inline void buzzer_enable() {
+
+}
+
+static inline void buzzer_disable() {
+
+}
+
+static inline void buzzer_toggle(uint64_t time) {
+
+}
+
+void buzzer_init() {
+
+}
+
diff --git a/fixmath_stubs/fixmath.c b/fixmath_stubs/fixmath.c
new file mode 100644
index 0000000..cf35cf7
--- /dev/null
+++ b/fixmath_stubs/fixmath.c
@@ -0,0 +1,28 @@
+#include "fixmath.h"
+
+#include <stdint>
+
+fix_t fix_emul(fix_t x, fix_t y) {
+
+}
+
+fix_t fix_ediv(fix_t x, fix_t y) {
+
+}
+
+fix_t fix_esqrt(fix_t x) {
+
+}
+
+fix_unit_t fix_umul(fix_unit_t x, fix_unit_t y) {
+
+}
+
+fix_unit_t fix_udiv(fix_unit_t x, fix_unit_t y) {
+
+}
+
+fix_unit_t fix_usqrt(fix_unit_t x) {
+
+}
+
diff --git a/fixmath_stubs/fixmath.h b/fixmath_stubs/fixmath.h
new file mode 100644
index 0000000..ffc1a48
--- /dev/null
+++ b/fixmath_stubs/fixmath.h
@@ -0,0 +1,66 @@
+#pragma once
+
+#include <stdint>
+
+// standard, even type (16.16) with range [-32768, 32768)
+typedef struct {
+    uint32_t raw;
+} fix_t;
+
+// unit type (1.31) with range [-1, 1)
+typedef struct {
+    uint32_t raw;
+} fix_unit_t;
+
+// fix_t functions
+static inline fix_t fix_eadd(fix_t x, fix_t y) {
+
+}
+
+static inline fix_t fix_esub(fix_t x, fix_t y) {
+
+}
+
+static inline fix_t fix_eneg(fix_t x) {
+
+}
+
+fix_t fix_emul(fix_t x, fix_t y);
+fix_t fix_ediv(fix_t x, fix_t y);
+
+fix_t fix_esqrt(fix_t x);
+
+static inline fix_t fix_efrom_int(int x) {
+
+}
+
+// fix_unit_t functions
+static inline fix_unit_t fix_uadd(fix_unit_t x, fix_unit_t y) {
+
+}
+
+static inline fix_unit_t fix_usub(fix_unit_t x, fix_unit_t y) {
+
+}
+
+static inline fix_unit_t fix_eneg(fix_t x) {
+
+}
+
+fix_unit_t fix_umul(fix_unit_t x, fix_unit_t y);
+fix_unit_t fix_udiv(fix_unit_t x, fix_unit_t y);
+
+fix_unit_t fix_usqrt(fix_unit_t x);
+
+static inline fix_unit_t fix_ufrom_reciprocal(int x) {
+
+}
+
+// generic macros
+# define fix_add(x, y) _Generic(x, fix_t: fix_eadd, fix_unit_t: fix_uadd)(x, y)
+# define fix_sub(x, y) _Generic(x, fix_t: fix_esub, fix_unit_t: fix_usub)(x, y)
+# define fix_mul(x, y) _Generic(x, fix_t: fix_emul, fix_unit_t: fix_umul)(x, y)
+# define fix_div(x, y) _Generic(x, fix_t: fix_ediv, fix_unit_t: fix_udiv)(x, y)
+
+# define fix_sqrt(x) _Generic(x, fix_t: fix_esqrt, fix_unit_t: fix_usqrt)(x)
+
-- 
GitLab