Added the projects

This commit is contained in:
2014-12-19 12:29:06 +01:00
parent 9c04c8f3f3
commit 868f28bff1
132 changed files with 19205 additions and 18 deletions
@@ -0,0 +1,158 @@
MCU = atmega328p
F_CPU = 16000000
LFUSE = 0xFF
HFUSE = 0xDE
EFUSE = 0x05
MAIN = main.c
## If you've split your program into multiple files,
## include the additional .c source (in same directory) here
## (and include the .h files in your foo.c)
LOCAL_SOURCE =
## Here you can link to one more directory (and multiple .c files)
# EXTRA_SOURCE_DIR = ../AVR-Programming-Library/
EXTRA_SOURCE_DIR =
EXTRA_SOURCE_FILES =
##########------------------------------------------------------##########
########## Programmer Defaults ##########
########## Set up once, then forget about it ##########
########## (Can override. See bottom of file.) ##########
##########------------------------------------------------------##########
#19200
PROGRAMMER_TYPE = arduino
PROGRAMMER_ARGS = -b 57600 -P /dev/ttyUSB0
##########------------------------------------------------------##########
########## Makefile Magic! ##########
########## Summary: ##########
########## We want a .hex file ##########
########## Compile source files into .elf ##########
########## Convert .elf file into .hex ##########
########## You shouldn't need to edit below. ##########
##########------------------------------------------------------##########
## Defined programs / locations
CC = avr-gcc
OBJCOPY = avr-objcopy
OBJDUMP = avr-objdump
AVRSIZE = avr-size
AVRDUDE = sudo avrdude
## Compilation options, type man avr-gcc if you're curious.
CFLAGS = -std=gnu99 -mmcu=$(MCU) -DF_CPU=$(F_CPU)UL -Os -I. -I$(EXTRA_SOURCE_DIR)
CFLAGS += -funsigned-char -funsigned-bitfields -fpack-struct -fshort-enums
CFLAGS += -Wall -Wstrict-prototypes -Wno-main -Wno-strict-prototypes -Wno-comment
CFLAGS += -g2 -ggdb
CFLAGS += -ffunction-sections -fdata-sections -Wl,--gc-sections -Wl,--relax
CFLAGS += -std=gnu99
# CFLAGS += -lm
## CFLAGS += -Wl,-u,vfprintf -lprintf_flt -lm ## for floating-point printf
## CFLAGS += -Wl,-u,vfprintf -lprintf_min ## for smaller printf
## Lump target and extra source files together
TARGET = $(strip $(basename $(MAIN)))
SRC = $(TARGET).c
EXTRA_SOURCE = $(addprefix $(EXTRA_SOURCE_DIR), $(EXTRA_SOURCE_FILES))
SRC += $(EXTRA_SOURCE)
SRC += $(LOCAL_SOURCE)
## List of all header files
HEADERS = $(SRC:.c=.h)
## For every .c file, compile an .o object file
OBJ = $(SRC:.c=.o)
## Generic Makefile targets. (Only .hex file is necessary)
all: $(TARGET).hex size
%.hex: %.elf
$(OBJCOPY) -R .eeprom -O ihex $< $@
%.elf: $(SRC)
$(CC) $(CFLAGS) $(SRC) --output $@
%.eeprom: %.elf
$(OBJCOPY) -j .eeprom --change-section-lma .eeprom=0 -O ihex $< $@
debug:
@echo
@echo "Source files:" $(SRC)
@echo "MCU, F_CPU, BAUD:" $(MCU), $(F_CPU), $(BAUD)
@echo
# Optionally create listing file from .elf
# This creates approximate assembly-language equivalent of your code.
# Useful for debugging time-sensitive bits,
# or making sure the compiler does what you want.
disassemble: $(TARGET).lst
dis: disassemble
eeprom: $(TARGET).eeprom
%.lst: %.elf
$(OBJDUMP) -S $< > $@
# Optionally show how big the resulting program is
size: $(TARGET).elf
$(AVRSIZE) -C --mcu=$(MCU) $(TARGET).elf
clean:
rm -f $(TARGET).elf $(TARGET).hex $(TARGET).obj \
$(TARGET).o $(TARGET).d $(TARGET).eep $(TARGET).lst \
$(TARGET).lss $(TARGET).sym $(TARGET).map $(TARGET)~ \
$(TARGET).eeprom
squeaky_clean:
rm -f *.elf *.hex *.obj *.o *.d *.eep *.lst *.lss *.sym *.map *~
##########------------------------------------------------------##########
########## Programmer-specific details ##########
########## Flashing code to AVR using avrdude ##########
##########------------------------------------------------------##########
flash: $(TARGET).hex
$(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) $(PROGRAMMER_ARGS) -U flash:w:$<
flash_eeprom: $(TARGET).eeprom
$(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) $(PROGRAMMER_ARGS) -U eeprom:w:$<
terminal:
$(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) $(PROGRAMMER_ARGS) -nt
flash_arduino: PROGRAMMER_TYPE = arduino
flash_arduino: PROGRAMMER_ARGS =
flash_arduino: flash
flash_dragon_isp: PROGRAMMER_TYPE = dragon_isp
flash_dragon_isp: PROGRAMMER_ARGS =
flash_dragon_isp: flash
##########------------------------------------------------------##########
########## Fuse settings and suitable defaults ##########
##########------------------------------------------------------##########
## Generic
FUSE_STRING = -U lfuse:w:$(LFUSE):m -U hfuse:w:$(HFUSE):m -U efuse:w:$(EFUSE):m
fuses:
$(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) \
$(PROGRAMMER_ARGS) $(FUSE_STRING)
show_fuses:
$(AVRDUDE) -c $(PROGRAMMER_TYPE) -p $(MCU) $(PROGRAMMER_ARGS) -nv
## Called with no extra definitions, sets to defaults
set_default_fuses: FUSE_STRING = -U lfuse:w:$(LFUSE):m -U hfuse:w:$(HFUSE):m -U efuse:w:$(EFUSE):m
set_default_fuses: fuses
@@ -0,0 +1,91 @@
#pragma once
#include <avr/io.h>
#define D0 0
#define D1 1
#define D2 2
#define D3 3
#define D4 4
#define D5 5
#define D6 6
#define D7 7
#define D8 0
#define D9 1
#define D10 2
#define D11 3
#define D12 4
#define D13 5
#define A0 0
#define A1 1
#define A2 2
#define A3 3
#define A4 4
#define A5 5
// port definitions
#define PORT_D0 PORTD
#define PORT_D1 PORTD
#define PORT_D2 PORTD
#define PORT_D3 PORTD
#define PORT_D4 PORTD
#define PORT_D5 PORTD
#define PORT_D6 PORTD
#define PORT_D7 PORTD
#define PORT_D8 PORTB
#define PORT_D9 PORTB
#define PORT_D10 PORTB
#define PORT_D11 PORTB
#define PORT_D12 PORTB
#define PORT_D13 PORTB
#define PORT_A0 PORTC
#define PORT_A1 PORTC
#define PORT_A2 PORTC
#define PORT_A3 PORTC
#define PORT_A4 PORTC
#define PORT_A5 PORTC
#define PIN_D0 PIND
#define PIN_D1 PIND
#define PIN_D2 PIND
#define PIN_D3 PIND
#define PIN_D4 PIND
#define PIN_D5 PIND
#define PIN_D6 PIND
#define PIN_D7 PIND
#define PIN_D8 PINB
#define PIN_D9 PINB
#define PIN_D10 PINB
#define PIN_D11 PINB
#define PIN_D12 PINB
#define PIN_D13 PINB
#define PIN_A0 PINC
#define PIN_A1 PINC
#define PIN_A2 PINC
#define PIN_A3 PINC
#define PIN_A4 PINC
#define PIN_A5 PINC
#define DDR_D0 DDRD
#define DDR_D1 DDRD
#define DDR_D2 DDRD
#define DDR_D3 DDRD
#define DDR_D4 DDRD
#define DDR_D5 DDRD
#define DDR_D6 DDRD
#define DDR_D7 DDRD
#define DDR_D8 DDRB
#define DDR_D9 DDRB
#define DDR_D10 DDRB
#define DDR_D11 DDRB
#define DDR_D12 DDRB
#define DDR_D13 DDRB
#define DDR_A0 DDRC
#define DDR_A1 DDRC
#define DDR_A2 DDRC
#define DDR_A3 DDRC
#define DDR_A4 DDRC
#define DDR_A5 DDRC
#define OUT 1
#define IN 0
@@ -0,0 +1,114 @@
#include <avr/io.h>
#include <avr/interrupt.h>
#include <avr/pgmspace.h>
#include <avr/cpufunc.h>
#include <util/delay.h>
#include <util/delay_basic.h>
#include <stdbool.h>
#include <stdint.h>
#include <math.h>
#include "utils.h"
#include "arduino_pins.h"
#define WS_PORT PORT_D8
#define WS_BIT D8
#define WS_DDR DDR_D8
#define ws_high() sbi(WS_PORT, WS_BIT)
#define ws_low() cbi(WS_PORT, WS_BIT)
#define T1H 800 // Width of a 1 bit in ns
#define T1L 450 // Width of a 1 bit in ns
#define T0H 200 // Width of a 0 bit in ns
#define T0L 650 // Width of a 0 bit in ns
#define RES 50000 // Width of the low gap between bits to cause a frame to latch
#define NS_PER_SEC (1000000000L) // Note that this has to be SIGNED since we want to be able to check for negative values of derivatives
#define CYCLES_PER_SEC (16000000L)
#define NS_PER_CYCLE ( NS_PER_SEC / CYCLES_PER_SEC )
#define NS_TO_CYCLES(n) ( (n) / NS_PER_CYCLE )
#define DELAY_CYCLES(n) ( ((n)>0) ? __builtin_avr_delay_cycles( n ) : __builtin_avr_delay_cycles( 0 ) ) // Make sure we never have a delay less than zero
void ws_show()
{
ws_low();
DELAY_CYCLES( NS_TO_CYCLES(RES) );
}
void ws_send_byte(uint8_t bb)
{
for (int8_t i = 7; i >= 0; --i) {
if (bb & (1 << i)) {
ws_high();
DELAY_CYCLES( NS_TO_CYCLES( T1H ) - 2 );
ws_low();
DELAY_CYCLES( NS_TO_CYCLES( T1L ) - 10 );
} else {
ws_high();
DELAY_CYCLES( NS_TO_CYCLES( T0H ) - 2 );
ws_low();
DELAY_CYCLES( NS_TO_CYCLES( T0L ) - 10 );
}
}
}
void ws_send_rgb(uint8_t r, uint8_t g, uint8_t b)
{
ws_send_byte(g);
ws_send_byte(r);
ws_send_byte(b);
}
void init_io(void) SECTION(".init8");
void init_io()
{
set_bit(WS_DDR, WS_BIT, OUT);
}
void main()
{
while (1) {
uint8_t r = 250;
uint8_t g = 0;
uint8_t b = 0;
uint8_t step = 0;
for (uint8_t i = 0; i < 30; i++) {
ws_send_rgb(r, g, b);
switch (step) {
case 0:
r -= 50;
g += 50;
if (g == 250) step++;
break;
case 1:
g -= 50;
b += 50;
if (b == 250) step++;
break;
case 2:
b -= 50;
r += 50;
if (r == 250) step=0;
break;
}
}
// ws_send_rgb(0x00, 0xFF, 0);
ws_show();
}
}
@@ -0,0 +1,15 @@
#pragma once
#include <avr/io.h>
// general macros
#define SECTION(pos) __attribute__((naked, used, section(pos)))
// pin manipulation
#define sbi(port, bit) (port) |= _BV(bit)
#define cbi(port, bit) (port) &= ~ _BV(bit)
#define set_bit(port, bit, value) (port) = (((port) & ~_BV(bit)) | ((value) << (bit)))
#define get_bit(port, bit) (((port) >> (bit)) & 1)
#define bus_pulse(port, bit) { sbi(port, bit); cbi(port, bit); }