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:
Nikolay Minaylov 2022-03-30 18:23:40 +03:00 committed by GitHub
parent 648d8aaa54
commit 2f3ea9494e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
93 changed files with 921 additions and 1270 deletions

View File

@ -55,19 +55,19 @@ void WIEGAND::begin() {
_wiegandType = 0;
_bitCount = 0;
hal_gpio_init_simple(pinD0, GpioModeInterruptFall); // Set D0 pin as input
hal_gpio_init_simple(pinD1, GpioModeInterruptFall); // Set D1 pin as input
furi_hal_gpio_init_simple(pinD0, GpioModeInterruptFall); // Set D0 pin as input
furi_hal_gpio_init_simple(pinD1, GpioModeInterruptFall); // Set D1 pin as input
hal_gpio_add_int_callback(pinD0, input_isr_d0, this);
hal_gpio_add_int_callback(pinD1, input_isr_d1, this);
furi_hal_gpio_add_int_callback(pinD0, input_isr_d0, this);
furi_hal_gpio_add_int_callback(pinD1, input_isr_d1, this);
}
void WIEGAND::end() {
hal_gpio_remove_int_callback(pinD0);
hal_gpio_remove_int_callback(pinD1);
furi_hal_gpio_remove_int_callback(pinD0);
furi_hal_gpio_remove_int_callback(pinD1);
hal_gpio_init_simple(pinD0, GpioModeAnalog);
hal_gpio_init_simple(pinD1, GpioModeAnalog);
furi_hal_gpio_init_simple(pinD0, GpioModeAnalog);
furi_hal_gpio_init_simple(pinD1, GpioModeAnalog);
}
void WIEGAND::ReadD0() {

View File

@ -155,7 +155,7 @@ void desktop_scene_pin_input_on_exit(void* context) {
desktop->scene_manager, DesktopScenePinInput);
xTimerStop(state->timer, portMAX_DELAY);
while(xTimerIsTimerActive(state->timer)) {
delay(1);
furi_hal_delay_ms(1);
}
xTimerDelete(state->timer, portMAX_DELAY);
free(state);

View File

@ -214,7 +214,7 @@ void desktop_view_pin_input_free(DesktopViewPinInput* pin_input) {
xTimerStop(pin_input->timer, portMAX_DELAY);
while(xTimerIsTimerActive(pin_input->timer)) {
delay(1);
furi_hal_delay_ms(1);
}
xTimerDelete(pin_input->timer, portMAX_DELAY);

View File

@ -20,8 +20,8 @@ static const GpioItem gpio_item[GPIO_ITEM_COUNT] = {
void gpio_item_configure_pin(uint8_t index, GpioMode mode) {
furi_assert(index < GPIO_ITEM_COUNT);
hal_gpio_write(gpio_item[index].pin, false);
hal_gpio_init(gpio_item[index].pin, mode, GpioPullNo, GpioSpeedVeryHigh);
furi_hal_gpio_write(gpio_item[index].pin, false);
furi_hal_gpio_init(gpio_item[index].pin, mode, GpioPullNo, GpioSpeedVeryHigh);
}
void gpio_item_configure_all_pins(GpioMode mode) {
@ -32,7 +32,7 @@ void gpio_item_configure_all_pins(GpioMode mode) {
void gpio_item_set_pin(uint8_t index, bool level) {
furi_assert(index < GPIO_ITEM_COUNT);
hal_gpio_write(gpio_item[index].pin, level);
furi_hal_gpio_write(gpio_item[index].pin, level);
}
void gpio_item_set_all_pins(bool level) {

View File

@ -134,8 +134,8 @@ static void usb_uart_update_ctrl_lines(UsbUartBridge* usb_uart) {
furi_assert((usb_uart->cfg.flow_pins - 1) < (sizeof(flow_pins) / sizeof(flow_pins[0])));
uint8_t state = furi_hal_cdc_get_ctrl_line_state(usb_uart->cfg.vcp_ch);
hal_gpio_write(flow_pins[usb_uart->cfg.flow_pins - 1][0], !(state & USB_CDC_BIT_RTS));
hal_gpio_write(flow_pins[usb_uart->cfg.flow_pins - 1][1], !(state & USB_CDC_BIT_DTR));
furi_hal_gpio_write(flow_pins[usb_uart->cfg.flow_pins - 1][0], !(state & USB_CDC_BIT_RTS));
furi_hal_gpio_write(flow_pins[usb_uart->cfg.flow_pins - 1][1], !(state & USB_CDC_BIT_DTR));
}
}
@ -161,8 +161,10 @@ static int32_t usb_uart_worker(void* context) {
usb_uart_set_baudrate(usb_uart, usb_uart->cfg.baudrate);
if(usb_uart->cfg.flow_pins != 0) {
furi_assert((usb_uart->cfg.flow_pins - 1) < (sizeof(flow_pins) / sizeof(flow_pins[0])));
hal_gpio_init_simple(flow_pins[usb_uart->cfg.flow_pins - 1][0], GpioModeOutputPushPull);
hal_gpio_init_simple(flow_pins[usb_uart->cfg.flow_pins - 1][1], GpioModeOutputPushPull);
furi_hal_gpio_init_simple(
flow_pins[usb_uart->cfg.flow_pins - 1][0], GpioModeOutputPushPull);
furi_hal_gpio_init_simple(
flow_pins[usb_uart->cfg.flow_pins - 1][1], GpioModeOutputPushPull);
usb_uart_update_ctrl_lines(usb_uart);
}
@ -219,18 +221,18 @@ static int32_t usb_uart_worker(void* context) {
}
if(usb_uart->cfg.flow_pins != usb_uart->cfg_new.flow_pins) {
if(usb_uart->cfg.flow_pins != 0) {
hal_gpio_init_simple(
furi_hal_gpio_init_simple(
flow_pins[usb_uart->cfg.flow_pins - 1][0], GpioModeAnalog);
hal_gpio_init_simple(
furi_hal_gpio_init_simple(
flow_pins[usb_uart->cfg.flow_pins - 1][1], GpioModeAnalog);
}
if(usb_uart->cfg_new.flow_pins != 0) {
furi_assert(
(usb_uart->cfg_new.flow_pins - 1) <
(sizeof(flow_pins) / sizeof(flow_pins[0])));
hal_gpio_init_simple(
furi_hal_gpio_init_simple(
flow_pins[usb_uart->cfg_new.flow_pins - 1][0], GpioModeOutputPushPull);
hal_gpio_init_simple(
furi_hal_gpio_init_simple(
flow_pins[usb_uart->cfg_new.flow_pins - 1][1], GpioModeOutputPushPull);
}
usb_uart->cfg.flow_pins = usb_uart->cfg_new.flow_pins;
@ -251,8 +253,8 @@ static int32_t usb_uart_worker(void* context) {
furi_hal_usb_unlock();
furi_hal_usb_set_config(usb_mode_prev, NULL);
if(usb_uart->cfg.flow_pins != 0) {
hal_gpio_init_simple(flow_pins[usb_uart->cfg.flow_pins - 1][0], GpioModeAnalog);
hal_gpio_init_simple(flow_pins[usb_uart->cfg.flow_pins - 1][1], GpioModeAnalog);
furi_hal_gpio_init_simple(flow_pins[usb_uart->cfg.flow_pins - 1][0], GpioModeAnalog);
furi_hal_gpio_init_simple(flow_pins[usb_uart->cfg.flow_pins - 1][1], GpioModeAnalog);
}
osThreadFlagsSet(furi_thread_get_thread_id(usb_uart->tx_thread), WorkerEvtTxStop);

View File

@ -223,7 +223,7 @@ void ibutton_cli_emulate(Cli* cli, string_t args) {
ibutton_worker_emulate_start(worker, key);
while(!cli_cmd_interrupt_received(cli)) {
delay(100);
furi_hal_delay_ms(100);
};
ibutton_worker_stop(worker);
} while(false);
@ -284,7 +284,7 @@ void onewire_cli_search(Cli* cli) {
}
printf("\r\n");
}
delay(100);
furi_hal_delay_ms(100);
}
furi_hal_power_disable_otg();

View File

@ -66,7 +66,7 @@ static void infrared_cli_start_ir_rx(Cli* cli, string_t args) {
printf("Receiving INFRARED...\r\nPress Ctrl+C to abort\r\n");
while(!cli_cmd_interrupt_received(cli)) {
delay(50);
furi_hal_delay_ms(50);
}
infrared_worker_rx_stop(worker);

View File

@ -1,6 +1,6 @@
#include "input_i.h"
#define GPIO_Read(input_pin) (hal_gpio_read(input_pin.pin->pin) ^ input_pin.pin->inverted)
#define GPIO_Read(input_pin) (furi_hal_gpio_read(input_pin.pin->gpio) ^ (input_pin.pin->inverted))
static Input* input = NULL;
@ -79,7 +79,7 @@ int32_t input_srv() {
input->pin_states = malloc(input_pins_count * sizeof(InputPinState));
for(size_t i = 0; i < input_pins_count; i++) {
hal_gpio_add_int_callback(input_pins[i].pin, input_isr, NULL);
furi_hal_gpio_add_int_callback(input_pins[i].gpio, input_isr, NULL);
input->pin_states[i].pin = &input_pins[i];
input->pin_states[i].state = GPIO_Read(input->pin_states[i]);
input->pin_states[i].debounce = INPUT_DEBOUNCE_TICKS_HALF;

View File

@ -3,13 +3,13 @@
#include <furi_hal.h>
void DecoderGpioOut::process_front(bool polarity, uint32_t time) {
hal_gpio_write(&gpio_ext_pa7, polarity);
furi_hal_gpio_write(&gpio_ext_pa7, polarity);
}
DecoderGpioOut::DecoderGpioOut() {
hal_gpio_init_simple(&gpio_ext_pa7, GpioModeOutputPushPull);
furi_hal_gpio_init_simple(&gpio_ext_pa7, GpioModeOutputPushPull);
}
DecoderGpioOut::~DecoderGpioOut() {
hal_gpio_init_simple(&gpio_ext_pa7, GpioModeAnalog);
furi_hal_gpio_init_simple(&gpio_ext_pa7, GpioModeAnalog);
}

View File

@ -48,15 +48,15 @@ void RfidWriter::stop() {
void RfidWriter::write_gap(uint32_t gap_time) {
furi_hal_rfid_tim_read_stop();
delay_us(gap_time * 8);
furi_hal_delay_us(gap_time * 8);
furi_hal_rfid_tim_read_start();
}
void RfidWriter::write_bit(bool value) {
if(value) {
delay_us(T55xxTiming::data_1 * 8);
furi_hal_delay_us(T55xxTiming::data_1 * 8);
} else {
delay_us(T55xxTiming::data_0 * 8);
furi_hal_delay_us(T55xxTiming::data_0 * 8);
}
write_gap(T55xxTiming::write_gap);
}
@ -68,7 +68,7 @@ void RfidWriter::write_byte(uint8_t value) {
}
void RfidWriter::write_block(uint8_t page, uint8_t block, bool lock_bit, uint32_t data) {
delay_us(T55xxTiming::wait_time * 8);
furi_hal_delay_us(T55xxTiming::wait_time * 8);
// start gap
write_gap(T55xxTiming::start_gap);
@ -101,9 +101,9 @@ void RfidWriter::write_block(uint8_t page, uint8_t block, bool lock_bit, uint32_
write_bit((block >> 1) & 1);
write_bit((block >> 0) & 1);
delay_us(T55xxTiming::program * 8);
furi_hal_delay_us(T55xxTiming::program * 8);
delay_us(T55xxTiming::wait_time * 8);
furi_hal_delay_us(T55xxTiming::wait_time * 8);
write_reset();
}

View File

@ -88,7 +88,7 @@ void lfrfid_cli_read(Cli* cli, string_t args) {
printf("\r\n");
break;
}
delay(100);
furi_hal_delay_ms(100);
}
printf("Reading stopped\r\n");
@ -136,7 +136,7 @@ void lfrfid_cli_emulate(Cli* cli, string_t args) {
printf("Emulating RFID...\r\nPress Ctrl+C to abort\r\n");
while(!cli_cmd_interrupt_received(cli)) {
delay(100);
furi_hal_delay_ms(100);
}
printf("Emulation stopped\r\n");
emulator.stop();

View File

@ -2,12 +2,12 @@
#include <furi_hal.h>
static void comparator_trigger_callback(bool level, void* comp_ctx) {
hal_gpio_write(&gpio_ext_pa7, !level);
furi_hal_gpio_write(&gpio_ext_pa7, !level);
}
void LfRfidDebugAppSceneTune::on_enter(LfRfidDebugApp* app, bool need_restore) {
app->view_controller.switch_to<LfRfidViewTuneVM>();
hal_gpio_init_simple(&gpio_ext_pa7, GpioModeOutputPushPull);
furi_hal_gpio_init_simple(&gpio_ext_pa7, GpioModeOutputPushPull);
furi_hal_rfid_comp_set_callback(comparator_trigger_callback, this);
furi_hal_rfid_comp_start();
@ -34,7 +34,7 @@ void LfRfidDebugAppSceneTune::on_exit(LfRfidDebugApp* app) {
furi_hal_rfid_comp_stop();
furi_hal_rfid_comp_set_callback(NULL, NULL);
hal_gpio_init_simple(&gpio_ext_pa7, GpioModeAnalog);
furi_hal_gpio_init_simple(&gpio_ext_pa7, GpioModeAnalog);
furi_hal_rfid_tim_read_stop();
furi_hal_rfid_tim_reset();
furi_hal_rfid_pins_reset();

View File

@ -245,7 +245,7 @@ static void loader_thread_state_callback(FuriThreadState thread_state, void* con
* started and after task completed. In process of leakage monitoring
* both values should be taken into account.
*/
delay(20);
furi_hal_delay_ms(20);
int heap_diff = instance->free_heap_size - memmgr_get_free_heap();
FURI_LOG_I(
TAG,

View File

@ -334,7 +334,7 @@ void process_note(
if(note_record->note != N) {
furi_hal_speaker_start(note_record->note, volume);
}
delay(note_delay);
furi_hal_delay_ms(note_delay);
furi_hal_speaker_stop();
}

View File

@ -248,7 +248,7 @@ void notification_process_notification_message(
if(led_active) {
if(notification_is_any_led_layer_internal_and_not_empty(app)) {
notification_apply_notification_leds(app, led_off_values);
delay(minimal_delay);
furi_hal_delay_ms(minimal_delay);
}
led_active = false;
@ -259,7 +259,7 @@ void notification_process_notification_message(
reset_mask |= reset_blue_mask;
}
delay(notification_message->data.delay.length);
furi_hal_delay_ms(notification_message->data.delay.length);
break;
case NotificationMessageTypeDoNotReset:
reset_notifications = false;
@ -293,7 +293,7 @@ void notification_process_notification_message(
if(need_minimal_delay) {
notification_apply_notification_leds(app, led_off_values);
delay(minimal_delay);
furi_hal_delay_ms(minimal_delay);
}
}

View File

@ -334,7 +334,7 @@ int32_t storage_test_app(void* p) {
do_test_end(api, "/ext");
while(true) {
delay(1000);
furi_hal_delay_ms(1000);
}
return 0;

View File

@ -82,7 +82,7 @@ static bool sd_mount_card(StorageData* storage, bool notify) {
}
if(!result) {
delay(1000);
furi_hal_delay_ms(1000);
FURI_LOG_E(
TAG, "init cycle %d, error: %s", counter, storage_data_status_text(storage));
counter--;

View File

@ -42,11 +42,12 @@ static void subghz_chat_worker_update_rx_event_chat(void* context) {
furi_assert(context);
SubGhzChatWorker* instance = context;
SubGhzChatEvent event;
if((millis() - instance->last_time_rx_data) > SUBGHZ_CHAT_WORKER_TIMEOUT_BETWEEN_MESSAGES) {
if((furi_hal_get_tick() - instance->last_time_rx_data) >
SUBGHZ_CHAT_WORKER_TIMEOUT_BETWEEN_MESSAGES) {
event.event = SubGhzChatEventNewMessage;
osMessageQueuePut(instance->event_queue, &event, 0, osWaitForever);
}
instance->last_time_rx_data = millis();
instance->last_time_rx_data = furi_hal_get_tick();
event.event = SubGhzChatEventRXData;
osMessageQueuePut(instance->event_queue, &event, 0, osWaitForever);
}

View File

@ -40,8 +40,8 @@ void subghz_cli_command_tx_carrier(Cli* cli, string_t args, void* context) {
furi_hal_subghz_load_preset(FuriHalSubGhzPresetOok650Async);
frequency = furi_hal_subghz_set_frequency_and_path(frequency);
hal_gpio_init(&gpio_cc1101_g0, GpioModeOutputPushPull, GpioPullNo, GpioSpeedLow);
hal_gpio_write(&gpio_cc1101_g0, true);
furi_hal_gpio_init(&gpio_cc1101_g0, GpioModeOutputPushPull, GpioPullNo, GpioSpeedLow);
furi_hal_gpio_write(&gpio_cc1101_g0, true);
furi_hal_power_suppress_charge_enter();
@ -254,7 +254,7 @@ void subghz_cli_command_rx(Cli* cli, string_t args, void* context) {
furi_hal_subghz_reset();
furi_hal_subghz_load_preset(FuriHalSubGhzPresetOok650Async);
frequency = furi_hal_subghz_set_frequency_and_path(frequency);
hal_gpio_init(&gpio_cc1101_g0, GpioModeInput, GpioPullNo, GpioSpeedLow);
furi_hal_gpio_init(&gpio_cc1101_g0, GpioModeInput, GpioPullNo, GpioSpeedLow);
furi_hal_power_suppress_charge_enter();
@ -495,7 +495,7 @@ static void subghz_cli_command_chat(Cli* cli, string_t args) {
subghz_chat,
(uint8_t*)string_get_cstr(input),
strlen(string_get_cstr(input)))) {
delay(10);
furi_hal_delay_ms(10);
}
string_printf(input, "%s", string_get_cstr(name));
@ -547,7 +547,7 @@ static void subghz_cli_command_chat(Cli* cli, string_t args) {
subghz_chat,
(uint8_t*)string_get_cstr(sysmsg),
strlen(string_get_cstr(sysmsg)));
delay(10);
furi_hal_delay_ms(10);
exit = true;
break;
default:

View File

@ -140,13 +140,13 @@ bool subghz_history_add_to_history(
SubGhzProtocolDecoderBase* decoder_base = context;
if((instance->code_last_hash_data ==
subghz_protocol_decoder_base_get_hash_data(decoder_base)) &&
((millis() - instance->last_update_timestamp) < 500)) {
instance->last_update_timestamp = millis();
((furi_hal_get_tick() - instance->last_update_timestamp) < 500)) {
instance->last_update_timestamp = furi_hal_get_tick();
return false;
}
instance->code_last_hash_data = subghz_protocol_decoder_base_get_hash_data(decoder_base);
instance->last_update_timestamp = millis();
instance->last_update_timestamp = furi_hal_get_tick();
string_t text;
string_init(text);

View File

@ -62,7 +62,7 @@ void subghz_begin(SubGhz* subghz, FuriHalSubGhzPreset preset) {
furi_hal_subghz_reset();
furi_hal_subghz_idle();
furi_hal_subghz_load_preset(preset);
hal_gpio_init(&gpio_cc1101_g0, GpioModeInput, GpioPullNo, GpioSpeedLow);
furi_hal_gpio_init(&gpio_cc1101_g0, GpioModeInput, GpioPullNo, GpioSpeedLow);
subghz->txrx->txrx_state = SubGhzTxRxStateIDLE;
}
@ -77,7 +77,7 @@ uint32_t subghz_rx(SubGhz* subghz, uint32_t frequency) {
furi_hal_subghz_idle();
uint32_t value = furi_hal_subghz_set_frequency_and_path(frequency);
hal_gpio_init(&gpio_cc1101_g0, GpioModeInput, GpioPullNo, GpioSpeedLow);
furi_hal_gpio_init(&gpio_cc1101_g0, GpioModeInput, GpioPullNo, GpioSpeedLow);
furi_hal_subghz_flush_rx();
furi_hal_subghz_rx();
@ -95,8 +95,8 @@ static bool subghz_tx(SubGhz* subghz, uint32_t frequency) {
furi_assert(subghz->txrx->txrx_state != SubGhzTxRxStateSleep);
furi_hal_subghz_idle();
furi_hal_subghz_set_frequency_and_path(frequency);
hal_gpio_init(&gpio_cc1101_g0, GpioModeOutputPushPull, GpioPullNo, GpioSpeedLow);
hal_gpio_write(&gpio_cc1101_g0, true);
furi_hal_gpio_init(&gpio_cc1101_g0, GpioModeOutputPushPull, GpioPullNo, GpioSpeedLow);
furi_hal_gpio_write(&gpio_cc1101_g0, true);
bool ret = furi_hal_subghz_tx();
subghz->txrx->txrx_state = SubGhzTxRxStateTx;
return ret;

View File

@ -113,13 +113,14 @@ bool subghz_test_carrier_input(InputEvent* event, void* context) {
furi_hal_subghz_set_path(model->path);
if(model->status == SubGhzTestCarrierModelStatusRx) {
hal_gpio_init(&gpio_cc1101_g0, GpioModeInput, GpioPullNo, GpioSpeedLow);
furi_hal_gpio_init(&gpio_cc1101_g0, GpioModeInput, GpioPullNo, GpioSpeedLow);
furi_hal_subghz_rx();
} else {
hal_gpio_init(&gpio_cc1101_g0, GpioModeOutputPushPull, GpioPullNo, GpioSpeedLow);
hal_gpio_write(&gpio_cc1101_g0, true);
furi_hal_gpio_init(
&gpio_cc1101_g0, GpioModeOutputPushPull, GpioPullNo, GpioSpeedLow);
furi_hal_gpio_write(&gpio_cc1101_g0, true);
if(!furi_hal_subghz_tx()) {
hal_gpio_init(&gpio_cc1101_g0, GpioModeInput, GpioPullNo, GpioSpeedLow);
furi_hal_gpio_init(&gpio_cc1101_g0, GpioModeInput, GpioPullNo, GpioSpeedLow);
subghz_test_carrier->callback(
SubGhzTestCarrierEventOnlyRx, subghz_test_carrier->context);
}
@ -138,7 +139,7 @@ void subghz_test_carrier_enter(void* context) {
furi_hal_subghz_reset();
furi_hal_subghz_load_preset(FuriHalSubGhzPresetOok650Async);
hal_gpio_init(&gpio_cc1101_g0, GpioModeInput, GpioPullNo, GpioSpeedLow);
furi_hal_gpio_init(&gpio_cc1101_g0, GpioModeInput, GpioPullNo, GpioSpeedLow);
with_view_model(
subghz_test_carrier->view, (SubGhzTestCarrierModel * model) {

View File

@ -140,7 +140,7 @@ static bool subghz_test_packet_input(InputEvent* event, void* context) {
if(model->status == SubGhzTestPacketModelStatusRx) {
furi_hal_subghz_stop_async_rx();
} else if(model->status == SubGhzTestPacketModelStatusTx) {
subghz_encoder_princeton_for_testing_stop(instance->encoder, millis());
subghz_encoder_princeton_for_testing_stop(instance->encoder, furi_hal_get_tick());
furi_hal_subghz_stop_async_tx();
}
@ -220,7 +220,7 @@ void subghz_test_packet_exit(void* context) {
if(model->status == SubGhzTestPacketModelStatusRx) {
furi_hal_subghz_stop_async_rx();
} else if(model->status == SubGhzTestPacketModelStatusTx) {
subghz_encoder_princeton_for_testing_stop(instance->encoder, millis());
subghz_encoder_princeton_for_testing_stop(instance->encoder, furi_hal_get_tick());
furi_hal_subghz_stop_async_tx();
}
return true;

View File

@ -118,7 +118,8 @@ bool subghz_test_static_input(InputEvent* event, void* context) {
} else if(event->type == InputTypeRelease) {
if(instance->satus_tx == SubGhzTestStaticStatusTX) {
FURI_LOG_I(TAG, "TX Stop");
subghz_encoder_princeton_for_testing_stop(instance->encoder, millis());
subghz_encoder_princeton_for_testing_stop(
instance->encoder, furi_hal_get_tick());
subghz_encoder_princeton_for_testing_print_log(instance->encoder);
furi_hal_subghz_stop_async_tx();
notification_message(notification, &sequence_reset_red);
@ -141,8 +142,8 @@ void subghz_test_static_enter(void* context) {
furi_hal_subghz_reset();
furi_hal_subghz_load_preset(FuriHalSubGhzPresetOok650Async);
hal_gpio_init(&gpio_cc1101_g0, GpioModeOutputPushPull, GpioPullNo, GpioSpeedLow);
hal_gpio_write(&gpio_cc1101_g0, false);
furi_hal_gpio_init(&gpio_cc1101_g0, GpioModeOutputPushPull, GpioPullNo, GpioSpeedLow);
furi_hal_gpio_write(&gpio_cc1101_g0, false);
instance->satus_tx = SubGhzTestStaticStatusIDLE;
with_view_model(

View File

@ -78,7 +78,7 @@ void furi_concurent_app(void* p) {
uint8_t b = value->b;
a++;
b++;
delay(2);
furi_hal_delay_ms(2);
value->a = a;
value->b = b;
release_mutex(mutex, value);
@ -114,12 +114,12 @@ void test_furi_concurrent_access() {
a++;
b++;
value->a = a;
delay(10); // this is only for test, do not add delay between take/give in prod!
furi_hal_delay_ms(10); // this is only for test, do not add delay between take/give in prod!
value->b = b;
release_mutex(&mutex, value);
}
delay(50);
furi_hal_delay_ms(50);
mu_assert_pointers_eq(second_app->handler, NULL);

View File

@ -86,7 +86,7 @@ static void test_rpc_setup(void) {
rpc = furi_record_open("rpc");
for(int i = 0; !(rpc_session[0].session) && (i < 10000); ++i) {
rpc_session[0].session = rpc_session_open(rpc);
delay(1);
furi_hal_delay_ms(1);
}
furi_check(rpc_session[0].session);
@ -106,7 +106,7 @@ static void test_rpc_setup_second_session(void) {
for(int i = 0; !(rpc_session[1].session) && (i < 10000); ++i) {
rpc_session[1].session = rpc_session_open(rpc);
delay(1);
furi_hal_delay_ms(1);
}
furi_check(rpc_session[1].session);
@ -1518,28 +1518,28 @@ MU_TEST(test_app_start_and_lock_status) {
test_app_get_status_lock_run(false, ++command_id);
test_app_start_run("Delay Test", "0", PB_CommandStatus_OK, ++command_id);
delay(100);
furi_hal_delay_ms(100);
test_app_get_status_lock_run(false, ++command_id);
test_app_start_run("Delay Test", "200", PB_CommandStatus_OK, ++command_id);
test_app_get_status_lock_run(true, ++command_id);
delay(100);
furi_hal_delay_ms(100);
test_app_get_status_lock_run(true, ++command_id);
test_app_start_run("Delay Test", "0", PB_CommandStatus_ERROR_APP_SYSTEM_LOCKED, ++command_id);
delay(200);
furi_hal_delay_ms(200);
test_app_get_status_lock_run(false, ++command_id);
test_app_start_run("Delay Test", "500", PB_CommandStatus_OK, ++command_id);
delay(100);
furi_hal_delay_ms(100);
test_app_get_status_lock_run(true, ++command_id);
test_app_start_run("Infrared", "0", PB_CommandStatus_ERROR_APP_SYSTEM_LOCKED, ++command_id);
delay(100);
furi_hal_delay_ms(100);
test_app_get_status_lock_run(true, ++command_id);
test_app_start_run(
"2_girls_1_app", "0", PB_CommandStatus_ERROR_INVALID_PARAMETERS, ++command_id);
delay(100);
furi_hal_delay_ms(100);
test_app_get_status_lock_run(true, ++command_id);
delay(500);
furi_hal_delay_ms(500);
test_app_get_status_lock_run(false, ++command_id);
}
@ -1786,7 +1786,7 @@ int32_t delay_test_app(void* p) {
int timeout = atoi((const char*)p);
if(timeout > 0) {
delay(timeout);
furi_hal_delay_ms(timeout);
}
return 0;

View File

@ -63,7 +63,7 @@ void unit_tests_cli(Cli* cli, string_t args, void* context) {
FURI_LOG_I(TAG, "Consumed: %0.2fs", (float)cycle_counter / (SystemCoreClock));
if(test_result == 0) {
delay(200); /* wait for tested services and apps to deallocate */
furi_hal_delay_ms(200); /* wait for tested services and apps to deallocate */
uint32_t heap_after = memmgr_get_free_heap();
notification_message(notification, &sequence_success);
if(heap_after != heap_before) {

View File

@ -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;

View File

@ -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;

View File

@ -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
}

View File

@ -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);
}
}

View File

@ -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};

View File

@ -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);
}
}

View File

@ -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);

View File

@ -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);

View File

@ -2,6 +2,7 @@
#include "common_defines.h"
#include <furi_hal_console.h>
#include <furi_hal_power.h>
#include <furi_hal_rtc.h>
#include <stdio.h>
@ -51,7 +52,7 @@ void furi_crash(const char* message) {
furi_hal_rtc_set_fault_data((uint32_t)message);
furi_hal_console_puts("\r\nRebooting system.\r\n");
furi_hal_console_puts("\033[0m\r\n");
NVIC_SystemReset();
furi_hal_power_reset();
#endif
}

View File

@ -3,6 +3,12 @@
#include <stdbool.h>
#include <cmsis_os2.h>
#ifdef __cplusplus
extern "C" {
#endif
#include <cmsis_compiler.h>
#ifndef MAX
#define MAX(a, b) \
({ \
@ -60,6 +66,14 @@
#define ALIGN(n) __attribute__((aligned(n)))
#endif
#ifndef __weak
#define __weak __attribute__((weak))
#endif
#ifndef UNUSED
#define UNUSED(X) (void)(X)
#endif
#ifndef STRINGIFY
#define STRINGIFY(x) #x
#endif
@ -110,3 +124,7 @@
taskEXIT_CRITICAL(); \
}
#endif
#ifdef __cplusplus
}
#endif

View File

@ -18,7 +18,7 @@ void furi_log_init() {
// Set default logging parameters
furi_log.log_level = FURI_LOG_LEVEL_DEFAULT;
furi_log.puts = furi_hal_console_puts;
furi_log.timetamp = HAL_GetTick;
furi_log.timetamp = furi_hal_get_tick;
furi_log.mutex = osMutexNew(NULL);
}

View File

@ -1,49 +0,0 @@
/**
******************************************************************************
* @file gpio.h
* @brief This file contains all the function prototypes for
* the gpio.c file
******************************************************************************
* @attention
*
* <h2><center>&copy; Copyright (c) 2021 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
*
******************************************************************************
*/
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __GPIO_H__
#define __GPIO_H__
#ifdef __cplusplus
extern "C" {
#endif
/* Includes ------------------------------------------------------------------*/
#include "main.h"
/* USER CODE BEGIN Includes */
/* USER CODE END Includes */
/* USER CODE BEGIN Private defines */
/* USER CODE END Private defines */
void MX_GPIO_Init(void);
/* USER CODE BEGIN Prototypes */
/* USER CODE END Prototypes */
#ifdef __cplusplus
}
#endif
#endif /*__ GPIO_H__ */
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

View File

@ -1,120 +0,0 @@
#pragma once
#ifdef __cplusplus
extern "C" {
#endif
#include "stm32wbxx_hal.h"
#include "stm32wbxx_ll_gpio.h"
void Error_Handler(void);
#define BUTTON_BACK_GPIO_Port GPIOC
#define BUTTON_BACK_Pin LL_GPIO_PIN_13
#define BUTTON_DOWN_GPIO_Port GPIOC
#define BUTTON_DOWN_Pin LL_GPIO_PIN_6
#define BUTTON_LEFT_GPIO_Port GPIOB
#define BUTTON_LEFT_Pin LL_GPIO_PIN_11
#define BUTTON_OK_GPIO_Port GPIOH
#define BUTTON_OK_Pin LL_GPIO_PIN_3
#define BUTTON_RIGHT_GPIO_Port GPIOB
#define BUTTON_RIGHT_Pin LL_GPIO_PIN_12
#define BUTTON_UP_GPIO_Port GPIOB
#define BUTTON_UP_Pin LL_GPIO_PIN_10
#define CC1101_CS_GPIO_Port GPIOD
#define CC1101_CS_Pin LL_GPIO_PIN_0
#define CC1101_G0_GPIO_Port GPIOA
#define CC1101_G0_Pin LL_GPIO_PIN_1
#define DISPLAY_CS_GPIO_Port GPIOC
#define DISPLAY_CS_Pin LL_GPIO_PIN_11
#define DISPLAY_DI_GPIO_Port GPIOB
#define DISPLAY_DI_Pin LL_GPIO_PIN_1
#define DISPLAY_RST_GPIO_Port GPIOB
#define DISPLAY_RST_Pin LL_GPIO_PIN_0
#define IR_RX_GPIO_Port GPIOA
#define IR_RX_Pin LL_GPIO_PIN_0
#define IR_TX_GPIO_Port GPIOB
#define IR_TX_Pin LL_GPIO_PIN_9
#define NFC_CS_GPIO_Port GPIOE
#define NFC_CS_Pin LL_GPIO_PIN_4
#define PA4_GPIO_Port GPIOA
#define PA4_Pin LL_GPIO_PIN_4
#define PA6_GPIO_Port GPIOA
#define PA6_Pin LL_GPIO_PIN_6
#define PA7_GPIO_Port GPIOA
#define PA7_Pin LL_GPIO_PIN_7
#define PB2_GPIO_Port GPIOB
#define PB2_Pin LL_GPIO_PIN_2
#define PB3_GPIO_Port GPIOB
#define PB3_Pin LL_GPIO_PIN_3
#define PC0_GPIO_Port GPIOC
#define PC0_Pin LL_GPIO_PIN_0
#define PC1_GPIO_Port GPIOC
#define PC1_Pin LL_GPIO_PIN_1
#define PC3_GPIO_Port GPIOC
#define PC3_Pin LL_GPIO_PIN_3
#define PERIPH_POWER_GPIO_Port GPIOA
#define PERIPH_POWER_Pin LL_GPIO_PIN_3
#define QUARTZ_32MHZ_IN_GPIO_Port GPIOC
#define QUARTZ_32MHZ_IN_Pin LL_GPIO_PIN_14
#define QUARTZ_32MHZ_OUT_GPIO_Port GPIOC
#define QUARTZ_32MHZ_OUT_Pin LL_GPIO_PIN_15
#define RFID_OUT_GPIO_Port GPIOB
#define RFID_OUT_Pin LL_GPIO_PIN_13
#define RFID_PULL_GPIO_Port GPIOA
#define RFID_PULL_Pin LL_GPIO_PIN_2
#define RFID_RF_IN_GPIO_Port GPIOC
#define RFID_RF_IN_Pin LL_GPIO_PIN_5
#define RFID_CARRIER_GPIO_Port GPIOA
#define RFID_CARRIER_Pin LL_GPIO_PIN_15
#define RF_SW_0_GPIO_Port GPIOC
#define RF_SW_0_Pin LL_GPIO_PIN_4
#define SD_CD_GPIO_Port GPIOC
#define SD_CD_Pin LL_GPIO_PIN_10
#define SD_CS_GPIO_Port GPIOC
#define SD_CS_Pin LL_GPIO_PIN_12
#define SPEAKER_GPIO_Port GPIOB
#define SPEAKER_Pin LL_GPIO_PIN_8
#define VIBRO_GPIO_Port GPIOA
#define VIBRO_Pin LL_GPIO_PIN_8
#define iBTN_GPIO_Port GPIOB
#define iBTN_Pin LL_GPIO_PIN_14
#define USART1_TX_Pin LL_GPIO_PIN_6
#define USART1_TX_Port GPIOB
#define USART1_RX_Pin LL_GPIO_PIN_7
#define USART1_RX_Port GPIOB
#define SPI_D_MISO_GPIO_Port GPIOC
#define SPI_D_MISO_Pin LL_GPIO_PIN_2
#define SPI_D_MOSI_GPIO_Port GPIOB
#define SPI_D_MOSI_Pin LL_GPIO_PIN_15
#define SPI_D_SCK_GPIO_Port GPIOD
#define SPI_D_SCK_Pin LL_GPIO_PIN_1
#define SPI_R_MISO_GPIO_Port GPIOB
#define SPI_R_MISO_Pin LL_GPIO_PIN_4
#define SPI_R_MOSI_GPIO_Port GPIOB
#define SPI_R_MOSI_Pin LL_GPIO_PIN_5
#define SPI_R_SCK_GPIO_Port GPIOA
#define SPI_R_SCK_Pin LL_GPIO_PIN_5
#define NFC_IRQ_Pin RFID_PULL_Pin
#define NFC_IRQ_GPIO_Port RFID_PULL_GPIO_Port
#ifdef __cplusplus
}
#endif

View File

@ -1,40 +0,0 @@
/**
******************************************************************************
* @file stm32_assert.h
* @brief STM32 assert file.
******************************************************************************
* @attention
*
* <h2><center>&copy; Copyright (c) 2019 STMicroelectronics.
* All rights reserved.</center></h2>
*
* This software component is licensed by ST under BSD 3-Clause license,
* the "License"; You may not use this file except in compliance with the
* License. You may obtain a copy of the License at:
* opensource.org/licenses/BSD-3-Clause
*
******************************************************************************
*/
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __STM32_ASSERT_H
#define __STM32_ASSERT_H
#ifdef __cplusplus
extern "C" {
#endif
#ifdef USE_FULL_ASSERT
#define assert_param(expr) ((expr) ? (void)0U : assert_failed())
void assert_failed();
#else
#define assert_param(expr) ((void)0U)
#endif /* USE_FULL_ASSERT */
#ifdef __cplusplus
}
#endif
#endif /* __STM32_ASSERT_H */
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

View File

@ -1,347 +0,0 @@
/**
******************************************************************************
* @file stm32wbxx_hal_conf.h
* @author MCD Application Team
* @brief HAL configuration file.
******************************************************************************
* @attention
*
* <h2><center>&copy; Copyright (c) 2019 STMicroelectronics.
* All rights reserved.</center></h2>
*
* This software component is licensed by ST under BSD 3-Clause license,
* the "License"; You may not use this file except in compliance with the
* License. You may obtain a copy of the License at:
* opensource.org/licenses/BSD-3-Clause
*
******************************************************************************
*/
/* Define to prevent recursive inclusion -------------------------------------*/
#ifndef __STM32WBxx_HAL_CONF_H
#define __STM32WBxx_HAL_CONF_H
#ifdef __cplusplus
extern "C" {
#endif
/* Exported types ------------------------------------------------------------*/
/* Exported constants --------------------------------------------------------*/
/* ########################## Module Selection ############################## */
/**
* @brief This is the list of modules to be used in the HAL driver
*/
#define HAL_MODULE_ENABLED
/*#define HAL_ADC_MODULE_ENABLED */
#define HAL_CRYP_MODULE_ENABLED
/*#define HAL_COMP_MODULE_ENABLED */
/*#define HAL_CRC_MODULE_ENABLED */
/*#define HAL_HSEM_MODULE_ENABLED */
/*#define HAL_I2C_MODULE_ENABLED */
/*#define HAL_IPCC_MODULE_ENABLED */
/*#define HAL_IRDA_MODULE_ENABLED */
/*#define HAL_IWDG_MODULE_ENABLED */
/*#define HAL_LCD_MODULE_ENABLED */
/*#define HAL_LPTIM_MODULE_ENABLED */
#define HAL_PCD_MODULE_ENABLED
#define HAL_PKA_MODULE_ENABLED
/*#define HAL_QSPI_MODULE_ENABLED */
#define HAL_RNG_MODULE_ENABLED
/*#define HAL_RTC_MODULE_ENABLED */
/*#define HAL_SAI_MODULE_ENABLED */
/*#define HAL_SMBUS_MODULE_ENABLED */
/*#define HAL_SMARTCARD_MODULE_ENABLED */
/*#define HAL_SPI_MODULE_ENABLED */
/*#define HAL_TIM_MODULE_ENABLED */
/*#define HAL_TSC_MODULE_ENABLED */
/*#define HAL_UART_MODULE_ENABLED */
/*#define HAL_USART_MODULE_ENABLED */
/*#define HAL_WWDG_MODULE_ENABLED */
#define HAL_EXTI_MODULE_ENABLED
#define HAL_CORTEX_MODULE_ENABLED
#define HAL_DMA_MODULE_ENABLED
#define HAL_FLASH_MODULE_ENABLED
#define HAL_GPIO_MODULE_ENABLED
#define HAL_PWR_MODULE_ENABLED
#define HAL_RCC_MODULE_ENABLED
#define USE_HAL_ADC_REGISTER_CALLBACKS 0u
#define USE_HAL_COMP_REGISTER_CALLBACKS 0u
#define USE_HAL_CRYP_REGISTER_CALLBACKS 0u
#define USE_HAL_I2C_REGISTER_CALLBACKS 0u
#define USE_HAL_IRDA_REGISTER_CALLBACKS 0u
#define USE_HAL_LPTIM_REGISTER_CALLBACKS 0u
#define USE_HAL_PCD_REGISTER_CALLBACKS 0u
#define USE_HAL_PKA_REGISTER_CALLBACKS 0u
#define USE_HAL_QSPI_REGISTER_CALLBACKS 0u
#define USE_HAL_RNG_REGISTER_CALLBACKS 0u
#define USE_HAL_RTC_REGISTER_CALLBACKS 0u
#define USE_HAL_SAI_REGISTER_CALLBACKS 0u
#define USE_HAL_SMARTCARD_REGISTER_CALLBACKS 0u
#define USE_HAL_SMBUS_REGISTER_CALLBACKS 0u
#define USE_HAL_SPI_REGISTER_CALLBACKS 0u
#define USE_HAL_TIM_REGISTER_CALLBACKS 0u
#define USE_HAL_TSC_REGISTER_CALLBACKS 0u
#define USE_HAL_UART_REGISTER_CALLBACKS 0u
#define USE_HAL_USART_REGISTER_CALLBACKS 0u
#define USE_HAL_WWDG_REGISTER_CALLBACKS 0u
/* ########################## Oscillator Values adaptation ####################*/
/**
* @brief Adjust the value of External High Speed oscillator (HSE) used in your application.
* This value is used by the RCC HAL module to compute the system frequency
* (when HSE is used as system clock source, directly or through the PLL).
*/
#if !defined(HSE_VALUE)
#define HSE_VALUE 32000000U /*!< Value of the External oscillator in Hz */
#endif /* HSE_VALUE */
#if !defined(HSE_STARTUP_TIMEOUT)
#define HSE_STARTUP_TIMEOUT ((uint32_t)100) /*!< Time out for HSE start up, in ms */
#endif /* HSE_STARTUP_TIMEOUT */
/**
* @brief Internal Multiple Speed oscillator (MSI) default value.
* This value is the default MSI range value after Reset.
*/
#if !defined(MSI_VALUE)
#define MSI_VALUE ((uint32_t)4000000) /*!< Value of the Internal oscillator in Hz*/
#endif /* MSI_VALUE */
/**
* @brief Internal High Speed oscillator (HSI) value.
* This value is used by the RCC HAL module to compute the system frequency
* (when HSI is used as system clock source, directly or through the PLL).
*/
#if !defined(HSI_VALUE)
#define HSI_VALUE 16000000U /*!< Value of the Internal oscillator in Hz*/
#endif /* HSI_VALUE */
/**
* @brief Internal Low Speed oscillator (LSI1) value.
*/
#if !defined(LSI1_VALUE)
#define LSI1_VALUE ((uint32_t)32000) /*!< LSI1 Typical Value in Hz*/
#endif /* LSI1_VALUE */ /*!< Value of the Internal Low Speed oscillator in Hz
The real value may vary depending on the variations
in voltage and temperature.*/
/**
* @brief Internal Low Speed oscillator (LSI2) value.
*/
#if !defined(LSI2_VALUE)
#define LSI2_VALUE ((uint32_t)32000) /*!< LSI2 Typical Value in Hz*/
#endif /* LSI2_VALUE */ /*!< Value of the Internal Low Speed oscillator in Hz
The real value may vary depending on the variations
in voltage and temperature.*/
/**
* @brief External Low Speed oscillator (LSE) value.
* This value is used by the UART, RTC HAL module to compute the system frequency
*/
#if !defined(LSE_VALUE)
#define LSE_VALUE 32768U /*!< Value of the External oscillator in Hz*/
#endif /* LSE_VALUE */
/**
* @brief Internal Multiple Speed oscillator (HSI48) default value.
* This value is the default HSI48 range value after Reset.
*/
#if !defined(HSI48_VALUE)
#define HSI48_VALUE ((uint32_t)48000000) /*!< Value of the Internal oscillator in Hz*/
#endif /* HSI48_VALUE */
#if !defined(LSE_STARTUP_TIMEOUT)
#define LSE_STARTUP_TIMEOUT 1000U /*!< Time out for LSE start up, in ms */
#endif /* HSE_STARTUP_TIMEOUT */
/**
* @brief External clock source for SAI1 peripheral
* This value is used by the RCC HAL module to compute the SAI1 & SAI2 clock source
* frequency.
*/
#if !defined(EXTERNAL_SAI1_CLOCK_VALUE)
#define EXTERNAL_SAI1_CLOCK_VALUE \
((uint32_t)2097000) /*!< Value of the SAI1 External clock source in Hz*/
#endif /* EXTERNAL_SAI1_CLOCK_VALUE */
/* Tip: To avoid modifying this file each time you need to use different HSE,
=== you can define the HSE value in your toolchain compiler preprocessor. */
/* ########################### System Configuration ######################### */
/**
* @brief This is the HAL system configuration section
*/
#define VDD_VALUE 3300U /*!< Value of VDD in mv */
#define TICK_INT_PRIORITY 0U /*!< tick interrupt priority */
#define USE_RTOS 0U
#define PREFETCH_ENABLE 1U
#define INSTRUCTION_CACHE_ENABLE 1U
#define DATA_CACHE_ENABLE 1U
/* ########################## Assert Selection ############################## */
/**
* @brief Uncomment the line below to expanse the "assert_param" macro in the
* HAL drivers code
*/
#ifdef APP_UNIT_TESTS
#define USE_FULL_ASSERT 1U
#endif
/* ################## SPI peripheral configuration ########################## */
/* CRC FEATURE: Use to activate CRC feature inside HAL SPI Driver
* Activated: CRC code is present inside driver
* Deactivated: CRC code cleaned from driver
*/
#define USE_SPI_CRC 0U
/* Includes ------------------------------------------------------------------*/
/**
* @brief Include module's header file
*/
#ifdef HAL_DMA_MODULE_ENABLED
#include "stm32wbxx_hal_dma.h"
#endif /* HAL_DMA_MODULE_ENABLED */
#ifdef HAL_ADC_MODULE_ENABLED
#include "stm32wbxx_hal_adc.h"
#endif /* HAL_ADC_MODULE_ENABLED */
#ifdef HAL_COMP_MODULE_ENABLED
#include "stm32wbxx_hal_comp.h"
#endif /* HAL_COMP_MODULE_ENABLED */
#ifdef HAL_CORTEX_MODULE_ENABLED
#include "stm32wbxx_hal_cortex.h"
#endif /* HAL_CORTEX_MODULE_ENABLED */
#ifdef HAL_CRC_MODULE_ENABLED
#include "stm32wbxx_hal_crc.h"
#endif /* HAL_CRC_MODULE_ENABLED */
#ifdef HAL_CRYP_MODULE_ENABLED
#include "stm32wbxx_hal_cryp.h"
#endif /* HAL_CRYP_MODULE_ENABLED */
#ifdef HAL_EXTI_MODULE_ENABLED
#include "stm32wbxx_hal_exti.h"
#endif /* HAL_EXTI_MODULE_ENABLED */
#ifdef HAL_FLASH_MODULE_ENABLED
#include "stm32wbxx_hal_flash.h"
#endif /* HAL_FLASH_MODULE_ENABLED */
#ifdef HAL_GPIO_MODULE_ENABLED
#include "stm32wbxx_hal_gpio.h"
#endif /* HAL_GPIO_MODULE_ENABLED */
#ifdef HAL_HSEM_MODULE_ENABLED
#include "stm32wbxx_hal_hsem.h"
#endif /* HAL_HSEM_MODULE_ENABLED */
#ifdef HAL_I2C_MODULE_ENABLED
#include "stm32wbxx_hal_i2c.h"
#endif /* HAL_I2C_MODULE_ENABLED */
#ifdef HAL_IPCC_MODULE_ENABLED
#include "stm32wbxx_hal_ipcc.h"
#endif /* HAL_IPCC_MODULE_ENABLED */
#ifdef HAL_IRDA_MODULE_ENABLED
#include "stm32wbxx_hal_irda.h"
#endif /* HAL_IRDA_MODULE_ENABLED */
#ifdef HAL_IWDG_MODULE_ENABLED
#include "stm32wbxx_hal_iwdg.h"
#endif /* HAL_IWDG_MODULE_ENABLED */
#ifdef HAL_LCD_MODULE_ENABLED
#include "stm32wbxx_hal_lcd.h"
#endif /* HAL_LCD_MODULE_ENABLED */
#ifdef HAL_LPTIM_MODULE_ENABLED
#include "stm32wbxx_hal_lptim.h"
#endif /* HAL_LPTIM_MODULE_ENABLED */
#ifdef HAL_PCD_MODULE_ENABLED
#include "stm32wbxx_hal_pcd.h"
#endif /* HAL_PCD_MODULE_ENABLED */
#ifdef HAL_PKA_MODULE_ENABLED
#include "stm32wbxx_hal_pka.h"
#endif /* HAL_PKA_MODULE_ENABLED */
#ifdef HAL_PWR_MODULE_ENABLED
#include "stm32wbxx_hal_pwr.h"
#endif /* HAL_PWR_MODULE_ENABLED */
#ifdef HAL_QSPI_MODULE_ENABLED
#include "stm32wbxx_hal_qspi.h"
#endif /* HAL_QSPI_MODULE_ENABLED */
#ifdef HAL_RCC_MODULE_ENABLED
#include "stm32wbxx_hal_rcc.h"
#endif /* HAL_RCC_MODULE_ENABLED */
#ifdef HAL_RNG_MODULE_ENABLED
#include "stm32wbxx_hal_rng.h"
#endif /* HAL_RNG_MODULE_ENABLED */
#ifdef HAL_RTC_MODULE_ENABLED
#include "stm32wbxx_hal_rtc.h"
#endif /* HAL_RTC_MODULE_ENABLED */
#ifdef HAL_SAI_MODULE_ENABLED
#include "stm32wbxx_hal_sai.h"
#endif /* HAL_SAI_MODULE_ENABLED */
#ifdef HAL_SMARTCARD_MODULE_ENABLED
#include "stm32wbxx_hal_smartcard.h"
#endif /* HAL_SMARTCARD_MODULE_ENABLED */
#ifdef HAL_SMBUS_MODULE_ENABLED
#include "stm32wbxx_hal_smbus.h"
#endif /* HAL_SMBUS_MODULE_ENABLED */
#ifdef HAL_SPI_MODULE_ENABLED
#include "stm32wbxx_hal_spi.h"
#endif /* HAL_SPI_MODULE_ENABLED */
#ifdef HAL_TIM_MODULE_ENABLED
#include "stm32wbxx_hal_tim.h"
#endif /* HAL_TIM_MODULE_ENABLED */
#ifdef HAL_TSC_MODULE_ENABLED
#include "stm32wbxx_hal_tsc.h"
#endif /* HAL_TSC_MODULE_ENABLED */
#ifdef HAL_UART_MODULE_ENABLED
#include "stm32wbxx_hal_uart.h"
#endif /* HAL_UART_MODULE_ENABLED */
#ifdef HAL_USART_MODULE_ENABLED
#include "stm32wbxx_hal_usart.h"
#endif /* HAL_USART_MODULE_ENABLED */
#ifdef HAL_WWDG_MODULE_ENABLED
#include "stm32wbxx_hal_wwdg.h"
#endif /* HAL_WWDG_MODULE_ENABLED */
/* Exported macro ------------------------------------------------------------*/
#ifdef USE_FULL_ASSERT
#define assert_param(expr) ((expr) ? (void)0U : assert_failed())
void assert_failed();
#else
#define assert_param(expr) ((void)0U)
#endif /* USE_FULL_ASSERT */
#ifdef __cplusplus
}
#endif
#endif /* __STM32WBxx_HAL_CONF_H */
/************************ (C) COPYRIGHT STMicroelectronics *****END OF FILE****/

View File

@ -1,131 +0,0 @@
#include "gpio.h"
void MX_GPIO_Init(void) {
GPIO_InitTypeDef GPIO_InitStruct = {0};
/*Configure GPIO pin : PtPin */
GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING_FALLING;
GPIO_InitStruct.Pull = GPIO_PULLUP;
GPIO_InitStruct.Pin = BUTTON_BACK_Pin;
HAL_GPIO_Init(BUTTON_BACK_GPIO_Port, &GPIO_InitStruct);
/*Configure GPIO pin : PtPin */
GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING_FALLING;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Pin = BUTTON_OK_Pin;
HAL_GPIO_Init(BUTTON_OK_GPIO_Port, &GPIO_InitStruct);
/*Configure GPIO pins : PCPin PCPin PCPin PCPin */
GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Pin = PC0_Pin;
HAL_GPIO_Init(PC0_GPIO_Port, &GPIO_InitStruct);
GPIO_InitStruct.Pin = PC1_Pin;
HAL_GPIO_Init(PC1_GPIO_Port, &GPIO_InitStruct);
GPIO_InitStruct.Pin = PC3_Pin;
HAL_GPIO_Init(PC3_GPIO_Port, &GPIO_InitStruct);
GPIO_InitStruct.Pin = VIBRO_Pin;
HAL_GPIO_Init(VIBRO_GPIO_Port, &GPIO_InitStruct);
/* RF_SW_0 */
HAL_GPIO_WritePin(RF_SW_0_GPIO_Port, RF_SW_0_Pin, GPIO_PIN_RESET);
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
GPIO_InitStruct.Pin = RF_SW_0_Pin;
HAL_GPIO_Init(RF_SW_0_GPIO_Port, &GPIO_InitStruct);
/* PERIPH_POWER */
HAL_GPIO_WritePin(PERIPH_POWER_GPIO_Port, PERIPH_POWER_Pin, GPIO_PIN_SET);
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_OD;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
GPIO_InitStruct.Pin = PERIPH_POWER_Pin;
HAL_GPIO_Init(PERIPH_POWER_GPIO_Port, &GPIO_InitStruct);
/*Configure GPIO pins : PAPin PAPin PAPin */
GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Pin = PA4_Pin;
HAL_GPIO_Init(PA4_GPIO_Port, &GPIO_InitStruct);
GPIO_InitStruct.Pin = PA6_Pin;
HAL_GPIO_Init(PA6_GPIO_Port, &GPIO_InitStruct);
GPIO_InitStruct.Pin = PA7_Pin;
HAL_GPIO_Init(PA7_GPIO_Port, &GPIO_InitStruct);
/*Configure GPIO pin : PtPin */
GPIO_InitStruct.Pin = RFID_PULL_Pin;
GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING;
GPIO_InitStruct.Pull = GPIO_NOPULL;
HAL_GPIO_Init(RFID_PULL_GPIO_Port, &GPIO_InitStruct);
/*Configure GPIO pins : PBPin PBPin PBPin */
GPIO_InitStruct.Mode = GPIO_MODE_ANALOG;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Pin = PB2_Pin;
HAL_GPIO_Init(PB2_GPIO_Port, &GPIO_InitStruct);
GPIO_InitStruct.Pin = iBTN_Pin;
HAL_GPIO_Init(iBTN_GPIO_Port, &GPIO_InitStruct);
GPIO_InitStruct.Pin = PB3_Pin;
HAL_GPIO_Init(PB3_GPIO_Port, &GPIO_InitStruct);
/*Configure GPIO pins : PBPin PBPin PBPin PBPin */
GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING_FALLING;
GPIO_InitStruct.Pull = GPIO_PULLUP;
GPIO_InitStruct.Pin = BUTTON_UP_Pin;
HAL_GPIO_Init(BUTTON_UP_GPIO_Port, &GPIO_InitStruct);
GPIO_InitStruct.Pin = BUTTON_LEFT_Pin;
HAL_GPIO_Init(BUTTON_LEFT_GPIO_Port, &GPIO_InitStruct);
GPIO_InitStruct.Pin = BUTTON_RIGHT_Pin;
HAL_GPIO_Init(BUTTON_RIGHT_GPIO_Port, &GPIO_InitStruct);
/*Configure GPIO pins : PBPin PBPin PBPin PBPin */
GPIO_InitStruct.Pin = BUTTON_DOWN_Pin;
GPIO_InitStruct.Mode = GPIO_MODE_IT_RISING_FALLING;
GPIO_InitStruct.Pull = GPIO_PULLUP;
HAL_GPIO_Init(BUTTON_DOWN_GPIO_Port, &GPIO_InitStruct);
/* DISPLAY_RST */
HAL_GPIO_WritePin(DISPLAY_RST_GPIO_Port, DISPLAY_RST_Pin, GPIO_PIN_RESET);
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
GPIO_InitStruct.Pin = DISPLAY_RST_Pin;
HAL_GPIO_Init(DISPLAY_RST_GPIO_Port, &GPIO_InitStruct);
/* DISPLAY_DI */
HAL_GPIO_WritePin(DISPLAY_DI_GPIO_Port, DISPLAY_DI_Pin, GPIO_PIN_RESET);
GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
GPIO_InitStruct.Pull = GPIO_NOPULL;
GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_LOW;
GPIO_InitStruct.Pin = DISPLAY_DI_Pin;
HAL_GPIO_Init(DISPLAY_DI_GPIO_Port, &GPIO_InitStruct);
/* SD_CD */
GPIO_InitStruct.Pin = SD_CD_Pin;
GPIO_InitStruct.Mode = GPIO_MODE_INPUT;
GPIO_InitStruct.Pull = GPIO_NOPULL;
HAL_GPIO_Init(SD_CD_GPIO_Port, &GPIO_InitStruct);
/* Enable all NVIC lines related to gpio */
HAL_NVIC_SetPriority(EXTI0_IRQn, 5, 0);
HAL_NVIC_EnableIRQ(EXTI0_IRQn);
HAL_NVIC_SetPriority(EXTI1_IRQn, 5, 0);
HAL_NVIC_EnableIRQ(EXTI1_IRQn);
HAL_NVIC_SetPriority(EXTI2_IRQn, 5, 0);
HAL_NVIC_EnableIRQ(EXTI2_IRQn);
HAL_NVIC_SetPriority(EXTI3_IRQn, 5, 0);
HAL_NVIC_EnableIRQ(EXTI3_IRQn);
HAL_NVIC_SetPriority(EXTI4_IRQn, 5, 0);
HAL_NVIC_EnableIRQ(EXTI4_IRQn);
HAL_NVIC_SetPriority(EXTI9_5_IRQn, 5, 0);
HAL_NVIC_EnableIRQ(EXTI9_5_IRQn);
HAL_NVIC_SetPriority(EXTI15_10_IRQn, 5, 0);
HAL_NVIC_EnableIRQ(EXTI15_10_IRQn);
}

View File

@ -1,5 +1,3 @@
#include "main.h"
#include <furi.h>
#include <furi_hal.h>
#include <flipper.h>
@ -13,9 +11,6 @@ int main(void) {
// Initialize FURI layer
furi_init();
// Initialize ST HAL
HAL_Init();
// Flipper FURI HAL
furi_hal_init();
@ -32,20 +27,3 @@ int main(void) {
while(1) {
}
}
void Error_Handler(void) {
furi_crash("ErrorHandler");
}
#ifdef USE_FULL_ASSERT
/**
* @brief Reports the name of the source file and the source line number
* where the assert_param error has occurred.
* @param file: pointer to the source file name
* @param line: assert_param error line source number
* @retval None
*/
void assert_failed(uint8_t* file, uint32_t line) {
furi_crash("HAL assert failed");
}
#endif /* USE_FULL_ASSERT */

View File

@ -149,29 +149,30 @@ void APPD_Init(void) {
/**
* Keep debugger enabled while in any low power mode
*/
HAL_DBGMCU_EnableDBGSleepMode();
HAL_DBGMCU_EnableDBGStopMode();
LL_DBGMCU_EnableDBGSleepMode();
LL_DBGMCU_EnableDBGStopMode();
/***************** ENABLE DEBUGGER *************************************/
LL_EXTI_EnableIT_32_63(LL_EXTI_LINE_48);
#else
GPIO_InitTypeDef gpio_config = {0};
LL_GPIO_InitTypeDef gpio_config = {0};
LL_PWR_EnableVddUSB();
gpio_config.Pull = GPIO_NOPULL;
gpio_config.Mode = GPIO_MODE_ANALOG;
gpio_config.Mode = LL_GPIO_MODE_ANALOG;
gpio_config.Speed = LL_GPIO_SPEED_FREQ_LOW;
// gpio_config.OutputType = LL_GPIO_OUTPUT_PUSHPULL;
// gpio_config.Pull = LL_GPIO_PULL_NO;
// gpio_config.Alternate = LL_GPIO_AF_10;
gpio_config.Pin = LL_GPIO_PIN_15 | LL_GPIO_PIN_14 | LL_GPIO_PIN_13;
LL_GPIO_Init(GPIOA, &gpio_config);
gpio_config.Pin = GPIO_PIN_15 | GPIO_PIN_14 | GPIO_PIN_13;
__HAL_RCC_GPIOA_CLK_ENABLE();
HAL_GPIO_Init(GPIOA, &gpio_config);
gpio_config.Pin = LL_GPIO_PIN_4 | LL_GPIO_PIN_3;
LL_GPIO_Init(GPIOB, &gpio_config);
gpio_config.Pin = GPIO_PIN_4 | GPIO_PIN_3;
__HAL_RCC_GPIOB_CLK_ENABLE();
HAL_GPIO_Init(GPIOB, &gpio_config);
HAL_DBGMCU_DisableDBGSleepMode();
HAL_DBGMCU_DisableDBGStopMode();
HAL_DBGMCU_DisableDBGStandbyMode();
LL_DBGMCU_DisableDBGSleepMode();
LL_DBGMCU_DisableDBGStopMode();
LL_DBGMCU_DisableDBGStandbyMode();
#endif /* (CFG_DEBUGGER_SUPPORTED == 1) */
@ -203,12 +204,12 @@ void APPD_EnableCPU2(void) {
/** GPIO DEBUG Initialization */
SHCI_C2_DEBUG_Init(&DebugCmdPacket);
// GPIO_InitTypeDef GPIO_InitStruct;
// GPIO_InitStruct.Pull = GPIO_NOPULL;
// GPIO_InitStruct.Mode = GPIO_MODE_OUTPUT_PP;
// GPIO_InitStruct.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
// GPIO_InitStruct.Pin = LL_GPIO_PIN_3;
// HAL_GPIO_Init(GPIOC, &GPIO_InitStruct);
// LL_GPIO_InitTypeDef gpio_config;
// gpio_config.Pull = GPIO_NOPULL;
// gpio_config.Mode = GPIO_MODE_OUTPUT_PP;
// gpio_config.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
// gpio_config.Pin = LL_GPIO_PIN_3;
// HAL_GPIO_Init(GPIOC, &gpio_config);
// SHCI_C2_ExtpaConfig((uint32_t)GPIOC, LL_GPIO_PIN_3, EXT_PA_ENABLED_LOW, EXT_PA_ENABLED);
/* USER CODE END APPD_EnableCPU2 */
@ -222,7 +223,7 @@ void APPD_EnableCPU2(void) {
*************************************************************/
static void APPD_SetCPU2GpioConfig(void) {
/* USER CODE BEGIN APPD_SetCPU2GpioConfig */
GPIO_InitTypeDef gpio_config = {0};
LL_GPIO_InitTypeDef gpio_config = {0};
uint8_t local_loop;
uint16_t gpioa_pin_list;
uint16_t gpiob_pin_list;
@ -253,32 +254,33 @@ static void APPD_SetCPU2GpioConfig(void) {
}
}
gpio_config.Pull = GPIO_NOPULL;
gpio_config.Mode = GPIO_MODE_OUTPUT_PP;
gpio_config.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
gpio_config.Mode = LL_GPIO_MODE_OUTPUT;
gpio_config.Speed = LL_GPIO_SPEED_FREQ_VERY_HIGH;
gpio_config.OutputType = LL_GPIO_OUTPUT_PUSHPULL;
gpio_config.Pull = LL_GPIO_PULL_NO;
gpio_config.Pin = LL_GPIO_PIN_15 | LL_GPIO_PIN_14 | LL_GPIO_PIN_13;
LL_GPIO_Init(GPIOA, &gpio_config);
if(gpioa_pin_list != 0) {
gpio_config.Pin = gpioa_pin_list;
__HAL_RCC_GPIOA_CLK_ENABLE();
__HAL_RCC_C2GPIOA_CLK_ENABLE();
HAL_GPIO_Init(GPIOA, &gpio_config);
HAL_GPIO_WritePin(GPIOA, gpioa_pin_list, GPIO_PIN_RESET);
LL_C2_AHB2_GRP1_EnableClock(LL_C2_AHB2_GRP1_PERIPH_GPIOA);
LL_GPIO_Init(GPIOA, &gpio_config);
LL_GPIO_ResetOutputPin(GPIOA, gpioa_pin_list);
}
if(gpiob_pin_list != 0) {
gpio_config.Pin = gpiob_pin_list;
__HAL_RCC_GPIOB_CLK_ENABLE();
__HAL_RCC_C2GPIOB_CLK_ENABLE();
HAL_GPIO_Init(GPIOB, &gpio_config);
HAL_GPIO_WritePin(GPIOB, gpiob_pin_list, GPIO_PIN_RESET);
LL_C2_AHB2_GRP1_EnableClock(LL_C2_AHB2_GRP1_PERIPH_GPIOB);
LL_GPIO_Init(GPIOB, &gpio_config);
LL_GPIO_ResetOutputPin(GPIOB, gpioa_pin_list);
}
if(gpioc_pin_list != 0) {
gpio_config.Pin = gpioc_pin_list;
__HAL_RCC_GPIOC_CLK_ENABLE();
__HAL_RCC_C2GPIOC_CLK_ENABLE();
HAL_GPIO_Init(GPIOC, &gpio_config);
HAL_GPIO_WritePin(GPIOC, gpioc_pin_list, GPIO_PIN_RESET);
LL_C2_AHB2_GRP1_EnableClock(LL_C2_AHB2_GRP1_PERIPH_GPIOC);
LL_GPIO_Init(GPIOC, &gpio_config);
LL_GPIO_ResetOutputPin(GPIOC, gpioa_pin_list);
}
/* USER CODE END APPD_SetCPU2GpioConfig */
@ -288,7 +290,7 @@ static void APPD_SetCPU2GpioConfig(void) {
static void APPD_BleDtbCfg(void) {
/* USER CODE BEGIN APPD_BleDtbCfg */
#if(BLE_DTB_CFG != 0)
GPIO_InitTypeDef gpio_config = {0};
LL_GPIO_InitTypeDef gpio_config = {0};
uint8_t local_loop;
uint16_t gpioa_pin_list;
uint16_t gpiob_pin_list;
@ -313,23 +315,23 @@ static void APPD_BleDtbCfg(void) {
}
}
gpio_config.Pull = GPIO_NOPULL;
gpio_config.Mode = GPIO_MODE_AF_PP;
gpio_config.Speed = GPIO_SPEED_FREQ_VERY_HIGH;
gpio_config.Alternate = GPIO_AF6_RF_DTB7;
gpio_config.Mode = LL_GPIO_MODE_ALTERNATE;
gpio_config.Speed = LL_GPIO_SPEED_FREQ_VERY_HIGH;
gpio_config.OutputType = LL_GPIO_OUTPUT_PUSHPULL;
gpio_config.Pull = LL_GPIO_PULL_NO;
gpio_config.Alternate = LL_GPIO_AF_6;
gpio_config.Pin = LL_GPIO_PIN_15 | LL_GPIO_PIN_14 | LL_GPIO_PIN_13;
if(gpioa_pin_list != 0) {
gpio_config.Pin = gpioa_pin_list;
__HAL_RCC_GPIOA_CLK_ENABLE();
__HAL_RCC_C2GPIOA_CLK_ENABLE();
HAL_GPIO_Init(GPIOA, &gpio_config);
LL_C2_AHB2_GRP1_EnableClock(LL_C2_AHB2_GRP1_PERIPH_GPIOA);
LL_GPIO_Init(GPIOA, &gpio_config);
}
if(gpiob_pin_list != 0) {
gpio_config.Pin = gpiob_pin_list;
__HAL_RCC_GPIOB_CLK_ENABLE();
__HAL_RCC_C2GPIOB_CLK_ENABLE();
HAL_GPIO_Init(GPIOB, &gpio_config);
LL_C2_AHB2_GRP1_EnableClock(LL_C2_AHB2_GRP1_PERIPH_GPIOB);
LL_GPIO_Init(GPIOB, &gpio_config);
}
#endif

View File

@ -23,6 +23,10 @@
#include "app_conf.h"
#ifndef __weak
#define __weak __attribute__((weak))
#endif
/******************************************************************************
*
* BLE SERVICES CONFIGURATION

View File

@ -1,6 +1,5 @@
#include "ble_glue.h"
#include "app_common.h"
#include "main.h"
#include "ble_app.h"
#include "ble.h"
#include "tl.h"

View File

@ -185,10 +185,10 @@ void HW_IPCC_Init(void) {
LL_C1_IPCC_EnableIT_RXO(IPCC);
LL_C1_IPCC_EnableIT_TXF(IPCC);
HAL_NVIC_SetPriority(IPCC_C1_RX_IRQn, 6, 0);
HAL_NVIC_EnableIRQ(IPCC_C1_RX_IRQn);
HAL_NVIC_SetPriority(IPCC_C1_TX_IRQn, 6, 0);
HAL_NVIC_EnableIRQ(IPCC_C1_TX_IRQn);
NVIC_SetPriority(IPCC_C1_RX_IRQn, NVIC_EncodePriority(NVIC_GetPriorityGrouping(), 6, 0));
NVIC_EnableIRQ(IPCC_C1_RX_IRQn);
NVIC_SetPriority(IPCC_C1_TX_IRQn, NVIC_EncodePriority(NVIC_GetPriorityGrouping(), 6, 0));
NVIC_EnableIRQ(IPCC_C1_TX_IRQn);
return;
}

View File

@ -24,9 +24,6 @@
/ Additional user header to be used
/-----------------------------------------------------------------------------*/
#include "main.h"
#include "stm32wbxx_hal.h"
/*-----------------------------------------------------------------------------/
/ Function Configurations
/-----------------------------------------------------------------------------*/

View File

@ -1,4 +1,3 @@
#include "main.h"
#include <furi_hal.h>
#include <furi.h>
@ -46,8 +45,8 @@ void SD_IO_Init(void) {
uint8_t counter = 0;
/* SD chip select high */
hal_gpio_write(furi_hal_sd_spi_handle->cs, true);
delay_us(10);
furi_hal_gpio_write(furi_hal_sd_spi_handle->cs, true);
furi_hal_delay_us(10);
/* Send dummy byte 0xFF, 10 times with CS high */
/* Rise CS and MOSI for 80 clocks cycles */
@ -65,11 +64,11 @@ void SD_IO_Init(void) {
void SD_IO_CSState(uint8_t val) {
/* Some SD Cards are prone to fail if CLK-ed too soon after CS transition. Worst case found: 8us */
if(val == 1) {
delay_us(10); // Exit guard time for some SD cards
hal_gpio_write(furi_hal_sd_spi_handle->cs, true);
furi_hal_delay_us(10); // Exit guard time for some SD cards
furi_hal_gpio_write(furi_hal_sd_spi_handle->cs, true);
} else {
hal_gpio_write(furi_hal_sd_spi_handle->cs, false);
delay_us(10); // Entry guard time for some SD cards
furi_hal_gpio_write(furi_hal_sd_spi_handle->cs, false);
furi_hal_delay_us(10); // Entry guard time for some SD cards
}
}

View File

@ -279,47 +279,47 @@ static uint8_t SD_ReadData(void);
/* Private functions ---------------------------------------------------------*/
void SD_SPI_Bus_To_Down_State() {
hal_gpio_init_ex(
furi_hal_gpio_init_ex(
furi_hal_sd_spi_handle->miso,
GpioModeOutputPushPull,
GpioPullNo,
GpioSpeedVeryHigh,
GpioAltFnUnused);
hal_gpio_init_ex(
furi_hal_gpio_init_ex(
furi_hal_sd_spi_handle->mosi,
GpioModeOutputPushPull,
GpioPullNo,
GpioSpeedVeryHigh,
GpioAltFnUnused);
hal_gpio_init_ex(
furi_hal_gpio_init_ex(
furi_hal_sd_spi_handle->sck,
GpioModeOutputPushPull,
GpioPullNo,
GpioSpeedVeryHigh,
GpioAltFnUnused);
hal_gpio_write(furi_hal_sd_spi_handle->cs, false);
hal_gpio_write(furi_hal_sd_spi_handle->miso, false);
hal_gpio_write(furi_hal_sd_spi_handle->mosi, false);
hal_gpio_write(furi_hal_sd_spi_handle->sck, false);
furi_hal_gpio_write(furi_hal_sd_spi_handle->cs, false);
furi_hal_gpio_write(furi_hal_sd_spi_handle->miso, false);
furi_hal_gpio_write(furi_hal_sd_spi_handle->mosi, false);
furi_hal_gpio_write(furi_hal_sd_spi_handle->sck, false);
}
void SD_SPI_Bus_To_Normal_State() {
hal_gpio_write(furi_hal_sd_spi_handle->cs, true);
furi_hal_gpio_write(furi_hal_sd_spi_handle->cs, true);
hal_gpio_init_ex(
furi_hal_gpio_init_ex(
furi_hal_sd_spi_handle->miso,
GpioModeAltFunctionPushPull,
GpioPullUp,
GpioSpeedVeryHigh,
GpioAltFn5SPI2);
hal_gpio_init_ex(
furi_hal_gpio_init_ex(
furi_hal_sd_spi_handle->mosi,
GpioModeAltFunctionPushPull,
GpioPullUp,
GpioSpeedVeryHigh,
GpioAltFn5SPI2);
hal_gpio_init_ex(
furi_hal_gpio_init_ex(
furi_hal_sd_spi_handle->sck,
GpioModeAltFunctionPushPull,
GpioPullUp,
@ -349,13 +349,13 @@ uint8_t BSP_SD_Init(bool reset_card) {
furi_hal_power_disable_external_3_3v();
SD_SPI_Bus_To_Down_State();
hal_sd_detect_set_low();
delay(250);
furi_hal_delay_ms(250);
/* reinit bus and enable power */
SD_SPI_Bus_To_Normal_State();
hal_sd_detect_init();
furi_hal_power_enable_external_3_3v();
delay(100);
furi_hal_delay_ms(100);
}
/* Configure IO functionalities for SD pin */
@ -867,7 +867,7 @@ SD_CmdAnswer_typedef SD_SendCmd(uint8_t Cmd, uint32_t Arg, uint8_t Crc, uint8_t
retr.r2 = SD_IO_WriteByte(SD_DUMMY_BYTE);
/* Set CS High */
SD_IO_CSState(1);
HAL_Delay(1);
furi_hal_delay_us(1000);
/* Set CS Low */
SD_IO_CSState(0);

View File

@ -1,7 +1,5 @@
#include <furi_hal.h>
#include <gpio.h>
#include <stm32wbxx_ll_cortex.h>
#include <fatfs.h>
@ -13,7 +11,7 @@ void furi_hal_init() {
furi_hal_interrupt_init();
furi_hal_delay_init();
MX_GPIO_Init();
furi_hal_resources_init();
FURI_LOG_I(TAG, "GPIO OK");
furi_hal_bootloader_init();

View File

@ -4,9 +4,12 @@
#include <stm32wbxx_ll_pwr.h>
#include <stm32wbxx_ll_rcc.h>
#include <stm32wbxx_ll_utils.h>
#include <stm32wbxx_ll_cortex.h>
#include <stm32wbxx_ll_bus.h>
#define TAG "FuriHalClock"
#define TICK_INT_PRIORITY 0U
#define HS_CLOCK_IS_READY() (LL_RCC_HSE_IsReady() && LL_RCC_HSI_IsReady())
#define LS_CLOCK_IS_READY() (LL_RCC_LSE_IsReady() && LL_RCC_LSI1_IsReady())
@ -83,9 +86,10 @@ void furi_hal_clock_init() {
LL_SetSystemCoreClock(64000000);
/* Update the time base */
if(HAL_InitTick(TICK_INT_PRIORITY) != HAL_OK) {
Error_Handler();
}
LL_InitTick(64000000, 1000);
LL_SYSTICK_EnableIT();
NVIC_SetPriority(SysTick_IRQn, TICK_INT_PRIORITY);
NVIC_EnableIRQ(SysTick_IRQn);
LL_RCC_SetUSARTClockSource(LL_RCC_USART1_CLKSOURCE_PCLK2);
LL_RCC_SetLPUARTClockSource(LL_RCC_LPUART1_CLKSOURCE_PCLK1);

View File

@ -1,16 +1,27 @@
#include <furi_hal_crypto.h>
#include <furi_hal_bt.h>
#include <furi_hal_random.h>
#include <stm32wbxx_ll_cortex.h>
#include <furi.h>
#include <shci.h>
#define TAG "FuriHalCrypto"
CRYP_HandleTypeDef crypt;
#define ENCLAVE_FACTORY_KEY_SLOTS 10
#define ENCLAVE_SIGNATURE_SIZE 16
#define CRYPTO_BLK_LEN (4 * sizeof(uint32_t))
#define CRYPTO_TIMEOUT (1000)
#define CRYPTO_MODE_ENCRYPT 0U
#define CRYPTO_MODE_DECRYPT (AES_CR_MODE_1)
#define CRYPTO_MODE_DECRYPT_INIT (AES_CR_MODE_0 | AES_CR_MODE_1)
#define CRYPTO_DATATYPE_32B 0U
#define CRYPTO_KEYSIZE_256B (AES_CR_KEYSIZE)
#define CRYPTO_AES_CBC (AES_CR_CHMOD_0)
static osMutexId_t furi_hal_crypto_mutex = NULL;
static const uint8_t enclave_signature_iv[ENCLAVE_FACTORY_KEY_SLOTS][16] = {
{0xac, 0x5d, 0x68, 0xb8, 0x79, 0x74, 0xfc, 0x7f, 0x45, 0x02, 0x82, 0xf1, 0x48, 0x7e, 0x75, 0x8a},
{0x38, 0xe6, 0x6a, 0x90, 0x5e, 0x5b, 0x8a, 0xa6, 0x70, 0x30, 0x04, 0x72, 0xc2, 0x42, 0xea, 0xaf},
@ -51,6 +62,7 @@ static const uint8_t enclave_signature_expected[ENCLAVE_FACTORY_KEY_SLOTS][ENCLA
};
void furi_hal_crypto_init() {
furi_hal_crypto_mutex = osMutexNew(NULL);
FURI_LOG_I(TAG, "Init OK");
}
@ -127,6 +139,8 @@ bool furi_hal_crypto_store_add_key(FuriHalCryptoKey* key, uint8_t* slot) {
furi_assert(key);
furi_assert(slot);
furi_check(osMutexAcquire(furi_hal_crypto_mutex, osWaitForever) == osOK);
if(!furi_hal_bt_is_alive()) {
return false;
}
@ -157,30 +171,91 @@ bool furi_hal_crypto_store_add_key(FuriHalCryptoKey* key, uint8_t* slot) {
memcpy(pParam.KeyData, key->data, key_data_size);
return SHCI_C2_FUS_StoreUsrKey(&pParam, slot) == SHCI_Success;
SHCI_CmdStatus_t shci_state = SHCI_C2_FUS_StoreUsrKey(&pParam, slot);
furi_check(osMutexRelease(furi_hal_crypto_mutex) == osOK);
return (shci_state == SHCI_Success);
}
static void crypto_enable() {
SET_BIT(AES1->CR, AES_CR_EN);
}
static void crypto_disable() {
CLEAR_BIT(AES1->CR, AES_CR_EN);
}
static void crypto_key_init(uint32_t* key, uint32_t* iv) {
crypto_disable();
MODIFY_REG(
AES1->CR,
AES_CR_DATATYPE | AES_CR_KEYSIZE | AES_CR_CHMOD,
CRYPTO_DATATYPE_32B | CRYPTO_KEYSIZE_256B | CRYPTO_AES_CBC);
if(key != NULL) {
AES1->KEYR7 = key[0];
AES1->KEYR6 = key[1];
AES1->KEYR5 = key[2];
AES1->KEYR4 = key[3];
AES1->KEYR3 = key[4];
AES1->KEYR2 = key[5];
AES1->KEYR1 = key[6];
AES1->KEYR0 = key[7];
}
AES1->IVR3 = iv[0];
AES1->IVR2 = iv[1];
AES1->IVR1 = iv[2];
AES1->IVR0 = iv[3];
}
static bool crypto_process_block(uint32_t* in, uint32_t* out, uint8_t blk_len) {
furi_check((blk_len <= 4) && (blk_len > 0));
for(uint8_t i = 0; i < 4; i++) {
if(i < blk_len) {
AES1->DINR = in[i];
} else {
AES1->DINR = 0;
}
}
uint32_t countdown = CRYPTO_TIMEOUT;
while(!READ_BIT(AES1->SR, AES_SR_CCF)) {
if(LL_SYSTICK_IsActiveCounterFlag()) {
countdown--;
}
if(countdown == 0) {
return false;
}
}
SET_BIT(AES1->CR, AES_CR_CCFC);
uint32_t out_temp[4];
for(uint8_t i = 0; i < 4; i++) {
out_temp[i] = AES1->DOUTR;
}
memcpy(out, out_temp, blk_len * sizeof(uint32_t));
return true;
}
bool furi_hal_crypto_store_load_key(uint8_t slot, const uint8_t* iv) {
furi_assert(slot > 0 && slot <= 100);
furi_assert(furi_hal_crypto_mutex);
furi_check(osMutexAcquire(furi_hal_crypto_mutex, osWaitForever) == osOK);
if(!furi_hal_bt_is_alive()) {
return false;
}
crypt.Instance = AES1;
crypt.Init.DataType = CRYP_DATATYPE_32B;
crypt.Init.KeySize = CRYP_KEYSIZE_256B;
crypt.Init.Algorithm = CRYP_AES_CBC;
crypt.Init.pInitVect = (uint32_t*)iv;
crypt.Init.KeyIVConfigSkip = CRYP_KEYIVCONFIG_ONCE;
crypt.Init.pKey = NULL;
furi_check(HAL_CRYP_Init(&crypt) == HAL_OK);
crypto_key_init(NULL, (uint32_t*)iv);
if(SHCI_C2_FUS_LoadUsrKey(slot) == SHCI_Success) {
return true;
} else {
furi_check(HAL_CRYP_DeInit(&crypt) == HAL_OK);
crypto_disable();
furi_check(osMutexRelease(furi_hal_crypto_mutex) == osOK);
return false;
}
}
@ -190,14 +265,55 @@ bool furi_hal_crypto_store_unload_key(uint8_t slot) {
return false;
}
furi_check(HAL_CRYP_DeInit(&crypt) == HAL_OK);
return SHCI_C2_FUS_UnloadUsrKey(slot) == SHCI_Success;
crypto_disable();
SHCI_CmdStatus_t shci_state = SHCI_C2_FUS_UnloadUsrKey(slot);
furi_check(osMutexRelease(furi_hal_crypto_mutex) == osOK);
return (shci_state == SHCI_Success);
}
bool furi_hal_crypto_encrypt(const uint8_t* input, uint8_t* output, size_t size) {
return HAL_CRYP_Encrypt(&crypt, (uint32_t*)input, size / 4, (uint32_t*)output, 1000) == HAL_OK;
bool state = false;
crypto_enable();
MODIFY_REG(AES1->CR, AES_CR_MODE, CRYPTO_MODE_ENCRYPT);
for(size_t i = 0; i < size; i += CRYPTO_BLK_LEN) {
size_t blk_len = size - i;
if(blk_len > CRYPTO_BLK_LEN) {
blk_len = CRYPTO_BLK_LEN;
}
state = crypto_process_block((uint32_t*)&input[i], (uint32_t*)&output[i], blk_len / 4);
if(state == false) {
break;
}
}
crypto_disable();
return state;
}
bool furi_hal_crypto_decrypt(const uint8_t* input, uint8_t* output, size_t size) {
return HAL_CRYP_Decrypt(&crypt, (uint32_t*)input, size / 4, (uint32_t*)output, 1000) == HAL_OK;
bool state = false;
MODIFY_REG(AES1->CR, AES_CR_MODE, CRYPTO_MODE_DECRYPT_INIT);
crypto_enable();
for(size_t i = 0; i < size; i += CRYPTO_BLK_LEN) {
size_t blk_len = size - i;
if(blk_len > CRYPTO_BLK_LEN) {
blk_len = CRYPTO_BLK_LEN;
}
state = crypto_process_block((uint32_t*)&input[i], (uint32_t*)&output[i], blk_len / 4);
if(state == false) {
break;
}
}
crypto_disable();
return state;
}

View File

@ -5,6 +5,7 @@
#define TAG "FuriHalDelay"
uint32_t instructions_per_us;
static volatile uint32_t tick_cnt = 0;
void furi_hal_delay_init(void) {
CoreDebug->DEMCR |= CoreDebug_DEMCR_TRCENA_Msk;
@ -14,7 +15,15 @@ void furi_hal_delay_init(void) {
FURI_LOG_I(TAG, "Init OK");
}
void delay_us(float microseconds) {
void furi_hal_tick(void) {
tick_cnt++;
}
uint32_t furi_hal_get_tick(void) {
return tick_cnt;
}
void furi_hal_delay_us(float microseconds) {
uint32_t start = DWT->CYCCNT;
uint32_t time_ticks = microseconds * instructions_per_us;
while((DWT->CYCCNT - start) < time_ticks) {
@ -23,13 +32,9 @@ void delay_us(float microseconds) {
// cannot be used in ISR
// TODO add delay_ISR variant
void delay(float milliseconds) {
void furi_hal_delay_ms(float milliseconds) {
uint32_t ticks = milliseconds / (1000.0f / osKernelGetTickFreq());
osStatus_t result = osDelay(ticks);
(void)result;
furi_assert(result == osOK);
}
uint32_t millis(void) {
return HAL_GetTick();
}

View File

@ -12,6 +12,17 @@
#define FURI_HAL_FLASH_WRITE_BLOCK 8
#define FURI_HAL_FLASH_PAGE_SIZE 4096
#define FURI_HAL_FLASH_CYCLES_COUNT 10000
#define FURI_HAL_FLASH_TIMEOUT 1000
#define FURI_HAL_FLASH_KEY1 0x45670123U
#define FURI_HAL_FLASH_KEY2 0xCDEF89ABU
#define FURI_HAL_FLASH_SR_ERRORS \
(FLASH_SR_OPERR | FLASH_SR_PROGERR | FLASH_SR_WRPERR | FLASH_SR_PGAERR | FLASH_SR_SIZERR | \
FLASH_SR_PGSERR | FLASH_SR_MISERR | FLASH_SR_FASTERR | FLASH_SR_RDERR | FLASH_SR_OPTVERR)
#define IS_ADDR_ALIGNED_64BITS(__VALUE__) (((__VALUE__)&0x7U) == (0x00UL))
#define IS_FLASH_PROGRAM_ADDRESS(__VALUE__) \
(((__VALUE__) >= FLASH_BASE) && ((__VALUE__) <= (FLASH_BASE + FLASH_SIZE - 8UL)) && \
(((__VALUE__) % 8UL) == 0UL))
/* Free flash space borders, exported by linker */
extern const void __free_flash_start__;
@ -43,7 +54,7 @@ const void* furi_hal_flash_get_free_start_address() {
const void* furi_hal_flash_get_free_end_address() {
uint32_t sfr_reg_val = READ_REG(FLASH->SFR);
uint32_t sfsa = (READ_BIT(sfr_reg_val, FLASH_SFR_SFSA) >> FLASH_SFR_SFSA_Pos);
return (const void*)((sfsa * FLASH_PAGE_SIZE) + FLASH_BASE);
return (const void*)((sfsa * FURI_HAL_FLASH_PAGE_SIZE) + FLASH_BASE);
}
size_t furi_hal_flash_get_free_page_start_address() {
@ -66,8 +77,8 @@ static void furi_hal_flash_unlock() {
furi_check(READ_BIT(FLASH->CR, FLASH_CR_LOCK) != 0U);
/* Authorize the FLASH Registers access */
WRITE_REG(FLASH->KEYR, FLASH_KEY1);
WRITE_REG(FLASH->KEYR, FLASH_KEY2);
WRITE_REG(FLASH->KEYR, FURI_HAL_FLASH_KEY1);
WRITE_REG(FLASH->KEYR, FURI_HAL_FLASH_KEY2);
/* verify Flash is unlock */
furi_check(READ_BIT(FLASH->CR, FLASH_CR_LOCK) == 0U);
@ -152,7 +163,7 @@ static void furi_hal_flash_end_with_core2(bool erase_flag) {
taskEXIT_CRITICAL();
// Doesn't make much sense, does it?
while(__HAL_FLASH_GET_FLAG(FLASH_FLAG_BSY)) {
while(READ_BIT(FLASH->SR, FLASH_SR_BSY)) {
osThreadYield();
}
@ -202,7 +213,7 @@ static void furi_hal_flush_cache(void) {
}
}
HAL_StatusTypeDef furi_hal_flash_wait_last_operation(uint32_t timeout) {
bool furi_hal_flash_wait_last_operation(uint32_t timeout) {
uint32_t error = 0;
uint32_t countdown = 0;
@ -210,12 +221,12 @@ HAL_StatusTypeDef furi_hal_flash_wait_last_operation(uint32_t timeout) {
// Even if the FLASH operation fails, the BUSY flag will be reset and an error
// flag will be set
countdown = timeout;
while(__HAL_FLASH_GET_FLAG(FLASH_FLAG_BSY)) {
while(READ_BIT(FLASH->SR, FLASH_SR_BSY)) {
if(LL_SYSTICK_IsActiveCounterFlag()) {
countdown--;
}
if(countdown == 0) {
return HAL_TIMEOUT;
return false;
}
}
@ -223,31 +234,30 @@ HAL_StatusTypeDef furi_hal_flash_wait_last_operation(uint32_t timeout) {
error = FLASH->SR;
/* Check FLASH End of Operation flag */
if((error & FLASH_FLAG_EOP) != 0U) {
if((error & FLASH_SR_EOP) != 0U) {
/* Clear FLASH End of Operation pending bit */
__HAL_FLASH_CLEAR_FLAG(FLASH_FLAG_EOP);
CLEAR_BIT(FLASH->SR, FLASH_SR_EOP);
}
/* Now update error variable to only error value */
error &= FLASH_FLAG_SR_ERRORS;
error &= FURI_HAL_FLASH_SR_ERRORS;
furi_check(error == 0);
/* clear error flags */
__HAL_FLASH_CLEAR_FLAG(error);
CLEAR_BIT(FLASH->SR, error);
/* Wait for control register to be written */
countdown = timeout;
while(__HAL_FLASH_GET_FLAG(FLASH_FLAG_CFGBSY)) {
while(READ_BIT(FLASH->SR, FLASH_SR_CFGBSY)) {
if(LL_SYSTICK_IsActiveCounterFlag()) {
countdown--;
}
if(countdown == 0) {
return HAL_TIMEOUT;
return false;
}
}
return HAL_OK;
return true;
}
bool furi_hal_flash_erase(uint8_t page) {
@ -257,14 +267,14 @@ bool furi_hal_flash_erase(uint8_t page) {
furi_check(FLASH->SR == 0);
/* Verify that next operation can be proceed */
furi_check(furi_hal_flash_wait_last_operation(FLASH_TIMEOUT_VALUE) == HAL_OK);
furi_check(furi_hal_flash_wait_last_operation(FURI_HAL_FLASH_TIMEOUT));
/* Select page and start operation */
MODIFY_REG(
FLASH->CR, FLASH_CR_PNB, ((page << FLASH_CR_PNB_Pos) | FLASH_CR_PER | FLASH_CR_STRT));
/* Wait for last operation to be completed */
furi_check(furi_hal_flash_wait_last_operation(FLASH_TIMEOUT_VALUE) == HAL_OK);
furi_check(furi_hal_flash_wait_last_operation(FURI_HAL_FLASH_TIMEOUT));
/* If operation is completed or interrupted, disable the Page Erase Bit */
CLEAR_BIT(FLASH->CR, (FLASH_CR_PER | FLASH_CR_PNB));
@ -301,7 +311,7 @@ bool furi_hal_flash_write_dword(size_t address, uint64_t data) {
*(uint32_t*)(address + 4U) = (uint32_t)(data >> 32U);
/* Wait for last operation to be completed */
furi_check(furi_hal_flash_wait_last_operation(FLASH_TIMEOUT_VALUE) == HAL_OK);
furi_check(furi_hal_flash_wait_last_operation(FURI_HAL_FLASH_TIMEOUT));
/* If the program operation is completed, disable the PG or FSTPG Bit */
CLEAR_BIT(FLASH->CR, FLASH_CR_PG);

View File

@ -34,7 +34,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;
@ -42,11 +42,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,
@ -55,10 +55,10 @@ void hal_gpio_init(
furi_assert(mode != GpioModeAltFunctionPushPull);
furi_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,
@ -133,7 +133,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);
@ -171,12 +171,12 @@ void hal_gpio_init_ex(
FURI_CRITICAL_EXIT();
}
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) {
furi_assert(gpio);
furi_assert(cb);
FURI_CRITICAL_ENTER();
uint8_t pin_num = hal_gpio_get_pin_num(gpio);
uint8_t pin_num = furi_hal_gpio_get_pin_num(gpio);
furi_assert(gpio_interrupt[pin_num].callback == NULL);
gpio_interrupt[pin_num].callback = cb;
gpio_interrupt[pin_num].context = ctx;
@ -184,38 +184,38 @@ void hal_gpio_add_int_callback(const GpioPin* gpio, GpioExtiCallback cb, void* c
FURI_CRITICAL_EXIT();
}
void hal_gpio_enable_int_callback(const GpioPin* gpio) {
void furi_hal_gpio_enable_int_callback(const GpioPin* gpio) {
furi_assert(gpio);
FURI_CRITICAL_ENTER();
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;
}
FURI_CRITICAL_EXIT();
}
void hal_gpio_disable_int_callback(const GpioPin* gpio) {
void furi_hal_gpio_disable_int_callback(const GpioPin* gpio) {
furi_assert(gpio);
FURI_CRITICAL_ENTER();
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;
FURI_CRITICAL_EXIT();
}
void hal_gpio_remove_int_callback(const GpioPin* gpio) {
void furi_hal_gpio_remove_int_callback(const GpioPin* gpio) {
furi_assert(gpio);
FURI_CRITICAL_ENTER();
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;
FURI_CRITICAL_EXIT();
}
static void hal_gpio_int_call(uint16_t pin_num) {
static void furi_hal_gpio_int_call(uint16_t pin_num) {
if(gpio_interrupt[pin_num].callback && gpio_interrupt[pin_num].ready) {
gpio_interrupt[pin_num].callback(gpio_interrupt[pin_num].context);
}
@ -225,84 +225,84 @@ static void hal_gpio_int_call(uint16_t pin_num) {
void EXTI0_IRQHandler(void) {
if(LL_EXTI_IsActiveFlag_0_31(LL_EXTI_LINE_0)) {
LL_EXTI_ClearFlag_0_31(LL_EXTI_LINE_0);
hal_gpio_int_call(0);
furi_hal_gpio_int_call(0);
}
}
void EXTI1_IRQHandler(void) {
if(LL_EXTI_IsActiveFlag_0_31(LL_EXTI_LINE_1)) {
LL_EXTI_ClearFlag_0_31(LL_EXTI_LINE_1);
hal_gpio_int_call(1);
furi_hal_gpio_int_call(1);
}
}
void EXTI2_IRQHandler(void) {
if(LL_EXTI_IsActiveFlag_0_31(LL_EXTI_LINE_2)) {
LL_EXTI_ClearFlag_0_31(LL_EXTI_LINE_2);
hal_gpio_int_call(2);
furi_hal_gpio_int_call(2);
}
}
void EXTI3_IRQHandler(void) {
if(LL_EXTI_IsActiveFlag_0_31(LL_EXTI_LINE_3)) {
LL_EXTI_ClearFlag_0_31(LL_EXTI_LINE_3);
hal_gpio_int_call(3);
furi_hal_gpio_int_call(3);
}
}
void EXTI4_IRQHandler(void) {
if(LL_EXTI_IsActiveFlag_0_31(LL_EXTI_LINE_4)) {
LL_EXTI_ClearFlag_0_31(LL_EXTI_LINE_4);
hal_gpio_int_call(4);
furi_hal_gpio_int_call(4);
}
}
void EXTI9_5_IRQHandler(void) {
if(LL_EXTI_IsActiveFlag_0_31(LL_EXTI_LINE_5)) {
LL_EXTI_ClearFlag_0_31(LL_EXTI_LINE_5);
hal_gpio_int_call(5);
furi_hal_gpio_int_call(5);
}
if(LL_EXTI_IsActiveFlag_0_31(LL_EXTI_LINE_6)) {
LL_EXTI_ClearFlag_0_31(LL_EXTI_LINE_6);
hal_gpio_int_call(6);
furi_hal_gpio_int_call(6);
}
if(LL_EXTI_IsActiveFlag_0_31(LL_EXTI_LINE_7)) {
LL_EXTI_ClearFlag_0_31(LL_EXTI_LINE_7);
hal_gpio_int_call(7);
furi_hal_gpio_int_call(7);
}
if(LL_EXTI_IsActiveFlag_0_31(LL_EXTI_LINE_8)) {
LL_EXTI_ClearFlag_0_31(LL_EXTI_LINE_8);
hal_gpio_int_call(8);
furi_hal_gpio_int_call(8);
}
if(LL_EXTI_IsActiveFlag_0_31(LL_EXTI_LINE_9)) {
LL_EXTI_ClearFlag_0_31(LL_EXTI_LINE_9);
hal_gpio_int_call(9);
furi_hal_gpio_int_call(9);
}
}
void EXTI15_10_IRQHandler(void) {
if(LL_EXTI_IsActiveFlag_0_31(LL_EXTI_LINE_10)) {
LL_EXTI_ClearFlag_0_31(LL_EXTI_LINE_10);
hal_gpio_int_call(10);
furi_hal_gpio_int_call(10);
}
if(LL_EXTI_IsActiveFlag_0_31(LL_EXTI_LINE_11)) {
LL_EXTI_ClearFlag_0_31(LL_EXTI_LINE_11);
hal_gpio_int_call(11);
furi_hal_gpio_int_call(11);
}
if(LL_EXTI_IsActiveFlag_0_31(LL_EXTI_LINE_12)) {
LL_EXTI_ClearFlag_0_31(LL_EXTI_LINE_12);
hal_gpio_int_call(12);
furi_hal_gpio_int_call(12);
}
if(LL_EXTI_IsActiveFlag_0_31(LL_EXTI_LINE_13)) {
LL_EXTI_ClearFlag_0_31(LL_EXTI_LINE_13);
hal_gpio_int_call(13);
furi_hal_gpio_int_call(13);
}
if(LL_EXTI_IsActiveFlag_0_31(LL_EXTI_LINE_14)) {
LL_EXTI_ClearFlag_0_31(LL_EXTI_LINE_14);
hal_gpio_int_call(14);
furi_hal_gpio_int_call(14);
}
if(LL_EXTI_IsActiveFlag_0_31(LL_EXTI_LINE_15)) {
LL_EXTI_ClearFlag_0_31(LL_EXTI_LINE_15);
hal_gpio_int_call(15);
furi_hal_gpio_int_call(15);
}
}

View File

@ -1,5 +1,4 @@
#pragma once
#include "main.h"
#include "stdbool.h"
#include <stm32wbxx_ll_gpio.h>
#include <stm32wbxx_ll_system.h>
@ -170,7 +169,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 +178,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 +192,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 +205,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;
@ -240,12 +239,28 @@ static inline void hal_gpio_write(const GpioPin* gpio, const bool state) {
}
}
/**
* GPIO read pin
* @param port GPIO port
* @param pin pin mask
* @return true / false
*/
static inline void
furi_hal_gpio_write_port_pin(GPIO_TypeDef* port, uint16_t pin, const bool state) {
// writing to BSSR is an atomic operation
if(state == true) {
port->BSRR = pin;
} else {
port->BSRR = pin << GPIO_NUMBER;
}
}
/**
* GPIO read pin
* @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 {
@ -253,6 +268,20 @@ static inline bool hal_gpio_read(const GpioPin* gpio) {
}
}
/**
* GPIO read pin
* @param port GPIO port
* @param pin pin mask
* @return true / false
*/
static inline bool furi_hal_gpio_read_port_pin(GPIO_TypeDef* port, uint16_t pin) {
if((port->IDR & pin) != 0x00U) {
return true;
} else {
return false;
}
}
#ifdef __cplusplus
}
#endif

View File

@ -1,4 +1,5 @@
#include <furi_hal_i2c.h>
#include <furi_hal_delay.h>
#include <furi_hal_version.h>
#include <stm32wbxx_ll_i2c.h>
@ -50,11 +51,11 @@ bool furi_hal_i2c_tx(
furi_assert(timeout > 0);
bool ret = true;
uint32_t timeout_tick = HAL_GetTick() + timeout;
uint32_t timeout_tick = furi_hal_get_tick() + timeout;
do {
while(LL_I2C_IsActiveFlag_BUSY(handle->bus->i2c)) {
if(HAL_GetTick() >= timeout_tick) {
if(furi_hal_get_tick() >= timeout_tick) {
ret = false;
break;
}
@ -79,7 +80,7 @@ bool furi_hal_i2c_tx(
size--;
}
if(HAL_GetTick() >= timeout_tick) {
if(furi_hal_get_tick() >= timeout_tick) {
ret = false;
break;
}
@ -101,11 +102,11 @@ bool furi_hal_i2c_rx(
furi_assert(timeout > 0);
bool ret = true;
uint32_t timeout_tick = HAL_GetTick() + timeout;
uint32_t timeout_tick = furi_hal_get_tick() + timeout;
do {
while(LL_I2C_IsActiveFlag_BUSY(handle->bus->i2c)) {
if(HAL_GetTick() >= timeout_tick) {
if(furi_hal_get_tick() >= timeout_tick) {
ret = false;
break;
}
@ -130,7 +131,7 @@ bool furi_hal_i2c_rx(
size--;
}
if(HAL_GetTick() >= timeout_tick) {
if(furi_hal_get_tick() >= timeout_tick) {
ret = false;
break;
}
@ -165,11 +166,11 @@ bool furi_hal_i2c_is_device_ready(FuriHalI2cBusHandle* handle, uint8_t i2c_addr,
furi_assert(timeout > 0);
bool ret = true;
uint32_t timeout_tick = HAL_GetTick() + timeout;
uint32_t timeout_tick = furi_hal_get_tick() + timeout;
do {
while(LL_I2C_IsActiveFlag_BUSY(handle->bus->i2c)) {
if(HAL_GetTick() >= timeout_tick) {
if(furi_hal_get_tick() >= timeout_tick) {
return false;
}
}
@ -180,14 +181,14 @@ bool furi_hal_i2c_is_device_ready(FuriHalI2cBusHandle* handle, uint8_t i2c_addr,
while((!LL_I2C_IsActiveFlag_NACK(handle->bus->i2c)) &&
(!LL_I2C_IsActiveFlag_STOP(handle->bus->i2c))) {
if(HAL_GetTick() >= timeout_tick) {
if(furi_hal_get_tick() >= timeout_tick) {
return false;
}
}
if(LL_I2C_IsActiveFlag_NACK(handle->bus->i2c)) {
while(!LL_I2C_IsActiveFlag_STOP(handle->bus->i2c)) {
if(HAL_GetTick() >= timeout_tick) {
if(furi_hal_get_tick() >= timeout_tick) {
return false;
}
}
@ -204,7 +205,7 @@ bool furi_hal_i2c_is_device_ready(FuriHalI2cBusHandle* handle, uint8_t i2c_addr,
}
while(!LL_I2C_IsActiveFlag_STOP(handle->bus->i2c)) {
if(HAL_GetTick() >= timeout_tick) {
if(furi_hal_get_tick() >= timeout_tick) {
return false;
}
}
@ -298,11 +299,11 @@ bool furi_hal_i2c_write_mem(
bool ret = true;
uint8_t size = len + 1;
uint32_t timeout_tick = HAL_GetTick() + timeout;
uint32_t timeout_tick = furi_hal_get_tick() + timeout;
do {
while(LL_I2C_IsActiveFlag_BUSY(handle->bus->i2c)) {
if(HAL_GetTick() >= timeout_tick) {
if(furi_hal_get_tick() >= timeout_tick) {
ret = false;
break;
}
@ -331,7 +332,7 @@ bool furi_hal_i2c_write_mem(
size--;
}
if(HAL_GetTick() >= timeout_tick) {
if(furi_hal_get_tick() >= timeout_tick) {
ret = false;
break;
}

View File

@ -1,6 +1,8 @@
#include "furi_hal_i2c_config.h"
#include <furi_hal_resources.h>
#include <furi_hal_version.h>
#include <stm32wbxx_ll_bus.h>
#include <stm32wbxx_ll_rcc.h>
/** Timing register value is computed with the STM32CubeMX Tool,
* Standard Mode @100kHz with I2CCLK = 64 MHz,
@ -70,13 +72,13 @@ void furi_hal_i2c_bus_handle_power_event(
FuriHalI2cBusHandle* handle,
FuriHalI2cBusHandleEvent event) {
if(event == FuriHalI2cBusHandleEventActivate) {
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,
@ -104,11 +106,11 @@ void furi_hal_i2c_bus_handle_power_event(
LL_I2C_EnableClockStretching(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);
}
}
@ -122,9 +124,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};
@ -144,10 +146,12 @@ void furi_hal_i2c_bus_handle_external_event(
LL_I2C_EnableClockStretching(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);
}
}

View File

@ -91,45 +91,45 @@ void furi_hal_ibutton_emulate_stop() {
void furi_hal_ibutton_start_drive() {
furi_hal_ibutton_pin_high();
hal_gpio_init(&ibutton_gpio, GpioModeOutputOpenDrain, GpioPullNo, GpioSpeedLow);
furi_hal_gpio_init(&ibutton_gpio, GpioModeOutputOpenDrain, GpioPullNo, GpioSpeedLow);
}
void furi_hal_ibutton_start_drive_in_isr() {
hal_gpio_init(&ibutton_gpio, GpioModeOutputOpenDrain, GpioPullNo, GpioSpeedLow);
furi_hal_gpio_init(&ibutton_gpio, GpioModeOutputOpenDrain, GpioPullNo, GpioSpeedLow);
LL_EXTI_ClearFlag_0_31(ibutton_gpio.pin);
}
void furi_hal_ibutton_start_interrupt() {
furi_hal_ibutton_pin_high();
hal_gpio_init(&ibutton_gpio, GpioModeInterruptRiseFall, GpioPullNo, GpioSpeedLow);
furi_hal_gpio_init(&ibutton_gpio, GpioModeInterruptRiseFall, GpioPullNo, GpioSpeedLow);
}
void furi_hal_ibutton_start_interrupt_in_isr() {
hal_gpio_init(&ibutton_gpio, GpioModeInterruptRiseFall, GpioPullNo, GpioSpeedLow);
furi_hal_gpio_init(&ibutton_gpio, GpioModeInterruptRiseFall, GpioPullNo, GpioSpeedLow);
LL_EXTI_ClearFlag_0_31(ibutton_gpio.pin);
}
void furi_hal_ibutton_stop() {
furi_hal_ibutton_pin_high();
hal_gpio_init(&ibutton_gpio, GpioModeAnalog, GpioPullNo, GpioSpeedLow);
furi_hal_gpio_init(&ibutton_gpio, GpioModeAnalog, GpioPullNo, GpioSpeedLow);
}
void furi_hal_ibutton_add_interrupt(GpioExtiCallback cb, void* context) {
hal_gpio_add_int_callback(&ibutton_gpio, cb, context);
furi_hal_gpio_add_int_callback(&ibutton_gpio, cb, context);
}
void furi_hal_ibutton_remove_interrupt() {
hal_gpio_remove_int_callback(&ibutton_gpio);
furi_hal_gpio_remove_int_callback(&ibutton_gpio);
}
void furi_hal_ibutton_pin_low() {
hal_gpio_write(&ibutton_gpio, false);
furi_hal_gpio_write(&ibutton_gpio, false);
}
void furi_hal_ibutton_pin_high() {
hal_gpio_write(&ibutton_gpio, true);
furi_hal_gpio_write(&ibutton_gpio, true);
}
bool furi_hal_ibutton_pin_get_level() {
return hal_gpio_read(&ibutton_gpio);
return furi_hal_gpio_read(&ibutton_gpio);
}

View File

@ -14,7 +14,6 @@
#include <stdio.h>
#include <furi.h>
#include <math.h>
#include <main.h>
#define INFRARED_TX_DEBUG 0
@ -138,7 +137,7 @@ static void furi_hal_infrared_tim_rx_isr() {
void furi_hal_infrared_async_rx_start(void) {
furi_assert(furi_hal_infrared_state == InfraredStateIdle);
hal_gpio_init_ex(
furi_hal_gpio_init_ex(
&gpio_infrared_rx, GpioModeAltFunctionPushPull, GpioPullNo, GpioSpeedLow, GpioAltFn1TIM2);
LL_TIM_InitTypeDef TIM_InitStruct = {0};
@ -548,7 +547,7 @@ static void furi_hal_infrared_async_tx_free_resources(void) {
(furi_hal_infrared_state == InfraredStateAsyncTxStopped));
osStatus_t status;
hal_gpio_init(&gpio_infrared_tx, GpioModeOutputOpenDrain, GpioPullDown, GpioSpeedLow);
furi_hal_gpio_init(&gpio_infrared_tx, GpioModeOutputOpenDrain, GpioPullDown, GpioSpeedLow);
furi_hal_interrupt_set_isr(FuriHalInterruptIdDma1Ch1, NULL, NULL);
furi_hal_interrupt_set_isr(FuriHalInterruptIdDma1Ch2, NULL, NULL);
LL_TIM_DeInit(TIM1);
@ -604,12 +603,12 @@ void furi_hal_infrared_async_tx_start(uint32_t freq, float duty_cycle) {
LL_TIM_ClearFlag_UPDATE(TIM1);
LL_DMA_EnableChannel(DMA1, LL_DMA_CHANNEL_1);
LL_DMA_EnableChannel(DMA1, LL_DMA_CHANNEL_2);
delay_us(5);
furi_hal_delay_us(5);
LL_TIM_GenerateEvent_UPDATE(TIM1); /* DMA -> TIMx_RCR */
delay_us(5);
furi_hal_delay_us(5);
LL_GPIO_ResetOutputPin(
gpio_infrared_tx.port, gpio_infrared_tx.pin); /* when disable it prevents false pulse */
hal_gpio_init_ex(
furi_hal_gpio_init_ex(
&gpio_infrared_tx, GpioModeAltFunctionPushPull, GpioPullUp, GpioSpeedHigh, GpioAltFn1TIM1);
FURI_CRITICAL_ENTER();

View File

@ -1,10 +1,11 @@
#include "furi_hal_interrupt.h"
#include "furi_hal_delay.h"
#include <furi.h>
#include <main.h>
#include <stm32wbxx.h>
#include <stm32wbxx_ll_tim.h>
#include <stm32wbxx_ll_rcc.h>
#define TAG "FuriHalInterrupt"
@ -80,9 +81,6 @@ void furi_hal_interrupt_init() {
NVIC_SetPriority(PendSV_IRQn, NVIC_EncodePriority(NVIC_GetPriorityGrouping(), 15, 0));
NVIC_SetPriority(HSEM_IRQn, NVIC_EncodePriority(NVIC_GetPriorityGrouping(), 5, 0));
HAL_NVIC_EnableIRQ(HSEM_IRQn);
FURI_LOG_I(TAG, "Init OK");
}
@ -251,7 +249,7 @@ extern void HW_IPCC_Tx_Handler();
extern void HW_IPCC_Rx_Handler();
void SysTick_Handler(void) {
HAL_IncTick();
furi_hal_tick();
}
void USB_LP_IRQHandler(void) {

View File

@ -2,6 +2,7 @@
#include <stm32wbxx_ll_lptim.h>
#include <stm32wbxx_ll_bus.h>
#include <stm32wbxx_ll_rcc.h>
#include <stdint.h>
// Timer used for system ticks

View File

@ -1,6 +1,7 @@
#include <furi_hal_power.h>
#include <furi_hal_clock.h>
#include <furi_hal_bt.h>
#include <furi_hal_resources.h>
#include <stm32wbxx_ll_rcc.h>
#include <stm32wbxx_ll_pwr.h>
@ -8,7 +9,6 @@
#include <stm32wbxx_ll_cortex.h>
#include <stm32wbxx_ll_gpio.h>
#include <main.h>
#include <hw_conf.h>
#include <bq27220.h>
#include <bq25896.h>

View File

@ -1,5 +1,4 @@
#include <furi_hal_resources.h>
#include "main.h"
#include <furi.h>
const GpioPin vibro_gpio = {.port = VIBRO_GPIO_Port, .pin = VIBRO_Pin};
@ -13,8 +12,16 @@ const GpioPin gpio_display_cs = {.port = DISPLAY_CS_GPIO_Port, .pin = DISPLAY_CS
const GpioPin gpio_display_rst = {.port = DISPLAY_RST_GPIO_Port, .pin = DISPLAY_RST_Pin};
const GpioPin gpio_display_di = {.port = DISPLAY_DI_GPIO_Port, .pin = DISPLAY_DI_Pin};
const GpioPin gpio_sdcard_cs = {.port = SD_CS_GPIO_Port, .pin = SD_CS_Pin};
const GpioPin gpio_sdcard_cd = {.port = SD_CD_GPIO_Port, .pin = SD_CD_Pin};
const GpioPin gpio_nfc_cs = {.port = NFC_CS_GPIO_Port, .pin = NFC_CS_Pin};
const GpioPin gpio_button_up = {.port = GPIOB, .pin = LL_GPIO_PIN_10};
const GpioPin gpio_button_down = {.port = GPIOC, .pin = LL_GPIO_PIN_6};
const GpioPin gpio_button_right = {.port = GPIOB, .pin = LL_GPIO_PIN_12};
const GpioPin gpio_button_left = {.port = GPIOB, .pin = LL_GPIO_PIN_11};
const GpioPin gpio_button_ok = {.port = GPIOH, .pin = LL_GPIO_PIN_3};
const GpioPin gpio_button_back = {.port = GPIOC, .pin = LL_GPIO_PIN_13};
const GpioPin gpio_spi_d_miso = {.port = SPI_D_MISO_GPIO_Port, .pin = SPI_D_MISO_Pin};
const GpioPin gpio_spi_d_mosi = {.port = SPI_D_MOSI_GPIO_Port, .pin = SPI_D_MOSI_Pin};
const GpioPin gpio_spi_d_sck = {.port = SPI_D_SCK_GPIO_Port, .pin = SPI_D_SCK_Pin};
@ -22,14 +29,14 @@ const GpioPin gpio_spi_r_miso = {.port = SPI_R_MISO_GPIO_Port, .pin = SPI_R_MISO
const GpioPin gpio_spi_r_mosi = {.port = SPI_R_MOSI_GPIO_Port, .pin = SPI_R_MOSI_Pin};
const GpioPin gpio_spi_r_sck = {.port = SPI_R_SCK_GPIO_Port, .pin = SPI_R_SCK_Pin};
const GpioPin gpio_ext_pc0 = {.port = GPIOC, .pin = GPIO_PIN_0};
const GpioPin gpio_ext_pc1 = {.port = GPIOC, .pin = GPIO_PIN_1};
const GpioPin gpio_ext_pc3 = {.port = GPIOC, .pin = GPIO_PIN_3};
const GpioPin gpio_ext_pb2 = {.port = GPIOB, .pin = GPIO_PIN_2};
const GpioPin gpio_ext_pb3 = {.port = GPIOB, .pin = GPIO_PIN_3};
const GpioPin gpio_ext_pa4 = {.port = GPIOA, .pin = GPIO_PIN_4};
const GpioPin gpio_ext_pa6 = {.port = GPIOA, .pin = GPIO_PIN_6};
const GpioPin gpio_ext_pa7 = {.port = GPIOA, .pin = GPIO_PIN_7};
const GpioPin gpio_ext_pc0 = {.port = GPIOC, .pin = LL_GPIO_PIN_0};
const GpioPin gpio_ext_pc1 = {.port = GPIOC, .pin = LL_GPIO_PIN_1};
const GpioPin gpio_ext_pc3 = {.port = GPIOC, .pin = LL_GPIO_PIN_3};
const GpioPin gpio_ext_pb2 = {.port = GPIOB, .pin = LL_GPIO_PIN_2};
const GpioPin gpio_ext_pb3 = {.port = GPIOB, .pin = LL_GPIO_PIN_3};
const GpioPin gpio_ext_pa4 = {.port = GPIOA, .pin = LL_GPIO_PIN_4};
const GpioPin gpio_ext_pa6 = {.port = GPIOA, .pin = LL_GPIO_PIN_6};
const GpioPin gpio_ext_pa7 = {.port = GPIOA, .pin = LL_GPIO_PIN_7};
const GpioPin gpio_rfid_pull = {.port = RFID_PULL_GPIO_Port, .pin = RFID_PULL_Pin};
const GpioPin gpio_rfid_carrier_out = {.port = RFID_OUT_GPIO_Port, .pin = RFID_OUT_Pin};
@ -47,20 +54,75 @@ const GpioPin gpio_i2c_power_scl = {.port = GPIOA, .pin = LL_GPIO_PIN_9};
const GpioPin gpio_speaker = {.port = GPIOB, .pin = LL_GPIO_PIN_8};
const GpioPin gpio_button_up = {.port = GPIOB, .pin = LL_GPIO_PIN_10};
const GpioPin gpio_button_down = {.port = GPIOC, .pin = LL_GPIO_PIN_6};
const GpioPin gpio_button_right = {.port = GPIOB, .pin = LL_GPIO_PIN_12};
const GpioPin gpio_button_left = {.port = GPIOB, .pin = LL_GPIO_PIN_11};
const GpioPin gpio_button_ok = {.port = GPIOH, .pin = LL_GPIO_PIN_3};
const GpioPin gpio_button_back = {.port = GPIOC, .pin = LL_GPIO_PIN_13};
const GpioPin periph_power = {.port = PERIPH_POWER_GPIO_Port, .pin = PERIPH_POWER_Pin};
const InputPin input_pins[] = {
{.pin = &gpio_button_up, .key = InputKeyUp, .inverted = true, .name = "Up"},
{.pin = &gpio_button_down, .key = InputKeyDown, .inverted = true, .name = "Down"},
{.pin = &gpio_button_right, .key = InputKeyRight, .inverted = true, .name = "Right"},
{.pin = &gpio_button_left, .key = InputKeyLeft, .inverted = true, .name = "Left"},
{.pin = &gpio_button_ok, .key = InputKeyOk, .inverted = false, .name = "Ok"},
{.pin = &gpio_button_back, .key = InputKeyBack, .inverted = true, .name = "Back"},
{.gpio = &gpio_button_up, .key = InputKeyUp, .inverted = true, .name = "Up"},
{.gpio = &gpio_button_down, .key = InputKeyDown, .inverted = true, .name = "Down"},
{.gpio = &gpio_button_right, .key = InputKeyRight, .inverted = true, .name = "Right"},
{.gpio = &gpio_button_left, .key = InputKeyLeft, .inverted = true, .name = "Left"},
{.gpio = &gpio_button_ok, .key = InputKeyOk, .inverted = false, .name = "Ok"},
{.gpio = &gpio_button_back, .key = InputKeyBack, .inverted = true, .name = "Back"},
};
const size_t input_pins_count = sizeof(input_pins) / sizeof(InputPin);
void furi_hal_resources_init(void) {
// Button pins
for(size_t i = 0; i < input_pins_count; i++) {
furi_hal_gpio_init(
input_pins[i].gpio, GpioModeInterruptRiseFall, GpioPullUp, GpioSpeedLow);
}
// External header pins
furi_hal_gpio_init(&gpio_ext_pc0, GpioModeAnalog, GpioPullNo, GpioSpeedLow);
furi_hal_gpio_init(&gpio_ext_pc1, GpioModeAnalog, GpioPullNo, GpioSpeedLow);
furi_hal_gpio_init(&gpio_ext_pc3, GpioModeAnalog, GpioPullNo, GpioSpeedLow);
furi_hal_gpio_init(&gpio_ext_pb2, GpioModeAnalog, GpioPullNo, GpioSpeedLow);
furi_hal_gpio_init(&gpio_ext_pb3, GpioModeAnalog, GpioPullNo, GpioSpeedLow);
furi_hal_gpio_init(&gpio_ext_pa4, GpioModeAnalog, GpioPullNo, GpioSpeedLow);
furi_hal_gpio_init(&gpio_ext_pa6, GpioModeAnalog, GpioPullNo, GpioSpeedLow);
furi_hal_gpio_init(&gpio_ext_pa7, GpioModeAnalog, GpioPullNo, GpioSpeedLow);
// Display pins
furi_hal_gpio_init(&gpio_display_rst, GpioModeOutputPushPull, GpioPullNo, GpioSpeedLow);
furi_hal_gpio_write(&gpio_display_rst, 0);
furi_hal_gpio_init(&gpio_display_di, GpioModeOutputPushPull, GpioPullNo, GpioSpeedLow);
furi_hal_gpio_write(&gpio_display_di, 0);
// SD pins
furi_hal_gpio_init(&gpio_sdcard_cd, GpioModeInput, GpioPullNo, GpioSpeedLow);
furi_hal_gpio_write(&gpio_sdcard_cd, 0);
furi_hal_gpio_init(&vibro_gpio, GpioModeAnalog, GpioPullNo, GpioSpeedLow);
furi_hal_gpio_init(&ibutton_gpio, GpioModeAnalog, GpioPullNo, GpioSpeedLow);
furi_hal_gpio_init(&gpio_rfid_pull, GpioModeInterruptRise, GpioPullNo, GpioSpeedLow);
furi_hal_gpio_init(&gpio_rf_sw_0, GpioModeOutputPushPull, GpioPullNo, GpioSpeedLow);
furi_hal_gpio_init(&periph_power, GpioModeOutputOpenDrain, GpioPullNo, GpioSpeedLow);
NVIC_SetPriority(EXTI0_IRQn, NVIC_EncodePriority(NVIC_GetPriorityGrouping(), 5, 0));
NVIC_EnableIRQ(EXTI0_IRQn);
NVIC_SetPriority(EXTI1_IRQn, NVIC_EncodePriority(NVIC_GetPriorityGrouping(), 5, 0));
NVIC_EnableIRQ(EXTI1_IRQn);
NVIC_SetPriority(EXTI2_IRQn, NVIC_EncodePriority(NVIC_GetPriorityGrouping(), 5, 0));
NVIC_EnableIRQ(EXTI2_IRQn);
NVIC_SetPriority(EXTI3_IRQn, NVIC_EncodePriority(NVIC_GetPriorityGrouping(), 5, 0));
NVIC_EnableIRQ(EXTI3_IRQn);
NVIC_SetPriority(EXTI4_IRQn, NVIC_EncodePriority(NVIC_GetPriorityGrouping(), 5, 0));
NVIC_EnableIRQ(EXTI4_IRQn);
NVIC_SetPriority(EXTI9_5_IRQn, NVIC_EncodePriority(NVIC_GetPriorityGrouping(), 5, 0));
NVIC_EnableIRQ(EXTI9_5_IRQn);
NVIC_SetPriority(EXTI15_10_IRQn, NVIC_EncodePriority(NVIC_GetPriorityGrouping(), 5, 0));
NVIC_EnableIRQ(EXTI15_10_IRQn);
}

View File

@ -1,6 +1,5 @@
#pragma once
#include "main.h"
#include <furi.h>
#include <stm32wbxx.h>
@ -32,12 +31,15 @@ typedef enum {
} Light;
typedef struct {
const GpioPin* pin;
const GpioPin* gpio;
const InputKey key;
const bool inverted;
const char* name;
} InputPin;
extern const InputPin input_pins[];
extern const size_t input_pins_count;
extern const GpioPin vibro_gpio;
extern const GpioPin ibutton_gpio;
@ -49,6 +51,7 @@ extern const GpioPin gpio_display_cs;
extern const GpioPin gpio_display_rst;
extern const GpioPin gpio_display_di;
extern const GpioPin gpio_sdcard_cs;
extern const GpioPin gpio_sdcard_cd;
extern const GpioPin gpio_nfc_cs;
extern const GpioPin gpio_spi_d_miso;
@ -82,9 +85,115 @@ extern const GpioPin gpio_i2c_power_scl;
extern const GpioPin gpio_speaker;
// Input pins
extern const InputPin input_pins[];
extern const size_t input_pins_count;
extern const GpioPin periph_power;
#define BUTTON_BACK_GPIO_Port GPIOC
#define BUTTON_BACK_Pin LL_GPIO_PIN_13
#define BUTTON_DOWN_GPIO_Port GPIOC
#define BUTTON_DOWN_Pin LL_GPIO_PIN_6
#define BUTTON_LEFT_GPIO_Port GPIOB
#define BUTTON_LEFT_Pin LL_GPIO_PIN_11
#define BUTTON_OK_GPIO_Port GPIOH
#define BUTTON_OK_Pin LL_GPIO_PIN_3
#define BUTTON_RIGHT_GPIO_Port GPIOB
#define BUTTON_RIGHT_Pin LL_GPIO_PIN_12
#define BUTTON_UP_GPIO_Port GPIOB
#define BUTTON_UP_Pin LL_GPIO_PIN_10
#define CC1101_CS_GPIO_Port GPIOD
#define CC1101_CS_Pin LL_GPIO_PIN_0
#define CC1101_G0_GPIO_Port GPIOA
#define CC1101_G0_Pin LL_GPIO_PIN_1
#define DISPLAY_CS_GPIO_Port GPIOC
#define DISPLAY_CS_Pin LL_GPIO_PIN_11
#define DISPLAY_DI_GPIO_Port GPIOB
#define DISPLAY_DI_Pin LL_GPIO_PIN_1
#define DISPLAY_RST_GPIO_Port GPIOB
#define DISPLAY_RST_Pin LL_GPIO_PIN_0
#define IR_RX_GPIO_Port GPIOA
#define IR_RX_Pin LL_GPIO_PIN_0
#define IR_TX_GPIO_Port GPIOB
#define IR_TX_Pin LL_GPIO_PIN_9
#define NFC_CS_GPIO_Port GPIOE
#define NFC_CS_Pin LL_GPIO_PIN_4
#define PA4_GPIO_Port GPIOA
#define PA4_Pin LL_GPIO_PIN_4
#define PA6_GPIO_Port GPIOA
#define PA6_Pin LL_GPIO_PIN_6
#define PA7_GPIO_Port GPIOA
#define PA7_Pin LL_GPIO_PIN_7
#define PB2_GPIO_Port GPIOB
#define PB2_Pin LL_GPIO_PIN_2
#define PB3_GPIO_Port GPIOB
#define PB3_Pin LL_GPIO_PIN_3
#define PC0_GPIO_Port GPIOC
#define PC0_Pin LL_GPIO_PIN_0
#define PC1_GPIO_Port GPIOC
#define PC1_Pin LL_GPIO_PIN_1
#define PC3_GPIO_Port GPIOC
#define PC3_Pin LL_GPIO_PIN_3
#define PERIPH_POWER_GPIO_Port GPIOA
#define PERIPH_POWER_Pin LL_GPIO_PIN_3
#define QUARTZ_32MHZ_IN_GPIO_Port GPIOC
#define QUARTZ_32MHZ_IN_Pin LL_GPIO_PIN_14
#define QUARTZ_32MHZ_OUT_GPIO_Port GPIOC
#define QUARTZ_32MHZ_OUT_Pin LL_GPIO_PIN_15
#define RFID_OUT_GPIO_Port GPIOB
#define RFID_OUT_Pin LL_GPIO_PIN_13
#define RFID_PULL_GPIO_Port GPIOA
#define RFID_PULL_Pin LL_GPIO_PIN_2
#define RFID_RF_IN_GPIO_Port GPIOC
#define RFID_RF_IN_Pin LL_GPIO_PIN_5
#define RFID_CARRIER_GPIO_Port GPIOA
#define RFID_CARRIER_Pin LL_GPIO_PIN_15
#define RF_SW_0_GPIO_Port GPIOC
#define RF_SW_0_Pin LL_GPIO_PIN_4
#define SD_CD_GPIO_Port GPIOC
#define SD_CD_Pin LL_GPIO_PIN_10
#define SD_CS_GPIO_Port GPIOC
#define SD_CS_Pin LL_GPIO_PIN_12
#define SPEAKER_GPIO_Port GPIOB
#define SPEAKER_Pin LL_GPIO_PIN_8
#define VIBRO_GPIO_Port GPIOA
#define VIBRO_Pin LL_GPIO_PIN_8
#define iBTN_GPIO_Port GPIOB
#define iBTN_Pin LL_GPIO_PIN_14
#define USART1_TX_Pin LL_GPIO_PIN_6
#define USART1_TX_Port GPIOB
#define USART1_RX_Pin LL_GPIO_PIN_7
#define USART1_RX_Port GPIOB
#define SPI_D_MISO_GPIO_Port GPIOC
#define SPI_D_MISO_Pin LL_GPIO_PIN_2
#define SPI_D_MOSI_GPIO_Port GPIOB
#define SPI_D_MOSI_Pin LL_GPIO_PIN_15
#define SPI_D_SCK_GPIO_Port GPIOD
#define SPI_D_SCK_Pin LL_GPIO_PIN_1
#define SPI_R_MISO_GPIO_Port GPIOB
#define SPI_R_MISO_Pin LL_GPIO_PIN_4
#define SPI_R_MOSI_GPIO_Port GPIOB
#define SPI_R_MOSI_Pin LL_GPIO_PIN_5
#define SPI_R_SCK_GPIO_Port GPIOA
#define SPI_R_SCK_Pin LL_GPIO_PIN_5
#define NFC_IRQ_Pin RFID_PULL_Pin
#define NFC_IRQ_GPIO_Port RFID_PULL_GPIO_Port
void furi_hal_resources_init(void);
#ifdef __cplusplus
}

View File

@ -65,16 +65,16 @@ void furi_hal_rfid_pins_reset() {
furi_hal_ibutton_stop();
// pulldown rfid antenna
hal_gpio_init(&gpio_rfid_carrier_out, GpioModeOutputPushPull, GpioPullNo, GpioSpeedLow);
hal_gpio_write(&gpio_rfid_carrier_out, false);
furi_hal_gpio_init(&gpio_rfid_carrier_out, GpioModeOutputPushPull, GpioPullNo, GpioSpeedLow);
furi_hal_gpio_write(&gpio_rfid_carrier_out, false);
// from both sides
hal_gpio_init(&gpio_rfid_pull, GpioModeOutputPushPull, GpioPullNo, GpioSpeedLow);
hal_gpio_write(&gpio_rfid_pull, true);
furi_hal_gpio_init(&gpio_rfid_pull, GpioModeOutputPushPull, GpioPullNo, GpioSpeedLow);
furi_hal_gpio_write(&gpio_rfid_pull, true);
hal_gpio_init_simple(&gpio_rfid_carrier, GpioModeAnalog);
furi_hal_gpio_init_simple(&gpio_rfid_carrier, GpioModeAnalog);
hal_gpio_init(&gpio_rfid_data_in, GpioModeAnalog, GpioPullNo, GpioSpeedLow);
furi_hal_gpio_init(&gpio_rfid_data_in, GpioModeAnalog, GpioPullNo, GpioSpeedLow);
}
void furi_hal_rfid_pins_emulate() {
@ -83,14 +83,14 @@ void furi_hal_rfid_pins_emulate() {
furi_hal_ibutton_pin_low();
// pull pin to timer out
hal_gpio_init_ex(
furi_hal_gpio_init_ex(
&gpio_rfid_pull, GpioModeAltFunctionPushPull, GpioPullNo, GpioSpeedLow, GpioAltFn1TIM2);
// pull rfid antenna from carrier side
hal_gpio_init(&gpio_rfid_carrier_out, GpioModeOutputPushPull, GpioPullNo, GpioSpeedLow);
hal_gpio_write(&gpio_rfid_carrier_out, false);
furi_hal_gpio_init(&gpio_rfid_carrier_out, GpioModeOutputPushPull, GpioPullNo, GpioSpeedLow);
furi_hal_gpio_write(&gpio_rfid_carrier_out, false);
hal_gpio_init_ex(
furi_hal_gpio_init_ex(
&gpio_rfid_carrier, GpioModeAltFunctionPushPull, GpioPullNo, GpioSpeedLow, GpioAltFn2TIM2);
}
@ -100,11 +100,11 @@ void furi_hal_rfid_pins_read() {
furi_hal_ibutton_pin_low();
// dont pull rfid antenna
hal_gpio_init(&gpio_rfid_pull, GpioModeOutputPushPull, GpioPullNo, GpioSpeedLow);
hal_gpio_write(&gpio_rfid_pull, false);
furi_hal_gpio_init(&gpio_rfid_pull, GpioModeOutputPushPull, GpioPullNo, GpioSpeedLow);
furi_hal_gpio_write(&gpio_rfid_pull, false);
// carrier pin to timer out
hal_gpio_init_ex(
furi_hal_gpio_init_ex(
&gpio_rfid_carrier_out,
GpioModeAltFunctionPushPull,
GpioPullNo,
@ -112,15 +112,15 @@ void furi_hal_rfid_pins_read() {
GpioAltFn1TIM1);
// comparator in
hal_gpio_init(&gpio_rfid_data_in, GpioModeAnalog, GpioPullNo, GpioSpeedLow);
furi_hal_gpio_init(&gpio_rfid_data_in, GpioModeAnalog, GpioPullNo, GpioSpeedLow);
}
void furi_hal_rfid_pin_pull_release() {
hal_gpio_write(&gpio_rfid_pull, true);
furi_hal_gpio_write(&gpio_rfid_pull, true);
}
void furi_hal_rfid_pin_pull_pulldown() {
hal_gpio_write(&gpio_rfid_pull, false);
furi_hal_gpio_write(&gpio_rfid_pull, false);
}
void furi_hal_rfid_tim_read(float freq, float duty_cycle) {

View File

@ -1,6 +1,7 @@
#include "furi_hal_sd.h"
#include <stm32wbxx_ll_gpio.h>
#include <furi.h>
#include <furi_hal.h>
void hal_sd_detect_init(void) {
// low speed input with pullup

View File

@ -16,7 +16,7 @@ void furi_hal_speaker_init() {
LL_TIM_DeInit(FURI_HAL_SPEAKER_TIMER);
FURI_CRITICAL_EXIT();
hal_gpio_init_ex(
furi_hal_gpio_init_ex(
&gpio_speaker, GpioModeAltFunctionPushPull, GpioPullNo, GpioSpeedLow, GpioAltFn14TIM16);
}

View File

@ -139,42 +139,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);
}
@ -230,22 +230,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,
@ -253,15 +253,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);
}
}

View File

@ -7,6 +7,8 @@
#include <furi_hal_interrupt.h>
#include <furi_hal_resources.h>
#include <stm32wbxx_ll_dma.h>
#include <furi.h>
#include <cc1101.h>
#include <stdio.h>
@ -328,34 +330,34 @@ void furi_hal_subghz_init() {
furi_hal_spi_acquire(&furi_hal_spi_bus_handle_subghz);
#ifdef FURI_HAL_SUBGHZ_TX_GPIO
hal_gpio_init(&FURI_HAL_SUBGHZ_TX_GPIO, GpioModeOutputPushPull, GpioPullNo, GpioSpeedLow);
furi_hal_gpio_init(&FURI_HAL_SUBGHZ_TX_GPIO, GpioModeOutputPushPull, GpioPullNo, GpioSpeedLow);
#endif
// Reset
hal_gpio_init(&gpio_cc1101_g0, GpioModeAnalog, GpioPullNo, GpioSpeedLow);
furi_hal_gpio_init(&gpio_cc1101_g0, GpioModeAnalog, GpioPullNo, GpioSpeedLow);
cc1101_reset(&furi_hal_spi_bus_handle_subghz);
cc1101_write_reg(&furi_hal_spi_bus_handle_subghz, CC1101_IOCFG0, CC1101IocfgHighImpedance);
// Prepare GD0 for power on self test
hal_gpio_init(&gpio_cc1101_g0, GpioModeInput, GpioPullNo, GpioSpeedLow);
furi_hal_gpio_init(&gpio_cc1101_g0, GpioModeInput, GpioPullNo, GpioSpeedLow);
// GD0 low
cc1101_write_reg(&furi_hal_spi_bus_handle_subghz, CC1101_IOCFG0, CC1101IocfgHW);
while(hal_gpio_read(&gpio_cc1101_g0) != false)
while(furi_hal_gpio_read(&gpio_cc1101_g0) != false)
;
// GD0 high
cc1101_write_reg(
&furi_hal_spi_bus_handle_subghz, CC1101_IOCFG0, CC1101IocfgHW | CC1101_IOCFG_INV);
while(hal_gpio_read(&gpio_cc1101_g0) != true)
while(furi_hal_gpio_read(&gpio_cc1101_g0) != true)
;
// Reset GD0 to floating state
cc1101_write_reg(&furi_hal_spi_bus_handle_subghz, CC1101_IOCFG0, CC1101IocfgHighImpedance);
hal_gpio_init(&gpio_cc1101_g0, GpioModeAnalog, GpioPullNo, GpioSpeedLow);
furi_hal_gpio_init(&gpio_cc1101_g0, GpioModeAnalog, GpioPullNo, GpioSpeedLow);
// RF switches
hal_gpio_init(&gpio_rf_sw_0, GpioModeOutputPushPull, GpioPullNo, GpioSpeedLow);
furi_hal_gpio_init(&gpio_rf_sw_0, GpioModeOutputPushPull, GpioPullNo, GpioSpeedLow);
cc1101_write_reg(&furi_hal_spi_bus_handle_subghz, CC1101_IOCFG2, CC1101IocfgHW);
// Go to sleep
@ -372,7 +374,7 @@ void furi_hal_subghz_sleep() {
cc1101_switch_to_idle(&furi_hal_spi_bus_handle_subghz);
cc1101_write_reg(&furi_hal_spi_bus_handle_subghz, CC1101_IOCFG0, CC1101IocfgHighImpedance);
hal_gpio_init(&gpio_cc1101_g0, GpioModeAnalog, GpioPullNo, GpioSpeedLow);
furi_hal_gpio_init(&gpio_cc1101_g0, GpioModeAnalog, GpioPullNo, GpioSpeedLow);
cc1101_shutdown(&furi_hal_spi_bus_handle_subghz);
@ -493,7 +495,7 @@ void furi_hal_subghz_shutdown() {
void furi_hal_subghz_reset() {
furi_hal_spi_acquire(&furi_hal_spi_bus_handle_subghz);
hal_gpio_init(&gpio_cc1101_g0, GpioModeAnalog, GpioPullNo, GpioSpeedLow);
furi_hal_gpio_init(&gpio_cc1101_g0, GpioModeAnalog, GpioPullNo, GpioSpeedLow);
cc1101_switch_to_idle(&furi_hal_spi_bus_handle_subghz);
cc1101_reset(&furi_hal_spi_bus_handle_subghz);
cc1101_write_reg(&furi_hal_spi_bus_handle_subghz, CC1101_IOCFG0, CC1101IocfgHighImpedance);
@ -634,18 +636,18 @@ uint32_t furi_hal_subghz_set_frequency(uint32_t value) {
void furi_hal_subghz_set_path(FuriHalSubGhzPath path) {
furi_hal_spi_acquire(&furi_hal_spi_bus_handle_subghz);
if(path == FuriHalSubGhzPath433) {
hal_gpio_write(&gpio_rf_sw_0, 0);
furi_hal_gpio_write(&gpio_rf_sw_0, 0);
cc1101_write_reg(
&furi_hal_spi_bus_handle_subghz, CC1101_IOCFG2, CC1101IocfgHW | CC1101_IOCFG_INV);
} else if(path == FuriHalSubGhzPath315) {
hal_gpio_write(&gpio_rf_sw_0, 1);
furi_hal_gpio_write(&gpio_rf_sw_0, 1);
cc1101_write_reg(&furi_hal_spi_bus_handle_subghz, CC1101_IOCFG2, CC1101IocfgHW);
} else if(path == FuriHalSubGhzPath868) {
hal_gpio_write(&gpio_rf_sw_0, 1);
furi_hal_gpio_write(&gpio_rf_sw_0, 1);
cc1101_write_reg(
&furi_hal_spi_bus_handle_subghz, CC1101_IOCFG2, CC1101IocfgHW | CC1101_IOCFG_INV);
} else if(path == FuriHalSubGhzPathIsolate) {
hal_gpio_write(&gpio_rf_sw_0, 0);
furi_hal_gpio_write(&gpio_rf_sw_0, 0);
cc1101_write_reg(&furi_hal_spi_bus_handle_subghz, CC1101_IOCFG2, CC1101IocfgHW);
} else {
furi_crash(NULL);
@ -688,7 +690,7 @@ void furi_hal_subghz_start_async_rx(FuriHalSubGhzCaptureCallback callback, void*
furi_hal_subghz_capture_callback = callback;
furi_hal_subghz_capture_callback_context = context;
hal_gpio_init_ex(
furi_hal_gpio_init_ex(
&gpio_cc1101_g0, GpioModeAltFunctionPushPull, GpioPullNo, GpioSpeedLow, GpioAltFn1TIM2);
// Timer: base
@ -750,7 +752,7 @@ void furi_hal_subghz_stop_async_rx() {
FURI_CRITICAL_EXIT();
furi_hal_interrupt_set_isr(FuriHalInterruptIdTIM2, NULL, NULL);
hal_gpio_init(&gpio_cc1101_g0, GpioModeAnalog, GpioPullNo, GpioSpeedLow);
furi_hal_gpio_init(&gpio_cc1101_g0, GpioModeAnalog, GpioPullNo, GpioSpeedLow);
}
#define API_HAL_SUBGHZ_ASYNC_TX_BUFFER_FULL (256)
@ -838,7 +840,7 @@ static void furi_hal_subghz_async_tx_timer_isr() {
if(furi_hal_subghz_state == SubGhzStateAsyncTx) {
furi_hal_subghz_state = SubGhzStateAsyncTxLast;
//forcibly pulls the pin to the ground so that there is no carrier
hal_gpio_init(&gpio_cc1101_g0, GpioModeInput, GpioPullDown, GpioSpeedLow);
furi_hal_gpio_init(&gpio_cc1101_g0, GpioModeInput, GpioPullDown, GpioSpeedLow);
} else {
furi_hal_subghz_state = SubGhzStateAsyncTxEnd;
LL_TIM_DisableCounter(TIM2);
@ -868,7 +870,7 @@ bool furi_hal_subghz_start_async_tx(FuriHalSubGhzAsyncTxCallback callback, void*
furi_hal_subghz_async_tx.buffer, API_HAL_SUBGHZ_ASYNC_TX_BUFFER_FULL);
// Connect CC1101_GD0 to TIM2 as output
hal_gpio_init_ex(
furi_hal_gpio_init_ex(
&gpio_cc1101_g0, GpioModeAltFunctionPushPull, GpioPullDown, GpioSpeedLow, GpioAltFn1TIM2);
// Configure DMA
@ -920,7 +922,7 @@ bool furi_hal_subghz_start_async_tx(FuriHalSubGhzAsyncTxCallback callback, void*
// Start counter
LL_TIM_GenerateEvent_UPDATE(TIM2);
#ifdef FURI_HAL_SUBGHZ_TX_GPIO
hal_gpio_write(&FURI_HAL_SUBGHZ_TX_GPIO, true);
furi_hal_gpio_write(&FURI_HAL_SUBGHZ_TX_GPIO, true);
#endif
furi_hal_subghz_tx();
@ -942,7 +944,7 @@ void furi_hal_subghz_stop_async_tx() {
// Shutdown radio
furi_hal_subghz_idle();
#ifdef FURI_HAL_SUBGHZ_TX_GPIO
hal_gpio_write(&FURI_HAL_SUBGHZ_TX_GPIO, false);
furi_hal_gpio_write(&FURI_HAL_SUBGHZ_TX_GPIO, false);
#endif
// Deinitialize Timer
@ -956,7 +958,7 @@ void furi_hal_subghz_stop_async_tx() {
furi_hal_interrupt_set_isr(FuriHalInterruptIdDma1Ch1, NULL, NULL);
// Deinitialize GPIO
hal_gpio_init(&gpio_cc1101_g0, GpioModeAnalog, GpioPullNo, GpioSpeedLow);
furi_hal_gpio_init(&gpio_cc1101_g0, GpioModeAnalog, GpioPullNo, GpioSpeedLow);
FURI_CRITICAL_EXIT();
free(furi_hal_subghz_async_tx.buffer);

View File

@ -2,6 +2,7 @@
#include <stdbool.h>
#include <stm32wbxx_ll_lpuart.h>
#include <stm32wbxx_ll_usart.h>
#include <stm32wbxx_ll_rcc.h>
#include <furi_hal_resources.h>
#include <furi.h>
@ -11,13 +12,13 @@ static void (*irq_cb[2])(uint8_t ev, uint8_t data, void* context);
static void* irq_ctx[2];
static void furi_hal_usart_init(uint32_t baud) {
hal_gpio_init_ex(
furi_hal_gpio_init_ex(
&gpio_usart_tx,
GpioModeAltFunctionPushPull,
GpioPullUp,
GpioSpeedVeryHigh,
GpioAltFn7USART1);
hal_gpio_init_ex(
furi_hal_gpio_init_ex(
&gpio_usart_rx,
GpioModeAltFunctionPushPull,
GpioPullUp,
@ -44,17 +45,17 @@ static void furi_hal_usart_init(uint32_t baud) {
LL_USART_EnableIT_RXNE_RXFNE(USART1);
LL_USART_EnableIT_IDLE(USART1);
HAL_NVIC_SetPriority(USART1_IRQn, 5, 0);
NVIC_SetPriority(USART1_IRQn, NVIC_EncodePriority(NVIC_GetPriorityGrouping(), 5, 0));
}
static void furi_hal_lpuart_init(uint32_t baud) {
hal_gpio_init_ex(
furi_hal_gpio_init_ex(
&gpio_ext_pc0,
GpioModeAltFunctionPushPull,
GpioPullUp,
GpioSpeedVeryHigh,
GpioAltFn8LPUART1);
hal_gpio_init_ex(
furi_hal_gpio_init_ex(
&gpio_ext_pc1,
GpioModeAltFunctionPushPull,
GpioPullUp,
@ -81,7 +82,7 @@ static void furi_hal_lpuart_init(uint32_t baud) {
LL_LPUART_EnableIT_RXNE_RXFNE(LPUART1);
LL_LPUART_EnableIT_IDLE(LPUART1);
HAL_NVIC_SetPriority(LPUART1_IRQn, 5, 0);
NVIC_SetPriority(LPUART1_IRQn, NVIC_EncodePriority(NVIC_GetPriorityGrouping(), 5, 0));
}
void furi_hal_uart_init(FuriHalUartId ch, uint32_t baud) {
@ -126,12 +127,12 @@ void furi_hal_uart_deinit(FuriHalUartId ch) {
furi_hal_uart_set_irq_cb(ch, NULL, NULL);
if(ch == FuriHalUartIdUSART1) {
LL_USART_Disable(USART1);
hal_gpio_init(&gpio_usart_tx, GpioModeAnalog, GpioPullNo, GpioSpeedLow);
hal_gpio_init(&gpio_usart_rx, GpioModeAnalog, GpioPullNo, GpioSpeedLow);
furi_hal_gpio_init(&gpio_usart_tx, GpioModeAnalog, GpioPullNo, GpioSpeedLow);
furi_hal_gpio_init(&gpio_usart_rx, GpioModeAnalog, GpioPullNo, GpioSpeedLow);
} else if(ch == FuriHalUartIdLPUART1) {
LL_LPUART_Disable(LPUART1);
hal_gpio_init(&gpio_ext_pc0, GpioModeAnalog, GpioPullNo, GpioSpeedLow);
hal_gpio_init(&gpio_ext_pc1, GpioModeAnalog, GpioPullNo, GpioSpeedLow);
furi_hal_gpio_init(&gpio_ext_pc0, GpioModeAnalog, GpioPullNo, GpioSpeedLow);
furi_hal_gpio_init(&gpio_ext_pc1, GpioModeAnalog, GpioPullNo, GpioSpeedLow);
}
}

View File

@ -3,6 +3,7 @@
#include "furi_hal_usb.h"
#include "furi_hal_vcp.h"
#include <furi_hal_power.h>
#include <stm32wbxx_ll_pwr.h>
#include <furi.h>
#include "usb.h"
@ -75,7 +76,7 @@ void furi_hal_usb_init(void) {
usb.enabled = false;
usb.if_cur = NULL;
HAL_NVIC_SetPriority(USB_LP_IRQn, 5, 0);
NVIC_SetPriority(USB_LP_IRQn, NVIC_EncodePriority(NVIC_GetPriorityGrouping(), 5, 0));
NVIC_EnableIRQ(USB_LP_IRQn);
usb.thread = furi_thread_alloc();

View File

@ -4,11 +4,11 @@
#define TAG "FuriHalVibro"
void furi_hal_vibro_init() {
hal_gpio_init(&vibro_gpio, GpioModeOutputPushPull, GpioPullNo, GpioSpeedLow);
hal_gpio_write(&vibro_gpio, false);
furi_hal_gpio_init(&vibro_gpio, GpioModeOutputPushPull, GpioPullNo, GpioSpeedLow);
furi_hal_gpio_write(&vibro_gpio, false);
FURI_LOG_I(TAG, "Init OK");
}
void furi_hal_vibro_on(bool value) {
hal_gpio_write(&vibro_gpio, value);
furi_hal_gpio_write(&vibro_gpio, value);
}

View File

@ -41,25 +41,13 @@ ASM_SOURCES += $(MXPROJECT_DIR)/startup_stm32wb55xx_cm4.s
CUBE_DIR = ../lib/STM32CubeWB
CFLAGS += \
-DUSE_FULL_LL_DRIVER \
-DUSE_HAL_DRIVER \
-DHAVE_FREERTOS
CFLAGS += \
-I$(CUBE_DIR)/Drivers/STM32WBxx_HAL_Driver/Inc \
-I$(CUBE_DIR)/Drivers/STM32WBxx_HAL_Driver/Inc/Legacy \
-I$(CUBE_DIR)/Drivers/CMSIS/Device/ST \
-I$(CUBE_DIR)/Drivers/CMSIS/Device/ST/STM32WBxx/Include \
-I$(CUBE_DIR)/Drivers/CMSIS/Include
C_SOURCES += \
$(CUBE_DIR)/Drivers/STM32WBxx_HAL_Driver/Src/stm32wbxx_hal.c \
$(CUBE_DIR)/Drivers/STM32WBxx_HAL_Driver/Src/stm32wbxx_hal_cortex.c \
$(CUBE_DIR)/Drivers/STM32WBxx_HAL_Driver/Src/stm32wbxx_hal_cryp.c \
$(CUBE_DIR)/Drivers/STM32WBxx_HAL_Driver/Src/stm32wbxx_hal_exti.c \
$(CUBE_DIR)/Drivers/STM32WBxx_HAL_Driver/Src/stm32wbxx_hal_gpio.c \
$(CUBE_DIR)/Drivers/STM32WBxx_HAL_Driver/Src/stm32wbxx_hal_pcd.c \
$(CUBE_DIR)/Drivers/STM32WBxx_HAL_Driver/Src/stm32wbxx_hal_pcd_ex.c \
$(CUBE_DIR)/Drivers/STM32WBxx_HAL_Driver/Src/stm32wbxx_hal_pwr.c \
$(CUBE_DIR)/Drivers/STM32WBxx_HAL_Driver/Src/stm32wbxx_hal_pwr_ex.c \
$(CUBE_DIR)/Drivers/STM32WBxx_HAL_Driver/Src/stm32wbxx_hal_rcc.c \
$(CUBE_DIR)/Drivers/STM32WBxx_HAL_Driver/Src/stm32wbxx_ll_adc.c \
$(CUBE_DIR)/Drivers/STM32WBxx_HAL_Driver/Src/stm32wbxx_ll_comp.c \
$(CUBE_DIR)/Drivers/STM32WBxx_HAL_Driver/Src/stm32wbxx_ll_dma.c \

View File

@ -5,7 +5,7 @@
#pragma once
#include "main.h"
#include <stdint.h>
#ifdef __cplusplus
extern "C" {
@ -17,26 +17,31 @@ extern uint32_t instructions_per_us;
*/
void furi_hal_delay_init(void);
/** Increase tick counter.
* Should be called from SysTick ISR
*/
void furi_hal_tick(void);
/** Get current tick counter
*
* System uptime, may overflow.
*
* @return Current ticks in milliseconds
*/
uint32_t furi_hal_get_tick(void);
/** Delay in milliseconds
* @warning Cannot be used from ISR
*
* @param[in] milliseconds milliseconds to wait
*/
void delay(float milliseconds);
void furi_hal_delay_ms(float milliseconds);
/** Delay in microseconds
*
* @param[in] microseconds microseconds to wait
*/
void delay_us(float microseconds);
/** Get current millisecond
*
* System uptime, pProvided by HAL, may overflow.
*
* @return Current milliseconds
*/
uint32_t millis(void);
void furi_hal_delay_us(float microseconds);
#ifdef __cplusplus
}

View File

@ -7,7 +7,6 @@
#include <stdint.h>
#include <stdbool.h>
#include <main.h>
#ifdef __cplusplus
extern "C" {

View File

@ -7,7 +7,6 @@
#include <stdint.h>
#include <stdbool.h>
#include <main.h>
#ifdef __cplusplus
extern "C" {

View File

@ -1,6 +1,5 @@
#include "platform.h"
#include <assert.h>
#include <main.h>
#include <furi.h>
#include <furi_hal_spi.h>
@ -30,25 +29,25 @@ void platformIrqThread() {
}
void platformEnableIrqCallback() {
hal_gpio_init(&pin, GpioModeInterruptRise, GpioPullDown, GpioSpeedLow);
hal_gpio_enable_int_callback(&pin);
furi_hal_gpio_init(&pin, GpioModeInterruptRise, GpioPullDown, GpioSpeedLow);
furi_hal_gpio_enable_int_callback(&pin);
}
void platformDisableIrqCallback() {
hal_gpio_init(&pin, GpioModeOutputOpenDrain, GpioPullNo, GpioSpeedLow);
hal_gpio_disable_int_callback(&pin);
furi_hal_gpio_init(&pin, GpioModeOutputOpenDrain, GpioPullNo, GpioSpeedLow);
furi_hal_gpio_disable_int_callback(&pin);
}
void platformSetIrqCallback(PlatformIrqCallback callback) {
platform_irq_callback = callback;
platform_irq_thread_id = osThreadNew(platformIrqThread, NULL, &platform_irq_thread_attr);
hal_gpio_add_int_callback(&pin, nfc_isr, NULL);
furi_hal_gpio_add_int_callback(&pin, nfc_isr, NULL);
// Disable interrupt callback as the pin is shared between 2 apps
// It is enabled in rfalLowPowerModeStop()
hal_gpio_disable_int_callback(&pin);
furi_hal_gpio_disable_int_callback(&pin);
}
HAL_StatusTypeDef platformSpiTxRx(const uint8_t* txBuf, uint8_t* rxBuf, uint16_t len) {
bool platformSpiTxRx(const uint8_t* txBuf, uint8_t* rxBuf, uint16_t len) {
bool ret = false;
if(txBuf && rxBuf) {
ret =
@ -59,11 +58,7 @@ HAL_StatusTypeDef platformSpiTxRx(const uint8_t* txBuf, uint8_t* rxBuf, uint16_t
ret = furi_hal_spi_bus_rx(&furi_hal_spi_bus_handle_nfc, (uint8_t*)rxBuf, len, 1000);
}
if(!ret) {
return HAL_ERROR;
} else {
return HAL_OK;
}
return ret;
}
void platformProtectST25RComm() {

View File

@ -5,10 +5,8 @@
#include <stdbool.h>
#include <limits.h>
#include <cmsis_os2.h>
#include <gpio.h>
#include "timer.h"
#include "math.h"
#include "main.h"
#include <furi_hal_gpio.h>
#include <furi_hal_light.h>
#include <furi_hal_spi.h>
@ -18,7 +16,7 @@ void platformSetIrqCallback(PlatformIrqCallback cb);
void platformEnableIrqCallback();
void platformDisableIrqCallback();
HAL_StatusTypeDef platformSpiTxRx(const uint8_t* txBuf, uint8_t* rxBuf, uint16_t len);
bool platformSpiTxRx(const uint8_t* txBuf, uint8_t* rxBuf, uint16_t len);
void platformProtectST25RComm();
void platformUnprotectST25RComm();
@ -87,11 +85,18 @@ void platformUnprotectST25RComm();
#define platformUnprotectST25RIrqStatus() \
platformUnprotectST25RComm() /*!< Unprotect the IRQ status var - IRQ enable on a single thread environment (MCU) ; Mutex unlock on a multi thread environment */
#define platformGpioSet(port, pin) LL_GPIO_SetOutputPin(port, pin)
#define platformGpioSet(port, pin) \
furi_hal_gpio_write_port_pin( \
port, pin, true) /*!< Turns the given GPIO High */
#define platformGpioClear(port, pin) \
furi_hal_gpio_write_port_pin( \
port, pin, false) /*!< Turns the given GPIO Low */
#define platformGpioClear(port, pin) LL_GPIO_ResetOutputPin(port, pin)
#define platformGpioIsHigh(port, pin) LL_GPIO_IsInputPinSet(port, pin)
#define platformGpioIsHigh(port, pin) \
(furi_hal_gpio_read_port_pin(port, pin) == \
true) /*!< Checks if the given LED is High */
#define platformGpioIsLow(port, pin) \
(!platformGpioIsHigh(port, pin)) /*!< Checks if the given LED is Low */
#define platformTimerCreate(t) \
timerCalculateTimer(t) /*!< Create a timer with the given time (ms) */

View File

@ -41,6 +41,7 @@
******************************************************************************
*/
#include "timer.h"
#include <furi_hal_delay.h>
/*
******************************************************************************
@ -64,7 +65,7 @@ static uint32_t timerStopwatchTick;
/*******************************************************************************/
uint32_t timerCalculateTimer(uint16_t time) {
return (HAL_GetTick() + time);
return (furi_hal_get_tick() + time);
}
/*******************************************************************************/
@ -72,7 +73,7 @@ bool timerIsExpired(uint32_t timer) {
uint32_t uDiff;
int32_t sDiff;
uDiff = (timer - HAL_GetTick()); /* Calculate the diff between the timers */
uDiff = (timer - furi_hal_get_tick()); /* Calculate the diff between the timers */
sDiff = uDiff; /* Convert the diff to a signed var */
/* Check if the given timer has expired already */
@ -95,10 +96,10 @@ void timerDelay(uint16_t tOut) {
/*******************************************************************************/
void timerStopwatchStart(void) {
timerStopwatchTick = HAL_GetTick();
timerStopwatchTick = furi_hal_get_tick();
}
/*******************************************************************************/
uint32_t timerStopwatchMeasure(void) {
return (uint32_t)(HAL_GetTick() - timerStopwatchTick);
return (uint32_t)(furi_hal_get_tick() - timerStopwatchTick);
}

View File

@ -42,7 +42,7 @@ bool bq27220_set_parameter_u16(FuriHalI2cBusHandle* handle, uint16_t address, ui
ret = furi_hal_i2c_write_mem(
handle, BQ27220_ADDRESS, CommandSelectSubclass, buffer, 4, BQ27220_I2C_TIMEOUT);
delay_us(10000);
furi_hal_delay_us(10000);
uint8_t checksum = bq27220_get_checksum(buffer, 4);
buffer[0] = checksum;
@ -50,7 +50,7 @@ bool bq27220_set_parameter_u16(FuriHalI2cBusHandle* handle, uint16_t address, ui
ret = furi_hal_i2c_write_mem(
handle, BQ27220_ADDRESS, CommandMACDataSum, buffer, 2, BQ27220_I2C_TIMEOUT);
delay_us(10000);
furi_hal_delay_us(10000);
return ret;
}
@ -96,7 +96,7 @@ bool bq27220_init(FuriHalI2cBusHandle* handle, const ParamCEDV* cedv) {
bq27220_set_parameter_u16(handle, AddressEDV2, cedv->EDV2);
bq27220_control(handle, Control_EXIT_CFG_UPDATE_REINIT);
delay_us(10000);
furi_hal_delay_us(10000);
design_cap = bq27220_get_design_capacity(handle);
if(cedv->design_cap == design_cap) {
FURI_LOG_I(TAG, "Battery profile update success");

View File

@ -8,7 +8,7 @@ CC1101Status cc1101_strobe(FuriHalSpiBusHandle* handle, uint8_t strobe) {
uint8_t tx[1] = {strobe};
CC1101Status rx[1] = {0};
while(hal_gpio_read(handle->miso))
while(furi_hal_gpio_read(handle->miso))
;
furi_hal_spi_bus_trx(handle, tx, (uint8_t*)rx, 1, CC1101_TIMEOUT);
@ -20,7 +20,7 @@ CC1101Status cc1101_write_reg(FuriHalSpiBusHandle* handle, uint8_t reg, uint8_t
uint8_t tx[2] = {reg, data};
CC1101Status rx[2] = {0};
while(hal_gpio_read(handle->miso))
while(furi_hal_gpio_read(handle->miso))
;
furi_hal_spi_bus_trx(handle, tx, (uint8_t*)rx, 2, CC1101_TIMEOUT);
@ -33,7 +33,7 @@ CC1101Status cc1101_read_reg(FuriHalSpiBusHandle* handle, uint8_t reg, uint8_t*
uint8_t tx[2] = {reg | CC1101_READ, 0};
CC1101Status rx[2] = {0};
while(hal_gpio_read(handle->miso))
while(furi_hal_gpio_read(handle->miso))
;
furi_hal_spi_bus_trx(handle, tx, (uint8_t*)rx, 2, CC1101_TIMEOUT);
@ -128,7 +128,7 @@ void cc1101_set_pa_table(FuriHalSpiBusHandle* handle, const uint8_t value[8]) {
memcpy(&tx[1], &value[0], 8);
while(hal_gpio_read(handle->miso))
while(furi_hal_gpio_read(handle->miso))
;
furi_hal_spi_bus_trx(handle, tx, (uint8_t*)rx, sizeof(rx), CC1101_TIMEOUT);
@ -143,7 +143,7 @@ uint8_t cc1101_write_fifo(FuriHalSpiBusHandle* handle, const uint8_t* data, uint
// Start transaction
// Wait IC to become ready
while(hal_gpio_read(handle->miso))
while(furi_hal_gpio_read(handle->miso))
;
// Tell IC what we want
furi_hal_spi_bus_trx(handle, buff_tx, (uint8_t*)buff_rx, size + 1, CC1101_TIMEOUT);
@ -158,7 +158,7 @@ uint8_t cc1101_read_fifo(FuriHalSpiBusHandle* handle, uint8_t* data, uint8_t* si
// Start transaction
// Wait IC to become ready
while(hal_gpio_read(handle->miso))
while(furi_hal_gpio_read(handle->miso))
;
// First byte - packet length

View File

@ -26,7 +26,7 @@ void lp5562_enable(FuriHalI2cBusHandle* handle) {
Reg00_Enable reg = {.CHIP_EN = true, .LOG_EN = true};
furi_hal_i2c_write_reg_8(handle, LP5562_ADDRESS, 0x00, *(uint8_t*)&reg, LP5562_I2C_TIMEOUT);
//>488μs delay is required after writing to 0x00 register, otherwise program engine will not work
delay_us(500);
furi_hal_delay_us(500);
}
void lp5562_set_channel_current(FuriHalI2cBusHandle* handle, LP5562Channel channel, uint8_t value) {
@ -121,7 +121,7 @@ void lp5562_execute_program(
reg_val &= ~(0x3 << bit_offset);
reg_val |= (0x01 << bit_offset); // load
furi_hal_i2c_write_reg_8(handle, LP5562_ADDRESS, 0x01, reg_val, LP5562_I2C_TIMEOUT);
delay_us(100);
furi_hal_delay_us(100);
// Program load
for(uint8_t i = 0; i < 16; i++) {

View File

@ -83,7 +83,7 @@ bool ibutton_worker_read_comparator(iButtonWorker* worker) {
furi_hal_rfid_comp_start();
// TODO: rework with thread events, "pulse_decoder_get_decoded_index_with_timeout"
delay(100);
furi_hal_delay_ms(100);
int32_t decoded_index = pulse_decoder_get_decoded_index(worker->pulse_decoder);
if(decoded_index >= 0) {
pulse_decoder_get_data(
@ -118,7 +118,7 @@ bool ibutton_worker_read_comparator(iButtonWorker* worker) {
bool ibutton_worker_read_dallas(iButtonWorker* worker) {
bool result = false;
onewire_host_start(worker->host);
delay(100);
furi_hal_delay_ms(100);
FURI_CRITICAL_ENTER();
if(onewire_host_search(worker->host, worker->key_data, NORMAL_SEARCH)) {
onewire_host_reset_search(worker->host);

View File

@ -11,13 +11,13 @@ struct iButtonWriter {
static void writer_write_one_bit(iButtonWriter* writer, bool value, uint32_t delay) {
onewire_host_write_bit(writer->host, value);
delay_us(delay);
furi_hal_delay_us(delay);
}
static void writer_write_byte_ds1990(iButtonWriter* writer, uint8_t data) {
for(uint8_t n_bit = 0; n_bit < 8; n_bit++) {
onewire_host_write_bit(writer->host, data & 1);
delay_us(5000);
furi_hal_delay_us(5000);
data = data >> 1;
}
}
@ -68,7 +68,7 @@ static bool writer_write_TM2004(iButtonWriter* writer, iButtonKey* key) {
// TODO: check answer CRC
// pulse indicating that data is correct
delay_us(600);
furi_hal_delay_us(600);
writer_write_one_bit(writer, 1, 50000);
// read writed key byte
@ -104,7 +104,7 @@ static bool writer_write_1990_1(iButtonWriter* writer, iButtonKey* key) {
// unlock
onewire_host_reset(writer->host);
onewire_host_write(writer->host, RW1990_1_CMD_WRITE_RECORD_FLAG);
delay_us(10);
furi_hal_delay_us(10);
writer_write_one_bit(writer, 0, 5000);
// write key
@ -113,7 +113,7 @@ static bool writer_write_1990_1(iButtonWriter* writer, iButtonKey* key) {
for(uint8_t i = 0; i < ibutton_key_get_data_size(key); i++) {
// inverted key for RW1990.1
writer_write_byte_ds1990(writer, ~ibutton_key_get_data_p(key)[i]);
delay_us(30000);
furi_hal_delay_us(30000);
}
// lock
@ -139,7 +139,7 @@ static bool writer_write_1990_2(iButtonWriter* writer, iButtonKey* key) {
// unlock
onewire_host_reset(writer->host);
onewire_host_write(writer->host, RW1990_2_CMD_WRITE_RECORD_FLAG);
delay_us(10);
furi_hal_delay_us(10);
writer_write_one_bit(writer, 1, 5000);
// write key
@ -147,7 +147,7 @@ static bool writer_write_1990_2(iButtonWriter* writer, iButtonKey* key) {
onewire_host_write(writer->host, RW1990_2_CMD_WRITE_ROM);
for(uint8_t i = 0; i < ibutton_key_get_data_size(key); i++) {
writer_write_byte_ds1990(writer, ibutton_key_get_data_p(key)[i]);
delay_us(30000);
furi_hal_delay_us(30000);
}
// lock
@ -191,7 +191,7 @@ static bool writer_write_TM01(
//} else {
for(uint8_t i = 0; i < key->get_type_data_size(); i++) {
write_byte_ds1990(key->get_data()[i]);
delay_us(10000);
furi_hal_delay_us(10000);
}
//}

View File

@ -30,23 +30,23 @@ bool onewire_host_reset(OneWireHost* host) {
furi_hal_ibutton_pin_high();
do {
if(--retries == 0) return 0;
delay_us(2);
furi_hal_delay_us(2);
} while(!furi_hal_ibutton_pin_get_level());
// pre delay
delay_us(OWH_RESET_DELAY_PRE);
furi_hal_delay_us(OWH_RESET_DELAY_PRE);
// drive low
furi_hal_ibutton_pin_low();
delay_us(OWH_RESET_DRIVE);
furi_hal_delay_us(OWH_RESET_DRIVE);
// release
furi_hal_ibutton_pin_high();
delay_us(OWH_RESET_RELEASE);
furi_hal_delay_us(OWH_RESET_RELEASE);
// read and post delay
r = !furi_hal_ibutton_pin_get_level();
delay_us(OWH_RESET_DELAY_POST);
furi_hal_delay_us(OWH_RESET_DELAY_POST);
return r;
}
@ -56,15 +56,15 @@ bool onewire_host_read_bit(OneWireHost* host) {
// drive low
furi_hal_ibutton_pin_low();
delay_us(OWH_READ_DRIVE);
furi_hal_delay_us(OWH_READ_DRIVE);
// release
furi_hal_ibutton_pin_high();
delay_us(OWH_READ_RELEASE);
furi_hal_delay_us(OWH_READ_RELEASE);
// read and post delay
result = furi_hal_ibutton_pin_get_level();
delay_us(OWH_READ_DELAY_POST);
furi_hal_delay_us(OWH_READ_DELAY_POST);
return result;
}
@ -91,19 +91,19 @@ void onewire_host_write_bit(OneWireHost* host, bool value) {
if(value) {
// drive low
furi_hal_ibutton_pin_low();
delay_us(OWH_WRITE_1_DRIVE);
furi_hal_delay_us(OWH_WRITE_1_DRIVE);
// release
furi_hal_ibutton_pin_high();
delay_us(OWH_WRITE_1_RELEASE);
furi_hal_delay_us(OWH_WRITE_1_RELEASE);
} else {
// drive low
furi_hal_ibutton_pin_low();
delay_us(OWH_WRITE_0_DRIVE);
furi_hal_delay_us(OWH_WRITE_0_DRIVE);
// release
furi_hal_ibutton_pin_high();
delay_us(OWH_WRITE_0_RELEASE);
furi_hal_delay_us(OWH_WRITE_0_RELEASE);
}
}

View File

@ -59,7 +59,7 @@ bool onewire_slave_show_presence(OneWireSlave* bus) {
// show presence
furi_hal_ibutton_pin_low();
delay_us(OWS_PRESENCE_MIN);
furi_hal_delay_us(OWS_PRESENCE_MIN);
furi_hal_ibutton_pin_high();
// somebody also can show presence
@ -126,7 +126,7 @@ bool onewire_slave_send_bit(OneWireSlave* bus, bool value) {
}
// hold line for ZERO or ONE time
delay_us(time);
furi_hal_delay_us(time);
furi_hal_ibutton_pin_high();
return true;

View File

@ -75,8 +75,9 @@ void subghz_encoder_princeton_for_testing_set(
instance->count_key = instance->count_key_package + 3;
if((millis() - instance->time_stop) < instance->timeout) {
instance->time_stop = (instance->timeout - (millis() - instance->time_stop)) * 1000;
if((furi_hal_get_tick() - instance->time_stop) < instance->timeout) {
instance->time_stop =
(instance->timeout - (furi_hal_get_tick() - instance->time_stop)) * 1000;
} else {
instance->time_stop = 0;
}

View File

@ -71,7 +71,7 @@ bool subghz_tx_rx_worker_rx(SubGhzTxRxWorker* instance, uint8_t* data, uint8_t*
osDelay(1);
}
//waiting for reception to complete
while(hal_gpio_read(&gpio_cc1101_g0)) {
while(furi_hal_gpio_read(&gpio_cc1101_g0)) {
osDelay(1);
if(!--timeout) {
FURI_LOG_W(TAG, "RX cc1101_g0 timeout");
@ -102,14 +102,14 @@ void subghz_tx_rx_worker_tx(SubGhzTxRxWorker* instance, uint8_t* data, size_t si
furi_hal_subghz_write_packet(data, size);
furi_hal_subghz_tx(); //start send
instance->status = SubGhzTxRxWorkerStatusTx;
while(!hal_gpio_read(&gpio_cc1101_g0)) { // Wait for GDO0 to be set -> sync transmitted
while(!furi_hal_gpio_read(&gpio_cc1101_g0)) { // Wait for GDO0 to be set -> sync transmitted
osDelay(1);
if(!--timeout) {
FURI_LOG_W(TAG, "TX !cc1101_g0 timeout");
break;
}
}
while(hal_gpio_read(&gpio_cc1101_g0)) { // Wait for GDO0 to be cleared -> end of packet
while(furi_hal_gpio_read(&gpio_cc1101_g0)) { // Wait for GDO0 to be cleared -> end of packet
osDelay(1);
if(!--timeout) {
FURI_LOG_W(TAG, "TX cc1101_g0 timeout");
@ -132,7 +132,7 @@ static int32_t subghz_tx_rx_worker_thread(void* context) {
furi_hal_subghz_idle();
furi_hal_subghz_load_preset(FuriHalSubGhzPresetGFSK9_99KbAsync);
//furi_hal_subghz_load_preset(FuriHalSubGhzPresetMSK99_97KbAsync);
hal_gpio_init(&gpio_cc1101_g0, GpioModeInput, GpioPullNo, GpioSpeedLow);
furi_hal_gpio_init(&gpio_cc1101_g0, GpioModeInput, GpioPullNo, GpioSpeedLow);
furi_hal_subghz_set_frequency_and_path(instance->frequency);
furi_hal_subghz_flush_rx();

View File

@ -8,16 +8,16 @@ uint8_t u8g2_gpio_and_delay_stm32(u8x8_t* u8x8, uint8_t msg, uint8_t arg_int, vo
/* HAL initialization contains all what we need so we can skip this part. */
break;
case U8X8_MSG_DELAY_MILLI:
delay(arg_int);
furi_hal_delay_ms(arg_int);
break;
case U8X8_MSG_DELAY_10MICRO:
delay_us(10);
furi_hal_delay_us(10);
break;
case U8X8_MSG_DELAY_100NANO:
asm("nop");
break;
case U8X8_MSG_GPIO_RESET:
hal_gpio_write(&gpio_display_rst, arg_int);
furi_hal_gpio_write(&gpio_display_rst, arg_int);
break;
default:
return 0;
@ -32,7 +32,7 @@ uint8_t u8x8_hw_spi_stm32(u8x8_t* u8x8, uint8_t msg, uint8_t arg_int, void* arg_
furi_hal_spi_bus_tx(&furi_hal_spi_bus_handle_display, (uint8_t*)arg_ptr, arg_int, 10000);
break;
case U8X8_MSG_BYTE_SET_DC:
hal_gpio_write(&gpio_display_di, arg_int);
furi_hal_gpio_write(&gpio_display_di, arg_int);
break;
case U8X8_MSG_BYTE_INIT:
break;