diff --git a/radio/src/hal/adc_driver.cpp b/radio/src/hal/adc_driver.cpp index 01814b4da..6569f19ce 100644 --- a/radio/src/hal/adc_driver.cpp +++ b/radio/src/hal/adc_driver.cpp @@ -115,7 +115,7 @@ static bool adcSingleRead() return true; } -bool adcRead() +bool adcRead() __attribute__((weak)) { uint16_t temp[NUM_ANALOGS] = { 0 }; diff --git a/radio/src/hal/adc_driver.h b/radio/src/hal/adc_driver.h index c240b6e8f..3f7f02642 100644 --- a/radio/src/hal/adc_driver.h +++ b/radio/src/hal/adc_driver.h @@ -52,8 +52,10 @@ struct etx_hal_adc_driver_t { }; bool adcInit(const etx_hal_adc_driver_t* driver); -//void adcDeInit(); +// void adcDeInit(); + +// Declare adcRead() weak so it can be re-declared +bool adcRead() __attribute__((weak)); -bool adcRead(); uint16_t getRTCBatteryVoltage(); uint16_t getAnalogValue(uint8_t index); diff --git a/radio/src/targets/horus/board.cpp b/radio/src/targets/horus/board.cpp index f3d10e507..b215f753d 100644 --- a/radio/src/targets/horus/board.cpp +++ b/radio/src/targets/horus/board.cpp @@ -21,7 +21,14 @@ #include "opentx.h" #include "hal/adc_driver.h" -#include "../common/arm/stm32/stm32_hal_adc.h" + +#if !defined(PCBX12S) + #include "../common/arm/stm32/stm32_hal_adc.h" + #define ADC_DRIVER stm32_hal_adc_driver +#else + #include "x12_adc_driver.h" + #define ADC_DRIVER x12s_adc_driver +#endif #if defined(__cplusplus) extern "C" { @@ -200,7 +207,7 @@ void boardInit() } #endif - if (!adcInit(&stm32_hal_adc_driver)) + if (!adcInit(&ADC_DRIVER)) TRACE("adcInit failed"); lcdInit(); diff --git a/radio/src/targets/horus/x12s_adc_driver.cpp b/radio/src/targets/horus/x12s_adc_driver.cpp index b8127bddc..e4628cd96 100644 --- a/radio/src/targets/horus/x12s_adc_driver.cpp +++ b/radio/src/targets/horus/x12s_adc_driver.cpp @@ -100,7 +100,7 @@ static void ADS7952_Init() ADC_CS_HIGH(); } -void adcInit() +static bool x12s_adc_init() { ADS7952_Init(); @@ -227,6 +227,8 @@ bool adcOnChipReadFinished() return (ADC_DMA->LISR & DMA_LISR_TCIF0); } +// Re-declare adcRead() +// (takes precedence over hal/adc_driver.cpp) void adcRead() { uint16_t temp[NUM_ANALOGS-MOUSE1] = { 0 }; @@ -279,3 +281,14 @@ uint16_t getAnalogValue(uint8_t index) return adcValues[index]; } #endif // #if !defined(SIMU) + +//TODO: implement these based on stm32_hal_adc.cpp +//static bool x12s_adc_init(); +//static bool x12s_adc_start_read(); +//static void x12s_adc_wait_completion(); + +const etx_hal_adc_driver_t x12s_adc_driver = { + x12s_adc_init, + nullptr,//x12s_adc_start_read, + nullptr,//x12s_adc_wait_completion +}; diff --git a/radio/src/targets/horus/x12s_adc_driver.h b/radio/src/targets/horus/x12s_adc_driver.h new file mode 100644 index 000000000..7e8fc8c2c --- /dev/null +++ b/radio/src/targets/horus/x12s_adc_driver.h @@ -0,0 +1,26 @@ +/* + * Copyright (C) EdgeTx + * + * Based on code named + * opentx - https://github.com/opentx/opentx + * th9x - http://code.google.com/p/th9x + * er9x - http://code.google.com/p/er9x + * gruvin9x - http://code.google.com/p/gruvin9x + * + * License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html + * + * 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. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + */ + +#pragma once + +#include "hal/adc_driver.h" + +extern const etx_hal_adc_driver_t x12s_adc_driver;