заменила функции в spi.begin, spi.end. работа проверена
This commit is contained in:
parent
fec81e89e7
commit
4ecc7f948b
@ -62,7 +62,8 @@ uint8_t SPIClass::interruptMask = 0;
|
|||||||
|
|
||||||
void SPIClass::begin()
|
void SPIClass::begin()
|
||||||
{
|
{
|
||||||
spiElbear_prepareBegin();
|
spi_onBegin();
|
||||||
|
|
||||||
spiInUse = true;
|
spiInUse = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -73,36 +74,14 @@ void SPIClass::end()
|
|||||||
// turn off spi
|
// turn off spi
|
||||||
HAL_SPI_Disable(&hspi);
|
HAL_SPI_Disable(&hspi);
|
||||||
|
|
||||||
// // deinit spi gpio pins
|
// deinit spi gpio pins
|
||||||
// if (hspi.Instance == SPI_1) // only spi1 is using in currunt version
|
if (hspi.Instance == SPI_1) // only spi1 is using in currunt version
|
||||||
// {
|
{
|
||||||
// HAL_GPIO_PinConfig(GPIO_1, (HAL_PinsTypeDef)(GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_2),
|
HAL_GPIO_PinConfig(GPIO_1, (HAL_PinsTypeDef)(GPIO_PIN_0 | GPIO_PIN_1 | GPIO_PIN_2),
|
||||||
// HAL_GPIO_MODE_GPIO_INPUT, HAL_GPIO_PULL_NONE, HAL_GPIO_DS_2MA);
|
HAL_GPIO_MODE_GPIO_INPUT, HAL_GPIO_PULL_NONE, HAL_GPIO_DS_2MA);
|
||||||
// }
|
}
|
||||||
|
|
||||||
// // return D10 with common gpio config to pin 1.3
|
spi_onEnd();
|
||||||
// PAD_CONFIG->PORT_1_CFG &= (~(0b11<<(2*PIN_1_3_GPIO_S))); // set config to 0 - common gpio mode
|
|
||||||
|
|
||||||
// // pin direction
|
|
||||||
// uint8_t direction = ((GPIO_1->DIRECTION_IN) & (1<<PIN_1_4_GPIO_S)) >> PIN_1_4_GPIO_S;
|
|
||||||
// if (direction == 1) // input
|
|
||||||
// GPIO_1->DIRECTION_IN |= (1<<PIN_1_3_GPIO_S);
|
|
||||||
// else // output
|
|
||||||
// GPIO_1->DIRECTION_OUT |= (1<<PIN_1_3_GPIO_S);
|
|
||||||
|
|
||||||
// // pull up/down
|
|
||||||
// uint8_t pupd_1_4 = ((PAD_CONFIG ->PORT_1_PUPD) & (0b11<<(2*PIN_1_4_GPIO_S))) >> (2*PIN_1_4_GPIO_S);
|
|
||||||
// PAD_CONFIG ->PORT_1_PUPD &= (~(0b11<<(2*PIN_1_3_GPIO_S))); // clear
|
|
||||||
// PAD_CONFIG ->PORT_1_PUPD |= ((pupd_1_4&0b11)<<(2*PIN_1_3_GPIO_S)); // set new
|
|
||||||
|
|
||||||
// // current state
|
|
||||||
// uint8_t state1_4 = ((GPIO_1->OUTPUT_) & (1<<PIN_1_4_GPIO_S)) >> PIN_1_4_GPIO_S;
|
|
||||||
// GPIO_1->OUTPUT_ &= (~(0b1<<PIN_1_3_GPIO_S)); // clear
|
|
||||||
// GPIO_1->OUTPUT_ |= ((state1_4&0b1)<<PIN_1_3_GPIO_S); // set new
|
|
||||||
|
|
||||||
// switch seller back to pin 1.3
|
|
||||||
HAL_GPIO_WritePin(GPIO_1, GPIO_PIN_6, GPIO_PIN_LOW);
|
|
||||||
unblockSpiPin();
|
|
||||||
|
|
||||||
spiInUse = false;
|
spiInUse = false;
|
||||||
isInited = false;
|
isInited = false;
|
||||||
|
|||||||
@ -10,7 +10,7 @@
|
|||||||
#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)
|
||||||
|
|
||||||
void spiElbear_prepareBegin(void)
|
void spi_onBegin(void)
|
||||||
{
|
{
|
||||||
// there is a seller on pin 1.6 which replace D10 from spi NSS pin 1.3 to pin 1.4,
|
// there is a seller on pin 1.6 which replace D10 from spi NSS pin 1.3 to pin 1.4,
|
||||||
// because spi needs pin 1.3 for correct work
|
// because spi needs pin 1.3 for correct work
|
||||||
@ -19,27 +19,19 @@ void spiElbear_prepareBegin(void)
|
|||||||
uint8_t config = PORT1_GET_PAD_CONFIG(PIN_3_SHIFT);
|
uint8_t config = PORT1_GET_PAD_CONFIG(PIN_3_SHIFT);
|
||||||
if (config == 0) // common gpio
|
if (config == 0) // common gpio
|
||||||
{
|
{
|
||||||
// pin direction
|
// get info from pin gpio1.3 and set config to gpio1.4
|
||||||
HAL_GPIO_ModeTypeDef pin3_direction = HAL_GPIO_GetPinDirection(GPIO_1, GPIO_PIN_3);
|
HAL_GPIO_PinConfig(GPIO_1, GPIO_PIN_4, HAL_GPIO_GetPinDirection(GPIO_1, GPIO_PIN_3),
|
||||||
// pull up/down
|
(HAL_GPIO_PullTypeDef)PORT1_GET_PAD_PUPD(PIN_3_SHIFT), HAL_GPIO_DS_2MA);
|
||||||
HAL_GPIO_PullTypeDef pin3_pupd = (HAL_GPIO_PullTypeDef)PORT1_GET_PAD_PUPD(PIN_3_SHIFT);
|
HAL_GPIO_WritePin(GPIO_1, GPIO_PIN_4, (GPIO_PinState)PORT1_GET_GPIO_STATE(PIN_3_SHIFT));
|
||||||
//current state
|
|
||||||
uint8_t pin3_state = PORT1_GET_GPIO_STATE(PIN_3_SHIFT);
|
|
||||||
|
|
||||||
// init and set state
|
|
||||||
HAL_GPIO_PinConfig(GPIO_1, GPIO_PIN_4, pin3_direction, pin3_pupd, HAL_GPIO_DS_2MA);
|
|
||||||
HAL_GPIO_WritePin(GPIO_1, GPIO_PIN_4, pin3_state);
|
|
||||||
// todo ПРОВЕРИТЬ, что по факту устанавливается то, что я говорю в HAL_GPIO_PinConfig
|
|
||||||
|
|
||||||
|
// pin D10 was switched to different gpio and can be used further
|
||||||
}
|
}
|
||||||
else if(config == 2) // timer for pwm
|
else if(config == 2) // timer for pwm
|
||||||
{
|
{
|
||||||
// вместо это возвращать что-то, что покажет, что это не gpio и снаружи выбросит предупреждение это
|
// if D10 (spi NSS pin) was used as pwm, we need to stop timer,
|
||||||
|
// because 1.4 don't support timer
|
||||||
// // if D10 (spi NSS pin) was used as pwm, we need to stop timer,
|
analogWriteStop(10);
|
||||||
// // because 1.4 don't support timer
|
ErrorMsgHandler("analogWrite(): D10 cannot be used as PWM pin while SPI is running");
|
||||||
// analogWriteStop(10);
|
|
||||||
// ErrorMsgHandler("analogWrite(): D10 cannot be used as PWM pin while SPI is running");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// switch seller to pin 1.4
|
// switch seller to pin 1.4
|
||||||
@ -47,3 +39,15 @@ void spiElbear_prepareBegin(void)
|
|||||||
HAL_GPIO_WritePin(GPIO_1, GPIO_PIN_6, GPIO_PIN_HIGH);
|
HAL_GPIO_WritePin(GPIO_1, GPIO_PIN_6, GPIO_PIN_HIGH);
|
||||||
blockSpiPin();
|
blockSpiPin();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void spi_onEnd(void)
|
||||||
|
{
|
||||||
|
// get info from pin gpio1.4 and set config to gpio1.3
|
||||||
|
HAL_GPIO_PinConfig(GPIO_1, GPIO_PIN_3, HAL_GPIO_GetPinDirection(GPIO_1, GPIO_PIN_4),
|
||||||
|
(HAL_GPIO_PullTypeDef)PORT1_GET_PAD_PUPD(PIN_4_SHIFT), HAL_GPIO_DS_2MA);
|
||||||
|
HAL_GPIO_WritePin(GPIO_1, GPIO_PIN_3, (GPIO_PinState)PORT1_GET_GPIO_STATE(PIN_4_SHIFT));
|
||||||
|
|
||||||
|
// switch seller back to pin 1.3
|
||||||
|
HAL_GPIO_WritePin(GPIO_1, GPIO_PIN_6, GPIO_PIN_LOW);
|
||||||
|
unblockSpiPin();
|
||||||
|
}
|
||||||
@ -1,2 +1,3 @@
|
|||||||
|
|
||||||
void spiElbear_prepareBegin(void);
|
void spi_onBegin(void);
|
||||||
|
void spi_onEnd(void);
|
||||||
Loading…
Reference in New Issue
Block a user