opencom_xl_firmware/opencom_xl_firmware.ino

1505 lines
45 KiB
Arduino
Raw Permalink Normal View History

// Copyright (C) 2024, Mark Qvist
2023-01-14 00:11:02 +01:00
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
2018-12-01 19:31:51 +01:00
#include <Arduino.h>
2018-04-05 18:10:42 +02:00
#include <SPI.h>
#include "Utilities.h"
2018-04-05 18:10:42 +02:00
#if MCU_VARIANT == MCU_NRF52
#define INTERFACE_SPI
2024-10-16 21:24:18 +01:00
#if BOARD_MODEL == BOARD_RAK4631 || BOARD_MODEL == BOARD_OPENCOM_XL
// Required because on RAK4631, non-default SPI pins must be initialised when class is declared.
SPIClass interface_spi[1] = {
// SX1262
SPIClass(
NRF_SPIM2,
interface_pins[0][3],
interface_pins[0][1],
interface_pins[0][2]
)
};
#elif BOARD_MODEL == BOARD_TECHO
SPIClass interface_spi[1] = {
// SX1262
SPIClass(
NRF_SPIM3,
interface_pins[0][3],
interface_pins[0][1],
interface_pins[0][2]
)
};
#endif
#endif
#ifndef INTERFACE_SPI
// INTERFACE_SPI is only required on NRF52 platforms, as the SPI pins are set in the class constructor and not by a setter method.
// Even if custom SPI interfaces are not needed, the array must exist to prevent compilation errors.
#define INTERFACE_SPI
SPIClass interface_spi[1];
#endif
2020-05-28 22:18:19 +02:00
FIFOBuffer serialFIFO;
uint8_t serialBuffer[CONFIG_UART_BUFFER_SIZE+1];
2020-05-28 22:18:19 +02:00
uint16_t packet_starts_buf[(CONFIG_QUEUE_MAX_LENGTH)+1];
2020-05-28 22:18:19 +02:00
uint16_t packet_lengths_buf[(CONFIG_QUEUE_MAX_LENGTH)+1];
2020-05-28 22:18:19 +02:00
2024-06-10 13:05:21 +01:00
FIFOBuffer16 packet_starts[INTERFACE_COUNT];
FIFOBuffer16 packet_lengths[INTERFACE_COUNT];
2020-05-28 22:18:19 +02:00
2024-06-10 13:05:21 +01:00
volatile uint8_t queue_height[INTERFACE_COUNT] = {0};
volatile uint16_t queued_bytes[INTERFACE_COUNT] = {0};
volatile uint16_t queue_cursor[INTERFACE_COUNT] = {0};
volatile uint16_t current_packet_start[INTERFACE_COUNT] = {0};
2020-05-29 14:58:10 +02:00
volatile bool serial_buffering = false;
extern void setup_interfaces(); // from src/misc/ModemISR.h
#if HAS_BLUETOOTH || HAS_BLE == true
bool bt_init_ran = false;
#endif
2020-05-29 14:58:10 +02:00
2023-01-06 22:29:23 +01:00
#if HAS_CONSOLE
#include "Console.h"
#endif
#define MODEM_QUEUE_SIZE 4*INTERFACE_COUNT
typedef struct {
size_t len;
int rssi;
int snr_raw;
uint8_t interface;
2024-10-15 17:34:16 +01:00
uint8_t data[];
} modem_packet_t;
static xQueueHandle modem_packet_queue = NULL;
2020-05-29 14:58:10 +02:00
char sbuf[128];