Mouse code for the MacroRat
GPIO.h@46:b156ef445742, 2017-06-03 (annotated)
- Committer:
- sahilmgandhi
- Date:
- Sat Jun 03 00:22:44 2017 +0000
- Revision:
- 46:b156ef445742
- Parent:
- 12:5790e56a056f
Final code for internal battlebot competition.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
kyleliangus | 12:5790e56a056f | 1 | #include "stm32f4xx.h" |
kyleliangus | 12:5790e56a056f | 2 | |
kyleliangus | 12:5790e56a056f | 3 | // PA_1 is A of right |
kyleliangus | 12:5790e56a056f | 4 | // PA_0 is B of right |
kyleliangus | 12:5790e56a056f | 5 | // PA_5 is A of left |
kyleliangus | 12:5790e56a056f | 6 | // PB_3 is B of left |
kyleliangus | 12:5790e56a056f | 7 | |
kyleliangus | 12:5790e56a056f | 8 | #define ALT_FUNC_MODE 0x03 |
kyleliangus | 12:5790e56a056f | 9 | //#define |
kyleliangus | 12:5790e56a056f | 10 | |
kyleliangus | 12:5790e56a056f | 11 | // set GPIO pins to alternate for the pins corresponding to A/B for eacah encoder, and 2 alternate function registers need to be selected for each type |
kyleliangus | 12:5790e56a056f | 12 | // of alternate function specified |
kyleliangus | 12:5790e56a056f | 13 | // 4 modes sets AHB1ENR |
kyleliangus | 12:5790e56a056f | 14 | // Now TMR: enable clock with timer, APB1ENR |
kyleliangus | 12:5790e56a056f | 15 | // set period, autoreload value, ARR value 2^32-1, CR1 - TMR resets itself, ARPE and EN |
kyleliangus | 12:5790e56a056f | 16 | // |
kyleliangus | 12:5790e56a056f | 17 | // Encoder mode: disable timer before changing timer to encoder |
kyleliangus | 12:5790e56a056f | 18 | // CCMR1/2 1/2 depends on channel 1/2 or 3/4, depends on upper bits, depending which channels you use |
kyleliangus | 12:5790e56a056f | 19 | // CCMR sets sample rate and set the channel to input |
kyleliangus | 12:5790e56a056f | 20 | // CCER, which edge to trigger on, cannot be 11(not allowed for encoder mode), CCER for both channels |
kyleliangus | 12:5790e56a056f | 21 | // SMCR - encoder mode |
kyleliangus | 12:5790e56a056f | 22 | // CR1 reenabales |
kyleliangus | 12:5790e56a056f | 23 | // then read CNT reg of timer |