/* void test(void) { window win; char name[10]="window"; clearscreen(); win_init(&win,1,1,10,40,name,blightgray|fwhite,blightgray|fblack); win_create(&win); win_putchar(&win,'n'); win_putchar(&win,'\n'); int i; for(i=0;i<7;i++) win_putstring(&win,"testing win_putstring\n");/ for(i=0;i<4;i++)// win_putstring(&win,"new line\n"); } */ int main(struct multiboot *mboot_ptr) { welcome(); init_descriptor_tables(); asm volatile("sti"); init_timer(1); wait(1); win_clear(&win_boot); win_putstring(&win_boot,"\ninitializing timer...\t"); wait(1); win_putstring(&win_boot," done"); win_putstring(&win_boot,"\ninitializing keyboard...\t"); init_kbd(); wait(1); win_putstring(&win_boot," done"); win_putstring(&win_boot,"\npress any key to continue...\n"); u8int s,a; kbd_read(&s,&a); clearscreen(); terminal(); while(1); return 0; }
void init_keyboard() { int devid; devmgr_char_desc mykeyboard; //initialize the keyboard interface memset(&mykeyboard,0,sizeof(mykeyboard)); mykeyboard.hdr.size = sizeof(mykeyboard); //set the type of device mykeyboard.hdr.type = DEVMGR_CHAR; strcpy(mykeyboard.hdr.name,"keyb"); strcpy(mykeyboard.hdr.description,"Default generic keyboard driver 1.00"); //fill up required fields mykeyboard.init_device = installkeyboard; mykeyboard.ready_put = 0; //you can only get from this device mykeyboard.ready_get = kb_ready; mykeyboard.get_char =kb_getchar; mykeyboard.put_char = 0; mykeyboard.hdr.sendmessage = kb_sendmessage; mykeyboard.set_callback_handler= 0; mykeyboard.get_callback_handler= 0; //register this device devid = devmgr_register( (devmgr_char_desc*)&mykeyboard); memset(&kb_busywait,0,sizeof(kb_busywait)); //assign the keyboard wrapper to IRQ 1 irq_addhandler(devid,1,kbd_irq); init_kbd(1,3,0); hotkey_list = 0; };
int main(int argc, char **argv) { if(argc > 1) { int i=1; while(i < argc) { if(*argv[i] == '-') { switch(*(argv[i] + 1)) { case 'h': print_usage(argv); exit(0); break; case 'k': i++; strcpy(KBD_DEVICE, argv[i]); break; case 't': i++; strcpy(TOUCH_DEVICE, argv[i]); break; } } i++; } } printf("Initializing framebuffer device " FB_DEVICE "...\n"); init_fb(); printf("Initializing keyboard device %s ...\n", KBD_DEVICE); init_kbd(); printf("Initializing touch device %s ...\n", TOUCH_DEVICE); init_touch(); printf("Initializing VNC server:\n"); printf(" width: %d\n", (int)scrinfo.xres); printf(" height: %d\n", (int)scrinfo.yres); printf(" bpp: %d\n", (int)scrinfo.bits_per_pixel); printf(" port: %d\n", (int)VNC_PORT); init_fb_server(argc, argv); /* Implement our own event loop to detect changes in the framebuffer. */ while (1) { while (vncscr->clientHead == NULL) rfbProcessEvents(vncscr, 100000); rfbProcessEvents(vncscr, 100000); update_screen(); } printf("Cleaning up...\n"); cleanup_fb(); cleanup_kdb(); cleanup_touch(); }
/* Initialise the cooked keyboard structure pointed to by CK. The CK->func field is set to NULL as well. */ void init_cooked_kbd(struct cooked_kbd *ck) { init_kbd(&ck->kbd); ck->kbd.use_key = cooked_use_key; ck->kbd.switch_to = cooked_switch_to; ck->kbd.switch_from = cooked_switch_from; ck->lock_state = 0; ck->type = ct_None; }
int kb_sendmessage(int type,const char *message) { if (type == DEVMGR_MESSAGESTR) { int l = strlen(message), i; char *p[100]; char *temp = malloc(l+1); char *s; int c = 0; //make a temporary copy sinced we cannot modify message strcpy(temp,message); s=strtok(temp," "); do { p[c]=s; c++; s=strtok(0," "); } while (s!=0); for (i=0;i<c;i++) { if (strcmp(p[i],"-typerate")==0) { if (i+1 < c) { int rate = atoi(p[i+1]); init_kbd(1,rate,0); printf("keyb: Typematic rate changed\n"); i++; }; } }; free(temp); return 1; }; return 1; };
void setIdt() { /* Program interrups/exception service routines */ idtR.base = (DWord)idt; idtR.limit = IDT_ENTRIES * sizeof(Gate) - 1; // in exceptions.c init_except(); // Ints setInterruptHandler (32, clock_handler, 0); // int 0x20 //setInterruptHandler (33, kbd_handler, 0); // int 0x21 init_kbd(); //syscals setTrapHandler (128, syscall_handler, 3); // int 0x80 /* ADD INITIALIZATION CODE FOR INTERRUPT VECTOR */ set_idt_reg(&idtR); }
int main(void) { char out_buf[20+1]; measured_val[0]=0; measured_val[1]=0; init_dac(); lcd_init(LCD_DISP_ON); init_kbd(); set_val[0]=15;set_val[1]=50; // 150mA and 5V if (eeprom_read_byte((uint8_t *)0x0) == 19){ // ok magic number matches accept values set_val[1]=eeprom_read_word((uint16_t *)0x04); set_val[0]=eeprom_read_word((uint16_t *)0x02); } // I2C also called TWI i2c_init(3,1,0); sei(); i2c_send_data("on"); init_analog(); while (1) { // current measured_val[0]=adc_i_to_disp(getanalogresult(0)); set_val_adcUnits[0]=disp_i_to_adc(set_val[0]); set_target_adc_val(0,set_val_adcUnits[0]); // voltage measured_val[1]=adc_u_to_disp(getanalogresult(1),measured_val[0]); set_val_adcUnits[1]=disp_u_to_adc(set_val[1])+disp_i_to_u_adc_offset(measured_val[0]); set_target_adc_val(1,set_val_adcUnits[1]); // voltage lcd_clrscr(); int_to_ascii(measured_val[1],out_buf,1,1); lcd_puts(out_buf); lcd_puts("V "); int_to_ascii(set_val[1],out_buf,1,1); lcd_putc('['); lcd_puts(out_buf); lcd_putc(']'); if (!is_current_limit()){ // put a marker to show which value is currenlty limiting lcd_puts("<-"); } // current lcd_gotoxy(0,1); int_to_ascii(measured_val[0],out_buf,2,0); lcd_puts(out_buf); lcd_puts("A "); int_to_ascii(set_val[0],out_buf,2,0); lcd_putc('['); lcd_puts(out_buf); lcd_putc(']'); if (is_current_limit()){ // put a marker to show which value is currenlty limiting lcd_puts("<-"); } //dbg //int_to_ascii(is_dacval(),out_buf,0,0); //lcd_puts(out_buf); check_i2c_interface(); // the buttons must be responsive but they must not // scroll too fast if pressed permanently if (check_buttons()==0){ // no buttons pressed delay_ms(100); bpress=0; check_i2c_interface(); check_buttons(); delay_ms(150); }else{ // button press if (bpress > 11){ // somebody pressed permanetly the button=>scroll fast delay_ms(10); check_i2c_interface(); delay_ms(40); }else{ bpress++; delay_ms(100); check_i2c_interface(); delay_ms(150); } } } return(0); }
int main(void) { int16_t dac_val=511; int16_t cnt; int8_t dac_dir=0; char out_buf[21]; DDRD|= (1<<DDD0); // LED, enable PD0, LED as output LEDOFF; init_dac(); lcd_init(); lcd_clrscr(); lcd_puts("use U+/U-"); lcd_gotoxy(0,1); lcd_puts("and store"); init_kbd(); delay_ms(500); delay_ms(500); lcd_clrscr(); lcd_puts_p(PSTR("pause")); while (1) { if (dac_dir==1){ dac_val++; } if (dac_dir==-1){ dac_val--; } if (dac_val>0xFFF){ dac_val=0xFFF; //max, 13bit } if (dac_val<0){ dac_val=0; } lcd_gotoxy(0,1); itoa(dac_val,out_buf,10); lcd_puts(out_buf); lcd_puts(" "); dac(dac_val); cnt=1; check_u_button(&cnt); if (cnt>1){ lcd_clrscr(); // u+ pressed lcd_puts_p(PSTR("up")); dac_dir=1; LEDOFF; } if (cnt<1){ lcd_clrscr(); // u- pressed lcd_puts_p(PSTR("down")); dac_dir=-1; LEDON; } if (check_store_button()){ lcd_clrscr(); lcd_puts_p(PSTR("pause")); dac_dir=0; } delay_ms(100); cnt=1; check_u_button(&cnt); if (cnt>1){ lcd_clrscr(); // u+ pressed lcd_puts_p(PSTR("up")); dac_dir=1; LEDOFF; } if (cnt<1){ lcd_clrscr(); // u- pressed lcd_puts_p(PSTR("down")); dac_dir=-1; LEDON; } if (check_store_button()){ lcd_clrscr(); lcd_puts_p(PSTR("pause")); dac_dir=0; } delay_ms(100); } return(0); }
static void fb_wait(GP_Backend *self) { struct fb_priv *fb = GP_BACKEND_PRIV(self); struct pollfd fd = {.fd = fb->con_fd, .events = POLLIN, .revents = 0}; if (poll(&fd, 1, -1) > 0) fb_poll(self); else GP_WARN("poll(): %s", strerror(errno)); } static void fb_exit(GP_Backend *self) { struct fb_priv *fb = GP_BACKEND_PRIV(self); if (fb->flags & GP_FB_SHADOW) free(fb->context.pixels); /* unmap framebuffer */ munmap(fb->fb_mem, fb->bsize); close(fb->fb_fd); if (fb->flags & GP_FB_INPUT_KBD) exit_kbd(fb); free_console(fb); free(self); } static void fb_flip_shadow(GP_Backend *self) { struct fb_priv *fb = GP_BACKEND_PRIV(self); GP_DEBUG(2, "Flipping buffer"); memcpy(fb->fb_mem, fb->context.pixels, fb->bsize); } static void fb_update_rect_shadow(GP_Backend *self, GP_Coord x0, GP_Coord y0, GP_Coord x1, GP_Coord y1) { struct fb_priv *fb = GP_BACKEND_PRIV(self); GP_DEBUG(2, "Flipping buffer"); size_t size = ((x1 - x0) * fb->context.bpp) / 8; for (;y0 <= y1; y0++) { void *src = GP_PIXEL_ADDR(&fb->context, x0, y0); void *dst = (char*)fb->fb_mem + y0 * fb->context.bytes_per_row + (x0 * fb->context.bpp)/8; memcpy(dst, src, size); } } GP_Backend *GP_BackendLinuxFBInit(const char *path, int flags) { GP_Backend *backend; struct fb_priv *fb; struct fb_fix_screeninfo fscri; struct fb_var_screeninfo vscri; int fd; backend = malloc(sizeof(GP_Backend) + sizeof(struct fb_priv) + strlen(path) + 1); if (backend == NULL) return NULL; fb = GP_BACKEND_PRIV(backend); if (allocate_console(fb, flags)) goto err0; if (flags & GP_FB_INPUT_KBD) { if (init_kbd(fb)) goto err1; } /* open and mmap framebuffer */ GP_DEBUG(1, "Opening framebuffer '%s'", path); fd = open(path, O_RDWR); if (fd < 0) { GP_DEBUG(1, "Opening framebuffer failed: %s", strerror(errno)); goto err2; } if (ioctl(fd, FBIOGET_FSCREENINFO, &fscri) < 0) { GP_DEBUG(1, "Failed to ioctl FBIOGET_FSCREENINFO: %s", strerror(errno)); goto err3; } if (ioctl(fd, FBIOGET_VSCREENINFO, &vscri) < 0) { GP_DEBUG(1, "Failed to ioctl FBIOGET_VSCREENINFO: %s", strerror(errno)); goto err3; } GP_DEBUG(1, "Have framebufer %ix%i %s %ibpp", vscri.xres, vscri.yres, vscri.grayscale ? "Gray" : "RGB", vscri.bits_per_pixel); /* * Framebuffer is grayscale. */ if (vscri.grayscale) { GP_WARN("Grayscale not implemented!"); goto err3; } enum GP_PixelType pixel_type; pixel_type = GP_PixelRGBLookup(vscri.red.length, vscri.red.offset, vscri.green.length, vscri.green.offset, vscri.blue.length, vscri.blue.offset, vscri.transp.length, vscri.transp.offset, vscri.bits_per_pixel); if (pixel_type == GP_PIXEL_UNKNOWN) { GP_DEBUG(1, "Unknown pixel type\n"); goto err3; } if (flags & GP_FB_SHADOW) { fb->context.pixels = malloc(fscri.smem_len); if (!fb->context.pixels) { GP_DEBUG(1, "Malloc failed :("); goto err3; } } fb->fb_mem = mmap(NULL, fscri.smem_len, PROT_READ | PROT_WRITE, MAP_FILE | MAP_SHARED, fd, 0); if (fb->fb_mem == MAP_FAILED) { GP_DEBUG(1, "mmaping framebuffer failed: %s", strerror(errno)); goto err4; } fb->fb_fd = fd; fb->bsize = fscri.smem_len; strcpy(fb->path, path); fb->flags = flags; if (!(flags & GP_FB_SHADOW)) fb->context.pixels = fb->fb_mem; fb->context.w = vscri.xres; fb->context.h = vscri.yres; fb->context.axes_swap = 0; fb->context.x_swap = 0; fb->context.y_swap = 0; fb->context.bpp = vscri.bits_per_pixel; fb->context.bytes_per_row = fscri.line_length; fb->context.pixel_type = pixel_type; int shadow = flags & GP_FB_SHADOW; int kbd = flags & GP_FB_INPUT_KBD; /* update API */ backend->name = "Linux FB"; backend->context = &fb->context; backend->Flip = shadow ? fb_flip_shadow : NULL; backend->UpdateRect = shadow ? fb_update_rect_shadow : NULL; backend->Exit = fb_exit; backend->SetAttributes = NULL; backend->ResizeAck = NULL; backend->Poll = kbd ? fb_poll : NULL; backend->Wait = kbd ? fb_wait : NULL; backend->fd = fb->con_fd; backend->timers = NULL; GP_EventQueueInit(&backend->event_queue, vscri.xres, vscri.yres, 0); return backend; err4: if (flags & GP_FB_SHADOW) free(fb->context.pixels); err3: close(fd); err2: if (flags & GP_FB_INPUT_KBD) exit_kbd(fb); err1: free_console(fb); err0: free(backend); return NULL; }
int main (int argc, char *argv[]) { int kfd, tfd; int nfd; fd_set fixed_mask, select_mask; int cr; char c; int i; int echo; int mapda; int ctsrts; if (argc < 2) { fprintf (stderr, "Usage %s <tty_spec> [ echo ] [ crlf ] [ noctsrts ]\n", argv[0]); init_tty("", 0, 0, 0); exit (1); } echo = 0; mapda = 0; ctsrts = 1; for (i = 2; i < argc; i++) { if (strcmp(argv[i], "echo") == 0) { echo = 1; } else if (strcmp(argv[i], "crlf") == 0) { mapda = 1; } else if (strcmp(argv[i], "noctsrts") == 0) { ctsrts = 0; } else { fprintf (stderr, "Usage %s <tty_spec> [ echo ] [ crlf ] [ noctsrts ]\n", argv[0]); init_tty("", 0, 0, 0); exit (1); } } init_tty(argv[1], ctsrts, echo, mapda); tfd = get_tty_fd(); printf ("Ready. Exit with Ctrl X.\n"); kfd = fileno(stdin); init_kbd(kfd); nfd = tfd; if (nfd < kfd) nfd = kfd; FD_ZERO (&fixed_mask); FD_SET (tfd, &fixed_mask); FD_SET (kfd, &fixed_mask); for (;;) { memcpy (&select_mask, &fixed_mask, sizeof(fd_set)); cr = select (nfd+1, &select_mask, (fd_set*)NULL, (fd_set*)NULL, (struct timeval*)NULL); if (cr == -1) { if (errno != EINTR) { perror ("select"); } } else if (cr == 0) { fprintf (stderr, "select returned 0\n"); } else { if (FD_ISSET(kfd, &select_mask) ) { #ifdef DEBUG fprintf (stderr, "kbd event selected\n"); #endif errno = 0; cr = read (kfd, &c, 1); if (cr != 1) { perror ("read kbd"); } #ifdef DEBUG fprintf (stderr, "kbd char read: %c 0x%x\n", c, (int)c); #endif if (c == 0x18) { /* Exit */ restore_kbd (kfd); restore_tty (); (void) putchar ((int)'\n'); exit (0); } send_tty (c); #ifdef DEBUG fprintf (stderr, "sent to tty.\n"); #endif } else if (FD_ISSET(tfd, &select_mask) ) { #ifdef DEBUG fprintf (stderr, "tty event selected\n"); #endif read_tty (&c); #ifdef DEBUG fprintf (stderr, "tty char read: %c %x\n", c, (int)c); #endif (void) putchar ((int)c); #ifdef DEBUG fprintf (stderr, "sent to display.\n"); #endif (void) fflush (stdout); } else { fprintf (stderr, "select returned but fd not set\n"); } } } }