diff --git a/.gitignore b/.gitignore index 35233dd..a7776d6 100644 --- a/.gitignore +++ b/.gitignore @@ -1,11 +1,23 @@ +# generated files: *.hex *.ihx *.bin -.*.swp build/* -config + +# vim +.*.swp + +# ctags +tags + +# vs/platformio .pioenvs .piolibdeps .vscode/c_cpp_properties.json .vscode/launch.json .vscode/.browse.c_cpp.db* + +# misc +config +*.diff +diff diff --git a/Makefile b/Makefile index 2e97abe..b286a6c 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,6 @@ SDCC ?= sdcc STCCODESIZE ?= 4089 SDCCOPTS ?= --code-size $(STCCODESIZE) --xram-size 0 --data-loc 0x30 --disable-warning 126 --disable-warning 59 -SDCCREV ?= -Dstc15f204ea STCGAL ?= stcgal/stcgal.py STCGALOPTS ?= STCGALPORT ?= /dev/ttyUSB0 @@ -10,6 +9,23 @@ FLASHFILE ?= main.hex SYSCLK ?= 11059 CFLAGS ?= -DWITH_ALT_LED9 -DWITHOUT_LEDTABLE_RELOC -DSHOW_TEMP_DATE_WEEKDAY +# +# You need to select which hardware you want to compile for: +# + +# the most common one: +HARDWARE=default + +# STC15W408AS + voice + 3 buttons: +#HARDWARE=stc15w408as + +# one (rare) variant +#HARDWARE=modelc + + + +SDCCOPTS+=-DHARDWARE=\"hal/$(HARDWARE).h\" + SRC = src/adc.c src/ds1302.c OBJ=$(patsubst src%.c,build%.rel, $(SRC)) @@ -18,10 +34,10 @@ all: main build/%.rel: src/%.c src/%.h mkdir -p $(dir $@) - $(SDCC) $(SDCCOPTS) $(SDCCREV) -o $@ -c $< + $(SDCC) $(SDCCOPTS) -o $@ -c $< main: $(OBJ) - $(SDCC) -o build/ src/$@.c $(SDCCOPTS) $(SDCCREV) $(CFLAGS) $^ + $(SDCC) -o build/ src/$@.c $(SDCCOPTS) $(CFLAGS) $^ @ tail -n 5 build/main.mem | head -n 2 @ tail -n 1 build/main.mem cp build/$@.ihx $@.hex diff --git a/README.md b/README.md index c4bd164..9e15dc6 100644 --- a/README.md +++ b/README.md @@ -56,6 +56,12 @@ choose platformio (preferred) or traditional make build * choose which mcu you are building for by uncommenting one `env_default` in `platformio.ini` * adjust `upload_port` as needed in `platformio.ini` +Then you can use the [standard platformio commands](https://docs.platformio.org/en/stable/core/quickstart.html#process-project) +``` +pio run +pio run --target upload +``` + ### traditional make ``` make clean diff --git a/docs/nmea/nmea_howto.txt b/docs/nmea/nmea_howto.txt index 1b74465..b00e28e 100644 --- a/docs/nmea/nmea_howto.txt +++ b/docs/nmea/nmea_howto.txt @@ -12,13 +12,7 @@ requires STC15W408AS cpu with > 4K flash. STCCODESIZE ?= 8184 SDCCOPTS ?= --code-size $(STCCODESIZE) --stack-auto --iram-size 256 --xram-size 256 --data-loc 0x30 --disable-warning 126 --disable-warning 59 - if you have a clock with STC15W408AS + voice + 3 buttons, compile it with - - SDCCREV ?= -Dstc15w408as - - otherwise, e.g. if you swapped STC15W404AS -> STC15W408AS, keep using - - SDCCREV ?= -Dstc15w404as + Double check the hardware target at the beginning of the Makefile ("HARDWARE" variable) - timezone and dst settings are saved to EEPROM and reset on each reflash, so cycle power of the clock after setting them for proper synchronization diff --git a/src/ds1302.c b/src/ds1302.c index 389a01f..b312a2d 100644 --- a/src/ds1302.c +++ b/src/ds1302.c @@ -120,7 +120,7 @@ uint8_t ds_readbyte(uint8_t addr) { void ds_readburst() { // ds1302 burst-read 8 bytes into struct uint8_t j, b; - b = DS_CMD | DS_CMD_CLOCK | DS_BURST_MODE << 1 | DS_CMD_READ; + b = DS_CMD | DS_CMD_CLOCK | (DS_BURST_MODE << 1) | DS_CMD_READ; DS_CE = 0; DS_SCLK = 0; DS_CE = 1; diff --git a/src/ds1302.h b/src/ds1302.h index d196704..1a61f08 100644 --- a/src/ds1302.h +++ b/src/ds1302.h @@ -4,15 +4,15 @@ #include "stc15.h" #include -#include "hwconfig.h" +#include HARDWARE #define _nop_ __asm nop __endasm; -#define DS_CMD 1 << 7 -#define DS_CMD_READ 1 +#define DS_CMD (1u << 7) +#define DS_CMD_READ 1u #define DS_CMD_WRITE 0 #define DS_CMD_RAM 1 << 6 -#define DS_CMD_CLOCK 0 << 6 +#define DS_CMD_CLOCK (0u << 6) #define DS_ADDR_SECONDS 0 #define DS_ADDR_MINUTES 1 @@ -34,7 +34,7 @@ #define DS_TC_D2_4KO 0b1010 #define DS_TC_D2_8KO 0b1011 -#define DS_BURST_MODE 31 +#define DS_BURST_MODE 31u // DS_ADDR_SECONDS c111_1111 0_0-5_9 c=clock_halt // DS_ADDR_MINUTES x111_1111 0_0-5_9 diff --git a/src/hal/default.h b/src/hal/default.h new file mode 100644 index 0000000..d0fff87 --- /dev/null +++ b/src/hal/default.h @@ -0,0 +1,46 @@ +#ifndef HWCONFIG_H +#define HWCONFIG_H + +/* + * the main model, based either on stc15f204ea or stc15w404as MCU + */ + +// alias for relay and buzzer outputs, using relay to drive led for indication of main loop status +#define BUZZER P1_5 +#define BUZZER_ON BUZZER = 0 +#define BUZZER_OFF BUZZER = 1 + +// 7-seg led port setup + +// which port the segments are connected to +#define LED_SEGMENT_PORT P2 +// which port controls the digits +#define LED_DIGITS_PORT P3 + +// offset where the digits start on LED_DIGITS_PORT +#define LED_DIGITS_PORT_BASE 2 + +// setup macro mask to turn off digits +#define LED_DIGITS_OFF() ( LED_DIGITS_PORT |= (0b1111 << LED_DIGITS_PORT_BASE)) +// setup macro to turn on single digit +#define LED_DIGIT_ON(digit) (LED_DIGITS_PORT &= ~((1<