comparison main.c @ 13:96c345d304af default tip

Add 1wire code. 1wire.c, 1wire.h and 1wire-config.h are copied avr-lib.
author Daniel O'Connor <darius@dons.net.au>
date Wed, 08 Feb 2012 10:37:22 +1030
parents 093bc0c3b1cc
children
comparison
equal deleted inserted replaced
12:093bc0c3b1cc 13:96c345d304af
7 #include <sys/time.h> 7 #include <sys/time.h>
8 #include <stdlib.h> 8 #include <stdlib.h>
9 9
10 #include "stm32f10x.h" 10 #include "stm32f10x.h"
11 11
12 #include "1wire.h"
12 #include "comm.h" 13 #include "comm.h"
13 #include "delay.h" 14 #include "delay.h"
14 #include "flash.h" 15 #include "flash.h"
15 #include "hw.h" 16 #include "hw.h"
16 #include "lcd.h" 17 #include "lcd.h"
241 GPIO_SetBits(GPIOE, GPIO_Pin_3); 242 GPIO_SetBits(GPIOE, GPIO_Pin_3);
242 _usleep16(30000); 243 _usleep16(30000);
243 GPIO_ResetBits(GPIOE, GPIO_Pin_3); 244 GPIO_ResetBits(GPIOE, GPIO_Pin_3);
244 _usleep16(60000); 245 _usleep16(60000);
245 } 246 }
247 } else if (!strncmp("rs", cmd.buf, 2)) {
248 printf("Reset got %d\r\n", OWTouchReset());
249 } else if (!strncmp("sr", cmd.buf, 2)) {
250 uint8_t ROM[8];
251 int8_t i;
252
253 memset(ROM, 0, 8);
254
255 i = OWFirst(ROM, 1, 0);
256 do {
257 switch (i) {
258 case OW_NOMODULES:
259 case OW_FOUND:
260 break;
261
262 case OW_BADWIRE:
263 case OW_NOPRESENCE:
264 case OW_BADCRC:
265 default:
266 printf("Err %d\r\n", i);
267 break;
268 }
269
270 if (i != OW_FOUND)
271 break;
272
273 for (i = 0; i < 8; i++)
274 printf("%02x%s", ROM[i], i == 7 ? "\r\n" : ":");
275
276 i = OWNext(ROM, 1, 0);
277 } while (1);
278 } else if (!strncmp("rb", cmd.buf, 2)) {
279 printf("Read bit returned %d\r\n", OWReadBit());
280 } else if (!strncmp("wb ", cmd.buf, 3)) {
281 x = atoi(cmd.buf + 3);
282 OWWriteBit(x);
283 printf("Wrote %d\r\n", x);
284 } else if (!strncasecmp(cmd.buf, "te ", 3)) {
285 uint8_t ROM[8];
286 int16_t res;
287
288 if (sscanf(cmd.buf, "te %hhx:%hhx:%hhx:%hhx:%hhx:%hhx:%hhx:%hhx",
289 &ROM[0], &ROM[1], &ROM[2], &ROM[3],
290 &ROM[4], &ROM[5], &ROM[6], &ROM[7]) != 8) {
291 printf("Unable to parse ROM ID\r\n");
292 goto out;
293 }
294
295 res = OWGetTemp(ROM);
296 switch (res) {
297 case OW_TEMP_WRONG_FAM:
298 printf("ROM specified isn't a temperature sensor\r\n");
299 break;
300
301 case OW_TEMP_CRC_ERR:
302 printf("CRC mismatch\r\n");
303 break;
304
305 case OW_TEMP_NO_ROM:
306 printf("No ROM found\r\n");
307 break;
308
309 default:
310 printf("%hd.%02hd\r\n", GETWHOLE(res), GETFRAC(res));
311 break;
312 }
246 } else if (!strncmp("zz", cmd.buf, 2)) { 313 } else if (!strncmp("zz", cmd.buf, 2)) {
247 NVIC_SystemReset(); 314 NVIC_SystemReset();
248 } else { 315 } else {
249 printf("Unknown command\r\n"); 316 printf("Unknown command\r\n");
250 } 317 }