From 4d943999d571b0716a3f20c5fa39bb73269dea58 Mon Sep 17 00:00:00 2001 From: Mark Qvist Date: Mon, 18 Jun 2018 22:30:24 +0200 Subject: [PATCH] Prepared EEPROM functionality --- Config.h | 6 +++++- EEPROM.cpp | 36 ++++++++++++++++++++++++++++++++++++ Framing.h | 5 +++++ LoRa.cpp | 6 +++--- RNode_Firmware.ino | 3 +++ Utilities.cpp | 20 ++++++++++++++++++++ 6 files changed, 72 insertions(+), 4 deletions(-) create mode 100644 EEPROM.cpp diff --git a/Config.h b/Config.h index 1a7b208..a8aeca6 100644 --- a/Config.h +++ b/Config.h @@ -1,9 +1,13 @@ #ifndef CONFIG_H #define CONFIG_H - #define MCU_328P 0x90 + #define MCU_328P 0x90 #define MCU_1284P 0x91 + #define PRODUCT_RNODE 0x03 + #define MODEL_A4 0xA4 + #define MODEL_A9 0xA9 + #if defined(__AVR_ATmega328P__) #define MCU_VARIANT MCU_328P #warning "Firmware is being compiled for atmega328p based boards" diff --git a/EEPROM.cpp b/EEPROM.cpp new file mode 100644 index 0000000..b1990c1 --- /dev/null +++ b/EEPROM.cpp @@ -0,0 +1,36 @@ +#include +#include +#include "Config.h" +#include "Framing.h" + +#define ADDR_PRODUCT 0x00 +#define ADDR_MODEL 0x01 +#define ADDR_HW_REV 0x02 +#define ADDR_SERIAL 0x03 +#define ADDR_MADE 0x06 +#define ADDR_CHKSUM 0x0A +#define ADDR_SIGNATURE 0x1A +#define ADDR_INFO_LOCK 0x9A +#define INFO_LOCK_BYTE 0x73 + +#define ADDR_CONF_SF 0x74 +#define ADDR_CONF_CR 0x75 +#define ADDR_CONF_TXP 0x76 +#define ADDR_CONF_BW 0x77 +#define ADDR_CONF_FREQ 0x7B +#define ADDR_CONF_OK 0x7F +#define CONF_OK_BYTE 0x73 + +void eeprom_dump_info() { + for (int addr = ADDR_PRODUCT; addr <= ADDR_INFO_LOCK; addr++) { + uint8_t rom_byte = EEPROM.read(addr); + Serial.write(rom_byte); + } +} + +void eeprom_dump_config() { + for (int addr = ADDR_CONF_SF; addr <= ADDR_CONF_OK; addr++) { + uint8_t rom_byte = EEPROM.read(addr); + Serial.write(rom_byte); + } +} \ No newline at end of file diff --git a/Framing.h b/Framing.h index 6b00cc4..af81042 100644 --- a/Framing.h +++ b/Framing.h @@ -22,6 +22,11 @@ #define CMD_BLINK 0x30 #define CMD_RANDOM 0x40 + #define CMD_INFO_READ 0x50 + #define CMD_INFO_WRITE 0x51 + #define CMD_CONF_READ 0x52 + #define CMD_CONF_WRITE 0x53 + #define RADIO_STATE_OFF 0x00 #define RADIO_STATE_ON 0x01 diff --git a/LoRa.cpp b/LoRa.cpp index 2b92f85..61166dd 100644 --- a/LoRa.cpp +++ b/LoRa.cpp @@ -6,7 +6,7 @@ #include -// registers +// Registers #define REG_FIFO 0x00 #define REG_OP_MODE 0x01 #define REG_FRF_MSB 0x06 @@ -39,7 +39,7 @@ #define REG_DIO_MAPPING_1 0x40 #define REG_VERSION 0x42 -// modes +// Modes #define MODE_LONG_RANGE_MODE 0x80 #define MODE_SLEEP 0x00 #define MODE_STDBY 0x01 @@ -112,7 +112,7 @@ int LoRaClass::begin(long frequency) writeRegister(REG_MODEM_CONFIG_3, 0x04); // set output power to 17 dBm - setTxPower(17); + setTxPower(2); // put in standby mode idle(); diff --git a/RNode_Firmware.ino b/RNode_Firmware.ino index 0d5e4b9..5d1c851 100644 --- a/RNode_Firmware.ino +++ b/RNode_Firmware.ino @@ -2,6 +2,7 @@ #include #include "Config.h" #include "Framing.h" +#include "EEPROM.cpp" #include "Utilities.cpp" void setup() { @@ -360,6 +361,8 @@ void loop() { dcd_waiting = true; } } + } else { + led_indicate_standby(); } if (Serial.available()) { diff --git a/Utilities.cpp b/Utilities.cpp index 533445c..29d9639 100644 --- a/Utilities.cpp +++ b/Utilities.cpp @@ -51,6 +51,26 @@ void led_indicate_info(int cycles) { digitalWrite(pin_led_rx, LOW); } +uint8_t led_standby_min = 1; +uint8_t led_standby_max = 22; +uint8_t led_standby_value = led_standby_min; +int8_t led_standby_direction = 0; +unsigned long led_standby_ticks = 0; +unsigned long led_standby_wait = 11000; +void led_indicate_standby() { + led_standby_ticks++; + if (led_standby_ticks > led_standby_wait) { + led_standby_ticks = 0; + if (led_standby_value <= led_standby_min) { + led_standby_direction = 1; + } else if (led_standby_value >= led_standby_max) { + led_standby_direction = -1; + } + led_standby_value += led_standby_direction; + analogWrite(pin_led_rx, led_standby_value); + } +} + void escapedSerialWrite(uint8_t byte) { if (byte == FEND) { Serial.write(FESC); byte = TFEND; } if (byte == FESC) { Serial.write(FESC); byte = TFESC; }