Updated all GPIO to PCBA updated version

Added LED module

git-svn-id: https://svn.vbchaos.nl/svn/hsb/trunk@321 05563f52-14a8-4384-a975-3d1654cca0fa
This commit is contained in:
mmi
2017-12-01 13:48:28 +00:00
parent 1415b5c6f2
commit e3b613c976
9 changed files with 369 additions and 73 deletions

View File

@@ -33,6 +33,7 @@ hsb-mrts.o \
Interlock.o \
IODevice.o \
KeyboardDevice.o \
Leds.o \
Logger.o \
MAX5715.o \
MemoryDevice.o \

View File

@@ -0,0 +1,114 @@
// -----------------------------------------------------------------------------
/// @file Leds.h
/// @brief File description
// -----------------------------------------------------------------------------
// Micro-Key bv
// Industrieweg 28, 9804 TG Noordhorn
// Postbus 92, 9800 AB Zuidhorn
// The Netherlands
// Tel: +31 594 503020
// Fax: +31 594 505825
// Email: support@microkey.nl
// Web: www.microkey.nl
// -----------------------------------------------------------------------------
/// $Revision$
/// $Author$
/// $Date$
// (c) 2015 Micro-Key bv
// -----------------------------------------------------------------------------
/// @defgroup {group_name} {group_description}
/// Description
/// @file Leds.h
/// @ingroup {group_name}
#ifndef INC_LEDS_H_
#define INC_LEDS_H_
// -----------------------------------------------------------------------------
// Include files
// -----------------------------------------------------------------------------
#include <stdbool.h>
// -----------------------------------------------------------------------------
// Constant and macro definitions
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
// Type definitions.
// -----------------------------------------------------------------------------
typedef enum
{
LED_ONBOARD_GREEN = 0,
LED_ONBOARD_ORANGE,
LED_BICOLOR_GREEN,
LED_BICOLOR_RED,
LED_BICOLOR_ORANGE,
LED_NUMBER_OF_LEDS
} Led;
// -----------------------------------------------------------------------------
// Function declarations
// -----------------------------------------------------------------------------
/** ----------------------------------------------------------------------------
* Led_construct
* Constructor for LEDs
*
* @return void
*
* @todo
* -----------------------------------------------------------------------------
*/
extern void Led_construct(void);
/** ----------------------------------------------------------------------------
* Led_on
* Turns on the LED given in argument led
*
* @param led The LED to set
*
* @return void
*
* @todo
* -----------------------------------------------------------------------------
*/
extern void Led_on(Led led);
/** ----------------------------------------------------------------------------
* Led_off
* Turns off the LED given in argument led
*
* @param led The LED to set
*
* @return void
*
* @todo
* -----------------------------------------------------------------------------
*/
extern void Led_off(Led led);
/** ----------------------------------------------------------------------------
* Led_getStatus
* Returns the status of the led in arugment led
*
* @param led The led to request the status of
* @param
* @return bool TRUE if led is ON
* FALSE if led is OFF
*
* @todo
* -----------------------------------------------------------------------------
*/
extern bool Led_getStatus(Led led);
#endif /* INC_LEDS_H_ */

View File

@@ -0,0 +1,158 @@
// -----------------------------------------------------------------------------
/// @file Leds.c
/// @brief Description
// -----------------------------------------------------------------------------
// Micro-Key bv
// Industrieweg 28, 9804 TG Noordhorn
// Postbus 92, 9800 AB Zuidhorn
// The Netherlands
// Tel: +31 594 503020
// Fax: +31 594 505825
// Email: support@microkey.nl
// Web: www.microkey.nl
// -----------------------------------------------------------------------------
/// $Revision$
/// $Author$
/// $Date$
// (c) 2017 Micro-Key bv
// -----------------------------------------------------------------------------
/// @file Leds.c
/// @ingroup {group_name}
// -----------------------------------------------------------------------------
// Include files
// -----------------------------------------------------------------------------
#include "gpio.h"
#include "platform.h"
#include "IODevice.h"
#include "Leds.h"
// -----------------------------------------------------------------------------
// Constant and macro definitions
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
// Type definitions
// -----------------------------------------------------------------------------
struct Led
{
bool initialized;
struct IODevice* ioDevice;
};
struct Leds
{
bool initialized;
struct Led leds[LED_NUMBER_OF_LEDS];
};
// -----------------------------------------------------------------------------
// File-scope variables
// -----------------------------------------------------------------------------
static struct Leds self = { .initialized = false };
// -----------------------------------------------------------------------------
// Function declarations
// -----------------------------------------------------------------------------
// -----------------------------------------------------------------------------
// Function definitions
// -----------------------------------------------------------------------------
void Led_construct(void)
{
if (!self.initialized)
{
self.initialized = true;
self.leds[LED_ONBOARD_GREEN].ioDevice = &ledInternGreen->device;
self.leds[LED_ONBOARD_GREEN].initialized = true;
self.leds[LED_ONBOARD_ORANGE].ioDevice = &ledInternOrange->device;
self.leds[LED_ONBOARD_ORANGE].initialized = true;
self.leds[LED_BICOLOR_GREEN].ioDevice = &ledBicolourGreen->device;
self.leds[LED_BICOLOR_GREEN].initialized = true;
self.leds[LED_BICOLOR_RED].ioDevice = &ledBicolourRed->device;
self.leds[LED_BICOLOR_RED].initialized = true;
}
}
extern void Led_on(Led led)
{
char bufferTrue = (char)true;
if (self.initialized)
{
if (self.leds[led].initialized)
{
// IN case of the BICOLOUR ORANGE LED, actually the GREEN and RED LEDs must be switched
if (led == LED_BICOLOR_ORANGE)
{
IODevice_write(self.leds[LED_BICOLOR_GREEN].ioDevice, &bufferTrue, 1);
IODevice_write(self.leds[LED_BICOLOR_RED].ioDevice, &bufferTrue, 1);
}
else
{
IODevice_write(self.leds[led].ioDevice, &bufferTrue, 1);
}
}
}
}
extern void Led_off(Led led)
{
char bufferFalse = (char)false;
if (self.initialized)
{
if (self.leds[led].initialized)
{
// IN case of the BICOLOUR ORANGE LED, actually the GREEN and RED LEDs must be switched
if (led == LED_BICOLOR_ORANGE)
{
IODevice_write(self.leds[LED_BICOLOR_GREEN].ioDevice, &bufferFalse, 1);
IODevice_write(self.leds[LED_BICOLOR_RED].ioDevice, &bufferFalse, 1);
}
else
{
IODevice_write(self.leds[led].ioDevice, &bufferFalse, 1);
}
}
}
}
extern bool Led_getStatus(Led led)
{
bool returnValue = false;
if (self.initialized)
{
if (self.leds[led].initialized)
{
char value;
IODevice_read(self.leds[led].ioDevice, &value, 1, NULL);
if (value != (char)false)
{
returnValue = true;
}
}
}
return returnValue;
}