mirror of
https://github.com/betaflight/betaflight.git
synced 2025-07-21 23:35:34 +03:00
Better split between RX SPI and RX NRF24L01 code
This commit is contained in:
parent
84059a78ff
commit
19a701a944
3 changed files with 32 additions and 35 deletions
|
@ -28,13 +28,15 @@
|
|||
|
||||
#include "build/build_config.h"
|
||||
|
||||
#include "system.h"
|
||||
#include "bus_spi.h"
|
||||
#include "io.h"
|
||||
#include "io_impl.h"
|
||||
#include "rx_spi.h"
|
||||
#include "rx_nrf24l01.h"
|
||||
#include "system.h"
|
||||
|
||||
#define NRF24_CE_HI() {IOHi(IOGetByTag(IO_TAG(RX_CE_PIN)));}
|
||||
#define NRF24_CE_LO() {IOLo(IOGetByTag(IO_TAG(RX_CE_PIN)));}
|
||||
#define NRF24_CE_HI() {IOHi(DEFIO_IO(RX_CE_PIN));}
|
||||
#define NRF24_CE_LO() {IOLo(DEFIO_IO(RX_CE_PIN));}
|
||||
|
||||
// Instruction Mnemonics
|
||||
// nRF24L01: Table 16. Command set for the nRF24L01 SPI. Product Specification, p46
|
||||
|
@ -52,6 +54,18 @@
|
|||
#define REUSE_TX_PL 0xE3
|
||||
#define NOP 0xFF
|
||||
|
||||
static void NRF24L01_InitGpio(void)
|
||||
{
|
||||
#if defined(STM32F10X)
|
||||
RCC_AHBPeriphClockCmd(RX_CE_GPIO_CLK_PERIPHERAL, ENABLE);
|
||||
#endif
|
||||
// CE as OUTPUT
|
||||
const SPIDevice rxSPIDevice = spiDeviceByInstance(RX_SPI_INSTANCE);
|
||||
IOInit(DEFIO_IO(RX_CE_PIN), OWNER_RX_SPI_CS, rxSPIDevice + 1);
|
||||
IOConfigGPIO(DEFIO_IO(RX_CE_PIN), SPI_IO_CS_CFG);
|
||||
NRF24_CE_LO();
|
||||
}
|
||||
|
||||
uint8_t NRF24L01_WriteReg(uint8_t reg, uint8_t data)
|
||||
{
|
||||
return rxSpiWriteCommand(W_REGISTER | (REGISTER_MASK & reg), data);
|
||||
|
@ -122,7 +136,7 @@ static uint8_t standbyConfig;
|
|||
void NRF24L01_Initialize(uint8_t baseConfig)
|
||||
{
|
||||
standbyConfig = BV(NRF24L01_00_CONFIG_PWR_UP) | baseConfig;
|
||||
NRF24_CE_LO();
|
||||
NRF24L01_InitGpio();
|
||||
// nRF24L01+ needs 100 milliseconds settling time from PowerOnReset to PowerDown mode
|
||||
static const uint32_t settlingTimeUs = 100000;
|
||||
const uint32_t currentTimeUs = micros();
|
||||
|
@ -208,8 +222,8 @@ bool NRF24L01_ReadPayloadIfAvailable(uint8_t *data, uint8_t length)
|
|||
}
|
||||
|
||||
#ifndef UNIT_TEST
|
||||
#define DISABLE_RX() {IOHi(IOGetByTag(IO_TAG(RX_NSS_PIN)));}
|
||||
#define ENABLE_RX() {IOLo(IOGetByTag(IO_TAG(RX_NSS_PIN)));}
|
||||
#define DISABLE_RX() {IOHi(DEFIO_IO(RX_NSS_PIN));}
|
||||
#define ENABLE_RX() {IOLo(DEFIO_IO(RX_NSS_PIN));}
|
||||
/*
|
||||
* Fast read of payload, for use in interrupt service routine
|
||||
*/
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue