Migrating repo.

This commit is contained in:
2018-06-06 09:26:03 +00:00
parent 12b5c26652
commit 4abcd2df5a
23 changed files with 41245 additions and 0 deletions

108
firmware/Makefile Normal file
View File

@@ -0,0 +1,108 @@
# GNU/Linux specific Make directives.
# Declare tools.
SHELL = /bin/sh
CC = avr-gcc
LD = avr-gcc
OBJCOPY = avr-objcopy
ECHO = @echo -e
# CHANGE HERE FOR YOUR PROJECT
MCU = attiny13a
MCUPROG = ATtiny13
ARCH =
SOURCES = main.c
# Programmer sepcs
SOFTPROGRAM = avrdude
HARDPROGRAM = buspirate
PORT = /dev/ttyUSB0
CFLAGS = -mmcu=$(MCU) -Os -std=c99
LDFLAGS = -mmcu=$(MCU)
OBJFLAGS = -j .text -j .data -O ihex
EXECUTABLE = firmware
OBJECTS = $(SOURCES:.c=.o)
CLEANFILES = main.o main.asm main.map main.lst main.cod $(EXECUTABLE).elf
# To get a fully verbose make output do declare 'AT' at the command line like so: 'make AT='.
# By default AT is undefined and thus assigned the string '@' which suppresses output from commands.
AT ?= @
# Colors and efects
#######################################
NORMAL = \033[m
FG_BLACK = \033[30m
FG_DKRED = \033[31m
FG_DKGREEN = \033[32;7m
FG_DKYELLOW = \033[33m
FG_DKBLUE = \033[34m
FG_DKMAGENTA = \033[35m
FG_DKCYAN = \033[36m
FG_GRAY = \033[37m
FG_DKGRAY = \033[30;1m
FG_REDFULL = \033[31;7m
FG_GREEN = \033[32;1m
FG_YELLOW = \033[33;7m
FG_BLUE = \033[34;7m
FG_MAGENTA = \033[35;1m
FG_CYAN = \033[36;1m
FG_WHITE = \033[37;1m
BG_BLACK = \033[40m
BG_DKRED = \033[41m
BG_DKGREEN = \033[42m
BG_DKYELLOW = \033[43m
BG_DKBLUE = \033[44m
BG_DKMAGENTA = \033[45m
BG_DKCYAN = \033[46m
BG_GRAY = \033[47m
BG_DKGRAY = \033[40;1m
BG_RED = \033[41;1m
BG_GREEN = \033[42;1m
BG_YELLOW = \033[43;1m
BG_BLUE = \033[44;1m
BG_MAGENTA = \033[45;1m
BG_CYAN = \033[46;1m
BG_WHITE = \033[47;1m
##########################################
.SUFFIXES: .c .o
.PHONY: clean
# Compile
all: $(EXECUTABLE)
.c.o:
$(ECHO) "[$(FG_BLUE)COMPILING$(NORMAL)] $@"
$(AT) $(CC) $(CFLAGS) -o $*.o -c $<
$(EXECUTABLE): $(OBJECTS)
$(ECHO) "[$(FG_YELLOW)LINKING$(NORMAL)] $(EXECUTABLE).elf"
$(AT) $(LD) $(LDFLAGS) $(OBJECTS) -o $(EXECUTABLE).elf
$(ECHO) "[$(FG_YELLOW)BUILDING$(NORMAL)] $(EXECUTABLE).hex"
$(AT) $(OBJCOPY) $(OBJFLAGS) $(EXECUTABLE).elf $(EXECUTABLE).hex
$(ECHO) "[$(FG_DKGREEN)SUCCESS$(NORMAL)]"
clean:
$(ECHO) "[$(FG_REDFULL)CLEANED$(NORMAL)] $(CLEANFILES)"
$(AT) rm -rf $(CLEANFILES)
flash:
$(AT) $(SOFTPROGRAM) -p $(MCUPROG) -c $(HARDPROGRAM) -P $(PORT) -e -U flash:w:$(EXECUTABLE).hex
$(ECHO) "[$(FG_WHITE)PROGRAMMED$(NORMAL)]"

55
firmware/firmware.hex Normal file
View File

@@ -0,0 +1,55 @@
:1000000009C021C034C01FC01EC01DC01CC01BC001
:100010001AC019C011241FBECFE9CDBF10E0A0E661
:10002000B0E0E2E4F3E002C005900D92AE36B10715
:10003000D9F720E0AEE6B0E001C01D92AF36B207BE
:10004000E1F751D07CC1DCCFE82FF0E0E05AFF4F60
:100050008081982F9F7097BB082E000C990B24E08D
:10006000959587952A95E1F78F7088BB08951F9223
:100070000F920FB60F9211240F931F932F933F935C
:100080004F935F936F937F938F939F93AF93BF93A0
:10009000CF93EF93FF93C9E107E010E0D6D0B8010A
:1000A00063D08F5F80936900CFDF8FE295E7019780
:1000B000F1F700C00000C15089F710926E00FF9167
:1000C000EF91CF91BF91AF919F918F917F916F9160
:1000D0005F914F913F912F911F910F910F900FBE04
:1000E0000F901F9018958BB780628BBFAC9A789455
:1000F000BC9885B7877E806185BF81E090E0B4D0F1
:10010000C1E0C80F6C2F81E090E0B5D08C2F90E05B
:10011000A0D010926E0080916E00883240F085B7BA
:10012000806285BF889585B78F7D85BFF2CF80912E
:1001300069008ADF2FE389E191E0215080409040FF
:10014000E1F700C0000080E07FDF2FE389E191E06C
:10015000215080409040E1F700C0000080916E0087
:100160008F5F80936E00D7CF97FB072E16F4009415
:1001700006D077FD08D00BD007FC05D03EF4909553
:1001800081959F4F0895709561957F4F0895AA1BA3
:10019000BB1B51E107C0AA1FBB1FA617B70710F072
:1001A000A61BB70B881F991F5A95A9F780959095A4
:1001B000BC01CD0108958F929F92AF92BF92CF92D2
:1001C000DF92EF92FF92CF93DF93EC016881798108
:1001D0008A819B81611571058105910521F464E295
:1001E00079ED8BE597E02DE133EF41E050E069D008
:1001F00049015A0127EA31E440E050E049D06B015F
:100200007C012CEE34EF4FEF5FEFC501B40140D01D
:10021000DC01CB018C0D9D1DAE1DBF1DB7FF03C0C2
:100220000197A109B04888839983AA83BB839F77EC
:10023000DF91CF91FF90EF90DF90CF90BF90AF9084
:100240009F908F900895B7DF08958AE690E0B3DF1E
:100250000895A0E0B0E080936A0090936B00A093B3
:100260006C00B0936D000895E199FECF8EBBE09ACB
:1002700099278DB30895262FE199FECF1CBA8EBB26
:100280002DBB0FB6F894E29AE19A0FBE019608953D
:10029000EE27FF27AA27BB2708C0A20FB31FE41F22
:1002A000F51F220F331F441F551F9695879577958D
:1002B000679598F37040A9F7009799F7BD01CF01B2
:1002C0000895052E97FB16F400940FD057FD05D026
:1002D00014D007FC02D046F408C0509540953095E4
:1002E00021953F4F4F4F5F4F0895909580957095A2
:1002F00061957F4F8F4F9F4F0895A1E21A2EAA1B41
:10030000BB1BFD010DC0AA1FBB1FEE1FFF1FA217C5
:10031000B307E407F50720F0A21BB30BE40BF50BC2
:10032000661F771F881F991F1A9469F7609570954B
:10033000809590959B01AC01BD01CF010895F89483
:02034000FFCFED
:0E0342000013264C23468C45150701000000D1
:00000001FF

62
firmware/main.c Normal file
View File

@@ -0,0 +1,62 @@
/*
www.electropepper.org
Beerright 2017.
*/
#include "main.h"
#define diceDelay 100 // LED speed change while shuffling
#define toggleDelay 300 // LED speed when stoped
#define none 0
int main(int argc, char **argv)
{
GIMSK |= _BV(PCIE); // Enable pin change interrupt
PCMSK |= _BV(PB4); // Enable PORTB4 for pin change interrupt
sei(); // Enable global interrupts
DDRB &= ~_BV(PB4); // Set PORTB4 to input
set_sleep_mode(SLEEP_MODE_PWR_DOWN); // Set sleep mode for Power-down(see datasheet)
uint8_t randSeed = eeprom_read_byte ((uint8_t*)1); // Reads eeprom byte 1, value
// into variable randSeed
++randSeed; // Increments it
eeprom_write_byte ((uint8_t*)1, randSeed); // Writes value back into
// eeprom byte 1
srand (randSeed); // Creates seed for random number
// generator from randSeed value
while (1) {
for (stand_cycle = 0; stand_cycle < 40; stand_cycle++){ // Repeats 40 times next 4 lines
what_led(cur_led); // Turn ON LED number inside variable cur_led
_delay_ms(toggleDelay); // Wait
what_led(none); // Truen off all LED's
_delay_ms(toggleDelay); // Wait
}
sleep_mode(); // Go into sleep mode to save power, will came back alive
// after interrupt is generated
}
}
ISR(PCINT0_vect) // Interrupt routine on pin change
{
for (uint8_t i = 0; i < 25; i++){ // Repeats 25 times next 3 lines
cur_led = ((rand() % 7) + 1); // Creates random integer from 0 to 6 into cur_led
what_led(cur_led); // Turn ON LED number inside variable cur_led
_delay_ms(diceDelay); // Wait
}
stand_cycle = 0; // Resets the standby blinking times
}
void what_led(uint8_t led)
{
int8_t ledN = led_table[led]; // Reads led_table given number(led) into ledN
DDRB = ledN & 0x0F; // Copy first ledN nibble into DDRB
ledN = (ledN & 0xF0) >> 4; // Move second nibble into first nibble
PORTB = ledN & 0x0F; // Copy first ledN nibble into PORTB
}

57
firmware/main.h Normal file
View File

@@ -0,0 +1,57 @@
#ifndef __MAIN_H_
#define __MAIN_H_
#define F_CPU 1200000UL // Chip left with
// default factory fuse values
// Low = 0x6A
// High = 0xFF
// Internal oscillator on 9.6MHZ with
// clock divided by 8, thus making
// making CPU to run at 1.2MHZ
#include <avr/io.h>
#include <avr/interrupt.h>
#include <avr/eeprom.h>
#include <avr/sleep.h>
#include <util/delay.h>
#include <stdlib.h>
// Global Variable declarations --------------
uint8_t cur_led = 7; // This will hold the
// current LED that is
// turned ON, starting
// with the central LED
// number 7
uint8_t stand_cycle = 0; // Saves the
// standby number of
// times will blink
uint8_t led_table[9] = { // Table that
// holds the first
// nibble for DDRB
// and second nibble
// for PORTB
0b00000000, // Led's off
0b00010011, // Led 1
0b00100110, // Led 2
0b01001100, // Led 3
0b00100011, // Led 4
0b01000110, // Led 5
0b10001100, // Led 6
0b01000101, // Led 7
0b00010101 // Led tester point
};
// -------------------------------------------
// Functions declarations --------------------
void what_led(uint8_t led); // Function to
// turn ON given
// led number with
// charlieplex
// -------------------------------------------
#endif