Nrf5 improvements (#938)
* Fix NRF5_ESB_readMessage, allways enable radio
* NRF5: fixes and improvements
- Compiles with arduino core for nRF52 (primo)
MY_RADIO_NRF5_ESB stays unsupported with primo!
- Split ACK negation flag into
MY_NRF5_ESB_REVERSE_ACK_TX
MY_NRF5_ESB_REVERSE_ACK_RX
- MY_RADIO_NRF5_ESB changes to act more than NRF24
- MY_RADIO_NRF5_ESB better support for powerdown/standby
- Moved initialization from MyMainNRF5 to hwInit()
This commit is contained in:
@@ -66,6 +66,25 @@ void hwWriteConfig(int adr, uint8_t value)
|
||||
|
||||
bool hwInit()
|
||||
{
|
||||
// Clock is manged by sleep modes. Radio depends on HFCLK.
|
||||
// Force to start HFCLK
|
||||
NRF_CLOCK->EVENTS_HFCLKSTARTED = 0;
|
||||
NRF_CLOCK->TASKS_HFCLKSTART = 1;
|
||||
while (NRF_CLOCK->EVENTS_HFCLKSTARTED == 0)
|
||||
;
|
||||
|
||||
// Enable low latency sleep mode
|
||||
NRF_POWER->TASKS_CONSTLAT = 1;
|
||||
|
||||
// Enable cache on >= NRF52
|
||||
#ifndef NRF51
|
||||
NRF_NVMC->ICACHECNF = NVMC_ICACHECNF_CACHEEN_Msk;
|
||||
#endif
|
||||
|
||||
// Suspend UART
|
||||
NRF_UART0->TASKS_STOPRX = 1;
|
||||
NRF_UART0->TASKS_STOPTX = 1;
|
||||
NRF_UART0->TASKS_SUSPEND = 1;
|
||||
|
||||
#ifdef MY_DISABLED_SERIAL
|
||||
// Disable UART, when not configured
|
||||
@@ -471,7 +490,13 @@ uint16_t hwCPUVoltage()
|
||||
|
||||
uint16_t hwCPUFrequency()
|
||||
{
|
||||
return F_CPU / 100000UL;
|
||||
#if defined(VARIANT_MCK)
|
||||
return (VARIANT_MCK) / 100000UL;
|
||||
#elif defined(F_CPU)
|
||||
return (F_CPU) / 100000UL;
|
||||
#else
|
||||
return 16;
|
||||
#endif
|
||||
}
|
||||
|
||||
uint16_t hwFreeMem()
|
||||
|
||||
@@ -29,12 +29,17 @@
|
||||
#endif
|
||||
|
||||
// Define NRF5_SOFTDEVICE when SoftDevice found
|
||||
#if defined(S110) || defined(S130) || defined(S132)
|
||||
#ifndef NRF5_SOFTDEVICE
|
||||
#define NRF5_SOFTDEVICE
|
||||
#if defined(S110) || defined(S130) || defined(S132) || defined(S140)
|
||||
#ifndef SOFTDEVICE_PRESENT
|
||||
#define SOFTDEVICE_PRESENT
|
||||
#endif
|
||||
#endif
|
||||
|
||||
// Define ARDUINO_ARCH_NRF5, if not defined
|
||||
#ifndef ARDUINO_ARCH_NRF5
|
||||
#define ARDUINO_ARCH_NRF5
|
||||
#endif
|
||||
|
||||
#include "drivers/NRF5/nrf5_wiring_digital.c"
|
||||
#include "drivers/NRF5/wdt.h"
|
||||
#include "drivers/NVM/NVRAM.h"
|
||||
@@ -42,8 +47,19 @@
|
||||
#include <avr/dtostrf.h>
|
||||
#include <nrf.h>
|
||||
|
||||
// mapping
|
||||
#ifndef strncpy_P
|
||||
#define strncpy_P strncpy
|
||||
#endif
|
||||
#ifndef snprintf_P
|
||||
#define snprintf_P(s, f, ...) snprintf((s), (f), __VA_ARGS__)
|
||||
#endif
|
||||
#ifndef vsnprintf_P
|
||||
#define vsnprintf_P vsnprintf
|
||||
#endif
|
||||
#ifndef printf_P
|
||||
#define printf_P printf
|
||||
#endif
|
||||
|
||||
#define MIN(a,b) min(a,b)
|
||||
#define MAX(a,b) max(a,b)
|
||||
@@ -139,4 +155,4 @@ typedef struct {
|
||||
#define MY_CRITICAL_SECTION
|
||||
#endif /* DOXYGEN || CPPCHECK */
|
||||
|
||||
#endif // #ifdef ARDUINO_ARCH_NRF5
|
||||
#endif // #ifndef MyHwNRF5_h
|
||||
|
||||
@@ -1,69 +0,0 @@
|
||||
/**
|
||||
* The MySensors Arduino library handles the wireless radio link and protocol
|
||||
* between your home built sensors/actuators and HA controller of choice.
|
||||
* The sensors forms a self healing radio network with optional repeaters. Each
|
||||
* repeater and gateway builds a routing tables in EEPROM which keeps track of
|
||||
* the
|
||||
* network topology allowing messages to be routed to nodes.
|
||||
*
|
||||
* Created by Henrik Ekblad <henrik.ekblad@mysensors.org>
|
||||
* Copyright (C) 2013-2017 Sensnology AB
|
||||
* Full contributor list:
|
||||
* https://github.com/mysensors/Arduino/graphs/contributors
|
||||
*
|
||||
* Documentation: http://www.mysensors.org
|
||||
* Support Forum: http://forum.mysensors.org
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or
|
||||
* modify it under the terms of the GNU General Public License
|
||||
* version 2 as published by the Free Software Foundation.
|
||||
*/
|
||||
|
||||
// Initialize library and handle sketch functions like we want to
|
||||
|
||||
extern "C" void __libc_init_array(void);
|
||||
|
||||
// Weak empty variant initialization function.
|
||||
// May be redefined by variant files.
|
||||
void initVariant() __attribute__((weak));
|
||||
void initVariant() {}
|
||||
|
||||
int main(void)
|
||||
{
|
||||
// Suspend UART
|
||||
NRF_UART0->TASKS_STOPRX = 1;
|
||||
NRF_UART0->TASKS_STOPTX = 1;
|
||||
NRF_UART0->TASKS_SUSPEND = 1;
|
||||
|
||||
// Clock is manged by sleep modes. Radio depends on HFCLK.
|
||||
// Force to start HFCLK
|
||||
NRF_CLOCK->EVENTS_HFCLKSTARTED = 0;
|
||||
NRF_CLOCK->TASKS_HFCLKSTART = 1;
|
||||
while (NRF_CLOCK->EVENTS_HFCLKSTARTED == 0)
|
||||
;
|
||||
|
||||
// Enable low latency sleep mode
|
||||
NRF_POWER->TASKS_CONSTLAT = 1;
|
||||
|
||||
// Enable cache on >= NRF52
|
||||
#ifndef NRF51
|
||||
NRF_NVMC->ICACHECNF = NVMC_ICACHECNF_CACHEEN_Msk;
|
||||
#endif
|
||||
|
||||
init();
|
||||
initVariant(); // arduino-nRF5 specific
|
||||
delay(1);
|
||||
|
||||
_begin(); // Startup MySensors library
|
||||
|
||||
for (;;) {
|
||||
_process(); // Process incoming data
|
||||
if (loop) {
|
||||
loop(); // Call sketch loop
|
||||
}
|
||||
if (serialEventRun) {
|
||||
serialEventRun();
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user