|
26 | 26 |
|
27 | 27 | #include "peripherals/pcnt.h" |
28 | 28 |
|
29 | | -#include "py/runtime.h" |
30 | | -#include "supervisor/shared/translate.h" |
31 | | - |
32 | 29 | #define PCNT_UNIT_ACTIVE 1 |
33 | 30 | #define PCNT_UNIT_INACTIVE 0 |
34 | 31 |
|
35 | 32 | static uint8_t pcnt_state[4]; |
36 | 33 |
|
37 | | -void peripherals_pcnt_init(pcnt_config_t* pcnt_config) { |
| 34 | +int peripherals_pcnt_init(pcnt_config_t pcnt_config) { |
38 | 35 | // Look for available pcnt unit |
39 | 36 | for (uint8_t i = 0; i<=3; i++) { |
40 | 37 | if (pcnt_state[i] == PCNT_UNIT_INACTIVE) { |
41 | | - pcnt_config->unit = (pcnt_unit_t)i; |
| 38 | + pcnt_config.unit = (pcnt_unit_t)i; |
42 | 39 | pcnt_state[i] = PCNT_UNIT_ACTIVE; |
43 | 40 | break; |
44 | 41 | } else if (i == 3) { |
45 | | - mp_raise_RuntimeError(translate("All PCNT units in use")); |
| 42 | + return -1; |
46 | 43 | } |
47 | 44 | } |
48 | 45 |
|
49 | 46 | // Initialize PCNT unit |
50 | | - pcnt_unit_config(pcnt_config); |
| 47 | + pcnt_unit_config(&pcnt_config); |
51 | 48 |
|
52 | 49 | // Configure and enable the input filter |
53 | | - pcnt_set_filter_value(pcnt_config->unit, 100); |
54 | | - pcnt_filter_enable(pcnt_config->unit); |
| 50 | + pcnt_set_filter_value(pcnt_config.unit, 100); |
| 51 | + pcnt_filter_enable(pcnt_config.unit); |
55 | 52 |
|
56 | 53 | // Initialize PCNT's counter |
57 | | - pcnt_counter_pause(pcnt_config->unit); |
58 | | - pcnt_counter_clear(pcnt_config->unit); |
| 54 | + pcnt_counter_pause(pcnt_config.unit); |
| 55 | + pcnt_counter_clear(pcnt_config.unit); |
59 | 56 |
|
60 | 57 | // Everything is set up, now go to counting |
61 | | - pcnt_counter_resume(pcnt_config->unit); |
| 58 | + pcnt_counter_resume(pcnt_config.unit); |
| 59 | + |
| 60 | + return pcnt_config.unit; |
62 | 61 | } |
63 | 62 |
|
64 | 63 | void peripherals_pcnt_deinit(pcnt_unit_t* unit) { |
|
0 commit comments