Skip to content

Commit

Permalink
feat:Compatible with sx1262 using tcxo.
Browse files Browse the repository at this point in the history
  • Loading branch information
Wvirgil123 committed Jan 14, 2025
1 parent c16c51a commit 55d1df4
Show file tree
Hide file tree
Showing 10 changed files with 91 additions and 128 deletions.
38 changes: 4 additions & 34 deletions components/liblorahub/lorahub_hal.c
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ License: Revised BSD License, see LICENSE.TXT file include in the project
#include "radio_context.h"
#include "ral.h"

#include "sx126x_lorahub.h"
#include "bsp_sx126x.h"

#define INDICATOR_LORAHUB 1

Expand Down Expand Up @@ -89,7 +89,6 @@ static struct lgw_conf_rxif_s rxif_conf = {
.bandwidth = BW_UNDEFINED, .coderate = CR_UNDEFINED, .datarate = DR_UNDEFINED, .modulation = MOD_UNDEFINED
};

static spi_host_device_t spi_host_id = SPI2_HOST;

static radio_context_t radio_context = { 0 };
#define RADIO_CONTEXT ( ( void* ) &radio_context )
Expand All @@ -112,9 +111,6 @@ const ral_t lgw_ral = RAL_LR11XX_INSTANTIATE( RADIO_CONTEXT );

int lgw_connect( void )
{
#if (INDICATOR_LORAHUB)
sx126x_init();
#endif
esp_err_t ret;

#if defined( CONFIG_RADIO_TYPE_SX1261 ) || defined( CONFIG_RADIO_TYPE_SX1262 ) || defined( CONFIG_RADIO_TYPE_SX1268 )
Expand Down Expand Up @@ -208,35 +204,9 @@ int lgw_connect( void )
{
ESP_LOGI( TAG_HAL, "LED_TX_GPIO not set" );
}

/* SPI configuration */
spi_bus_config_t spi_bus_config = { .mosi_io_num = radio_context.spi_mosi,
.miso_io_num = radio_context.spi_miso,
.sclk_io_num = radio_context.spi_sclk,
.quadwp_io_num = -1,
.quadhd_io_num = -1 };

ret = spi_bus_initialize( spi_host_id, &spi_bus_config, SPI_DMA_CH_AUTO );
if( ret != ESP_OK )
{
ESP_LOGE( TAG_HAL, "ERROR: spi_bus_initialize failed with %d", ret );
return -1;
}

spi_device_interface_config_t devcfg;
memset( &devcfg, 0, sizeof( spi_device_interface_config_t ) );
devcfg.clock_speed_hz = SPI_SPEED;
devcfg.spics_io_num = -1;
devcfg.queue_size = 7;
devcfg.mode = 0;
devcfg.flags = SPI_DEVICE_NO_DUMMY;

ret = spi_bus_add_device( spi_host_id, &devcfg, &( radio_context.spi_handle ) );
if( ret != ESP_OK )
{
ESP_LOGE( TAG_HAL, "ERROR: spi_bus_add_device failed with %d", ret );
return -1;
}

// SPI has been initialized in file sensecap_indicator_board.c
radio_context.spi_handle = bsp_sx126x_spi_handle_get();

return 0;
}
Expand Down
1 change: 0 additions & 1 deletion components/lora/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ set(srcs
"radio.c"
"sx126x.c"
"timer.c"
"sx126x_lorahub.c"
)

idf_component_register(SRCS "${srcs}"
Expand Down
15 changes: 5 additions & 10 deletions components/lora/sx126x_lorahub.h → components/lora/bsp_sx126x.h
Original file line number Diff line number Diff line change
@@ -1,9 +1,6 @@
#include <stdlib.h>
#include "driver/i2c.h"
#include <string.h>

#include "bsp_i2c.h"
#pragma once

#include "bsp_board.h"
#ifdef __cplusplus
extern "C" {
#endif
Expand All @@ -12,6 +9,7 @@ extern "C" {
#define EXPANDER_IO_RADIO_RST 1
#define EXPANDER_IO_RADIO_BUSY 2
#define EXPANDER_IO_RADIO_DIO_1 3
#define EXPANDER_IO_RADIO_VER 11 //Pull-up indicates the use of tcxo

#define ESP32_RADIO_MOSI GPIO_NUM_48
#define ESP32_RADIO_MISO GPIO_NUM_47
Expand All @@ -20,12 +18,9 @@ extern "C" {

extern io_expander_ops_t *indicator_io_expander;


void sx126x_init(void);



spi_device_handle_t bsp_sx126x_spi_handle_get(void);

#ifdef __cplusplus
}
#endif

20 changes: 12 additions & 8 deletions components/lora/radio.c
Original file line number Diff line number Diff line change
Expand Up @@ -1058,16 +1058,20 @@ void RadioSleep( void )
DelayMs( 2 );
}

extern bool g_have_tcxo;
void RadioStandby( void )
{
SX126xSetStandby( STDBY_XOSC ); //todo

// set PF
//uint8_t xt_config= 25;
uint8_t xt_config= 16; // hw verion 1.3 or above
//printf("xt_config:%d\r\n", xt_config);
SX126xWriteRegister(REG_XTA_TRIM, xt_config);
SX126xWriteRegister(REG_XTB_TRIM, xt_config);
if(g_have_tcxo) {
SX126xSetStandby( STDBY_RC );
} else {
SX126xSetStandby( STDBY_XOSC ); //todo
// set PF
//uint8_t xt_config= 25;
uint8_t xt_config= 16; // hw verion 1.3 or above
//printf("xt_config:%d\r\n", xt_config);
SX126xWriteRegister(REG_XTA_TRIM, xt_config);
SX126xWriteRegister(REG_XTB_TRIM, xt_config);
}
}

void RadioRx( uint32_t timeout )
Expand Down
34 changes: 0 additions & 34 deletions components/lora/sx126x_lorahub.c

This file was deleted.

Loading

0 comments on commit 55d1df4

Please sign in to comment.