@@ -147,17 +147,17 @@ void analogWriteDAC(pin_size_t pinNumber, int val){
147
147
indexAnalogWriteDAC (index, val);
148
148
}
149
149
150
- void indexAnalogWrite (pin_size_t index, int val){
151
- standInFunc ();
152
- // mbed::PwmOut* pwm = pinPWMByIndex(index);
153
- // if (pwm == NULL) {
154
- // pwm = new mbed::PwmOut(pinNameByIndex(index));
155
- // pinPWMByIndex(index) = pwm;
156
- // }
157
- // pwm->period_ms(2);
158
- // float percent = (float)val/(float)(1 << res_analog_w);
159
- // pwm->write(percent);
160
- }
150
+ // void indexAnalogWrite(pin_size_t index, int val){
151
+ // standInFunc();
152
+ // // mbed::PwmOut* pwm = pinPWMByIndex(index);
153
+ // // if (pwm == NULL) {
154
+ // // pwm = new mbed::PwmOut(pinNameByIndex(index));
155
+ // // pinPWMByIndex(index) = pwm;
156
+ // // }
157
+ // // pwm->period_ms(2);
158
+ // // float percent = (float)val/(float)(1 << res_analog_w);
159
+ // // pwm->write(percent);
160
+ // }
161
161
162
162
void analogWrite (PinName pinName, int val){
163
163
pin_size_t index = pinIndexByName (pinName);
@@ -170,3 +170,73 @@ void analogWrite(pin_size_t pinNumber, int val){
170
170
if ( index == variantPinCount ){ return ; }
171
171
indexAnalogWrite (index, val);
172
172
}
173
+
174
+ // #if DEVICE_LPTICKER
175
+ // static mbed::LowPowerTimer t;
176
+ // #else
177
+ static mbed::Timer t;
178
+ // #endif
179
+
180
+ using namespace std ::chrono_literals;
181
+ using namespace std ::chrono;
182
+
183
+ void
EDBE
span> initTimer (void ){
184
+ t.start ();
185
+ }
186
+
187
+ unsigned long millis (void ){
188
+ return duration_cast<milliseconds>(t.elapsed_time ()).count ();
189
+ }
190
+
191
+ unsigned long micros (void ){
192
+ return t.elapsed_time ().count ();
193
+ }
194
+
195
+ void delay (unsigned long ms){
196
+ #ifndef NO_RTOS
197
+ rtos::ThisThread::sleep_for (ms * 1ms);
198
+ #else
199
+ wait_us (ms * 1000 );
200
+ #endif
201
+ }
202
+
203
+ void delayMicroseconds (unsigned int us){
204
+ wait_us (us);
205
+ }
206
+
207
+ // unsigned long indexPulseIn(pin_size_t index, uint8_t state, unsigned long timeout){
208
+ // standInFunc();
209
+ // return 0;
210
+ // }
211
+
212
+ unsigned long pulseIn (PinName pinName, uint8_t state, unsigned long timeout){
213
+ pin_size_t index = pinIndexByName (pinName);
214
+ if ( index == variantPinCount ){ return 0 ; }
215
+ return indexPulseIn (index, state, timeout);
216
+ }
217
+
218
+ unsigned long pulseIn (pin_size_t pinNumber, uint8_t state, unsigned long timeout){
219
+ pin_size_t index = pinIndexByNumber (pinNumber);
220
+ if ( index == variantPinCount ){ return 0 ; }
221
+ return indexPulseIn (index, state, timeout);
222
+ }
223
+
224
+ unsigned long indexPulseInLong (pin_size_t index, uint8_t state, unsigned long timeout){
225
+ return indexPulseIn (index, state, timeout); // pulseIn and pulseInLong are identical
226
+ }
227
+
228
+ unsigned long pulseInLong (PinName pinName, uint8_t state, unsigned long timeout){
229
+ pin_size_t index = pinIndexByName (pinName);
230
+ if ( index == variantPinCount ){ return 0 ; }
231
+ return pulseInLong (index, state, timeout);
232
+ }
233
+
234
+ unsigned long pulseInLong (pin_size_t pinNumber, uint8_t state, unsigned long timeout){
235
+ pin_size_t index = pinIndexByNumber (pinNumber);
236
+ if ( index == variantPinCount ){ return 0 ; }
237
+ return pulseInLong (index, state, timeout);
238
+ }
239
+
240
+ void init (void ){
241
+ initTimer ();
242
+ }
0 commit comments