Skip to content

Commit

Permalink
init
Browse files Browse the repository at this point in the history
  • Loading branch information
QuintusJoyal committed Apr 19, 2024
0 parents commit 7b9a04f
Show file tree
Hide file tree
Showing 7 changed files with 1,549 additions and 0 deletions.
24 changes: 24 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
on:
workflow_dispatch:
push:
pull_request:

permissions:
contents: read
pull-requests: read

jobs:
build:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v3
- name: install avr tool chain
run: |
apt update && apt install -y \
avrdude \
gcc-avr \
gdb-avr \
avr-libc \
binutils-avr
- name: make
run: make all
55 changes: 55 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
build/
.vscode/

# Prerequisites
*.d

# Object files
*.o
*.ko
*.obj
*.elf

# Linker output
*.ilk
*.map
*.exp

# Precompiled Headers
*.gch
*.pch

# Libraries
*.lib
*.a
*.la
*.lo

# Shared objects (inc. Windows DLLs)
*.dll
*.so
*.so.*
*.dylib

# Executables
*.exe
*.out
*.app
*.i*86
*.x86_64
*.hex

# Debug files
*.dSYM/
*.su
*.idb
*.pdb

# Kernel Module Compile Results
*.mod*
*.cmd
.tmp_versions/
modules.order
Module.symvers
Mkfile.old
dkms.conf
70 changes: 70 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
# AVR project Makefile

# Microcontroller
MCU = atmega328p

# F_CPU (in Hz)
F_CPU = 16000000UL

# Programmer
PROGRAMMER = -c arduino -P /dev/ttyACM0 -b 115200

# Compiler
CC = avr-gcc
OBJCOPY = avr-objcopy
OBJDUMP = avr-objdump
SIZE = avr-size
AVRDUDE = avrdude

# Compiler flags
CFLAGS = -g -Wall -Os -mmcu=$(MCU) -DF_CPU=$(F_CPU) -fexceptions

# Source directory
SRC_DIR = src

# Build directory
BUILD_DIR = build

# Source files
SRCS = main.c $(wildcard $(SRC_DIR)/libs/**/*.c)

# Object files
OBJS = $(patsubst $(SRC_DIR)/%.c,$(BUILD_DIR)/%.o,$(SRCS))

# Output files
TARGET = main
ELF = $(TARGET).elf
HEX = $(TARGET).hex
MAP = $(TARGET).map
EEP = $(TARGET).eep

# Rules
all: $(HEX)

$(HEX): $(ELF)
$(OBJCOPY) -O ihex -R .eeprom $(ELF) $(HEX)

$(ELF): $(OBJS)
$(CC) $(CFLAGS) $(OBJS) -o $(ELF)
$(OBJDUMP) -h -S $(ELF) > $(MAP)
$(SIZE) --format=avr --mcu=$(MCU) $(ELF)

$(BUILD_DIR)/%.o: $(SRC_DIR)/%.c | $(BUILD_DIR) $(dir $(OBJS))
$(CC) $(CFLAGS) -c $< -o $@

$(BUILD_DIR):
mkdir -p $(BUILD_DIR)

$(dir $(OBJS)):
mkdir -p $@

flash: $(HEX)
$(AVRDUDE) $(PROGRAMMER) -p $(MCU) -U flash:w:$(HEX):i

eeprom: $(EEP)
$(AVRDUDE) $(PROGRAMMER) -p $(MCU) -U eeprom:w:$(EEP):i

clean:
rm -rf $(BUILD_DIR) $(ELF) $(HEX) $(MAP) $(EEP)

.PHONY: all flash eeprom clean
113 changes: 113 additions & 0 deletions main.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
#define F_CPU 16000000UL
#define BAUDRATE 115200

#define VOL_UP 25
#define VOL_DOWN 22
#define CH_UP 21
#define CH_DOWN 7
#define RESET 69

#include <avr/io.h>
#include <util/delay.h>
#include <avr/interrupt.h>
#include "./src/libs/uart.h"
#include "./src/libs/IRremote.h"
#include "./src/libs/softwarePWM.h"

uint8_t brightness = 255;
uint8_t level = 0;

void LED_brightness() {
for (uint8_t i = 0; i < 7; i++) {
softwarePWM_Set(i, brightness);
}
}

void LED_turn_on(uint8_t led) {
softwarePWM_Set(led, brightness);
}

void LED_turn_off(uint8_t led) {
softwarePWM_Set(led, 0);
}

void RGB_toggle() {
uint8_t m = (level - 1) % 3;
softwarePWM_Set(4, brightness * (m == 0));
softwarePWM_Set(5, brightness * (m == 1));
softwarePWM_Set(6, brightness * (m == 2));
}

void vol_up() {
if (level >= 7) {
RGB_toggle();
level = (level % 3) ? level + 1 : 7;
return;
}
LED_turn_on(level++);
}

void vol_down() {
if (level >= 7) {
RGB_toggle();
--level;
return;
}
if (level == 5) {
LED_turn_on(4);
LED_turn_on(5);
LED_turn_on(6);
--level;
return;
}
if (level) LED_turn_off(--level);
}

void ch_up() {
brightness += (bool)level * 15;
if (brightness >= 255) brightness = 255;
LED_brightness();
}

void ch_down() {
brightness -= (bool)level * 15;
if (brightness <= 0) brightness = 0;
LED_brightness();
}

void LED_control(uint16_t command) {
switch (command) {
case VOL_UP: vol_up(); break;
case VOL_DOWN: vol_down(); break;
case CH_UP: ch_up(); break;
case CH_DOWN: ch_down(); break;
default: break;
}
}


int main()
{
uint16_t address = 0;
uint16_t command = 0;

IR_init();
uart_init();
softwarePWM_Init();

uart_puts("Well I'm working here!\r\n");
while (1) {
if (IR_codeAvailable()) {
if (!IR_isRepeatCode()) {
IR_getCode(&address, &command);
uart_putU16(address);
uart_puts(", ");
uart_putU16(command);
uart_puts(", ");
uart_putU8(level);
uart_puts("\r\n");
LED_control(command);
}
}
}
}
Loading

0 comments on commit 7b9a04f

Please sign in to comment.