|
HardFOC Core
API reference
|
Thread-safe BaseAdc handler for one ADS9324 on a SPI bus.
More...
#include <Ads9324Handler.h>
Public Member Functions | |
| Ads9324Handler (BaseSpi &spi, BaseGpio *convst, BaseGpio *drdy=nullptr, const Ads9324HandlerConfig &config=GetDefaultAds9324Config()) noexcept | |
| Construct handler (lazy — no SPI). | |
| ~Ads9324Handler () noexcept override=default | |
| Releases driver/adapter unique_ptrs. | |
| Ads9324Handler (const Ads9324Handler &)=delete | |
| Ads9324Handler & | operator= (const Ads9324Handler &)=delete |
| Ads9324Handler (Ads9324Handler &&)=delete | |
| Ads9324Handler & | operator= (Ads9324Handler &&)=delete |
| bool | Initialize () noexcept override |
| Create adapter + driver, 1-lane SDOUT bring-up, DEVICE_ID, default PGA. | |
| bool | Deinitialize () noexcept override |
| Destroy driver and adapter; leave GPIOs as-is. | |
| hf_u8_t | GetMaxChannels () const noexcept override |
Channel count for BaseAdc. | |
| bool | IsChannelAvailable (hf_channel_id_t channel) const noexcept override |
Whether channel is in [0, 15] (API 0 = AIN1). | |
| hf_adc_err_t | ReadChannelV (hf_channel_id_t channel, float &voltage, hf_u8_t samples=1, hf_time_t timeout_ms=0) noexcept override |
| Read voltage (averaged). Internally a full simultaneous snapshot per sample. | |
| hf_adc_err_t | ReadChannelCount (hf_channel_id_t channel, hf_u32_t &count, hf_u8_t samples=1, hf_time_t timeout_ms=0) noexcept override |
| Read raw count (averaged). See ReadChannel for signed-code caveat. | |
| hf_adc_err_t | ReadChannel (hf_channel_id_t channel, hf_u32_t &count, float &voltage, hf_u8_t samples=1, hf_time_t timeout_ms=0) noexcept override |
| Read count and voltage (averaged). | |
| hf_adc_err_t | ReadMultipleChannels (const hf_channel_id_t *channels, hf_u8_t num_channels, hf_u32_t *counts, float *voltages) noexcept override |
| One snapshot, then index the requested channels. | |
| bool | ConfigureChannel (uint8_t channel, const ads9324::ChannelConfig &cfg) noexcept |
| Program one channel PGA (mutex-protected). | |
| bool | SetChannelOffset (uint8_t channel, int16_t ofs_10bit) noexcept |
| Program OFS_AINx (10-bit two's-complement). | |
| bool | SetChannelGain (uint8_t channel, int16_t gan_14bit) noexcept |
| Program GAN_AINx (14-bit two's complement). Correction = GAN / 65536. | |
| bool | ReadSnapshot (ads9324::Snapshot &snap) noexcept |
| Simultaneous capture of all enabled channels. | |
| ads9324::ADS9324< Ads9324SpiHostAdapter, Ads9324SpiHostAdapter > * | GetDriver () noexcept |
| Raw driver pointer. | |
| const ads9324::ADS9324< Ads9324SpiHostAdapter, Ads9324SpiHostAdapter > * | GetDriver () const noexcept |
| Raw driver pointer. | |
| template<typename Fn > | |
| auto | visitDriver (Fn &&fn) noexcept -> decltype(fn(std::declval< ads9324::ADS9324< Ads9324SpiHostAdapter, Ads9324SpiHostAdapter > & >())) |
Invoke fn with the driver while holding the handler mutex. | |
| const char * | GetDescription () const noexcept |
Human-readable instance tag (ADS9324_Handler_SPI_DevN). | |
| bool | GetHandlerDiagnostics (Ads9324Diagnostics &diag) const noexcept |
| Copy diagnostics under the handler mutex. | |
| void | DumpDiagnostics () const noexcept |
| Log CONVST/DRDY presence, DEVICE_ID, and read/error counts. | |
| uint8_t | GetDeviceIndex () const noexcept |
| Logical device index from config. | |
Private Member Functions | |
| bool | EnsureInitializedLocked () noexcept |
| Initialize if needed while handler_mutex_ is already held. | |
Private Attributes | |
| BaseSpi & | spi_ref_ |
| SPI device. | |
| BaseGpio * | convst_ |
| Required CONVST. | |
| BaseGpio * | drdy_ |
| Optional DRDY. | |
| std::unique_ptr< Ads9324SpiHostAdapter > | adapter_ |
| CRTP bridge. | |
| std::unique_ptr< ads9324::ADS9324< Ads9324SpiHostAdapter, Ads9324SpiHostAdapter > > | adc_driver_ |
| Ads9324HandlerConfig | config_ |
| Init defaults. | |
| RtosMutex | handler_mutex_ |
| Serializes all driver access except GetDriver(). | |
| char | description_ [64] {} |
| GetDescription buffer. | |
| uint32_t | total_reads_ {0} |
| Successful operations. | |
| uint32_t | error_count_ {0} |
| Failures. | |
| uint16_t | device_id_ {0} |
| Cached DEVICE_ID. | |
Thread-safe BaseAdc handler for one ADS9324 on a SPI bus.
CONVST is required for conversion. DRDY may be nullptr (timed fallback). Construction is lightweight; SPI and GPIO traffic start in Initialize.
|
noexcept |
Construct handler (lazy — no SPI).
| spi | SPI device with the ADS9324 CS. |
| convst | CONVST GPIO; must be non-null at Initialize. |
| drdy | Optional DRDY; nullptr uses timed wait after CONVST. |
| config | Default PGA, data format, device index. |
|
overridedefaultnoexcept |
Releases driver/adapter unique_ptrs.
|
delete |
|
delete |
|
noexcept |
Program one channel PGA (mutex-protected).
| channel | 0–15. |
| cfg | Input type, range, bandwidth, CME. |
|
overridenoexcept |
Destroy driver and adapter; leave GPIOs as-is.
|
noexcept |
Log CONVST/DRDY presence, DEVICE_ID, and read/error counts.
|
privatenoexcept |
Initialize if needed while handler_mutex_ is already held.
| false | Driver still unavailable. |
|
noexcept |
Human-readable instance tag (ADS9324_Handler_SPI_DevN).
|
inlinenoexcept |
Logical device index from config.
|
noexcept |
Raw driver pointer.
|
noexcept |
Raw driver pointer.
|
noexcept |
Copy diagnostics under the handler mutex.
| [out] | diag | Filled snapshot. |
|
overridenoexcept |
Channel count for BaseAdc.
|
overridenoexcept |
Create adapter + driver, 1-lane SDOUT bring-up, DEVICE_ID, default PGA.
| true | Device ready. |
| false | CONVST missing, EnsureInitialized failed, or PGA write failed. |
|
overridenoexcept |
Whether channel is in [0, 15] (API 0 = AIN1).
| channel | 0-based channel id. |
|
delete |
|
delete |
|
overridenoexcept |
Read count and voltage (averaged).
Each sample calls ads9324::ADS9324::ReadChannel, which itself runs a full 16-channel snapshot. Prefer ReadSnapshot or ReadMultipleChannels when several channels are needed.
| channel | 0–15. | |
| [out] | count | Mean of signed codes cast through uint16_t (two's complement bit pattern, not a magnitude). |
| [out] | voltage | Mean voltage. |
| samples | Average count. | |
| timeout_ms | Unused. |
|
overridenoexcept |
Read raw count (averaged). See ReadChannel for signed-code caveat.
| channel | 0–15. | |
| [out] | count | Averaged count stored as uint16_t inside hf_u32_t. |
| samples | Average count. | |
| timeout_ms | Unused. |
|
overridenoexcept |
Read voltage (averaged). Internally a full simultaneous snapshot per sample.
| channel | 0–15. | |
| [out] | voltage | Averaged voltage. |
| samples | Average count (0 treated as 1). | |
| timeout_ms | Unused (kept for BaseAdc signature). |
ADC_SUCCESS or a hf_adc_err_t failure.
|
overridenoexcept |
One snapshot, then index the requested channels.
| channels | Array of channel ids. | |
| num_channels | Length of channels. | |
| [out] | counts | Optional per-channel counts (may be nullptr). |
| [out] | voltages | Optional per-channel voltages (may be nullptr). |
|
noexcept |
Simultaneous capture of all enabled channels.
| [out] | snap | Driver snapshot (valid_mask + counts + voltages). |
snap reports ok().
|
noexcept |
Program GAN_AINx (14-bit two's complement). Correction = GAN / 65536.
| channel | 0–15. |
| gan_14bit | Signed gain, ads9324::kGainMin (−8192) to kGainMax (+8191); pass the signed value, not the raw 14-bit pattern. |
|
noexcept |
Program OFS_AINx (10-bit two's-complement).
| channel | 0–15. |
| ofs_10bit | Offset, ads9324::kOffsetMin (−512) to kOffsetMax (+511). |
|
inlinenoexcept |
Invoke fn with the driver while holding the handler mutex.
| Fn | Callable accepting ADS9324<Ads9324SpiHostAdapter, Ads9324SpiHostAdapter>&. |
| fn | Visitor (window comparator, power-down, channel-count, …). |
|
private |
CRTP bridge.
|
private |
|
private |
Init defaults.
|
private |
Required CONVST.
|
private |
GetDescription buffer.
|
private |
Cached DEVICE_ID.
|
private |
Optional DRDY.
|
mutableprivate |
Failures.
|
mutableprivate |
Serializes all driver access except GetDriver().
|
private |
SPI device.
|
mutableprivate |
Successful operations.