Skip to content
Open
Show file tree
Hide file tree
Changes from 35 commits
Commits
Show all changes
37 commits
Select commit Hold shift + click to select a range
0ad25f8
add -C flag
kmoncr Nov 12, 2024
e46b7f5
increased readability
kmoncr Nov 13, 2024
3d9610e
let code breathe
kmoncr Nov 13, 2024
11d036c
add -C flag
kmoncr Nov 12, 2024
239926a
increased readability
kmoncr Nov 13, 2024
692b962
let code breathe
kmoncr Nov 13, 2024
467d9d3
added initial files
zidanekarim Feb 28, 2025
8b2b78c
testing push
zidanekarim Mar 7, 2025
fdbf8be
clanged sup.c
zidanekarim Mar 7, 2025
a51ea58
created enum arrays for zero/one
zidanekarim Mar 7, 2025
cafd6d1
initialized all the pins
zidanekarim Mar 7, 2025
4dccda1
hum
juhum1 Mar 7, 2025
357e2c8
added init
zidanekarim Mar 7, 2025
fbaf1f1
s
juhum1 Mar 7, 2025
bdedc4e
added digit 1-3 on
zidanekarim Mar 7, 2025
1416ccf
wrote bts_authorization with 100ms view delay
zidanekarim Mar 8, 2025
ef1d459
fixed enum def before func
zidanekarim Mar 8, 2025
63ffdc2
fixed set_one to remove zero
zidanekarim Mar 14, 2025
c815058
trying selected digits
zidanekarim Mar 14, 2025
d50d7c7
changed to active low
zidanekarim Mar 14, 2025
eee1b82
edit
juhum1 Mar 22, 2025
6d9ef43
testing static bts authorize
zidanekarim Mar 28, 2025
f445758
add -C flag
kmoncr Nov 12, 2024
98f45dc
increased readability
kmoncr Nov 13, 2024
eabe265
let code breathe
kmoncr Nov 13, 2024
d3e7f57
add -C flag
kmoncr Nov 12, 2024
7bac742
increased readability
kmoncr Nov 13, 2024
35b6e48
let code breathe
kmoncr Nov 13, 2024
8a87234
add -C flag
kmoncr Nov 12, 2024
1d93a40
increased readability
kmoncr Nov 13, 2024
5997ded
let code breathe
kmoncr Nov 13, 2024
adcbaa7
added init
zidanekarim Mar 7, 2025
6bd3008
added digit 1-3 on
zidanekarim Mar 7, 2025
20ea781
switched to 1khz
zidanekarim Apr 4, 2025
537a436
removed tester variables
zidanekarim Apr 4, 2025
23483cd
updated to use gpio_config and bitmasking
juhum1 Apr 25, 2025
cda05e7
fix .envrc
juhum1 Apr 25, 2025
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
10 changes: 10 additions & 0 deletions .envrc
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,16 @@ eval $(./site_scons/env.py --export)

export SCONSFLAGS="${SCONSFLAGS:-} --directory=$(expand_path .)"

export SCONSFLAGS="${SCONSFLAGS:-} --directory=$(expand_path .)"

export SCONSFLAGS="${SCONSFLAGS:-} --directory=$(expand_path .)"

export SCONSFLAGS="${SCONSFLAGS:-} --directory=$(expand_path .)"

export SCONSFLAGS="${SCONSFLAGS:-} --directory=$(expand_path .)"

export SCONSFLAGS="${SCONSFLAGS:-} --directory=$(expand_path .)"

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

What was the point of doing this?


COLOR_MAGENTA="\033[1;35m"

Expand Down
119 changes: 119 additions & 0 deletions components/sup/src/sup.c
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
#include "sup.h"

#include "driver/gpio.h"
#include "firmware-base/state-machine.h"
#include <ember_taskglue.h>
#include <freertos/FreeRTOS.h>
Expand All @@ -8,13 +9,131 @@
#include <opencan_templates.h>
#include <opencan_tx.h>

typedef enum {
SEG_A = 13,
SEG_B = 4,
SEG_C = 7,
SEG_D = 8,
SEG_E = 9,
SEG_F = 12,
SEG_G = 5,
SEG_DP = 11,
SEG_1 = 1,
SEG_2 = 2,
SEG_3 = 3,
SEG_4 = 6,
} SEVEN_SEG_PINS;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

ESP-IDF defines macros for pin values, try to use those over numeric values instead, even if in this case they evaluate to the same thing. Since, C lacks namespaces, please prefix enums with some kind of common value like PIN_. Also, try to follow the convention for typedefs of name_t, in this case I'd call it seven_segment_pin_t, however, since this is only in the scope of sup.c, it is safe to just make this an anonymous enum. You also include the indices for the digit selection, but give them a name that's easy to interpret as a segment. It's also strange that you start indexing at 1, does the datasheet do the same? I'd also personally turn this into a lookup table for the digit index so that you could write something like PIN_DIGIT[N] and have a pragmatic way to select the digit you want.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

On second thought, all pins should be in this enum, or just be #defines. The lookup tables can be like your zero and one array.


static void bts_authorization();
static void init_led();
static void sup_100Hz();
static void init_pin(SEVEN_SEG_PINS pin);
static void set_one();
static void set_zero();


static bool bbc_authorized;
static bool throttle_authorized;
static bool steer_authorized;


static const SEVEN_SEG_PINS zero[]
= {SEG_A, SEG_B, SEG_C, SEG_D, SEG_E, SEG_F};

static const SEVEN_SEG_PINS one[] = {SEG_B, SEG_C};

static enum {
bbc_state,
throttle_state,
steer_state
} current_state = bbc_state;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

enum constants should be in SNAKE_CASE.


static void init_pin(SEVEN_SEG_PINS pin)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I see the vision, but this is common use-case, so look into using gpio_config_t to achieve similar behavior.

{
gpio_pad_select_gpio(pin);
gpio_set_direction(pin, GPIO_MODE_OUTPUT);
}

static void init_led()
{
init_pin(SEG_A);
init_pin(SEG_B);
init_pin(SEG_C);
init_pin(SEG_D);
init_pin(SEG_E);
init_pin(SEG_F);
init_pin(SEG_G);
init_pin(SEG_DP);
init_pin(SEG_1);
init_pin(SEG_2);
init_pin(SEG_3);
init_pin(SEG_4);

// set default state to 0

set_zero();
gpio_set_level(SEG_1, 1);
gpio_set_level(SEG_2, 1);
gpio_set_level(SEG_3, 1);
}

static void set_one()
{
for (int i = 0; i < 6; i++) {
gpio_set_level(zero[i], 1);
}
for (int i = 0; i < 2; i++) {
gpio_set_level(one[i], 0);
}
gpio_set_level(SEG_G, 1);
}

static void set_zero()
{
for (int i = 0; i < 6; i++) {
gpio_set_level(zero[i], 0); // active low
}
gpio_set_level(SEG_G, 1);
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Once, again, I see the vision, but you can make this a general function that accepts a bitfield as an argument, since the seven segments + decimal point can be represented as 8-bits. Instead make a function that maps each bit of a byte into something you can display. For special digit values you can define a constant (i.e write_segments(SEGMENTS_PATTERN_1)).


static void bts_authorization()
{
if (current_state == bbc_state) {
if (bbc_authorized) {
// if bbc is authorized, show 0
set_zero();
} else {
// if not authorized, show 1
set_one();
}
gpio_set_level(SEG_1, 1);
gpio_set_level(SEG_2, 0);
gpio_set_level(SEG_3, 0);
} else if (current_state == throttle_state) {
if (throttle_authorized) {
set_zero();
} else {
set_one();
}
gpio_set_level(SEG_1, 0);
gpio_set_level(SEG_2, 1);
gpio_set_level(SEG_3, 0);
} else if (current_state == steer_state) {
if (steer_authorized) {
set_zero();
} else {
set_one();
}
gpio_set_level(SEG_1, 0);
gpio_set_level(SEG_2, 0);
gpio_set_level(SEG_3, 1);
}
current_state = (current_state + 1) % 3;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

No magic numbers! Add an additional member to your state enum called STATES_TOTAL. Since enums start counting at zero, the last element will conveniently have the same value as the number of states.

}

ember_rate_funcs_S module_rf = {
.call_init = init_led,
.call_1kHz = bts_authorization,
.call_100Hz = sup_100Hz,
};

Expand Down