Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 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
1 change: 0 additions & 1 deletion app/payload/control_freak/flight-software/sample.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ sample:
common:
build_only: true
platform_allow:
- native_sim
- control_freak
tests:
control_freak.flight.default: {}
66 changes: 66 additions & 0 deletions app/payload/control_freak/flight-software/src/5v_ctrl.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
#include "5v_ctrl.h"

#include <initializer_list>
#include <tuple>
#include <zephyr/drivers/gpio.h>
#include <zephyr/logging/log.h>
LOG_MODULE_REGISTER(rail5v);

static const struct gpio_dt_spec ldo_en = GPIO_DT_SPEC_GET(DT_ALIAS(ldo5v), gpios);

static const struct gpio_dt_spec servo_en = GPIO_DT_SPEC_GET(DT_NODELABEL(servo_enable), gpios);

static const struct gpio_dt_spec pump_enable = GPIO_DT_SPEC_GET(DT_NODELABEL(pump_enable), gpios);

const struct gpio_dt_spec buzzer = GPIO_DT_SPEC_GET(DT_ALIAS(buzz), gpios);

// Prepares the GPIO
int five_volt_rail_init() {
using Pair = std::tuple<const struct gpio_dt_spec *, const char *>;
constexpr Pair pairs[4] = {
Pair{&ldo_en, "ldo5v"},
Pair{&servo_en, "servo"},
Pair{&pump_enable, "pump"},
Pair{&buzzer, "buzzer"},
};
for (auto [gpio, name] : pairs) {
if (!gpio_is_ready_dt(gpio)) {
LOG_WRN("No %s pin :(", name);
}
int ret = gpio_pin_configure_dt(gpio, GPIO_OUTPUT_INACTIVE);
if (ret < 0) {
LOG_WRN("Failed to conf %s pin:(", name);
Comment thread
ZZwatermelon marked this conversation as resolved.
Outdated
return ret;
}
}
LOG_INF("5V Rail all good");
return 0;
}

static bool state[(int) FiveVoltItem::NumItems] = {false};

static int set_ldo_accordingly() { return gpio_pin_set_dt(&ldo_en, (state[0] || state[1] || state[2])); }
static int set_item(FiveVoltItem item, bool set) {
if (item >= FiveVoltItem::NumItems) {
LOG_WRN("Invalid 5v rail item");
return -ENODEV;
}
state[(int) item] = set;
if (item == FiveVoltItem::Buzzer) {
return gpio_pin_set_dt(&buzzer, set);
} else if (item == FiveVoltItem::Servos) {
return gpio_pin_set_dt(&servo_en, set);
} else {
return gpio_pin_set_dt(&pump_enable, set);
}
return 0;
}
// CONFIG_PM who?
int rail_item_enable(FiveVoltItem item) { return rail_item_set(item, true); }

int rail_item_disable(FiveVoltItem item) { return rail_item_set(item, false); }

int rail_item_set(FiveVoltItem item, bool set) {
set_item(item, set);
return set_ldo_accordingly();
}
26 changes: 26 additions & 0 deletions app/payload/control_freak/flight-software/src/5v_ctrl.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#pragma once
#include <cstdint>

enum class FiveVoltItem : uint8_t { Buzzer = 0, Servos = 1, Pump = 2, NumItems = 3 };
/*
5V Bus looks like this

+-- Servo Logic Shifter Enable---Servo Logic Shifters
VBAT---LDO Enable---+-- Buzzer Enable ---Buzzer
+-- Pump Enable ---Pump

The LDO draws a fair amount of current when running even when things downstream are off
This file allows controlling individual elements and automatically handling the LDO Enable pin
*/

// Prepares the GPIO
int five_volt_rail_init();

// enable a zone (if everything else is off, turn the rail on)
int rail_item_enable(FiveVoltItem item);

// disable a zone (if everything else is off, turn the rail off)
int rail_item_disable(FiveVoltItem item);

// change the state of a zone
int rail_item_set(FiveVoltItem item, bool state);
51 changes: 42 additions & 9 deletions boards/arm/control_freak/control_freak.dts
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,25 @@
buzz = &buzzer;
ldo5v = &ldo5v_enable;
gnss = &gnss;

gpsreset = &gps_reset;
gpssafeboot = &gps_timepulse;

lora0 = &lora;
servo1 = &servo1;
servo2 = &servo2;
servo3 = &servo3;

radioreset = &radioreset;

imu = &lsm6dsl;
barom = &bmp390;

inapump = &ina260_pump;
inaservo = &ina260_servo;

groundcam = &cam1_enable;
antennacam = &cam2_enable;
};

servos: servos{
Expand All @@ -42,12 +51,12 @@
servo1: servo1 {
label = "Servo 1 PWM";
// &gpioc 6 GPIO_ACTIVE_HIGH
pwms = <&pwm3 1 PWM_MSEC(3) PWM_POLARITY_NORMAL>;
pwms = <&pwm3 2 PWM_MSEC(3) PWM_POLARITY_NORMAL>;
};
servo2: servo2 {
label = "Servo 2 PWM";
// &gpioc 7 GPIO_ACTIVE_HIGH
pwms = <&pwm3 2 PWM_MSEC(3) PWM_POLARITY_NORMAL>;
pwms = <&pwm3 1 PWM_MSEC(3) PWM_POLARITY_NORMAL>;
};
servo3: servo3 {
label = "Servo 3 PWM";
Expand Down Expand Up @@ -242,10 +251,15 @@
pinctrl-names = "default";
current-speed = <9600>;


gnss: gnss {
// MAX-M10M-00B
compatible = "gnss-nmea-generic";
compatible = "u-blox,m10";
label = "UBLOXM10";
status="okay";
reset-gpios = <&gpioa 11 GPIO_ACTIVE_LOW>;
timepulse-gpios = <&gpioa 12 GPIO_ACTIVE_HIGH>;
// reset-on-boot;
};
};

Expand All @@ -255,6 +269,9 @@
status = "okay";
clock-frequency = <I2C_BITRATE_FAST>;

scl-gpios = <&gpiob 6 GPIO_ACTIVE_HIGH>;
sda-gpios = <&gpiob 7 GPIO_ACTIVE_HIGH>;

bmp390: bmp390@77 {
status = "okay";

Expand Down Expand Up @@ -349,15 +366,29 @@
#address-cells = <1>;
#size-cells = <1>;
super_fast_partition: fastpartition@0 {
// loop(5s * 100 page/s) + (400s * 10 page/s)
// 4500 pages = 1125 KB
// loop size = 5s
// rest size = 400s
// total 405s
// 1000 acc samp/s = 100 pack/s = 100 page/s
// 405s * 100 page/s = 40500 pages
// 40500 pages = 10125 KB sector round to 10128 KB
label = "superfast-storage";
reg = <0 DT_SIZE_K(1128)>;
reg = <0 DT_SIZE_K(10128)>;
};
super_slow_partition: slowpartition@9e4000{
label = "superslow-storage";
// 1 day (24 hrs) = 86400s
// 1 page / 8 seconds
// 86400s * 1 page/ 8 s = 10800 pages
// 2700 KB
reg = <0x9e4000 DT_SIZE_K(2700)>;
};

external_storage_partition: partition@11a000 {
external_storage_partition: partition@c87000 {
// the rest for littlefs
// 16384 - 2700 - 10128
label = "w25q-storage";
reg = <0x11a000 DT_SIZE_K(15256)>;
reg = <0xc87000 DT_SIZE_K(3556)>;
};
};
};
Expand All @@ -370,7 +401,7 @@
status = "okay";
lora: lora@0{
reg = <0>;
spi-max-frequency = <(10 * 1000 * 1000)>;
spi-max-frequency = <(DT_FREQ_M(50))>;
compatible = "semtech,sx1276";

reset-gpios = <&gpioa 4 GPIO_ACTIVE_LOW>;
Expand All @@ -397,6 +428,8 @@
};


// fake and untrue, call me when we use mcuboot

// fake and untrue, call me when we use mcuboot
&flash0 {

Expand Down