HAL to LL migration: GPIO, HSEM, AES (#1069)
* gpio, hsem, crypto: switch from HAL to LL/registers * Moved GPIO initialization to furi_hal * More HAL removed * All HAL modules disabled * HAL is finally removed * hal_gpio -> furi_hal_gpio, main.h removed * Bootloader build fix * RTOS config moved to freertos-glue * delay -> furi_hal_delay Co-authored-by: あく <alleteam@gmail.com>
This commit is contained in:
		| @@ -8,11 +8,11 @@ void furi_hal_init() { | ||||
|     furi_hal_version_init(); | ||||
| } | ||||
|  | ||||
| void delay(float milliseconds) { | ||||
| void furi_hal_delay_ms(float milliseconds) { | ||||
|     LL_mDelay((uint32_t)milliseconds); | ||||
| } | ||||
|  | ||||
| void delay_us(float microseconds) { | ||||
| void furi_hal_delay_us(float microseconds) { | ||||
|     microseconds = microseconds / 1000; | ||||
|     if(microseconds < 1) { | ||||
|         microseconds = 1; | ||||
|   | ||||
| @@ -33,7 +33,7 @@ | ||||
|  | ||||
| static volatile GpioInterrupt gpio_interrupt[GPIO_NUMBER]; | ||||
|  | ||||
| static uint8_t hal_gpio_get_pin_num(const GpioPin* gpio) { | ||||
| static uint8_t furi_hal_gpio_get_pin_num(const GpioPin* gpio) { | ||||
|     uint8_t pin_num = 0; | ||||
|     for(pin_num = 0; pin_num < GPIO_NUMBER; pin_num++) { | ||||
|         if(gpio->pin & (1 << pin_num)) break; | ||||
| @@ -41,11 +41,11 @@ 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 furi_hal_gpio_init_simple(const GpioPin* gpio, const GpioMode mode) { | ||||
|     furi_hal_gpio_init(gpio, mode, GpioPullNo, GpioSpeedLow); | ||||
| } | ||||
|  | ||||
| void hal_gpio_init( | ||||
| void furi_hal_gpio_init( | ||||
|     const GpioPin* gpio, | ||||
|     const GpioMode mode, | ||||
|     const GpioPull pull, | ||||
| @@ -54,10 +54,10 @@ void hal_gpio_init( | ||||
|     assert(mode != GpioModeAltFunctionPushPull); | ||||
|     assert(mode != GpioModeAltFunctionOpenDrain); | ||||
|  | ||||
|     hal_gpio_init_ex(gpio, mode, pull, speed, GpioAltFnUnused); | ||||
|     furi_hal_gpio_init_ex(gpio, mode, pull, speed, GpioAltFnUnused); | ||||
| } | ||||
|  | ||||
| void hal_gpio_init_ex( | ||||
| void furi_hal_gpio_init_ex( | ||||
|     const GpioPin* gpio, | ||||
|     const GpioMode mode, | ||||
|     const GpioPull pull, | ||||
| @@ -132,7 +132,7 @@ void hal_gpio_init_ex( | ||||
|         // Prepare alternative part if any | ||||
|         if(mode == GpioModeAltFunctionPushPull || mode == GpioModeAltFunctionOpenDrain) { | ||||
|             // set alternate function | ||||
|             if(hal_gpio_get_pin_num(gpio) < 8) { | ||||
|             if(furi_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); | ||||
| @@ -170,43 +170,43 @@ void hal_gpio_init_ex( | ||||
|     __enable_irq(); | ||||
| } | ||||
|  | ||||
| void hal_gpio_add_int_callback(const GpioPin* gpio, GpioExtiCallback cb, void* ctx) { | ||||
| void furi_hal_gpio_add_int_callback(const GpioPin* gpio, GpioExtiCallback cb, void* ctx) { | ||||
|     assert(gpio); | ||||
|     assert(cb); | ||||
|  | ||||
|     __disable_irq(); | ||||
|     uint8_t pin_num = hal_gpio_get_pin_num(gpio); | ||||
|     uint8_t pin_num = furi_hal_gpio_get_pin_num(gpio); | ||||
|     gpio_interrupt[pin_num].callback = cb; | ||||
|     gpio_interrupt[pin_num].context = ctx; | ||||
|     gpio_interrupt[pin_num].ready = true; | ||||
|     __enable_irq(); | ||||
| } | ||||
|  | ||||
| void hal_gpio_enable_int_callback(const GpioPin* gpio) { | ||||
| void furi_hal_gpio_enable_int_callback(const GpioPin* gpio) { | ||||
|     assert(gpio); | ||||
|  | ||||
|     __disable_irq(); | ||||
|     uint8_t pin_num = hal_gpio_get_pin_num(gpio); | ||||
|     uint8_t pin_num = furi_hal_gpio_get_pin_num(gpio); | ||||
|     if(gpio_interrupt[pin_num].callback) { | ||||
|         gpio_interrupt[pin_num].ready = true; | ||||
|     } | ||||
|     __enable_irq(); | ||||
| } | ||||
|  | ||||
| void hal_gpio_disable_int_callback(const GpioPin* gpio) { | ||||
| void furi_hal_gpio_disable_int_callback(const GpioPin* gpio) { | ||||
|     assert(gpio); | ||||
|  | ||||
|     __disable_irq(); | ||||
|     uint8_t pin_num = hal_gpio_get_pin_num(gpio); | ||||
|     uint8_t pin_num = furi_hal_gpio_get_pin_num(gpio); | ||||
|     gpio_interrupt[pin_num].ready = false; | ||||
|     __enable_irq(); | ||||
| } | ||||
|  | ||||
| void hal_gpio_remove_int_callback(const GpioPin* gpio) { | ||||
| void furi_hal_gpio_remove_int_callback(const GpioPin* gpio) { | ||||
|     assert(gpio); | ||||
|  | ||||
|     __disable_irq(); | ||||
|     uint8_t pin_num = hal_gpio_get_pin_num(gpio); | ||||
|     uint8_t pin_num = furi_hal_gpio_get_pin_num(gpio); | ||||
|     gpio_interrupt[pin_num].callback = NULL; | ||||
|     gpio_interrupt[pin_num].context = NULL; | ||||
|     gpio_interrupt[pin_num].ready = false; | ||||
|   | ||||
| @@ -1,6 +1,6 @@ | ||||
| #pragma once | ||||
| #include "main.h" | ||||
| #include "stdbool.h" | ||||
| #include "main.h" | ||||
| #include <stm32wbxx_ll_gpio.h> | ||||
| #include <stm32wbxx_ll_system.h> | ||||
| #include <stm32wbxx_ll_exti.h> | ||||
| @@ -170,7 +170,7 @@ typedef struct { | ||||
|  * @param gpio  GpioPin | ||||
|  * @param mode  GpioMode | ||||
|  */ | ||||
| void hal_gpio_init_simple(const GpioPin* gpio, const GpioMode mode); | ||||
| void furi_hal_gpio_init_simple(const GpioPin* gpio, const GpioMode mode); | ||||
|  | ||||
| /** | ||||
|  * GPIO initialization function, normal version | ||||
| @@ -179,7 +179,7 @@ void hal_gpio_init_simple(const GpioPin* gpio, const GpioMode mode); | ||||
|  * @param pull  GpioPull | ||||
|  * @param speed GpioSpeed | ||||
|  */ | ||||
| void hal_gpio_init( | ||||
| void furi_hal_gpio_init( | ||||
|     const GpioPin* gpio, | ||||
|     const GpioMode mode, | ||||
|     const GpioPull pull, | ||||
| @@ -193,7 +193,7 @@ void hal_gpio_init( | ||||
|  * @param speed GpioSpeed | ||||
|  * @param alt_fn GpioAltFn | ||||
|  */ | ||||
| void hal_gpio_init_ex( | ||||
| void furi_hal_gpio_init_ex( | ||||
|     const GpioPin* gpio, | ||||
|     const GpioMode mode, | ||||
|     const GpioPull pull, | ||||
| @@ -206,32 +206,32 @@ void hal_gpio_init_ex( | ||||
|  * @param cb   GpioExtiCallback | ||||
|  * @param ctx  context for callback | ||||
|  */ | ||||
| void hal_gpio_add_int_callback(const GpioPin* gpio, GpioExtiCallback cb, void* ctx); | ||||
| void furi_hal_gpio_add_int_callback(const GpioPin* gpio, GpioExtiCallback cb, void* ctx); | ||||
|  | ||||
| /** | ||||
|  * Enable interrupt | ||||
|  * @param gpio GpioPin | ||||
|  */ | ||||
| void hal_gpio_enable_int_callback(const GpioPin* gpio); | ||||
| void furi_hal_gpio_enable_int_callback(const GpioPin* gpio); | ||||
|  | ||||
| /** | ||||
|  * Disable interrupt | ||||
|  * @param gpio GpioPin | ||||
|  */ | ||||
| void hal_gpio_disable_int_callback(const GpioPin* gpio); | ||||
| void furi_hal_gpio_disable_int_callback(const GpioPin* gpio); | ||||
|  | ||||
| /** | ||||
|  * Remove interrupt | ||||
|  * @param gpio GpioPin | ||||
|  */ | ||||
| void hal_gpio_remove_int_callback(const GpioPin* gpio); | ||||
| void furi_hal_gpio_remove_int_callback(const GpioPin* gpio); | ||||
|  | ||||
| /** | ||||
|  * GPIO write pin | ||||
|  * @param gpio  GpioPin | ||||
|  * @param state true / false | ||||
|  */ | ||||
| static inline void hal_gpio_write(const GpioPin* gpio, const bool state) { | ||||
| static inline void furi_hal_gpio_write(const GpioPin* gpio, const bool state) { | ||||
|     // writing to BSSR is an atomic operation | ||||
|     if(state == true) { | ||||
|         gpio->port->BSRR = gpio->pin; | ||||
| @@ -245,7 +245,7 @@ static inline void hal_gpio_write(const GpioPin* gpio, const bool state) { | ||||
|  * @param gpio GpioPin | ||||
|  * @return true / false | ||||
|  */ | ||||
| static inline bool hal_gpio_read(const GpioPin* gpio) { | ||||
| static inline bool furi_hal_gpio_read(const GpioPin* gpio) { | ||||
|     if((gpio->port->IDR & gpio->pin) != 0x00U) { | ||||
|         return true; | ||||
|     } else { | ||||
| @@ -257,7 +257,7 @@ static inline bool hal_gpio_read(const GpioPin* gpio) { | ||||
|  * Get RFID IN level | ||||
|  * @return false = LOW, true = HIGH | ||||
|  */ | ||||
| bool hal_gpio_get_rfid_in_level(); | ||||
| bool furi_hal_gpio_get_rfid_in_level(); | ||||
|  | ||||
| #ifdef __cplusplus | ||||
| } | ||||
|   | ||||
| @@ -60,13 +60,13 @@ void furi_hal_i2c_bus_handle_power_event( | ||||
|     FuriHalI2cBusHandleEvent event) { | ||||
|     if(event == FuriHalI2cBusHandleEventActivate) { | ||||
|         LL_AHB2_GRP1_EnableClock(LL_AHB2_GRP1_PERIPH_GPIOA); | ||||
|         hal_gpio_init_ex( | ||||
|         furi_hal_gpio_init_ex( | ||||
|             &gpio_i2c_power_sda, | ||||
|             GpioModeAltFunctionOpenDrain, | ||||
|             GpioPullNo, | ||||
|             GpioSpeedLow, | ||||
|             GpioAltFn4I2C1); | ||||
|         hal_gpio_init_ex( | ||||
|         furi_hal_gpio_init_ex( | ||||
|             &gpio_i2c_power_scl, | ||||
|             GpioModeAltFunctionOpenDrain, | ||||
|             GpioPullNo, | ||||
| @@ -95,11 +95,11 @@ void furi_hal_i2c_bus_handle_power_event( | ||||
|         LL_I2C_Enable(handle->bus->i2c); | ||||
|     } else if(event == FuriHalI2cBusHandleEventDeactivate) { | ||||
|         LL_I2C_Disable(handle->bus->i2c); | ||||
|         hal_gpio_write(&gpio_i2c_power_sda, 1); | ||||
|         hal_gpio_write(&gpio_i2c_power_scl, 1); | ||||
|         hal_gpio_init_ex( | ||||
|         furi_hal_gpio_write(&gpio_i2c_power_sda, 1); | ||||
|         furi_hal_gpio_write(&gpio_i2c_power_scl, 1); | ||||
|         furi_hal_gpio_init_ex( | ||||
|             &gpio_i2c_power_sda, GpioModeAnalog, GpioPullNo, GpioSpeedLow, GpioAltFnUnused); | ||||
|         hal_gpio_init_ex( | ||||
|         furi_hal_gpio_init_ex( | ||||
|             &gpio_i2c_power_scl, GpioModeAnalog, GpioPullNo, GpioSpeedLow, GpioAltFnUnused); | ||||
|     } | ||||
| } | ||||
| @@ -113,9 +113,9 @@ void furi_hal_i2c_bus_handle_external_event( | ||||
|     FuriHalI2cBusHandle* handle, | ||||
|     FuriHalI2cBusHandleEvent event) { | ||||
|     if(event == FuriHalI2cBusHandleEventActivate) { | ||||
|         hal_gpio_init_ex( | ||||
|         furi_hal_gpio_init_ex( | ||||
|             &gpio_ext_pc0, GpioModeAltFunctionOpenDrain, GpioPullNo, GpioSpeedLow, GpioAltFn4I2C3); | ||||
|         hal_gpio_init_ex( | ||||
|         furi_hal_gpio_init_ex( | ||||
|             &gpio_ext_pc1, GpioModeAltFunctionOpenDrain, GpioPullNo, GpioSpeedLow, GpioAltFn4I2C3); | ||||
|  | ||||
|         LL_I2C_InitTypeDef I2C_InitStruct = {0}; | ||||
| @@ -136,10 +136,12 @@ void furi_hal_i2c_bus_handle_external_event( | ||||
|         LL_I2C_Enable(handle->bus->i2c); | ||||
|     } else if(event == FuriHalI2cBusHandleEventDeactivate) { | ||||
|         LL_I2C_Disable(handle->bus->i2c); | ||||
|         hal_gpio_write(&gpio_ext_pc0, 1); | ||||
|         hal_gpio_write(&gpio_ext_pc1, 1); | ||||
|         hal_gpio_init_ex(&gpio_ext_pc0, GpioModeAnalog, GpioPullNo, GpioSpeedLow, GpioAltFnUnused); | ||||
|         hal_gpio_init_ex(&gpio_ext_pc1, GpioModeAnalog, GpioPullNo, GpioSpeedLow, GpioAltFnUnused); | ||||
|         furi_hal_gpio_write(&gpio_ext_pc0, 1); | ||||
|         furi_hal_gpio_write(&gpio_ext_pc1, 1); | ||||
|         furi_hal_gpio_init_ex( | ||||
|             &gpio_ext_pc0, GpioModeAnalog, GpioPullNo, GpioSpeedLow, GpioAltFnUnused); | ||||
|         furi_hal_gpio_init_ex( | ||||
|             &gpio_ext_pc1, GpioModeAnalog, GpioPullNo, GpioSpeedLow, GpioAltFnUnused); | ||||
|     } | ||||
| } | ||||
|  | ||||
|   | ||||
| @@ -1,5 +1,4 @@ | ||||
| #include "furi_hal_resources.h" | ||||
| #include "main.h" | ||||
|  | ||||
| const GpioPin vibro_gpio = {.port = VIBRO_GPIO_Port, .pin = VIBRO_Pin}; | ||||
| const GpioPin ibutton_gpio = {.port = iBTN_GPIO_Port, .pin = iBTN_Pin}; | ||||
|   | ||||
| @@ -117,42 +117,42 @@ inline static void furi_hal_spi_bus_r_handle_event_callback( | ||||
|     FuriHalSpiBusHandleEvent event, | ||||
|     const LL_SPI_InitTypeDef* preset) { | ||||
|     if(event == FuriHalSpiBusHandleEventInit) { | ||||
|         hal_gpio_write(handle->cs, true); | ||||
|         hal_gpio_init(handle->cs, GpioModeOutputPushPull, GpioPullNo, GpioSpeedVeryHigh); | ||||
|         furi_hal_gpio_write(handle->cs, true); | ||||
|         furi_hal_gpio_init(handle->cs, GpioModeOutputPushPull, GpioPullNo, GpioSpeedVeryHigh); | ||||
|     } else if(event == FuriHalSpiBusHandleEventDeinit) { | ||||
|         hal_gpio_write(handle->cs, true); | ||||
|         hal_gpio_init(handle->cs, GpioModeAnalog, GpioPullNo, GpioSpeedLow); | ||||
|         furi_hal_gpio_write(handle->cs, true); | ||||
|         furi_hal_gpio_init(handle->cs, GpioModeAnalog, GpioPullNo, GpioSpeedLow); | ||||
|     } else if(event == FuriHalSpiBusHandleEventActivate) { | ||||
|         LL_SPI_Init(handle->bus->spi, (LL_SPI_InitTypeDef*)preset); | ||||
|         LL_SPI_SetRxFIFOThreshold(handle->bus->spi, LL_SPI_RX_FIFO_TH_QUARTER); | ||||
|         LL_SPI_Enable(handle->bus->spi); | ||||
|  | ||||
|         hal_gpio_init_ex( | ||||
|         furi_hal_gpio_init_ex( | ||||
|             handle->miso, | ||||
|             GpioModeAltFunctionPushPull, | ||||
|             GpioPullNo, | ||||
|             GpioSpeedVeryHigh, | ||||
|             GpioAltFn5SPI1); | ||||
|         hal_gpio_init_ex( | ||||
|         furi_hal_gpio_init_ex( | ||||
|             handle->mosi, | ||||
|             GpioModeAltFunctionPushPull, | ||||
|             GpioPullNo, | ||||
|             GpioSpeedVeryHigh, | ||||
|             GpioAltFn5SPI1); | ||||
|         hal_gpio_init_ex( | ||||
|         furi_hal_gpio_init_ex( | ||||
|             handle->sck, | ||||
|             GpioModeAltFunctionPushPull, | ||||
|             GpioPullNo, | ||||
|             GpioSpeedVeryHigh, | ||||
|             GpioAltFn5SPI1); | ||||
|  | ||||
|         hal_gpio_write(handle->cs, false); | ||||
|         furi_hal_gpio_write(handle->cs, false); | ||||
|     } else if(event == FuriHalSpiBusHandleEventDeactivate) { | ||||
|         hal_gpio_write(handle->cs, true); | ||||
|         furi_hal_gpio_write(handle->cs, true); | ||||
|  | ||||
|         hal_gpio_init(handle->miso, GpioModeAnalog, GpioPullNo, GpioSpeedLow); | ||||
|         hal_gpio_init(handle->mosi, GpioModeAnalog, GpioPullNo, GpioSpeedLow); | ||||
|         hal_gpio_init(handle->sck, GpioModeAnalog, GpioPullNo, GpioSpeedLow); | ||||
|         furi_hal_gpio_init(handle->miso, GpioModeAnalog, GpioPullNo, GpioSpeedLow); | ||||
|         furi_hal_gpio_init(handle->mosi, GpioModeAnalog, GpioPullNo, GpioSpeedLow); | ||||
|         furi_hal_gpio_init(handle->sck, GpioModeAnalog, GpioPullNo, GpioSpeedLow); | ||||
|  | ||||
|         LL_SPI_Disable(handle->bus->spi); | ||||
|     } | ||||
| @@ -208,22 +208,22 @@ inline static void furi_hal_spi_bus_d_handle_event_callback( | ||||
|     FuriHalSpiBusHandleEvent event, | ||||
|     const LL_SPI_InitTypeDef* preset) { | ||||
|     if(event == FuriHalSpiBusHandleEventInit) { | ||||
|         hal_gpio_write(handle->cs, true); | ||||
|         hal_gpio_init(handle->cs, GpioModeOutputPushPull, GpioPullUp, GpioSpeedVeryHigh); | ||||
|         furi_hal_gpio_write(handle->cs, true); | ||||
|         furi_hal_gpio_init(handle->cs, GpioModeOutputPushPull, GpioPullUp, GpioSpeedVeryHigh); | ||||
|  | ||||
|         hal_gpio_init_ex( | ||||
|         furi_hal_gpio_init_ex( | ||||
|             handle->miso, | ||||
|             GpioModeAltFunctionPushPull, | ||||
|             GpioPullNo, | ||||
|             GpioSpeedVeryHigh, | ||||
|             GpioAltFn5SPI2); | ||||
|         hal_gpio_init_ex( | ||||
|         furi_hal_gpio_init_ex( | ||||
|             handle->mosi, | ||||
|             GpioModeAltFunctionPushPull, | ||||
|             GpioPullNo, | ||||
|             GpioSpeedVeryHigh, | ||||
|             GpioAltFn5SPI2); | ||||
|         hal_gpio_init_ex( | ||||
|         furi_hal_gpio_init_ex( | ||||
|             handle->sck, | ||||
|             GpioModeAltFunctionPushPull, | ||||
|             GpioPullNo, | ||||
| @@ -231,15 +231,15 @@ inline static void furi_hal_spi_bus_d_handle_event_callback( | ||||
|             GpioAltFn5SPI2); | ||||
|  | ||||
|     } else if(event == FuriHalSpiBusHandleEventDeinit) { | ||||
|         hal_gpio_write(handle->cs, true); | ||||
|         hal_gpio_init(handle->cs, GpioModeAnalog, GpioPullUp, GpioSpeedLow); | ||||
|         furi_hal_gpio_write(handle->cs, true); | ||||
|         furi_hal_gpio_init(handle->cs, GpioModeAnalog, GpioPullUp, GpioSpeedLow); | ||||
|     } else if(event == FuriHalSpiBusHandleEventActivate) { | ||||
|         LL_SPI_Init(handle->bus->spi, (LL_SPI_InitTypeDef*)preset); | ||||
|         LL_SPI_SetRxFIFOThreshold(handle->bus->spi, LL_SPI_RX_FIFO_TH_QUARTER); | ||||
|         LL_SPI_Enable(handle->bus->spi); | ||||
|         hal_gpio_write(handle->cs, false); | ||||
|         furi_hal_gpio_write(handle->cs, false); | ||||
|     } else if(event == FuriHalSpiBusHandleEventDeactivate) { | ||||
|         hal_gpio_write(handle->cs, true); | ||||
|         furi_hal_gpio_write(handle->cs, true); | ||||
|         LL_SPI_Disable(handle->bus->spi); | ||||
|     } | ||||
| } | ||||
|   | ||||
| @@ -185,8 +185,8 @@ void target_usb_wire_reset() { | ||||
|  | ||||
| void target_display_init() { | ||||
|     // Prepare gpio | ||||
|     hal_gpio_init_simple(&gpio_display_rst, GpioModeOutputPushPull); | ||||
|     hal_gpio_init_simple(&gpio_display_di, GpioModeOutputPushPull); | ||||
|     furi_hal_gpio_init_simple(&gpio_display_rst, GpioModeOutputPushPull); | ||||
|     furi_hal_gpio_init_simple(&gpio_display_di, GpioModeOutputPushPull); | ||||
|     // Initialize | ||||
|     u8g2_t fb; | ||||
|     u8g2_Setup_st756x_flipper(&fb, U8G2_R0, u8x8_hw_spi_stm32, u8g2_gpio_and_delay_stm32); | ||||
|   | ||||
| @@ -10,6 +10,6 @@ | ||||
|  | ||||
| void furi_hal_init(); | ||||
|  | ||||
| void delay(float milliseconds); | ||||
| void furi_hal_delay_ms(float milliseconds); | ||||
|  | ||||
| void delay_us(float microseconds); | ||||
| void furi_hal_delay_us(float microseconds); | ||||
|   | ||||
		Reference in New Issue
	
	Block a user