1wire-config.h
author darius@Inchoate
Mon, 19 Jan 2009 22:54:19 +1030
changeset 71 553c061fda7c
parent 33 0aa6bf4b98ae
permissions -rw-r--r--
Keep the newer GCC happy.
darius@32
     1
/*
darius@32
     2
 * 1 wire header
darius@32
     3
 *
darius@32
     4
 * This is the user servicable stuff - how to do delays and how to
darius@32
     5
 * frob the IO pins.
darius@32
     6
 *
darius@32
     7
 * $Id$
darius@32
     8
 *
darius@32
     9
 * Copyright (c) 2004
darius@32
    10
 *      Daniel O'Connor <darius@dons.net.au>.  All rights reserved.
darius@32
    11
 *
darius@32
    12
 * Redistribution and use in source and binary forms, with or without
darius@32
    13
 * modification, are permitted provided that the following conditions
darius@32
    14
 * are met:
darius@32
    15
 * 1. Redistributions of source code must retain the above copyright
darius@32
    16
 *    notice, this list of conditions and the following disclaimer.
darius@32
    17
 * 2. Redistributions in binary form must reproduce the above copyright
darius@32
    18
 *    notice, this list of conditions and the following disclaimer in the
darius@32
    19
 *    documentation and/or other materials provided with the distribution.
darius@32
    20
 *
darius@32
    21
 * THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND
darius@32
    22
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
darius@32
    23
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
darius@32
    24
 * ARE DISCLAIMED.  IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
darius@32
    25
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
darius@32
    26
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
darius@32
    27
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
darius@32
    28
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
darius@32
    29
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
darius@32
    30
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
darius@32
    31
 * SUCH DAMAGE.
darius@32
    32
 */
darius@32
    33
darius@32
    34
/*
darius@32
    35
 * Alter these for your configuration
darius@32
    36
 */
darius@32
    37
darius@32
    38
/* Set DDR on the right pins */
darius@32
    39
#define OWBUSINIT()		do {			\
darius@32
    40
	                            DDRD |= _BV(4);	\
darius@32
    41
				    DDRD &= ~_BV(3);	\
darius@32
    42
                                } while (0)
darius@32
    43
darius@32
    44
/* Read the 1-wire bus, non-inverting logic */
darius@32
    45
#define OWREADBUS()		(PIND & _BV(3) ? 1 : 0)
darius@32
    46
darius@32
    47
/* Set the 1-wire bus to 0
darius@32
    48
 * Turns a transistor on to pull it low
darius@32
    49
 */
darius@32
    50
#define OWSETBUSLOW()		PORTD |= _BV(4)
darius@32
    51
darius@32
    52
/* Set the 1-wire bus to 1
darius@32
    53
 * Turn the transistor off to let the pullup do its job
darius@32
    54
 */
darius@32
    55
#define OWSETBUSHIGH()		PORTD &= ~_BV(4)
darius@32
    56
darius@33
    57
/* Turn Vpp on (ie put +12V on the bus
darius@33
    58
 * This is optional, if it is undefined OWProgROM always fails */
darius@33
    59
#define OWSETVPPON()		PORTD |= _BV(5)
darius@33
    60
#define OWSETVPPOFF()		PORTD &= ~_BV(5)
darius@33
    61
darius@32
    62
/* _delay_us can only do a delay of 768/clock_freq */
darius@32
    63
#if F_CPU > 16000000
darius@32
    64
#error F_CPU > 16MHz, delays need adjusting
darius@32
    65
#endif
darius@32
    66
darius@32
    67
#define OWDELAY_A _delay_us(6)						/* 6 usec */
darius@32
    68
#define OWDELAY_B do { _delay_us(48); _delay_us(16); } while (0)	/* 64 usec */
darius@32
    69
#define OWDELAY_C do { _delay_us(48); _delay_us(12); } while (0)	/* 60 usec */
darius@32
    70
#define OWDELAY_D _delay_us(10)						/* 10 usec */
darius@32
    71
#define OWDELAY_E _delay_us(9)						/* 9 usec */
darius@32
    72
#define OWDELAY_F do { _delay_us(55); } while (0)			/* 55 usec */
darius@32
    73
#define OWDELAY_G							/* 0 usec */
darius@32
    74
#define OWDELAY_H do { _delay_us(48); _delay_us(48);  _delay_us(48); 	\
darius@32
    75
	_delay_us(48);	_delay_us(48);  _delay_us(48);  _delay_us(48);  \
darius@32
    76
	_delay_us(48);_delay_us(48);  _delay_us(48); } while (0)	/* 480 usec */
darius@32
    77
#define OWDELAY_I do { _delay_us(48); _delay_us(22); } while (0)	/* 70 usec */
darius@33
    78
darius@41
    79
#ifdef OW_DEBUG
darius@41
    80
#define OWPUTS(x)		puts_P(x)
darius@41
    81
#define OWPUTSP(x)		puts_P(x)
darius@41
    82
#define OWPRINTFP(fmt, ...)	printf_P(fmt, ## __VA_ARGS__)
darius@33
    83
#else
darius@33
    84
#define OWPUTS(x)
darius@33
    85
#define OWPUTSP(x)
darius@41
    86
#define OWPRINTFP(fmt, ...)
darius@33
    87
#endif
darius@33
    88