[FL-1167] Rework GPIO and EXTI with LL lib (#424)
* api-hal-gpio: rework gpio on ll * one_wire_slave: rework gpio initialization * interrupts: add attribute weak to hal exti interrupts handlers * api-hal-gpio: add exti interrupt handlers * input: rework with api-hal-gpio interrupts * one_wire_slave: rework with api-hal-gpio interrupts * api-hal-gpio: fix incorrect exti line config * api-hal-gpio: add doxygen documentation * api-hal-gpio: add enable / disable interrupts * api-hal-gpio: add get_rfid_level * core: remove api-gpio * applications: rework gpio with api-hal-gpio * lib: rework gpio with api-hal-gpio * rfal: disable exti interrupt when rfal is inactive * rfal: add interrupt gpio reinitialization * api-hal-gpio: hide setting speed and pull mode LL implementation * stm32wbxx_it: remove unused EXTI handlers * api-hal-gpio: guard set, enable, disable and remove interrupt * Drop F4 target * Accessor: update gpio api usage Co-authored-by: Aleksandr Kutuzov <alleteam@gmail.com>
This commit is contained in:
@@ -101,8 +101,8 @@ AccessorApp::Scene AccessorApp::get_previous_scene() {
|
||||
void AccessorApp::notify_init() {
|
||||
// TODO open record
|
||||
const GpioPin* vibro_record = &vibro_gpio;
|
||||
gpio_init(vibro_record, GpioModeOutputPushPull);
|
||||
gpio_write(vibro_record, false);
|
||||
hal_gpio_init(vibro_record, GpioModeOutputPushPull, GpioPullNo, GpioSpeedLow);
|
||||
hal_gpio_write(vibro_record, false);
|
||||
|
||||
GPIO_InitTypeDef GPIO_InitStruct = {0};
|
||||
|
||||
|
||||
@@ -60,8 +60,8 @@ void WIEGAND::begin() {
|
||||
const GpioPin* pinD0 = &ext_pa6_gpio;
|
||||
const GpioPin* pinD1 = &ext_pa7_gpio;
|
||||
|
||||
gpio_init(pinD0, GpioModeInterruptFall); // Set D0 pin as input
|
||||
gpio_init(pinD1, GpioModeInterruptFall); // Set D1 pin as input
|
||||
hal_gpio_init(pinD0, GpioModeInterruptFall, GpioPullNo, GpioSpeedLow); // Set D0 pin as input
|
||||
hal_gpio_init(pinD1, GpioModeInterruptFall, GpioPullNo, GpioSpeedLow); // Set D1 pin as input
|
||||
|
||||
api_interrupt_add(
|
||||
input_isr, InterruptTypeExternalInterrupt, this); // Hardware interrupt - high to low pulse
|
||||
|
||||
@@ -8,7 +8,7 @@ int32_t application_uart_write(void* p) {
|
||||
// TODO open record
|
||||
GpioPin* led_record = &led;
|
||||
|
||||
gpio_init(led_record, GpioModeOutputOpenDrain);
|
||||
hal_gpio_init(led_record, GpioModeOutputOpenDrain, GpioPullNo, GpioSpeedLow);
|
||||
|
||||
// create buffer
|
||||
const char test_string[] = "test\n";
|
||||
@@ -23,9 +23,9 @@ int32_t application_uart_write(void* p) {
|
||||
counter++;
|
||||
|
||||
// flash at every send
|
||||
gpio_write(led_record, false);
|
||||
hal_gpio_write(led_record, false);
|
||||
delay(50);
|
||||
gpio_write(led_record, true);
|
||||
hal_gpio_write(led_record, true);
|
||||
|
||||
// delay with overall perion of 1s
|
||||
delay(950);
|
||||
|
||||
@@ -40,14 +40,14 @@ int32_t application_vibro(void* p) {
|
||||
Gui* gui = furi_record_open("gui");
|
||||
gui_add_view_port(gui, view_port, GuiLayerFullscreen);
|
||||
|
||||
gpio_init(gpio, GpioModeOutputPushPull);
|
||||
gpio_write(gpio, false);
|
||||
hal_gpio_init(gpio, GpioModeOutputPushPull, GpioPullNo, GpioSpeedLow);
|
||||
hal_gpio_write(gpio, false);
|
||||
VibroEvent event;
|
||||
|
||||
while(1) {
|
||||
furi_check(osMessageQueueGet(event_queue, &event, NULL, osWaitForever) == osOK);
|
||||
if(event.input.type == InputTypeShort && event.input.key == InputKeyBack) {
|
||||
gpio_write(gpio, false);
|
||||
hal_gpio_write(gpio, false);
|
||||
api_hal_light_set(LightGreen, 0);
|
||||
view_port_enabled_set(view_port, false);
|
||||
gui_remove_view_port(gui, view_port);
|
||||
@@ -58,10 +58,10 @@ int32_t application_vibro(void* p) {
|
||||
}
|
||||
if(event.input.key == InputKeyOk) {
|
||||
if(event.input.type == InputTypePress) {
|
||||
gpio_write(gpio, true);
|
||||
hal_gpio_write(gpio, true);
|
||||
api_hal_light_set(LightGreen, 255);
|
||||
} else if(event.input.type == InputTypeRelease) {
|
||||
gpio_write(gpio, false);
|
||||
hal_gpio_write(gpio, false);
|
||||
api_hal_light_set(LightGreen, 0);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -83,7 +83,8 @@ int32_t app_gpio_test(void* p) {
|
||||
|
||||
// configure pin
|
||||
for(uint8_t i = 0; i < sizeof(GPIO_PINS) / sizeof(GPIO_PINS[0]); i++) {
|
||||
gpio_init((GpioPin*)&GPIO_PINS[i].pin, GpioModeOutputPushPull);
|
||||
hal_gpio_init(
|
||||
(GpioPin*)&GPIO_PINS[i].pin, GpioModeOutputPushPull, GpioPullNo, GpioSpeedLow);
|
||||
}
|
||||
|
||||
AppEvent event;
|
||||
@@ -122,10 +123,10 @@ int32_t app_gpio_test(void* p) {
|
||||
|
||||
if(event.value.input.key == InputKeyOk) {
|
||||
if(event.value.input.type == InputTypePress) {
|
||||
gpio_write((GpioPin*)&GPIO_PINS[state->gpio_index].pin, true);
|
||||
hal_gpio_write((GpioPin*)&GPIO_PINS[state->gpio_index].pin, true);
|
||||
api_hal_light_set(LightGreen, 0xFF);
|
||||
} else if(event.value.input.type == InputTypeRelease) {
|
||||
gpio_write((GpioPin*)&GPIO_PINS[state->gpio_index].pin, false);
|
||||
hal_gpio_write((GpioPin*)&GPIO_PINS[state->gpio_index].pin, false);
|
||||
api_hal_light_set(LightGreen, 0x00);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -116,13 +116,13 @@ void KeyReader::start_comaparator(void) {
|
||||
// pulldown lf-rfid pins to prevent interference
|
||||
// TODO open record
|
||||
GpioPin rfid_pull_pin = {.port = RFID_PULL_GPIO_Port, .pin = RFID_PULL_Pin};
|
||||
gpio_init(&rfid_pull_pin, GpioModeOutputOpenDrain);
|
||||
gpio_write(&rfid_pull_pin, false);
|
||||
hal_gpio_init(&rfid_pull_pin, GpioModeOutputOpenDrain, GpioPullNo, GpioSpeedLow);
|
||||
hal_gpio_write(&rfid_pull_pin, false);
|
||||
|
||||
// TODO open record
|
||||
GpioPin rfid_out_pin = {.port = RFID_OUT_GPIO_Port, .pin = RFID_OUT_Pin};
|
||||
gpio_init(&rfid_out_pin, GpioModeOutputOpenDrain);
|
||||
gpio_write(&rfid_out_pin, false);
|
||||
hal_gpio_init(&rfid_out_pin, GpioModeOutputOpenDrain, GpioPullNo, GpioSpeedLow);
|
||||
hal_gpio_write(&rfid_out_pin, false);
|
||||
|
||||
comparator_callback_pointer =
|
||||
cbc::obtain_connector(this, &KeyReader::comparator_trigger_callback);
|
||||
@@ -140,9 +140,11 @@ void KeyReader::comparator_trigger_callback(void* hcomp, void* comp_ctx) {
|
||||
KeyReader* _this = static_cast<KeyReader*>(comp_ctx);
|
||||
|
||||
if(hcomp == &hcomp1) {
|
||||
_this->cyfral_decoder.process_front(get_rfid_in_level(), DWT->CYCCNT - last_dwt_value);
|
||||
_this->cyfral_decoder.process_front(
|
||||
hal_gpio_get_rfid_in_level(), DWT->CYCCNT - last_dwt_value);
|
||||
|
||||
_this->metakom_decoder.process_front(get_rfid_in_level(), DWT->CYCCNT - last_dwt_value);
|
||||
_this->metakom_decoder.process_front(
|
||||
hal_gpio_get_rfid_in_level(), DWT->CYCCNT - last_dwt_value);
|
||||
|
||||
last_dwt_value = DWT->CYCCNT;
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@ void PulseSequencer::start() {
|
||||
|
||||
init_timer(periods[period_index]);
|
||||
pin_state = pin_start_state;
|
||||
gpio_write(&ibutton_gpio, pin_state);
|
||||
hal_gpio_write(&ibutton_gpio, pin_state);
|
||||
pin_state = !pin_state;
|
||||
period_index = 1;
|
||||
|
||||
@@ -57,7 +57,7 @@ void PulseSequencer::init_timer(uint32_t period) {
|
||||
HAL_NVIC_SetPriority(TIM1_UP_TIM16_IRQn, 5, 0);
|
||||
HAL_NVIC_EnableIRQ(TIM1_UP_TIM16_IRQn);
|
||||
|
||||
gpio_init(&ibutton_gpio, GpioModeOutputOpenDrain);
|
||||
hal_gpio_init(&ibutton_gpio, GpioModeOutputOpenDrain, GpioPullNo, GpioSpeedLow);
|
||||
}
|
||||
|
||||
void PulseSequencer::deinit_timer() {
|
||||
@@ -76,7 +76,7 @@ void PulseSequencer::timer_elapsed_callback(void* hw, void* context) {
|
||||
_this->pin_state = !_this->pin_state;
|
||||
}
|
||||
|
||||
gpio_write(&ibutton_gpio, _this->pin_state);
|
||||
hal_gpio_write(&ibutton_gpio, _this->pin_state);
|
||||
|
||||
_this->period_index++;
|
||||
|
||||
|
||||
@@ -289,8 +289,8 @@ uint8_t iButtonApp::get_file_name_size() {
|
||||
void iButtonApp::notify_init() {
|
||||
// TODO open record
|
||||
const GpioPin* vibro_record = &vibro_gpio;
|
||||
gpio_init(vibro_record, GpioModeOutputPushPull);
|
||||
gpio_write(vibro_record, false);
|
||||
hal_gpio_init(vibro_record, GpioModeOutputPushPull, GpioPullNo, GpioSpeedLow);
|
||||
hal_gpio_write(vibro_record, false);
|
||||
}
|
||||
|
||||
void iButtonApp::notify_green_blink() {
|
||||
@@ -348,11 +348,11 @@ void iButtonApp::notify_success() {
|
||||
}
|
||||
|
||||
void iButtonApp::notify_vibro_on() {
|
||||
gpio_write(&vibro_gpio, true);
|
||||
hal_gpio_write(&vibro_gpio, true);
|
||||
}
|
||||
|
||||
void iButtonApp::notify_vibro_off() {
|
||||
gpio_write(&vibro_gpio, false);
|
||||
hal_gpio_write(&vibro_gpio, false);
|
||||
}
|
||||
|
||||
void iButtonApp::set_text_store(const char* text...) {
|
||||
|
||||
@@ -35,7 +35,7 @@ void input_press_timer_callback(void* arg) {
|
||||
}
|
||||
}
|
||||
|
||||
void input_isr(void* _pin, void* _ctx) {
|
||||
void input_isr(void* _ctx) {
|
||||
osThreadFlagsSet(input->thread, INPUT_THREAD_FLAG_ISR);
|
||||
}
|
||||
|
||||
@@ -105,9 +105,9 @@ int32_t input_task() {
|
||||
const size_t pin_count = input_pins_count;
|
||||
input->pin_states = furi_alloc(pin_count * sizeof(InputPinState));
|
||||
|
||||
api_interrupt_add(input_isr, InterruptTypeExternalInterrupt, NULL);
|
||||
|
||||
for(size_t i = 0; i < pin_count; i++) {
|
||||
GpioPin gpio = {(GPIO_TypeDef*)input_pins[i].port, (uint16_t)input_pins[i].pin};
|
||||
hal_gpio_add_int_callback(&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;
|
||||
|
||||
@@ -9,6 +9,7 @@
|
||||
#include <furi.h>
|
||||
#include <cli/cli.h>
|
||||
#include <m-string.h>
|
||||
#include <api-hal-gpio.h>
|
||||
|
||||
#define INPUT_DEBOUNCE_TICKS_HALF (INPUT_DEBOUNCE_TICKS / 2)
|
||||
#define INPUT_PRESS_TICKS 200
|
||||
@@ -37,4 +38,4 @@ typedef struct {
|
||||
void input_press_timer_callback(void* arg);
|
||||
|
||||
/* Input interrupt handler */
|
||||
void input_isr(void* _pin, void* _ctx);
|
||||
void input_isr(void* _ctx);
|
||||
|
||||
@@ -55,17 +55,17 @@ void prepare_data(uint32_t ID, uint32_t VENDOR, uint8_t* data) {
|
||||
|
||||
void em4100_emulation(uint8_t* data, GpioPin* pin) {
|
||||
taskENTER_CRITICAL();
|
||||
gpio_write(pin, true);
|
||||
hal_gpio_write(pin, true);
|
||||
|
||||
for(uint8_t i = 0; i < 8; i++) {
|
||||
for(uint8_t j = 0; j < 64; j++) {
|
||||
delay_us(260);
|
||||
gpio_write(pin, data[j]);
|
||||
hal_gpio_write(pin, data[j]);
|
||||
delay_us(260);
|
||||
gpio_write(pin, !data[j]);
|
||||
hal_gpio_write(pin, !data[j]);
|
||||
}
|
||||
}
|
||||
|
||||
gpio_write(pin, false);
|
||||
hal_gpio_write(pin, false);
|
||||
taskEXIT_CRITICAL();
|
||||
}
|
||||
|
||||
@@ -101,10 +101,10 @@ void comparator_trigger_callback(void* hcomp, void* comp_ctx) {
|
||||
// wait message will be consumed
|
||||
if(xStreamBufferBytesAvailable(ctx->stream_buffer) == 64) return;
|
||||
|
||||
gpio_write(&debug_0, true);
|
||||
hal_gpio_write(&debug_0, true);
|
||||
|
||||
// TOOD F4 and F5 differ
|
||||
bool rx_value = get_rfid_in_level();
|
||||
bool rx_value = hal_gpio_get_rfid_in_level();
|
||||
|
||||
if(dt > 384) {
|
||||
// change symbol 0->1 or 1->0
|
||||
@@ -116,18 +116,18 @@ void comparator_trigger_callback(void* hcomp, void* comp_ctx) {
|
||||
}
|
||||
|
||||
/*
|
||||
gpio_write(&debug_1, true);
|
||||
hal_gpio_write(&debug_1, true);
|
||||
delay_us(center ? 10 : 30);
|
||||
gpio_write(&debug_1, false);
|
||||
hal_gpio_write(&debug_1, false);
|
||||
*/
|
||||
|
||||
BaseType_t xHigherPriorityTaskWoken = pdFALSE;
|
||||
|
||||
if(ctx->center && ctx->symbol != -1) {
|
||||
/*
|
||||
gpio_write(&debug_0, true);
|
||||
hal_gpio_write(&debug_0, true);
|
||||
delay_us(symbol ? 10 : 30);
|
||||
gpio_write(&debug_0, false);
|
||||
hal_gpio_write(&debug_0, false);
|
||||
*/
|
||||
|
||||
ctx->int_buffer[ctx->symbol_cnt] = ctx->symbol;
|
||||
@@ -160,7 +160,7 @@ void comparator_trigger_callback(void* hcomp, void* comp_ctx) {
|
||||
ctx->symbol_cnt = 0;
|
||||
}
|
||||
|
||||
gpio_write(&debug_0, false);
|
||||
hal_gpio_write(&debug_0, false);
|
||||
|
||||
portYIELD_FROM_ISR(xHigherPriorityTaskWoken);
|
||||
}
|
||||
@@ -253,14 +253,14 @@ int32_t lf_rfid_workaround(void* p) {
|
||||
// TODO open record
|
||||
GpioPin* pull_pin_record = &pull_pin;
|
||||
|
||||
gpio_init(pull_pin_record, GpioModeOutputPushPull);
|
||||
hal_gpio_init(pull_pin_record, GpioModeOutputPushPull, GpioPullNo, GpioSpeedLow);
|
||||
|
||||
gpio_init(&debug_0, GpioModeOutputPushPull);
|
||||
gpio_init(&debug_1, GpioModeOutputPushPull);
|
||||
hal_gpio_init(&debug_0, GpioModeOutputPushPull, GpioPullNo, GpioSpeedLow);
|
||||
hal_gpio_init(&debug_1, GpioModeOutputPushPull, GpioPullNo, GpioSpeedLow);
|
||||
|
||||
// pulldown iBtn pin to prevent interference from ibutton
|
||||
gpio_init((GpioPin*)&ibutton_gpio, GpioModeOutputOpenDrain);
|
||||
gpio_write((GpioPin*)&ibutton_gpio, false);
|
||||
hal_gpio_init((GpioPin*)&ibutton_gpio, GpioModeOutputOpenDrain, GpioPullNo, GpioSpeedLow);
|
||||
hal_gpio_write((GpioPin*)&ibutton_gpio, false);
|
||||
|
||||
// init ctx
|
||||
ComparatorCtx comp_ctx;
|
||||
@@ -370,7 +370,7 @@ int32_t lf_rfid_workaround(void* p) {
|
||||
|
||||
if(state->dirty) {
|
||||
if(state->on) {
|
||||
gpio_write(pull_pin_record, false);
|
||||
hal_gpio_write(pull_pin_record, false);
|
||||
init_comp_ctx(&comp_ctx);
|
||||
api_interrupt_add(
|
||||
comparator_trigger_callback, InterruptTypeComparatorTrigger, &comp_ctx);
|
||||
@@ -403,8 +403,8 @@ int32_t lf_rfid_workaround(void* p) {
|
||||
hal_pwmn_stop(&TIM_C, TIM_CHANNEL_1); // TODO: move to furiac_onexit
|
||||
api_interrupt_remove(comparator_trigger_callback, InterruptTypeComparatorTrigger);
|
||||
|
||||
gpio_init(pull_pin_record, GpioModeInput);
|
||||
gpio_init((GpioPin*)&ibutton_gpio, GpioModeInput);
|
||||
hal_gpio_init(pull_pin_record, GpioModeInput, GpioPullNo, GpioSpeedLow);
|
||||
hal_gpio_init((GpioPin*)&ibutton_gpio, GpioModeInput, GpioPullNo, GpioSpeedLow);
|
||||
|
||||
// TODO remove all view_ports create by app
|
||||
view_port_enabled_set(view_port, false);
|
||||
|
||||
@@ -114,15 +114,15 @@ bool subghz_static_input(InputEvent* event, void* context) {
|
||||
uint8_t bit = i % 8;
|
||||
bool value = (key[byte] >> (7 - bit)) & 1;
|
||||
// Payload send
|
||||
gpio_write(&cc1101_g0_gpio, false);
|
||||
hal_gpio_write(&cc1101_g0_gpio, false);
|
||||
delay_us(value ? SUBGHZ_PT_ONE : SUBGHZ_PT_ZERO);
|
||||
gpio_write(&cc1101_g0_gpio, true);
|
||||
hal_gpio_write(&cc1101_g0_gpio, true);
|
||||
delay_us(value ? SUBGHZ_PT_ZERO : SUBGHZ_PT_ONE);
|
||||
}
|
||||
// Last bit
|
||||
gpio_write(&cc1101_g0_gpio, false);
|
||||
hal_gpio_write(&cc1101_g0_gpio, false);
|
||||
delay_us(SUBGHZ_PT_ONE);
|
||||
gpio_write(&cc1101_g0_gpio, true);
|
||||
hal_gpio_write(&cc1101_g0_gpio, true);
|
||||
// Guard time
|
||||
delay_us(10600);
|
||||
}
|
||||
@@ -144,8 +144,8 @@ void subghz_static_enter(void* context) {
|
||||
api_hal_subghz_reset();
|
||||
api_hal_subghz_load_preset(ApiHalSubGhzPresetOokAsync);
|
||||
|
||||
gpio_init(&cc1101_g0_gpio, GpioModeOutputPushPull);
|
||||
gpio_write(&cc1101_g0_gpio, true);
|
||||
hal_gpio_init(&cc1101_g0_gpio, GpioModeOutputPushPull, GpioPullNo, GpioSpeedLow);
|
||||
hal_gpio_write(&cc1101_g0_gpio, true);
|
||||
|
||||
with_view_model(
|
||||
subghz_static->view, (SubghzStaticModel * model) {
|
||||
|
||||
@@ -105,12 +105,12 @@ bool subghz_test_basic_input(InputEvent* event, void* context) {
|
||||
}
|
||||
|
||||
if(model->status == SubghzTestBasicModelStatusRx) {
|
||||
gpio_init(&cc1101_g0_gpio, GpioModeInput);
|
||||
hal_gpio_init(&cc1101_g0_gpio, GpioModeInput, GpioPullNo, GpioSpeedLow);
|
||||
api_hal_subghz_rx();
|
||||
osTimerStart(subghz_test_basic->timer, 1024 / 4);
|
||||
} else {
|
||||
gpio_init(&cc1101_g0_gpio, GpioModeOutputPushPull);
|
||||
gpio_write(&cc1101_g0_gpio, false);
|
||||
hal_gpio_init(&cc1101_g0_gpio, GpioModeOutputPushPull, GpioPullNo, GpioSpeedLow);
|
||||
hal_gpio_write(&cc1101_g0_gpio, false);
|
||||
api_hal_subghz_tx();
|
||||
}
|
||||
|
||||
@@ -127,7 +127,7 @@ void subghz_test_basic_enter(void* context) {
|
||||
api_hal_subghz_reset();
|
||||
api_hal_subghz_load_preset(ApiHalSubGhzPresetOokAsync);
|
||||
|
||||
gpio_init(&cc1101_g0_gpio, GpioModeInput);
|
||||
hal_gpio_init(&cc1101_g0_gpio, GpioModeInput, GpioPullNo, GpioSpeedLow);
|
||||
|
||||
with_view_model(
|
||||
subghz_test_basic->view, (SubghzTestBasicModel * model) {
|
||||
|
||||
@@ -134,7 +134,7 @@ void subghz_test_packet_enter(void* context) {
|
||||
api_hal_subghz_reset();
|
||||
api_hal_subghz_load_preset(ApiHalSubGhzPreset2FskPacket);
|
||||
|
||||
gpio_init(&cc1101_g0_gpio, GpioModeInput);
|
||||
hal_gpio_init(&cc1101_g0_gpio, GpioModeInput, GpioPullNo, GpioSpeedLow);
|
||||
|
||||
with_view_model(
|
||||
subghz_test_packet->view, (SubghzTestPacketModel * model) {
|
||||
|
||||
Reference in New Issue
Block a user