/* Public functions ---------------------------------------------------------*/ void mainMenu(void){ uint8_t buttons; static Ttimer btnTimer={0,0}; // Check if the function is colled for the first time if (firstRun) { // Initialize mainMenu_Init(); // clear firstRun variable firstRun=0; } // Check the time elapsed sinced last read of button state // If it is more than 200ms (10*20ms) if (((TIM1_cnt&0xFF)-btnTimer.timeStart)>10) { // Store current time btnTimer.timeStart=TIM1_cnt&0xFF; // Read state of buttons buttons=btn_getState(); if (buttons>0) buzzer_beep(); // If UP button is pressed if ((buttons&btnUp)>0){ if (selection>SEL_ANALOG){ selection--; } } // If DOWN button is pressed if ((buttons&btnDown)>0){ if (selection<SEL_SETUP){ selection++; } } // If ENTER button is pressed if ((buttons&btnEnter)>0){ mainMenu_DeInit(); menu=selection; } } //If selection was changed if (selection!=selection_old){ //redraw the tick symbol select(selection); //store old selection value selection_old=selection; } }
static __exit void uart_mod_exit(void) { printk("uart module exit ok!\n"); unregister_chrdev_region(uart_dev, 4); cdev_del(&uart_cdev); buzzer_beep(2); return; }
static __init int uart_mod_init(void) { int rc; printk("uart module init ok!\n"); printk("v = %d\n", v); printk("jiffies = 0x%x\n", (int)jiffies); printk("HZ = %d\n", HZ); uart_dev = MKDEV(241, 0); rc = register_chrdev_region(uart_dev, 4, "ttyS"); DPRINT(rc); cdev_init(&uart_cdev, &uart_fops); cdev_add(&uart_cdev, uart_dev, 4); buzzer_init(); buzzer_beep(1); return 0; }
/* Public functions ---------------------------------------------------------*/ void menuPC(void){ uint8_t buttons,str[14]; static Ttimer btnTimer={0,0}; // Check if the function is called for the first time if (menuPC_firstRun) { // Initialize menuPC_Init(); // Clear menuPC_firstRun variable menuPC_firstRun=0; } // Calculate the time elapsed since the button timer was started btnTimer.timeElapsed=(TIM1_cnt&0xFF)-btnTimer.timeStart; // If time elapsed is more than 200ms(10*20ms) if (btnTimer.timeElapsed>10) { // Set timeStart to the current time btnTimer.timeStart=TIM1_cnt&0xFF; // Read state of buttons buttons=btn_getState(); if (buttons>0) buzzer_beep(); // If EXIT button is pressed if ((buttons&btnExit)>0){ buzzer_beepA(3200,10); /* menuPC_DeInit(); menu=MENU_MAIN;*/ } // If ENTER button is pressed if ((buttons&btnEnter)>0){ buzzer_beepA(3200,10); } if ((buttons&btnUp)>0){ } if ((buttons&btnDown)>0){ } } ///////////////////////////// if (pwm_S1>PWM_WIDTH_MAX) pwm_S1=PWM_WIDTH_MAX; if (pwm_S2>PWM_WIDTH_MAX) pwm_S2=PWM_WIDTH_MAX; TIM1_SetCompare3(pwm_S1*2); TIM1_SetCompare2(pwm_S2*2); ///////////////////////////// //display pwm width in us itoa(pwm_S1,&str); lcd_3310_drawTextXY(9*6,3," "); if (pwm_S1==0) lcd_3310_drawTextXY(5*6,3,"0000"); else lcd_3310_drawTextXY(5*6,3,str); //display pwm width in us itoa(pwm_S2,&str); lcd_3310_drawTextXY(9*6,4," "); if (pwm_S2==0) lcd_3310_drawTextXY(5*6,4,"0000"); else lcd_3310_drawTextXY(5*6,4,str); menu_displayRPM(5*6,2); }
/* * RTTTL (RingTone Text Transfer Language) is the primary format used to distribute * ringtones for Nokia phones. An RTTTL file is a text file, containing the * ringtone name, a control section and a section containing a comma separated * sequence of ring tone commands. White space must be ignored by any reader * application. * * Example: * Simpsons:d=4,o=5,b=160:32p,c.6,e6,f#6,8a6,g.6,e6,c6,8a,8f#,8f#,8f#,2g * * This file describes a ringtone whose name is 'Simpsons'. The control section * sets the beats per minute at 160, the default note length as 4, and the default * scale as Octave 5. * <RTX file> := <name> ":" [<control section>] ":" <tone-commands> * * <name> := <char> ; maximum name length 10 characters * * <control-section> := <control-pair> ["," <control-section>] * * <control-pair> := <control-name> ["="] <control-value> * * <control-name> := "d" | "o" | "b" * ; Valid in control section: d=default duration, o=default scale, b=default beats per minute. * ; if not specified, defaults are 4=duration, 6=scale, 63=beats-per-minute * ; any unknown control-names must be ignored * * <tone-commands> := <tone-command> ["," <tone-commands>] * * <tone-command> :=<note> | <control-pair> * * <note> := [<duration>] <note> [<scale>] [<special-duration>] <delimiter> * * <duration> := "1" | "2" | "4" | "8" | "16" | "32" * ; duration is divider of full note duration, eg. 4 represents a quarter note * * <note> := "P" | "C" | "C#" | "D" | "D#" | "E" | "F" | "F#" | "G" | "G#" | "A" | "A#" | "B" * * <scale> :="4" | "5" | "6" | "7" * ; Note that octave 4: A=440Hz, 5: A=880Hz, 6: A=1.76 kHz, 7: A=3.52 kHz * ; The lowest note on the Nokia 61xx is A4, the highest is B7 * * <special-duration> := "." ; Dotted note */ void buzzer_play(struct buzzer_t * buzzer, const char * rtttl) { const int notes[] = { 0, NOTE_C4, NOTE_CS4, NOTE_D4, NOTE_DS4, NOTE_E4, NOTE_F4, NOTE_FS4, NOTE_G4, NOTE_GS4, NOTE_A4, NOTE_AS4, NOTE_B4, NOTE_C5, NOTE_CS5, NOTE_D5, NOTE_DS5, NOTE_E5, NOTE_F5, NOTE_FS5, NOTE_G5, NOTE_GS5, NOTE_A5, NOTE_AS5, NOTE_B5, NOTE_C6, NOTE_CS6, NOTE_D6, NOTE_DS6, NOTE_E6, NOTE_F6, NOTE_FS6, NOTE_G6, NOTE_GS6, NOTE_A6, NOTE_AS6, NOTE_B6, NOTE_C7, NOTE_CS7, NOTE_D7, NOTE_DS7, NOTE_E7, NOTE_F7, NOTE_FS7, NOTE_G7, NOTE_GS7, NOTE_A7, NOTE_AS7, NOTE_B7 }; char * p = (char *)rtttl; int d = 4, o = 6, b = 63; int duration, scale, index; int n, t; char c; buzzer_beep(buzzer, 0, 0); if(!p) return; while(*p && *p != ':') p++; if(!*p) return; p++; while(*p) { while(*p == ' ') p++; if(!*p) return; if(*p == ':') break; c = *p++; if(*p != '=') return; p++; n = 0; while(*p >= '0' && *p <= '9') n = n * 10 + (*p++ - '0'); switch(c) { case 'd': d = 32 / n; break; case 'o': if(n >= 4 && n <= 7) o = n; break; case 'b': b = n; break; default: break; } while(*p == ' ') p++; if(*p == ',') p++; } p++; while(*p) { duration = d; scale = o; index = 0; while(*p == ' ') p++; if(!*p) return; if(*p >= '0' && *p <= '9') { n = 0; while(*p >= '0' && *p <= '9') n = n * 10 + (*p++ - '0'); duration = 32 / n; } switch(*p) { case 0: return; case 'c': case 'C': index = 1; break; case 'd': case 'D': index = 3; break; case 'e': case 'E': index = 5; break; case 'f': case 'F': index = 6; break; case 'g': case 'G': index = 8; break; case 'a': case 'A': index = 10; break; case 'b': case 'B': case 'h': case 'H': index = 12; break; case 'p': case 'P': default: index = 0; break; } p++; if(*p == '#') { index++; p++; } if(*p == '.') { duration += duration / 2; p++; } if(*p >= '0' && *p <= '9') scale = (*p++ - '0'); if(*p == '.') { duration += duration / 2; p++; } while(*p == ' ') p++; if(*p == ',') p++; t = duration * 60000 / (b * 8); if(index != 0) { buzzer_beep(buzzer, notes[(scale - 4) * 12 + index], t * 7 / 8); buzzer_beep(buzzer, 0, t / 8); } else { buzzer_beep(buzzer, 0, t); } } }
/** * Entry point */ int main(void) { /* Misc variables */ DCPU_registers reg; // CPU registers states (at boot) /* Hardware initialisation */ cli(); led_setup(); spi_setup(SPI_PRESCALER, SPI_MODE, SPI_BITS_ORDER); uart_setup(UART_BAUDRATE); DEBUG_STR("Main init", "UART ready"); button_setup(); buzzer_setup(BUZZER_FREQUENCY, BUZZER_DURATION); ram_setup(); rom_setup(); microvga_setup(); microvga_enable(); dcpu_register_init(®); DEBUG_STR("Main init", "done"); sei(); /* MicroVGA initialisation */ _delay_ms(1000); // MicroVGA boot time microvga_clear_screen(); // Clear screen and goto (0, 0) microvga_goto_cursor(0, 0); uart_puts_PSTR(PSTR("SkyWodd DCPU-16 hardware emulator")); // Screen test buzzer_beep(); DEBUG_STR("Main init", "MicroVGA ready"); /* Hardware self-test */ DEBUG_STR("Main init", "self-test run"); led_run_write(1); // Led test _delay_ms(250); led_run_write(0); led_cpu_write(1); _delay_ms(250); led_cpu_write(0); led_rom_write(1); _delay_ms(250); led_rom_write(0); led_ram_write(1); _delay_ms(250); led_ram_write(0); DEBUG_STR("Main init", "self-test done"); /* Keyboard & MicroVGA api test */ DEBUG_STR("Main init", "waiting for keypress"); microvga_goto_cursor(0, 1); uart_puts_PSTR(PSTR("Press any key to boot ...")); keyboard_wait(); uart_puts_PSTR(PSTR("Loading please wait ...")); dcpu_setup(reg); buzzer_beep(); microvga_clear_screen(); microvga_goto_cursor(0, 0); DEBUG_STR("Main init", "ready to run"); /* Infinite loop */ for(;;) { /* Handle pause */ while(!button_get_state()); #ifdef SERIAL_DEBUG_SUPPORT /* Debug */ dcpu_registers_dump(); #endif /* Fetch opcode from ROM */ dcpu_step(); } }