-
Notifications
You must be signed in to change notification settings - Fork 1
5V Rail system controller and DT updates #312
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
Merged
Merged
Changes from 2 commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
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
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,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); | ||
| 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(); | ||
| } | ||
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,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); |
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
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.