diff --git a/.github/workflows/TestCompile.yml b/.github/workflows/TestCompile.yml index 088e249..4fd96e5 100644 --- a/.github/workflows/TestCompile.yml +++ b/.github/workflows/TestCompile.yml @@ -17,7 +17,7 @@ jobs: uses: actions/checkout@master # - name: Checkout custom library -# uses: actions/checkout@v2 +# uses: actions/checkout@v3 # with: # repository: ArminJo/Arduino-BlueDisplay # ref: master @@ -26,6 +26,6 @@ jobs: - name: Compile all examples uses: ArminJo/arduino-test-compile@master with: - sketch-names: SimpleTouchScreenDSO.cpp + sketch-names: SimpleDSO.cpp build-properties: '{ "All": "-DUSE_SIMPLE_SERIAL" }' required-libraries: BlueDisplay diff --git a/FrequencyGeneratorPage.h b/FrequencyGeneratorPage.h index e47c258..4573b60 100644 --- a/FrequencyGeneratorPage.h +++ b/FrequencyGeneratorPage.h @@ -5,7 +5,6 @@ * Email: armin.joachimsmeyer@gmail.com * License: GPL v3 (http://www.gnu.org/licenses/gpl.html) */ - #ifndef _FREQUENCY_GENERATOR_PAGE_H #define _FREQUENCY_GENERATOR_PAGE_H @@ -29,4 +28,3 @@ void stopFrequencyGeneratorPage(void); extern const char StringStop[] PROGMEM; // "Stop" #endif // _FREQUENCY_GENERATOR_PAGE_H -#pragma once diff --git a/FrequencyGeneratorPage.cpp b/FrequencyGeneratorPage.hpp similarity index 90% rename from FrequencyGeneratorPage.cpp rename to FrequencyGeneratorPage.hpp index 37c084a..1b8d4f3 100644 --- a/FrequencyGeneratorPage.cpp +++ b/FrequencyGeneratorPage.hpp @@ -1,5 +1,5 @@ /* - * FrequencyGeneratorPage.cpp + * FrequencyGeneratorPage.hpp * * Frequency output from 119 mHz (8.388 second) to 8 MHz square wave on Arduino using timer1. * Sine waveform output from 7,421 mHz to 7812.5 Hz @@ -11,12 +11,12 @@ * Waveform frequency is not stable and decreased, since not all TIMER1 OVERFLOW interrupts are handled. * * PWM RC-Filter suggestions - * Simple: 2k2 Ohm and 100 nF - * 2nd order (good for sine and triangle): 1 kOhm and 100 nF -> 4k7 Ohm and 22 nF - * 2nd order (better for sawtooth): 1 kOhm and 22 nF -> 4k7 Ohm and 4.7 nF + * Simple: 2.2 kOhm and 100 nF + * 2nd order (good for sine and triangle): 1 kOhm and 100 nF -> 4.7 kOhm and 22 nF + * 2nd order (better for sawtooth): 1 kOhm and 22 nF -> 4.7 kOhm and 4.7 nF * * - * Copyright (C) 2015 Armin Joachimsmeyer + * Copyright (C) 2015-2022 Armin Joachimsmeyer * Email: armin.joachimsmeyer@gmail.com * * This file is part of Arduino-Simple-DSO https://github.com/ArminJo/Arduino-Simple-DSO. @@ -35,12 +35,12 @@ * along with this program. If not, see . * */ +#ifndef _FREQUENCY_GENERATOR_PAGE_HPP +#define _FREQUENCY_GENERATOR_PAGE_HPP #if defined(AVR) #include "FrequencyGeneratorPage.h" -#define SUPPRESS_HPP_WARNING -#include "BlueDisplay.h" -#include "SimpleTouchScreenDSO.h" +//#include "SimpleTouchScreenDSO.h" #include // for dtostrf @@ -92,7 +92,7 @@ const char StringMHz[] PROGMEM = "MHz"; const char* RangeButtonStrings[5] = {StringmHz, StringHz, String10Hz, StringkHz, StringMHz}; #else const uint16_t FixedFrequencyButtonCaptions[NUMBER_OF_FIXED_FREQUENCY_BUTTONS] = { 1, 2, 5, 10, 20, 50, 100, 200, 500, 1000 }; -const char* const RangeButtonStrings[5] = { "mHz", "Hz", "10Hz", "kHz", "MHz" }; +const char *const RangeButtonStrings[5] = { "mHz", "Hz", "10Hz", "kHz", "MHz" }; const char FrequencyFactorChars[4] = { 'm', ' ', 'k', 'M' }; struct FrequencyInfoStruct sFrequencyInfo; @@ -100,7 +100,6 @@ struct FrequencyInfoStruct sFrequencyInfo; #define INDEX_OF_10HZ 2 static bool is10HzRange = true; - static const int BUTTON_INDEX_SELECTED_INITIAL = 2; // select 10Hz Button /* @@ -124,7 +123,7 @@ BDButton TouchButton100; BDButton TouchButton200; BDButton TouchButton500; BDButton TouchButton1k; -BDButton * const TouchButtonFixedFrequency[] = { &TouchButton1, &TouchButton2, &TouchButton5, &TouchButton10, &TouchButton20, +BDButton *const TouchButtonFixedFrequency[] = { &TouchButton1, &TouchButton2, &TouchButton5, &TouchButton10, &TouchButton20, &TouchButton50, &TouchButton100, &TouchButton200, &TouchButton500, &TouchButton1k }; #else BDButton TouchButtonFirstFixedFrequency; @@ -136,11 +135,11 @@ void initFrequencyGeneratorPageGui(void); void doFrequencySlider(BDSlider *aTheTouchedSlider, uint16_t aValue); -void doWaveformMode(BDButton * aTheTouchedButton, int16_t aValue); -void doSetFixedFrequency(BDButton * aTheTouchedButton, int16_t aValue); -void doSetFrequencyRange(BDButton * aTheTouchedButton, int16_t aValue); -void doFrequencyGeneratorStartStop(BDButton * aTheTouchedButton, int16_t aValue); -void doGetFrequency(BDButton * aTheTouchedButton, int16_t aValue); +void doWaveformMode(BDButton *aTheTouchedButton, int16_t aValue); +void doSetFixedFrequency(BDButton *aTheTouchedButton, int16_t aValue); +void doSetFrequencyRange(BDButton *aTheTouchedButton, int16_t aValue); +void doFrequencyGeneratorStartStop(BDButton *aTheTouchedButton, int16_t aValue); +void doGetFrequency(BDButton *aTheTouchedButton, int16_t aValue); bool setWaveformFrequencyAndPrintValues(); @@ -148,7 +147,6 @@ void printFrequencyAndPeriod(); #if defined(AVR) void setWaveformButtonCaption(void); void initTimer1ForCTC(void); -#else #endif /*********************** @@ -206,7 +204,7 @@ void loopFrequencyGeneratorPage(void) { } void stopFrequencyGeneratorPage(void) { -#if defined(LOCAL_DISPLAY_EXISTS) +#if defined(BD_DRAW_TO_LOCAL_DISPLAY_TOO) // free buttons for (unsigned int i = 0; i < NUMBER_OF_FIXED_FREQUENCY_BUTTONS; ++i) { TouchButtonFixedFrequency[i]->deinit(); @@ -218,7 +216,9 @@ void stopFrequencyGeneratorPage(void) { TouchButtonFrequencyStartStop.deinit(); TouchButtonGetFrequency.deinit(); TouchSliderFrequency.deinit(); +# if defined(AVR) TouchButtonWaveform.deinit(); +# endif #endif /* * restore previous state @@ -249,12 +249,10 @@ void initFrequencyGeneratorPageGui() { #endif #if defined(LOCAL_DISPLAY_EXISTS) - TouchButtonFixedFrequency[i]->init(tXPos, - REMOTE_DISPLAY_HEIGHT - BUTTON_HEIGHT_4 - BUTTON_HEIGHT_5 - BUTTON_HEIGHT_6 - 2 * BUTTON_DEFAULT_SPACING, - BUTTON_WIDTH_10, BUTTON_HEIGHT_6, COLOR16_BLUE, sStringBuffer, TEXT_SIZE_11, 0, tFrequency, &doSetFixedFrequency); + TouchButtonFixedFrequency[i]->init(tXPos, 96, BUTTON_WIDTH_10, BUTTON_HEIGHT_6, COLOR16_BLUE, sStringBuffer, TEXT_SIZE_11, + 0, tFrequency, &doSetFixedFrequency); #else - TouchButtonFirstFixedFrequency.init(tXPos, - REMOTE_DISPLAY_HEIGHT - BUTTON_HEIGHT_4 - BUTTON_HEIGHT_5 - BUTTON_HEIGHT_6 - 2 * BUTTON_DEFAULT_SPACING, + TouchButtonFirstFixedFrequency.init(tXPos, 92, BUTTON_WIDTH_10, BUTTON_HEIGHT_6, COLOR16_BLUE, sStringBuffer, TEXT_SIZE_11, 0, tFrequency, &doSetFixedFrequency); #endif @@ -276,16 +274,17 @@ void initFrequencyGeneratorPageGui() { tButtonColor = BUTTON_AUTO_RED_GREEN_TRUE_COLOR; } TouchButtonFrequencyRanges[i].init(tXPos, tYPos, BUTTON_WIDTH_5 + BUTTON_DEFAULT_SPACING_HALF, - BUTTON_HEIGHT_5, tButtonColor, reinterpret_cast(RangeButtonStrings[i]), TEXT_SIZE_22, FLAG_BUTTON_DO_BEEP_ON_TOUCH, i, &doSetFrequencyRange); + BUTTON_HEIGHT_5, tButtonColor, reinterpret_cast(RangeButtonStrings[i]), TEXT_SIZE_22, + FLAG_BUTTON_DO_BEEP_ON_TOUCH, i, &doSetFrequencyRange); tXPos += BUTTON_WIDTH_5 + BUTTON_DEFAULT_SPACING - 2; } ActiveTouchButtonFrequencyRange = TouchButtonFrequencyRanges[BUTTON_INDEX_SELECTED_INITIAL]; - TouchButtonFrequencyStartStop.init(0, REMOTE_DISPLAY_HEIGHT - BUTTON_HEIGHT_4, BUTTON_WIDTH_3, BUTTON_HEIGHT_4, 0, - F("Start"), TEXT_SIZE_26, FLAG_BUTTON_DO_BEEP_ON_TOUCH | FLAG_BUTTON_TYPE_TOGGLE_RED_GREEN, - sFrequencyInfo.isOutputEnabled, &doFrequencyGeneratorStartStop); + TouchButtonFrequencyStartStop.init(0, REMOTE_DISPLAY_HEIGHT - BUTTON_HEIGHT_4, BUTTON_WIDTH_3, BUTTON_HEIGHT_4, 0, F("Start"), + TEXT_SIZE_26, FLAG_BUTTON_DO_BEEP_ON_TOUCH | FLAG_BUTTON_TYPE_TOGGLE_RED_GREEN, sFrequencyInfo.isOutputEnabled, + &doFrequencyGeneratorStartStop); TouchButtonFrequencyStartStop.setCaptionForValueTrue(F("Stop")); TouchButtonGetFrequency.init(BUTTON_WIDTH_3_POS_2, REMOTE_DISPLAY_HEIGHT - BUTTON_HEIGHT_4, BUTTON_WIDTH_3, @@ -309,9 +308,8 @@ void drawFrequencyGeneratorPage(void) { #endif TouchSliderFrequency.drawSlider(); - 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); + TEXT_SIZE_11, COLOR16_BLUE, COLOR_BACKGROUND_FREQ); #if defined(AVR) BlueDisplay1.drawText(REMOTE_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, @@ -350,7 +348,9 @@ void drawFrequencyGeneratorPage(void) { TouchButtonFrequencyStartStop.drawButton(); TouchButtonGetFrequency.drawButton(); +#if defined(AVR) TouchButtonWaveform.drawButton(); +#endif // show values printFrequencyAndPeriod(); @@ -395,7 +395,7 @@ void setWaveformButtonCaption(void) { } #endif -void doWaveformMode(BDButton * aTheTouchedButton, int16_t aValue) { +void doWaveformMode(BDButton *aTheTouchedButton, int16_t aValue) { #if defined(AVR) cycleWaveformMode(); setWaveformButtonCaption(); @@ -405,7 +405,7 @@ void doWaveformMode(BDButton * aTheTouchedButton, int16_t aValue) { /** * Set frequency to fixed value 1,2,5,10...,1000 */ -void doSetFixedFrequency(BDButton * aTheTouchedButton, int16_t aValue) { +void doSetFixedFrequency(BDButton *aTheTouchedButton, int16_t aValue) { setFrequencyNormalizedForGUI(aValue); bool tErrorOrClippingHappend = setWaveformFrequencyAndPrintValues(); #if defined(LOCAL_DISPLAY_EXISTS) @@ -419,7 +419,7 @@ void doSetFixedFrequency(BDButton * aTheTouchedButton, int16_t aValue) { * sets the unit (mHz - MHz) * set color for old and new button */ -void doSetFrequencyRange(BDButton * aTheTouchedButton, int16_t aValue) { +void doSetFrequencyRange(BDButton *aTheTouchedButton, int16_t aValue) { if (ActiveTouchButtonFrequencyRange != *aTheTouchedButton) { // Handling of 10 Hz button @@ -451,7 +451,7 @@ void doSetFrequencyRange(BDButton * aTheTouchedButton, int16_t aValue) { * @param aTheTouchedButton * @param aValue */ -void doGetFrequency(BDButton * aTheTouchedButton, int16_t aValue) { +void doGetFrequency(BDButton *aTheTouchedButton, int16_t aValue) { TouchSliderFrequency.deactivate(); float tNumber = getNumberFromNumberPad(NUMBERPAD_DEFAULT_X, 0, COLOR16_BLUE); // check for cancel @@ -479,7 +479,7 @@ void doGetFrequency(BDButton * aTheTouchedButton, int16_t aValue) { } #endif -void doFrequencyGeneratorStartStop(BDButton * aTheTouchedButton, int16_t aValue) { +void doFrequencyGeneratorStartStop(BDButton *aTheTouchedButton, int16_t aValue) { sFrequencyInfo.isOutputEnabled = aValue; if (aValue) { // Start timer @@ -622,9 +622,9 @@ bool setWaveformFrequency(float aValue) { tDividerInt = 2; } -#if defined(STM)32F30X +# if defined(STM32F30X) Synth_Timer32_SetReloadValue(tDividerInt); -#else +# else uint32_t tPrescalerValue = (tDividerInt >> 16) + 1; // +1 since at least divider by 1 if (tPrescalerValue > 1) { //we have prescaler > 1 -> adjust reload value to be less than 0x10001 @@ -632,7 +632,7 @@ bool setWaveformFrequency(float aValue) { } Synth_Timer16_SetReloadValue(tDividerInt, tPrescalerValue); tDividerInt *= tPrescalerValue; -#endif +# endif sFrequencyInfo.ControlValue.DividerInt = tDividerInt; // recompute frequency sFrequencyInfo.Frequency = 36000000 / tDividerInt; @@ -651,5 +651,6 @@ bool setWaveformFrequency() { float getPeriodMicros() { return sFrequencyInfo.ControlValue.DividerInt / 36.0f; } -#endif +#endif // !defined(AVR) +#endif // _FREQUENCY_GENERATOR_PAGE_HPP diff --git a/README.md b/README.md index 48d180c..5f9bcee 100644 --- a/README.md +++ b/README.md @@ -32,7 +32,7 @@ You can load the library with *Tools -> Manage Libraries...* or *Ctrl+Shift+I*. - no attenuator (pin 8+9 left open). - passive attenuator with /1, /10, /100 attenuation (pin 8 connected to ground). - active attenuator (pin 9 connected to ground) - still experimental. -- Using 1.1 volt internal reference. 5 volt (VCC) is also selectable and is useful if no attenuator is attached. +- Using 1.1 volt internal reference. 5 V (VCC) is also selectable and is useful if no attenuator is attached. - Integrated frequency generator using 16 bit Timer1. Frequency from 119 mHz (8.388 second) to 8 MHz - Integrated PWM Waveform generator for sinus, triangle and sawtooth using 16 bit Timer1. Frequency from 1.9 mHz to 7.8 kHz @@ -41,11 +41,11 @@ You can load the library with *Tools -> Manage Libraries...* or *Ctrl+Shift+I*. 1. Arduino Nano 2. Breadboard 400 points 3. Resistors - - Resistors for the simple (0-5 volt) version: 1x 10 kOhm, 2x 100 k, 1x 4 M or more. - - Resistors for the 3 range (0-110 volt) version: 1x 2.2 kOhm, 2x 10 k, 3x 100 k, 2x 220 k, 2x 1 M, 1x 4 M or greater + - Resistors for the simple (0-5 V) version: 1x 10 kΩ, 2x 100 k, 1x 4 M or more. + - Resistors for the 3 range (0-110 V) version: 1x 2.2 kΩ, 2x 10 k, 3x 100 k, 2x 220 k, 2x 1 M, 1x 4 M or greater 4. Capacitors - - Capacitors for the simple version: 1x 100 nF / 10 volt (or more) - - Capacitors for the 3 range (0-110 volt) version: 4x 100 nF / 100 volt (or more), 6.8 uF + - Capacitors for the simple version: 1x 100 nF / 10 V (or more) + - Capacitors for the 3 range (0-110 V) version: 4x 100 nF / 100 V (or more), 6.8 µF 5. Jumper wires Optional for Bluetooth connection @@ -111,7 +111,7 @@ The stack size is required for testing different buffer size values during devel - **History** -> **red** history off, **green** history on, i.e. old chart data is not deleted, it stays as a light green trace. This button is also available (invisible) at the chart page. - Slope - **Slope A** -> trigger on ascending slope, **Slope D** -> trigger on descending slope. - **Back** -> Back to chart page. -- **Trigger delay** -> Trigger delay can be numerical specified from 4 µs to 64.000.000 µs (64 seconds, if you really want). Microseconds resolution is used for values below 64.000. +- **Trigger delay** -> Trigger delay can be numerical specified from 4 µs to 64.000.000 µs (64 seconds, if you really want). Microseconds resolution is used for values below 64.000. - Trigger - the trigger value can be set on the chart page by touching the light violet vertical bar in the 4. left grid. - **Trigger auto** -> let the DSO compute the trigger value using the average of the last measurement. - **Trigger man timeout** -> use manual trigger value, but with timeout, i.e. if trigger condition not met, new data is shown after timeout. @@ -121,7 +121,7 @@ The stack size is required for testing different buffer size values during devel -**Trigger ext** uses pin 2 as external trigger source. - Input selector - - **%1** -> Pin A0 with no attenuator, only a 10k Ohm protection resistor. + - **%1** -> Pin A0 with no attenuator, only a 10 kΩ protection resistor. - **%10** -> Pin A1 with an 1 to 10 attenuator. - **%100** -> Pin A2 with an 1 to 100 attenuator. - **CH 3** -> sequences through the channels **CH 4**, **Temp** (internal temperature sensor), **VRef** (internal reference). @@ -147,36 +147,34 @@ Short touch switches info output, long touch shows active GUI elements. |Maximum values | Minimum values| | :--- | :--- | -|SINE: clip to minimum 8 samples per period => 128 µs / 7812.5 Hz |7,421 mHz| -|SAWTOOTH: clip to minimum 16 samples per period => 256 µs / 3906.25 Hz |3.725 mHz| -|TRIANGLE: clip to minimum 32 samples per period => 512 µs / 1953.125 Hz|1.866 mHz| +|SINE: clip to minimum 8 samples per period => 128 µs / 7812.5 Hz |7,421 mHz| +|SAWTOOTH: clip to minimum 16 samples per period => 256 µs / 3906.25 Hz |3.725 mHz| +|TRIANGLE: clip to minimum 32 samples per period => 512 µs / 1953.125 Hz|1.866 mHz| ### RC-Filter suggestions -- Simple: 2k2 Ohm and 100 nF -- 2nd order (good for sine and triangle): 1 kOhm and 100 nF -> 4k7 Ohm and 22 nF -- 2nd order (better for sawtooth): 1 kOhm and 22 nF -> 4k7 Ohm and 4.7 nF +- Simple: 2.2 kΩ and 100 nF +- 2nd order (good for sine and triangle): 1 kΩ and 100 nF -> 4.7 kΩ and 22 nF +- 2nd order (better for sawtooth): 1 kΩ and 22 nF -> 4.7 kΩ and 4.7 nF **Do not run DSO acquisition and non square wave waveform generation at the same time.** Because of the interrupts at 62 kHz rate, DSO is almost not usable during non square wave waveform generation and waveform frequency is not stable and decreased, since not all TIMER1 OVERFLOW interrupts are handled. # SCREENSHOTS -DSO start screen -![DSO start screen](https://github.com/ArminJo/Arduino-Simple-DSO/blob/master/pictures/Welcome.jpg) - -| DSO Chart screen | DSO Chart screen with long info | +| DSO start screen | DSO at work | | :-: | :-: | +| ![DSO start screen](https://github.com/ArminJo/Arduino-Simple-DSO/blob/master/pictures/Welcome.jpg) | ![DSO at work](https://github.com/ArminJo/Arduino-Simple-DSO/blob/master/pictures/DSO+Tablet.jpg) | +| DSO chart screen | DSO chart screen with long info | | ![DSO chart screen](https://github.com/ArminJo/Arduino-Simple-DSO/blob/master/pictures/Chart.jpg) | ![DSO chart screen with long info](https://github.com/ArminJo/Arduino-Simple-DSO/blob/master/pictures/Chart_Long_Info.jpg) | -| ![DSO at work](https://github.com/ArminJo/Arduino-Simple-DSO/blob/master/pictures/DSO+Tablet.jpg) | | ## Linearity of the ATmega328P(B) ADC converter The captured signal was generated with a STM32F303 DAC and the DSO input range was chosen to see the LSB of the 10 bit ADC conversion. -| All ranges including the 1 ms range (up to 30 kSamples per second / 26 µs conversion time) have almost perfect linearity. | In the 50 µs to 10 µs ranges with 300 kSamples per second (3 µs conversion time) the linearity is only acceptable. | +| All ranges including the 1 ms range (up to 30 kSamples per second / 26 µs conversion time) have almost perfect linearity. | In the 50 µs to 10 µs ranges with 300 kSamples per second (3 µs conversion time) the linearity is only acceptable. | | :-: | :-: | -| ![26 µs conversion](https://github.com/ArminJo/Arduino-Simple-DSO/blob/master/pictures/Linearity_26us_conversion_time.jpg) | ![3 µs conversion](https://github.com/ArminJo/Arduino-Simple-DSO/blob/master/pictures/Linearity_3us_conversion_time.jpg) | -| First small linearity issues can be seen in the 496 µs range with 60 kSamples per second (13 µs conversion time). | And in the 101 µs range with 150 kSamples per second (6.5 µs conversion time). | -| ![13 µs conversion](https://github.com/ArminJo/Arduino-Simple-DSO/blob/master/pictures/Linearity_13us_conversion_time.jpg) | ![6.5 µs conversion](https://github.com/ArminJo/Arduino-Simple-DSO/blob/master/pictures/Linearity_6us5_conversion_time.jpg) | +| ![26 µs conversion](https://github.com/ArminJo/Arduino-Simple-DSO/blob/master/pictures/Linearity_26us_conversion_time.jpg) | ![3 µs conversion](https://github.com/ArminJo/Arduino-Simple-DSO/blob/master/pictures/Linearity_3us_conversion_time.jpg) | +| First small linearity issues can be seen in the 496 µs range with 60 kSamples per second (13 µs conversion time). | And in the 101 µs range with 150 kSamples per second (6.5 µs conversion time). | +| ![13 µs conversion](https://github.com/ArminJo/Arduino-Simple-DSO/blob/master/pictures/Linearity_13us_conversion_time.jpg) | ![6.5 µs conversion](https://github.com/ArminJo/Arduino-Simple-DSO/blob/master/pictures/Linearity_6us5_conversion_time.jpg) | # SCHEMATICS | SIMPLE 1 RANGE VERSION | 3 RANGE VERSION | diff --git a/SimpleTouchScreenDSO.cpp b/SimpleDSO.cpp similarity index 98% rename from SimpleTouchScreenDSO.cpp rename to SimpleDSO.cpp index eb2bd84..8328340 100644 --- a/SimpleTouchScreenDSO.cpp +++ b/SimpleDSO.cpp @@ -1,7 +1,7 @@ /* - * SimpleTouchScreenDSO.cpp + * SimpleDSO.cpp * - * Copyright (C) 2015 Armin Joachimsmeyer + * Copyright (C) 2015-2023 Armin Joachimsmeyer * Email: armin.joachimsmeyer@gmail.com * * This file is part of Arduino-Simple-DSO https://github.com/ArminJo/Arduino-Simple-DSO. @@ -159,16 +159,28 @@ //#define DEBUG #include +/* + * Enabling program features dependent on display configuration + */ +//#define LOCAL_DISPLAY_EXISTS // Activate, if a local display is attached and should be drawn simultaneously +//#define USE_HY32D // Activate, if local display is a HY32D / SSD1289 type. Otherwise a MI0283QT2 type is assumed. + /* * Settings to configure the BlueDisplay library and to reduce its size */ //#define BLUETOOTH_BAUD_RATE BAUD_115200 // Activate this, if you have reprogrammed the HC05 module for 115200, otherwise 9600 is used as baud rate //#define DO_NOT_NEED_BASIC_TOUCH_EVENTS // Disables basic touch events like down, move and up. Saves 620 bytes program memory and 36 bytes RAM #define USE_SIMPLE_SERIAL // Do not use the Serial object. Saves up to 1250 bytes program memory and 185 bytes RAM, if Serial is not used otherwise +//#define SUPPORT_LOCAL_DISPLAY // Supports simultaneously drawing on a locally attached display. Not (yet) implemented for all commands! #include "BlueDisplay.hpp" -#include "SimpleTouchScreenDSO.h" -#include "FrequencyGeneratorPage.h" +#if defined(SUPPORT_LOCAL_DISPLAY) && !defined(LOCAL_DISPLAY_EXISTS) +#error SUPPORT_LOCAL_DISPLAY is defined but no local display seems to be attached since LOCAL_DISPLAY_EXISTS is not defined. +#endif + +#include "SimpleDSO.h" +#include "FrequencyGeneratorPage.hpp" // include sources +#include "TouchDSOGui.hpp" // include sources #include "digitalWriteFast.h" @@ -1626,7 +1638,7 @@ uint16_t getAttenuatorFactor(void) { /* * toggle between DC and AC mode */ -void doAcDcMode(__attribute__((unused)) BDButton *aTheTouchedButton, __attribute__((unused)) int16_t aValue) { +void doAcDcMode(__attribute__((unused)) BDButton *aTheTouchedButton, __attribute__((unused)) int16_t aValue) { setACMode(!MeasurementControl.ChannelIsACMode); } @@ -1660,7 +1672,7 @@ void doSetTriggerDelay(float aValue) { /* * toggle between 5 and 1.1 volt reference */ -void doADCReference(__attribute__((unused)) BDButton *aTheTouchedButton, __attribute__((unused)) int16_t aValue) { +void doADCReference(__attribute__((unused)) BDButton *aTheTouchedButton, __attribute__((unused)) int16_t aValue) { uint8_t tNewReference = MeasurementControl.ADCReference; if (MeasurementControl.ADCReference == DEFAULT) { tNewReference = INTERNAL; @@ -1675,7 +1687,7 @@ void doADCReference(__attribute__((unused)) BDButton *aTheTouchedButton, __a } } -void doStartStopDSO(__attribute__((unused)) BDButton *aTheTouchedButton, __attribute__((unused)) int16_t aValue) { +void doStartStopDSO(__attribute__((unused)) BDButton *aTheTouchedButton, __attribute__((unused)) int16_t aValue) { if (MeasurementControl.isRunning) { /* * Stop here @@ -2023,8 +2035,8 @@ void printInfo(bool aRecomputeValues) { */ #if defined(LOCAL_DISPLAY_EXISTS) snprintf(sStringBuffer, sizeof sStringBuffer, "%6.*fV %6.*fV%s%4u%cs", tPrecision, - getFloatFromRawValue(MeasurementControl.RawValueAverage), tPrecision, - getFloatFromRawValue(tValueDiff), tBufferForPeriodAndFrequency, tUnitsPerGrid, tTimebaseUnitChar); + getFloatFromRawValue(MeasurementControl.RawValueAverage), tPrecision, getFloatFromRawValue(tValueDiff), + tBufferForPeriodAndFrequency, tUnitsPerGrid, tTimebaseUnitChar); #else #if defined(AVR) diff --git a/SimpleTouchScreenDSO.h b/SimpleDSO.h similarity index 97% rename from SimpleTouchScreenDSO.h rename to SimpleDSO.h index 0df0589..58dcc8c 100644 --- a/SimpleTouchScreenDSO.h +++ b/SimpleDSO.h @@ -38,8 +38,8 @@ /* * Display size */ -const unsigned int REMOTE_DISPLAY_HEIGHT = 256; // we use 8 bit resolution and have 256 different analog values -const unsigned int REMOTE_DISPLAY_WIDTH = DISPLAY_HALF_VGA_WIDTH; // 320 +#define REMOTE_DISPLAY_HEIGHT 256 // we use 8 bit resolution and have 256 different analog values +#define REMOTE_DISPLAY_WIDTH DISPLAY_HALF_VGA_WIDTH // 320 #define THOUSANDS_SEPARATOR '.' @@ -241,4 +241,3 @@ extern BDButton TouchButtonBack; extern bool sBackButtonPressed; #endif // _SIMPLE_TOUCHSCREEN_DSO_H -#pragma once diff --git a/TouchDSOCommon.h b/TouchDSOCommon.h index f6cac6f..30f61a2 100644 --- a/TouchDSOCommon.h +++ b/TouchDSOCommon.h @@ -35,7 +35,7 @@ // Data buffer size (must be small enough to leave appr. 7 % (144 Byte) for stack #define DATABUFFER_SIZE (3*REMOTE_DISPLAY_WIDTH) //960 #else -#if defined(STM)32F303xC +#if defined(STM32F303xC) #define DATABUFFER_SIZE_FACTOR 9 #else #define DATABUFFER_SIZE_FACTOR 7 @@ -53,7 +53,7 @@ #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 -#if defined(STM)32F303xC +#if defined(STM32F303xC) #define ADC_CHANNEL_COUNT 6 // The number of ADC channels #else #define ADC_CHANNEL_COUNT 6 // The number of ADC channels @@ -146,7 +146,7 @@ extern const char * const ChannelDivByButtonStrings[]; #define TIMEBASE_FAST_MODES 7 // first modes are fast DMA modes #define TIMEBASE_INDEX_DRAW_WHILE_ACQUIRE 17 // min index where chart is drawn while buffer is filled #define TIMEBASE_INDEX_CAN_USE_OVERSAMPLING 11 // min index where Min/Max oversampling is enabled -#if defined(STM)32F303xC +#if defined(STM32F303xC) #define TIMEBASE_NUMBER_START 1 // first reasonable Timebase to display - 0 if interleaving is realized #define TIMEBASE_NUMBER_OF_XSCALE_CORRECTION 5 // number of timebase which are simulated by display XSale factor #else @@ -282,7 +282,7 @@ extern BDButton TouchButtonDrawModeTriggerLine; extern BDButton TouchButtonDrawModeLinePixel; extern BDButton TouchButtonADS7846TestOnOff; extern BDSlider TouchSliderBacklight; -#endif +#endif // LOCAL_DISPLAY_EXISTS extern BDButton TouchButtonSingleshot; extern BDButton TouchButtonStartStopDSOMeasurement; @@ -388,8 +388,8 @@ void printInfo(bool aRecomputeValues = true); void printTriggerInfo(void); // GUI event handler section -void doSwitchInfoModeOnTouchUp(struct TouchEvent * const aTochPosition); -void doLongTouchDownDSO(struct TouchEvent * const aTochPosition); +void doSwitchInfoModeOnTouchUp(struct TouchEvent * const aTouchPosition); +void doLongTouchDownDSO(struct TouchEvent * const aTouchPosition); void doSwipeEndDSO(struct Swipe * const aSwipeInfo); void doSetTriggerDelay(float aValue); @@ -418,11 +418,12 @@ void doPromptForTriggerDelay(BDButton * aTheTouchedButton, int16_t aValue); void doChannelSelect(BDButton * aTheTouchedButton, int16_t aValue); void doOffsetMode(BDButton * aTheTouchedButton, int16_t aValue); void doAcDcMode(BDButton * aTheTouchedButton, int16_t aValue); + #if defined(LOCAL_DISPLAY_EXISTS) void readADS7846Channels(void); void doADS7846TestOnOff(BDButton * aTheTouchedButton, int16_t aValue); void doDrawMode(BDButton * aTheTouchedButton, int16_t aValue); -#endif +#endif // LOCAL_DISPLAY_EXISTS // Slider handler section void doTriggerLevel(BDSlider *aTheTouchedSlider, uint16_t aValue); @@ -452,4 +453,3 @@ uint32_t getMicrosFromHorizontalDisplayValue(uint16_t aDisplayValueHorizontal, u #endif #endif // _TOUCH_DSO_COMMON_H -#pragma once diff --git a/TouchDSOGui.cpp b/TouchDSOGui.hpp similarity index 91% rename from TouchDSOGui.cpp rename to TouchDSOGui.hpp index 012ca53..01516b8 100644 --- a/TouchDSOGui.cpp +++ b/TouchDSOGui.hpp @@ -1,9 +1,9 @@ /* - * TouchDSOGui.cpp + * TouchDSOGui.hpp * * Implements the common (GUI) parts of AVR and ARM development * - * Copyright (C) 2017 Armin Joachimsmeyer + * Copyright (C) 2017-2022 Armin Joachimsmeyer * Email: armin.joachimsmeyer@gmail.com * * This file is part of Arduino-Simple-DSO https://github.com/ArminJo/Arduino-Simple-DSO. @@ -22,13 +22,13 @@ * along with this program. If not, see . * */ - -#define SUPPRESS_HPP_WARNING +#ifndef _TOUCH_DSO_GUI_HPP +#define _TOUCH_DSO_GUI_HPP #if defined(AVR) #include -#include "SimpleTouchScreenDSO.h" +//#include "SimpleTouchScreenDSO.h" #include "digitalWriteFast.h" #else #include "Pages.h" @@ -53,7 +53,7 @@ void computeMinMax(void) { uint16_t tMax, tMin; uint16_t *tDataBufferPointer = DataBufferControl.DataBufferDisplayStart - + adjustIntWithScaleFactor(DisplayControl.DatabufferPreTriggerDisplaySize, DisplayControl.XScale); + + adjustIntWithScaleFactor(DisplayControl.DatabufferPreTriggerDisplaySize, DisplayControl.XScale); if (DataBufferControl.DataBufferEndPointer <= tDataBufferPointer) { return; } @@ -134,48 +134,48 @@ void computePeriodFrequency(void) { } for (i = 0; i < REMOTE_DISPLAY_WIDTH; ++i) { #else - /** - * Get period and frequency and average for display - * - * Use databuffer and only post trigger area! - * For frequency use only max values! - */ - uint16_t *tDataBufferPointer = DataBufferControl.DataBufferDisplayStart - + adjustIntWithScaleFactor(DisplayControl.DatabufferPreTriggerDisplaySize, DisplayControl.XScale); - if (DataBufferControl.DataBufferEndPointer <= tDataBufferPointer) { - return; - } - uint16_t tAcquisitionSize = DataBufferControl.DataBufferEndPointer + 1 - tDataBufferPointer; - - uint16_t tValue; - uint32_t tIntegrateValue = 0; - uint32_t tIntegrateValueForTotalPeriods = 0; - int tCount = 0; - uint16_t tStartPositionForPulsPause = 0; - uint16_t tFirstEndPositionForPulsPause = 0; - int tCountPosition = 0; - int tPeriodDelta = 0; - int tPeriodMin = 1024; - int tPeriodMax = 0; - int tTriggerStatus = TRIGGER_STATUS_START; - int tTriggerStatusForFirstInterval = TRIGGER_STATUS_START; - - uint16_t tActualCompareValue = MeasurementControl.RawTriggerLevelHysteresis; - - uint16_t tFirstTriggerLevel; // start with opposite hysteresis for measurement of first interval - if (MeasurementControl.TriggerSlopeRising) { - tFirstTriggerLevel = MeasurementControl.RawTriggerLevel + MeasurementControl.RawHysteresis; - } else { - tFirstTriggerLevel = MeasurementControl.RawTriggerLevel - MeasurementControl.RawHysteresis; - } + /** + * Get period and frequency and average for display + * + * Use databuffer and only post trigger area! + * For frequency use only max values! + */ + uint16_t *tDataBufferPointer = DataBufferControl.DataBufferDisplayStart + + adjustIntWithScaleFactor(DisplayControl.DatabufferPreTriggerDisplaySize, DisplayControl.XScale); + if (DataBufferControl.DataBufferEndPointer <= tDataBufferPointer) { + return; + } + uint16_t tAcquisitionSize = DataBufferControl.DataBufferEndPointer + 1 - tDataBufferPointer; - bool tReliableValue = true; + uint16_t tValue; + uint32_t tIntegrateValue = 0; + uint32_t tIntegrateValueForTotalPeriods = 0; + int tCount = 0; + uint16_t tStartPositionForPulsPause = 0; + uint16_t tFirstEndPositionForPulsPause = 0; + int tCountPosition = 0; + int tPeriodDelta = 0; + int tPeriodMin = 1024; + int tPeriodMax = 0; + int tTriggerStatus = TRIGGER_STATUS_START; + int tTriggerStatusForFirstInterval = TRIGGER_STATUS_START; - /* - * Trigger condition and average taken only from entire periods - * Use only max value for period - */ - for (int i = 0; i < tAcquisitionSize; ++i) { + uint16_t tActualCompareValue = MeasurementControl.RawTriggerLevelHysteresis; + + uint16_t tFirstTriggerLevel; // start with opposite hysteresis for measurement of first interval + if (MeasurementControl.TriggerSlopeRising) { + tFirstTriggerLevel = MeasurementControl.RawTriggerLevel + MeasurementControl.RawHysteresis; + } else { + tFirstTriggerLevel = MeasurementControl.RawTriggerLevel - MeasurementControl.RawHysteresis; + } + + bool tReliableValue = true; + + /* + * Trigger condition and average taken only from entire periods + * Use only max value for period + */ + for (int i = 0; i < tAcquisitionSize; ++i) { #endif tValue = *tDataBufferPointer; @@ -264,17 +264,17 @@ void computePeriodFrequency(void) { // found and search for next slope tIntegrateValueForTotalPeriods = tIntegrateValue; #endif - tCount++; - if (tCount == 0) { - // set start position for TRIGGER_MODE_FREE, TRIGGER_MODE_EXTERN or delayed trigger. - tStartPositionForPulsPause = i; - } else if (tCount == 1) { - // first complete period (pulse + pause) is detected here - MeasurementControl.PeriodSecond = getMicrosFromHorizontalDisplayValue(i - tFirstEndPositionForPulsPause, 1); - } - tCountPosition = i; + tCount++; + if (tCount == 0) { + // set start position for TRIGGER_MODE_FREE, TRIGGER_MODE_EXTERN or delayed trigger. + tStartPositionForPulsPause = i; + } else if (tCount == 1) { + // first complete period (pulse + pause) is detected here + MeasurementControl.PeriodSecond = getMicrosFromHorizontalDisplayValue(i - tFirstEndPositionForPulsPause, 1); + } + tCountPosition = i; #if !defined(AVR) - } + } #endif } } @@ -307,9 +307,9 @@ void computePeriodFrequency(void) { #if defined(AVR) if (tCount <= 0) { #else - if (tCountPosition <= 0 || tCount <= 0 || !tReliableValue) { - MeasurementControl.FrequencyHertz = 0; - MeasurementControl.RawValueAverage = (tIntegrateValue + (tAcquisitionSize / 2)) / tAcquisitionSize; + if (tCountPosition <= 0 || tCount <= 0 || !tReliableValue) { + MeasurementControl.FrequencyHertz = 0; + MeasurementControl.RawValueAverage = (tIntegrateValue + (tAcquisitionSize / 2)) / tAcquisitionSize; #endif MeasurementControl.PeriodMicros = 0; MeasurementControl.FrequencyHertz = 0; @@ -527,11 +527,11 @@ const char StringVBattDiv2[] PROGMEM = "\xBD" "VBatt"; const char *const ADCInputMUXChannelStrings[] = { StringChannel0, StringChannel1, StringChannel2, StringChannel3, StringChannel4, StringTemperature, StringVRefint }; #else -#if defined(STM)32F30X -const char * const ADCInputMUXChannelStrings[ADC_CHANNEL_COUNT] = {StringChannel2, StringChannel3, StringChannel4, - StringTemperature, StringVBattDiv2, StringVRefint}; -uint8_t const ADCInputMUXChannels[] = {ADC_CHANNEL_2, ADC_CHANNEL_3, ADC_CHANNEL_4, - ADC_CHANNEL_TEMPSENSOR, ADC_CHANNEL_VBAT, ADC_CHANNEL_VREFINT}; +#if defined(STM32F30X) +const char *const ADCInputMUXChannelStrings[ADC_CHANNEL_COUNT] = { StringChannel2, StringChannel3, StringChannel4, + StringTemperature, StringVBattDiv2, StringVRefint }; +uint8_t const ADCInputMUXChannels[] = { ADC_CHANNEL_2, ADC_CHANNEL_3, ADC_CHANNEL_4, +ADC_CHANNEL_TEMPSENSOR, ADC_CHANNEL_VBAT, ADC_CHANNEL_VREFINT }; #else const char * const ADCInputMUXChannelStrings[] = {StringChannel0, StringChannel1, StringChannel2, StringChannel3, StringTemperature, StringVRefint}; @@ -576,8 +576,13 @@ void initDSOGUI(void) { ***************************/ // 1. row // Button for Singleshot +#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 + TouchButtonSingleshot.init(BUTTON_WIDTH_6_POS_4, tPosY, BUTTON_WIDTH_3, START_PAGE_BUTTON_HEIGHT, + COLOR_GUI_CONTROL, F("Singleshot"), TEXT_SIZE_14, FLAG_BUTTON_DO_BEEP_ON_TOUCH, 0, &doStartSingleshot); +#endif // 2. row tPosY += START_PAGE_ROW_INCREMENT; @@ -600,7 +605,7 @@ void initDSOGUI(void) { #if !defined(AVR) // Button for show FFT - only for Start and Chart pages TouchButtonFFT.init(0, tPosY, BUTTON_WIDTH_3, BUTTON_HEIGHT_4, COLOR16_GREEN, "FFT", - TEXT_SIZE_22, FLAG_BUTTON_DO_BEEP_ON_TOUCH | FLAG_BUTTON_TYPE_TOGGLE_RED_GREEN_MANUAL_REFRESH, DisplayControl.ShowFFT, + TEXT_SIZE_22, FLAG_BUTTON_DO_BEEP_ON_TOUCH | FLAG_BUTTON_TYPE_TOGGLE_RED_GREEN_MANUAL_REFRESH, DisplayControl.ShowFFT, &doShowFFT); #endif @@ -619,7 +624,7 @@ void initDSOGUI(void) { */ #if defined(LOCAL_DISPLAY_EXISTS) TouchButtonChartHistoryOnOff.init(SLIDER_DEFAULT_BAR_WIDTH + 6, tPosY, BUTTON_WIDTH_3 - (SLIDER_DEFAULT_BAR_WIDTH + 6), - SETTINGS_PAGE_BUTTON_HEIGHT, COLOR_GUI_DISPLAY_CONTROL, "History", TEXT_SIZE_11, + SETTINGS_PAGE_BUTTON_HEIGHT, COLOR_GUI_DISPLAY_CONTROL, "History", TEXT_SIZE_11, FLAG_BUTTON_DO_BEEP_ON_TOUCH | FLAG_BUTTON_TYPE_TOGGLE_RED_GREEN_MANUAL_REFRESH, 0, &doChartHistory); #else TouchButtonChartHistoryOnOff.init(0, tPosY, BUTTON_WIDTH_3, SETTINGS_PAGE_BUTTON_HEIGHT, COLOR16_RED, F("History"), @@ -665,8 +670,8 @@ void initDSOGUI(void) { // Button for pretrigger area show #if defined(LOCAL_DISPLAY_EXISTS) TouchButtonShowPretriggerValuesOnOff.init(SLIDER_DEFAULT_BAR_WIDTH + 6, tPosY, - BUTTON_WIDTH_3 - (SLIDER_DEFAULT_BAR_WIDTH + 6), SETTINGS_PAGE_BUTTON_HEIGHT, - COLOR_BLACK, "Show\nPretrigger", TEXT_SIZE_11, FLAG_BUTTON_DO_BEEP_ON_TOUCH | FLAG_BUTTON_TYPE_TOGGLE_RED_GREEN, + BUTTON_WIDTH_3 - (SLIDER_DEFAULT_BAR_WIDTH + 6), SETTINGS_PAGE_BUTTON_HEIGHT, + COLOR_BLACK, "Show\nPretrigger", TEXT_SIZE_11, FLAG_BUTTON_DO_BEEP_ON_TOUCH | FLAG_BUTTON_TYPE_TOGGLE_RED_GREEN, (DisplayControl.DatabufferPreTriggerDisplaySize != 0), &doShowPretriggerValuesOnOff); #else TouchButtonShowPretriggerValuesOnOff.init(0, tPosY, BUTTON_WIDTH_3, SETTINGS_PAGE_BUTTON_HEIGHT, @@ -697,7 +702,7 @@ void initDSOGUI(void) { // Button for min/max acquisition mode #if defined(LOCAL_DISPLAY_EXISTS) TouchButtonMinMaxMode.init(SLIDER_DEFAULT_BAR_WIDTH + 6, tPosY, BUTTON_WIDTH_3 - (SLIDER_DEFAULT_BAR_WIDTH + 6), - SETTINGS_PAGE_BUTTON_HEIGHT, COLOR_GUI_DISPLAY_CONTROL, "", TEXT_SIZE_11, + SETTINGS_PAGE_BUTTON_HEIGHT, COLOR_GUI_DISPLAY_CONTROL, "", TEXT_SIZE_11, FLAG_BUTTON_DO_BEEP_ON_TOUCH | FLAG_BUTTON_TYPE_TOGGLE_RED_GREEN, MeasurementControl.isMinMaxMode, &doMinMaxMode); setMinMaxModeButtonCaption(); #else @@ -740,7 +745,7 @@ void initDSOGUI(void) { #else // Button for more-settings pages TouchButtonDSOMoreSettings.init(BUTTON_WIDTH_3_POS_3, tPosY, BUTTON_WIDTH_3, BUTTON_HEIGHT_5, - COLOR_GUI_CONTROL, "More", TEXT_SIZE_22, FLAG_BUTTON_DO_BEEP_ON_TOUCH, 0, &doShowMoreSettingsPage); + COLOR_GUI_CONTROL, "More", TEXT_SIZE_22, FLAG_BUTTON_DO_BEEP_ON_TOUCH, 0, &doShowMoreSettingsPage); /*************************** * More Settings page @@ -749,7 +754,7 @@ void initDSOGUI(void) { tPosY = 0; // Button for voltage calibration TouchButtonCalibrateVoltage.init(0, tPosY, BUTTON_WIDTH_3, BUTTON_HEIGHT_4, - COLOR_GUI_SOURCE_TIMEBASE, "Calibrate U", TEXT_SIZE_11, FLAG_BUTTON_DO_BEEP_ON_TOUCH, 0, &doVoltageCalibration); + COLOR_GUI_SOURCE_TIMEBASE, "Calibrate U", TEXT_SIZE_11, FLAG_BUTTON_DO_BEEP_ON_TOUCH, 0, &doVoltageCalibration); // 2. row tPosY += SETTINGS_PAGE_ROW_INCREMENT; // Button for system info @@ -775,19 +780,19 @@ void initDSOGUI(void) { // 2. row // Button for switching draw mode - line/pixel TouchButtonDrawModeLinePixel.init(0, BUTTON_HEIGHT_4_LINE_2, BUTTON_WIDTH_3, - BUTTON_HEIGHT_4, COLOR_GUI_DISPLAY_CONTROL, DrawModeButtonStringLine, TEXT_SIZE_11, FLAG_BUTTON_DO_BEEP_ON_TOUCH, 0, + BUTTON_HEIGHT_4, COLOR_GUI_DISPLAY_CONTROL, DrawModeButtonStringLine, TEXT_SIZE_11, FLAG_BUTTON_DO_BEEP_ON_TOUCH, 0, &doDrawMode); // Button for ADS7846 channel TouchButtonADS7846TestOnOff.init(BUTTON_WIDTH_3_POS_2, BUTTON_HEIGHT_4_LINE_2, BUTTON_WIDTH_3, BUTTON_HEIGHT_4, 0, "ADS7846", - TEXT_SIZE_11, FLAG_BUTTON_DO_BEEP_ON_TOUCH | FLAG_BUTTON_TYPE_TOGGLE_RED_GREEN, MeasurementControl.ADS7846ChannelsAsDatasource, + TEXT_SIZE_11, FLAG_BUTTON_DO_BEEP_ON_TOUCH | FLAG_BUTTON_TYPE_TOGGLE_RED_GREEN, MeasurementControl.ADS7846ChannelsAsDatasource, &doADS7846TestOnOff); /* * Backlight slider */ TouchSliderBacklight.init(0, 0, SLIDER_DEFAULT_BAR_WIDTH, BACKLIGHT_MAX_VALUE, BACKLIGHT_MAX_VALUE, getBacklightValue(), - COLOR16_BLUE, COLOR16_GREEN, FLAG_SLIDER_VERTICAL_SHOW_NOTHING, &doBacklightSlider); + COLOR16_BLUE, COLOR16_GREEN, FLAG_SLIDER_VERTICAL_SHOW_NOTHING, &doBacklightSlider); #endif } @@ -853,7 +858,7 @@ void redrawDisplay() { drawDataBuffer(DataBufferControl.DataBufferDisplayStart, COLOR_DATA_HOLD, DisplayControl.EraseColor); #else drawDataBuffer(DataBufferControl.DataBufferDisplayStart, REMOTE_DISPLAY_WIDTH, COLOR_DATA_HOLD, 0, - DRAW_MODE_REGULAR, MeasurementControl.isEffectiveMinMaxMode); + DRAW_MODE_REGULAR, MeasurementControl.isEffectiveMinMaxMode); #endif printInfo(); } else if (DisplayControl.DisplayPage == DISPLAY_PAGE_SETTINGS) { @@ -875,11 +880,12 @@ void drawStartPage(void) { // 4. Row #if !defined(AVR) TouchButtonFFT.drawButton(); + TouchButtonMainHome.drawButton(); #endif TouchButtonSettingsPage.drawButton(); //Welcome text - BlueDisplay1.drawText(10, BUTTON_HEIGHT_4_LINE_2 + 32, F("Welcome to\nArduino DSO"), 32, COLOR16_BLUE, - COLOR_BACKGROUND_DSO); + BlueDisplay1.drawMLText(10, BUTTON_HEIGHT_4_LINE_2 + 32, F("Welcome to\nArduino DSO"), 32, COLOR16_BLUE, + COLOR16_NO_BACKGROUND); BlueDisplay1.drawText(10, BUTTON_HEIGHT_4_LINE_2 + (3 * 32), F("300 kSamples/s"), 22, COLOR16_BLUE, COLOR_BACKGROUND_DSO); uint8_t tPos = BlueDisplay1.drawText(10, BUTTON_HEIGHT_4_LINE_2 + (3 * 32) + 22, F("V" VERSION_DSO "/" VERSION_BLUE_DISPLAY), @@ -889,15 +895,11 @@ void drawStartPage(void) { // Hints #if !defined(AVR) - BlueDisplay1.drawText(BUTTON_WIDTH_3_POS_2, TEXT_SIZE_22_ASCEND, "\xABScale\xBB", - TEXT_SIZE_22, COLOR_YELLOW, COLOR_BACKGROUND_DSO); + BlueDisplay1.drawText(BUTTON_WIDTH_3, TEXT_SIZE_11_ASCEND, "\xABScale\xBB", TEXT_SIZE_11, COLOR_YELLOW, + COLOR_BACKGROUND_DSO); #endif - BlueDisplay1.drawText(BUTTON_WIDTH_3_POS_2, BUTTON_HEIGHT_4_LINE_4 + BUTTON_DEFAULT_SPACING + TEXT_SIZE_22_ASCEND, + BlueDisplay1.drawText(BUTTON_WIDTH_3, BUTTON_HEIGHT_4_LINE_4 + BUTTON_DEFAULT_SPACING + TEXT_SIZE_22_ASCEND, F("\xABScroll\xBB"), TEXT_SIZE_22, COLOR16_GREEN, COLOR_BACKGROUND_DSO); - -#if defined(LOCAL_DISPLAY_EXISTS) - TouchButtonMainHome.drawButton(); -#endif } /** @@ -1007,7 +1009,7 @@ void drawRunningOnlyPartOfGui(void) { if (!MeasurementControl.RangeAutomatic || MeasurementControl.OffsetMode == OFFSET_MODE_MANUAL) { #if defined(LOCAL_DISPLAY_EXISTS) BlueDisplay1.drawMLText(TEXT_SIZE_11_WIDTH, TEXT_SIZE_11_HEIGHT + TEXT_SIZE_22_ASCEND, "\xD4\nR\na\nn\ng\ne\n\xD5", - TEXT_SIZE_22, COLOR_GUI_TRIGGER, COLOR16_NO_BACKGROUND); + TEXT_SIZE_22, COLOR_GUI_TRIGGER, COLOR16_NO_BACKGROUND); #else //START_PAGE_BUTTON_HEIGHT + TEXT_SIZE_22_ASCEND is to much for 240 display BlueDisplay1.drawText(TEXT_SIZE_11_WIDTH, START_PAGE_BUTTON_HEIGHT, F("\xD4\nR\na\nn\ng\ne\n\xD5"), TEXT_SIZE_22, @@ -1322,15 +1324,15 @@ void doSwitchInfoModeOnTouchUp(struct TouchEvent *const aTouchPosition) { // first check for buttons if (!TouchButton::checkAllButtons(aTouchPosition->TouchPosition.PosX, aTouchPosition->TouchPosition.PosY)) { #endif - if (DisplayControl.DisplayPage == DISPLAY_PAGE_CHART) { - // Wrap display mode + if (DisplayControl.DisplayPage == DISPLAY_PAGE_CHART) { + // Wrap display mode // uint8_t tOldMode = DisplayControl.showInfoMode; - uint8_t tNewMode = DisplayControl.showInfoMode + 1; - if (tNewMode > INFO_MODE_LONG_INFO) { - tNewMode = INFO_MODE_NO_INFO; - } - DisplayControl.showInfoMode = tNewMode; - redrawDisplay(); + uint8_t tNewMode = DisplayControl.showInfoMode + 1; + if (tNewMode > INFO_MODE_LONG_INFO) { + tNewMode = INFO_MODE_NO_INFO; + } + DisplayControl.showInfoMode = tNewMode; + redrawDisplay(); // if (tNewMode == INFO_MODE_NO_INFO) { // if (MeasurementControl.isRunning) { @@ -1344,9 +1346,9 @@ void doSwitchInfoModeOnTouchUp(struct TouchEvent *const aTouchPosition) { // clearInfo(tOldMode); // printInfo(); // } - } + } #if defined(LOCAL_DISPLAY_EXISTS) -} + } #endif } @@ -1354,7 +1356,7 @@ void doSwitchInfoModeOnTouchUp(struct TouchEvent *const aTouchPosition) { * If stopped toggle between Start and Chart page * If running toggle between gui display and chart only */ -void doLongTouchDownDSO(struct TouchEvent *const aTochPosition) { +void doLongTouchDownDSO(struct TouchEvent *const aTouchPosition) { static bool sIsGUIVisible = false; if (DisplayControl.DisplayPage == DISPLAY_PAGE_CHART) { if (MeasurementControl.isRunning) { @@ -1439,12 +1441,12 @@ void doSwipeEndDSO(struct Swipe *const aSwipeInfo) { #if !defined(AVR) if (aSwipeInfo->TouchStartY > BUTTON_HEIGHT_4_LINE_3 + TEXT_SIZE_22) { #endif - tFeedbackType = scrollChart(-aSwipeInfo->TouchDeltaX); + tFeedbackType = scrollChart(-aSwipeInfo->TouchDeltaX); #if !defined(AVR) - } else { - // scale - tFeedbackType = changeXScale(aSwipeInfo->TouchDeltaX / 64); - } + } else { + // scale + tFeedbackType = changeXScale(aSwipeInfo->TouchDeltaX / 64); + } #endif } } @@ -1529,7 +1531,7 @@ void doOffsetMode(BDButton *aTheTouchedButton, int16_t aValue) { } else if (MeasurementControl.OffsetMode == OFFSET_MODE_MANUAL) { // Offset mode manual implies range mode manual - aTheTouchedButton->setCaption(AutoOffsetButtonStringMan,true); + aTheTouchedButton->setCaption(AutoOffsetButtonStringMan, true); setAutoRangeModeAndButtonCaption(false); TouchButtonAutoRangeOnOff.deactivate(); #endif @@ -1728,7 +1730,7 @@ void doPromptForTriggerDelay(BDButton *aTheTouchedButton, int16_t aValue) { } #else -void doShowPretriggerValuesOnOff(BDButton * aTheTouchedButton, int16_t aValue) { +void doShowPretriggerValuesOnOff(BDButton *aTheTouchedButton, int16_t aValue) { DisplayControl.DatabufferPreTriggerDisplaySize = 0; if (aValue) { DisplayControl.DatabufferPreTriggerDisplaySize = (2 * DATABUFFER_DISPLAY_RESOLUTION); @@ -1738,7 +1740,7 @@ void doShowPretriggerValuesOnOff(BDButton * aTheTouchedButton, int16_t aValue) { /* * Sets only the flag and button caption */ -void doMinMaxMode(BDButton * aTheTouchedButton, int16_t aValue) { +void doMinMaxMode(BDButton *aTheTouchedButton, int16_t aValue) { MeasurementControl.isMinMaxMode = aValue; if (MeasurementControl.TimebaseEffectiveIndex >= TIMEBASE_INDEX_CAN_USE_OVERSAMPLING) { // changeTimeBase() manages oversampling rate for Min/Max oversampling @@ -1753,12 +1755,12 @@ void doMinMaxMode(BDButton * aTheTouchedButton, int16_t aValue) { /* * show gui of more settings screen */ -void doShowMoreSettingsPage(BDButton * aTheTouchedButton, int16_t aValue) { +void doShowMoreSettingsPage(BDButton *aTheTouchedButton, int16_t aValue) { DisplayControl.DisplayPage = DISPLAY_PAGE_MORE_SETTINGS; startDSOMoreSettingsPage(); } -void doShowSystemInfoPage(BDButton * aTheTouchedButton, int16_t aValue) { +void doShowSystemInfoPage(BDButton *aTheTouchedButton, int16_t aValue) { DisplayControl.DisplayPage = DISPLAY_PAGE_SYST_INFO; startSystemInfoPage(); } @@ -1766,7 +1768,7 @@ void doShowSystemInfoPage(BDButton * aTheTouchedButton, int16_t aValue) { /** * 3 ms for FFT, 9 ms complete with -OS */ -void doShowFFT(BDButton * aTheTouchedButton, int16_t aValue) { +void doShowFFT(BDButton *aTheTouchedButton, int16_t aValue) { DisplayControl.ShowFFT = aValue; aTheTouchedButton->setValue(aValue); @@ -1796,15 +1798,15 @@ void doShowFFT(BDButton * aTheTouchedButton, int16_t aValue) { /* * Toggle between pixel and line draw mode (for data chart) */ -void doDrawMode(BDButton * aTheTouchedButton, int16_t aValue) { +void doDrawMode(BDButton *aTheTouchedButton, int16_t aValue) { // erase old chart in old mode drawDataBuffer(NULL, REMOTE_DISPLAY_WIDTH, DisplayControl.EraseColor, 0, DRAW_MODE_CLEAR_OLD, MeasurementControl.isEffectiveMinMaxMode); // switch mode if (!DisplayControl.drawPixelMode) { - aTheTouchedButton->setCaption(DrawModeButtonStringPixel,true); + aTheTouchedButton->setCaption(DrawModeButtonStringPixel, true); } else { - aTheTouchedButton->setCaption(DrawModeButtonStringLine,true); + aTheTouchedButton->setCaption(DrawModeButtonStringLine, true); } DisplayControl.drawPixelMode = !DisplayControl.drawPixelMode; } @@ -1812,7 +1814,7 @@ void doDrawMode(BDButton * aTheTouchedButton, int16_t aValue) { /* * Toggles ADS7846Test on / off */ -void doADS7846TestOnOff(BDButton * aTheTouchedButton, int16_t aValue) { +void doADS7846TestOnOff(BDButton *aTheTouchedButton, int16_t aValue) { aValue = !aValue; MeasurementControl.ADS7846ChannelsAsDatasource = aValue; MeasurementControl.ADCInputMUXChannelIndex = 0; @@ -1837,3 +1839,4 @@ uint32_t getMicrosFromHorizontalDisplayValue(uint16_t aDisplayValueHorizontal, u #endif return (tMicros / (aNumberOfPeriods * TIMING_GRID_WIDTH)); } +#endif // _TOUCH_DSO_GUI_HPP diff --git a/Waveforms.cpp b/Waveforms.cpp index 9dac772..56fb99f 100644 --- a/Waveforms.cpp +++ b/Waveforms.cpp @@ -17,9 +17,9 @@ * Output is at PIN 10 * * PWM RC-Filter suggestions - * Simple: 2k2 Ohm and 100 nF - * 2nd order (good for sine and triangle): 1 kOhm and 100 nF -> 4k7 Ohm and 22 nF - * 2nd order (better for sawtooth): 1 kOhm and 22 nF -> 4k7 Ohm and 4.7 nF + * Simple: 2.2 kOhm and 100 nF + * 2nd order (good for sine and triangle): 1 kOhm and 100 nF -> 4.7 kOhm and 22 nF + * 2nd order (better for sawtooth): 1 kOhm and 22 nF -> 4.7 kOhm and 4.7 nF * * Copyright (C) 2017 Armin Joachimsmeyer * Email: armin.joachimsmeyer@gmail.com @@ -42,6 +42,8 @@ */ #include +#if defined(AVR) && defined(TCCR1A) + #include "Waveforms.h" #define TIMER_PRESCALER_MASK 0x07 @@ -451,3 +453,4 @@ void computeSineTableValues(uint8_t aSineTable[], unsigned int aNumber) { tRadian += tRadianDelta; } } +#endif // defined(AVR) && defined(TCCR1A) diff --git a/Waveforms.h b/Waveforms.h index a895cc7..38761a8 100644 --- a/Waveforms.h +++ b/Waveforms.h @@ -72,4 +72,3 @@ void startWaveform(); void computeSineTableValues(uint8_t aSineTable[], unsigned int aNumber); #endif // _WAVEFORMS_H -#pragma once diff --git a/digitalWriteFast.h b/digitalWriteFast.h index de3b06e..50d447c 100644 --- a/digitalWriteFast.h +++ b/digitalWriteFast.h @@ -1,13 +1,17 @@ /* - Optimized digital functions for AVR microcontrollers - by Watterott electronic (www.watterott.com) - based on http://code.google.com/p/digitalwritefast + * digitalWriteFast.h + * + * Optimized digital functions for AVR microcontrollers + * by Watterott electronic (www.watterott.com) + * based on https://code.google.com/p/digitalwritefast + * + * License: BSD 3-Clause License (https://opensource.org/licenses/BSD-3-Clause) */ #ifndef __digitalWriteFast_h_ #define __digitalWriteFast_h_ 1 -//#define SANGUINO_PINOUT //define for Sanguino pinout +//#define SANGUINO_PINOUT // define for Sanguino pinout // general macros/defines #if !defined(BIT_READ) @@ -23,125 +27,8 @@ # define BIT_WRITE(value, bit, bitvalue) (bitvalue ? BIT_SET(value, bit) : BIT_CLEAR(value, bit)) #endif -#if !defined(SWAP) -# define SWAP(x,y) do{ (x)=(x)^(y); (y)=(x)^(y); (x)=(x)^(y); }while(0) -#endif - -#if !defined(DEC) -# define DEC (10) -#endif -#if !defined(HEX) -# define HEX (16) -#endif -#if !defined(OCT) -# define OCT (8) -#endif -#if !defined(BIN) -# define BIN (2) -#endif - - -// workarounds for ARM microcontrollers -#if (!defined(__AVR__) || \ - defined(ARDUINO_ARCH_SAM) || \ - defined(ARDUINO_ARCH_SAMD)) - -#if !defined(PROGMEM) -# define PROGMEM -#endif -#if !defined(PGM_P) -# define PGM_P const char * -#endif -#if !defined(PSTR) -# define PSTR(str) (str) -#endif - -#if !defined(memcpy_P) -# define memcpy_P(dest, src, num) memcpy((dest), (src), (num)) -#endif -#if !defined(strcpy_P) -# define strcpy_P(dst, src) strcpy((dst), (src)) -#endif -#if !defined(strcat_P) -# define strcat_P(dst, src) strcat((dst), (src)) -#endif -#if !defined(strcmp_P) -# define strcmp_P(a, b) strcmp((a), (b)) -#endif -#if !defined(strcasecmp_P) -# define strcasecmp_P(a, b) strcasecmp((a), (b)) -#endif -#if !defined(strncmp_P) -# define strncmp_P(a, b, n) strncmp((a), (b), (n)) -#endif -#if !defined(strncasecmp_P) -# define strncasecmp_P(a, b, n) strncasecmp((a), (b), (n)) -#endif -#if !defined(strstr_P) -# define strstr_P(a, b) strstr((a), (b)) -#endif -#if !defined(strlen_P) -# define strlen_P(a) strlen((a)) -#endif -#if !defined(sprintf_P) -# define sprintf_P(s, f, ...) sprintf((s), (f), __VA_ARGS__) -#endif - -#if !defined(pgm_read_byte) -# define pgm_read_byte(addr) (*(const unsigned char *)(addr)) -#endif -#if !defined(pgm_read_word) -# define pgm_read_word(addr) (*(const unsigned short *)(addr)) -#endif -#if !defined(pgm_read_dword) -# define pgm_read_dword(addr) (*(const unsigned long *)(addr)) -#endif - -#endif - - -// digital functions -//#if !defined(digitalPinToPortReg) -#define SPI_SW_SS_PIN (10) //SS on Uno (for software SPI) -#define SPI_SW_MOSI_PIN (11) //MOSI on Uno (for software SPI) -#define SPI_SW_MISO_PIN (12) //MISO on Uno (for software SPI) -#define SPI_SW_SCK_PIN (13) //SCK on Uno (for software SPI) - - -// --- Arduino Due and SAM3X8E based boards --- -#if (defined(ARDUINO_SAM_DUE) || \ - defined(__SAM3X8E__)) - -#define UART_RX_PIN (0) -#define UART_TX_PIN (1) - -#define I2C_SDA_PIN (20) -#define I2C_SCL_PIN (21) - -#define SPI_HW_SS_PIN (78) //SS0:77, SS1:87, SS2:86, SS3:78 -#define SPI_HW_MOSI_PIN (75) //75 -#define SPI_HW_MISO_PIN (74) //74 -#define SPI_HW_SCK_PIN (76) //76 - - -// --- Arduino Zero and SAMD21G18 based boards --- -#elif (defined(ARDUINO_SAMD_ZERO) || \ - defined(__SAMD21G18A__)) - -#define UART_RX_PIN (0) -#define UART_TX_PIN (1) - -#define I2C_SDA_PIN (16) -#define I2C_SCL_PIN (17) - -#define SPI_HW_SS_PIN (14) //14 -#define SPI_HW_MOSI_PIN (21) //21 -#define SPI_HW_MISO_PIN (18) //18 -#define SPI_HW_SCK_PIN (20) //20 - - // --- Arduino Mega and ATmega128x/256x based boards --- -#elif (defined(ARDUINO_AVR_MEGA) || \ +#if (defined(ARDUINO_AVR_MEGA) || \ defined(ARDUINO_AVR_MEGA1280) || \ defined(ARDUINO_AVR_MEGA2560) || \ defined(__AVR_ATmega1280__) || \ @@ -149,23 +36,12 @@ defined(__AVR_ATmega2560__) || \ defined(__AVR_ATmega2561__)) -#define UART_RX_PIN (0) //PE0 -#define UART_TX_PIN (1) //PE1 - -#define I2C_SDA_PIN (20) -#define I2C_SCL_PIN (21) - -#define SPI_HW_SS_PIN (53) //PB0 -#define SPI_HW_MOSI_PIN (51) //PB2 -#define SPI_HW_MISO_PIN (50) //PB3 -#define SPI_HW_SCK_PIN (52) //PB1 - #define __digitalPinToPortReg(P) \ (((P) >= 22 && (P) <= 29) ? &PORTA : \ ((((P) >= 10 && (P) <= 13) || ((P) >= 50 && (P) <= 53)) ? &PORTB : \ (((P) >= 30 && (P) <= 37) ? &PORTC : \ ((((P) >= 18 && (P) <= 21) || (P) == 38) ? &PORTD : \ -((((P) >= 0 && (P) <= 3) || (P) == 5) ? &PORTE : \ +((((P) <= 3) || (P) == 5) ? &PORTE : \ (((P) >= 54 && (P) <= 61) ? &PORTF : \ ((((P) >= 39 && (P) <= 41) || (P) == 4) ? &PORTG : \ ((((P) >= 6 && (P) <= 9) || (P) == 16 || (P) == 17) ? &PORTH : \ @@ -177,7 +53,7 @@ ((((P) >= 10 && (P) <= 13) || ((P) >= 50 && (P) <= 53)) ? &DDRB : \ (((P) >= 30 && (P) <= 37) ? &DDRC : \ ((((P) >= 18 && (P) <= 21) || (P) == 38) ? &DDRD : \ -((((P) >= 0 && (P) <= 3) || (P) == 5) ? &DDRE : \ +((((P) <= 3) || (P) == 5) ? &DDRE : \ (((P) >= 54 && (P) <= 61) ? &DDRF : \ ((((P) >= 39 && (P) <= 41) || (P) == 4) ? &DDRG : \ ((((P) >= 6 && (P) <= 9) || (P) == 16 || (P) == 17) ? &DDRH : \ @@ -189,7 +65,7 @@ ((((P) >= 10 && (P) <= 13) || ((P) >= 50 && (P) <= 53)) ? &PINB : \ (((P) >= 30 && (P) <= 37) ? &PINC : \ ((((P) >= 18 && (P) <= 21) || (P) == 38) ? &PIND : \ -((((P) >= 0 && (P) <= 3) || (P) == 5) ? &PINE : \ +((((P) <= 3) || (P) == 5) ? &PINE : \ (((P) >= 54 && (P) <= 61) ? &PINF : \ ((((P) >= 39 && (P) <= 41) || (P) == 4) ? &PING : \ ((((P) >= 6 && (P) <= 9) || (P) == 16 || (P) == 17) ? &PINH : \ @@ -231,44 +107,40 @@ defined(__AVR_ATmega8535__)) && \ !defined(BOBUINO_PINOUT) -#define UART_RX_PIN (8) //PD0 -#define UART_TX_PIN (9) //PD1 - -#define I2C_SDA_PIN (17) //PC1 -#define I2C_SCL_PIN (16) //PC0 - -#define SPI_HW_SS_PIN (4) //PB4 -#define SPI_HW_MOSI_PIN (5) //PB5 -#define SPI_HW_MISO_PIN (6) //PB6 -#define SPI_HW_SCK_PIN (7) //PB7 - #if defined(__AVR_ATmega324PB__) #define __digitalPinToPortReg(P) \ -(((P) >= 0 && (P) <= 7) ? &PORTB : (((P) >= 8 && (P) <= 15) ? &PORTD : (((P) >= 16 && (P) <= 23) ? &PORTC : (((P) >= 24 && (P) <= 31) ? &PORTA : &PORTE)))) +(((P) <= 7) ? &PORTB : (((P) >= 8 && (P) <= 15) ? &PORTD : (((P) >= 16 && (P) <= 23) ? &PORTC : (((P) >= 24 && (P) <= 31) ? &PORTA : &PORTE)))) #define __digitalPinToDDRReg(P) \ -(((P) >= 0 && (P) <= 7) ? &DDRB : (((P) >= 8 && (P) <= 15) ? &DDRD : (((P) >= 16 && (P) <= 23) ? &DDRC : (((P) >= 24 && (P) <= 31) ? &DDRA : &DDRE)))) +(((P) <= 7) ? &DDRB : (((P) >= 8 && (P) <= 15) ? &DDRD : (((P) >= 16 && (P) <= 23) ? &DDRC : (((P) >= 24 && (P) <= 31) ? &DDRA : &DDRE)))) #define __digitalPinToPINReg(P) \ -(((P) >= 0 && (P) <= 7) ? &PINB : (((P) >= 8 && (P) <= 15) ? &PIND : (((P) >= 16 && (P) <= 23) ? &PINC : (((P) >= 24 && (P) <= 31) ? &PINA : &PINE)))) +(((P) <= 7) ? &PINB : (((P) >= 8 && (P) <= 15) ? &PIND : (((P) >= 16 && (P) <= 23) ? &PINC : (((P) >= 24 && (P) <= 31) ? &PINA : &PINE)))) # if defined(SANGUINO_PINOUT) #define __digitalPinToBit(P) \ -(((P) >= 0 && (P) <= 7) ? (P) : (((P) >= 8 && (P) <= 15) ? (P) - 8 : (((P) >= 16 && (P) <= 23) ? (P) - 16 : (((P) >= 16 && (P) <= 23) ? (7 - ((P) - 24)) : (P) - 32)))) +(((P) <= 7) ? (P) : (((P) >= 8 && (P) <= 15) ? (P) - 8 : (((P) >= 16 && (P) <= 23) ? (P) - 16 : (((P) >= 16 && (P) <= 23) ? (7 - ((P) - 24)) : (P) - 32)))) # else //MightyCore Pinout #define __digitalPinToBit(P) \ -(((P) >= 0 && (P) <= 7) ? (P) : (((P) >= 8 && (P) <= 15) ? (P) - 8 : (((P) >= 16 && (P) <= 23) ? (P) - 16 : (((P) >= 16 && (P) <= 23) ? (P) - 24 : (P) - 32)))) +(((P) <= 7) ? (P) : (((P) >= 8 && (P) <= 15) ? (P) - 8 : (((P) >= 16 && (P) <= 23) ? (P) - 16 : (((P) >= 16 && (P) <= 23) ? (P) - 24 : (P) - 32)))) # endif +#elif defined(PORTA) +#define __digitalPinToPortReg(P) \ +(((P) <= 7) ? &PORTB : (((P) >= 8 && (P) <= 15) ? &PORTD : (((P) >= 16 && (P) <= 23) ? &PORTC : &PORTA))) +#define __digitalPinToDDRReg(P) \ +(((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))) #else #define __digitalPinToPortReg(P) \ -(((P) >= 0 && (P) <= 7) ? &PORTB : (((P) >= 8 && (P) <= 15) ? &PORTD : (((P) >= 16 && (P) <= 23) ? &PORTC : &PORTA))) +(((P) <= 7) ? &PORTB : (((P) >= 8 && (P) <= 15) ? &PORTD : &PORTC)) #define __digitalPinToDDRReg(P) \ -(((P) >= 0 && (P) <= 7) ? &DDRB : (((P) >= 8 && (P) <= 15) ? &DDRD : (((P) >= 16 && (P) <= 23) ? &DDRC : &DDRA))) +(((P) <= 7) ? &DDRB : (((P) >= 8 && (P) <= 15) ? &DDRD : &DDRC)) #define __digitalPinToPINReg(P) \ -(((P) >= 0 && (P) <= 7) ? &PINB : (((P) >= 8 && (P) <= 15) ? &PIND : (((P) >= 16 && (P) <= 23) ? &PINC : &PINA))) +(((P) <= 7) ? &PINB : (((P) >= 8 && (P) <= 15) ? &PIND : &PINC)) # if defined(SANGUINO_PINOUT) #define __digitalPinToBit(P) \ -(((P) >= 0 && (P) <= 7) ? (P) : (((P) >= 8 && (P) <= 15) ? (P) - 8 : (((P) >= 16 && (P) <= 23) ? (P) - 16 : (7 - ((P) - 24))))) +(((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) >= 0 && (P) <= 7) ? (P) : (((P) >= 8 && (P) <= 15) ? (P) - 8 : (((P) >= 16 && (P) <= 23) ? (P) - 16 : (P) - 24))) +(((P) <= 7) ? (P) : (((P) >= 8 && (P) <= 15) ? (P) - 8 : (((P) >= 16 && (P) <= 23) ? (P) - 16 : (P) - 24))) # endif #endif @@ -277,27 +149,38 @@ #elif (defined(ARDUINO_AVR_LEONARDO) || \ defined(__AVR_ATmega16U4__) || \ defined(__AVR_ATmega32U4__)) - -#define UART_RX_PIN (0) //PD2 -#define UART_TX_PIN (1) //PD3 - -#define I2C_SDA_PIN (2) //PD1 -#define I2C_SCL_PIN (3) //PD0 - -#define SPI_HW_SS_PIN (17) //PB0 -#define SPI_HW_MOSI_PIN (16) //PB2 -#define SPI_HW_MISO_PIN (14) //PB3 -#define SPI_HW_SCK_PIN (15) //PB1 +# if defined(TEENSYDUINO) #define __digitalPinToPortReg(P) \ -((((P) >= 0 && (P) <= 4) || (P) == 6 || (P) == 12 || (P) == 24 || (P) == 25 || (P) == 29) ? &PORTD : (((P) == 5 || (P) == 13) ? &PORTC : (((P) >= 18 && (P) <= 23)) ? &PORTF : (((P) == 7) ? &PORTE : &PORTB))) +((((P) <= 4) || ((P) >= 13 && (P) <= 15)) ? &PORTB : (((P) == 9 || (P) == 10) ? &PORTC : (((P) >= 16 && (P) <= 21)) ? &PORTF : &PORTD)) #define __digitalPinToDDRReg(P) \ -((((P) >= 0 && (P) <= 4) || (P) == 6 || (P) == 12 || (P) == 24 || (P) == 25 || (P) == 29) ? &DDRD : (((P) == 5 || (P) == 13) ? &DDRC : (((P) >= 18 && (P) <= 23)) ? &DDRF : (((P) == 7) ? &DDRE : &DDRB))) +((((P) <= 4) || ((P) >= 13 && (P) <= 15)) ? &DDRB : (((P) == 9 || (P) == 10) ? &DDRC : (((P) >= 16 && (P) <= 21)) ? &DDRF : &DDRD)) #define __digitalPinToPINReg(P) \ -((((P) >= 0 && (P) <= 4) || (P) == 6 || (P) == 12 || (P) == 24 || (P) == 25 || (P) == 29) ? &PIND : (((P) == 5 || (P) == 13) ? &PINC : (((P) >= 18 && (P) <= 23)) ? &PINF : (((P) == 7) ? &PINE : &PINB))) +((((P) <= 4) || ((P) >= 13 && (P) <= 15)) ? &PINB : (((P) == 9 || (P) == 10) ? &PINC : (((P) >= 16 && (P) <= 21)) ? &PINF : &PIND)) #define __digitalPinToBit(P) \ -(((P) >= 8 && (P) <= 11) ? (P) - 4 : (((P) >= 18 && (P) <= 21) ? 25 - (P) : (((P) == 0) ? 2 : (((P) == 1) ? 3 : (((P) == 2) ? 1 : (((P) == 3) ? 0 : (((P) == 4) ? 4 : (((P) == 6) ? 7 : (((P) == 13) ? 7 : (((P) == 14) ? 3 : (((P) == 15) ? 1 : (((P) == 16) ? 2 : (((P) == 17) ? 0 : (((P) == 22) ? 1 : (((P) == 23) ? 0 : (((P) == 24) ? 4 : (((P) == 25) ? 7 : (((P) == 26) ? 4 : (((P) == 27) ? 5 : 6 ))))))))))))))))))) +(((P) <= 3) ? (P) : \ +(((P) == 4 || (P) == 12) ? 7 : \ +(((P) <= 8) ? (P) - 5 : \ +(((P) <= 10) ? (P) - 3 : \ +(((P) == 11) ? 6 : \ +(((P) <= 15) ? (P) - 9 : \ +(((P) <= 19) ? 23 - (P) : \ +(((P) <= 21) ? 21 - (P) : (P) - 18)))))))) +# else +#define __digitalPinToPortReg(P) \ +((((P) <= 4) || (P) == 6 || (P) == 12 || (P) == 24 || (P) == 25 || (P) == 29) ? &PORTD : (((P) == 5 || (P) == 13) ? &PORTC : (((P) >= 18 && (P) <= 23)) ? &PORTF : (((P) == 7) ? &PORTE : &PORTB))) +#define __digitalPinToDDRReg(P) \ +((((P) <= 4) || (P) == 6 || (P) == 12 || (P) == 24 || (P) == 25 || (P) == 29) ? &DDRD : (((P) == 5 || (P) == 13) ? &DDRC : (((P) >= 18 && (P) <= 23)) ? &DDRF : (((P) == 7) ? &DDRE : &DDRB))) +#define __digitalPinToPINReg(P) \ +((((P) <= 4) || (P) == 6 || (P) == 12 || (P) == 24 || (P) == 25 || (P) == 29) ? &PIND : (((P) == 5 || (P) == 13) ? &PINC : (((P) >= 18 && (P) <= 23)) ? &PINF : (((P) == 7) ? &PINE : &PINB))) +#define __digitalPinToBit(P) \ +(((P) >= 8 && (P) <= 11) ? (P) - 4 : \ +(((P) >= 18 && (P) <= 21) ? 25 - (P) : \ +(((P) == 0) ? 2 : (((P) == 1) ? 3 : (((P) == 2) ? 1 : (((P) == 3) ? 0 : (((P) == 4) ? 4 : (((P) == 6) ? 7 : (((P) == 13) ? 7 : \ +(((P) == 14) ? 3 : (((P) == 15) ? 1 : (((P) == 16) ? 2 : (((P) == 17) ? 0 : (((P) == 22) ? 1 : (((P) == 23) ? 0 : \ +(((P) == 24) ? 4 : (((P) == 25) ? 7 : (((P) == 26) ? 4 : (((P) == 27) ? 5 : 6 ))))))))))))))))))) +# endif // --- Arduino Uno and ATmega168/328 based boards --- #elif (defined(ARDUINO_AVR_UNO) || \ @@ -315,52 +198,29 @@ defined(__AVR_ATmega328P__) || \ defined(__AVR_ATmega328PB__)) -#define UART_RX_PIN (0) //PD0 -#define UART_TX_PIN (1) //PD1 - -#define I2C_SDA_PIN (18) //A4 -#define I2C_SCL_PIN (19) //A5 - -#define SPI_HW_SS_PIN (10) //PB0 -#define SPI_HW_MOSI_PIN (11) //PB2 -#define SPI_HW_MISO_PIN (12) //PB3 -#define SPI_HW_SCK_PIN (13) //PB1 - #if defined(__AVR_ATmega48PB__) || defined(__AVR_ATmega88PB__) || defined(__AVR_ATmega168PB__) || defined(__AVR_ATmega328PB__) #define __digitalPinToPortReg(P) \ -(((P) >= 0 && (P) <= 7) ? &PORTD : (((P) >= 8 && (P) <= 13) ? &PORTB : (((P) >= 14 && (P) <= 19) ? &PORTC : &PORTE))) +(((P) <= 7) ? &PORTD : (((P) >= 8 && (P) <= 13) ? &PORTB : (((P) >= 14 && (P) <= 19) ? &PORTC : &PORTE))) #define __digitalPinToDDRReg(P) \ -(((P) >= 0 && (P) <= 7) ? &DDRD : (((P) >= 8 && (P) <= 13) ? &DDRB : (((P) >= 14 && (P) <= 19) ? &DDRC : &DDRE))) +(((P) <= 7) ? &DDRD : (((P) >= 8 && (P) <= 13) ? &DDRB : (((P) >= 14 && (P) <= 19) ? &DDRC : &DDRE))) #define __digitalPinToPINReg(P) \ -(((P) >= 0 && (P) <= 7) ? &PIND : (((P) >= 8 && (P) <= 13) ? &PINB : (((P) >= 14 && (P) <= 19) ? &PINC : &PINE))) +(((P) <= 7) ? &PIND : (((P) >= 8 && (P) <= 13) ? &PINB : (((P) >= 14 && (P) <= 19) ? &PINC : &PINE))) #define __digitalPinToBit(P) \ -(((P) >= 0 && (P) <= 7) ? (P) : (((P) >= 8 && (P) <= 13) ? (P) - 8 : (((P) >= 14 && (P) <= 19) ? (P) - 14 : (((P) >= 20 && (P) <= 21) ? (P) - 18 : (P) - 22)))) +(((P) <= 7) ? (P) : (((P) >= 8 && (P) <= 13) ? (P) - 8 : (((P) >= 14 && (P) <= 19) ? (P) - 14 : (((P) >= 20 && (P) <= 21) ? (P) - 18 : (P) - 22)))) #else #define __digitalPinToPortReg(P) \ -(((P) >= 0 && (P) <= 7) ? &PORTD : (((P) >= 8 && (P) <= 13) ? &PORTB : &PORTC)) +(((P) <= 7) ? &PORTD : (((P) >= 8 && (P) <= 13) ? &PORTB : &PORTC)) #define __digitalPinToDDRReg(P) \ -(((P) >= 0 && (P) <= 7) ? &DDRD : (((P) >= 8 && (P) <= 13) ? &DDRB : &DDRC)) +(((P) <= 7) ? &DDRD : (((P) >= 8 && (P) <= 13) ? &DDRB : &DDRC)) #define __digitalPinToPINReg(P) \ -(((P) >= 0 && (P) <= 7) ? &PIND : (((P) >= 8 && (P) <= 13) ? &PINB : &PINC)) +(((P) <= 7) ? &PIND : (((P) >= 8 && (P) <= 13) ? &PINB : &PINC)) #define __digitalPinToBit(P) \ -(((P) >= 0 && (P) <= 7) ? (P) : (((P) >= 8 && (P) <= 13) ? (P) - 8 : (P) - 14)) +(((P) <= 7) ? (P) : (((P) >= 8 && (P) <= 13) ? (P) - 8 : (P) - 14)) #endif - // --- Arduino Uno WiFi Rev 2, Nano Every --- #elif defined(__AVR_ATmega4809__) -#define UART_RX_PIN (0) //PB0 -#define UART_TX_PIN (1) //PB1 - -#define I2C_SDA_PIN (22) //PA2 -#define I2C_SCL_PIN (23) //PA3 - -#define SPI_HW_SS_PIN (8) //PE3 -#define SPI_HW_MOSI_PIN (11) //PE0 -#define SPI_HW_MISO_PIN (12) //PE1 -#define SPI_HW_SCK_PIN (13) //PE2 - #define __digitalPinToPortReg(P) \ (((P) == 2 || (P) == 7 ) ? &VPORTA.OUT : ((P) == 5 || (P) == 9 || (P) == 10) ? &VPORTB.OUT : ((P) == 4) ? &VPORTC.OUT : (((P) >= 14 && (P) <= 17) || (P) == 20 || (P) == 21) ? &VPORTD.OUT : ((P) == 8 || (P) == 11 || (P) == 12 || (P) == 13) ? &VPORTE.OUT : &VPORTF.OUT) #define __digitalPinToDDRReg(P) \ @@ -374,12 +234,24 @@ // TinyCore // https://raw.githubusercontent.com/xukangmin/TinyCore/master/avr/package/package_tinycore_index.json // https://docs.tinycore.dev/en/latest/ -#elif defined(__AVR_ATtiny1616__) || defined(__AVR_ATtiny3216__) || defined(__AVR_ATtiny3217__) +#elif defined(__AVR_ATtiny1616__) || defined(__AVR_ATtiny3216__) || defined(__AVR_ATtiny3217__) #define __digitalPinToPortReg(P) ((P) <= 5 ? &VPORTB.OUT : ((P) <= 9 ? &VPORTC.OUT : ((P) <= 16 ? &VPORTA.OUT : ((P) <= 18 ? &VPORTB.OUT : &VPORTC.OUT)))) #define __digitalPinToDDRReg(P) ((P) <= 5 ? &VPORTB.DIR : ((P) <= 9 ? &VPORTC.DIR : ((P) <= 16 ? &VPORTA.DIR : ((P) <= 18 ? &VPORTB.DIR : &VPORTC.DIR)))) #define __digitalPinToPINReg(P) ((P) <= 5 ? &VPORTB.IN : ((P) <= 9 ? &VPORTC.IN : ((P) <= 16 ? &VPORTA.IN : ((P) <= 18 ? &VPORTB.IN : &VPORTC.IN)))) #define __digitalPinToBit(P) ( (P) <= 3 ? (3 - P) : ((P) <= 5 ? (P) : ((P) <= 9 ? (P - 6) : ((P) <= 16 ? ((P) - 9) : ((P) <= 18 ? ((P) - 11) : ((P) - 15))))) ) +#elif defined(__AVR_ATtiny1614__) +#define __digitalPinToPortReg(P) ((P) <= 3 ? &VPORTA.OUT : ((P) <= 7 ? &VPORTB.OUT : &VPORTA.OUT)) +#define __digitalPinToDDRReg(P) ((P) <= 3 ? &VPORTA.DIR : ((P) <= 7 ? &VPORTB.DIR : &VPORTA.DIR)) +#define __digitalPinToPINReg(P) ((P) <= 3 ? &VPORTA.IN : ((P) <= 7 ? &VPORTB.IN : &VPORTA.IN)) +#define __digitalPinToBit(P) ( (P) <= 3 ? (P + 4) : ((P) <= 7 ? (7 - P) : ((P) <= 10 ? (P - 7) : (P) - 11)) ) + +#elif defined(__AVR_ATtiny816__) +// https://github.com/Arduino-IRremote/Arduino-IRremote/discussions/1029 +#define __digitalPinToPortReg(P) ((P) <= 3 ? &VPORTA.OUT : ((P) <= 9 ? &VPORTB.OUT : ((P) <= 13 ? &VPORTC.OUT : ((P) <= 17 ? &VPORTA.OUT : &VPORTC.OUT)))) +#define __digitalPinToDDRReg(P) ((P) <= 3 ? &VPORTA.DIR : ((P) <= 9 ? &VPORTB.DIR : ((P) <= 13 ? &VPORTC.DIR : ((P) <= 17 ? &VPORTA.DIR : &VPORTC.DIR)))) +#define __digitalPinToPINReg(P) ((P) <= 3 ? &VPORTA.IN : ((P) <= 9 ? &VPORTB.IN : ((P) <= 13 ? &VPORTC.IN : ((P) <= 17 ? &VPORTA.IN : &VPORTC.IN)))) +#define __digitalPinToBit(P) ( (P) <= 3 ? (P + 4) : ((P) <= 9 ? (9 - P) : ((P) <= 13 ? (P - 10) : ((P) <= 16 ? (P - 13) : ((P) - 17)))) ) // --- ATtinyX5 --- #elif defined(__AVR_ATtiny25__) || defined(__AVR_ATtiny45__) || defined(__AVR_ATtiny85__) @@ -406,7 +278,8 @@ // --- ATtinyX4 + ATtinyX7 --- -#elif defined(__AVR_ATtiny24__) || defined(__AVR_ATtiny44__) || defined(__AVR_ATtiny84__) || defined(__AVR_ATtiny87__) || defined(__AVR_ATtiny167__) +#elif defined(__AVR_ATtiny24__) || defined(__AVR_ATtiny44__) || defined(__AVR_ATtiny84__) \ + || defined(__AVR_ATtiny441__) || defined(__AVR_ATtiny841__) || defined(__AVR_ATtiny87__) || defined(__AVR_ATtiny167__) # if defined(ARDUINO_AVR_DIGISPARKPRO) || PIN_PA7 == 5 // Strange enumeration of pins on Digispark board and core library #define __digitalPinToPortReg(P) (((P) <= 4) ? &PORTB : &PORTA) @@ -419,41 +292,59 @@ #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__) +// 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 #define __digitalPinToBit(P) (((P) <= 7) ? (P) : (P) - 8 ) # endif -// --- Other --- -#else - -#define I2C_SDA_PIN SDA -#define I2C_SCL_PIN SCL - -#define SPI_HW_SS_PIN SS -#define SPI_HW_MOSI_PIN MOSI -#define SPI_HW_MISO_PIN MISO -#define SPI_HW_SCK_PIN SCK - - #endif -//#endif //#if !defined(digitalPinToPortReg) +void NonConstantsUsedForPinModeFast( void ) __attribute__ (( error("Parameter for pinModeFast() function is not constant") )); +void NonConstantsUsedForDigitalWriteFast( void ) __attribute__ (( error("Parameter for digitalWriteFast() function is not constant") )); +void NonConstantsUsedForDigitalToggleFast( void ) __attribute__ (( error("Parameter for digitalToggleFast() function is not constant") )); +int NonConstantsUsedForDigitalReadFast( void ) __attribute__ (( error("Parameter for digitalReadFast() function is not constant") )); + #if !defined(digitalWriteFast) -#if (defined(__AVR__) || defined(ARDUINO_ARCH_AVR)) && defined(__digitalPinToPortReg) +# if (defined(__AVR__) || defined(ARDUINO_ARCH_AVR)) && defined(__digitalPinToPortReg) +# if defined(THROW_ERROR_IF_NOT_FAST) +#define digitalWriteFast(P, V) \ +if (__builtin_constant_p(P)) { \ + BIT_WRITE(*__digitalPinToPortReg(P), __digitalPinToBit(P), (V)); \ +} else { \ + NonConstantsUsedForDigitalWriteFast(); \ +} +# else #define digitalWriteFast(P, V) \ if (__builtin_constant_p(P)) { \ BIT_WRITE(*__digitalPinToPortReg(P), __digitalPinToBit(P), (V)); \ } else { \ digitalWrite((P), (V)); \ } -#else +# endif // defined(THROW_ERROR_IF_NOT_FAST) +# else #define digitalWriteFast digitalWrite +# endif #endif -#endif - #if !defined(pinModeFast) -#if (defined(__AVR__) || defined(ARDUINO_ARCH_AVR)) && defined(__digitalPinToPortReg) +# if (defined(__AVR__) || defined(ARDUINO_ARCH_AVR)) && defined(__digitalPinToPortReg) +# if defined(THROW_ERROR_IF_NOT_FAST) +#define pinModeFast(P, V) \ +if (__builtin_constant_p(P) && __builtin_constant_p(V)) { \ + if (V == INPUT_PULLUP) {\ + BIT_CLEAR(*__digitalPinToDDRReg(P), __digitalPinToBit(P)); \ + BIT_SET(*__digitalPinToPortReg(P), __digitalPinToBit(P)); \ + } else { \ + BIT_WRITE(*__digitalPinToDDRReg(P), __digitalPinToBit(P), (V)); \ + } \ +} else { \ + NonConstantsUsedForPinModeFast(); \ +} +# else #define pinModeFast(P, V) \ if (__builtin_constant_p(P) && __builtin_constant_p(V)) { \ if (V == INPUT_PULLUP) {\ @@ -465,37 +356,54 @@ if (__builtin_constant_p(P) && __builtin_constant_p(V)) { \ } else { \ pinMode((P), (V)); \ } -#else +# endif // defined(THROW_ERROR_IF_NOT_FAST) +# else #define pinModeFast pinMode -#endif -#endif - +# endif +#endif // !defined(pinModeFast) #if !defined(digitalReadFast) -#if (defined(__AVR__) || defined(ARDUINO_ARCH_AVR)) +# if (defined(__AVR__) || defined(ARDUINO_ARCH_AVR)) && defined(__digitalPinToPINReg) +# if defined(THROW_ERROR_IF_NOT_FAST) +#define digitalReadFast(P) ( (int) __digitalReadFast((P)) ) +// since we have return values, it is easier to implement it by ?: +#define __digitalReadFast(P ) \ + (__builtin_constant_p(P) ) ? \ + (( BIT_READ(*__digitalPinToPINReg(P), __digitalPinToBit(P))) ? HIGH:LOW ) : \ + NonConstantsUsedForDigitalReadFast() +# else #define digitalReadFast(P) ( (int) __digitalReadFast((P)) ) +// since we have return values, it is easier to implement it by ?: #define __digitalReadFast(P ) \ (__builtin_constant_p(P) ) ? \ (( BIT_READ(*__digitalPinToPINReg(P), __digitalPinToBit(P))) ? HIGH:LOW ) : \ digitalRead((P)) -#else +# endif // defined(THROW_ERROR_IF_NOT_FAST) +# else #define digitalReadFast digitalRead -#endif -#endif - +# endif +#endif // !defined(digitalReadFast) #if !defined(digitalToggleFast) -#if (defined(__AVR__) || defined(ARDUINO_ARCH_AVR)) +# if (defined(__AVR__) || defined(ARDUINO_ARCH_AVR)) && defined(__digitalPinToPINReg) +# if defined(THROW_ERROR_IF_NOT_FAST) +#define digitalToggleFast(P) \ +if (__builtin_constant_p(P)) { \ + BIT_SET(*__digitalPinToPINReg(P), __digitalPinToBit(P)); \ +} else { \ + NonConstantsUsedForDigitalToggleFast(); \ +} +# else #define digitalToggleFast(P) \ if (__builtin_constant_p(P)) { \ BIT_SET(*__digitalPinToPINReg(P), __digitalPinToBit(P)); \ } else { \ digitalWrite(P, ! digitalRead(P)); \ } -#else +# endif // defined(THROW_ERROR_IF_NOT_FAST) +# else #define digitalToggleFast(P) digitalWrite(P, ! digitalRead(P)) -#endif -#endif - +# endif +#endif // !defined(digitalToggleFast) #endif //__digitalWriteFast_h_ diff --git a/extras/.picasa.ini b/extras/.picasa.ini deleted file mode 100644 index df253ab..0000000 --- a/extras/.picasa.ini +++ /dev/null @@ -1,2 +0,0 @@ -[Picasa] -name=extras diff --git a/pictures/Frequency.jpg b/pictures/Frequency.jpg index 8af0655..12151da 100644 Binary files a/pictures/Frequency.jpg and b/pictures/Frequency.jpg differ diff --git a/pictures/Settings_Passive_Attenuator.jpg b/pictures/Settings_Passive_Attenuator.jpg index fe5c7f7..043d473 100644 Binary files a/pictures/Settings_Passive_Attenuator.jpg and b/pictures/Settings_Passive_Attenuator.jpg differ diff --git a/pictures/Settings_simple.jpg b/pictures/Settings_simple.jpg index f7f7a6e..49d7c9d 100644 Binary files a/pictures/Settings_simple.jpg and b/pictures/Settings_simple.jpg differ diff --git a/pictures/Welcome.jpg b/pictures/Welcome.jpg index 5c03d58..f3bf1bd 100644 Binary files a/pictures/Welcome.jpg and b/pictures/Welcome.jpg differ