Skip to content

Commit

Permalink
WiP: get rid of VSRCRAW and some more
Browse files Browse the repository at this point in the history
  • Loading branch information
raphaelcoeffic committed Nov 19, 2022
1 parent bb8692d commit f0512f4
Show file tree
Hide file tree
Showing 135 changed files with 1,969 additions and 2,933 deletions.
5 changes: 4 additions & 1 deletion cmake/Macros.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,17 @@ function(GenerateDatacopy source output)
# Fetch defines / include directories in use
AddCompilerFlags(GEN_DATACOPY_ARGS)

# Hack to get rid of warnings in StdPeriph lib
set(GEN_DATACOPY_ARGS ${GEN_DATACOPY_ARGS} -Wno-asm-operand-widths)

set(GEN_DATACOPY_ARGS
# source file MUST be the first argument
${CMAKE_CURRENT_SOURCE_DIR}/${source}
-DBACKUP ${GEN_DATACOPY_ARGS} ${SYSROOT_ARG})

set(GEN_DATACOPY_CMD
${PYTHON_EXECUTABLE} ${GEN_DATACOPY} ${GEN_DATACOPY_ARGS})

add_custom_command(
OUTPUT ${output}
COMMAND ${GEN_DATACOPY_CMD} > ${output}
Expand Down
4 changes: 4 additions & 0 deletions cmake/toolchain/native.cmake
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
# Native toolchain

if(APPLE)
set(CMAKE_C_FLAGS "-Wno-asm-operand-widths -Wno-deprecated-declarations")
set(CMAKE_CXX_FLAGS "-Wno-asm-operand-widths -Wno-deprecated-declarations")
endif()
3 changes: 2 additions & 1 deletion radio/src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -200,7 +200,7 @@ if(RTC_BACKUP_RAM)
)

# Add custom target for debugging
add_custom_target(datacopy DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/datacopy.cpp)
add_custom_target(datacopy DEPENDS ${CMAKE_CURRENT_BINARY_DIR}/datacopy.inc)
endif()

if(LUA)
Expand Down Expand Up @@ -482,6 +482,7 @@ set(SRC
functions.cpp
strhelpers.cpp
switches.cpp
analogs.cpp
mixer.cpp
mixer_scheduler.cpp
stamp.cpp
Expand Down
76 changes: 76 additions & 0 deletions radio/src/analogs.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/*
* 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 "analogs.h"
#include "dataconstants.h"
#include "opentx_helpers.h"

#include "hal/adc_driver.h"

static char _stickNames[MAX_STICKS][LEN_ANA_NAME + 1] = { 0 };
static char _potNames[MAX_STICKS][LEN_ANA_NAME + 1] = { 0 };

void analogSetCustomStickName(uint8_t idx, const char* str, size_t len)
{
strncpy(_stickNames[idx], str, min<size_t>(LEN_ANA_NAME, len));
_stickNames[idx][LEN_ANA_NAME] = '\0';
}

const char* analogGetCustomStickName(uint8_t idx)
{
return _stickNames[idx];
}

bool analogHasCustomStickName(uint8_t idx)
{
return *analogGetCustomStickName(idx) != 0;
}

void analogSetCustomPotName(uint8_t idx, const char* str, size_t len)
{
strncpy(_potNames[idx], str, min<size_t>(LEN_ANA_NAME, len));
_potNames[idx][LEN_ANA_NAME] = '\0';
}

const char* analogGetCustomPotName(uint8_t idx)
{
return _potNames[idx];
}

bool analogHasCustomPotName(uint8_t idx)
{
return *analogGetCustomPotName(idx) != 0;
}

int analogLookupPotIdx(const char* name, size_t len)
{
for (uint8_t i = 0; i < adcGetMaxPots(); i++) {
if (!strncmp(adcGetPotName(i), name, len)) return i;
}

return -1;
}

const char* analogGetCanonicalPotName(uint8_t idx)
{
return adcGetPotName(idx);
}

36 changes: 36 additions & 0 deletions radio/src/analogs.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* 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 <stddef.h>
#include <stdint.h>

void analogSetCustomStickName(uint8_t idx, const char* str, size_t len);
const char* analogGetCustomStickName(uint8_t idx);
bool analogHasCustomStickName(uint8_t idx);

void analogSetCustomPotName(uint8_t idx, const char* str, size_t len);
const char* analogGetCustomPotName(uint8_t idx);
bool analogHasCustomPotName(uint8_t idx);

int analogLookupPotIdx(const char* name, size_t len);
const char* analogGetCanonicalPotName(uint8_t idx);
16 changes: 9 additions & 7 deletions radio/src/audio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -242,9 +242,12 @@ const char * const audioFilenames[] = {
"timovr3"
};

constexpr unsigned int MAX_SWITCH_POSITIONS =
MAX_SWITCHES * 3 + MAX_POTS * XPOTS_MULTIPOS_COUNT;

BitField<(AU_SPECIAL_SOUND_FIRST)> sdAvailableSystemAudioFiles;
BitField<(MAX_FLIGHT_MODES * 2/*on, off*/)> sdAvailableFlightmodeAudioFiles;
BitField<(SWSRC_LAST_SWITCH+NUM_XPOTS*XPOTS_MULTIPOS_COUNT)> sdAvailableSwitchAudioFiles;
BitField<MAX_SWITCH_POSITIONS> sdAvailableSwitchAudioFiles;
BitField<(MAX_LOGICAL_SWITCHES * 2/*on, off*/)> sdAvailableLogicalSwitchAudioFiles;

char * getAudioPath(char * path)
Expand Down Expand Up @@ -331,22 +334,21 @@ void getSwitchAudioFile(char * filename, swsrc_t index)
{
char * str = getModelAudioPath(filename);

if (index <= SWSRC_LAST_SWITCH) {
if (index <= MAX_SWITCHES * 3) {
div_t swinfo = switchInfo(index);
*str++ = 'S';
*str++ = switchGetLetter(swinfo.quot);
const char * positions[] = { "-up", "-mid", "-down" };
strcpy(str, positions[swinfo.rem]);
}
#if NUM_XPOTS > 0
else {
div_t swinfo = div(int(index - SWSRC_FIRST_MULTIPOS_SWITCH), XPOTS_MULTIPOS_COUNT);
index -= MAX_SWITCHES * 3;
div_t swinfo = div((int)index, XPOTS_MULTIPOS_COUNT);
*str++ = 'S';
*str++ = '1' + swinfo.quot;
*str++ = '1' + swinfo.rem;
*str = '\0';
}
#endif
strcat(str, SOUNDS_EXT);
}

Expand Down Expand Up @@ -408,11 +410,11 @@ void referenceModelAudioFiles()
}

// Switches Audio Files <switchname>-[up|mid|down].wav
for (int i=SWSRC_FIRST_SWITCH; i<=SWSRC_LAST_SWITCH+NUM_XPOTS*XPOTS_MULTIPOS_COUNT && !found; i++) {
for (int i = 0; i <= MAX_SWITCH_POSITIONS && !found; i++) {
getSwitchAudioFile(path, i);
// TRACE("referenceModelAudioFiles(): searching for %s in %s (%d)", path, fno.fname, i);
if (!strcasecmp(filename, fno.fname)) {
sdAvailableSwitchAudioFiles.setBit(i-SWSRC_FIRST_SWITCH);
sdAvailableSwitchAudioFiles.setBit(i);
found = true;
TRACE("\tfound: %s", filename);
}
Expand Down
6 changes: 3 additions & 3 deletions radio/src/audio.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,10 @@
Implements a bit field, number of bits is set by the template,
each bit can be modified and read by the provided methods.
*/
template <unsigned int NUM_BITS> class BitField {
template <unsigned int NUM_BITS> class BitField
{
private:
uint8_t bits[(NUM_BITS+7)/8];
uint8_t bits[(NUM_BITS + 7) / 8];
public:
BitField()
{
Expand All @@ -54,7 +55,6 @@ template <unsigned int NUM_BITS> class BitField {

bool getBit(unsigned int bitNo) const
{
// assert(bitNo < NUM_BITS);
if (bitNo >= NUM_BITS) return false;
return bits[bitNo >> 3] & (1 << (bitNo & 0x07));
}
Expand Down
12 changes: 7 additions & 5 deletions radio/src/cli.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1439,11 +1439,13 @@ int cliRepeat(const char ** argv)
int cliShowJitter(const char ** argv)
{
cliSerialPrint( "# anaIn rawJ avgJ");
for (int i=0; i<NUM_ANALOGS; i++) {
cliSerialPrint("A%02d %04X %04X %3d %3d", i, getAnalogValue(i), anaIn(i), rawJitter[i].get(), avgJitter[i].get());
if (IS_POT_MULTIPOS(i)) {
StepsCalibData * calib = (StepsCalibData *) &g_eeGeneral.calib[i];
for (int j=0; j<calib->count; j++) {
for (int i = 0; i < MAX_ANALOG_INPUTS; i++) {
cliSerialPrint("A%02d %04X %04X %3d %3d", i, getAnalogValue(i), anaIn(i),
rawJitter[i].get(), avgJitter[i].get());

if (i >= MAX_STICKS && IS_POT_MULTIPOS(i - MAX_STICKS)) {
StepsCalibData *calib = (StepsCalibData *)&g_eeGeneral.calib[i];
for (int j = 0; j < calib->count; j++) {
cliSerialPrint(" s%d %04X", j, calib->steps[j]);
}
}
Expand Down
Loading

0 comments on commit f0512f4

Please sign in to comment.