Skip to content

Commit

Permalink
AP_Radio: tidy AP_Radio includes
Browse files Browse the repository at this point in the history
  • Loading branch information
peterbarker committed Feb 1, 2024
1 parent e494386 commit 50cc18b
Show file tree
Hide file tree
Showing 12 changed files with 87 additions and 37 deletions.
25 changes: 11 additions & 14 deletions libraries/AP_Radio/AP_Radio.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#include <AP_HAL/AP_HAL.h>
#include "AP_Radio_config.h"

#if AP_RADIO_ENABLED

#if HAL_RCINPUT_WITH_AP_RADIO
#include <AP_HAL/AP_HAL.h>

#include "AP_Radio.h"
#include "AP_Radio_backend.h"
Expand Down Expand Up @@ -151,40 +153,36 @@ AP_Radio::AP_Radio(void)
bool AP_Radio::init(void)
{
switch (radio_type) {
#if (not defined AP_RADIO_CYRF6936 || AP_RADIO_CYRF6936)
#if AP_RADIO_CYRF6936_ENABLED
case RADIO_TYPE_CYRF6936:
driver = new AP_Radio_cypress(*this);
break;
#endif
#if CONFIG_HAL_BOARD == HAL_BOARD_CHIBIOS
#if (not defined AP_RADIO_CC2500 || AP_RADIO_CC2500)
#if AP_RADIO_CC2500_ENABLED
case RADIO_TYPE_CC2500:
driver = new AP_Radio_cc2500(*this);
break;
#endif
#endif
#if CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_CHIBIOS_SKYVIPER_F412
#if (not defined AP_RADIO_BK2425 || AP_RADIO_BK2425)
#if AP_RADIO_BK2425_ENABLED
case RADIO_TYPE_BK2425:
driver = new AP_Radio_beken(*this);
break;
#endif
#endif
#if CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_CHIBIOS_SKYVIPER_F412
case RADIO_TYPE_AUTO:
// auto-detect between cc2500 and beken radios
#if (not defined AP_RADIO_CC2500 || AP_RADIO_CC2500)
#if AP_RADIO_CC2500_ENABLED
if (AP_Radio_cc2500::probe()) {
driver = new AP_Radio_cc2500(*this);
}
#endif
#if (not defined AP_RADIO_BK2425 || AP_RADIO_BK2425)
#if AP_RADIO_BK2425_ENABLED
if (driver == nullptr) {
driver = new AP_Radio_beken(*this);
}
#endif
break;
#endif
#endif // CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_CHIBIOS_SKYVIPER_F412
default:
break;
}
Expand Down Expand Up @@ -301,5 +299,4 @@ void AP_Radio::change_txmode(void)
}
}

#endif // HAL_RCINPUT_WITH_AP_RADIO

#endif // AP_RADIO_ENABLED
6 changes: 6 additions & 0 deletions libraries/AP_Radio/AP_Radio.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@
*/
#pragma once

#include "AP_Radio_config.h"

#if AP_RADIO_ENABLED

/*
* base class for direct attached radios
*/
Expand Down Expand Up @@ -128,3 +132,5 @@ class AP_Radio

static AP_Radio *_singleton;
};

#endif // AP_RADIO_ENABLED
6 changes: 6 additions & 0 deletions libraries/AP_Radio/AP_Radio_backend.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@
* backend class for direct attached radios
*/

#include "AP_Radio_config.h"

#if AP_RADIO_ENABLED

#include <AP_HAL/AP_HAL.h>
#include "AP_Radio_backend.h"

Expand All @@ -27,3 +31,5 @@ AP_Radio_backend::AP_Radio_backend(AP_Radio &_radio) :
AP_Radio_backend::~AP_Radio_backend(void)
{
}

#endif // AP_RADIO_ENABLED
6 changes: 6 additions & 0 deletions libraries/AP_Radio/AP_Radio_backend.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,10 @@
*/
#pragma once

#include "AP_Radio_config.h"

#if AP_RADIO_ENABLED

/*
* backend class for direct attached radios
*/
Expand Down Expand Up @@ -156,3 +160,5 @@ class AP_Radio_backend

AP_Radio &radio;
};

#endif // AP_RADIO_ENABLED
11 changes: 5 additions & 6 deletions libraries/AP_Radio/AP_Radio_bk2425.cpp
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
#include "AP_Radio_config.h"

#if AP_RADIO_BK2425_ENABLED

/*
driver for Beken_2425 radio
*/
#include <AP_HAL/AP_HAL.h>

//#pragma GCC optimize("O0")

#if defined(HAL_RCINPUT_WITH_AP_RADIO) && CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_CHIBIOS_SKYVIPER_F412

#include <AP_Math/AP_Math.h>
#include "AP_Radio_bk2425.h"
#include <utility>
Expand Down Expand Up @@ -1421,7 +1423,4 @@ void SyncAdaptive::Miss(uint8_t channel)
}
}



#endif // HAL_RCINPUT_WITH_AP_RADIO

#endif // AP_RADIO_BK2425_ENABLED
7 changes: 5 additions & 2 deletions libraries/AP_Radio/AP_Radio_bk2425.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,12 @@
With thanks to cleanflight and betaflight projects
*/

#include "AP_Radio_config.h"

#if AP_RADIO_BK2425_ENABLED

#include "AP_Radio_backend.h"

#if defined(HAL_RCINPUT_WITH_AP_RADIO) && CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_CHIBIOS_SKYVIPER_F412
#include "hal.h"
#include "telem_structure.h"
#include "driver_bk2425.h"
Expand Down Expand Up @@ -258,4 +261,4 @@ class AP_Radio_beken : public AP_Radio_backend
uint8_t myDroneId[4]; // CRC of the flight boards UUID, to inform the tx
};

#endif // HAL_RCINPUT_WITH_AP_RADIO
#endif // AP_RADIO_BK2425_ENABLED
9 changes: 6 additions & 3 deletions libraries/AP_Radio/AP_Radio_cc2500.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,12 @@
With thanks to cleanflight and betaflight projects
*/

#include "AP_Radio_config.h"

#if AP_RADIO_CC2500_ENABLED

#include "AP_Radio_backend.h"
#if CONFIG_HAL_BOARD == HAL_BOARD_CHIBIOS

#include "hal.h"
#include "telem_structure.h"
#include "driver_cc2500.h"
Expand Down Expand Up @@ -226,5 +230,4 @@ class AP_Radio_cc2500 : public AP_Radio_backend
};


#endif // CONFIG_HAL_BOARD == HAL_BOARD_CHIBIOS

#endif // AP_RADIO_CC2500_ENABLED
23 changes: 23 additions & 0 deletions libraries/AP_Radio/AP_Radio_config.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#pragma once

#include <AP_HAL/AP_HAL_Boards.h>

#ifndef AP_RADIO_ENABLED
#define AP_RADIO_ENABLED HAL_RCINPUT_WITH_AP_RADIO
#endif

#ifndef AP_RADIO_BACKEND_DEFAULT_ENABLED
#define AP_RADIO_BACKEND_DEFAULT_ENABLED AP_RADIO_ENABLED
#endif

#ifndef AP_RADIO_CC2500_ENABLED
#define AP_RADIO_CC2500_ENABLED AP_RADIO_BACKEND_DEFAULT_ENABLED
#endif

#ifndef AP_RADIO_CYRF6936_ENABLED
#define AP_RADIO_CYRF6936_ENABLED AP_RADIO_BACKEND_DEFAULT_ENABLED
#endif

#ifndef AP_RADIO_BK2425_ENABLED
#define AP_RADIO_BK2425_ENABLED AP_RADIO_BACKEND_DEFAULT_ENABLED
#endif
9 changes: 5 additions & 4 deletions libraries/AP_Radio/AP_Radio_cypress.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
#include <AP_HAL/AP_HAL.h>
#include "AP_Radio_config.h"

#if AP_RADIO_CYRF6936_ENABLED

#if HAL_RCINPUT_WITH_AP_RADIO
#include <AP_HAL/AP_HAL.h>

#include <AP_Math/AP_Math.h>
#include "AP_Radio_cypress.h"
Expand Down Expand Up @@ -1681,5 +1683,4 @@ void AP_Radio_cypress::handle_data_packet(mavlink_channel_t chan, const mavlink_
}
}

#endif // HAL_RCINPUT_WITH_AP_RADIO

#endif // AP_RADIO_CYRF6936_ENABLED
6 changes: 4 additions & 2 deletions libraries/AP_Radio/AP_Radio_cypress.h
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@
*/
#pragma once

#if HAL_RCINPUT_WITH_AP_RADIO
#include "AP_Radio_config.h"

#if AP_RADIO_CYRF6936_ENABLED

/*
AP_Radio implementation for Cypress 2.4GHz radio.
Expand Down Expand Up @@ -279,4 +281,4 @@ class AP_Radio_cypress : public AP_Radio_backend
void setup_timeout(uint32_t timeout_ms);
};

#endif
#endif // AP_RADIO_CYRPRESS_ENABLED
8 changes: 5 additions & 3 deletions libraries/AP_Radio/driver_bk2425.cpp
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
#include "AP_Radio_config.h"

#if AP_RADIO_BK2425_ENABLED

// --------------------------------------------------------------------
// low level driver for the beken radio on SPI
// --------------------------------------------------------------------

#include "driver_bk2425.h"

#if defined(HAL_RCINPUT_WITH_AP_RADIO) && CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_CHIBIOS_SKYVIPER_F412

#include <utility>
#include <AP_HAL_ChibiOS/AP_HAL_ChibiOS.h>
using namespace ChibiOS;
Expand Down Expand Up @@ -722,4 +724,4 @@ void Radio_Beken::DumpRegisters(void)
SetRBank(0);
}

#endif // HAL_RCINPUT_WITH_AP_RADIO
#endif // AP_RADIO_BK2425_ENABLED
8 changes: 5 additions & 3 deletions libraries/AP_Radio/driver_bk2425.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,11 @@

#pragma once

#include <AP_HAL/AP_HAL.h>
#include "AP_Radio_config.h"

#if AP_RADIO_BK2425_ENABLED

#if defined(HAL_RCINPUT_WITH_AP_RADIO) && CONFIG_HAL_BOARD_SUBTYPE == HAL_BOARD_SUBTYPE_CHIBIOS_SKYVIPER_F412
#include <AP_HAL/AP_HAL.h>

#define SUPPORT_BK_DEBUG_PINS 0 // 0=UART6 is for GPS, 1=UART6 is debug gpio
#define TX_SPEED 250u // Default transmit speed in kilobits per second.
Expand Down Expand Up @@ -414,4 +416,4 @@ class Radio_Beken
BkRadioMode bkMode;
};

#endif
#endif // AP_RADIO_BK2425_ENABLED

0 comments on commit 50cc18b

Please sign in to comment.