Removed unused functions, Added new structure

+ Added new structure for holding a byte of LEDS.
+ Added new function to creating structure of Led array.
- Removed older functions for half-bytes.
- Removed the older function prototypes.
This commit is contained in:
Jake Goodwin 2024-08-25 06:19:31 -07:00
parent 92512c257e
commit 33e75b2e6a
3 changed files with 35 additions and 72 deletions

View File

@ -21,63 +21,24 @@
#define HALF_BYTE_BM
// static LedController controller;
void LedControler_SetPortADefault(void);
/*
* Uses pins: 9, 8, 12, 13
*/
void LedControler_SetPortBDefault(void)
LedByte LedController_New(uint8_t *port)
{
// controller.port = &PORTA;
LedByte led_byte;
for (int i = 0; i < 8; i++)
{
led_byte.leds[i].pin_num = 1;
led_byte.leds[i].state = false;
led_byte.leds[i].port = port;
}
return led_byte;
}
void LedController_SetLedBitNum(void *port, uint8_t pin, uint8_t bit);
void LedController_ShowByte(uint8_t byte);
void LedControler_ShowHalfByte(uint8_t byte)
void LedController_ShowByte(LedByte *led_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)
{
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;
}
}
void LedControler_ClearHalfByte(void)
void LedControler_ClearByte(LedByte *led_byte)
{
// 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;
}
void LedController_SetHigh(Led *led)

View File

@ -23,38 +23,25 @@ typedef struct Led
bool state;
} Led;
/**
* Sets the default PORTB pins for output.
*/
void LedControler_SetPortADefault(void);
typedef struct LedByte
{
Led leds[8];
} LedByte;
/**
* Sets the default PORTA pins for output.
* Returns a instance of the LedByte structure.
*/
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);
LedByte LedController_New(uint8_t *port);
/**
* Displays the byte of data via led pins.
*/
void LedController_ShowByte(uint8_t byte);
void LedController_ShowByte(LedByte *led_byte);
/**
* Displays the the first 4 bits of a byte.
* Clears out the byte led representation
*/
void LedControler_ShowHalfByte(uint8_t byte);
/**
* Clears out the halfbyte led representation
*/
void LedControler_ClearHalfByte(void);
void LedControler_ClearByte(LedByte *led_byte);
/**
* Sets a AVR Led to High/on.

View File

@ -87,4 +87,19 @@ TEST(test_LedController, LedSetLow)
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);
}
}