/* Toggle the 1kHz calibration pin, only accurate up to ca. 8MHz. */
#define TOGGLE_CALIBRATION_PIN() PA7 = !PA7
+#define LED_CLEAR() PC0 = 1; PC1 = 1;
+#define LED_GREEN() PC0 = 1; PC1 = 0;
+#define LED_RED() PC0 = 0; PC1 = 1;
+
/* Change to support as many interfaces as you need. */
static BYTE altiface = 0;
{
TOGGLE_CALIBRATION_PIN();
- if (ledcounter) {
- if (--ledcounter == 0) {
- /* Clear LED. */
- PC0 = 1;
- PC1 = 1;
- }
- }
+ if (ledcounter && (--ledcounter == 0))
+ LED_CLEAR();
TF2 = 0;
}
GPIFTCB0 = 0;
GPIFTRIG = (altiface == 0) ? 6 : 4;
- /* Set green LED, don't clear LED. */
+ /* Set green LED, don't clear LED afterwards (ledcounter = 0). */
+ LED_GREEN();
ledcounter = 0;
- PC0 = 1;
- PC1 = 0;
}
static void select_interface(BYTE alt)
{
stop_sampling();
- /* Set red LED. */
- PC0 = 0;
- PC1 = 1;
+ /* Set red LED, clear after timeout. */
+ LED_RED();
ledcounter = 1000;
/* Clear EP0BCH/L for each valid command. */
/* Toggle the 1kHz calibration pin, only accurate up to ca. 8MHz. */
#define TOGGLE_CALIBRATION_PIN() PC2 = !PC2
+#define LED_CLEAR() PC0 = 1; PC1 = 1;
+#define LED_GREEN() PC0 = 1; PC1 = 0;
+#define LED_RED() PC0 = 0; PC1 = 1;
+
/* Change to support as many interfaces as you need. */
static BYTE altiface = 0;
{
TOGGLE_CALIBRATION_PIN();
- if (ledcounter) {
- if (--ledcounter == 0) {
- /* Clear LED. */
- PC0 = 1;
- PC1 = 1;
- }
- }
+ if (ledcounter && (--ledcounter == 0))
+ LED_CLEAR();
TF2 = 0;
}
GPIFTCB0 = 0;
GPIFTRIG = (altiface == 0) ? 6 : 4;
- /* Set green LED, don't clear LED. */
+ /* Set green LED, don't clear LED afterwards (ledcounter = 0). */
+ LED_GREEN();
ledcounter = 0;
- PC0 = 1;
- PC1 = 0;
}
static void select_interface(BYTE alt)
{
stop_sampling();
- /* Set red LED. */
- PC0 = 0;
- PC1 = 1;
+ /* Set red LED, clear after timeout. */
+ LED_RED();
ledcounter = 1000;
/* Clear EP0BCH/L for each valid command. */
/* Note: There's no PE2 as IOE is not bit-addressable (see TRM 15.2). */
#define TOGGLE_CALIBRATION_PIN() IOE = IOE ^ 0x04
+#define LED_CLEAR() NOP
+#define LED_GREEN() NOP
+#define LED_RED() NOP
+
/* Change to support as many interfaces as you need. */
static BYTE altiface = 0;
+static volatile WORD ledcounter = 0;
+
static volatile __bit dosud = FALSE;
static volatile __bit dosuspend = FALSE;
{
TOGGLE_CALIBRATION_PIN();
+ if (ledcounter && (--ledcounter == 0))
+ LED_CLEAR();
+
TF2 = 0;
}
GPIFTCB0 = 0;
GPIFTRIG = (altiface == 0) ? 6 : 4;
+ /* Set green LED, don't clear LED afterwards (ledcounter = 0). */
+ LED_GREEN();
+ ledcounter = 0;
}
static void select_interface(BYTE alt)
{
stop_sampling();
+ /* Set red LED, clear after timeout. */
+ LED_RED();
+ ledcounter = 1000;
+
/* Clear EP0BCH/L for each valid command. */
if (cmd >= 0xe0 && cmd <= 0xe6) {
EP0BCH = 0;