summaryrefslogtreecommitdiff
path: root/n/avr/adc/test_adc.c
blob: b01b7a084bf02baa4349525fcfa55194387b3c89 (plain)
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
/* test_adc.c */
/*  {{{
 *
 * Copyright (C) 2005 Thomas Burg
 *
 * This program 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.
 * 
 * This program 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 this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
 *
 * Contact :
 *      Email: <burg@efrei.fr>
 * }}} */
#include <n/avr/proto/proto.h>
#include <n/avr/rs232/rs232.h>
#include <n/avr/utils/utils.h>
#include <n/avr/twi-slave/twi_slave.h>

#include "adc.h"

#include <avr/interrupt.h>

/* +AutoDec */
/* -AutoDec */

uint8_t go;

void
proto_callback (uint8_t cmd, uint8_t size, uint8_t *args)
{
    switch (cmd)
    {
	case 'z':
	    reset ();
	    break;
	case 'm':
	    go = 1;
	    break;
    }
    proto_send (cmd, size, args);
}

void
proto_putc (uint8_t c)
{
    rs232_putc (c);
}

int
main (void)
{
    uint16_t adc[3];
    int i;
    go = 0;
    rs232_init ();
    proto_send0 ('z');
    sei ();
    adc_init ();
    twi_init (0x02);
    while (1)
      {
        delay_ms (100L);
	/* D�marre une acquisition de mesure sur l'adc 0. */
	for (i = 0; i < 3; i ++)
	  {
	    adc_start (i);

	    /* Attente active sur adc jusqu'a ce que la valeur soit disponible. */
	    while (adc_checkf() !=0)
		;
	    /* Lit l'adc. */
	    adc[i] = adc_read();
	  }

	/* Lit la valeur puis l'envoit. */
	if (go)
	    proto_send3w ('m', adc[0], adc[1], adc[2]);
	twi_update ((uint8_t *) adc, 6);
	if (rs232_poll ())
	    proto_accept (rs232_getc ());
      }
    return 0;
}