Files
edgetx-gx12/radio/src/targets/simu/module_drivers.cpp
T
Raphael CoefficandGitHub 72193eda82 chore: New module/serial API (#3055)
* WiP: new module interface

* WiP: softserial timer DMA

* WiP: setup() and send() in one step

and remove methods specific to internal or external module

* fixes and extra port config

* horus targets

* module ports have moved

* T8 support (only internal module)

* fix nv14

* stupid GCC....

* disable BT

* remove nv14 telem driver

* remove old aux serial driver

* Move module buffers out of pulses.h

* Soft serial fixes and PXX1 support

* Fixed PPM module output

* Fixed CLI

* compilation fixes

* Ported bluetooth and flysky gimbal to new serial driver

* Re-enable soft-serial RX

* fixes and cleanup

* nv14 fixes

* Fix flysky gimbals

* Ghost module

* 16 bytes of RAM

* Remove getByte from module API

* Ghost cleanup

* fix: _half_duplex_input() must be called after usart init

* WiP

* more cleanup

* Remove board specific settings from PXX1 / PXX2 drivers

* A bit of PXX2 header cleanup

* Add support for OVER8 and ONEBIT

* Add some support for inverters (NV14 / EL18)

* Support NV14 power fixes in generic board

* Fix polarity handling

* Fix RX DMA

* Fix mixer not running

* Add soft-serial polarity control

* Quick fix for telemetry polling while module port is changed

* Fix bootloader DEBUG

* Fix MPM telemetry

* Fix pulse start

* DSM2 soft-serial fallback

* DSMP async module restart

* Fix CRSF LUA upstream

* Remove global variable telemetryProtocol

* Use HAL/LL constants

* Fix various issue with AFHDS3 and NV14/EL18 internal module

* Fixed S.PORT unit tests

* fix: update widx after writing at current index

* fix: init error condition

* Fix: possible infinite loop in _find_port()

* Add support for bidir S.PORT init

* Add support for "getLastByte" in HW serial driver

* PXX1: Add support for S.PORT based on IDLE callback

* Fix rebase error

* Fix softserial _rx_fifo_push()

* Add softserial support for waitForTxCompleted()

* Fix MPM flashing (internal / external)

* Fixed external MPM

* Activate RX DMA on internal module

Seems to work with serial passthrough without issues, at least on the L3R PRO.

* Fix softserial DMA on stdlcd F4 targets

* Add softserial support for 32bit timers (mostly TIM2)

* More precise soft-serial

* Fix MPM update using inverters & HW uart

* Raise S.PORT DMA/USART IRQ prio to achieve faster switching to input

* Remove useless delays

* Fix flashing external ELRS module

* Added a retry mechanism for FrSky S.PORT update

* Remove useless enableRx()

* External FrSky modules are all flashed via S.PORT

* Remove power management unit update

This was only used on the first batch of X-lite.
2023-02-09 19:44:32 +10:00

225 lines
5.9 KiB
C++

/*
* 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.
*/
#include "hal.h"
#include "hal/serial_driver.h"
#include "hal/module_port.h"
#include "dataconstants.h"
void intmoduleStop() {}
void intmoduleFifoError() {}
void intmoduleFifoReceive(uint8_t){}
void intmodulePxx1PulsesStart() {}
void intmoduleSendNextFramePxx1(unsigned short const*, unsigned char) {}
void extmoduleStop() {}
void extmoduleFifoError() {}
void extmoduleFifoReceive(uint8_t){}
void extmodulePpmStart(unsigned short, bool) {}
void extmoduleSerialStart() {}
void extmodulePxx1PulsesStart() {}
void extmoduleInitTxPin() {}
void extmoduleSendInvertedByte(uint8_t) {}
void extmoduleSendNextFramePxx1(void const*, unsigned short) {}
void extmoduleSendNextFrameSoftSerial(void const*, unsigned short, bool) {}
void extmoduleSendNextFramePpm(void*, unsigned short, unsigned short, bool) {}
void init_trainer_ppm() {}
void stop_trainer_ppm() {}
void init_trainer_capture() {}
void stop_trainer_capture() {}
bool is_trainer_connected() { return false; }
void init_trainer_module_cppm() {}
void stop_trainer_module_cppm() {}
void init_trainer_module_sbus() {}
void stop_trainer_module_sbus() {}
void init_intmodule_heartbeat() {}
void stop_intmodule_heartbeat() {}
static void* init(void*, const etx_serial_init*) { return (void*)1; }
static void deinit(void*) {}
static void sendByte(void*, uint8_t) {}
static void sendBuffer(void*, const uint8_t*, uint32_t) {}
static void waitForTxCompleted(void*) {}
static int getByte(void*,uint8_t*) { return -1; }
const etx_serial_driver_t _fakeSerialDriver = {
.init = init,
.deinit = deinit,
.sendByte = sendByte,
.sendBuffer = sendBuffer,
.txCompleted = nullptr,
.waitForTxCompleted = waitForTxCompleted,
.enableRx = nullptr,
.getByte = getByte,
.getLastByte = nullptr,
.clearRxBuffer = nullptr,
.getBaudrate = nullptr,
.setBaudrate = nullptr,
.setPolarity = nullptr,
.setHWOption = nullptr,
.setReceiveCb = nullptr,
.setIdleCb = nullptr,
.setBaudrateCb = nullptr,
};
static void* module_timer_init(void* hw_def, const etx_timer_config_t* cfg)
{ return (void*)1; }
static void module_timer_deinit(void* ctx) {}
static void module_timer_send(void* ctx, const etx_timer_config_t* cfg,
const void* pulses, uint16_t length)
{}
const etx_timer_driver_t _fakeTimerDriver = {
.init = module_timer_init,
.deinit = module_timer_deinit,
.send = module_timer_send,
};
#if defined(HARDWARE_INTERNAL_MODULE)
const etx_module_port_t _internal_ports[] = {
#if defined(INTMODULE_USART)
{
.port = ETX_MOD_PORT_UART,
.type = ETX_MOD_TYPE_SERIAL,
.dir_flags = ETX_MOD_DIR_TX_RX | ETX_MOD_FULL_DUPLEX,
.drv = { .serial = &_fakeSerialDriver },
.hw_def = nullptr,
},
#else // INTMODULE_USART
{
.port = ETX_MOD_PORT_SOFT_INV,
.type = ETX_MOD_TYPE_SERIAL,
.dir_flags = ETX_MOD_DIR_TX,
.drv = { .timer = &_fakeTimerDriver },
.hw_def = nullptr,
},
#endif
#if defined(INTERNAL_MODULE_PXX1)
{
.port = ETX_MOD_PORT_SPORT,
.type = ETX_MOD_TYPE_SERIAL,
.dir_flags = ETX_MOD_DIR_TX | ETX_MOD_DIR_RX,
.drv = { .serial = &_fakeSerialDriver },
.hw_def = nullptr,
},
#endif
};
static const etx_module_t _internal_module = {
.ports = _internal_ports,
.set_pwr = nullptr,
.set_bootcmd = nullptr,
.n_ports = DIM(_internal_ports),
};
#endif
#if defined(SPORT_UPDATE_PWR_GPIO)
void _sport_set_pwr(uint8_t) {}
const etx_module_t _sport_module = {
.ports = nullptr,
.set_pwr = _sport_set_pwr,
.set_bootcmd = nullptr,
.n_ports = 0,
};
#endif
#if defined(HARDWARE_EXTERNAL_MODULE)
const etx_module_port_t _external_ports[] = {
#if defined(EXTMODULE_USART)
// TX on PPM, RX on HEARTBEAT
{
.port = ETX_MOD_PORT_UART,
.type = ETX_MOD_TYPE_SERIAL,
.dir_flags = ETX_MOD_DIR_TX_RX | ETX_MOD_FULL_DUPLEX,
.drv = { .serial = &_fakeSerialDriver },
.hw_def = nullptr,
},
#endif
// Timer output on PPM
{
.port = ETX_MOD_PORT_TIMER,
.type = ETX_MOD_TYPE_TIMER,
.dir_flags = ETX_MOD_DIR_TX,
.drv = { .timer = &_fakeTimerDriver },
.hw_def = nullptr,
},
// TX inverted DMA pulse train on S.PORT
{
.port = ETX_MOD_PORT_SOFT_INV,
.type = ETX_MOD_TYPE_SERIAL,
.dir_flags = ETX_MOD_DIR_TX,
.drv = { .serial = &_fakeSerialDriver },
.hw_def = nullptr,
},
// TX/RX half-duplex on S.PORT
{
.port = ETX_MOD_PORT_SPORT,
.type = ETX_MOD_TYPE_SERIAL,
.dir_flags = ETX_MOD_DIR_TX | ETX_MOD_DIR_RX,
.drv = { .serial = &_fakeSerialDriver },
.hw_def = nullptr,
},
#if defined(TELEMETRY_TIMER)
// RX soft-serial sampled bit-by-bit via timer IRQ on S.PORT
{
.port = ETX_MOD_PORT_SPORT_INV,
.type = ETX_MOD_TYPE_SERIAL,
.dir_flags = ETX_MOD_DIR_RX,
.drv = { .serial = &_fakeSerialDriver },
.hw_def = nullptr,
},
#endif
};
static const etx_module_t _external_module = {
.ports = _external_ports,
.set_pwr = nullptr,
.set_bootcmd = nullptr,
.n_ports = DIM(_external_ports),
};
#endif
BEGIN_MODULES()
#if defined(HARDWARE_INTERNAL_MODULE)
&_internal_module,
#else
nullptr,
#endif
#if defined(HARDWARE_EXTERNAL_MODULE)
&_external_module,
#else
nullptr,
#endif
#if defined(SPORT_UPDATE_PWR_GPIO)
&_sport_module,
#endif
END_MODULES()