Added screen clear and reset functions

- added asdf_actions.c, asdf_actions.h to place misc. key actions
- asdf.c: asdf_activate_action(): added actions for screen clear and reset
- asdf_config.h, Arch/asdf_arch_atmega328p.c: added defs to specify polarity of data,
  strobe, SCREEN_CLEAR and reset outputs.
- Arch/asdf_arch_atmega328p.h: fixed pin definitions for RESET and SCREEN_CLEAR
This commit is contained in:
Dave 2019-12-15 02:38:04 -06:00
parent 6b78fe9111
commit a03473769f
9 changed files with 269 additions and 50 deletions

View File

@ -38,13 +38,13 @@
#include <avr/interrupt.h>
#include <util/delay.h>
#include <stdint.h>
#include "asdf_config.h"
#include "asdf_arch.h"
static volatile uint8_t tick = 0;
static uint8_t data_polarity = 0; // normally positive polarity
static uint8_t strobe_polarity = 0; // normally positive polarity
static uint8_t data_polarity = ASDF_DEFAULT_DATA_POLARITY;
static uint8_t strobe_polarity = ASDF_DEFAULT_STROBE_POLARITY;
// PROCEDURE: ISR for Timer 0 overflow
@ -223,22 +223,31 @@ static void asdf_arch_init_special_outputs(void)
set_bit(&ASDF_CAPS_LED_DDR, ASDF_CAPS_LED_BIT);
// initialize SCREEN_CLEAR output line to LOW (inactive)
clear_bit(&ASDF_SCREEN_CLEAR_PORT, ASDF_SCREEN_CLEAR_BIT);
// initialize SCREEN_CLEAR output line to inactive
if (ASDF_DEFAULT_SCREEN_CLEAR_POLARITY == ASDF_POSITIVE_POLARITY) {
clear_bit(&ASDF_SCREEN_CLEAR_PORT, ASDF_SCREEN_CLEAR_BIT);
} else {
set_bit(&ASDF_SCREEN_CLEAR_PORT, ASDF_SCREEN_CLEAR_BIT);
}
set_bit(&ASDF_SCREEN_CLEAR_DDR, ASDF_SCREEN_CLEAR_BIT);
// initialize /SYS_RESET output line to HIGH (inactive)
set_bit(&ASDF_SYS_RESET_PORT, ASDF_SYS_RESET_BIT);
// initialize /SYS_RESET output line to inactive
if (ASDF_DEFAULT_RESET_POLARITY == ASDF_POSITIVE_POLARITY) {
clear_bit(&ASDF_SYS_RESET_PORT, ASDF_SYS_RESET_BIT);
} else {
set_bit(&ASDF_SYS_RESET_PORT, ASDF_SYS_RESET_BIT);
}
set_bit(&ASDF_SYS_RESET_DDR, ASDF_SYS_RESET_BIT);
// initialize /STROBE output to inactive. Must test before set/clear to avoid spurious strobe
if (strobe_polarity) {
set_bit(&ASDF_STROBE_PORT, ASDF_STROBE_BIT);
// initialize /STROBE output to inactive. Must test before set/clear to avoid
// spurious strobe
if (ASDF_DEFAULT_STROBE_POLARITY == ASDF_POSITIVE_POLARITY) {
clear_bit(&ASDF_STROBE_PORT, ASDF_STROBE_BIT);
}
else {
clear_bit(&ASDF_STROBE_PORT, ASDF_STROBE_BIT);
set_bit(&ASDF_STROBE_PORT, ASDF_STROBE_BIT);
}
set_bit(&ASDF_STROBE_DDR, ASDF_STROBE_BIT);
@ -260,7 +269,7 @@ static void asdf_arch_init_ascii_output(void)
{
// set all outputs
ASDF_ASCII_PORT = 0;
ASDF_ASCII_PORT = ASDF_DEFAULT_DATA_POLARITY;
ASDF_ASCII_DDR = ALL_OUTPUTS;
}
@ -339,8 +348,8 @@ void asdf_arch_init(void)
asdf_arch_init_ascii_output();
// initialize keyboard data and strobe to positive polairy
data_polarity = 0;
strobe_polarity = 0;
data_polarity = ASDF_DEFAULT_DATA_POLARITY;
strobe_polarity = ASDF_DEFAULT_STROBE_POLARITY;
// set up strobe output
// set up indicator output
@ -358,6 +367,48 @@ void asdf_arch_init(void)
sei();
}
// PROCEDURE: asdf_arch_send_screen_clear
// INPUTS: none
// OUTPUTS: none
//
// DESCRIPTION: Toggles the SCREEN_CLEAR output.
//
// SIDE EFFECTS: see DESCRIPTION
//
// NOTES:
//
// SCOPE: public
//
// COMPLEXITY: 1
//
void asdf_arch_send_screen_clear(void)
{
set_bit(&ASDF_SCREEN_CLEAR_PIN, ASDF_SCREEN_CLEAR_BIT);
_delay_us(ASDF_STROBE_LENGTH_US);
set_bit(&ASDF_SCREEN_CLEAR_PIN, ASDF_SCREEN_CLEAR_BIT);
}
// PROCEDURE: asdf_arch_send_reset
// INPUTS: none
// OUTPUTS: none
//
// DESCRIPTION: Toggles the SCREEN_CLEAR output.
//
// SIDE EFFECTS: see DESCRIPTION
//
// NOTES:
//
// SCOPE: public
//
// COMPLEXITY: 1
//
void asdf_arch_send_reset(void)
{
set_bit(&ASDF_SYS_RESET_PIN, ASDF_SYS_RESET_BIT);
_delay_us(ASDF_STROBE_LENGTH_US);
set_bit(&ASDF_SYS_RESET_PIN, ASDF_SYS_RESET_BIT);
}
// PROCEDURE: asdf_arch_read_row
// INPUTS: (uint8_t) row: the row number to be scanned
// OUTPUTS: returns a word containing the active (pressed) columns
@ -436,11 +487,11 @@ void asdf_arch_send_code(asdf_keycode_t code)
// toggle strobe. Must test before setting to avoid spurious strobe
set_bit(&ASDF_STROBE_PINS, ASDF_STROBE_BIT);
set_bit(&ASDF_STROBE_PIN, ASDF_STROBE_BIT);
_delay_us(ASDF_STROBE_LENGTH_US);
set_bit(&ASDF_STROBE_PINS, ASDF_STROBE_BIT);
set_bit(&ASDF_STROBE_PIN, ASDF_STROBE_BIT);
}
//-------|---------|---------+---------+---------+---------+---------+---------+

View File

@ -206,15 +206,17 @@
#define ASDF_CAPS_LED_BIT 3
#define ASDF_SCREEN_CLEAR_PORT PORTC
#define ASDF_SCREEN_CLEAR_PIN PINC
#define ASDF_SCREEN_CLEAR_DDR DDRC
#define ASDF_SCREEN_CLEAR_BIT 4
#define ASDF_SCREEN_CLEAR_BIT 5
#define ASDF_SYS_RESET_PORT PORTC
#define ASDF_SYS_RESET_DDR DDRC
#define ASDF_SYS_RESET_BIT 5
#define ASDF_SYS_RESET_PORT PORTB
#define ASDF_SYS_RESET_PIN PINB
#define ASDF_SYS_RESET_DDR DDRB
#define ASDF_SYS_RESET_BIT 7
#define ASDF_STROBE_PORT PORTB
#define ASDF_STROBE_PINS PINB
#define ASDF_STROBE_PIN PINB
#define ASDF_STROBE_DDR DDRB
#define ASDF_STROBE_BIT 6
@ -247,6 +249,18 @@ asdf_cols_t asdf_arch_read_row(uint8_t row);
// OUTPUTS: returns a 1 if the 1ms timer timed out, 0 otherwise
uint8_t asdf_arch_tick(void);
// PROCEDURE: asdf_arch_send_screen_clear
// INPUTS: none
// OUTPUTS: none
// DESCRIPTION: Toggles the SCREEN_CLEAR output.
void asdf_arch_send_screen_clear(void);
// PROCEDURE: asdf_arch_send_reset
// INPUTS: none
// OUTPUTS: none
// DESCRIPTION: Toggles the SCREEN_CLEAR output.
void asdf_arch_send_reset(void);
// PROCEDURE: asdf_arch_send_code
// INPUTS: (keycode_t) code - the code to be output by the keyboard
// OUTPUTS: none

View File

@ -92,8 +92,14 @@
ACTION_NOTHING, ASCII_ESC, ACTION_CTRL, 0x1c }, \
{ ACTION_NOTHING, ASCII_CTRL_P, ACTION_NOTHING, ACTION_NOTHING, \
ASCII_SPACE, ASCII_CTRL_Z, ASCII_CTRL_A, ASCII_CTRL_Q }, \
{ ACTION_BREAK, ASCII_COMMA, ASCII_CTRL_M, ASCII_CTRL_N, \
ASCII_CTRL_B, ASCII_CTRL_V, ASCII_CTRL_C, ASCII_CTRL_X }, \
{ ACTION_RESET /*ctrl-break is RESET*/, \
ASCII_COMMA, \
ASCII_CTRL_M, \
ASCII_CTRL_N, \
ASCII_CTRL_B, \
ASCII_CTRL_V, \
ASCII_CTRL_C, \
ASCII_CTRL_X }, \
{ ACTION_CLEAR, ASCII_CTRL_I, ASCII_CTRL_U, ASCII_CTRL_Y, \
ASCII_CTRL_T, ASCII_CTRL_R, ASCII_CTRL_E, ASCII_CTRL_W }, \
{ ACTION_REPEAT, ACTION_HERE_IS, ACTION_SHIFT_LOCK, ASCII_CR, \

View File

@ -65,7 +65,7 @@ MAKEDEPEND = $(CPP) $(DEPFLAGS) $(CPPFLAGS) $< \
| sed -n 's,^\# *[0-9][0-9]* *"\([^"<]*\)".*,$@: \1\n\1:,p' \
| sort -u > $*.d
SRC_FILES = main.c asdf.c asdf_modifiers.c asdf_repeat.c asdf_keymaps.c asdf_buffer.c asdf_arch.c
SRC_FILES = main.c asdf.c asdf_modifiers.c asdf_repeat.c asdf_keymaps.c asdf_buffer.c asdf_arch.c asdf_actions.c
OBJ_FILES := $(SRC_FILES:.c=.o)
DEP_FILES := $(SRC_FILES:%.c=$(DEP_DIR)/%.d)
MAP_FILE = $(TARGET).map
@ -137,6 +137,7 @@ asdf.o: asdf.c asdf.h asdf_arch.h asdf_keymaps.h asdf_config.h
asdf_repeat.o: asdf_repeat.c asdf_repeat.h asdf_config.h
asdf_buffer.o: asdf_buffer.c asdf.h asdf_config.h
asdf_modifiers.o: asdf_modifiers.c asdf_modifiers.h
asdf_actions.o: asdf_actions.h asdf.h asdf_arch.h
tags: $(SRC_FILES)
etags $(SRC_FILES)

View File

@ -1,9 +1,12 @@
// File recommented by recomment.cpp
// on Dec 9 2019 at 10:14:05.
//
// -*- mode: C; tab-width: 2 ; indent-tabs-mode: nil -*-
//
// Unified Keyboard Project
// ASDF firmware - small, fast, and simple keyboard encoder.
// Universal Keyboard Project
// ASDF firmware - small, fast, and simple keyboard encoder.
//
// asdf.c
// asdf.c
//
// This file contains code for:
// - the main scan code and key handler routines
@ -35,6 +38,7 @@
#include "asdf_modifiers.h"
#include "asdf_buffer.h"
#include "asdf_arch.h"
#include "asdf_actions.h"
static asdf_cols_t last_stable_key_state[ASDF_NUM_ROWS];
@ -151,6 +155,14 @@ static void asdf_activate_action(action_t keycode)
asdf_repeat_activate();
break;
}
case ACTION_CLEAR: {
asdf_send_screen_clear();
break;
}
case ACTION_RESET: {
asdf_send_reset();
break;
}
case ACTION_NOTHING:
case ACTION_LOCAL:
case ACTION_BREAK:
@ -165,7 +177,6 @@ static void asdf_activate_action(action_t keycode)
case ACTION_FN_8:
case ACTION_FN_9:
case ACTION_FN_10:
case ACTION_CLEAR:
default: break;
}
}
@ -444,4 +455,3 @@ void asdf_keyscan(void)
//-------|---------|---------+---------+---------+---------+---------+---------+
// Above line is 80 columns, and should display completely in the editor.

View File

@ -1,6 +1,6 @@
// -*- mode: C; tab-width: 4 ; indent-tabs-mode: nil -*-
//
// Unified Keyboard Project
// Universal Keyboard Project
// ASDF keyboard firmware
//
// asdf.h
@ -42,25 +42,26 @@ typedef uint8_t asdf_keycode_t;
typedef enum {
ACTION_NOTHING = ASDF_ACTION,
ACTION_SHIFT = ASDF_ACTION + 0x01,
ACTION_SHIFT_LOCK = ASDF_ACTION + 0x02,
ACTION_CAPS = ASDF_ACTION + 0x03,
ACTION_CTRL = ASDF_ACTION + 0x04,
ACTION_REPEAT = ASDF_ACTION + 0x05,
ACTION_LOCAL = ASDF_ACTION + 0x06,
ACTION_BREAK = ASDF_ACTION + 0x07,
ACTION_HERE_IS = ASDF_ACTION + 0x08,
ACTION_CLEAR = ASDF_ACTION + 0x09,
ACTION_FN_1 = ASDF_ACTION + 0x11,
ACTION_FN_2 = ASDF_ACTION + 0x12,
ACTION_FN_3 = ASDF_ACTION + 0x13,
ACTION_FN_4 = ASDF_ACTION + 0x14,
ACTION_FN_5 = ASDF_ACTION + 0x15,
ACTION_FN_6 = ASDF_ACTION + 0x16,
ACTION_FN_7 = ASDF_ACTION + 0x17,
ACTION_FN_8 = ASDF_ACTION + 0x18,
ACTION_FN_9 = ASDF_ACTION + 0x19,
ACTION_FN_10 = ASDF_ACTION + 0x1a
ACTION_SHIFT,
ACTION_SHIFT_LOCK,
ACTION_CAPS,
ACTION_CTRL,
ACTION_REPEAT,
ACTION_LOCAL,
ACTION_BREAK,
ACTION_HERE_IS,
ACTION_CLEAR,
ACTION_RESET,
ACTION_FN_1,
ACTION_FN_2,
ACTION_FN_3,
ACTION_FN_4,
ACTION_FN_5,
ACTION_FN_6,
ACTION_FN_7,
ACTION_FN_8,
ACTION_FN_9,
ACTION_FN_10
} action_t;

View File

@ -0,0 +1,74 @@
// -*- mode: C; tab-width: 2 ; indent-tabs-mode: nil -*-
//
// Unified Keyboard Project
// ASDF keyboard firmware
//
// asdf_actions.c
//
// This file implements actions that are bound to keys in the keymap that don't
// have a clear home in any other module.
//
// Copyright 2019 David Fenyes
//
// This program is free software: 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 MERCHANTABILITY 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. If not, see <https://www.gnu.org/licenses/>.
//
#include "asdf_actions.h"
#include "asdf_arch.h"
// PROCEDURE: asdf_screen_clear
// INPUTS: none
// OUTPUTS: none
//
// DESCRIPTION: Performs screen clear. This function contains implementation
// independent actions, which may be simply calling the architecture-dependent
// hardware screen clear routine, or could involve a special character output.
//
// SIDE EFFECTS: causes screen clear may occur. See DESCRIPTION
//
// NOTES:
//
// SCOPE: public
//
// COMPLEXITY: 1
//
void asdf_send_screen_clear(void)
{
asdf_arch_send_screen_clear();
}
// PROCEDURE: asdf_send_reset
// INPUTS: none
// OUTPUTS: none
//
// DESCRIPTION: Performs host reset. This function contains implementation
// independent actions, which may be simply calling the architecture-dependent
// hardware screen clear routine, or could involve a special character output.
//
// SIDE EFFECTS: causes host reset. See DESCRIPTION
//
// NOTES:
//
// SCOPE: public
//
// COMPLEXITY: 1
//
void asdf_send_reset(void)
{
asdf_arch_send_reset();
}
//-------|---------|---------+---------+---------+---------+---------+---------+
// Above line is 80 columns, and should display completely in the editor.

View File

@ -0,0 +1,46 @@
// -*- mode: C; tab-width: 4 ; indent-tabs-mode: nil -*-
//
// Unified Keyboard Project
// ASDF keyboard firmware
//
// asdf_actions.h
//
// Copyright 2019 David Fenyes
// This program is free software: 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 MERCHANTABILITY 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. If not, see <https://www.gnu.org/licenses/>.
//
#if !defined (ASDF_ACTIONS_H)
#define ASDF_ACTIONS_H
// PROCEDURE: asdf_screen_clear
// INPUTS: none
// OUTPUTS: none
// DESCRIPTION: Performs screen clear. This function contains implementation
// independent actions, which may be simply calling the architecture-dependent
// hardware screen clear routine, or could involve a special character output.
void asdf_send_screen_clear(void);
// PROCEDURE: asdf_send_reset
// INPUTS: none
// OUTPUTS: none
// DESCRIPTION: Performs host reset. This function contains implementation
// independent actions, which may be simply calling the architecture-dependent
// hardware screen clear routine, or could involve a special character output.
void asdf_send_reset(void);
#endif /* !defined (ASDF_ACTIONS_H) */
//-------|---------|---------+---------+---------+---------+---------+---------+
// Above line is 80 columns, and should display completely in the editor.

View File

@ -1,6 +1,6 @@
// -*- mode: C; tab-width: 4 ; indent-tabs-mode: nil -*-
//
// Unified Keyboard Project
// Universal Keyboard Project
// ASDF keyboard firmware
//
// asdf_config.h
@ -31,6 +31,22 @@
#if !defined (CONFIG_H)
#define CONFIG_H
#define ASDF_POSITIVE_POLARITY 0
#define ASDF_NEGATIVE_POLARITY (~ASDF_POSITIVE_POLARITY)
// data polarity is positive (inactive is low, active is high)
#define ASDF_DEFAULT_DATA_POLARITY ASDF_POSITIVE_POLARITY
// Strobe polarity is positive (inactive is low, active is high)
#define ASDF_DEFAULT_STROBE_POLARITY ASDF_POSITIVE_POLARITY
// RESET output polarity is negative (inactive is high, active is low)
#define ASDF_DEFAULT_RESET_POLARITY ASDF_NEGATIVE_POLARITY
// SCREEN_CLEAR output polarity is positive (inactive is low, active is high)
#define ASDF_DEFAULT_SCREEN_CLEAR_POLARITY ASDF_POSITIVE_POLARITY
// size of the keycode output buffer.
#define ASDF_KEYCODE_BUFFER_SIZE 16