From bdcbf9de6674cb9bfa9e04b37a6b91971eb8738b Mon Sep 17 00:00:00 2001 From: Armin Date: Sat, 30 Sep 2023 09:39:22 +0200 Subject: [PATCH] Housekeeping --- .github/workflows/TestCompile.yml | 2 +- FrequencyGeneratorPage.hpp | 40 +++++------ LICENSE.txt | 57 ++++++++++++++- README.md | 4 +- SimpleDSO.ino | 18 ++--- SimpleDSO.h => SimpleDSO_BlueDisplay.h | 10 +-- TouchDSOCommon.h | 22 +++--- TouchDSOGui.hpp | 99 +++++++++++++------------- Waveforms.cpp | 4 +- digitalWriteFast.h | 14 +++- 10 files changed, 167 insertions(+), 103 deletions(-) rename SimpleDSO.h => SimpleDSO_BlueDisplay.h (98%) diff --git a/.github/workflows/TestCompile.yml b/.github/workflows/TestCompile.yml index 797b192..af8ee0c 100644 --- a/.github/workflows/TestCompile.yml +++ b/.github/workflows/TestCompile.yml @@ -10,7 +10,7 @@ name: TestCompile on: push jobs: build: - name: Test compiling examples for UNO + name: Test compiling examples for Uno runs-on: ubuntu-latest steps: - name: Checkout diff --git a/FrequencyGeneratorPage.hpp b/FrequencyGeneratorPage.hpp index db3b891..529f8c7 100644 --- a/FrequencyGeneratorPage.hpp +++ b/FrequencyGeneratorPage.hpp @@ -38,7 +38,7 @@ #ifndef _FREQUENCY_GENERATOR_PAGE_HPP #define _FREQUENCY_GENERATOR_PAGE_HPP -#if defined(AVR) +#if defined(__AVR__) #include "FrequencyGeneratorPage.h" #endif @@ -48,7 +48,7 @@ static void (*sLastRedrawCallback)(void); #define COLOR_BACKGROUND_FREQ COLOR16_WHITE -#if defined(AVR) +#if defined(__AVR__) #define TIMER_PRESCALER_64 0x03 #define TIMER_PRESCALER_MASK 0x07 #endif @@ -67,7 +67,7 @@ static void (*sLastRedrawCallback)(void); /* * Direct frequency + range buttons */ -#if defined(AVR) +#if defined(__AVR__) const uint16_t FixedFrequencyButtonCaptions[NUMBER_OF_FIXED_FREQUENCY_BUTTONS] PROGMEM = { 1, 2, 5, 10, 20, 50, 100, 200, 500, 1000 }; @@ -133,7 +133,7 @@ void doGetFrequency(BDButton *aTheTouchedButton, int16_t aValue); bool setWaveformFrequencyAndPrintValues(); void printFrequencyAndPeriod(); -#if defined(AVR) +#if defined(__AVR__) void setWaveformButtonCaption(void); void initTimer1ForCTC(void); #endif @@ -143,7 +143,7 @@ void initTimer1ForCTC(void); ***********************/ void initFrequencyGenerator(void) { -#if defined(AVR) +#if defined(__AVR__) initTimer1ForCTC(); #else Synth_Timer_initialize(4711); @@ -183,7 +183,7 @@ void startFrequencyGeneratorPage(void) { sLastRedrawCallback = getRedrawCallback(); registerRedrawCallback(&drawFrequencyGeneratorPage); -#if !defined(AVR) +#if !defined(__AVR__) Synth_Timer_Start(); #endif } @@ -205,7 +205,7 @@ void stopFrequencyGeneratorPage(void) { TouchButtonFrequencyStartStop.deinit(); TouchButtonGetFrequency.deinit(); TouchSliderFrequency.deinit(); -# if defined(AVR) +# if defined(__AVR__) TouchButtonWaveform.deinit(); # endif #endif @@ -230,7 +230,7 @@ void initFrequencyGeneratorPageGui() { */ uint16_t tXPos = 0; uint16_t tFrequency; -#if defined(AVR) +#if defined(__AVR__) // captions are in PGMSPACE const uint16_t *tFrequencyCaptionPtr = &FixedFrequencyButtonCaptions[0]; for (uint8_t i = 0; i < NUMBER_OF_FIXED_FREQUENCY_BUTTONS; ++i) { @@ -251,7 +251,7 @@ void initFrequencyGeneratorPageGui() { #endif tXPos += BUTTON_WIDTH_10 + BUTTON_DEFAULT_SPACING_QUARTER; -#if defined(AVR) +#if defined(__AVR__) tFrequencyCaptionPtr++; #endif } @@ -284,7 +284,7 @@ void initFrequencyGeneratorPageGui() { TouchButtonGetFrequency.init(BUTTON_WIDTH_3_POS_2, DISPLAY_HEIGHT - BUTTON_HEIGHT_4, BUTTON_WIDTH_3, BUTTON_HEIGHT_4, COLOR16_BLUE, F("Hz..."), TEXT_SIZE_22, FLAG_BUTTON_DO_BEEP_ON_TOUCH, 0, &doGetFrequency); -#if defined(AVR) +#if defined(__AVR__) TouchButtonWaveform.init(BUTTON_WIDTH_3_POS_3, DISPLAY_HEIGHT - BUTTON_HEIGHT_4, BUTTON_WIDTH_3, BUTTON_HEIGHT_4, COLOR16_BLUE, "", TEXT_SIZE_18, FLAG_BUTTON_DO_BEEP_ON_TOUCH, sFrequencyInfo.Waveform, &doWaveformMode); setWaveformButtonCaption(); @@ -304,7 +304,7 @@ void drawFrequencyGeneratorPage(void) { BlueDisplay1.drawText(TEXT_SIZE_11_WIDTH, FREQ_SLIDER_Y + 3 * FREQ_SLIDER_SIZE + TEXT_SIZE_11_HEIGHT, F("1"), TEXT_SIZE_11, COLOR16_BLUE, COLOR_BACKGROUND_FREQ); -#if defined(AVR) +#if defined(__AVR__) BlueDisplay1.drawText(DISPLAY_WIDTH - 5 * TEXT_SIZE_11_WIDTH, FREQ_SLIDER_Y + 3 * FREQ_SLIDER_SIZE + TEXT_SIZE_11_HEIGHT, F("1000"), TEXT_SIZE_11, COLOR16_BLUE, COLOR_BACKGROUND_FREQ); @@ -340,7 +340,7 @@ void drawFrequencyGeneratorPage(void) { TouchButtonFrequencyStartStop.drawButton(); TouchButtonGetFrequency.drawButton(); -#if defined(AVR) +#if defined(__AVR__) TouchButtonWaveform.drawButton(); #endif @@ -426,14 +426,14 @@ void doSetFrequencyRange(BDButton *aTheTouchedButton, int16_t aInputRangeIndex) } } -#if defined(AVR) +#if defined(__AVR__) void setWaveformButtonCaption(void) { TouchButtonWaveform.setCaption(getWaveformModePGMString(), (DisplayControl.DisplayPage == DSO_PAGE_FREQUENCY)); } #endif void doWaveformMode(BDButton *aTheTouchedButton, int16_t aValue) { -#if defined(AVR) +#if defined(__AVR__) cycleWaveformMode(); setWaveformButtonCaption(); #endif @@ -477,13 +477,13 @@ void doFrequencyGeneratorStartStop(BDButton *aTheTouchedButton, int16_t aValue) sFrequencyInfo.isOutputEnabled = aValue; if (aValue) { // Start timer -#if !defined(AVR) +#if !defined(__AVR__) Synth_Timer_Start(); #endif setWaveformFrequencyAndPrintValues(); } else { // Stop timer -#if defined(AVR) +#if defined(__AVR__) stopWaveform(); #else Synth_Timer_Stop(); @@ -498,7 +498,7 @@ void printFrequencyAndPeriod() { float tPeriodMicros; -#if defined(AVR) +#if defined(__AVR__) dtostrf(sFrequencyInfo.FrequencyNormalizedTo_1_to_1000, 9, 3, &sStringBuffer[20]); sprintf_P(sStringBuffer, PSTR("%s%cHz"), &sStringBuffer[20], FrequencyRangeChars[sFrequencyInfo.FrequencyRangeIndex]); @@ -520,7 +520,7 @@ void printFrequencyAndPeriod() { tUnitChar = 'm'; } -#if defined(AVR) +#if defined(__AVR__) dtostrf(tPeriodMicros, 10, 3, &sStringBuffer[20]); sprintf_P(sStringBuffer, PSTR("%s%cs"), &sStringBuffer[20], tUnitChar); #else @@ -554,7 +554,7 @@ bool setWaveformFrequencyAndPrintValues() { return tErrorOrClippingHappend; } -#if !defined(AVR) +#if !defined(__AVR__) // content for AVR is in Waveforms.cpp #define WAVEFORM_SQUARE 0 @@ -643,6 +643,6 @@ bool setWaveformFrequencyFromNormalizedValues() { float getPeriodMicros() { return sFrequencyInfo.ControlValue.DividerInt / 36.0f; } -#endif // !defined(AVR) +#endif // !defined(__AVR__) #endif // _FREQUENCY_GENERATOR_PAGE_HPP diff --git a/LICENSE.txt b/LICENSE.txt index e587591..f288702 100644 --- a/LICENSE.txt +++ b/LICENSE.txt @@ -1,7 +1,7 @@ GNU GENERAL PUBLIC LICENSE Version 3, 29 June 2007 - Copyright (C) 2007 Free Software Foundation, Inc. + Copyright (C) 2007 Free Software Foundation, Inc. Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. @@ -618,4 +618,57 @@ an absolute waiver of all civil liability in connection with the Program, unless a warranty or assumption of liability accompanies a copy of the Program in return for a fee. - END OF TERMS AND CONDITIONS \ No newline at end of file + END OF TERMS AND CONDITIONS + + How to Apply These Terms to Your New Programs + + If you develop a new program, and you want it to be of the greatest +possible use to the public, the best way to achieve this is to make it +free software which everyone can redistribute and change under these terms. + + To do so, attach the following notices to the program. It is safest +to attach them to the start of each source file to most effectively +state the exclusion of warranty; and each file should have at least +the "copyright" line and a pointer to where the full notice is found. + + + Copyright (C) + + This program 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 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program. If not, see . + +Also add information on how to contact you by electronic and paper mail. + + If the program does terminal interaction, make it output a short +notice like this when it starts in an interactive mode: + + Copyright (C) + This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'. + This is free software, and you are welcome to redistribute it + under certain conditions; type `show c' for details. + +The hypothetical commands `show w' and `show c' should show the appropriate +parts of the General Public License. Of course, your program's commands +might be different; for a GUI interface, you would use an "about box". + + You should also get your employer (if you work as a programmer) or school, +if any, to sign a "copyright disclaimer" for the program, if necessary. +For more information on this, and how to apply and follow the GNU GPL, see +. + + The GNU General Public License does not permit incorporating your program +into proprietary programs. If your program is a subroutine library, you +may consider it more useful to permit linking proprietary applications with +the library. If this is what you want to do, use the GNU Lesser General +Public License instead of this License. But first, please read +. diff --git a/README.md b/README.md index 7f4c531..58eb3a0 100644 --- a/README.md +++ b/README.md @@ -9,7 +9,7 @@ This DSO needs only a standard Arduino-Uno or Arduino-Nano, a HC-05 Bluetooth mo     [![Badge Commits since latest](https://img.shields.io/github/commits-since/ArminJo/Arduino-Simple-DSO/latest?color=yellow)](https://github.com/ArminJo/Arduino-Simple-DSO/commits/master)     -[![Badge Build Status](https://github.com/ArminJo/Arduino-Simple-DSO/workflows/LibraryBuild/badge.svg)](https://github.com/ArminJo/Arduino-Simple-DSO/actions) +[![Badge Build Status](https://github.com/ArminJo/Arduino-Simple-DSO/workflows/TestCompile/badge.svg)](https://github.com/ArminJo/Arduino-Simple-DSO/actions)     ![Badge Hit Counter](https://visitor-badge.laobi.icu/badge?page_id=ArminJo_Arduino-Simple-DSO)
@@ -62,7 +62,7 @@ You can load the library with *Tools -> Manage Libraries...* or *Ctrl+Shift+I*. Optional for Bluetooth connection 6. HC-05 Bluetooth module -7. Shottky diode e.g. BAT42 +7. Schottky diode e.g. BAT42 # INSTRUCTIONS FOR USE The DSO software has 4 pages. diff --git a/SimpleDSO.ino b/SimpleDSO.ino index 4a0a96b..431b5aa 100644 --- a/SimpleDSO.ino +++ b/SimpleDSO.ino @@ -1,5 +1,5 @@ /* - * SimpleDSO.cpp + * SimpleDSO_BlueDisplay.cpp * * Copyright (C) 2015-2023 Armin Joachimsmeyer * Email: armin.joachimsmeyer@gmail.com @@ -172,10 +172,11 @@ #endif #include "BlueDisplay.hpp" -#include "SimpleDSO.h" +#include "SimpleDSO_BlueDisplay.h" #include "LocalDisplay/digitalWriteFast.h" #include "FrequencyGeneratorPage.hpp" // include sources #include "TouchDSOGui.hpp" // include sources +#include "ADCUtils.hpp" // for getVCCVoltage() /********************** * Buttons @@ -258,7 +259,7 @@ extern volatile unsigned long timer0_millis; */ #define TRIGGER_WAIT_NUMBER_OF_SAMPLES 3300 // Number of samples (<=112us) used for detecting the trigger condition #define ADC_CYCLES_PER_CONVERSION 13 -#define SCALE_CHANGE_DELAY_MILLIS 2000 +#define RANGE_CHANGE_DELAY_MILLIS 2000 #define ADC_MAX_CONVERSION_VALUE (1024 -1) // 10 bit #define ATTENUATOR_FACTOR 10 @@ -348,7 +349,6 @@ void clearDisplayedChart(uint8_t *aDisplayBufferPtr); void drawRemainingDataBufferValues(void); //Hardware support section -float getTemperature(void); void setVCCValue(void); inline void setPrescaleFactor(uint8_t aFactor); void setADCReferenceShifted(uint8_t aReferenceShifted); @@ -521,7 +521,7 @@ void setup() { /************************************************************************ * main loop - 32 microseconds ************************************************************************/ -// noreturn saves 56 byte program memory! +// noreturn saves 56 byte program memory! but no stack void __attribute__((noreturn)) loop(void) { uint32_t sMillisOfLastInfoOutput; @@ -583,7 +583,7 @@ void __attribute__((noreturn)) loop(void) { } else if (DisplayControl.DisplayPage == DSO_PAGE_FREQUENCY) { // refresh buttons drawFrequencyGeneratorPage(); -#if !defined(AVR) +#if !defined(__AVR__) } else if (DisplayControl.DisplayPage == DSO_PAGE_MORE_SETTINGS) { // refresh buttons drawDSOMoreSettingsPage(); @@ -1536,7 +1536,7 @@ void computeAutoRange(void) { * wait n-milliseconds before switch to higher resolution (lower index) */ uint32_t tActualMillis = millis(); - if (tActualMillis - MeasurementControl.TimestampLastRangeChange > SCALE_CHANGE_DELAY_MILLIS) { + if (tActualMillis - MeasurementControl.TimestampLastRangeChange > RANGE_CHANGE_DELAY_MILLIS) { MeasurementControl.TimestampLastRangeChange = tActualMillis; setInputRange(tNewValueShift, tNewAttenuatorValue); } @@ -2026,7 +2026,7 @@ void printInfo(bool aRecomputeValues) { getFloatFromRawValue(MeasurementControl.RawValueAverage), tPrecision, getFloatFromRawValue(tValueDiff), tBufferForPeriodAndFrequency, tUnitsPerGrid, tTimebaseUnitChar); #else -#if defined(AVR) +#if defined(__AVR__) sprintf_P(sStringBuffer, PSTR("%sV %sV %5luHz %3u%cs"), tAverageStringBuffer, tP2PStringBuffer, tHertz, tTimebaseUnitsPerGrid, tTimebaseUnitChar); @@ -2101,7 +2101,7 @@ void printTriggerInfo(void) { */ void printVCCAndTemperature(void) { if (!MeasurementControl.isRunning) { - float tTemp = getTemperature(); + float tTemp = getCPUTemperature(); dtostrf(tTemp, 4, 1, &sStringBuffer[40]); setVCCValue(); diff --git a/SimpleDSO.h b/SimpleDSO_BlueDisplay.h similarity index 98% rename from SimpleDSO.h rename to SimpleDSO_BlueDisplay.h index 29f6dc0..8f6e009 100644 --- a/SimpleDSO.h +++ b/SimpleDSO_BlueDisplay.h @@ -1,5 +1,5 @@ /* - * SimpleDSO.h + * SimpleDSO_BlueDisplay.h * * Copyright (C) 2015-2023 Armin Joachimsmeyer * Email: armin.joachimsmeyer@gmail.com @@ -20,8 +20,8 @@ * along with this program. If not, see . */ -#ifndef _SIMPLE_TOUCHSCREEN_DSO_H -#define _SIMPLE_TOUCHSCREEN_DSO_H +#ifndef _SIMPLE_DSO_BLUEDISPLAY_H +#define _SIMPLE_DSO_BLUEDISPLAY_H #include "TouchDSOCommon.h" @@ -245,7 +245,7 @@ void clearSingleshotMarker(); extern "C" void INT0_vect(); // for printf etc. -#if defined(AVR) +#if defined(__AVR__) #define SIZEOF_STRINGBUFFER 50 #else #define SIZEOF_STRINGBUFFER 240 @@ -256,4 +256,4 @@ extern BDButton TouchButtonBack; // global flag for page control. Is evaluated by calling loop or page and set by buttonBack handler extern bool sBackButtonPressed; -#endif // _SIMPLE_TOUCHSCREEN_DSO_H +#endif // _SIMPLE_DSO_BLUEDISPLAY_H diff --git a/TouchDSOCommon.h b/TouchDSOCommon.h index 9b9d1ea..e9f8e67 100644 --- a/TouchDSOCommon.h +++ b/TouchDSOCommon.h @@ -26,7 +26,7 @@ #ifndef _TOUCH_DSO_COMMON_H #define _TOUCH_DSO_COMMON_H -#if defined(AVR) +#if defined(__AVR__) // Data buffer size (must be small enough to leave appr. 7 % (144 Byte) for stack #define DATABUFFER_SIZE (3*DISPLAY_WIDTH) //960 #else @@ -44,7 +44,7 @@ * CHANNEL */ #define MAX_ADC_EXTERNAL_CHANNEL 4 // 5 channels 0-4, since ADC5/PC5 is used for AC/DC switching -#if defined(AVR) +#if defined(__AVR__) #define ADC_CHANNEL_COUNT ((MAX_ADC_EXTERNAL_CHANNEL + 1) + 2) // The number of external and internal ADC channels #else #define START_ADC_CHANNEL_INDEX 0 // see also ChannelSelectButtonString @@ -70,7 +70,7 @@ extern const char *const ChannelDivByButtonStrings[]; #define TRIGGER_MODE_EXTERN 4 #define TRIGGER_HYSTERESIS_FOR_MODE_MANUAL 4 -#if defined(AVR) +#if defined(__AVR__) /***************************** * Timebase stuff *****************************/ @@ -197,7 +197,7 @@ extern const float TimebaseExactDivValuesMicros[] PROGMEM; #define INFO_UPPER_MARGIN (1 + TEXT_SIZE_11_ASCEND) #define INFO_LEFT_MARGIN 0 -#if defined(AVR) +#if defined(__AVR__) #define FONT_SIZE_INFO_SHORT TEXT_SIZE_18 // for 1 line info #define FONT_SIZE_INFO_LONG TEXT_SIZE_11 // for 2 lines info #define FONT_SIZE_INFO_SHORT_ASC TEXT_SIZE_18_ASCEND @@ -263,7 +263,7 @@ extern const float TimebaseExactDivValuesMicros[] PROGMEM; extern uint8_t sLastPickerValue; -#if defined(AVR) +#if defined(__AVR__) extern BDButton TouchButtonADCReference; #else extern BDButton TouchButtonFFT; @@ -339,7 +339,7 @@ void setOffsetAutomatic(bool aNewState); void setACMode(bool aNewACMode); int changeOffsetGridCount(int aValue); -#if defined(AVR) +#if defined(__AVR__) uint8_t changeRange(int8_t aChangeAmount); uint8_t changeTimeBaseValue(int8_t aChangeValue); #else @@ -363,7 +363,7 @@ void drawMinMaxLines(void); void clearTriggerLine(uint8_t aTriggerLevelDisplayValue); void drawRunningOnlyPartOfGui(void); void activateChartGui(void); -#if defined(AVR) +#if defined(__AVR__) bool scrollChart(int aValue); uint8_t getDisplayFromRawInputValue(uint16_t aRawValue); void drawDataBuffer(uint8_t *aByteBuffer, uint16_t aColor, uint16_t aClearBeforeColor); @@ -389,7 +389,7 @@ void doSwipeEndDSO(struct Swipe *const aSwipeInfo); void doSetTriggerDelay(float aValue); // Button handler section -#if defined(AVR) +#if defined(__AVR__) void doADCReference(BDButton *aTheTouchedButton, int16_t aValue); #else void doShowPretriggerValuesOnOff(BDButton * aTheTouchedButton, int16_t aValue); @@ -425,7 +425,7 @@ void doTriggerLevel(BDSlider *aTheTouchedSlider, uint16_t aValue); void doVoltagePicker(BDSlider *aTheTouchedSlider, uint16_t aValue); // Button caption section -#if defined(AVR) +#if defined(__AVR__) #else void setMinMaxModeButtonCaption(void); #endif @@ -441,10 +441,10 @@ void setAutoOffsetButtonCaption(void); uint32_t getMicrosFromHorizontalDisplayValue(uint16_t aDisplayValueHorizontal, uint8_t aNumberOfPeriods); -#if defined(AVR) +#if defined(__AVR__) #else #endif -#if !defined(AVR) +#if !defined(__AVR__) #endif #endif // _TOUCH_DSO_COMMON_H diff --git a/TouchDSOGui.hpp b/TouchDSOGui.hpp index adffb81..31a25a1 100644 --- a/TouchDSOGui.hpp +++ b/TouchDSOGui.hpp @@ -33,7 +33,7 @@ uint8_t sLastPickerValue; /************************************************************************ * Data analysis section ************************************************************************/ -#if !defined(AVR) +#if !defined(__AVR__) /** * Get max and min for display and automatic triggering. */ @@ -82,7 +82,7 @@ void computeMinMax(void) { #endif void computePeriodFrequency(void) { -#if defined(AVR) +#if defined(__AVR__) /* * Scan data buffer (8 Bit display (!inverted!) values) for trigger conditions. * Assume that first value is the first valid after a trigger @@ -168,7 +168,7 @@ void computePeriodFrequency(void) { tValue = *tDataBufferPointer; bool tValueGreaterCompareValue = (tValue > tActualCompareValue); // variable name is correct for rising slope! -#if defined(AVR) +#if defined(__AVR__) // Since all values are inverted Display values, we have to use just the inverted condition -> toggle compare result if (TriggerSlopeRising == true) tValueGreaterCompareValue = tValueGreaterCompareValue ^ MeasurementControl.TriggerSlopeRising; #else @@ -184,7 +184,7 @@ void computePeriodFrequency(void) { * First wait for signal to go beyond hysteresis, then check for crossing trigger level */ bool tValueLessThanTriggerForFirstPeriod = (tValue < tFirstTriggerLevel); -#if defined(AVR) +#if defined(__AVR__) // Since all values are inverted Display values, we have to use just the inverted condition -> toggle compare result if (TriggerSlopeRising == true) tValueLessThanTriggerForFirstPeriod = tValueLessThanTriggerForFirstPeriod ^ MeasurementControl.TriggerSlopeRising; #else @@ -218,7 +218,7 @@ void computePeriodFrequency(void) { // falling slope - wait for value above hysteresis value if (!tValueGreaterCompareValue) { tTriggerStatus = TRIGGER_STATUS_AFTER_HYSTERESIS; -#if defined(AVR) +#if defined(__AVR__) tActualCompareValue = getDisplayFromRawInputValue(MeasurementControl.RawTriggerLevel); #else tActualCompareValue = MeasurementControl.RawTriggerLevel; @@ -232,7 +232,7 @@ void computePeriodFrequency(void) { */ if (tValueGreaterCompareValue) { -#if defined(AVR) +#if defined(__AVR__) tTriggerStatus = TRIGGER_STATUS_START; tActualCompareValue = getDisplayFromRawInputValue(MeasurementControl.RawTriggerLevelHysteresis); #else @@ -261,12 +261,12 @@ void computePeriodFrequency(void) { MeasurementControl.PeriodSecond = getMicrosFromHorizontalDisplayValue(i - tFirstEndPositionForPulsPause, 1); } tCountPosition = i; -#if !defined(AVR) +#if !defined(__AVR__) } #endif } } -#if !defined(AVR) +#if !defined(__AVR__) if (MeasurementControl.isEffectiveMinMaxMode) { uint16_t tValueMin = *(tDataBufferPointer + DATABUFFER_MIN_OFFSET); tIntegrateValue += (tValue + tValueMin) / 2; @@ -278,7 +278,7 @@ void computePeriodFrequency(void) { #endif tDataBufferPointer++; } // for -#if !defined(AVR) +#if !defined(__AVR__) /* * check for plausi of period values * allow delta of periods to be at least 1/8 period + 3 @@ -292,7 +292,7 @@ void computePeriodFrequency(void) { /* * compute period and frequency */ -#if defined(AVR) +#if defined(__AVR__) if (tCount <= 0) { #else if (tCountPosition <= 0 || tCount <= 0 || !tReliableValue) { @@ -302,7 +302,7 @@ void computePeriodFrequency(void) { MeasurementControl.PeriodMicros = 0; MeasurementControl.FrequencyHertz = 0; } else { -#if defined(AVR) +#if defined(__AVR__) tCountPosition -= tStartPositionForPulsPause; uint32_t tPeriodMicros = getMicrosFromHorizontalDisplayValue(tCountPosition, tCount); MeasurementControl.PeriodMicros = tPeriodMicros; @@ -373,14 +373,14 @@ void setTriggerLevelAndHysteresis(int aRawTriggerValue, int aRawTriggerHysteresi * uses MeasurementControl.DisplayRangeIndex for getRawOffsetValueFromGridCount() */ void setACMode(bool aNewACMode) { -#if defined(AVR) +#if defined(__AVR__) if (MeasurementControl.isRunning) { //clear old grid, since it will be changed BlueDisplay1.clearDisplay(); } #endif MeasurementControl.isACMode = aNewACMode; -#if defined(AVR) +#if defined(__AVR__) // Allow manual setting of AC mode MeasurementControl.ChannelIsACMode = aNewACMode; @@ -395,7 +395,7 @@ void setACMode(bool aNewACMode) { /* * Handle AC hardware switching */ -#if defined(AVR) +#if defined(__AVR__) if (aNewACMode) { /* * AC mode here: Change AC_DC_BIAS_PIN pin to input @@ -425,7 +425,7 @@ void setACMode(bool aNewACMode) { /* * New Offset for AC Mode */ -#if defined(AVR) +#if defined(__AVR__) // must do it here after settings of flags and before drawing setACModeButtonCaption(); if (DisplayControl.DisplayPage == DSO_PAGE_SETTINGS) { @@ -459,7 +459,7 @@ void clearInfo(uint8_t aOldMode) { /*********************************************************************** * GUI initialization ***********************************************************************/ -#if defined(AVR) +#if defined(__AVR__) BDButton TouchButtonADCReference; const char ReferenceButtonVCC[] PROGMEM = "Ref VCC"; const char ReferenceButton1_1V[] PROGMEM = "Ref 1.1V"; @@ -510,7 +510,7 @@ const char StringChannel4[] PROGMEM = "Ch 4"; const char StringTemperature[] PROGMEM = "Temp"; const char StringVRefint[] PROGMEM = "VRef"; const char StringVBattDiv2[] PROGMEM = "\xBD" "VBatt"; -#if defined(AVR) +#if defined(__AVR__) const char *const ADCInputMUXChannelStrings[] = {StringChannel0, StringChannel1, StringChannel2, StringChannel3, StringChannel4, StringTemperature, StringVRefint}; #else @@ -563,7 +563,7 @@ void initDSOGUI(void) { ***************************/ // 1. row // Button for Singleshot -#if defined(AVR) +#if defined(__AVR__) TouchButtonSingleshot.init(BUTTON_WIDTH_3_POS_3, tPosY, BUTTON_WIDTH_3, START_PAGE_BUTTON_HEIGHT, COLOR_GUI_CONTROL, F("Singleshot"), TEXT_SIZE_14, FLAG_BUTTON_DO_BEEP_ON_TOUCH, 0, &doStartSingleshot); #else @@ -589,7 +589,7 @@ void initDSOGUI(void) { // 4. row tPosY += 2 * START_PAGE_ROW_INCREMENT; -#if !defined(AVR) +#if !defined(__AVR__) // Button for show FFT - only for Start and Chart pages. Invisible if running. TouchButtonFFT.init(0, tPosY, BUTTON_WIDTH_3, BUTTON_HEIGHT_4, 0, "FFT", TEXT_SIZE_22, FLAG_BUTTON_DO_BEEP_ON_TOUCH | FLAG_BUTTON_TYPE_TOGGLE_RED_GREEN_MANUAL_REFRESH, DisplayControl.ShowFFT, &doShowFFT); @@ -629,7 +629,7 @@ void initDSOGUI(void) { // 2. row tPosY += SETTINGS_PAGE_ROW_INCREMENT; -#if defined(AVR) +#if defined(__AVR__) // Button for delay TouchButtonTriggerDelay.init(0, tPosY, BUTTON_WIDTH_3, SETTINGS_PAGE_BUTTON_HEIGHT, COLOR_GUI_TRIGGER, "", TEXT_SIZE_11, FLAG_BUTTON_DO_BEEP_ON_TOUCH, 0, &doPromptForTriggerDelay); @@ -652,7 +652,7 @@ void initDSOGUI(void) { // 3. row tPosY += SETTINGS_PAGE_ROW_INCREMENT; -#if !defined(AVR) +#if !defined(__AVR__) // Button for pretrigger area show #if defined(SUPPORT_LOCAL_DISPLAY) TouchButtonShowPretriggerValuesOnOff.init(SLIDER_DEFAULT_BAR_WIDTH + 6, tPosY, BUTTON_WIDTH_3 - (SLIDER_DEFAULT_BAR_WIDTH + 6), @@ -684,7 +684,7 @@ void initDSOGUI(void) { // 4. row tPosY += SETTINGS_PAGE_ROW_INCREMENT; -#if !defined(AVR) +#if !defined(__AVR__) // Button for min/max acquisition mode # if defined(SUPPORT_LOCAL_DISPLAY) TouchButtonMinMaxMode.init(SLIDER_DEFAULT_BAR_WIDTH + 6, tPosY, BUTTON_WIDTH_3 - (SLIDER_DEFAULT_BAR_WIDTH + 6), @@ -721,7 +721,7 @@ void initDSOGUI(void) { TEXT_SIZE_22, FLAG_BUTTON_DO_BEEP_ON_TOUCH, 0, &doAcDcMode); setACModeButtonCaption(); -#if defined(AVR) +#if defined(__AVR__) // Button for reference voltage switching TouchButtonADCReference.init(BUTTON_WIDTH_3_POS_3, tPosY, BUTTON_WIDTH_3, SETTINGS_PAGE_BUTTON_HEIGHT, COLOR_GUI_SOURCE_TIMEBASE, "", TEXT_SIZE_18, FLAG_BUTTON_DO_BEEP_ON_TOUCH, 0, &doADCReference); @@ -820,7 +820,7 @@ void redrawDisplay() { // refresh grid - not really needed, since after MILLIS_BETWEEN_INFO_OUTPUT it is done by loop drawGridLinesWithHorizLabelsAndTriggerLine(); printInfo(); -#if !defined(AVR) +#if !defined(__AVR__) TouchButtonChartHistoryOnOff.activate(); //??? // initialize FFTDisplayBuffer memset(&DisplayBufferFFT[0], DISPLAY_HEIGHT - 1, sizeof(DisplayBufferFFT)); @@ -837,7 +837,7 @@ void redrawDisplay() { drawGridLinesWithHorizLabelsAndTriggerLine(); drawMinMaxLines(); // draw from last scroll position -#if defined(AVR) +#if defined(__AVR__) drawDataBuffer(DataBufferControl.DataBufferDisplayStart, COLOR_DATA_HOLD, DisplayControl.EraseColor); #else drawDataBuffer(DataBufferControl.DataBufferDisplayStart, DISPLAY_WIDTH, COLOR_DATA_HOLD, 0, DRAW_MODE_REGULAR, @@ -861,7 +861,7 @@ void drawStartPage(void) { #endif TouchButtonStartStopDSOMeasurement.drawButton(); // 4. Row -#if !defined(AVR) +#if !defined(__AVR__) TouchButtonFFT.drawButton(); TouchButtonMainHome.drawButton(); #endif @@ -876,7 +876,7 @@ void drawStartPage(void) { COLOR_BACKGROUND_DSO); // Hints -#if !defined(AVR) +#if !defined(__AVR__) BlueDisplay1.drawText(SLIDER_DEFAULT_BAR_WIDTH + 6, BUTTON_HEIGHT_4 + TEXT_SIZE_22_ASCEND, "\xABScale\xBB", TEXT_SIZE_22, COLOR16_YELLOW, COLOR_BACKGROUND_DSO); #endif BlueDisplay1.drawText(BUTTON_WIDTH_3, BUTTON_HEIGHT_4_LINE_4 + BUTTON_DEFAULT_SPACING + TEXT_SIZE_22_ASCEND, @@ -893,7 +893,7 @@ void drawDSOSettingsPage(void) { TouchButtonBack.drawButton(); //2. Row -#if defined(AVR) +#if defined(__AVR__) TouchButtonTriggerDelay.drawButton(); #endif TouchButtonTriggerMode.drawButton(); @@ -918,7 +918,7 @@ void drawDSOSettingsPage(void) { TouchButtonChannelSelect.setButtonColorAndDraw(tButtonColor); //3. Row -#if !defined(AVR) +#if !defined(__AVR__) TouchButtonShowPretriggerValuesOnOff.drawButton(); #endif TouchButtonAutoRangeOnOff.drawButton(); @@ -930,7 +930,7 @@ void drawDSOSettingsPage(void) { TouchButtonChannelSelect.drawButton(); // 4. Row -#if !defined(AVR) +#if !defined(__AVR__) TouchButtonMinMaxMode.drawButton(); #endif TouchButtonAutoOffsetMode.drawButton(); @@ -948,14 +948,14 @@ void drawDSOSettingsPage(void) { TouchButtonAcDc.drawButton(); } -#if defined(AVR) +#if defined(__AVR__) setReferenceButtonCaption(); // also draws the button for this page #else TouchButtonDSOMoreSettings.drawButton(); #endif } -#if !defined(AVR) +#if !defined(__AVR__) void drawDSOMoreSettingsPage(void) { // do not clear screen here since gui is refreshed periodically while DSO is running BDButton::deactivateAll(); @@ -1018,7 +1018,7 @@ void drawRunningOnlyPartOfGui(void) { TouchButtonStartStopDSOMeasurement.drawButton(); // 5. row -#if !defined(AVR) +#if !defined(__AVR__) TouchButtonFFT.drawButton(); #endif TouchButtonSettingsPage.drawButton(); @@ -1028,7 +1028,7 @@ void clearTriggerLine(uint8_t aTriggerLevelDisplayValue) { // clear old line clearHorizontalLineAndRestoreGrid(aTriggerLevelDisplayValue); -#if !defined(AVR) +#if !defined(__AVR__) if (!MeasurementControl.isRunning) { // in analysis mode restore graph at old y position uint8_t *ScreenBufferPointer = &DisplayBuffer[0]; @@ -1058,7 +1058,7 @@ void drawTriggerLine(void) { */ void drawMinMaxLines(void) { // draw max line -#if defined(AVR) +#if defined(__AVR__) uint8_t tValueDisplay; #else int tValueDisplay; @@ -1093,7 +1093,7 @@ void drawGridLinesWithHorizLabelsAndTriggerLine() { for (unsigned int tXPos = TIMING_GRID_WIDTH - 1; tXPos < DISPLAY_WIDTH; tXPos += TIMING_GRID_WIDTH) { BlueDisplay1.drawLineRel(tXPos, 0, 0, DISPLAY_HEIGHT, COLOR_GRID_LINES); } -#if defined(AVR) +#if defined(__AVR__) /* * drawHorizontalLineLabels * adjust the distance between the lines to the actual range which is also determined by the reference voltage @@ -1254,7 +1254,7 @@ void setACModeButtonCaption(void) { } } -#if defined(AVR) +#if defined(__AVR__) void setTriggerDelayCaption(void) { strcpy_P(&sStringBuffer[0], PSTR("Trigger\nset delay")); if (MeasurementControl.TriggerDelayMode != TRIGGER_DELAY_NONE) { @@ -1345,7 +1345,7 @@ void doSwipeEndDSO(struct Swipe *const aSwipeInfo) { /* * Horizontal swipe - Timebase -> use TouchDeltaX/64 */ -#if defined(AVR) +#if defined(__AVR__) int8_t tTouchDeltaXGrid = aSwipeInfo->TouchDeltaX / 64; #else int tTouchDeltaXGrid = aSwipeInfo->TouchDeltaX / 64; @@ -1356,11 +1356,11 @@ void doSwipeEndDSO(struct Swipe *const aSwipeInfo) { } } else { // Vertical swipe -#if !defined(AVR) +#if !defined(__AVR__) int tTouchDeltaYGrid = aSwipeInfo->TouchDeltaY / 32; #endif if (!MeasurementControl.RangeAutomatic) { -#if defined(AVR) +#if defined(__AVR__) tIsError = changeRange(aSwipeInfo->TouchDeltaY / 64); #else /* @@ -1369,9 +1369,10 @@ void doSwipeEndDSO(struct Swipe *const aSwipeInfo) { if (MeasurementControl.OffsetMode != OFFSET_MODE_0_VOLT) { // decide which swipe to perform according to x position of swipe if (aSwipeInfo->TouchStartX > BUTTON_WIDTH_3_POS_2) { - //offset + // Offset tIsError = changeOffsetGridCount(tTouchDeltaYGrid); } else { + // Range tIsError = changeDisplayRangeAndAdjustOffsetGridCount(tTouchDeltaYGrid / 2); } } @@ -1384,7 +1385,7 @@ void doSwipeEndDSO(struct Swipe *const aSwipeInfo) { /* * Analyze Mode -> scroll or scale */ -#if !defined(AVR) +#if !defined(__AVR__) if (aSwipeInfo->TouchStartY < LOCAL_DISPLAY_HEIGHT / 2) { tIsError = changeXScale(aSwipeInfo->TouchDeltaX / 64); } else @@ -1441,7 +1442,7 @@ void doTriggerMode(BDButton *aTheTouchedButton, int16_t aValue) { if (tNewMode > TRIGGER_MODE_EXTERN) { tNewMode = TRIGGER_MODE_AUTOMATIC; MeasurementControl.TriggerMode = tNewMode; -#if defined(AVR) +#if defined(__AVR__) noInterrupts(); if (EIMSK != 0) { // Release waiting for external trigger @@ -1468,7 +1469,7 @@ void doOffsetMode(BDButton *aTheTouchedButton, int16_t aValue) { // switch back from Mode Manual to mode 0 volt and set range mode to automatic MeasurementControl.OffsetMode = OFFSET_MODE_0_VOLT; setAutoRangeModeAndButtonCaption(true); -#if defined(AVR) +#if defined(__AVR__) MeasurementControl.OffsetValue = 0; #else setOffsetGridCountAccordingToACMode(); @@ -1569,7 +1570,7 @@ void doStartSingleshot(BDButton *aTheTouchedButton, int16_t aValue) { MeasurementControl.RawValueMax = 0; MeasurementControl.RawValueMin = 0; -#if defined(AVR) +#if defined(__AVR__) BlueDisplay1.clearDisplay(); drawGridLinesWithHorizLabelsAndTriggerLine(); printSingleshotMarker(); @@ -1620,7 +1621,7 @@ void doVoltagePicker(BDSlider *aTheTouchedSlider, uint16_t aValue) { int tYpos = DISPLAY_VALUE_FOR_ZERO - sLastPickerValue; clearHorizontalLineAndRestoreGrid(tYpos); -#if !defined(AVR) +#if !defined(__AVR__) if (!MeasurementControl.isRunning) { // restore graph uint8_t *ScreenBufferPointer = &DisplayBuffer[0]; @@ -1646,7 +1647,7 @@ void doVoltagePicker(BDSlider *aTheTouchedSlider, uint16_t aValue) { sLastPickerValue = aValue; float tVoltage = getFloatFromDisplayValue(tValue); -#if defined(AVR) +#if defined(__AVR__) dtostrf(tVoltage, 4, 2, sStringBuffer); sStringBuffer[4] = 'V'; sStringBuffer[5] = '\0'; @@ -1664,7 +1665,7 @@ void doVoltagePicker(BDSlider *aTheTouchedSlider, uint16_t aValue) { BlueDisplay1.drawText(SLIDER_VPICKER_INFO_X, tYPos, sStringBuffer, FONT_SIZE_INFO_SHORT, COLOR16_BLACK, COLOR_INFO_BACKGROUND); } -#if defined(AVR) +#if defined(__AVR__) /* * Request delay value as number */ @@ -1787,7 +1788,7 @@ void doADS7846TestOnOff(BDButton *aTheTouchedButton, int16_t aValue) { #endif uint32_t getMicrosFromHorizontalDisplayValue(uint16_t aDisplayValueHorizontal, uint8_t aNumberOfPeriods) { -#if defined(AVR) +#if defined(__AVR__) // values in TimebaseExactDivValuesMicros are guaranteed to be multiple of 31 if index is greater than 4 uint32_t tMicros = aDisplayValueHorizontal * pgm_read_float(&TimebaseExactDivValuesMicros[MeasurementControl.TimebaseIndex]); #else diff --git a/Waveforms.cpp b/Waveforms.cpp index ad07c6f..89328fa 100644 --- a/Waveforms.cpp +++ b/Waveforms.cpp @@ -42,7 +42,7 @@ */ #include -#if defined(AVR) && defined(TCCR1A) +#if defined(__AVR__) && defined(TCCR1A) #include "Waveforms.h" @@ -458,4 +458,4 @@ void computeSineTableValues(uint8_t aSineTable[], unsigned int aNumber) { tRadian += tRadianDelta; } } -#endif // defined(AVR) && defined(TCCR1A) +#endif // defined(__AVR__) && defined(TCCR1A) diff --git a/digitalWriteFast.h b/digitalWriteFast.h index 50d447c..1bb8eb5 100644 --- a/digitalWriteFast.h +++ b/digitalWriteFast.h @@ -27,6 +27,8 @@ # define BIT_WRITE(value, bit, bitvalue) (bitvalue ? BIT_SET(value, bit) : BIT_CLEAR(value, bit)) #endif +#include // declarations for the fallback to digitalWrite(), digitalRead() etc. + // --- Arduino Mega and ATmega128x/256x based boards --- #if (defined(ARDUINO_AVR_MEGA) || \ defined(ARDUINO_AVR_MEGA1280) || \ @@ -128,6 +130,13 @@ (((P) <= 7) ? &DDRB : (((P) >= 8 && (P) <= 15) ? &DDRD : (((P) >= 16 && (P) <= 23) ? &DDRC : &DDRA))) #define __digitalPinToPINReg(P) \ (((P) <= 7) ? &PINB : (((P) >= 8 && (P) <= 15) ? &PIND : (((P) >= 16 && (P) <= 23) ? &PINC : &PINA))) +# if defined(SANGUINO_PINOUT) +#define __digitalPinToBit(P) \ +(((P) <= 7) ? (P) : (((P) >= 8 && (P) <= 15) ? (P) - 8 : (((P) >= 16 && (P) <= 23) ? (P) - 16 : (7 - ((P) - 24))))) +# else //MightyCore Pinout +#define __digitalPinToBit(P) \ +(((P) <= 7) ? (P) : (((P) >= 8 && (P) <= 15) ? (P) - 8 : (((P) >= 16 && (P) <= 23) ? (P) - 16 : (P) - 24))) +# endif #else #define __digitalPinToPortReg(P) \ (((P) <= 7) ? &PORTB : (((P) >= 8 && (P) <= 15) ? &PORTD : &PORTC)) @@ -292,11 +301,12 @@ #define __digitalPinToPortReg(P) (((P) <= 7) ? &PORTA : &PORTB) #define __digitalPinToDDRReg(P) (((P) <= 7) ? &DDRA : &DDRB) #define __digitalPinToPINReg(P) (((P) <= 7) ? &PINA : &PINB) -# if defined(__AVR_ATtiny24__) || defined(__AVR_ATtiny44__) || defined(__AVR_ATtiny84__) || defined(__AVR_ATtiny441__) || defined(__AVR_ATtiny841__) +# endif +# if defined(__AVR_ATtiny24__) || defined(__AVR_ATtiny44__) || defined(__AVR_ATtiny84__) || defined(__AVR_ATtiny441__) || defined(__AVR_ATtiny841__) // https://github.com/SpenceKonde/ATTinyCore/blob/v2.0.0-devThis-is-the-head-submit-PRs-against-this/avr/variants/tinyx41_cw/pins_arduino.h#L334 // Clockwise layout #define __digitalPinToBit(P) (((P) <= 7) ? (P) : ((P) == 11 ? (3) : 10 - (P))) -# endif +# else #define __digitalPinToBit(P) (((P) <= 7) ? (P) : (P) - 8 ) # endif