summaryrefslogtreecommitdiffstats
path: root/sleep
diff options
context:
space:
mode:
authorSadeep Madurange <sadeep@asciimx.com>2025-05-01 10:24:46 +0800
committerSadeep Madurange <sadeep@asciimx.com>2025-05-01 10:24:46 +0800
commitd11b0f733b293c768f1bca6bc54ae88997d691a2 (patch)
treedb4f8af1ced15f9a8b7bc61b3fad8b25e1a79c43 /sleep
parent3e0215f1bcb7018dbbcd1cff9b2dce606cb0328d (diff)
downloadsmart-home-d11b0f733b293c768f1bca6bc54ae88997d691a2.tar.gz
Delete temp, sleep mode code.
Diffstat (limited to 'sleep')
-rw-r--r--sleep/Makefile44
-rw-r--r--sleep/main.c74
-rw-r--r--sleep/uart.c37
-rw-r--r--sleep/uart.h8
4 files changed, 0 insertions, 163 deletions
diff --git a/sleep/Makefile b/sleep/Makefile
deleted file mode 100644
index c818369..0000000
--- a/sleep/Makefile
+++ /dev/null
@@ -1,44 +0,0 @@
-CC = avr-gcc
-MCU = atmega328p
-PORT = /dev/cuaU0
-TARGET = sleep
-
-SRC = main.c uart.c
-OBJ = $(SRC:.c=.o)
-
-CFLAGS = -std=gnu99
-CFLAGS += -Os
-CFLAGS += -Wall
-CFLAGS += -mmcu=$(MCU)
-CFLAGS += -DBAUD=115200
-CFLAGS += -DF_CPU=16000000UL
-CFLAGS += -ffunction-sections -fdata-sections
-
-LDFLAGS = -mmcu=$(MCU)
-LDFLAGS += -Wl,--gc-sections
-
-HEX_FLAGS = -O ihex
-HEX_FLAGS += -j .text -j .data
-
-AVRDUDE_FLAGS = -p $(MCU)
-AVRDUDE_FLAGS += -c arduino
-AVRDUDE_FLAGS += -P $(PORT)
-AVRDUDE_FLAGS += -D -U
-
-%.o: %.c
- $(CC) $(CFLAGS) -c -o $@ $<
-
-elf: $(OBJ)
- $(CC) $(LDFLAGS) $(OBJ) -o $(TARGET).elf
-
-hex: elf
- avr-objcopy $(HEX_FLAGS) $(TARGET).elf $(TARGET).hex
-
-upload: hex
- avrdude $(AVRDUDE_FLAGS) flash:w:$(TARGET).hex:i
-
-.PHONY: clean
-
-clean:
- rm *.o *.elf *.hex
-
diff --git a/sleep/main.c b/sleep/main.c
deleted file mode 100644
index ef4e520..0000000
--- a/sleep/main.c
+++ /dev/null
@@ -1,74 +0,0 @@
-#include <avr/interrupt.h>
-#include <avr/sleep.h>
-#include <avr/wdt.h>
-#include <util/delay.h>
-
-#include "uart.h"
-
-#define LOCK_PIN PD2
-#define UNLOCK_PIN PD3
-
-static inline void init_wdt(void)
-{
- cli();
- wdt_reset();
- WDTCSR |= (1 << WDCE) | ( 1 << WDE);
- WDTCSR = (1 << WDP2) | (1 << WDP1) | (1 << WDP0);
- WDTCSR |= (1 << WDIE);
-}
-
-static inline void init_btns(void)
-{
- DDRD &= ~((1 << LOCK_PIN) | (1 << UNLOCK_PIN));
- PORTD |= ((1 << LOCK_PIN) | (1 << UNLOCK_PIN));
- EICRA = 0b00000000;
- EIMSK = (1 << INT0) | (1 << INT1);
-}
-
-int main(void)
-{
- init_wdt();
- init_btns();
- uart_init();
-
- set_sleep_mode(SLEEP_MODE_PWR_DOWN);
- sei();
-
- for (;;) {
- uart_write_line("Going to sleep");
- sleep_enable();
- sleep_bod_disable();
- sleep_cpu();
-
- sleep_disable();
- _delay_ms(500); /* wait for start-up */
- uart_write_line("Doing some work...");
- _delay_ms(500);
- }
- return 0;
-}
-
-static inline int is_btn_pressed(uint8_t pin, uint8_t btn)
-{
- if (!((pin >> btn) & 0x01)) {
- _delay_ms(100);
- return !((pin >> btn) & 0x01);
- }
- return 0;
-}
-
-ISR(INT0_vect)
-{
- if (is_btn_pressed(PIND, LOCK_PIN))
- uart_write_line("Locked");
-}
-
-ISR(INT1_vect)
-{
- if (is_btn_pressed(PIND, UNLOCK_PIN))
- uart_write_line("Unlocked");
-}
-
-ISR(WDT_vect)
-{
-}
diff --git a/sleep/uart.c b/sleep/uart.c
deleted file mode 100644
index a6d6674..0000000
--- a/sleep/uart.c
+++ /dev/null
@@ -1,37 +0,0 @@
-#include <avr/io.h>
-#include <util/setbaud.h>
-
-#include "uart.h"
-
-void uart_init(void)
-{
- UBRR0H = UBRRH_VALUE;
- UBRR0L = UBRRL_VALUE;
-#if USE_2X
- UCSR0A |= (1 << U2X0);
-#else
- UCSR0A &= ~(1 << U2X0);
-#endif
- UCSR0B = (1 << TXEN0) | (1 << RXEN0);
- UCSR0C = (1 << UCSZ01) | (1 << UCSZ00);
-}
-
-static inline void uart_write_char(char c)
-{
- while (!(UCSR0A & (1 << UDRE0)))
- ;
- UDR0 = c;
-}
-
-void uart_write(const char *s)
-{
- for (; *s; s++)
- uart_write_char(*s);
-}
-
-void uart_write_line(const char *s)
-{
- uart_write(s);
- uart_write_char('\r');
- uart_write_char('\n');
-}
diff --git a/sleep/uart.h b/sleep/uart.h
deleted file mode 100644
index a88a3c6..0000000
--- a/sleep/uart.h
+++ /dev/null
@@ -1,8 +0,0 @@
-#ifndef UART_H
-#define UART_H
-
-void uart_init(void);
-void uart_write(const char *s);
-void uart_write_line(const char *s);
-
-#endif /* UART_H */