X-Git-Url: https://git.gag.com/?p=fw%2Faltos;a=blobdiff_plain;f=src%2Fkernel%2Fao.h;h=edfbbb871de6416bdd0303bbe994b2215b39fd5d;hp=b3f780f5c7609797c15c895e90b0fa965dcf1a44;hb=70481772386d556b8a7981da38a03f5c9b181a7c;hpb=f495f2a479569d839f4efe8f115d51ae162edcfd diff --git a/src/kernel/ao.h b/src/kernel/ao.h index b3f780f5..edfbbb87 100644 --- a/src/kernel/ao.h +++ b/src/kernel/ao.h @@ -982,4 +982,26 @@ void ao_ms5607_init(void); #include +/* + * dv = (sensor * (p+m) * ref_dv)/ (max * m) + * value * (max * m) = (sensor * (p+m) * ref) + * value * (max * m) / ((p+m) * ref) = sensor + */ + +#define AO_DV_MUL(p,m) ((int32_t) AO_ADC_MAX * (m)) +#define AO_DV_DIV(p,m) ((int32_t) AO_ADC_REFERENCE_DV * ((p) + (m))) +#define AO_DV_ADD(p,m) (AO_DV_DIV(p,m) / 2) + +#define ao_decivolt_to_adc(dv, p, m) \ + ((int16_t) (((int32_t) (dv) * AO_DV_MUL(p,m) + AO_DV_ADD(p,m)) / AO_DV_DIV(p,m))) + +#define AO_IGNITER_CLOSED_DV 35 +#define AO_IGNITER_OPEN_DV 10 + +#undef AO_IGNITER_OPEN +#undef AO_IGNITER_CLOSED + +#define AO_IGNITER_OPEN ao_decivolt_to_adc(AO_IGNITER_OPEN_DV, AO_IGNITE_DIV_PLUS, AO_IGNITE_DIV_MINUS) +#define AO_IGNITER_CLOSED ao_decivolt_to_adc(AO_IGNITER_CLOSED_DV, AO_IGNITE_DIV_PLUS, AO_IGNITE_DIV_MINUS) + #endif /* _AO_H_ */