Add support for LEDs

- asdf_modifier.c: refactor CAPS LOCK setting and add LED setting
- asdf_arch_atmega328p.[ch]: add in LED definitions and functions
- add dummy asdf_arch_caps_led() function to arch files so test can compile.
This commit is contained in:
David Fenyes 2020-02-20 16:48:17 -06:00
parent 919a422d57
commit a598eaaee1
6 changed files with 127 additions and 47 deletions

View File

@ -203,24 +203,6 @@ static void asdf_arch_init_clock(void)
CLKPR = (CLKPCE | SYSCLK_DIV1);
}
// PROCEDURE: asdf_arch_init_caps_led
// INPUTS: none
// OUTPUTS: none
//
// DESCRIPTION: Initialize CAPSLOCK LED to off.
//
// SIDE EFFECTS: See DESCRIPTION
//
// SCOPE: private
//
// COMPLEXITY: 1
//
static void asdf_arch_init_caps_led(void)
{
clear_bit(&ASDF_CAPS_LED_PORT, ASDF_CAPS_LED_BIT);
set_bit(&ASDF_CAPS_LED_DDR, ASDF_CAPS_LED_BIT);
}
// PROCEDURE: asdf_arch_screen_clear(void)
// INPUTS: none
// OUTPUTS: none
@ -357,6 +339,65 @@ static void asdf_arch_init_row_outputs(void)
ASDF_ROW_DDR |= ASDF_ROW_MASK;
}
// PROCEDURE: asdf_arch_caps_led
// INPUTS: (uint8_t) led_state: nonzero value turns on LED, zero turns off LED
// OUTPUTS: none
//
// DESCRIPTION: Controls the CAPSLOCK LED.
//
// SIDE EFFECTS: See DESCRIPTION
//
// SCOPE: public
//
// COMPLEXITY: 2
//
void asdf_arch_caps_led(uint8_t led_status)
{
if (led_status) {
set_bit(&ASDF_CAPS_LED_PORT, ASDF_CAPS_LED_BIT);
} else {
clear_bit(&ASDF_CAPS_LED_PORT, ASDF_CAPS_LED_BIT);
}
}
// PROCEDURE: asdf_arch_init_caps_led
// INPUTS: none
// OUTPUTS: none
//
// DESCRIPTION: Initialize CAPSLOCK LED to off.
//
// SIDE EFFECTS: See DESCRIPTION
//
// SCOPE: private
//
// COMPLEXITY: 1
//
static void asdf_arch_init_caps_led(void)
{
asdf_arch_caps_led(0);
set_bit(&ASDF_CAPS_LED_DDR, ASDF_CAPS_LED_BIT);
}
// PROCEDURE: asdf_arch_init_power_led
// INPUTS: none
// OUTPUTS: none
//
// DESCRIPTION: Initialize CAPSLOCK LED to off.
//
// SIDE EFFECTS: See DESCRIPTION
//
// SCOPE: private
//
// COMPLEXITY: 1
//
static void asdf_arch_init_power_led(void)
{
clear_bit(&ASDF_POWER_LED_PORT, ASDF_POWER_LED_BIT);
set_bit(&ASDF_POWER_LED_DDR, ASDF_POWER_LED_BIT);
}
// PROCEDURE: asdf_arch_init
// INPUTS: none
// OUTPUTS: none
@ -392,6 +433,7 @@ void asdf_arch_init(void)
asdf_arch_init_screen_clear();
asdf_arch_init_sys_reset();
asdf_arch_init_caps_led();
asdf_arch_init_power_led();
// set up row output port
asdf_arch_init_row_outputs();
@ -404,27 +446,6 @@ void asdf_arch_init(void)
}
// PROCEDURE: asdf_arch_caps_led
// INPUTS: (uint8_t) led_state: nonzero value turns on LED, zero turns off LED
// OUTPUTS: none
//
// DESCRIPTION: Controls the CAPSLOCK LED.
//
// SIDE EFFECTS: See DESCRIPTION
//
// SCOPE: public
//
// COMPLEXITY: 2
//
void asdf_arch_caps_led(uint8_t led_status)
{
if (led_status) {
set_bit(&ASDF_CAPS_LED_PORT, ASDF_CAPS_LED_BIT);
} else {
clear_bit(&ASDF_CAPS_LED_PORT, ASDF_CAPS_LED_BIT);
}
}
// PROCEDURE: asdf_arch_send_screen_clear
// INPUTS: none
// OUTPUTS: none

View File

@ -201,9 +201,25 @@
#define ASDF_ASCII_PORT PORTD
#define ASDF_ASCII_DDR DDRD
#define ASDF_CAPS_LED_PORT PORTC
#define ASDF_CAPS_LED_DDR DDRC
#define ASDF_CAPS_LED_BIT 3
#define ASDF_LED1_PORT PORTC
#define ASDF_LED1_DDR DDRC
#define ASDF_LED1_BIT 4
#define ASDF_LED2_PORT PORTB
#define ASDF_LED2_DDR DDRB
#define ASDF_LED2_BIT 5
#define ASDF_LED3_PORT PORTB
#define ASDF_LED3_DDR DDRB
#define ASDF_LED3_BIT 4
#define ASDF_POWER_LED_PORT ASDF_LED1_PORT
#define ASDF_POWER_LED_DDR ASDF_LED1_DDR
#define ASDF_POWER_LED_BIT ASDF_LED1_BIT
#define ASDF_CAPS_LED_PORT ASDF_LED3_PORT
#define ASDF_CAPS_LED_DDR ASDF_LED3_DDR
#define ASDF_CAPS_LED_BIT ASDF_LED3_BIT
#define ASDF_SCREEN_CLEAR_PORT PORTC
#define ASDF_SCREEN_CLEAR_PIN PINC

View File

@ -39,7 +39,8 @@
#include "asdf_config.h"
#include "asdf_arch.h"
// this is to get rid of "unused variable" warnings.
volatile static uint32_t junk_variable;
// PROCEDURE: asdf_arch_init
// INPUTS: none
@ -87,6 +88,23 @@ void asdf_arch_send_screen_clear(void) {}
//
void asdf_arch_send_reset(void) {}
// PROCEDURE: asdf_arch_caps_led
// INPUTS: (uint8_t) led_state: nonzero value turns on LED, zero turns off LED
// OUTPUTS: none
//
// DESCRIPTION: Controls the CAPSLOCK LED. Test version is empty.
//
// SIDE EFFECTS: None for test version
//
// SCOPE: public
//
// COMPLEXITY: 1
//
void asdf_arch_caps_led(uint8_t led_status) {
junk_variable = led_status;
}
//-------|---------|---------+---------+---------+---------+---------+---------+
// Above line is 80 columns, and should display completely in the editor.
//

View File

@ -58,6 +58,12 @@ void asdf_arch_send_reset(void);
// DESCRIPTION: sets up all the hardware for the keyboard
void asdf_arch_init(void);
// PROCEDURE: asdf_arch_caps_led
// INPUTS: (uint8_t) led_state: nonzero value turns on LED, zero turns off LED
// OUTPUTS: none
// DESCRIPTION: Controls the CAPSLOCK LED. Test version is empty.
void asdf_arch_caps_led(uint8_t led_status);
#endif // !defined (ASDF_ARCH_H)
//-------|---------|---------+---------+---------+---------+---------+---------+

View File

@ -49,7 +49,7 @@ TEST1_DEPS = ./$(TEST1).c $(UNITY_DIR)/unity.c
TEST1_BUILD = $(BUILD_DIR)/test_$(TEST1)
TEST2 = asdf_modifiers
TEST2_SRC = $(TEST_DIR)/test_$(TEST2).c
TEST2_SRC = $(TEST_DIR)/test_$(TEST2).c ./asdf_arch.c
TEST2_DEPS = ./$(TEST2).c $(UNITY_DIR)/unity.c
TEST2_BUILD = $(BUILD_DIR)/test_$(TEST2)
@ -94,6 +94,8 @@ $(ARCH_TOKEN):
touch $(ARCH_TOKEN)
asdf_keymaps.c: asdf.h asdf_ascii.h asdf_modifiers.h asdf_arch.h asdf_keymaps.h asdf_keymap_defs.h
asdf_modifiers.c: asdf_modifiers.h asdf_arch.h asdf_keymap_defs.h
asdf_arch.h: asdf_arch.h
tags: $(SRC_FILES)
etags $(SRC_FILES)

View File

@ -26,6 +26,7 @@
#include <stdint.h>
#include "asdf_modifiers.h"
#include "asdf_arch.h"
static shift_state_t shift_state;
static caps_state_t caps_state;
@ -92,6 +93,22 @@ void asdf_modifier_shiftlock_activate(void)
}
}
// PROCEDURE: asdf_modifier_set_caps_state
// INPUTS: (uint8_t) new_state
// OUTPUTS: none
//
// DESCRIPTION: sets CAPS state and sets CAPS LED.
//
// SIDE EFFECTS: see DESCRIPTION
//
// COMPLEXITY: 1
//
void asdf_modifier_set_caps_state(uint8_t new_state)
{
uint8_t caps_state = new_state;
asdf_arch_caps_led(caps_state);
}
// PROCEDURE: asdf_modifier_caps_activate
// INPUTS: none
// OUTPUTS: none
@ -104,7 +121,7 @@ void asdf_modifier_shiftlock_activate(void)
//
void asdf_modifier_caps_activate(void)
{
caps_state |= CAPS_ON_ST;
asdf_modifier_set_caps_state(caps_state |= CAPS_ON_ST);
}
// PROCEDURE: asdf_modifier_caps_deactivate
@ -119,7 +136,7 @@ void asdf_modifier_caps_activate(void)
//
void asdf_modifier_caps_deactivate(void)
{
caps_state &= ~CAPS_ON_ST;
asdf_modifier_set_caps_state(caps_state &= ~CAPS_ON_ST);
}
// PROCEDURE: asdf_modifier_capslock_activate
@ -134,7 +151,7 @@ void asdf_modifier_caps_deactivate(void)
//
void asdf_modifier_capslock_activate(void)
{
caps_state ^= CAPS_LOCKED_ST;
asdf_modifier_set_caps_state(caps_state ^= CAPS_LOCKED_ST);
}
// PROCEDURE: asdf_modifier_ctrl_activate