Files
MinumelArmMCU/AdafruitPWMBoard.hpp
T
2025-12-14 15:02:55 +01:00

28 lines
1.0 KiB
C++
Executable File

#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);
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;
};