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
178 lines
5.8 KiB
C++
178 lines
5.8 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.
|
|
*/
|
|
|
|
#ifndef _STRHELPERS_H_
|
|
#define _STRHELPERS_H_
|
|
|
|
#include "definitions.h"
|
|
#include "opentx_types.h"
|
|
|
|
#include <string>
|
|
|
|
#include <string>
|
|
#include <cstring>
|
|
|
|
#define IS_UFT8_2BYTES(c) \
|
|
( (((uint8_t)c) & 0xE0) == 0xC0 )
|
|
|
|
#define IS_UTF8_3BYTES(c) \
|
|
( (((uint8_t)c) & 0xF0) == 0xE0 )
|
|
|
|
#define IS_UTF8(c) \
|
|
( IS_UFT8_2BYTES(c) || IS_UTF8_3BYTES(c) )
|
|
|
|
#define UTF8_WIDTH(c) \
|
|
( IS_UFT8_2BYTES(c) ? 2 : IS_UTF8_3BYTES(c) ? 3 : 1 )
|
|
|
|
|
|
#define SHOW_TIME 0x1
|
|
#define SHOW_TIMER 0x0
|
|
#define SHOW_TIMER_UPPER_CASE 0x2
|
|
#define SHOW_TIMER_HM_FORMAT 0x5
|
|
|
|
PACK(typedef struct {
|
|
uint8_t showTime:1;
|
|
uint8_t upperCase:1;
|
|
uint8_t numDigitGroups:3;
|
|
uint8_t hmFormat:1;
|
|
uint8_t reserved:2;
|
|
}) TimerDisplayOptions;
|
|
|
|
typedef union {
|
|
uint8_t options;
|
|
TimerDisplayOptions displayOptions;
|
|
} TimerOptions;
|
|
|
|
char hex2zchar(uint8_t hex);
|
|
char hex2char(uint8_t hex);
|
|
char zchar2char(int8_t idx);
|
|
char char2lower(char c);
|
|
int8_t char2zchar(char c);
|
|
void str2zchar(char *dest, const char *src, int size);
|
|
int zchar2str(char *dest, const char *src, int size);
|
|
int strnlen(const char *src, int max_size);
|
|
unsigned int effectiveLen(const char * str, unsigned int size);
|
|
|
|
char *strAppend(char *dest, const char *source, int len = 0);
|
|
char *strAppendUnsigned(char *dest, uint32_t value, uint8_t digits = 0,
|
|
uint8_t radix = 10);
|
|
char *strAppendSigned(char *dest, int32_t value, uint8_t digits = 0,
|
|
uint8_t radix = 10);
|
|
char *strSetCursor(char *dest, int position);
|
|
char *strAppendDate(char *str, bool time = false);
|
|
char *strAppendFilename(char *dest, const char *filename, const int size);
|
|
std::string formatNumberAsString(int32_t val, LcdFlags flags = 0, uint8_t len = 0, const char * prefix = nullptr, const char * suffix = nullptr);
|
|
|
|
#if !defined(BOOT)
|
|
char *getStringAtIndex(char *dest, const char *const *s, int idx);
|
|
char *strAppendStringWithIndex(char *dest, const char *s, int idx);
|
|
#define LEN_TIMER_STRING 10 // "-00:00:00"
|
|
char *getTimerString(char *dest, int32_t tme, TimerOptions timerOptions = {.options = 0});
|
|
char *getFormattedTimerString(char *dest, int32_t tme, TimerOptions timerOptions);
|
|
char *getCurveString(char *dest, int idx);
|
|
char *getGVarString(char *dest, int idx);
|
|
char *getGVarString(int idx);
|
|
char *getValueOrGVarString(char *dest, size_t len, gvar_t value, gvar_t vmin,
|
|
gvar_t vmax, LcdFlags flags = 0,
|
|
const char *suffix = nullptr, gvar_t offset = 0);
|
|
const char *getSwitchWarnSymbol(uint8_t pos);
|
|
const char *getSwitchPositionSymbol(uint8_t pos);
|
|
char *getSwitchPositionName(char *dest, swsrc_t idx);
|
|
char *getSwitchName(char *dest, uint8_t idx);
|
|
|
|
const char* getAnalogLabel(uint8_t type, uint8_t idx);
|
|
const char* getAnalogShortLabel(uint8_t idx);
|
|
const char* getMainControlLabel(uint8_t idx);
|
|
const char* getTrimLabel(uint8_t idx);
|
|
const char* getTrimSourceLabel(uint16_t src_raw, int8_t trim_src);
|
|
const char* getPotLabel(uint8_t idx);
|
|
|
|
template<size_t L>
|
|
char* getSourceString(char (&dest)[L], mixsrc_t idx);
|
|
|
|
template <size_t L>
|
|
char *getSourceCustomValueString(char (&dest)[L], source_t source, int32_t val,
|
|
LcdFlags flags);
|
|
|
|
#endif
|
|
|
|
char *getFlightModeString(char *dest, int8_t idx);
|
|
|
|
char *getSourceString(mixsrc_t idx);
|
|
char *getSourceCustomValueString(source_t source, int32_t val, LcdFlags flags);
|
|
char *getSwitchPositionName(swsrc_t idx);
|
|
char *getCurveString(int idx);
|
|
char *getTimerString(int32_t tme, TimerOptions timerOptions = {.options = 0});
|
|
void splitTimer(char *s0, char *s1, char *s2, char *s3, int tme,
|
|
bool bLowercase = true);
|
|
|
|
template<size_t N>
|
|
std::string stringFromNtString(const char (&a)[N]) {
|
|
return std::string(a, strnlen(a, N));
|
|
}
|
|
template<size_t L>
|
|
void copyToUnTerminated(char (&dest)[L], const char* const src) {
|
|
strncpy(dest, src, L);
|
|
}
|
|
template<size_t L>
|
|
void copyToUnTerminated(char (&dest)[L], const std::string& src) {
|
|
strncpy(dest, src.c_str(), L);
|
|
}
|
|
template<typename S>
|
|
void clearStruct(S& s) {
|
|
memset((void*) &s, 0, sizeof(S));
|
|
}
|
|
|
|
template <size_t N>
|
|
using offset_t = std::integral_constant<size_t, N>;
|
|
|
|
template <size_t DL, size_t SL, size_t O = 0>
|
|
void copyToTerminated(char (&dest)[DL], const char (&src)[SL],
|
|
const offset_t<O> = offset_t<0>{})
|
|
{
|
|
// unfortinately std::min() isn't constexpr in C++11
|
|
// static constexpr size_t len = std::min(DL - O - 1, SL);
|
|
static constexpr size_t dl{DL - O - 1};
|
|
static_assert(dl > 0, "wrong sizes or offset");
|
|
static constexpr size_t len = (dl < SL) ? dl : SL;
|
|
strncpy(&dest[O], &src[0], len);
|
|
static_assert((len + O) < DL, "wrong sizes of offset");
|
|
dest[len + O] = '\0';
|
|
}
|
|
|
|
template <size_t L1, size_t L2>
|
|
int strncasecmp(char (&s1)[L1], const char (&s2)[L2])
|
|
{
|
|
static constexpr size_t len = (L1 < L2) ? L1 : L2;
|
|
return strncasecmp(s1, s2, len);
|
|
}
|
|
|
|
template <size_t L1>
|
|
int strncasecmp(char (&s1)[L1], const char *const s2)
|
|
{
|
|
return strncasecmp(s1, s2, L1);
|
|
}
|
|
|
|
std::string getValueWithUnit(int val, uint8_t unit, LcdFlags flags);
|
|
std::string getGVarValue(uint8_t gvar, gvar_t value, LcdFlags flags);
|
|
|
|
#endif // _STRHELPERS_H_
|