-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathUtils.cpp
31 lines (23 loc) · 869 Bytes
/
Utils.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
#include "Utils.h"
#include "common.h"
#define RCC_APB2ENR_ADDR (0x40021000u + 0x18u)
//APB1ENR is @ RCC_APB2ENR_ADDR + 4
#define RCC_APB2RSTR_ADDR (0x40021000u + 0x0Cu)
void Utils::enablePeripheral(Utils::Peripheral peripheral) {
auto p = static_cast<uint8_t>(peripheral);
__RMM(RCC_APB2ENR_ADDR + ((uint8_t) (p >> 3u) & ~0b11u)) |= (1u << (p & 0b11111u));
}
void Utils::resetPeripheral(Utils::Peripheral peripheral) {
auto p = static_cast<uint8_t>(peripheral);
__RMM(RCC_APB2RSTR_ADDR + ((uint8_t) (p >> 3u) & ~0b11u)) |= (1u << (p & 0b11111u));
__RMM(RCC_APB2RSTR_ADDR + ((uint8_t) (p >> 3u) & ~0b11u)) &= ~(1u << (p & 0b11111u));
}
void Utils::reverseString(char *str, size_t len) {
char *right = str + len - 1;
char tmp;
while (str < right) {
tmp = *str;
*(str++) = *right;
*(right--) = tmp;
}
}