[FL-1351] Wiegand read fix (#483)
* App accessor: fix external interrupts binding. Hal: removed InterruptTypeExternalInterrupt. * GPIO hal: add ex and simple init functions to F6 target * GPIO hal: add dummy alt fn to F6 target * RFID hal: update gpio hal usage * F5,F6: synchronize targets, backport VCP fixes, cleanup. Co-authored-by: あく <alleteam@gmail.com>
This commit is contained in:
		| @@ -152,7 +152,7 @@ void MX_GPIO_Init(void) { | ||||
|     GPIO_InitStruct.Pin = CC1101_CS_Pin; | ||||
|     HAL_GPIO_Init(CC1101_CS_GPIO_Port, &GPIO_InitStruct); | ||||
|  | ||||
|     /* EXTI interrupt init*/ | ||||
|     /* Enable all NVIC lines related to gpio */ | ||||
|     HAL_NVIC_SetPriority(EXTI0_IRQn, 5, 0); | ||||
|     HAL_NVIC_EnableIRQ(EXTI0_IRQn); | ||||
|  | ||||
|   | ||||
| @@ -41,11 +41,28 @@ static uint8_t hal_gpio_get_pin_num(const GpioPin* gpio) { | ||||
|     return pin_num; | ||||
| } | ||||
|  | ||||
| void hal_gpio_init_simple(const GpioPin* gpio, const GpioMode mode) { | ||||
|     hal_gpio_init(gpio, mode, GpioPullNo, GpioSpeedLow); | ||||
| } | ||||
|  | ||||
| void hal_gpio_init( | ||||
|     const GpioPin* gpio, | ||||
|     const GpioMode mode, | ||||
|     const GpioPull pull, | ||||
|     const GpioSpeed speed) { | ||||
|     // we cannot set alternate mode in this function | ||||
|     furi_assert(mode != GpioModeAltFunctionPushPull); | ||||
|     furi_assert(mode != GpioModeAltFunctionOpenDrain); | ||||
|  | ||||
|     hal_gpio_init_ex(gpio, mode, GpioPullNo, GpioSpeedLow, GpioAltFnUnused); | ||||
| } | ||||
|  | ||||
| void hal_gpio_init_ex( | ||||
|     const GpioPin* gpio, | ||||
|     const GpioMode mode, | ||||
|     const GpioPull pull, | ||||
|     const GpioSpeed speed, | ||||
|     const GpioAltFn alt_fn) { | ||||
|     uint32_t sys_exti_port = GET_SYSCFG_EXTI_PORT(gpio->port); | ||||
|     uint32_t sys_exti_line = GET_SYSCFG_EXTI_LINE(gpio->pin); | ||||
|     uint32_t exti_line = GET_EXTI_LINE(gpio->pin); | ||||
| @@ -112,27 +129,19 @@ void hal_gpio_init( | ||||
|             LL_GPIO_SetPinMode(gpio->port, gpio->pin, LL_GPIO_MODE_ANALOG); | ||||
|         } | ||||
|     } | ||||
|     __enable_irq(); | ||||
| } | ||||
|  | ||||
| void hal_gpio_init_alt( | ||||
|     const GpioPin* gpio, | ||||
|     const GpioMode mode, | ||||
|     const GpioPull pull, | ||||
|     const GpioSpeed speed, | ||||
|     const GpioAltFn alt_fn) { | ||||
|     hal_gpio_init(gpio, mode, pull, speed); | ||||
|     if(mode == GpioModeAltFunctionPushPull || mode == GpioModeAltFunctionOpenDrain) { | ||||
|         // enable alternate mode | ||||
|         LL_GPIO_SetPinMode(gpio->port, gpio->pin, LL_GPIO_MODE_ALTERNATE); | ||||
|  | ||||
|     __disable_irq(); | ||||
|     // enable alternate mode | ||||
|     LL_GPIO_SetPinMode(gpio->port, gpio->pin, LL_GPIO_MODE_ALTERNATE); | ||||
|  | ||||
|     // set alternate function | ||||
|     if(hal_gpio_get_pin_num(gpio) < 8) { | ||||
|         LL_GPIO_SetAFPin_0_7(gpio->port, gpio->pin, alt_fn); | ||||
|     } else { | ||||
|         LL_GPIO_SetAFPin_8_15(gpio->port, gpio->pin, alt_fn); | ||||
|         // set alternate function | ||||
|         if(hal_gpio_get_pin_num(gpio) < 8) { | ||||
|             LL_GPIO_SetAFPin_0_7(gpio->port, gpio->pin, alt_fn); | ||||
|         } else { | ||||
|             LL_GPIO_SetAFPin_8_15(gpio->port, gpio->pin, alt_fn); | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     __enable_irq(); | ||||
| } | ||||
|  | ||||
|   | ||||
| @@ -153,6 +153,8 @@ typedef enum { | ||||
|     GpioAltFn14LPTIM2 = 14, /*!< LPTIM2 Alternate Function mapping */ | ||||
|  | ||||
|     GpioAltFn15EVENTOUT = 15, /*!< EVENTOUT Alternate Function mapping */ | ||||
|  | ||||
|     GpioAltFnUnused = 16, /*!< just dummy value */ | ||||
| } GpioAltFn; | ||||
|  | ||||
| /** | ||||
| @@ -164,7 +166,14 @@ typedef struct { | ||||
| } GpioPin; | ||||
|  | ||||
| /** | ||||
|  * GPIO initialization function | ||||
|  * GPIO initialization function, simple version | ||||
|  * @param gpio  GpioPin | ||||
|  * @param mode  GpioMode | ||||
|  */ | ||||
| void hal_gpio_init_simple(const GpioPin* gpio, const GpioMode mode); | ||||
|  | ||||
| /** | ||||
|  * GPIO initialization function, normal version | ||||
|  * @param gpio  GpioPin | ||||
|  * @param mode  GpioMode | ||||
|  * @param pull  GpioPull | ||||
| @@ -177,14 +186,14 @@ void hal_gpio_init( | ||||
|     const GpioSpeed speed); | ||||
|  | ||||
| /** | ||||
|  * GPIO initialization with alternative function | ||||
|  * GPIO initialization function, extended version | ||||
|  * @param gpio  GpioPin | ||||
|  * @param mode  GpioMode | ||||
|  * @param pull  GpioPull | ||||
|  * @param speed GpioSpeed | ||||
|  * @param alt_fn GpioAltFn | ||||
|  */ | ||||
| void hal_gpio_init_alt( | ||||
| void hal_gpio_init_ex( | ||||
|     const GpioPin* gpio, | ||||
|     const GpioMode mode, | ||||
|     const GpioPull pull, | ||||
|   | ||||
| @@ -26,7 +26,7 @@ void api_hal_rfid_pins_emulate() { | ||||
|     api_hal_ibutton_pin_low(); | ||||
|  | ||||
|     // pull pin to timer out | ||||
|     hal_gpio_init_alt( | ||||
|     hal_gpio_init_ex( | ||||
|         &gpio_rfid_pull, GpioModeOutputPushPull, GpioSpeedLow, GpioPullNo, GpioAltFn1TIM1); | ||||
|  | ||||
|     // pull rfid antenna from carrier side | ||||
| @@ -44,7 +44,7 @@ void api_hal_rfid_pins_read() { | ||||
|     hal_gpio_write(&gpio_rfid_pull, false); | ||||
|  | ||||
|     // carrier pin to timer out | ||||
|     hal_gpio_init_alt( | ||||
|     hal_gpio_init_ex( | ||||
|         &gpio_rfid_carrier_out, GpioModeOutputPushPull, GpioSpeedLow, GpioPullNo, GpioAltFn1TIM1); | ||||
|  | ||||
|     // comparator in | ||||
|   | ||||
| @@ -46,11 +46,15 @@ void _api_hal_vcp_control_line(uint8_t state) { | ||||
|     bool rts = state & 0b10; | ||||
|  | ||||
|     if (rts) { | ||||
|         api_hal_vcp->alive = true; | ||||
|         _api_hal_vcp_rx_callback(&ascii_soh, 1); // SOH | ||||
|         if (!api_hal_vcp->alive) { | ||||
|             api_hal_vcp->alive = true; | ||||
|             _api_hal_vcp_rx_callback(&ascii_soh, 1); // SOH | ||||
|         } | ||||
|     } else { | ||||
|         api_hal_vcp->alive = false; | ||||
|         _api_hal_vcp_rx_callback(&ascii_eot, 1); // EOT | ||||
|         if (api_hal_vcp->alive) { | ||||
|             _api_hal_vcp_rx_callback(&ascii_eot, 1); // EOT | ||||
|             api_hal_vcp->alive = false; | ||||
|         } | ||||
|     } | ||||
|  | ||||
|     osSemaphoreRelease(api_hal_vcp->tx_semaphore); | ||||
|   | ||||
| @@ -18,9 +18,4 @@ void HAL_TIM_OC_DelayElapsedCallback(TIM_HandleTypeDef* htim) { | ||||
| /* Timer update event */ | ||||
| void HAL_TIM_PeriodElapsedCallback(TIM_HandleTypeDef* htim) { | ||||
|     api_interrupt_call(InterruptTypeTimerUpdate, htim); | ||||
| } | ||||
|  | ||||
| /* External interrupt event */ | ||||
| void HAL_GPIO_EXTI_Callback(uint16_t GPIO_Pin) { | ||||
|     api_interrupt_call(InterruptTypeExternalInterrupt, (void*)(uint32_t)GPIO_Pin); | ||||
| } | ||||
| } | ||||
| @@ -66,13 +66,6 @@ extern "C"{ | ||||
|    *  Some useful macro definitions   * | ||||
|    * -------------------------------- */ | ||||
|  | ||||
| #ifndef MAX | ||||
| #define MAX( x, y )          (((x)>(y))?(x):(y)) | ||||
| #endif | ||||
|  | ||||
| #ifndef MIN | ||||
| #define MIN( x, y )          (((x)<(y))?(x):(y)) | ||||
| #endif | ||||
|  | ||||
| #define MODINC( a, m )       M_BEGIN  (a)++;  if ((a)>=(m)) (a)=0;  M_END | ||||
|  | ||||
|   | ||||
		Reference in New Issue
	
	Block a user