]> git.donarmstrong.com Git - qmk_firmware.git/blob - tool/mbed/mbed-sdk/libraries/tests/mbed/pwm/main.cpp
Squashed 'tmk_core/' changes from 7967731..b9e0ea0
[qmk_firmware.git] / tool / mbed / mbed-sdk / libraries / tests / mbed / pwm / main.cpp
1 #include "test_env.h"
2
3 /* Timer/Match Register    Pinout Options
4
5 CT16B0/MR0  p5 (P0_9)
6 CT16B0/MR1  p6 (P0_8)
7 CT16B0/MR2  p34 (P1_15)
8
9 CT16B1/MR0  p36 (P0_21)
10 CT16B1/MR1  p20 (P0_22) and p14 (P1_23)
11
12 CT32B0/MR0  p25 (P1_24)
13 CT32B0/MR1  p26 (P1_25) and USBTX (P0_19)
14 CT32B0/MR2  p10 (P1_26)
15  */
16
17 float value = 0.75;
18
19 int main() {
20 #if defined(TARGET_FF_ARDUINO)
21     PwmOut pwm(D9);
22
23     pwm.period_ms(10);
24     pwm.write(value);
25
26     float result = floor(pwm.read() * 100 + 0.5) / 100; // round it to 0.xx
27     printf("Initialize PWM on pin D9 with duty cycle: %.2f\n", result);
28
29     notify_completion(result == value ? true : false);
30
31 #elif defined(TARGET_LPC1768) || defined(TARGET_LPC2368) || defined(TARGET_LPC11U24) || defined(TARGET_LPC4088)
32     PwmOut pwm_p25(p25);
33     PwmOut pwm_p26(p26);
34
35     pwm_p25.write(0.75);
36     pwm_p26.write(0.50);
37
38     printf("Initialize PWM on pin 25 with duty cycle: %.2f\n", pwm_p25.read());
39     printf("Initialize PWM on pin 26 with duty cycle: %.2f\n", pwm_p26.read());
40
41 #elif defined(TARGET_LPC1114)
42     PwmOut pwm_dp24(dp24); // P0_1
43     PwmOut pwm_dp18(dp18); // P1_9
44
45     pwm_dp24.write(0.75);
46     pwm_dp18.write(0.50);
47
48     printf("Initialize PWM on pin 24 with duty cycle: %.2f\n", pwm_dp24.read());
49     printf("Initialize PWM on pin 18 with duty cycle: %.2f\n", pwm_dp18.read());
50
51 #elif defined(TARGET_nRF51822)
52     PwmOut pwm_p24(p24);
53     PwmOut pwm_p25(p25);
54
55     pwm_p24.write(0.75);
56     pwm_p25.write(0.50);
57
58     printf("Initialize PWM on pin 24 with duty cycle: %.2f\n", pwm_p24.read());
59     printf("Initialize PWM on pin 25 with duty cycle: %.2f\n", pwm_p25.read());
60
61 #elif defined(TARGET_DISCO_F100RB)
62     PwmOut pwm_1(PB_3);
63     PwmOut pwm_2(PB_4);
64
65     pwm_1.write(0.75);
66     pwm_2.write(0.50);
67
68     printf("Initialize PWM on pin PB_3 with duty cycle: %.2f\n", pwm_1.read());
69     printf("Initialize PWM on pin PB_4 with duty cycle: %.2f\n", pwm_2.read());
70 #elif defined(TARGET_DISCO_F051R8)
71     PwmOut pwm_1(PA_7);
72     PwmOut pwm_2(PC_7);
73
74     pwm_1.write(0.75);
75     pwm_2.write(0.50);
76
77     printf("Initialize PWM on pin PA_7 with duty cycle: %.2f\n", pwm_1.read());
78     printf("Initialize PWM on pin PC_7 with duty cycle: %.2f\n", pwm_2.read());
79 #elif defined(TARGET_DISCO_F303VC)
80     PwmOut pwm_1(PA_8);
81     PwmOut pwm_2(PA_9);
82
83     pwm_1.write(0.75);
84     pwm_2.write(0.50);
85
86     printf("Initialize PWM on pin PA_7 with duty cycle: %.2f\n", pwm_1.read());
87     printf("Initialize PWM on pin PC_7 with duty cycle: %.2f\n", pwm_2.read());
88 #elif defined(TARGET_MAXWSNENV)
89     PwmOut pwm_1(TP2);
90     PwmOut pwm_2(TP4);
91
92     pwm_1.write(0.75);
93     pwm_2.write(0.50);
94
95     printf("Initialize PWM on pin TP2 with duty cycle: %.2f\n", pwm_1.read());
96     printf("Initialize PWM on pin TP4 with duty cycle: %.2f\n", pwm_2.read());
97 #elif defined(TARGET_DISCO_F407VG)
98     PwmOut pwm_1(PD_12);
99     PwmOut pwm_2(PD_13);
100
101     pwm_1.write(value);
102     pwm_2.write(0.50);
103     
104     float result = floor(pwm_1.read() * 100 + 0.5) / 100; // round it to 0.xx
105
106     printf("Initialize PWM on pin PD_12 with duty cycle: %.2f\n", result);
107     printf("Initialize PWM on pin PD_13 with duty cycle: %.2f\n", pwm_2.read());
108
109     notify_completion(result == value ? true : false);
110 #elif defined(TARGET_DISCO_F429ZI)
111     PwmOut pwm_1(PA_0);
112
113     pwm_1.write(value);
114     
115     float result = floor(pwm_1.read() * 100 + 0.5) / 100; // round it to 0.xx
116
117     printf("Initialize PWM on pin PD_12 with duty cycle: %.2f\n", result);
118
119     notify_completion(result == value ? true : false);
120 #elif defined(TARGET_MTS_MDOT_F405RG)
121     PwmOut pwm_1(PA_0);
122
123     pwm_1.write(value);
124     
125     float result = floor(pwm_1.read() * 100 + 0.5) / 100; // round it to 0.xx
126
127     printf("Initialize PWM on pin PD_12 with duty cycle: %.2f\n", result);
128
129     notify_completion(result == value ? true : false);
130 #elif defined(TARGET_MTS_DRAGONFLY_F411RE)
131     PwmOut pwm_1(PA_0);
132
133     pwm_1.write(value);
134     
135     float result = floor(pwm_1.read() * 100 + 0.5) / 100; // round it to 0.xx
136
137     printf("Initialize PWM on pin PD_12 with duty cycle: %.2f\n", result);
138
139     notify_completion(result == value ? true : false);
140 #elif defined(TARGET_MTS_MDOT_F411RE)
141     PwmOut pwm_1(PA_0);
142
143     pwm_1.write(value);
144     
145     float result = floor(pwm_1.read() * 100 + 0.5) / 100; // round it to 0.xx
146
147     printf("Initialize PWM on pin PD_12 with duty cycle: %.2f\n", result);
148
149     notify_completion(result == value ? true : false);
150 #elif defined(TARGET_UBLOX_C029)
151     PwmOut pwm_1(PA_0);
152
153     pwm_1.write(value);
154     
155     float result = floor(pwm_1.read() * 100 + 0.5) / 100; // round it to 0.xx
156
157     printf("Initialize PWM on pin PD_12 with duty cycle: %.2f\n", result);
158
159     notify_completion(result == value ? true : false);
160 #elif defined(TARGET_MAX32600MBED)
161     PwmOut pwm_1(P1_2);
162     PwmOut pwm_2(P1_3);
163
164     pwm_1.write(0.75);
165     pwm_2.write(0.50);
166
167     printf("Initialize PWM on pin P1.2 with duty cycle: %.2f\n", pwm_1.read());
168     printf("Initialize PWM on pin P1.3 with duty cycle: %.2f\n", pwm_2.read());
169 #else
170 #error This test is not supported on this target.
171 #endif
172
173     notify_completion(true);
174 }