rcc_periph_clock_enable(RCC_GPIOB);
rcc_periph_clock_enable(RCC_GPIOC);
rcc_periph_clock_enable(RCC_USART1);
+ rcc_periph_clock_enable(RCC_TIM1);
// rcc_periph_clock_enable(RCC_TIM4);
// rcc_periph_clock_enable(RCC_DMA1);
rcc_periph_clock_enable(RCC_I2C2);
rcc_periph_reset_pulse(RST_GPIOB);
rcc_periph_reset_pulse(RST_GPIOC);
rcc_periph_reset_pulse(RST_USART1);
+ rcc_periph_reset_pulse(RST_TIM1);
// rcc_periph_reset_pulse(RST_TIM4);
rcc_periph_reset_pulse(RST_I2C2);
}
;
}
+/*** Microsecond delays via TIM1 ***/
+
+static void delay_init(void)
+{
+ timer_set_prescaler(TIM1, CPU_CLOCK_MHZ - 1); // 1 MHz
+ timer_set_mode(TIM1, TIM_CR1_CKD_CK_INT, TIM_CR1_CMS_EDGE, TIM_CR1_DIR_UP);
+ timer_update_on_overflow(TIM1);
+ timer_disable_preload(TIM1);
+ timer_one_shot_mode(TIM1);
+}
+
+static void delay_us(uint us)
+{
+ timer_set_period(TIM1, us - 1);
+ timer_generate_event(TIM1, TIM_EGR_UG);
+ timer_enable_counter(TIM1);
+ while (TIM_CR1(TIM1) & TIM_CR1_CEN)
+ ;
+}
+
/*** Display ***/
/*
// Sends a nibble of data with a combination of control signals
display_pcf_write(value);
display_pcf_write(value | LCD_BIT_E);
- delay_ms(1); // FIXME
+ delay_us(50);
display_pcf_write(value);
- delay_ms(1); // FIXME
+ delay_us(50);
}
static void display_command(byte cmd)
gpio_init();
usart_init();
tick_init();
+ delay_init();
display_init();
// neopixel_init();
usb_init();