-
Notifications
You must be signed in to change notification settings - Fork 1
/
small-scope.h
103 lines (86 loc) · 3.47 KB
/
small-scope.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
//-----------------------------------------------------------------------------
// small-scope.h
//-----------------------------------------------------------------------------
// Copyright 2015 Marvin Sinister
//
// This file is part of small-scope.
//
// small-scope 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.
//
// small-scope 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 small-scope. If not, see <http://www.gnu.org/licenses/>.
//
//-----------------------------------------------------------------------------
// Includes
//-----------------------------------------------------------------------------
#include <Arduino.h>
//-----------------------------------------------------------------------------
// Defines and Typedefs
//-----------------------------------------------------------------------------
#define DEBUG 0
#define ADCBUFFERSIZE 1024
#define ADCPIN 0
#define errorPin 13
#define thresholdPin 3
#define BAUDRATE 500000 // Baud rate of UART in bps
#define COMMANDDELAY 2 // ms to wait for the filling of Serial buffer
#define COMBUFFERSIZE 4 // Size of buffer for incoming numbers
#if DEBUG == 1
#define dprint(expression) Serial.print("# "); Serial.print( #expression ); Serial.print( ": " ); Serial.println( expression )
#define dshow(expression) Serial.println( expression )
#else
#define dprint(expression)
#define dshow(expression)
#endif
// Defines for setting and clearing register bits
#ifndef cbi
#define cbi(sfr, bit) (_SFR_BYTE(sfr) &= ~_BV(bit))
#endif
#ifndef sbi
#define sbi(sfr, bit) (_SFR_BYTE(sfr) |= _BV(bit))
#endif
//-----------------------------------------------------------------------------
// Global Constants
//-----------------------------------------------------------------------------
//-----------------------------------------------------------------------------
// Function Prototypes
//-----------------------------------------------------------------------------
void initPins(void);
void initADC(void);
void initAnalogComparator(void);
void startADC( void );
void stopADC( void );
void startAnalogComparator( void );
void stopAnalogComparator( void );
void setADCPrescaler( uint8_t prescaler );
void setVoltageReference( uint8_t reference );
void setTriggerEvent( uint8_t event );
void error (void);
// Fills the given buffer with bufferSize chars from a Serial object
void fillBuffer( \
char *buffer, \
byte bufferSize, \
HardwareSerial* serial = &Serial );
void printStatus(void);
//-----------------------------------------------------------------------------
// Global Variables
//-----------------------------------------------------------------------------
extern volatile uint16_t waitDuration;
extern volatile int16_t waitRemaining;
extern volatile uint16_t stopIndex;
extern volatile uint16_t triggerIndex;
extern volatile uint16_t ADCCounter;
extern volatile uint8_t ADCBuffer[ADCBUFFERSIZE];
extern volatile boolean freeze;
extern uint8_t prescaler;
extern uint8_t triggerEvent;
extern uint8_t threshold;
extern char commandBuffer[COMBUFFERSIZE+1];