-
Notifications
You must be signed in to change notification settings - Fork 0
/
adc.h
66 lines (55 loc) · 2.04 KB
/
adc.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
/*
* Copyright (C) 2006, Joe Lake, monome.org
*
* This file is part of 40h.
*
* 40h 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 2 of the License, or
* (at your option) any later version.
*
* 40h 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 40h; if not, write to the Free Software
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*
* $Id: adc.h,v. 1.1.1.1 2006/05/02 1:01:22
*/
/*
Altered source version
Modified by: Sean Echevarria (http://www.creepingfog.com/sean/) 2007.11.03
changed kAdcFilterNumBuckets and kAdcFilterRightShiftValue
*/
#ifndef __ADC_H__
#define __ADC_H__
#include "types.h"
#define kAdcFilterNumAdcs 4
#define kAdcFilterNumBuckets 4 // 4 8 16
#define kAdcFilterRightShiftValue 2 // 2 3 4
#ifdef __cplusplus
extern "C"
{
#endif
typedef struct _adc_filter {
uint16 bucket[kAdcFilterNumBuckets]; // ring buffer for storing adc frames
uint16 accum; // sum of all adc frames in bucket
uint8 index; // write index into bucket
volatile uint16 value; // average of all values in bucket
uint16 last_value; // last value (dirty only gets set if value != last_value)
volatile uint8 dirty; // flag to indicate whether or not the adc value has changed and should be output
} t_adc_filter;
void initAdcs(void);
void disableAdcs(void);
void hardInitAdcs(void);
void initAdcFilters(void);
void adcAddNextValue(uint8 adc, uint16 value);
void enableAdc(uint8 adc);
void disableAdc(uint8 adc);
extern t_adc_filter gAdcFilters[kAdcFilterNumAdcs];
#ifdef __cplusplus
}
#endif
#endif