HF Interface Wrapper 0.1.0-dev
Embedded C++ hardware abstraction layer
Loading...
Searching...
No Matches
BaseGpio.h
Go to the documentation of this file.
1
21#pragma once
22
23#include "HardwareTypes.h"
24#include <cstdint>
25#include <string_view>
26
45#define HF_GPIO_ERR_LIST(X) \
46 /* Success codes */ \
47 X(GPIO_SUCCESS, 0, "Success") \
48 \
49 /* General errors */ \
50 X(GPIO_ERR_FAILURE, 1, "General failure") \
51 X(GPIO_ERR_NOT_INITIALIZED, 2, "Not initialized") \
52 X(GPIO_ERR_ALREADY_INITIALIZED, 3, "Already initialized") \
53 X(GPIO_ERR_INVALID_PARAMETER, 4, "Invalid parameter") \
54 X(GPIO_ERR_NULL_POINTER, 5, "Null pointer") \
55 X(GPIO_ERR_OUT_OF_MEMORY, 6, "Out of memory") \
56 \
57 /* Pin errors */ \
58 X(GPIO_ERR_INVALID_PIN, 7, "Invalid pin") \
59 X(GPIO_ERR_PIN_NOT_FOUND, 8, "Pin not found") \
60 X(GPIO_ERR_PIN_NOT_CONFIGURED, 9, "Pin not configured") \
61 X(GPIO_ERR_PIN_ALREADY_REGISTERED, 10, "Pin already registered") \
62 X(GPIO_ERR_PIN_ACCESS_DENIED, 11, "Pin access denied") \
63 X(GPIO_ERR_PIN_BUSY, 12, "Pin busy") \
64 \
65 /* Hardware errors */ \
66 X(GPIO_ERR_HARDWARE_FAULT, 13, "Hardware fault") \
67 X(GPIO_ERR_COMMUNICATION_FAILURE, 14, "Communication failure") \
68 X(GPIO_ERR_DEVICE_NOT_RESPONDING, 15, "Device not responding") \
69 X(GPIO_ERR_TIMEOUT, 16, "Timeout") \
70 X(GPIO_ERR_VOLTAGE_OUT_OF_RANGE, 17, "Voltage out of range") \
71 \
72 /* Configuration errors */ \
73 X(GPIO_ERR_INVALID_CONFIGURATION, 18, "Invalid configuration") \
74 X(GPIO_ERR_UNSUPPORTED_OPERATION, 19, "Unsupported operation") \
75 X(GPIO_ERR_RESOURCE_BUSY, 20, "Resource busy") \
76 X(GPIO_ERR_RESOURCE_UNAVAILABLE, 21, "Resource unavailable") \
77 \
78 /* I/O errors */ \
79 X(GPIO_ERR_READ_FAILURE, 22, "Read failure") \
80 X(GPIO_ERR_WRITE_FAILURE, 23, "Write failure") \
81 X(GPIO_ERR_DIRECTION_MISMATCH, 24, "Direction mismatch") \
82 X(GPIO_ERR_PULL_RESISTOR_FAILURE, 25, "Pull resistor failure") \
83 \
84 /* Interrupt errors */ \
85 X(GPIO_ERR_INTERRUPT_NOT_SUPPORTED, 26, "Interrupt not supported") \
86 X(GPIO_ERR_INTERRUPT_ALREADY_ENABLED, 27, "Interrupt already enabled") \
87 X(GPIO_ERR_INTERRUPT_NOT_ENABLED, 28, "Interrupt not enabled") \
88 X(GPIO_ERR_INTERRUPT_HANDLER_FAILED, 29, "Interrupt handler failed") \
89 \
90 /* System errors */ \
91 X(GPIO_ERR_SYSTEM_ERROR, 30, "System error") \
92 X(GPIO_ERR_PERMISSION_DENIED, 31, "Permission denied") \
93 X(GPIO_ERR_OPERATION_ABORTED, 32, "Operation aborted") \
94 \
95 /* Extended errors for McuGpio implementation */ \
96 X(GPIO_ERR_NOT_SUPPORTED, 33, "Operation not supported") \
97 X(GPIO_ERR_DRIVER_ERROR, 34, "Driver error") \
98 X(GPIO_ERR_INVALID_STATE, 35, "Invalid state") \
99 X(GPIO_ERR_INVALID_ARG, 36, "Invalid argument") \
100 X(GPIO_ERR_CALIBRATION_FAILURE, 37, "Calibration failure") \
101 X(GPIO_ERR_UNKNOWN, 38, "Unknown error")
102
108enum class hf_gpio_err_t : hf_u8_t {
109#define X(NAME, VALUE, DESC) NAME = VALUE,
111#undef X
112 GPIO_ERR_COUNT // Automatically calculated count
113};
114
121constexpr std::string_view HfGpioErrToString(hf_gpio_err_t err) noexcept {
122 switch (err) {
123#define X(NAME, VALUE, DESC) \
124 case hf_gpio_err_t::NAME: \
125 return DESC;
127#undef X
128 default:
130 }
131}
132
142
151};
152
162
172
182
194
208
209// Forward declaration for callback
210class BaseGpio;
211
221 void(*)(BaseGpio* gpio, hf_gpio_interrupt_trigger_t trigger, void* user_data);
222
233
254
274
294class BaseGpio {
295public:
296 //==============================================================//
297 // CONSTRUCTORS AND DESTRUCTOR
298 //==============================================================//
299
303 BaseGpio(const BaseGpio& copy) = delete;
304
308 BaseGpio& operator=(const BaseGpio& copy) = delete;
309
313 virtual ~BaseGpio() noexcept = default;
314
315 //==============================================================//
316 // INITIALIZATION AND STATUS
317 //==============================================================//
318
323 [[nodiscard]] bool IsInitialized() const noexcept;
324
329 bool EnsureInitialized() noexcept;
330
335 bool EnsureDeinitialized() noexcept;
336
341 [[nodiscard]] hf_pin_num_t GetPin() const noexcept;
342
343protected:
344 //==============================================================//
345 // [PROTECTED] PURE VIRTUAL IMPLEMENTATIONS - PLATFORM SPECIFIC
346 //==============================================================//
347
353 virtual hf_gpio_err_t SetDirectionImpl(hf_gpio_direction_t direction) noexcept = 0;
362 virtual hf_gpio_err_t GetDirectionImpl(hf_gpio_direction_t& direction) const noexcept = 0;
363
378 virtual hf_gpio_err_t GetOutputModeImpl(hf_gpio_output_mode_t& mode) const noexcept = 0;
379
393 virtual hf_gpio_pull_mode_t GetPullModeImpl() const noexcept = 0;
394
400 virtual hf_gpio_err_t SetPinLevelImpl(hf_gpio_level_t level) noexcept = 0;
406 virtual hf_gpio_err_t GetPinLevelImpl(hf_gpio_level_t& level) noexcept = 0;
407
408public:
409 //==============================================================//
410 // DIRECTION AND MODE MANAGEMENT
411 //==============================================================//
412
417 [[nodiscard]] hf_gpio_direction_t GetDirection() const noexcept;
418
425
430 [[nodiscard]] bool IsInput() const noexcept;
431
436 [[nodiscard]] bool IsOutput() const noexcept;
437
442 [[nodiscard]] hf_gpio_output_mode_t GetOutputMode() const noexcept;
443
450
451 //==============================================================//
452 // PULL RESISTOR MANAGEMENT
453 //==============================================================//
454
459 [[nodiscard]] hf_gpio_pull_mode_t GetPullMode() const noexcept;
460
467
468 //==============================================================//
469 // STATE MANAGEMENT AND I/O OPERATIONS
470 //==============================================================//
471
476 [[nodiscard]] hf_gpio_state_t GetCurrentState() const noexcept;
477
483 hf_gpio_err_t SetState(hf_gpio_state_t state) noexcept;
484
489 [[nodiscard]] hf_gpio_active_state_t GetActiveState() const noexcept;
490
495 void SetActiveState(hf_gpio_active_state_t active_state) noexcept;
496
497 //==============================================================//
498 // STATE CONTROL METHODS
499 //==============================================================//
500
505 hf_gpio_err_t SetActive() noexcept;
506
511 hf_gpio_err_t SetInactive() noexcept;
512
517 hf_gpio_err_t Toggle() noexcept;
518
524 hf_gpio_err_t IsActive(bool& is_active) noexcept;
525
526 //==============================================================//
527 // HARDWARE VERIFICATION AND FAULT DETECTION
528 //==============================================================//
529
538 hf_gpio_err_t VerifyDirection(hf_gpio_direction_t& direction) const noexcept;
539
549
558
559 //==============================================================//
560 // HARDWARE ABSTRACTION INTERFACE
561 //==============================================================//
562
567 [[nodiscard]] virtual bool IsPinAvailable() const noexcept = 0;
568
573 [[nodiscard]] virtual hf_u8_t GetMaxPins() const noexcept = 0;
578 [[nodiscard]] virtual const char* GetDescription() const noexcept = 0;
579
580 //==============================================================//
581 // INTERRUPT FUNCTIONALITY
582 //==============================================================//
583
588 [[nodiscard]] virtual hf_gpio_err_t SupportsInterrupts() const noexcept {
589 return hf_gpio_err_t::GPIO_ERR_NOT_SUPPORTED; // Default implementation - no interrupt support
590 }
591
600 InterruptCallback callback = nullptr,
601 void* user_data = nullptr) noexcept {
603 }
604
612
620
626 virtual hf_gpio_err_t WaitForInterrupt(hf_u32_t timeout_ms = 0) noexcept {
628 }
629
638
646
647 //==============================================================//
648 // STATISTICS AND DIAGNOSTICS
649 //==============================================================//
650
656 virtual hf_gpio_err_t ResetStatistics() noexcept {
657 statistics_ = hf_gpio_statistics_t{}; // Reset statistics to default values
659 }
660
666 virtual hf_gpio_err_t ResetDiagnostics() noexcept {
667 diagnostics_ = hf_gpio_diagnostics_t{}; // Reset diagnostics to default values
669 }
670
676 virtual hf_gpio_err_t GetStatistics(hf_gpio_statistics_t& statistics) const noexcept {
677 statistics = statistics_; // Return statistics by default
679 }
680
686 virtual hf_gpio_err_t GetDiagnostics(hf_gpio_diagnostics_t& diagnostics) const noexcept {
687 diagnostics = diagnostics_; // Return diagnostics by default
689 }
690
691 //==============================================================//
692 // STRING CONVERSION UTILITIES
693 //==============================================================//
694 static const char* ToString(hf_gpio_state_t state) noexcept;
695 static const char* ToString(hf_gpio_level_t level) noexcept;
696 static const char* ToString(hf_gpio_active_state_t active_state) noexcept;
697 static const char* ToString(hf_gpio_direction_t direction) noexcept;
698 static const char* ToString(hf_gpio_output_mode_t output_mode) noexcept;
699 static const char* ToString(hf_gpio_pull_mode_t pull_mode) noexcept;
700 static const char* ToString(hf_gpio_interrupt_trigger_t trigger) noexcept;
701
702 //==============================================================//
703 // PURE VIRTUAL FUNCTIONS - MUST BE IMPLEMENTED BY DERIVED CLASSES
704 //==============================================================//
705
710 virtual bool Initialize() noexcept = 0;
711
716 virtual bool Deinitialize() noexcept {
717 initialized_ = false;
718 return true;
719 }
720
721protected:
722 //==============================================================//
723 // PROTECTED HELPER METHODS
724 //==============================================================//
725
730 [[nodiscard]] hf_gpio_err_t ValidateBasicOperation() const noexcept;
731
737 [[nodiscard]] hf_gpio_level_t StateToLevel(hf_gpio_state_t state) const noexcept;
738
744 [[nodiscard]] hf_gpio_state_t LevelToState(hf_gpio_level_t level) const noexcept;
745
765
766 //==============================================================//
767 // MEMBER VARIABLES
768 //==============================================================//
769
779};
780
781//==============================================================//
782// MEMBER FUNCTION DEFINITIONS
783//==============================================================//
784
785// Initialization and Status Methods
786inline bool BaseGpio::IsInitialized() const noexcept {
787 return initialized_;
788}
789
790inline bool BaseGpio::EnsureInitialized() noexcept {
791 if (!initialized_) {
793 }
794 return initialized_;
795}
796
797inline bool BaseGpio::EnsureDeinitialized() noexcept {
798 if (initialized_) {
800 return !initialized_;
801 }
802 return true;
803}
804
805inline hf_pin_num_t BaseGpio::GetPin() const noexcept {
806 return pin_;
807}
808
809// Direction and Mode Management Methods
811 return current_direction_;
812}
813
815 hf_gpio_err_t validation = ValidateBasicOperation();
816 if (validation != hf_gpio_err_t::GPIO_SUCCESS) {
817 return validation;
818 }
819
820 hf_gpio_err_t result = SetDirectionImpl(direction);
821 if (result == hf_gpio_err_t::GPIO_SUCCESS) {
822 current_direction_ = direction;
823 }
824 return result;
825}
826
827//=================================================================//
828//=================================================================//
829// FUNCTION DEFINITIONS //
830//=================================================================//
831//=================================================================//
832
836
840
842 return output_mode_;
843}
844
846 hf_gpio_err_t validation = ValidateBasicOperation();
847 if (validation != hf_gpio_err_t::GPIO_SUCCESS) {
848 return validation;
849 }
850
851 hf_gpio_err_t result = SetOutputModeImpl(mode);
852 if (result == hf_gpio_err_t::GPIO_SUCCESS) {
853 output_mode_ = mode;
854 }
855 return result;
856}
857
858// Pull Resistor Management Methods
860 return pull_mode_;
861}
862
864 hf_gpio_err_t validation = ValidateBasicOperation();
865 if (validation != hf_gpio_err_t::GPIO_SUCCESS) {
866 return validation;
867 }
868
869 hf_gpio_err_t result = SetPullModeImpl(mode);
870 if (result == hf_gpio_err_t::GPIO_SUCCESS) {
871 pull_mode_ = mode;
872 }
873 return result;
874}
875
876// State Management and I/O Operations Methods
878 return current_state_;
879}
880
882 hf_gpio_err_t validation = ValidateBasicOperation();
883 if (validation != hf_gpio_err_t::GPIO_SUCCESS) {
884 return validation;
885 }
886
887 // Convert logical state to electrical level based on polarity
888 hf_gpio_level_t level = StateToLevel(state);
889 hf_gpio_err_t result = SetPinLevelImpl(level);
890 if (result == hf_gpio_err_t::GPIO_SUCCESS) {
891 current_state_ = state;
892 }
893 return result;
894}
895
897 return active_state_;
898}
899
900inline void BaseGpio::SetActiveState(hf_gpio_active_state_t active_state) noexcept {
901 active_state_ = active_state;
902}
903
904// State Control Methods
907 if (validation != hf_gpio_err_t::GPIO_SUCCESS) {
908 return validation;
909 }
910
911 // Convert logical state to electrical level based on polarity
913 hf_gpio_err_t result = SetPinLevelImpl(level);
914 if (result == hf_gpio_err_t::GPIO_SUCCESS) {
916 }
917 return result;
918}
919
922 if (validation != hf_gpio_err_t::GPIO_SUCCESS) {
923 return validation;
924 }
925
926 // Convert logical state to electrical level based on polarity
928 hf_gpio_err_t result = SetPinLevelImpl(level);
929 if (result == hf_gpio_err_t::GPIO_SUCCESS) {
931 }
932 return result;
933}
934
937 if (validation != hf_gpio_err_t::GPIO_SUCCESS) {
938 return validation;
939 }
940
941 // Read current level, invert it, and set the new level
942 hf_gpio_level_t current_level;
943 hf_gpio_err_t result = GetPinLevelImpl(current_level);
944 if (result != hf_gpio_err_t::GPIO_SUCCESS) {
945 return result;
946 }
947
948 hf_gpio_level_t new_level = (current_level == hf_gpio_level_t::HF_GPIO_LEVEL_HIGH)
951
952 result = SetPinLevelImpl(new_level);
953 if (result == hf_gpio_err_t::GPIO_SUCCESS) {
954 current_state_ = LevelToState(new_level);
955 }
956 return result;
957}
958
959inline hf_gpio_err_t BaseGpio::IsActive(bool& is_active) noexcept {
960 hf_gpio_err_t validation = ValidateBasicOperation();
961 if (validation != hf_gpio_err_t::GPIO_SUCCESS) {
962 return validation;
963 }
964
965 hf_gpio_level_t level;
966 hf_gpio_err_t result = GetPinLevelImpl(level);
967 if (result == hf_gpio_err_t::GPIO_SUCCESS) {
968 hf_gpio_state_t state = LevelToState(level);
969 is_active = (state == hf_gpio_state_t::HF_GPIO_STATE_ACTIVE);
970 current_state_ = state;
971 }
972 return result;
973}
974
975// Protected Helper Methods
985
987 bool active_high = (active_state_ == hf_gpio_active_state_t::HF_GPIO_ACTIVE_HIGH);
988 bool should_be_high =
989 (state == hf_gpio_state_t::HF_GPIO_STATE_ACTIVE) ? active_high : !active_high;
991}
992
994 bool active_high = (active_state_ == hf_gpio_active_state_t::HF_GPIO_ACTIVE_HIGH);
995 bool is_high = (level == hf_gpio_level_t::HF_GPIO_LEVEL_HIGH);
996 return (is_high == active_high) ? hf_gpio_state_t::HF_GPIO_STATE_ACTIVE
998}
999
1000//==============================================================//
1001// STRING CONVERSION IMPLEMENTATIONS
1002//==============================================================//
1003
1004inline const char* BaseGpio::ToString(hf_gpio_state_t state) noexcept {
1005 switch (state) {
1007 return "Active";
1009 return "Inactive";
1010 default:
1011 return "Unknown";
1012 }
1013}
1014
1015inline const char* BaseGpio::ToString(hf_gpio_level_t level) noexcept {
1016 switch (level) {
1018 return "High";
1020 return "Low";
1021 default:
1022 return "Unknown";
1023 }
1024}
1025
1026inline const char* BaseGpio::ToString(hf_gpio_active_state_t active_state) noexcept {
1027 switch (active_state) {
1029 return "ActiveHigh";
1031 return "ActiveLow";
1032 default:
1033 return "Unknown";
1034 }
1035}
1036
1037inline const char* BaseGpio::ToString(hf_gpio_direction_t direction) noexcept {
1038 switch (direction) {
1040 return "Input";
1042 return "Output";
1043 default:
1044 return "Unknown";
1045 }
1046}
1047
1048inline const char* BaseGpio::ToString(hf_gpio_output_mode_t output_mode) noexcept {
1049 switch (output_mode) {
1051 return "PushPull";
1053 return "OpenDrain";
1054 default:
1055 return "Unknown";
1056 }
1057}
1058
1059inline const char* BaseGpio::ToString(hf_gpio_pull_mode_t pull_mode) noexcept {
1060 switch (pull_mode) {
1062 return "Floating";
1064 return "PullUp";
1066 return "PullDown";
1068 return "PullUpDown";
1069 default:
1070 return "Unknown";
1071 }
1072}
1073
1074inline const char* BaseGpio::ToString(hf_gpio_interrupt_trigger_t trigger) noexcept {
1075 switch (trigger) {
1077 return "None";
1079 return "RisingEdge";
1081 return "FallingEdge";
1083 return "BothEdges";
1085 return "LowLevel";
1087 return "HighLevel";
1088 default:
1089 return "Unknown";
1090 }
1091}
1092
1093//==============================================================//
1094// HARDWARE VERIFICATION IMPLEMENTATIONS
1095//==============================================================//
1096
1098 if (!initialized_) {
1100 }
1101
1102 // Read actual hardware direction
1103 hf_gpio_err_t result = GetDirectionImpl(direction);
1104 if (result != hf_gpio_err_t::GPIO_SUCCESS) {
1105 return result;
1106 }
1107
1108 // Compare with cached value for fault detection
1109 if (direction != current_direction_) {
1110 // Hardware mismatch detected - potential fault!
1112 }
1113
1115}
1116
1118 if (!initialized_) {
1120 }
1121
1122 // Read actual hardware output mode
1123 hf_gpio_err_t result = GetOutputModeImpl(mode);
1124 if (result != hf_gpio_err_t::GPIO_SUCCESS) {
1125 return result;
1126 }
1127
1128 // Compare with cached value for fault detection
1129 if (mode != output_mode_) {
1130 // Hardware mismatch detected - potential fault!
1132 }
1133
1135}
1136
1138 if (!initialized_) {
1140 }
1141
1142 // Verify direction
1143 hf_gpio_direction_t hw_direction;
1144 hf_gpio_err_t result = VerifyDirection(hw_direction);
1145 if (result != hf_gpio_err_t::GPIO_SUCCESS) {
1146 return result;
1147 }
1148
1149 // Verify output mode (only relevant for output pins)
1151 hf_gpio_output_mode_t hw_output_mode;
1152 result = VerifyOutputMode(hw_output_mode);
1153 if (result != hf_gpio_err_t::GPIO_SUCCESS) {
1154 return result;
1155 }
1156 }
1157
1158 // Verify pull mode
1159 hf_gpio_pull_mode_t hw_pull_mode = GetPullModeImpl();
1160 if (hw_pull_mode != pull_mode_) {
1162 }
1163
1165}
#define X(NAME, VALUE, DESC)
Definition BaseGpio.h:109
Platform-agnostic hardware type definitions for the HardFOC system.
uint32_t hf_u32_t
Platform-agnostic 32-bit unsigned integer type.
Definition HardwareTypes.h:52
uint8_t hf_u8_t
Platform-agnostic 8-bit unsigned integer type.
Definition HardwareTypes.h:40
hf_i32_t hf_pin_num_t
Platform-agnostic GPIO pin number type.
Definition HardwareTypes.h:99
Unified GPIO base class for all digital GPIO implementations.
Definition BaseGpio.h:294
hf_gpio_output_mode_t output_mode_
Output drive mode.
Definition BaseGpio.h:774
hf_gpio_state_t GetCurrentState() const noexcept
Get the current logical state of the pin.
Definition BaseGpio.h:877
virtual bool Deinitialize() noexcept
Deinitialize the GPIO pin.
Definition BaseGpio.h:716
void SetActiveState(hf_gpio_active_state_t active_state) noexcept
Set the active state polarity configuration.
Definition BaseGpio.h:900
BaseGpio(const BaseGpio &copy)=delete
Copy constructor is deleted to avoid copying instances.
hf_gpio_err_t ValidateBasicOperation() const noexcept
Validate basic parameters before GPIO operations.
Definition BaseGpio.h:976
hf_gpio_err_t VerifyOutputMode(hf_gpio_output_mode_t &mode) const noexcept
Verify current output mode setting by reading from hardware registers.
Definition BaseGpio.h:1117
static const char * ToString(hf_gpio_state_t state) noexcept
Definition BaseGpio.h:1004
virtual hf_gpio_err_t GetDirectionImpl(hf_gpio_direction_t &direction) const noexcept=0
Hardware read-back of current pin direction from registers.
bool IsInitialized() const noexcept
Check if the pin is initialized.
Definition BaseGpio.h:786
hf_gpio_err_t SetInactive() noexcept
Set the GPIO to inactive state.
Definition BaseGpio.h:920
bool EnsureDeinitialized() noexcept
Ensures the pin is deinitialized (lazy deinitialization).
Definition BaseGpio.h:797
hf_pin_num_t GetPin() const noexcept
Get the GPIO pin number/identifier.
Definition BaseGpio.h:805
bool IsInput() const noexcept
Check if the pin is currently configured as input.
Definition BaseGpio.h:833
hf_gpio_err_t VerifyDirection(hf_gpio_direction_t &direction) const noexcept
Verify current direction setting by reading from hardware registers.
Definition BaseGpio.h:1097
bool EnsureInitialized() noexcept
Ensures the pin is initialized (lazy initialization).
Definition BaseGpio.h:790
virtual const char * GetDescription() const noexcept=0
Get human-readable description of this GPIO instance.
virtual hf_gpio_err_t EnableInterrupt() noexcept
Enable GPIO interrupt.
Definition BaseGpio.h:609
virtual hf_gpio_err_t WaitForInterrupt(hf_u32_t timeout_ms=0) noexcept
Wait for GPIO interrupt to occur.
Definition BaseGpio.h:626
hf_gpio_active_state_t GetActiveState() const noexcept
Get the active state polarity configuration.
Definition BaseGpio.h:896
virtual hf_gpio_err_t ResetDiagnostics() noexcept
Reset GPIO diagnostic information.
Definition BaseGpio.h:666
hf_gpio_direction_t current_direction_
Current pin direction.
Definition BaseGpio.h:772
hf_gpio_pull_mode_t pull_mode_
Pull resistor configuration.
Definition BaseGpio.h:775
virtual hf_gpio_err_t GetOutputModeImpl(hf_gpio_output_mode_t &mode) const noexcept=0
Hardware read-back of current output mode from registers.
virtual hf_gpio_err_t GetDiagnostics(hf_gpio_diagnostics_t &diagnostics) const noexcept
Get GPIO diagnostic information.
Definition BaseGpio.h:686
hf_gpio_err_t SetDirection(hf_gpio_direction_t direction) noexcept
Set the pin direction (input or output).
Definition BaseGpio.h:814
virtual bool IsPinAvailable() const noexcept=0
Check if the pin is available for GPIO operations.
virtual hf_gpio_err_t SetPinLevelImpl(hf_gpio_level_t level) noexcept=0
Platform-specific implementation for setting pin electrical level.
hf_gpio_state_t current_state_
Current logical state.
Definition BaseGpio.h:776
hf_gpio_err_t SetPullMode(hf_gpio_pull_mode_t mode) noexcept
Set the pull resistor mode.
Definition BaseGpio.h:863
virtual bool Initialize() noexcept=0
Initialize the GPIO pin with current configuration.
hf_gpio_err_t Toggle() noexcept
Toggle the GPIO state.
Definition BaseGpio.h:935
hf_gpio_err_t IsActive(bool &is_active) noexcept
Check if the GPIO is currently active.
Definition BaseGpio.h:959
BaseGpio & operator=(const BaseGpio &copy)=delete
Assignment operator is deleted to avoid copying instances.
hf_gpio_err_t VerifyHardwareConfiguration() const noexcept
Perform comprehensive hardware verification of all pin settings.
Definition BaseGpio.h:1137
hf_gpio_diagnostics_t diagnostics_
GPIO diagnostic information.
Definition BaseGpio.h:778
virtual hf_gpio_err_t ClearInterruptStats() noexcept
Clear interrupt statistics.
Definition BaseGpio.h:643
virtual hf_gpio_err_t SetOutputModeImpl(hf_gpio_output_mode_t mode) noexcept=0
Platform-specific implementation for setting output mode.
virtual ~BaseGpio() noexcept=default
Virtual destructor for proper cleanup of derived classes.
virtual hf_gpio_err_t SupportsInterrupts() const noexcept
Check if this GPIO implementation supports interrupts.
Definition BaseGpio.h:588
hf_gpio_direction_t GetDirection() const noexcept
Get the current pin direction.
Definition BaseGpio.h:810
virtual hf_gpio_err_t GetPinLevelImpl(hf_gpio_level_t &level) noexcept=0
Platform-specific implementation for getting pin electrical level.
hf_gpio_err_t SetState(hf_gpio_state_t state) noexcept
Set the pin to a specific logical state.
Definition BaseGpio.h:881
hf_gpio_err_t SetActive() noexcept
Set the GPIO to active state.
Definition BaseGpio.h:905
hf_gpio_err_t SetOutputMode(hf_gpio_output_mode_t mode) noexcept
Set the output drive mode.
Definition BaseGpio.h:845
virtual hf_gpio_err_t ConfigureInterrupt(hf_gpio_interrupt_trigger_t trigger, InterruptCallback callback=nullptr, void *user_data=nullptr) noexcept
Configure GPIO interrupt settings.
Definition BaseGpio.h:599
hf_gpio_active_state_t active_state_
Active state polarity.
Definition BaseGpio.h:773
hf_gpio_pull_mode_t GetPullMode() const noexcept
Get the current pull resistor mode.
Definition BaseGpio.h:859
virtual hf_gpio_err_t GetInterruptStatus(InterruptStatus &status) noexcept
Get interrupt status information.
Definition BaseGpio.h:635
virtual hf_gpio_err_t DisableInterrupt() noexcept
Disable GPIO interrupt.
Definition BaseGpio.h:617
virtual hf_gpio_err_t ResetStatistics() noexcept
Reset GPIO operation statistics.
Definition BaseGpio.h:656
bool initialized_
Initialization state flag.
Definition BaseGpio.h:771
hf_gpio_statistics_t statistics_
GPIO operation statistics.
Definition BaseGpio.h:777
virtual hf_gpio_err_t SetDirectionImpl(hf_gpio_direction_t direction) noexcept=0
Platform-specific implementation for setting pin direction.
virtual hf_u8_t GetMaxPins() const noexcept=0
Get the maximum number of pins supported by this GPIO instance.
hf_gpio_level_t StateToLevel(hf_gpio_state_t state) const noexcept
Convert logical state to electrical level based on polarity.
Definition BaseGpio.h:986
const hf_pin_num_t pin_
GPIO pin number/identifier.
Definition BaseGpio.h:770
virtual hf_gpio_err_t SetPullModeImpl(hf_gpio_pull_mode_t mode) noexcept=0
Platform-specific implementation for setting pull resistor mode.
bool IsOutput() const noexcept
Check if the pin is currently configured as output.
Definition BaseGpio.h:837
virtual hf_gpio_pull_mode_t GetPullModeImpl() const noexcept=0
Hardware read-back of current pull resistor mode from registers.
hf_gpio_state_t LevelToState(hf_gpio_level_t level) const noexcept
Convert electrical level to logical state based on polarity.
Definition BaseGpio.h:993
virtual hf_gpio_err_t GetStatistics(hf_gpio_statistics_t &statistics) const noexcept
Get GPIO operation statistics.
Definition BaseGpio.h:676
hf_gpio_output_mode_t GetOutputMode() const noexcept
Get the output drive mode.
Definition BaseGpio.h:841
hf_gpio_level_t
GPIO pin electrical levels.
Definition BaseGpio.h:148
hf_gpio_err_t
HardFOC GPIO error codes.
Definition BaseGpio.h:108
hf_gpio_state_t
GPIO pin logical states.
Definition BaseGpio.h:138
hf_gpio_direction_t
GPIO pin direction/mode configuration.
Definition BaseGpio.h:168
hf_gpio_interrupt_trigger_t
GPIO interrupt trigger types.
Definition BaseGpio.h:200
hf_gpio_pull_mode_t
GPIO pull resistor configuration.
Definition BaseGpio.h:188
hf_gpio_output_mode_t
GPIO output drive modes.
Definition BaseGpio.h:178
void(*)(BaseGpio *gpio, hf_gpio_interrupt_trigger_t trigger, void *user_data) InterruptCallback
GPIO interrupt callback function type.
Definition BaseGpio.h:220
#define HF_GPIO_ERR_LIST(X)
HardFOC GPIO error codes macro list.
Definition BaseGpio.h:45
hf_gpio_active_state_t
GPIO active state polarity configuration.
Definition BaseGpio.h:158
constexpr std::string_view HfGpioErrToString(hf_gpio_err_t err) noexcept
Convert hf_gpio_err_t to human-readable string.
Definition BaseGpio.h:121
@ HF_GPIO_LEVEL_LOW
Electrical low level (0V)
@ HF_GPIO_LEVEL_HIGH
Electrical high level (VCC)
@ GPIO_ERR_UNSUPPORTED_OPERATION
@ GPIO_ERR_PIN_ACCESS_DENIED
@ GPIO_ERR_NOT_INITIALIZED
@ HF_GPIO_STATE_ACTIVE
Logical active state.
@ HF_GPIO_STATE_INACTIVE
Logical inactive state.
@ HF_GPIO_DIRECTION_INPUT
Pin configured as input.
@ HF_GPIO_DIRECTION_OUTPUT
Pin configured as output.
@ HF_GPIO_INTERRUPT_TRIGGER_BOTH_EDGES
Trigger on both rising and falling edges.
@ HF_GPIO_INTERRUPT_TRIGGER_RISING_EDGE
Trigger on rising edge (low to high)
@ HF_GPIO_INTERRUPT_TRIGGER_NONE
No interrupt (disabled)
@ HF_GPIO_INTERRUPT_TRIGGER_FALLING_EDGE
Trigger on falling edge (high to low)
@ HF_GPIO_INTERRUPT_TRIGGER_HIGH_LEVEL
Trigger on high level.
@ HF_GPIO_INTERRUPT_TRIGGER_LOW_LEVEL
Trigger on low level.
@ HF_GPIO_PULL_MODE_UP
Internal pull-up resistor enabled.
@ HF_GPIO_PULL_MODE_UP_DOWN
Both pull-up and pull-down resistors enabled.
@ HF_GPIO_PULL_MODE_DOWN
Internal pull-down resistor enabled.
@ HF_GPIO_PULL_MODE_FLOATING
No pull resistor (floating/high-impedance)
@ HF_GPIO_OUTPUT_MODE_PUSH_PULL
Push-pull output (strong high and low)
@ HF_GPIO_OUTPUT_MODE_OPEN_DRAIN
Open-drain output (strong low, high-impedance high)
@ HF_GPIO_ACTIVE_LOW
Active state is electrical low.
@ HF_GPIO_ACTIVE_HIGH
Active state is electrical high.
GPIO interrupt status structure.
Definition BaseGpio.h:227
bool is_enabled
Interrupt currently enabled.
Definition BaseGpio.h:228
bool has_callback
Callback function is registered.
Definition BaseGpio.h:231
hf_u32_t interrupt_count
Number of interrupts occurred.
Definition BaseGpio.h:230
hf_gpio_interrupt_trigger_t trigger_type
Current trigger configuration.
Definition BaseGpio.h:229
GPIO diagnostic information.
Definition BaseGpio.h:259
hf_gpio_err_t lastErrorCode
Last error code.
Definition BaseGpio.h:261
hf_gpio_diagnostics_t()
Definition BaseGpio.h:269
hf_u32_t consecutiveErrors
Consecutive error count.
Definition BaseGpio.h:263
bool gpioHealthy
Overall GPIO health status.
Definition BaseGpio.h:260
bool pinAvailable
Pin availability status.
Definition BaseGpio.h:264
bool interruptEnabled
Interrupt enabled status.
Definition BaseGpio.h:266
hf_u32_t currentState
Current pin state.
Definition BaseGpio.h:267
hf_u32_t lastErrorTimestamp
Last error timestamp.
Definition BaseGpio.h:262
bool interruptSupported
Interrupt support status.
Definition BaseGpio.h:265
GPIO operation statistics.
Definition BaseGpio.h:238
hf_gpio_statistics_t()
Definition BaseGpio.h:249
hf_u32_t stateChanges
Number of state changes.
Definition BaseGpio.h:242
hf_u32_t averageOperationTimeUs
Average operation time (microseconds)
Definition BaseGpio.h:245
hf_u32_t minOperationTimeUs
Minimum operation time.
Definition BaseGpio.h:247
hf_u32_t interruptCount
Number of interrupts received.
Definition BaseGpio.h:244
hf_u32_t totalOperations
Total GPIO operations performed.
Definition BaseGpio.h:239
hf_u32_t maxOperationTimeUs
Maximum operation time.
Definition BaseGpio.h:246
hf_u32_t directionChanges
Number of direction changes.
Definition BaseGpio.h:243
hf_u32_t successfulOperations
Successful operations.
Definition BaseGpio.h:240
hf_u32_t failedOperations
Failed operations.
Definition BaseGpio.h:241