123

Dependencies:   mbed

Fork of LG by igor Apu

DeviceLightUp.c

Committer:
Kovalev_D
Date:
2016-10-19
Revision:
197:7a05523bf588
Parent:
167:bedc0a9d559a

File content as of revision 197:7a05523bf588:

#include "Device.h"

#ifdef DEV_BOARD_HAOYU
#warning "DeviceLightUp.c debug: development board LED1, LED2 in use instead light-up and backlight!!!"
#endif

extern Device device;

void InitLightUpDefaultSettings(void){
  device.lightUp.settings.sequence = 0x0155;
  device.lightUp.state.sequence = 0x0000;
  device.lightUp.state.enabled = 0;
}

void InitLightUpState(void) {
  device.lightUp.state.sequence = device.lightUp.settings.sequence;
  device.lightUp.state.enabled = 1;  
}

void DeviceStartLightUp(void) {
  #ifdef DEV_BOARD_HAOYU
    //Development board - P3.25: LED1
    LPC_PINCON->PINSEL7  &= ~(3<<18);    //P3.25 is GPIO pin (write ( 00 ) in bits 19:18 of PISEL7)
    LPC_PINCON->PINMODE7 |=  (3<<18);    //P3.25 pull-down resistor on (write ( 11 ) in bits 19:18 of PINMODE7)
    LPC_GPIO3->FIODIR    |=  (1<<25);    //P3.25 is output (write ( 1 ) in bit 25 of FIODIR)
    LPC_GPIO3->FIOSET    |=  (1<<25);    //off
  
    //Development board - P3.26: LED2
    LPC_PINCON->PINSEL7  &= ~(3<<20);    //P3.26 is GPIO pin (write ( 00 ) in bits 21:20 of PISEL7)
    LPC_PINCON->PINMODE7 |=  (3<<20);    //P3.26 pull-down resistor on (write ( 11 ) in bits 21:20 of PINMODE7)
    LPC_GPIO3->FIODIR    |=  (1<<26);    //P3.26 is output (write ( 1 ) in bit 26 of FIODIR)
    LPC_GPIO3->FIOSET    |=  (1<<26);    //off
  #else  
    //Device - P0.4: Light-up
    LPC_PINCON->PINSEL0  &= ~(3<<8);     //P0.4 is GPIO pin (write ( 00 ) in bits 9:8 of PISEL0)
    LPC_PINCON->PINMODE0 |=  (3<<8);     //P0.4 pull-down resistor on (write ( 11 ) in bits 9:8 of PINMODE0)
    LPC_GPIO0->FIODIR    |=  (1<<4);     //P0.4 is output (write ( 1 ) in bit 4 of FIODIR)
    LPC_GPIO0->FIOSET    |=  (1<<4);    //off
  
    //Device - P2.12: Back light
    LPC_PINCON->PINSEL3  &= ~(0x00<<24); 
    LPC_PINCON->PINSEL3  |=  (0x00<<24); //P2.12 is GPIO pin (write ( 00 ) in bits 13:12 of PISEL3)
    LPC_PINCON->PINMODE3 |=  (3<<24);    //P2.12 pull-down resistor on (write ( 11 ) in bits 13:12 of PINMODE3)
    LPC_GPIO2->FIODIR    |=  (1<<12);    //P2.12 is output   (write ( 1 ) in  bit 12 of FIODIR)
    LPC_GPIO2->FIOSET    |=  (1<<12);    //off
  #endif
}

void DeviceLightUpDoCycle(void)
{
  if (device.lightUp.state.enabled){
    if (device.lightUp.state.sequence & 0x01){
      #ifdef DEV_BOARD_HAOYU
        //Development board - P3.25: LED 1 on
        LPC_GPIO3->FIOCLR = (1<<25);
        //Development board - P3.26: LED 2 on
        LPC_GPIO3->FIOCLR = (1<<26);
      #else
        //Device - P0.4: Light-up on
        LPC_GPIO0->FIOCLR = (1<<4);
        //Device - P2.12: Back light on
        LPC_GPIO2->FIOCLR  = (1<<12);
      #endif
    } else {
      #ifdef DEV_BOARD_HAOYU
        //Development board - P3.25: LED 1 off
        LPC_GPIO3->FIOSET = (1<<25);
        //Development board - P3.26: LED 2 off
        LPC_GPIO3->FIOSET = (1<<26);
      #else
        //Device - P0.4: Light-up off
        LPC_GPIO0->FIOSET = (1<<4);
        //Device - P2.12: Back light off
        LPC_GPIO2->FIOSET  = (1<<12);
      #endif
    }
      
    if (device.lightUp.state.sequence)
      device.lightUp.state.sequence = device.lightUp.state.sequence >> 1;
    else
      device.lightUp.state.enabled = 0;
  }
}