Files
MinumelArmMCU/AdafruitPWMBoard.hpp
T

30 lines
1.2 KiB
C++
Raw Normal View History

2025-12-14 15:02:55 +01:00
#pragma once
#include <Arduino.h>
#include <Adafruit_PWMServoDriver.h>
// Wrapper class to prevent duplicate motor port assignments
// This board can drive up to 16 motors
class AdafruitPWMBoard
{
public:
AdafruitPWMBoard(const uint8_t addr, const uint8_t pwmFreq);
2025-12-14 19:28:41 +01:00
AdafruitPWMBoard(const AdafruitPWMBoard& other) = delete;
AdafruitPWMBoard(AdafruitPWMBoard&&) noexcept = default;
2025-12-14 15:02:55 +01:00
Adafruit_PWMServoDriver& get() noexcept { return hwif; };
const Adafruit_PWMServoDriver& get() const noexcept { return hwif; };
bool isGood() const noexcept { return good; }
bool isMotorSlotOccupied(const uint8_t motorIndex) const noexcept;
// Returns false if the slot is already occupied or index is out of range
bool occupyMotorSlot(const uint8_t motorIndex) noexcept;
// Returns false if the slot is already free or index is out of range
bool releaseMotorSlot(const uint8_t motorIndex) noexcept;
private:
// No release needed, hardware interface does not expose any method for release
Adafruit_PWMServoDriver hwif;
bool good;
uint16_t occupiedMotorSlots = 0;
};