при отключени шим добавила проверку, работает ли на этом конкретном пине сейчас таймер. если работает, тогда выключаем его и пин настраиваем на вход
This commit is contained in:
parent
39ee35f88d
commit
e548e7e486
@ -148,7 +148,7 @@ It is recommended to turn off the timer in the following order:
|
|||||||
*/
|
*/
|
||||||
void analogWriteStop(uint32_t PinNumber)
|
void analogWriteStop(uint32_t PinNumber)
|
||||||
{
|
{
|
||||||
if (pwmIsInited > 0)
|
if ((pwmIsInited > 0) && (digitalPinPwmIsOn(PinNumber)))
|
||||||
{
|
{
|
||||||
// load the timer address and channel number corresponding to the specified pin
|
// load the timer address and channel number corresponding to the specified pin
|
||||||
htimer32.Instance = pwmPinToTimer(PinNumber);
|
htimer32.Instance = pwmPinToTimer(PinNumber);
|
||||||
@ -164,6 +164,10 @@ void analogWriteStop(uint32_t PinNumber)
|
|||||||
HAL_Timer32_Stop(&htimer32);
|
HAL_Timer32_Stop(&htimer32);
|
||||||
HAL_Timer32_Deinit(&htimer32);
|
HAL_Timer32_Deinit(&htimer32);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// config pin as input when timer channel off
|
||||||
|
HAL_GPIO_PinConfig(digitalPinToPort(PinNumber), digitalPinToBitMask(PinNumber),
|
||||||
|
HAL_GPIO_MODE_GPIO_INPUT, HAL_GPIO_PULL_NONE, HAL_GPIO_DS_2MA);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@ -76,6 +76,7 @@ uint32_t analogInputToChannelNumber(uint32_t PinNumber);
|
|||||||
|
|
||||||
// PWM
|
// PWM
|
||||||
bool digitalPinHasPWM(uint8_t p);
|
bool digitalPinHasPWM(uint8_t p);
|
||||||
|
bool digitalPinPwmIsOn(uint8_t digitalPin); // use only if digitalPinHasPWM() == true
|
||||||
// determines which timer the pin belongs to
|
// determines which timer the pin belongs to
|
||||||
TIMER32_TypeDef* pwmPinToTimer(uint32_t digPinNumber);
|
TIMER32_TypeDef* pwmPinToTimer(uint32_t digPinNumber);
|
||||||
// determines which timer channel the pin belongs to
|
// determines which timer channel the pin belongs to
|
||||||
|
|||||||
@ -107,6 +107,10 @@ volatile uint32_t* portInputRegister(GPIO_TypeDef* GPIO_x)
|
|||||||
return &GPIO_x->STATE;
|
return &GPIO_x->STATE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// return config of pin with pinShift(0...16) in portReg (config, pupd, ds for ports 0...2)
|
||||||
|
#define PIN_PAD_CONFIG(portReg, pinShift) ((PAD_CONFIG->portReg >> (pinShift<<1)) & 0b11)
|
||||||
|
|
||||||
|
|
||||||
// ---------------------- ADC ---------------------- //
|
// ---------------------- ADC ---------------------- //
|
||||||
// determines the ADC channel number by the board pin number
|
// determines the ADC channel number by the board pin number
|
||||||
uint32_t analogInputToChannelNumber(uint32_t PinNumber)
|
uint32_t analogInputToChannelNumber(uint32_t PinNumber)
|
||||||
@ -142,6 +146,38 @@ uint32_t analogInputToChannelNumber(uint32_t PinNumber)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// ---------------------- PWM ---------------------- //
|
// ---------------------- PWM ---------------------- //
|
||||||
|
// use only if digitalPinHasPWM() == true
|
||||||
|
#define PWM_PIN_TO_PORT_NUMBER(pin) (((pin==10)||(pin==11)) ? 1:0)
|
||||||
|
// use only if digitalPinHasPWM() == true
|
||||||
|
static inline uint8_t pwmPinToGpioPinShift(uint8_t digitalPin)
|
||||||
|
{
|
||||||
|
if (digitalPin == 3)
|
||||||
|
return 0;
|
||||||
|
else if ((digitalPin == 5) || (digitalPin == 11))
|
||||||
|
return 1;
|
||||||
|
else if (digitalPin == 6)
|
||||||
|
return 2;
|
||||||
|
else // pins 9 10
|
||||||
|
return 3;
|
||||||
|
}
|
||||||
|
// use only if digitalPinHasPWM() == true
|
||||||
|
// return true if digitalPin configured as pwm
|
||||||
|
bool digitalPinPwmIsOn(uint8_t digitalPin)
|
||||||
|
{
|
||||||
|
uint8_t config = 0;
|
||||||
|
uint8_t pinShift = pwmPinToGpioPinShift(digitalPin);
|
||||||
|
|
||||||
|
if (PWM_PIN_TO_PORT_NUMBER(digitalPin) == 0)
|
||||||
|
config = PIN_PAD_CONFIG(PORT_0_CFG, pinShift);
|
||||||
|
else
|
||||||
|
config = PIN_PAD_CONFIG(PORT_1_CFG, pinShift);
|
||||||
|
|
||||||
|
if (config == 2)
|
||||||
|
return true;
|
||||||
|
else
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
bool digitalPinHasPWM(uint8_t p)
|
bool digitalPinHasPWM(uint8_t p)
|
||||||
{
|
{
|
||||||
bool ret = false;
|
bool ret = false;
|
||||||
@ -232,7 +268,6 @@ int8_t digitalPinToInterrupt(uint32_t digPinNumber)
|
|||||||
// pins shift in registers
|
// pins shift in registers
|
||||||
#define PIN_3_SHIFT 3
|
#define PIN_3_SHIFT 3
|
||||||
#define PIN_4_SHIFT 4
|
#define PIN_4_SHIFT 4
|
||||||
#define PORT1_GET_PAD_CONFIG(pinShift) ((PAD_CONFIG->PORT_1_CFG >> (pinShift<<1)) & 0b11)
|
|
||||||
#define PORT1_GET_PAD_PUPD(pinShift) ((PAD_CONFIG->PORT_1_PUPD >> (pinShift<<1)) & 0b11)
|
#define PORT1_GET_PAD_PUPD(pinShift) ((PAD_CONFIG->PORT_1_PUPD >> (pinShift<<1)) & 0b11)
|
||||||
#define PORT1_GET_GPIO_STATE(pinShift) ((GPIO_1->OUTPUT_ >> pinShift) & 0b1)
|
#define PORT1_GET_GPIO_STATE(pinShift) ((GPIO_1->OUTPUT_ >> pinShift) & 0b1)
|
||||||
|
|
||||||
@ -242,7 +277,7 @@ void spi_onBegin(void)
|
|||||||
// because spi needs pin 1.3 for correct work
|
// because spi needs pin 1.3 for correct work
|
||||||
|
|
||||||
// replace config from 1.3 to 1.4
|
// replace config from 1.3 to 1.4
|
||||||
uint8_t config = PORT1_GET_PAD_CONFIG(PIN_3_SHIFT);
|
uint8_t config = PIN_PAD_CONFIG(PORT_1_CFG, PIN_3_SHIFT);
|
||||||
if (config == 0) // common gpio
|
if (config == 0) // common gpio
|
||||||
{
|
{
|
||||||
// get info from pin gpio1.3 and set config to gpio1.4
|
// get info from pin gpio1.3 and set config to gpio1.4
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user