Skip to content
This repository was archived by the owner on Sep 16, 2024. It is now read-only.

Commit 976af3b

Browse files
committed
MicroPython 1.20.0.rc11.2
Add support for LoRa regions CN470 and IN865 This is a special customer pre-release and has only been tested on the LoPy4!
1 parent 19bd9e7 commit 976af3b

File tree

16 files changed

+273
-9
lines changed

16 files changed

+273
-9
lines changed

drivers/sx127x/radio.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,14 @@ struct Radio_s
117117
* \param [IN] freq Channel RF frequency
118118
*/
119119
void ( *SetChannel )( uint32_t freq );
120+
121+
/*!
122+
* \brief Gets the channel frequency
123+
*
124+
* \param Channel RF frequency
125+
*/
126+
uint32_t ( *GetChannel )( void );
127+
120128
/*!
121129
* \brief Checks if the channel is free for the given time
122130
*

drivers/sx127x/sx1272/sx1272.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -230,6 +230,11 @@ IRAM_ATTR void SX1272SetChannel( uint32_t freq )
230230
SX1272Write( REG_FRFLSB, ( uint8_t )( freq & 0xFF ) );
231231
}
232232

233+
IRAM_ATTR uint32_t SX1272GetChannel( void )
234+
{
235+
return SX1272.Settings.Channel;
236+
}
237+
233238
bool SX1272IsChannelFree( RadioModems_t modem, uint32_t freq, int16_t rssiThresh, uint32_t maxCarrierSenseTime )
234239
{
235240
bool status = true;

drivers/sx127x/sx1272/sx1272.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,13 @@ void SX1272SetModem( RadioModems_t modem );
175175
*/
176176
void SX1272SetChannel( uint32_t freq );
177177

178+
/*!
179+
* Return the channel configuration
180+
*
181+
* \param Channel RF frequency .
182+
*/
183+
uint32_t SX1272GetChannel( void );
184+
178185
/*!
179186
* \brief Checks if the channel is free for the given time
180187
*

drivers/sx127x/sx1276/sx1276.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,11 @@ IRAM_ATTR void SX1276SetChannel( uint32_t freq )
251251
SX1276Write( REG_FRFLSB, ( uint8_t )( freq & 0xFF ) );
252252
}
253253

254+
IRAM_ATTR uint32_t SX1276GetChannel( void )
255+
{
256+
return SX1276.Settings.Channel;
257+
}
258+
254259
bool SX1276IsChannelFree( RadioModems_t modem, uint32_t freq, int16_t rssiThresh, uint32_t maxCarrierSenseTime )
255260
{
256261
bool status = true;

drivers/sx127x/sx1276/sx1276.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,13 @@ void SX1276SetModem( RadioModems_t modem );
175175
*/
176176
void SX1276SetChannel( uint32_t freq );
177177

178+
/*!
179+
* Return the channel configuration
180+
*
181+
* \param Channel RF frequency .
182+
*/
183+
uint32_t SX1276GetChannel( void );
184+
178185
/*!
179186
* \brief Checks if the channel is free for the given time
180187
*

esp32/application.mk

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -216,6 +216,8 @@ APP_LIB_LORA_SRC_C = $(addprefix lib/lora/,\
216216
mac/region/RegionCommon.c \
217217
mac/region/RegionEU868.c \
218218
mac/region/RegionUS915.c \
219+
mac/region/RegionCN470.c \
220+
mac/region/RegionIN865.c \
219221
system/delay.c \
220222
system/gpio.c \
221223
system/timer.c \
@@ -358,7 +360,7 @@ APP_LDFLAGS += $(LDFLAGS) -T esp32_out.ld -T esp32.common.ld -T esp32.rom.ld -T
358360
# add the application specific CFLAGS
359361
CFLAGS += $(APP_INC) -DMICROPY_NLR_SETJMP=1 -DMBEDTLS_CONFIG_FILE='"mbedtls/esp_config.h"' -DHAVE_CONFIG_H -DESP_PLATFORM -DFFCONF_H=\"lib/oofatfs/ffconf.h\"
360362
CFLAGS_SIGFOX += $(APP_INC) -DMICROPY_NLR_SETJMP=1 -DMBEDTLS_CONFIG_FILE='"mbedtls/esp_config.h"' -DHAVE_CONFIG_H -DESP_PLATFORM
361-
CFLAGS += -DREGION_AS923 -DREGION_AU915 -DREGION_EU868 -DREGION_US915 -DBASE=0 -DPYBYTES=1
363+
CFLAGS += -DREGION_AS923 -DREGION_AU915 -DREGION_EU868 -DREGION_US915 -DREGION_CN470 -DREGION_IN865 -DBASE=0 -DPYBYTES=1
362364
# Specify if this is base or Pybytes Firmware
363365
ifeq ($(VARIANT),BASE)
364366
CFLAGS += -DVARIANT=0
@@ -456,7 +458,8 @@ ENTER_FLASHING_MODE = $(PIC_TOOL) --enter
456458
EXIT_FLASHING_MODE = $(PIC_TOOL) --exit
457459

458460
ESPTOOLPY = $(PYTHON) $(IDF_PATH)/components/esptool_py/esptool/esptool.py --chip esp32
459-
ESPTOOLPY_SERIAL = $(ESPTOOLPY) --port $(ESPPORT) --baud $(ESPBAUD) --before no_reset --after no_reset
461+
ESPRESET ?= --before no_reset --after no_reset
462+
ESPTOOLPY_SERIAL = $(ESPTOOLPY) --port $(ESPPORT) --baud $(ESPBAUD) $(ESPRESET)
460463

461464
ESPTOOLPY_WRITE_FLASH = $(ESPTOOLPY_SERIAL) write_flash -z --flash_mode $(ESPFLASHMODE) --flash_freq $(ESPFLASHFREQ) --flash_size $(FLASH_SIZE)
462465
ESPTOOLPY_ERASE_FLASH = $(ESPTOOLPY_SERIAL) erase_flash

esp32/lora/sx1272-board.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ DRAM_ATTR const struct Radio_s Radio =
3232
SX1272GetStatus,
3333
SX1272SetModem,
3434
SX1272SetChannel,
35+
SX1272GetChannel,
3536
SX1272IsChannelFree,
3637
SX1272Random,
3738
SX1272SetRxConfig,

esp32/lora/sx1276-board.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ DRAM_ATTR const struct Radio_s Radio =
3131
SX1276GetStatus,
3232
SX1276SetModem,
3333
SX1276SetChannel,
34+
SX1276GetChannel,
3435
SX1276IsChannelFree,
3536
SX1276Random,
3637
SX1276SetRxConfig,

esp32/mods/modlora.c

Lines changed: 42 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,8 @@
5252
#include "lora/mac/region/RegionUS915.h"
5353
#include "lora/mac/region/RegionUS915-Hybrid.h"
5454
#include "lora/mac/region/RegionEU868.h"
55+
#include "lora/mac/region/RegionCN470.h"
56+
#include "lora/mac/region/RegionIN865.h"
5557

5658
// openThread includes
5759
#ifdef LORA_OPENTHREAD_ENABLED
@@ -1317,6 +1319,20 @@ static void lora_validate_frequency (uint32_t frequency) {
13171319
goto freq_error;
13181320
}
13191321
break;
1322+
case LORAMAC_REGION_CN470:
1323+
#if defined(LOPY4)
1324+
if (frequency < 470000000 || frequency > 510000000) {
1325+
goto freq_error;
1326+
}
1327+
#else
1328+
goto freq_error;
1329+
#endif
1330+
break;
1331+
case LORAMAC_REGION_IN865:
1332+
if (frequency < 865000000 || frequency > 867000000) {
1333+
goto freq_error;
1334+
}
1335+
break;
13201336
case LORAMAC_REGION_EU868:
13211337
#if defined(LOPY4)
13221338
if (frequency < 410000000 || frequency > 870000000) {
@@ -1362,6 +1378,16 @@ static void lora_validate_channel (uint32_t index) {
13621378
goto channel_error;
13631379
}
13641380
break;
1381+
case LORAMAC_REGION_CN470:
1382+
if (index >= CN470_MAX_NB_CHANNELS) {
1383+
goto channel_error;
1384+
}
1385+
break;
1386+
case LORAMAC_REGION_IN865:
1387+
if (index >= IN865_MAX_NB_CHANNELS) {
1388+
goto channel_error;
1389+
}
1390+
break;
13651391
default:
13661392
break;
13671393
}
@@ -1383,6 +1409,8 @@ static bool lora_validate_data_rate (uint32_t data_rate) {
13831409
case LORAMAC_REGION_AS923:
13841410
case LORAMAC_REGION_EU868:
13851411
case LORAMAC_REGION_AU915:
1412+
case LORAMAC_REGION_CN470:
1413+
case LORAMAC_REGION_IN865:
13861414
if (data_rate > DR_6) {
13871415
return false;
13881416
}
@@ -1432,7 +1460,8 @@ static void lora_validate_device_class (DeviceClass_t device_class) {
14321460

14331461
static void lora_validate_region (LoRaMacRegion_t region) {
14341462
if (region != LORAMAC_REGION_AS923 && region != LORAMAC_REGION_AU915
1435-
&& region != LORAMAC_REGION_EU868 && region != LORAMAC_REGION_US915) {
1463+
&& region != LORAMAC_REGION_EU868 && region != LORAMAC_REGION_US915
1464+
&& region != LORAMAC_REGION_CN470 && region != LORAMAC_REGION_IN865) {
14361465
nlr_raise(mp_obj_new_exception_msg_varg(&mp_type_ValueError, "invalid region %d", region));
14371466
}
14381467
}
@@ -1653,6 +1682,10 @@ static mp_obj_t lora_init_helper(lora_obj_t *self, const mp_arg_val_t *args) {
16531682
case LORAMAC_REGION_EU868:
16541683
cmd_data.info.init.frequency = 868000000;
16551684
break;
1685+
case LORAMAC_REGION_CN470:
1686+
cmd_data.info.init.frequency = 470000000;
1687+
case LORAMAC_REGION_IN865:
1688+
cmd_data.info.init.frequency = 865000000;
16561689
default:
16571690
break;
16581691
}
@@ -1666,9 +1699,11 @@ static mp_obj_t lora_init_helper(lora_obj_t *self, const mp_arg_val_t *args) {
16661699
case LORAMAC_REGION_AS923:
16671700
case LORAMAC_REGION_AU915:
16681701
case LORAMAC_REGION_US915:
1702+
case LORAMAC_REGION_IN865:
16691703
case LORAMAC_REGION_US915_HYBRID:
16701704
cmd_data.info.init.tx_power = 20;
16711705
break;
1706+
case LORAMAC_REGION_CN470:
16721707
case LORAMAC_REGION_EU868:
16731708
cmd_data.info.init.tx_power = 14;
16741709
break;
@@ -1829,7 +1864,9 @@ STATIC mp_obj_t lora_join(mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_t *
18291864
case LORAMAC_REGION_US915_HYBRID:
18301865
dr = DR_4;
18311866
break;
1867+
case LORAMAC_REGION_CN470:
18321868
case LORAMAC_REGION_EU868:
1869+
case LORAMAC_REGION_IN865:
18331870
dr = DR_5;
18341871
break;
18351872
default:
@@ -1860,6 +1897,7 @@ STATIC mp_obj_t lora_join(mp_uint_t n_args, const mp_obj_t *pos_args, mp_map_t *
18601897
goto dr_error;
18611898
}
18621899
break;
1900+
case LORAMAC_REGION_CN470:
18631901
case LORAMAC_REGION_EU868:
18641902
if (dr > DR_5) {
18651903
goto dr_error;
@@ -2406,6 +2444,8 @@ STATIC const mp_map_elem_t lora_locals_dict_table[] = {
24062444
{ MP_OBJ_NEW_QSTR(MP_QSTR_AU915), MP_OBJ_NEW_SMALL_INT(LORAMAC_REGION_AU915) },
24072445
{ MP_OBJ_NEW_QSTR(MP_QSTR_EU868), MP_OBJ_NEW_SMALL_INT(LORAMAC_REGION_EU868) },
24082446
{ MP_OBJ_NEW_QSTR(MP_QSTR_US915), MP_OBJ_NEW_SMALL_INT(LORAMAC_REGION_US915) },
2447+
{ MP_OBJ_NEW_QSTR(MP_QSTR_CN470), MP_OBJ_NEW_SMALL_INT(LORAMAC_REGION_CN470) },
2448+
{ MP_OBJ_NEW_QSTR(MP_QSTR_IN865), MP_OBJ_NEW_SMALL_INT(LORAMAC_REGION_IN865) },
24092449
};
24102450

24112451
STATIC MP_DEFINE_CONST_DICT(lora_locals_dict, lora_locals_dict_table);
@@ -2451,6 +2491,7 @@ static int lora_socket_socket (mod_network_socket_obj_t *s, int *_errno) {
24512491
switch (lora_obj.region) {
24522492
case LORAMAC_REGION_AS923:
24532493
case LORAMAC_REGION_EU868:
2494+
case LORAMAC_REGION_CN470:
24542495
dr = DR_5;
24552496
break;
24562497
case LORAMAC_REGION_AU915:

esp32/pycom_version.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
#ifndef VERSION_H_
1111
#define VERSION_H_
1212

13-
#define SW_VERSION_NUMBER "1.20.0.rc11.1"
13+
#define SW_VERSION_NUMBER "1.20.0.rc11.2"
1414

1515
#define LORAWAN_VERSION_NUMBER "1.0.2"
1616

0 commit comments

Comments
 (0)