mirror of
https://github.com/ttrftech/NanoVNA.git
synced 2025-12-06 03:31:59 +01:00
style: uniform code style and untabify
This commit is contained in:
parent
a4821604a5
commit
0d407577f8
156
.clang-format
Normal file
156
.clang-format
Normal file
|
|
@ -0,0 +1,156 @@
|
||||||
|
---
|
||||||
|
Language: Cpp
|
||||||
|
# BasedOnStyle: Google
|
||||||
|
AccessModifierOffset: -1
|
||||||
|
AlignAfterOpenBracket: Align
|
||||||
|
AlignConsecutiveAssignments: false
|
||||||
|
AlignConsecutiveDeclarations: false
|
||||||
|
AlignEscapedNewlines: Left
|
||||||
|
AlignOperands: true
|
||||||
|
AlignTrailingComments: true
|
||||||
|
AllowAllArgumentsOnNextLine: true
|
||||||
|
AllowAllConstructorInitializersOnNextLine: true
|
||||||
|
AllowAllParametersOfDeclarationOnNextLine: true
|
||||||
|
AllowShortBlocksOnASingleLine: false
|
||||||
|
AllowShortCaseLabelsOnASingleLine: false
|
||||||
|
AllowShortFunctionsOnASingleLine: All
|
||||||
|
AllowShortLambdasOnASingleLine: All
|
||||||
|
AllowShortIfStatementsOnASingleLine: WithoutElse
|
||||||
|
AllowShortLoopsOnASingleLine: true
|
||||||
|
AlwaysBreakAfterDefinitionReturnType: None
|
||||||
|
AlwaysBreakAfterReturnType: None
|
||||||
|
AlwaysBreakBeforeMultilineStrings: true
|
||||||
|
AlwaysBreakTemplateDeclarations: Yes
|
||||||
|
BinPackArguments: true
|
||||||
|
BinPackParameters: true
|
||||||
|
BraceWrapping:
|
||||||
|
AfterCaseLabel: false
|
||||||
|
AfterClass: true
|
||||||
|
AfterControlStatement: false
|
||||||
|
AfterEnum: false
|
||||||
|
AfterFunction: true
|
||||||
|
AfterNamespace: false
|
||||||
|
AfterObjCDeclaration: false
|
||||||
|
AfterStruct: false
|
||||||
|
AfterUnion: false
|
||||||
|
AfterExternBlock: false
|
||||||
|
BeforeCatch: false
|
||||||
|
BeforeElse: false
|
||||||
|
IndentBraces: false
|
||||||
|
SplitEmptyFunction: true
|
||||||
|
SplitEmptyRecord: true
|
||||||
|
SplitEmptyNamespace: true
|
||||||
|
BreakBeforeBinaryOperators: None
|
||||||
|
BreakBeforeBraces: Attach
|
||||||
|
BreakBeforeInheritanceComma: false
|
||||||
|
BreakInheritanceList: BeforeColon
|
||||||
|
BreakBeforeTernaryOperators: true
|
||||||
|
BreakConstructorInitializersBeforeComma: false
|
||||||
|
BreakConstructorInitializers: BeforeColon
|
||||||
|
BreakAfterJavaFieldAnnotations: false
|
||||||
|
BreakStringLiterals: true
|
||||||
|
ColumnLimit: 90
|
||||||
|
CommentPragmas: '^ IWYU pragma:'
|
||||||
|
CompactNamespaces: false
|
||||||
|
ConstructorInitializerAllOnOneLineOrOnePerLine: true
|
||||||
|
ConstructorInitializerIndentWidth: 4
|
||||||
|
ContinuationIndentWidth: 4
|
||||||
|
Cpp11BracedListStyle: true
|
||||||
|
DerivePointerAlignment: true
|
||||||
|
DisableFormat: false
|
||||||
|
ExperimentalAutoDetectBinPacking: false
|
||||||
|
FixNamespaceComments: true
|
||||||
|
ForEachMacros:
|
||||||
|
- foreach
|
||||||
|
- Q_FOREACH
|
||||||
|
- BOOST_FOREACH
|
||||||
|
IncludeBlocks: Regroup
|
||||||
|
IncludeCategories:
|
||||||
|
- Regex: '^<ext/.*\.h>'
|
||||||
|
Priority: 2
|
||||||
|
- Regex: '^<.*\.h>'
|
||||||
|
Priority: 1
|
||||||
|
- Regex: '^<.*'
|
||||||
|
Priority: 2
|
||||||
|
- Regex: '.*'
|
||||||
|
Priority: 3
|
||||||
|
IncludeIsMainRegex: '([-_](test|unittest))?$'
|
||||||
|
IndentCaseLabels: true
|
||||||
|
IndentPPDirectives: None
|
||||||
|
IndentWidth: 2
|
||||||
|
IndentWrappedFunctionNames: false
|
||||||
|
JavaScriptQuotes: Leave
|
||||||
|
JavaScriptWrapImports: true
|
||||||
|
KeepEmptyLinesAtTheStartOfBlocks: false
|
||||||
|
MacroBlockBegin: ''
|
||||||
|
MacroBlockEnd: ''
|
||||||
|
MaxEmptyLinesToKeep: 1
|
||||||
|
NamespaceIndentation: None
|
||||||
|
ObjCBinPackProtocolList: Never
|
||||||
|
ObjCBlockIndentWidth: 2
|
||||||
|
ObjCSpaceAfterProperty: false
|
||||||
|
ObjCSpaceBeforeProtocolList: true
|
||||||
|
PenaltyBreakAssignment: 2
|
||||||
|
PenaltyBreakBeforeFirstCallParameter: 1
|
||||||
|
PenaltyBreakComment: 300
|
||||||
|
PenaltyBreakFirstLessLess: 120
|
||||||
|
PenaltyBreakString: 1000
|
||||||
|
PenaltyBreakTemplateDeclaration: 10
|
||||||
|
PenaltyExcessCharacter: 1000000
|
||||||
|
PenaltyReturnTypeOnItsOwnLine: 200
|
||||||
|
PointerAlignment: Left
|
||||||
|
RawStringFormats:
|
||||||
|
- Language: Cpp
|
||||||
|
Delimiters:
|
||||||
|
- cc
|
||||||
|
- CC
|
||||||
|
- cpp
|
||||||
|
- Cpp
|
||||||
|
- CPP
|
||||||
|
- 'c++'
|
||||||
|
- 'C++'
|
||||||
|
CanonicalDelimiter: ''
|
||||||
|
BasedOnStyle: google
|
||||||
|
- Language: TextProto
|
||||||
|
Delimiters:
|
||||||
|
- pb
|
||||||
|
- PB
|
||||||
|
- proto
|
||||||
|
- PROTO
|
||||||
|
EnclosingFunctions:
|
||||||
|
- EqualsProto
|
||||||
|
- EquivToProto
|
||||||
|
- PARSE_PARTIAL_TEXT_PROTO
|
||||||
|
- PARSE_TEST_PROTO
|
||||||
|
- PARSE_TEXT_PROTO
|
||||||
|
- ParseTextOrDie
|
||||||
|
- ParseTextProtoOrDie
|
||||||
|
CanonicalDelimiter: ''
|
||||||
|
BasedOnStyle: google
|
||||||
|
ReflowComments: true
|
||||||
|
SortIncludes: true
|
||||||
|
SortUsingDeclarations: true
|
||||||
|
SpaceAfterCStyleCast: false
|
||||||
|
SpaceAfterLogicalNot: false
|
||||||
|
SpaceAfterTemplateKeyword: true
|
||||||
|
SpaceBeforeAssignmentOperators: true
|
||||||
|
SpaceBeforeCpp11BracedList: false
|
||||||
|
SpaceBeforeCtorInitializerColon: true
|
||||||
|
SpaceBeforeInheritanceColon: true
|
||||||
|
SpaceBeforeParens: ControlStatements
|
||||||
|
SpaceBeforeRangeBasedForLoopColon: true
|
||||||
|
SpaceInEmptyParentheses: false
|
||||||
|
SpacesBeforeTrailingComments: 2
|
||||||
|
SpacesInAngles: false
|
||||||
|
SpacesInContainerLiterals: true
|
||||||
|
SpacesInCStyleCastParentheses: false
|
||||||
|
SpacesInParentheses: false
|
||||||
|
SpacesInSquareBrackets: false
|
||||||
|
Standard: Auto
|
||||||
|
StatementMacros:
|
||||||
|
- Q_UNUSED
|
||||||
|
- QT_REQUIRE_VERSION
|
||||||
|
TabWidth: 4
|
||||||
|
UseTab: Never
|
||||||
|
...
|
||||||
|
|
||||||
3
.vscode/settings.json
vendored
3
.vscode/settings.json
vendored
|
|
@ -1,3 +1,4 @@
|
||||||
{
|
{
|
||||||
"C_Cpp.errorSquiggles": "Disabled"
|
"C_Cpp.errorSquiggles": "Disabled",
|
||||||
|
"cpplint.filters": ["-build/include_subdir", "-build/include_order", "-readability/casting", "-whitespace/comments"]
|
||||||
}
|
}
|
||||||
|
|
@ -9,10 +9,10 @@
|
||||||
* Check 1 byte of char bitmap data for get width
|
* Check 1 byte of char bitmap data for get width
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#define FONT_GET_DATA(ch) (&x5x7_bits[ch*7])
|
#define FONT_GET_DATA(ch) (&x5x7_bits[ch*7])
|
||||||
#define FONT_GET_WIDTH(ch) (8-x5x7_bits[ch*7]&7)
|
#define FONT_GET_WIDTH(ch) (8-x5x7_bits[ch*7]&7)
|
||||||
#define FONT_MAX_WIDTH 7
|
#define FONT_MAX_WIDTH 7
|
||||||
#define FONT_GET_HEIGHT 7
|
#define FONT_GET_HEIGHT 7
|
||||||
|
|
||||||
#define CHAR5x7_WIDTH_1px 0x07
|
#define CHAR5x7_WIDTH_1px 0x07
|
||||||
#define CHAR5x7_WIDTH_2px 0x06
|
#define CHAR5x7_WIDTH_2px 0x06
|
||||||
|
|
|
||||||
101
chprintf.c
101
chprintf.c
|
|
@ -49,17 +49,17 @@ static const uint32_t pow10[FLOAT_PRECISION+1] = {
|
||||||
};
|
};
|
||||||
// Prefixes for values bigger then 1000.0
|
// Prefixes for values bigger then 1000.0
|
||||||
// 1 1e3, 1e6, 1e9, 1e12, 1e15, 1e18, 1e21, 1e24
|
// 1 1e3, 1e6, 1e9, 1e12, 1e15, 1e18, 1e21, 1e24
|
||||||
static char bigPrefix[] = {' ', 'k', 'M', 'G', 'T', 'P', 'E', 'Z', 'Y', 0};
|
static char bigPrefix[] = {' ', 'k', 'M', 'G', 'T', 'P', 'E', 'Z', 'Y', 0};
|
||||||
// Prefixes for values less then 1.0
|
// Prefixes for values less then 1.0
|
||||||
// 1e-3, 1e-6, 1e-9, 1e-12, 1e-15, 1e-18, 1e-21, 1e-24
|
// 1e-3, 1e-6, 1e-9, 1e-12, 1e-15, 1e-18, 1e-21, 1e-24
|
||||||
static char smallPrefix[]= { 'm', 0x1d, 'n', 'p', 'f', 'a', 'z', 'y', 0};
|
static char smallPrefix[] = {'m', 0x1d, 'n', 'p', 'f', 'a', 'z', 'y', 0};
|
||||||
|
|
||||||
#pragma pack(pop)
|
#pragma pack(pop)
|
||||||
|
|
||||||
static char *long_to_string_with_divisor(char *p,
|
static char *long_to_string_with_divisor(char *p,
|
||||||
uint32_t num,
|
uint32_t num,
|
||||||
uint32_t radix,
|
uint32_t radix,
|
||||||
uint32_t precision) {
|
uint32_t precision) {
|
||||||
char *q = p + MAX_FILLER;
|
char *q = p + MAX_FILLER;
|
||||||
char *b = q;
|
char *b = q;
|
||||||
// convert to string from end buffer to begin
|
// convert to string from end buffer to begin
|
||||||
|
|
@ -78,12 +78,14 @@ static char *long_to_string_with_divisor(char *p,
|
||||||
|
|
||||||
// default prescision = 13
|
// default prescision = 13
|
||||||
// g.mmm kkk hhh
|
// g.mmm kkk hhh
|
||||||
#define MAX_FREQ_PRESCISION 13
|
#define MAX_FREQ_PRESCISION 13
|
||||||
#define FREQ_PSET 1
|
#define FREQ_PSET 1
|
||||||
#define FREQ_NO_SPACE 2
|
#define FREQ_NO_SPACE 2
|
||||||
#define FREQ_PREFIX_SPACE 4
|
#define FREQ_PREFIX_SPACE 4
|
||||||
|
|
||||||
static char *ulong_freq(char *p, uint32_t freq, uint32_t precision){
|
static char *
|
||||||
|
ulong_freq(char *p, uint32_t freq, uint32_t precision)
|
||||||
|
{
|
||||||
uint8_t flag = FREQ_PSET;
|
uint8_t flag = FREQ_PSET;
|
||||||
if (precision == 0)
|
if (precision == 0)
|
||||||
flag|=FREQ_PREFIX_SPACE;
|
flag|=FREQ_PREFIX_SPACE;
|
||||||
|
|
@ -94,7 +96,7 @@ static char *ulong_freq(char *p, uint32_t freq, uint32_t precision){
|
||||||
// Prefix counter
|
// Prefix counter
|
||||||
uint32_t s = 0;
|
uint32_t s = 0;
|
||||||
// Set format (every 3 digits add ' ' up to GHz)
|
// Set format (every 3 digits add ' ' up to GHz)
|
||||||
uint32_t format=0b00100100100;
|
uint32_t format = 0b00100100100;
|
||||||
do {
|
do {
|
||||||
#if 0
|
#if 0
|
||||||
uint8_t c = freq % 10;
|
uint8_t c = freq % 10;
|
||||||
|
|
@ -104,21 +106,27 @@ static char *ulong_freq(char *p, uint32_t freq, uint32_t precision){
|
||||||
// c = freq % 10
|
// c = freq % 10
|
||||||
// freq = freq / 10;
|
// freq = freq / 10;
|
||||||
uint32_t c = freq;
|
uint32_t c = freq;
|
||||||
freq>>=1;
|
freq >>= 1;
|
||||||
freq+=freq>>1;
|
freq += freq >> 1;
|
||||||
freq+=freq>>4;
|
freq += freq >> 4;
|
||||||
freq+=freq>>8;
|
freq += freq >> 8;
|
||||||
freq+=freq>>16; // freq = 858993459*freq/1073741824 = freq * 0,799999999813735485076904296875
|
freq += freq >> 16; // freq = 858993459*freq/1073741824 = freq *
|
||||||
freq>>=3; // freq/=8; freq = freq * 0,09999999997671693563461303710938
|
// 0,799999999813735485076904296875
|
||||||
c-= freq*10; // freq*10 = (freq*4+freq)*2 = ((freq<<2)+freq)<<1
|
freq >>= 3; // freq/=8; freq = freq * 0,09999999997671693563461303710938
|
||||||
while (c>=10) {freq++;c-=10;}
|
c -= freq * 10; // freq*10 = (freq*4+freq)*2 = ((freq<<2)+freq)<<1
|
||||||
|
while (c >= 10) {
|
||||||
|
freq++;
|
||||||
|
c -= 10;
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
*--q = c + '0';
|
*--q = c + '0';
|
||||||
if (freq==0)
|
if (freq == 0) break;
|
||||||
break;
|
|
||||||
// Add spaces, calculate prefix
|
// Add spaces, calculate prefix
|
||||||
if (format&1) {*--q = ' '; s++;}
|
if (format & 1) {
|
||||||
format>>=1;
|
*--q = ' ';
|
||||||
|
s++;
|
||||||
|
}
|
||||||
|
format >>= 1;
|
||||||
} while (1);
|
} while (1);
|
||||||
s = bigPrefix[s];
|
s = bigPrefix[s];
|
||||||
|
|
||||||
|
|
@ -126,26 +134,25 @@ static char *ulong_freq(char *p, uint32_t freq, uint32_t precision){
|
||||||
uint32_t i = (b - q);
|
uint32_t i = (b - q);
|
||||||
// Limit string size, max size is - precision
|
// Limit string size, max size is - precision
|
||||||
if (precision && i > precision) {
|
if (precision && i > precision) {
|
||||||
i = precision;
|
i = precision;
|
||||||
flag|=FREQ_NO_SPACE;
|
flag |= FREQ_NO_SPACE;
|
||||||
}
|
}
|
||||||
// copy string
|
// copy string
|
||||||
// Replace first ' ' by '.', remove ' ' if size too big
|
// Replace first ' ' by '.', remove ' ' if size too big
|
||||||
do{
|
do {
|
||||||
char c = *q++;
|
char c = *q++;
|
||||||
// replace first ' ' on '.'
|
// replace first ' ' on '.'
|
||||||
if (c == ' ') {
|
if (c == ' ') {
|
||||||
if (flag&FREQ_PSET){
|
if (flag & FREQ_PSET) {
|
||||||
c = '.';
|
c = '.';
|
||||||
flag&=~FREQ_PSET;
|
flag &= ~FREQ_PSET;
|
||||||
}
|
} else if (flag & FREQ_NO_SPACE)
|
||||||
else if (flag&FREQ_NO_SPACE)
|
|
||||||
c = *q++;
|
c = *q++;
|
||||||
}
|
}
|
||||||
*p++ = c;
|
*p++ = c;
|
||||||
}while (--i);
|
} while (--i);
|
||||||
// Put pref (amd space before it if need)
|
// Put pref (amd space before it if need)
|
||||||
if (flag&FREQ_PREFIX_SPACE && s!=' ')
|
if (flag & FREQ_PREFIX_SPACE && s != ' ')
|
||||||
*p++ = ' ';
|
*p++ = ' ';
|
||||||
*p++ = s;
|
*p++ = s;
|
||||||
return p;
|
return p;
|
||||||
|
|
@ -153,7 +160,7 @@ static char *ulong_freq(char *p, uint32_t freq, uint32_t precision){
|
||||||
|
|
||||||
#if CHPRINTF_USE_FLOAT
|
#if CHPRINTF_USE_FLOAT
|
||||||
static char *ftoa(char *p, float num, uint32_t precision) {
|
static char *ftoa(char *p, float num, uint32_t precision) {
|
||||||
// Check precision limit
|
// Check precision limit
|
||||||
if (precision > FLOAT_PRECISION)
|
if (precision > FLOAT_PRECISION)
|
||||||
precision = FLOAT_PRECISION;
|
precision = FLOAT_PRECISION;
|
||||||
uint32_t multi = pow10[precision];
|
uint32_t multi = pow10[precision];
|
||||||
|
|
@ -163,7 +170,7 @@ static char *ftoa(char *p, float num, uint32_t precision) {
|
||||||
// Fix rounding error if get
|
// Fix rounding error if get
|
||||||
if (k>=multi){k-=multi;l++;}
|
if (k>=multi){k-=multi;l++;}
|
||||||
p = long_to_string_with_divisor(p, l, 10, 0);
|
p = long_to_string_with_divisor(p, l, 10, 0);
|
||||||
if (precision){
|
if (precision) {
|
||||||
*p++ = '.';
|
*p++ = '.';
|
||||||
p=long_to_string_with_divisor(p, k, 10, precision);
|
p=long_to_string_with_divisor(p, k, 10, precision);
|
||||||
#ifndef CHPRINTF_FORCE_TRAILING_ZEROS
|
#ifndef CHPRINTF_FORCE_TRAILING_ZEROS
|
||||||
|
|
@ -227,23 +234,23 @@ static char *ftoaS(char *p, float num, uint32_t precision) {
|
||||||
*
|
*
|
||||||
* @api
|
* @api
|
||||||
*/
|
*/
|
||||||
#define IS_LONG 1
|
#define IS_LONG 1
|
||||||
#define LEFT_ALIGN 2
|
#define LEFT_ALIGN 2
|
||||||
#define POSITIVE 4
|
#define POSITIVE 4
|
||||||
#define NEGATIVE 8
|
#define NEGATIVE 8
|
||||||
#define PAD_ZERO 16
|
#define PAD_ZERO 16
|
||||||
#define PLUS_SPACE 32
|
#define PLUS_SPACE 32
|
||||||
#define DEFAULT_PRESCISION 64
|
#define DEFAULT_PRESCISION 64
|
||||||
|
|
||||||
int chvprintf(BaseSequentialStream *chp, const char *fmt, va_list ap) {
|
int chvprintf(BaseSequentialStream *chp, const char *fmt, va_list ap) {
|
||||||
char *p, *s, c, filler=' ';
|
char *p, *s, c, filler=' ';
|
||||||
int precision, width;
|
int precision, width;
|
||||||
int n = 0;
|
int n = 0;
|
||||||
uint32_t state;
|
uint32_t state;
|
||||||
union {
|
union {
|
||||||
uint32_t u;
|
uint32_t u;
|
||||||
int32_t l;
|
int32_t l;
|
||||||
float f;
|
float f;
|
||||||
}value;
|
}value;
|
||||||
#if CHPRINTF_USE_FLOAT
|
#if CHPRINTF_USE_FLOAT
|
||||||
char tmpbuf[2*MAX_FILLER + 1];
|
char tmpbuf[2*MAX_FILLER + 1];
|
||||||
|
|
@ -321,8 +328,8 @@ int chvprintf(BaseSequentialStream *chp, const char *fmt, va_list ap) {
|
||||||
if (*fmt)
|
if (*fmt)
|
||||||
c = *fmt++;
|
c = *fmt++;
|
||||||
}
|
}
|
||||||
else if((c >= 'A') && (c <= 'Z'))
|
else if ((c >= 'A') && (c <= 'Z'))
|
||||||
state|=IS_LONG;
|
state|=IS_LONG;
|
||||||
*/
|
*/
|
||||||
// Parse type
|
// Parse type
|
||||||
switch (c) {
|
switch (c) {
|
||||||
|
|
@ -377,7 +384,7 @@ int chvprintf(BaseSequentialStream *chp, const char *fmt, va_list ap) {
|
||||||
*p++ = '+';
|
*p++ = '+';
|
||||||
#ifdef CHPRINTF_USE_SPACE_FLAG
|
#ifdef CHPRINTF_USE_SPACE_FLAG
|
||||||
else if (state & PLUS_SPACE)
|
else if (state & PLUS_SPACE)
|
||||||
*p++ = ' ';
|
*p++ = ' ';
|
||||||
#endif
|
#endif
|
||||||
if (value.f == INFINITY){
|
if (value.f == INFINITY){
|
||||||
*p++ = 0x19;
|
*p++ = 0x19;
|
||||||
|
|
|
||||||
9
flash.c
9
flash.c
|
|
@ -96,7 +96,7 @@ config_save(void)
|
||||||
flash_erase_page((uint32_t)dst);
|
flash_erase_page((uint32_t)dst);
|
||||||
|
|
||||||
/* write to flahs */
|
/* write to flahs */
|
||||||
while(count-- > 0) {
|
while (count-- > 0) {
|
||||||
flash_program_half_word((uint32_t)dst, *src++);
|
flash_program_half_word((uint32_t)dst, *src++);
|
||||||
dst++;
|
dst++;
|
||||||
}
|
}
|
||||||
|
|
@ -141,7 +141,8 @@ caldata_save(int id)
|
||||||
dst = (uint16_t*)saveareas[id];
|
dst = (uint16_t*)saveareas[id];
|
||||||
|
|
||||||
current_props.magic = CONFIG_MAGIC;
|
current_props.magic = CONFIG_MAGIC;
|
||||||
current_props.checksum = checksum(¤t_props, sizeof current_props - sizeof current_props.checksum);
|
current_props.checksum = checksum(
|
||||||
|
¤t_props, sizeof current_props - sizeof current_props.checksum);
|
||||||
|
|
||||||
flash_unlock();
|
flash_unlock();
|
||||||
|
|
||||||
|
|
@ -154,7 +155,7 @@ caldata_save(int id)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* write to flahs */
|
/* write to flahs */
|
||||||
while(count-- > 0) {
|
while (count-- > 0) {
|
||||||
flash_program_half_word((uint32_t)dst, *src++);
|
flash_program_half_word((uint32_t)dst, *src++);
|
||||||
dst++;
|
dst++;
|
||||||
}
|
}
|
||||||
|
|
@ -191,7 +192,7 @@ caldata_recall(int id)
|
||||||
memcpy(dst, src, sizeof(properties_t));
|
memcpy(dst, src, sizeof(properties_t));
|
||||||
return 0;
|
return 0;
|
||||||
load_default:
|
load_default:
|
||||||
loadDefaultProps();
|
load_default_properties();
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
212
ili9341.c
212
ili9341.c
|
|
@ -23,8 +23,8 @@
|
||||||
|
|
||||||
uint16_t spi_buffer[SPI_BUFFER_SIZE];
|
uint16_t spi_buffer[SPI_BUFFER_SIZE];
|
||||||
// Default foreground & background colors
|
// Default foreground & background colors
|
||||||
uint16_t foreground_color=0;
|
uint16_t foreground_color = 0;
|
||||||
uint16_t background_color=0;
|
uint16_t background_color = 0;
|
||||||
|
|
||||||
// Display width and height definition
|
// Display width and height definition
|
||||||
#define ILI9341_WIDTH 320
|
#define ILI9341_WIDTH 320
|
||||||
|
|
@ -129,7 +129,8 @@ uint16_t background_color=0;
|
||||||
#define DISPLAY_ROTATION_270 (ILI9341_MADCTL_MX | ILI9341_MADCTL_BGR)
|
#define DISPLAY_ROTATION_270 (ILI9341_MADCTL_MX | ILI9341_MADCTL_BGR)
|
||||||
#define DISPLAY_ROTATION_90 (ILI9341_MADCTL_MY | ILI9341_MADCTL_BGR)
|
#define DISPLAY_ROTATION_90 (ILI9341_MADCTL_MY | ILI9341_MADCTL_BGR)
|
||||||
#define DISPLAY_ROTATION_0 (ILI9341_MADCTL_MV | ILI9341_MADCTL_BGR)
|
#define DISPLAY_ROTATION_0 (ILI9341_MADCTL_MV | ILI9341_MADCTL_BGR)
|
||||||
#define DISPLAY_ROTATION_180 (ILI9341_MADCTL_MX | ILI9341_MADCTL_MY | ILI9341_MADCTL_MV | ILI9341_MADCTL_BGR)
|
#define DISPLAY_ROTATION_180 (ILI9341_MADCTL_MX | ILI9341_MADCTL_MY \
|
||||||
|
| ILI9341_MADCTL_MV | ILI9341_MADCTL_BGR)
|
||||||
|
|
||||||
//
|
//
|
||||||
// Pin macros
|
// Pin macros
|
||||||
|
|
@ -179,14 +180,17 @@ uint16_t background_color=0;
|
||||||
#define SPI_READ_DATA SPI1->DR
|
#define SPI_READ_DATA SPI1->DR
|
||||||
|
|
||||||
#ifdef __USE_DISPLAY_DMA__
|
#ifdef __USE_DISPLAY_DMA__
|
||||||
static const stm32_dma_stream_t *dmatx = STM32_DMA_STREAM(STM32_SPI_SPI1_TX_DMA_STREAM);
|
static const stm32_dma_stream_t *dmatx =
|
||||||
static uint32_t txdmamode = STM32_DMA_CR_CHSEL(SPI1_TX_DMA_CHANNEL) // Select SPI1 Tx DMA
|
STM32_DMA_STREAM(STM32_SPI_SPI1_TX_DMA_STREAM);
|
||||||
| STM32_DMA_CR_PL(STM32_SPI_SPI1_DMA_PRIORITY) // Set priority
|
static uint32_t txdmamode =
|
||||||
| STM32_DMA_CR_DIR_M2P // Memory to Spi
|
STM32_DMA_CR_CHSEL(SPI1_TX_DMA_CHANNEL) // Select SPI1 Tx DMA
|
||||||
| STM32_DMA_CR_DMEIE //
|
| STM32_DMA_CR_PL(STM32_SPI_SPI1_DMA_PRIORITY) // Set priority
|
||||||
| STM32_DMA_CR_TEIE;
|
| STM32_DMA_CR_DIR_M2P // Memory to Spi
|
||||||
|
| STM32_DMA_CR_DMEIE //
|
||||||
|
| STM32_DMA_CR_TEIE;
|
||||||
|
|
||||||
static void spi_lld_serve_tx_interrupt(SPIDriver *spip, uint32_t flags) {
|
static void spi_lld_serve_tx_interrupt(SPIDriver *spip, uint32_t flags)
|
||||||
|
{
|
||||||
(void)spip;
|
(void)spip;
|
||||||
(void)flags;
|
(void)flags;
|
||||||
}
|
}
|
||||||
|
|
@ -199,13 +203,15 @@ static uint32_t rxdmamode = STM32_DMA_CR_CHSEL(SPI1_RX_DMA_CHANNEL)
|
||||||
| STM32_DMA_CR_DMEIE
|
| STM32_DMA_CR_DMEIE
|
||||||
| STM32_DMA_CR_TEIE;
|
| STM32_DMA_CR_TEIE;
|
||||||
|
|
||||||
static void spi_lld_serve_rx_interrupt(SPIDriver *spip, uint32_t flags) {
|
static void spi_lld_serve_rx_interrupt(SPIDriver *spip, uint32_t flags)
|
||||||
|
{
|
||||||
(void)spip;
|
(void)spip;
|
||||||
(void)flags;
|
(void)flags;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void dmaStreamFlush(uint32_t len){
|
static void dmaStreamFlush(uint32_t len)
|
||||||
while (len){
|
{
|
||||||
|
while (len) {
|
||||||
// DMA data transfer limited by 65535
|
// DMA data transfer limited by 65535
|
||||||
uint16_t tx_size = len > 65535 ? 65535 : len;
|
uint16_t tx_size = len > 65535 ? 65535 : len;
|
||||||
dmaStreamSetTransactionSize(dmatx, tx_size);
|
dmaStreamSetTransactionSize(dmatx, tx_size);
|
||||||
|
|
@ -251,11 +257,13 @@ static void __attribute__ ((noinline)) send_command(uint8_t cmd, uint8_t len, co
|
||||||
DC_CMD;
|
DC_CMD;
|
||||||
SPI_WRITE_8BIT(cmd);
|
SPI_WRITE_8BIT(cmd);
|
||||||
// Need wait transfer complete and set data bit
|
// Need wait transfer complete and set data bit
|
||||||
while (SPI_IS_BUSY);
|
while (SPI_IS_BUSY)
|
||||||
|
;
|
||||||
// Send command data (if need)
|
// Send command data (if need)
|
||||||
DC_DATA;
|
DC_DATA;
|
||||||
while (len-- > 0) {
|
while (len-- > 0) {
|
||||||
while (SPI_TX_IS_NOT_EMPTY);
|
while (SPI_TX_IS_NOT_EMPTY)
|
||||||
|
;
|
||||||
SPI_WRITE_8BIT(*data++);
|
SPI_WRITE_8BIT(*data++);
|
||||||
}
|
}
|
||||||
//CS_HIGH;
|
//CS_HIGH;
|
||||||
|
|
@ -345,31 +353,33 @@ void ili9341_fill(int x, int y, int w, int h, int color)
|
||||||
{
|
{
|
||||||
//uint8_t xx[4] = { x >> 8, x, (x+w-1) >> 8, (x+w-1) };
|
//uint8_t xx[4] = { x >> 8, x, (x+w-1) >> 8, (x+w-1) };
|
||||||
//uint8_t yy[4] = { y >> 8, y, (y+h-1) >> 8, (y+h-1) };
|
//uint8_t yy[4] = { y >> 8, y, (y+h-1) >> 8, (y+h-1) };
|
||||||
uint32_t xx = __REV16(x|((x+w-1)<<16));
|
uint32_t xx = __REV16(x | ((x + w - 1) << 16));
|
||||||
uint32_t yy = __REV16(y|((y+h-1)<<16));
|
uint32_t yy = __REV16(y | ((y + h - 1) << 16));
|
||||||
send_command(ILI9341_COLUMN_ADDRESS_SET, 4, (uint8_t*)&xx);
|
send_command(ILI9341_COLUMN_ADDRESS_SET, 4, (uint8_t*)&xx);
|
||||||
send_command(ILI9341_PAGE_ADDRESS_SET, 4, (uint8_t*)&yy);
|
send_command(ILI9341_PAGE_ADDRESS_SET, 4, (uint8_t*)&yy);
|
||||||
send_command(ILI9341_MEMORY_WRITE, 0, NULL);
|
send_command(ILI9341_MEMORY_WRITE, 0, NULL);
|
||||||
int32_t len = w * h;
|
int32_t len = w * h;
|
||||||
while (len-- > 0){
|
while (len-- > 0) {
|
||||||
while (SPI_TX_IS_NOT_EMPTY);
|
while (SPI_TX_IS_NOT_EMPTY)
|
||||||
|
;
|
||||||
SPI_WRITE_16BIT(color);
|
SPI_WRITE_16BIT(color);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ili9341_bulk(int x, int y, int w, int h)
|
void ili9341_bulk(int x, int y, int w, int h)
|
||||||
{
|
{
|
||||||
//uint8_t xx[4] = { x >> 8, x, (x+w-1) >> 8, (x+w-1) };
|
// uint8_t xx[4] = { x >> 8, x, (x+w-1) >> 8, (x+w-1) };
|
||||||
//uint8_t yy[4] = { y >> 8, y, (y+h-1) >> 8, (y+h-1) };
|
// uint8_t yy[4] = { y >> 8, y, (y+h-1) >> 8, (y+h-1) };
|
||||||
uint16_t *buf = spi_buffer;
|
uint16_t *buf = spi_buffer;
|
||||||
uint32_t xx = __REV16(x|((x+w-1)<<16));
|
uint32_t xx = __REV16(x | ((x + w - 1) << 16));
|
||||||
uint32_t yy = __REV16(y|((y+h-1)<<16));
|
uint32_t yy = __REV16(y | ((y + h - 1) << 16));
|
||||||
send_command(ILI9341_COLUMN_ADDRESS_SET, 4, (uint8_t*)&xx);
|
send_command(ILI9341_COLUMN_ADDRESS_SET, 4, (uint8_t *)&xx);
|
||||||
send_command(ILI9341_PAGE_ADDRESS_SET, 4, (uint8_t*)&yy);
|
send_command(ILI9341_PAGE_ADDRESS_SET, 4, (uint8_t*)&yy);
|
||||||
send_command(ILI9341_MEMORY_WRITE, 0, NULL);
|
send_command(ILI9341_MEMORY_WRITE, 0, NULL);
|
||||||
int32_t len = w * h;
|
int32_t len = w * h;
|
||||||
while (len-- > 0){
|
while (len-- > 0) {
|
||||||
while (SPI_TX_IS_NOT_EMPTY);
|
while (SPI_TX_IS_NOT_EMPTY)
|
||||||
|
;
|
||||||
SPI_WRITE_16BIT(*buf++);
|
SPI_WRITE_16BIT(*buf++);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -378,18 +388,18 @@ static uint8_t ssp_sendrecvdata(void)
|
||||||
{
|
{
|
||||||
// Start RX clock (by sending data)
|
// Start RX clock (by sending data)
|
||||||
SPI_WRITE_8BIT(0);
|
SPI_WRITE_8BIT(0);
|
||||||
while(SPI_RX_IS_EMPTY && SPI_IS_BUSY)
|
while (SPI_RX_IS_EMPTY && SPI_IS_BUSY)
|
||||||
;
|
;
|
||||||
return SPI_READ_DATA;
|
return SPI_READ_DATA;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ili9341_read_memory(int x, int y, int w, int h, int len, uint16_t *out)
|
void ili9341_read_memory(int x, int y, int w, int h, int len, uint16_t *out)
|
||||||
{
|
{
|
||||||
//uint8_t xx[4] = { x >> 8, x, (x+w-1) >> 8, (x+w-1) };
|
// uint8_t xx[4] = { x >> 8, x, (x+w-1) >> 8, (x+w-1) };
|
||||||
//uint8_t yy[4] = { y >> 8, y, (y+h-1) >> 8, (y+h-1) };
|
// uint8_t yy[4] = { y >> 8, y, (y+h-1) >> 8, (y+h-1) };
|
||||||
uint32_t xx = __REV16(x|((x+w-1)<<16));
|
uint32_t xx = __REV16(x | ((x + w - 1) << 16));
|
||||||
uint32_t yy = __REV16(y|((y+h-1)<<16));
|
uint32_t yy = __REV16(y | ((y + h - 1) << 16));
|
||||||
send_command(ILI9341_COLUMN_ADDRESS_SET, 4, (uint8_t*)&xx);
|
send_command(ILI9341_COLUMN_ADDRESS_SET, 4, (uint8_t *)&xx);
|
||||||
send_command(ILI9341_PAGE_ADDRESS_SET, 4, (uint8_t*)&yy);
|
send_command(ILI9341_PAGE_ADDRESS_SET, 4, (uint8_t*)&yy);
|
||||||
send_command(ILI9341_MEMORY_READ, 0, NULL);
|
send_command(ILI9341_MEMORY_READ, 0, NULL);
|
||||||
|
|
||||||
|
|
@ -399,11 +409,11 @@ void ili9341_read_memory(int x, int y, int w, int h, int len, uint16_t *out)
|
||||||
// require 8bit dummy clock
|
// require 8bit dummy clock
|
||||||
ssp_sendrecvdata();
|
ssp_sendrecvdata();
|
||||||
while (len-- > 0) {
|
while (len-- > 0) {
|
||||||
// read data is always 18bit
|
// read data is always 18bit
|
||||||
uint8_t r = ssp_sendrecvdata();
|
uint8_t r = ssp_sendrecvdata();
|
||||||
uint8_t g = ssp_sendrecvdata();
|
uint8_t g = ssp_sendrecvdata();
|
||||||
uint8_t b = ssp_sendrecvdata();
|
uint8_t b = ssp_sendrecvdata();
|
||||||
*out++ = RGB565(r,g,b);
|
*out++ = RGB565(r, g, b);
|
||||||
}
|
}
|
||||||
CS_HIGH;
|
CS_HIGH;
|
||||||
}
|
}
|
||||||
|
|
@ -415,10 +425,10 @@ void ili9341_read_memory(int x, int y, int w, int h, int len, uint16_t *out)
|
||||||
// Fill region by some color
|
// Fill region by some color
|
||||||
void ili9341_fill(int x, int y, int w, int h, int color)
|
void ili9341_fill(int x, int y, int w, int h, int color)
|
||||||
{
|
{
|
||||||
uint32_t xx = __REV16(x|((x+w-1)<<16));
|
uint32_t xx = __REV16(x | ((x + w - 1) << 16));
|
||||||
uint32_t yy = __REV16(y|((y+h-1)<<16));
|
uint32_t yy = __REV16(y | ((y + h - 1) << 16));
|
||||||
send_command(ILI9341_COLUMN_ADDRESS_SET, 4, (uint8_t*)&xx);
|
send_command(ILI9341_COLUMN_ADDRESS_SET, 4, (uint8_t *)&xx);
|
||||||
send_command(ILI9341_PAGE_ADDRESS_SET, 4, (uint8_t*)&yy);
|
send_command(ILI9341_PAGE_ADDRESS_SET, 4, (uint8_t *)&yy);
|
||||||
send_command(ILI9341_MEMORY_WRITE, 0, NULL);
|
send_command(ILI9341_MEMORY_WRITE, 0, NULL);
|
||||||
|
|
||||||
dmaStreamSetMemory0(dmatx, &color);
|
dmaStreamSetMemory0(dmatx, &color);
|
||||||
|
|
@ -426,18 +436,20 @@ void ili9341_fill(int x, int y, int w, int h, int color)
|
||||||
dmaStreamFlush(w * h);
|
dmaStreamFlush(w * h);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ili9341_bulk_8bit(int x, int y, int w, int h, uint16_t *palette){
|
void ili9341_bulk_8bit(int x, int y, int w, int h, uint16_t *palette)
|
||||||
uint32_t xx = __REV16(x|((x+w-1)<<16));
|
{
|
||||||
uint32_t yy = __REV16(y|((y+h-1)<<16));
|
uint32_t xx = __REV16(x | ((x + w - 1) << 16));
|
||||||
send_command(ILI9341_COLUMN_ADDRESS_SET, 4, (uint8_t*)&xx);
|
uint32_t yy = __REV16(y | ((y + h - 1) << 16));
|
||||||
send_command(ILI9341_PAGE_ADDRESS_SET, 4, (uint8_t*)&yy);
|
send_command(ILI9341_COLUMN_ADDRESS_SET, 4, (uint8_t *)&xx);
|
||||||
|
send_command(ILI9341_PAGE_ADDRESS_SET, 4, (uint8_t *)&yy);
|
||||||
send_command(ILI9341_MEMORY_WRITE, 0, NULL);
|
send_command(ILI9341_MEMORY_WRITE, 0, NULL);
|
||||||
|
|
||||||
uint8_t *buf = (uint8_t *)spi_buffer;
|
uint8_t *buf = (uint8_t *)spi_buffer;
|
||||||
int32_t len = w * h;
|
int32_t len = w * h;
|
||||||
while (len-- > 0){
|
while (len-- > 0) {
|
||||||
uint16_t color = palette[*buf++];
|
uint16_t color = palette[*buf++];
|
||||||
while (SPI_TX_IS_NOT_EMPTY);
|
while (SPI_TX_IS_NOT_EMPTY)
|
||||||
|
;
|
||||||
SPI_WRITE_16BIT(color);
|
SPI_WRITE_16BIT(color);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -445,15 +457,16 @@ void ili9341_bulk_8bit(int x, int y, int w, int h, uint16_t *palette){
|
||||||
// Copy spi_buffer to region
|
// Copy spi_buffer to region
|
||||||
void ili9341_bulk(int x, int y, int w, int h)
|
void ili9341_bulk(int x, int y, int w, int h)
|
||||||
{
|
{
|
||||||
uint32_t xx = __REV16(x|((x+w-1)<<16));
|
uint32_t xx = __REV16(x | ((x + w - 1) << 16));
|
||||||
uint32_t yy = __REV16(y|((y+h-1)<<16));
|
uint32_t yy = __REV16(y | ((y + h - 1) << 16));
|
||||||
send_command(ILI9341_COLUMN_ADDRESS_SET, 4, (uint8_t*)&xx);
|
send_command(ILI9341_COLUMN_ADDRESS_SET, 4, (uint8_t *)&xx);
|
||||||
send_command(ILI9341_PAGE_ADDRESS_SET, 4, (uint8_t*)&yy);
|
send_command(ILI9341_PAGE_ADDRESS_SET, 4, (uint8_t *)&yy);
|
||||||
send_command(ILI9341_MEMORY_WRITE, 0, NULL);
|
send_command(ILI9341_MEMORY_WRITE, 0, NULL);
|
||||||
|
|
||||||
// Init Tx DMA mem->spi, set size, mode (spi and mem data size is 16 bit)
|
// Init Tx DMA mem->spi, set size, mode (spi and mem data size is 16 bit)
|
||||||
dmaStreamSetMemory0(dmatx, spi_buffer);
|
dmaStreamSetMemory0(dmatx, spi_buffer);
|
||||||
dmaStreamSetMode(dmatx, txdmamode | STM32_DMA_CR_PSIZE_HWORD | STM32_DMA_CR_MSIZE_HWORD | STM32_DMA_CR_MINC);
|
dmaStreamSetMode(dmatx, txdmamode | STM32_DMA_CR_PSIZE_HWORD |
|
||||||
|
STM32_DMA_CR_MSIZE_HWORD | STM32_DMA_CR_MINC);
|
||||||
dmaStreamFlush(w * h);
|
dmaStreamFlush(w * h);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -462,20 +475,20 @@ void ili9341_bulk(int x, int y, int w, int h)
|
||||||
void ili9341_read_memory(int x, int y, int w, int h, int len, uint16_t *out)
|
void ili9341_read_memory(int x, int y, int w, int h, int len, uint16_t *out)
|
||||||
{
|
{
|
||||||
uint8_t dummy_tx = 0;
|
uint8_t dummy_tx = 0;
|
||||||
uint8_t *rgbbuf=(uint8_t *)out;
|
uint8_t *rgbbuf = (uint8_t *)out;
|
||||||
uint16_t data_size = len * 3 + 1;
|
uint16_t data_size = len * 3 + 1;
|
||||||
uint32_t xx = __REV16(x|((x+w-1)<<16));
|
uint32_t xx = __REV16(x | ((x + w - 1) << 16));
|
||||||
uint32_t yy = __REV16(y|((y+h-1)<<16));
|
uint32_t yy = __REV16(y | ((y + h - 1) << 16));
|
||||||
send_command(ILI9341_COLUMN_ADDRESS_SET, 4, (uint8_t*)&xx);
|
send_command(ILI9341_COLUMN_ADDRESS_SET, 4, (uint8_t *)&xx);
|
||||||
send_command(ILI9341_PAGE_ADDRESS_SET, 4, (uint8_t*)&yy);
|
send_command(ILI9341_PAGE_ADDRESS_SET, 4, (uint8_t *)&yy);
|
||||||
send_command(ILI9341_MEMORY_READ, 0, NULL);
|
send_command(ILI9341_MEMORY_READ, 0, NULL);
|
||||||
// Skip SPI rx buffer
|
// Skip SPI rx buffer
|
||||||
while (SPI_RX_IS_NOT_EMPTY)
|
while (SPI_RX_IS_NOT_EMPTY) (void)SPI_READ_DATA;
|
||||||
(void) SPI_READ_DATA;
|
|
||||||
// Init Rx DMA buffer, size, mode (spi and mem data size is 8 bit)
|
// Init Rx DMA buffer, size, mode (spi and mem data size is 8 bit)
|
||||||
dmaStreamSetMemory0(dmarx, rgbbuf);
|
dmaStreamSetMemory0(dmarx, rgbbuf);
|
||||||
dmaStreamSetTransactionSize(dmarx, data_size);
|
dmaStreamSetTransactionSize(dmarx, data_size);
|
||||||
dmaStreamSetMode(dmarx, rxdmamode | STM32_DMA_CR_PSIZE_BYTE | STM32_DMA_CR_MSIZE_BYTE | STM32_DMA_CR_MINC);
|
dmaStreamSetMode(dmarx, rxdmamode | STM32_DMA_CR_PSIZE_BYTE | STM32_DMA_CR_MSIZE_BYTE |
|
||||||
|
STM32_DMA_CR_MINC);
|
||||||
// Init dummy Tx DMA (for rx clock), size, mode (spi and mem data size is 8 bit)
|
// Init dummy Tx DMA (for rx clock), size, mode (spi and mem data size is 8 bit)
|
||||||
dmaStreamSetMemory0(dmatx, &dummy_tx);
|
dmaStreamSetMemory0(dmatx, &dummy_tx);
|
||||||
dmaStreamSetTransactionSize(dmatx, data_size);
|
dmaStreamSetTransactionSize(dmatx, data_size);
|
||||||
|
|
@ -498,39 +511,53 @@ void ili9341_read_memory(int x, int y, int w, int h, int len, uint16_t *out)
|
||||||
r = rgbbuf[0];
|
r = rgbbuf[0];
|
||||||
g = rgbbuf[1];
|
g = rgbbuf[1];
|
||||||
b = rgbbuf[2];
|
b = rgbbuf[2];
|
||||||
*out++ = RGB565(r,g,b);
|
*out++ = RGB565(r, g, b);
|
||||||
rgbbuf+=3;
|
rgbbuf += 3;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
void clearScreen(void){
|
void ili9341_clear_screen(void)
|
||||||
|
{
|
||||||
ili9341_fill(0, 0, ILI9341_WIDTH, ILI9341_HEIGHT, background_color);
|
ili9341_fill(0, 0, ILI9341_WIDTH, ILI9341_HEIGHT, background_color);
|
||||||
}
|
}
|
||||||
|
|
||||||
void setForegroundColor(uint16_t fg) {foreground_color = fg;}
|
void ili9341_set_foreground(uint16_t fg)
|
||||||
void setBackgroundColor(uint16_t bg) {background_color = bg;}
|
{
|
||||||
|
foreground_color = fg;
|
||||||
|
}
|
||||||
|
|
||||||
void ili9341_setRotation(uint8_t r) {
|
void ili9341_set_background(uint16_t bg)
|
||||||
// static const uint8_t rotation_const[]={DISPLAY_ROTATION_0, DISPLAY_ROTATION_90, DISPLAY_ROTATION_180, DISPLAY_ROTATION_270};
|
{
|
||||||
|
background_color = bg;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ili9341_set_rotation(uint8_t r)
|
||||||
|
{
|
||||||
|
// static const uint8_t rotation_const[]={DISPLAY_ROTATION_0, DISPLAY_ROTATION_90,
|
||||||
|
// DISPLAY_ROTATION_180, DISPLAY_ROTATION_270};
|
||||||
send_command(ILI9341_MEMORY_ACCESS_CONTROL, 1, &r);
|
send_command(ILI9341_MEMORY_ACCESS_CONTROL, 1, &r);
|
||||||
}
|
}
|
||||||
|
|
||||||
void blit8BitWidthBitmap(uint16_t x, uint16_t y, uint16_t width, uint16_t height, const uint8_t *bitmap){
|
void blit8BitWidthBitmap(uint16_t x, uint16_t y, uint16_t width, uint16_t height,
|
||||||
|
const uint8_t *bitmap)
|
||||||
|
{
|
||||||
uint16_t *buf = spi_buffer;
|
uint16_t *buf = spi_buffer;
|
||||||
for(uint16_t c = 0; c < height; c++) {
|
for (uint16_t c = 0; c < height; c++) {
|
||||||
uint8_t bits = *bitmap++;
|
uint8_t bits = *bitmap++;
|
||||||
for (uint16_t r = 0; r < width; r++) {
|
for (uint16_t r = 0; r < width; r++) {
|
||||||
*buf++ = (0x80 & bits) ? foreground_color : background_color;
|
*buf++ = (0x80 & bits) ? foreground_color : background_color;
|
||||||
bits <<= 1;
|
bits <<= 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ili9341_bulk(x, y, width, height);
|
ili9341_bulk(x, y, width, height);
|
||||||
}
|
}
|
||||||
|
|
||||||
void blit16BitWidthBitmap(uint16_t x, uint16_t y, uint16_t width, uint16_t height, const uint16_t *bitmap){
|
static void blit16BitWidthBitmap(uint16_t x, uint16_t y, uint16_t width, uint16_t height,
|
||||||
|
const uint16_t *bitmap)
|
||||||
|
{
|
||||||
uint16_t *buf = spi_buffer;
|
uint16_t *buf = spi_buffer;
|
||||||
for(uint16_t c = 0; c < height; c++) {
|
for (uint16_t c = 0; c < height; c++) {
|
||||||
uint16_t bits = *bitmap++;
|
uint16_t bits = *bitmap++;
|
||||||
for (uint16_t r = 0; r < width; r++) {
|
for (uint16_t r = 0; r < width; r++) {
|
||||||
*buf++ = (0x8000 & bits) ? foreground_color : background_color;
|
*buf++ = (0x8000 & bits) ? foreground_color : background_color;
|
||||||
|
|
@ -552,36 +579,38 @@ void ili9341_drawstring(const char *str, int x, int y)
|
||||||
const uint8_t *char_buf = FONT_GET_DATA(ch);
|
const uint8_t *char_buf = FONT_GET_DATA(ch);
|
||||||
uint16_t w = FONT_GET_WIDTH(ch);
|
uint16_t w = FONT_GET_WIDTH(ch);
|
||||||
blit8BitWidthBitmap(x, y, w, FONT_GET_HEIGHT, char_buf);
|
blit8BitWidthBitmap(x, y, w, FONT_GET_HEIGHT, char_buf);
|
||||||
x+=w;
|
x += w;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ili9341_drawstringV(const char *str, int x, int y){
|
void ili9341_drawstringV(const char *str, int x, int y)
|
||||||
ili9341_setRotation(DISPLAY_ROTATION_270);
|
{
|
||||||
|
ili9341_set_rotation(DISPLAY_ROTATION_270);
|
||||||
ili9341_drawstring(str, ILI9341_HEIGHT-y, x);
|
ili9341_drawstring(str, ILI9341_HEIGHT-y, x);
|
||||||
ili9341_setRotation(DISPLAY_ROTATION_0);
|
ili9341_set_rotation(DISPLAY_ROTATION_0);
|
||||||
}
|
}
|
||||||
|
|
||||||
int ili9341_drawchar_size(uint8_t ch, int x, int y, uint8_t size)
|
int ili9341_drawchar_size(uint8_t ch, int x, int y, uint8_t size)
|
||||||
{
|
{
|
||||||
uint16_t *buf = spi_buffer;
|
uint16_t *buf = spi_buffer;
|
||||||
const uint8_t *char_buf = FONT_GET_DATA(ch);
|
const uint8_t *char_buf = FONT_GET_DATA(ch);
|
||||||
uint16_t w=FONT_GET_WIDTH(ch);
|
uint16_t w = FONT_GET_WIDTH(ch);
|
||||||
for(int c = 0; c < FONT_GET_HEIGHT; c++, char_buf++){
|
for (int c = 0; c < FONT_GET_HEIGHT; c++, char_buf++) {
|
||||||
for (int i=0;i<size;i++){
|
for (int i = 0; i < size; i++) {
|
||||||
uint8_t bits = *char_buf;
|
uint8_t bits = *char_buf;
|
||||||
for (int r = 0; r < w; r++, bits<<=1)
|
for (int r = 0; r < w; r++, bits <<= 1)
|
||||||
for (int j=0; j<size; j++)
|
for (int j = 0; j < size; j++)
|
||||||
*buf++ = (0x80 & bits) ? foreground_color : background_color;
|
*buf++ = (0x80 & bits) ? foreground_color : background_color;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
ili9341_bulk(x, y, w*size, FONT_GET_HEIGHT*size);
|
ili9341_bulk(x, y, w * size, FONT_GET_HEIGHT * size);
|
||||||
return w*size;
|
return w*size;
|
||||||
}
|
}
|
||||||
|
|
||||||
void ili9341_drawfont(uint8_t ch, int x, int y)
|
void ili9341_drawfont(uint8_t ch, int x, int y)
|
||||||
{
|
{
|
||||||
blit16BitWidthBitmap(x, y, NUM_FONT_GET_WIDTH, NUM_FONT_GET_HEIGHT, NUM_FONT_GET_DATA(ch));
|
blit16BitWidthBitmap(x, y, NUM_FONT_GET_WIDTH, NUM_FONT_GET_HEIGHT,
|
||||||
|
NUM_FONT_GET_DATA(ch));
|
||||||
}
|
}
|
||||||
|
|
||||||
void ili9341_drawstring_size(const char *str, int x, int y, uint8_t size)
|
void ili9341_drawstring_size(const char *str, int x, int y, uint8_t size)
|
||||||
|
|
@ -600,7 +629,8 @@ static void ili9341_pixel(int x, int y, uint16_t color)
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define SWAP(x,y) { int z=x; x = y; y = z; }
|
#define SWAP(x, y) { int z = x; x = y; y = z; }
|
||||||
|
|
||||||
void ili9341_line(int x0, int y0, int x1, int y1)
|
void ili9341_line(int x0, int y0, int x1, int y1)
|
||||||
{
|
{
|
||||||
#if 0
|
#if 0
|
||||||
|
|
@ -608,7 +638,7 @@ void ili9341_line(int x0, int y0, int x1, int y1)
|
||||||
int dx = x1 - x0, sx = 1; if (dx < 0) {dx = -dx; sx = -1;}
|
int dx = x1 - x0, sx = 1; if (dx < 0) {dx = -dx; sx = -1;}
|
||||||
int dy = y1 - y0, sy = 1; if (dy < 0) {dy = -dy; sy = -1;}
|
int dy = y1 - y0, sy = 1; if (dy < 0) {dy = -dy; sy = -1;}
|
||||||
int err = (dx > dy ? dx : -dy) / 2;
|
int err = (dx > dy ? dx : -dy) / 2;
|
||||||
while (1){
|
while (1) {
|
||||||
ili9341_pixel(x0, y0, DEFAULT_FG_COLOR);
|
ili9341_pixel(x0, y0, DEFAULT_FG_COLOR);
|
||||||
if (x0 == x1 && y0 == y1)
|
if (x0 == x1 && y0 == y1)
|
||||||
break;
|
break;
|
||||||
|
|
|
||||||
505
main.c
505
main.c
|
|
@ -26,16 +26,15 @@
|
||||||
#include "fft.h"
|
#include "fft.h"
|
||||||
|
|
||||||
#include <chprintf.h>
|
#include <chprintf.h>
|
||||||
//#include <stdlib.h>
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
//#include <ctype.h>
|
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Shell settings
|
* Shell settings
|
||||||
*/
|
*/
|
||||||
// If need run shell as thread (use more amount of memory fore stack), after enable this need reduce spi_buffer size, by default shell run in main thread
|
// If need run shell as thread (use more amount of memory fore stack), after
|
||||||
//#define VNA_SHELL_THREAD
|
// enable this need reduce spi_buffer size, by default shell run in main thread
|
||||||
|
// #define VNA_SHELL_THREAD
|
||||||
|
|
||||||
static BaseSequentialStream *shell_stream = (BaseSequentialStream *)&SDU1;
|
static BaseSequentialStream *shell_stream = (BaseSequentialStream *)&SDU1;
|
||||||
|
|
||||||
|
|
@ -47,13 +46,15 @@ static BaseSequentialStream *shell_stream = (BaseSequentialStream *)&SDU1;
|
||||||
#define VNA_SHELL_MAX_ARGUMENTS 4
|
#define VNA_SHELL_MAX_ARGUMENTS 4
|
||||||
// Shell max command line size
|
// Shell max command line size
|
||||||
#define VNA_SHELL_MAX_LENGTH 48
|
#define VNA_SHELL_MAX_LENGTH 48
|
||||||
|
|
||||||
// Shell command functions prototypes
|
// Shell command functions prototypes
|
||||||
typedef void (*vna_shellcmd_t)(int argc, char *argv[]);
|
typedef void (*vna_shellcmd_t)(int argc, char *argv[]);
|
||||||
#define VNA_SHELL_FUNCTION(command_name) static void command_name(int argc, char *argv[])
|
#define VNA_SHELL_FUNCTION(command_name) \
|
||||||
|
static void command_name(int argc, char *argv[])
|
||||||
|
|
||||||
// Shell command line buffer, args, nargs, and function ptr
|
// Shell command line buffer, args, nargs, and function ptr
|
||||||
static char shell_line[VNA_SHELL_MAX_LENGTH];
|
static char shell_line[VNA_SHELL_MAX_LENGTH];
|
||||||
static char *shell_args[VNA_SHELL_MAX_ARGUMENTS + 1];
|
static char *shell_args[VNA_SHELL_MAX_ARGUMENTS + 1];
|
||||||
static uint16_t shell_nargs;
|
static uint16_t shell_nargs;
|
||||||
static volatile vna_shellcmd_t shell_function = 0;
|
static volatile vna_shellcmd_t shell_function = 0;
|
||||||
|
|
||||||
|
|
@ -117,21 +118,21 @@ static THD_FUNCTION(Thread1, arg)
|
||||||
__WFI();
|
__WFI();
|
||||||
}
|
}
|
||||||
// Run Shell command in sweep thread
|
// Run Shell command in sweep thread
|
||||||
if (shell_function){
|
if (shell_function) {
|
||||||
shell_function(shell_nargs-1, &shell_args[1]);
|
shell_function(shell_nargs - 1, &shell_args[1]);
|
||||||
shell_function = 0;
|
shell_function = 0;
|
||||||
osalThreadSleepMilliseconds(10);
|
osalThreadSleepMilliseconds(10);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
// Process UI inputs
|
// Process UI inputs
|
||||||
ui_process();
|
ui_process();
|
||||||
// Process collected data, calculate trace coordinates and plot only if scan completed
|
// Process collected data, calculate trace coordinates and plot only if scan
|
||||||
if (sweep_mode&SWEEP_ENABLE && completed) {
|
// completed
|
||||||
if ((domain_mode & DOMAIN_MODE) == DOMAIN_TIME)
|
if (sweep_mode & SWEEP_ENABLE && completed) {
|
||||||
transform_domain();
|
if ((domain_mode & DOMAIN_MODE) == DOMAIN_TIME) transform_domain();
|
||||||
// Prepare draw graphics, cache all lines, mark screen cells for redraw
|
// Prepare draw graphics, cache all lines, mark screen cells for redraw
|
||||||
plot_into_index(measured);
|
plot_into_index(measured);
|
||||||
redraw_request |= REDRAW_CELLS|REDRAW_BATTERY;
|
redraw_request |= REDRAW_CELLS | REDRAW_BATTERY;
|
||||||
|
|
||||||
if (uistat.marker_tracking) {
|
if (uistat.marker_tracking) {
|
||||||
int i = marker_search();
|
int i = marker_search();
|
||||||
|
|
@ -142,30 +143,32 @@ static THD_FUNCTION(Thread1, arg)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// plot trace and other indications as raster
|
// plot trace and other indications as raster
|
||||||
draw_all(completed); // flush markmap only if scan completed to prevent remaining traces
|
draw_all(completed); // flush markmap only if scan completed to prevent
|
||||||
|
// remaining traces
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void
|
static inline void
|
||||||
pause_sweep(void)
|
pause_sweep(void)
|
||||||
{
|
{
|
||||||
sweep_mode&=~SWEEP_ENABLE;
|
sweep_mode &= ~SWEEP_ENABLE;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void
|
static inline void
|
||||||
resume_sweep(void)
|
resume_sweep(void)
|
||||||
{
|
{
|
||||||
sweep_mode|=SWEEP_ENABLE;
|
sweep_mode |= SWEEP_ENABLE;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
toggle_sweep(void)
|
toggle_sweep(void)
|
||||||
{
|
{
|
||||||
sweep_mode^=SWEEP_ENABLE;
|
sweep_mode ^= SWEEP_ENABLE;
|
||||||
}
|
}
|
||||||
|
|
||||||
static float
|
static float
|
||||||
bessel0(float x) {
|
bessel0(float x)
|
||||||
|
{
|
||||||
const float eps = 0.0001;
|
const float eps = 0.0001;
|
||||||
|
|
||||||
float ret = 0;
|
float ret = 0;
|
||||||
|
|
@ -181,7 +184,8 @@ bessel0(float x) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static float
|
static float
|
||||||
kaiser_window(float k, float n, float beta) {
|
kaiser_window(float k, float n, float beta)
|
||||||
|
{
|
||||||
if (beta == 0.0) return 1.0;
|
if (beta == 0.0) return 1.0;
|
||||||
float r = (2 * k) / (n - 1) - 1;
|
float r = (2 * k) / (n - 1) - 1;
|
||||||
return bessel0(beta * sqrt(1 - r * r)) / bessel0(beta);
|
return bessel0(beta * sqrt(1 - r * r)) / bessel0(beta);
|
||||||
|
|
@ -197,70 +201,70 @@ transform_domain(void)
|
||||||
uint8_t window_size = POINTS_COUNT, offset = 0;
|
uint8_t window_size = POINTS_COUNT, offset = 0;
|
||||||
uint8_t is_lowpass = FALSE;
|
uint8_t is_lowpass = FALSE;
|
||||||
switch (domain_mode & TD_FUNC) {
|
switch (domain_mode & TD_FUNC) {
|
||||||
case TD_FUNC_BANDPASS:
|
case TD_FUNC_BANDPASS:
|
||||||
offset = 0;
|
offset = 0;
|
||||||
window_size = POINTS_COUNT;
|
window_size = POINTS_COUNT;
|
||||||
break;
|
break;
|
||||||
case TD_FUNC_LOWPASS_IMPULSE:
|
case TD_FUNC_LOWPASS_IMPULSE:
|
||||||
case TD_FUNC_LOWPASS_STEP:
|
case TD_FUNC_LOWPASS_STEP:
|
||||||
is_lowpass = TRUE;
|
is_lowpass = TRUE;
|
||||||
offset = POINTS_COUNT;
|
offset = POINTS_COUNT;
|
||||||
window_size = POINTS_COUNT*2;
|
window_size = POINTS_COUNT * 2;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
float beta = 0.0;
|
float beta = 0.0;
|
||||||
switch (domain_mode & TD_WINDOW) {
|
switch (domain_mode & TD_WINDOW) {
|
||||||
case TD_WINDOW_MINIMUM:
|
case TD_WINDOW_MINIMUM:
|
||||||
beta = 0.0; // this is rectangular
|
beta = 0.0; // this is rectangular
|
||||||
break;
|
break;
|
||||||
case TD_WINDOW_NORMAL:
|
case TD_WINDOW_NORMAL:
|
||||||
beta = 6.0;
|
beta = 6.0;
|
||||||
break;
|
break;
|
||||||
case TD_WINDOW_MAXIMUM:
|
case TD_WINDOW_MAXIMUM:
|
||||||
beta = 13;
|
beta = 13;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
for (int ch = 0; ch < 2; ch++) {
|
for (int ch = 0; ch < 2; ch++) {
|
||||||
memcpy(tmp, measured[ch], sizeof(measured[0]));
|
memcpy(tmp, measured[ch], sizeof(measured[0]));
|
||||||
for (int i = 0; i < POINTS_COUNT; i++) {
|
for (int i = 0; i < POINTS_COUNT; i++) {
|
||||||
float w = kaiser_window(i+offset, window_size, beta);
|
float w = kaiser_window(i + offset, window_size, beta);
|
||||||
tmp[i*2+0] *= w;
|
tmp[i * 2 + 0] *= w;
|
||||||
tmp[i*2+1] *= w;
|
tmp[i * 2 + 1] *= w;
|
||||||
}
|
}
|
||||||
for (int i = POINTS_COUNT; i < FFT_SIZE; i++) {
|
for (int i = POINTS_COUNT; i < FFT_SIZE; i++) {
|
||||||
tmp[i*2+0] = 0.0;
|
tmp[i * 2 + 0] = 0.0;
|
||||||
tmp[i*2+1] = 0.0;
|
tmp[i * 2 + 1] = 0.0;
|
||||||
}
|
}
|
||||||
if (is_lowpass) {
|
if (is_lowpass) {
|
||||||
for (int i = 1; i < POINTS_COUNT; i++) {
|
for (int i = 1; i < POINTS_COUNT; i++) {
|
||||||
tmp[(FFT_SIZE-i)*2+0] = tmp[i*2+0];
|
tmp[(FFT_SIZE - i) * 2 + 0] = tmp[i * 2 + 0];
|
||||||
tmp[(FFT_SIZE-i)*2+1] = -tmp[i*2+1];
|
tmp[(FFT_SIZE - i) * 2 + 1] = -tmp[i * 2 + 1];
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fft256_inverse((float(*)[2])tmp);
|
fft256_inverse((float(*)[2])tmp);
|
||||||
memcpy(measured[ch], tmp, sizeof(measured[0]));
|
memcpy(measured[ch], tmp, sizeof(measured[0]));
|
||||||
for (int i = 0; i < POINTS_COUNT; i++) {
|
for (int i = 0; i < POINTS_COUNT; i++) {
|
||||||
measured[ch][i][0] /= (float)FFT_SIZE;
|
measured[ch][i][0] /= (float)FFT_SIZE;
|
||||||
if (is_lowpass) {
|
if (is_lowpass) {
|
||||||
measured[ch][i][1] = 0.0;
|
measured[ch][i][1] = 0.0;
|
||||||
} else {
|
} else {
|
||||||
measured[ch][i][1] /= (float)FFT_SIZE;
|
measured[ch][i][1] /= (float)FFT_SIZE;
|
||||||
}
|
|
||||||
}
|
}
|
||||||
if ( (domain_mode & TD_FUNC) == TD_FUNC_LOWPASS_STEP ) {
|
}
|
||||||
for (int i = 1; i < POINTS_COUNT; i++) {
|
if ((domain_mode & TD_FUNC) == TD_FUNC_LOWPASS_STEP) {
|
||||||
measured[ch][i][0] += measured[ch][i-1][0];
|
for (int i = 1; i < POINTS_COUNT; i++) {
|
||||||
}
|
measured[ch][i][0] += measured[ch][i - 1][0];
|
||||||
}
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Shell commands output
|
// Shell commands output
|
||||||
static int shell_printf(const char *fmt, ...) {
|
static int shell_printf(const char *fmt, ...)
|
||||||
|
{
|
||||||
va_list ap;
|
va_list ap;
|
||||||
int formatted_bytes;
|
int formatted_bytes;
|
||||||
va_start(ap, fmt);
|
va_start(ap, fmt);
|
||||||
|
|
@ -330,7 +334,7 @@ static int
|
||||||
adjust_gain(uint32_t newfreq)
|
adjust_gain(uint32_t newfreq)
|
||||||
{
|
{
|
||||||
int new_order = newfreq / FREQ_HARMONICS;
|
int new_order = newfreq / FREQ_HARMONICS;
|
||||||
int old_order = si5351_getFrequency() / FREQ_HARMONICS;
|
int old_order = si5351_get_frequency() / FREQ_HARMONICS;
|
||||||
if (new_order != old_order) {
|
if (new_order != old_order) {
|
||||||
tlv320aic3204_set_gain(gain_table[new_order], gain_table[new_order]);
|
tlv320aic3204_set_gain(gain_table[new_order], gain_table[new_order]);
|
||||||
return DELAY_GAIN_CHANGE;
|
return DELAY_GAIN_CHANGE;
|
||||||
|
|
@ -345,7 +349,7 @@ int set_frequency(uint32_t freq)
|
||||||
if (ds == DRIVE_STRENGTH_AUTO) {
|
if (ds == DRIVE_STRENGTH_AUTO) {
|
||||||
ds = freq > FREQ_HARMONICS ? SI5351_CLK_DRIVE_STRENGTH_8MA : SI5351_CLK_DRIVE_STRENGTH_2MA;
|
ds = freq > FREQ_HARMONICS ? SI5351_CLK_DRIVE_STRENGTH_8MA : SI5351_CLK_DRIVE_STRENGTH_2MA;
|
||||||
}
|
}
|
||||||
delay += si5351_set_frequency_with_offset(freq, ds);
|
delay += si5351_set_frequency(freq, ds);
|
||||||
return delay;
|
return delay;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -354,7 +358,8 @@ int set_frequency(uint32_t freq)
|
||||||
// Rewrite universal standart str to value functions to more compact
|
// Rewrite universal standart str to value functions to more compact
|
||||||
//
|
//
|
||||||
// Convert string to int32
|
// Convert string to int32
|
||||||
static int32_t my_atoi(const char *p){
|
static int32_t my_atoi(const char *p)
|
||||||
|
{
|
||||||
int32_t value = 0;
|
int32_t value = 0;
|
||||||
uint32_t c;
|
uint32_t c;
|
||||||
bool neg = false;
|
bool neg = false;
|
||||||
|
|
@ -371,7 +376,8 @@ static int32_t my_atoi(const char *p){
|
||||||
// 0o - for oct radix
|
// 0o - for oct radix
|
||||||
// 0b - for bin radix
|
// 0b - for bin radix
|
||||||
// default dec radix
|
// default dec radix
|
||||||
uint32_t my_atoui(const char *p) {
|
uint32_t my_atoui(const char *p)
|
||||||
|
{
|
||||||
uint32_t value = 0, radix = 10, c;
|
uint32_t value = 0, radix = 10, c;
|
||||||
if (*p == '+') p++;
|
if (*p == '+') p++;
|
||||||
if (*p == '0') {
|
if (*p == '0') {
|
||||||
|
|
@ -435,13 +441,15 @@ my_atof(const char *p)
|
||||||
// Example need search parameter "center" in "start|stop|center|span|cw" getStringIndex return 2
|
// Example need search parameter "center" in "start|stop|center|span|cw" getStringIndex return 2
|
||||||
// If not found return -1
|
// If not found return -1
|
||||||
// Used for easy parse command arguments
|
// Used for easy parse command arguments
|
||||||
static int getStringIndex(char *v, const char *list){
|
static int get_str_index(char *v, const char *list)
|
||||||
|
{
|
||||||
int i = 0;
|
int i = 0;
|
||||||
while(1){
|
while (1) {
|
||||||
char *p = v;
|
char *p = v;
|
||||||
while (1){
|
while (1) {
|
||||||
char c = *list; if (c == '|') c = 0;
|
char c = *list;
|
||||||
if (c == *p++){
|
if (c == '|') c = 0;
|
||||||
|
if (c == *p++) {
|
||||||
// Found, return index
|
// Found, return index
|
||||||
if (c == 0) return i;
|
if (c == 0) return i;
|
||||||
list++; // Compare next symbol
|
list++; // Compare next symbol
|
||||||
|
|
@ -450,9 +458,9 @@ static int getStringIndex(char *v, const char *list){
|
||||||
break; // Not equal, break
|
break; // Not equal, break
|
||||||
}
|
}
|
||||||
// Set new substring ptr
|
// Set new substring ptr
|
||||||
while (1){
|
while (1) {
|
||||||
// End of string, not found
|
// End of string, not found
|
||||||
if (*list == 0 ) return -1;
|
if (*list == 0) return -1;
|
||||||
if (*list++ == '|') break;
|
if (*list++ == '|') break;
|
||||||
}
|
}
|
||||||
i++;
|
i++;
|
||||||
|
|
@ -684,11 +692,11 @@ VNA_SHELL_FUNCTION(cmd_capture)
|
||||||
#error "Low size of spi_buffer for cmd_capture"
|
#error "Low size of spi_buffer for cmd_capture"
|
||||||
#endif
|
#endif
|
||||||
// read 2 row pixel time (read buffer limit by 2/3 + 1 from spi_buffer size)
|
// read 2 row pixel time (read buffer limit by 2/3 + 1 from spi_buffer size)
|
||||||
for (y=0; y < 240; y+=2){
|
for (y = 0; y < 240; y += 2) {
|
||||||
// use uint16_t spi_buffer[2048] (defined in ili9341) for read buffer
|
// use uint16_t spi_buffer[2048] (defined in ili9341) for read buffer
|
||||||
uint8_t *buf = (uint8_t *)spi_buffer;
|
uint8_t *buf = (uint8_t *)spi_buffer;
|
||||||
ili9341_read_memory(0, y, 320, 2, 2*320, spi_buffer);
|
ili9341_read_memory(0, y, 320, 2, 2 * 320, spi_buffer);
|
||||||
for (i = 0; i < 4*320; i++) {
|
for (i = 0; i < 4 * 320; i++) {
|
||||||
streamPut(shell_stream, *buf++);
|
streamPut(shell_stream, *buf++);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -715,14 +723,21 @@ static void (*sample_func)(float *gamma) = calculate_gamma;
|
||||||
|
|
||||||
VNA_SHELL_FUNCTION(cmd_sample)
|
VNA_SHELL_FUNCTION(cmd_sample)
|
||||||
{
|
{
|
||||||
if (argc!=1) goto usage;
|
if (argc != 1) goto usage;
|
||||||
// 0 1 2
|
// 0 1 2
|
||||||
static const char cmd_sample_list[] = "gamma|ampl|ref";
|
static const char cmd_sample_list[] = "gamma|ampl|ref";
|
||||||
switch (getStringIndex(argv[0], cmd_sample_list)){
|
switch (get_str_index(argv[0], cmd_sample_list)) {
|
||||||
case 0:sample_func = calculate_gamma; return;
|
case 0:
|
||||||
case 1:sample_func = fetch_amplitude; return;
|
sample_func = calculate_gamma;
|
||||||
case 2:sample_func = fetch_amplitude_ref; return;
|
return;
|
||||||
default:break;
|
case 1:
|
||||||
|
sample_func = fetch_amplitude;
|
||||||
|
return;
|
||||||
|
case 2:
|
||||||
|
sample_func = fetch_amplitude_ref;
|
||||||
|
return;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
usage:
|
usage:
|
||||||
shell_printf("usage: sample {%s}\r\n", cmd_sample_list);
|
shell_printf("usage: sample {%s}\r\n", cmd_sample_list);
|
||||||
|
|
@ -758,7 +773,8 @@ static const marker_t def_markers[MARKERS_MAX] = {
|
||||||
};
|
};
|
||||||
|
|
||||||
// Load propeties default settings
|
// Load propeties default settings
|
||||||
void loadDefaultProps(void){
|
void load_default_properties(void)
|
||||||
|
{
|
||||||
//Magic add on caldata_save
|
//Magic add on caldata_save
|
||||||
//current_props.magic = CONFIG_MAGIC;
|
//current_props.magic = CONFIG_MAGIC;
|
||||||
current_props._frequency0 = 50000; // start = 50kHz
|
current_props._frequency0 = 50000; // start = 50kHz
|
||||||
|
|
@ -808,7 +824,7 @@ bool sweep(bool break_on_operation)
|
||||||
if (frequencies[i] == 0) break;
|
if (frequencies[i] == 0) break;
|
||||||
delay = set_frequency(frequencies[i]); // 700
|
delay = set_frequency(frequencies[i]); // 700
|
||||||
tlv320aic3204_select(0); // 60 CH0:REFLECT, reset and begin measure
|
tlv320aic3204_select(0); // 60 CH0:REFLECT, reset and begin measure
|
||||||
DSP_START(delay+((i==0)?1:0)); // 1900
|
DSP_START(delay + ((i == 0) ? 1 : 0)); // 1900
|
||||||
//================================================
|
//================================================
|
||||||
// Place some code thats need execute while delay
|
// Place some code thats need execute while delay
|
||||||
//================================================
|
//================================================
|
||||||
|
|
@ -870,17 +886,15 @@ VNA_SHELL_FUNCTION(cmd_scan)
|
||||||
pause_sweep();
|
pause_sweep();
|
||||||
sweep(false);
|
sweep(false);
|
||||||
// Output data after if set (faster data recive)
|
// Output data after if set (faster data recive)
|
||||||
if (argc == 4){
|
if (argc == 4) {
|
||||||
uint16_t mask = my_atoui(argv[3]);
|
uint16_t mask = my_atoui(argv[3]);
|
||||||
if (mask)
|
if (mask) {
|
||||||
for (i = 0; i < points; i++){
|
for (i = 0; i < points; i++) {
|
||||||
if (mask&1)
|
if (mask & 1) shell_printf("%u ", frequencies[i]);
|
||||||
shell_printf("%u ", frequencies[i]);
|
if (mask & 2) shell_printf("%f %f ", measured[0][i][0], measured[0][i][1]);
|
||||||
if (mask&2)
|
if (mask & 4) shell_printf("%f %f ", measured[1][i][0], measured[1][i][1]);
|
||||||
shell_printf("%f %f ", measured[0][i][0], measured[0][i][1]);
|
shell_printf("\r\n");
|
||||||
if (mask&4)
|
}
|
||||||
shell_printf("%f %f ", measured[1][i][0], measured[1][i][1]);
|
|
||||||
shell_printf("\r\n");
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -905,7 +919,7 @@ update_marker_index(void)
|
||||||
} else {
|
} else {
|
||||||
for (i = 0; i < sweep_points-1; i++) {
|
for (i = 0; i < sweep_points-1; i++) {
|
||||||
if (frequencies[i] <= f && f < frequencies[i+1]) {
|
if (frequencies[i] <= f && f < frequencies[i+1]) {
|
||||||
markers[m].index = f < (frequencies[i]/2 + frequencies[i+1]/2) ? i : i+1;
|
markers[m].index = f < (frequencies[i] / 2 + frequencies[i + 1] / 2) ? i : i + 1;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -927,7 +941,7 @@ set_frequencies(uint32_t start, uint32_t stop, uint16_t points)
|
||||||
df+=error;
|
df+=error;
|
||||||
if (df >=step) {
|
if (df >=step) {
|
||||||
f++;
|
f++;
|
||||||
df-=step;
|
df -= step;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// disable at out of sweep range
|
// disable at out of sweep range
|
||||||
|
|
@ -943,7 +957,7 @@ update_frequencies(void)
|
||||||
stop = get_sweep_frequency(ST_STOP);
|
stop = get_sweep_frequency(ST_STOP);
|
||||||
|
|
||||||
set_frequencies(start, stop, sweep_points);
|
set_frequencies(start, stop, sweep_points);
|
||||||
// operation_requested|= OP_FREQCHANGE;
|
// operation_requested|= OP_FREQCHANGE;
|
||||||
|
|
||||||
update_marker_index();
|
update_marker_index();
|
||||||
|
|
||||||
|
|
@ -957,67 +971,65 @@ set_sweep_frequency(int type, uint32_t freq)
|
||||||
int cal_applied = cal_status & CALSTAT_APPLY;
|
int cal_applied = cal_status & CALSTAT_APPLY;
|
||||||
|
|
||||||
// Check frequency for out of bounds (minimum SPAN can be any value)
|
// Check frequency for out of bounds (minimum SPAN can be any value)
|
||||||
if (type!=ST_SPAN && freq < START_MIN)
|
if (type != ST_SPAN && freq < START_MIN)
|
||||||
freq = START_MIN;
|
freq = START_MIN;
|
||||||
if (freq > STOP_MAX)
|
if (freq > STOP_MAX)
|
||||||
freq = STOP_MAX;
|
freq = STOP_MAX;
|
||||||
|
|
||||||
ensure_edit_config();
|
ensure_edit_config();
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case ST_START:
|
case ST_START:
|
||||||
config.freq_mode&=~FREQ_MODE_CENTER_SPAN;
|
config.freq_mode &= ~FREQ_MODE_CENTER_SPAN;
|
||||||
if (frequency0 != freq) {
|
if (frequency0 != freq) {
|
||||||
frequency0 = freq;
|
|
||||||
// if start > stop then make start = stop
|
|
||||||
if (frequency1 < freq)
|
|
||||||
frequency1 = freq;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case ST_STOP:
|
|
||||||
config.freq_mode&=~FREQ_MODE_CENTER_SPAN;
|
|
||||||
if (frequency1 != freq) {
|
|
||||||
frequency1 = freq;
|
|
||||||
// if start > stop then make start = stop
|
|
||||||
if (frequency0 > freq)
|
|
||||||
frequency0 = freq;
|
frequency0 = freq;
|
||||||
}
|
// if start > stop then make start = stop
|
||||||
break;
|
if (frequency1 < freq) frequency1 = freq;
|
||||||
case ST_CENTER:
|
|
||||||
config.freq_mode|=FREQ_MODE_CENTER_SPAN;
|
|
||||||
uint32_t center = frequency0/2 + frequency1/2;
|
|
||||||
if (center != freq) {
|
|
||||||
uint32_t span = frequency1 - frequency0;
|
|
||||||
if (freq < START_MIN + span/2) {
|
|
||||||
span = (freq - START_MIN) * 2;
|
|
||||||
}
|
}
|
||||||
if (freq > STOP_MAX - span/2) {
|
break;
|
||||||
span = (STOP_MAX - freq) * 2;
|
case ST_STOP:
|
||||||
|
config.freq_mode &= ~FREQ_MODE_CENTER_SPAN;
|
||||||
|
if (frequency1 != freq) {
|
||||||
|
frequency1 = freq;
|
||||||
|
// if start > stop then make start = stop
|
||||||
|
if (frequency0 > freq) frequency0 = freq;
|
||||||
}
|
}
|
||||||
frequency0 = freq - span/2;
|
break;
|
||||||
frequency1 = freq + span/2;
|
case ST_CENTER:
|
||||||
}
|
config.freq_mode |= FREQ_MODE_CENTER_SPAN;
|
||||||
break;
|
uint32_t center = frequency0 / 2 + frequency1 / 2;
|
||||||
case ST_SPAN:
|
if (center != freq) {
|
||||||
config.freq_mode|=FREQ_MODE_CENTER_SPAN;
|
uint32_t span = frequency1 - frequency0;
|
||||||
if (frequency1 - frequency0 != freq) {
|
if (freq < START_MIN + span / 2) {
|
||||||
uint32_t center = frequency0/2 + frequency1/2;
|
span = (freq - START_MIN) * 2;
|
||||||
if (center < START_MIN + freq/2) {
|
}
|
||||||
center = START_MIN + freq/2;
|
if (freq > STOP_MAX - span / 2) {
|
||||||
|
span = (STOP_MAX - freq) * 2;
|
||||||
|
}
|
||||||
|
frequency0 = freq - span / 2;
|
||||||
|
frequency1 = freq + span / 2;
|
||||||
}
|
}
|
||||||
if (center > STOP_MAX - freq/2) {
|
break;
|
||||||
center = STOP_MAX - freq/2;
|
case ST_SPAN:
|
||||||
|
config.freq_mode |= FREQ_MODE_CENTER_SPAN;
|
||||||
|
if (frequency1 - frequency0 != freq) {
|
||||||
|
uint32_t center = frequency0 / 2 + frequency1 / 2;
|
||||||
|
if (center < START_MIN + freq / 2) {
|
||||||
|
center = START_MIN + freq / 2;
|
||||||
|
}
|
||||||
|
if (center > STOP_MAX - freq / 2) {
|
||||||
|
center = STOP_MAX - freq / 2;
|
||||||
|
}
|
||||||
|
frequency0 = center - freq / 2;
|
||||||
|
frequency1 = center + freq / 2;
|
||||||
}
|
}
|
||||||
frequency0 = center - freq/2;
|
break;
|
||||||
frequency1 = center + freq/2;
|
case ST_CW:
|
||||||
}
|
config.freq_mode |= FREQ_MODE_CENTER_SPAN;
|
||||||
break;
|
if (frequency0 != freq || frequency1 != freq) {
|
||||||
case ST_CW:
|
frequency0 = freq;
|
||||||
config.freq_mode|=FREQ_MODE_CENTER_SPAN;
|
frequency1 = freq;
|
||||||
if (frequency0 != freq || frequency1 != freq) {
|
}
|
||||||
frequency0 = freq;
|
break;
|
||||||
frequency1 = freq;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
}
|
}
|
||||||
update_frequencies();
|
update_frequencies();
|
||||||
if (cal_auto_interpolate && cal_applied)
|
if (cal_auto_interpolate && cal_applied)
|
||||||
|
|
@ -1028,7 +1040,11 @@ uint32_t
|
||||||
get_sweep_frequency(int type)
|
get_sweep_frequency(int type)
|
||||||
{
|
{
|
||||||
// Obsolete, ensure correct start/stop, start always must be < stop
|
// Obsolete, ensure correct start/stop, start always must be < stop
|
||||||
if (frequency0>frequency1) {uint32_t t=frequency0; frequency0=frequency1; frequency1=t;}
|
if (frequency0 > frequency1) {
|
||||||
|
uint32_t t = frequency0;
|
||||||
|
frequency0 = frequency1;
|
||||||
|
frequency1 = t;
|
||||||
|
}
|
||||||
switch (type) {
|
switch (type) {
|
||||||
case ST_START: return frequency0;
|
case ST_START: return frequency0;
|
||||||
case ST_STOP: return frequency1;
|
case ST_STOP: return frequency1;
|
||||||
|
|
@ -1049,16 +1065,16 @@ VNA_SHELL_FUNCTION(cmd_sweep)
|
||||||
}
|
}
|
||||||
uint32_t value0 = 0;
|
uint32_t value0 = 0;
|
||||||
uint32_t value1 = 0;
|
uint32_t value1 = 0;
|
||||||
if (argc >=1) value0 = my_atoui(argv[0]);
|
if (argc >= 1) value0 = my_atoui(argv[0]);
|
||||||
if (argc >=2) value1 = my_atoui(argv[1]);
|
if (argc >= 2) value1 = my_atoui(argv[1]);
|
||||||
#if MAX_FREQ_TYPE!=5
|
#if MAX_FREQ_TYPE != 5
|
||||||
#error "Sweep mode possibly changed, check cmd_sweep function"
|
#error "Sweep mode possibly changed, check cmd_sweep function"
|
||||||
#endif
|
#endif
|
||||||
// Parse sweep {start|stop|center|span|cw} {freq(Hz)}
|
// Parse sweep {start|stop|center|span|cw} {freq(Hz)}
|
||||||
// get enum ST_START, ST_STOP, ST_CENTER, ST_SPAN, ST_CW
|
// get enum ST_START, ST_STOP, ST_CENTER, ST_SPAN, ST_CW
|
||||||
static const char sweep_cmd[] = "start|stop|center|span|cw";
|
static const char sweep_cmd[] = "start|stop|center|span|cw";
|
||||||
if (argc == 2 && value0 == 0) {
|
if (argc == 2 && value0 == 0) {
|
||||||
int type = getStringIndex(argv[0], sweep_cmd);
|
int type = get_str_index(argv[0], sweep_cmd);
|
||||||
if (type == -1)
|
if (type == -1)
|
||||||
goto usage;
|
goto usage;
|
||||||
set_sweep_frequency(type, value1);
|
set_sweep_frequency(type, value1);
|
||||||
|
|
@ -1415,27 +1431,46 @@ VNA_SHELL_FUNCTION(cmd_cal)
|
||||||
redraw_request|=REDRAW_CAL_STATUS;
|
redraw_request|=REDRAW_CAL_STATUS;
|
||||||
// 0 1 2 3 4 5 6 7 8 9 10
|
// 0 1 2 3 4 5 6 7 8 9 10
|
||||||
static const char cmd_cal_list[] = "load|open|short|thru|isoln|done|on|off|reset|data|in";
|
static const char cmd_cal_list[] = "load|open|short|thru|isoln|done|on|off|reset|data|in";
|
||||||
switch (getStringIndex(argv[0], cmd_cal_list)){
|
switch (get_str_index(argv[0], cmd_cal_list)) {
|
||||||
case 0:cal_collect(CAL_LOAD ); return;
|
case 0:
|
||||||
case 1:cal_collect(CAL_OPEN ); return;
|
cal_collect(CAL_LOAD);
|
||||||
case 2:cal_collect(CAL_SHORT); return;
|
return;
|
||||||
case 3:cal_collect(CAL_THRU ); return;
|
case 1:
|
||||||
case 4:cal_collect(CAL_ISOLN); return;
|
cal_collect(CAL_OPEN);
|
||||||
case 5:cal_done(); return;
|
return;
|
||||||
case 6:cal_status|= CALSTAT_APPLY;return;
|
case 2:
|
||||||
case 7:cal_status&=~CALSTAT_APPLY;return;
|
cal_collect(CAL_SHORT);
|
||||||
case 8:cal_status = 0; return;
|
return;
|
||||||
case 9:
|
case 3:
|
||||||
shell_printf("%f %f\r\n", cal_data[CAL_LOAD ][0][0], cal_data[CAL_LOAD ][0][1]);
|
cal_collect(CAL_THRU);
|
||||||
shell_printf("%f %f\r\n", cal_data[CAL_OPEN ][0][0], cal_data[CAL_OPEN ][0][1]);
|
return;
|
||||||
|
case 4:
|
||||||
|
cal_collect(CAL_ISOLN);
|
||||||
|
return;
|
||||||
|
case 5:
|
||||||
|
cal_done();
|
||||||
|
return;
|
||||||
|
case 6:
|
||||||
|
cal_status |= CALSTAT_APPLY;
|
||||||
|
return;
|
||||||
|
case 7:
|
||||||
|
cal_status &= ~CALSTAT_APPLY;
|
||||||
|
return;
|
||||||
|
case 8:
|
||||||
|
cal_status = 0;
|
||||||
|
return;
|
||||||
|
case 9:
|
||||||
|
shell_printf("%f %f\r\n", cal_data[CAL_LOAD][0][0], cal_data[CAL_LOAD][0][1]);
|
||||||
|
shell_printf("%f %f\r\n", cal_data[CAL_OPEN][0][0], cal_data[CAL_OPEN][0][1]);
|
||||||
shell_printf("%f %f\r\n", cal_data[CAL_SHORT][0][0], cal_data[CAL_SHORT][0][1]);
|
shell_printf("%f %f\r\n", cal_data[CAL_SHORT][0][0], cal_data[CAL_SHORT][0][1]);
|
||||||
shell_printf("%f %f\r\n", cal_data[CAL_THRU ][0][0], cal_data[CAL_THRU ][0][1]);
|
shell_printf("%f %f\r\n", cal_data[CAL_THRU][0][0], cal_data[CAL_THRU][0][1]);
|
||||||
shell_printf("%f %f\r\n", cal_data[CAL_ISOLN][0][0], cal_data[CAL_ISOLN][0][1]);
|
shell_printf("%f %f\r\n", cal_data[CAL_ISOLN][0][0], cal_data[CAL_ISOLN][0][1]);
|
||||||
return;
|
return;
|
||||||
case 10:
|
case 10:
|
||||||
cal_interpolate((argc > 1) ? my_atoi(argv[1]) : 0);
|
cal_interpolate((argc > 1) ? my_atoi(argv[1]) : 0);
|
||||||
return;
|
return;
|
||||||
default:break;
|
default:
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
shell_printf("usage: cal [%s]\r\n", cmd_cal_list);
|
shell_printf("usage: cal [%s]\r\n", cmd_cal_list);
|
||||||
}
|
}
|
||||||
|
|
@ -1590,20 +1625,20 @@ VNA_SHELL_FUNCTION(cmd_trace)
|
||||||
shell_printf("%d %s %s\r\n", t, type, channel);
|
shell_printf("%d %s %s\r\n", t, type, channel);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
#if MAX_TRACE_TYPE!=12
|
#if MAX_TRACE_TYPE != 12
|
||||||
#error "Trace type enum possibly changed, check cmd_trace function"
|
#error "Trace type enum possibly changed, check cmd_trace function"
|
||||||
#endif
|
#endif
|
||||||
// enum TRC_LOGMAG, TRC_PHASE, TRC_DELAY, TRC_SMITH, TRC_POLAR, TRC_LINEAR, TRC_SWR, TRC_REAL, TRC_IMAG, TRC_R, TRC_X, TRC_OFF
|
// enum TRC_LOGMAG, TRC_PHASE, TRC_DELAY, TRC_SMITH, TRC_POLAR, TRC_LINEAR, TRC_SWR, TRC_REAL, TRC_IMAG, TRC_R, TRC_X, TRC_OFF
|
||||||
static const char cmd_type_list[] = "logmag|phase|delay|smith|polar|linear|swr|real|imag|r|x|off";
|
static const char cmd_type_list[] = "logmag|phase|delay|smith|polar|linear|swr|real|imag|r|x|off";
|
||||||
int type = getStringIndex(argv[1], cmd_type_list);
|
int type = get_str_index(argv[1], cmd_type_list);
|
||||||
if (type >= 0){
|
if (type >= 0) {
|
||||||
set_trace_type(t, type);
|
set_trace_type(t, type);
|
||||||
goto check_ch_num;
|
goto check_ch_num;
|
||||||
}
|
}
|
||||||
// 0 1
|
// 0 1
|
||||||
static const char cmd_scale_ref_list[] = "scale|refpos";
|
static const char cmd_scale_ref_list[] = "scale|refpos";
|
||||||
if (argc >= 3){
|
if (argc >= 3) {
|
||||||
switch (getStringIndex(argv[1], cmd_scale_ref_list)){
|
switch (get_str_index(argv[1], cmd_scale_ref_list)) {
|
||||||
case 0:
|
case 0:
|
||||||
//trace[t].scale = my_atof(argv[2]);
|
//trace[t].scale = my_atof(argv[2]);
|
||||||
set_trace_scale(t, my_atof(argv[2]));
|
set_trace_scale(t, my_atof(argv[2]));
|
||||||
|
|
@ -1686,7 +1721,7 @@ VNA_SHELL_FUNCTION(cmd_marker)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
static const char cmd_marker_list[] = "on|off";
|
static const char cmd_marker_list[] = "on|off";
|
||||||
switch (getStringIndex(argv[1], cmd_marker_list)){
|
switch (get_str_index(argv[1], cmd_marker_list)) {
|
||||||
case 0: markers[t].enabled = TRUE; active_marker = t; return;
|
case 0: markers[t].enabled = TRUE; active_marker = t; return;
|
||||||
case 1: markers[t].enabled =FALSE; if (active_marker == t) active_marker = -1; return;
|
case 1: markers[t].enabled =FALSE; if (active_marker == t) active_marker = -1; return;
|
||||||
default:
|
default:
|
||||||
|
|
@ -1726,7 +1761,7 @@ VNA_SHELL_FUNCTION(cmd_touchtest)
|
||||||
(void)argv;
|
(void)argv;
|
||||||
do {
|
do {
|
||||||
touch_draw_test();
|
touch_draw_test();
|
||||||
} while(argc);
|
} while (argc);
|
||||||
}
|
}
|
||||||
|
|
||||||
VNA_SHELL_FUNCTION(cmd_frequencies)
|
VNA_SHELL_FUNCTION(cmd_frequencies)
|
||||||
|
|
@ -1771,16 +1806,33 @@ VNA_SHELL_FUNCTION(cmd_transform)
|
||||||
// 0 1 2 3 4 5 6 7
|
// 0 1 2 3 4 5 6 7
|
||||||
static const char cmd_transform_list[] = "on|off|impulse|step|bandpass|minimum|normal|maximum";
|
static const char cmd_transform_list[] = "on|off|impulse|step|bandpass|minimum|normal|maximum";
|
||||||
for (i = 0; i < argc; i++) {
|
for (i = 0; i < argc; i++) {
|
||||||
switch (getStringIndex(argv[i], cmd_transform_list)){
|
switch (get_str_index(argv[i], cmd_transform_list)) {
|
||||||
case 0:set_domain_mode(DOMAIN_TIME);return;
|
case 0:
|
||||||
case 1:set_domain_mode(DOMAIN_FREQ);return;
|
set_domain_mode(DOMAIN_TIME);
|
||||||
case 2:set_timedomain_func(TD_FUNC_LOWPASS_IMPULSE);return;
|
return;
|
||||||
case 3:set_timedomain_func(TD_FUNC_LOWPASS_STEP);return;
|
case 1:
|
||||||
case 4:set_timedomain_func(TD_FUNC_BANDPASS);return;
|
set_domain_mode(DOMAIN_FREQ);
|
||||||
case 5:set_timedomain_window(TD_WINDOW_MINIMUM);return;
|
return;
|
||||||
case 6:set_timedomain_window(TD_WINDOW_NORMAL);return;
|
case 2:
|
||||||
case 7:set_timedomain_window(TD_WINDOW_MAXIMUM);return;
|
set_timedomain_func(TD_FUNC_LOWPASS_IMPULSE);
|
||||||
default: goto usage;
|
return;
|
||||||
|
case 3:
|
||||||
|
set_timedomain_func(TD_FUNC_LOWPASS_STEP);
|
||||||
|
return;
|
||||||
|
case 4:
|
||||||
|
set_timedomain_func(TD_FUNC_BANDPASS);
|
||||||
|
return;
|
||||||
|
case 5:
|
||||||
|
set_timedomain_window(TD_WINDOW_MINIMUM);
|
||||||
|
return;
|
||||||
|
case 6:
|
||||||
|
set_timedomain_window(TD_WINDOW_NORMAL);
|
||||||
|
return;
|
||||||
|
case 7:
|
||||||
|
set_timedomain_window(TD_WINDOW_MAXIMUM);
|
||||||
|
return;
|
||||||
|
default:
|
||||||
|
goto usage;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return;
|
return;
|
||||||
|
|
@ -1941,7 +1993,7 @@ VNA_SHELL_FUNCTION(cmd_info)
|
||||||
{
|
{
|
||||||
(void)argc;
|
(void)argc;
|
||||||
(void)argv;
|
(void)argv;
|
||||||
int i=0;
|
int i = 0;
|
||||||
while (info_about[i])
|
while (info_about[i])
|
||||||
shell_printf("%s\r\n", info_about[i++]);
|
shell_printf("%s\r\n", info_about[i++]);
|
||||||
}
|
}
|
||||||
|
|
@ -1956,7 +2008,7 @@ VNA_SHELL_FUNCTION(cmd_color)
|
||||||
shell_printf("usage: color {id} {rgb24}\r\n");
|
shell_printf("usage: color {id} {rgb24}\r\n");
|
||||||
for (i=-3; i < TRACES_MAX; i++) {
|
for (i=-3; i < TRACES_MAX; i++) {
|
||||||
#if 0
|
#if 0
|
||||||
switch(i){
|
switch(i) {
|
||||||
case -3: color = config.grid_color; break;
|
case -3: color = config.grid_color; break;
|
||||||
case -2: color = config.menu_normal_color; break;
|
case -2: color = config.menu_normal_color; break;
|
||||||
case -1: color = config.menu_active_color; break;
|
case -1: color = config.menu_active_color; break;
|
||||||
|
|
@ -1981,7 +2033,7 @@ VNA_SHELL_FUNCTION(cmd_color)
|
||||||
return;
|
return;
|
||||||
color = RGBHEX(my_atoui(argv[1]));
|
color = RGBHEX(my_atoui(argv[1]));
|
||||||
#if 0
|
#if 0
|
||||||
switch(i){
|
switch(i) {
|
||||||
case -3: config.grid_color = color; break;
|
case -3: config.grid_color = color; break;
|
||||||
case -2: config.menu_normal_color = color; break;
|
case -2: config.menu_normal_color = color; break;
|
||||||
case -1: config.menu_active_color = color; break;
|
case -1: config.menu_active_color = color; break;
|
||||||
|
|
@ -2000,7 +2052,8 @@ VNA_SHELL_FUNCTION(cmd_color)
|
||||||
#if CH_CFG_USE_REGISTRY == FALSE
|
#if CH_CFG_USE_REGISTRY == FALSE
|
||||||
#error "Threads Requite enabled CH_CFG_USE_REGISTRY in chconf.h"
|
#error "Threads Requite enabled CH_CFG_USE_REGISTRY in chconf.h"
|
||||||
#endif
|
#endif
|
||||||
VNA_SHELL_FUNCTION(cmd_threads) {
|
VNA_SHELL_FUNCTION(cmd_threads)
|
||||||
|
{
|
||||||
static const char *states[] = {CH_STATE_NAMES};
|
static const char *states[] = {CH_STATE_NAMES};
|
||||||
thread_t *tp;
|
thread_t *tp;
|
||||||
(void)argc;
|
(void)argc;
|
||||||
|
|
@ -2116,18 +2169,19 @@ VNA_SHELL_FUNCTION(cmd_help)
|
||||||
//
|
//
|
||||||
// Read command line from shell_stream
|
// Read command line from shell_stream
|
||||||
//
|
//
|
||||||
static int VNAShell_readLine(char *line, int max_size){
|
static int VNAShell_readLine(char *line, int max_size)
|
||||||
|
{
|
||||||
// Read line from input stream
|
// Read line from input stream
|
||||||
uint8_t c;
|
uint8_t c;
|
||||||
char *ptr = line;
|
char *ptr = line;
|
||||||
while (1){
|
while (1) {
|
||||||
// Return 0 only if stream not active
|
// Return 0 only if stream not active
|
||||||
if (streamRead(shell_stream, &c, 1) == 0)
|
if (streamRead(shell_stream, &c, 1) == 0)
|
||||||
return 0;
|
return 0;
|
||||||
// Backspace or Delete
|
// Backspace or Delete
|
||||||
if (c == 8 || c == 0x7f) {
|
if (c == 8 || c == 0x7f) {
|
||||||
if (ptr != line) {
|
if (ptr != line) {
|
||||||
static const char backspace[] = {0x08,0x20,0x08,0x00};
|
static const char backspace[] = {0x08, 0x20, 0x08, 0x00};
|
||||||
shell_printf(backspace);
|
shell_printf(backspace);
|
||||||
ptr--;
|
ptr--;
|
||||||
}
|
}
|
||||||
|
|
@ -2154,52 +2208,54 @@ static int VNAShell_readLine(char *line, int max_size){
|
||||||
//
|
//
|
||||||
// Parse and run command line
|
// Parse and run command line
|
||||||
//
|
//
|
||||||
static void VNAShell_executeLine(char *line){
|
static void VNAShell_executeLine(char *line)
|
||||||
|
{
|
||||||
// Parse and execute line
|
// Parse and execute line
|
||||||
char *lp = line, *ep;
|
char *lp = line, *ep;
|
||||||
shell_nargs = 0;
|
shell_nargs = 0;
|
||||||
while (*lp!=0){
|
while (*lp != 0) {
|
||||||
// Skipping white space and tabs at string begin.
|
// Skipping white space and tabs at string begin.
|
||||||
while (*lp==' ' || *lp=='\t') lp++;
|
while (*lp == ' ' || *lp == '\t') lp++;
|
||||||
// If an argument starts with a double quote then its delimiter is another quote, else delimiter is white space.
|
// If an argument starts with a double quote then its delimiter is another quote, else
|
||||||
ep = (*lp == '"') ? strpbrk(++lp, "\"") : strpbrk( lp, " \t");
|
// delimiter is white space.
|
||||||
|
ep = (*lp == '"') ? strpbrk(++lp, "\"") : strpbrk(lp, " \t");
|
||||||
// Store in args string
|
// Store in args string
|
||||||
shell_args[shell_nargs++]=lp;
|
shell_args[shell_nargs++] = lp;
|
||||||
// Stop, end of input string
|
// Stop, end of input string
|
||||||
if ((lp = ep) == NULL)
|
if ((lp = ep) == NULL) break;
|
||||||
break;
|
|
||||||
// Argument limits check
|
// Argument limits check
|
||||||
if (shell_nargs > VNA_SHELL_MAX_ARGUMENTS) {
|
if (shell_nargs > VNA_SHELL_MAX_ARGUMENTS) {
|
||||||
shell_printf("too many arguments, max "define_to_STR(VNA_SHELL_MAX_ARGUMENTS)""VNA_SHELL_NEWLINE_STR);
|
shell_printf("too many arguments, max " define_to_STR(
|
||||||
|
VNA_SHELL_MAX_ARGUMENTS) "" VNA_SHELL_NEWLINE_STR);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
// Set zero at the end of string and continue check
|
// Set zero at the end of string and continue check
|
||||||
*lp++ = 0;
|
*lp++ = 0;
|
||||||
}
|
}
|
||||||
if (shell_nargs == 0)
|
if (shell_nargs == 0) return;
|
||||||
return;
|
|
||||||
// Execute line
|
// Execute line
|
||||||
const VNAShellCommand *scp;
|
const VNAShellCommand *scp;
|
||||||
for (scp = commands; scp->sc_name!=NULL;scp++) {
|
for (scp = commands; scp->sc_name != NULL; scp++) {
|
||||||
if (strcmp(scp->sc_name, shell_args[0]) == 0) {
|
if (strcmp(scp->sc_name, shell_args[0]) == 0) {
|
||||||
if (scp->flags&CMD_WAIT_MUTEX){
|
if (scp->flags & CMD_WAIT_MUTEX) {
|
||||||
shell_function= scp->sc_function;
|
shell_function = scp->sc_function;
|
||||||
// Wait execute command in sweep thread
|
// Wait execute command in sweep thread
|
||||||
do{
|
do {
|
||||||
osalThreadSleepMilliseconds(100);
|
osalThreadSleepMilliseconds(100);
|
||||||
} while(shell_function);
|
} while (shell_function);
|
||||||
|
} else {
|
||||||
|
scp->sc_function(shell_nargs - 1, &shell_args[1]);
|
||||||
}
|
}
|
||||||
else
|
|
||||||
scp->sc_function(shell_nargs-1, &shell_args[1]);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
shell_printf("%s?"VNA_SHELL_NEWLINE_STR, shell_args[0]);
|
shell_printf("%s?" VNA_SHELL_NEWLINE_STR, shell_args[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef VNA_SHELL_THREAD
|
#ifdef VNA_SHELL_THREAD
|
||||||
static THD_WORKING_AREA(waThread2, /* cmd_* max stack size + alpha */442);
|
static THD_WORKING_AREA(waThread2, /* cmd_* max stack size + alpha */442);
|
||||||
THD_FUNCTION(myshellThread, p) {
|
THD_FUNCTION(myshellThread, p)
|
||||||
|
{
|
||||||
(void)p;
|
(void)p;
|
||||||
chRegSetThreadName("shell");
|
chRegSetThreadName("shell");
|
||||||
shell_printf(VNA_SHELL_NEWLINE_STR"NanoVNA Shell"VNA_SHELL_NEWLINE_STR);
|
shell_printf(VNA_SHELL_NEWLINE_STR"NanoVNA Shell"VNA_SHELL_NEWLINE_STR);
|
||||||
|
|
@ -2341,20 +2397,21 @@ int main(void)
|
||||||
|
|
||||||
/* The prototype shows it is a naked function - in effect this is just an
|
/* The prototype shows it is a naked function - in effect this is just an
|
||||||
assembly function. */
|
assembly function. */
|
||||||
void HardFault_Handler( void );
|
void HardFault_Handler(void);
|
||||||
|
|
||||||
void hard_fault_handler_c(uint32_t *sp) __attribute__( ( naked ) );;
|
void hard_fault_handler_c(uint32_t *sp) __attribute__((naked));
|
||||||
|
|
||||||
void HardFault_Handler(void)
|
void HardFault_Handler(void)
|
||||||
{
|
{
|
||||||
uint32_t* sp;
|
uint32_t *sp;
|
||||||
//__asm volatile ("mrs %0, msp \n\t": "=r" (sp) );
|
//__asm volatile ("mrs %0, msp \n\t": "=r" (sp) );
|
||||||
__asm volatile ("mrs %0, psp \n\t": "=r" (sp) );
|
__asm volatile("mrs %0, psp \n\t" : "=r"(sp));
|
||||||
hard_fault_handler_c(sp);
|
hard_fault_handler_c(sp);
|
||||||
}
|
}
|
||||||
|
|
||||||
void hard_fault_handler_c(uint32_t* sp)
|
void hard_fault_handler_c(uint32_t *sp)
|
||||||
{
|
{
|
||||||
(void)sp;
|
(void)sp;
|
||||||
while (true) {}
|
while (true) {
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -96,7 +96,7 @@
|
||||||
#define STM32_EXT_EXTI17_IRQ_PRIORITY 3
|
#define STM32_EXT_EXTI17_IRQ_PRIORITY 3
|
||||||
#define STM32_EXT_EXTI21_22_IRQ_PRIORITY 3
|
#define STM32_EXT_EXTI21_22_IRQ_PRIORITY 3
|
||||||
|
|
||||||
#define STM32_DISABLE_EXTI2122_HANDLER TRUE
|
#define STM32_DISABLE_EXTI2122_HANDLER TRUE
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* GPT driver system settings.
|
* GPT driver system settings.
|
||||||
|
|
|
||||||
52
nanovna.h
52
nanovna.h
|
|
@ -93,7 +93,7 @@ uint32_t get_sweep_frequency(int type);
|
||||||
double my_atof(const char *p);
|
double my_atof(const char *p);
|
||||||
|
|
||||||
void toggle_sweep(void);
|
void toggle_sweep(void);
|
||||||
void loadDefaultProps(void);
|
void load_default_properties(void);
|
||||||
|
|
||||||
#define SWEEP_ENABLE 0x01
|
#define SWEEP_ENABLE 0x01
|
||||||
#define SWEEP_ONCE 0x02
|
#define SWEEP_ONCE 0x02
|
||||||
|
|
@ -169,15 +169,15 @@ extern int16_t area_height;
|
||||||
|
|
||||||
// font
|
// font
|
||||||
extern const uint8_t x5x7_bits [];
|
extern const uint8_t x5x7_bits [];
|
||||||
#define FONT_GET_DATA(ch) (&x5x7_bits[ch*7])
|
#define FONT_GET_DATA(ch) (&x5x7_bits[ch*7])
|
||||||
#define FONT_GET_WIDTH(ch) (8-(x5x7_bits[ch*7]&7))
|
#define FONT_GET_WIDTH(ch) (8-(x5x7_bits[ch*7]&7))
|
||||||
#define FONT_MAX_WIDTH 7
|
#define FONT_MAX_WIDTH 7
|
||||||
#define FONT_GET_HEIGHT 7
|
#define FONT_GET_HEIGHT 7
|
||||||
|
|
||||||
extern const uint16_t numfont16x22[];
|
extern const uint16_t numfont16x22[];
|
||||||
#define NUM_FONT_GET_DATA(ch) (&numfont16x22[ch*22])
|
#define NUM_FONT_GET_DATA(ch) (&numfont16x22[ch*22])
|
||||||
#define NUM_FONT_GET_WIDTH 16
|
#define NUM_FONT_GET_WIDTH 16
|
||||||
#define NUM_FONT_GET_HEIGHT 22
|
#define NUM_FONT_GET_HEIGHT 22
|
||||||
|
|
||||||
#define S_DELTA "\004"
|
#define S_DELTA "\004"
|
||||||
#define S_DEGREE "\037"
|
#define S_DEGREE "\037"
|
||||||
|
|
@ -306,21 +306,21 @@ extern volatile uint8_t redraw_request;
|
||||||
#define RGBHEX(hex) ( (((hex)&0x001c00)<<3) | (((hex)&0x0000f8)<<5) | (((hex)&0xf80000)>>16) | (((hex)&0x00e000)>>13) )
|
#define RGBHEX(hex) ( (((hex)&0x001c00)<<3) | (((hex)&0x0000f8)<<5) | (((hex)&0xf80000)>>16) | (((hex)&0x00e000)>>13) )
|
||||||
|
|
||||||
// Define size of screen buffer in pixels (one pixel 16bit size)
|
// Define size of screen buffer in pixels (one pixel 16bit size)
|
||||||
#define SPI_BUFFER_SIZE 2048
|
#define SPI_BUFFER_SIZE 2048
|
||||||
|
|
||||||
#define DEFAULT_FG_COLOR RGB565(255,255,255)
|
#define DEFAULT_FG_COLOR RGB565(255,255,255)
|
||||||
#define DEFAULT_BG_COLOR RGB565( 0, 0, 0)
|
#define DEFAULT_BG_COLOR RGB565( 0, 0, 0)
|
||||||
#define DEFAULT_GRID_COLOR RGB565(128,128,128)
|
#define DEFAULT_GRID_COLOR RGB565(128,128,128)
|
||||||
#define DEFAULT_MENU_COLOR RGB565(255,255,255)
|
#define DEFAULT_MENU_COLOR RGB565(255,255,255)
|
||||||
#define DEFAULT_MENU_TEXT_COLOR RGB565( 0, 0, 0)
|
#define DEFAULT_MENU_TEXT_COLOR RGB565( 0, 0, 0)
|
||||||
#define DEFAULT_MENU_ACTIVE_COLOR RGB565(180,255,180)
|
#define DEFAULT_MENU_ACTIVE_COLOR RGB565(180,255,180)
|
||||||
#define DEFAULT_TRACE_1_COLOR RGB565(255,255, 0)
|
#define DEFAULT_TRACE_1_COLOR RGB565(255,255, 0)
|
||||||
#define DEFAULT_TRACE_2_COLOR RGB565( 0,255,255)
|
#define DEFAULT_TRACE_2_COLOR RGB565( 0,255,255)
|
||||||
#define DEFAULT_TRACE_3_COLOR RGB565( 0,255, 0)
|
#define DEFAULT_TRACE_3_COLOR RGB565( 0,255, 0)
|
||||||
#define DEFAULT_TRACE_4_COLOR RGB565(255, 0,255)
|
#define DEFAULT_TRACE_4_COLOR RGB565(255, 0,255)
|
||||||
#define DEFAULT_NORMAL_BAT_COLOR RGB565( 31,227, 0)
|
#define DEFAULT_NORMAL_BAT_COLOR RGB565( 31,227, 0)
|
||||||
#define DEFAULT_LOW_BAT_COLOR RGB565(255, 0, 0)
|
#define DEFAULT_LOW_BAT_COLOR RGB565(255, 0, 0)
|
||||||
#define DEFAULT_SPEC_INPUT_COLOR RGB565(128,255,128);
|
#define DEFAULT_SPEC_INPUT_COLOR RGB565(128,255,128);
|
||||||
|
|
||||||
extern uint16_t foreground_color;
|
extern uint16_t foreground_color;
|
||||||
extern uint16_t background_color;
|
extern uint16_t background_color;
|
||||||
|
|
@ -328,15 +328,13 @@ extern uint16_t background_color;
|
||||||
extern uint16_t spi_buffer[SPI_BUFFER_SIZE];
|
extern uint16_t spi_buffer[SPI_BUFFER_SIZE];
|
||||||
|
|
||||||
void ili9341_init(void);
|
void ili9341_init(void);
|
||||||
//void ili9341_setRotation(uint8_t r);
|
|
||||||
void ili9341_test(int mode);
|
void ili9341_test(int mode);
|
||||||
void ili9341_bulk(int x, int y, int w, int h);
|
void ili9341_bulk(int x, int y, int w, int h);
|
||||||
void ili9341_fill(int x, int y, int w, int h, int color);
|
void ili9341_fill(int x, int y, int w, int h, int color);
|
||||||
void setForegroundColor(uint16_t fg);
|
void ili9341_set_foreground(uint16_t fg);
|
||||||
void setBackgroundColor(uint16_t fg);
|
void ili9341_set_background(uint16_t fg);
|
||||||
void clearScreen(void);
|
void ili9341_clear_screen(void);
|
||||||
void blit8BitWidthBitmap(uint16_t x, uint16_t y, uint16_t width, uint16_t height, const uint8_t *bitmap);
|
void blit8BitWidthBitmap(uint16_t x, uint16_t y, uint16_t width, uint16_t height, const uint8_t *bitmap);
|
||||||
void blit16BitWidthBitmap(uint16_t x, uint16_t y, uint16_t width, uint16_t height, const uint16_t *bitmap);
|
|
||||||
void ili9341_drawchar(uint8_t ch, int x, int y);
|
void ili9341_drawchar(uint8_t ch, int x, int y);
|
||||||
void ili9341_drawstring(const char *str, int x, int y);
|
void ili9341_drawstring(const char *str, int x, int y);
|
||||||
void ili9341_drawstringV(const char *str, int x, int y);
|
void ili9341_drawstringV(const char *str, int x, int y);
|
||||||
|
|
|
||||||
1013
numfont20x22.c
1013
numfont20x22.c
File diff suppressed because it is too large
Load diff
370
plot.c
370
plot.c
|
|
@ -1,3 +1,23 @@
|
||||||
|
/*
|
||||||
|
* Copyright (c) 2014-2015, TAKAHASHI Tomohiro (TTRFTECH) edy555@gmail.com
|
||||||
|
* All rights reserved.
|
||||||
|
*
|
||||||
|
* This is free software; you can redistribute it and/or modify
|
||||||
|
* it under the terms of the GNU General Public License as published by
|
||||||
|
* the Free Software Foundation; either version 3, or (at your option)
|
||||||
|
* any later version.
|
||||||
|
*
|
||||||
|
* The software 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.
|
||||||
|
*
|
||||||
|
* You should have received a copy of the GNU General Public License
|
||||||
|
* along with GNU Radio; see the file COPYING. If not, write to
|
||||||
|
* the Free Software Foundation, Inc., 51 Franklin Street,
|
||||||
|
* Boston, MA 02110-1301, USA.
|
||||||
|
*/
|
||||||
|
|
||||||
#include <math.h>
|
#include <math.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include "ch.h"
|
#include "ch.h"
|
||||||
|
|
@ -15,8 +35,8 @@ int16_t area_width = AREA_WIDTH_NORMAL;
|
||||||
int16_t area_height = AREA_HEIGHT_NORMAL;
|
int16_t area_height = AREA_HEIGHT_NORMAL;
|
||||||
|
|
||||||
// Cell render use spi buffer
|
// Cell render use spi buffer
|
||||||
typedef uint16_t pixel;
|
typedef uint16_t pixel_t;
|
||||||
pixel *cell_buffer = (pixel *)spi_buffer;
|
pixel_t *cell_buffer = (pixel_t *)spi_buffer;
|
||||||
// Cell size
|
// Cell size
|
||||||
// Depends from spi_buffer size, CELLWIDTH*CELLHEIGHT*sizeof(pixel) <= sizeof(spi_buffer)
|
// Depends from spi_buffer size, CELLWIDTH*CELLHEIGHT*sizeof(pixel) <= sizeof(spi_buffer)
|
||||||
#define CELLWIDTH (64)
|
#define CELLWIDTH (64)
|
||||||
|
|
@ -51,12 +71,13 @@ static index_t trace_index[TRACES_MAX][POINTS_COUNT];
|
||||||
#define CELL_X(i) (int)(((i)>>16))
|
#define CELL_X(i) (int)(((i)>>16))
|
||||||
#define CELL_Y(i) (int)(((i)&0xFFFF))
|
#define CELL_Y(i) (int)(((i)&0xFFFF))
|
||||||
|
|
||||||
//#define floatToInt(v) ((int)(v))
|
//#define float2int(v) ((int)(v))
|
||||||
static int
|
static int
|
||||||
floatToInt(float v){
|
float2int(float v)
|
||||||
if (v < 0) return v-0.5;
|
{
|
||||||
if (v > 0) return v+0.5;
|
if (v < 0) return v - 0.5;
|
||||||
return 0;
|
if (v > 0) return v + 0.5;
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
void update_grid(void)
|
void update_grid(void)
|
||||||
|
|
@ -112,8 +133,7 @@ polar_grid(int x, int y)
|
||||||
if (d == 0) return 1;
|
if (d == 0) return 1;
|
||||||
|
|
||||||
// vertical and horizontal axis
|
// vertical and horizontal axis
|
||||||
if (x == 0 || y == 0)
|
if (x == 0 || y == 0) return 1;
|
||||||
return 1;
|
|
||||||
|
|
||||||
d = circle_inout(x, y, P_RADIUS / 5);
|
d = circle_inout(x, y, P_RADIUS / 5);
|
||||||
if (d == 0) return 1;
|
if (d == 0) return 1;
|
||||||
|
|
@ -124,8 +144,7 @@ polar_grid(int x, int y)
|
||||||
if (d > 0) return 0;
|
if (d > 0) return 0;
|
||||||
|
|
||||||
// cross sloping lines
|
// cross sloping lines
|
||||||
if (x == y || x == -y)
|
if (x == y || x == -y) return 1;
|
||||||
return 1;
|
|
||||||
|
|
||||||
d = circle_inout(x, y, P_RADIUS * 3 / 5);
|
d = circle_inout(x, y, P_RADIUS * 3 / 5);
|
||||||
if (d == 0) return 1;
|
if (d == 0) return 1;
|
||||||
|
|
@ -151,49 +170,39 @@ smith_grid(int x, int y)
|
||||||
|
|
||||||
// outer circle
|
// outer circle
|
||||||
d = circle_inout(x, y, P_RADIUS);
|
d = circle_inout(x, y, P_RADIUS);
|
||||||
if (d < 0)
|
if (d < 0) return 0;
|
||||||
return 0;
|
if (d == 0) return 1;
|
||||||
if (d == 0)
|
|
||||||
return 1;
|
|
||||||
|
|
||||||
// horizontal axis
|
// horizontal axis
|
||||||
if (y == 0)
|
if (y == 0) return 1;
|
||||||
return 1;
|
|
||||||
|
|
||||||
// shift circle center to right origin
|
// shift circle center to right origin
|
||||||
x -= P_RADIUS;
|
x -= P_RADIUS;
|
||||||
|
|
||||||
// Constant Reactance Circle: 2j : R/2 = P_RADIUS/2
|
// Constant Reactance Circle: 2j : R/2 = P_RADIUS/2
|
||||||
if (circle_inout(x, y+P_RADIUS/2, P_RADIUS/2) == 0)
|
if (circle_inout(x, y + P_RADIUS / 2, P_RADIUS / 2) == 0) return 1;
|
||||||
return 1;
|
if (circle_inout(x, y - P_RADIUS / 2, P_RADIUS / 2) == 0) return 1;
|
||||||
if (circle_inout(x, y-P_RADIUS/2, P_RADIUS/2) == 0)
|
|
||||||
return 1;
|
|
||||||
|
|
||||||
// Constant Resistance Circle: 3 : R/4 = P_RADIUS/4
|
// Constant Resistance Circle: 3 : R/4 = P_RADIUS/4
|
||||||
d = circle_inout(x+P_RADIUS/4, y, P_RADIUS/4);
|
d = circle_inout(x + P_RADIUS / 4, y, P_RADIUS / 4);
|
||||||
if (d > 0) return 0;
|
if (d > 0) return 0;
|
||||||
if (d == 0) return 1;
|
if (d == 0) return 1;
|
||||||
|
|
||||||
// Constant Reactance Circle: 1j : R = P_RADIUS
|
// Constant Reactance Circle: 1j : R = P_RADIUS
|
||||||
if (circle_inout(x, y+P_RADIUS, P_RADIUS) == 0)
|
if (circle_inout(x, y + P_RADIUS, P_RADIUS) == 0) return 1;
|
||||||
return 1;
|
if (circle_inout(x, y - P_RADIUS, P_RADIUS) == 0) return 1;
|
||||||
if (circle_inout(x, y-P_RADIUS, P_RADIUS) == 0)
|
|
||||||
return 1;
|
|
||||||
|
|
||||||
// Constant Resistance Circle: 1 : R/2
|
// Constant Resistance Circle: 1 : R/2
|
||||||
d = circle_inout(x+P_RADIUS/2, y, P_RADIUS/2);
|
d = circle_inout(x + P_RADIUS / 2, y, P_RADIUS / 2);
|
||||||
if (d > 0) return 0;
|
if (d > 0) return 0;
|
||||||
if (d == 0) return 1;
|
if (d == 0) return 1;
|
||||||
|
|
||||||
// Constant Reactance Circle: 1/2j : R*2
|
// Constant Reactance Circle: 1/2j : R*2
|
||||||
if (circle_inout(x, y+P_RADIUS*2, P_RADIUS*2) == 0)
|
if (circle_inout(x, y + P_RADIUS * 2, P_RADIUS * 2) == 0) return 1;
|
||||||
return 1;
|
if (circle_inout(x, y - P_RADIUS * 2, P_RADIUS * 2) == 0) return 1;
|
||||||
if (circle_inout(x, y-P_RADIUS*2, P_RADIUS*2) == 0)
|
|
||||||
return 1;
|
|
||||||
|
|
||||||
// Constant Resistance Circle: 1/3 : R*3/4
|
// Constant Resistance Circle: 1/3 : R*3/4
|
||||||
if (circle_inout(x+P_RADIUS*3/4, y, P_RADIUS*3/4) == 0)
|
if (circle_inout(x + P_RADIUS * 3 / 4, y, P_RADIUS * 3 / 4) == 0) return 1;
|
||||||
return 1;
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -354,9 +363,8 @@ rectangular_grid(int x, int y)
|
||||||
static int
|
static int
|
||||||
rectangular_grid_x(int x)
|
rectangular_grid_x(int x)
|
||||||
{
|
{
|
||||||
x-=CELLOFFSETX;
|
x -= CELLOFFSETX;
|
||||||
if (x < 0)
|
if (x < 0) return 0;
|
||||||
return 0;
|
|
||||||
if (x == 0 || x == WIDTH)
|
if (x == 0 || x == WIDTH)
|
||||||
return 1;
|
return 1;
|
||||||
if ((((x + grid_offset) * 10) % grid_width) < 10)
|
if ((((x + grid_offset) * 10) % grid_width) < 10)
|
||||||
|
|
@ -466,7 +474,8 @@ swr(const float *v)
|
||||||
}
|
}
|
||||||
|
|
||||||
static float
|
static float
|
||||||
resitance(const float *v) {
|
resitance(const float *v)
|
||||||
|
{
|
||||||
float z0 = 50;
|
float z0 = 50;
|
||||||
float d = z0 / ((1-v[0])*(1-v[0])+v[1]*v[1]);
|
float d = z0 / ((1-v[0])*(1-v[0])+v[1]*v[1]);
|
||||||
float zr = ((1+v[0])*(1-v[0]) - v[1]*v[1]) * d;
|
float zr = ((1+v[0])*(1-v[0]) - v[1]*v[1]) * d;
|
||||||
|
|
@ -474,7 +483,8 @@ resitance(const float *v) {
|
||||||
}
|
}
|
||||||
|
|
||||||
static float
|
static float
|
||||||
reactance(const float *v) {
|
reactance(const float *v)
|
||||||
|
{
|
||||||
float z0 = 50;
|
float z0 = 50;
|
||||||
float d = z0 / ((1-v[0])*(1-v[0])+v[1]*v[1]);
|
float d = z0 / ((1-v[0])*(1-v[0])+v[1]*v[1]);
|
||||||
float zi = 2*v[1] * d;
|
float zi = 2*v[1] * d;
|
||||||
|
|
@ -485,8 +495,8 @@ static void
|
||||||
cartesian_scale(float re, float im, int *xp, int *yp, float scale)
|
cartesian_scale(float re, float im, int *xp, int *yp, float scale)
|
||||||
{
|
{
|
||||||
//float scale = 4e-3;
|
//float scale = 4e-3;
|
||||||
int x = floatToInt(re * P_RADIUS * scale);
|
int x = float2int(re * P_RADIUS * scale);
|
||||||
int y = floatToInt(im * P_RADIUS * scale);
|
int y = float2int(im * P_RADIUS * scale);
|
||||||
if (x < -P_RADIUS) x = -P_RADIUS;
|
if (x < -P_RADIUS) x = -P_RADIUS;
|
||||||
else if (x > P_RADIUS) x = P_RADIUS;
|
else if (x > P_RADIUS) x = P_RADIUS;
|
||||||
if (y < -P_RADIUS) y = -P_RADIUS;
|
if (y < -P_RADIUS) y = -P_RADIUS;
|
||||||
|
|
@ -566,7 +576,7 @@ trace_into_index(int t, int i, float array[POINTS_COUNT][2])
|
||||||
if (v < 0) v = 0;
|
if (v < 0) v = 0;
|
||||||
if (v > NGRIDY) v = NGRIDY;
|
if (v > NGRIDY) v = NGRIDY;
|
||||||
x = (i * (WIDTH) + (sweep_points-1)/2) / (sweep_points-1) + CELLOFFSETX;
|
x = (i * (WIDTH) + (sweep_points-1)/2) / (sweep_points-1) + CELLOFFSETX;
|
||||||
y = floatToInt(v * GRIDY);
|
y = float2int(v * GRIDY);
|
||||||
set_index:
|
set_index:
|
||||||
return INDEX(x, y);
|
return INDEX(x, y);
|
||||||
}
|
}
|
||||||
|
|
@ -594,6 +604,7 @@ format_smith_value(char *buf, int len, const float coeff[2], uint32_t frequency)
|
||||||
plot_printf(buf, len, "%.1fdB %.1f" S_DEGREE, v, phase(coeff));
|
plot_printf(buf, len, "%.1fdB %.1f" S_DEGREE, v, phase(coeff));
|
||||||
}
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case MS_REIM:
|
case MS_REIM:
|
||||||
plot_printf(buf, len, "%F%+Fj", coeff[0], coeff[1]);
|
plot_printf(buf, len, "%F%+Fj", coeff[0], coeff[1]);
|
||||||
break;
|
break;
|
||||||
|
|
@ -603,11 +614,10 @@ format_smith_value(char *buf, int len, const float coeff[2], uint32_t frequency)
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case MS_RLC:
|
case MS_RLC:
|
||||||
if (zi < 0){// Capacity
|
if (zi < 0) {// Capacity
|
||||||
prefix = 'F';
|
prefix = 'F';
|
||||||
value = -1 / (2 * VNA_PI * frequency * zi);
|
value = -1 / (2 * VNA_PI * frequency * zi);
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
prefix = 'H';
|
prefix = 'H';
|
||||||
value = zi / (2 * VNA_PI * frequency);
|
value = zi / (2 * VNA_PI * frequency);
|
||||||
}
|
}
|
||||||
|
|
@ -698,8 +708,7 @@ trace_get_value_string_delta(int t, char *buf, int len, float array[POINTS_COUNT
|
||||||
case TRC_SWR:
|
case TRC_SWR:
|
||||||
format = S_DELTA"%.3f";
|
format = S_DELTA"%.3f";
|
||||||
v = swr(coeff);
|
v = swr(coeff);
|
||||||
if (v!=INFINITY)
|
if (v != INFINITY) v -= swr(coeff_ref);
|
||||||
v-=swr(coeff_ref);
|
|
||||||
break;
|
break;
|
||||||
case TRC_SMITH:
|
case TRC_SMITH:
|
||||||
format_smith_value(buf, len, coeff, frequencies[index]);
|
format_smith_value(buf, len, coeff, frequencies[index]);
|
||||||
|
|
@ -753,20 +762,23 @@ trace_get_info(int t, char *buf, int len)
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static float time_of_index(int idx) {
|
static float time_of_index(int idx)
|
||||||
return 1.0 / (float)(frequencies[1] - frequencies[0]) / (float)FFT_SIZE * idx;
|
{
|
||||||
|
return 1.0 / (float)(frequencies[1] - frequencies[0]) / (float)FFT_SIZE * idx;
|
||||||
}
|
}
|
||||||
|
|
||||||
static float distance_of_index(int idx) {
|
static float distance_of_index(int idx)
|
||||||
float distance = ((float)idx * (float)SPEED_OF_LIGHT) / ( (float)(frequencies[1] - frequencies[0]) * (float)FFT_SIZE * 2.0);
|
{
|
||||||
return distance * velocity_factor;
|
float distance = ((float)idx * (float)SPEED_OF_LIGHT) /
|
||||||
|
((float)(frequencies[1] - frequencies[0]) * (float)FFT_SIZE * 2.0);
|
||||||
|
return distance * velocity_factor;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void
|
static inline void
|
||||||
mark_map(int x, int y)
|
mark_map(int x, int y)
|
||||||
{
|
{
|
||||||
if (y >= 0 && y < MAX_MARKMAP_Y && x >= 0 && x < MAX_MARKMAP_X)
|
if (y >= 0 && y < MAX_MARKMAP_Y && x >= 0 && x < MAX_MARKMAP_X)
|
||||||
markmap[current_mappage][y] |= 1<<x;
|
markmap[current_mappage][y] |= 1 << x;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void
|
static inline void
|
||||||
|
|
@ -788,14 +800,15 @@ force_set_markmap(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
invalidateRect(int x0, int y0, int x1, int y1){
|
invalidate_rect(int x0, int y0, int x1, int y1)
|
||||||
x0/=CELLWIDTH;
|
{
|
||||||
x1/=CELLWIDTH;
|
x0 /= CELLWIDTH;
|
||||||
y0/=CELLHEIGHT;
|
x1 /= CELLWIDTH;
|
||||||
y1/=CELLHEIGHT;
|
y0 /= CELLHEIGHT;
|
||||||
|
y1 /= CELLHEIGHT;
|
||||||
int x, y;
|
int x, y;
|
||||||
for (y=y0; y<=y1; y++)
|
for (y = y0; y <= y1; y++)
|
||||||
for (x=x0; x<=x1; x++)
|
for (x = x0; x <= x1; x++)
|
||||||
mark_map(x, y);
|
mark_map(x, y);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -813,17 +826,17 @@ mark_cells_from_index(void)
|
||||||
index_t *index = &trace_index[t][0];
|
index_t *index = &trace_index[t][0];
|
||||||
int m0 = CELL_X(index[0]) / CELLWIDTH;
|
int m0 = CELL_X(index[0]) / CELLWIDTH;
|
||||||
int n0 = CELL_Y(index[0]) / CELLHEIGHT;
|
int n0 = CELL_Y(index[0]) / CELLHEIGHT;
|
||||||
map[n0]|= 1<<m0;
|
map[n0] |= 1 << m0;
|
||||||
for (i = 1; i < sweep_points; i++) {
|
for (i = 1; i < sweep_points; i++) {
|
||||||
int m1 = CELL_X(index[i]) / CELLWIDTH;
|
int m1 = CELL_X(index[i]) / CELLWIDTH;
|
||||||
int n1 = CELL_Y(index[i]) / CELLHEIGHT;
|
int n1 = CELL_Y(index[i]) / CELLHEIGHT;
|
||||||
if (m0 == m1 && n0 == n1)
|
if (m0 == m1 && n0 == n1)
|
||||||
continue;
|
continue;
|
||||||
int x0 = m0; int x1 = m1; if (x0>x1) SWAP(x0, x1); m0=m1;
|
int x0 = m0; int x1 = m1; if (x0>x1) SWAP(x0, x1); m0 = m1;
|
||||||
int y0 = n0; int y1 = n1; if (y0>y1) SWAP(y0, y1); n0=n1;
|
int y0 = n0; int y1 = n1; if (y0>y1) SWAP(y0, y1); n0 = n1;
|
||||||
for (; y0<=y1; y0++)
|
for (; y0 <= y1; y0++)
|
||||||
for(j=x0; j<=x1; j++)
|
for (j = x0; j <= x1; j++)
|
||||||
map[y0]|= 1<<j;
|
map[y0] |= 1 << j;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -832,7 +845,7 @@ static inline void
|
||||||
markmap_upperarea(void)
|
markmap_upperarea(void)
|
||||||
{
|
{
|
||||||
// Hardcoded, Text info from upper area
|
// Hardcoded, Text info from upper area
|
||||||
invalidateRect(0, 0, AREA_WIDTH_NORMAL, 31);
|
invalidate_rect(0, 0, AREA_WIDTH_NORMAL, 31);
|
||||||
}
|
}
|
||||||
|
|
||||||
//
|
//
|
||||||
|
|
@ -841,20 +854,20 @@ markmap_upperarea(void)
|
||||||
static inline void
|
static inline void
|
||||||
cell_drawline(int x0, int y0, int x1, int y1, int c)
|
cell_drawline(int x0, int y0, int x1, int y1, int c)
|
||||||
{
|
{
|
||||||
if (x0<0 && x1<0) return;
|
if (x0 < 0 && x1 < 0) return;
|
||||||
if (y0<0 && y1<0) return;
|
if (y0 < 0 && y1 < 0) return;
|
||||||
if (x0>=CELLWIDTH && x1>=CELLWIDTH )return;
|
if (x0 >= CELLWIDTH && x1 >= CELLWIDTH) return;
|
||||||
if (y0>=CELLHEIGHT && y1>=CELLHEIGHT)return;
|
if (y0 >= CELLHEIGHT && y1 >= CELLHEIGHT) return;
|
||||||
|
|
||||||
// modifed Bresenham's line algorithm, see https://en.wikipedia.org/wiki/Bresenham%27s_line_algorithm
|
// modifed Bresenham's line algorithm, see https://en.wikipedia.org/wiki/Bresenham%27s_line_algorithm
|
||||||
if (x1 < x0) {SWAP(x0,x1);SWAP(y0,y1);}
|
if (x1 < x0) { SWAP(x0, x1); SWAP(y0, y1); }
|
||||||
int dx = x1 - x0;
|
int dx = x1 - x0;
|
||||||
int dy = y1 - y0, sy = 1; if (dy < 0) {dy = -dy; sy = -1;}
|
int dy = y1 - y0, sy = 1; if (dy < 0) { dy = -dy; sy = -1; }
|
||||||
int err = (dx > dy ? dx : -dy) / 2;
|
int err = (dx > dy ? dx : -dy) / 2;
|
||||||
|
|
||||||
while (1){
|
while (1) {
|
||||||
if (y0>=0 && y0<CELLHEIGHT && x0>=0 && x0<CELLWIDTH)
|
if (y0 >= 0 && y0 < CELLHEIGHT && x0 >= 0 && x0 < CELLWIDTH)
|
||||||
cell_buffer[y0*CELLWIDTH+x0]|= c;
|
cell_buffer[y0 * CELLWIDTH + x0] |= c;
|
||||||
if (x0 == x1 && y0 == y1)
|
if (x0 == x1 && y0 == y1)
|
||||||
return;
|
return;
|
||||||
int e2 = err;
|
int e2 = err;
|
||||||
|
|
@ -877,12 +890,12 @@ search_index_range_x(int x1, int x2, index_t index[POINTS_COUNT], int *i0, int *
|
||||||
while (1) {
|
while (1) {
|
||||||
i = (head + tail) / 2;
|
i = (head + tail) / 2;
|
||||||
idx_x = CELL_X(index[i]);
|
idx_x = CELL_X(index[i]);
|
||||||
if (idx_x >= x2){ // index after cell
|
if (idx_x >= x2) { // index after cell
|
||||||
if (tail == i)
|
if (tail == i)
|
||||||
return false;
|
return false;
|
||||||
tail = i;
|
tail = i;
|
||||||
}
|
}
|
||||||
else if (idx_x < x1){ // index before cell
|
else if (idx_x < x1) { // index before cell
|
||||||
if (head == i)
|
if (head == i)
|
||||||
return false;
|
return false;
|
||||||
head = i;
|
head = i;
|
||||||
|
|
@ -892,14 +905,14 @@ search_index_range_x(int x1, int x2, index_t index[POINTS_COUNT], int *i0, int *
|
||||||
}
|
}
|
||||||
j = i;
|
j = i;
|
||||||
// Search index left from point
|
// Search index left from point
|
||||||
do{
|
do {
|
||||||
j--;
|
j--;
|
||||||
}while (j > 0 && x1 <= CELL_X(index[j]));
|
} while (j > 0 && x1 <= CELL_X(index[j]));
|
||||||
*i0 = j;
|
*i0 = j;
|
||||||
// Search index right from point
|
// Search index right from point
|
||||||
do{
|
do {
|
||||||
i++;
|
i++;
|
||||||
}while (i < sweep_points-1 && CELL_X(index[i]) < x2);
|
} while (i < sweep_points-1 && CELL_X(index[i]) < x2);
|
||||||
*i1 = i;
|
*i1 = i;
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
|
|
@ -922,17 +935,16 @@ static const uint8_t reference_bitmap[]={
|
||||||
static void
|
static void
|
||||||
draw_refpos(int x, int y, int c)
|
draw_refpos(int x, int y, int c)
|
||||||
{
|
{
|
||||||
int y0=y, j;
|
int y0 = y, j;
|
||||||
for (j=0; j<REFERENCE_HEIGHT; j++, y0++){
|
for (j = 0; j < REFERENCE_HEIGHT; j++, y0++) {
|
||||||
if (y0 < 0 || y0 >= CELLHEIGHT)
|
if (y0 < 0 || y0 >= CELLHEIGHT) continue;
|
||||||
continue;
|
int x0 = x;
|
||||||
int x0=x;
|
|
||||||
uint8_t bits = reference_bitmap[j];
|
uint8_t bits = reference_bitmap[j];
|
||||||
while (bits){
|
while (bits) {
|
||||||
if (x0 >= 0 && x0 < CELLWIDTH)
|
if (x0 >= 0 && x0 < CELLWIDTH)
|
||||||
cell_buffer[y0*CELLWIDTH+x0] = (bits&0x80) ? c : DEFAULT_BG_COLOR;
|
cell_buffer[y0 * CELLWIDTH + x0] = (bits & 0x80) ? c : DEFAULT_BG_COLOR;
|
||||||
x0++;
|
x0++;
|
||||||
bits<<=1;
|
bits <<= 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -991,22 +1003,21 @@ static const uint8_t marker_bitmap[]={
|
||||||
static void
|
static void
|
||||||
draw_marker(int x, int y, int c, int ch)
|
draw_marker(int x, int y, int c, int ch)
|
||||||
{
|
{
|
||||||
int y0=y, j;
|
int y0 = y, j;
|
||||||
for (j=0;j<MARKER_HEIGHT;j++,y0++){
|
for (j = 0; j < MARKER_HEIGHT; j++, y0++) {
|
||||||
int x0=x;
|
int x0 = x;
|
||||||
uint8_t bits = marker_bitmap[ch*MARKER_HEIGHT+j];
|
uint8_t bits = marker_bitmap[ch * MARKER_HEIGHT + j];
|
||||||
bool force_color = false;
|
bool force_color = false;
|
||||||
while (bits){
|
while (bits) {
|
||||||
if (bits&0x80)
|
if (bits & 0x80) force_color = true;
|
||||||
force_color = true;
|
if (x0 >= 0 && x0 < CELLWIDTH && y0 >= 0 && y0 < CELLHEIGHT) {
|
||||||
if (x0 >= 0 && x0 < CELLWIDTH && y0 >= 0 && y0 < CELLHEIGHT){
|
if (bits & 0x80)
|
||||||
if (bits&0x80)
|
cell_buffer[y0 * CELLWIDTH + x0] = c;
|
||||||
cell_buffer[y0*CELLWIDTH+x0] = c;
|
|
||||||
else if (force_color)
|
else if (force_color)
|
||||||
cell_buffer[y0*CELLWIDTH+x0] = DEFAULT_BG_COLOR;
|
cell_buffer[y0 * CELLWIDTH + x0] = DEFAULT_BG_COLOR;
|
||||||
}
|
}
|
||||||
x0++;
|
x0++;
|
||||||
bits<<=1;
|
bits <<= 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1023,7 +1034,7 @@ markmap_marker(int marker)
|
||||||
index_t index = trace_index[t][markers[marker].index];
|
index_t index = trace_index[t][markers[marker].index];
|
||||||
int x = CELL_X(index) - X_MARKER_OFFSET;
|
int x = CELL_X(index) - X_MARKER_OFFSET;
|
||||||
int y = CELL_Y(index) - Y_MARKER_OFFSET;
|
int y = CELL_Y(index) - Y_MARKER_OFFSET;
|
||||||
invalidateRect(x, y, x+MARKER_WIDTH-1, y+MARKER_HEIGHT-1);
|
invalidate_rect(x, y, x+MARKER_WIDTH-1, y+MARKER_HEIGHT-1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1211,14 +1222,14 @@ draw_cell(int m, int n)
|
||||||
#error "CELLWIDTH % 8 should be == 0 for speed, or need rewrite cell cleanup"
|
#error "CELLWIDTH % 8 should be == 0 for speed, or need rewrite cell cleanup"
|
||||||
#endif
|
#endif
|
||||||
// Set DEFAULT_BG_COLOR for 8 pixels in one cycle
|
// Set DEFAULT_BG_COLOR for 8 pixels in one cycle
|
||||||
int count = h*CELLWIDTH / (16/sizeof(pixel));
|
int count = h*CELLWIDTH / (16/sizeof(pixel_t));
|
||||||
uint32_t *p = (uint32_t *)cell_buffer;
|
uint32_t *p = (uint32_t *)cell_buffer;
|
||||||
while (count--) {
|
while (count--) {
|
||||||
p[0] = DEFAULT_BG_COLOR|(DEFAULT_BG_COLOR<<16);
|
p[0] = DEFAULT_BG_COLOR | (DEFAULT_BG_COLOR << 16);
|
||||||
p[1] = DEFAULT_BG_COLOR|(DEFAULT_BG_COLOR<<16);
|
p[1] = DEFAULT_BG_COLOR | (DEFAULT_BG_COLOR << 16);
|
||||||
p[2] = DEFAULT_BG_COLOR|(DEFAULT_BG_COLOR<<16);
|
p[2] = DEFAULT_BG_COLOR | (DEFAULT_BG_COLOR << 16);
|
||||||
p[3] = DEFAULT_BG_COLOR|(DEFAULT_BG_COLOR<<16);
|
p[3] = DEFAULT_BG_COLOR | (DEFAULT_BG_COLOR << 16);
|
||||||
p+=4;
|
p += 4;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
@ -1227,41 +1238,40 @@ draw_cell(int m, int n)
|
||||||
c = config.grid_color;
|
c = config.grid_color;
|
||||||
// Generate grid type list
|
// Generate grid type list
|
||||||
uint32_t trace_type = 0;
|
uint32_t trace_type = 0;
|
||||||
for (t = 0; t < TRACES_MAX; t++)
|
for (t = 0; t < TRACES_MAX; t++) {
|
||||||
if (trace[t].enabled)
|
if (trace[t].enabled) {
|
||||||
trace_type|=(1<<trace[t].type);
|
trace_type |= (1 << trace[t].type);
|
||||||
|
}
|
||||||
|
}
|
||||||
// Draw rectangular plot (40 system ticks for all screen calls)
|
// Draw rectangular plot (40 system ticks for all screen calls)
|
||||||
if (trace_type&RECTANGULAR_GRID_MASK){
|
if (trace_type & RECTANGULAR_GRID_MASK) {
|
||||||
for (x = 0; x < w; x++) {
|
for (x = 0; x < w; x++) {
|
||||||
if (rectangular_grid_x(x+x0)){
|
if (rectangular_grid_x(x + x0)) {
|
||||||
for (y = 0; y < h; y++)
|
for (y = 0; y < h; y++) cell_buffer[y * CELLWIDTH + x] = c;
|
||||||
cell_buffer[y * CELLWIDTH + x] = c;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (y = 0; y < h; y++) {
|
for (y = 0; y < h; y++) {
|
||||||
if (rectangular_grid_y(y+y0)){
|
if (rectangular_grid_y(y + y0)) {
|
||||||
for (x = 0; x < w; x++)
|
for (x = 0; x < w; x++)
|
||||||
if (x+x0 >= CELLOFFSETX && x+x0 <= WIDTH+CELLOFFSETX)
|
if (x + x0 >= CELLOFFSETX && x + x0 <= WIDTH + CELLOFFSETX)
|
||||||
cell_buffer[y * CELLWIDTH + x] = c;
|
cell_buffer[y * CELLWIDTH + x] = c;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Smith greed line (1000 system ticks for all screen calls)
|
// Smith greed line (1000 system ticks for all screen calls)
|
||||||
if(trace_type&(1<<TRC_SMITH)){
|
if (trace_type & (1 << TRC_SMITH)) {
|
||||||
for (y = 0; y < h; y++)
|
for (y = 0; y < h; y++)
|
||||||
for (x = 0; x < w; x++)
|
for (x = 0; x < w; x++)
|
||||||
if (smith_grid(x+x0, y+y0))
|
if (smith_grid(x + x0, y + y0)) cell_buffer[y * CELLWIDTH + x] = c;
|
||||||
cell_buffer[y * CELLWIDTH + x] = c;
|
|
||||||
}
|
}
|
||||||
// Polar greed line (800 system ticks for all screen calls)
|
// Polar greed line (800 system ticks for all screen calls)
|
||||||
else if(trace_type&(1<<TRC_POLAR)){
|
else if (trace_type & (1 << TRC_POLAR)) {
|
||||||
for (y = 0; y < h; y++)
|
for (y = 0; y < h; y++)
|
||||||
for (x = 0; x < w; x++)
|
for (x = 0; x < w; x++)
|
||||||
if (polar_grid(x+x0, y+y0))
|
if (polar_grid(x + x0, y + y0)) cell_buffer[y * CELLWIDTH + x] = c;
|
||||||
cell_buffer[y * CELLWIDTH + x] = c;
|
|
||||||
}
|
}
|
||||||
#if 0
|
#if 0
|
||||||
else if(trace_type&(1<<TRC_ADMIT)){
|
else if (trace_type & (1 << TRC_ADMIT)) {
|
||||||
for (y = 0; y < h; y++)
|
for (y = 0; y < h; y++)
|
||||||
for (x = 0; x < w; x++)
|
for (x = 0; x < w; x++)
|
||||||
if (smith_grid3(x+x0, y+y0)
|
if (smith_grid3(x+x0, y+y0)
|
||||||
|
|
@ -1271,34 +1281,38 @@ draw_cell(int m, int n)
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
// PULSE;
|
// PULSE;
|
||||||
// Draw traces (50-600 system ticks for all screen calls, depend from lines count and size)
|
// Draw traces (50-600 system ticks for all screen calls, depend from lines
|
||||||
|
// count and size)
|
||||||
#if 1
|
#if 1
|
||||||
for (t = 0; t < TRACES_MAX; t++) {
|
for (t = 0; t < TRACES_MAX; t++) {
|
||||||
if (!trace[t].enabled)
|
if (!trace[t].enabled)
|
||||||
continue;
|
continue;
|
||||||
c = config.trace_color[t];
|
c = config.trace_color[t];
|
||||||
// draw polar plot (check all points)
|
// draw polar plot (check all points)
|
||||||
i0 = 0; i1=0;
|
i0 = 0;
|
||||||
uint32_t trace_type = (1<<trace[t].type);
|
i1 = 0;
|
||||||
if (trace_type & ((1<<TRC_SMITH)|(1<<TRC_POLAR)))
|
uint32_t trace_type = (1 << trace[t].type);
|
||||||
i1 = sweep_points-1;
|
if (trace_type & ((1 << TRC_SMITH) | (1 << TRC_POLAR)))
|
||||||
else // draw rectangular plot (search index range in cell, save 50-70 system ticks for all screen calls)
|
i1 = sweep_points - 1;
|
||||||
search_index_range_x(x0, x0+w, trace_index[t], &i0, &i1);
|
else // draw rectangular plot (search index range in cell, save 50-70
|
||||||
|
// system ticks for all screen calls)
|
||||||
|
search_index_range_x(x0, x0 + w, trace_index[t], &i0, &i1);
|
||||||
index_t *index = trace_index[t];
|
index_t *index = trace_index[t];
|
||||||
for (i=i0; i < i1; i++) {
|
for (i = i0; i < i1; i++) {
|
||||||
int x1 = CELL_X(index[i ]) - x0;
|
int x1 = CELL_X(index[i]) - x0;
|
||||||
int y1 = CELL_Y(index[i ]) - y0;
|
int y1 = CELL_Y(index[i]) - y0;
|
||||||
int x2 = CELL_X(index[i+1]) - x0;
|
int x2 = CELL_X(index[i + 1]) - x0;
|
||||||
int y2 = CELL_Y(index[i+1]) - y0;
|
int y2 = CELL_Y(index[i + 1]) - y0;
|
||||||
cell_drawline(x1, y1, x2, y2, c);
|
cell_drawline(x1, y1, x2, y2, c);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#else
|
#else
|
||||||
for (x=0;x<area_width;x+=6)
|
for (x = 0; x < area_width; x += 6)
|
||||||
cell_drawline(x-x0, 0-y0, area_width-x-x0, area_height-y0, config.trace_color[0]);
|
cell_drawline(x - x0, 0 - y0, area_width - x - x0, area_height - y0,
|
||||||
|
config.trace_color[0]);
|
||||||
#endif
|
#endif
|
||||||
// PULSE;
|
// PULSE;
|
||||||
//draw marker symbols on each trace (<10 system ticks for all screen calls)
|
// draw marker symbols on each trace (<10 system ticks for all screen calls)
|
||||||
#if 1
|
#if 1
|
||||||
for (i = 0; i < MARKERS_MAX; i++) {
|
for (i = 0; i < MARKERS_MAX; i++) {
|
||||||
if (!markers[i].enabled)
|
if (!markers[i].enabled)
|
||||||
|
|
@ -1310,7 +1324,8 @@ draw_cell(int m, int n)
|
||||||
int x = CELL_X(index) - x0 - X_MARKER_OFFSET;
|
int x = CELL_X(index) - x0 - X_MARKER_OFFSET;
|
||||||
int y = CELL_Y(index) - y0 - Y_MARKER_OFFSET;
|
int y = CELL_Y(index) - y0 - Y_MARKER_OFFSET;
|
||||||
// Check marker icon on cell
|
// Check marker icon on cell
|
||||||
if (x+MARKER_WIDTH>=0 && x-MARKER_WIDTH<CELLWIDTH && y+MARKER_HEIGHT>=0 && y-MARKER_HEIGHT<CELLHEIGHT)
|
if (x + MARKER_WIDTH >= 0 && x - MARKER_WIDTH < CELLWIDTH &&
|
||||||
|
y + MARKER_HEIGHT >= 0 && y - MARKER_HEIGHT < CELLHEIGHT)
|
||||||
draw_marker(x, y, config.trace_color[t], i);
|
draw_marker(x, y, config.trace_color[t], i);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1325,24 +1340,24 @@ draw_cell(int m, int n)
|
||||||
for (t = 0; t < TRACES_MAX; t++) {
|
for (t = 0; t < TRACES_MAX; t++) {
|
||||||
if (!trace[t].enabled)
|
if (!trace[t].enabled)
|
||||||
continue;
|
continue;
|
||||||
uint32_t trace_type = (1<<trace[t].type);
|
uint32_t trace_type = (1 << trace[t].type);
|
||||||
if (trace_type&((1<<TRC_SMITH)|(1<<TRC_POLAR)))
|
if (trace_type & ((1 << TRC_SMITH) | (1 << TRC_POLAR)))
|
||||||
continue;
|
continue;
|
||||||
int x = 0 - x0 + CELLOFFSETX - REFERENCE_X_OFFSET;
|
int x = 0 - x0 + CELLOFFSETX - REFERENCE_X_OFFSET;
|
||||||
if (x+REFERENCE_WIDTH>=0 && x-REFERENCE_WIDTH<CELLWIDTH){
|
if (x + REFERENCE_WIDTH >= 0 && x - REFERENCE_WIDTH < CELLWIDTH) {
|
||||||
int y = HEIGHT - floatToInt((get_trace_refpos(t) * GRIDY)) - y0 - REFERENCE_Y_OFFSET;
|
int y = HEIGHT - float2int((get_trace_refpos(t) * GRIDY)) - y0 - REFERENCE_Y_OFFSET;
|
||||||
if (y+REFERENCE_HEIGHT>=0 && y-REFERENCE_HEIGHT<CELLHEIGHT)
|
if (y + REFERENCE_HEIGHT >= 0 && y - REFERENCE_HEIGHT < CELLHEIGHT)
|
||||||
draw_refpos(x, y, config.trace_color[t]);
|
draw_refpos(x, y, config.trace_color[t]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Need right clip cell render (25 system ticks for all screen calls)
|
// Need right clip cell render (25 system ticks for all screen calls)
|
||||||
#if 1
|
#if 1
|
||||||
if (w < CELLWIDTH){
|
if (w < CELLWIDTH) {
|
||||||
pixel *src = cell_buffer+CELLWIDTH;
|
pixel_t *src = cell_buffer + CELLWIDTH;
|
||||||
pixel *dst = cell_buffer+w;
|
pixel_t *dst = cell_buffer + w;
|
||||||
for (y=h; --y; src+=CELLWIDTH-w)
|
for (y = h; --y; src += CELLWIDTH - w)
|
||||||
for(x=w;x--;)
|
for (x = w; x--;)
|
||||||
*dst++=*src++;
|
*dst++ = *src++;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
// Draw cell (500 system ticks for all screen calls)
|
// Draw cell (500 system ticks for all screen calls)
|
||||||
|
|
@ -1350,12 +1365,13 @@ draw_cell(int m, int n)
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
draw_all_cells(bool flush_markmap){
|
draw_all_cells(bool flush_markmap)
|
||||||
|
{
|
||||||
int m, n;
|
int m, n;
|
||||||
// START_PROFILE
|
// START_PROFILE
|
||||||
for (m = 0; m < (area_width+CELLWIDTH-1) / CELLWIDTH; m++)
|
for (m = 0; m < (area_width+CELLWIDTH-1) / CELLWIDTH; m++)
|
||||||
for (n = 0; n < (area_height+CELLHEIGHT-1) / CELLHEIGHT; n++) {
|
for (n = 0; n < (area_height+CELLHEIGHT-1) / CELLHEIGHT; n++) {
|
||||||
if ((markmap[0][n] | markmap[1][n]) & (1<<m)){
|
if ((markmap[0][n] | markmap[1][n]) & (1 << m)) {
|
||||||
draw_cell(m, n);
|
draw_cell(m, n);
|
||||||
// ili9341_fill(m*CELLWIDTH+10, n*CELLHEIGHT, 2, 2, RGB565(255,0,0));
|
// ili9341_fill(m*CELLWIDTH+10, n*CELLHEIGHT, 2, 2, RGB565(255,0,0));
|
||||||
}
|
}
|
||||||
|
|
@ -1412,7 +1428,7 @@ void
|
||||||
request_to_draw_cells_behind_menu(void)
|
request_to_draw_cells_behind_menu(void)
|
||||||
{
|
{
|
||||||
// Values Hardcoded from ui.c
|
// Values Hardcoded from ui.c
|
||||||
invalidateRect(320-70, 0, 319, 239);
|
invalidate_rect(320-70, 0, 319, 239);
|
||||||
redraw_request |= REDRAW_CELLS;
|
redraw_request |= REDRAW_CELLS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1420,7 +1436,7 @@ void
|
||||||
request_to_draw_cells_behind_numeric_input(void)
|
request_to_draw_cells_behind_numeric_input(void)
|
||||||
{
|
{
|
||||||
// Values Hardcoded from ui.c
|
// Values Hardcoded from ui.c
|
||||||
invalidateRect(0, 240-32, 319, 239);
|
invalidate_rect(0, 240-32, 319, 239);
|
||||||
redraw_request |= REDRAW_CELLS;
|
redraw_request |= REDRAW_CELLS;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -1430,12 +1446,12 @@ cell_drawchar(uint8_t ch, int x, int y)
|
||||||
uint8_t bits;
|
uint8_t bits;
|
||||||
int c, r, ch_size;
|
int c, r, ch_size;
|
||||||
const uint8_t *char_buf = FONT_GET_DATA(ch);
|
const uint8_t *char_buf = FONT_GET_DATA(ch);
|
||||||
ch_size=FONT_GET_WIDTH(ch);
|
ch_size = FONT_GET_WIDTH(ch);
|
||||||
// if (y <= -FONT_GET_HEIGHT || y >= CELLHEIGHT || x <= -ch_size || x >= CELLWIDTH)
|
// if (y <= -FONT_GET_HEIGHT || y >= CELLHEIGHT || x <= -ch_size || x >= CELLWIDTH)
|
||||||
// return ch_size;
|
// return ch_size;
|
||||||
if (x <= -ch_size)
|
if (x <= -ch_size)
|
||||||
return ch_size;
|
return ch_size;
|
||||||
for(c = 0; c < FONT_GET_HEIGHT; c++) {
|
for (c = 0; c < FONT_GET_HEIGHT; c++) {
|
||||||
bits = *char_buf++;
|
bits = *char_buf++;
|
||||||
if ((y + c) < 0 || (y + c) >= CELLHEIGHT)
|
if ((y + c) < 0 || (y + c) >= CELLHEIGHT)
|
||||||
continue;
|
continue;
|
||||||
|
|
@ -1478,7 +1494,7 @@ cell_draw_marker_info(int x0, int y0)
|
||||||
int xpos = 1 + (j%2)*(WIDTH/2) + CELLOFFSETX - x0;
|
int xpos = 1 + (j%2)*(WIDTH/2) + CELLOFFSETX - x0;
|
||||||
int ypos = 1 + (j/2)*(FONT_GET_HEIGHT+1) - y0;
|
int ypos = 1 + (j/2)*(FONT_GET_HEIGHT+1) - y0;
|
||||||
|
|
||||||
setForegroundColor(config.trace_color[t]);
|
ili9341_set_foreground(config.trace_color[t]);
|
||||||
if (mk == active_marker)
|
if (mk == active_marker)
|
||||||
cell_drawstring(S_SARROW, xpos, ypos);
|
cell_drawstring(S_SARROW, xpos, ypos);
|
||||||
xpos += 5;
|
xpos += 5;
|
||||||
|
|
@ -1500,7 +1516,7 @@ cell_draw_marker_info(int x0, int y0)
|
||||||
trace_get_value_string_delta(t, buf, sizeof buf, measured[trace[t].channel], markers[mk].index, markers[active_marker].index);
|
trace_get_value_string_delta(t, buf, sizeof buf, measured[trace[t].channel], markers[mk].index, markers[active_marker].index);
|
||||||
else
|
else
|
||||||
trace_get_value_string(t, buf, sizeof buf, measured[trace[t].channel], markers[mk].index);
|
trace_get_value_string(t, buf, sizeof buf, measured[trace[t].channel], markers[mk].index);
|
||||||
setForegroundColor(DEFAULT_FG_COLOR);
|
ili9341_set_foreground(DEFAULT_FG_COLOR);
|
||||||
cell_drawstring(buf, xpos, ypos);
|
cell_drawstring(buf, xpos, ypos);
|
||||||
j++;
|
j++;
|
||||||
}
|
}
|
||||||
|
|
@ -1512,7 +1528,7 @@ cell_draw_marker_info(int x0, int y0)
|
||||||
int ypos = 1 + (j/2)*(FONT_GET_HEIGHT+1) - y0;
|
int ypos = 1 + (j/2)*(FONT_GET_HEIGHT+1) - y0;
|
||||||
|
|
||||||
plot_printf(buf, sizeof buf, S_DELTA"%d-%d:", active_marker+1, previous_marker+1);
|
plot_printf(buf, sizeof buf, S_DELTA"%d-%d:", active_marker+1, previous_marker+1);
|
||||||
setForegroundColor(DEFAULT_FG_COLOR);
|
ili9341_set_foreground(DEFAULT_FG_COLOR);
|
||||||
cell_drawstring(buf, xpos, ypos);
|
cell_drawstring(buf, xpos, ypos);
|
||||||
xpos += 27;
|
xpos += 27;
|
||||||
if ((domain_mode & DOMAIN_MODE) == DOMAIN_FREQ) {
|
if ((domain_mode & DOMAIN_MODE) == DOMAIN_FREQ) {
|
||||||
|
|
@ -1532,7 +1548,7 @@ cell_draw_marker_info(int x0, int y0)
|
||||||
int xpos = 1 + (j%2)*(WIDTH/2) + CELLOFFSETX - x0;
|
int xpos = 1 + (j%2)*(WIDTH/2) + CELLOFFSETX - x0;
|
||||||
int ypos = 1 + (j/2)*(FONT_GET_HEIGHT+1) - y0;
|
int ypos = 1 + (j/2)*(FONT_GET_HEIGHT+1) - y0;
|
||||||
|
|
||||||
setForegroundColor(config.trace_color[t]);
|
ili9341_set_foreground(config.trace_color[t]);
|
||||||
if (t == uistat.current_trace)
|
if (t == uistat.current_trace)
|
||||||
cell_drawstring(S_SARROW, xpos, ypos);
|
cell_drawstring(S_SARROW, xpos, ypos);
|
||||||
xpos += 5;
|
xpos += 5;
|
||||||
|
|
@ -1545,7 +1561,7 @@ cell_draw_marker_info(int x0, int y0)
|
||||||
xpos += n * 5 + 2;
|
xpos += n * 5 + 2;
|
||||||
//xpos += 60;
|
//xpos += 60;
|
||||||
trace_get_value_string(t, buf, sizeof buf, measured[trace[t].channel], idx);
|
trace_get_value_string(t, buf, sizeof buf, measured[trace[t].channel], idx);
|
||||||
setForegroundColor(DEFAULT_FG_COLOR);
|
ili9341_set_foreground(DEFAULT_FG_COLOR);
|
||||||
cell_drawstring(buf, xpos, ypos);
|
cell_drawstring(buf, xpos, ypos);
|
||||||
j++;
|
j++;
|
||||||
}
|
}
|
||||||
|
|
@ -1554,7 +1570,7 @@ cell_draw_marker_info(int x0, int y0)
|
||||||
int xpos = (WIDTH/2+40) + CELLOFFSETX - x0;
|
int xpos = (WIDTH/2+40) + CELLOFFSETX - x0;
|
||||||
int ypos = 1 + (j/2)*(FONT_GET_HEIGHT+1) - y0;
|
int ypos = 1 + (j/2)*(FONT_GET_HEIGHT+1) - y0;
|
||||||
|
|
||||||
setForegroundColor(DEFAULT_FG_COLOR);
|
ili9341_set_foreground(DEFAULT_FG_COLOR);
|
||||||
if (uistat.lever_mode == LM_MARKER)
|
if (uistat.lever_mode == LM_MARKER)
|
||||||
cell_drawstring(S_SARROW, xpos, ypos);
|
cell_drawstring(S_SARROW, xpos, ypos);
|
||||||
xpos += 5;
|
xpos += 5;
|
||||||
|
|
@ -1569,7 +1585,7 @@ cell_draw_marker_info(int x0, int y0)
|
||||||
}
|
}
|
||||||
cell_drawstring(buf, xpos, ypos);
|
cell_drawstring(buf, xpos, ypos);
|
||||||
}
|
}
|
||||||
setForegroundColor(DEFAULT_FG_COLOR);
|
ili9341_set_foreground(DEFAULT_FG_COLOR);
|
||||||
if (electrical_delay != 0) {
|
if (electrical_delay != 0) {
|
||||||
// draw electrical delay
|
// draw electrical delay
|
||||||
int xpos = 21 + CELLOFFSETX - x0;
|
int xpos = 21 + CELLOFFSETX - x0;
|
||||||
|
|
@ -1590,9 +1606,9 @@ void
|
||||||
draw_frequencies(void)
|
draw_frequencies(void)
|
||||||
{
|
{
|
||||||
char buf1[32];
|
char buf1[32];
|
||||||
char buf2[32];buf2[0]=0;
|
char buf2[32]; buf2[0] = 0;
|
||||||
if ((domain_mode & DOMAIN_MODE) == DOMAIN_FREQ) {
|
if ((domain_mode & DOMAIN_MODE) == DOMAIN_FREQ) {
|
||||||
if (FREQ_IS_CW()){
|
if (FREQ_IS_CW()) {
|
||||||
plot_printf(buf1, sizeof(buf1), " CW %qHz", get_sweep_frequency(ST_CW));
|
plot_printf(buf1, sizeof(buf1), " CW %qHz", get_sweep_frequency(ST_CW));
|
||||||
} else if (FREQ_IS_STARTSTOP()) {
|
} else if (FREQ_IS_STARTSTOP()) {
|
||||||
plot_printf(buf1, sizeof(buf1), " START %qHz", get_sweep_frequency(ST_START));
|
plot_printf(buf1, sizeof(buf1), " START %qHz", get_sweep_frequency(ST_START));
|
||||||
|
|
@ -1605,8 +1621,8 @@ draw_frequencies(void)
|
||||||
plot_printf(buf1, sizeof(buf1), " START 0s");
|
plot_printf(buf1, sizeof(buf1), " START 0s");
|
||||||
plot_printf(buf2, sizeof(buf2), "STOP %Fs (%Fm)", time_of_index(sweep_points-1), distance_of_index(sweep_points-1));
|
plot_printf(buf2, sizeof(buf2), "STOP %Fs (%Fm)", time_of_index(sweep_points-1), distance_of_index(sweep_points-1));
|
||||||
}
|
}
|
||||||
setForegroundColor(DEFAULT_FG_COLOR);
|
ili9341_set_foreground(DEFAULT_FG_COLOR);
|
||||||
setBackgroundColor(DEFAULT_BG_COLOR);
|
ili9341_set_background(DEFAULT_BG_COLOR);
|
||||||
ili9341_fill(0, FREQUENCIES_YPOS, 320, FONT_GET_HEIGHT, DEFAULT_BG_COLOR);
|
ili9341_fill(0, FREQUENCIES_YPOS, 320, FONT_GET_HEIGHT, DEFAULT_BG_COLOR);
|
||||||
if (uistat.lever_mode == LM_CENTER)
|
if (uistat.lever_mode == LM_CENTER)
|
||||||
buf1[0] = S_SARROW[0];
|
buf1[0] = S_SARROW[0];
|
||||||
|
|
@ -1622,8 +1638,8 @@ draw_cal_status(void)
|
||||||
int x = 0;
|
int x = 0;
|
||||||
int y = 100;
|
int y = 100;
|
||||||
char c[3];
|
char c[3];
|
||||||
setForegroundColor(DEFAULT_FG_COLOR);
|
ili9341_set_foreground(DEFAULT_FG_COLOR);
|
||||||
setBackgroundColor(DEFAULT_BG_COLOR);
|
ili9341_set_background(DEFAULT_BG_COLOR);
|
||||||
ili9341_fill(0, y, OFFSETX, 6*(FONT_GET_HEIGHT+1), DEFAULT_BG_COLOR);
|
ili9341_fill(0, y, OFFSETX, 6*(FONT_GET_HEIGHT+1), DEFAULT_BG_COLOR);
|
||||||
if (cal_status & CALSTAT_APPLY) {
|
if (cal_status & CALSTAT_APPLY) {
|
||||||
c[0] = cal_status & CALSTAT_INTERPOLATED ? 'c' : 'C';
|
c[0] = cal_status & CALSTAT_INTERPOLATED ? 'c' : 'C';
|
||||||
|
|
@ -1657,13 +1673,13 @@ static void draw_battery_status(void)
|
||||||
return;
|
return;
|
||||||
uint8_t string_buf[16];
|
uint8_t string_buf[16];
|
||||||
// Set battery color
|
// Set battery color
|
||||||
setForegroundColor(vbat < BATTERY_WARNING_LEVEL ? DEFAULT_LOW_BAT_COLOR : DEFAULT_NORMAL_BAT_COLOR);
|
ili9341_set_foreground(vbat < BATTERY_WARNING_LEVEL ? DEFAULT_LOW_BAT_COLOR : DEFAULT_NORMAL_BAT_COLOR);
|
||||||
setBackgroundColor(DEFAULT_BG_COLOR);
|
ili9341_set_background(DEFAULT_BG_COLOR);
|
||||||
// plot_printf(string_buf, sizeof string_buf, "V:%d", vbat);
|
// plot_printf(string_buf, sizeof string_buf, "V:%d", vbat);
|
||||||
// ili9341_drawstringV(string_buf, 1, 60);
|
// ili9341_drawstringV(string_buf, 1, 60);
|
||||||
// Prepare battery bitmap image
|
// Prepare battery bitmap image
|
||||||
// Battery top
|
// Battery top
|
||||||
int x=0;
|
int x = 0;
|
||||||
string_buf[x++] = 0b00111100;
|
string_buf[x++] = 0b00111100;
|
||||||
string_buf[x++] = 0b00100100;
|
string_buf[x++] = 0b00100100;
|
||||||
string_buf[x++] = 0b11111111;
|
string_buf[x++] = 0b11111111;
|
||||||
|
|
@ -1689,8 +1705,8 @@ request_to_redraw_grid(void)
|
||||||
void
|
void
|
||||||
redraw_frame(void)
|
redraw_frame(void)
|
||||||
{
|
{
|
||||||
setBackgroundColor(DEFAULT_BG_COLOR);
|
ili9341_set_background(DEFAULT_BG_COLOR);
|
||||||
clearScreen();
|
ili9341_clear_screen();
|
||||||
draw_frequencies();
|
draw_frequencies();
|
||||||
draw_cal_status();
|
draw_cal_status();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
160
si5351.c
160
si5351.c
|
|
@ -34,7 +34,7 @@
|
||||||
#define PLL_N 32
|
#define PLL_N 32
|
||||||
|
|
||||||
// I2C address on bus (only 0x60 for Si5351A in 10-Pin MSOP)
|
// I2C address on bus (only 0x60 for Si5351A in 10-Pin MSOP)
|
||||||
#define SI5351_I2C_ADDR 0x60
|
#define SI5351_I2C_ADDR 0x60
|
||||||
|
|
||||||
static uint8_t current_band = 0;
|
static uint8_t current_band = 0;
|
||||||
static uint32_t current_freq = 0;
|
static uint32_t current_freq = 0;
|
||||||
|
|
@ -51,9 +51,13 @@ static int32_t current_offset = FREQUENCY_OFFSET;
|
||||||
// Delay after set new PLL values, and send reset (on band 1 unstable if less then 900, on 4000-5000 no amplitude spike on change)
|
// Delay after set new PLL values, and send reset (on band 1 unstable if less then 900, on 4000-5000 no amplitude spike on change)
|
||||||
#define DELAY_RESET_PLL 5000
|
#define DELAY_RESET_PLL 5000
|
||||||
|
|
||||||
uint32_t si5351_getFrequency(void) {return current_freq;}
|
uint32_t si5351_get_frequency(void)
|
||||||
|
{
|
||||||
|
return current_freq;
|
||||||
|
}
|
||||||
|
|
||||||
void si5351_set_frequency_offset(int32_t offset) {
|
void si5351_set_frequency_offset(int32_t offset)
|
||||||
|
{
|
||||||
current_offset = offset;
|
current_offset = offset;
|
||||||
current_freq = 0; // reset freq, for
|
current_freq = 0; // reset freq, for
|
||||||
}
|
}
|
||||||
|
|
@ -178,34 +182,34 @@ static void si5351_setupPLL(uint8_t pllSource, /* SI5351_REG_PLL_A or SI5351_
|
||||||
/* Feedback Multisynth Divider Equation
|
/* Feedback Multisynth Divider Equation
|
||||||
* where: a = mult, b = num and c = denom
|
* where: a = mult, b = num and c = denom
|
||||||
* P1 register is an 18-bit value using following formula:
|
* P1 register is an 18-bit value using following formula:
|
||||||
* P1[17:0] = 128 * mult + int((128*num)/denom) - 512
|
* P1[17:0] = 128 * mult + int((128*num)/denom) - 512
|
||||||
* P2 register is a 20-bit value using the following formula:
|
* P2 register is a 20-bit value using the following formula:
|
||||||
* P2[19:0] = (128 * num) % denom
|
* P2[19:0] = (128 * num) % denom
|
||||||
* P3 register is a 20-bit value using the following formula:
|
* P3 register is a 20-bit value using the following formula:
|
||||||
* P3[19:0] = denom
|
* P3[19:0] = denom
|
||||||
*/
|
*/
|
||||||
/* Set the main PLL config registers */
|
/* Set the main PLL config registers */
|
||||||
mult<<=7;
|
mult <<= 7;
|
||||||
num<<=7;
|
num <<= 7;
|
||||||
uint32_t P1 = mult - 512; // Integer mode
|
uint32_t P1 = mult - 512; // Integer mode
|
||||||
uint32_t P2 = 0;
|
uint32_t P2 = 0;
|
||||||
uint32_t P3 = 1;
|
uint32_t P3 = 1;
|
||||||
if (num){ // Fractional mode
|
if (num) { // Fractional mode
|
||||||
P1+= num / denom;
|
P1+= num / denom;
|
||||||
P2 = num % denom;
|
P2 = num % denom;
|
||||||
P3 = denom;
|
P3 = denom;
|
||||||
}
|
}
|
||||||
// Pll MSN(A|B) registers Datasheet
|
// Pll MSN(A|B) registers Datasheet
|
||||||
uint8_t reg[9];
|
uint8_t reg[9];
|
||||||
reg[0]= pllSource; // SI5351_REG_PLL_A or SI5351_REG_PLL_B
|
reg[0] = pllSource; // SI5351_REG_PLL_A or SI5351_REG_PLL_B
|
||||||
reg[1]=( P3 & 0x0FF00)>> 8; // MSN_P3[15: 8]
|
reg[1] = (P3 & 0x0FF00) >> 8; // MSN_P3[15: 8]
|
||||||
reg[2]=( P3 & 0x000FF); // MSN_P3[ 7: 0]
|
reg[2] = (P3 & 0x000FF); // MSN_P3[ 7: 0]
|
||||||
reg[3]=( P1 & 0x30000)>>16; // MSN_P1[17:16]
|
reg[3] = (P1 & 0x30000) >> 16; // MSN_P1[17:16]
|
||||||
reg[4]=( P1 & 0x0FF00)>> 8; // MSN_P1[15: 8]
|
reg[4] = (P1 & 0x0FF00) >> 8; // MSN_P1[15: 8]
|
||||||
reg[5]=( P1 & 0x000FF); // MSN_P1[ 7: 0]
|
reg[5] = (P1 & 0x000FF); // MSN_P1[ 7: 0]
|
||||||
reg[6]=((P3 & 0xF0000)>>12)|((P2 & 0xF0000)>>16); // MSN_P3[19:16] | MSN_P2[19:16]
|
reg[6] = ((P3 & 0xF0000) >> 12) | ((P2 & 0xF0000) >> 16); // MSN_P3[19:16] | MSN_P2[19:16]
|
||||||
reg[7]=( P2 & 0x0FF00)>> 8; // MSN_P2[15: 8]
|
reg[7] = (P2 & 0x0FF00) >> 8; // MSN_P2[15: 8]
|
||||||
reg[8]=( P2 & 0x000FF); // MSN_P2[ 7: 0]
|
reg[8] = (P2 & 0x000FF); // MSN_P2[ 7: 0]
|
||||||
si5351_bulk_write(reg, 9);
|
si5351_bulk_write(reg, 9);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -237,7 +241,7 @@ si5351_setupMultisynth(uint8_t channel,
|
||||||
num<<=7;
|
num<<=7;
|
||||||
div<<=7;
|
div<<=7;
|
||||||
P1 = div - 512; // Integer mode
|
P1 = div - 512; // Integer mode
|
||||||
if (num){ // Fractional mode
|
if (num) { // Fractional mode
|
||||||
P1+= num / denom;
|
P1+= num / denom;
|
||||||
P2 = num % denom;
|
P2 = num % denom;
|
||||||
P3 = denom;
|
P3 = denom;
|
||||||
|
|
@ -245,15 +249,15 @@ si5351_setupMultisynth(uint8_t channel,
|
||||||
}
|
}
|
||||||
/* Set the MSx config registers */
|
/* Set the MSx config registers */
|
||||||
uint8_t reg[9];
|
uint8_t reg[9];
|
||||||
reg[0]= msreg_base[channel]; // SI5351_REG_42_MULTISYNTH0, SI5351_REG_50_MULTISYNTH1, SI5351_REG_58_MULTISYNTH2
|
reg[0] = msreg_base[channel]; // SI5351_REG_42_MULTISYNTH0, SI5351_REG_50_MULTISYNTH1, SI5351_REG_58_MULTISYNTH2
|
||||||
reg[1]=( P3 & 0x0FF00)>>8; // MSx_P3[15: 8]
|
reg[1] = (P3 & 0x0FF00)>>8; // MSx_P3[15: 8]
|
||||||
reg[2]=( P3 & 0x000FF); // MSx_P3[ 7: 0]
|
reg[2] = (P3 & 0x000FF); // MSx_P3[ 7: 0]
|
||||||
reg[3]=((P1 & 0x30000)>>16)| rdiv; // Rx_DIV[2:0] | MSx_DIVBY4[1:0] | MSx_P1[17:16]
|
reg[3] = ((P1 & 0x30000)>>16)| rdiv; // Rx_DIV[2:0] | MSx_DIVBY4[1:0] | MSx_P1[17:16]
|
||||||
reg[4]=( P1 & 0x0FF00)>> 8; // MSx_P1[15: 8]
|
reg[4] = (P1 & 0x0FF00)>> 8; // MSx_P1[15: 8]
|
||||||
reg[5]=( P1 & 0x000FF); // MSx_P1[ 7: 0]
|
reg[5] = (P1 & 0x000FF); // MSx_P1[ 7: 0]
|
||||||
reg[6]=((P3 & 0xF0000)>>12)|((P2 & 0xF0000)>>16); // MSx_P3[19:16] | MSx_P2[19:16]
|
reg[6] = ((P3 & 0xF0000)>>12)|((P2 & 0xF0000)>>16); // MSx_P3[19:16] | MSx_P2[19:16]
|
||||||
reg[7]=( P2 & 0x0FF00)>>8; // MSx_P2[15: 8]
|
reg[7] = (P2 & 0x0FF00)>>8; // MSx_P2[15: 8]
|
||||||
reg[8]=( P2 & 0x000FF); // MSx_P2[ 7: 0]
|
reg[8] = (P2 & 0x000FF); // MSx_P2[ 7: 0]
|
||||||
si5351_bulk_write(reg, 9);
|
si5351_bulk_write(reg, 9);
|
||||||
|
|
||||||
/* Configure the clk control and enable the output */
|
/* Configure the clk control and enable the output */
|
||||||
|
|
@ -264,7 +268,7 @@ si5351_setupMultisynth(uint8_t channel,
|
||||||
#if USE_CLK_CONTROL_CACHE == TRUE
|
#if USE_CLK_CONTROL_CACHE == TRUE
|
||||||
// Use cache for this reg, not update if not change
|
// Use cache for this reg, not update if not change
|
||||||
static uint8_t clk_cache[3];
|
static uint8_t clk_cache[3];
|
||||||
if (clk_cache[channel]!=dat){
|
if (clk_cache[channel]!=dat) {
|
||||||
si5351_write(clkctrl[channel], dat);
|
si5351_write(clkctrl[channel], dat);
|
||||||
clk_cache[channel]=dat;
|
clk_cache[channel]=dat;
|
||||||
}
|
}
|
||||||
|
|
@ -275,7 +279,8 @@ si5351_setupMultisynth(uint8_t channel,
|
||||||
|
|
||||||
// Find better approximate values for n/d
|
// Find better approximate values for n/d
|
||||||
#define MAX_DENOMINATOR ((1 << 20) - 1)
|
#define MAX_DENOMINATOR ((1 << 20) - 1)
|
||||||
static inline void fractionalSolve(uint32_t *n, uint32_t *d){
|
static inline void approximate_fraction(uint32_t *n, uint32_t *d)
|
||||||
|
{
|
||||||
// cf. https://github.com/python/cpython/blob/master/Lib/fractions.py#L227
|
// cf. https://github.com/python/cpython/blob/master/Lib/fractions.py#L227
|
||||||
uint32_t denom = *d;
|
uint32_t denom = *d;
|
||||||
if (denom > MAX_DENOMINATOR) {
|
if (denom > MAX_DENOMINATOR) {
|
||||||
|
|
@ -303,18 +308,19 @@ si5351_set_frequency_fixedpll(uint8_t channel, uint64_t pllfreq, uint32_t freq,
|
||||||
uint32_t denom = freq;
|
uint32_t denom = freq;
|
||||||
uint32_t div = pllfreq / denom; // range: 8 ~ 1800
|
uint32_t div = pllfreq / denom; // range: 8 ~ 1800
|
||||||
uint32_t num = pllfreq % denom;
|
uint32_t num = pllfreq % denom;
|
||||||
fractionalSolve(&num, &denom);
|
approximate_fraction(&num, &denom);
|
||||||
si5351_setupMultisynth(channel, div, num, denom, rdiv, chctrl);
|
si5351_setupMultisynth(channel, div, num, denom, rdiv, chctrl);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Setup PLL freq if Multisynth divider fixed = div (need get output = freq/mul)
|
// Setup PLL freq if Multisynth divider fixed = div (need get output = freq/mul)
|
||||||
static void
|
static void
|
||||||
si5351_setupPLL_freq(uint32_t pllSource, uint32_t freq, uint32_t div, uint32_t mul){
|
si5351_setupPLL_freq(uint32_t pllSource, uint32_t freq, uint32_t div, uint32_t mul)
|
||||||
|
{
|
||||||
uint32_t denom = XTALFREQ * mul;
|
uint32_t denom = XTALFREQ * mul;
|
||||||
uint64_t pllfreq = (uint64_t)freq * div;
|
uint64_t pllfreq = (uint64_t)freq * div;
|
||||||
uint32_t multi = pllfreq / denom;
|
uint32_t multi = pllfreq / denom;
|
||||||
uint32_t num = pllfreq % denom;
|
uint32_t num = pllfreq % denom;
|
||||||
fractionalSolve(&num, &denom);
|
approximate_fraction(&num, &denom);
|
||||||
si5351_setupPLL(pllSource, multi, num, denom);
|
si5351_setupPLL(pllSource, multi, num, denom);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -328,7 +334,8 @@ si5351_set_frequency_fixeddiv(uint8_t channel, uint32_t pll, uint32_t freq, uint
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
si5351_set_frequency(int channel, uint32_t freq, uint8_t drive_strength){
|
si5351_set_frequency(int channel, uint32_t freq, uint8_t drive_strength)
|
||||||
|
{
|
||||||
if (freq <= 100000000) {
|
if (freq <= 100000000) {
|
||||||
si5351_setupPLL(SI5351_PLL_B, 32, 0, 1);
|
si5351_setupPLL(SI5351_PLL_B, 32, 0, 1);
|
||||||
si5351_set_frequency_fixedpll(channel, SI5351_PLL_B, PLLFREQ, freq, SI5351_R_DIV_1, drive_strength, 1);
|
si5351_set_frequency_fixedpll(channel, SI5351_PLL_B, PLLFREQ, freq, SI5351_R_DIV_1, drive_strength, 1);
|
||||||
|
|
@ -361,7 +368,9 @@ si5351_set_frequency(int channel, uint32_t freq, uint8_t drive_strength){
|
||||||
* | of = 50kHz-300MHz |of= 60- 90 |of= 90-180 |of=128-215 |of=166-234 |of=190-246 |
|
* | of = 50kHz-300MHz |of= 60- 90 |of= 90-180 |of=128-215 |of=166-234 |of=190-246 |
|
||||||
* +-----------------------------------------------------------------------------------------------------------------------+
|
* +-----------------------------------------------------------------------------------------------------------------------+
|
||||||
*/
|
*/
|
||||||
static inline uint8_t si5351_getBand(uint32_t freq){
|
static inline uint8_t
|
||||||
|
si5351_get_band(uint32_t freq)
|
||||||
|
{
|
||||||
if (freq < 100000000U) return 1;
|
if (freq < 100000000U) return 1;
|
||||||
if (freq < 150000000U) return 2;
|
if (freq < 150000000U) return 2;
|
||||||
return 3;
|
return 3;
|
||||||
|
|
@ -375,7 +384,8 @@ static inline uint8_t si5351_getBand(uint32_t freq){
|
||||||
* CLK2: fixed 8MHz
|
* CLK2: fixed 8MHz
|
||||||
*/
|
*/
|
||||||
int
|
int
|
||||||
si5351_set_frequency_with_offset(uint32_t freq, uint8_t drive_strength){
|
si5351_set_frequency(uint32_t freq, uint8_t drive_strength)
|
||||||
|
{
|
||||||
uint8_t band;
|
uint8_t band;
|
||||||
int delay = DELAY_NORMAL;
|
int delay = DELAY_NORMAL;
|
||||||
if (freq == current_freq)
|
if (freq == current_freq)
|
||||||
|
|
@ -402,8 +412,7 @@ si5351_set_frequency_with_offset(uint32_t freq, uint8_t drive_strength){
|
||||||
} else if (freq >= config.harmonic_freq_threshold) {
|
} else if (freq >= config.harmonic_freq_threshold) {
|
||||||
mul = 3;
|
mul = 3;
|
||||||
omul = 5;
|
omul = 5;
|
||||||
}
|
} else if (freq <= 500000U) {
|
||||||
else if (freq <= 500000U) {
|
|
||||||
rdiv = SI5351_R_DIV_64;
|
rdiv = SI5351_R_DIV_64;
|
||||||
freq<<= 6;
|
freq<<= 6;
|
||||||
ofreq<<= 6;
|
ofreq<<= 6;
|
||||||
|
|
@ -412,38 +421,49 @@ si5351_set_frequency_with_offset(uint32_t freq, uint8_t drive_strength){
|
||||||
freq<<= 3;
|
freq<<= 3;
|
||||||
ofreq<<= 3;
|
ofreq<<= 3;
|
||||||
}
|
}
|
||||||
band = si5351_getBand(freq/mul);
|
band = si5351_get_band(freq / mul);
|
||||||
switch (band) {
|
switch (band) {
|
||||||
case 1:
|
case 1:
|
||||||
// Setup CH0 and CH1 constant PLLA freq at band change, and set CH2 freq = CLK2_FREQUENCY
|
// Setup CH0 and CH1 constant PLLA freq at band change, and set CH2 freq =
|
||||||
if (current_band != 1){
|
// CLK2_FREQUENCY
|
||||||
si5351_setupPLL(SI5351_REG_PLL_A, PLL_N, 0, 1);
|
if (current_band != 1) {
|
||||||
si5351_set_frequency_fixedpll(2, XTALFREQ * PLL_N, CLK2_FREQUENCY, SI5351_R_DIV_1, SI5351_CLK_DRIVE_STRENGTH_2MA|SI5351_CLK_PLL_SELECT_A);
|
si5351_setupPLL(SI5351_REG_PLL_A, PLL_N, 0, 1);
|
||||||
delay=DELAY_BANDCHANGE_1;
|
si5351_set_frequency_fixedpll(
|
||||||
}
|
2, XTALFREQ * PLL_N, CLK2_FREQUENCY, SI5351_R_DIV_1,
|
||||||
else
|
SI5351_CLK_DRIVE_STRENGTH_2MA | SI5351_CLK_PLL_SELECT_A);
|
||||||
delay=DELAY_BAND_1;
|
delay = DELAY_BANDCHANGE_1;
|
||||||
// Calculate and set CH0 and CH1 divider
|
} else {
|
||||||
si5351_set_frequency_fixedpll(0, (uint64_t)omul * XTALFREQ * PLL_N, ofreq, rdiv, drive_strength|SI5351_CLK_PLL_SELECT_A);
|
delay = DELAY_BAND_1;
|
||||||
si5351_set_frequency_fixedpll(1, (uint64_t) mul * XTALFREQ * PLL_N, freq, rdiv, drive_strength|SI5351_CLK_PLL_SELECT_A);
|
}
|
||||||
break;
|
// Calculate and set CH0 and CH1 divider
|
||||||
case 2:// fdiv = 6
|
si5351_set_frequency_fixedpll(0, (uint64_t)omul * XTALFREQ * PLL_N, ofreq, rdiv,
|
||||||
case 3:// fdiv = 4;
|
drive_strength | SI5351_CLK_PLL_SELECT_A);
|
||||||
fdiv = (band == 2) ? 6 : 4;
|
si5351_set_frequency_fixedpll(1, (uint64_t)mul * XTALFREQ * PLL_N, freq, rdiv,
|
||||||
// Setup CH0 and CH1 constant fdiv divider at change
|
drive_strength | SI5351_CLK_PLL_SELECT_A);
|
||||||
if (current_band != band){
|
break;
|
||||||
si5351_setupMultisynth(0, fdiv, 0, 1, SI5351_R_DIV_1, drive_strength|SI5351_CLK_PLL_SELECT_A);
|
case 2: // fdiv = 6
|
||||||
si5351_setupMultisynth(1, fdiv, 0, 1, SI5351_R_DIV_1, drive_strength|SI5351_CLK_PLL_SELECT_B);
|
case 3: // fdiv = 4;
|
||||||
delay=DELAY_BANDCHANGE_2;
|
fdiv = (band == 2) ? 6 : 4;
|
||||||
}
|
// Setup CH0 and CH1 constant fdiv divider at change
|
||||||
else
|
if (current_band != band) {
|
||||||
delay=DELAY_BAND_2;
|
si5351_setupMultisynth(0, fdiv, 0, 1, SI5351_R_DIV_1,
|
||||||
// Calculate and set CH0 and CH1 PLL freq
|
drive_strength | SI5351_CLK_PLL_SELECT_A);
|
||||||
si5351_setupPLL_freq(SI5351_REG_PLL_A, ofreq, fdiv, omul);// set PLLA freq = (ofreq/omul)*fdiv
|
si5351_setupMultisynth(1, fdiv, 0, 1, SI5351_R_DIV_1,
|
||||||
si5351_setupPLL_freq(SI5351_REG_PLL_B, freq, fdiv, mul);// set PLLB freq = ( freq/ mul)*fdiv
|
drive_strength | SI5351_CLK_PLL_SELECT_B);
|
||||||
// Calculate CH2 freq = CLK2_FREQUENCY, depend from calculated before CH1 PLLB = (freq/mul)*fdiv
|
delay = DELAY_BANDCHANGE_2;
|
||||||
si5351_set_frequency_fixedpll(2, (uint64_t)freq*fdiv, CLK2_FREQUENCY*mul, SI5351_R_DIV_1, SI5351_CLK_DRIVE_STRENGTH_2MA|SI5351_CLK_PLL_SELECT_B);
|
} else {
|
||||||
break;
|
delay = DELAY_BAND_2;
|
||||||
|
}
|
||||||
|
// Calculate and set CH0 and CH1 PLL freq
|
||||||
|
si5351_setupPLL_freq(SI5351_REG_PLL_A, ofreq, fdiv,
|
||||||
|
omul); // set PLLA freq = (ofreq/omul)*fdiv
|
||||||
|
si5351_setupPLL_freq(SI5351_REG_PLL_B, freq, fdiv,
|
||||||
|
mul); // set PLLB freq = ( freq/ mul)*fdiv
|
||||||
|
// Calculate CH2 freq = CLK2_FREQUENCY, depend from calculated before CH1 PLLB = (freq/mul)*fdiv
|
||||||
|
si5351_set_frequency_fixedpll(
|
||||||
|
2, (uint64_t)freq * fdiv, CLK2_FREQUENCY * mul, SI5351_R_DIV_1,
|
||||||
|
SI5351_CLK_DRIVE_STRENGTH_2MA | SI5351_CLK_PLL_SELECT_B);
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
if (current_band != band) {
|
if (current_band != band) {
|
||||||
si5351_reset_pll(SI5351_PLL_RESET_A|SI5351_PLL_RESET_B);
|
si5351_reset_pll(SI5351_PLL_RESET_A|SI5351_PLL_RESET_B);
|
||||||
|
|
|
||||||
82
si5351.h
82
si5351.h
|
|
@ -24,56 +24,54 @@
|
||||||
#define SI5351_CLK2_EN (1<<2)
|
#define SI5351_CLK2_EN (1<<2)
|
||||||
|
|
||||||
// Reg 16-18 CLKX_CONTROL
|
// Reg 16-18 CLKX_CONTROL
|
||||||
#define SI5351_REG_16_CLK0_CONTROL 16
|
#define SI5351_REG_16_CLK0_CONTROL 16
|
||||||
#define SI5351_REG_17_CLK1_CONTROL 17
|
#define SI5351_REG_17_CLK1_CONTROL 17
|
||||||
#define SI5351_REG_18_CLK2_CONTROL 18
|
#define SI5351_REG_18_CLK2_CONTROL 18
|
||||||
#define SI5351_CLK_POWERDOWN (1<<7)
|
#define SI5351_CLK_POWERDOWN (1<<7)
|
||||||
#define SI5351_CLK_INTEGER_MODE (1<<6)
|
#define SI5351_CLK_INTEGER_MODE (1<<6)
|
||||||
#define SI5351_CLK_PLL_SELECT_A (0<<5)
|
#define SI5351_CLK_PLL_SELECT_A (0<<5)
|
||||||
#define SI5351_CLK_PLL_SELECT_B (1<<5)
|
#define SI5351_CLK_PLL_SELECT_B (1<<5)
|
||||||
#define SI5351_CLK_INVERT (1<<4)
|
#define SI5351_CLK_INVERT (1<<4)
|
||||||
#define SI5351_CLK_INPUT_MASK (3<<2)
|
#define SI5351_CLK_INPUT_MASK (3<<2)
|
||||||
#define SI5351_CLK_INPUT_XTAL (0<<2)
|
#define SI5351_CLK_INPUT_XTAL (0<<2)
|
||||||
#define SI5351_CLK_INPUT_CLKIN (1<<2)
|
#define SI5351_CLK_INPUT_CLKIN (1<<2)
|
||||||
#define SI5351_CLK_INPUT_MULTISYNTH_0_4 (2<<2)
|
#define SI5351_CLK_INPUT_MULTISYNTH_0_4 (2<<2)
|
||||||
#define SI5351_CLK_INPUT_MULTISYNTH_N (3<<2)
|
#define SI5351_CLK_INPUT_MULTISYNTH_N (3<<2)
|
||||||
#define SI5351_CLK_DRIVE_STRENGTH_MASK (3<<0)
|
#define SI5351_CLK_DRIVE_STRENGTH_MASK (3<<0)
|
||||||
#define SI5351_CLK_DRIVE_STRENGTH_2MA (0<<0)
|
#define SI5351_CLK_DRIVE_STRENGTH_2MA (0<<0)
|
||||||
#define SI5351_CLK_DRIVE_STRENGTH_4MA (1<<0)
|
#define SI5351_CLK_DRIVE_STRENGTH_4MA (1<<0)
|
||||||
#define SI5351_CLK_DRIVE_STRENGTH_6MA (2<<0)
|
#define SI5351_CLK_DRIVE_STRENGTH_6MA (2<<0)
|
||||||
#define SI5351_CLK_DRIVE_STRENGTH_8MA (3<<0)
|
#define SI5351_CLK_DRIVE_STRENGTH_8MA (3<<0)
|
||||||
|
|
||||||
#define SI5351_REG_PLL_A 26
|
#define SI5351_REG_PLL_A 26
|
||||||
#define SI5351_REG_PLL_B 34
|
#define SI5351_REG_PLL_B 34
|
||||||
|
|
||||||
#define SI5351_REG_42_MULTISYNTH0 42
|
#define SI5351_REG_42_MULTISYNTH0 42
|
||||||
#define SI5351_REG_50_MULTISYNTH1 50
|
#define SI5351_REG_50_MULTISYNTH1 50
|
||||||
#define SI5351_REG_58_MULTISYNTH2 58
|
#define SI5351_REG_58_MULTISYNTH2 58
|
||||||
#define SI5351_DIVBY4 (3<<2)
|
#define SI5351_DIVBY4 (3<<2)
|
||||||
#define SI5351_R_DIV_1 (0<<4)
|
#define SI5351_R_DIV_1 (0<<4)
|
||||||
#define SI5351_R_DIV_2 (1<<4)
|
#define SI5351_R_DIV_2 (1<<4)
|
||||||
#define SI5351_R_DIV_4 (2<<4)
|
#define SI5351_R_DIV_4 (2<<4)
|
||||||
#define SI5351_R_DIV_8 (3<<4)
|
#define SI5351_R_DIV_8 (3<<4)
|
||||||
#define SI5351_R_DIV_16 (4<<4)
|
#define SI5351_R_DIV_16 (4<<4)
|
||||||
#define SI5351_R_DIV_32 (5<<4)
|
#define SI5351_R_DIV_32 (5<<4)
|
||||||
#define SI5351_R_DIV_64 (6<<4)
|
#define SI5351_R_DIV_64 (6<<4)
|
||||||
#define SI5351_R_DIV_128 (7<<4)
|
#define SI5351_R_DIV_128 (7<<4)
|
||||||
|
|
||||||
#define SI5351_REG_177_PLL_RESET 177
|
#define SI5351_REG_177_PLL_RESET 177
|
||||||
#define SI5351_PLL_RESET_B (1<<7)
|
#define SI5351_PLL_RESET_B (1<<7)
|
||||||
#define SI5351_PLL_RESET_A (1<<5)
|
#define SI5351_PLL_RESET_A (1<<5)
|
||||||
|
|
||||||
#define SI5351_REG_183_CRYSTAL_LOAD 183
|
#define SI5351_REG_183_CRYSTAL_LOAD 183
|
||||||
#define SI5351_CRYSTAL_LOAD_6PF (1<<6)
|
#define SI5351_CRYSTAL_LOAD_6PF (1<<6)
|
||||||
#define SI5351_CRYSTAL_LOAD_8PF (2<<6)
|
#define SI5351_CRYSTAL_LOAD_8PF (2<<6)
|
||||||
#define SI5351_CRYSTAL_LOAD_10PF (3<<6)
|
#define SI5351_CRYSTAL_LOAD_10PF (3<<6)
|
||||||
|
|
||||||
void si5351_init(void);
|
void si5351_init(void);
|
||||||
void si5351_disable_output(void);
|
void si5351_disable_output(void);
|
||||||
void si5351_enable_output(void);
|
void si5351_enable_output(void);
|
||||||
//void si5351_set_frequency(int channel, uint32_t freq, uint8_t drive_strength);
|
|
||||||
|
|
||||||
void si5351_set_frequency_offset(int32_t offset);
|
void si5351_set_frequency_offset(int32_t offset);
|
||||||
int si5351_set_frequency_with_offset(uint32_t freq, uint8_t drive_strength);
|
int si5351_set_frequency(uint32_t freq, uint8_t drive_strength);
|
||||||
uint32_t si5351_getFrequency(void);
|
uint32_t si5351_get_frequency(void);
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -116,7 +116,7 @@ static void
|
||||||
tlv320aic3204_config(const uint8_t *data, int len)
|
tlv320aic3204_config(const uint8_t *data, int len)
|
||||||
{
|
{
|
||||||
i2cAcquireBus(&I2CD1);
|
i2cAcquireBus(&I2CD1);
|
||||||
for (;len--;data+=2)
|
for (; len--; data += 2)
|
||||||
tlv320aic3204_bulk_write(data, 2);
|
tlv320aic3204_bulk_write(data, 2);
|
||||||
i2cReleaseBus(&I2CD1);
|
i2cReleaseBus(&I2CD1);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
115
ui.c
115
ui.c
|
|
@ -33,23 +33,23 @@ uistat_t uistat = {
|
||||||
marker_tracking : FALSE,
|
marker_tracking : FALSE,
|
||||||
};
|
};
|
||||||
|
|
||||||
#define NO_EVENT 0
|
#define NO_EVENT 0
|
||||||
#define EVT_BUTTON_SINGLE_CLICK 0x01
|
#define EVT_BUTTON_SINGLE_CLICK 0x01
|
||||||
#define EVT_BUTTON_DOUBLE_CLICK 0x02
|
#define EVT_BUTTON_DOUBLE_CLICK 0x02
|
||||||
#define EVT_BUTTON_DOWN_LONG 0x04
|
#define EVT_BUTTON_DOWN_LONG 0x04
|
||||||
#define EVT_UP 0x10
|
#define EVT_UP 0x10
|
||||||
#define EVT_DOWN 0x20
|
#define EVT_DOWN 0x20
|
||||||
#define EVT_REPEAT 0x40
|
#define EVT_REPEAT 0x40
|
||||||
|
|
||||||
#define BUTTON_DOWN_LONG_TICKS 5000 /* 1sec */
|
#define BUTTON_DOWN_LONG_TICKS 5000 /* 1sec */
|
||||||
#define BUTTON_DOUBLE_TICKS 2500 /* 500ms */
|
#define BUTTON_DOUBLE_TICKS 2500 /* 500ms */
|
||||||
#define BUTTON_REPEAT_TICKS 625 /* 125ms */
|
#define BUTTON_REPEAT_TICKS 625 /* 125ms */
|
||||||
#define BUTTON_DEBOUNCE_TICKS 200
|
#define BUTTON_DEBOUNCE_TICKS 200
|
||||||
|
|
||||||
/* lever switch assignment */
|
/* lever switch assignment */
|
||||||
#define BIT_UP1 3
|
#define BIT_UP1 3
|
||||||
#define BIT_PUSH 2
|
#define BIT_PUSH 2
|
||||||
#define BIT_DOWN1 1
|
#define BIT_DOWN1 1
|
||||||
|
|
||||||
#define READ_PORT() palReadPort(GPIOA)
|
#define READ_PORT() palReadPort(GPIOA)
|
||||||
#define BUTTON_MASK 0b1111
|
#define BUTTON_MASK 0b1111
|
||||||
|
|
@ -288,13 +288,17 @@ touch_check(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void
|
static inline void
|
||||||
touch_wait_release(void) {
|
touch_wait_release(void)
|
||||||
while(touch_check()!=EVT_TOUCH_RELEASED);
|
{
|
||||||
|
while (touch_check() != EVT_TOUCH_RELEASED)
|
||||||
|
;
|
||||||
}
|
}
|
||||||
|
|
||||||
static inline void
|
static inline void
|
||||||
touch_wait_pressed(void) {
|
touch_wait_pressed(void)
|
||||||
while(touch_check()!=EVT_TOUCH_PRESSED);
|
{
|
||||||
|
while (touch_check() != EVT_TOUCH_PRESSED)
|
||||||
|
;
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
|
@ -303,9 +307,9 @@ touch_cal_exec(void)
|
||||||
int x1, x2, y1, y2;
|
int x1, x2, y1, y2;
|
||||||
|
|
||||||
adc_stop();
|
adc_stop();
|
||||||
setForegroundColor(DEFAULT_FG_COLOR);
|
ili9341_set_foreground(DEFAULT_FG_COLOR);
|
||||||
setBackgroundColor(DEFAULT_BG_COLOR);
|
ili9341_set_background(DEFAULT_BG_COLOR);
|
||||||
clearScreen();
|
ili9341_clear_screen();
|
||||||
ili9341_line(0, 0, 0, 32);
|
ili9341_line(0, 0, 0, 32);
|
||||||
ili9341_line(0, 0, 32, 0);
|
ili9341_line(0, 0, 32, 0);
|
||||||
ili9341_drawstring("TOUCH UPPER LEFT", 10, 10);
|
ili9341_drawstring("TOUCH UPPER LEFT", 10, 10);
|
||||||
|
|
@ -314,7 +318,7 @@ touch_cal_exec(void)
|
||||||
x1 = last_touch_x;
|
x1 = last_touch_x;
|
||||||
y1 = last_touch_y;
|
y1 = last_touch_y;
|
||||||
|
|
||||||
clearScreen();
|
ili9341_clear_screen();
|
||||||
ili9341_line(320-1, 240-1, 320-1, 240-32);
|
ili9341_line(320-1, 240-1, 320-1, 240-32);
|
||||||
ili9341_line(320-1, 240-1, 320-32, 240-1);
|
ili9341_line(320-1, 240-1, 320-32, 240-1);
|
||||||
ili9341_drawstring("TOUCH LOWER RIGHT", 230, 220);
|
ili9341_drawstring("TOUCH LOWER RIGHT", 230, 220);
|
||||||
|
|
@ -340,9 +344,9 @@ touch_draw_test(void)
|
||||||
|
|
||||||
adc_stop();
|
adc_stop();
|
||||||
|
|
||||||
setForegroundColor(DEFAULT_FG_COLOR);
|
ili9341_set_foreground(DEFAULT_FG_COLOR);
|
||||||
setBackgroundColor(DEFAULT_BG_COLOR);
|
ili9341_set_background(DEFAULT_BG_COLOR);
|
||||||
clearScreen();
|
ili9341_clear_screen();
|
||||||
ili9341_drawstring("TOUCH TEST: DRAG PANEL", OFFSETX, 233);
|
ili9341_drawstring("TOUCH TEST: DRAG PANEL", OFFSETX, 233);
|
||||||
|
|
||||||
touch_wait_pressed();
|
touch_wait_pressed();
|
||||||
|
|
@ -354,7 +358,7 @@ touch_draw_test(void)
|
||||||
x0 = x1;
|
x0 = x1;
|
||||||
y0 = y1;
|
y0 = y1;
|
||||||
chThdSleepMilliseconds(50);
|
chThdSleepMilliseconds(50);
|
||||||
} while(touch_check()!=EVT_TOUCH_RELEASED);
|
} while (touch_check() != EVT_TOUCH_RELEASED);
|
||||||
|
|
||||||
touch_start_watchdog();
|
touch_start_watchdog();
|
||||||
}
|
}
|
||||||
|
|
@ -372,13 +376,13 @@ show_version(void)
|
||||||
{
|
{
|
||||||
int x = 5, y = 5, i = 0;
|
int x = 5, y = 5, i = 0;
|
||||||
adc_stop();
|
adc_stop();
|
||||||
setForegroundColor(DEFAULT_FG_COLOR);
|
ili9341_set_foreground(DEFAULT_FG_COLOR);
|
||||||
setBackgroundColor(DEFAULT_BG_COLOR);
|
ili9341_set_background(DEFAULT_BG_COLOR);
|
||||||
|
|
||||||
clearScreen();
|
ili9341_clear_screen();
|
||||||
uint16_t shift = 0b0000010000111110;
|
uint16_t shift = 0b0000010000111110;
|
||||||
ili9341_drawstring_size(info_about[i++], x , y, 4);
|
ili9341_drawstring_size(info_about[i++], x , y, 4);
|
||||||
while (info_about[i]){
|
while (info_about[i]) {
|
||||||
do {shift>>=1; y+=5;} while (shift&1);
|
do {shift>>=1; y+=5;} while (shift&1);
|
||||||
ili9341_drawstring(info_about[i++], x, y+=5);
|
ili9341_drawstring(info_about[i++], x, y+=5);
|
||||||
}
|
}
|
||||||
|
|
@ -398,10 +402,10 @@ enter_dfu(void)
|
||||||
adc_stop();
|
adc_stop();
|
||||||
|
|
||||||
int x = 5, y = 5;
|
int x = 5, y = 5;
|
||||||
setForegroundColor(DEFAULT_FG_COLOR);
|
ili9341_set_foreground(DEFAULT_FG_COLOR);
|
||||||
setBackgroundColor(DEFAULT_BG_COLOR);
|
ili9341_set_background(DEFAULT_BG_COLOR);
|
||||||
// leave a last message
|
// leave a last message
|
||||||
clearScreen();
|
ili9341_clear_screen();
|
||||||
ili9341_drawstring("DFU: Device Firmware Update Mode", x, y += 10);
|
ili9341_drawstring("DFU: Device Firmware Update Mode", x, y += 10);
|
||||||
ili9341_drawstring("To exit DFU mode, please reset device yourself.", x, y += 10);
|
ili9341_drawstring("To exit DFU mode, please reset device yourself.", x, y += 10);
|
||||||
|
|
||||||
|
|
@ -606,7 +610,8 @@ menu_transform_cb(int item, uint8_t data)
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
menu_velocity_cb(int item, uint8_t data){
|
menu_velocity_cb(int item, uint8_t data)
|
||||||
|
{
|
||||||
(void)item;
|
(void)item;
|
||||||
(void)data;
|
(void)data;
|
||||||
if (btn_wait_release() & EVT_BUTTON_DOWN_LONG) {
|
if (btn_wait_release() & EVT_BUTTON_DOWN_LONG) {
|
||||||
|
|
@ -1233,16 +1238,18 @@ static void
|
||||||
draw_keypad(void)
|
draw_keypad(void)
|
||||||
{
|
{
|
||||||
int i = 0;
|
int i = 0;
|
||||||
while (keypads[i].c>=0) {
|
while (keypads[i].c >= 0) {
|
||||||
uint16_t bg = config.menu_normal_color;
|
uint16_t bg = config.menu_normal_color;
|
||||||
if (i == selection)
|
if (i == selection)
|
||||||
bg = config.menu_active_color;
|
bg = config.menu_active_color;
|
||||||
setForegroundColor(DEFAULT_MENU_TEXT_COLOR);
|
ili9341_set_foreground(DEFAULT_MENU_TEXT_COLOR);
|
||||||
setBackgroundColor(bg);
|
ili9341_set_background(bg);
|
||||||
int x = KP_GET_X(keypads[i].x);
|
int x = KP_GET_X(keypads[i].x);
|
||||||
int y = KP_GET_Y(keypads[i].y);
|
int y = KP_GET_Y(keypads[i].y);
|
||||||
ili9341_fill(x+2, y+2, KP_WIDTH-4, KP_HEIGHT-4, bg);
|
ili9341_fill(x+2, y+2, KP_WIDTH-4, KP_HEIGHT-4, bg);
|
||||||
ili9341_drawfont(keypads[i].c, x+(KP_WIDTH-NUM_FONT_GET_WIDTH)/2, y+(KP_HEIGHT-NUM_FONT_GET_HEIGHT)/2);
|
ili9341_drawfont(keypads[i].c,
|
||||||
|
x + (KP_WIDTH - NUM_FONT_GET_WIDTH) / 2,
|
||||||
|
y + (KP_HEIGHT - NUM_FONT_GET_HEIGHT) / 2);
|
||||||
i++;
|
i++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -1251,8 +1258,8 @@ static void
|
||||||
draw_numeric_area_frame(void)
|
draw_numeric_area_frame(void)
|
||||||
{
|
{
|
||||||
ili9341_fill(0, 240-NUM_INPUT_HEIGHT, 320, NUM_INPUT_HEIGHT, config.menu_normal_color);
|
ili9341_fill(0, 240-NUM_INPUT_HEIGHT, 320, NUM_INPUT_HEIGHT, config.menu_normal_color);
|
||||||
setForegroundColor(DEFAULT_MENU_TEXT_COLOR);
|
ili9341_set_foreground(DEFAULT_MENU_TEXT_COLOR);
|
||||||
setBackgroundColor(config.menu_normal_color);
|
ili9341_set_background(config.menu_normal_color);
|
||||||
ili9341_drawstring(keypad_mode_label[keypad_mode], 10, 240-(FONT_GET_HEIGHT+NUM_INPUT_HEIGHT)/2);
|
ili9341_drawstring(keypad_mode_label[keypad_mode], 10, 240-(FONT_GET_HEIGHT+NUM_INPUT_HEIGHT)/2);
|
||||||
//ili9341_drawfont(KP_KEYPAD, 300, 216);
|
//ili9341_drawfont(KP_KEYPAD, 300, 216);
|
||||||
}
|
}
|
||||||
|
|
@ -1282,8 +1289,8 @@ draw_numeric_input(const char *buf)
|
||||||
// if (uistat.digit_mode)
|
// if (uistat.digit_mode)
|
||||||
// bg = DEFAULT_MENU_COLOR;
|
// bg = DEFAULT_MENU_COLOR;
|
||||||
}
|
}
|
||||||
setForegroundColor(fg);
|
ili9341_set_foreground(fg);
|
||||||
setBackgroundColor(bg);
|
ili9341_set_background(bg);
|
||||||
if (c >= 0) // c is number
|
if (c >= 0) // c is number
|
||||||
ili9341_drawfont(c, x, 240-NUM_INPUT_HEIGHT+4);
|
ili9341_drawfont(c, x, 240-NUM_INPUT_HEIGHT+4);
|
||||||
else if (focused) // c not number, but focused
|
else if (focused) // c not number, but focused
|
||||||
|
|
@ -1397,8 +1404,8 @@ draw_menu_buttons(const menuitem_t *menu)
|
||||||
ili9341_fill(320-MENU_BUTTON_WIDTH, y, MENU_BUTTON_WIDTH, MENU_BUTTON_HEIGHT-2, bg);
|
ili9341_fill(320-MENU_BUTTON_WIDTH, y, MENU_BUTTON_WIDTH, MENU_BUTTON_HEIGHT-2, bg);
|
||||||
|
|
||||||
menu_item_modify_attribute(menu, i, &fg, &bg);
|
menu_item_modify_attribute(menu, i, &fg, &bg);
|
||||||
setForegroundColor(fg);
|
ili9341_set_foreground(fg);
|
||||||
setBackgroundColor(bg);
|
ili9341_set_background(bg);
|
||||||
if (menu_is_multiline(menu[i].label, &l1, &l2)) {
|
if (menu_is_multiline(menu[i].label, &l1, &l2)) {
|
||||||
ili9341_fill(320-MENU_BUTTON_WIDTH+3, y+5, MENU_BUTTON_WIDTH-6, 2+FONT_GET_HEIGHT+1+FONT_GET_HEIGHT+2, bg);
|
ili9341_fill(320-MENU_BUTTON_WIDTH+3, y+5, MENU_BUTTON_WIDTH-6, 2+FONT_GET_HEIGHT+1+FONT_GET_HEIGHT+2, bg);
|
||||||
ili9341_drawstring(l1, 320-MENU_BUTTON_WIDTH+5, y+7);
|
ili9341_drawstring(l1, 320-MENU_BUTTON_WIDTH+5, y+7);
|
||||||
|
|
@ -1839,9 +1846,9 @@ keypad_click(int key)
|
||||||
}
|
}
|
||||||
|
|
||||||
return KP_DONE;
|
return KP_DONE;
|
||||||
} else if (c <= 9 && kp_index < NUMINPUT_LEN)
|
} else if (c <= 9 && kp_index < NUMINPUT_LEN) {
|
||||||
kp_buf[kp_index++] = '0' + c;
|
kp_buf[kp_index++] = '0' + c;
|
||||||
else if (c == KP_PERIOD && kp_index < NUMINPUT_LEN) {
|
} else if (c == KP_PERIOD && kp_index < NUMINPUT_LEN) {
|
||||||
// check period in former input
|
// check period in former input
|
||||||
int j;
|
int j;
|
||||||
for (j = 0; j < kp_index && kp_buf[j] != '.'; j++)
|
for (j = 0; j < kp_index && kp_buf[j] != '.'; j++)
|
||||||
|
|
@ -1871,7 +1878,7 @@ keypad_apply_touch(void)
|
||||||
|
|
||||||
touch_position(&touch_x, &touch_y);
|
touch_position(&touch_x, &touch_y);
|
||||||
|
|
||||||
while (keypads[i].c>=0) {
|
while (keypads[i].c >= 0) {
|
||||||
int x = KP_GET_X(keypads[i].x);
|
int x = KP_GET_X(keypads[i].x);
|
||||||
int y = KP_GET_Y(keypads[i].y);
|
int y = KP_GET_Y(keypads[i].y);
|
||||||
if (x < touch_x && touch_x < x+KP_WIDTH && y < touch_y && touch_y < y+KP_HEIGHT) {
|
if (x < touch_x && touch_x < x+KP_WIDTH && y < touch_y && touch_y < y+KP_HEIGHT) {
|
||||||
|
|
@ -2069,7 +2076,7 @@ drag_marker(int t, int m)
|
||||||
markers[m].frequency = frequencies[index];
|
markers[m].frequency = frequencies[index];
|
||||||
redraw_marker(m);
|
redraw_marker(m);
|
||||||
}
|
}
|
||||||
} while(touch_check()!=EVT_TOUCH_RELEASED);
|
} while (touch_check()!= EVT_TOUCH_RELEASED);
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
|
|
@ -2091,9 +2098,9 @@ touch_pickup_marker(void)
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
marker_position(m, t, &x, &y);
|
marker_position(m, t, &x, &y);
|
||||||
x-=touch_x;
|
x -= touch_x;
|
||||||
y-=touch_y;
|
y -= touch_y;
|
||||||
if ((x*x+y*y) < 20*20) {
|
if ((x * x + y * y) < 20 * 20) {
|
||||||
if (active_marker != m) {
|
if (active_marker != m) {
|
||||||
previous_marker = active_marker;
|
previous_marker = active_marker;
|
||||||
active_marker = m;
|
active_marker = m;
|
||||||
|
|
@ -2125,8 +2132,9 @@ touch_lever_mode_select(void)
|
||||||
if (touch_y < 25) {
|
if (touch_y < 25) {
|
||||||
if (touch_x < FREQUENCIES_XPOS2 && get_electrical_delay() != 0.0) {
|
if (touch_x < FREQUENCIES_XPOS2 && get_electrical_delay() != 0.0) {
|
||||||
select_lever_mode(LM_EDELAY);
|
select_lever_mode(LM_EDELAY);
|
||||||
} else
|
} else {
|
||||||
select_lever_mode(LM_MARKER);
|
select_lever_mode(LM_MARKER);
|
||||||
|
}
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
@ -2178,7 +2186,8 @@ ui_process(void)
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Triggered when the button is pressed or released. The LED4 is set to ON.*/
|
/* Triggered when the button is pressed or released. The LED4 is set to ON.*/
|
||||||
static void extcb1(EXTDriver *extp, expchannel_t channel) {
|
static void extcb1(EXTDriver *extp, expchannel_t channel)
|
||||||
|
{
|
||||||
(void)extp;
|
(void)extp;
|
||||||
(void)channel;
|
(void)channel;
|
||||||
operation_requested|=OP_LEVER;
|
operation_requested|=OP_LEVER;
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue