target.cpp 985 B

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  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. SensorManager sensors;
  8. bool radio_init() {
  9. rtc_clock.begin();
  10. radio_driver.init();
  11. return true; // success
  12. }
  13. uint32_t radio_get_rng_seed() {
  14. return millis() + radio_driver.intID(); // TODO: where to get some entropy?
  15. }
  16. void radio_set_params(float freq, float bw, uint8_t sf, uint8_t cr) {
  17. // no-op
  18. }
  19. void radio_set_tx_power(uint8_t dbm) {
  20. radio_driver.setTxPower(dbm);
  21. }
  22. // NOTE: as we are using the WiFi radio, the ESP_IDF will have enabled hardware RNG:
  23. // https://docs.espressif.com/projects/esp-idf/en/stable/esp32/api-reference/system/random.html
  24. class ESP_RNG : public mesh::RNG {
  25. public:
  26. void random(uint8_t* dest, size_t sz) override {
  27. esp_fill_random(dest, sz);
  28. }
  29. };
  30. mesh::LocalIdentity radio_new_identity() {
  31. ESP_RNG rng;
  32. return mesh::LocalIdentity(&rng); // create new random identity
  33. }