removed all refernces to the LEDController module.
This commit is contained in:
parent
952541f9b4
commit
e04504088b
|
@ -53,5 +53,5 @@ endif()
|
|||
add_subdirectory(RegEdit)
|
||||
add_subdirectory(usart)
|
||||
add_subdirectory(timer)
|
||||
add_subdirectory(LedController)
|
||||
|
||||
add_subdirectory(SuperLoop)
|
||||
|
|
|
@ -1,7 +0,0 @@
|
|||
add_library(LedController STATIC
|
||||
LedController.c
|
||||
)
|
||||
|
||||
target_include_directories(LedController PUBLIC
|
||||
${CMAKE_CURRENT_LIST_DIR}
|
||||
)
|
|
@ -1,54 +0,0 @@
|
|||
/*
|
||||
* Author: Jake G
|
||||
* Date: 2024
|
||||
* filename: LedController.c
|
||||
* description: Abstract LED interface and control.
|
||||
*/
|
||||
|
||||
#ifndef __AVR_ATtiny404__
|
||||
#define __AVR_ATtiny404__
|
||||
#endif
|
||||
|
||||
#include "LedController.h"
|
||||
#include "avr/io.h"
|
||||
|
||||
#define LED_BM_PORTA (1 << 6) | (1 << 1) | (1 << 2) | (1 << 3)
|
||||
#define LED_BM_PORTB (1 << 3) | (1 << 2) | (1 << 0) | (1 << 1)
|
||||
|
||||
LedByte LedController_New(uint8_t *port) {
|
||||
LedByte led_byte;
|
||||
for (int i = 0; i < 8; i++) {
|
||||
led_byte.leds[i].pin_num = i;
|
||||
led_byte.leds[i].state = false;
|
||||
led_byte.leds[i].port = port;
|
||||
}
|
||||
return led_byte;
|
||||
}
|
||||
|
||||
void LedController_ShowByte(LedByte *led_byte, uint8_t byte) {
|
||||
for (int i = 0; i < 8; i++) {
|
||||
if (byte & (1 << i)) {
|
||||
LedController_SetHigh(&led_byte->leds[i]);
|
||||
} else {
|
||||
LedController_SetLow(&led_byte->leds[i]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void LedControler_ClearByte(LedByte *led_byte) {
|
||||
for (int i = 0; i < 8; i++) {
|
||||
LedController_SetLow(&led_byte->leds[i]);
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
|
@ -1,59 +0,0 @@
|
|||
/**
|
||||
* @brief Led Controller module
|
||||
* @details This file outputs a byte of data to the pins for led indication.
|
||||
* @author Jake G
|
||||
* @date 2024-08-21
|
||||
* @copyright None
|
||||
* @file LEDCONTROLLER.h
|
||||
*/
|
||||
|
||||
#ifndef LEDCONTROLLER
|
||||
#define LEDCONTROLLER
|
||||
|
||||
#include "stdbool.h"
|
||||
#include <stdint.h>
|
||||
|
||||
/**
|
||||
* A structure representing an LED
|
||||
*/
|
||||
typedef struct Led {
|
||||
volatile uint8_t *port;
|
||||
uint8_t pin_num;
|
||||
bool state;
|
||||
} Led;
|
||||
|
||||
typedef struct LedByte {
|
||||
Led leds[8];
|
||||
} LedByte;
|
||||
|
||||
/**
|
||||
* Returns a instance of the LedByte structure.
|
||||
*/
|
||||
LedByte LedController_New(uint8_t *port);
|
||||
|
||||
/**
|
||||
* Displays the byte of data via led pins.
|
||||
* @param led_byte A pointer to a LedByte structure.
|
||||
* @param byte A uint8_t representing the byte to be displayed.
|
||||
*/
|
||||
void LedController_ShowByte(LedByte *led_byte, uint8_t byte);
|
||||
|
||||
/**
|
||||
* Clears out the byte led representation
|
||||
* @param led_byte A pointer to the LedByte structure.
|
||||
*/
|
||||
void LedControler_ClearByte(LedByte *led_byte);
|
||||
|
||||
/**
|
||||
* 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
|
73
src/main.c
73
src/main.c
|
@ -24,31 +24,13 @@
|
|||
#include <avr/io.h>
|
||||
#include <util/delay.h>
|
||||
|
||||
#define SW1PIN (1 << 5)
|
||||
#define SW2PIN (1 << 4)
|
||||
#define RELAYPIN (1 << 7)
|
||||
#define RELAYREADINGPIN \
|
||||
(1 << 6) // It would be better to use PA7 so USART worked
|
||||
|
||||
//#define LED_BM_PORTA (1 << 6)|(1 << 1)|(1 << 2)|(1 << 3)
|
||||
#define LED_BM_PORTA (1 << 1) | (1 << 2) | (1 << 3)
|
||||
#define LED_BM_PORTB (1 << 3) | (1 << 2) | (1 << 0) | (1 << 1)
|
||||
|
||||
// Set the function pointer for the delay func
|
||||
void (*Delay_MicroSeconds)(double us) = _delay_us;
|
||||
|
||||
void SW1_Wait(void) {
|
||||
// poll the input.
|
||||
while (PORTA.IN & SW1PIN) {
|
||||
}
|
||||
}
|
||||
|
||||
void SW2_Wait(void) {
|
||||
// poll the input.
|
||||
while (PORTA.IN & SW2PIN) {
|
||||
}
|
||||
}
|
||||
|
||||
void Activate_Relay(void) { PORTA.OUT |= RELAYPIN; }
|
||||
|
||||
void Deactivate_Relay(void) { PORTA.OUT &= ~RELAYPIN; }
|
||||
|
@ -65,62 +47,20 @@ void WaitForRelayDisconnect(void) {
|
|||
}
|
||||
}
|
||||
|
||||
void LedSetup(LedByte *led_byte) {
|
||||
PORTA.DIR |= LED_BM_PORTA;
|
||||
PORTB.DIR |= LED_BM_PORTB;
|
||||
|
||||
// pin 13, bit 0, PA3
|
||||
led_byte->leds[0].port = (void *)&PORTA.OUT;
|
||||
led_byte->leds[0].pin_num = 3;
|
||||
|
||||
// pin 12, bit 1, PA2
|
||||
led_byte->leds[1].port = &PORTA.OUT;
|
||||
led_byte->leds[1].pin_num = 2;
|
||||
|
||||
// pin 11, bit 2, PA1
|
||||
led_byte->leds[2].port = &PORTA.OUT;
|
||||
led_byte->leds[2].pin_num = 1;
|
||||
|
||||
// pin 9, bit 3, PB0
|
||||
led_byte->leds[3].port = &PORTB.OUT;
|
||||
led_byte->leds[3].pin_num = 0;
|
||||
|
||||
// pin 8, bit 4, PB1
|
||||
led_byte->leds[4].port = &PORTB.OUT;
|
||||
led_byte->leds[4].pin_num = 1;
|
||||
|
||||
// pin 2, bit 5, PB2
|
||||
led_byte->leds[5].port = &PORTB.OUT;
|
||||
led_byte->leds[5].pin_num = 2;
|
||||
|
||||
// pin 3, bit 6, PB3
|
||||
led_byte->leds[6].port = &PORTB.OUT;
|
||||
led_byte->leds[6].pin_num = 3;
|
||||
|
||||
// pin 3, bit 7, PA6
|
||||
led_byte->leds[7].port = &PORTA.OUT;
|
||||
// led_byte->leds[7].pin_num = 6;
|
||||
led_byte->leds[7].pin_num = 3;
|
||||
}
|
||||
|
||||
/*
|
||||
int main(int argc, char **argv) {
|
||||
// We use pin 10 which is the UDPI/RESET pin.
|
||||
// This means we have to change it's mode.
|
||||
|
||||
PORTA.DIR |= RELAYPIN;
|
||||
PORTA.DIR &= ~RELAYREADINGPIN;
|
||||
PORTA.DIR &= ~SW1PIN;
|
||||
PORTA.DIR &= ~SW2PIN;
|
||||
|
||||
uint16_t make_time = 0;
|
||||
uint16_t break_time = 0;
|
||||
uint8_t temp = 0;
|
||||
|
||||
LedByte led_byte = LedController_New(&PORTA.OUT);
|
||||
LedSetup(&led_byte);
|
||||
|
||||
while (true) {
|
||||
SW1_Wait();
|
||||
Activate_Relay();
|
||||
|
||||
Timer_Start();
|
||||
|
@ -131,9 +71,7 @@ int main(int argc, char **argv) {
|
|||
|
||||
// Output the Make time via LEDS
|
||||
temp = (uint8_t)(make_time & 0xFF);
|
||||
LedController_ShowByte(&led_byte, temp);
|
||||
|
||||
SW2_Wait();
|
||||
Deactivate_Relay();
|
||||
|
||||
Timer_Start();
|
||||
|
@ -144,6 +82,13 @@ int main(int argc, char **argv) {
|
|||
|
||||
// Output the Break time via LEDS
|
||||
temp = (uint8_t)(break_time & 0xFF);
|
||||
LedController_ShowByte(&led_byte, temp);
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
//Setup for Infinite Loop
|
||||
SuperLoop_SetIterations(0);
|
||||
SuperLoop_Run();
|
||||
}
|
||||
|
|
|
@ -1,10 +0,0 @@
|
|||
# TEST_RUNNER
|
||||
add_library(test_LedController
|
||||
test_LedController.cpp
|
||||
)
|
||||
|
||||
target_link_libraries(test_LedController
|
||||
${CPPUTEST_LIBRARIES}/libCppUTest.a
|
||||
${CPPUTEST_LIBRARIES}/libCppUTestExt.a
|
||||
LedController
|
||||
)
|
|
@ -1,161 +0,0 @@
|
|||
/*
|
||||
* Author: username
|
||||
* Date: todays_date
|
||||
* filename: test_LedController.c
|
||||
* description: module_purpose
|
||||
*/
|
||||
|
||||
#include "CppUTest/CommandLineTestRunner.h"
|
||||
|
||||
extern "C"
|
||||
{
|
||||
#include "LedController.h"
|
||||
}
|
||||
|
||||
TEST_GROUP(test_LedController)
|
||||
{
|
||||
void setup()
|
||||
{
|
||||
|
||||
}
|
||||
void teardown()
|
||||
{
|
||||
|
||||
}
|
||||
};
|
||||
|
||||
TEST(test_LedController, selftest)
|
||||
{
|
||||
CHECK_TRUE(true);
|
||||
}
|
||||
|
||||
|
||||
TEST(test_LedController, LedSetHighWorks)
|
||||
{
|
||||
uint8_t fake_port = 0x00;
|
||||
|
||||
Led fake_led;
|
||||
fake_led.port = &fake_port;
|
||||
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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
TEST(test_LedController, LedByteDisplay)
|
||||
{
|
||||
uint8_t fake_port = 0x00;
|
||||
uint8_t byte = 0xFF;
|
||||
LedByte led_byte = LedController_New(&fake_port);
|
||||
|
||||
LedController_ShowByte(&led_byte, byte);
|
||||
|
||||
for(int i = 0; i < 8; i++){
|
||||
CHECK_TRUE(led_byte.leds[i].state);
|
||||
}
|
||||
|
||||
CHECK_EQUAL(0xFF, fake_port);
|
||||
|
||||
}
|
||||
|
||||
TEST(test_LedController, LedByteDisplayPattern)
|
||||
{
|
||||
uint8_t fake_port = 0x00;
|
||||
uint8_t byte = 0xAA;
|
||||
LedByte led_byte = LedController_New(&fake_port);
|
||||
|
||||
|
||||
LedController_ShowByte(&led_byte, byte);
|
||||
|
||||
for(int i = 0; i < 8; i++){
|
||||
if(byte & (1<<i)) {
|
||||
CHECK_TRUE(led_byte.leds[i].state);
|
||||
}
|
||||
else {
|
||||
CHECK_TRUE(!led_byte.leds[i].state);
|
||||
}
|
||||
}
|
||||
|
||||
CHECK_EQUAL(0xAA, fake_port);
|
||||
}
|
||||
|
||||
TEST(test_LedController, ClearingLedByteWorks)
|
||||
{
|
||||
uint8_t fake_port = 0xFF;
|
||||
LedByte led_byte = LedController_New(&fake_port);
|
||||
|
||||
for(int i = 0; i < 8; i++){
|
||||
led_byte.leds[i].state = true;
|
||||
}
|
||||
|
||||
LedControler_ClearByte(&led_byte);
|
||||
|
||||
for(int i = 0; i < 8; i++){
|
||||
CHECK_TRUE(!led_byte.leds[i].state);
|
||||
/*loop body*/
|
||||
}
|
||||
|
||||
CHECK_EQUAL(0x00, fake_port);
|
||||
}
|
Loading…
Reference in New Issue