lfrfid-debug-app-scene-tune.cpp 2.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  1. #include "lfrfid-debug-app-scene-tune.h"
  2. #include <furi-hal.h>
  3. extern COMP_HandleTypeDef hcomp1;
  4. static void comparator_trigger_callback(void* hcomp, void* comp_ctx) {
  5. COMP_HandleTypeDef* _hcomp = static_cast<COMP_HandleTypeDef*>(hcomp);
  6. if(hcomp == &hcomp1) {
  7. hal_gpio_write(&gpio_ext_pa7, HAL_COMP_GetOutputLevel(_hcomp) == COMP_OUTPUT_LEVEL_HIGH);
  8. }
  9. }
  10. void LfRfidDebugAppSceneTune::on_enter(LfRfidDebugApp* app, bool need_restore) {
  11. app->view_controller.switch_to<LfRfidViewTuneVM>();
  12. hal_gpio_init_simple(&gpio_ext_pa7, GpioModeOutputPushPull);
  13. api_interrupt_add(comparator_trigger_callback, InterruptTypeComparatorTrigger, this);
  14. hcomp1.Init.InputMinus = COMP_INPUT_MINUS_1_2VREFINT;
  15. hcomp1.Init.InputPlus = COMP_INPUT_PLUS_IO1;
  16. hcomp1.Init.OutputPol = COMP_OUTPUTPOL_NONINVERTED;
  17. hcomp1.Init.Hysteresis = COMP_HYSTERESIS_HIGH;
  18. hcomp1.Init.BlankingSrce = COMP_BLANKINGSRC_NONE;
  19. hcomp1.Init.Mode = COMP_POWERMODE_MEDIUMSPEED;
  20. hcomp1.Init.WindowMode = COMP_WINDOWMODE_DISABLE;
  21. hcomp1.Init.TriggerMode = COMP_TRIGGERMODE_IT_RISING_FALLING;
  22. if(HAL_COMP_Init(&hcomp1) != HAL_OK) {
  23. Error_Handler();
  24. }
  25. HAL_COMP_Start(&hcomp1);
  26. furi_hal_rfid_pins_read();
  27. furi_hal_rfid_tim_read(125000, 0.5);
  28. furi_hal_rfid_tim_read_start();
  29. }
  30. bool LfRfidDebugAppSceneTune::on_event(LfRfidDebugApp* app, LfRfidDebugApp::Event* event) {
  31. bool consumed = false;
  32. LfRfidViewTuneVM* tune = app->view_controller;
  33. if(tune->is_dirty()) {
  34. furi_hal_rfid_set_read_period(tune->get_ARR());
  35. furi_hal_rfid_set_read_pulse(tune->get_CCR());
  36. }
  37. return consumed;
  38. }
  39. void LfRfidDebugAppSceneTune::on_exit(LfRfidDebugApp* app) {
  40. HAL_COMP_Stop(&hcomp1);
  41. api_interrupt_remove(comparator_trigger_callback, InterruptTypeComparatorTrigger);
  42. hal_gpio_init_simple(&gpio_ext_pa7, GpioModeAnalog);
  43. furi_hal_rfid_tim_read_stop();
  44. furi_hal_rfid_tim_reset();
  45. furi_hal_rfid_pins_reset();
  46. }