tusb322.cpp 1000 B

1234567891011121314151617181920212223242526272829303132333435
  1. #include "mbed.h"
  2. #include "main.h"
  3. #include "tusb322.h"
  4. InterruptIn IO_Usb(PB_4);
  5. void UsbInterrupt(void) {
  6. // No real uses for this at the moment
  7. }
  8. void TUSB322_Init(void) {
  9. TUSB322_REGS regs = {0};
  10. IO_Usb.fall(UsbInterrupt);
  11. // Disable UFP accessory support (otherwise IC stays in DRP mode)
  12. regs.Status2.UFP_ACCESSORY = 0x1;
  13. // Disable CC termination to change to UFP mode
  14. regs.Control.DISABLE_TERM = 0x1;
  15. // For operation in UFP mode
  16. regs.Control.MODE_SELECT = 0x01;
  17. I2C_Write(TUSB322_ADDR, FIELD_OFFSET(TUSB322_REGS, Status2),
  18. regs.AS_BYTE + FIELD_OFFSET(TUSB322_REGS, Status2),
  19. FIELD_SIZE_THROUGH(TUSB322_REGS, Status2, Control));
  20. // Reenable CC termination
  21. regs.Control.DISABLE_TERM = 0x0;
  22. I2C_Write(TUSB322_ADDR, FIELD_OFFSET(TUSB322_REGS, Control),
  23. regs.AS_BYTE + FIELD_OFFSET(TUSB322_REGS, Control),
  24. FIELD_SIZE_THROUGH(TUSB322_REGS, Control, Control));
  25. }