52#define CS_ADC_NUM_SAADC_BUFFERS 2
Analog-Digital conversion.
Definition: cs_ADC.h:84
adc_state_t _state
Definition: cs_ADC.h:241
void enterCriticalRegion()
Enter a region of code where variables are used that are also used in SAADC interrupts.
cs_ret_code_t _addBufferToSaadcQueue(adc_buffer_id_t bufIndex)
Same as addBufferToSaadcQueue(), but without critical region enter/exit.
nrf_saadc_event_t _eventLimitHigh
Cache limit event.
Definition: cs_ADC.h:281
void enableZeroCrossingInterrupt(adc_channel_id_t channel, int32_t zeroVal)
Enable zero crossing detection on given channel, generating interrupts.
bool _firstBuffer
Definition: cs_ADC.h:238
adc_channel_id_t _zeroCrossingChannel
The channel which is checked for zero crossings.
Definition: cs_ADC.h:267
bool _changeConfig
Whether or not the config should be changed.
Definition: cs_ADC.h:183
cs_ret_code_t initSaadc()
void _handleAdcLimitInterrupt(nrf_saadc_limit_t type)
Called when the sampled value is above upper limit, or below lower limit.
cs_ret_code_t initChannel(adc_channel_id_t channel, adc_channel_config_t &config)
Configure a channel.
static nrf_ppi_channel_t getPpiChannel(uint8_t index)
cs_ret_code_t init(const adc_config_t &config)
Initialize ADC.
void exitCriticalRegion()
Exit a region of code where variables are used that are also used in SAADC interrupts.
void setZeroCrossingCallback(adc_zero_crossing_cb_t callback)
Set the callback which is called on a zero crossing interrupt.
cs_ret_code_t fillSaadcQueue()
Try to add all queued buffers to the SAADC queue.
CircularBuffer< adc_buffer_id_t > _bufferQueue
Queue of buffers that are free to be added to the SAADC queue.
Definition: cs_ADC.h:226
static nrf_saadc_event_t getLimitHighEvent(adc_channel_id_t channel)
CircularBuffer< adc_buffer_id_t > _saadcBufferQueue
Keeps up which buffers that are queued in the SAADC peripheral.
Definition: cs_ADC.h:235
void start()
Start the ADC sampling.
void setDoneCallback(adc_done_cb_t callback)
Set the callback which is called when a buffer is filled.
void handleEvent(event_t &event)
Handle events.
adc_done_cb_t _doneCallback
Definition: cs_ADC.h:251
bool _zeroCrossingEnabled
Keep up whether zero crossing is enabled.
Definition: cs_ADC.h:288
uint32_t _lastZeroCrossUpTime
Store the RTC timestamp of the last upwards zero crossing.
Definition: cs_ADC.h:295
static ADC & getInstance()
Use static variant of singleton, no dynamic memory allocation.
Definition: cs_ADC.h:88
adc_zero_crossing_cb_t _zeroCrossingCallback
The zero crossing callback.
Definition: cs_ADC.h:260
int _criticalRegionEntered
Keep up number of nested critical regions entered.
Definition: cs_ADC.h:307
static nrf_saadc_event_t getLimitLowEvent(adc_channel_id_t channel)
void operator=(ADC const &)
static nrf_saadc_input_t getAdcPin(adc_pin_id_t pinNum)
void _handleAdcInterrupt()
Handles the ADC interrupt.
nrf_saadc_event_t _eventLimitLow
Cache limit event.
Definition: cs_ADC.h:274
cs_ret_code_t addBufferToSaadcQueue(adc_buffer_id_t bufIndex)
Puts a buffer in the SAADC queue.
int32_t _zeroValue
Store the zero value used to detect zero crossings.
Definition: cs_ADC.h:302
cs_ret_code_t changeChannel(adc_channel_id_t channel, adc_channel_config_t &config)
Change channel config.
void _handleAdcDone(adc_buffer_id_t bufIndex)
Handle buffer, called in main thread.
cs_ret_code_t _fillSaadcQueue(bool fromInterrupt)
Same as fillSaadcQueue(), but without critical region enter/exit.
adc_config_t _config
Configuration of this class.
Definition: cs_ADC.h:190
volatile adc_saadc_state_t _saadcState
Sate of the SAADC peripheral.
Definition: cs_ADC.h:248
nrf_ppi_channel_t _ppiChannelStart
PPI channel used to start the SAADC on end event.
Definition: cs_ADC.h:219
adc_buffer_seq_nr_t _bufSeqNr
Buffer sequence number.
Definition: cs_ADC.h:204
bool dataCallbackRegistered()
Definition: cs_ADC.h:253
cs_ret_code_t initBufferQueue()
nrf_ppi_channel_t _ppiChannelSample
PPI channel to sample each tick, and count these.
Definition: cs_ADC.h:212
adc_channel_config_result_t _channelResultConfigs[CS_ADC_NUM_CHANNELS]
Resulting configuration of this class.
Definition: cs_ADC.h:197
static nrf_gpiote_tasks_t getGpioteTaskOut(uint8_t index)
void stop()
Stop the ADC sampling Only to be called from main thread.
Circular Buffer implementation.
Definition: cs_CircularBuffer.h:27
Event listener.
Definition: cs_EventListener.h:17
Author: Crownstone Team Copyright: Crownstone (https://crownstone.rocks) Date: Oct 9,...
Definition: cs_Event.h:26
void(* adc_zero_crossing_cb_t)()
Definition: cs_ADC.h:33
adc_gain_t
Definition: cs_ADC.h:15
@ CS_ADC_GAIN1_2
Definition: cs_ADC.h:19
@ CS_ADC_GAIN2
Definition: cs_ADC.h:17
@ CS_ADC_GAIN1
Definition: cs_ADC.h:18
@ CS_ADC_GAIN1_3
Definition: cs_ADC.h:20
@ CS_ADC_GAIN1_4
Definition: cs_ADC.h:21
@ CS_ADC_GAIN1_5
Definition: cs_ADC.h:22
@ CS_ADC_GAIN4
Definition: cs_ADC.h:16
@ CS_ADC_GAIN1_6
Definition: cs_ADC.h:23
adc_state_t
Definition: cs_ADC.h:36
@ ADC_STATE_READY_TO_START
Definition: cs_ADC.h:40
@ ADC_STATE_IDLE
Definition: cs_ADC.h:37
@ ADC_STATE_BUSY
Definition: cs_ADC.h:38
@ ADC_STATE_WAITING_TO_START
Definition: cs_ADC.h:39
adc_saadc_state_t
Definition: cs_ADC.h:45
@ ADC_SAADC_STATE_STOPPING
Definition: cs_ADC.h:48
@ ADC_SAADC_STATE_IDLE
Definition: cs_ADC.h:46
@ ADC_SAADC_STATE_BUSY
Definition: cs_ADC.h:47
void(* adc_done_cb_t)(adc_buffer_id_t bufIndex)
The typedef adc_done_cb_t is a function pointer to a function with the buffer index as argument.
Definition: cs_ADC.h:31
#define CS_ADC_NUM_CHANNELS
Definition: cs_Config.h:147
uint8_t adc_buffer_seq_nr_t
Definition: cs_Typedefs.h:35
uint8_t adc_pin_id_t
Definition: cs_Typedefs.h:32
uint8_t adc_buffer_id_t
Definition: cs_Typedefs.h:30
uint16_t cs_ret_code_t
Definition: cs_Typedefs.h:21
uint8_t adc_channel_id_t
Definition: cs_Typedefs.h:31
Result struct after configuring an ADC channel.
Definition: cs_PacketsInternal.h:333
Struct to configure an ADC channel.
Definition: cs_PacketsInternal.h:293
Struct to configure the ADC.
Definition: cs_PacketsInternal.h:306