/* initialize the IO subsystems for the appropriate dongles */
static void io_init(void)
{
#ifdef IMME
    
 #ifdef IMMEDONGLE   // CC1110 on IMME pink dongle
    // IM-ME Dongle.  It's a CC1110, so no USB stuffs.  Still, a bit of stuff to init for talking 
    // to it's own Cypress USB chip
    P0SEL |= (BIT5 | BIT3);     // Select SCK and MOSI as SPI
    P0DIR |= BIT4 | BIT6;       // SSEL and LED as output
    P0 &= ~(BIT4 | BIT2);       // Drive SSEL and MISO low

    P1IF = 0;                   // clear P1 interrupt flag
    IEN2 |= IEN2_P1IE;          // enable P1 interrupt
    P1IEN |= BIT1;              // enable interrupt for P1.1

    P1DIR |= BIT0;              // P1.0 as output, attention line to cypress
    P1 &= ~BIT0;                // not ready to receive
 #else              // full blown IMME with screen and keyboard
    
    //Disable WDT
    IEN2&=~IEN2_WDTIE;
    IEN0&=~EA;
	setIOPorts();
	configureSPI();
	LCDReset();
  
    //Startup display.
    setDisplayStart(0);
    SSN = LOW;
    setNormalReverse(0);
    erasescreen();
    drawstr(0,0, "IMME SNIFF v0.1");
    SSN = HIGH;

    //immeLCDInitScreen();
    //sleepMillis(100);
  
 #endif 
#else       // CC1111
 #ifdef DONSDONGLES
    // CC1111 USB Dongle
    // turn on LED and BUTTON
    P1DIR |= 3;
    // Activate BUTTON - Do we need this?
    //CC1111EM_BUTTON = 1;

 #else
    // CC1111 USB (ala Chronos watch dongle), we just need LED
    P1DIR |= 3;

 #endif      // CC1111

 #ifndef VIRTUAL_COM
    // Turn off LED
    LED = 0;
 #endif

#endif // conditional
}
/* clear all LCD pixels */
void clear() {
    u8 row;
    u8 col;

    SSN = LOW;
    setDisplayStart(0);

    /* normal display mode (not inverted) */
    setNormalReverse(0);

    for (row = 0; row <= 9; row++) {
        setCursor(row, 0);
        for (col = 0; col < WIDTH; col++)
            txData(0x00);
    }

    SSN = HIGH;
}
void LCDReset(void) {
  LCDRst = LOW; // hold down the RESET line to reset the display
  sleepMillis(1);
  LCDRst = HIGH;
  SSN = LOW;
  // send the initialisation commands to the LCD display
  txCtl(0xe2); // RESET cmd
  txCtl(0x24); // set internal resistor ratio
  txCtl(0x81); // set Vol Control
  txCtl(0x60); // set Vol Control - ctd
  txCtl(0xe6); // ?? -- don't know what this command is
  txCtl(0x00); // ?? -- don't know what this command is
  txCtl(0x2f); // set internal PSU operating mode
  txCtl(0xa1); // LCD bias set
  txCtl(0xaf); // Display ON
  txCtl(0xa4); // Normal (not all pixels) mode.
  setNormalReverse(0); //Non-inverted screen.
  SSN = HIGH;
}