Skip to content
Snippets Groups Projects
Commit b732cac4 authored by William Grant's avatar William Grant
Browse files

stubs for my challenges

parent 6dd44321
No related branches found
No related tags found
No related merge requests found
build/**
submission/**
*.swp
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()
#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();
}
}
#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() {
}
#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) {
}
#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)
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment