Skip to content

Commit 9a620e6

Browse files
authored
Control Freak 5V Rail system controller and DT updates (#312)
1 parent 8363976 commit 9a620e6

4 files changed

Lines changed: 134 additions & 10 deletions

File tree

app/payload/control_freak/flight-software/sample.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ sample:
44
common:
55
build_only: true
66
platform_allow:
7-
- native_sim
87
- control_freak
98
tests:
109
control_freak.flight.default: {}
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
#include "5v_ctrl.h"
2+
3+
#include <initializer_list>
4+
#include <tuple>
5+
#include <zephyr/drivers/gpio.h>
6+
#include <zephyr/logging/log.h>
7+
LOG_MODULE_REGISTER(rail5v);
8+
9+
static const struct gpio_dt_spec ldo_en = GPIO_DT_SPEC_GET(DT_ALIAS(ldo5v), gpios);
10+
11+
static const struct gpio_dt_spec servo_en = GPIO_DT_SPEC_GET(DT_NODELABEL(servo_enable), gpios);
12+
13+
static const struct gpio_dt_spec pump_enable = GPIO_DT_SPEC_GET(DT_NODELABEL(pump_enable), gpios);
14+
15+
const struct gpio_dt_spec buzzer = GPIO_DT_SPEC_GET(DT_ALIAS(buzz), gpios);
16+
17+
// Prepares the GPIO
18+
int five_volt_rail_init() {
19+
using Pair = std::tuple<const struct gpio_dt_spec *, const char *>;
20+
constexpr Pair pairs[4] = {
21+
Pair{&ldo_en, "ldo5v"},
22+
Pair{&servo_en, "servo"},
23+
Pair{&pump_enable, "pump"},
24+
Pair{&buzzer, "buzzer"},
25+
};
26+
for (auto [gpio, name] : pairs) {
27+
if (!gpio_is_ready_dt(gpio)) {
28+
LOG_WRN("No %s pin :(", name);
29+
}
30+
int ret = gpio_pin_configure_dt(gpio, GPIO_OUTPUT_INACTIVE);
31+
if (ret < 0) {
32+
LOG_WRN("Failed to conf %s pin :(", name);
33+
return ret;
34+
}
35+
}
36+
LOG_INF("5V Rail all good");
37+
return 0;
38+
}
39+
40+
static bool state[(int) FiveVoltItem::NumItems] = {false};
41+
42+
static int set_ldo_accordingly() { return gpio_pin_set_dt(&ldo_en, (state[0] || state[1] || state[2])); }
43+
static int set_item(FiveVoltItem item, bool set) {
44+
if (item >= FiveVoltItem::NumItems) {
45+
LOG_WRN("Invalid 5v rail item");
46+
return -ENODEV;
47+
}
48+
state[(int) item] = set;
49+
if (item == FiveVoltItem::Buzzer) {
50+
return gpio_pin_set_dt(&buzzer, set);
51+
} else if (item == FiveVoltItem::Servos) {
52+
return gpio_pin_set_dt(&servo_en, set);
53+
} else {
54+
return gpio_pin_set_dt(&pump_enable, set);
55+
}
56+
return 0;
57+
}
58+
// CONFIG_PM who?
59+
int rail_item_enable(FiveVoltItem item) { return rail_item_set(item, true); }
60+
61+
int rail_item_disable(FiveVoltItem item) { return rail_item_set(item, false); }
62+
63+
int rail_item_set(FiveVoltItem item, bool set) {
64+
set_item(item, set);
65+
return set_ldo_accordingly();
66+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
#pragma once
2+
#include <cstdint>
3+
4+
enum class FiveVoltItem : uint8_t { Buzzer = 0, Servos = 1, Pump = 2, NumItems = 3 };
5+
/*
6+
5V Bus looks like this
7+
8+
+-- Servo Logic Shifter Enable---Servo Logic Shifters
9+
VBAT---LDO Enable---+-- Buzzer Enable ---Buzzer
10+
+-- Pump Enable ---Pump
11+
12+
The LDO draws a fair amount of current when running even when things downstream are off
13+
This file allows controlling individual elements and automatically handling the LDO Enable pin
14+
*/
15+
16+
// Prepares the GPIO
17+
int five_volt_rail_init();
18+
19+
// enable a zone (if everything else is off, turn the rail on)
20+
int rail_item_enable(FiveVoltItem item);
21+
22+
// disable a zone (if everything else is off, turn the rail off)
23+
int rail_item_disable(FiveVoltItem item);
24+
25+
// change the state of a zone
26+
int rail_item_set(FiveVoltItem item, bool state);

boards/arm/control_freak/control_freak.dts

Lines changed: 42 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,16 +21,25 @@
2121
buzz = &buzzer;
2222
ldo5v = &ldo5v_enable;
2323
gnss = &gnss;
24+
2425
gpsreset = &gps_reset;
2526
gpssafeboot = &gps_timepulse;
27+
2628
lora0 = &lora;
2729
servo1 = &servo1;
2830
servo2 = &servo2;
2931
servo3 = &servo3;
32+
3033
radioreset = &radioreset;
3134

3235
imu = &lsm6dsl;
3336
barom = &bmp390;
37+
38+
inapump = &ina260_pump;
39+
inaservo = &ina260_servo;
40+
41+
groundcam = &cam1_enable;
42+
antennacam = &cam2_enable;
3443
};
3544

3645
servos: servos{
@@ -42,12 +51,12 @@
4251
servo1: servo1 {
4352
label = "Servo 1 PWM";
4453
// &gpioc 6 GPIO_ACTIVE_HIGH
45-
pwms = <&pwm3 1 PWM_MSEC(3) PWM_POLARITY_NORMAL>;
54+
pwms = <&pwm3 2 PWM_MSEC(3) PWM_POLARITY_NORMAL>;
4655
};
4756
servo2: servo2 {
4857
label = "Servo 2 PWM";
4958
// &gpioc 7 GPIO_ACTIVE_HIGH
50-
pwms = <&pwm3 2 PWM_MSEC(3) PWM_POLARITY_NORMAL>;
59+
pwms = <&pwm3 1 PWM_MSEC(3) PWM_POLARITY_NORMAL>;
5160
};
5261
servo3: servo3 {
5362
label = "Servo 3 PWM";
@@ -242,10 +251,15 @@
242251
pinctrl-names = "default";
243252
current-speed = <9600>;
244253

254+
245255
gnss: gnss {
246256
// MAX-M10M-00B
247-
compatible = "gnss-nmea-generic";
257+
compatible = "u-blox,m10";
258+
label = "UBLOXM10";
248259
status="okay";
260+
reset-gpios = <&gpioa 11 GPIO_ACTIVE_LOW>;
261+
timepulse-gpios = <&gpioa 12 GPIO_ACTIVE_HIGH>;
262+
// reset-on-boot;
249263
};
250264
};
251265

@@ -255,6 +269,9 @@
255269
status = "okay";
256270
clock-frequency = <I2C_BITRATE_FAST>;
257271

272+
scl-gpios = <&gpiob 6 GPIO_ACTIVE_HIGH>;
273+
sda-gpios = <&gpiob 7 GPIO_ACTIVE_HIGH>;
274+
258275
bmp390: bmp390@77 {
259276
status = "okay";
260277

@@ -349,15 +366,29 @@
349366
#address-cells = <1>;
350367
#size-cells = <1>;
351368
super_fast_partition: fastpartition@0 {
352-
// loop(5s * 100 page/s) + (400s * 10 page/s)
353-
// 4500 pages = 1125 KB
369+
// loop size = 5s
370+
// rest size = 400s
371+
// total 405s
372+
// 1000 acc samp/s = 100 pack/s = 100 page/s
373+
// 405s * 100 page/s = 40500 pages
374+
// 40500 pages = 10125 KB sector round to 10128 KB
354375
label = "superfast-storage";
355-
reg = <0 DT_SIZE_K(1128)>;
376+
reg = <0 DT_SIZE_K(10128)>;
377+
};
378+
super_slow_partition: slowpartition@9e4000{
379+
label = "superslow-storage";
380+
// 1 day (24 hrs) = 86400s
381+
// 1 page / 8 seconds
382+
// 86400s * 1 page/ 8 s = 10800 pages
383+
// 2700 KB
384+
reg = <0x9e4000 DT_SIZE_K(2700)>;
356385
};
357386

358-
external_storage_partition: partition@11a000 {
387+
external_storage_partition: partition@c87000 {
388+
// the rest for littlefs
389+
// 16384 - 2700 - 10128
359390
label = "w25q-storage";
360-
reg = <0x11a000 DT_SIZE_K(15256)>;
391+
reg = <0xc87000 DT_SIZE_K(3556)>;
361392
};
362393
};
363394
};
@@ -370,7 +401,7 @@
370401
status = "okay";
371402
lora: lora@0{
372403
reg = <0>;
373-
spi-max-frequency = <(10 * 1000 * 1000)>;
404+
spi-max-frequency = <(DT_FREQ_M(50))>;
374405
compatible = "semtech,sx1276";
375406

376407
reset-gpios = <&gpioa 4 GPIO_ACTIVE_LOW>;
@@ -397,6 +428,8 @@
397428
};
398429

399430

431+
// fake and untrue, call me when we use mcuboot
432+
400433
// fake and untrue, call me when we use mcuboot
401434
&flash0 {
402435

0 commit comments

Comments
 (0)