changeset 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 4e10d1eef9a5
children d8002c716678
files 1wire-config-avr.h 1wire-config-stm32.h 1wire-config.h 1wire.c
diffstat 4 files changed, 207 insertions(+), 104 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/1wire-config-avr.h	Tue Feb 07 13:53:21 2012 +1030
@@ -0,0 +1,99 @@
+/*
+ * 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) 2009
+ *      Daniel O'Connor <darius@dons.net.au>.  All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+/*
+ * 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.
+ */
+
+#include <avr/io.h>
+#include <avr/pgmspace.h>
+#include <util/delay.h>
+#include "cons.h"
+
+/* 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 {	                                        \
+    } while (0)
+
+
+/* Read the 1-wire bus, non-inverting logic */
+#define OWREADBUS()		(PIND & _BV(3) ? 1 : 0)
+
+/* Set the 1-wire bus to 0
+ * Turns a transistor on to pull it low
+ */
+#define OWSETBUSLOW()		PORTD |= _BV(4)
+
+/* Set the 1-wire bus to 1
+ * Turn the transistor off to let the pullup do its job
+ */
+#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
+#error F_CPU > 16MHz, delays need adjusting
+#endif
+
+#define OWDELAY_A _delay_us(6)						/* 6 usec */
+#define OWDELAY_B do { _delay_us(48); _delay_us(16); } while (0)	/* 64 usec */
+#define OWDELAY_C do { _delay_us(48); _delay_us(12); } while (0)	/* 60 usec */
+#define OWDELAY_D _delay_us(10)						/* 10 usec */
+#define OWDELAY_E _delay_us(9)						/* 9 usec */
+#define OWDELAY_F do { _delay_us(55); } while (0)			/* 55 usec */
+#define OWDELAY_G							/* 0 usec */
+#define OWDELAY_H do { _delay_us(48); _delay_us(48);  _delay_us(48); 	\
+	_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 */
+
+#ifdef OW_DEBUG
+#define OWPUTS(x)		puts_P(x)
+#define OWPUTSP(x)		puts_P(x)
+#define OWPRINTFP(fmt, ...)	printf_P(fmt, ## __VA_ARGS__)
+#else
+#define OWPUTS(x)
+#define OWPUTSP(x)
+#define OWPRINTFP(fmt, ...)
+#endif
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/1wire-config-stm32.h	Tue Feb 07 13:53:21 2012 +1030
@@ -0,0 +1,101 @@
+/*
+ * 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) 2009
+ *      Daniel O'Connor <darius@dons.net.au>.  All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *    notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *    notice, this list of conditions and the following disclaimer in the
+ *    documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED.  IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
+ * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+ * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
+ * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ */
+
+/*
+ * The configuration described here has the 1-wire IO on GPIOE3,
+ * with no pull down, nor VPP
+ */
+
+#include "stm32f10x.h" /* GPIO* */
+#include "hw.h" /* For _usleep16() */
+
+/* No need for this on ARM */
+#define PROGMEM
+#define PSTR(x)			x
+#define pgm_read_byte(x)	*(x)
+
+/* Init bus */
+#define OWBUSINIT()
+
+/* Set the port up to allow reading from the 1 wire bus */
+#define OWSETREAD() 		do {			\
+    GPIO_InitTypeDef GPIO_InitStructure;		\
+    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3;		\
+    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;	\
+    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING; \
+    GPIO_Init(GPIOE, &GPIO_InitStructure);		\
+} while (0)
+
+
+/* Read the 1-wire bus, non-inverting logic */
+#define OWREADBUS()		(GPIO_ReadInputDataBit(GPIOE, GPIO_Pin_3))
+
+/* Set the 1-wire bus to 0
+ */
+#define OWSETBUSLOW()		do {			\
+    GPIO_InitTypeDef GPIO_InitStructure;		\
+    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3;		\
+    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;	\
+    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;	\
+    GPIO_Init(GPIOE, &GPIO_InitStructure);		\
+    GPIO_ResetBits(GPIOE, GPIO_Pin_3);			\
+} while (0)
+
+/* Set the 1-wire bus to 1
+ * Change to input and let the pull up do its job
+ */
+#define OWSETBUSHIGH()		do {			\
+    GPIO_InitTypeDef GPIO_InitStructure;		\
+    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3;		\
+    GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;	\
+    GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING; \
+    GPIO_Init(GPIOE, &GPIO_InitStructure);		\
+} while (0)
+
+#define OWDELAY_A _usleep16(6)						/* 6 usec */
+#define OWDELAY_B _usleep16(64)						/* 64 usec */
+#define OWDELAY_C _usleep16(60)						/* 60 usec */
+#define OWDELAY_D _usleep16(10)						/* 10 usec */
+#define OWDELAY_E _usleep16(9)						/* 9 usec */
+#define OWDELAY_F _usleep16(55)						/* 55 usec */
+#define OWDELAY_G							/* 0 usec */
+#define OWDELAY_H _usleep16(480)					/* 480 usec */
+#define OWDELAY_I _usleep16(70)						/* 70 usec */
+
+#ifdef OW_DEBUG
+#define OWPUTS(x)		puts_P(x)
+#define OWPUTSP(x)		puts_P(x)
+#define OWPRINTFP(fmt, ...)	printf_P(fmt, ## __VA_ARGS__)
+#else
+#define OWPUTS(x)
+#define OWPUTSP(x)
+#define OWPRINTFP(fmt, ...)
+#endif
--- a/1wire-config.h	Thu Jan 06 23:37:15 2011 +1030
+++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
@@ -1,95 +0,0 @@
-/*
- * 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) 2009
- *      Daniel O'Connor <darius@dons.net.au>.  All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that the following conditions
- * are met:
- * 1. Redistributions of source code must retain the above copyright
- *    notice, this list of conditions and the following disclaimer.
- * 2. Redistributions in binary form must reproduce the above copyright
- *    notice, this list of conditions and the following disclaimer in the
- *    documentation and/or other materials provided with the distribution.
- *
- * THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND
- * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
- * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
- * ARE DISCLAIMED.  IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
- * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
- * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
- * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- */
-
-/*
- * 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.
- */
-#error You must edit this file to suit your project
-
-/* 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 {	                                        \
-    } while (0)
-
-
-/* Read the 1-wire bus, non-inverting logic */
-#define OWREADBUS()		(PIND & _BV(3) ? 1 : 0)
-
-/* Set the 1-wire bus to 0
- * Turns a transistor on to pull it low
- */
-#define OWSETBUSLOW()		PORTD |= _BV(4)
-
-/* Set the 1-wire bus to 1
- * Turn the transistor off to let the pullup do its job
- */
-#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
-#error F_CPU > 16MHz, delays need adjusting
-#endif
-
-#define OWDELAY_A _delay_us(6)						/* 6 usec */
-#define OWDELAY_B do { _delay_us(48); _delay_us(16); } while (0)	/* 64 usec */
-#define OWDELAY_C do { _delay_us(48); _delay_us(12); } while (0)	/* 60 usec */
-#define OWDELAY_D _delay_us(10)						/* 10 usec */
-#define OWDELAY_E _delay_us(9)						/* 9 usec */
-#define OWDELAY_F do { _delay_us(55); } while (0)			/* 55 usec */
-#define OWDELAY_G							/* 0 usec */
-#define OWDELAY_H do { _delay_us(48); _delay_us(48);  _delay_us(48); 	\
-	_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 */
-
-#ifdef OW_DEBUG
-#define OWPUTS(x)		puts_P(x)
-#define OWPUTSP(x)		puts_P(x)
-#define OWPRINTFP(fmt, ...)	printf_P(fmt, ## __VA_ARGS__)
-#else
-#define OWPUTS(x)
-#define OWPUTSP(x)
-#define OWPRINTFP(fmt, ...)
-#endif
--- a/1wire.c	Thu Jan 06 23:37:15 2011 +1030
+++ b/1wire.c	Tue Feb 07 13:53:21 2012 +1030
@@ -37,12 +37,9 @@
  */
 
 #include <stdio.h>
-#include <avr/io.h>
-#include <avr/pgmspace.h>
-#include <util/delay.h>
+#include <stdint.h>
+#include "1wire-config.h"
 #include "1wire.h"
-#include "1wire-config.h"
-#include "cons.h"
 
 static uint8_t OW_LastDevice = 0;
 static uint8_t OW_LastDiscrepancy = 0;
@@ -78,11 +75,9 @@
      * the delay so we guarantee we don't see a slave from a previous
      * comms attempt
      */
-#if 0
     OWSETREAD();
     if(OWREADBUS() == 0)
 	return 2;
-#endif
 
     OWSETBUSLOW();
     OWDELAY_H;
@@ -431,9 +426,9 @@
  *  3 if the DS2502 didn't respond appropriately (also happens if the
  *  module doesn't exist)
  */
+#if defined(OWSETVPPON) && defined(OWSETVPPOFF)
 uint8_t
 OWProgROM(uint8_t *ROM, uint8_t start, uint8_t len, uint8_t *data, uint8_t exact, uint8_t status) {
-#if defined(OWSETVPPON) && defined(OWSETVPPOFF)
     uint8_t	crc, i, tmp;
     
     /* Stupid programmer detection */
@@ -527,10 +522,13 @@
     }
 
     return(0);
+}
 #else
+uint8_t
+OWProgROM(uint8_t *ROM __attribute((unused)), uint8_t start __attribute((unused)), uint8_t len __attribute((unused)), uint8_t *data __attribute((unused)), uint8_t exact __attribute((unused)), uint8_t status __attribute((unused))) {
     return(1);
+}
 #endif
-}
 
 /* 
  * OWGetTemp