VT100 Terminal App
Circle VT100 module documentation
Loading...
Searching...
No Matches
hal.h
Go to the documentation of this file.
1//------------------------------------------------------------------------------
2// Module: CHAL
3// Description: Hardware abstraction for buzzer control and serial pin routing.
4// Author: R. Zuehlsdorff, ralf.zuehlsdorff@t-online.de
5// Created: 2026-01-18
6// License: MIT License (https://opensource.org/license/mit/)
7//------------------------------------------------------------------------------
8// Change Log:
9// 2026-01-18 R. Zuehlsdorff Initial creation
10//------------------------------------------------------------------------------
11
12#pragma once
13
14
15// Include Circle core components
16#include <circle/types.h>
17#include <circle/timer.h>
18#include <circle/logger.h>
19#include <circle/usertimer.h>
20#include <circle/gpiopin.h>
21
31// Forward declarations and includes for classes used in this module
32
33
42class CHAL
43{
44public:
46 CHAL(CInterruptSystem *pInterruptSystem, CTimer *pTimer);
48 ~CHAL(void);
49
50 // \return Pointer to singleton CHAL instance
52 static CHAL *Get(void);
53
54 // Initialize PWM hardware (call once during startup)
56 boolean Initialize(void);
57
58 // 800 Hz PWM Buzzer with configured volume and 250ms duration
60 void BEEP(void);
61
62 // 800 Hz Click sound for key press
64 void Click(void);
65
66 // Start Buzzer with specified duty cycle and duration
67 // duty: 0-100% duty cycle
68 // duration: milliseconds (0 = continuous)
70 void StartBuzzer(unsigned duty, unsigned duration = 0);
71
72 // Stop Buzzer output
74 void StopBuzzer(void);
75
76 // Switch RxD <-> TxD pins for RS-232 mode
78 void SwitchRxTx(void);
79
80 // Apply configured RX/TX swap state
82 void ConfigureRxTxSwap(boolean enableSwap);
83
84 // Apply configured buzzer volume (0-100)
86 void ConfigureBuzzerVolume(unsigned volumePercent);
87
88 // Update function - call regularly from main loop to handle auto-stop
90 void Update(void);
91
92private:
94 static void UserTimerHandler(CUserTimer *pTimer, void *pParam);
96 void HandleTimerTick();
98 void StopInternal(boolean logMessage);
99
100private:
101 enum
102 {
103 PWMFrequencyHz = 800,
104 PWMPeriodMicros = 1000000U / PWMFrequencyHz,
105 PWMGPIOPin = 12,
106 RxTXSwitchPin = 16
107 };
108
109 CInterruptSystem *m_pInterruptSystem;
110 CTimer *m_pTimer;
111 CUserTimer m_UserTimer;
112 CGPIOPin m_Pin;
113 CGPIOPin m_RxTXSwitchPin;
114
115 boolean m_bGPIO16Configured;
116 boolean m_bBuzzerPinConfigured;
117 boolean m_bTimerInitialized;
118 boolean m_bActive;
119 boolean m_bUseTimer;
120 boolean m_bHighPhase;
121 boolean m_bRxTxSwitchMode;
122 unsigned m_nConfiguredBuzzerVolume;
123 unsigned m_nStopTicks;
124 unsigned m_nOnMicros;
125 unsigned m_nOffMicros;
126};
Provides buzzer control, GPIO switching, and timing utilities.
Definition hal.h:43
void StopBuzzer(void)
Halt buzzer activity immediately.
Definition hal.cpp:158
void Update(void)
Update fast timers to manage auto-stop behavior.
Definition hal.cpp:185
void ConfigureBuzzerVolume(unsigned volumePercent)
Store the buzzer volume percentage.
Definition hal.cpp:276
void Click(void)
Play a short click feedback tone.
Definition hal.cpp:101
void StartBuzzer(unsigned duty, unsigned duration=0)
Begin buzzer output with optional auto-stop duration.
Definition hal.cpp:106
void BEEP(void)
Play a fixed-duration beep using current volume setting.
Definition hal.cpp:96
void ConfigureRxTxSwap(boolean enableSwap)
Set the RX/TX swap mode explicitly.
Definition hal.cpp:255
boolean Initialize(void)
Prepare GPIO and timer resources required for HAL features.
Definition hal.cpp:57
void SwitchRxTx(void)
Toggle the hardware RX/TX pin swap relay.
Definition hal.cpp:244
~CHAL(void)
Ensure peripherals are quiesced on shutdown.
Definition hal.cpp:46
static CHAL * Get(void)
Access the singleton HAL instance.
Definition hal.cpp:19