[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

@@ -29,7 +29,7 @@ void platformIrqWorker() {
void platformSetIrqCallback(PlatformIrqCallback callback) {
platform_irq_callback = callback;
platform_irq_thread_attr.name = "rfal_irq_worker";
platform_irq_thread_attr.stack_size = 512;
platform_irq_thread_attr.stack_size = 1024;
platform_irq_thread_attr.priority = osPriorityISR;
platform_irq_thread_id = osThreadNew(platformIrqWorker, NULL, &platform_irq_thread_attr);
api_interrupt_add(nfc_isr, InterruptTypeExternalInterrupt, NULL);

View File

@@ -10,6 +10,7 @@
#include "math.h"
#include "spi.h"
#include "main.h"
#include <api-hal.h>
typedef void (*PlatformIrqCallback)();
void platformSetIrqCallback(PlatformIrqCallback cb);
@@ -24,10 +25,10 @@ void platformUnprotectST25RComm();
#define ST25R_INT_PIN NFC_IRQ_Pin
#define ST25R_INT_PORT NFC_IRQ_GPIO_Port
#define PLATFORM_LED_RX_PIN LED_RED_Pin
#define PLATFORM_LED_RX_PORT LED_RED_GPIO_Port
#define PLATFORM_LED_FIELD_PIN LED_BLUE_Pin
#define PLATFORM_LED_FIELD_PORT LED_BLUE_GPIO_Port
#define PLATFORM_LED_RX_PIN LightRed
#define PLATFORM_LED_RX_PORT NULL
#define PLATFORM_LED_FIELD_PIN LightBlue
#define PLATFORM_LED_FIELD_PORT NULL
#define RFAL_FEATURE_LISTEN_MODE true /*!< Enable/Disable RFAL support for Listen Mode */
#define RFAL_FEATURE_WAKEUP_MODE true /*!< Enable/Disable RFAL support for the Wake-Up mode */
@@ -60,8 +61,8 @@ void platformUnprotectST25RComm();
#define platformProtectST25RIrqStatus() platformProtectST25RComm() /*!< Protect unique access to IRQ status var - IRQ disable on single thread environment (MCU) ; Mutex lock on a multi thread environment */
#define platformUnprotectST25RIrqStatus() platformUnprotectST25RComm() /*!< Unprotect the IRQ status var - IRQ enable on a single thread environment (MCU) ; Mutex unlock on a multi thread environment */
#define platformLedOff( port, pin ) platformGpioSet(port, pin)
#define platformLedOn( port, pin ) platformGpioClear(port, pin)
#define platformLedOff( port, pin ) api_hal_light_set(pin, 0x00)
#define platformLedOn( port, pin ) api_hal_light_set(pin, 0xFF)
#define platformGpioSet( port, pin ) HAL_GPIO_WritePin(port, pin, GPIO_PIN_SET) /*!< Turns the given GPIO High */
#define platformGpioClear( port, pin ) HAL_GPIO_WritePin(port, pin, GPIO_PIN_RESET) /*!< Turns the given GPIO Low */

View File

@@ -1,4 +1,3 @@
#include <furi.h>
#include "app-template.h"
/*

View File

@@ -1,6 +1,8 @@
#pragma once
#include "callback-connector.h"
#include <furi.h>
#include <api-hal.h>
#include <gui/gui.h>
#include <input/input.h>

View File

@@ -1,5 +1,7 @@
#pragma once
#include <furi.h>
#include <api-hal.h>
class CyfralTiming {
public:

View File

@@ -1,7 +1,7 @@
#include <bq25896.h>
#include <bq25896_reg.h>
#include <i2c.h>
#include <api-hal.h>
uint8_t bit_reverse(uint8_t b) {
b = (b & 0xF0) >> 4 | (b & 0x0F) << 4;
@@ -11,13 +11,17 @@ uint8_t bit_reverse(uint8_t b) {
}
bool bq25896_read(uint8_t address, uint8_t* data, size_t size) {
if (HAL_I2C_Master_Transmit(&POWER_I2C, BQ25896_ADDRESS, &address, 1, 2000) != HAL_OK) {
return false;
}
if (HAL_I2C_Master_Receive(&POWER_I2C, BQ25896_ADDRESS, data, size, 2000) != HAL_OK) {
return false;
}
return true;
bool ret;
with_api_hal_i2c(bool, &ret, (){
if (HAL_I2C_Master_Transmit(&POWER_I2C, BQ25896_ADDRESS, &address, 1, 2000) != HAL_OK) {
return false;
}
if (HAL_I2C_Master_Receive(&POWER_I2C, BQ25896_ADDRESS, data, size, 2000) != HAL_OK) {
return false;
}
return true;
});
return ret;
}
bool bq25896_read_reg(uint8_t address, uint8_t* data) {
@@ -27,11 +31,14 @@ bool bq25896_read_reg(uint8_t address, uint8_t* data) {
bool bq25896_write_reg(uint8_t address, uint8_t* data) {
uint8_t buffer[2] = { address, *data };
if (HAL_I2C_Master_Transmit(&POWER_I2C, BQ25896_ADDRESS, buffer, 2, 2000) != HAL_OK) {
return false;
}
return true;
bool ret;
with_api_hal_i2c(bool, &ret, (){
if (HAL_I2C_Master_Transmit(&POWER_I2C, BQ25896_ADDRESS, buffer, 2, 2000) != HAL_OK) {
return false;
}
return true;
});
return ret;
}
typedef struct {

View File

@@ -1,30 +1,38 @@
#include <bq27220.h>
#include <bq27220_reg.h>
#include <i2c.h>
#include <api-hal.h>
#include <stdbool.h>
uint16_t bq27220_read_word(uint8_t address) {
uint8_t data[2] = { address };
if (HAL_I2C_Master_Transmit(&POWER_I2C, BQ27220_ADDRESS, data, 1, 2000) != HAL_OK) {
return BQ27220_ERROR;
}
uint16_t ret;
with_api_hal_i2c(uint16_t, &ret, (){
if (HAL_I2C_Master_Transmit(&POWER_I2C, BQ27220_ADDRESS, data, 1, 2000) != HAL_OK) {
return BQ27220_ERROR;
}
if (HAL_I2C_Master_Receive(&POWER_I2C, BQ27220_ADDRESS, data, 2, 2000) != HAL_OK) {
return BQ27220_ERROR;
}
return *(uint16_t*)data;
if (HAL_I2C_Master_Receive(&POWER_I2C, BQ27220_ADDRESS, data, 2, 2000) != HAL_OK) {
return BQ27220_ERROR;
}
return *(uint16_t*)data;
});
return ret;
}
bool bq27220_control(uint16_t control) {
uint8_t data[3];
data[0] = CommandControl;
data[1] = (control>>8) & 0xFF;
data[2] = control & 0xFF;
if (HAL_I2C_Master_Transmit(&POWER_I2C, BQ27220_ADDRESS, data, 3, 2000) != HAL_OK) {
return false;
}
return true;
bool ret;
with_api_hal_i2c(bool, &ret, (){
uint8_t data[3];
data[0] = CommandControl;
data[1] = (control>>8) & 0xFF;
data[2] = control & 0xFF;
if (HAL_I2C_Master_Transmit(&POWER_I2C, BQ27220_ADDRESS, data, 3, 2000) != HAL_OK) {
return false;
}
return true;
});
return ret;
}
void bq27220_init() {

90
lib/drivers/lp5562.c Normal file
View File

@@ -0,0 +1,90 @@
#include "lp5562.h"
#include "lp5562_reg.h"
#include <api-hal.h>
#include <stdio.h>
bool lp5562_read(uint8_t address, uint8_t* data, size_t size) {
bool ret;
with_api_hal_i2c(bool, &ret, (){
if (HAL_I2C_Master_Transmit(&POWER_I2C, LP5562_ADDRESS, &address, 1, 2000) != HAL_OK) {
return false;
}
if (HAL_I2C_Master_Receive(&POWER_I2C, LP5562_ADDRESS, data, size, 2000) != HAL_OK) {
return false;
}
return true;
});
return ret;
}
bool lp5562_read_reg(uint8_t address, uint8_t* data) {
return lp5562_read(address, data, 1);
}
bool lp5562_write_reg(uint8_t address, uint8_t *data) {
uint8_t buffer[2] = { address, *data };
bool ret;
with_api_hal_i2c(bool, &ret, (){
if (HAL_I2C_Master_Transmit(&POWER_I2C, LP5562_ADDRESS, buffer, 2, 2000) != HAL_OK) {
return false;
}
return true;
});
return ret;
}
void lp5562_reset() {
Reg0D_Reset reg = {.value = 0xFF };
lp5562_write_reg(0x0D, (uint8_t*)&reg);
}
void lp5562_configure() {
Reg08_Config config = { .INT_CLK_EN = true, .PS_EN = true, .PWM_HF = true };
lp5562_write_reg(0x08, (uint8_t*)&config);
Reg70_LedMap map = {
.red = EngSelectI2C,
.green = EngSelectI2C,
.blue = EngSelectI2C,
.white = EngSelectI2C,
};
lp5562_write_reg(0x70, (uint8_t*)&map);
}
void lp5562_enable() {
Reg00_Enable reg = { .CHIP_EN = true, .LOG_EN = true };
lp5562_write_reg(0x00, (uint8_t*)&reg);
}
void lp5562_set_channel_current(LP5562Channel channel, uint8_t value) {
uint8_t reg_no;
if (channel == LP5562ChannelRed) {
reg_no = 0x07;
} else if (channel == LP5562ChannelGreen) {
reg_no = 0x06;
} else if (channel == LP5562ChannelBlue) {
reg_no = 0x05;
} else if (channel == LP5562ChannelWhite) {
reg_no = 0x0F;
} else {
return;
}
lp5562_write_reg(reg_no, &value);
}
void lp5562_set_channel_value(LP5562Channel channel, uint8_t value) {
uint8_t reg_no;
if (channel == LP5562ChannelRed) {
reg_no = 0x04;
} else if (channel == LP5562ChannelGreen) {
reg_no = 0x03;
} else if (channel == LP5562ChannelBlue) {
reg_no = 0x02;
} else if (channel == LP5562ChannelWhite) {
reg_no = 0x0E;
} else {
return;
}
lp5562_write_reg(reg_no, &value);
}

22
lib/drivers/lp5562.h Normal file
View File

@@ -0,0 +1,22 @@
#pragma once
#include <stdint.h>
#include <stdbool.h>
typedef enum {
LP5562ChannelRed,
LP5562ChannelGreen,
LP5562ChannelBlue,
LP5562ChannelWhite,
} LP5562Channel;
/* Initialize Driver */
void lp5562_reset();
void lp5562_configure();
void lp5562_enable();
void lp5562_set_channel_current(LP5562Channel channel, uint8_t value);
void lp5562_set_channel_value(LP5562Channel channel, uint8_t value);

86
lib/drivers/lp5562_reg.h Normal file
View File

@@ -0,0 +1,86 @@
#pragma once
#if BITS_BIG_ENDIAN == 1
#error Bit structures defined in this file is not portable to BE
#endif
#define LP5562_ADDRESS 0x60
typedef enum {
EngExecHold=0b00,
EngExecStep=0b01,
EngExecRun=0b10,
EngExecPC=0b11,
} EngExec;
typedef struct {
EngExec ENG3_EXEC:2;
EngExec ENG2_EXEC:2;
EngExec ENG1_EXEC:2;
bool CHIP_EN:1;
bool LOG_EN:1;
} Reg00_Enable;
typedef enum {
EngModeDisable=0b00,
EngModeLoad=0b01,
EngModeRun=0b10,
EngModeDirect=0b11,
} EngMode;
typedef struct {
EngMode ENG3_MODE:2;
EngMode ENG2_MODE:2;
EngMode ENG1_MODE:2;
uint8_t reserved:2;
} Reg01_OpMode;
typedef struct {
bool INT_CLK_EN:1;
bool CLK_DET_EN:1;
uint8_t reserved0:3;
bool PS_EN:1;
bool PWM_HF:1;
uint8_t reserved1:1;
} Reg08_Config;
typedef struct {
uint8_t pc:3;
uint8_t reserved:5;
} Reg09_Engine1PC;
typedef struct {
uint8_t pc:3;
uint8_t reserved:5;
} Reg0A_Engine2PC;
typedef struct {
uint8_t pc:3;
uint8_t reserved:5;
} Reg0B_Engine3PC;
typedef struct {
bool ENG3_INT:1;
bool ENG2_INT:1;
bool ENG1_INT:1;
bool EXT_CLK_USED:1;
uint8_t reserved:5;
} Reg0C_Status;
typedef struct {
uint8_t value;
} Reg0D_Reset;
typedef enum {
EngSelectI2C=0b00,
EngSelectEngine1=0b01,
EngSelectEngine2=0b10,
EngSelectEngine3=0b11,
} EngSelect;
typedef struct {
EngSelect blue:2;
EngSelect green:2;
EngSelect red:2;
EngSelect white:2;
} Reg70_LedMap;

View File

@@ -1,5 +1,6 @@
#pragma once
#include <furi.h>
#include <api-hal.h>
#include "one_wire_timings.h"
class OneWireMaster {

View File

@@ -1,5 +1,6 @@
#pragma once
#include <furi.h>
#include <api-hal.h>
#include "one_wire_timings.h"
class OneWireDevice;