allocateChipSelectPin method
Check that the pin can be used for chip select with the specified controller and return the chip select. Throw an exception if the pin has already been allocated or if the controller chip select combination is invalid. This should be called by subclasses not clients.
Implementation
int allocateChipSelectPin(int controller, int chipSelectPin) {
if (_allocatedChipSelectPins.contains(chipSelectPin)) {
throw SpiException('Already allocated', controller, chipSelectPin);
}
var chipSelect = -1;
const chipSelectIndexes = [
/* controller 0 */ [24, 26],
/* controller 1 */ // [12, 11, 36], not supported
];
if (controller >= 0 && controller < chipSelectIndexes.length) {
chipSelect = chipSelectIndexes[controller].indexOf(chipSelectPin);
}
if (chipSelect == -1) {
throw SpiException('invalid controller chip select combination',
controller, chipSelectPin);
}
_allocatedChipSelectPins.add(chipSelectPin);
return chipSelect;
}