[FL-873] Add F5 target, lp5562 driver and api-hal-light (#347)

* Add F5 target, lp5562 driver and api-hal-light. Update api-usage, switch to F5 by default.
* API HAL: add i2c and hardware version api. Dolphin: show hardware version.
* OTP version generator and flashing utility.
* Assets script: fix code formatting
* Backport F5 changes to F4
* F4: disable insomnia, prevent damage to BLE RX path
* F5 HAL API Light: remove magic delay to fix magic BLE
* Dolphin: HW target validation on start
* invert RSSI indication in sub-1
* API HAL: rename board to body in version api
* Gpio tester: detach and release viewport on exit

Co-authored-by: aanper <mail@s3f.ru>
This commit is contained in:
あく
2021-02-18 15:49:32 +03:00
committed by GitHub
parent da91482b7d
commit 68a3f6b4b7
214 changed files with 25577 additions and 184 deletions

View File

@@ -1,6 +1,7 @@
#include "api-hal-gpio.h"
#include "api-hal-resources.h"
#include "spi.h"
#include <api-hal-gpio.h>
#include <api-hal-spi.h>
#include <api-hal-resources.h>
#include <api-hal-delay.h>
// init GPIO
void hal_gpio_init(

View File

@@ -0,0 +1,17 @@
#include <api-hal-i2c.h>
#include <furi.h>
osMutexId_t api_hal_i2c_mutex = NULL;
void api_hal_i2c_init() {
api_hal_i2c_mutex = osMutexNew(NULL);
furi_check(api_hal_i2c_mutex);
}
void api_hal_i2c_lock() {
furi_check(osMutexAcquire(api_hal_i2c_mutex, osWaitForever) == osOK);
}
void api_hal_i2c_unlock() {
furi_check(osMutexRelease(api_hal_i2c_mutex) == osOK);
}

View File

@@ -0,0 +1,55 @@
#include <api-hal-light.h>
#include <stm32wbxx_ll_gpio.h>
// LCD backlight
#define BOOT_LCD_BL_PORT GPIOA
#define BOOT_LCD_BL_PIN LL_GPIO_PIN_15
// LEDs
#define LED_RED_PORT GPIOA
#define LED_RED_PIN LL_GPIO_PIN_1
#define LED_GREEN_PORT GPIOA
#define LED_GREEN_PIN LL_GPIO_PIN_2
#define LED_BLUE_PORT GPIOA
#define LED_BLUE_PIN LL_GPIO_PIN_3
static void api_hal_light_gpio_set(GPIO_TypeDef* port, uint32_t pin, uint8_t value) {
if (value) {
LL_GPIO_ResetOutputPin(port, pin);
} else {
LL_GPIO_SetOutputPin(port, pin);
}
}
void api_hal_light_init() {
LL_GPIO_SetPinMode(BOOT_LCD_BL_PORT, BOOT_LCD_BL_PIN, LL_GPIO_MODE_OUTPUT);
LL_GPIO_SetPinSpeed(BOOT_LCD_BL_PORT, BOOT_LCD_BL_PIN, LL_GPIO_SPEED_FREQ_LOW);
LL_GPIO_SetPinOutputType(BOOT_LCD_BL_PORT, BOOT_LCD_BL_PIN, LL_GPIO_OUTPUT_PUSHPULL);
LL_GPIO_SetPinMode(LED_RED_PORT, LED_RED_PIN, LL_GPIO_MODE_OUTPUT);
LL_GPIO_SetPinOutputType(LED_RED_PORT, LED_RED_PIN, LL_GPIO_OUTPUT_OPENDRAIN);
LL_GPIO_SetPinMode(LED_GREEN_PORT, LED_GREEN_PIN, LL_GPIO_MODE_OUTPUT);
LL_GPIO_SetPinOutputType(LED_GREEN_PORT, LED_GREEN_PIN, LL_GPIO_OUTPUT_OPENDRAIN);
LL_GPIO_SetPinMode(LED_BLUE_PORT, LED_BLUE_PIN, LL_GPIO_MODE_OUTPUT);
LL_GPIO_SetPinOutputType(LED_BLUE_PORT, LED_BLUE_PIN, LL_GPIO_OUTPUT_OPENDRAIN);
}
void api_hal_light_set(Light light, uint8_t value) {
switch(light) {
case LightRed:
api_hal_light_gpio_set(LED_RED_PORT, LED_RED_PIN, value);
break;
case LightGreen:
api_hal_light_gpio_set(LED_GREEN_PORT, LED_GREEN_PIN, value);
break;
case LightBlue:
api_hal_light_gpio_set(LED_BLUE_PORT, LED_BLUE_PIN, value);
break;
case LightBacklight:
api_hal_light_gpio_set(BOOT_LCD_BL_PORT, BOOT_LCD_BL_PIN, !value);
break;
default:
break;
}
}

View File

@@ -12,7 +12,7 @@
#include <bq27220.h>
#include <bq25896.h>
volatile uint32_t api_hal_power_insomnia = 0;
volatile uint32_t api_hal_power_insomnia = 1;
void HAL_RCC_CSSCallback(void) {
LL_RCC_ForceBackupDomainReset();

View File

@@ -1,7 +1,12 @@
#pragma once
#include "main.h"
#include <furi.h>
#ifdef __cplusplus
extern "C" {
#endif
/* Input Related Constants */
#define INPUT_DEBOUNCE_TICKS 20
@@ -15,6 +20,14 @@ typedef enum {
InputKeyBack,
} InputKey;
/* Light */
typedef enum {
LightRed,
LightGreen,
LightBlue,
LightBacklight,
} Light;
typedef struct {
const GPIO_TypeDef* port;
const uint16_t pin;
@@ -25,9 +38,11 @@ typedef struct {
extern const InputPin input_pins[];
extern const size_t input_pins_count;
extern const GpioPin led_gpio[3];
extern const GpioPin backlight_gpio;
extern const GpioPin sd_cs_gpio;
extern const GpioPin vibro_gpio;
extern const GpioPin ibutton_gpio;
extern const GpioPin cc1101_g0_gpio;
#ifdef __cplusplus
}
#endif

View File

@@ -0,0 +1,34 @@
#include <api-hal-version.h>
#include <stm32wbxx.h>
typedef struct {
uint8_t version;
uint8_t target;
uint8_t body;
uint8_t connect;
uint32_t timestamp;
} ApiHalVersionOTP;
bool api_hal_version_do_i_belong_here() {
return api_hal_version_get_hw_target() == 4;
}
const uint8_t api_hal_version_get_hw_version() {
return ((ApiHalVersionOTP*)OTP_AREA_BASE)->version;
}
const uint8_t api_hal_version_get_hw_target() {
return ((ApiHalVersionOTP*)OTP_AREA_BASE)->target;
}
const uint8_t api_hal_version_get_hw_body() {
return ((ApiHalVersionOTP*)OTP_AREA_BASE)->body;
}
const uint8_t api_hal_version_get_hw_connect() {
return ((ApiHalVersionOTP*)OTP_AREA_BASE)->connect;
}
const uint32_t api_hal_version_get_hw_timestamp() {
return ((ApiHalVersionOTP*)OTP_AREA_BASE)->timestamp;
}

View File

@@ -4,4 +4,6 @@ void api_hal_init() {
api_hal_os_init();
api_hal_vcp_init();
api_hal_spi_init();
}
api_hal_i2c_init();
api_hal_light_init();
}