Refactor to minimize differences between galp3-c and lemp9 code

This commit is contained in:
Jeremy Soller 2020-01-15 15:54:43 -07:00
parent e2a38c7a88
commit efa9fb7fb4
No known key found for this signature in database
GPG Key ID: E988B49EE78A7FB1
27 changed files with 493 additions and 612 deletions

View File

@ -2,10 +2,9 @@
#include <board/battery.h>
#include <board/peci.h>
#include <common/debug.h>
#include <ec/gpio.h>
#include <board/gpio.h>
static struct Gpio __code ACIN_N = GPIO(B, 6);
static struct Gpio __code LID_SW_N = GPIO(D, 1);
extern bool lid_wake;
uint8_t acpi_read(uint8_t addr) {
uint8_t data = 0;
@ -30,6 +29,9 @@ uint8_t acpi_read(uint8_t addr) {
// Lid is open
data |= 1 << 0;
}
if (lid_wake) {
data |= 1 << 2;
}
break;
// Handle AC adapter and battery present
@ -64,14 +66,13 @@ uint8_t acpi_read(uint8_t addr) {
}
// If not in debug mode, data is not used, ignore warning
#pragma save
#pragma disable_warning 85
void acpi_write(uint8_t addr, uint8_t data) {
DEBUG("acpi_write %02X = %02X\n", addr, data);
switch (addr) {
//TODO
// Lid state and other flags
case 0x03:
lid_wake = (bool)(data & (1 << 2));
break;
}
}
#pragma restore

View File

@ -1,7 +1,8 @@
EC=it8587e
# Add keymaps to include
INCLUDE+=$(wildcard $(BOARD_DIR)/keymap/*.h)
# Add keymap to src
KEYMAP?=default
SRC+=$(BOARD_DIR)/keymap/$(KEYMAP).c
# Set log level
# 0 - NONE

View File

@ -1,6 +1,42 @@
#include <board/gpio.h>
#include <common/debug.h>
struct Gpio __code ACIN_N = GPIO(B, 6);
struct Gpio __code AC_PRESENT = GPIO(E, 7);
struct Gpio __code ALL_SYS_PWRGD = GPIO(C, 0);
struct Gpio __code BKL_EN = GPIO(H, 2);
struct Gpio __code BT_EN = GPIO(F, 3);
struct Gpio __code BUF_PLT_RST_N = GPIO(D, 2);
struct Gpio __code CCD_EN = GPIO(G, 0);
struct Gpio __code DD_ON = GPIO(E, 4);
struct Gpio __code EC_EN = GPIO(E, 1);
struct Gpio __code EC_RSMRST_N = GPIO(E, 5);
struct Gpio __code LED_ACIN = GPIO(C, 7);
struct Gpio __code LED_BAT_CHG = GPIO(A, 5);
struct Gpio __code LED_BAT_FULL = GPIO(A, 6);
struct Gpio __code LED_PWR = GPIO(A, 7);
struct Gpio __code LID_SW_N = GPIO(D, 1);
struct Gpio __code PCH_DPWROK_EC = GPIO(A, 3);
struct Gpio __code PCH_PWROK_EC = GPIO(A, 4);
struct Gpio __code PM_CLKRUN_N = GPIO(H, 0);
struct Gpio __code PM_PWROK = GPIO(C, 6);
struct Gpio __code PWR_BTN_N = GPIO(D, 5);
struct Gpio __code PWR_SW_N = GPIO(D, 0);
struct Gpio __code SB_KBCRST_N = GPIO(E, 6);
struct Gpio __code SCI_N = GPIO(D, 4);
struct Gpio __code SLP_SUS_N = GPIO(I, 2);
struct Gpio __code SMI_N = GPIO(D, 3);
struct Gpio __code SUSB_N_PCH = GPIO(H, 6);
struct Gpio __code SUSC_N_PCH = GPIO(H, 1);
struct Gpio __code SUSWARN_N = GPIO(D, 7);
struct Gpio __code SUS_PWR_ACK = GPIO(J, 0);
struct Gpio __code SWI_N = GPIO(E, 0);
struct Gpio __code USB_PWR_EN_N = GPIO(F, 7);
struct Gpio __code VA_EC_EN = GPIO(E, 3);
struct Gpio __code VR_ON = GPIO(H, 4);
struct Gpio __code WLAN_EN = GPIO(H, 5);
struct Gpio __code WLAN_PWR_EN = GPIO(J, 4);
void gpio_init() {
// Enable LPC reset on GPD2
GCR = 0x04;

View File

@ -12,4 +12,38 @@
void gpio_init(void);
void gpio_debug(void);
extern struct Gpio __code ACIN_N;
extern struct Gpio __code AC_PRESENT;
extern struct Gpio __code ALL_SYS_PWRGD;
extern struct Gpio __code BKL_EN;
extern struct Gpio __code BT_EN;
extern struct Gpio __code BUF_PLT_RST_N;
extern struct Gpio __code CCD_EN;
extern struct Gpio __code DD_ON;
extern struct Gpio __code EC_EN;
extern struct Gpio __code EC_RSMRST_N;
extern struct Gpio __code LED_ACIN;
extern struct Gpio __code LED_PWR;
extern struct Gpio __code LID_SW_N;
extern struct Gpio __code PCH_DPWROK_EC;
extern struct Gpio __code PCH_PWROK_EC;
extern struct Gpio __code PM_CLKRUN_N;
extern struct Gpio __code PM_PWROK;
extern struct Gpio __code PWR_BTN_N;
extern struct Gpio __code PWR_SW_N;
extern struct Gpio __code SB_KBCRST_N;
extern struct Gpio __code SCI_N;
extern struct Gpio __code SLP_SUS_N;
extern struct Gpio __code SMI_N;
extern struct Gpio __code SUSB_N_PCH;
extern struct Gpio __code SUSC_N_PCH;
extern struct Gpio __code SUSWARN_N;
extern struct Gpio __code SUS_PWR_ACK;
extern struct Gpio __code SWI_N;
extern struct Gpio __code USB_PWR_EN_N;
extern struct Gpio __code VA_EC_EN;
extern struct Gpio __code VR_ON;
extern struct Gpio __code WLAN_EN;
extern struct Gpio __code WLAN_PWR_EN;
#endif // _BOARD_GPIO_H

View File

@ -1,7 +1,7 @@
#ifndef _BOARD_KEYMAP_H
#define _BOARD_KEYMAP_H
#include <stdint.h>
#include <common/keymap.h>
// Keymap output pins (16 for galago, 18 for darter)
#define KM_OUT 18
@ -10,198 +10,10 @@
// Keymap layers (normal, Fn)
#define KM_LAY 2
// Keymap
extern uint16_t __code KEYMAP[KM_LAY][KM_OUT][KM_IN];
// Get a keycode from the keymap
uint16_t keymap(int output, int input, int layer);
uint16_t keymap_translate(uint16_t key);
// Key types
#define KT_MASK (0xF000)
// Normal keys
#define KT_NORMAL (0x0000)
// Layer selection
#define KT_FN (0x1000)
// SCI
#define KT_SCI (0x2000)
#define SCI_BRIGHTNESS_DOWN (0x11)
#define SCI_BRIGHTNESS_UP (0x12)
#define SCI_AIRPLANE_MODE (0x14)
#define SCI_SUSPEND (0x15)
// See http://www.techtoys.com.hk/Downloads/Download/Microchip/PS2_driver/ScanCode.pdf
// Should send 0xE0 before scancode bytes
#define K_E0 (0x0100)
// Hotkeys
#define K_PLAY_PAUSE (K_E0 | 0x34)
#define K_MUTE (K_E0 | 0x23)
#define K_VOLUME_DOWN (K_E0 | 0x21)
#define K_VOLUME_UP (K_E0 | 0x32)
// Custom scancode
#define K_TOUCHPAD (K_E0 | 0x63)
// Function keys
#define K_F1 (0x05)
#define K_F2 (0x06)
#define K_F3 (0x04)
#define K_F4 (0x0C)
#define K_F5 (0x03)
#define K_F6 (0x0B)
#define K_F7 (0x83)
#define K_F8 (0x0A)
#define K_F9 (0x01)
#define K_F10 (0x09)
#define K_F11 (0x78)
#define K_F12 (0x07)
// Number keys
#define K_0 (0x45)
#define K_1 (0x16)
#define K_2 (0x1E)
#define K_3 (0x26)
#define K_4 (0x25)
#define K_5 (0x2E)
#define K_6 (0x36)
#define K_7 (0x3D)
#define K_8 (0x3E)
#define K_9 (0x46)
// Letter keys
#define K_A (0x1C)
#define K_B (0x32)
#define K_C (0x21)
#define K_D (0x23)
#define K_E (0x24)
#define K_F (0x2B)
#define K_G (0x34)
#define K_H (0x33)
#define K_I (0x43)
#define K_J (0x3B)
#define K_K (0x42)
#define K_L (0x4B)
#define K_M (0x3A)
#define K_N (0x31)
#define K_O (0x44)
#define K_P (0x4D)
#define K_Q (0x15)
#define K_R (0x2D)
#define K_S (0x1B)
#define K_T (0x2C)
#define K_U (0x3C)
#define K_V (0x2A)
#define K_W (0x1D)
#define K_X (0x22)
#define K_Y (0x35)
#define K_Z (0x1A)
// Special keys
// Escape key
#define K_ESC (0x76)
//TODO: Print screen, scroll lock, pause
// Tick/tilde key
#define K_TICK (0x0E)
// Minus/underline key
#define K_MINUS (0x4E)
// Equals/plus key
#define K_EQUALS (0x55)
// Backspace key
#define K_BKSP (0x66)
// Tab key
#define K_TAB (0x0D)
// Bracket open key
#define K_BRACE_OPEN (0x54)
// Bracket close key
#define K_BRACE_CLOSE (0x5B)
// Backslash/pipe key
#define K_BACKSLASH (0x5D)
// Capslock
#define K_CAPS (0x58)
// Semicolon key
#define K_SEMICOLON (0x4C)
// Quote key
#define K_QUOTE (0x52)
// Enter key
#define K_ENTER (0x5A)
// Left shift
#define K_LEFT_SHIFT (0x12)
// Comma key
#define K_COMMA (0x41)
// Period key
#define K_PERIOD (0x49)
// Slash key
#define K_SLASH (0x4A)
// Right shift
#define K_RIGHT_SHIFT (0x59)
// Left control key
#define K_LEFT_CTRL (0x14)
// Left super key
#define K_LEFT_SUPER (K_E0 | 0x1F)
// Left alt key
#define K_LEFT_ALT (0x11)
// Space key
#define K_SPACE (0x29)
// Right alt key
#define K_RIGHT_ALT (K_E0 | 0x11)
// Right super key
#define K_RIGHT_SUPER (K_E0 | 0x27)
// Application key
#define K_APP (K_E0 | 0x2F)
// Right control key
#define K_RIGHT_CTRL (K_E0 | 0x14)
// Arrow keys and related
// Insert key
#define K_INSERT (K_E0 | 0x70)
// Delete key
#define K_DEL (K_E0 | 0x71)
// Home key
#define K_HOME (K_E0 | 0x6C)
// End key
#define K_END (K_E0 | 0x69)
// Page up key
#define K_PGUP (K_E0 | 0x7D)
// Page down key
#define K_PGDN (K_E0 | 0x7A)
#define K_UP (K_E0 | 0x75)
#define K_LEFT (K_E0 | 0x6B)
#define K_DOWN (K_E0 | 0x72)
#define K_RIGHT (K_E0 | 0x74)
// Numpad
#define K_NUM_LOCK (0x77)
#define K_NUM_SLASH (K_E0 | 0x4A)
#define K_NUM_ASTERISK (0x7C)
#define K_NUM_MINUS (0x7B)
#define K_NUM_PLUS (0x79)
#define K_NUM_PERIOD (0x71)
#define K_NUM_ENTER (K_E0 | 0x5A)
#define K_NUM_0 (0x70)
#define K_NUM_1 (0x69)
#define K_NUM_2 (0x72)
#define K_NUM_3 (0x7A)
#define K_NUM_4 (0x6B)
#define K_NUM_5 (0x73)
#define K_NUM_6 (0x74)
#define K_NUM_7 (0x6C)
#define K_NUM_8 (0x75)
#define K_NUM_9 (0x7D)
#endif // _BOARD_KEYMAP_H

View File

@ -9,6 +9,7 @@ extern uint8_t peci_duty;
extern uint8_t peci_tcontrol;
extern uint8_t peci_tjmax;
void peci_init(void);
void peci_event(void);
#endif // _BOARD_PECI_H

View File

@ -1,9 +1,6 @@
#include <board/keymap.h>
#include <common/debug.h>
// Set the desired keymap here
#include "keymap/default.h"
uint16_t keymap(int output, int input, int layer) {
if (output < KM_OUT && input < KM_IN && layer < KM_LAY) {
return KEYMAP[output][input][layer];
@ -12,26 +9,3 @@ uint16_t keymap(int output, int input, int layer) {
}
}
// https://www.win.tue.nl/~aeb/linux/kbd/scancodes-10.html#ss10.3
static uint8_t __code lookup[256] = {
0xff, 0x43, 0x41, 0x3f, 0x3d, 0x3b, 0x3c, 0x58, 0x64, 0x44, 0x42, 0x40, 0x3e, 0x0f, 0x29, 0x59,
0x65, 0x38, 0x2a, 0x70, 0x1d, 0x10, 0x02, 0x5a, 0x66, 0x71, 0x2c, 0x1f, 0x1e, 0x11, 0x03, 0x5b,
0x67, 0x2e, 0x2d, 0x20, 0x12, 0x05, 0x04, 0x5c, 0x68, 0x39, 0x2f, 0x21, 0x14, 0x13, 0x06, 0x5d,
0x69, 0x31, 0x30, 0x23, 0x22, 0x15, 0x07, 0x5e, 0x6a, 0x72, 0x32, 0x24, 0x16, 0x08, 0x09, 0x5f,
0x6b, 0x33, 0x25, 0x17, 0x18, 0x0b, 0x0a, 0x60, 0x6c, 0x34, 0x35, 0x26, 0x27, 0x19, 0x0c, 0x61,
0x6d, 0x73, 0x28, 0x74, 0x1a, 0x0d, 0x62, 0x6e, 0x3a, 0x36, 0x1c, 0x1b, 0x75, 0x2b, 0x63, 0x76,
0x55, 0x56, 0x77, 0x78, 0x79, 0x7a, 0x0e, 0x7b, 0x7c, 0x4f, 0x7d, 0x4b, 0x47, 0x7e, 0x7f, 0x6f,
0x52, 0x53, 0x50, 0x4c, 0x4d, 0x48, 0x01, 0x45, 0x57, 0x4e, 0x51, 0x4a, 0x37, 0x49, 0x46, 0x54,
0x80, 0x81, 0x82, 0x41, 0x54, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f,
0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f,
0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7, 0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf,
0xb0, 0xb1, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6, 0xb7, 0xb8, 0xb9, 0xba, 0xbb, 0xbc, 0xbd, 0xbe, 0xbf,
0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7, 0xc8, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf,
0xd0, 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7, 0xd8, 0xd9, 0xda, 0xdb, 0xdc, 0xdd, 0xde, 0xdf,
0xe0, 0xe1, 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7, 0xe8, 0xe9, 0xea, 0xeb, 0xec, 0xed, 0xee, 0xef,
0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff,
};
uint16_t keymap_translate(uint16_t key) {
return (key & 0xFF00) | lookup[(key & 0xFF)];
}

View File

@ -1,5 +1,7 @@
// Default layout
#include <board/keymap.h>
#define K(V) {V, V}
uint16_t __code KEYMAP[KM_OUT][KM_IN][KM_LAY] = {

View File

@ -1,5 +1,7 @@
// Default layout - http://www.keyboard-layout-editor.com/#/gists/6aec6d441a039b76ec0895bd6bbda68d
#include <board/keymap.h>
#define K(V) {V, V}
uint16_t __code KEYMAP[KM_OUT][KM_IN][KM_LAY] = {

View File

@ -1,5 +1,7 @@
// Jeremy's layout - http://www.keyboard-layout-editor.com/#/gists/fe00274727fc01b78a79d79473cd547c
#include <board/keymap.h>
#define K(V) {V, V}
uint16_t __code KEYMAP[KM_OUT][KM_IN][KM_LAY] = {

View File

@ -51,52 +51,9 @@ void init(void) {
kbscan_init();
pwm_init();
smbus_init();
peci_init();
//TODO: INTC, PECI
// Allow PECI pin to be used
GCR2 |= (1 << 4);
}
void ac_adapter() {
static struct Gpio __code ACIN_N = GPIO(B, 6);
static struct Gpio __code LED_ACIN = GPIO(C, 7);
static bool send_sci = true;
static bool last = true;
// Check if the adapter line goes low
bool new = gpio_get(&ACIN_N);
// Set ACIN LED
gpio_set(&LED_ACIN, !new);
// If there has been a change, print
if (new != last) {
DEBUG("Power adapter ");
if (new) {
DEBUG("unplugged\n");
battery_charger_disable();
} else {
DEBUG("plugged in\n");
battery_charger_enable();
}
battery_debug();
// Reset main loop cycle to force reading PECI and battery
main_cycle = 0;
// Send SCI to update AC and battery information
send_sci = true;
}
if (send_sci) {
// Send SCI 0x16 for AC detect event
if (pmc_sci(&PMC_1, 0x16)) {
send_sci = false;
}
}
last = new;
//TODO: INTC
}
void touchpad_event(struct Ps2 * ps2) {
@ -115,9 +72,8 @@ void touchpad_event(struct Ps2 * ps2) {
}
}
bool lid_wake = false;
void lid_event(void) {
static struct Gpio __code LID_SW_N = GPIO(D, 1);
static bool send_sci = true;
static bool last = true;
@ -129,7 +85,16 @@ void lid_event(void) {
if (new) {
DEBUG("open\n");
//TODO: send SWI if needed
if (lid_wake) {
gpio_set(&SWI_N, false);
//TODO: find correct delay
delay_ticks(10);
gpio_set(&SWI_N, true);
lid_wake = false;
}
} else {
DEBUG("closed\n");
}
@ -156,20 +121,6 @@ void main(void) {
INFO("\n");
static struct Gpio __code LED_BAT_CHG = GPIO(A, 5);
static struct Gpio __code LED_BAT_FULL = GPIO(A, 6);
static struct Gpio __code SMI_N = GPIO(D, 3);
static struct Gpio __code SCI_N = GPIO(D, 4);
static struct Gpio __code SWI_N = GPIO(E, 0);
static struct Gpio __code SB_KBCRST_N = GPIO(E, 6);
static struct Gpio __code BT_EN = GPIO(F, 3);
static struct Gpio __code USB_PWR_EN_N = GPIO(F, 7);
static struct Gpio __code CCD_EN = GPIO(G, 0);
static struct Gpio __code PM_CLKRUN_N = GPIO(H, 0);
static struct Gpio __code BKL_EN = GPIO(H, 2);
static struct Gpio __code WLAN_EN = GPIO(H, 5);
static struct Gpio __code WLAN_PWR_EN = GPIO(J, 4);
// Set the battery full LED (to know our firmware is loading)
gpio_set(&LED_BAT_CHG, true);
@ -199,8 +150,6 @@ void main(void) {
INFO("Hello from System76 EC for %s!\n", xstr(__BOARD__));
for(main_cycle = 0; ; main_cycle++) {
// Enables or disables battery charging based on AC adapter
ac_adapter();
// Handle power states
power_event();
// Scans keyboard and sends keyboard packets

View File

@ -2,6 +2,7 @@
#include <board/peci.h>
#include <common/debug.h>
#include <ec/gpio.h>
#include <ec/pwm.h>
// Tjunction = 100C for i7-8565U (and probably the same for all WHL-U)
@ -16,6 +17,16 @@ static bool peci_config_loaded = false;
#define PECI_TEMP(X) (((int16_t)(X)) << 6)
void peci_init(void) {
// Allow PECI pin to be used
GCR2 |= (1 << 4);
// Set frequency to 1MHz
HOCTL2R = 0x01;
// Set VTT to 1V
PADCTLR = 0x02;
}
// Read tjmax using index 16 of RdPkgConfig
static void peci_config(void) {
// Wait for completion

View File

@ -1,8 +1,8 @@
#include <board/acpi.h>
#include <board/gpio.h>
#include <board/pmc.h>
#include <board/scratch.h>
#include <common/debug.h>
#include <ec/gpio.h>
void pmc_init(void) {
*(PMC_1.control) = 0x41;
@ -19,7 +19,6 @@ enum PmcState {
};
static uint8_t pmc_sci_queue = 0;
static struct Gpio __code SCI_N = GPIO(D, 4);
bool pmc_sci(struct Pmc * pmc, uint8_t sci) {
bool update = pmc_sci_queue == 0;

View File

@ -1,34 +1,18 @@
#include <mcs51/8051.h>
#include <arch/delay.h>
#include <board/battery.h>
#include <board/gpio.h>
#include <board/power.h>
#include <board/pmc.h>
#include <board/pnp.h>
#include <common/debug.h>
#include <ec/gpio.h>
// Platform does not currently support Deep Sx
#define DEEP_SX 0
extern uint8_t main_cycle;
static struct Gpio __code PCH_DPWROK_EC = GPIO(A, 3);
static struct Gpio __code PCH_PWROK_EC = GPIO(A, 4);
static struct Gpio __code LED_PWR = GPIO(A, 7);
static struct Gpio __code ALL_SYS_PWRGD = GPIO(C, 0);
static struct Gpio __code PM_PWROK = GPIO(C, 6);
static struct Gpio __code PWR_SW_N = GPIO(D, 0);
static struct Gpio __code BUF_PLT_RST_N = GPIO(D, 2);
static struct Gpio __code PWR_BTN_N = GPIO(D, 5);
static struct Gpio __code SUSWARN_N = GPIO(D, 7);
static struct Gpio __code EC_EN = GPIO(E, 1);
static struct Gpio __code VA_EC_EN = GPIO(E, 3);
static struct Gpio __code DD_ON = GPIO(E, 4);
static struct Gpio __code EC_RSMRST_N = GPIO(E, 5);
static struct Gpio __code AC_PRESENT = GPIO(E, 7);
static struct Gpio __code SUSC_N_PCH = GPIO(H, 1);
static struct Gpio __code VR_ON = GPIO(H, 4);
static struct Gpio __code SUSB_N_PCH = GPIO(H, 6);
static struct Gpio __code SLP_SUS_N = GPIO(I, 2);
static struct Gpio __code SUS_PWR_ACK = GPIO(J, 0);
// VccRTC stable (55%) to RTCRST# high
#define tPCH01 delay_ms(9)
// VccDSW stable (95%) to RSMRST# high
@ -192,6 +176,35 @@ void power_event(void) {
state = POWER_STATE_DS5;
}
// Check if the adapter line goes low
static bool ac_send_sci = true;
static bool ac_last = true;
bool ac_new = gpio_get(&ACIN_N);
if (ac_new != ac_last) {
DEBUG("Power adapter ");
if (ac_new) {
DEBUG("unplugged\n");
battery_charger_disable();
} else {
DEBUG("plugged in\n");
battery_charger_enable();
}
battery_debug();
// Reset main loop cycle to force reading PECI and battery
main_cycle = 0;
// Send SCI to update AC and battery information
ac_send_sci = true;
}
if (ac_send_sci) {
// Send SCI 0x16 for AC detect event
if (pmc_sci(&PMC_1, 0x16)) {
ac_send_sci = false;
}
}
ac_last = ac_new;
// Read power switch state
static bool ps_last = true;
bool ps_new = gpio_get(&PWR_SW_N);
@ -278,16 +291,20 @@ void power_event(void) {
DEBUG("%02X: SLP_S3# de-asserted\n", main_cycle);
}
s3_last = s3_new;
#endif
static bool s4_last = false;
bool s4_new = gpio_get(&SUSC_N_PCH);
static bool s4_last = false;
bool s4_new = gpio_get(&SUSC_N_PCH);
#if LEVEL >= LEVEL_DEBUG
if (!s4_new && s4_last) {
DEBUG("%02X: SLP_S4# asserted\n", main_cycle);
} else if(s4_new && !s4_last) {
DEBUG("%02X: SLP_S4# de-asserted\n", main_cycle);
}
s4_last = s4_new;
#endif
s4_last = s4_new;
#if LEVEL >= LEVEL_DEBUG
static bool sus_last = false;
bool sus_new = gpio_get(&SLP_SUS_N);
if (!sus_new && sus_last) {
@ -305,7 +322,7 @@ void power_event(void) {
if (ack_new && !ack_last) {
DEBUG("%02X: SUSPWRDNACK asserted\n", main_cycle);
if (gpio_get(&SUSC_N_PCH)) {
if (s4_new) {
DEBUG("%02X: entering S3 state\n", main_cycle);
} else if (state == POWER_STATE_S5) {
power_off_s5();
@ -319,5 +336,47 @@ void power_event(void) {
#endif
ack_last = ack_new;
if (rst_new) {
// CPU on, green light
gpio_set(&LED_PWR, true);
gpio_set(&LED_ACIN, false);
} else if (s4_new) {
// Suspended, flashing green light
static int8_t suspend_timer = 0;
if (suspend_timer <= 0) {
gpio_set(&LED_PWR, !gpio_get(&LED_PWR));
// Suspend timer fires every 1 s
suspend_timer = 100;
}
gpio_set(&LED_ACIN, false);
// If timer 1 is finished
if (TF1) {
// Stop timer 1 running
TR1 = 0;
// Clear timer 1 finished flag
TF1 = 0;
// Decrement suspend timer
suspend_timer -= 1;
}
// If timer 1 is not running
if (!TR1) {
// Start timer for 10 ms
// 65536-(10000 * 69 + 89)/90 = 0xE20C
TMOD = (TMOD & 0x0F) | 0x10;
TH1 = 0xE2;
TL1 = 0x0C;
TR1 = 1;
}
} else if (!ac_new) {
// AC plugged in, orange light
gpio_set(&LED_PWR, false);
gpio_set(&LED_ACIN, true);
} else {
// CPU off and AC adapter unplugged, no light
gpio_set(&LED_PWR, false);
gpio_set(&LED_ACIN, false);
}
#endif // DEEP_SX
}

View File

@ -16,9 +16,6 @@ void smbus_init(void) {
SMB45P3USL = 0xA1;
SMB45P3USH = 0x01;
// Clock set to 50 KHz
// SCLKTSA = 1;
// Set up for i2c usage
i2c_reset(true);
}

View File

@ -2,13 +2,10 @@
#include <board/battery.h>
#include <board/peci.h>
#include <common/debug.h>
#include <ec/gpio.h>
#include <board/gpio.h>
extern bool lid_wake;
static struct Gpio __code ACIN_N = GPIO(B, 0);
static struct Gpio __code LID_SW_N = GPIO(B, 1);
uint8_t acpi_read(uint8_t addr) {
uint8_t data = 0;

View File

@ -1,7 +1,7 @@
EC=it5570e
# Add keymap to src
KEYMAP?=jeremy
KEYMAP?=default
SRC+=$(BOARD_DIR)/keymap/$(KEYMAP).c
# Set log level

View File

@ -1,40 +1,39 @@
#include <board/gpio.h>
#include <common/debug.h>
struct Gpio __code WLAN_PWR_EN = GPIO(A, 3);
struct Gpio __code PCH_PWROK_EC = GPIO(A, 6);
struct Gpio __code PCH_DPWROK_EC = GPIO(A, 7);
struct Gpio __code ACIN_N = GPIO(B, 0);
struct Gpio __code LID_SW_N = GPIO(B, 1);
struct Gpio __code PWR_SW_N = GPIO(B, 3);
struct Gpio __code SWI_N = GPIO(B, 5);
struct Gpio __code AC_PRESENT = GPIO(E, 1);
struct Gpio __code ALL_SYS_PWRGD = GPIO(C, 0);
struct Gpio __code PM_PWROK = GPIO(C, 6);
struct Gpio __code BKL_EN = GPIO(H, 2);
struct Gpio __code BT_EN = GPIO(F, 3);
struct Gpio __code BUF_PLT_RST_N = GPIO(D, 2);
struct Gpio __code CCD_EN = GPIO(D, 1);
struct Gpio __code DD_ON = GPIO(E, 4);
struct Gpio __code EC_EN = GPIO(J, 6);
struct Gpio __code EC_RSMRST_N = GPIO(E, 5);
struct Gpio __code LED_ACIN = GPIO(C, 7);
struct Gpio __code LED_PWR = GPIO(D, 0);
struct Gpio __code CCD_EN = GPIO(D, 1);
struct Gpio __code BUF_PLT_RST_N = GPIO(D, 2);
struct Gpio __code SCI_N = GPIO(D, 3);
struct Gpio __code SMI_N = GPIO(D, 4);
struct Gpio __code PWR_BTN_N = GPIO(D, 5);
struct Gpio __code SUSWARN_N = GPIO(D, 7);
struct Gpio __code AC_PRESENT = GPIO(E, 1);
struct Gpio __code USB_PWR_EN_N = GPIO(E, 3);
struct Gpio __code DD_ON = GPIO(E, 4);
struct Gpio __code EC_RSMRST_N = GPIO(E, 5);
struct Gpio __code SB_KBCRST_N = GPIO(E, 6);
struct Gpio __code BT_EN = GPIO(F, 3);
struct Gpio __code WLAN_EN = GPIO(G, 1);
struct Gpio __code LID_SW_N = GPIO(B, 1);
struct Gpio __code PCH_DPWROK_EC = GPIO(A, 7);
struct Gpio __code PCH_PWROK_EC = GPIO(A, 6);
struct Gpio __code PM_CLKRUN_N = GPIO(H, 0);
struct Gpio __code SUSC_N_PCH = GPIO(H, 1);
struct Gpio __code BKL_EN = GPIO(H, 2);
struct Gpio __code VR_ON = GPIO(H, 4);
struct Gpio __code SUSB_N_PCH = GPIO(H, 6);
struct Gpio __code PM_PWROK = GPIO(C, 6);
struct Gpio __code PWR_BTN_N = GPIO(D, 5);
struct Gpio __code PWR_SW_N = GPIO(B, 3);
struct Gpio __code SB_KBCRST_N = GPIO(E, 6);
struct Gpio __code SCI_N = GPIO(D, 3);
struct Gpio __code SLP_SUS_N = GPIO(J, 3);
struct Gpio __code VA_EC_EN = GPIO(J, 4);
struct Gpio __code EC_EN = GPIO(J, 6);
struct Gpio __code SMI_N = GPIO(D, 4);
struct Gpio __code SUSB_N_PCH = GPIO(H, 6);
struct Gpio __code SUSC_N_PCH = GPIO(H, 1);
struct Gpio __code SUSWARN_N = GPIO(D, 7);
struct Gpio __code SUS_PWR_ACK = GPIO(J, 7);
struct Gpio __code SWI_N = GPIO(B, 5);
struct Gpio __code USB_PWR_EN_N = GPIO(E, 3);
struct Gpio __code VA_EC_EN = GPIO(J, 4);
struct Gpio __code VR_ON = GPIO(H, 4);
struct Gpio __code WLAN_EN = GPIO(G, 1);
struct Gpio __code WLAN_PWR_EN = GPIO(A, 3);
void gpio_init() {
// Enable LPC reset on GPD2

View File

@ -12,4 +12,38 @@
void gpio_init(void);
void gpio_debug(void);
extern struct Gpio __code ACIN_N;
extern struct Gpio __code AC_PRESENT;
extern struct Gpio __code ALL_SYS_PWRGD;
extern struct Gpio __code BKL_EN;
extern struct Gpio __code BT_EN;
extern struct Gpio __code BUF_PLT_RST_N;
extern struct Gpio __code CCD_EN;
extern struct Gpio __code DD_ON;
extern struct Gpio __code EC_EN;
extern struct Gpio __code EC_RSMRST_N;
extern struct Gpio __code LED_ACIN;
extern struct Gpio __code LED_PWR;
extern struct Gpio __code LID_SW_N;
extern struct Gpio __code PCH_DPWROK_EC;
extern struct Gpio __code PCH_PWROK_EC;
extern struct Gpio __code PM_CLKRUN_N;
extern struct Gpio __code PM_PWROK;
extern struct Gpio __code PWR_BTN_N;
extern struct Gpio __code PWR_SW_N;
extern struct Gpio __code SB_KBCRST_N;
extern struct Gpio __code SCI_N;
extern struct Gpio __code SLP_SUS_N;
extern struct Gpio __code SMI_N;
extern struct Gpio __code SUSB_N_PCH;
extern struct Gpio __code SUSC_N_PCH;
extern struct Gpio __code SUSWARN_N;
extern struct Gpio __code SUS_PWR_ACK;
extern struct Gpio __code SWI_N;
extern struct Gpio __code USB_PWR_EN_N;
extern struct Gpio __code VA_EC_EN;
extern struct Gpio __code VR_ON;
extern struct Gpio __code WLAN_EN;
extern struct Gpio __code WLAN_PWR_EN;
#endif // _BOARD_GPIO_H

View File

@ -1,7 +1,7 @@
#ifndef _BOARD_KEYMAP_H
#define _BOARD_KEYMAP_H
#include <stdint.h>
#include <common/keymap.h>
#define ___ 0
@ -46,197 +46,4 @@ extern uint16_t __code KEYMAP[KM_LAY][KM_OUT][KM_IN];
// Get a keycode from the keymap
uint16_t keymap(int output, int input, int layer);
// Translate a keycode from PS/2 set 2 to PS/2 set 1
uint16_t keymap_translate(uint16_t key);
// Key types
#define KT_MASK (0xF000)
// Normal keys
#define KT_NORMAL (0x0000)
// Layer selection
#define KT_FN (0x1000)
// SCI
#define KT_SCI (0x2000)
#define SCI_BRIGHTNESS_DOWN (0x11)
#define SCI_BRIGHTNESS_UP (0x12)
#define SCI_AIRPLANE_MODE (0x14)
#define SCI_SUSPEND (0x15)
// See http://www.techtoys.com.hk/Downloads/Download/Microchip/PS2_driver/ScanCode.pdf
// Should send 0xE0 before scancode bytes
#define K_E0 (0x0100)
// Hotkeys
#define K_PLAY_PAUSE (K_E0 | 0x34)
#define K_MUTE (K_E0 | 0x23)
#define K_VOLUME_DOWN (K_E0 | 0x21)
#define K_VOLUME_UP (K_E0 | 0x32)
// Custom scancode
#define K_TOUCHPAD (K_E0 | 0x63)
// Function keys
#define K_F1 (0x05)
#define K_F2 (0x06)
#define K_F3 (0x04)
#define K_F4 (0x0C)
#define K_F5 (0x03)
#define K_F6 (0x0B)
#define K_F7 (0x83)
#define K_F8 (0x0A)
#define K_F9 (0x01)
#define K_F10 (0x09)
#define K_F11 (0x78)
#define K_F12 (0x07)
// Number keys
#define K_0 (0x45)
#define K_1 (0x16)
#define K_2 (0x1E)
#define K_3 (0x26)
#define K_4 (0x25)
#define K_5 (0x2E)
#define K_6 (0x36)
#define K_7 (0x3D)
#define K_8 (0x3E)
#define K_9 (0x46)
// Letter keys
#define K_A (0x1C)
#define K_B (0x32)
#define K_C (0x21)
#define K_D (0x23)
#define K_E (0x24)
#define K_F (0x2B)
#define K_G (0x34)
#define K_H (0x33)
#define K_I (0x43)
#define K_J (0x3B)
#define K_K (0x42)
#define K_L (0x4B)
#define K_M (0x3A)
#define K_N (0x31)
#define K_O (0x44)
#define K_P (0x4D)
#define K_Q (0x15)
#define K_R (0x2D)
#define K_S (0x1B)
#define K_T (0x2C)
#define K_U (0x3C)
#define K_V (0x2A)
#define K_W (0x1D)
#define K_X (0x22)
#define K_Y (0x35)
#define K_Z (0x1A)
// Special keys
// Escape key
#define K_ESC (0x76)
//TODO: Print screen, scroll lock, pause
// Tick/tilde key
#define K_TICK (0x0E)
// Minus/underline key
#define K_MINUS (0x4E)
// Equals/plus key
#define K_EQUALS (0x55)
// Backspace key
#define K_BKSP (0x66)
// Tab key
#define K_TAB (0x0D)
// Bracket open key
#define K_BRACE_OPEN (0x54)
// Bracket close key
#define K_BRACE_CLOSE (0x5B)
// Backslash/pipe key
#define K_BACKSLASH (0x5D)
// Capslock
#define K_CAPS (0x58)
// Semicolon key
#define K_SEMICOLON (0x4C)
// Quote key
#define K_QUOTE (0x52)
// Enter key
#define K_ENTER (0x5A)
// Left shift
#define K_LEFT_SHIFT (0x12)
// Comma key
#define K_COMMA (0x41)
// Period key
#define K_PERIOD (0x49)
// Slash key
#define K_SLASH (0x4A)
// Right shift
#define K_RIGHT_SHIFT (0x59)
// Left control key
#define K_LEFT_CTRL (0x14)
// Left super key
#define K_LEFT_SUPER (K_E0 | 0x1F)
// Left alt key
#define K_LEFT_ALT (0x11)
// Space key
#define K_SPACE (0x29)
// Right alt key
#define K_RIGHT_ALT (K_E0 | 0x11)
// Right super key
#define K_RIGHT_SUPER (K_E0 | 0x27)
// Application key
#define K_APP (K_E0 | 0x2F)
// Right control key
#define K_RIGHT_CTRL (K_E0 | 0x14)
// Arrow keys and related
// Insert key
#define K_INSERT (K_E0 | 0x70)
// Delete key
#define K_DEL (K_E0 | 0x71)
// Home key
#define K_HOME (K_E0 | 0x6C)
// End key
#define K_END (K_E0 | 0x69)
// Page up key
#define K_PGUP (K_E0 | 0x7D)
// Page down key
#define K_PGDN (K_E0 | 0x7A)
#define K_UP (K_E0 | 0x75)
#define K_LEFT (K_E0 | 0x6B)
#define K_DOWN (K_E0 | 0x72)
#define K_RIGHT (K_E0 | 0x74)
// Numpad
#define K_NUM_LOCK (0x77)
#define K_NUM_SLASH (K_E0 | 0x4A)
#define K_NUM_ASTERISK (0x7C)
#define K_NUM_MINUS (0x7B)
#define K_NUM_PLUS (0x79)
#define K_NUM_PERIOD (0x71)
#define K_NUM_ENTER (K_E0 | 0x5A)
#define K_NUM_0 (0x70)
#define K_NUM_1 (0x69)
#define K_NUM_2 (0x72)
#define K_NUM_3 (0x7A)
#define K_NUM_4 (0x6B)
#define K_NUM_5 (0x73)
#define K_NUM_6 (0x74)
#define K_NUM_7 (0x6C)
#define K_NUM_8 (0x75)
#define K_NUM_9 (0x7D)
#endif // _BOARD_KEYMAP_H

View File

@ -9,26 +9,3 @@ uint16_t keymap(int output, int input, int layer) {
}
}
// https://www.win.tue.nl/~aeb/linux/kbd/scancodes-10.html#ss10.3
static uint8_t __code lookup[256] = {
0xff, 0x43, 0x41, 0x3f, 0x3d, 0x3b, 0x3c, 0x58, 0x64, 0x44, 0x42, 0x40, 0x3e, 0x0f, 0x29, 0x59,
0x65, 0x38, 0x2a, 0x70, 0x1d, 0x10, 0x02, 0x5a, 0x66, 0x71, 0x2c, 0x1f, 0x1e, 0x11, 0x03, 0x5b,
0x67, 0x2e, 0x2d, 0x20, 0x12, 0x05, 0x04, 0x5c, 0x68, 0x39, 0x2f, 0x21, 0x14, 0x13, 0x06, 0x5d,
0x69, 0x31, 0x30, 0x23, 0x22, 0x15, 0x07, 0x5e, 0x6a, 0x72, 0x32, 0x24, 0x16, 0x08, 0x09, 0x5f,
0x6b, 0x33, 0x25, 0x17, 0x18, 0x0b, 0x0a, 0x60, 0x6c, 0x34, 0x35, 0x26, 0x27, 0x19, 0x0c, 0x61,
0x6d, 0x73, 0x28, 0x74, 0x1a, 0x0d, 0x62, 0x6e, 0x3a, 0x36, 0x1c, 0x1b, 0x75, 0x2b, 0x63, 0x76,
0x55, 0x56, 0x77, 0x78, 0x79, 0x7a, 0x0e, 0x7b, 0x7c, 0x4f, 0x7d, 0x4b, 0x47, 0x7e, 0x7f, 0x6f,
0x52, 0x53, 0x50, 0x4c, 0x4d, 0x48, 0x01, 0x45, 0x57, 0x4e, 0x51, 0x4a, 0x37, 0x49, 0x46, 0x54,
0x80, 0x81, 0x82, 0x41, 0x54, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f,
0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f,
0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7, 0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf,
0xb0, 0xb1, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6, 0xb7, 0xb8, 0xb9, 0xba, 0xbb, 0xbc, 0xbd, 0xbe, 0xbf,
0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7, 0xc8, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf,
0xd0, 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7, 0xd8, 0xd9, 0xda, 0xdb, 0xdc, 0xdd, 0xde, 0xdf,
0xe0, 0xe1, 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7, 0xe8, 0xe9, 0xea, 0xeb, 0xec, 0xed, 0xee, 0xef,
0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff,
};
uint16_t keymap_translate(uint16_t key) {
return (key & 0xFF00) | lookup[(key & 0xFF)];
}

View File

@ -74,9 +74,6 @@ void touchpad_event(struct Ps2 * ps2) {
bool lid_wake = false;
void lid_event(void) {
extern struct Gpio __code LID_SW_N;
extern struct Gpio __code SWI_N;
static bool send_sci = true;
static bool last = true;
@ -88,7 +85,6 @@ void lid_event(void) {
if (new) {
DEBUG("open\n");
//TODO: send SWI if needed
if (lid_wake) {
gpio_set(&SWI_N, false);
@ -122,17 +118,6 @@ void main(void) {
INFO("\n");
extern struct Gpio __code SMI_N;
extern struct Gpio __code SCI_N;
extern struct Gpio __code SWI_N;
extern struct Gpio __code SB_KBCRST_N;
extern struct Gpio __code BT_EN;
extern struct Gpio __code USB_PWR_EN_N;
extern struct Gpio __code CCD_EN;
extern struct Gpio __code BKL_EN;
extern struct Gpio __code WLAN_EN;
extern struct Gpio __code WLAN_PWR_EN;
#if GPIO_DEBUG
gpio_debug();
#endif

View File

@ -1,8 +1,8 @@
#include <board/acpi.h>
#include <board/gpio.h>
#include <board/pmc.h>
#include <board/scratch.h>
#include <common/debug.h>
#include <ec/gpio.h>
void pmc_init(void) {
*(PMC_1.control) = 0x41;
@ -19,7 +19,6 @@ enum PmcState {
};
static uint8_t pmc_sci_queue = 0;
static struct Gpio __code SCI_N = GPIO(D, 3);
bool pmc_sci(struct Pmc * pmc, uint8_t sci) {
bool update = pmc_sci_queue == 0;

View File

@ -2,39 +2,17 @@
#include <arch/delay.h>
#include <board/battery.h>
#include <board/gpio.h>
#include <board/power.h>
#include <board/pmc.h>
#include <board/pnp.h>
#include <common/debug.h>
#include <ec/gpio.h>
// Platform does not currently support Deep Sx
#define DEEP_SX 0
extern uint8_t main_cycle;
extern struct Gpio __code ACIN_N;
extern struct Gpio __code LED_ACIN;
extern struct Gpio __code PCH_DPWROK_EC;
extern struct Gpio __code PCH_PWROK_EC;
extern struct Gpio __code LED_PWR;
extern struct Gpio __code ALL_SYS_PWRGD;
extern struct Gpio __code PM_PWROK;
extern struct Gpio __code PWR_SW_N;
extern struct Gpio __code BUF_PLT_RST_N;
extern struct Gpio __code PWR_BTN_N;
extern struct Gpio __code SUSWARN_N;
extern struct Gpio __code EC_EN;
extern struct Gpio __code VA_EC_EN;
extern struct Gpio __code DD_ON;
extern struct Gpio __code EC_RSMRST_N;
extern struct Gpio __code AC_PRESENT;
extern struct Gpio __code SUSC_N_PCH;
extern struct Gpio __code VR_ON;
extern struct Gpio __code SUSB_N_PCH;
extern struct Gpio __code SLP_SUS_N;
extern struct Gpio __code SUS_PWR_ACK;
// VccRTC stable (55%) to RTCRST# high
#define tPCH01 delay_ms(9)
// VccDSW stable (95%) to RSMRST# high

View File

@ -0,0 +1,199 @@
#ifndef _COMMON_KEYMAP_H
#define _COMMON_KEYMAP_H
#include <stdint.h>
// Translate a keycode from PS/2 set 2 to PS/2 set 1
uint16_t keymap_translate(uint16_t key);
// Key types
#define KT_MASK (0xF000)
// Normal keys
#define KT_NORMAL (0x0000)
// Layer selection
#define KT_FN (0x1000)
// SCI
#define KT_SCI (0x2000)
#define SCI_BRIGHTNESS_DOWN (0x11)
#define SCI_BRIGHTNESS_UP (0x12)
#define SCI_AIRPLANE_MODE (0x14)
#define SCI_SUSPEND (0x15)
// See http://www.techtoys.com.hk/Downloads/Download/Microchip/PS2_driver/ScanCode.pdf
// Should send 0xE0 before scancode bytes
#define K_E0 (0x0100)
// Hotkeys
#define K_PLAY_PAUSE (K_E0 | 0x34)
#define K_MUTE (K_E0 | 0x23)
#define K_VOLUME_DOWN (K_E0 | 0x21)
#define K_VOLUME_UP (K_E0 | 0x32)
// Custom scancode
#define K_TOUCHPAD (K_E0 | 0x63)
// Function keys
#define K_F1 (0x05)
#define K_F2 (0x06)
#define K_F3 (0x04)
#define K_F4 (0x0C)
#define K_F5 (0x03)
#define K_F6 (0x0B)
#define K_F7 (0x83)
#define K_F8 (0x0A)
#define K_F9 (0x01)
#define K_F10 (0x09)
#define K_F11 (0x78)
#define K_F12 (0x07)
// Number keys
#define K_0 (0x45)
#define K_1 (0x16)
#define K_2 (0x1E)
#define K_3 (0x26)
#define K_4 (0x25)
#define K_5 (0x2E)
#define K_6 (0x36)
#define K_7 (0x3D)
#define K_8 (0x3E)
#define K_9 (0x46)
// Letter keys
#define K_A (0x1C)
#define K_B (0x32)
#define K_C (0x21)
#define K_D (0x23)
#define K_E (0x24)
#define K_F (0x2B)
#define K_G (0x34)
#define K_H (0x33)
#define K_I (0x43)
#define K_J (0x3B)
#define K_K (0x42)
#define K_L (0x4B)
#define K_M (0x3A)
#define K_N (0x31)
#define K_O (0x44)
#define K_P (0x4D)
#define K_Q (0x15)
#define K_R (0x2D)
#define K_S (0x1B)
#define K_T (0x2C)
#define K_U (0x3C)
#define K_V (0x2A)
#define K_W (0x1D)
#define K_X (0x22)
#define K_Y (0x35)
#define K_Z (0x1A)
// Special keys
// Escape key
#define K_ESC (0x76)
//TODO: Print screen, scroll lock, pause
// Tick/tilde key
#define K_TICK (0x0E)
// Minus/underline key
#define K_MINUS (0x4E)
// Equals/plus key
#define K_EQUALS (0x55)
// Backspace key
#define K_BKSP (0x66)
// Tab key
#define K_TAB (0x0D)
// Bracket open key
#define K_BRACE_OPEN (0x54)
// Bracket close key
#define K_BRACE_CLOSE (0x5B)
// Backslash/pipe key
#define K_BACKSLASH (0x5D)
// Capslock
#define K_CAPS (0x58)
// Semicolon key
#define K_SEMICOLON (0x4C)
// Quote key
#define K_QUOTE (0x52)
// Enter key
#define K_ENTER (0x5A)
// Left shift
#define K_LEFT_SHIFT (0x12)
// Comma key
#define K_COMMA (0x41)
// Period key
#define K_PERIOD (0x49)
// Slash key
#define K_SLASH (0x4A)
// Right shift
#define K_RIGHT_SHIFT (0x59)
// Left control key
#define K_LEFT_CTRL (0x14)
// Left super key
#define K_LEFT_SUPER (K_E0 | 0x1F)
// Left alt key
#define K_LEFT_ALT (0x11)
// Space key
#define K_SPACE (0x29)
// Right alt key
#define K_RIGHT_ALT (K_E0 | 0x11)
// Right super key
#define K_RIGHT_SUPER (K_E0 | 0x27)
// Application key
#define K_APP (K_E0 | 0x2F)
// Right control key
#define K_RIGHT_CTRL (K_E0 | 0x14)
// Arrow keys and related
// Insert key
#define K_INSERT (K_E0 | 0x70)
// Delete key
#define K_DEL (K_E0 | 0x71)
// Home key
#define K_HOME (K_E0 | 0x6C)
// End key
#define K_END (K_E0 | 0x69)
// Page up key
#define K_PGUP (K_E0 | 0x7D)
// Page down key
#define K_PGDN (K_E0 | 0x7A)
#define K_UP (K_E0 | 0x75)
#define K_LEFT (K_E0 | 0x6B)
#define K_DOWN (K_E0 | 0x72)
#define K_RIGHT (K_E0 | 0x74)
// Numpad
#define K_NUM_LOCK (0x77)
#define K_NUM_SLASH (K_E0 | 0x4A)
#define K_NUM_ASTERISK (0x7C)
#define K_NUM_MINUS (0x7B)
#define K_NUM_PLUS (0x79)
#define K_NUM_PERIOD (0x71)
#define K_NUM_ENTER (K_E0 | 0x5A)
#define K_NUM_0 (0x70)
#define K_NUM_1 (0x69)
#define K_NUM_2 (0x72)
#define K_NUM_3 (0x7A)
#define K_NUM_4 (0x6B)
#define K_NUM_5 (0x73)
#define K_NUM_6 (0x74)
#define K_NUM_7 (0x6C)
#define K_NUM_8 (0x75)
#define K_NUM_9 (0x7D)
#endif // _COMMON_KEYMAP_H

25
src/common/keymap.c Normal file
View File

@ -0,0 +1,25 @@
#include <common/keymap.h>
// https://www.win.tue.nl/~aeb/linux/kbd/scancodes-10.html#ss10.3
static uint8_t __code lookup[256] = {
0xff, 0x43, 0x41, 0x3f, 0x3d, 0x3b, 0x3c, 0x58, 0x64, 0x44, 0x42, 0x40, 0x3e, 0x0f, 0x29, 0x59,
0x65, 0x38, 0x2a, 0x70, 0x1d, 0x10, 0x02, 0x5a, 0x66, 0x71, 0x2c, 0x1f, 0x1e, 0x11, 0x03, 0x5b,
0x67, 0x2e, 0x2d, 0x20, 0x12, 0x05, 0x04, 0x5c, 0x68, 0x39, 0x2f, 0x21, 0x14, 0x13, 0x06, 0x5d,
0x69, 0x31, 0x30, 0x23, 0x22, 0x15, 0x07, 0x5e, 0x6a, 0x72, 0x32, 0x24, 0x16, 0x08, 0x09, 0x5f,
0x6b, 0x33, 0x25, 0x17, 0x18, 0x0b, 0x0a, 0x60, 0x6c, 0x34, 0x35, 0x26, 0x27, 0x19, 0x0c, 0x61,
0x6d, 0x73, 0x28, 0x74, 0x1a, 0x0d, 0x62, 0x6e, 0x3a, 0x36, 0x1c, 0x1b, 0x75, 0x2b, 0x63, 0x76,
0x55, 0x56, 0x77, 0x78, 0x79, 0x7a, 0x0e, 0x7b, 0x7c, 0x4f, 0x7d, 0x4b, 0x47, 0x7e, 0x7f, 0x6f,
0x52, 0x53, 0x50, 0x4c, 0x4d, 0x48, 0x01, 0x45, 0x57, 0x4e, 0x51, 0x4a, 0x37, 0x49, 0x46, 0x54,
0x80, 0x81, 0x82, 0x41, 0x54, 0x85, 0x86, 0x87, 0x88, 0x89, 0x8a, 0x8b, 0x8c, 0x8d, 0x8e, 0x8f,
0x90, 0x91, 0x92, 0x93, 0x94, 0x95, 0x96, 0x97, 0x98, 0x99, 0x9a, 0x9b, 0x9c, 0x9d, 0x9e, 0x9f,
0xa0, 0xa1, 0xa2, 0xa3, 0xa4, 0xa5, 0xa6, 0xa7, 0xa8, 0xa9, 0xaa, 0xab, 0xac, 0xad, 0xae, 0xaf,
0xb0, 0xb1, 0xb2, 0xb3, 0xb4, 0xb5, 0xb6, 0xb7, 0xb8, 0xb9, 0xba, 0xbb, 0xbc, 0xbd, 0xbe, 0xbf,
0xc0, 0xc1, 0xc2, 0xc3, 0xc4, 0xc5, 0xc6, 0xc7, 0xc8, 0xc9, 0xca, 0xcb, 0xcc, 0xcd, 0xce, 0xcf,
0xd0, 0xd1, 0xd2, 0xd3, 0xd4, 0xd5, 0xd6, 0xd7, 0xd8, 0xd9, 0xda, 0xdb, 0xdc, 0xdd, 0xde, 0xdf,
0xe0, 0xe1, 0xe2, 0xe3, 0xe4, 0xe5, 0xe6, 0xe7, 0xe8, 0xe9, 0xea, 0xeb, 0xec, 0xed, 0xee, 0xef,
0xf0, 0xf1, 0xf2, 0xf3, 0xf4, 0xf5, 0xf6, 0xf7, 0xf8, 0xf9, 0xfa, 0xfb, 0xfc, 0xfd, 0xfe, 0xff,
};
uint16_t keymap_translate(uint16_t key) {
return (key & 0xFF00) | lookup[(key & 0xFF)];
}

View File

@ -13,5 +13,6 @@ static volatile uint8_t __xdata __at(0x3006) HOWRDR;
static volatile uint8_t __xdata __at(0x3007) HORDDR;
static volatile uint8_t __xdata __at(0x3008) HOCTL2R;
static volatile uint8_t __xdata __at(0x3009) RWFCSV;
static volatile uint8_t __xdata __at(0x300E) PADCTLR;
#endif // _EC_PECI_H