1818// #include <device/i2c_simple.h>
1919#include < Arduino.h>
2020#include < drivers/DigitalOut.h>
21+ #include < drivers/DigitalInOut.h>
2122// #include <gpio.h>
2223// #include <timer.h>
2324#include < string.h>
3334#define ANXDEBUG (format, ...) \
3435 printk (BIOS_DEBUG, " %s: " format, __func__, ##__VA_ARGS__)
3536
36- mbed::DigitalOut video_on(PK_2);
37- mbed::DigitalOut video_rst (PJ_3);
38- mbed::DigitalOut otg_on (PJ_6);
37+ mbed::DigitalOut video_on(PK_2, 0 );
38+ mbed::DigitalOut video_rst (PJ_3, 0 );
39+ mbed::DigitalInOut otg_on (PJ_6, PIN_INPUT, PullUp, 0 );
3940mbed::I2C i2cx (I2C_SDA_INTERNAL , I2C_SCL_INTERNAL);
4041
4142int i2c_writeb (uint8_t bus, uint8_t saddr, uint8_t offset, uint8_t val) {
@@ -1318,24 +1319,20 @@ int anx7625_init(uint8_t bus)
13181319 int retry_power_on = 3 ;
13191320
13201321 ANXINFO (" OTG_ON = 1 -> VBUS OFF\n " );
1321- otg_on = 1 ;
1322+ if (otg_on != 0 ) {
1323+ otg_on.output ();
1324+ otg_on = 1 ;
1325+ } else {
1326+ ANXERROR (" Cannot disable VBUS, someone is actively driving OTG_ON (PJ_6, USB_HS ID Pin)\n " );
1327+ }
1328+ mdelay (1000 ); // @TODO: wait for VBUS to discharge (VBUS is activated during bootloader, can be removed when fixed)
13221329
1323- mdelay ( 1000 );
1330+ ANXINFO ( " Powering on anx7625... \n " );
13241331 video_on = 1 ;
13251332 mdelay (10 );
13261333 video_rst = 1 ;
13271334 mdelay (10 );
13281335
1329- video_on = 0 ;
1330- mdelay (10 );
1331- video_rst = 0 ;
1332- mdelay (100 );
1333-
1334- ANXINFO (" Powering on anx7625...\n " );
1335- video_on = 1 ;
1336- mdelay (100 );
1337- video_rst = 1 ;
1338-
13391336 while (--retry_power_on) {
13401337 if (anx7625_power_on_init (bus) == 0 )
13411338 break ;
@@ -1349,7 +1346,7 @@ int anx7625_init(uint8_t bus)
13491346
13501347 if (anx7625_is_power_provider (0 )) {
13511348 ANXINFO (" OTG_ON = 0 -> VBUS ON\n " );
1352- otg_on = 0 ;
1349+ otg_on = 0 ; // If the pin is still input this has not effect
13531350 mdelay (1000 ); // Wait for powered device to be stable
13541351 }
13551352
@@ -1391,7 +1388,7 @@ int anx7625_get_cc_status(uint8_t bus, uint8_t *cc_status)
13911388 default :
13921389 ANXDEBUG (" anx: CC1: Reserved\n " );
13931390 }
1394- switch (*cc_status & 0xF0 ) {
1391+ switch (( *cc_status >> 4 ) & 0x0F ) {
13951392 case 0 :
13961393 ANXDEBUG (" anx: CC2: SRC.Open\n " ); break ;
13971394 case 1 :
0 commit comments