#include "SX1273.h" SX1273::SX1273(Module* mod) : SX1272(mod) { } int16_t SX1273::begin(float freq, float bw, uint8_t sf, uint8_t cr, uint8_t syncWord, int8_t power, uint8_t currentLimit, uint16_t preambleLength, uint8_t gain) { // execute common part int16_t state = SX127x::begin(SX1272_CHIP_VERSION, syncWord, currentLimit, preambleLength); if(state != ERR_NONE) { return(state); } // configure settings not accessible by API state = config(); if(state != ERR_NONE) { return(state); } // mitigation of receiver spurious response // see SX1272/73 Errata, section 2.2 for details state = _mod->SPIsetRegValue(0x31, 0b10000000, 7, 7); if(state != ERR_NONE) { return(state); } // configure publicly accessible settings state = setFrequency(freq); if(state != ERR_NONE) { return(state); } state = setBandwidth(bw); if(state != ERR_NONE) { return(state); } state = setSpreadingFactor(sf); if(state != ERR_NONE) { return(state); } state = setCodingRate(cr); if(state != ERR_NONE) { return(state); } state = setOutputPower(power); if(state != ERR_NONE) { return(state); } state = setGain(gain); if(state != ERR_NONE) { return(state); } return(state); } int16_t SX1273::setSpreadingFactor(uint8_t sf) { uint8_t newSpreadingFactor; // check allowed spreading factor values switch(sf) { case 6: newSpreadingFactor = SX127X_SF_6; break; case 7: newSpreadingFactor = SX127X_SF_7; break; case 8: newSpreadingFactor = SX127X_SF_8; break; case 9: newSpreadingFactor = SX127X_SF_9; break; default: return(ERR_INVALID_SPREADING_FACTOR); } // set spreading factor and if successful, save the new setting int16_t state = setSpreadingFactorRaw(newSpreadingFactor); if(state == ERR_NONE) { SX127x::_sf = sf; } return(state); }