bool ChipInputPin::get() const
{
    const auto decodedPin = decodePin(pin_);
    auto& port = *decodedPin.first;
    const auto pinNumber = decodedPin.second;
    return static_cast<bool>(port.IDR & (1 << pinNumber)) != inverted_;
}
void ChipOutputPin::set(const bool state)
{
	const auto decodedPin = decodePin(pin_);
	auto& port = *decodedPin.first;
	const auto pinNumber = decodedPin.second;
	port.BSRR = 1 << (pinNumber + (state == false ? 16 : 0));
}
bool ChipOutputPin::get() const
{
	const auto decodedPin = decodePin(pin_);
	auto& port = *decodedPin.first;
	const auto pinNumber = decodedPin.second;
	return (port.IDR & (1 << pinNumber)) != 0;
}
void ChipOutputPin::set(const bool state)
{
	const auto decodedPin = decodePin(pin_);
	auto& port = *decodedPin.first;
	const auto pinNumber = decodedPin.second;
	(state == inverted_ ? port.BRR : port.BSRR) = 1 << pinNumber;
}
Example #5
0
void configurePin(const Pin pin, const PinMode mode, const bool openDrain, const PinOutputSpeed outputSpeed,
		const PinPull pull, const PinAlternateFunction alternateFunction, const bool initialState)
{
	const auto decodedPin = decodePin(pin);
	auto& port = *decodedPin.first;
	const auto pinNumber = decodedPin.second;
	auto& afr = port.AFR[pinNumber / 8];
	const auto moderInvertedMask = ~(GPIO_MODER_mask << (pinNumber * 2));
	const auto shiftedMode = static_cast<uint32_t>(mode) << (pinNumber * 2);
	const auto otyperInvertedMask = ~(GPIO_OTYPER_mask << pinNumber);
	const auto shiftedOpenDrain = static_cast<uint32_t>(openDrain) << pinNumber;
	const auto ospeedrInvertedMask = ~(GPIO_OSPEEDR_mask << (pinNumber * 2));
	const auto shiftedOutputSpeed = static_cast<uint32_t>(outputSpeed) << (pinNumber * 2);
	const auto pupdrInvertedMask = ~(GPIO_PUPDR_mask << (pinNumber * 2));
	const auto shiftedPull = static_cast<uint32_t>(pull) << (pinNumber * 2);
	const auto afrInvertedMask = ~(GPIO_AFRx_mask << ((pinNumber * 4) % 32));
	const auto shiftedAlternateFunction = static_cast<uint32_t>(alternateFunction) << ((pinNumber * 4) % 32);

	port.BSRR = 1 << (pinNumber + (initialState == false ? 16 : 0));

	architecture::InterruptMaskingLock interruptMaskingLock;

	port.MODER = (port.MODER & moderInvertedMask) | shiftedMode;
	port.OTYPER = (port.OTYPER & otyperInvertedMask) | shiftedOpenDrain;
	port.OSPEEDR = (port.OSPEEDR & ospeedrInvertedMask) | shiftedOutputSpeed;
	port.PUPDR = (port.PUPDR & pupdrInvertedMask) | shiftedPull;
	afr = (afr & afrInvertedMask) | shiftedAlternateFunction;
}
Example #6
0
void configurePin(const Pin pin, const PinConfiguration configuration, const bool initialState)
{
	const auto decodedPin = decodePin(pin);
	auto& port = *decodedPin.first;
	const auto pinNumber = decodedPin.second;
	auto& cr = pinNumber < 8 ? port.CRL : port.CRH;
	const auto invertedMask = ~((GPIO_CRL_CNF0 | GPIO_CRL_MODE0) << ((pinNumber * 4) % 32));
	const auto configurationValue = static_cast<uint32_t>(configuration) << ((pinNumber * 4) % 32);

	(initialState == false ? port.BRR : port.BSRR) = 1 << pinNumber;

	architecture::InterruptMaskingLock interruptMaskingLock;

	cr = (cr & invertedMask) | configurationValue;
}