Hallo, ich habe 2 verschiedene Versionen von dem qdec Driver für die XMegas gefunden. ich habe mich für den von folgender Seite entschieden: https://github.com/avrxml/asf/tree/master/xmega/drivers/qdec Jedoch verstehe ich Folgendes nicht: in der init Funktion qdec_get_config_defaults werden die Input Ports festgelegt. in der nächsten init Funktion qdec_config_phase_pins wird der PORT neu konfiguriert? Ich denke auf Grund meiner Unerfahrenheit kann ich den Code noch nicht ganz verstehen, jedoch muss ich mich schnell mit dem Treiber vertraut machen. Ich bitte um Hilfe. Woher weiß der Compiler welcher XMEGA verwendet wird?
1 | void qdec_get_config_defaults(qdec_config_t *config) |
2 | {
|
3 | #if !XMEGA_B3
|
4 | config->port = &PORTA; |
5 | #else
|
6 | config->port = &PORTB; |
7 | #endif
|
8 | config->pins_base = 0; |
9 | config->pins_filter_us = 2; |
10 | config->phases.pins_invert = false; |
11 | config->index.enabled = false; |
12 | config->rotary = false; |
13 | config->event_channel = 0; |
14 | #if XMEGA_E
|
15 | config->timer = &TCC5; |
16 | config->freq_opt.timer = &TCC4; |
17 | #else
|
18 | config->timer = &TCC0; |
19 | config->freq_opt.timer = &TCC1; |
20 | #endif
|
21 | config->freq_opt.enabled = false; |
22 | config->freq_opt.event_channel = 2; |
23 | config->freq_opt.unit = 1000; |
24 | config->revolution = 4; |
25 | }
|
26 | |
27 | |
28 | |
29 | |
30 | |
31 | |
32 | |
33 | |
34 | |
35 | void qdec_config_phase_pins(qdec_config_t *config, PORT_t *port, |
36 | uint8_t pin_base, bool pins_invert, uint16_t filter_us) |
37 | {
|
38 | config->port = port; |
39 | config->pins_base = pin_base; |
40 | config->pins_filter_us = filter_us; |
41 | config->phases.pins_invert = pins_invert; |
42 | }
|
Dannach wird der qdec enabled und es wird nochmal alles gecheckt. Das ist mir auch noch nicht klar wieso.
1 | void qdec_enabled(qdec_config_t *config) |
2 | {
|
3 | /* Check PORT configuration */
|
4 | #if XMEGA_B3
|
5 | Assert((config->port >= &PORTB) && (config->port <= &PORTD)); |
6 | #elif XMEGA_B || XMEGA_E
|
7 | Assert((config->port >= &PORTA) && (config->port <= &PORTD)); |
8 | #elif (!XMEGA_A4) && (!XMEGA_C4) && (!XMEGA_D4)
|
9 | Assert((config->port >= &PORTA) && (config->port <= &PORTF)); |
10 | #else
|
11 | Assert((config->port >= &PORTA) && (config->port <= &PORTE)); |
12 | #endif
|
13 | /* Check channel configuration */
|
14 | #if XMEGA_B || XMEGA_E
|
15 | Assert(config->event_channel == 0); |
16 | #elif XMEGA_D
|
17 | Assert((config->event_channel == 0) |
18 | || (config->event_channel == 2)); |
19 | #elif XMEGA_A || XMEGA_C
|
20 | Assert((config->event_channel == 0) |
21 | || (config->event_channel == 2) |
22 | || (config->event_channel == 4)); |
23 | #endif
|
24 | /* Check rotary configuration */
|
25 | #if !XMEGA_E
|
26 | Assert(!config->rotary); |
27 | #endif
|
28 | |
29 | qdec_enabled_pins(config); |
30 | qdec_enabled_evsys(config); |
31 | qdec_enabled_tc(config); |
32 | if (config->freq_opt.enabled) { |
33 | qdec_enabled_tc_freq(config); |
34 | }
|
35 | }
|
Gruß Tho -- mit den dafür vorgesehenen [ c ] [ /c ] -Tags wird das gleich etwas lesbarer, findest Du nicht? -rufus