Skip to content

Commit

Permalink
Ham: use of TWR V2.1 green NeoPixel color to keep track SA868 SQL sig…
Browse files Browse the repository at this point in the history
…nal status
  • Loading branch information
lyusupov committed Mar 11, 2024
1 parent 4979023 commit 132b218
Show file tree
Hide file tree
Showing 6 changed files with 72 additions and 46 deletions.
8 changes: 5 additions & 3 deletions software/firmware/source/SoftRF/src/driver/RF.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2406,9 +2406,10 @@ extern NeoPixelBus<NeoGrbFeature, Neo800KbpsMethod> TWR2_Pixel;
void sa868_Tx_LED_state(bool val) {
if (hw_info.model == SOFTRF_MODEL_HAM) {
#if defined(USE_NEOPIXELBUS_LIBRARY)
TWR2_Pixel.SetPixelColor(0, val ? LED_COLOR_RED :
color_t inactive_color = hw_info.revision > 0 ? LED_COLOR_BLACK :
settings->power_save & POWER_SAVE_NORECEIVE ?
LED_COLOR_BLACK : LED_COLOR_GREEN);
LED_COLOR_BLACK : LED_COLOR_GREEN;
TWR2_Pixel.SetPixelColor(0, val ? LED_COLOR_RED : inactive_color);
TWR2_Pixel.Show();
#endif /* USE_NEOPIXELBUS_LIBRARY */
}
Expand Down Expand Up @@ -2599,7 +2600,8 @@ static void sa8x8_setup()

if (hw_info.model == SOFTRF_MODEL_HAM) {
#if defined(USE_NEOPIXELBUS_LIBRARY)
TWR2_Pixel.SetPixelColor(0, rx ? LED_COLOR_GREEN: LED_COLOR_BLACK);
TWR2_Pixel.SetPixelColor(0, rx && hw_info.revision == 0 ?
LED_COLOR_GREEN : LED_COLOR_BLACK);
TWR2_Pixel.Show();
#endif /* USE_NEOPIXELBUS_LIBRARY */
}
Expand Down
43 changes: 30 additions & 13 deletions software/firmware/source/SoftRF/src/platform/ESP32.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -629,6 +629,7 @@ static void ESP32_setup()
#elif defined(CONFIG_IDF_TARGET_ESP32C2)
switch (flash_id)
{
case MakeFlashId(FMICRO_ID, FMICRO_ZB25Q16): /* WT018684-S5 */
default:
esp32_board = ESP32_C2_DEVKIT;
break;
Expand Down Expand Up @@ -1286,12 +1287,6 @@ static void ESP32_setup()
#if defined(CONFIG_IDF_TARGET_ESP32C2)
} else if (esp32_board == ESP32_C2_DEVKIT) {

#if ARDUINO_USB_CDC_ON_BOOT
SerialOutput.begin(SERIAL_OUT_BR, SERIAL_OUT_BITS,
SOC_GPIO_PIN_C2_CONS_RX,
SOC_GPIO_PIN_C2_CONS_TX);
#endif /* ARDUINO_USB_CDC_ON_BOOT */

lmic_pins.nss = SOC_GPIO_PIN_C2_SS;
lmic_pins.rst = LMIC_UNUSED_PIN;
lmic_pins.busy = SOC_GPIO_PIN_C2_TXE;
Expand Down Expand Up @@ -1442,8 +1437,7 @@ static void ESP32_setup()
#endif /* TBD */

#elif ARDUINO_USB_CDC_ON_BOOT && \
(defined(CONFIG_IDF_TARGET_ESP32C2) || \
defined(CONFIG_IDF_TARGET_ESP32C3) || \
(defined(CONFIG_IDF_TARGET_ESP32C3) || \
defined(CONFIG_IDF_TARGET_ESP32C6))

Serial.begin(SERIAL_OUT_BR);
Expand Down Expand Up @@ -2061,6 +2055,29 @@ static void ESP32_loop()
}
#endif /* !EXCLUDE_MAG */

#if defined(USE_SA8X8)
if (esp32_board == ESP32_LILYGO_T_TWR2 && hw_info.revision > 0) {
#if defined(USE_NEOPIXELBUS_LIBRARY)
color_t color = TWR2_Pixel.GetPixelColor(0);

if (color != LED_COLOR_RED) {
bool sql = digitalRead(SOC_GPIO_PIN_TWR2_RADIO_SQL);
if (sql == LOW) {
if (color == LED_COLOR_BLACK) {
TWR2_Pixel.SetPixelColor(0, LED_COLOR_GREEN);
TWR2_Pixel.Show();
}
} else {
if (color == LED_COLOR_GREEN) {
TWR2_Pixel.SetPixelColor(0, LED_COLOR_BLACK);
TWR2_Pixel.Show();
}
}
}
#endif /* USE_NEOPIXELBUS_LIBRARY */
}
#endif /* USE_SA8X8 */

// if (esp32_board == ESP32_HELTEC_TRACKER) {
// digitalWrite(SOC_GPIO_PIN_HELTRK_LED,
// digitalRead(SOC_GPIO_PIN_HELTRK_GNSS_PPS));
Expand Down Expand Up @@ -2924,7 +2941,9 @@ static void ESP32_EEPROM_extension(int cmd)
#endif /* CONFIG_IDF_TARGET_ESP32S3 */

if (cmd == EEPROM_EXT_LOAD) {
#if defined(CONFIG_IDF_TARGET_ESP32) || defined(USE_USB_HOST)
#if defined(CONFIG_IDF_TARGET_ESP32) || \
defined(CONFIG_IDF_TARGET_ESP32C2) || \
defined(USE_USB_HOST)
if (settings->nmea_out == NMEA_USB) {
settings->nmea_out = NMEA_UART;
}
Expand Down Expand Up @@ -4759,8 +4778,7 @@ IODev_ops_t ESP32SX_USBSerial_ops = {
#endif /* CONFIG_IDF_TARGET_ESP32S2 */

#if ARDUINO_USB_MODE && \
(defined(CONFIG_IDF_TARGET_ESP32C2) || \
defined(CONFIG_IDF_TARGET_ESP32C3) || \
(defined(CONFIG_IDF_TARGET_ESP32C3) || \
defined(CONFIG_IDF_TARGET_ESP32C6))

#define USB_TX_FIFO_SIZE (MAX_TRACKING_OBJECTS * 65 + 75 + 75 + 42 + 20)
Expand Down Expand Up @@ -5004,8 +5022,7 @@ const SoC_ops_t ESP32_ops = {
(ARDUINO_USB_CDC_ON_BOOT || defined(USE_USB_HOST))
&ESP32SX_USBSerial_ops,
#elif ARDUINO_USB_MODE && \
(defined(CONFIG_IDF_TARGET_ESP32C2) || \
defined(CONFIG_IDF_TARGET_ESP32C3) || \
(defined(CONFIG_IDF_TARGET_ESP32C3) || \
defined(CONFIG_IDF_TARGET_ESP32C6))
&ESP32CX_USBSerial_ops,
#else
Expand Down
6 changes: 5 additions & 1 deletion software/firmware/source/SoftRF/src/platform/ESP32.h
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,10 @@ struct rst_info {
#define ZBIT_ID 0x5E
#define ZBIT_ZB25VQ32B 0x4016

/* Shanghai Fudan Microelectronics Group Co., Ltd. */
#define FMICRO_ID 0xA1
#define FMICRO_ZB25Q16 0x4015

#define MakeFlashId(v,d) ((v << 16) | d)

#define MPU6886_REG_PWR_MGMT_1 (0x6B)
Expand Down Expand Up @@ -404,7 +408,7 @@ extern const USB_Device_List_t supported_USB_devices[];
defined(CONFIG_IDF_TARGET_ESP32C6)
#undef USE_OLED
#undef USE_TFT
#if defined(CONFIG_IDF_TARGET_ESP32C6)
#if defined(CONFIG_IDF_TARGET_ESP32C2) || defined(CONFIG_IDF_TARGET_ESP32C6)
#define EXCLUDE_EGM96
#define EXCLUDE_TEST_MODE
#define EXCLUDE_WATCHOUT_MODE
Expand Down
1 change: 1 addition & 0 deletions software/firmware/source/SoftRF/src/ui/Web.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1291,6 +1291,7 @@ void Web_setup()

/* FLASH memory usage optimization */
#if !defined(ARDUINO_ARCH_RP2040) && \
!defined(CONFIG_IDF_TARGET_ESP32C2) && \
!defined(CONFIG_IDF_TARGET_ESP32C6) && \
!defined(ARDUINO_ARCH_RENESAS)

Expand Down
52 changes: 27 additions & 25 deletions software/firmware/source/libraries/ADC/battery.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6,30 +6,7 @@

#include "battery.h"

#if defined(CONFIG_IDF_TARGET_ESP32C2) || defined(CONFIG_IDF_TARGET_ESP32C6)
static uint8_t adc_pin = 1;

void calibrate_voltage(uint8_t pin, adc_attenuation_t atten) {
adc_pin = pin;
analogReadResolution(12);
analogSetPinAttenuation(adc_pin, atten);
}

uint16_t read_voltage() {
// multisample ADC
uint32_t adc_reading = 0;

for (int i = 0; i < NO_OF_SAMPLES; i++) {
adc_reading += analogReadMilliVolts(adc_pin);
yield();
}

adc_reading /= NO_OF_SAMPLES;

return (uint16_t) adc_reading;
}

#else
#if !defined(ESP_IDF_VERSION_MAJOR) || ESP_IDF_VERSION_MAJOR < 5

// Local logging tag
static const char TAG[] = "ADC";
Expand Down Expand Up @@ -118,4 +95,29 @@ uint16_t read_voltage() {
ESP_LOGD(TAG, "Raw: %d / Voltage: %dmV", adc_reading, voltage);
return voltage;
}
#endif /* CONFIG_IDF_TARGET_ESP32C2 || C6 */

#else

static uint8_t adc_pin = 1;

void calibrate_voltage(uint8_t pin, adc_attenuation_t atten) {
adc_pin = pin;
analogReadResolution(12);
analogSetPinAttenuation(adc_pin, atten);
}

uint16_t read_voltage() {
// multisample ADC
uint32_t adc_reading = 0;

for (int i = 0; i < NO_OF_SAMPLES; i++) {
adc_reading += analogReadMilliVolts(adc_pin);
yield();
}

adc_reading /= NO_OF_SAMPLES;

return (uint16_t) adc_reading;
}

#endif /* ESP_IDF_VERSION_MAJOR */
8 changes: 4 additions & 4 deletions software/firmware/source/libraries/ADC/battery.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@

uint16_t read_voltage(void);

#if defined(CONFIG_IDF_TARGET_ESP32C2) || defined(CONFIG_IDF_TARGET_ESP32C6)
void calibrate_voltage(uint8_t, adc_attenuation_t atten = ADC_11db);
#else
#if !defined(ESP_IDF_VERSION_MAJOR) || ESP_IDF_VERSION_MAJOR < 5
#include <driver/adc.h>
#include <esp_adc_cal.h>

void calibrate_voltage(adc1_channel_t, adc_atten_t atten = ADC_ATTEN_DB_11);
#endif /* CONFIG_IDF_TARGET_ESP32C2 || C6 */
#else
void calibrate_voltage(uint8_t, adc_attenuation_t atten = ADC_11db);
#endif /* ESP_IDF_VERSION_MAJOR */

#define DEFAULT_VREF 1100 // tbd: use adc2_vref_to_gpio() for better estimate
#define NO_OF_SAMPLES 32 // we do some multisampling to get better values
Expand Down

0 comments on commit 132b218

Please sign in to comment.