source: test2.git/leds.c

Last change on this file was b6aa0ba, checked in by andib <andi.b@…>, 2 years ago

test with more files

  • Property mode set to 100644
File size: 4.0 KB
Line 
1/*******************************************************************************
2MODULE : leds.c
3 Driver for LEDs. Derived from EM sample code/library.
4
520101007 AB Initial G880 Olimex
620150323 AB Changed to BS-OI3 Port PF3..5
720170826 AB Added BS-OI3 Port PE13..15 for LED10, 11, 12 (red, green, blue)
820191213 AB Adapted for JADE STK3401A
9*******************************************************************************/
10
11// --- Includes ---------------------------------------------------------------
12#define LOGGING_TOKEN LED_LOGGING
13#include "TraceLeUart.h"
14
15#include <efm32.h>
16#include <em_cmu.h>
17#include "em_gpio.h"
18
19#include "leds.h"
20
21// --- Pin Definitions --------------------------------------------------------
22// PF4 is used for TRACE_LEUART_RX
23// #define LED0_INIT() { GPIO_PinModeSet(gpioPortF, 4, gpioModePushPull, 0);}
24//#define LED0_OUT( x ) { if ( x ) GPIO_PinOutSet(gpioPortF, 4); else GPIO_PinOutClear(gpioPortF, 4); }
25//#define LED0_GET() GPIO_PinOutGet(gpioPortF, 4)
26
27// PF5 pinX (for search in project - Testpin_on)
28#define LED2_INIT() { GPIO_PinModeSet(gpioPortF, 5, gpioModePushPull, 0);}
29#define LED2_OUT( x ) { if ( x ) GPIO->P[gpioPortF].DOUT |= 1 << 5; else GPIO->P[gpioPortF].DOUT &= ~(1 << 5); }
30#define LED2_GET GPIO_PinOutGet(gpioPortF, 5)
31
32// --- Defines ----------------------------------------------------------------
33
34// --- Typedefs ---------------------------------------------------------------
35
36// --- PUBLIC Variables -------------------------------------------------------
37
38// --- Variables --------------------------------------------------------------
39
40// --- Macros -----------------------------------------------------------------
41
42// --- Functionprototypes -----------------------------------------------------
43
44// --- Code -------------------------------------------------------------------
45/**************************************************************************//**
46 * @brief Light up LED
47 * @param led LED number (0-2), 1 not used as not populated on STK
48 *****************************************************************************/
49void LED_Set(int led)
50 {
51 if (led < 3)
52 {
53 switch (led)
54 {
55 case 0:
56// LED0_OUT(1);
57 break;
58
59 case 2:
60 LED2_OUT(1);
61 break;
62
63 default:
64 TRACE_L2("LED: wrong number %d", led);
65 break;
66 }
67 }
68 }
69
70/**************************************************************************//**
71 * @brief Turn off LED
72 * @param led LED number (0-2), 1 not used as not populated on STK
73 *****************************************************************************/
74void LED_Clear(int led)
75 {
76 if (led < 3)
77 {
78 switch (led)
79 {
80 case 0:
81// LED0_OUT(0);
82 break;
83
84 case 2:
85 LED2_OUT(0);
86 break;
87
88 default:
89 TRACE_L2("LED: wrong number %d", led);
90 break;
91 }
92 }
93 }
94
95/**************************************************************************//**
96 * @brief Toggle LED, switch from on to off or vice versa
97 * @param led LED number (0-2), 1 not used as not populated on STK
98 *****************************************************************************/
99void LED_Toggle(int led)
100 {
101 if (led < 3)
102 {
103 switch (led)
104 {
105 case 0:
106// if ( LED0_GET() ) LED_Clear(0);
107// else LED_Set(0);
108 break;
109
110 case 2:
111 if ( LED2_GET ) LED_Clear(2);
112 else LED_Set(2);
113 break;
114
115 default:
116 TRACE_L2("LED: wrong number %d", led);
117 break;
118 }
119 }
120 }
121
122/**************************************************************************//**
123 * @brief Initialize LED interface
124 *****************************************************************************/
125void LedInit(void)
126 {
127
128 TRACE_L2("LED: init"); // usually no output as TRACE is not initialized when called
129 /* Enable GPIO */
130 CMU_ClockEnable(cmuClock_GPIO, true);
131
132 /* Configure GPIO port PF4 and PF5 as LED control outputs */
133// LED0_INIT();
134 LED2_INIT();
135
136 /* Light them all */
137 LedOn(0);
138 LedOn(2);
139 }
Note: See TracBrowser for help on using the repository browser.