-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhal.cpp
More file actions
100 lines (79 loc) · 2.5 KB
/
hal.cpp
File metadata and controls
100 lines (79 loc) · 2.5 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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
/*
* TT Control, advanced sinusoidal control of multi-phase turntable motors
* Created by Ashley Cox at The Blind Man’s Workshop
* https://theblindmansworkshop.com
* No part of this code may be used or reproduced for commercial purposes without written permission and contractual agreement
* All external libraries and frameworks are the property of their respective authors and governed by their respective licenses
*/
#include "hal.h"
extern "C" {
#include <hardware/watchdog.h>
#include <pico/stdlib.h>
}
HardwareAbstraction hal;
HardwareAbstraction::HardwareAbstraction() {
_watchdogEnabled = false;
}
void HardwareAbstraction::begin() {
// Initialize any global hardware states here if needed
}
void HardwareAbstraction::setPinMode(int pin, int mode) {
pinMode(pin, mode);
}
void HardwareAbstraction::digitalWrite(int pin, int value) {
::digitalWrite(pin, (PinStatus)value);
}
int HardwareAbstraction::digitalRead(int pin) {
return ::digitalRead(pin);
}
void HardwareAbstraction::analogWrite(int pin, int value) {
::analogWrite(pin, value);
}
void HardwareAbstraction::setPWMFreq(int freq) {
::analogWriteFreq(freq);
}
void HardwareAbstraction::setPWMRange(int range) {
::analogWriteRange(range);
}
void HardwareAbstraction::watchdogEnable(int timeoutMs) {
// RP2040 Watchdog Max timeout is approx 8.3 seconds
if (timeoutMs > 8300) timeoutMs = 8300;
// Enable watchdog with pause on debug support
watchdog_enable(timeoutMs, 1);
_watchdogEnabled = true;
}
void HardwareAbstraction::watchdogFeed() {
if (_watchdogEnabled) {
watchdog_update();
}
}
void HardwareAbstraction::watchdogReboot() {
// Force immediate reboot
watchdog_reboot(0, 0, 0);
}
uint32_t HardwareAbstraction::getMicros() {
return micros();
}
uint32_t HardwareAbstraction::getMillis() {
return millis();
}
void HardwareAbstraction::delayMs(uint32_t ms) {
delay(ms);
}
void HardwareAbstraction::setMuteRelay(int index, bool active) {
// Helper to map index to physical pin
// Note: Polarity and timing are handled by MotorController
int pin = -1;
switch(index) {
case 0: pin = PIN_MUTE_PHASE_A; break;
case 1: pin = PIN_MUTE_PHASE_B; break;
case 2: pin = PIN_MUTE_PHASE_C; break;
case 3: pin = PIN_MUTE_PHASE_D; break;
}
if (pin != -1) {
::digitalWrite(pin, active ? HIGH : LOW);
}
}
void HardwareAbstraction::setStandbyRelay(bool active) {
::digitalWrite(PIN_RELAY_STANDBY, active ? HIGH : LOW);
}