Mercurial > ~darius > hgwebdir.cgi > avr-lib
comparison 1wire-config-avr.h @ 13:6f8f7b87d2f1
- Rename 1wire config example to note it's for AVR.
- Add STM32 config.
- Rework a little to remove AVR depedencies.
- Re-do OWProgROM in the no VPP case so it doesn't generate warnings.
author | Daniel O'Connor <darius@dons.net.au> |
---|---|
date | Tue, 07 Feb 2012 13:53:21 +1030 |
parents | 1wire-config.h@d111f64eb619 |
children | 3aac1bb54918 |
comparison
equal
deleted
inserted
replaced
12:4e10d1eef9a5 | 13:6f8f7b87d2f1 |
---|---|
1 /* | |
2 * Example configuration header for 1-wire bus code. | |
3 * | |
4 * This is the user servicable stuff - how to do delays and how to | |
5 * frob the IO pins. | |
6 * | |
7 * Copyright (c) 2009 | |
8 * Daniel O'Connor <darius@dons.net.au>. All rights reserved. | |
9 * | |
10 * Redistribution and use in source and binary forms, with or without | |
11 * modification, are permitted provided that the following conditions | |
12 * are met: | |
13 * 1. Redistributions of source code must retain the above copyright | |
14 * notice, this list of conditions and the following disclaimer. | |
15 * 2. Redistributions in binary form must reproduce the above copyright | |
16 * notice, this list of conditions and the following disclaimer in the | |
17 * documentation and/or other materials provided with the distribution. | |
18 * | |
19 * THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND | |
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
22 * ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE | |
23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | |
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | |
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | |
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |
29 * SUCH DAMAGE. | |
30 */ | |
31 | |
32 /* | |
33 * Alter these for your configuration | |
34 * | |
35 * The configuration described here has the 1-wire read on D3, | |
36 * a pulldown transistor on D4 and VPP controlled by D5. | |
37 */ | |
38 | |
39 #include <avr/io.h> | |
40 #include <avr/pgmspace.h> | |
41 #include <util/delay.h> | |
42 #include "cons.h" | |
43 | |
44 /* Initialise the DDR pins if necessary */ | |
45 #define OWBUSINIT() do { \ | |
46 DDRD |= _BV(4); \ | |
47 DDRD &= ~_BV(3); \ | |
48 } while (0) | |
49 | |
50 /* Set the port up to allow reading from the 1 wire bus */ | |
51 #define OWSETREAD() \ | |
52 do { \ | |
53 } while (0) | |
54 | |
55 | |
56 /* Read the 1-wire bus, non-inverting logic */ | |
57 #define OWREADBUS() (PIND & _BV(3) ? 1 : 0) | |
58 | |
59 /* Set the 1-wire bus to 0 | |
60 * Turns a transistor on to pull it low | |
61 */ | |
62 #define OWSETBUSLOW() PORTD |= _BV(4) | |
63 | |
64 /* Set the 1-wire bus to 1 | |
65 * Turn the transistor off to let the pullup do its job | |
66 */ | |
67 #define OWSETBUSHIGH() PORTD &= ~_BV(4) | |
68 | |
69 /* Turn Vpp on (ie put +12V on the bus | |
70 * This is optional, if it is undefined OWProgROM always fails */ | |
71 #define OWSETVPPON() PORTD |= _BV(5) | |
72 #define OWSETVPPOFF() PORTD &= ~_BV(5) | |
73 | |
74 /* _delay_us can only do a delay of 768/clock_freq */ | |
75 #if F_CPU > 16000000 | |
76 #error F_CPU > 16MHz, delays need adjusting | |
77 #endif | |
78 | |
79 #define OWDELAY_A _delay_us(6) /* 6 usec */ | |
80 #define OWDELAY_B do { _delay_us(48); _delay_us(16); } while (0) /* 64 usec */ | |
81 #define OWDELAY_C do { _delay_us(48); _delay_us(12); } while (0) /* 60 usec */ | |
82 #define OWDELAY_D _delay_us(10) /* 10 usec */ | |
83 #define OWDELAY_E _delay_us(9) /* 9 usec */ | |
84 #define OWDELAY_F do { _delay_us(55); } while (0) /* 55 usec */ | |
85 #define OWDELAY_G /* 0 usec */ | |
86 #define OWDELAY_H do { _delay_us(48); _delay_us(48); _delay_us(48); \ | |
87 _delay_us(48); _delay_us(48); _delay_us(48); _delay_us(48); \ | |
88 _delay_us(48);_delay_us(48); _delay_us(48); } while (0) /* 480 usec */ | |
89 #define OWDELAY_I do { _delay_us(48); _delay_us(22); } while (0) /* 70 usec */ | |
90 | |
91 #ifdef OW_DEBUG | |
92 #define OWPUTS(x) puts_P(x) | |
93 #define OWPUTSP(x) puts_P(x) | |
94 #define OWPRINTFP(fmt, ...) printf_P(fmt, ## __VA_ARGS__) | |
95 #else | |
96 #define OWPUTS(x) | |
97 #define OWPUTSP(x) | |
98 #define OWPRINTFP(fmt, ...) | |
99 #endif |