void test_interrupt() { lcd_print_char('a'); //intc_enable(); lcd_enable_interrupt(); lcd_print_char('b'); int i = 0; int j = 0; for(i=0;i<100000000;i++) {j++;} lcd_print_char('x'); lcd_disable_interrupt(); }
void lcd_update(void) { int x, y; for (y = 0; y < lcd_pattern_count; y++) if (lcd_patterns[y].count > 0) sim_lcd_define_pattern(y, lcd_patterns[y].pattern); for (y = 0; y < LCD_HEIGHT; y++) for (x = 0; x < LCD_WIDTH; x++) lcd_print_char(x, y, lcd_charbuffer[y][x]); if (lcd_cursor.visible) lcd_print_char(lcd_cursor.x, lcd_cursor.y, lcd_cursor.hw_char); sim_lcd_update_rect(0, ICON_HEIGHT, SIM_LCD_WIDTH, LCD_HEIGHT*CHAR_HEIGHT*CHAR_PIXEL); }
void lcd_print_string( lcd_x_t x, lcd_y_t y, const char *string, lcd_color_t foreground_color, lcd_color_t background_color) { # define MAX_STRING_LENGTH 256 # define CHAR_WIDTH_IN_PIXELS ((LCD_FONT_WIDTH + 1) * LCD_FONT_DOT_SIZE_IN_PIXELS) size_t length; size_t length_in_pixels; lcd_x_t x_cursor; /* * Calculate length of NULL terminated string */ for (length = 0; length < MAX_STRING_LENGTH && string[length] != '\0'; length ++) ; length_in_pixels = length * CHAR_WIDTH_IN_PIXELS; /* * Truncate string if necessary */ if (x + length_in_pixels > LCD_X_SIZE) { length_in_pixels -= (x + length_in_pixels) - LCD_X_SIZE; length = length_in_pixels / CHAR_WIDTH_IN_PIXELS; } x_cursor = x; for (size_t i = 0; i < length; i ++) { lcd_print_char( x_cursor, y, (uint8_t)string[i], foreground_color, background_color); x_cursor += CHAR_WIDTH_IN_PIXELS; } }
// Halt board on init failure and print message void board_fail_P(PGM_P msg) { printf(str_boot_fail, msg); // print message #ifdef LCD_DEBUG lcd_set_pos(16); lcd_printf(msg); lcd_set_pos(31); lcd_print_char('\3', NULL); #endif // and stop while (1) { for (int i = 0; i < 2; i++) { LED_COMM(1); pause(100); LED_COMM(0); pause(150); } pause(800); } }
void lcd_print_string(lcd_t *lcd, char *c) { uint8_t i = 0; while (*c && ++i < 16) lcd_print_char(lcd, *(++c)); }
void lputcln(unsigned char c){ lcd_print_char(c); lcd_print_char(STR_NEWLINE); }
void lputc(unsigned char c){ lcd_print_char(c); }
void lputsln(unsigned char * str){ lcd_print_str(str); lcd_print_char(STR_NEWLINE); }
// Initialise board void board_init (void) { #ifndef SIMULATE io_init(); // Init GPIOs uart_init(BAUD_RATE); stderr = &uartio; printf(str_boot_uart,BAUD_RATE); printf(str_boot_start); #else printf("Skipping UART initialization...\n"); #endif #ifndef SIMULATE digital_init(); #endif encoder_init(); #ifndef SIMULATE spi_init(); motor_init(); servo_init(); #ifdef LCD_DEBUG lcd_init(); //consider wrapping this in an #ifdef LCD_DEBUG tag? stdout = &lcdout; #else stdout = &uartio; stdin = &uartio; #endif adc_init(); isr_init(); memory_init(); #endif // load config, or fail if invalid if (!board_load_config()) board_fail("Bad Config"); printf(str_boot_conf); printf(str_boot_board, board_config.version>>8, board_config.version&0xFF); printf(str_boot_id, board_config.id); // print boot text to screen printf(str_boot_message, board_config.version>>8, board_config.version&0xFF); // check battery, fail if <7.5V printf(str_boot_batt,read_battery()); #ifdef CHECK_BATTERY if (!(read_battery()>=7200)) { // NOTE: in the current 2-battery version of the HappyBoard, the // battery voltage is the motor battery (P+). Holding GO overrides // the check so you can run the HappyBoard without a motor battery. if (go_press()) printf("WARNING: LOW BATTERY\n"); else board_fail("Low battery"); } else { printf("Battery OK\n"); } #endif #ifndef SIMULATE // initialise FPGA if (!fpga_init(FPGA_CONFIG_ADDRESS, board_config.fpga_len)) board_fail("FPGA failure"); printf(str_boot_fpga, fpga_get_version_major(), fpga_get_version_minor()); #else printf("Skipping FPGA initialization...\n"); #endif // all ok #ifndef SIMULATE #ifdef LCD_DEBUG lcd_set_pos(31); lcd_print_char('\1', NULL); #else printf("Board init complete.\n"); #endif #else printf("Board init complete.\n"); #endif #ifndef SIMULATE LED_COMM(0); #endif }