\ Program Name: f0-lmt01-temp-sensor-simple-version.includes.fs \ Date: Sat 12 Oct 2019 14:18:49 AEDT \ Copyright 2019 by t.j.porter , licensed under the GPLV2 \ Contains required low level support Words for f0-lmt01-temp-sensor-simple-version.fs \ Must be loaded **BEFORE** f0-lmt01-temp-sensor-simple-version.fs compiletoram \ compiletoflash \ Constants and variables 0 variable lmt01.count \ Moder %00 constant INPUT %01 constant OUTPUT %10 constant AF %11 constant ANALOG \ RCC Words : rcc_apb2enr_syscfgen-set ( -- ) %1 0 lshift rcc_apb2enr bis! ; \ rcc_apb2enr_syscfgen syscfg clock enable \ GPIO Words : GPIOC_MODER_MODER0 ( %XX -- ) 0 lshift GPIOC_MODER bis! ; : GPIOC_MODER_MODER1 ( %XX -- ) 2 lshift GPIOC_MODER bis! ; : GPIOC_BSRR_BS1 %1 1 lshift GPIOC_BSRR bis! ; : GPIOC_BSRR_BR1 %1 17 lshift GPIOC_BSRR bis! ; : gpioc_moder_moder9 ( %XX -- ) %01 18 lshift $48000800 bis! ; ( gpioc.9 blue led ) : gpioc_moder_moder8 ( %XX -- ) %01 16 lshift $48000800 bis! ; ( gpioc.8 green led ) \ Leds : green-on ( -- ) %1 9 lshift $48000818 bis! ; \ gpioc_bs9 green led on : green-off ( -- ) %1 25 lshift $48000818 bis! ; \ gpioc_br9 green led off : init.gpio ( -- ) rcc_apb2enr_syscfgen-set \ required when using GPIO's as interrupts! INPUT GPIOC_MODER_MODER0 \ PCO = input mode OUTPUT GPIOC_MODER_MODER1 \ gpioc_moder_moder1; set PC1 to output mode ; \ LMT01 related Words : syscfg_exticr1_exti0 ( -- ) %0010 0 lshift syscfg_exticr1 bis! ; \ pc-0 is interrupt source x010: pc[0] pin : exti_imr_mr0-set ( -- ) %1 0 lshift exti_imr bis! ; \ exti_imr_mr0 set interrupt mask on line 0 : exti_pr_pr0 ( -- ) %1 0 lshift exti_pr bis! ; \ exti_pr_pr0 pending bit 0 : exti_ftsr_tr0-set ( -- ) %1 0 lshift exti_ftsr bis! ; \ exti_ftsr_tr0 falling trigger event configuration of line 0 : exti_pr_pr0-set ( -- ) %1 0 lshift exti_pr bis! ; \ exti_pr_pr0 interrupt pending flag for line 0 : nvic_iser_setena-exti0_1 ( -- ) %100000 0 lshift nvic_iser bis! ; \ nvic_iser_setena-exti0_1 : lmt01.power.on ( -- ) GPIOC_BSRR_BS1 \ set PC1 high ; : lmt01.power.off ( -- ) GPIOC_BSRR_BR1 \ set PC1 low, kill LMT01 power ; : lmt01.interrupt.handler ( -- ) exti_pr_pr0 \ clear pending bit 0 1 lmt01.count +! \ increment count by one exti_pr_pr0-set \ clear external interrupt pending register (exti_pr) ; : init.lmt01 ( -- ) \ negative going lmt01 pulses trigger interrupt syscfg_exticr1_exti0 \ via PC-0 exti_imr_mr0-set \ exti0 set interrupt mask on line 0 exti_ftsr_tr0-set \ falling trigger on line 0 ['] lmt01.interrupt.handler irq-exti0_1 ! \ tie the interrupt handler to the interrupt nvic_iser_setena-exti0_1 \ enable exti0_1 interrupt ;