summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Makefile8
-rw-r--r--include/esp8266/driver/gpio.h18
-rw-r--r--include/esp8266/user_config.h5
-rw-r--r--src/arch/esp8266/Makefile.inc46
-rw-r--r--src/arch/esp8266/arch.cc30
-rw-r--r--src/arch/esp8266/driver/gpio.cc40
6 files changed, 140 insertions, 7 deletions
diff --git a/Makefile b/Makefile
index bd82543..468b153 100644
--- a/Makefile
+++ b/Makefile
@@ -7,13 +7,7 @@ CXXFLAGS = -std=c++14
TARGETS = src/os/main.cc
-ifeq (${arch}, msp430fr5969lp)
-include src/arch/msp430fr5969lp/Makefile.inc
-endif
-
-ifeq (${arch}, posix)
-include src/arch/posix/Makefile.inc
-endif
+include src/arch/${arch}/Makefile.inc
clean: arch_clean
rm -f build/system.elf
diff --git a/include/esp8266/driver/gpio.h b/include/esp8266/driver/gpio.h
new file mode 100644
index 0000000..177e7c5
--- /dev/null
+++ b/include/esp8266/driver/gpio.h
@@ -0,0 +1,18 @@
+#ifndef GPIO_H
+#define GPIO_H
+
+class GPIO {
+ private:
+ GPIO(const GPIO &copy);
+
+ public:
+ GPIO () {}
+ void setup();
+ void led_on(unsigned char id);
+ void led_off(unsigned char id);
+ void led_toggle(unsigned char id);
+};
+
+extern GPIO gpio;
+
+#endif
diff --git a/include/esp8266/user_config.h b/include/esp8266/user_config.h
new file mode 100644
index 0000000..529fb46
--- /dev/null
+++ b/include/esp8266/user_config.h
@@ -0,0 +1,5 @@
+/*
+ * required by ESP8266 SDK's osapi.h
+ *
+ * Intentionally left blank.
+ */
diff --git a/src/arch/esp8266/Makefile.inc b/src/arch/esp8266/Makefile.inc
new file mode 100644
index 0000000..3f7f9ff
--- /dev/null
+++ b/src/arch/esp8266/Makefile.inc
@@ -0,0 +1,46 @@
+# vim:ft=make
+
+TOOLCHAIN_BASE = /home/derf/var/projects/esp8266/toolchain/xtensa-lx106-elf/bin
+SDK_BASE = /home/derf/var/projects/esp8266/toolchain/xtensa-lx106-elf/xtensa-lx106-elf/sysroot/usr
+ESPTOOL = esptool
+PORT = /dev/ttyUSB0
+
+CC = ${TOOLCHAIN_BASE}/xtensa-lx106-elf-gcc
+CXX = ${TOOLCHAIN_BASE}/xtensa-lx106-elf-g++
+AR = ${TOOLCHAIN_BASE}/xtensa-lx106-elf-ar
+LD = ${TOOLCHAIN_BASE}/xtensa-lx106-elf-gcc
+
+INCLUDES += -Iinclude/esp8266 -I${SDK_BASE}/include
+COMMON_FLAGS += -nostdlib -mlongcalls
+CXXFLAGS = -std=c++11
+LDFLAGS += -nostdlib -Wl,--no-check-sections -u call_user_start -Wl,-static
+
+TARGETS += src/arch/esp8266/arch.cc src/arch/esp8266/driver/gpio.cc
+
+OBJECTS = ${TARGETS:.cc=.o}
+
+.cc.o:
+ ${CXX} ${INCLUDES} ${COMMON_FLAGS} ${CXXFLAGS} -c -o $@ ${@:.o=.cc}
+
+build/system.ar: ${OBJECTS}
+ ${AR} cru $@ ${OBJECTS}
+
+build/system.elf: build/system.ar
+ ${CC} -L${SDK_BASE}/lib -T${SDK_BASE}/lib/eagle.app.v6.ld ${LDFLAGS} \
+ -Wl,--start-group -lc -lgcc -lhal -lpp -lphy -lnet80211 -llwip -lwpa \
+ -lmain $< -Wl,--end-group -o $@
+
+build/0x00000.bin: build/system.elf
+ ${ESPTOOL} --chip esp8266 elf2image -o build/ $<
+
+build/0x40000.bin: build/0x00000.bin
+ # also created by commandline for 0x00000.bin
+
+program: build/0x00000.bin build/0x40000.bin
+ ${ESPTOOL} write_flash 0x00000 build/0x00000.bin 0x40000 build/0x40000.bin
+
+arch_clean:
+ rm -f ${OBJECTS}
+ rm -f build/system.ar
+
+.PHONY: arch_clean program
diff --git a/src/arch/esp8266/arch.cc b/src/arch/esp8266/arch.cc
new file mode 100644
index 0000000..e7a26bb
--- /dev/null
+++ b/src/arch/esp8266/arch.cc
@@ -0,0 +1,30 @@
+#include "arch.h"
+
+extern "C" {
+#include "ets_sys.h"
+#include "osapi.h"
+#include "os_type.h"
+#include "user_interface.h"
+#include "gpio.h"
+#include "mem.h"
+}
+
+#define user_procTaskPrio 0
+#define user_procTaskQueueLen 1
+
+extern int main(void);
+
+void Arch::setup(void)
+{
+}
+
+void Arch::idle_loop(void)
+{
+}
+
+extern "C" void user_init(void)
+{
+ main();
+}
+
+Arch arch;
diff --git a/src/arch/esp8266/driver/gpio.cc b/src/arch/esp8266/driver/gpio.cc
new file mode 100644
index 0000000..bc236a9
--- /dev/null
+++ b/src/arch/esp8266/driver/gpio.cc
@@ -0,0 +1,40 @@
+#include "driver/gpio.h"
+extern "C" {
+#include "osapi.h"
+#include "user_interface.h"
+#include "gpio.h"
+}
+
+void ICACHE_FLASH_ATTR GPIO::setup()
+{
+ gpio_init();
+
+ // Enable GPIO2 (ESP8266 on-board LED) as output
+ PIN_FUNC_SELECT(PERIPHS_IO_MUX_GPIO2_U, FUNC_GPIO2);
+
+ // Enable GPIO16 (RTC out / NodeMCU on-board LED) as output
+ //WRITE_PERI_REG(PAD_XPD_DCDC_CONF, (READ_PERI_REG(PAD_XPD_DCDC_CONF) & 0xffffffbc) | (uint32)0x1);
+ //WRITE_PERI_REG(RTC_GPIO_CONF, (READ_PERI_REG(RTC_GPIO_CONF) & (uint32)0xfffffffe) | (uint32)0x0);
+ //WRITE_PERI_REG(RTC_GPIO_ENABLE, (READ_PERI_REG(RTC_GPIO_ENABLE) & (uint32)0xfffffffe) | (uint32)0x1);
+}
+
+void ICACHE_FLASH_ATTR GPIO::led_on(unsigned char id)
+{
+ gpio_output_set(0, BIT2, BIT2, 0);
+}
+
+void ICACHE_FLASH_ATTR GPIO::led_off(unsigned char id)
+{
+ gpio_output_set(BIT2, 0, BIT2, 0);
+}
+
+void ICACHE_FLASH_ATTR GPIO::led_toggle(unsigned char id)
+{
+ if (GPIO_REG_READ(GPIO_OUT_ADDRESS) & BIT2) {
+ led_on(0);
+ } else {
+ led_off(0);
+ }
+}
+
+GPIO gpio;