target.cpp 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. #include <Arduino.h>
  2. #include "target.h"
  3. #include <helpers/ArduinoHelpers.h>
  4. ESP32Board board;
  5. ESPNOWRadio radio_driver;
  6. ESP32RTCClock rtc_clock;
  7. #if defined(ENV_INCLUDE_GPS)
  8. MicroNMEALocationProvider nmea = MicroNMEALocationProvider(Serial1, (mesh::RTCClock*)&rtc_clock);
  9. EnvironmentSensorManager sensors = EnvironmentSensorManager(nmea);
  10. #else
  11. EnvironmentSensorManager sensors = EnvironmentSensorManager();
  12. #endif
  13. #ifdef DISPLAY_CLASS
  14. DISPLAY_CLASS display;
  15. #ifdef PIN_USER_BTN
  16. MomentaryButton user_btn(PIN_USER_BTN, 1000, true, true);
  17. #endif
  18. #endif
  19. bool radio_init() {
  20. rtc_clock.begin();
  21. radio_driver.init();
  22. return true; // success
  23. }
  24. uint32_t radio_get_rng_seed() {
  25. return millis() + radio_driver.intID(); // TODO: where to get some entropy?
  26. }
  27. void radio_set_params(float freq, float bw, uint8_t sf, uint8_t cr) {
  28. // no-op
  29. }
  30. void radio_set_tx_power(int8_t dbm) {
  31. radio_driver.setTxPower(dbm);
  32. }
  33. // NOTE: as we are using the WiFi radio, the ESP_IDF will have enabled hardware RNG:
  34. // https://docs.espressif.com/projects/esp-idf/en/stable/esp32/api-reference/system/random.html
  35. class ESP_RNG : public mesh::RNG {
  36. public:
  37. void random(uint8_t* dest, size_t sz) override {
  38. esp_fill_random(dest, sz);
  39. }
  40. };
  41. mesh::LocalIdentity radio_new_identity() {
  42. ESP_RNG rng;
  43. return mesh::LocalIdentity(&rng); // create new random identity
  44. }