diff 1wire-config.h @ 1:be930b34fcd3

Make it compile, no testing yet.
author Daniel O'Connor <darius@dons.net.au>
date Mon, 26 Jan 2015 23:04:09 +1030
parents 93d4ddff7dd0
children
line wrap: on
line diff
--- a/1wire-config.h	Wed Jan 04 23:19:12 2012 +1030
+++ b/1wire-config.h	Mon Jan 26 23:04:09 2015 +1030
@@ -1,10 +1,10 @@
 /*
- * 1 wire header
+ * Example configuration header for 1-wire bus code.
  *
  * This is the user servicable stuff - how to do delays and how to
  * frob the IO pins.
  *
- * Copyright (c) 2004-2009
+ * Copyright (c) 2009
  *      Daniel O'Connor <darius@dons.net.au>.  All rights reserved.
  *
  * Redistribution and use in source and binary forms, with or without
@@ -31,42 +31,45 @@
 
 /*
  * Alter these for your configuration
+ *
+ * The configuration described here has the 1-wire read on D3,
+ * a pulldown transistor on D4 and VPP controlled by D5.
  */
 
-#define OWBUSINIT()
+#include <avr/io.h>
+#include <avr/pgmspace.h>
+#include <util/delay.h>
+#include "cons.h"
 
-/* Set the IO to input */
+/* Initialise the DDR pins if necessary */
+#define OWBUSINIT()		do {			\
+	                            DDRD |= _BV(4);	\
+				    DDRD &= ~_BV(3);	\
+                                } while (0)
+
+/* Set the port up to allow reading from the 1 wire bus */
 #define OWSETREAD() \
-    do {					\
-	__asm__ volatile ("" ::: "memory");	\
-	DDRB &= ~_BV(0);			\
-	PORTB &= ~_BV(0);			\
-	__asm__ volatile ("" ::: "memory");	\
+        do {	                                        \
     } while (0)
 
+
 /* Read the 1-wire bus, non-inverting logic */
-#define OWREADBUS()		(PINB & _BV(0) ? 1 : 0)
+#define OWREADBUS()		(PIND & _BV(3) ? 1 : 0)
 
 /* Set the 1-wire bus to 0
- * Drive output low
+ * Turns a transistor on to pull it low
  */
-#define OWSETBUSLOW() \
-    do {					\
-	__asm__ volatile ("" ::: "memory");	\
-	DDRB |= _BV(0);				\
-	PORTB &= ~_BV(0);			\
-    __asm__ volatile ("" ::: "memory");		\
-    } while (0)
+#define OWSETBUSLOW()		PORTD |= _BV(4)
 
 /* Set the 1-wire bus to 1
- * Allow to float, use pullup
+ * Turn the transistor off to let the pullup do its job
  */
-#define OWSETBUSHIGH() \
-    do {					\
-    __asm__ volatile ("" ::: "memory");		\
-	DDRB &= ~_BV(0);			\
-    __asm__ volatile ("" ::: "memory");		\
-    } while (0)
+#define OWSETBUSHIGH()		PORTD &= ~_BV(4)
+
+/* Turn Vpp on (ie put +12V on the bus
+ * This is optional, if it is undefined OWProgROM always fails */
+#define OWSETVPPON()		PORTD |= _BV(5)
+#define OWSETVPPOFF()		PORTD &= ~_BV(5)
 
 /* _delay_us can only do a delay of 768/clock_freq */
 #if F_CPU > 16000000
@@ -84,6 +87,9 @@
 	_delay_us(48);	_delay_us(48);  _delay_us(48);  _delay_us(48);  \
 	_delay_us(48);_delay_us(48);  _delay_us(48); } while (0)	/* 480 usec */
 #define OWDELAY_I do { _delay_us(48); _delay_us(22); } while (0)	/* 70 usec */
+#define OWDELAY_J do { _delay_us(41); _delay_us(41);  _delay_us(41); 	\
+	_delay_us(41);	_delay_us(41);  _delay_us(41);  _delay_us(41);  \
+	_delay_us(41);_delay_us(41);  _delay_us(41); } while (0)	/* 410 usec */
 
 #ifdef OW_DEBUG
 #define OWPUTS(x)		puts_P(x)
@@ -94,4 +100,3 @@
 #define OWPUTSP(x)
 #define OWPRINTFP(fmt, ...)
 #endif
-