Merge branch 'flipperdevices:dev' into dev

This commit is contained in:
Eng1n33r
2022-06-09 15:03:18 +03:00
committed by GitHub
56 changed files with 1365 additions and 841 deletions
+87 -17
View File
@@ -1,4 +1,5 @@
#include "lp5562.h"
#include "furi/common_defines.h"
#include "lp5562_reg.h"
#include <furi_hal.h>
@@ -79,27 +80,32 @@ uint8_t lp5562_get_channel_value(FuriHalI2cBusHandle* handle, LP5562Channel chan
return value;
}
static void
lp5562_set_channel_src(FuriHalI2cBusHandle* handle, LP5562Channel channel, LP5562Engine src) {
void lp5562_set_channel_src(FuriHalI2cBusHandle* handle, LP5562Channel channel, LP5562Engine src) {
uint8_t reg_val = 0;
uint8_t bit_offset = 0;
if(channel == LP5562ChannelRed) {
bit_offset = 4;
} else if(channel == LP5562ChannelGreen) {
bit_offset = 2;
} else if(channel == LP5562ChannelBlue) {
bit_offset = 0;
} else if(channel == LP5562ChannelWhite) {
bit_offset = 6;
} else {
return;
}
do {
if(channel & LP5562ChannelRed) {
bit_offset = 4;
channel &= ~LP5562ChannelRed;
} else if(channel & LP5562ChannelGreen) {
bit_offset = 2;
channel &= ~LP5562ChannelGreen;
} else if(channel & LP5562ChannelBlue) {
bit_offset = 0;
channel &= ~LP5562ChannelBlue;
} else if(channel & LP5562ChannelWhite) {
bit_offset = 6;
channel &= ~LP5562ChannelWhite;
} else {
return;
}
furi_hal_i2c_read_reg_8(handle, LP5562_ADDRESS, 0x70, &reg_val, LP5562_I2C_TIMEOUT);
reg_val &= ~(0x3 << bit_offset);
reg_val |= ((src & 0x03) << bit_offset);
furi_hal_i2c_write_reg_8(handle, LP5562_ADDRESS, 0x70, reg_val, LP5562_I2C_TIMEOUT);
furi_hal_i2c_read_reg_8(handle, LP5562_ADDRESS, 0x70, &reg_val, LP5562_I2C_TIMEOUT);
reg_val &= ~(0x3 << bit_offset);
reg_val |= ((src & 0x03) << bit_offset);
furi_hal_i2c_write_reg_8(handle, LP5562_ADDRESS, 0x70, reg_val, LP5562_I2C_TIMEOUT);
} while(channel);
}
void lp5562_execute_program(
@@ -151,6 +157,19 @@ void lp5562_execute_program(
furi_hal_i2c_write_reg_8(handle, LP5562_ADDRESS, 0x00, enable_reg, LP5562_I2C_TIMEOUT);
}
void lp5562_stop_program(FuriHalI2cBusHandle* handle, LP5562Engine eng) {
if((eng < LP5562Engine1) || (eng > LP5562Engine3)) return;
uint8_t reg_val = 0;
uint8_t bit_offset = 0;
// Engine configuration
bit_offset = (3 - eng) * 2;
furi_hal_i2c_read_reg_8(handle, LP5562_ADDRESS, 0x01, &reg_val, LP5562_I2C_TIMEOUT);
reg_val &= ~(0x3 << bit_offset);
reg_val |= (0x00 << bit_offset); // Disabled
furi_hal_i2c_write_reg_8(handle, LP5562_ADDRESS, 0x01, reg_val, LP5562_I2C_TIMEOUT);
}
void lp5562_execute_ramp(
FuriHalI2cBusHandle* handle,
LP5562Engine eng,
@@ -194,3 +213,54 @@ void lp5562_execute_ramp(
// Write end value to register
lp5562_set_channel_value(handle, ch, val_end);
}
void lp5562_execute_blink(
FuriHalI2cBusHandle* handle,
LP5562Engine eng,
LP5562Channel ch,
uint16_t on_time,
uint16_t period,
uint8_t brightness) {
// Temporary switch to constant value from register
lp5562_set_channel_src(handle, ch, LP5562Direct);
// Prepare command sequence
uint16_t program[16];
uint16_t time_step = 0;
uint8_t prescaller = 0;
program[0] = 0x4000 | brightness; // Set PWM
time_step = on_time * 2;
if(time_step > 0x3F) {
time_step /= 32;
prescaller = 1;
} else {
prescaller = 0;
}
if(time_step == 0) {
time_step = 1;
} else if(time_step > 0x3F)
time_step = 0x3F;
program[1] = (prescaller << 14) | (time_step << 8); // Delay
program[2] = 0x4000 | 0; // Set PWM
time_step = (period - on_time) * 2;
if(time_step > 0x3F) {
time_step /= 32;
prescaller = 1;
} else {
prescaller = 0;
}
if(time_step == 0) {
time_step = 1;
} else if(time_step > 0x3F)
time_step = 0x3F;
program[3] = (prescaller << 14) | (time_step << 8); // Delay
program[4] = 0x0000; // Go to start
// Execute program
lp5562_execute_program(handle, eng, ch, program);
}
+19 -4
View File
@@ -6,10 +6,10 @@
/** Channel types */
typedef enum {
LP5562ChannelRed,
LP5562ChannelGreen,
LP5562ChannelBlue,
LP5562ChannelWhite,
LP5562ChannelRed = (1 << 0),
LP5562ChannelGreen = (1 << 1),
LP5562ChannelBlue = (1 << 2),
LP5562ChannelWhite = (1 << 3),
} LP5562Channel;
typedef enum {
@@ -37,6 +37,9 @@ void lp5562_set_channel_value(FuriHalI2cBusHandle* handle, LP5562Channel channel
/** Get channel PWM value */
uint8_t lp5562_get_channel_value(FuriHalI2cBusHandle* handle, LP5562Channel channel);
/** Set channel source */
void lp5562_set_channel_src(FuriHalI2cBusHandle* handle, LP5562Channel channel, LP5562Engine src);
/** Execute program sequence */
void lp5562_execute_program(
FuriHalI2cBusHandle* handle,
@@ -44,6 +47,9 @@ void lp5562_execute_program(
LP5562Channel ch,
uint16_t* program);
/** Stop program sequence */
void lp5562_stop_program(FuriHalI2cBusHandle* handle, LP5562Engine eng);
/** Execute ramp program sequence */
void lp5562_execute_ramp(
FuriHalI2cBusHandle* handle,
@@ -52,3 +58,12 @@ void lp5562_execute_ramp(
uint8_t val_start,
uint8_t val_end,
uint16_t time);
/** Start blink program sequence */
void lp5562_execute_blink(
FuriHalI2cBusHandle* handle,
LP5562Engine eng,
LP5562Channel ch,
uint16_t on_time,
uint16_t period,
uint8_t brightness);
+2 -1
View File
@@ -397,7 +397,8 @@ bool emv_read_bank_card(FuriHalNfcTxRxContext* tx_rx, EmvApplication* emv_app) {
bool emv_card_emulation(FuriHalNfcTxRxContext* tx_rx) {
furi_assert(tx_rx);
bool emulation_complete = false;
memset(tx_rx, 0, sizeof(FuriHalNfcTxRxContext));
tx_rx->tx_bits = 0;
tx_rx->tx_rx_type = FuriHalNfcTxRxTypeDefault;
do {
FURI_LOG_D(TAG, "Read select PPSE command");
+5 -2
View File
@@ -270,7 +270,9 @@ static bool mf_classic_auth(
MfClassicKey key_type,
Crypto1* crypto) {
bool auth_success = false;
memset(tx_rx, 0, sizeof(FuriHalNfcTxRxContext));
memset(tx_rx->tx_data, 0, sizeof(tx_rx->tx_data));
memset(tx_rx->tx_parity, 0, sizeof(tx_rx->tx_parity));
tx_rx->tx_rx_type = FuriHalNfcTxRxTypeDefault;
do {
if(key_type == MfClassicKeyA) {
@@ -372,7 +374,8 @@ bool mf_classic_read_block(
bool read_block_success = false;
uint8_t plain_cmd[4] = {MF_CLASSIC_READ_SECT_CMD, block_num, 0x00, 0x00};
nfca_append_crc16(plain_cmd, 2);
memset(tx_rx, 0, sizeof(FuriHalNfcTxRxContext));
memset(tx_rx->tx_data, 0, sizeof(tx_rx->tx_data));
memset(tx_rx->tx_parity, 0, sizeof(tx_rx->tx_parity));
for(uint8_t i = 0; i < 4; i++) {
tx_rx->tx_data[i] = crypto1_byte(crypto, 0x00, 0) ^ plain_cmd[i];
+11
View File
@@ -1,4 +1,6 @@
#include "path.h"
#include "m-string.h"
#include <stddef.h>
void path_extract_filename_no_ext(const char* path, string_t filename) {
string_set(filename, path);
@@ -33,6 +35,15 @@ void path_extract_filename(string_t path, string_t name, bool trim_ext) {
}
}
void path_extract_extension(string_t path, char* ext, size_t ext_len_max) {
size_t dot = string_search_rchar(path, '.');
size_t filename_start = string_search_rchar(path, '/');
if((dot > 0) && (filename_start < dot)) {
strlcpy(ext, &(string_get_cstr(path))[dot], ext_len_max);
}
}
static inline void path_cleanup(string_t path) {
string_strim(path);
while(string_end_with_str_p(path, "/")) {
+9
View File
@@ -23,6 +23,15 @@ void path_extract_filename_no_ext(const char* path, string_t filename);
*/
void path_extract_filename(string_t path, string_t filename, bool trim_ext);
/**
* @brief Extract file extension from path.
*
* @param path path string
* @param ext output extension string
* @param ext_len_max maximum extension string length
*/
void path_extract_extension(string_t path, char* ext, size_t ext_len_max);
/**
* @brief Extract last path component
*