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.
22 lines
530 B
C++
22 lines
530 B
C++
// SPDX-License-Identifier: GPL-2.0-or-later
|
|
#pragma once
|
|
|
|
#include <array>
|
|
#include <optional>
|
|
#include <string>
|
|
|
|
class SerialPortManagerClass {
|
|
public:
|
|
void init();
|
|
|
|
std::optional<uint8_t> allocatePort(std::string const& owner);
|
|
void freePort(std::string const& 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;
|