Skip to content
This repository has been archived by the owner on Aug 21, 2024. It is now read-only.

Commit

Permalink
Introduce per-target files (aka "hardware abstraction layer")
Browse files Browse the repository at this point in the history
  • Loading branch information
orzel committed Feb 3, 2022
1 parent ed5bfd5 commit f5ad3e2
Show file tree
Hide file tree
Showing 8 changed files with 169 additions and 108 deletions.
22 changes: 19 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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))
Expand All @@ -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
Expand Down
8 changes: 1 addition & 7 deletions docs/nmea/nmea_howto.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/ds1302.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

#include "stc15.h"
#include <stdint.h>
#include "hwconfig.h"
#include HARDWARE

#define _nop_ __asm nop __endasm;

Expand Down
47 changes: 47 additions & 0 deletions src/hal/default.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
#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 RELAY P1_4
#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<<LED_DIGITS_PORT_BASE) << digit))

// adc channels for sensors, P1_n
#define ADC_LIGHT 6
#define ADC_TEMP 7

// button switch aliases
#define SW1 P3_1
#define SW2 P3_0
#define NUM_SW 2

// ds1302 pins
#define DS_CE P1_0
#define DS_IO P1_1
#define DS_SCLK P1_2
// needed for asm optimizations
#define _DS_IO _P1_1
#define _DS_SCLK _P1_2

#endif // #ifndef HWCONFIG_H

48 changes: 48 additions & 0 deletions src/hal/modelc.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#ifndef HWCONFIG_H
#define HWCONFIG_H

/*
* The variant based on MCU stc15f204 and described here:
* https://github.com/zerog2k/stc_diyclock/issues/20
*/

// alias for relay and buzzer outputs, using relay to drive led for indication of main loop status
#define RELAY
#define BUZZER P3_3
#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 4

// 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<<LED_DIGITS_PORT_BASE) << digit))

// adc channels for sensors, P1_n
#define ADC_LIGHT 3
#define ADC_TEMP 6

// button switch aliases
#define SW1 P3_1
#define SW2 P3_0
#define NUM_SW 2

// ds1302 pins
#define DS_CE P0_0
#define DS_IO P0_1
#define DS_SCLK P3_2
// needed for asm optimizations
#define _DS_IO _P0_1
#define _DS_SCLK _P3_2

#endif // #ifndef HWCONFIG_H

48 changes: 48 additions & 0 deletions src/hal/stc15w408as.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#ifndef HWCONFIG_H
#define HWCONFIG_H

/*
* hardware with stc15w408as and voice chips
*/

#define LED P1_5
// no buzzer ?
#define BUZZER_ON
#define BUZZER_OFF

// 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<<LED_DIGITS_PORT_BASE) << digit))

// adc channels for sensors, P1_n
#define ADC_LIGHT 6
#define ADC_TEMP 7

// button switch aliases
// the stc15w408as has a third one
#define SW1 P3_1
#define SW2 P3_0
#define SW3 P1_4
#define NUM_SW 3

// ds1302 pins
#define DS_CE P1_0
#define DS_IO P1_1
#define DS_SCLK P1_2
// needed for asm optimizations
#define _DS_IO _P1_1
#define _DS_SCLK _P1_2

#endif // #ifndef HWCONFIG_H

92 changes: 0 additions & 92 deletions src/hwconfig.h

This file was deleted.

10 changes: 5 additions & 5 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
#define WDT_CLEAR() (WDT_CONTR |= 1 << 4)

// hardware configuration
#include "hwconfig.h"
#include HARDWARE

// keyboard mode states
enum keyboard_mode {
Expand Down Expand Up @@ -184,7 +184,7 @@ volatile __bit S1_LONG;
volatile __bit S1_PRESSED;
volatile __bit S2_LONG;
volatile __bit S2_PRESSED;
#ifdef stc15w408as
#ifdef SW3
volatile __bit S3_LONG;
volatile __bit S3_PRESSED;
#endif
Expand All @@ -200,7 +200,7 @@ enum Event {
EV_S2_SHORT,
EV_S2_LONG,
EV_S1S2_LONG,
#ifdef stc15w408as
#ifdef SW3
EV_S3_SHORT,
EV_S3_LONG,
#endif
Expand Down Expand Up @@ -318,7 +318,7 @@ void timer0_isr() __interrupt 1 __using 1

MONITOR_S(1);
MONITOR_S(2);
#ifdef stc15w408as
#ifdef SW3
MONITOR_S(3);
#endif

Expand Down Expand Up @@ -914,7 +914,7 @@ int main()
kmode = K_SET_HOUR;
else if (ev == EV_S2_SHORT)
kmode = K_TEMP_DISP;
#ifdef stc15w408as
#ifdef SW3
else if (ev == EV_S3_LONG) {
LED = !LED;
}
Expand Down

0 comments on commit f5ad3e2

Please sign in to comment.