You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
if (portmux==PORTMUX_TWI1_ALT2_gc) { // make sure we don't get errata'ed
558
+
#if defined(PORTB)
559
+
PORTB.OUTCLR=0x0C; // bits 2 and 3
560
+
#endif
561
+
} else
562
+
#endif
563
+
{
564
+
PORTF.OUTCLR=0x0C; // bits 2 and 3
565
+
}
566
+
#if defined(TWI1_DUALCTRL)
567
+
#if defined(PORTB)
568
+
if (TWI1.DUALCTRL&TWI_ENABLE_bm) {
569
+
if (portmux==PORTMUX_TWI1_DEFAULT_gc) {
570
+
PORTB.OUTCLR=0x0C; // bits 2 and 3
571
+
} else {
572
+
PORTB.OUTCLR=0xC0; // bits 6 and 7
573
+
}
574
+
}
575
+
#endif
576
+
#endif
577
+
(void) portmux; //this is grabbed early, but depending on which part and hence what is conditionally compiled, may not go into the code. It will produce spurious warnings without this line
// Danger: 'portmux' in this context means all the other settings in portmux, since we're replacing the PORTMUX setting for TWI1, and will bitwise-or with the _gc constants.
584
+
// Elsewhere, 'portmux' refers to the setting for this peripheral only, and we compare it to PORTMUX_TWI1_xxx_gc
// Danger: 'portmux' in this context means all the other settings in portmux, since we're replacing the PORTMUX setting for TWI1, and will bitwise-or with the _gc constants.
630
+
// Elsewhere, 'portmux' refers to the setting for this peripheral only, and we compare it to PORTMUX_TWI1_xxx_gc
#if defined(PORTB) //All parts with a TWI1 have a PORTF
673
+
if (portmux==PORTMUX_TWI1_ALT2_gc) {
674
+
port=&PORTB;
675
+
} else {
676
+
port=&PORTF;
677
+
}
678
+
#else
679
+
port=&PORTF;
680
+
#endif
681
+
682
+
port->OUTCLR=0x0C; // bits 2 and 3
683
+
port->PIN2CTRL |= PORT_PULLUPEN_bm;
684
+
port->PIN3CTRL |= PORT_PULLUPEN_bm;
685
+
686
+
#if defined(TWI0_DUALCTRL) && defined(PORTB)
687
+
if (TWI1.DUALCTRL&TWI_ENABLE_bm) {
688
+
if (portmux==PORTMUX_TWI1_DEFAULT_gc) {
689
+
PORTB.OUTCLR=0x0C; // bits 2 and 3
690
+
PORTB.PIN2CTRL |= PORT_PULLUPEN_bm;
691
+
PORTB.PIN3CTRL |= PORT_PULLUPEN_bm;
692
+
} else {
693
+
PORTB.OUTCLR=0xC0; // bits 6 and 7
694
+
PORTB.PIN6CTRL |= PORT_PULLUPEN_bm;
695
+
PORTB.PIN7CTRL |= PORT_PULLUPEN_bm;
696
+
}
697
+
}
698
+
#endif
699
+
(void) portmux; //this is grabbed early, but depending on which part and hence what is conditionally compiled, may not go into the code. It will produce spurious warnings without this line
700
+
}
701
+
702
+
//Check if TWI1 Master pins have a HIGH level: Bit0 = SDA, Bit 1 = SCL
703
+
uint8_tTWI1_checkPinLevel(void) {
704
+
// we do it this way because when accessed using a pointer, it's no longer any faster to use VPORTx
705
+
#if defined(PORTB) //All parts with a TWI1 have a PORTF
706
+
uint8_tportmux=PORTMUX.TWIROUTEA&PORTMUX_TWI1_gm;
707
+
if (portmux==PORTMUX_TWI1_ALT2_gc) {
708
+
return ((VPORTB.IN&0x0C) >> 2);
709
+
} else {
710
+
return ((VPORTF.IN&0x0C) >> 2);
711
+
}
712
+
#else
713
+
return ((VPORTF.IN&0x0C) >> 2);
714
+
#endif
715
+
}
716
+
717
+
// All devices with TWI1 have dual mode and the most have the smbus levels; the exceptions are caught before this is called
0 commit comments