Skip to content
This repository was archived by the owner on Oct 26, 2025. It is now read-only.
Open
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions projects/fw102_example/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<!--
General guidelines
These are just guidelines, not strict rules - document however seems best.
A README for a firmware-only project (e.g. Babydriver, MU, bootloader, CAN explorer) should answer the following questions:
- What is it?
- What problem does it solve?
- How do I use it? (with usage examples / example commands, etc)
- How does it work? (architectural overview)
A README for a board project (powering a hardware board, e.g. power distribution, centre console, charger, BMS carrier) should answer the following questions:
- What is the purpose of the board?
- What are all the things that the firmware needs to do?
- How does it fit into the overall system?
- How does it work? (architectural overview, e.g. what each module's purpose is or how data flows through the firmware)
-->
# fw102_example

9 changes: 9 additions & 0 deletions projects/fw102_example/rules.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Defines $(T)_SRC, $(T)_INC, $(T)_DEPS, and $(T)_CFLAGS for the build makefile.
# Tests can be excluded by defining $(T)_EXCLUDE_TESTS.
# Pre-defined:
# $(T)_SRC_ROOT: $(T)_DIR/src
# $(T)_INC_DIRS: $(T)_DIR/inc{/$(PLATFORM)}
# $(T)_SRC: $(T)_DIR/src{/$(PLATFORM)}/*.{c,s}

# Specify the libraries you want to include
$(T)_DEPS := ms-common
42 changes: 42 additions & 0 deletions projects/fw102_example/src/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
//
// Created by Matthew Keller on 2022-01-22.
//
#include <stdbool.h>
#include "interrupt.h" // For interrupting stuff
#include "log.h" // For printing stuff.
#include "misc.h" // Various helper functions/macros.
#include "soft_timer.h" // Software timers for scheduling future events.
#include "wait.h" //

#define COUNTER_LENGTH_MS 500

typedef struct Counters {
uint8_t counter_a;
uint8_t counter_b;
} Counters;

static void prv_increment_a(SoftTimerId timer_id, void *context) {
Counters *counting = context;
counting->counter_a++;
LOG_DEBUG("Counter A: %d\n", counting->counter_a);

if (counting->counter_a % 2 == 0) counting->counter_b++;
LOG_DEBUG("Counter B: %d\n", counting->counter_b);
}

soft_timer_start_millis(COUNTER_LENGTH_MS, prv_increment_a, context, NULL);
}

int main(void) {
interrupt_init();
soft_timer_init();

Counters counting = { 0 };
soft_timer_start_millis(COUNTER_LENGTH_MS, prv_increment_a, &counting, NULL);

while (true) {
wait();
Comment thread
mitchellostler marked this conversation as resolved.
}

return 0;
}
67 changes: 67 additions & 0 deletions projects/fw_103_hw/src/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
#include <stdbool.h>
#include <stdio.h>

#include "adc.h"
#include "delay.h"
#include "gpio.h"
#include "gpio_it.h"
#include "interrupt.h"
#include "log.h"
#include "wait.h"

/*
* Create a project that reads an ADC converted reading from pin A6
* whenever a button connected to pin B2 is pressed and logs the output.
* The adc reading should trigger whenever the button is released,
* not initially when the button is pressed.
* Follow the same submission procedures as the firmware 102 homework,
* except the suffix of the branch should be fw_103.

Hints:
assume the button is active-high

register an interrupt with the appropriate InterruptEdge settings (google this or ask someone / your
lead)

*/

int main(void) {
gpio_init();
gpio_it_init();
adc_init(ADC_MODE_SINGLE);

GpioAddress button_addr = {
.port = GPIO_PORT_A,
.pin = 6,
};

GpioSettings pot_settings = {
.direction = GPIO_DIR_IN,
.state = GPIO_STATE_LOW,
.resistor = GPIO_RES_NONE,
.alt_function = GPIO_ALTFN_ANALOG,
};

gpio_init_pin(&button_addr, &pot_settings);

InterruptSettings button_interrupt_settings = {
.type = INTERRUPT_TYPE_INTERRUPT,
.priority = INTERRUPT_PRIORITY_HIGH,
};

adc_set_channel_pin(button_addr, true);

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The adc should be set for the potentiometer pin, instead of the button


gpio_it_get_edge(&button_addr, INTERRUPT_EDGE_RISING);
Comment thread
m6keller marked this conversation as resolved.
Outdated

uint16_t button_data = 0;
Comment thread
m6keller marked this conversation as resolved.
Outdated
void prv_button_interrupt_callback(const GpioAddress *button_addr, void *context) {
Comment thread
m6keller marked this conversation as resolved.
Outdated
LOG_DEBUG("button data: %d\n", button_data);
};

gpio_it_register_interrupt(&button_addr, &button_interrupt_settings, INTERRUPT_EDGE_RISING,
&prv_button_interrupt_callback, NULL);

while (true) {
wait();
}
}
16 changes: 16 additions & 0 deletions projects/helloworld/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<!--
General guidelines
These are just guidelines, not strict rules - document however seems best.
A README for a firmware-only project (e.g. Babydriver, MU, bootloader, CAN explorer) should answer the following questions:
- What is it?
- What problem does it solve?
- How do I use it? (with usage examples / example commands, etc)
- How does it work? (architectural overview)
A README for a board project (powering a hardware board, e.g. power distribution, centre console, charger, BMS carrier) should answer the following questions:
- What is the purpose of the board?
- What are all the things that the firmware needs to do?
- How does it fit into the overall system?
- How does it work? (architectural overview, e.g. what each module's purpose is or how data flows through the firmware)
-->
# helloworld

9 changes: 9 additions & 0 deletions projects/helloworld/rules.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Defines $(T)_SRC, $(T)_INC, $(T)_DEPS, and $(T)_CFLAGS for the build makefile.
# Tests can be excluded by defining $(T)_EXCLUDE_TESTS.
# Pre-defined:
# $(T)_SRC_ROOT: $(T)_DIR/src
# $(T)_INC_DIRS: $(T)_DIR/inc{/$(PLATFORM)}
# $(T)_SRC: $(T)_DIR/src{/$(PLATFORM)}/*.{c,s}

# Specify the libraries you want to include
$(T)_DEPS := ms-common
11 changes: 11 additions & 0 deletions projects/helloworld/src/main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
//
// Created by Matthew Keller on 2022-01-22.
//

#include "log.h"

int main(void) {
LOG_DEBUG("Hello World!\n");

return 0;
}