Added firmware
This commit is contained in:
parent
b6985b4ac3
commit
24ed427a2b
1
firmware/.gitignore
vendored
Normal file
1
firmware/.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
|||||||
|
magic.hex
|
||||||
11
firmware/Makefile
Normal file
11
firmware/Makefile
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
all:
|
||||||
|
make build
|
||||||
|
make program
|
||||||
|
|
||||||
|
build:
|
||||||
|
avr-gcc main.c -o magic.hex -mmcu=attiny84a -Wall -Wextra -Os
|
||||||
|
|
||||||
|
program:
|
||||||
|
avrdude -p attiny84 -c usbtiny -U flash:w:magic.hex
|
||||||
|
|
||||||
|
.PHONY: all build program
|
||||||
54
firmware/main.c
Normal file
54
firmware/main.c
Normal file
@ -0,0 +1,54 @@
|
|||||||
|
#include <avr/io.h>
|
||||||
|
#include <avr/sleep.h>
|
||||||
|
|
||||||
|
#include <stdint.h>
|
||||||
|
|
||||||
|
int main()
|
||||||
|
{
|
||||||
|
uint8_t input;
|
||||||
|
uint8_t temp;
|
||||||
|
uint8_t count;
|
||||||
|
uint8_t i;
|
||||||
|
|
||||||
|
// Setup
|
||||||
|
PORTA = (1 << PORTA7) | (1 << PORTA6) | (1 << PORTA5) | (1 << PORTA4);
|
||||||
|
DDRA = (1 << DDA7) | (1 << DDA6) | (1 << DDA5) | (1 << DDA4);
|
||||||
|
PORTB = (1 << PORTB2);
|
||||||
|
DDRB = (1 << DDB2);
|
||||||
|
PRR = (1 << PRTIM1) | (1 << PRTIM0) | (1 << PRUSI) | (1 << PRADC);
|
||||||
|
|
||||||
|
// Read Inputs
|
||||||
|
input = PINA;
|
||||||
|
temp = input;
|
||||||
|
count = 0;
|
||||||
|
|
||||||
|
// How many inputs are set
|
||||||
|
for (i = 0; i < 4; ++i)
|
||||||
|
{
|
||||||
|
if (temp & 0x01)
|
||||||
|
{
|
||||||
|
++count;
|
||||||
|
}
|
||||||
|
temp >>= 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
// If none or more than 1 are providing power - do nothing until reboot
|
||||||
|
if (count != 1)
|
||||||
|
{
|
||||||
|
goto end;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Set Upstream Facing Port
|
||||||
|
input = ~input;
|
||||||
|
input <<= 4;
|
||||||
|
PORTA = input;
|
||||||
|
PORTB &= ~(1 << PORTB2);
|
||||||
|
|
||||||
|
end:
|
||||||
|
// Power Down Mode
|
||||||
|
MCUCR = (1 << SM1) | (1 << SE);
|
||||||
|
while (1)
|
||||||
|
{
|
||||||
|
sleep_cpu();
|
||||||
|
}
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user