Add KBC and PMC objects
This commit is contained in:
parent
b479defcc4
commit
e9897a321e
@ -3,6 +3,32 @@
|
||||
|
||||
void kbc_init(void);
|
||||
|
||||
struct Kbc {
|
||||
// Control register
|
||||
volatile unsigned char * control;
|
||||
// Interrupt control register
|
||||
volatile unsigned char * irq;
|
||||
// Status register
|
||||
volatile unsigned char * status;
|
||||
// Keyboard out register
|
||||
volatile unsigned char * keyboard_out;
|
||||
// Mouse out register
|
||||
volatile unsigned char * mouse_out;
|
||||
// Data in register
|
||||
volatile unsigned char * data_in;
|
||||
};
|
||||
|
||||
extern __code struct Kbc KBC;
|
||||
|
||||
#define KBC_STS_OBF (1 << 0)
|
||||
#define KBC_STS_IBF (1 << 1)
|
||||
#define KBC_STS_CMD (1 << 3)
|
||||
|
||||
unsigned char kbc_status(struct Kbc * kbc);
|
||||
unsigned char kbc_read(struct Kbc * kbc);
|
||||
void kbc_keyboard(struct Kbc * kbc, unsigned char data);
|
||||
void kbc_mouse(struct Kbc * kbc, unsigned char data);
|
||||
|
||||
__xdata volatile unsigned char __at(0x1300) KBHICR;
|
||||
__xdata volatile unsigned char __at(0x1302) KBIRQR;
|
||||
__xdata volatile unsigned char __at(0x1304) KBHISR;
|
||||
|
@ -3,7 +3,36 @@
|
||||
|
||||
void pmc_init(void);
|
||||
|
||||
struct Pmc {
|
||||
// Status register
|
||||
volatile unsigned char * status;
|
||||
// Data out register
|
||||
volatile unsigned char * data_out;
|
||||
// Data in register
|
||||
volatile unsigned char * data_in;
|
||||
// Control register
|
||||
volatile unsigned char * control;
|
||||
};
|
||||
|
||||
extern __code struct Pmc PMC_1;
|
||||
extern __code struct Pmc PMC_2;
|
||||
|
||||
#define PMC_STS_OBF (1 << 0)
|
||||
#define PMC_STS_IBF (1 << 1)
|
||||
#define PMC_STS_CMD (1 << 3)
|
||||
|
||||
unsigned char pmc_status(struct Pmc * pmc);
|
||||
unsigned char pmc_read(struct Pmc * pmc);
|
||||
void pmc_write(struct Pmc * pmc, unsigned char data);
|
||||
|
||||
__xdata volatile unsigned char __at(0x1500) PM1STS;
|
||||
__xdata volatile unsigned char __at(0x1501) PM1DO;
|
||||
__xdata volatile unsigned char __at(0x1504) PM1DI;
|
||||
__xdata volatile unsigned char __at(0x1506) PM1CTL;
|
||||
|
||||
__xdata volatile unsigned char __at(0x1510) PM2STS;
|
||||
__xdata volatile unsigned char __at(0x1511) PM2DO;
|
||||
__xdata volatile unsigned char __at(0x1514) PM2DI;
|
||||
__xdata volatile unsigned char __at(0x1516) PM2CTL;
|
||||
|
||||
#endif // _PMC_H_
|
||||
|
29
src/kbc.c
29
src/kbc.c
@ -1,6 +1,31 @@
|
||||
#include "include/kbc.h"
|
||||
|
||||
__code struct Kbc KBC = {
|
||||
.control = &KBHICR,
|
||||
.irq = &KBIRQR,
|
||||
.status = &KBHISR,
|
||||
.keyboard_out = &KBHIKDOR,
|
||||
.mouse_out = &KBHIMDOR,
|
||||
.data_in = &KBHIDIR,
|
||||
};
|
||||
|
||||
void kbc_init(void) {
|
||||
KBIRQR = 0;
|
||||
KBHICR = 0x48;
|
||||
*(KBC.irq) = 0;
|
||||
*(KBC.control) = 0x48;
|
||||
}
|
||||
|
||||
unsigned char kbc_status(struct Kbc * kbc) {
|
||||
return *(kbc->status);
|
||||
}
|
||||
|
||||
unsigned char kbc_read(struct Kbc * kbc) {
|
||||
return *(kbc->data_in);
|
||||
}
|
||||
|
||||
void kbc_keyboard(struct Kbc * kbc, unsigned char data) {
|
||||
*(kbc->keyboard_out) = data;
|
||||
}
|
||||
|
||||
void kbc_mouse(struct Kbc * kbc, unsigned char data) {
|
||||
*(kbc->mouse_out) = data;
|
||||
}
|
||||
|
91
src/main.c
91
src/main.c
@ -1,6 +1,6 @@
|
||||
#include <8051.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdio.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#include "include/delay.h"
|
||||
#include "include/gpio.h"
|
||||
@ -11,17 +11,31 @@
|
||||
#include "include/ps2.h"
|
||||
#include "include/kbscan.h"
|
||||
|
||||
struct Pin LED_BAT_CHG = PIN(A, 5);
|
||||
struct Pin LED_BAT_FULL = PIN(A, 6);
|
||||
struct Pin LED_PWR = PIN(A, 7);
|
||||
struct Pin LED_ACIN = PIN(C, 7);
|
||||
struct Pin LED_AIRPLANE_N = PIN(G, 6);
|
||||
void external_0(void) __interrupt(0) {
|
||||
printf("external_0\n");
|
||||
}
|
||||
|
||||
struct Pin PWR_SW = PIN(D, 0);
|
||||
void timer_0(void) __interrupt(1) {
|
||||
printf("timer_0\n");
|
||||
}
|
||||
|
||||
static char * MODEL = "galp3-c";
|
||||
void external_1(void) __interrupt(2) {
|
||||
printf("external_1\n");
|
||||
}
|
||||
|
||||
void main() {
|
||||
void timer_1(void) __interrupt(3) {
|
||||
printf("timer_1\n");
|
||||
}
|
||||
|
||||
void serial(void) __interrupt(4) {
|
||||
printf("serial\n");
|
||||
}
|
||||
|
||||
void timer_2(void) __interrupt(5) {
|
||||
printf("timer_2\n");
|
||||
}
|
||||
|
||||
void init(void) {
|
||||
gpio_init();
|
||||
gctrl_init();
|
||||
kbc_init();
|
||||
@ -29,6 +43,55 @@ void main() {
|
||||
kbscan_init();
|
||||
|
||||
//TODO: INTC, PECI, PWM, SMBUS
|
||||
}
|
||||
|
||||
struct Pin PWR_SW = PIN(D, 0);
|
||||
|
||||
void power_switch(void) {
|
||||
static bool last = false;
|
||||
|
||||
// Check if the power switch goes low
|
||||
bool new = pin_get(&PWR_SW);
|
||||
if (!new && last) {
|
||||
printf("Power Switch\n");
|
||||
}
|
||||
last = new;
|
||||
}
|
||||
|
||||
void kbc_event(struct Kbc * kbc) {
|
||||
uint8_t sts = kbc_status(kbc);
|
||||
if (sts & KBC_STS_IBF) {
|
||||
uint8_t data = kbc_read(kbc);
|
||||
if (sts & KBC_STS_CMD) {
|
||||
printf("KBC command: %X\n", data);
|
||||
} else {
|
||||
printf("KBC data: %X\n", data);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void pmc_event(struct Pmc * pmc) {
|
||||
uint8_t sts = pmc_status(pmc);
|
||||
if (sts & PMC_STS_IBF) {
|
||||
uint8_t data = pmc_read(pmc);
|
||||
if (sts & PMC_STS_CMD) {
|
||||
printf("PMC command: %X\n", data);
|
||||
} else {
|
||||
printf("PMC data: %X\n", data);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
struct Pin LED_BAT_CHG = PIN(A, 5);
|
||||
struct Pin LED_BAT_FULL = PIN(A, 6);
|
||||
struct Pin LED_PWR = PIN(A, 7);
|
||||
struct Pin LED_ACIN = PIN(C, 7);
|
||||
struct Pin LED_AIRPLANE_N = PIN(G, 6);
|
||||
|
||||
__code const char * MODEL = "galp3-c";
|
||||
|
||||
void main(void) {
|
||||
init();
|
||||
|
||||
// Set the battery full LED (to know our firmware is loaded)
|
||||
pin_set(&LED_BAT_FULL, true);
|
||||
@ -36,13 +99,9 @@ void main() {
|
||||
|
||||
gpio_debug();
|
||||
|
||||
bool last = false;
|
||||
for(;;) {
|
||||
// Check if the power switch goes low
|
||||
bool new = pin_get(&PWR_SW);
|
||||
if (!new && last) {
|
||||
printf("Power Switch\n");
|
||||
}
|
||||
last = new;
|
||||
power_switch();
|
||||
kbc_event(&KBC);
|
||||
pmc_event(&PMC_1);
|
||||
}
|
||||
}
|
||||
|
28
src/pmc.c
28
src/pmc.c
@ -1,6 +1,28 @@
|
||||
#include "include/pmc.h"
|
||||
|
||||
void pmc_init(void) {
|
||||
PM1CTL = 0x41;
|
||||
PM2CTL = 0x41;
|
||||
#define PMC(NUM) { \
|
||||
.status = &PM ## NUM ## STS, \
|
||||
.data_out = &PM ## NUM ## DO, \
|
||||
.data_in = &PM ## NUM ## DI, \
|
||||
.control = &PM ## NUM ## CTL, \
|
||||
}
|
||||
|
||||
__code struct Pmc PMC_1 = PMC(1);
|
||||
__code struct Pmc PMC_2 = PMC(2);
|
||||
|
||||
void pmc_init(void) {
|
||||
*(PMC_1.control) = 0x41;
|
||||
*(PMC_2.control) = 0x41;
|
||||
}
|
||||
|
||||
unsigned char pmc_status(struct Pmc * pmc) {
|
||||
return *(pmc->status);
|
||||
}
|
||||
|
||||
unsigned char pmc_read(struct Pmc * pmc) {
|
||||
return *(pmc->data_in);
|
||||
}
|
||||
|
||||
void pmc_write(struct Pmc * pmc, unsigned char data) {
|
||||
*(pmc->data_out) = data;
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user