|
24 | 24 |
|
25 | 25 | #include "net/lora.h"
|
26 | 26 | #include "periph/spi.h"
|
| 27 | +#include "units.h" |
27 | 28 |
|
28 | 29 | #include "sx126x.h"
|
29 | 30 | #include "sx126x_regs.h"
|
@@ -475,11 +476,46 @@ uint32_t sx126x_get_channel(const sx126x_t *dev)
|
475 | 476 | return dev->channel;
|
476 | 477 | }
|
477 | 478 |
|
| 479 | +/* 9.2.1 Image Calibration for Specific Frequency Bands */ |
| 480 | +static void _cal_img(sx126x_t *dev, uint32_t freq) |
| 481 | +{ |
| 482 | + sx126x_chip_modes_t state = sx126x_get_state(dev); |
| 483 | + /* don't know what to do with frequencies that don't fit in the intervals from the datasheet */ |
| 484 | + if (freq <= MHZ(928) && freq >= MHZ(902)) { |
| 485 | + /* 902 - 928 MHz band and anything upper */ |
| 486 | + sx126x_cal_img_in_mhz(dev, 902, 928); |
| 487 | + } |
| 488 | + else if (freq <= MHZ(870) && freq >= MHZ(863)) { |
| 489 | + /* 863 - 870 MHz band */ |
| 490 | + sx126x_cal_img_in_mhz(dev, 863, 870); |
| 491 | + } |
| 492 | + else if (freq <= MHZ(787) && freq >= MHZ(779)) { |
| 493 | + /* 779 - 787 MHz band */ |
| 494 | + sx126x_cal_img_in_mhz(dev, 779, 787); |
| 495 | + } |
| 496 | + else if (freq <= MHZ(510) && freq >= MHZ(470)) { |
| 497 | + /* 470 - 510 MHz band */ |
| 498 | + sx126x_cal_img_in_mhz(dev, 470, 510); |
| 499 | + } |
| 500 | + else if (freq <= MHZ(440) && freq >= MHZ(430)) { |
| 501 | + /* 430 - 440 MHz band and anything lower */ |
| 502 | + sx126x_cal_img_in_mhz(dev, 430, 440); |
| 503 | + } |
| 504 | + else { |
| 505 | + /* Contact your Semtech representative for the other optimal calibration settings |
| 506 | + outside of the given frequency bands. */ |
| 507 | + } |
| 508 | + /* Image calibration sets the chip mode back to STBY_RC */ |
| 509 | + /* When using DIO3, TCXO switches off. */ |
| 510 | + sx126x_set_state(dev, state); |
| 511 | +} |
| 512 | + |
478 | 513 | void sx126x_set_channel(sx126x_t *dev, uint32_t freq)
|
479 | 514 | {
|
480 | 515 | DEBUG("[sx126x]: sx126x_set_channel %" PRIu32 "Hz \n", freq);
|
481 | 516 | dev->channel = freq;
|
482 | 517 | sx126x_set_rf_freq(dev, dev->channel);
|
| 518 | + _cal_img(dev, freq); |
483 | 519 | }
|
484 | 520 |
|
485 | 521 | uint8_t sx126x_get_bandwidth(const sx126x_t *dev)
|
|
0 commit comments