diff options
Diffstat (limited to 'lib/chibios-contrib/testhal/NRF51/NRF51822/PWM/main.c')
-rw-r--r-- | lib/chibios-contrib/testhal/NRF51/NRF51822/PWM/main.c | 74 |
1 files changed, 74 insertions, 0 deletions
diff --git a/lib/chibios-contrib/testhal/NRF51/NRF51822/PWM/main.c b/lib/chibios-contrib/testhal/NRF51/NRF51822/PWM/main.c new file mode 100644 index 000000000..34b18288d --- /dev/null +++ b/lib/chibios-contrib/testhal/NRF51/NRF51822/PWM/main.c | |||
@@ -0,0 +1,74 @@ | |||
1 | /* | ||
2 | Copyright (C) 2016 Stéphane D'Alu | ||
3 | |||
4 | Licensed under the Apache License, Version 2.0 (the "License"); | ||
5 | you may not use this file except in compliance with the License. | ||
6 | You may obtain a copy of the License at | ||
7 | |||
8 | http://www.apache.org/licenses/LICENSE-2.0 | ||
9 | |||
10 | Unless required by applicable law or agreed to in writing, software | ||
11 | distributed under the License is distributed on an "AS IS" BASIS, | ||
12 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
13 | See the License for the specific language governing permissions and | ||
14 | limitations under the License. | ||
15 | */ | ||
16 | |||
17 | #include "ch.h" | ||
18 | #include "hal.h" | ||
19 | |||
20 | static void pwm_cb_period(PWMDriver *pwmp) { | ||
21 | (void)pwmp; | ||
22 | |||
23 | palTogglePad(IOPORT1, LED0); | ||
24 | palClearPad(IOPORT1, LED1); | ||
25 | |||
26 | } | ||
27 | |||
28 | static void pwm_cb_channel0(PWMDriver *pwmp) { | ||
29 | (void)pwmp; | ||
30 | palSetPad(IOPORT1, LED1); | ||
31 | } | ||
32 | |||
33 | |||
34 | /* | ||
35 | * Application entry point. | ||
36 | */ | ||
37 | int main(void) { | ||
38 | PWMConfig pwmcfg = { | ||
39 | .frequency = PWM_FREQUENCY_31250HZ, | ||
40 | .period = 31250, | ||
41 | .callback = pwm_cb_period, | ||
42 | { { .mode = PWM_OUTPUT_DISABLED, | ||
43 | .callback = pwm_cb_channel0, }, | ||
44 | { .mode = PWM_OUTPUT_ACTIVE_HIGH, | ||
45 | .callback = NULL, | ||
46 | .ioline = LINE_LED2, | ||
47 | .gpiote_channel = 0, | ||
48 | .ppi_channel = { 0, 1 } }, | ||
49 | }, | ||
50 | }; | ||
51 | |||
52 | /* | ||
53 | * System initializations. | ||
54 | * - HAL initialization, this also initializes the configured device drivers | ||
55 | * and performs the board-specific initializations. | ||
56 | * - Kernel initialization, the main() function becomes a thread and the | ||
57 | * RTOS is active. | ||
58 | */ | ||
59 | halInit(); | ||
60 | chSysInit(); | ||
61 | |||
62 | /* | ||
63 | * | ||
64 | */ | ||
65 | pwmStart(&PWMD1, &pwmcfg); | ||
66 | pwmEnablePeriodicNotification(&PWMD1); | ||
67 | pwmEnableChannel(&PWMD1, 0, PWM_FRACTION_TO_WIDTH(&PWMD1, 2, 1)); | ||
68 | pwmEnableChannelNotification(&PWMD1, 0); | ||
69 | pwmEnableChannel(&PWMD1, 1, PWM_FRACTION_TO_WIDTH(&PWMD1, 4, 3)); | ||
70 | |||
71 | while (1) { | ||
72 | chThdSleepMilliseconds(500); | ||
73 | } | ||
74 | } | ||