-
Notifications
You must be signed in to change notification settings - Fork 55
/
mbed.cpp
35 lines (26 loc) · 928 Bytes
/
mbed.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
// Minimal mbed mock for testing JLed hardware accessing functions
// Copyright 2020 Jan Delgado [email protected]
//
#include "mbed.h" // NOLINT
constexpr auto MBED_PINS = 32;
struct MbedState {
uint32_t us_ticks;
float pin_state[MBED_PINS];
} MbedState_;
void mbedMockInit() {
for (auto i = 0; i < MBED_PINS; i++) {
MbedState_.pin_state[i] = kUninitialized;
}
MbedState_.us_ticks = 0;
}
void mbedMockWrite(PinName pin, float value) {
MbedState_.pin_state[pin] = value;
}
float mbedMockGetPinState(uint8_t pin) { return MbedState_.pin_state[pin]; }
void mbedMockSetUsTicks(uint32_t ticks) { MbedState_.us_ticks = ticks; }
uint32_t us_ticker_read() { return MbedState_.us_ticks; }
void PwmOut::write(float val) { mbedMockWrite(pin_, val); }
Kernel::Clock::time_point Kernel::Clock::now() {
return Kernel::Clock::time_point(
std::chrono::microseconds(MbedState_.us_ticks));
}