Mercurial > ~darius > hgwebdir.cgi > avr-lib
annotate 1wire-config-stm32.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 | |
children | a50a054d060c |
rev | line source |
---|---|
13
6f8f7b87d2f1
- Rename 1wire config example to note it's for AVR.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
1 /* |
6f8f7b87d2f1
- Rename 1wire config example to note it's for AVR.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
2 * Example configuration header for 1-wire bus code. |
6f8f7b87d2f1
- Rename 1wire config example to note it's for AVR.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
3 * |
6f8f7b87d2f1
- Rename 1wire config example to note it's for AVR.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
4 * This is the user servicable stuff - how to do delays and how to |
6f8f7b87d2f1
- Rename 1wire config example to note it's for AVR.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
5 * frob the IO pins. |
6f8f7b87d2f1
- Rename 1wire config example to note it's for AVR.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
6 * |
6f8f7b87d2f1
- Rename 1wire config example to note it's for AVR.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
7 * Copyright (c) 2009 |
6f8f7b87d2f1
- Rename 1wire config example to note it's for AVR.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
8 * Daniel O'Connor <darius@dons.net.au>. All rights reserved. |
6f8f7b87d2f1
- Rename 1wire config example to note it's for AVR.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
9 * |
6f8f7b87d2f1
- Rename 1wire config example to note it's for AVR.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
10 * Redistribution and use in source and binary forms, with or without |
6f8f7b87d2f1
- Rename 1wire config example to note it's for AVR.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
11 * modification, are permitted provided that the following conditions |
6f8f7b87d2f1
- Rename 1wire config example to note it's for AVR.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
12 * are met: |
6f8f7b87d2f1
- Rename 1wire config example to note it's for AVR.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
13 * 1. Redistributions of source code must retain the above copyright |
6f8f7b87d2f1
- Rename 1wire config example to note it's for AVR.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
14 * notice, this list of conditions and the following disclaimer. |
6f8f7b87d2f1
- Rename 1wire config example to note it's for AVR.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
15 * 2. Redistributions in binary form must reproduce the above copyright |
6f8f7b87d2f1
- Rename 1wire config example to note it's for AVR.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
16 * notice, this list of conditions and the following disclaimer in the |
6f8f7b87d2f1
- Rename 1wire config example to note it's for AVR.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
17 * documentation and/or other materials provided with the distribution. |
6f8f7b87d2f1
- Rename 1wire config example to note it's for AVR.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
18 * |
6f8f7b87d2f1
- Rename 1wire config example to note it's for AVR.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
19 * THIS SOFTWARE IS PROVIDED BY AUTHOR AND CONTRIBUTORS ``AS IS'' AND |
6f8f7b87d2f1
- Rename 1wire config example to note it's for AVR.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
6f8f7b87d2f1
- Rename 1wire config example to note it's for AVR.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
21 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
6f8f7b87d2f1
- Rename 1wire config example to note it's for AVR.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
22 * ARE DISCLAIMED. IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE |
6f8f7b87d2f1
- Rename 1wire config example to note it's for AVR.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
23 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
6f8f7b87d2f1
- Rename 1wire config example to note it's for AVR.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
6f8f7b87d2f1
- Rename 1wire config example to note it's for AVR.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
25 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
6f8f7b87d2f1
- Rename 1wire config example to note it's for AVR.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
26 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
6f8f7b87d2f1
- Rename 1wire config example to note it's for AVR.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
27 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
6f8f7b87d2f1
- Rename 1wire config example to note it's for AVR.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
28 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
6f8f7b87d2f1
- Rename 1wire config example to note it's for AVR.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
29 * SUCH DAMAGE. |
6f8f7b87d2f1
- Rename 1wire config example to note it's for AVR.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
30 */ |
6f8f7b87d2f1
- Rename 1wire config example to note it's for AVR.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
31 |
6f8f7b87d2f1
- Rename 1wire config example to note it's for AVR.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
32 /* |
6f8f7b87d2f1
- Rename 1wire config example to note it's for AVR.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
33 * The configuration described here has the 1-wire IO on GPIOE3, |
6f8f7b87d2f1
- Rename 1wire config example to note it's for AVR.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
34 * with no pull down, nor VPP |
6f8f7b87d2f1
- Rename 1wire config example to note it's for AVR.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
35 */ |
6f8f7b87d2f1
- Rename 1wire config example to note it's for AVR.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
36 |
6f8f7b87d2f1
- Rename 1wire config example to note it's for AVR.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
37 #include "stm32f10x.h" /* GPIO* */ |
6f8f7b87d2f1
- Rename 1wire config example to note it's for AVR.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
38 #include "hw.h" /* For _usleep16() */ |
6f8f7b87d2f1
- Rename 1wire config example to note it's for AVR.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
39 |
6f8f7b87d2f1
- Rename 1wire config example to note it's for AVR.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
40 /* No need for this on ARM */ |
6f8f7b87d2f1
- Rename 1wire config example to note it's for AVR.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
41 #define PROGMEM |
6f8f7b87d2f1
- Rename 1wire config example to note it's for AVR.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
42 #define PSTR(x) x |
6f8f7b87d2f1
- Rename 1wire config example to note it's for AVR.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
43 #define pgm_read_byte(x) *(x) |
6f8f7b87d2f1
- Rename 1wire config example to note it's for AVR.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
44 |
6f8f7b87d2f1
- Rename 1wire config example to note it's for AVR.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
45 /* Init bus */ |
6f8f7b87d2f1
- Rename 1wire config example to note it's for AVR.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
46 #define OWBUSINIT() |
6f8f7b87d2f1
- Rename 1wire config example to note it's for AVR.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
47 |
6f8f7b87d2f1
- Rename 1wire config example to note it's for AVR.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
48 /* Set the port up to allow reading from the 1 wire bus */ |
6f8f7b87d2f1
- Rename 1wire config example to note it's for AVR.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
49 #define OWSETREAD() do { \ |
6f8f7b87d2f1
- Rename 1wire config example to note it's for AVR.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
50 GPIO_InitTypeDef GPIO_InitStructure; \ |
6f8f7b87d2f1
- Rename 1wire config example to note it's for AVR.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
51 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3; \ |
6f8f7b87d2f1
- Rename 1wire config example to note it's for AVR.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
52 GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; \ |
6f8f7b87d2f1
- Rename 1wire config example to note it's for AVR.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
53 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING; \ |
6f8f7b87d2f1
- Rename 1wire config example to note it's for AVR.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
54 GPIO_Init(GPIOE, &GPIO_InitStructure); \ |
6f8f7b87d2f1
- Rename 1wire config example to note it's for AVR.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
55 } while (0) |
6f8f7b87d2f1
- Rename 1wire config example to note it's for AVR.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
56 |
6f8f7b87d2f1
- Rename 1wire config example to note it's for AVR.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
57 |
6f8f7b87d2f1
- Rename 1wire config example to note it's for AVR.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
58 /* Read the 1-wire bus, non-inverting logic */ |
6f8f7b87d2f1
- Rename 1wire config example to note it's for AVR.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
59 #define OWREADBUS() (GPIO_ReadInputDataBit(GPIOE, GPIO_Pin_3)) |
6f8f7b87d2f1
- Rename 1wire config example to note it's for AVR.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
60 |
6f8f7b87d2f1
- Rename 1wire config example to note it's for AVR.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
61 /* Set the 1-wire bus to 0 |
6f8f7b87d2f1
- Rename 1wire config example to note it's for AVR.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
62 */ |
6f8f7b87d2f1
- Rename 1wire config example to note it's for AVR.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
63 #define OWSETBUSLOW() do { \ |
6f8f7b87d2f1
- Rename 1wire config example to note it's for AVR.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
64 GPIO_InitTypeDef GPIO_InitStructure; \ |
6f8f7b87d2f1
- Rename 1wire config example to note it's for AVR.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
65 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3; \ |
6f8f7b87d2f1
- Rename 1wire config example to note it's for AVR.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
66 GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; \ |
6f8f7b87d2f1
- Rename 1wire config example to note it's for AVR.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
67 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP; \ |
6f8f7b87d2f1
- Rename 1wire config example to note it's for AVR.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
68 GPIO_Init(GPIOE, &GPIO_InitStructure); \ |
6f8f7b87d2f1
- Rename 1wire config example to note it's for AVR.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
69 GPIO_ResetBits(GPIOE, GPIO_Pin_3); \ |
6f8f7b87d2f1
- Rename 1wire config example to note it's for AVR.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
70 } while (0) |
6f8f7b87d2f1
- Rename 1wire config example to note it's for AVR.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
71 |
6f8f7b87d2f1
- Rename 1wire config example to note it's for AVR.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
72 /* Set the 1-wire bus to 1 |
6f8f7b87d2f1
- Rename 1wire config example to note it's for AVR.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
73 * Change to input and let the pull up do its job |
6f8f7b87d2f1
- Rename 1wire config example to note it's for AVR.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
74 */ |
6f8f7b87d2f1
- Rename 1wire config example to note it's for AVR.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
75 #define OWSETBUSHIGH() do { \ |
6f8f7b87d2f1
- Rename 1wire config example to note it's for AVR.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
76 GPIO_InitTypeDef GPIO_InitStructure; \ |
6f8f7b87d2f1
- Rename 1wire config example to note it's for AVR.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
77 GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3; \ |
6f8f7b87d2f1
- Rename 1wire config example to note it's for AVR.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
78 GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz; \ |
6f8f7b87d2f1
- Rename 1wire config example to note it's for AVR.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
79 GPIO_InitStructure.GPIO_Mode = GPIO_Mode_IN_FLOATING; \ |
6f8f7b87d2f1
- Rename 1wire config example to note it's for AVR.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
80 GPIO_Init(GPIOE, &GPIO_InitStructure); \ |
6f8f7b87d2f1
- Rename 1wire config example to note it's for AVR.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
81 } while (0) |
6f8f7b87d2f1
- Rename 1wire config example to note it's for AVR.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
82 |
6f8f7b87d2f1
- Rename 1wire config example to note it's for AVR.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
83 #define OWDELAY_A _usleep16(6) /* 6 usec */ |
6f8f7b87d2f1
- Rename 1wire config example to note it's for AVR.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
84 #define OWDELAY_B _usleep16(64) /* 64 usec */ |
6f8f7b87d2f1
- Rename 1wire config example to note it's for AVR.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
85 #define OWDELAY_C _usleep16(60) /* 60 usec */ |
6f8f7b87d2f1
- Rename 1wire config example to note it's for AVR.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
86 #define OWDELAY_D _usleep16(10) /* 10 usec */ |
6f8f7b87d2f1
- Rename 1wire config example to note it's for AVR.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
87 #define OWDELAY_E _usleep16(9) /* 9 usec */ |
6f8f7b87d2f1
- Rename 1wire config example to note it's for AVR.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
88 #define OWDELAY_F _usleep16(55) /* 55 usec */ |
6f8f7b87d2f1
- Rename 1wire config example to note it's for AVR.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
89 #define OWDELAY_G /* 0 usec */ |
6f8f7b87d2f1
- Rename 1wire config example to note it's for AVR.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
90 #define OWDELAY_H _usleep16(480) /* 480 usec */ |
6f8f7b87d2f1
- Rename 1wire config example to note it's for AVR.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
91 #define OWDELAY_I _usleep16(70) /* 70 usec */ |
6f8f7b87d2f1
- Rename 1wire config example to note it's for AVR.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
92 |
6f8f7b87d2f1
- Rename 1wire config example to note it's for AVR.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
93 #ifdef OW_DEBUG |
6f8f7b87d2f1
- Rename 1wire config example to note it's for AVR.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
94 #define OWPUTS(x) puts_P(x) |
6f8f7b87d2f1
- Rename 1wire config example to note it's for AVR.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
95 #define OWPUTSP(x) puts_P(x) |
6f8f7b87d2f1
- Rename 1wire config example to note it's for AVR.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
96 #define OWPRINTFP(fmt, ...) printf_P(fmt, ## __VA_ARGS__) |
6f8f7b87d2f1
- Rename 1wire config example to note it's for AVR.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
97 #else |
6f8f7b87d2f1
- Rename 1wire config example to note it's for AVR.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
98 #define OWPUTS(x) |
6f8f7b87d2f1
- Rename 1wire config example to note it's for AVR.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
99 #define OWPUTSP(x) |
6f8f7b87d2f1
- Rename 1wire config example to note it's for AVR.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
100 #define OWPRINTFP(fmt, ...) |
6f8f7b87d2f1
- Rename 1wire config example to note it's for AVR.
Daniel O'Connor <darius@dons.net.au>
parents:
diff
changeset
|
101 #endif |