добавлена проверка - не превышает ли номер вывода из аргумента функции общее кол-во выводов

This commit is contained in:
klassents committed 2025-02-21 15:43:13 +07:00
1 parent 5b2e2eb1d5
commit fbaa4b931a
11 files changed
+171 -96

No files matched your search

+12
View File
@@ -79,6 +79,12 @@ static void calcFrequencyParams(FrequencyParams_t* params, unsigned int newFrequ
// start tone with frequency (in hertz) and duration (in milliseconds)
void tone(uint8_t pin, unsigned int frequency, unsigned long duration)
{
if ((pin>=pinCommonQty()))
{
ErrorMsgHandler("tone(): pin number exceeds the total number of pins");
return;
}
if (!timerIsOn) // if tone is not generated at the moment
{
// calculate the parameters necessary to ensure a given frequency if the frequency has changed
@@ -123,6 +129,12 @@ void tone(uint8_t pin, unsigned int frequency, unsigned long duration)
// stop tone
void noTone(uint8_t pin)
{
if ((pin>=pinCommonQty()))
{
ErrorMsgHandler("noTone(): pin number exceeds the total number of pins");
return;
}
if (timerIsOn)
{
// pin to 0
+1 -1
View File
@@ -170,7 +170,7 @@ It is recommended to turn off the timer in the following order:
*/
void analogWriteStop(uint32_t PinNumber)
{
if ((pwmIsInited > 0) && (digitalPinPwmIsOn(PinNumber)))
if (digitalPinHasPWM(PinNumber) && (pwmIsInited > 0) && digitalPinPwmIsOn(PinNumber))
{
// load the timer address and channel number corresponding to the specified pin
htimer32.Instance = pwmPinToTimer(PinNumber);
+7
View File
@@ -69,8 +69,15 @@ void pinMode(uint32_t PinNumber, uint32_t PinMode)
void fastPinMode(uint32_t PinNumber, uint32_t PinMode)
{
if ((PinNumber>=pinCommonQty()))
{
ErrorMsgHandler("fastPinMode(): pin number exceeds the total number of pins");
return;
}
GPIO_TypeDef* port = digitalPinToPort(PinNumber);
HAL_PinsTypeDef pinMask = digitalPinToBitMask(PinNumber);
// set direction
if (PinMode == OUTPUT)
GPIO_OUTPUT_MODE_PIN(port, pinMask);