This repository was archived by the owner on Oct 26, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
[SOFT 999] FW 103 HW #504
Open
m6keller
wants to merge
7
commits into
master
Choose a base branch
from
soft_999_fw_103_hw
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
[SOFT 999] FW 103 HW #504
Changes from 5 commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
13b2e9d
Firmware 102 Homework completed
m6keller 8b1dea4
test commit
m6keller 5a88aa7
FW 103 initial commit
m6keller a1c0a1b
FW 103 updated commit - forgot to add file to git in init commit
m6keller 08ce26a
make format and make lint
m6keller b4cb905
Updated fw 103
m6keller 76b8373
pull request suggestions changed
m6keller File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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(); | ||
| } | ||
|
|
||
| return 0; | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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); | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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); | ||
|
m6keller marked this conversation as resolved.
Outdated
|
||
|
|
||
| uint16_t button_data = 0; | ||
|
m6keller marked this conversation as resolved.
Outdated
|
||
| void prv_button_interrupt_callback(const GpioAddress *button_addr, void *context) { | ||
|
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(); | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 | ||
|
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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; | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.