EEPROM config and TNC mode

This commit is contained in:
Mark Qvist 2018-06-20 16:32:30 +02:00
parent 31de28714f
commit 720f34d41f
6 changed files with 66 additions and 34 deletions

View File

@ -62,9 +62,9 @@
const int lora_rx_turnaround_ms = 50;
// Default LoRa settings
int lora_sf = 0;
int lora_cr = 5;
int lora_txp = 0xFF;
int lora_sf = 0;
int lora_cr = 5;
int lora_txp = 0xFF;
uint32_t lora_bw = 0;
uint32_t lora_freq = 0;

View File

@ -28,6 +28,7 @@
#define CMD_ROM_READ 0x51
#define CMD_ROM_WRITE 0x52
#define CMD_CONF_SAVE 0x53
#define CMD_CONF_DELETE 0x54
#define CMD_UNLOCK_ROM 0x59
#define ROM_UNLOCK_BYTE 0xF8
@ -53,26 +54,4 @@
bool ESCAPE = false;
uint8_t command = CMD_UNKNOWN;
#endif
/*
Frequency 433.200 0xc00119d21b80c0
Bandwidth 20.800 0xc00200005140c0
TX Power 8dbm 0xc00308c0
SF 7 0xc00407c0
All: 0xc00119d21b80c00200005140c00308c00407c0
Radio on 0xc00501c0
Config+on 0xc00119d21b80c00200005140c00301c00407c00601c0
c1 = self.bandwidth >> 24
c2 = self.bandwidth >> 16 & 0xFF
c3 = self.bandwidth >> 8 & 0xFF
c4 = self.bandwidth & 0xFF
data = KISS.escape(chr(c1)+chr(c2)+chr(c3)+chr(c4))
*/
#endif

View File

@ -370,24 +370,24 @@ void LoRaClass::setTxPower(int level, int outputPin)
}
}
void LoRaClass::setFrequency(long frequency)
{
void LoRaClass::setFrequency(long frequency) {
_frequency = frequency;
uint64_t frf = ((uint64_t)frequency << 19) / 32000000;
uint32_t frf = ((uint64_t)frequency << 19) / 32000000;
writeRegister(REG_FRF_MSB, (uint8_t)(frf >> 16));
writeRegister(REG_FRF_MID, (uint8_t)(frf >> 8));
writeRegister(REG_FRF_LSB, (uint8_t)(frf >> 0));
}
long LoRaClass::getFrequency() {
uint32_t LoRaClass::getFrequency() {
uint8_t msb = readRegister(REG_FRF_MSB);
uint8_t mid = readRegister(REG_FRF_MID);
uint8_t lsb = readRegister(REG_FRF_LSB);
uint64_t frf = msb << 16 | mid << 8 | lsb;
long frequency = (uint64_t)(frf*32000000) >> 19;
uint32_t frf = ((uint32_t)msb << 16) | ((uint32_t)mid << 8) | (uint32_t)lsb;
uint64_t frm = (uint64_t)frf*32000000;
uint32_t frequency = (frm >> 19);
return frequency;
}

2
LoRa.h
View File

@ -46,7 +46,7 @@ public:
void sleep();
void setTxPower(int level, int outputPin = PA_OUTPUT_PA_BOOST_PIN);
long getFrequency();
uint32_t getFrequency();
void setFrequency(long frequency);
void setSpreadingFactor(int sf);
long getSignalBandwidth();

View File

@ -344,6 +344,10 @@ void serialCallback(uint8_t sbyte) {
}
} else if (command == CMD_FW_VERSION) {
kiss_indicate_version();
} else if (command == CMD_CONF_SAVE) {
eeprom_conf_save();
} else if (command == CMD_CONF_DELETE) {
eeprom_conf_delete();
}
}
}
@ -390,6 +394,11 @@ void validateStatus() {
if (eeprom_product_valid() && eeprom_model_valid() && eeprom_hwrev_valid()) {
if (eeprom_checksum_valid()) {
hw_ready = true;
if (eeprom_have_conf()) {
eeprom_conf_load();
startRadio();
}
}
} else {
hw_ready = false;

View File

@ -228,7 +228,6 @@ void getPacketData(int len) {
}
}
void setSpreadingFactor() {
if (radio_online) LoRa.setSpreadingFactor(lora_sf);
}
@ -387,6 +386,51 @@ bool eeprom_checksum_valid() {
return checksum_valid;
}
bool eeprom_have_conf() {
if (EEPROM.read(eeprom_addr(ADDR_CONF_OK)) == CONF_OK_BYTE) {
return true;
} else {
return false;
}
}
void eeprom_conf_load() {
if (eeprom_have_conf()) {
lora_sf = EEPROM.read(eeprom_addr(ADDR_CONF_SF));
lora_cr = EEPROM.read(eeprom_addr(ADDR_CONF_CR));
lora_txp = EEPROM.read(eeprom_addr(ADDR_CONF_TXP));
lora_freq = (uint32_t)EEPROM.read(eeprom_addr(ADDR_CONF_FREQ)+0x00) << 24 | (uint32_t)EEPROM.read(eeprom_addr(ADDR_CONF_FREQ)+0x01) << 16 | (uint32_t)EEPROM.read(eeprom_addr(ADDR_CONF_FREQ)+0x02) << 8 | (uint32_t)EEPROM.read(eeprom_addr(ADDR_CONF_FREQ)+0x03);
lora_bw = (uint32_t)EEPROM.read(eeprom_addr(ADDR_CONF_BW)+0x00) << 24 | (uint32_t)EEPROM.read(eeprom_addr(ADDR_CONF_BW)+0x01) << 16 | (uint32_t)EEPROM.read(eeprom_addr(ADDR_CONF_BW)+0x02) << 8 | (uint32_t)EEPROM.read(eeprom_addr(ADDR_CONF_BW)+0x03);
}
}
void eeprom_conf_save() {
if (hw_ready && radio_online) {
EEPROM.update(eeprom_addr(ADDR_CONF_SF), lora_sf);
EEPROM.update(eeprom_addr(ADDR_CONF_CR), lora_cr);
EEPROM.update(eeprom_addr(ADDR_CONF_TXP), lora_txp);
EEPROM.update(eeprom_addr(ADDR_CONF_BW)+0x00, lora_bw>>24);
EEPROM.update(eeprom_addr(ADDR_CONF_BW)+0x01, lora_bw>>16);
EEPROM.update(eeprom_addr(ADDR_CONF_BW)+0x02, lora_bw>>8);
EEPROM.update(eeprom_addr(ADDR_CONF_BW)+0x03, lora_bw);
EEPROM.update(eeprom_addr(ADDR_CONF_FREQ)+0x00, lora_freq>>24);
EEPROM.update(eeprom_addr(ADDR_CONF_FREQ)+0x01, lora_freq>>16);
EEPROM.update(eeprom_addr(ADDR_CONF_FREQ)+0x02, lora_freq>>8);
EEPROM.update(eeprom_addr(ADDR_CONF_FREQ)+0x03, lora_freq);
EEPROM.update(eeprom_addr(ADDR_CONF_OK), CONF_OK_BYTE);
led_indicate_info(10);
} else {
led_indicate_warning(10);
}
}
void eeprom_conf_delete() {
EEPROM.update(eeprom_addr(ADDR_CONF_OK), 0x00);
}
void unlock_rom() {
led_indicate_error(50);
eeprom_erase();