refact: ADC, switches and keys

Add "hardware_defs" target to dump hardware defines from hal.h per target

Fixed hal.h definitions for switches & ADC inputs

Tools to generate hardware definitions from current hal.h

generator: add support for EXTx and analog switches

WiP

Add generated header to hardware_defs target

Add support for ADC input direction and index per GPIO port

Incredible: it compiles

Removed StdPeriph ADC driver

Works on QX7

Works on TX16S (VBat missing)

Switch driver using generated switches for stm32 targets

Switch driver with generated switches for simu

Use switch names from switch driver

Fixed single conversion handling

Fixed horus VBat reading

Added switch name

Fix warnings about bitfield offsets and GCC 4.4

This is caused by bitfields that cross type boundaries. In this particular case, it happens as the bitfield is not defined the same in `rtc_backup.cpp`.

Switches has already been moved to generic driver

Jitter measurement for each sample, not just for oversampled values

Moved periph clock init to the ADC driver

ADC & GPIOs.

Add switchInit() to init pins

Fix NV14 CMake

Fix taranis target

Fix NV14 (again)

Model audio files: use new interface for switch index

Fix X9-lite

Fix simu headers

Fix getSwitchName()

Add support for ADC switches

Fix switch warning YAML

Test only switches which are defined

Conversions tests for QX7 only on QX7

Fix X12S

Fix function switch names

Enable ADC periph clock before initialising channels

NV14: offset inputs for the sticks & fix switches

WiP: get rid of VSRCRAW and some more

Simu shall use normal ADC driver

fix x7

fix nv14

Fix 9x nav

fix 212x64

fix xlite

fix x9e

fix simu lib

fix unit tests

fix x7 tests

PWM stick values should be written directly into adcValues

... just like FlySky sticks.

fix x12s

fix nv14

Add some support for SPI ADC (only unit tests)

Remove `jq` usage

fix generate_yaml.py for newer libclang

fix pot config

fix stick names

Some YAML generator improvements

Max 16 Pots on COLORLCD

Fix some source names

Use 10 bits for switches to prevent overflow

Removed horus constants for switches & ADC inputs

Fix unit tests

Fix curve edit

Fix libsimulator

Fix function switches (tpro)

Refine ADC & analog API

Moved hardware definitions scripts and templates into own dir

cleanup API refine

Fix unit tests

Mixer: apply calibration only on required inputs

Place ADC switches after all other ADC inputs

Fix X12S

Remove useless TR_POTS_VSRCRAW, TR_SW_VSRCRAW, and TR_VSRCRAW

Cleanup redundant generated YAML parsers

Fixes Boxer rebase

Add boxer to generate-hw-defs.sh

Obsolete LUA exports

Add boxer ADC_DIRECTION

Split generate_hw_defs.py into multiple files

Some cleanup (+ LUA switches)

Fix AXIS definitions

Fixed translation strings declarations

Some rebase fixes

Remove some useless StdPeriph drivers

fix: set pin mode to reset state on usart deinit

fix: use canonical names for calibration data

fix: ADC driver does not care about unconfigured inputs

fix X12S ADC

Add support for ADC conversion chaining

Better X12S ADC implem

Moved X12S ADC driver to HAL/LL

Improve ADC driver separation

Fixed taranis & nv14

Moved PWM gimbals to HAL/LL

Removed useless TR_EXTRA_VSRCRAW

Fixed include guards

Small fixes

Renamed control inputs

Moved internal and external module pulse driver def to boards

Move more things to the generic_stm32 board

Remove STR_VMIXTRIMS

Added analog labels

Generate main control names

Misuse labels / short labels for main controls

Backward compatibility: sliders and legacy names

New keys driver

Let's get rid of StdPeriph headers in simu

Add jinja2 to CI workflows

Use `grep` instead of `sed`

chore: add python jinja2 oto msys setup script

Removed more static definitions and use dynamic ones instead

Fixes X9E

Fix x7 nav too

212 switch display

Fix default sliders

Removed NUM_STICKS

212 switch display working nicely

Surface radio 'stick' replacements

fix: switch, trim & rotary pin init

Remove old key drivers

Removed VKEYS

Removed ETX_FOURCC

Fixed SURFACE_NAME

Removed TR_VSWITCHES & TR_TRIMS_SWITCHES

Fix xpot switches

Store calibrated analogs in physical order

Use getSourceString in drawSource

Implement missing YAML read/write

Fix isSourceAvailableInInputs()

Fix isSourceAvailable()

Some surface fixes

Fix CLI debug

Ported colour UI of analog diagnostics to new ADC API

Small fixes

Better input mapping

Minor tpro fixes

Fix trims available

Remove TX mode choice on surface radio

Rename surface controls

Channel order alignement

Fix throttle warning

Fix checkTrims()

Fix pot config casting issue

Fix IS_SWITCH_FS()

Fixed input mapping

Fix fswitch auto-switch

Fixed storing / reading function switches in YAML

Fix enableVBatBridge() / disableVBatBridge()

Fix interesting mode conversion

Fix sources issues

Fix special funnction list

Proper function switch handling

128 GUI improvements

Fix compilation

Boxer cosmetics

128 hardware screen cosmetic

Fix TX12 switches

More switches fixes

Simplify CPU type handling

Fix flash size

Fixed page-up / page-down in libopenui
This commit is contained in:
Raphael Coeffic
2023-06-25 14:32:39 +02:00
committed by Malte Langermann
parent b6dd3a0ef8
commit 2b100e0eb5
323 changed files with 12812 additions and 22301 deletions
+15 -1
View File
@@ -11,6 +11,8 @@ set(SIMU_DRIVERS
simufatfs.cpp
simudisk.cpp
simulcd.cpp
switch_driver.cpp
adc_driver.cpp
module_drivers.cpp
led_driver.cpp
backlight_driver.cpp
@@ -18,6 +20,19 @@ set(SIMU_DRIVERS
bt_driver.cpp
)
set(HW_DESC_JSON ${FLAVOUR}.json)
AddHardwareDefTarget(${HW_DESC_JSON})
AddHWGenTarget(${HW_DESC_JSON} simu_keys simu_keys.inc)
AddHWGenTarget(${HW_DESC_JSON} simu_switches simu_switches.inc)
AddHWGenTarget(${HW_DESC_JSON} hal_adc_inputs hal_adc_inputs.inc)
set(SIMU_DRIVERS ${SIMU_DRIVERS}
${CMAKE_CURRENT_BINARY_DIR}/simu_keys.inc
${CMAKE_CURRENT_BINARY_DIR}/simu_switches.inc
${CMAKE_CURRENT_BINARY_DIR}/hal_adc_inputs.inc
${CMAKE_CURRENT_BINARY_DIR}/${HW_DESC_JSON}
)
include_directories(${CMAKE_CURRENT_BINARY_DIR})
if(SDL2_FOUND)
include_directories(${SDL2_INCLUDE_DIRS})
@@ -156,7 +171,6 @@ endif()
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${WARNING_FLAGS}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${WARNING_FLAGS}")
use_cxx11() # ensure gnu++11 in CXX_FLAGS with CMake < 3.1
if(FOX_FOUND)
add_executable(simu WIN32
+67
View File
@@ -0,0 +1,67 @@
/*
* 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/adc_driver.h"
#include "definitions.h"
#include "myeeprom.h"
#include "translations.h"
#include "hal_adc_inputs.inc"
#include "board.h"
void enableVBatBridge(){}
void disableVBatBridge(){}
bool isVBatBridgeEnabled(){ return false; }
extern uint16_t simu_get_analog(uint8_t idx);
static bool simu_start_conversion()
{
int max_input = adcGetInputOffset(ADC_INPUT_VBAT);
for (int i = 0; i < max_input; i++) {
setAnalogValue(i, simu_get_analog(i));
}
// set VBAT / RTC_BAT
if (adcGetMaxInputs(ADC_INPUT_VBAT) > 0) {
uint32_t vbat = (BATTERY_MAX + BATTERY_MIN) / 2;
vbat = (vbat * BATTERY_DIVIDER) / 100;
setAnalogValue(adcGetInputOffset(ADC_INPUT_VBAT), vbat * 2);
}
if (adcGetMaxInputs(ADC_INPUT_RTC_BAT) > 0) {
uint32_t rtc_bat = (300 * (2048 >> ANALOG_SCALE)) / ADC_VREF_PREC2;
setAnalogValue(adcGetInputOffset(ADC_INPUT_RTC_BAT), rtc_bat * 2);
}
return true;
}
extern const etx_hal_adc_driver_t simu_adc_driver;
const etx_hal_adc_driver_t simu_adc_driver = {
.inputs = _hal_inputs,
.default_pots_cfg = _pot_default_config,
.init = nullptr,
.start_conversion = simu_start_conversion,
.wait_completion = nullptr,
};
+1
View File
@@ -28,3 +28,4 @@ void ledBlue() {}
void ledOff() {}
void fsLedOn(uint8_t) {}
void fsLedOff(uint8_t) {}
bool getFSLedState(uint8_t) { return false;}
+21 -26
View File
@@ -22,6 +22,10 @@
#include "opentxsimulator.h"
#include "opentx.h"
#include "simulcd.h"
#include "switches.h"
#include "hal/adc_driver.h"
#include "hal/rotary_encoder.h"
#include <QDebug>
#include <QElapsedTimer>
@@ -34,7 +38,7 @@
#define ETXS_DBG qDebug() << "(" << simuTimerMicros() << "us)"
int16_t g_anas[Analogs::NUM_ANALOGS];
int16_t g_anas[MAX_ANALOG_INPUTS];
QVector<QIODevice *> OpenTxSimulator::tracebackDevices;
#if defined(HARDWARE_TOUCH)
@@ -44,14 +48,9 @@ QVector<QIODevice *> OpenTxSimulator::tracebackDevices;
#define TAP_TIME 25
#endif
uint16_t anaIn(uint8_t chan)
uint16_t simu_get_analog(uint8_t idx)
{
return g_anas[chan];
}
uint16_t getAnalogValue(uint8_t index)
{
return anaIn(index);
return g_anas[idx];
}
void firmwareTraceCb(const char * text)
@@ -123,9 +122,10 @@ void OpenTxSimulator::init()
QMutexLocker lckr(&m_mtxSimuMain);
memset(g_anas, 0, sizeof(g_anas));
#if defined(PCBTARANIS)
g_anas[TX_RTC_VOLTAGE] = 800; // 2,34V
#endif
if (adcGetMaxInputs(ADC_INPUT_RTC_BAT) > 0) {
auto idx = adcGetInputOffset(ADC_INPUT_RTC_BAT);
setAnalogValue(idx, 800);
}
simuInit();
}
@@ -221,9 +221,7 @@ void OpenTxSimulator::setTrimSwitch(uint8_t trim, bool state)
void OpenTxSimulator::setTrim(unsigned int idx, int value)
{
unsigned i = idx;
if (i < 4) // swap axes
i = modn12x3[4 * getStickMode() + idx];
unsigned i = inputMappingConvertMode(idx);
uint8_t phase = getTrimFlightMode(getFlightMode(), i);
setTrimValue(phase, i, value);
}
@@ -245,13 +243,14 @@ void OpenTxSimulator::setInputValue(int type, uint8_t index, int16_t value)
setAnalogValue(index, value);
break;
case INPUT_SRC_KNOB :
setAnalogValue(index + NUM_STICKS, value);
break;
case INPUT_SRC_SLIDER :
setAnalogValue(index + NUM_STICKS + NUM_POTS, value);
setAnalogValue(index + adcGetInputOffset(ADC_INPUT_POT), value);
break;
case INPUT_SRC_TXVIN :
setAnalogValue(Analogs::TX_VOLTAGE, voltageToAdc(value));
if (adcGetMaxInputs(ADC_INPUT_VBAT) > 0) {
auto idx = adcGetInputOffset(ADC_INPUT_VBAT);
setAnalogValue(idx, voltageToAdc(value));
}
break;
case INPUT_SRC_SWITCH :
setSwitch(index, (int8_t)value);
@@ -274,6 +273,7 @@ void OpenTxSimulator::setInputValue(int type, uint8_t index, int16_t value)
}
}
extern volatile rotenc_t rotencValue;
extern volatile uint32_t rotencDt;
void OpenTxSimulator::rotaryEncoderEvent(int steps)
@@ -282,7 +282,7 @@ void OpenTxSimulator::rotaryEncoderEvent(int steps)
static uint32_t last_tick = 0;
if (steps != 0) {
if (g_eeGeneral.rotEncMode >= ROTARY_ENCODER_MODE_INVERT_BOTH) steps *= -1;
ROTARY_ENCODER_NAVIGATION_VALUE += steps * ROTARY_ENCODER_GRANULARITY;
rotencValue += steps * ROTARY_ENCODER_GRANULARITY;
// TODO: set rotencDt
uint32_t now = RTOS_GET_MS();
uint32_t dt = now - last_tick;
@@ -548,7 +548,6 @@ void OpenTxSimulator::checkOutputsChanged()
qint32 tmpVal;
uint8_t i, idx;
const uint8_t phase = getFlightMode(); // opentx.cpp
const uint8_t mode = getStickMode();
for (i=0; i < chansDim; i++) {
if (lastOutputs.chans[i] != channelOutputs[i] || m_resetOutputsData) {
@@ -564,7 +563,7 @@ void OpenTxSimulator::checkOutputsChanged()
}
for (i=0; i < MAX_LOGICAL_SWITCHES; i++) {
tmpVal = (qint32)GET_SWITCH_BOOL(SWSRC_SW1+i);
tmpVal = (qint32)GET_SWITCH_BOOL(SWSRC_FIRST_LOGICAL_SWITCH+i);
if (lastOutputs.vsw[i] != (bool)tmpVal || m_resetOutputsData) {
emit virtualSwValueChange(i, tmpVal);
emit outputValueChange(OUTPUT_SRC_VIRTUAL_SW, i, tmpVal);
@@ -573,11 +572,7 @@ void OpenTxSimulator::checkOutputsChanged()
}
for (i=0; i < Board::TRIM_AXIS_COUNT; i++) {
if (i < 4) // swap axes
idx = modn12x3[4 * mode + i];
else
idx = i;
idx = inputMappingConvertMode(i);
tmpVal = getTrimValue(getTrimFlightMode(phase, idx), idx);
if (lastOutputs.trims[i] != tmpVal || m_resetOutputsData) {
emit trimValueChange(i, tmpVal);
+34 -114
View File
@@ -28,6 +28,9 @@
#include "opentx.h"
#include "simulcd.h"
#include "hal/adc_driver.h"
#include "hal/rotary_encoder.h"
#include <errno.h>
#include <stdarg.h>
#include <string>
@@ -45,16 +48,20 @@ char * main_thread_error = nullptr;
bool simu_shutdown = false;
bool simu_running = false;
uint32_t telemetryErrors = 0;
typedef int32_t rotenc_t;
volatile rotenc_t rotencValue = 0;
volatile uint32_t rotencDt = 0;
rotenc_t rotaryEncoderGetValue()
{
return rotencValue / ROTARY_ENCODER_GRANULARITY;
}
rotenc_t rotaryEncoderGetRawValue() { return rotencValue; }
// TODO: remove all STM32 defs
GPIO_TypeDef gpioa, gpiob, gpioc, gpiod, gpioe, gpiof, gpiog, gpioh, gpioi, gpioj;
ADC_Common_TypeDef adc;
RTC_TypeDef rtc;
extern const etx_hal_adc_driver_t simu_adc_driver;
void lcdCopy(void * dest, void * src);
@@ -114,9 +121,12 @@ void simuInit()
#if defined(ROTARY_ENCODER_NAVIGATION)
rotencValue = 0;
#endif
// Init ADC driver callback
adcInit(&simu_adc_driver);
}
bool keysStates[NUM_KEYS] = { false };
bool keysStates[MAX_KEYS] = { false };
void simuSetKey(uint8_t key, bool state)
{
// TRACE("simuSetKey(%d, %d)", key, state);
@@ -124,7 +134,7 @@ void simuSetKey(uint8_t key, bool state)
keysStates[key] = state;
}
bool trimsStates[NUM_TRIMS_KEYS] = { false };
bool trimsStates[MAX_TRIMS * 2] = { false };
void simuSetTrim(uint8_t trim, bool state)
{
// TRACE("simuSetTrim(%d, %d)", trim, state);
@@ -132,14 +142,6 @@ void simuSetTrim(uint8_t trim, bool state)
trimsStates[trim] = state;
}
int8_t switchesStates[NUM_SWITCHES] = { -1 };
void simuSetSwitch(uint8_t swtch, int8_t state)
{
// TRACE("simuSetSwitch(%d, %d)", swtch, state);
assert(swtch < DIM(switchesStates));
switchesStates[swtch] = state;
}
#if defined(SIMU_BOOTLOADER)
int bootloaderMain();
static void* bootloaderThread(void*)
@@ -206,9 +208,9 @@ void simuStart(bool tests, const char * sdPath, const char * settingsPath)
try {
#endif
// Init LCD call backs
// Init LCD callbacks
lcdInit();
#if !defined(SIMU_BOOTLOADER)
simuMain();
#else
@@ -421,86 +423,28 @@ void lcdSetRefVolt(uint8_t val)
}
#endif
void telemetryPortInit(uint8_t baudrate)
{
}
void telemetryPortInit()
{
}
void sportUpdatePowerOn()
{
}
void sportUpdatePowerOff()
{
}
void sportUpdatePowerInit()
{
}
void telemetryPortSetDirectionInput()
{
}
void telemetryPortSetDirectionOutput()
{
}
void rxPdcUsart( void (*pChProcess)(uint8_t x) )
{
}
void telemetryPortInit(uint32_t baudrate, uint8_t mode)
{
}
bool sportGetByte(uint8_t * byte)
{
return false;
}
void telemetryClearFifo()
{
}
void telemetryPortInvertedInit(uint32_t baudrate)
{
}
void sportSendByte(uint8_t byte)
{
}
void sportSendBuffer(const uint8_t * buffer, uint32_t count)
{
}
void check_telemetry_exti()
{
}
void boardInit()
{
}
uint32_t pwrCheck() { return simu_shutdown ? e_power_off : e_power_on; }
bool pwrPressed() { return false; }
bool pwrOffPressed()
{
#if defined(PWR_BUTTON_PRESS)
return pwrPressed();
#else
return !pwrPressed();
#endif
}
void pwrInit() {}
void pwrOn() {}
void pwrOff() {}
bool keyDown()
{
return readKeys();
}
bool trimDown(uint8_t idx)
{
return readTrims() & (1 << idx);
}
bool UNEXPECTED_SHUTDOWN() { return false; }
void SET_POWER_REASON(uint32_t value) {}
#if defined(TRIMS_EMULATE_BUTTONS)
bool trimsAsButtons = false;
@@ -521,7 +465,7 @@ uint32_t readKeys()
{
uint32_t result = 0;
for (int i = 0; i < NUM_KEYS; i++) {
for (int i = 0; i < MAX_KEYS; i++) {
if (keysStates[i]) {
// TRACE("key pressed %d", i);
result |= 1 << i;
@@ -535,7 +479,7 @@ uint32_t readTrims()
{
uint32_t result = 0;
for (int i=0; i<NUM_TRIMS_KEYS; i++) {
for (int i = 0; i < MAX_TRIMS; i++) {
if (trimsStates[i]) {
// TRACE("trim pressed %d", i);
result |= 1 << i;
@@ -543,27 +487,13 @@ uint32_t readTrims()
}
#if defined(PCBXLITE)
if (IS_SHIFT_PRESSED())
if (keysStates[KEY_SHIFT])
result = ((result & 0x03) << 6) | ((result & 0x0c) << 2);
#endif
return result;
}
uint32_t switchState(uint8_t index)
{
div_t qr = div(index, 3);
int state = switchesStates[qr.quot];
switch (qr.rem) {
case 0:
return state < 0;
case 2:
return state > 0;
default:
return state == 0;
}
}
int usbPlugged() { return false; }
int getSelectedUsbMode() { return USB_JOYSTICK_MODE; }
void setSelectedUsbMode(int mode) {}
@@ -599,16 +529,6 @@ void serialPrintf(const char * format, ...) { }
void serialCrlf() { }
void serialPutc(char c) { }
uint16_t getBatteryVoltage()
{
return (g_eeGeneral.vBatWarn * 10) + 50; // 0.5 volt above alerm (value is PREC1)
}
uint16_t getRTCBatteryVoltage()
{
return 300;
}
void boardOff()
{
}
+2 -174
View File
@@ -22,176 +22,20 @@
#ifndef _SIMPGMSPACE_H_
#define _SIMPGMSPACE_H_
#ifndef __GNUC__
#include <windows.h>
#include <intrin.h>
#define sleep(x) Sleep(x)
#define strcasecmp _stricmp
#define strncasecmp _tcsnicmp
#define chdir _chdir
#define getcwd _getcwd
inline int __builtin_clz(unsigned x)
{
return (int)__lzcnt(x);
}
#else
#include <unistd.h>
#define sleep(x) usleep(1000*x)
#endif
#ifdef SIMU_EXCEPTIONS
extern char * main_thread_error;
#include <stdlib.h>
#include <stdio.h>
#include <signal.h>
#if defined(_MSC_VER) || !defined(__GNUC__)
#define write_backtrace(output)
#else
#include <execinfo.h>
inline void write_backtrace(char *output)
{
void *buf[16];
char **s;
int n = backtrace(buf, 16);
s = backtrace_symbols(buf, n);
if (s) {
for (int i=0; i<n; ++i) {
sprintf(output+strlen(output), "%02i: %s\n", i, s[i]);
}
}
}
#endif
void sig(int sgn)
{
main_thread_error = (char *)malloc(2048);
sprintf(main_thread_error,"Signal %d caught\n", sgn);
write_backtrace(main_thread_error);
throw std::exception();
}
#define assert(x) do { if (!(x)) { main_thread_error = (char *)malloc(2048); sprintf(main_thread_error, "Assert failed, %s:%d: %s\n", __FILE__, __LINE__, #x); write_backtrace(main_thread_error); throw std::exception(); } } while(0)
#else
#include <assert.h>
#endif
#include <inttypes.h>
#include <stdio.h>
#include <stddef.h>
#include <errno.h>
#undef min
#undef max
#define __REV
extern GPIO_TypeDef gpioa, gpiob, gpioc, gpiod, gpioe, gpiof, gpiog, gpioh, gpioi, gpioj;
extern TIM_TypeDef tim1, tim2, tim3, tim4, tim5, tim6, tim7, tim8, tim9, tim10;
extern USART_TypeDef Usart0, Usart1, Usart2, Usart3, Usart4;
extern RCC_TypeDef rcc;
extern DMA_Stream_TypeDef dma1_stream0, dma1_stream1, dma1_stream2, dma1_stream3, dma1_stream4, dma1_stream5, dma1_stream6, dma1_stream7, dma2_stream1, dma2_stream2, dma2_stream5, dma2_stream6, dma2_stream7;
extern DMA_TypeDef dma2;
extern SysTick_Type systick;
extern ADC_Common_TypeDef adc;
extern RTC_TypeDef rtc;
#undef SysTick
#define SysTick (&systick)
#undef GPIOA
#undef GPIOB
#undef GPIOC
#undef GPIOD
#undef GPIOE
#undef GPIOF
#undef GPIOG
#undef GPIOH
#undef GPIOI
#undef GPIOJ
#define GPIOA (&gpioa)
#define GPIOB (&gpiob)
#define GPIOC (&gpioc)
#define GPIOD (&gpiod)
#define GPIOE (&gpioe)
#define GPIOF (&gpiof)
#define GPIOG (&gpiog)
#define GPIOH (&gpioh)
#define GPIOI (&gpioi)
#define GPIOJ (&gpioj)
#undef TIM1
#undef TIM2
#undef TIM3
#undef TIM4
#undef TIM5
#undef TIM6
#undef TIM7
#undef TIM8
#undef TIM9
#undef TIM10
#define TIM1 (&tim1)
#define TIM2 (&tim2)
#define TIM3 (&tim3)
#define TIM4 (&tim4)
#define TIM5 (&tim4)
#define TIM6 (&tim4)
#define TIM7 (&tim4)
#define TIM8 (&tim8)
#define TIM9 (&tim9)
#define TIM10 (&tim10)
#undef USART0
#undef USART1
#undef USART2
#undef USART3
#define USART0 (&Usart0)
#define USART1 (&Usart1)
#define USART2 (&Usart2)
#define USART3 (&Usart3)
#undef RCC
#define RCC (&rcc)
#undef DMA1_Stream0
#undef DMA1_Stream1
#undef DMA1_Stream2
#undef DMA1_Stream3
#undef DMA1_Stream4
#undef DMA1_Stream5
#undef DMA1_Stream7
#undef DMA2_Stream1
#undef DMA2_Stream2
#undef DMA2_Stream5
#undef DMA2_Stream6
#undef DMA2_Stream7
#define DMA1_Stream0 (&dma1_stream0)
#define DMA1_Stream1 (&dma1_stream1)
#define DMA1_Stream2 (&dma1_stream2)
#define DMA1_Stream3 (&dma1_stream3)
#define DMA1_Stream4 (&dma1_stream4)
#define DMA1_Stream5 (&dma1_stream5)
#define DMA1_Stream7 (&dma1_stream7)
#define DMA2_Stream1 (&dma2_stream1)
#define DMA2_Stream2 (&dma2_stream2)
#define DMA2_Stream5 (&dma2_stream5)
#define DMA2_Stream6 (&dma2_stream6)
#define DMA2_Stream7 (&dma2_stream7)
#undef DMA2
#define DMA2 (&dma2)
#undef ADC
#define ADC (&adc)
#undef RTC
#define RTC (&rtc)
// #undef min
// #undef max
extern uint8_t * eeprom;
extern void startPdcUsartReceive() ;
extern uint32_t txPdcUsart( uint8_t *buffer, uint32_t size );
extern uint32_t txPdcPending();
extern void rxPdcUsart( void (*pChProcess)(uint8_t x) );
#define ISR(x, ...) void x()
#if !defined(_MSC_VER) && defined(__GNUC__)
#define asm(...)
#endif
extern uint32_t Master_frequency;
#define NVIC_EnableIRQ(x)
#define NVIC_DisableIRQ(x)
#define NVIC_SetPriority(...)
#define NVIC_SystemReset() exit(0)
#define __disable_irq()
#define __enable_irq()
@@ -200,7 +44,6 @@ extern char * main_thread_error;
#define OPENTX_START_DEFAULT_ARGS simu_start_mode
inline void getADC() { }
uint64_t simuTimerMicros(void);
uint8_t simuSleep(uint32_t ms); // returns true if thread shutdown requested
@@ -228,21 +71,6 @@ void stopEepromThread();
void simuMain();
#define UART_Stop(...)
#define UART3_Stop(...)
#define USART_GetITStatus(...) 0
#define USART_ClearFlag(...)
#define TIM_DeInit(...)
#define TIM_SetCompare2(...)
#define TIM_ClearFlag(...)
#define TIM_Cmd(...)
#define TIM_ITConfig(...)
#define GPIO_SetBits(GPIOx, pin) GPIOx->BSRRL |= pin
#define GPIO_ResetBits(GPIOx, pin) GPIOx->BSRRL &= ~pin
#define GPIO_ReadInputDataBit(GPIOx, pin) (GPIOx->BSRRL & pin)
#define RCC_AHB1PeriphClockCmd(...)
#define RCC_APB2PeriphClockCmd(...)
// inline void delay_01us(uint32_t dummy) { }
+3
View File
@@ -289,9 +289,12 @@ void DMACopyAlphaMask(uint16_t *dest, uint16_t destw, uint16_t desth,
}
}
#define DMA2D_ARGB4444 ((uint32_t)0x00000004)
void DMABitmapConvert(uint16_t *dest, const uint8_t *src, uint16_t w,
uint16_t h, uint32_t format)
{
if (format == DMA2D_ARGB4444) {
for (int row = 0; row < h; ++row) {
for (int col = 0; col < w; ++col) {
+129
View File
@@ -0,0 +1,129 @@
/*
* 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/switch_driver.h"
#include "definitions.h"
#include "myeeprom.h"
#include <stdlib.h>
#include <assert.h>
struct hw_switch_def {
const char* name;
SwitchHwType type;
};
#include "simu_switches.inc"
int8_t switchesStates[n_total_switches] = { -1 };
void simuSetSwitch(uint8_t swtch, int8_t state)
{
assert(swtch < n_total_switches);
switchesStates[swtch] = state;
}
swconfig_t switchGetDefaultConfig()
{
return _switch_default_config;
}
switch_display_pos_t switchGetDisplayPosition(uint8_t idx)
{
if (idx >= DIM(_switch_display))
return {0, 0};
return _switch_display[idx];
}
uint8_t switchGetMaxSwitches()
{
return n_switches;
}
uint8_t getSwitchCount()
{
int count = 0;
for (int i = 0; i < switchGetMaxSwitches(); ++i) {
if (SWITCH_EXISTS(i)) {
++count;
}
}
return count;
}
uint8_t switchGetMaxRow(uint8_t col)
{
uint8_t lastrow = 0;
for (int i = 0; i < switchGetMaxSwitches(); ++i) {
if (SWITCH_EXISTS(i)) {
auto switch_display = switchGetDisplayPosition(i);
if (switch_display.col == col)
lastrow = switch_display.row > lastrow ? switch_display.row : lastrow;
}
}
return lastrow;
}
uint8_t switchGetMaxFctSwitches()
{
return n_fct_switches;
}
const char* switchGetName(uint8_t idx)
{
assert(idx < n_total_switches);
return _hw_switch_defs[idx].name;
}
SwitchHwType switchGetHwType(uint8_t idx)
{
assert(idx < n_total_switches);
return _hw_switch_defs[idx].type;
}
uint32_t switchState(uint8_t pos)
{
assert(pos < n_total_switches * 3);
div_t qr = div(pos, 3);
int state = switchesStates[qr.quot];
switch (qr.rem) {
case SWITCH_HW_UP:
return state < 0;
case SWITCH_HW_DOWN:
return state > 0;
default:
return state == 0;
}
}
SwitchHwPos switchGetPosition(uint8_t idx)
{
assert(idx < n_total_switches);
if (switchesStates[idx] < 0)
return SWITCH_HW_UP;
else if (switchesStates[idx] == 0)
return SWITCH_HW_MID;
else
return SWITCH_HW_DOWN;
}