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 all 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,69 @@ | ||
| #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 "soft_timer.h" | ||
|
|
||
|
|
||
| // GPIO address that we will allow us to read button data | ||
| const GpioAddress potentiometer_addr_A6 = { // could be passed as context | ||
|
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. Good programming practice is to not to use global variables (ie any variable that is non-static declared outside a function). The const is good since they won't be changed, but declare them static as well |
||
| .port = GPIO_PORT_A, | ||
| .pin = 6, | ||
| }; | ||
|
|
||
|
|
||
| // function that is called each time the button is clicked | ||
| static void prv_button_interrupt_callback(const GpioAddress *potentiometer_addr_B2, void *context) { | ||
|
|
||
| uint16_t data = 0; | ||
| StatusCode button_data = adc_read_raw_pin( potentiometer_addr_A6, &data); // see what this takes in in the header file | ||
|
|
||
| LOG_DEBUG("Status Code: %d\n", button_data); | ||
| LOG_DEBUG("button data: %d\n", data); | ||
| }; | ||
|
|
||
| int main(void) { | ||
| interrupt_init(); | ||
| gpio_init(); | ||
| gpio_it_init(); | ||
| soft_timer_init(); | ||
| adc_init(ADC_MODE_SINGLE); | ||
|
|
||
| // GPIO Address where button is pressed | ||
| GpioAddress potentiometer_addr_B2 = { | ||
|
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. This wouldn't be a potentiometer address, this would be a button address, so it would be good to label it as such |
||
| .port = GPIO_PORT_B, | ||
| .pin = 2, | ||
| }; | ||
|
|
||
| GpioSettings pot_settings = { | ||
| .direction = GPIO_DIR_IN, | ||
| .state = GPIO_STATE_LOW, | ||
| .resistor = GPIO_RES_NONE, | ||
| .alt_function = GPIO_ALTFN_ANALOG, | ||
| }; | ||
|
|
||
| gpio_init_pin(&potentiometer_addr_A6, &pot_settings); | ||
| gpio_init_pin(&potentiometer_addr_B2, &pot_settings); | ||
|
|
||
| InterruptSettings button_interrupt_settings = { | ||
| .type = INTERRUPT_TYPE_INTERRUPT, | ||
| .priority = INTERRUPT_PRIORITY_HIGH, | ||
| }; | ||
|
|
||
| // allow A6 to read adc | ||
| adc_set_channel_pin(potentiometer_addr_A6, true); | ||
|
|
||
| // registering interrupt for the B2 GPIO Address | ||
| gpio_it_register_interrupt(&potentiometer_addr_B2, &button_interrupt_settings, | ||
| INTERRUPT_EDGE_RISING, prv_button_interrupt_callback, NULL); | ||
|
|
||
| while (true) { | ||
| gpio_it_trigger_interrupt(&potentiometer_addr_B2); | ||
| delay_ms(200); | ||
| } | ||
| } | ||
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,84 @@ | ||
| #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" | ||
| /* | ||
| * | ||
| * Based on the MSXII pedal board schematics, write a function that writes | ||
| * 0b0010010010100110 to the configuration register, then reads the conversion register. | ||
|
|
||
| Hint: you’ll need to look at the schematics for the pedal board and the datasheet for the ADC. | ||
|
|
||
| * | ||
| */ | ||
|
|
||
| #define CAN_DEVICE_ID //something | ||
| #define CAN_BITRATE //something | ||
|
|
||
| typedef enum { | ||
| CAN_RX = 0, | ||
| CAN_TX, | ||
| CAN_FAULT, | ||
| CAN_EVENTS, | ||
| } CanEvent; | ||
|
|
||
| typedef enum { | ||
| MSG_TYPE_DATA = 0, | ||
| MSG_TYPE_ACK, | ||
| NUM_CAN_MSG_TYPES, | ||
| } CanMsgType; | ||
|
|
||
| typedef u_int16_t CanMessageId; | ||
|
|
||
| can_register_rx_handler rx_handler ( message_id, /*handler?*/, *context) { | ||
|
|
||
| } | ||
|
|
||
| typedef struct CanMessage { | ||
| u_int_16 source_id; | ||
| CanMessageId msg_id; // this is just an int | ||
| union { | ||
| uint64_t data; | ||
| uint32_t data_u32[2]; | ||
| uint16_t data_u16[4]; | ||
| uint8_t data_u8[8]; | ||
| }; | ||
| CanMsgType type; | ||
| size_t dlc; | ||
| } CanMessage; | ||
|
|
||
| int main() { | ||
|
|
||
| static *CanStorage s_can_storage = { 0 }; | ||
|
|
||
| *CanSettings can_settings = { | ||
| .device_id = CAN_DEVICE_ID, | ||
| .bitrate = CAN_BITRATE, | ||
| .tx = { GPIO_PORT_A, }, | ||
| .rx = { GPIO_PORT_A, }, | ||
| .rx_event = CAN_RX, | ||
| .tx_event = CAN_TX, | ||
| .fault_event = CAN_FAULT, | ||
| }; | ||
|
|
||
| // i have can settings so i can initialize it | ||
| // // still need to define some values taken from the schematics?? | ||
| can_init( can_settings, s_can_storage ); | ||
|
|
||
| CanMessageId message_id = ; | ||
|
|
||
| // message to send for the handler | ||
| CanMessage message = { | ||
| /* define this stuff */ | ||
| }; | ||
|
|
||
| can_register_rx_handler( message, handler, *context) | ||
|
|
||
| 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,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.