forked from tbnobody/OpenDTU
-
Notifications
You must be signed in to change notification settings - Fork 67
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor serial port manager: hand out UARTs FCFS
get rid of particular compile-time designations by UART index. just hand out the next free index of hardware UARTs, or indicate that none is available any more. use names as keys to register and free UARTs.
- Loading branch information
1 parent
5a1c3af
commit be41e6b
Showing
10 changed files
with
97 additions
and
125 deletions.
There are no files selected for viewing
This file contains 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 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 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 |
---|---|---|
@@ -1,29 +1,21 @@ | ||
// SPDX-License-Identifier: GPL-2.0-or-later | ||
#pragma once | ||
|
||
#include <map> | ||
#include <array> | ||
#include <optional> | ||
#include <string> | ||
|
||
class SerialPortManagerClass { | ||
public: | ||
void init(); | ||
bool allocateMpptPort(uint8_t port); | ||
bool allocateBatteryPort(uint8_t port); | ||
void invalidateBatteryPort(); | ||
void invalidateMpptPorts(); | ||
|
||
private: | ||
enum class Owner { | ||
Console, | ||
Battery, | ||
MPPT | ||
}; | ||
|
||
std::map<uint8_t, Owner> allocatedPorts; | ||
std::optional<uint8_t> allocatePort(std::string const& owner); | ||
void freePort(std::string const& owner); | ||
|
||
bool allocatePort(uint8_t port, Owner owner); | ||
void invalidate(Owner owner); | ||
|
||
static const char* print(Owner owner); | ||
private: | ||
// the amount of hardare UARTs available on supported ESP32 chips | ||
static size_t constexpr _num_controllers = 3; | ||
std::array<std::string, _num_controllers> _ports = { "" }; | ||
}; | ||
|
||
extern SerialPortManagerClass SerialPortManager; |
This file contains 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 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 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 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 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
Oops, something went wrong.