summaryrefslogtreecommitdiffstats
path: root/stm32/app/ds1820.c
diff options
context:
space:
mode:
authorfishsoupisgood <github@madingley.org>2020-09-09 11:53:37 +0100
committerfishsoupisgood <github@madingley.org>2020-09-09 11:53:37 +0100
commit9d87c925a9eaa4fc256be3173c14a20d1469472d (patch)
tree50d63f87a47a0eac3f5b8058850184bcd4e6ee95 /stm32/app/ds1820.c
parentdafd8cf2fdcdd637cc06f760d318cf8391b1a294 (diff)
downloadheating-9d87c925a9eaa4fc256be3173c14a20d1469472d.tar.gz
heating-9d87c925a9eaa4fc256be3173c14a20d1469472d.tar.bz2
heating-9d87c925a9eaa4fc256be3173c14a20d1469472d.zip
everything, mostly, working
Diffstat (limited to 'stm32/app/ds1820.c')
-rw-r--r--stm32/app/ds1820.c93
1 files changed, 0 insertions, 93 deletions
diff --git a/stm32/app/ds1820.c b/stm32/app/ds1820.c
deleted file mode 100644
index 200f4b7..0000000
--- a/stm32/app/ds1820.c
+++ /dev/null
@@ -1,93 +0,0 @@
-#include "project.h"
-
-#define DS1820_READ_SCRATCHPAD 0xbe
-#define DS1820_CONVERT_T 0x44
-
-
-#define TIMEOUT 150
-
-
-
-static unsigned extract_leu16 (uint8_t *d)
-{
- uint32_t u;
-
- u = (uint32_t) d[0] | (((uint32_t) d[1]) << 8);
- return u;
-}
-
-
-
-static int extract_les16 (uint8_t *d)
-{
- uint32_t u;
- u = extract_leu16 (d);
-
- if (u & 0x8000) u |= 0xffff0000;
-
- return (int) u;
-}
-
-
-
-
-
-static int
-ds1820_read_sp (const Onewire_addr *a, unsigned page, uint8_t *buf, unsigned len)
-{
- if (onewire_reset_and_select (a))
- return ~0U;
-
- onewire_write_byte (DS1820_READ_SCRATCHPAD);
- onewire_read_bytes (buf, len);
-
- if ((len == 9) && onewire_check_crc (buf, 8, buf[8]))
- return ~0U;
-
- return 0;
-}
-
-
-
-static int ds1820_convert_t (const Onewire_addr *a)
-{
-
- if (onewire_reset_and_select (a))
- return ~0U;
-
- onewire_write_byte (DS1820_CONVERT_T);
-
- if (onewire_wait_complete (TIMEOUT))
- return ~0U;
-
- return 0;
-}
-
-int
-ds1820_read (const Onewire_addr *a, int *temp)
-{
- uint8_t buf[9];
- int t;
-
- if (ds1820_read_sp (a, 0, buf, 9))
- return 1;
-
- if (ds1820_convert_t (a))
- return 1;
-
- if (ds1820_read_sp (a, 0, buf, 9))
- return 1;
-
- t = extract_les16 (&buf[0]);
-
- t <<= 4 ;
-
- if (temp)
- *temp = t;
-
-
- return 0;
-}
-
-
-