URL
https://opencores.org/ocsvn/s6soc/s6soc/trunk
Subversion Repositories s6soc
Compare Revisions
- This comparison shows the changes necessary to convert path
/s6soc/trunk/sw/dev
- from Rev 21 to Rev 29
- ↔ Reverse comparison
Rev 21 → Rev 29
/keypad.h
0,0 → 1,46
//////////////////////////////////////////////////////////////////////////////// |
// |
// Filename: keypad.h |
// |
// Project: CMod S6 System on a Chip, ZipCPU demonstration project |
// |
// Purpose: A device driver (task) for the 16 character keypad. |
// |
// Creator: Dan Gisselquist, Ph.D. |
// Gisselquist Technology, LLC |
// |
//////////////////////////////////////////////////////////////////////////////// |
// |
// Copyright (C) 2015-2016, Gisselquist Technology, LLC |
// |
// This program is free software (firmware): you can redistribute it and/or |
// modify it under the terms of the GNU General Public License as published |
// by the Free Software Foundation, either version 3 of the License, or (at |
// your option) any later version. |
// |
// This program is distributed in the hope that it will be useful, but WITHOUT |
// ANY WARRANTY; without even the implied warranty of MERCHANTIBILITY or |
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
// for more details. |
// |
// You should have received a copy of the GNU General Public License along |
// with this program. (It's in the $(ROOT)/doc directory, run make with no |
// target there if the PDF file isn't present.) If not, see |
// <http://www.gnu.org/licenses/> for a copy. |
// |
// License: GPL, v3, as defined and found on www.gnu.org, |
// http://www.gnu.org/licenses/gpl.html |
// |
// |
//////////////////////////////////////////////////////////////////////////////// |
// |
// |
#ifndef KEYPAD_H |
#define KEYPAD_H |
extern int keypadread(void); |
extern void keypad_wait_for_release(void); |
|
#ifdef ZIPOS |
extern void keypad_task(void); |
#endif |
#endif |
/kptest.c
0,0 → 1,93
//////////////////////////////////////////////////////////////////////////////// |
// |
// Filename: kptest.c |
// |
// Project: CMod S6 System on a Chip, ZipCPU demonstration project |
// |
// Purpose: To test and demonstrate that the keypad works. |
// |
// Creator: Dan Gisselquist, Ph.D. |
// Gisselquist Technology, LLC |
// |
//////////////////////////////////////////////////////////////////////////////// |
// |
// Copyright (C) 2015-2016, Gisselquist Technology, LLC |
// |
// This program is free software (firmware): you can redistribute it and/or |
// modify it under the terms of the GNU General Public License as published |
// by the Free Software Foundation, either version 3 of the License, or (at |
// your option) any later version. |
// |
// This program is distributed in the hope that it will be useful, but WITHOUT |
// ANY WARRANTY; without even the implied warranty of MERCHANTIBILITY or |
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
// for more details. |
// |
// You should have received a copy of the GNU General Public License along |
// with this program. (It's in the $(ROOT)/doc directory, run make with no |
// target there if the PDF file isn't present.) If not, see |
// <http://www.gnu.org/licenses/> for a copy. |
// |
// License: GPL, v3, as defined and found on www.gnu.org, |
// http://www.gnu.org/licenses/gpl.html |
// |
// |
//////////////////////////////////////////////////////////////////////////////// |
// |
// |
#include "asmstartup.h" |
#include "board.h" |
#include "keypad.h" |
|
void txchr(char v) { |
volatile IOSPACE *sys = (IOSPACE *)IOADDR; |
if (v < 10) |
return; |
v &= 0x07f; |
sys->io_pic = INT_UARTTX; |
while((sys->io_pic&INT_UARTTX)==0) |
; |
sys->io_uart = v; |
} |
|
void txstr(const char *str) { |
const char *ptr = str; |
while(*ptr) { |
txchr(*ptr++); |
} |
} |
|
void entry(void) { |
register IOSPACE *sys = (IOSPACE *)0x0100; |
|
sys->io_pic = 0x07fffffff; // Acknowledge and turn off all interrupts |
sys->io_spio = 0x0f0; |
sys->io_tima = 100000 | TM_REPEAT; |
|
txstr("Press any keypad button for test.\r\n"); |
|
while(1) { |
int ch; |
while(0 == (sys->io_pic & INT_KEYPAD)) |
; |
sys->io_pic = INT_KEYPAD | INT_TIMA; |
// Wait 5 ms |
for(int i=0; i<5; i++) { |
while(0 == (sys->io_pic & INT_TIMA)) |
; |
} |
sys->io_spio = 0x011; |
ch = keypadread(); |
if (ch < 0) |
; // txstr("Unknown key pressed or error\n"); |
else if (ch < 10) |
txchr(ch+'0'); |
else if (ch == 15) |
txstr("F\r\n"); |
else if (ch < 15) |
txchr(ch+'A'-10); |
else txstr("Unknown key pressed\n"); |
keypad_wait_for_release(); |
sys->io_spio = 0x010; |
} |
} |
/Makefile
46,7 → 46,7
## |
## |
all: |
PROGRAMS := helloworld |
PROGRAMS := helloworld doorbell doorbell2 kptest |
all: $(OBJDIR)/ $(PROGRAMS) |
|
|
61,7 → 61,7
# Not for build, for for building tags and dependency files, we need to know |
# what the sources and headers are |
DEVDRVR:= keypad.c display.c rtcsim.c |
SOURCES:= helloworld.c doorbell.c doorbell2.c $(DEVDRVR) |
SOURCES:= helloworld.c doorbell.c doorbell2.c kptest.c $(DEVDRVR) |
HEADERS:= board.h |
# OBJECTS:= $(addprefix $(OBJDIR)/,$(subst .cpp,.o,$(SOURCES))) |
OBJDRVR := $(addprefix $(OBJDIR)/,$(subst .c,.o,$(DEVDRVR))) |
96,6 → 96,11
$(OBJDIR)/doorbell2.txt: doorbell2 |
$(OBJDUMP) -dr $^ > $@ |
|
kptest: $(OBJDIR)/ $(OBJDIR)/kptest.o $(OBJDRVR) cmod.ld |
$(CC) $(LDFLAGS) $(OBJDIR)/kptest.o $(OBJDRVR) -o $@ |
$(OBJDIR)/kptest.txt: kptest |
$(OBJDUMP) -dr $^ > $@ |
|
define build-depends |
@echo "Building dependency file(s)" |
$(CC) $(CPPFLAGS) -MM $(SOURCES) > $(OBJDIR)/xdep.txt |
/keypad.c
0,0 → 1,138
//////////////////////////////////////////////////////////////////////////////// |
// |
// Filename: keypad.c |
// |
// Project: CMod S6 System on a Chip, ZipCPU demonstration project |
// |
// Purpose: A device driver (task) for the 16 character keypad. |
// |
// Creator: Dan Gisselquist, Ph.D. |
// Gisselquist Technology, LLC |
// |
//////////////////////////////////////////////////////////////////////////////// |
// |
// Copyright (C) 2015-2016, Gisselquist Technology, LLC |
// |
// This program is free software (firmware): you can redistribute it and/or |
// modify it under the terms of the GNU General Public License as published |
// by the Free Software Foundation, either version 3 of the License, or (at |
// your option) any later version. |
// |
// This program is distributed in the hope that it will be useful, but WITHOUT |
// ANY WARRANTY; without even the implied warranty of MERCHANTIBILITY or |
// FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
// for more details. |
// |
// You should have received a copy of the GNU General Public License along |
// with this program. (It's in the $(ROOT)/doc directory, run make with no |
// target there if the PDF file isn't present.) If not, see |
// <http://www.gnu.org/licenses/> for a copy. |
// |
// License: GPL, v3, as defined and found on www.gnu.org, |
// http://www.gnu.org/licenses/gpl.html |
// |
// |
//////////////////////////////////////////////////////////////////////////////// |
// |
// |
#include "board.h" |
#ifdef ZIPOS |
#include "../zipos/ktraps.h" |
#include "../zipos/kfildes.h" |
#endif |
|
static const int keymap[] = { |
0x01,0x02,0x03,0x0a, |
0x04,0x05,0x06,0x0b, |
0x07,0x08,0x09,0x0c, |
0x00,0x0f,0x0e,0x0d |
}; |
|
int keypadread(void) { |
int row, col, key; |
IOSPACE *sys = (IOSPACE *)IOADDR; |
|
row = sys->io_spio & 0x0f00; |
if (row != 0x0f00) { |
// If a button is still pressed .. |
// |
// Check columns one and two to see if they were responsible |
// for the button |
sys->io_spio = 0x0cf00; |
// Get the result |
col = sys->io_spio; |
if ((col&0x0f00)!=0x0f00) { |
// Column one or two is pressed |
sys->io_spio = 0x0ef00; |
col = sys->io_spio; |
if ((col&0x0f00)!=0x0f00) |
col = 0; |
else |
col = 1; |
} else { |
// Must be column three or four |
sys->io_spio = 0x7f00; |
col = sys->io_spio; |
if ((col & 0x0f00)!= 0x0f00) // Column 4 |
col = 3; |
else |
col = 2; |
} sys->io_spio = 0x0f00; // Reset column pins to zero |
if (row == (int)(sys->io_spio & 0x0f00)) { |
// The key didn't change, so we might have something |
row >>= 8; |
row &= 0x0f; |
row ^= 0x0f; |
|
// Found the pin |
if (row == 1) |
row=0; |
else if (row == 2) |
row = 1; |
else if (row == 4) |
row = 2; |
else if (row == 8) |
row = 3; |
else |
// Two or more buttons were pressed |
// -- declare an error |
row = -1; |
|
if (row>=0) { |
key = (row |(col<<2)); |
key = keymap[key]; |
} else key = -1; |
} else key = -1; |
} else key = -1; |
|
if (sys->io_pic & INT_ENABLE) |
sys->io_pic = INT_ENABLE|INT_KEYPAD; |
else sys->io_pic = INT_KEYPAD; |
|
return key; |
} |
|
void keypad_wait_for_release(void) { |
IOSPACE *sys = (IOSPACE *)IOADDR; |
sys->io_spio = 0x0f00; |
while((sys->io_spio & 0x0f00)!=0x0f00) |
#ifdef ZIPOS |
wait(0,2); |
#else |
; |
#endif |
} |
|
#ifdef ZIPOS |
void keypad_task(void) { |
clear(INT_KEYPAD); |
while(1) { |
int key; |
wait(INT_KEYPAD,-1); // Automatically clears |
key = keypadread(); |
write(FILENO_STDOUT, &key, 1); |
// Prepare for the next key |
clear(INT_KEYPAD); |
} |
} |
#endif |