Skip to content

Commit

Permalink
Replace unsigned with size_t
Browse files Browse the repository at this point in the history
  • Loading branch information
blazoncek committed Feb 1, 2025
1 parent 00856a9 commit eb14e34
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 30 deletions.
18 changes: 9 additions & 9 deletions wled00/bus_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -389,13 +389,13 @@ uint32_t IRAM_ATTR BusDigital::getPixelColor(unsigned pix) const {
}
}

unsigned BusDigital::getPins(uint8_t* pinArray) const {
size_t BusDigital::getPins(uint8_t* pinArray) const {
unsigned numPins = is2Pin(_type) + 1;
if (pinArray) for (unsigned i = 0; i < numPins; i++) pinArray[i] = _pins[i];
return numPins;
}

unsigned BusDigital::getBusSize() const {
size_t BusDigital::getBusSize() const {
return sizeof(BusDigital) + (isOk() ? PolyBus::getDataSize(_busPtr, _iType) + (_data ? _len * getNumberOfChannels() : 0) : 0);
}

Expand Down Expand Up @@ -585,7 +585,7 @@ void BusPwm::show() {
// if _needsRefresh is true (UI hack) we are using dithering (credit @dedehai & @zalatnaicsongor)
// https://github.com/Aircoookie/WLED/pull/4115 and https://github.com/zalatnaicsongor/WLED/pull/1)
const bool dithering = _needsRefresh; // avoid working with bitfield
const unsigned numPins = getPins();
const size_t numPins = getPins();
const unsigned maxBri = (1<<_depth); // possible values: 16384 (14), 8192 (13), 4096 (12), 2048 (11), 1024 (10), 512 (9) and 256 (8)
[[maybe_unused]] const unsigned bitShift = dithering * 4; // if dithering, _depth is 12 bit but LEDC channel is set to 8 bit (using 4 fractional bits)

Expand Down Expand Up @@ -636,7 +636,7 @@ void BusPwm::show() {
}
}

unsigned BusPwm::getPins(uint8_t* pinArray) const {
size_t BusPwm::getPins(uint8_t* pinArray) const {
if (!_valid) return 0;
unsigned numPins = numPWMPins(_type);
if (pinArray) for (unsigned i = 0; i < numPins; i++) pinArray[i] = _pins[i];
Expand All @@ -656,7 +656,7 @@ std::vector<LEDType> BusPwm::getLEDTypes() {
}

void BusPwm::deallocatePins() {
unsigned numPins = getPins();
size_t numPins = getPins();
for (unsigned i = 0; i < numPins; i++) {
PinManager::deallocatePin(_pins[i], PinOwner::BusPwm);
if (!PinManager::isPinOk(_pins[i])) continue;
Expand Down Expand Up @@ -712,7 +712,7 @@ void BusOnOff::show() {
digitalWrite(_pin, _reversed ? !(bool)_data[0] : (bool)_data[0]);
}

unsigned BusOnOff::getPins(uint8_t* pinArray) const {
size_t BusOnOff::getPins(uint8_t* pinArray) const {
if (!_valid) return 0;
if (pinArray) pinArray[0] = _pin;
return 1;
Expand Down Expand Up @@ -776,7 +776,7 @@ void BusNetwork::show() {
_broadcastLock = false;
}

unsigned BusNetwork::getPins(uint8_t* pinArray) const {
size_t BusNetwork::getPins(uint8_t* pinArray) const {
if (pinArray) for (unsigned i = 0; i < 4; i++) pinArray[i] = _client[i];
return 4;
}
Expand Down Expand Up @@ -805,7 +805,7 @@ void BusNetwork::cleanup() {


//utility to get the approx. memory usage of a given BusConfig
unsigned BusConfig::memUsage(unsigned nr) const {
size_t BusConfig::memUsage(unsigned nr) const {
if (Bus::isVirtual(type)) {
return sizeof(BusNetwork) + (count * Bus::getNumberOfChannels(type));
} else if (Bus::isDigital(type)) {
Expand All @@ -818,7 +818,7 @@ unsigned BusConfig::memUsage(unsigned nr) const {
}


unsigned BusManager::memUsage() {
size_t BusManager::memUsage() {
// when ESP32, S2 & S3 use parallel I2S only the largest bus determines the total memory requirements for back buffers
// front buffers are always allocated per bus
unsigned size = 0;
Expand Down
41 changes: 20 additions & 21 deletions wled00/bus_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,6 @@
#include "pin_manager.h"
#include <vector>
#include <memory>
#include <bits/unique_ptr.h>

#if __cplusplus >= 201402L
using std::make_unique;
Expand Down Expand Up @@ -126,15 +125,15 @@ class Bus {
virtual void setBrightness(uint8_t b) { _bri = b; };
virtual void setColorOrder(uint8_t co) {}
virtual uint32_t getPixelColor(unsigned pix) const { return 0; }
virtual unsigned getPins(uint8_t* pinArray = nullptr) const { return 0; }
virtual size_t getPins(uint8_t* pinArray = nullptr) const { return 0; }
virtual uint16_t getLength() const { return isOk() ? _len : 0; }
virtual uint8_t getColorOrder() const { return COL_ORDER_RGB; }
virtual unsigned skippedLeds() const { return 0; }
virtual uint16_t getFrequency() const { return 0U; }
virtual uint16_t getLEDCurrent() const { return 0; }
virtual uint16_t getUsedCurrent() const { return 0; }
virtual uint16_t getMaxCurrent() const { return 0; }
virtual unsigned getBusSize() const { return sizeof(Bus); }
virtual size_t getBusSize() const { return sizeof(Bus); }

inline bool hasRGB() const { return _hasRgb; }
inline bool hasWhite() const { return _hasWhite; }
Expand All @@ -150,7 +149,7 @@ class Bus {
inline void setStart(uint16_t start) { _start = start; }
inline void setAutoWhiteMode(uint8_t m) { if (m < 5) _autoWhiteMode = m; }
inline uint8_t getAutoWhiteMode() const { return _autoWhiteMode; }
inline unsigned getNumberOfChannels() const { return hasWhite() + 3*hasRGB() + hasCCT(); }
inline size_t getNumberOfChannels() const { return hasWhite() + 3*hasRGB() + hasCCT(); }
inline uint16_t getStart() const { return _start; }
inline uint8_t getType() const { return _type; }
inline bool isOk() const { return _valid; }
Expand All @@ -159,8 +158,8 @@ class Bus {
inline bool containsPixel(uint16_t pix) const { return pix >= _start && pix < _start + _len; }

static inline std::vector<LEDType> getLEDTypes() { return {{TYPE_NONE, "", PSTR("None")}}; } // not used. just for reference for derived classes
static constexpr unsigned getNumberOfPins(uint8_t type) { return isVirtual(type) ? 4 : isPWM(type) ? numPWMPins(type) : is2Pin(type) + 1; } // credit @PaoloTK
static constexpr unsigned getNumberOfChannels(uint8_t type) { return hasWhite(type) + 3*hasRGB(type) + hasCCT(type); }
static constexpr size_t getNumberOfPins(uint8_t type) { return isVirtual(type) ? 4 : isPWM(type) ? numPWMPins(type) : is2Pin(type) + 1; } // credit @PaoloTK
static constexpr size_t getNumberOfChannels(uint8_t type) { return hasWhite(type) + 3*hasRGB(type) + hasCCT(type); }
static constexpr bool hasRGB(uint8_t type) {
return !((type >= TYPE_WS2812_1CH && type <= TYPE_WS2812_WWA) || type == TYPE_ANALOG_1CH || type == TYPE_ANALOG_2CH || type == TYPE_ONOFF);
}
Expand Down Expand Up @@ -248,13 +247,13 @@ class BusDigital : public Bus {
void setColorOrder(uint8_t colorOrder) override;
[[gnu::hot]] uint32_t getPixelColor(unsigned pix) const override;
uint8_t getColorOrder() const override { return _colorOrder; }
unsigned getPins(uint8_t* pinArray = nullptr) const override;
size_t getPins(uint8_t* pinArray = nullptr) const override;
unsigned skippedLeds() const override { return _skip; }
uint16_t getFrequency() const override { return _frequencykHz; }
uint16_t getLEDCurrent() const override { return _milliAmpsPerLed; }
uint16_t getUsedCurrent() const override { return _milliAmpsTotal; }
uint16_t getMaxCurrent() const override { return _milliAmpsMax; }
unsigned getBusSize() const override;
size_t getBusSize() const override;
void begin() override;
void cleanup();

Expand Down Expand Up @@ -294,9 +293,9 @@ class BusPwm : public Bus {

void setPixelColor(unsigned pix, uint32_t c) override;
uint32_t getPixelColor(unsigned pix) const override; //does no index check
unsigned getPins(uint8_t* pinArray = nullptr) const override;
size_t getPins(uint8_t* pinArray = nullptr) const override;
uint16_t getFrequency() const override { return _frequency; }
unsigned getBusSize() const override { return sizeof(BusPwm); }
size_t getBusSize() const override { return sizeof(BusPwm); }
void show() override;
inline void cleanup() { deallocatePins(); _data = nullptr; }

Expand All @@ -322,8 +321,8 @@ class BusOnOff : public Bus {

void setPixelColor(unsigned pix, uint32_t c) override;
uint32_t getPixelColor(unsigned pix) const override;
unsigned getPins(uint8_t* pinArray) const override;
unsigned getBusSize() const override { return sizeof(BusOnOff); }
size_t getPins(uint8_t* pinArray) const override;
size_t getBusSize() const override { return sizeof(BusOnOff); }
void show() override;
inline void cleanup() { PinManager::deallocatePin(_pin, PinOwner::BusOnOff); _data = nullptr; }

Expand All @@ -343,10 +342,10 @@ class BusNetwork : public Bus {
bool canShow() const override { return !_broadcastLock; } // this should be a return value from UDP routine if it is still sending data out
[[gnu::hot]] void setPixelColor(unsigned pix, uint32_t c) override;
[[gnu::hot]] uint32_t getPixelColor(unsigned pix) const override;
unsigned getPins(uint8_t* pinArray = nullptr) const override;
unsigned getBusSize() const override { return sizeof(BusNetwork) + (isOk() ? _len * _UDPchannels : 0); }
void show() override;
void cleanup();
size_t getPins(uint8_t* pinArray = nullptr) const override;
size_t getBusSize() const override { return sizeof(BusNetwork) + (isOk() ? _len * _UDPchannels : 0); }
void show() override;
void cleanup();

static std::vector<LEDType> getLEDTypes();

Expand Down Expand Up @@ -414,7 +413,7 @@ struct BusConfig {
return true;
}

unsigned memUsage(unsigned nr = 0) const;
size_t memUsage(unsigned nr = 0) const;
};


Expand All @@ -438,13 +437,13 @@ namespace BusManager {
#ifdef ESP32_DATA_IDLE_HIGH
void esp32RMTInvertIdle() ;
#endif
inline uint8_t getNumVirtualBusses() {
int j = 0;
inline size_t getNumVirtualBusses() {
size_t j = 0;
for (const auto &bus : busses) j += bus->isVirtual();
return j;
}

unsigned memUsage();
size_t memUsage();
inline uint16_t currentMilliamps() { return _gMilliAmpsUsed + MA_FOR_ESP; }
//inline uint16_t ablMilliampsMax() { unsigned sum = 0; for (auto &bus : busses) sum += bus->getMaxCurrent(); return sum; }
inline uint16_t ablMilliampsMax() { return _gMilliAmpsMax; } // used for compatibility reasons (and enabling virtual global ABL)
Expand All @@ -471,7 +470,7 @@ namespace BusManager {
void setSegmentCCT(int16_t cct, bool allowWBCorrection = false);
inline int16_t getSegmentCCT() { return Bus::getCCT(); }
inline Bus* getBus(size_t busNr) { return busNr < busses.size() ? busses[busNr].get() : nullptr; }
inline uint8_t getNumBusses() { return busses.size(); }
inline size_t getNumBusses() { return busses.size(); }

//semi-duplicate of strip.getLengthTotal() (though that just returns strip._length, calculated in finalizeInit())
inline uint16_t getTotalLength(bool onlyPhysical = false) {
Expand Down

0 comments on commit eb14e34

Please sign in to comment.