diff hw.c @ 13:96c345d304af

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 0b75cff7c570
children afdd22502c2a
line wrap: on
line diff
--- a/hw.c	Mon Feb 06 23:55:53 2012 +1030
+++ b/hw.c	Wed Feb 08 10:37:22 2012 +1030
@@ -1,21 +1,24 @@
 #include <stdint.h>
 #include <stdio.h>
 #include "stm32f10x.h"
+
+#include "1wire.h"
 #include "lcd.h"
 
 static void	hw_port_cfg(void);
 
 /* Wait for cnt microseconds */
-void _usleep16(uint16_t cnt) {
-    TIM6->ARR = cnt;
+void
+_usleep16(uint16_t cnt) {
+    TIM6->ARR = cnt > 3 ? cnt - 3 : cnt;
     TIM_SetCounter(TIM6, 0);
     TIM_Cmd(TIM6, ENABLE);
     while ((TIM6->CR1 & TIM_CR1_CEN) != 0)
 	;
-    
 }
 
-void hw_init(void) {
+void
+hw_init(void) {
     hw_port_cfg();
     lcd_init();
     lcd_setpwm(1000);
@@ -279,17 +282,33 @@
 
     /* Time Base configuration */
     TIM_TimeBaseStructure.TIM_Period = 0;
-    TIM_TimeBaseStructure.TIM_Prescaler = (SystemCoreClock / 1000000) - 1; /* 1 MHz clock */
+    TIM_TimeBaseStructure.TIM_Prescaler = (SystemCoreClock / 2 / 1000000) - 1; /* 1 MHz clock */
     TIM_TimeBaseInit(TIM6, &TIM_TimeBaseStructure);
 
     TIM_Cmd(TIM6, DISABLE);
 
-    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_3;
+    /* Setup for single pulse mode clear UDIS */
+    TIM_SelectOnePulseMode(TIM6, TIM_OPMode_Single);
+    TIM_UpdateDisableConfig(TIM6, DISABLE);
+
+    /* Setup GPIO for 1-wire */
+    GPIO_InitStructure.GPIO_Pin = GPIO_Pin_2 | GPIO_Pin_3;
     GPIO_InitStructure.GPIO_Speed = GPIO_Speed_50MHz;
     GPIO_InitStructure.GPIO_Mode = GPIO_Mode_Out_PP;
     GPIO_Init(GPIOE, &GPIO_InitStructure);
 
-    TIM_SelectOnePulseMode(TIM6, TIM_OPMode_Single);
-    TIM_UpdateDisableConfig(TIM6, DISABLE);
+    OWInit();
 
+#if 0
+    while (1) {
+	GPIO_SetBits(GPIOE, GPIO_Pin_2);
+	_usleep16(10);
+	GPIO_ResetBits(GPIOE, GPIO_Pin_2);
+	_usleep16(20);
+	GPIO_SetBits(GPIOE, GPIO_Pin_2);
+	_usleep16(30);
+	GPIO_ResetBits(GPIOE, GPIO_Pin_2);
+	_usleep16(100);
+    }
+#endif    
 }