Изменения на новый
This commit is contained in:
parent
58589a5d2a
commit
6af74838db
|
|
@ -14,8 +14,12 @@ typedef struct {
|
||||||
uint8_t ADC_Channel;
|
uint8_t ADC_Channel;
|
||||||
|
|
||||||
int32_t offset;
|
int32_t offset;
|
||||||
int32_t mux;
|
double mux;
|
||||||
int32_t div;
|
double div;
|
||||||
|
|
||||||
|
#ifdef ACCESS_ADC
|
||||||
|
osMutexId_t access;
|
||||||
|
#endif
|
||||||
|
|
||||||
} tAdcArtery;
|
} tAdcArtery;
|
||||||
|
|
||||||
|
|
@ -23,8 +27,8 @@ tAdcArtery ADC_Initial(
|
||||||
adc_type *ADCx,
|
adc_type *ADCx,
|
||||||
adc_channel_select_type ADC_Channel,
|
adc_channel_select_type ADC_Channel,
|
||||||
int32_t offset,
|
int32_t offset,
|
||||||
int32_t mux,
|
double mux,
|
||||||
int32_t div
|
double div
|
||||||
);
|
);
|
||||||
|
|
||||||
tAdcIO vAdcGetIo(tAdcArtery *env);
|
tAdcIO vAdcGetIo(tAdcArtery *env);
|
||||||
|
|
|
||||||
|
|
@ -8,8 +8,8 @@ tAdcArtery ADC_Initial(
|
||||||
adc_type *ADCx,
|
adc_type *ADCx,
|
||||||
adc_channel_select_type ADC_Channel,
|
adc_channel_select_type ADC_Channel,
|
||||||
int32_t offset,
|
int32_t offset,
|
||||||
int32_t mux,
|
double mux,
|
||||||
int32_t div
|
double div
|
||||||
) {
|
) {
|
||||||
|
|
||||||
adc_common_config_type adc_common_struct;
|
adc_common_config_type adc_common_struct;
|
||||||
|
|
@ -78,6 +78,18 @@ tAdcArtery ADC_Initial(
|
||||||
adc_calibration_start(ADCx);
|
adc_calibration_start(ADCx);
|
||||||
while (adc_calibration_status_get(ADCx));
|
while (adc_calibration_status_get(ADCx));
|
||||||
|
|
||||||
|
#ifdef ACCESS_ADC
|
||||||
|
|
||||||
|
tAdcArtery adc = {
|
||||||
|
.ADCx = ADCx,
|
||||||
|
.ADC_Channel = ADC_Channel,
|
||||||
|
.offset = offset,
|
||||||
|
.div = div,
|
||||||
|
.mux = mux,
|
||||||
|
.access = osMutexNew(NULL)
|
||||||
|
};
|
||||||
|
|
||||||
|
#else
|
||||||
|
|
||||||
tAdcArtery adc = {
|
tAdcArtery adc = {
|
||||||
.ADCx = ADCx,
|
.ADCx = ADCx,
|
||||||
|
|
@ -87,10 +99,44 @@ tAdcArtery ADC_Initial(
|
||||||
.mux = mux
|
.mux = mux
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#endif
|
||||||
|
|
||||||
return adc;
|
return adc;
|
||||||
}
|
}
|
||||||
|
|
||||||
static uint16_t vAdcGet(tAdcArtery *env, uint32_t timeout) {
|
static uint16_t vAdcGet(tAdcArtery *env, uint32_t timeout) {
|
||||||
|
|
||||||
|
#ifdef ACCESS_ADC
|
||||||
|
|
||||||
|
if (osMutexAcquire(env->access, 1200) == osOK) {
|
||||||
|
|
||||||
|
uint32_t endMs = SystemGetMs() + timeout;
|
||||||
|
uint16_t data;
|
||||||
|
|
||||||
|
adc_ordinary_software_trigger_enable(env->ADCx, TRUE);
|
||||||
|
|
||||||
|
while (adc_flag_get(env->ADCx, ADC_OCCE_FLAG) == RESET) {
|
||||||
|
if (SystemGetMs() > endMs) {
|
||||||
|
//todo error
|
||||||
|
osMutexRelease(env->access);
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
data = adc_ordinary_conversion_data_get(env->ADCx);
|
||||||
|
|
||||||
|
adc_flag_clear(env->ADCx, ADC_OCCO_FLAG);
|
||||||
|
|
||||||
|
int64_t projected = (int64_t) ((double )(data + env->offset) * env->mux / env->div);
|
||||||
|
|
||||||
|
osMutexRelease(env->access);
|
||||||
|
|
||||||
|
return projected;
|
||||||
|
} else {
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
#else
|
||||||
uint32_t endMs = SystemGetMs() + timeout;
|
uint32_t endMs = SystemGetMs() + timeout;
|
||||||
uint16_t data;
|
uint16_t data;
|
||||||
|
|
||||||
|
|
@ -109,6 +155,7 @@ static uint16_t vAdcGet(tAdcArtery *env, uint32_t timeout) {
|
||||||
|
|
||||||
int64_t projected = ((data + env->offset) * env->mux / env->div);
|
int64_t projected = ((data + env->offset) * env->mux / env->div);
|
||||||
return projected;
|
return projected;
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
tAdcIO vAdcGetIo(tAdcArtery *env) {
|
tAdcIO vAdcGetIo(tAdcArtery *env) {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue