+static bool bypass_active;
+static byte pwm;
+
+static void show_temperature(void)
+{
+ debug_putc('#');
+ for (uint i=0; ds_sensors[i].address[0]; i++) {
+ debug_putc(' ');
+ int t = ds_sensors[i].current_temp;
+ if (t == DS_TEMP_UNKNOWN)
+ debug_puts("---.---");
+ else
+ debug_printf("%3d.%03d", t / 1000, t % 1000);
+ }
+ debug_printf(" %d", bypass_active);
+ debug_printf(" %d", pwm);
+ debug_puts("\r\n");
+}
+
+static void pwm_init(void)
+{
+ timer_set_prescaler(TIM4, 3); // clock = 72 MHz / 2 = 36 MHz
+ timer_set_mode(TIM4, TIM_CR1_CKD_CK_INT, TIM_CR1_CMS_EDGE, TIM_CR1_DIR_UP);
+ timer_disable_preload(TIM4);
+ timer_set_period(TIM4, 255); // PWM frequency = 18 MHz / 256 = 70.3125 kHz FIXME
+ timer_set_oc_mode(TIM4, TIM_OC1, TIM_OCM_PWM1);
+ timer_set_oc_value(TIM4, TIM_OC1, 1);
+ pwm = 1;
+ /*
+ * 1 0.03
+ * 4 0.48
+ * 8 1.54
+ * 12 2.71
+ * 16 3.99
+ * 24 6.34
+ * 32 7.85
+ * 64 7.95
+ * 128 8.02
+ * 255
+ */
+ timer_set_oc_polarity_high(TIM4, TIM_OC1);
+ timer_enable_counter(TIM4);
+ timer_enable_oc_output(TIM4, TIM_OC1);
+
+ gpio_set_mode(GPIOB, GPIO_MODE_OUTPUT_50_MHZ, GPIO_CNF_OUTPUT_ALTFN_PUSHPULL, GPIO6);
+}
+