通过IO端口控制键盘灯

内核空间程序代码:

static int retries = 5;
static int timeout = 1000;
static int state = 0; // the leds configuration

#define SCROLL_LOCK (1 << 0)
#define NUM_LOCK (1 << 1)
#define CAPS_LOCK (1 << 2)

static void setAllLedsOn()
{
    state = SCROLL_LOCK | NUM_LOCK | CAPS_LOCK;

    outb(0xed, 0x60); // tell the keyboard we want to set the leds configuration
    udelay(timeout);

    while (retries != 0 && inb(0x60) != 0xfa) { // wait for the keyboard controller
        retries--;
        udelay(timeout);
    }

    if (retries != 0) { //check is keyboard is ready to accept command
        outb(state, 0x60);
    }
}

用户空间程序代码:

#include <stdio.h>
#include <sys/io.h>

int main()
{
    int ret;

    ret = ioperm(0x60, 0xf, 1);
    if (ret < 0) {
        perror("ioperm");
        return 1;
    }

    while (inb(0x64) & 0x2);
    outb(0xed, 0x60);
    while (inb(0x64) & 0x2);
    outb(0x07, 0x60);
    ioperm(0x60, 0xf, 0);

    return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值