forked from Archive/PX4-Autopilot
stm32_common:board_hw_rev_ver Use Analog resistor detection
When the VER_DRIVE and REV_DRIVE are the same GPIO we need to use Analog detection.
This commit is contained in:
parent
b87dd317d4
commit
1e7dfe227a
|
@ -151,6 +151,7 @@ static int read_id_dn(int *id, uint32_t gpio_drive, uint32_t gpio_sense, int adc
|
||||||
{
|
{
|
||||||
int rv = -EIO;
|
int rv = -EIO;
|
||||||
const unsigned int samples = 16;
|
const unsigned int samples = 16;
|
||||||
|
#if GPIO_HW_REV_DRIVE != GPIO_HW_VER_DRIVE
|
||||||
/*
|
/*
|
||||||
* Step one is there resistors?
|
* Step one is there resistors?
|
||||||
*
|
*
|
||||||
|
@ -206,7 +207,6 @@ static int read_id_dn(int *id, uint32_t gpio_drive, uint32_t gpio_sense, int adc
|
||||||
|
|
||||||
if ((high ^ low) && low == 0) {
|
if ((high ^ low) && low == 0) {
|
||||||
|
|
||||||
|
|
||||||
/* Yes - Fire up the ADC (it has once control) */
|
/* Yes - Fire up the ADC (it has once control) */
|
||||||
|
|
||||||
if (px4_arch_adc_init(HW_REV_VER_ADC_BASE) == OK) {
|
if (px4_arch_adc_init(HW_REV_VER_ADC_BASE) == OK) {
|
||||||
|
@ -235,13 +235,103 @@ static int read_id_dn(int *id, uint32_t gpio_drive, uint32_t gpio_sense, int adc
|
||||||
rv = OK;
|
rv = OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#else /* GPIO_HW_REV_DRIVE == GPIO_HW_VER_DRIVE */
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Step one is there resistors?
|
||||||
|
*
|
||||||
|
* With the common REV/VER Drive we have to look at the ADC values.
|
||||||
|
* to determine if the R's are hooked up. This is because the
|
||||||
|
* the REV and VER pairs will influence each other and not make
|
||||||
|
* digital thresholds.
|
||||||
|
*
|
||||||
|
* I.E
|
||||||
|
*
|
||||||
|
* VDD
|
||||||
|
* 442K
|
||||||
|
* REV is a Float
|
||||||
|
* 24.9K
|
||||||
|
* Drive as input
|
||||||
|
* 442K
|
||||||
|
* VER is 0.
|
||||||
|
* 24.9K
|
||||||
|
* VDD
|
||||||
|
*
|
||||||
|
* This is 466K up and 442K down.
|
||||||
|
*
|
||||||
|
* Driving VER Low and reading DRIVE will result in approximately mid point
|
||||||
|
* values not a digital Low.
|
||||||
|
*/
|
||||||
|
|
||||||
|
uint32_t dn_sum = 0;
|
||||||
|
uint16_t dn = 0;
|
||||||
|
uint16_t high = 0;
|
||||||
|
uint16_t low = 0;
|
||||||
|
|
||||||
|
/* Turn the drive lines to digital outputs High */
|
||||||
|
|
||||||
|
stm32_configgpio(gpio_drive);
|
||||||
|
|
||||||
|
up_udelay(100); /* About 10 TC assuming 485 K */
|
||||||
|
|
||||||
|
for (unsigned av = 0; av < samples; av++) {
|
||||||
|
if (px4_arch_adc_init(HW_REV_VER_ADC_BASE) == OK) {
|
||||||
|
dn = px4_arch_adc_sample(HW_REV_VER_ADC_BASE, adc_channel);
|
||||||
|
|
||||||
|
if (dn == 0xffff) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
dn_sum += dn;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (dn != 0xffff) {
|
||||||
|
high = dn_sum / samples;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Turn the drive lines to digital outputs LOW */
|
||||||
|
|
||||||
|
stm32_configgpio(gpio_drive ^ GPIO_OUTPUT_SET);
|
||||||
|
|
||||||
|
up_udelay(100); /* About 10 TC assuming 485 K */
|
||||||
|
|
||||||
|
dn_sum = 0;
|
||||||
|
|
||||||
|
for (unsigned av = 0; av < samples; av++) {
|
||||||
|
|
||||||
|
dn = px4_arch_adc_sample(HW_REV_VER_ADC_BASE, adc_channel);
|
||||||
|
|
||||||
|
if (dn == 0xffff) {
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
dn_sum += dn;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (dn != 0xffff) {
|
||||||
|
low = dn_sum / samples;
|
||||||
|
}
|
||||||
|
|
||||||
|
if ((high > low) && high > px4_arch_adc_dn_fullcount() - 100) {
|
||||||
|
|
||||||
|
*id = low;
|
||||||
|
rv = OK;
|
||||||
|
|
||||||
|
} else {
|
||||||
|
/* No - No Resistors is ID 0 */
|
||||||
|
*id = 0;
|
||||||
|
rv = OK;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif /* GPIO_HW_REV_DRIVE != GPIO_HW_VER_DRIVE */
|
||||||
|
|
||||||
/* Turn the drive lines to digital outputs High */
|
/* Turn the drive lines to digital outputs High */
|
||||||
|
|
||||||
stm32_configgpio(gpio_drive);
|
stm32_configgpio(gpio_drive);
|
||||||
return rv;
|
return rv;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static int determine_hw_info(int *revision, int *version)
|
static int determine_hw_info(int *revision, int *version)
|
||||||
{
|
{
|
||||||
int dn;
|
int dn;
|
||||||
|
|
Loading…
Reference in New Issue