Skip to content

Commit

Permalink
Add RAKWireless WisBlock Core RAK4631 support to the mesh network.
Browse files Browse the repository at this point in the history
  • Loading branch information
beegee-tokyo committed Dec 10, 2021
1 parent ba52ebe commit fb0bd63
Show file tree
Hide file tree
Showing 9 changed files with 57 additions and 22 deletions.
4 changes: 2 additions & 2 deletions lib/nrf52Timer/src/nrf52Timer.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#ifdef NRF52
#ifdef NRF52_SERIES
#include <Arduino.h>
#include "nrf_timer.h"
#include "nrf52Timer.h"
Expand Down Expand Up @@ -56,7 +56,7 @@ void TimerClass::attachInterrupt(funcPtr_t callback, int microsec)
if (microsec >= 1 << 28)
microsec = (1 << 28) - 1;
uint32_t ticks = nrf_timer_us_to_ticks(microsec, NRF_TIMER_FREQ_16MHz);
nrf_timer_cc_write(nrf_timer, cc_channel, ticks);
nrf_timer_cc_set(nrf_timer, cc_channel, ticks);
}

// Should be called in the Timer_callbackPtr() function
Expand Down
4 changes: 2 additions & 2 deletions lib/nrf52Timer/src/nrf52Timer.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#ifdef NRF52
#ifdef NRF52_SERIES
#ifndef _TIMER_H_
#define _TIMER_H_

Expand All @@ -20,4 +20,4 @@ extern NRF_TIMER_Type *nrf_timers[5];
extern TimerClass *Timers[5];

#endif // _TIMER_H_
#endif // NRF52
#endif // NRF52_SERIES
18 changes: 9 additions & 9 deletions lib/nrf52Timer/src/nrfTimer.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#ifdef NRF52
#ifdef NRF52_SERIES
/* Copyright (c) 2010 - 2017, Nordic Semiconductor ASA All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
Expand Down Expand Up @@ -87,7 +87,7 @@ typedef enum
NRF_TIMER_TASK_CAPTURE1 = offsetof(NRF_TIMER_Type, TASKS_CAPTURE[1]), ///< Task for capturing the timer value on channel 1.
NRF_TIMER_TASK_CAPTURE2 = offsetof(NRF_TIMER_Type, TASKS_CAPTURE[2]), ///< Task for capturing the timer value on channel 2.
NRF_TIMER_TASK_CAPTURE3 = offsetof(NRF_TIMER_Type, TASKS_CAPTURE[3]), ///< Task for capturing the timer value on channel 3.
#ifdef NRF52
#ifdef NRF52_SERIES
NRF_TIMER_TASK_CAPTURE4 = offsetof(NRF_TIMER_Type, TASKS_CAPTURE[4]), ///< Task for capturing the timer value on channel 4.
NRF_TIMER_TASK_CAPTURE5 = offsetof(NRF_TIMER_Type, TASKS_CAPTURE[5]), ///< Task for capturing the timer value on channel 5.
#endif
Expand All @@ -104,7 +104,7 @@ typedef enum
NRF_TIMER_EVENT_COMPARE1 = offsetof(NRF_TIMER_Type, EVENTS_COMPARE[1]), ///< Event from compare channel 1.
NRF_TIMER_EVENT_COMPARE2 = offsetof(NRF_TIMER_Type, EVENTS_COMPARE[2]), ///< Event from compare channel 2.
NRF_TIMER_EVENT_COMPARE3 = offsetof(NRF_TIMER_Type, EVENTS_COMPARE[3]), ///< Event from compare channel 3.
#ifdef NRF52
#ifdef NRF52_SERIES
NRF_TIMER_EVENT_COMPARE4 = offsetof(NRF_TIMER_Type, EVENTS_COMPARE[4]), ///< Event from compare channel 4.
NRF_TIMER_EVENT_COMPARE5 = offsetof(NRF_TIMER_Type, EVENTS_COMPARE[5]), ///< Event from compare channel 5.
#endif
Expand All @@ -120,15 +120,15 @@ typedef enum
NRF_TIMER_SHORT_COMPARE1_STOP_MASK = TIMER_SHORTS_COMPARE1_STOP_Msk, ///< Shortcut for stopping the timer based on compare 1.
NRF_TIMER_SHORT_COMPARE2_STOP_MASK = TIMER_SHORTS_COMPARE2_STOP_Msk, ///< Shortcut for stopping the timer based on compare 2.
NRF_TIMER_SHORT_COMPARE3_STOP_MASK = TIMER_SHORTS_COMPARE3_STOP_Msk, ///< Shortcut for stopping the timer based on compare 3.
#ifdef NRF52
#ifdef NRF52_SERIES
NRF_TIMER_SHORT_COMPARE4_STOP_MASK = TIMER_SHORTS_COMPARE4_STOP_Msk, ///< Shortcut for stopping the timer based on compare 4.
NRF_TIMER_SHORT_COMPARE5_STOP_MASK = TIMER_SHORTS_COMPARE5_STOP_Msk, ///< Shortcut for stopping the timer based on compare 5.
#endif
NRF_TIMER_SHORT_COMPARE0_CLEAR_MASK = TIMER_SHORTS_COMPARE0_CLEAR_Msk, ///< Shortcut for clearing the timer based on compare 0.
NRF_TIMER_SHORT_COMPARE1_CLEAR_MASK = TIMER_SHORTS_COMPARE1_CLEAR_Msk, ///< Shortcut for clearing the timer based on compare 1.
NRF_TIMER_SHORT_COMPARE2_CLEAR_MASK = TIMER_SHORTS_COMPARE2_CLEAR_Msk, ///< Shortcut for clearing the timer based on compare 2.
NRF_TIMER_SHORT_COMPARE3_CLEAR_MASK = TIMER_SHORTS_COMPARE3_CLEAR_Msk, ///< Shortcut for clearing the timer based on compare 3.
#ifdef NRF52
#ifdef NRF52_SERIES
NRF_TIMER_SHORT_COMPARE4_CLEAR_MASK = TIMER_SHORTS_COMPARE4_CLEAR_Msk, ///< Shortcut for clearing the timer based on compare 4.
NRF_TIMER_SHORT_COMPARE5_CLEAR_MASK = TIMER_SHORTS_COMPARE5_CLEAR_Msk, ///< Shortcut for clearing the timer based on compare 5.
#endif
Expand All @@ -141,7 +141,7 @@ typedef enum
{
NRF_TIMER_MODE_TIMER = TIMER_MODE_MODE_Timer, ///< Timer mode: timer.
NRF_TIMER_MODE_COUNTER = TIMER_MODE_MODE_Counter, ///< Timer mode: counter.
#ifdef NRF52
#ifdef NRF52_SERIES
NRF_TIMER_MODE_LOW_POWER_COUNTER = TIMER_MODE_MODE_LowPowerCounter, ///< Timer mode: low-power counter.
#endif
} nrf_timer_mode_t;
Expand Down Expand Up @@ -183,7 +183,7 @@ typedef enum
NRF_TIMER_CC_CHANNEL1, ///< Timer capture/compare channel 1.
NRF_TIMER_CC_CHANNEL2, ///< Timer capture/compare channel 2.
NRF_TIMER_CC_CHANNEL3, ///< Timer capture/compare channel 3.
#ifdef NRF52
#ifdef NRF52_SERIES
NRF_TIMER_CC_CHANNEL4, ///< Timer capture/compare channel 4.
NRF_TIMER_CC_CHANNEL5, ///< Timer capture/compare channel 5.
#endif
Expand All @@ -198,7 +198,7 @@ typedef enum
NRF_TIMER_INT_COMPARE1_MASK = TIMER_INTENSET_COMPARE1_Msk, ///< Timer interrupt from compare event on channel 1.
NRF_TIMER_INT_COMPARE2_MASK = TIMER_INTENSET_COMPARE2_Msk, ///< Timer interrupt from compare event on channel 2.
NRF_TIMER_INT_COMPARE3_MASK = TIMER_INTENSET_COMPARE3_Msk, ///< Timer interrupt from compare event on channel 3.
#ifdef NRF52
#ifdef NRF52_SERIES
NRF_TIMER_INT_COMPARE4_MASK = TIMER_INTENSET_COMPARE4_Msk, ///< Timer interrupt from compare event on channel 4.
NRF_TIMER_INT_COMPARE5_MASK = TIMER_INTENSET_COMPARE5_Msk, ///< Timer interrupt from compare event on channel 5.
#endif
Expand Down Expand Up @@ -582,4 +582,4 @@ __STATIC_INLINE uint32_t nrf_timer_ms_to_ticks(uint32_t time_ms,
#endif // NRF_TIMER_H__

/** @} */
#endif // NRF52
#endif // NRF52_SERIES
18 changes: 17 additions & 1 deletion platformio.ini
Original file line number Diff line number Diff line change
@@ -1,13 +1,28 @@
[platformio]
default_envs =
alora_isp4520
wiscore_rak4631
adafruit-nrf52
wroveresp32
redesp32
featheresp32-1
featheresp32-2
featheresp32-3
featheresp32-4
featheresp32-4

[env:wiscore_rak4631]
platform = nordicnrf52
board = wiscore_rak4631
framework = arduino
; upload_port = COM8
build_flags =
-DCFG_DEBUG=0
-DSW_VERSION=1.0
-DMYLOG_LOG_LEVEL=MYLOG_LOG_LEVEL_DEBUG
-DADAFRUIT=1
lib_deps =
SX126x-Arduino
extra_scripts = pre:post_rename.nrf.py

[env:alora_isp4520]
platform = circuitrocks
Expand All @@ -18,6 +33,7 @@ build_flags =
-DCFG_DEBUG=2
-DSW_VERSION=1.0
-DMYLOG_LOG_LEVEL=MYLOG_LOG_LEVEL_ERROR
-DISP4520=1
lib_deps =
SX126x-Arduino
extra_scripts = pre:post_rename.py
Expand Down
2 changes: 1 addition & 1 deletion src/BLE/ble_nrf52.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#ifdef NRF52
#ifdef NRF52_SERIES
#include "main.h"
#include <bluefruit.h>

Expand Down
10 changes: 8 additions & 2 deletions src/Mesh/lora.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ int RADIO_RXEN = -1;
#define LED_BUILTIN 16
#endif
#endif
#ifdef NRF52
#ifdef NRF52_SERIES
#ifdef ADAFRUIT
/** LORA RESET */
int PIN_LORA_RESET = 31;
Expand Down Expand Up @@ -98,7 +98,13 @@ static MeshEvents_t MeshEvents;
bool initLoRa(void)
{
bool initResult = true;
#if defined(ESP32) || defined(ADAFRUIT)
#if defined(_VARIANT_RAK4630_) // WisBlock RAK4631
if (lora_rak4630_init() != 0)
{
myLog_e("Error in hardware init");
initResult = false;
}
#elif 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
Expand Down
2 changes: 1 addition & 1 deletion src/Mesh/mesh.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ extern volatile xQueueHandle meshMsgQueue;
#define CAD_RETRY 20

// LoRa definitions
#define RF_FREQUENCY 910000000 // Hz
#define RF_FREQUENCY 916000000 // Hz
#define TX_OUTPUT_POWER 22 // dBm
#define LORA_BANDWIDTH 1 // [0: 125 kHz, 1: 250 kHz, 2: 500 kHz, 3: Reserved]
#define LORA_SPREADING_FACTOR 7 // [SF7..SF12]
Expand Down
19 changes: 16 additions & 3 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
#define LED_BUILTIN 16
#endif

#ifdef NRF52
#ifdef NRF52_SERIES
#if not defined ADAFRUIT
#undef LED_BUILTIN
#define LED_BUILTIN 22
Expand Down Expand Up @@ -65,7 +65,7 @@ void ledOff(void)
*/
void setup()
{
#ifdef NRF52
#ifdef ISP4520
pinMode(17, OUTPUT);
digitalWrite(17, HIGH);
#endif
Expand All @@ -78,7 +78,20 @@ void setup()

#ifdef ADAFRUIT
// The serial interface of the nRF52's seems to need some time before it is ready
delay(500);
time_t serial_timeout = millis();
// On nRF52840 the USB serial is not available immediately
while (!Serial)
{
if ((millis() - serial_timeout) < 5000)
{
delay(100);
digitalWrite(LED_BUILTIN, !digitalRead(LED_BUILTIN));
}
else
{
break;
}
}
#endif

// Create node ID
Expand Down
2 changes: 1 addition & 1 deletion src/main.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
#include <esp_wifi.h>
#include <Ticker.h>
#include <Log/my-log.h>
#elif defined(NRF52)
#elif defined(NRF52_SERIES)
#include <nrf.h>
#include "nrf_timer.h"
#include "nrf52Timer.h"
Expand Down

0 comments on commit fb0bd63

Please sign in to comment.