firmware: improve platform detection

Slow down the detection of pull-up and pull-down resistors to make
detection more reliable.
This commit is contained in:
Michael Ossmann
2022-09-26 16:44:38 -04:00
parent b026c07000
commit f3d10dcc62
2 changed files with 15 additions and 9 deletions

View File

@ -253,6 +253,7 @@ typedef enum {
} clock_source_t; } clock_source_t;
void delay(uint32_t duration); void delay(uint32_t duration);
void delay_us_at_mhz(uint32_t us, uint32_t mhz);
/* TODO: Hide these configurations */ /* TODO: Hide these configurations */
extern si5351c_driver_t clock_gen; extern si5351c_driver_t clock_gen;

View File

@ -120,24 +120,29 @@ void detect_hardware_platform(void)
gpio_input(&gpio2_9_on_P5_0); gpio_input(&gpio2_9_on_P5_0);
gpio_input(&gpio3_6_on_P6_10); gpio_input(&gpio3_6_on_P6_10);
scu_pinmux(P5_0, SCU_GPIO_PUP | SCU_CONF_FUNCTION0); /* activate internal pull-down */
scu_pinmux(P6_10, SCU_GPIO_PUP | SCU_CONF_FUNCTION0);
delay(20);
scu_pinmux(P5_0, SCU_GPIO_PDN | SCU_CONF_FUNCTION0); scu_pinmux(P5_0, SCU_GPIO_PDN | SCU_CONF_FUNCTION0);
scu_pinmux(P6_10, SCU_GPIO_PDN | SCU_CONF_FUNCTION0); scu_pinmux(P6_10, SCU_GPIO_PDN | SCU_CONF_FUNCTION0);
delay(20); delay_us_at_mhz(4, 96);
/* tri-state for a moment before testing input */
scu_pinmux(P5_0, SCU_GPIO_NOPULL | SCU_CONF_FUNCTION0);
scu_pinmux(P6_10, SCU_GPIO_NOPULL | SCU_CONF_FUNCTION0);
delay_us_at_mhz(4, 96);
/* if input rose quickly, there must be an external pull-up */
detected_resistors |= (gpio_read(&gpio2_9_on_P5_0)) ? P5_0_PUP : 0; detected_resistors |= (gpio_read(&gpio2_9_on_P5_0)) ? P5_0_PUP : 0;
detected_resistors |= (gpio_read(&gpio3_6_on_P6_10)) ? P6_10_PUP : 0; detected_resistors |= (gpio_read(&gpio3_6_on_P6_10)) ? P6_10_PUP : 0;
/* activate internal pull-up */
scu_pinmux(P5_0, SCU_GPIO_PUP | SCU_CONF_FUNCTION0); scu_pinmux(P5_0, SCU_GPIO_PUP | SCU_CONF_FUNCTION0);
scu_pinmux(P6_10, SCU_GPIO_PUP | SCU_CONF_FUNCTION0); scu_pinmux(P6_10, SCU_GPIO_PUP | SCU_CONF_FUNCTION0);
delay(20); delay_us_at_mhz(4, 96);
detected_resistors |= (gpio_read(&gpio2_9_on_P5_0)) ? 0 : P5_0_PDN; /* tri-state for a moment before testing input */
detected_resistors |= (gpio_read(&gpio3_6_on_P6_10)) ? 0 : P6_10_PDN;
scu_pinmux(P5_0, SCU_GPIO_NOPULL | SCU_CONF_FUNCTION0); scu_pinmux(P5_0, SCU_GPIO_NOPULL | SCU_CONF_FUNCTION0);
scu_pinmux(P6_10, SCU_GPIO_NOPULL | SCU_CONF_FUNCTION0); scu_pinmux(P6_10, SCU_GPIO_NOPULL | SCU_CONF_FUNCTION0);
delay_us_at_mhz(4, 96);
/* if input fell quickly, there must be an external pull-down */
detected_resistors |= (gpio_read(&gpio2_9_on_P5_0)) ? 0 : P5_0_PDN;
detected_resistors |= (gpio_read(&gpio3_6_on_P6_10)) ? 0 : P6_10_PDN;
switch (detected_resistors) { switch (detected_resistors) {
case JAWBREAKER_RESISTORS: case JAWBREAKER_RESISTORS: