Skip to content

Commit ca44a7d

Browse files
myst729jim-kirisame
authored andcommitted
支持不基于事件系统的阻塞式主动ADC采样
1 parent 21a95af commit ca44a7d

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

application/main/src/keyboard/adc_convert.c

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -163,3 +163,19 @@ void adc_init()
163163
err_code = app_timer_create(&adc_timer, APP_TIMER_MODE_REPEATED, adc_convert);
164164
APP_ERROR_CHECK(err_code);
165165
}
166+
167+
/**
168+
* @brief 阻塞式读取 ADC 值
169+
*
170+
* @param channel_index
171+
*/
172+
nrf_saadc_value_t adc_read_sync(uint8_t channel_index)
173+
{
174+
nrf_saadc_value_t result_sync = 0;
175+
ret_code_t err_code;
176+
177+
err_code = nrfx_saadc_sample_convert(channel_index, &result_sync);
178+
APP_ERROR_CHECK(err_code);
179+
180+
return result_sync;
181+
}

application/main/src/keyboard/adc_convert.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,5 @@ struct adc_channel_config {
3838
#define ADC_CONVERT_CHANNEL(conf) NRF_SECTION_ITEM_REGISTER(adc_channel, const struct adc_channel_config* _pt_##conf) = &conf
3939

4040
void adc_timer_start(void);
41-
void adc_init(void);
41+
void adc_init(void);
42+
nrf_saadc_value_t adc_read_sync(uint8_t channel_index);

0 commit comments

Comments
 (0)