Bus progress

This commit is contained in:
cschwinne
2020-12-07 01:39:42 +01:00
parent c930d6ddc0
commit 854501385e
9 changed files with 709 additions and 308 deletions

View File

@@ -51,4 +51,42 @@ bool PinManagerClass::isPinOk(byte gpio, bool output)
#endif
return false;
}
}
#ifdef ARDUINO_ARCH_ESP32
byte PinManagerClass::allocateLedc(byte channels)
{
if (channels > 16 || channels == 0) return 255;
byte ca = 0;
for (byte i = 0; i < 16; i++) {
byte by = i >> 3;
byte bi = i - 8*by;
if (bitRead(ledcAlloc[by], bi)) { //found occupied pin
ca = 0;
} else {
ca++;
}
if (ca >= channels) { //enough free channels
byte in = (i + 1) - ca;
for (byte j = 0; j < ca; j++) {
byte b = in + j;
byte by = b >> 3;
byte bi = b - 8*by;
bitWrite(ledcAlloc[by], bi, true);
}
return in;
}
}
return 255; //not enough consecutive free LEDC channels
}
void PinManagerClass::deallocateLedc(byte pos, byte channels)
{
for (byte j = pos; j < pos + channels; j++) {
if (j > 16) return;
byte by = j >> 3;
byte bi = j - 8*by;
bitWrite(ledcAlloc[by], bi, false);
}
}
#endif