#include <drivers/tsensor.h>
-#define PRESCALER 36000 // 1 Mhz
+#define PRESCALER 8000 // 1 kHz
int *ccr1, *ccr2, *ccr1b, *ccr2b;
bool s1, s2;
tsensor_input(0xFFFF);
}
+int cnt;
+
+void * bare_handler() {
+ cnt += 1;
+ printf("Count event %d\n", cnt);
+ int switchled = cnt % 2;
+ if (switchled) {
+ printf("setting low\n");
+ rclrbit(GPIOB_ODR, 6); // low
+ }
+ else {
+ printf("setting high\n");
+ rsetbit(GPIOB_ODR, 6); // high
+ }
+ rclrbit(TIM4_SR1, 0);
+}
+
void tsensor_simple(uint16_t preload) {
rwrite(TIM4_ARR, preload);
rsetbit(TIM4_EGR, 0);
- ivt_set_gate(46, cnt_complete_handler, 0);
+ ivt_set_gate(46, bare_handler, 0);
rsetbit(NVIC_ISER0, 30); // interupt 41 - 32
- rsetbit(GPIOB_BSRR, 22); //
+ rsetbit(GPIOB_ODR, 6); //
rsetbit(TIM4_DIER, 0);
rsetbit(TIM4_CR1, 0);
void run() {
+ cnt = 0;
rsetbit(RCC_APB2ENR, 3); // GPIOB enable
- rwrite(GPIOB_CRL, 0x47444444); // open drain general
+ rwrite(GPIOB_CRL, 0x42444444); // open drain general for sensor?
rsetbit(GPIOB_BSRR, 22); // high
- tsensor_simple(2000);
+
+ tsensor_simple(4000); // 2 second?
+
// tsensor_output(580, 520);
// reset();
// tsensor_simple(580);
#define GPIOA_ODR MEM_ADDR(0x4001080C)
#define GPIOB_CRL MEM_ADDR(0x40010C00) // low register (!) for I2C1
#define GPIOB_BSRR MEM_ADDR(0x40010C10)
+#define GPIOB_ODR MEM_ADDR(0x40010C0C)
#define GPIOC_CRL MEM_ADDR(0x40011000) // led
#define GPIOC_CRH MEM_ADDR(0x40011004)
#define GPIOC_ODR MEM_ADDR(0x4001100C)
void * rtc_handler() {
// Real time clock output on a LED display
- int cntvalue = *RTC_CNTL;
+ /* int cntvalue = *RTC_CNTL;
if (cntvalue < 9999) {
unsigned char dn[10] = {0xFC, 0x60, 0xDA, 0xF2, 0x66, 0xB6, 0xBE, 0xE0, 0xFE, 0xF6};
}
set_display(true, 0);
- }
+ } */
// Simple LED blink
- //uint32_t curr = *RTC_CNTL;
- //int even = *RTC_CNTL % 2;
- //(!even) ? led_off() : led_on();
+ uint32_t curr = *RTC_CNTL;
+ int even = *RTC_CNTL % 2;
+ (!even) ? led_off() : led_on();
rclrbit(RTC_CRL, 0); /* clear interrupt flag */
}