Echelon Mini FX User Manual

Page 94

Advertising
background image

Mini FX User's Guide

81

// levels, i.e. TRUE for "on".
// The driver function translates the logical levels as necessary.
//
#ifdef USE_MINIGIZMO
IO_2 output bitshift numbits(8) ioLeds;
IO_1 output bit ioLedLoad = 1;
#else
#ifdef USE_5000EVB
IO_2 output bit ioLed1 = 1;
IO_3 output bit ioLed2 = 1;
#endif // 5000 evb
#endif // mini gizmo

void SetLeds(boolean led1, boolean led2)
{
#ifdef USE_MINIGIZMO
unsigned data;

// compute the data byte for the shift register:
data = led1 ? 0x01 : 0x00;
data |= led2 ? 0x02 : 0x00;

// push inverted data into shift register:
io_out(ioLeds, ~data);

// strobe:
io_out(ioLedLoad, 0);
io_out(ioLedLoad, 1);
#else
#ifdef USE_5000EVB
io_out(ioLed1, !led1);
io_out(ioLed2, !led2);
#endif // 5000 evb
#endif // mini gizmo
} // SetLeds

//
// Driver to support one button. The driver calls the OnButtonPressed()
// function, which is a callback function implemented by the application.
//
extern void OnButtonPressed(void);

#ifdef USE_MINIGIZMO

IO_4 input bitshift numbits(8) clockedge(-) ioButtons;
IO_6 output bit ioButtonLoad = 1;
boolean GetButton(void)
{
unsigned debounce;
unsigned data;
data = 0xFF;
for (debounce = 0; debounce < 3; ++debounce) {
// Strobe:
io_out(ioButtonLoad, 0);
io_out(ioButtonLoad, 1);
// Sample data and debounce:
data &= (unsigned)io_in(ioButtons);
}
return ~data & 0x01;
}

//
// buttonTimer expires every 25ms, and triggers the timer_expires event
// with each expiry
//
mtimer repeating buttonTimer = 25;
//
// The Neuron C scheduler activates the following when-task whenever the
// button timer expires. The task samples the button state, detects a
// newly activated SW1 button, and fires the OnButtonPressed() event when
// necessary.

Advertising