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