Skip to content

Commit

Permalink
Reorganize project structure. Update with latest improvements from Em…
Browse files Browse the repository at this point in the history
…yChat app development.
  • Loading branch information
beegee-tokyo committed Mar 10, 2020
1 parent 4be4cd9 commit ba52ebe
Show file tree
Hide file tree
Showing 16 changed files with 482 additions and 315 deletions.
8 changes: 7 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@
"PLATFORMIO_CALLER": "vscode"
},
"files.associations": {
"functional": "cpp"
"functional": "cpp",
"array": "cpp",
"*.tcc": "cpp",
"memory": "cpp",
"istream": "cpp",
"tuple": "cpp",
"utility": "cpp"
}
}
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,4 @@ Other defines used in the code, but setup by the PlatformIO packages
- The Arduino BSP for Espressif ESP32 based board.

#### [Arduino Core for Circuitrocks Alora Boards](https://github.com/beegee-tokyo/Circuitrocks_ISP4520_Arduino)
- The Arduino BSP for the ISP4520 boards. Manual installation pf the BSP is required as explained [here](https://github.com/beegee-tokyo/Circuitrocks_ISP4520_Arduino#bsp-installation)
- The Arduino BSP for the ISP4520 boards. Manual installation of the BSP is required as explained [here](https://github.com/beegee-tokyo/Circuitrocks_ISP4520_Arduino#bsp-installation)
10 changes: 5 additions & 5 deletions platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ upload_port = COM99
build_flags =
-DCFG_DEBUG=2
-DSW_VERSION=1.0
-DMYLOG_LOG_LEVEL=MYLOG_LOG_LEVEL_INFO
-DMYLOG_LOG_LEVEL=MYLOG_LOG_LEVEL_ERROR
lib_deps =
SX126x-Arduino
extra_scripts = pre:post_rename.py
Expand All @@ -44,7 +44,7 @@ upload_port = COM30
upload_speed = 915200
build_flags =
-DSW_VERSION=1.0
-DMYLOG_LOG_LEVEL=MYLOG_LOG_LEVEL_WARN
-DMYLOG_LOG_LEVEL=MYLOG_LOG_LEVEL_ERROR
; -DARDUHAL_LOG_LEVEL=ARDUHAL_LOG_LEVEL_ERROR
-DOLED_SDA=23
-DOLED_SCL=22
Expand All @@ -61,7 +61,7 @@ upload_port = COM28
upload_speed = 915200
build_flags =
-DSW_VERSION=1.0
-DMYLOG_LOG_LEVEL=MYLOG_LOG_LEVEL_WARN
-DMYLOG_LOG_LEVEL=MYLOG_LOG_LEVEL_DEBUG
; -DARDUHAL_LOG_LEVEL=ARDUHAL_LOG_LEVEL_ERROR
lib_deps =
SX126x-Arduino
Expand All @@ -74,7 +74,7 @@ upload_port = COM24
upload_speed = 915200
build_flags =
-DSW_VERSION=1.0
-DMYLOG_LOG_LEVEL=MYLOG_LOG_LEVEL_WARN
-DMYLOG_LOG_LEVEL=MYLOG_LOG_LEVEL_ERROR
; -DARDUHAL_LOG_LEVEL=ARDUHAL_LOG_LEVEL_ERROR
lib_deps =
SX126x-Arduino
Expand All @@ -87,7 +87,7 @@ upload_port = COM29
upload_speed = 915200
build_flags =
-DSW_VERSION=1.0
-DMYLOG_LOG_LEVEL=MYLOG_LOG_LEVEL_WARN
-DMYLOG_LOG_LEVEL=MYLOG_LOG_LEVEL_DEBUG
; -DARDUHAL_LOG_LEVEL=ARDUHAL_LOG_LEVEL_ERROR
lib_deps =
SX126x-Arduino
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
7 changes: 5 additions & 2 deletions src/display.cpp → src/Display/display.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,11 @@ void dispWriteHeader(void)
{
display.clear();
display.setTextAlignment(TEXT_ALIGN_LEFT);
int strWidth = display.getStringWidth("LoRa Mesh Test #dev " + String(numElements + 1));
display.drawString(64 - (strWidth / 2), 0, "LoRa Mesh Test #dev " + String(numElements + 1));
// int strWidth = display.getStringWidth("LoRa Mesh Test #dev " + String(numElements + 1));
// display.drawString(64 - (strWidth / 2), 0, "LoRa Mesh Test #dev " + String(numElements + 1));
char lineString[64] = {0};
sprintf(lineString, "LR Mesh %08X #n %d", deviceID, numOfNodes() + 1);
display.drawString(0, 0, lineString);
display.display();
}

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
143 changes: 143 additions & 0 deletions src/Mesh/lora.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
#include "main.h"

/** HW configuration structure for the LoRa library */
extern hw_config _hwConfig;

#ifdef ESP32
#ifdef IS_WROVER
// ESP32 Wrover - SX126x pin configuration
/** LORA RESET */
int PIN_LORA_RESET = 4;
/** LORA DIO_1 */
int PIN_LORA_DIO_1 = 21;
/** LORA SPI BUSY */
int PIN_LORA_BUSY = 22;
/** LORA SPI CS */
int PIN_LORA_NSS = 5;
/** LORA SPI CLK */
int PIN_LORA_SCLK = 18;
/** LORA SPI MISO */
int PIN_LORA_MISO = 19;
/** LORA SPI MOSI */
int PIN_LORA_MOSI = 23;
/** LORA ANTENNA TX ENABLE */
int RADIO_TXEN = 26;
/** LORA ANTENNA RX ENABLE */
int RADIO_RXEN = 27;

#define LED_BUILTIN 15
#else
// ESP32 Feather - SX126x pin configuration
/** LORA RESET */
int PIN_LORA_RESET = 32;
/** LORA DIO_1 */
int PIN_LORA_DIO_1 = 14;
/** LORA SPI BUSY */
int PIN_LORA_BUSY = 27;
/** LORA SPI CS */
int PIN_LORA_NSS = 33;
/** LORA SPI CLK */
int PIN_LORA_SCLK = SCK;
/** LORA SPI MISO */
int PIN_LORA_MISO = MISO;
/** LORA SPI MOSI */
int PIN_LORA_MOSI = MOSI;
/** LORA ANTENNA TX ENABLE */
int RADIO_TXEN = -1;
/** LORA ANTENNA RX ENABLE */
int RADIO_RXEN = -1;
#endif
#ifdef RED_ESP
#undef LED_BUILTIN
#define LED_BUILTIN 16
#endif
#endif
#ifdef NRF52
#ifdef ADAFRUIT
/** LORA RESET */
int PIN_LORA_RESET = 31;
/** LORA DIO_1 */
int PIN_LORA_DIO_1 = 11;
/** LORA SPI BUSY */
int PIN_LORA_BUSY = 30;
/** LORA SPI CS */
int PIN_LORA_NSS = 27;
/** LORA SPI CLK */
int PIN_LORA_SCLK = SCK;
/** LORA SPI MISO */
int PIN_LORA_MISO = MISO;
/** LORA SPI MOSI */
int PIN_LORA_MOSI = MOSI;
/** LORA ANTENNA TX ENABLE */
int RADIO_TXEN = -1;
/** LORA ANTENNA RX ENABLE */
int RADIO_RXEN = -1;
// Singleton for SPI connection to the LoRa chip
SPIClass SPI_LORA(NRF_SPIM1, MISO, SCK, MOSI);
#else
// Singleton for SPI connection to the LoRa chip
SPIClass SPI_LORA(NRF_SPIM2, MISO, SCK, MOSI);
#undef LED_BUILTIN
#define LED_BUILTIN 22
#endif
#endif

/** Callback if data was received over LoRa SX1262 */
void OnLoraData(uint32_t fromID, uint8_t *rxPayload, uint16_t rxSize, int16_t rxRssi, int8_t rxSnr);
/** Callback if Mesh map changed */
void onNodesListChange(void);

/** Structure with Mesh event callbacks */
static MeshEvents_t MeshEvents;

/**
* Initialize the LoRa HW
* @return bool
* True if initialization was successfull, false if not
*/
bool initLoRa(void)
{
bool initResult = true;
#if defined(ESP32) || defined(ADAFRUIT)
// Define the HW configuration between MCU and SX126x
_hwConfig.CHIP_TYPE = SX1262_CHIP; // eByte E22 module with an SX1262
_hwConfig.PIN_LORA_RESET = PIN_LORA_RESET; // LORA RESET
_hwConfig.PIN_LORA_NSS = PIN_LORA_NSS; // LORA SPI CS
_hwConfig.PIN_LORA_SCLK = PIN_LORA_SCLK; // LORA SPI CLK
_hwConfig.PIN_LORA_MISO = PIN_LORA_MISO; // LORA SPI MISO
_hwConfig.PIN_LORA_DIO_1 = PIN_LORA_DIO_1; // LORA DIO_1
_hwConfig.PIN_LORA_BUSY = PIN_LORA_BUSY; // LORA SPI BUSY
_hwConfig.PIN_LORA_MOSI = PIN_LORA_MOSI; // LORA SPI MOSI
_hwConfig.RADIO_TXEN = RADIO_TXEN; // LORA ANTENNA TX ENABLE
_hwConfig.RADIO_RXEN = RADIO_RXEN; // LORA ANTENNA RX ENABLE
_hwConfig.USE_DIO2_ANT_SWITCH = true; // Example uses an eByte E22 module which uses RXEN and TXEN pins as antenna control
_hwConfig.USE_DIO3_TCXO = true; // Example uses an eByte E22 module which uses DIO3 to control oscillator voltage
_hwConfig.USE_DIO3_ANT_SWITCH = false; // Only Insight ISP4520 module uses DIO3 as antenna control

if (lora_hardware_init(_hwConfig) != 0)
{
myLog_e("Error in hardware init");
}
#else // ISP4520
if (lora_isp4520_init(SX1262) != 0)
{
myLog_e("Error in hardware init");
initResult = false;
}
#endif
uint16_t readSyncWord = 0;
SX126xReadRegisters(REG_LR_SYNCWORD, (uint8_t *)&readSyncWord, 2);
myLog_w("Got syncword %X", readSyncWord);

MeshEvents.DataAvailable = OnLoraData;
MeshEvents.NodesListChanged = onNodesListChange;

// Initialize the LoRa Mesh
// * events, number of nodes, frequency, TX power
#ifdef ESP32
initMesh(&MeshEvents, 48);
#else
initMesh(&MeshEvents, 30);
#endif
return initResult;
}
Loading

0 comments on commit ba52ebe

Please sign in to comment.