Compare commits
No commits in common. "2b45d7004486886512bbb1e47e905319928217ac" and "624b57e56aa79086a257fefbbfd47d84564005dc" have entirely different histories.
2b45d70044
...
624b57e56a
8 changed files with 147 additions and 134 deletions
|
|
@ -5,6 +5,7 @@
|
|||
* description: Abstract LED interface and control.
|
||||
*/
|
||||
|
||||
|
||||
#ifndef __AVR_ATtiny404__
|
||||
#define __AVR_ATtiny404__
|
||||
#endif
|
||||
|
|
@ -21,11 +22,17 @@
|
|||
|
||||
#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);
|
||||
|
||||
|
||||
/*
|
||||
* 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 LedControler_ShowHalfByte(uint8_t byte)
|
||||
{
|
||||
byte = byte & 0x0F;
|
||||
|
|
@ -52,24 +60,21 @@ void LedControler_ShowHalfByte(uint8_t byte)
|
|||
// 15 = 0b1111
|
||||
//PORTA.OUT |= (byte & 0x0F);
|
||||
|
||||
if (byte & 0x01)
|
||||
{
|
||||
if(byte & 0x01){
|
||||
PORTA.OUT |= PA_B1;
|
||||
}
|
||||
if (byte & 0x02)
|
||||
{
|
||||
if(byte & 0x02){
|
||||
PORTA.OUT |= PA_B2;
|
||||
}
|
||||
if (byte & 0x04)
|
||||
{
|
||||
if(byte & 0x04){
|
||||
PORTA.OUT |= PA_B3;
|
||||
}
|
||||
if (byte & 0x08)
|
||||
{
|
||||
if(byte & 0x08){
|
||||
PORTA.OUT |= PA_B4;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void LedControler_ClearHalfByte(void)
|
||||
{
|
||||
//PORTA.OUT &= HALF_BYTE_BM;
|
||||
|
|
|
|||
|
|
@ -10,20 +10,8 @@
|
|||
#ifndef LEDCONTROLLER
|
||||
#define LEDCONTROLLER
|
||||
|
||||
|
||||
#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.
|
||||
|
|
@ -35,6 +23,7 @@ void LedControler_SetPortADefault(void);
|
|||
*/
|
||||
void LedControler_SetPortBDefault(void);
|
||||
|
||||
|
||||
/**
|
||||
* Allows the setting or changing of which pins represent which bits.
|
||||
* @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);
|
||||
|
||||
|
||||
/**
|
||||
* Displays the the first 4 bits of a byte.
|
||||
*/
|
||||
void LedControler_ShowHalfByte(uint8_t byte);
|
||||
|
||||
|
||||
/**
|
||||
* Clears out the halfbyte led representation
|
||||
*/
|
||||
|
|
|
|||
22
src/main.c
22
src/main.c
|
|
@ -15,8 +15,8 @@
|
|||
// This can prevent issues with utils/delay.h library with the gcc toolchain
|
||||
#define __DELAY_BACKWARD_COMPATIBLE__
|
||||
|
||||
#include "LedController.h"
|
||||
#include "RegEdit.h"
|
||||
#include "LedController.h"
|
||||
#include "config.h"
|
||||
#include "timer.h"
|
||||
#include <avr/cpufunc.h> /* Required header file */
|
||||
|
|
@ -28,6 +28,7 @@
|
|||
#define RELAYPIN (1<<1)
|
||||
#define RELAYREADINGPIN (1<<2) //It would be better to use PA7 so USART worked
|
||||
|
||||
|
||||
//Set the function pointer for the delay func
|
||||
void (*Delay_MicroSeconds)(double us) = _delay_us;
|
||||
|
||||
|
|
@ -43,6 +44,7 @@ void SW2_Wait(void)
|
|||
while(PORTA.IN & SW2PIN){}
|
||||
}
|
||||
|
||||
|
||||
void Activate_Relay(void)
|
||||
{
|
||||
PORTA.OUT |= RELAYPIN;
|
||||
|
|
@ -53,22 +55,18 @@ void Deactivate_Relay(void)
|
|||
PORTA.OUT &= ~RELAYPIN;
|
||||
}
|
||||
|
||||
|
||||
void WaitForRelayConnect(void)
|
||||
{
|
||||
while (!(PORTB.IN & RELAYREADINGPIN))
|
||||
{
|
||||
;
|
||||
}
|
||||
while(!(PORTB.IN & RELAYREADINGPIN)){;}
|
||||
}
|
||||
|
||||
void WaitForRelayDisconnect(void)
|
||||
{
|
||||
while (PORTB.IN & RELAYREADINGPIN)
|
||||
{
|
||||
;
|
||||
}
|
||||
while(PORTB.IN & RELAYREADINGPIN){;}
|
||||
}
|
||||
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
PORTA.DIR |= RELAYPIN;
|
||||
|
|
@ -76,12 +74,12 @@ int main(int argc, char **argv)
|
|||
PORTA.DIR &= ~SW1PIN;
|
||||
PORTA.DIR &= ~SW2PIN;
|
||||
|
||||
|
||||
uint16_t make_time = 0;
|
||||
uint16_t break_time = 0;
|
||||
uint8_t temp = 0;
|
||||
|
||||
while (true)
|
||||
{
|
||||
while(true) {
|
||||
SW1_Wait();
|
||||
Activate_Relay();
|
||||
|
||||
|
|
@ -132,6 +130,8 @@ int main(int argc, char **argv)
|
|||
|
||||
LedControler_ClearHalfByte();
|
||||
|
||||
|
||||
|
||||
/*
|
||||
USART0_sendString(maketime_msg);
|
||||
USART0_sendChar((uint8_t)(0xFF & make_time));
|
||||
|
|
|
|||
|
|
@ -13,8 +13,8 @@
|
|||
#endif
|
||||
|
||||
#include "timer.h"
|
||||
#include <avr/interrupt.h>
|
||||
#include <avr/io.h>
|
||||
#include <avr/interrupt.h>
|
||||
|
||||
#define FCLK_PER 3333333UL
|
||||
#define DIV8 0x3
|
||||
|
|
@ -26,8 +26,10 @@
|
|||
#define OVERHEAD_TWO 151
|
||||
#define OVERHEAD_THREE 75
|
||||
|
||||
|
||||
static uint16_t overflow_count = 0;
|
||||
|
||||
|
||||
uint16_t Timer_GetOverflowCount(void)
|
||||
{
|
||||
return overflow_count;
|
||||
|
|
@ -59,6 +61,7 @@ void Timer_Start(void)
|
|||
TCA0.SINGLE.CTRLA |= TCA_SINGLE_ENABLE_bm;
|
||||
}
|
||||
|
||||
|
||||
void Timer_Disable(void)
|
||||
{
|
||||
cli();
|
||||
|
|
|
|||
|
|
@ -10,14 +10,15 @@
|
|||
#ifndef TIMER
|
||||
#define TIMER
|
||||
|
||||
#include "inttypes.h"
|
||||
#include "stdbool.h"
|
||||
#include "inttypes.h"
|
||||
|
||||
/**
|
||||
*
|
||||
* @param a The first argument
|
||||
*/
|
||||
|
||||
|
||||
void Timer_Start(void);
|
||||
|
||||
void Timer_Disable(void);
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@
|
|||
* description: module_purpose
|
||||
*/
|
||||
|
||||
|
||||
#ifndef __AVR_ATtiny404__
|
||||
#define __AVR_ATtiny404__
|
||||
#endif
|
||||
|
|
@ -20,9 +21,11 @@
|
|||
//#define F_CPU 3333333UL
|
||||
//#define F_PER F_CPU / 6
|
||||
|
||||
|
||||
#define F_PER 3333333UL
|
||||
#define USART0_BAUD_RATE(BAUD_RATE) ((float)(F_PER * 64 / (16 * (float)BAUD_RATE)) + 0.5)
|
||||
|
||||
|
||||
//RX PIN6, TX PIN7
|
||||
//ALT: RX PIN12 TX PIN11
|
||||
void USART0_Init(void)
|
||||
|
|
@ -48,6 +51,7 @@ void USART0_Init(void)
|
|||
|
||||
void USART0_Alt_Init(void)
|
||||
{
|
||||
|
||||
//setup Alternate pints on PA1 and PA2
|
||||
PORTMUX.CTRLB |= PORTMUX_USART0_ALTERNATE_gc;
|
||||
PORTA.DIR |= (1<<1);
|
||||
|
|
|
|||
|
|
@ -15,6 +15,7 @@
|
|||
*/
|
||||
void USART0_Init(void);
|
||||
|
||||
|
||||
/**
|
||||
* @brief Initializes the USART0 peripheral on Alternate pins.
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -25,13 +25,21 @@ TEST_GROUP(test_LedController)
|
|||
};
|
||||
|
||||
|
||||
TEST(test_LedController, LedController_SetHigh)
|
||||
TEST(test_LedController, SpyStructWorks)
|
||||
{
|
||||
uint8_t fake_port = 0x00;
|
||||
|
||||
Led fake_led;
|
||||
fake_led.port = &fake_port;
|
||||
fake_led.pin_num = 0;
|
||||
fake_led.state = false;
|
||||
|
||||
FAIL("Not yet implimented");
|
||||
}
|
||||
|
||||
|
||||
TEST(test_LedController, FirstTest)
|
||||
{
|
||||
FAIL("Fail me!");
|
||||
}
|
||||
|
||||
TEST(test_LedController, SecondTest)
|
||||
{
|
||||
STRCMP_EQUAL("hello", "world");
|
||||
LONGS_EQUAL(1, 2);
|
||||
CHECK(false);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue