Compare commits

..

No commits in common. "2b45d7004486886512bbb1e47e905319928217ac" and "624b57e56aa79086a257fefbbfd47d84564005dc" have entirely different histories.

8 changed files with 147 additions and 134 deletions

View file

@ -5,6 +5,7 @@
* description: Abstract LED interface and control. * description: Abstract LED interface and control.
*/ */
#ifndef __AVR_ATtiny404__ #ifndef __AVR_ATtiny404__
#define __AVR_ATtiny404__ #define __AVR_ATtiny404__
#endif #endif
@ -21,11 +22,17 @@
#define HALF_BYTE_BM #define HALF_BYTE_BM
typedef struct LedController {
void *port;
uint8_t pins[BITS_IN_BYTE];
}LedController;
static LedController controller;
//static LedController controller;
void LedControler_SetPortADefault(void); void LedControler_SetPortADefault(void);
/* /*
* Uses pins: 9, 8, 12, 13 * Uses pins: 9, 8, 12, 13
*/ */
@ -38,6 +45,7 @@ void LedController_SetLedBitNum(void *port, uint8_t pin, uint8_t bit);
void LedController_ShowByte(uint8_t byte); void LedController_ShowByte(uint8_t byte);
void LedControler_ShowHalfByte(uint8_t byte) void LedControler_ShowHalfByte(uint8_t byte)
{ {
byte = byte & 0x0F; byte = byte & 0x0F;
@ -52,24 +60,21 @@ void LedControler_ShowHalfByte(uint8_t byte)
// 15 = 0b1111 // 15 = 0b1111
//PORTA.OUT |= (byte & 0x0F); //PORTA.OUT |= (byte & 0x0F);
if (byte & 0x01) if(byte & 0x01){
{
PORTA.OUT |= PA_B1; PORTA.OUT |= PA_B1;
} }
if (byte & 0x02) if(byte & 0x02){
{
PORTA.OUT |= PA_B2; PORTA.OUT |= PA_B2;
} }
if (byte & 0x04) if(byte & 0x04){
{
PORTA.OUT |= PA_B3; PORTA.OUT |= PA_B3;
} }
if (byte & 0x08) if(byte & 0x08){
{
PORTA.OUT |= PA_B4; PORTA.OUT |= PA_B4;
} }
} }
void LedControler_ClearHalfByte(void) void LedControler_ClearHalfByte(void)
{ {
//PORTA.OUT &= HALF_BYTE_BM; //PORTA.OUT &= HALF_BYTE_BM;

View file

@ -10,20 +10,8 @@
#ifndef LEDCONTROLLER #ifndef LEDCONTROLLER
#define LEDCONTROLLER #define LEDCONTROLLER
#include <stdint.h> #include <stdint.h>
#include "stdbool.h"
/**
* A structure representing an LED
*/
typedef struct Led
{
uint8_t *port;
uint8_t pin_num;
bool state;
}Led;
/** /**
* Sets the default PORTB pins for output. * Sets the default PORTB pins for output.
@ -35,6 +23,7 @@ void LedControler_SetPortADefault(void);
*/ */
void LedControler_SetPortBDefault(void); void LedControler_SetPortBDefault(void);
/** /**
* Allows the setting or changing of which pins represent which bits. * Allows the setting or changing of which pins represent which bits.
* @param port The address of the port. * @param port The address of the port.
@ -48,11 +37,13 @@ void LedController_SetLedBitNum(void *port, uint8_t pin, uint8_t bit);
*/ */
void LedController_ShowByte(uint8_t byte); void LedController_ShowByte(uint8_t byte);
/** /**
* Displays the the first 4 bits of a byte. * Displays the the first 4 bits of a byte.
*/ */
void LedControler_ShowHalfByte(uint8_t byte); void LedControler_ShowHalfByte(uint8_t byte);
/** /**
* Clears out the halfbyte led representation * Clears out the halfbyte led representation
*/ */

View file

@ -15,8 +15,8 @@
// This can prevent issues with utils/delay.h library with the gcc toolchain // This can prevent issues with utils/delay.h library with the gcc toolchain
#define __DELAY_BACKWARD_COMPATIBLE__ #define __DELAY_BACKWARD_COMPATIBLE__
#include "LedController.h"
#include "RegEdit.h" #include "RegEdit.h"
#include "LedController.h"
#include "config.h" #include "config.h"
#include "timer.h" #include "timer.h"
#include <avr/cpufunc.h> /* Required header file */ #include <avr/cpufunc.h> /* Required header file */
@ -28,6 +28,7 @@
#define RELAYPIN (1<<1) #define RELAYPIN (1<<1)
#define RELAYREADINGPIN (1<<2) //It would be better to use PA7 so USART worked #define RELAYREADINGPIN (1<<2) //It would be better to use PA7 so USART worked
//Set the function pointer for the delay func //Set the function pointer for the delay func
void (*Delay_MicroSeconds)(double us) = _delay_us; void (*Delay_MicroSeconds)(double us) = _delay_us;
@ -43,6 +44,7 @@ void SW2_Wait(void)
while(PORTA.IN & SW2PIN){} while(PORTA.IN & SW2PIN){}
} }
void Activate_Relay(void) void Activate_Relay(void)
{ {
PORTA.OUT |= RELAYPIN; PORTA.OUT |= RELAYPIN;
@ -53,22 +55,18 @@ void Deactivate_Relay(void)
PORTA.OUT &= ~RELAYPIN; PORTA.OUT &= ~RELAYPIN;
} }
void WaitForRelayConnect(void) void WaitForRelayConnect(void)
{ {
while (!(PORTB.IN & RELAYREADINGPIN)) while(!(PORTB.IN & RELAYREADINGPIN)){;}
{
;
}
} }
void WaitForRelayDisconnect(void) void WaitForRelayDisconnect(void)
{ {
while (PORTB.IN & RELAYREADINGPIN) while(PORTB.IN & RELAYREADINGPIN){;}
{
;
}
} }
int main(int argc, char **argv) int main(int argc, char **argv)
{ {
PORTA.DIR |= RELAYPIN; PORTA.DIR |= RELAYPIN;
@ -76,12 +74,12 @@ int main(int argc, char **argv)
PORTA.DIR &= ~SW1PIN; PORTA.DIR &= ~SW1PIN;
PORTA.DIR &= ~SW2PIN; PORTA.DIR &= ~SW2PIN;
uint16_t make_time = 0; uint16_t make_time = 0;
uint16_t break_time = 0; uint16_t break_time = 0;
uint8_t temp = 0; uint8_t temp = 0;
while (true) while(true) {
{
SW1_Wait(); SW1_Wait();
Activate_Relay(); Activate_Relay();
@ -132,6 +130,8 @@ int main(int argc, char **argv)
LedControler_ClearHalfByte(); LedControler_ClearHalfByte();
/* /*
USART0_sendString(maketime_msg); USART0_sendString(maketime_msg);
USART0_sendChar((uint8_t)(0xFF & make_time)); USART0_sendChar((uint8_t)(0xFF & make_time));

View file

@ -13,8 +13,8 @@
#endif #endif
#include "timer.h" #include "timer.h"
#include <avr/interrupt.h>
#include <avr/io.h> #include <avr/io.h>
#include <avr/interrupt.h>
#define FCLK_PER 3333333UL #define FCLK_PER 3333333UL
#define DIV8 0x3 #define DIV8 0x3
@ -26,8 +26,10 @@
#define OVERHEAD_TWO 151 #define OVERHEAD_TWO 151
#define OVERHEAD_THREE 75 #define OVERHEAD_THREE 75
static uint16_t overflow_count = 0; static uint16_t overflow_count = 0;
uint16_t Timer_GetOverflowCount(void) uint16_t Timer_GetOverflowCount(void)
{ {
return overflow_count; return overflow_count;
@ -59,6 +61,7 @@ void Timer_Start(void)
TCA0.SINGLE.CTRLA |= TCA_SINGLE_ENABLE_bm; TCA0.SINGLE.CTRLA |= TCA_SINGLE_ENABLE_bm;
} }
void Timer_Disable(void) void Timer_Disable(void)
{ {
cli(); cli();

View file

@ -10,14 +10,15 @@
#ifndef TIMER #ifndef TIMER
#define TIMER #define TIMER
#include "inttypes.h"
#include "stdbool.h" #include "stdbool.h"
#include "inttypes.h"
/** /**
* *
* @param a The first argument * @param a The first argument
*/ */
void Timer_Start(void); void Timer_Start(void);
void Timer_Disable(void); void Timer_Disable(void);

View file

@ -5,6 +5,7 @@
* description: module_purpose * description: module_purpose
*/ */
#ifndef __AVR_ATtiny404__ #ifndef __AVR_ATtiny404__
#define __AVR_ATtiny404__ #define __AVR_ATtiny404__
#endif #endif
@ -20,9 +21,11 @@
//#define F_CPU 3333333UL //#define F_CPU 3333333UL
//#define F_PER F_CPU / 6 //#define F_PER F_CPU / 6
#define F_PER 3333333UL #define F_PER 3333333UL
#define USART0_BAUD_RATE(BAUD_RATE) ((float)(F_PER * 64 / (16 * (float)BAUD_RATE)) + 0.5) #define USART0_BAUD_RATE(BAUD_RATE) ((float)(F_PER * 64 / (16 * (float)BAUD_RATE)) + 0.5)
//RX PIN6, TX PIN7 //RX PIN6, TX PIN7
//ALT: RX PIN12 TX PIN11 //ALT: RX PIN12 TX PIN11
void USART0_Init(void) void USART0_Init(void)
@ -48,6 +51,7 @@ void USART0_Init(void)
void USART0_Alt_Init(void) void USART0_Alt_Init(void)
{ {
//setup Alternate pints on PA1 and PA2 //setup Alternate pints on PA1 and PA2
PORTMUX.CTRLB |= PORTMUX_USART0_ALTERNATE_gc; PORTMUX.CTRLB |= PORTMUX_USART0_ALTERNATE_gc;
PORTA.DIR |= (1<<1); PORTA.DIR |= (1<<1);

View file

@ -15,6 +15,7 @@
*/ */
void USART0_Init(void); void USART0_Init(void);
/** /**
* @brief Initializes the USART0 peripheral on Alternate pins. * @brief Initializes the USART0 peripheral on Alternate pins.
*/ */

View file

@ -25,13 +25,21 @@ TEST_GROUP(test_LedController)
}; };
TEST(test_LedController, LedController_SetHigh) TEST(test_LedController, SpyStructWorks)
{ {
uint8_t fake_port = 0x00; FAIL("Not yet implimented");
Led fake_led;
fake_led.port = &fake_port;
fake_led.pin_num = 0;
fake_led.state = false;
} }
TEST(test_LedController, FirstTest)
{
FAIL("Fail me!");
}
TEST(test_LedController, SecondTest)
{
STRCMP_EQUAL("hello", "world");
LONGS_EQUAL(1, 2);
CHECK(false);
}