Skip to content

Commit

Permalink
Merge branch 'dev' into release-candidate
Browse files Browse the repository at this point in the history
  • Loading branch information
skotopes committed Mar 25, 2022
2 parents e1ff6da + 76f524d commit e74aa2d
Show file tree
Hide file tree
Showing 29 changed files with 196 additions and 322 deletions.
4 changes: 2 additions & 2 deletions applications/bad_usb/bad_usb_script.c
Original file line number Diff line number Diff line change
Expand Up @@ -366,9 +366,9 @@ static bool ducky_script_preload(BadUsbScript* bad_usb, File* script_file) {
}

if(id_set) {
furi_hal_usb_set_config(&usb_hid, &bad_usb->hid_cfg);
furi_check(furi_hal_usb_set_config(&usb_hid, &bad_usb->hid_cfg));
} else {
furi_hal_usb_set_config(&usb_hid, NULL);
furi_check(furi_hal_usb_set_config(&usb_hid, NULL));
}

storage_file_seek(script_file, 0, true);
Expand Down
70 changes: 18 additions & 52 deletions applications/ibutton/helpers/pulse_sequencer.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include "pulse_sequencer.h"

#include <furi.h>
#include <callback-connector.h>
#include <furi_hal_resources.h>
#include <furi_hal.h>

void PulseSequencer::set_periods(
uint32_t* _periods,
Expand All @@ -13,74 +13,40 @@ void PulseSequencer::set_periods(
}

void PulseSequencer::start() {
callback_pointer = cbc::obtain_connector(this, &PulseSequencer::timer_elapsed_callback);
api_interrupt_add(callback_pointer, InterruptTypeTimerUpdate, this);

period_index = 1;
init_timer(periods[period_index]);
pin_state = pin_start_state;
hal_gpio_write(&ibutton_gpio, pin_state);
pin_state = !pin_state;

HAL_TIM_Base_Start_IT(&htim1);
hal_gpio_init(&ibutton_gpio, GpioModeOutputOpenDrain, GpioPullNo, GpioSpeedVeryHigh);
furi_hal_ibutton_emulate_start(
periods[period_index], PulseSequencer::timer_elapsed_callback, this);
}

void PulseSequencer::stop() {
HAL_TIM_Base_Stop_IT(&htim1);

api_interrupt_remove(callback_pointer, InterruptTypeTimerUpdate);
deinit_timer();
furi_hal_ibutton_emulate_stop();
}

PulseSequencer::~PulseSequencer() {
stop();
}

void PulseSequencer::init_timer(uint32_t period) {
TIM_ClockConfigTypeDef sClockSourceConfig = {0};
void PulseSequencer::timer_elapsed_callback(void* context) {
PulseSequencer* self = static_cast<PulseSequencer*>(context);

htim1.Instance = TIM1;
htim1.Init.Prescaler = 0;
htim1.Init.CounterMode = TIM_COUNTERMODE_UP;
htim1.Init.Period = period;
htim1.Init.ClockDivision = TIM_CLOCKDIVISION_DIV1;
htim1.Init.RepetitionCounter = 0;
htim1.Init.AutoReloadPreload = TIM_AUTORELOAD_PRELOAD_DISABLE;
if(HAL_TIM_Base_Init(&htim1) != HAL_OK) {
Error_Handler();
}
sClockSourceConfig.ClockSource = TIM_CLOCKSOURCE_INTERNAL;
if(HAL_TIM_ConfigClockSource(&htim1, &sClockSourceConfig) != HAL_OK) {
Error_Handler();
}
furi_hal_ibutton_emulate_set_next(self->periods[self->period_index]);

HAL_NVIC_EnableIRQ(TIM1_UP_TIM16_IRQn);

hal_gpio_init(&ibutton_gpio, GpioModeOutputOpenDrain, GpioPullNo, GpioSpeedVeryHigh);
}

void PulseSequencer::deinit_timer() {
}

void PulseSequencer::timer_elapsed_callback(void* hw, void* context) {
PulseSequencer* _this = static_cast<PulseSequencer*>(context);
TIM_HandleTypeDef* htim = static_cast<TIM_HandleTypeDef*>(hw);

if(htim->Instance == TIM1) {
htim->Instance->ARR = _this->periods[_this->period_index];

if(_this->period_index == 0) {
_this->pin_state = _this->pin_start_state;
} else {
_this->pin_state = !_this->pin_state;
}
if(self->period_index == 0) {
self->pin_state = self->pin_start_state;
} else {
self->pin_state = !self->pin_state;
}

hal_gpio_write(&ibutton_gpio, _this->pin_state);
hal_gpio_write(&ibutton_gpio, self->pin_state);

_this->period_index++;
self->period_index++;

if(_this->period_index == _this->periods_count) {
_this->period_index = 0;
}
if(self->period_index == self->periods_count) {
self->period_index = 0;
}
}
6 changes: 3 additions & 3 deletions applications/ibutton/helpers/pulse_sequencer.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ class PulseSequencer {
bool pin_state;

void init_timer(uint32_t period);
void deinit_timer();

void reset_period_index(PulseSequencer* _this);

void (*callback_pointer)(void*, void*);
void timer_elapsed_callback(void* hcomp, void* comp_ctx);
};

static void timer_elapsed_callback(void* comp_ctx);
};
4 changes: 3 additions & 1 deletion applications/ibutton/scene/ibutton_scene_readed_key_menu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ void iButtonSceneReadedKeyMenu::on_enter(iButtonApp* app) {
Submenu* submenu = view_manager->get_submenu();
auto callback = cbc::obtain_connector(this, &iButtonSceneReadedKeyMenu::submenu_callback);

submenu_add_item(submenu, "Write", SubmenuIndexWrite, callback, app);
if(app->get_key()->get_key_type() == iButtonKeyType::KeyDallas) {
submenu_add_item(submenu, "Write", SubmenuIndexWrite, callback, app);
}
submenu_add_item(submenu, "Name and save", SubmenuIndexNameAndSave, callback, app);
submenu_add_item(submenu, "Emulate", SubmenuIndexEmulate, callback, app);
submenu_add_item(submenu, "Read new key", SubmenuIndexReadNewKey, callback, app);
Expand Down
4 changes: 3 additions & 1 deletion applications/ibutton/scene/ibutton_scene_saved_key_menu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,9 @@ void iButtonSceneSavedKeyMenu::on_enter(iButtonApp* app) {
auto callback = cbc::obtain_connector(this, &iButtonSceneSavedKeyMenu::submenu_callback);

submenu_add_item(submenu, "Emulate", SubmenuIndexEmulate, callback, app);
submenu_add_item(submenu, "Write", SubmenuIndexWrite, callback, app);
if(app->get_key()->get_key_type() == iButtonKeyType::KeyDallas) {
submenu_add_item(submenu, "Write", SubmenuIndexWrite, callback, app);
}
submenu_add_item(submenu, "Edit", SubmenuIndexEdit, callback, app);
submenu_add_item(submenu, "Delete", SubmenuIndexDelete, callback, app);
submenu_add_item(submenu, "Info", SubmenuIndexInfo, callback, app);
Expand Down
2 changes: 1 addition & 1 deletion applications/nfc/helpers/nfc_mf_classic_dict.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ bool nfc_mf_classic_dict_get_next_key(Stream* stream, uint64_t* key) {

bool next_key_read = false;
while(!next_key_read) {
if(stream_read_line(stream, next_line)) break;
if(!stream_read_line(stream, next_line)) break;
if(string_get_char(next_line, 0) == '#') continue;
if(string_size(next_line) != NFC_MF_CLASSIC_KEY_LEN) continue;
for(uint8_t i = 0; i < 12; i += 2) {
Expand Down
10 changes: 5 additions & 5 deletions applications/rpc/rpc_cli.c
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
typedef struct {
Cli* cli;
bool session_close_request;
SemaphoreHandle_t terminate_semaphore;
osSemaphoreId_t terminate_semaphore;
} CliRpc;

#define CLI_READ_BUFFER_SIZE 64
Expand All @@ -32,7 +32,7 @@ static void rpc_session_terminated_callback(void* context) {
furi_check(context);
CliRpc* cli_rpc = context;

xSemaphoreGive(cli_rpc->terminate_semaphore);
osSemaphoreRelease(cli_rpc->terminate_semaphore);
}

void rpc_cli_command_start_session(Cli* cli, string_t args, void* context) {
Expand All @@ -47,7 +47,7 @@ void rpc_cli_command_start_session(Cli* cli, string_t args, void* context) {
}

CliRpc cli_rpc = {.cli = cli, .session_close_request = false};
cli_rpc.terminate_semaphore = xSemaphoreCreateBinary();
cli_rpc.terminate_semaphore = osSemaphoreNew(1, 0, NULL);
rpc_session_set_context(rpc_session, &cli_rpc);
rpc_session_set_send_bytes_callback(rpc_session, rpc_send_bytes_callback);
rpc_session_set_close_callback(rpc_session, rpc_session_close_callback);
Expand All @@ -71,9 +71,9 @@ void rpc_cli_command_start_session(Cli* cli, string_t args, void* context) {

rpc_session_close(rpc_session);

furi_check(xSemaphoreTake(cli_rpc.terminate_semaphore, portMAX_DELAY));
furi_check(osSemaphoreAcquire(cli_rpc.terminate_semaphore, osWaitForever) == osOK);

vSemaphoreDelete(cli_rpc.terminate_semaphore);
osSemaphoreDelete(cli_rpc.terminate_semaphore);

free(buffer);
furi_hal_usb_unlock();
Expand Down
24 changes: 0 additions & 24 deletions firmware/targets/f7/Inc/main.h
Original file line number Diff line number Diff line change
Expand Up @@ -117,30 +117,6 @@ void Error_Handler(void);
#define SPI_R_SCK_GPIO_Port GPIOA
#define SPI_R_SCK_Pin GPIO_PIN_5

extern TIM_HandleTypeDef htim1;
extern TIM_HandleTypeDef htim2;
extern TIM_HandleTypeDef htim16;

#define TIM_A htim1
#define TIM_B htim2
#define TIM_C htim16

#define SPEAKER_TIM htim16
#define SPEAKER_CH TIM_CHANNEL_1

#define LFRFID_TIM htim1
#define LFRFID_CH TIM_CHANNEL_1

#define INFRARED_TX_TIM htim1
#define INFRARED_TX_CH TIM_CHANNEL_3

// only for reference
// INFRARED RX timer dont exist in F2
// and timer need more data to init (NVIC IRQn to set priority)
#define INFRARED_RX_TIM htim2
#define INFRARED_RX_FALLING_CH TIM_CHANNEL_1
#define INFRARED_RX_RISING_CH TIM_CHANNEL_2

#define NFC_IRQ_Pin RFID_PULL_Pin
#define NFC_IRQ_GPIO_Port RFID_PULL_GPIO_Port

Expand Down
8 changes: 0 additions & 8 deletions firmware/targets/f7/Src/gpio.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,6 @@
void MX_GPIO_Init(void) {
GPIO_InitTypeDef GPIO_InitStruct = {0};

/* GPIO Ports Clock Enable */
__HAL_RCC_GPIOA_CLK_ENABLE();
__HAL_RCC_GPIOB_CLK_ENABLE();
__HAL_RCC_GPIOC_CLK_ENABLE();
__HAL_RCC_GPIOD_CLK_ENABLE();
__HAL_RCC_GPIOE_CLK_ENABLE();
__HAL_RCC_GPIOH_CLK_ENABLE();

/*Configure GPIO pin : PtPin */
GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING_FALLING;
GPIO_InitStruct.Pull = GPIO_PULLUP;
Expand Down
83 changes: 1 addition & 82 deletions firmware/targets/f7/Src/stm32wbxx_hal_msp.c
Original file line number Diff line number Diff line change
@@ -1,92 +1,11 @@
/* USER CODE BEGIN Header */
/**
******************************************************************************
* File Name : stm32wbxx_hal_msp.c
* Description : This file provides code for the MSP Initialization
* and de-Initialization codes.
******************************************************************************
* @attention
*
* <h2><center>&copy; Copyright (c) 2020 STMicroelectronics.
* All rights reserved.</center></h2>
*
* This software component is licensed by ST under Ultimate Liberty license
* SLA0044, the "License"; You may not use this file except in compliance with
* the License. You may obtain a copy of the License at:
* www.st.com/SLA0044
*
******************************************************************************
*/
/* USER CODE END Header */

/* Includes ------------------------------------------------------------------*/
#include "main.h"
/* USER CODE BEGIN Includes */

/* USER CODE END Includes */

/* Private typedef -----------------------------------------------------------*/
/* USER CODE BEGIN TD */

/* USER CODE END TD */

/* Private define ------------------------------------------------------------*/
/* USER CODE BEGIN Define */

/* USER CODE END Define */

/* Private macro -------------------------------------------------------------*/
/* USER CODE BEGIN Macro */

/* USER CODE END Macro */

/* Private variables ---------------------------------------------------------*/
/* USER CODE BEGIN PV */

/* USER CODE END PV */

/* Private function prototypes -----------------------------------------------*/
/* USER CODE BEGIN PFP */

/* USER CODE END PFP */

/* External functions --------------------------------------------------------*/
/* USER CODE BEGIN ExternalFunctions */

/* USER CODE END ExternalFunctions */

/* USER CODE BEGIN 0 */

/* USER CODE END 0 */
/**
* Initializes the Global MSP.
*/
void HAL_MspInit(void) {
/* USER CODE BEGIN MspInit 0 */

/* USER CODE END MspInit 0 */

__HAL_RCC_HSEM_CLK_ENABLE();

/* System interrupt init*/
/* PendSV_IRQn interrupt configuration */
HAL_NVIC_SetPriority(PendSV_IRQn, 15, 0);

/* Peripheral interrupt init */
/* RCC_IRQn interrupt configuration */
HAL_NVIC_SetPriority(RCC_IRQn, 5, 0);
HAL_NVIC_EnableIRQ(RCC_IRQn);
/* HSEM_IRQn interrupt configuration */

HAL_NVIC_SetPriority(HSEM_IRQn, 5, 0);
HAL_NVIC_EnableIRQ(HSEM_IRQn);

/* USER CODE BEGIN MspInit 1 */

/* USER CODE END MspInit 1 */
}

/* USER CODE BEGIN 1 */

/* USER CODE END 1 */

/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/
Loading

0 comments on commit e74aa2d

Please sign in to comment.