-
Notifications
You must be signed in to change notification settings - Fork 56
Expand file tree
/
Copy pathstm32cube_hal_mock.cpp
More file actions
48 lines (39 loc) · 1.39 KB
/
Copy pathstm32cube_hal_mock.cpp
File metadata and controls
48 lines (39 loc) · 1.39 KB
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
36
37
38
39
40
41
42
43
44
45
46
47
48
// Copyright 2026 Jan Delgado jdelgado@gmx.net
#include "stm32cube_hal_mock.h"
#include <cassert>
static Stm32CubeMockState* gState_ = nullptr;
void stm32MockSetInstance(Stm32CubeMockState* state) {
gState_ = state;
if (state) *state = Stm32CubeMockState{};
}
int stm32MockChanIndex(uint32_t channel) {
const int idx = static_cast<int>(channel / 4);
assert(idx >= 0 && idx < 4);
return idx;
}
extern "C" uint32_t HAL_GetTick(void) {
assert(gState_);
return gState_->tick;
}
extern "C" HAL_StatusTypeDef HAL_TIM_PWM_Start(TIM_HandleTypeDef* /*htim*/, uint32_t channel) {
assert(gState_);
gState_->pwm_start_count++;
gState_->last_start_channel = channel;
return HAL_OK;
}
extern "C" HAL_StatusTypeDef HAL_TIM_PWM_ConfigChannel(TIM_HandleTypeDef* /*htim*/,
const TIM_OC_InitTypeDef* config,
uint32_t channel) {
assert(gState_);
gState_->last_oc_config = *config;
gState_->last_config_channel = channel;
return HAL_OK;
}
uint32_t stm32MockGetCompare(TIM_HandleTypeDef* /*htim*/, uint32_t channel) {
assert(gState_);
return gState_->compare[stm32MockChanIndex(channel)];
}
void stm32MockSetCompare(TIM_HandleTypeDef* /*htim*/, uint32_t channel, uint32_t val) {
assert(gState_);
gState_->compare[stm32MockChanIndex(channel)] = val;
}