Added functions to set leds high and low.
This commit is contained in:
parent
2b45d70044
commit
92512c257e
|
@ -21,8 +21,7 @@
|
|||
|
||||
#define HALF_BYTE_BM
|
||||
|
||||
|
||||
//static LedController controller;
|
||||
// static LedController controller;
|
||||
|
||||
void LedControler_SetPortADefault(void);
|
||||
|
||||
|
@ -80,3 +79,17 @@ void LedControler_ClearHalfByte(void)
|
|||
PORTA.OUT &= ~PA_B4;
|
||||
// PORTA.OUT = 0x00;
|
||||
}
|
||||
|
||||
void LedController_SetHigh(Led *led)
|
||||
{
|
||||
*led->port |= (1 << led->pin_num);
|
||||
led->state = true;
|
||||
return;
|
||||
}
|
||||
|
||||
void LedController_SetLow(Led *led)
|
||||
{
|
||||
*led->port &= ~(1 << led->pin_num);
|
||||
led->state = false;
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -10,9 +10,8 @@
|
|||
#ifndef LEDCONTROLLER
|
||||
#define LEDCONTROLLER
|
||||
|
||||
#include <stdint.h>
|
||||
#include "stdbool.h"
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
/**
|
||||
* A structure representing an LED
|
||||
|
@ -22,8 +21,7 @@ typedef struct Led
|
|||
uint8_t *port;
|
||||
uint8_t pin_num;
|
||||
bool state;
|
||||
}Led;
|
||||
|
||||
} Led;
|
||||
|
||||
/**
|
||||
* Sets the default PORTB pins for output.
|
||||
|
@ -58,4 +56,16 @@ void LedControler_ShowHalfByte(uint8_t byte);
|
|||
*/
|
||||
void LedControler_ClearHalfByte(void);
|
||||
|
||||
/**
|
||||
* Sets a AVR Led to High/on.
|
||||
* @param led Pointer to an Led structure.
|
||||
*/
|
||||
void LedController_SetHigh(Led *led);
|
||||
|
||||
/**
|
||||
* Sets a AVR Led to Low/off.
|
||||
* @param led Pointer to an Led structure.
|
||||
*/
|
||||
void LedController_SetLow(Led *led);
|
||||
|
||||
#endif // LEDCONTROLLER
|
||||
|
|
|
@ -1,12 +1,12 @@
|
|||
project(Tests)
|
||||
|
||||
# TEST_DIRS
|
||||
add_subdirectory(LedController)
|
||||
#add_subdirectory(timer)
|
||||
#add_subdirectory(usart)
|
||||
add_subdirectory(MockRegEdit)
|
||||
add_subdirectory(RegEdit)
|
||||
add_subdirectory(simple_test)
|
||||
add_subdirectory(LedController)
|
||||
|
||||
|
||||
|
||||
|
|
|
@ -24,8 +24,13 @@ TEST_GROUP(test_LedController)
|
|||
}
|
||||
};
|
||||
|
||||
TEST(test_LedController, selftest)
|
||||
{
|
||||
CHECK_TRUE(true);
|
||||
}
|
||||
|
||||
TEST(test_LedController, LedController_SetHigh)
|
||||
|
||||
TEST(test_LedController, LedSetHighWorks)
|
||||
{
|
||||
uint8_t fake_port = 0x00;
|
||||
|
||||
|
@ -34,4 +39,52 @@ TEST(test_LedController, LedController_SetHigh)
|
|||
fake_led.pin_num = 0;
|
||||
fake_led.state = false;
|
||||
|
||||
LedController_SetHigh(&fake_led);
|
||||
|
||||
//Check that it sets the correct bit.
|
||||
CHECK_TRUE(fake_port & 0x01);
|
||||
|
||||
//It should set the state to true.
|
||||
CHECK_TRUE(fake_led.state);
|
||||
|
||||
//Only the first bit should have been set
|
||||
CHECK_TRUE(fake_port == 0x01);
|
||||
}
|
||||
|
||||
TEST(test_LedController, LedSetHighMaintainsPortState)
|
||||
{
|
||||
uint8_t fake_port = 0x00;
|
||||
|
||||
Led fake_led;
|
||||
fake_led.port = &fake_port;
|
||||
fake_led.pin_num = 0;
|
||||
fake_led.state = false;
|
||||
|
||||
Led led_two;
|
||||
led_two.pin_num = 1;
|
||||
led_two.port = &fake_port;
|
||||
led_two.state = false;
|
||||
|
||||
LedController_SetHigh(&fake_led);
|
||||
LedController_SetHigh(&led_two);
|
||||
|
||||
CHECK_TRUE(fake_port & 0x01);
|
||||
CHECK_TRUE(fake_port & 0x02);
|
||||
}
|
||||
|
||||
TEST(test_LedController, LedSetLow)
|
||||
{
|
||||
uint8_t fake_port = 0x01;
|
||||
|
||||
Led fake_led;
|
||||
fake_led.port = &fake_port;
|
||||
fake_led.pin_num = 0;
|
||||
fake_led.state = true;
|
||||
|
||||
LedController_SetLow(&fake_led);
|
||||
|
||||
CHECK_EQUAL(0x00, fake_port);
|
||||
CHECK_EQUAL(false, fake_led.state);
|
||||
}
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue