From e181f0e2b94c9c352100aa7a6aa851d66072a86e Mon Sep 17 00:00:00 2001 From: Frej Drejhammar Date: Sun, 19 Jul 2015 14:58:31 +0200 Subject: [PATCH] cores: Add ADC to the ATtiny13 --- simavr/cores/sim_tiny13.c | 50 ++++++++++++++++++++++++++++++++++++++- 1 file changed, 49 insertions(+), 1 deletion(-) diff --git a/simavr/cores/sim_tiny13.c b/simavr/cores/sim_tiny13.c index 23793bc..469926c 100644 --- a/simavr/cores/sim_tiny13.c +++ b/simavr/cores/sim_tiny13.c @@ -27,6 +27,7 @@ #include "avr_extint.h" #include "avr_ioport.h" #include "avr_timer.h" +#include "avr_adc.h" #define _AVR_IO_H_ #define __ASSEMBLER__ @@ -43,6 +44,7 @@ static const struct mcu_t { avr_extint_t extint; avr_ioport_t portb; avr_timer_t timer0; + avr_adc_t adc; } mcu = { .core = { .mmcu = "attiny13", @@ -116,7 +118,52 @@ static const struct mcu_t { } } } - } + }, + .adc = { + .r_admux = ADMUX, + .mux = { AVR_IO_REGBIT(ADMUX, MUX0), + AVR_IO_REGBIT(ADMUX, MUX1), }, + .ref = { AVR_IO_REGBIT(ADMUX, REFS0), }, + .ref_values = { + [0] = ADC_VREF_VCC, [1] = ADC_VREF_V110, + }, + + .adlar = AVR_IO_REGBIT(ADMUX, ADLAR), + .r_adcsra = ADCSRA, + .aden = AVR_IO_REGBIT(ADCSRA, ADEN), + .adsc = AVR_IO_REGBIT(ADCSRA, ADSC), + .adate = AVR_IO_REGBIT(ADCSRA, ADATE), + .adps = { AVR_IO_REGBIT(ADCSRA, ADPS0), + AVR_IO_REGBIT(ADCSRA, ADPS1), + AVR_IO_REGBIT(ADCSRA, ADPS2),}, + + .r_adch = ADCH, + .r_adcl = ADCL, + + .r_adcsrb = ADCSRB, + .adts = { AVR_IO_REGBIT(ADCSRB, ADTS0), + AVR_IO_REGBIT(ADCSRB, ADTS1), + AVR_IO_REGBIT(ADCSRB, ADTS2),}, + .adts_op = { + [0] = avr_adts_free_running, + [1] = avr_adts_analog_comparator_0, + [2] = avr_adts_external_interrupt_0, + [3] = avr_adts_timer_0_compare_match_a, + [4] = avr_adts_timer_0_overflow, + [5] = avr_adts_timer_0_compare_match_b, + [6] = avr_adts_pin_change_interrupt, + }, + .muxmode = { + [0] = AVR_ADC_SINGLE(0), [1] = AVR_ADC_SINGLE(1), + [2] = AVR_ADC_SINGLE(2), [3] = AVR_ADC_SINGLE(3), + }, + + .adc = { + .enable = AVR_IO_REGBIT(ADCSRA, ADIE), + .raised = AVR_IO_REGBIT(ADCSRA, ADIF), + .vector = ADC_vect, + }, + }, }; static avr_t * make() @@ -138,6 +185,7 @@ static void init(struct avr_t * avr) avr_extint_init(avr, &mcu->extint); avr_ioport_init(avr, &mcu->portb); avr_timer_init(avr, &mcu->timer0); + avr_adc_init(avr, &mcu->adc); } static void reset(struct avr_t * avr) -- 2.39.5