summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Franke <nobody@nowhere.ws>2013-12-05 03:06:23 (GMT)
committerChristian Franke <nobody@nowhere.ws>2013-12-05 03:06:23 (GMT)
commit12688a2578ace9776eadfaae0806eaf4ebec48e6 (patch)
treefe48442a5f8bc4d4af233cb5a58a96bf17bde03e
Initial commit
-rw-r--r--.gitignore6
-rw-r--r--Makefile41
-rw-r--r--ferment.c69
3 files changed, 116 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..6769eb2
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,6 @@
+*.o
+*.flash
+*.eeprom
+*.map
+*.orig
+*.?#?
diff --git a/Makefile b/Makefile
new file mode 100644
index 0000000..b7690cd
--- /dev/null
+++ b/Makefile
@@ -0,0 +1,41 @@
+MCU=atmega32
+AVRDUDE=avrdude
+ACC=avr-gcc
+AOBJCOPY=avr-objcopy
+ALD=avr-ld
+ASIZE=avr-size
+CFLAGS=-Wall -Wextra -Wno-unused-parameter -pedantic -std=c99
+
+ACFLAGS=-g -mmcu=$(MCU) $(CFLAGS) $(DPIN) -Os -mcall-prologues
+# ALDFLAGS=-L/usr/avr/lib/avr4 -L/usr/lib/binutils/avr/2.18
+LD=gcc
+CC=gcc
+CXX=g++ -g
+LDXX=g++ -g
+
+love: ferment.flash ferment.eeprom
+
+%.flash: %.ld.o
+ $(AOBJCOPY) -O binary $< $@
+
+%.eeprom: %.ld.o
+ $(AOBJCOPY) -j .eeprom -O binary $^ $@
+
+%.ld.o: %.o
+ $(ACC) $(ACFLAGS) $(ALDFLAGS) -Wl,-Map,$(patsubst %.ld.o,%.map,$@) -o $@ $<
+ @$(ASIZE) $@
+
+%.o: %.c
+ $(ACC) $(ACFLAGS) -c -o $@ $<
+
+flash: ferment.flash
+ $(AVRDUDE) -y -p m32 -E noreset -U flash:w:$<:r
+eeprom: ferment.eeprom
+ $(AVRDUDE) -y -p m32 -E noreset -U eeprom:w:$<:r
+
+clean:
+ rm -f *.flash *.eeprom *.o
+
+.PHONY: love flash eeprom clean
+.SECONDARY:
+
diff --git a/ferment.c b/ferment.c
new file mode 100644
index 0000000..aba1916
--- /dev/null
+++ b/ferment.c
@@ -0,0 +1,69 @@
+#define F_CPU 1000000UL
+#include <stdint.h>
+#include <string.h>
+#include <avr/io.h>
+#include <avr/interrupt.h>
+#include <avr/sleep.h>
+#include <avr/pgmspace.h>
+#include <avr/eeprom.h>
+#include <util/delay.h>
+
+/* port D
+ *
+ * 4 1- (NMOS, inverted)
+ * 5 1+ (PMOS)
+ * 6 2- (NMOS, inverted)
+ * 7 2+ (PMOS)
+ *
+ */
+
+#define D_1_MINUS (1 << 4)
+#define D_1_PLUS (1 << 5)
+#define D_2_MINUS (1 << 6)
+#define D_2_PLUS (1 << 7)
+
+/* Turns the H-bridge off, putting the output
+ * into high impedance mode. */
+static void bridge_off(void)
+{
+ PORTD |= D_1_MINUS | D_2_MINUS;
+ PORTD &= ~(D_1_PLUS | D_2_PLUS);
+}
+
+/* Turns the H-bridge on, setting 1+ 2- */
+static void bridge_on_a(void)
+{
+ bridge_off();
+ _delay_ms(100);
+ PORTD |= D_1_PLUS;
+ PORTD &= ~D_2_MINUS;
+}
+
+/* Turns the H-bridge on, setting 1- 2+ */
+static void bridge_on_b(void)
+{
+ bridge_off();
+ _delay_ms(100);
+ PORTD |= D_2_PLUS;
+ PORTD &= ~D_1_MINUS;
+}
+
+/* Initializes the output port needed for the H-bridge */
+static void bridge_init(void)
+{
+ bridge_off();
+ DDRD |= D_1_PLUS | D_1_MINUS | D_2_PLUS | D_2_MINUS;
+}
+
+int main()
+{
+ bridge_init();
+ /* simple demo, just flips polarity every now and then */
+ while (1) {
+ bridge_on_a();
+ _delay_ms(200);
+ bridge_on_b();
+ _delay_ms(200);
+ }
+}
+