Skip to content

Commit

Permalink
支持不基于事件系统的阻塞式主动ADC采样
Browse files Browse the repository at this point in the history
  • Loading branch information
myst729 committed Nov 23, 2023
1 parent 21a95af commit 2feef91
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
16 changes: 16 additions & 0 deletions application/main/src/keyboard/adc_convert.c
Original file line number Diff line number Diff line change
Expand Up @@ -163,3 +163,19 @@ void adc_init()
err_code = app_timer_create(&adc_timer, APP_TIMER_MODE_REPEATED, adc_convert);
APP_ERROR_CHECK(err_code);
}

/**
* @brief 阻塞式读取 ADC 值
*
* @param channel_index
*/
nrf_saadc_value_t adc_read_sync(uint8_t channel_index)
{
nrf_saadc_value_t result_sync = 0;
ret_code_t err_code;

err_code = nrfx_saadc_sample_convert(channel_index, &result_sync);
APP_ERROR_CHECK(err_code);

return result_sync;
}
3 changes: 2 additions & 1 deletion application/main/src/keyboard/adc_convert.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,4 +38,5 @@ struct adc_channel_config {
#define ADC_CONVERT_CHANNEL(conf) NRF_SECTION_ITEM_REGISTER(adc_channel, const struct adc_channel_config* _pt_##conf) = &conf

void adc_timer_start(void);
void adc_init(void);
void adc_init(void);
nrf_saadc_value_t adc_read_sync(uint8_t channel_index);

0 comments on commit 2feef91

Please sign in to comment.