Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SOFT 999] FW 103 HW #504

Open
wants to merge 7 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all 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();
mitchellostler marked this conversation as resolved.
Show resolved Hide resolved
}

return 0;
}
69 changes: 69 additions & 0 deletions projects/fw_103_hw/src/main.c
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
Copy link
Contributor

Choose a reason for hiding this comment

The 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 const static

.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 = {
Copy link
Contributor

Choose a reason for hiding this comment

The 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);
}
}
84 changes: 84 additions & 0 deletions projects/fw_104/src/main.c
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;
}
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;
}