123

Dependencies:   mbed

Fork of LG by igor Apu

Revision:
149:abbf7663d27d
Child:
156:e68ee0bcdcda
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/DeviceLightUp.c	Tue May 03 05:12:26 2016 +0000
@@ -0,0 +1,85 @@
+#include "Device.h"
+
+#ifdef DEV_BOARD
+#warning "DeviceLightUp.c debug: development board LED1, LED2 in use instead light-up and backlight!!!"
+#endif
+
+extern Device device;
+
+void InitLightUpWithDefaults(void){
+  device.lightUp.settings.sequence = 0x0155;
+  device.lightUp.state.sequence = 0x0000;
+  device.lightUp.state.enabled = 0;
+}
+
+void InitLightUp(void)//проверка битового поля поджига  и  установка значения бита поджига
+{
+  #ifdef DEV_BOARD
+    //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 StartLightUp(void)//проверка битового поля поджига  и  установка значения бита поджига
+{
+  device.lightUp.state.sequence = device.lightUp.settings.sequence;
+  device.lightUp.state.enabled = 1;
+}
+
+void LightUpCycle(void)
+{
+  if (device.lightUp.state.enabled){
+    if (device.lightUp.state.sequence & 0x01){
+      #ifdef DEV_BOARD
+        //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
+        //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;
+  }
+}
\ No newline at end of file