[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:
@@ -43,7 +43,7 @@ public:
|
||||
#include <api-hal.h>
|
||||
|
||||
void BlanksWriter::onewire_release(void) {
|
||||
gpio_write(gpio, true);
|
||||
hal_gpio_write(gpio, true);
|
||||
}
|
||||
|
||||
void BlanksWriter::onewire_write_one_bit(bool value, uint32_t delay = 10000) {
|
||||
|
@@ -11,11 +11,11 @@ OneWireMaster::~OneWireMaster() {
|
||||
}
|
||||
|
||||
void OneWireMaster::start(void) {
|
||||
gpio_init(gpio, GpioModeOutputOpenDrain);
|
||||
hal_gpio_init(gpio, GpioModeOutputOpenDrain, GpioPullNo, GpioSpeedLow);
|
||||
}
|
||||
|
||||
void OneWireMaster::stop(void) {
|
||||
gpio_init(gpio, GpioModeAnalog);
|
||||
hal_gpio_init(gpio, GpioModeAnalog, GpioPullNo, GpioSpeedLow);
|
||||
}
|
||||
|
||||
void OneWireMaster::reset_search() {
|
||||
@@ -154,25 +154,25 @@ bool OneWireMaster::reset(void) {
|
||||
uint8_t retries = 125;
|
||||
|
||||
// wait until the gpio is high
|
||||
gpio_write(gpio, true);
|
||||
hal_gpio_write(gpio, true);
|
||||
do {
|
||||
if(--retries == 0) return 0;
|
||||
delay_us(2);
|
||||
} while(!gpio_read(gpio));
|
||||
} while(!hal_gpio_read(gpio));
|
||||
|
||||
// pre delay
|
||||
delay_us(OneWireTiming::RESET_DELAY_PRE);
|
||||
|
||||
// drive low
|
||||
gpio_write(gpio, false);
|
||||
hal_gpio_write(gpio, false);
|
||||
delay_us(OneWireTiming::RESET_DRIVE);
|
||||
|
||||
// release
|
||||
gpio_write(gpio, true);
|
||||
hal_gpio_write(gpio, true);
|
||||
delay_us(OneWireTiming::RESET_RELEASE);
|
||||
|
||||
// read and post delay
|
||||
r = !gpio_read(gpio);
|
||||
r = !hal_gpio_read(gpio);
|
||||
delay_us(OneWireTiming::RESET_DELAY_POST);
|
||||
|
||||
return r;
|
||||
@@ -182,15 +182,15 @@ bool OneWireMaster::read_bit(void) {
|
||||
bool result;
|
||||
|
||||
// drive low
|
||||
gpio_write(gpio, false);
|
||||
hal_gpio_write(gpio, false);
|
||||
delay_us(OneWireTiming::READ_DRIVE);
|
||||
|
||||
// release
|
||||
gpio_write(gpio, true);
|
||||
hal_gpio_write(gpio, true);
|
||||
delay_us(OneWireTiming::READ_RELEASE);
|
||||
|
||||
// read and post delay
|
||||
result = gpio_read(gpio);
|
||||
result = hal_gpio_read(gpio);
|
||||
delay_us(OneWireTiming::READ_DELAY_POST);
|
||||
|
||||
return result;
|
||||
@@ -199,19 +199,19 @@ bool OneWireMaster::read_bit(void) {
|
||||
void OneWireMaster::write_bit(bool value) {
|
||||
if(value) {
|
||||
// drive low
|
||||
gpio_write(gpio, false);
|
||||
hal_gpio_write(gpio, false);
|
||||
delay_us(OneWireTiming::WRITE_1_DRIVE);
|
||||
|
||||
// release
|
||||
gpio_write(gpio, true);
|
||||
hal_gpio_write(gpio, true);
|
||||
delay_us(OneWireTiming::WRITE_1_RELEASE);
|
||||
} else {
|
||||
// drive low
|
||||
gpio_write(gpio, false);
|
||||
hal_gpio_write(gpio, false);
|
||||
delay_us(OneWireTiming::WRITE_0_DRIVE);
|
||||
|
||||
// release
|
||||
gpio_write(gpio, true);
|
||||
hal_gpio_write(gpio, true);
|
||||
delay_us(OneWireTiming::WRITE_0_RELEASE);
|
||||
}
|
||||
}
|
||||
|
@@ -7,10 +7,10 @@
|
||||
|
||||
void OneWireSlave::start(void) {
|
||||
// add exti interrupt
|
||||
api_interrupt_add(exti_cb, InterruptTypeExternalInterrupt, this);
|
||||
hal_gpio_add_int_callback(one_wire_pin_record, exti_cb, this);
|
||||
|
||||
// init gpio
|
||||
gpio_init(one_wire_pin_record, GpioModeInterruptRiseFall);
|
||||
hal_gpio_init(one_wire_pin_record, GpioModeInterruptRiseFall, GpioPullNo, GpioSpeedLow);
|
||||
pin_set_float();
|
||||
|
||||
// init instructions per us count
|
||||
@@ -19,15 +19,9 @@ void OneWireSlave::start(void) {
|
||||
|
||||
void OneWireSlave::stop(void) {
|
||||
// deinit gpio
|
||||
gpio_init_ex(one_wire_pin_record, GpioModeInput, GpioPullNo, GpioSpeedLow);
|
||||
// TODO change after gpio rework
|
||||
// Clear EXTI registers
|
||||
LL_EXTI_DisableRisingTrig_0_31(LL_EXTI_LINE_14);
|
||||
LL_EXTI_DisableFallingTrig_0_31(LL_EXTI_LINE_14);
|
||||
LL_EXTI_DisableIT_0_31(LL_EXTI_LINE_14);
|
||||
|
||||
hal_gpio_init(one_wire_pin_record, GpioModeInput, GpioPullNo, GpioSpeedLow);
|
||||
// remove exti interrupt
|
||||
api_interrupt_remove(exti_cb, InterruptTypeExternalInterrupt);
|
||||
hal_gpio_remove_int_callback(one_wire_pin_record);
|
||||
|
||||
// deattach devices
|
||||
deattach();
|
||||
@@ -60,11 +54,11 @@ void OneWireSlave::set_result_callback(OneWireSlaveResultCallback result_cb, voi
|
||||
}
|
||||
|
||||
void OneWireSlave::pin_set_float() {
|
||||
gpio_write(one_wire_pin_record, true);
|
||||
hal_gpio_write(one_wire_pin_record, true);
|
||||
}
|
||||
|
||||
void OneWireSlave::pin_set_low() {
|
||||
gpio_write(one_wire_pin_record, false);
|
||||
hal_gpio_write(one_wire_pin_record, false);
|
||||
}
|
||||
|
||||
void OneWireSlave::pin_init_interrupt_in_isr_ctx(void) {
|
||||
@@ -84,7 +78,7 @@ OneWiteTimeType OneWireSlave::wait_while_gpio_is(OneWiteTimeType time, const boo
|
||||
|
||||
do {
|
||||
time_captured = DWT->CYCCNT;
|
||||
if(gpio_read(one_wire_pin_record) != pin_value) {
|
||||
if(hal_gpio_read(one_wire_pin_record) != pin_value) {
|
||||
OneWiteTimeType remaining_time = time_ticks - (time_captured - start);
|
||||
remaining_time /= __instructions_per_us;
|
||||
return remaining_time;
|
||||
@@ -286,33 +280,29 @@ bool OneWireSlave::bus_start(void) {
|
||||
return result;
|
||||
}
|
||||
|
||||
void OneWireSlave::exti_callback(void* _pin, void* _ctx) {
|
||||
// interrupt manager get us pin constant, so...
|
||||
uint32_t pin = (uint32_t)_pin;
|
||||
void OneWireSlave::exti_callback(void* _ctx) {
|
||||
OneWireSlave* _this = static_cast<OneWireSlave*>(_ctx);
|
||||
|
||||
if(pin == _this->one_wire_pin_record->pin) {
|
||||
volatile bool input_state = gpio_read(_this->one_wire_pin_record);
|
||||
static uint32_t pulse_start = 0;
|
||||
volatile bool input_state = hal_gpio_read(_this->one_wire_pin_record);
|
||||
static uint32_t pulse_start = 0;
|
||||
|
||||
if(input_state) {
|
||||
uint32_t pulse_length = (DWT->CYCCNT - pulse_start) / __instructions_per_us;
|
||||
if(pulse_length >= OWET::RESET_MIN) {
|
||||
if(pulse_length <= OWET::RESET_MAX) {
|
||||
// reset cycle ok
|
||||
bool result = _this->bus_start();
|
||||
if(result && _this->result_cb != nullptr) {
|
||||
_this->result_cb(result, _this->result_cb_ctx);
|
||||
}
|
||||
} else {
|
||||
error = OneWireSlaveError::VERY_LONG_RESET;
|
||||
if(input_state) {
|
||||
uint32_t pulse_length = (DWT->CYCCNT - pulse_start) / __instructions_per_us;
|
||||
if(pulse_length >= OWET::RESET_MIN) {
|
||||
if(pulse_length <= OWET::RESET_MAX) {
|
||||
// reset cycle ok
|
||||
bool result = _this->bus_start();
|
||||
if(result && _this->result_cb != nullptr) {
|
||||
_this->result_cb(result, _this->result_cb_ctx);
|
||||
}
|
||||
} else {
|
||||
error = OneWireSlaveError::VERY_SHORT_RESET;
|
||||
error = OneWireSlaveError::VERY_LONG_RESET;
|
||||
}
|
||||
} else {
|
||||
//FALL event
|
||||
pulse_start = DWT->CYCCNT;
|
||||
error = OneWireSlaveError::VERY_SHORT_RESET;
|
||||
}
|
||||
} else {
|
||||
//FALL event
|
||||
pulse_start = DWT->CYCCNT;
|
||||
}
|
||||
}
|
@@ -30,8 +30,8 @@ private:
|
||||
const GpioPin* one_wire_pin_record;
|
||||
|
||||
// exti callback and its pointer
|
||||
void exti_callback(void* _pin, void* _ctx);
|
||||
void (*exti_cb)(void* _pin, void* _ctx);
|
||||
void exti_callback(void* _ctx);
|
||||
void (*exti_cb)(void* _ctx);
|
||||
|
||||
uint32_t __instructions_per_us;
|
||||
|
||||
|
Reference in New Issue
Block a user