target.h 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. #pragma once
  2. #define RADIOLIB_STATIC_ONLY 1
  3. #include <RadioLib.h>
  4. #include <helpers/ArduinoHelpers.h>
  5. #include <helpers/SensorManager.h>
  6. #include <helpers/radiolib/CustomSTM32WLxWrapper.h>
  7. #include <helpers/radiolib/RadioLibWrappers.h>
  8. #include <helpers/stm32/STM32Board.h>
  9. #define PIN_VBAT_READ A0
  10. #define ADC_MULTIPLIER (5 * 1.73 * 1000)
  11. class TinyRelayBoard : public STM32Board
  12. {
  13. public:
  14. void begin() override
  15. {
  16. STM32Board::begin();
  17. pinMode(PA0, OUTPUT);
  18. pinMode(PA1, OUTPUT);
  19. }
  20. const char *getManufacturerName() const override { return "Tiny Relay"; }
  21. uint16_t getBattMilliVolts() override
  22. {
  23. analogReadResolution(12);
  24. uint32_t raw = 0;
  25. for (int i = 0; i < 8; i++) {
  26. raw += analogRead(PIN_VBAT_READ);
  27. }
  28. return ((double)raw) * ADC_MULTIPLIER / 8 / 4096;
  29. }
  30. void setGpio(uint32_t values) override
  31. {
  32. // set led values
  33. digitalWrite(PA0, values & 1);
  34. digitalWrite(PA1, (values & 2) >> 1);
  35. }
  36. uint32_t getGpio() override
  37. {
  38. // get led value
  39. return (digitalRead(PA1) << 1) | digitalRead(PA0);
  40. }
  41. };
  42. extern TinyRelayBoard board;
  43. extern WRAPPER_CLASS radio_driver;
  44. extern VolatileRTCClock rtc_clock;
  45. extern SensorManager sensors;
  46. bool radio_init();
  47. uint32_t radio_get_rng_seed();
  48. void radio_set_params(float freq, float bw, uint8_t sf, uint8_t cr);
  49. void radio_set_tx_power(int8_t dbm);
  50. mesh::LocalIdentity radio_new_identity();