feat(ex00): done
This commit is contained in:
commit
20cab5c109
7 changed files with 144 additions and 0 deletions
1
.clang-format
Normal file
1
.clang-format
Normal file
|
|
@ -0,0 +1 @@
|
|||
git@vogsphere.42paris.fr:vogsphere/intra-uuid-daecd842-c910-4973-b9ff-efcdd4424883-7368496-macaruan
|
||||
8
.gitignore
vendored
Normal file
8
.gitignore
vendored
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
*.o
|
||||
*.hex
|
||||
*.bin
|
||||
*.elf
|
||||
build/
|
||||
/avr-libc
|
||||
compile_commands.json
|
||||
.cache/
|
||||
55
ex00/Makefile
Normal file
55
ex00/Makefile
Normal file
|
|
@ -0,0 +1,55 @@
|
|||
# Makefile
|
||||
MCU=atmega328p
|
||||
F_CPU=16000000
|
||||
CC=avr-gcc
|
||||
OBJCOPY=avr-objcopy
|
||||
CFLAGS=-std=c99 -Wall -Wextra -g -Os -mmcu=$(MCU) -DF_CPU=$(F_CPU) -Iinclude
|
||||
IFLAGS=
|
||||
TARGET=main
|
||||
SERIAL=-P /dev/ttyUSB0 -b 115200
|
||||
|
||||
|
||||
SRC_DIR=src
|
||||
OBJ_DIR=build
|
||||
|
||||
SRC_FILES=main.c utils.c
|
||||
OBJ_FILES=$(patsubst %.c,%.o,$(SRC_FILES))
|
||||
|
||||
SRC=$(addprefix $(SRC_DIR)/,$(SRC_FILES))
|
||||
OBJ=$(addprefix $(OBJ_DIR)/,$(OBJ_FILES))
|
||||
|
||||
ELF_FILE=$(OBJ_DIR)/$(TARGET).elf
|
||||
HEX_FILE=$(OBJ_DIR)/$(TARGET).hex
|
||||
|
||||
all: flash
|
||||
|
||||
re: fclean all
|
||||
|
||||
fclean: clean
|
||||
rm -f $(HEX_FILE)
|
||||
rm -f $(ELF_FILE)
|
||||
clean:
|
||||
rm -rf $(OBJ_DIR)
|
||||
|
||||
hex: $(HEX_FILE)
|
||||
|
||||
flash: hex
|
||||
avrdude -p $(MCU) -c arduino -U flash:w:$(HEX_FILE):i $(SERIAL)
|
||||
|
||||
|
||||
$(OBJ_DIR)/%.o: $(SRC_DIR)/%.c
|
||||
@mkdir -p $(shell dirname $@)
|
||||
$(CC) $(CFLAGS) $(IFLAGS) -c $< -o $@
|
||||
|
||||
$(ELF_FILE): $(OBJ)
|
||||
$(CC) $(CFLAGS) $(OBJ) -o $@
|
||||
|
||||
$(HEX_FILE): $(ELF_FILE)
|
||||
$(OBJCOPY) -j .text -j .data -O ihex $< $@
|
||||
|
||||
print:
|
||||
@echo $(SRC)
|
||||
@echo $(OBJ)
|
||||
@echo $(ELF_FILE)
|
||||
@echo $(HEX_FILE)
|
||||
|
||||
15
ex00/include/mystd.h
Normal file
15
ex00/include/mystd.h
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
#ifndef MYSTDINT_H
|
||||
#define MYSTDINT_H
|
||||
|
||||
typedef unsigned int uint16_t;
|
||||
typedef signed int int16_t;
|
||||
|
||||
typedef unsigned char uint8_t;
|
||||
typedef signed char int8_t;
|
||||
|
||||
typedef uint8_t bool;
|
||||
|
||||
#define true (1)
|
||||
#define false (0)
|
||||
|
||||
#endif /* MYSTDINT_H */
|
||||
10
ex00/include/utils.h
Normal file
10
ex00/include/utils.h
Normal file
|
|
@ -0,0 +1,10 @@
|
|||
#ifndef UTILS_H
|
||||
#define UTILS_H
|
||||
|
||||
#include "mystd.h"
|
||||
|
||||
void delay_ms(uint16_t count);
|
||||
|
||||
void ft_bzero(void *data, uint16_t size);
|
||||
|
||||
#endif /* UTILS_H */
|
||||
27
ex00/src/main.c
Normal file
27
ex00/src/main.c
Normal file
|
|
@ -0,0 +1,27 @@
|
|||
#include <avr/interrupt.h>
|
||||
#include <avr/io.h>
|
||||
|
||||
#include "mystd.h"
|
||||
#include "utils.h"
|
||||
|
||||
|
||||
// this isnt what the datasheet says lol
|
||||
#define D5_R PD5
|
||||
#define D5_G PD6
|
||||
#define D5_B PD3
|
||||
|
||||
#define RGB_MASK (_BV(D5_R) | _BV(D5_G) | _BV(D5_B))
|
||||
|
||||
int main(void) {
|
||||
DDRD |= RGB_MASK;
|
||||
|
||||
PORTD = (PORTD & ~RGB_MASK);
|
||||
while (1) {
|
||||
PORTD = (PORTD & ~RGB_MASK) | _BV(D5_R);
|
||||
delay_ms(1000);
|
||||
PORTD = (PORTD & ~RGB_MASK) | _BV(D5_G);
|
||||
delay_ms(1000);
|
||||
PORTD = (PORTD & ~RGB_MASK) | _BV(D5_B);
|
||||
delay_ms(1000);
|
||||
}
|
||||
}
|
||||
28
ex00/src/utils.c
Normal file
28
ex00/src/utils.c
Normal file
|
|
@ -0,0 +1,28 @@
|
|||
#include "utils.h"
|
||||
|
||||
// this just burns cycles.
|
||||
// the volatile is important, it means that the cpu can't optimize any
|
||||
// read/writes for the value
|
||||
static inline void spin_loop(volatile uint16_t counts) {
|
||||
while (counts)
|
||||
counts--;
|
||||
}
|
||||
|
||||
void delay_ms(uint16_t ms) {
|
||||
while (ms) {
|
||||
// this value was taken using a delay of 500ms, and just recording the led
|
||||
// blinking. it seems to be high enough such that each loop of delay_loop
|
||||
// takes 1ms :D
|
||||
spin_loop((F_CPU) / 5000);
|
||||
ms--;
|
||||
}
|
||||
}
|
||||
|
||||
void ft_bzero(void* data, uint16_t size) {
|
||||
char* d = data;
|
||||
while (size) {
|
||||
*d = 0;
|
||||
d++;
|
||||
size--;
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue