flipperzero-firmware/applications/ibutton/helpers/pulse_sequencer.cpp
あく 1fdc5f2950
[FL-2366] HAL to LL migration part 2 (#1053)
* iButton, FuriHal: add onewire HAL, migrate to LL, add missing critical section guards
* FuriHal: rename onewire to ibutton, cleanup RCC domain usage, fix ibutton and rfid
* FuriHal: cleanup RCC usage
2022-03-25 13:33:01 +03:00

53 lines
1.3 KiB
C++

#include "pulse_sequencer.h"
#include <furi.h>
#include <furi_hal.h>
void PulseSequencer::set_periods(
uint32_t* _periods,
uint16_t _periods_count,
bool _pin_start_state) {
periods = _periods;
periods_count = _periods_count;
pin_start_state = _pin_start_state;
}
void PulseSequencer::start() {
period_index = 1;
pin_state = pin_start_state;
hal_gpio_write(&ibutton_gpio, pin_state);
pin_state = !pin_state;
hal_gpio_init(&ibutton_gpio, GpioModeOutputOpenDrain, GpioPullNo, GpioSpeedVeryHigh);
furi_hal_ibutton_emulate_start(
periods[period_index], PulseSequencer::timer_elapsed_callback, this);
}
void PulseSequencer::stop() {
furi_hal_ibutton_emulate_stop();
}
PulseSequencer::~PulseSequencer() {
stop();
}
void PulseSequencer::timer_elapsed_callback(void* context) {
PulseSequencer* self = static_cast<PulseSequencer*>(context);
furi_hal_ibutton_emulate_set_next(self->periods[self->period_index]);
if(self->period_index == 0) {
self->pin_state = self->pin_start_state;
} else {
self->pin_state = !self->pin_state;
}
hal_gpio_write(&ibutton_gpio, self->pin_state);
self->period_index++;
if(self->period_index == self->periods_count) {
self->period_index = 0;
}
}