Compare commits

..

No commits in common. "33e75b2e6af9235343a1a292425616e3753081dd" and "2b45d7004486886512bbb1e47e905319928217ac" have entirely different histories.

4 changed files with 80 additions and 119 deletions

View file

@ -21,36 +21,62 @@
#define HALF_BYTE_BM
LedByte LedController_New(uint8_t *port)
//static LedController controller;
void LedControler_SetPortADefault(void);
/*
* Uses pins: 9, 8, 12, 13
*/
void LedControler_SetPortBDefault(void)
{
LedByte led_byte;
for (int i = 0; i < 8; i++)
// controller.port = &PORTA;
}
void LedController_SetLedBitNum(void *port, uint8_t pin, uint8_t bit);
void LedController_ShowByte(uint8_t byte);
void LedControler_ShowHalfByte(uint8_t byte)
{
byte = byte & 0x0F;
// PORTA.DIR |= (1<<2)|(1<<3)|(1<<6)|(1<<7);
PORTA.DIR |= PA_B1;
PORTA.DIR |= PA_B2;
PORTA.DIR |= PA_B3;
PORTA.DIR |= PA_B4;
// PORTA.DIR |= HALF_BYTE_BM;
// 15 = 0b1111
// PORTA.OUT |= (byte & 0x0F);
if (byte & 0x01)
{
led_byte.leds[i].pin_num = 1;
led_byte.leds[i].state = false;
led_byte.leds[i].port = port;
PORTA.OUT |= PA_B1;
}
if (byte & 0x02)
{
PORTA.OUT |= PA_B2;
}
if (byte & 0x04)
{
PORTA.OUT |= PA_B3;
}
if (byte & 0x08)
{
PORTA.OUT |= PA_B4;
}
return led_byte;
}
void LedController_ShowByte(LedByte *led_byte)
void LedControler_ClearHalfByte(void)
{
}
void LedControler_ClearByte(LedByte *led_byte)
{
}
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;
// PORTA.OUT &= HALF_BYTE_BM;
// PORTA.OUT &= ~((1<<2)|(1<<3)|(1<<6)|(1<<7));
PORTA.OUT &= ~PA_B1;
PORTA.OUT &= ~PA_B2;
PORTA.OUT &= ~PA_B3;
PORTA.OUT &= ~PA_B4;
// PORTA.OUT = 0x00;
}

View file

@ -10,8 +10,9 @@
#ifndef LEDCONTROLLER
#define LEDCONTROLLER
#include "stdbool.h"
#include <stdint.h>
#include "stdbool.h"
/**
* A structure representing an LED
@ -21,38 +22,40 @@ typedef struct Led
uint8_t *port;
uint8_t pin_num;
bool state;
} Led;
}Led;
typedef struct LedByte
{
Led leds[8];
} LedByte;
/**
* Returns a instance of the LedByte structure.
* Sets the default PORTB pins for output.
*/
LedByte LedController_New(uint8_t *port);
void LedControler_SetPortADefault(void);
/**
* Sets the default PORTA pins for output.
*/
void LedControler_SetPortBDefault(void);
/**
* Allows the setting or changing of which pins represent which bits.
* @param port The address of the port.
* @param pin The pin number for the port.
* @param bit The bit that the pin should represent.
*/
void LedController_SetLedBitNum(void *port, uint8_t pin, uint8_t bit);
/**
* Displays the byte of data via led pins.
*/
void LedController_ShowByte(LedByte *led_byte);
void LedController_ShowByte(uint8_t byte);
/**
* Clears out the byte led representation
* Displays the the first 4 bits of a byte.
*/
void LedControler_ClearByte(LedByte *led_byte);
void LedControler_ShowHalfByte(uint8_t byte);
/**
* Sets a AVR Led to High/on.
* @param led Pointer to an Led structure.
* Clears out the halfbyte led representation
*/
void LedController_SetHigh(Led *led);
/**
* Sets a AVR Led to Low/off.
* @param led Pointer to an Led structure.
*/
void LedController_SetLow(Led *led);
void LedControler_ClearHalfByte(void);
#endif // LEDCONTROLLER

View file

@ -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)

View file

@ -24,13 +24,8 @@ TEST_GROUP(test_LedController)
}
};
TEST(test_LedController, selftest)
{
CHECK_TRUE(true);
}
TEST(test_LedController, LedSetHighWorks)
TEST(test_LedController, LedController_SetHigh)
{
uint8_t fake_port = 0x00;
@ -39,67 +34,4 @@ TEST(test_LedController, LedSetHighWorks)
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);
}
/*
* what's the best way to handle an array of 8 leds. Should they
* reside in a structure? Or should it just be an array that the user defines?
*/
TEST(test_LedController, NewLedByte)
{
uint8_t fake_port = 0x00;
LedByte led_byte = LedController_New(&fake_port);
for(int i = 0; i < 8; i++){
CHECK_TRUE(led_byte.leds[i].state == false);
CHECK_EQUAL(&fake_port, led_byte.leds[i].port);
CHECK_EQUAL(false, led_byte.leds[i].state);
}
}