e756871b2924505b3fc6eb498b78792a6708e7ae
[simavr] / simavr / sim / avr_adc.h
1 /*
2         avr_adc.h
3
4         Copyright 2008, 2009 Michel Pollet <buserror@gmail.com>
5
6         This file is part of simavr.
7
8         simavr is free software: you can redistribute it and/or modify
9         it under the terms of the GNU General Public License as published by
10         the Free Software Foundation, either version 3 of the License, or
11         (at your option) any later version.
12
13         simavr is distributed in the hope that it will be useful,
14         but WITHOUT ANY WARRANTY; without even the implied warranty of
15         MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16         GNU General Public License for more details.
17
18         You should have received a copy of the GNU General Public License
19         along with simavr.  If not, see <http://www.gnu.org/licenses/>.
20  */
21
22 #ifndef __AVR_ADC_H___
23 #define __AVR_ADC_H___
24
25 #include "sim_avr.h"
26
27 typedef struct avr_adc_t {
28         avr_io_t                io;
29
30         uint8_t                 r_admux;
31         // if the last bit exists in the mux, we are an extended ADC
32         avr_regbit_t    mux[5];
33         avr_regbit_t    ref[3];         // reference voltage
34         avr_regbit_t    adlar;          // left/right adjustment bit
35
36         uint8_t                 r_adcsra;       // ADC Control and Status Register A
37         avr_regbit_t    aden;           // ADC Enabled
38         avr_regbit_t    adsc;           // ADC Start Conversion
39         avr_regbit_t    adate;          // ADC Auto Trigger Enable
40
41         avr_regbit_t    adps[3];        // Prescaler bits. Note that it's a frequency bit shift
42
43         uint8_t                 r_adcl, r_adch; // Data Registers
44
45         uint8_t                 r_adcsrb;       // ADC Control and Status Register B
46         avr_regbit_t    adts[3];        // Timing Source
47         avr_regbit_t    bin;            // Bipolar Input Mode (tinyx5 have it)
48         avr_regbit_t    ipr;            // Input Polarity Reversal (tinyx5 have it)
49
50
51         // use ADIF and ADIE bits
52         avr_int_vector_t adc;
53 } avr_adc_t;
54
55 void avr_adc_init(avr_t * avr, avr_adc_t * port);
56
57 #endif /* __AVR_ADC_H___ */