From: Bernard Blackham Date: Wed, 6 Aug 2003 14:58:55 +0000 (+0000) Subject: More keypad fixes. X-Git-Tag: ROMW~101 X-Git-Url: https://git.ucc.asn.au/?a=commitdiff_plain;h=9366107abfbfbe85f00b27449c79284d0e1aa59e;p=uccvend-snackrom.git More keypad fixes. Chiming. Beginnings of an RTI. --- diff --git a/ROM2/Makefile b/ROM2/Makefile index 949e801..e79afb2 100644 --- a/ROM2/Makefile +++ b/ROM2/Makefile @@ -1,10 +1,9 @@ # muchly stolen from m68hc1x's example.tar.gz's Makefile OBJS = \ - motors.o keypad.o display.o coinmech.o helpers.o main.o \ + motors.o keypad.o display.o coinmech.o chime.o helpers.o main.o \ vectors.o -INCLUDES = vend.h - +INCLUDES = vend.h keypad.h chime.h asm.h display.h ports.h types.h CFLAGS = -O3 -m68hc11 -mshort -Wall -Os -g0 \ -msoft-reg-count=0 -ffixed-z @@ -39,7 +38,7 @@ rom2.elf: $(OBJS) memory.x $(CC) $(LDFLAGS) -o $@ $(OBJS) $(LIBADD) clean: - rm -f $(OBJS) *.elf *.s19 *.b *.a + rm -f *.o *.elf *.s19 *.b *.a # # Some useful rules diff --git a/ROM2/chime.c b/ROM2/chime.c new file mode 100644 index 0000000..57c4630 --- /dev/null +++ b/ROM2/chime.c @@ -0,0 +1,16 @@ +#include "vend.h" +#include "chime.h" + +u8 chime_count; + +void chime() { + /* called from the RTI interrupt, sees if we need to turn the chime on or + * off (chime would be on for N RTI cycles + */ + if (chime_count) { + bset((void*)&_io_ports[M6811_PORTA], PORTA_CHIME); + --chime_count; + } else + bclr((void*)&_io_ports[M6811_PORTA], PORTA_CHIME); +} + diff --git a/ROM2/chime.h b/ROM2/chime.h new file mode 100644 index 0000000..7cc7fa7 --- /dev/null +++ b/ROM2/chime.h @@ -0,0 +1,13 @@ +#ifndef _CHIME_H_ +#define _CHIME_H_ + +#include "types.h" + +#define CHIME_TIME 10 /* number of RTI interrupts to have the chimer on */ + +extern u8 chime_count; + +void chime(); +extern inline void chime_start() { chime_count = CHIME_TIME; } + +#endif /* _CHIME_H_ */ diff --git a/ROM2/keypad.c b/ROM2/keypad.c index e87715d..b36b326 100644 --- a/ROM2/keypad.c +++ b/ROM2/keypad.c @@ -1,7 +1,9 @@ +#include "chime.h" #include "vend.h" +#include "keypad.h" u8 last_key; /* the last key registered */ -u8 curr_key; /* the key currently being held down */ +bool new_key = 0; /* first 8 from the first row, then 3 from the second row */ /* keys are 1-9, 0, reset */ @@ -27,18 +29,28 @@ extern inline int keypad_read_row(int row) { return num; } -/* returns a key 0..9 or 11 for reset */ +/* returns a key 1..10 or 11 for reset */ void keypad_read() { /* FIXME: need to do debouncing of some sort? */ int key; key = keypad_read_row(0); if (!key) { key = keypad_read_row(1); - curr_key = keymap0[key]; + key = keymap0[key]; } - curr_key = keymap1[key]; - - if (curr_key != last_key) { - last_key = curr_key; + key = keymap1[key]; + + if (key != last_key) { + last_key = key; + if (key != 0) { + new_key = 1; + chime_start(); + } } } + +bool keypad_pressed() { + if (!new_key) return 0; + new_key = 0; + return 1; +} diff --git a/ROM2/keypad.h b/ROM2/keypad.h index d7a5382..b9cee95 100644 --- a/ROM2/keypad.h +++ b/ROM2/keypad.h @@ -2,6 +2,9 @@ #define _KEYPAD_H_ extern u8 last_key; -extern u8 curr_key; + +/* returns true if a key has been pressed since the last call */ +bool keypad_pressed(); +void keypad_read(); #endif /* _KEYPAD_H_ */ diff --git a/ROM2/main.c b/ROM2/main.c index 188fef0..1567700 100644 --- a/ROM2/main.c +++ b/ROM2/main.c @@ -1,4 +1,6 @@ #include "display.h" +#include "keypad.h" +#include "chime.h" #include "vend.h" int main() { @@ -11,6 +13,12 @@ int main() { delay(1000); while(1) { + keypad_read(); + if (keypad_pressed()) { + switch (last_key) { + + } + } } } @@ -23,3 +31,6 @@ void _start() { main(); } +void rti() { + chime(); +} diff --git a/ROM2/vectors.s b/ROM2/vectors.s index 642f6da..14ae986 100644 --- a/ROM2/vectors.s +++ b/ROM2/vectors.s @@ -77,7 +77,7 @@ vectors: .word def ; ffee ;; Misc - .word def ; fff0 (RTII) + .word rti ; fff0 (RTII) .word def ; fff2 (IRQ) .word def ; fff4 (XIRQ) .word def ; fff6 (SWI) diff --git a/ROM2/vend.h b/ROM2/vend.h index a756e25..10d3171 100644 --- a/ROM2/vend.h +++ b/ROM2/vend.h @@ -30,6 +30,7 @@ void delay(u16 ms); /******** Some meaningful bits ******/ #define PORTA_DISP_RESET 0x80 /* active low */ +#define PORTA_CHIME 0x10 /* chime is on when set */ #define PORTD_KEYPAD_ROW 0x20 /* clear for row 0, set for row 1 */ /* Address 3800 bits */ @@ -37,5 +38,6 @@ void delay(u16 ms); /******* from main.c *******/ int __attribute__((noreturn)) main (void); +void __attribute__((interrupt)) rti (void); #endif /* _VEND_H_ */