static void one_test (const struct matrix *A, const struct matrix *B, int i) { struct matrix R; struct matrix P; mp_ptr tp; matrix_init (&R, A->n + B->n + 1); matrix_init (&P, A->n + B->n + 1); tp = refmpn_malloc_limbs (mpn_matrix22_mul_itch (A->n, B->n)); ref_matrix22_mul (&R, A, B, tp); matrix_copy (&P, A); mpn_matrix22_mul (P.e00, P.e01, P.e10, P.e11, A->n, B->e00, B->e01, B->e10, B->e11, B->n, tp); P.n = A->n + B->n + 1; if (!matrix_equal_p (&R, &P)) { fprintf (stderr, "ERROR in test %d\n", i); gmp_fprintf (stderr, "A = (%Nx, %Nx\n %Nx, %Nx)\n" "B = (%Nx, %Nx\n %Nx, %Nx)\n" "R = (%Nx, %Nx (expected)\n %Nx, %Nx)\n" "P = (%Nx, %Nx (incorrect)\n %Nx, %Nx)\n", A->e00, A->n, A->e01, A->n, A->e10, A->n, A->e11, A->n, B->e00, B->n, B->e01, B->n, B->e10, B->n, B->e11, B->n, R.e00, R.n, R.e01, R.n, R.e10, R.n, R.e11, R.n, P.e00, P.n, P.e01, P.n, P.e10, P.n, P.e11, P.n); abort(); } refmpn_free_limbs (tp); matrix_clear (&R); matrix_clear (&P); }
void hook_usb_wakeup(void) { //dprintf("huwu\n"); // // ---> This replaces the call of suspend_wakeup_init() <-- // // suspend_wakeup_init(); // clear keyboard state matrix_clear(); clear_keyboard(); #ifdef BACKLIGHT_ENABLE // // --> do not call this! I2C IRQ will destroy USB communication! <-- // // backlight_init(); backlight_enableShutdown(false); resume_animation_in_idle_state(); #endif #ifdef SLEEP_LED_ENABLE sleep_led_disable(); #endif mcpu_hardware_shutdown(false); send_sleep_to_other_side(false); // Restore LED status // BIOS/grub won't recognize/enumerate if led_set() takes long(around 40ms?) // Converters fall into the case and miss wakeup event(timeout to reply?) in the end. // led_set(host_keyboard_leds()); // Instead, restore stats and update at keyboard_task() in main loop keyboard_led_stats = _led_stats; }
void iota_gfx_task_user(void) { #if DEBUG_TO_SCREEN if (debug_enable) { return; } #endif struct CharacterMatrix matrix; matrix_clear(&matrix); matrix_write_P(&matrix, PSTR("TKC1800")); uint8_t layer = biton32(layer_state); char buf[40]; snprintf(buf,sizeof(buf), "Undef-%d", layer); matrix_write_P(&matrix, PSTR("\nLayer: ")); matrix_write(&matrix, layer_lookup[layer]); // Host Keyboard LED Status char led[40]; snprintf(led, sizeof(led), "\n\n%s %s %s", (host_keyboard_leds() & (1<<USB_LED_NUM_LOCK)) ? "NUMLOCK" : " ", (host_keyboard_leds() & (1<<USB_LED_CAPS_LOCK)) ? "CAPS" : " ", (host_keyboard_leds() & (1<<USB_LED_SCROLL_LOCK)) ? "SCLK" : " "); matrix_write(&matrix, led); matrix_update(&display, &matrix); }
static void destroy_matrix(void) { if (matrix) { matrix_clear(); shm_free(matrix); } }
/* -- * Check that C = A*B to within roundoff error. * * We use the fact that dot products satisfy the error bound * * float(sum a_i * b_i) = sum a_i * b_i * (1 + delta_i) * * where delta_i <= n * epsilon. In order to check your matrix * multiply, we compute each element in turn and make sure that * your product is within three times the given error bound. * We make it three times because there are three sources of * error: * * - the roundoff error in your multiply * - the roundoff error in our multiply * - the roundoff error in computing the error bound * * That last source of error is not so significant, but that's a * story for another day. */ void validate_dgemm(const int M, const double *A, const double *B, double *C) { matrix_clear(C); square_dgemm(M, A, B, C); for (int i = 0; i < M; ++i) { for (int j = 0; j < M; ++j) { double dotprod = 0; double errorbound = 0; for (int k = 0; k < M; ++k) { double prod = A[k*M + i] * B[j*M + k]; dotprod += prod; errorbound += fabs(prod); } errorbound *= (M * DBL_EPSILON); double err = fabs(C[j*M + i] - dotprod); if (err > 3*errorbound) { fprintf(stderr, "Matrix multiply failed.\n"); fprintf(stderr, "C(%d,%d) should be %lg, was %lg\n", i, j, dotprod, C[j*M + i]); fprintf(stderr, "Error of %lg, acceptable limit %lg\n", err, 3*errorbound); diff_dgemm(M, A, B, C); exit(-1); } } } }
/* -- * Check that C = A*B to within roundoff error. * * We use the fact that dot products satisfy the error bound * * float(sum a_i * b_i) = sum a_i * b_i * (1 + delta_i) * * where delta_i <= n * epsilon. In order to check your matrix * multiply, we compute each element in turn and make sure that * your product is within three times the given error bound. * We make it three times because there are three sources of * error: * * - the roundoff error in your multiply * - the roundoff error in our multiply * - the roundoff error in computing the error bound * * That last source of error is not so significant, but that's a * story for another day. */ void diff_dgemm(const int M, const double *A, const double *B, double *C) { FILE* fp_our = fopen("dump_our.txt", "w"); FILE* fp_ref = fopen("dump_ref.txt", "w"); FILE* fp_diff = fopen("dump_diff.txt", "w"); matrix_clear(C); square_dgemm(M, A, B, C); for (int i = 0; i < M; ++i) { for (int j = 0; j < M; ++j) { double dotprod = 0; double errorbound = 0; for (int k = 0; k < M; ++k) { double prod = A[k*M + i] * B[j*M + k]; dotprod += prod; errorbound += fabs(prod); } fprintf(fp_our, " %g", C[j*M+i]); fprintf(fp_ref, " %g", dotprod); fprintf(fp_diff, " % 0.0e", C[j*M+i]-dotprod); } fprintf(fp_our, "\n"); fprintf(fp_ref, "\n"); fprintf(fp_diff, "\n"); } fclose(fp_diff); fclose(fp_ref); fclose(fp_our); }
static void clear_display(void) { matrix_clear(&display); // Clear all of the display bits (there can be random noise // in the RAM on startup) send_cmd3(PageAddr, 0, (DisplayHeight / 8) - 1); send_cmd3(ColumnAddr, 0, DisplayWidth - 1); if (i2c_start_write(SSD1306_ADDRESS)) { goto done; } if (i2c_master_write(0x40)) { // Data mode goto done; } for (uint8_t row = 0; row < MatrixRows; ++row) { for (uint8_t col = 0; col < DisplayWidth; ++col) { i2c_master_write(0); } } display.dirty = false; done: i2c_master_stop(); }
void hook_usb_suspend_entry(void) { //dprintf("huse\n"); // Turn LED off to save power // Set 0 with putting aside status before suspend and restore // it after wakeup, then LED is updated at keyboard_task() in main loop _led_stats = keyboard_led_stats; keyboard_led_stats = 0; led_set(keyboard_led_stats); matrix_clear(); clear_keyboard(); send_sleep_to_other_side(true); mcpu_hardware_shutdown(true); #ifdef BACKLIGHT_ENABLE suspend_animation(); backlight_enableShutdown(true); #endif #ifdef SLEEP_LED_ENABLE sleep_led_enable(); #endif }
int mh_osc_clear( const char *path, const char *types, lo_arg **argv, int argc, void *data, void *user_data ) { matrix_clear(); return 0; }
void matrix_init(void) { // initialize row and col matrix_clear(); LedInfo1_Off(); LedInfo2_Off(); }
// run immediately after wakeup void suspend_wakeup_init(void) { // clear keyboard state matrix_clear(); clear_keyboard(); #ifdef BACKLIGHT_ENABLE backlight_init(); #endif }
void matrix_init(void) { debug_enable = true; print("IBM 4704 converter\n"); matrix_clear(); _delay_ms(2000); // wait for keyboard starting up xprintf("Keyboard ID: %02X\n", ibm4704_recv()); enable_break(); }
void matrix_init(void) { SPI_MasterInit(); matrix_transmit(OP_SHUTDOWN,0b00000000); matrix_clear(); matrix_transmit(OP_DISPLAYTEST,0x00); matrix_transmit(OP_SCANLIMIT,0x07); matrix_transmit(OP_DECODEMODE,0x00); matrix_transmit(OP_INTENSITY,0x0F); matrix_transmit(OP_SHUTDOWN,0b00000001); }
/** Set a matrix as an identity matrix * * @param m a pointer to a square matrix * * @return m */ Matrix *matrix_set_identity(Matrix *m) { unsigned int i; assert(MATRIX_IS_SQUARE(m)); /* Clear all values */ matrix_clear(m); /* Set diagonal values to 1 */ for(i=0; i < m->rows; i++) matrix_set(m, i, i, 1.0); return m; }
void iota_gfx_task_user(void) { struct CharacterMatrix matrix; matrix_clear(&matrix); if (is_master) { matrix_write(&matrix, read_mode_icon(!get_enable_kc_lang())); matrix_write(&matrix, " "); matrix_write(&matrix, read_layer_state()); matrix_write(&matrix, read_host_led_state()); } else { matrix_write(&matrix, read_logo()); } matrix_update(&display, &matrix); }
int main (int argc, char **argv) { struct matrix A; struct matrix B; gmp_randstate_ptr rands; mpz_t bs; int i; tests_start (); rands = RANDS; matrix_init (&A, MAX_SIZE); matrix_init (&B, MAX_SIZE); mpz_init (bs); for (i = 0; i < 17; i++) { mp_size_t an, bn; mpz_urandomb (bs, rands, 32); an = 1 + mpz_get_ui (bs) % MAX_SIZE; mpz_urandomb (bs, rands, 32); bn = 1 + mpz_get_ui (bs) % MAX_SIZE; matrix_random (&A, an, rands); matrix_random (&B, bn, rands); one_test (&A, &B, i); } mpz_clear (bs); matrix_clear (&A); matrix_clear (&B); return 0; }
void iota_gfx_task_user(void) { struct CharacterMatrix matrix; #if DEBUG_TO_SCREEN if (debug_enable) { return; } #endif matrix_clear(&matrix); if (is_master) { render_status(&matrix); } else { render_logo(&matrix); } matrix_update(&display, &matrix); }
/** * Rebuild matrix using database entries * \return negative on failure, positive on success, indicating the number of matrix entries */ static int db_reload_matrix(void) { db_key_t columns[3] = { &matrix_first_col, &matrix_second_col, &matrix_res_col }; db1_res_t *res; int i; int n = 0; if (matrix_dbf.use_table(matrix_dbh, &matrix_table) < 0) { LM_ERR("cannot use table '%.*s'.\n", matrix_table.len, matrix_table.s); return -1; } if (matrix_dbf.query(matrix_dbh, NULL, NULL, NULL, columns, 0, 3, NULL, &res) < 0) { LM_ERR("error while executing query.\n"); return -1; } /* critical section start: avoids dirty reads when updating d-tree */ lock_get(lock); matrix_clear(); if (RES_COL_N(res) > 2) { for(i = 0; i < RES_ROW_N(res); i++) { if ((!RES_ROWS(res)[i].values[0].nul) && (!RES_ROWS(res)[i].values[1].nul)) { if ((RES_ROWS(res)[i].values[0].type == DB1_INT) && (RES_ROWS(res)[i].values[1].type == DB1_INT) && (RES_ROWS(res)[i].values[2].type == DB1_INT)) { matrix_insert(RES_ROWS(res)[i].values[0].val.int_val, RES_ROWS(res)[i].values[1].val.int_val, RES_ROWS(res)[i].values[2].val.int_val); n++; } else { LM_ERR("got invalid result type from query.\n"); } } } } /* critical section end */ lock_release(lock); matrix_dbf.free_result(matrix_dbh, res); LM_INFO("loaded %d matrix entries.", n); return n; }
int test_matrix_clear(void) { Matrix *matrix = new_matrix(); int res = fill_matrix(matrix, 20, 20); if(res != 0) { LOG_ERR("test matrix clear -> fill matrix error"); return res; } Status status = matrix_clear(matrix); if(status != STAT_SUCCESS) { LOG_ERR("test matrix clear"); return 1; } else { LOG_SUCCESS("test matrix clear"); return 0; } }
/* -- * Compute a MFlop/s rate for C += A*B. * * The code runs the multiplication repeatedly in a loop MIN_RUNS times, * then doubles the loop time if it did not take MIN_SECS to perform the * run. This helps us get around the limits of timer resolution. */ double time_dgemm(const int M, const double *A, const double *B, double *C) { double secs = -1.0; double mflops_sec; int num_iterations = MIN_RUNS; while (secs < MIN_SECS) { matrix_clear(C); double start = omp_get_wtime(); for (int i = 0; i < num_iterations; ++i) { square_dgemm(M, A, B, C); } double finish = omp_get_wtime(); double mflops = 2.0 * num_iterations * M * M * M / 1.0e6; secs = finish-start; mflops_sec = mflops / secs; num_iterations *= 2; } return mflops_sec; }
/* * Run a basic test and timing trial. */ int main(int argc, char** argv) { // Allocate space for ordinary column-major matrices double* A = malloc(DIM_M * DIM_P * sizeof(double)); double* B = malloc(DIM_P * DIM_N * sizeof(double)); double* C = malloc(DIM_M * DIM_N * sizeof(double)); // Allocate aligned scratch space for use by the kernel double* Ak = _mm_malloc(DIM_M * DIM_P * sizeof(double), 16); double* Bk = _mm_malloc(DIM_P * DIM_N * sizeof(double), 16); double* Ck = _mm_malloc(DIM_M * DIM_N * sizeof(double), 16); // Initialize the input matrices and convert to kernel format matrix_init(A, DIM_M, DIM_P); matrix_init(B, DIM_P, DIM_N); to_kdgemm_A(DIM_M, A, Ak); to_kdgemm_B(DIM_P, B, Bk); // Clear the kernel scratch output, run the kernel, convert to col major matrix_clear(Ck, DIM_M, DIM_N); kdgemm(Ak, Bk, Ck); from_kdgemm_C(DIM_M, Ck, C); // Check for agreement double max_diff = check_kdgemm(A, B, C); // Print kernel dimensions, megaflop rate, and error from check printf("%u,%u,%u,%lg,%0.0e\n", DIM_M, DIM_P, DIM_N, time_dgemm(Ak, Bk, Ck), max_diff); // Free kernel matrix space _mm_free(Ck); _mm_free(Bk); _mm_free(Ak); // Free argument matrix space free(C); free(B); free(A); return 0; }
/* * IBM 4704 Scan Code */ uint8_t matrix_scan(void) { uint8_t code = ibm4704_recv(); if (code==0xFF) { // Not receivd return 0; } else if ((code&0x7F) >= 0x7A) { // 0xFF-FA and 0x7F-7A is not scancode xprintf("Error: %02X\n", code); matrix_clear(); return 0; } else if (code&0x80) { dprintf("%02X\n", code); matrix_make(code); } else { dprintf("%02X\n", code); matrix_break(code); } return 1; }
static void mh_cleanup() { printf("Shutting down\n"); matrix_clear(); matrix_end(); exit(1); }
void iota_gfx_task_user(void) { #if DEBUG_TO_SCREEN if (debug_enable) { return; } #endif struct CharacterMatrix matrix; matrix_clear(&matrix); matrix_write_P(&matrix, PSTR("USB: ")); #ifdef PROTOCOL_LUFA switch (USB_DeviceState) { case DEVICE_STATE_Unattached: matrix_write_P(&matrix, PSTR("Unattached")); break; case DEVICE_STATE_Suspended: matrix_write_P(&matrix, PSTR("Suspended")); break; case DEVICE_STATE_Configured: matrix_write_P(&matrix, PSTR("Connected")); break; case DEVICE_STATE_Powered: matrix_write_P(&matrix, PSTR("Powered")); break; case DEVICE_STATE_Default: matrix_write_P(&matrix, PSTR("Default")); break; case DEVICE_STATE_Addressed: matrix_write_P(&matrix, PSTR("Addressed")); break; default: matrix_write_P(&matrix, PSTR("Invalid")); } #endif // Define layers here, Have not worked out how to have text displayed for each layer. Copy down the number you see and add a case for it below char buf[40]; snprintf(buf,sizeof(buf), "Undef-%ld", layer_state); matrix_write_P(&matrix, PSTR("\n\nLayer: ")); switch (layer_state) { case L_BASE: matrix_write_P(&matrix, PSTR("Default")); break; case L_RAISE: matrix_write_P(&matrix, PSTR("Raise")); break; case L_LOWER: matrix_write_P(&matrix, PSTR("Lower")); break; case L_ADJUST: matrix_write_P(&matrix, PSTR("ADJUST")); break; default: matrix_write(&matrix, buf); } // Host Keyboard LED Status char led[40]; snprintf(led, sizeof(led), "\n%s %s %s", (host_keyboard_leds() & (1<<USB_LED_NUM_LOCK)) ? "NUMLOCK" : " ", (host_keyboard_leds() & (1<<USB_LED_CAPS_LOCK)) ? "CAPS" : " ", (host_keyboard_leds() & (1<<USB_LED_SCROLL_LOCK)) ? "SCLK" : " "); matrix_write(&matrix, led); matrix_update(&display, &matrix); }
static void *matrix_new(t_symbol *s, int ac, t_atom *av) { t_pd *z; if (!fittermax_get() && (z = fragile_class_mutate(matrixps_matrixtilde, (t_newmethod)matrix_new, ac, av))) return (z); else if (ac < 2) { loud_error(0, "bad creation arguments for class '%s'", matrixps_matrixtilde->s_name); loud_errand(0, "missing number of %s", (ac ? "outlets" : "inlets")); return (0); /* CHECKED */ } else { t_matrix *x = (t_matrix *)pd_new(matrix_class); int i; if (av[0].a_type == A_FLOAT) { if ((x->x_ninlets = (int)av[0].a_w.w_float) < 1) x->x_ninlets = 1; } else x->x_ninlets = 1; /* CHECKED */ if (av[1].a_type == A_FLOAT) { if ((x->x_noutlets = (int)av[1].a_w.w_float) < 1) x->x_noutlets = 1; } else x->x_noutlets = 1; /* CHECKED */ x->x_ncells = x->x_ninlets * x->x_noutlets; x->x_ivecs = getbytes(x->x_ninlets * sizeof(*x->x_ivecs)); x->x_ovecs = getbytes(x->x_noutlets * sizeof(*x->x_ovecs)); x->x_nblock = x->x_maxblock = sys_getblksize(); x->x_osums = getbytes(x->x_noutlets * sizeof(*x->x_osums)); for (i = 0; i < x->x_noutlets; i++) x->x_osums[i] = getbytes(x->x_maxblock * sizeof(*x->x_osums[i])); x->x_cells = getbytes(x->x_ncells * sizeof(*x->x_cells)); matrix_clear(x); if (ac >= 3) { if (av[2].a_type == A_FLOAT) x->x_defgain = av[2].a_w.w_float; else x->x_defgain = MATRIX_DEFGAIN; x->x_gains = getbytes(x->x_ncells * sizeof(*x->x_gains)); for (i = 0; i < x->x_ncells; i++) x->x_gains[i] = x->x_defgain; x->x_ramps = getbytes(x->x_ncells * sizeof(*x->x_ramps)); matrix_ramp(x, MATRIX_DEFRAMP); x->x_coefs = getbytes(x->x_ncells * sizeof(*x->x_coefs)); for (i = 0; i < x->x_ncells; i++) x->x_coefs[i] = 0.; x->x_ksr = sys_getsr() * .001; x->x_incrs = getbytes(x->x_ncells * sizeof(*x->x_incrs)); x->x_bigincrs = getbytes(x->x_ncells * sizeof(*x->x_bigincrs)); x->x_remains = getbytes(x->x_ncells * sizeof(*x->x_remains)); for (i = 0; i < x->x_ncells; i++) x->x_remains[i] = 0; } else { x->x_gains = 0; x->x_ramps = 0; x->x_coefs = 0; x->x_incrs = 0; x->x_bigincrs = 0; x->x_remains = 0; } for (i = 1; i < x->x_ninlets; i++) sic_newinlet((t_sic *)x, 0.); for (i = 0; i < x->x_noutlets; i++) outlet_new((t_object *)x, &s_signal); x->x_dumpout = outlet_new((t_object *)x, &s_list); return (x); } }
static void *matrix_new(t_symbol *s, int argc, t_atom *argv) { t_matrix *x = (t_matrix *)pd_new(matrix_class); t_float rampval = MATRIX_DEFRAMP; x->x_numinlets = (int)MATRIX_MININLETS; x->x_numoutlets = (int)MATRIX_MINOUTLETS; x->x_defgain = MATRIX_DEFGAIN; int i; int argnum = 0; while(argc > 0){ if(argv -> a_type == A_FLOAT){ t_float argval = atom_getfloatarg(0, argc, argv); switch(argnum){ case 0: if(argval < MATRIX_MININLETS){ x->x_numinlets = (int)MATRIX_MININLETS; } else if (argval > MATRIX_MAXINLETS){ x->x_numinlets = (int)MATRIX_MAXINLETS; post("matrix~: resizing to %d signal inlets", (int)MATRIX_MAXINLETS); } else{ x->x_numinlets = (int)argval; }; break; case 1: if(argval < MATRIX_MINOUTLETS){ x->x_numoutlets = (int)MATRIX_MINOUTLETS; } else if (argval > MATRIX_MAXOUTLETS){ x->x_numoutlets = (int)MATRIX_MAXOUTLETS; post("matrix~: resizing to %d signal outlets", (int)MATRIX_MAXOUTLETS); } else{ x->x_numoutlets = (int)argval; }; break; case 2: x->x_defgain = argval; break; default: break; }; argc--; argv++; argnum++; } else if(argv -> a_type == A_SYMBOL){ t_symbol *argname = atom_getsymbolarg(0, argc, argv); if(strcmp(argname->s_name, "@ramp")==0){ if(argc >= 2){ t_float argval = atom_getfloatarg(1, argc, argv); if(argval < MATRIX_MINRAMP){ rampval = MATRIX_MINRAMP; } else{ rampval = argval; }; argc -= 2; argv += 2; } else{ goto errstate; }; } else{ goto errstate; }; } else{ goto errstate; }; }; int gaingiven = argnum >= 3; //if >= 3 args given, then gain is given, binary mode is off x->x_ncells = x->x_numinlets * x->x_numoutlets; x->x_ivecs = getbytes(x->x_numinlets * sizeof(*x->x_ivecs)); x->x_ovecs = getbytes(x->x_numoutlets * sizeof(*x->x_ovecs)); x->x_nblock = x->x_maxblock = sys_getblksize(); x->x_osums = getbytes(x->x_numoutlets * sizeof(*x->x_osums)); for (i = 0; i < x->x_numoutlets; i++){ x->x_osums[i] = getbytes(x->x_maxblock * sizeof(*x->x_osums[i])); }; x->x_cells = getbytes(x->x_ncells * sizeof(*x->x_cells)); /* zerovec for filtering float inputs*/ x->x_zerovec = getbytes(x->x_maxblock * sizeof(*x->x_zerovec)); matrix_clear(x); if (gaingiven){ x->x_gains = getbytes(x->x_ncells * sizeof(*x->x_gains)); for (i = 0; i < x->x_ncells; i++){ x->x_gains[i] = x->x_defgain; }; x->x_ramps = getbytes(x->x_ncells * sizeof(*x->x_ramps)); matrix_ramp(x, rampval); x->x_coefs = getbytes(x->x_ncells * sizeof(*x->x_coefs)); for (i = 0; i < x->x_ncells; i++){ x->x_coefs[i] = 0.; }; x->x_ksr = sys_getsr() * .001; x->x_incrs = getbytes(x->x_ncells * sizeof(*x->x_incrs)); x->x_bigincrs = getbytes(x->x_ncells * sizeof(*x->x_bigincrs)); x->x_remains = getbytes(x->x_ncells * sizeof(*x->x_remains)); for (i = 0; i < x->x_ncells; i++){ x->x_remains[i] = 0; }; } else{ x->x_gains = 0; x->x_ramps = 0; x->x_coefs = 0; x->x_incrs = 0; x->x_bigincrs = 0; x->x_remains = 0; }; for (i = 1; i < x->x_numinlets; i++){ pd_float( (t_pd *)inlet_new(&x->x_obj, &x->x_obj.ob_pd, &s_signal, &s_signal), -0.); x->x_signalscalars[i] = obj_findsignalscalar((t_object *)x, i); }; for (i = 0; i < x->x_numoutlets; i++){ outlet_new(&x->x_obj, gensym("signal")); }; x->x_dumpout = outlet_new((t_object *)x, &s_list); x->x_glist = canvas_getcurrent(); return (x); errstate: pd_error(x, "matrix~: improper args"); return NULL; }
void iota_gfx_task_user(void) { struct CharacterMatrix matrix; matrix_clear(&matrix); matrix_render_user(&matrix); matrix_update(&display, &matrix); }
void iota_gfx_clear_screen(void) { matrix_clear(&display); }
/* * PS/2 Scan Code Set 2: Exceptional Handling * * There are several keys to be handled exceptionally. * The scan code for these keys are varied or prefix/postfix'd * depending on modifier key state. * * Keyboard Scan Code Specification: * http://www.microsoft.com/whdc/archive/scancode.mspx * http://download.microsoft.com/download/1/6/1/161ba512-40e2-4cc9-843a-923143f3456c/scancode.doc * * * 1) Insert, Delete, Home, End, PageUp, PageDown, Up, Down, Right, Left * a) when Num Lock is off * modifiers | make | break * ----------+---------------------------+---------------------- * Ohter | <make> | <break> * LShift | E0 F0 12 <make> | <break> E0 12 * RShift | E0 F0 59 <make> | <break> E0 59 * L+RShift | E0 F0 12 E0 F0 59 <make> | <break> E0 59 E0 12 * * b) when Num Lock is on * modifiers | make | break * ----------+---------------------------+---------------------- * Other | E0 12 <make> | <break> E0 F0 12 * Shift'd | <make> | <break> * * Handling: These prefix/postfix codes are ignored. * * * 2) Keypad / * modifiers | make | break * ----------+---------------------------+---------------------- * Ohter | <make> | <break> * LShift | E0 F0 12 <make> | <break> E0 12 * RShift | E0 F0 59 <make> | <break> E0 59 * L+RShift | E0 F0 12 E0 F0 59 <make> | <break> E0 59 E0 12 * * Handling: These prefix/postfix codes are ignored. * * * 3) PrintScreen * modifiers | make | break * ----------+--------------+----------------------------------- * Other | E0 12 E0 7C | E0 F0 7C E0 F0 12 * Shift'd | E0 7C | E0 F0 7C * Control'd | E0 7C | E0 F0 7C * Alt'd | 84 | F0 84 * * Handling: These prefix/postfix codes are ignored, and both scan codes * 'E0 7C' and 84 are seen as PrintScreen. * * 4) Pause * modifiers | make(no break code) * ----------+-------------------------------------------------- * Other | E1 14 77 E1 F0 14 F0 77 * Control'd | E0 7E E0 F0 7E * * Handling: Both code sequences are treated as a whole. * And we need a ad hoc 'pseudo break code' hack to get the key off * because it has no break code. * */ uint8_t matrix_scan(void) { // scan code reading states static enum { INIT, F0, E0, E0_F0, // Pause E1, E1_14, E1_14_77, E1_14_77_E1, E1_14_77_E1_F0, E1_14_77_E1_F0_14, E1_14_77_E1_F0_14_F0, // Control'd Pause E0_7E, E0_7E_E0, E0_7E_E0_F0, } state = INIT; is_modified = false; // 'pseudo break code' hack if (matrix_is_on(ROW(PAUSE), COL(PAUSE))) { matrix_break(PAUSE); } uint8_t code = ps2_host_recv(); if (!ps2_error) { switch (state) { case INIT: switch (code) { case 0xE0: state = E0; break; case 0xF0: state = F0; break; case 0xE1: state = E1; break; case 0x83: // F7 matrix_make(F7); state = INIT; break; case 0x84: // Alt'd PrintScreen matrix_make(PRINT_SCREEN); state = INIT; break; case 0x00: // Overrun [3]p.25 matrix_clear(); clear_keyboard(); print("Overrun\n"); state = INIT; break; default: // normal key make if (code < 0x80) { matrix_make(code); } else { matrix_clear(); clear_keyboard(); xprintf("unexpected scan code at INIT: %02X\n", code); } state = INIT; } break; case E0: // E0-Prefixed switch (code) { case 0x12: // to be ignored case 0x59: // to be ignored state = INIT; break; case 0x7E: // Control'd Pause state = E0_7E; break; case 0xF0: state = E0_F0; break; default: if (code < 0x80) { matrix_make(code|0x80); } else { matrix_clear(); clear_keyboard(); xprintf("unexpected scan code at E0: %02X\n", code); } state = INIT; } break; case F0: // Break code switch (code) { case 0x83: // F7 matrix_break(F7); state = INIT; break; case 0x84: // Alt'd PrintScreen matrix_break(PRINT_SCREEN); state = INIT; break; case 0xF0: matrix_clear(); clear_keyboard(); xprintf("unexpected scan code at F0: F0(clear and cont.)\n"); break; default: if (code < 0x80) { matrix_break(code); } else { matrix_clear(); clear_keyboard(); xprintf("unexpected scan code at F0: %02X\n", code); } state = INIT; } break; case E0_F0: // Break code of E0-prefixed switch (code) { case 0x12: // to be ignored case 0x59: // to be ignored state = INIT; break; default: if (code < 0x80) { matrix_break(code|0x80); } else { matrix_clear(); clear_keyboard(); xprintf("unexpected scan code at E0_F0: %02X\n", code); } state = INIT; } break; // following are states of Pause case E1: switch (code) { case 0x14: state = E1_14; break; default: state = INIT; } break; case E1_14: switch (code) { case 0x77: state = E1_14_77; break; default: state = INIT; } break; case E1_14_77: switch (code) { case 0xE1: state = E1_14_77_E1; break; default: state = INIT; } break; case E1_14_77_E1: switch (code) { case 0xF0: state = E1_14_77_E1_F0; break; default: state = INIT; } break; case E1_14_77_E1_F0: switch (code) { case 0x14: state = E1_14_77_E1_F0_14; break; default: state = INIT; } break; case E1_14_77_E1_F0_14: switch (code) { case 0xF0: state = E1_14_77_E1_F0_14_F0; break; default: state = INIT; } break; case E1_14_77_E1_F0_14_F0: switch (code) { case 0x77: matrix_make(PAUSE); state = INIT; break; default: state = INIT; } break; // Following are states of Control'd Pause case E0_7E: if (code == 0xE0) state = E0_7E_E0; else state = INIT; break; case E0_7E_E0: if (code == 0xF0) state = E0_7E_E0_F0; else state = INIT; break; case E0_7E_E0_F0: if (code == 0x7E) matrix_make(PAUSE); state = INIT; break; default: state = INIT; } } // TODO: request RESEND when error occurs? /* if (PS2_IS_FAILED(ps2_error)) { uint8_t ret = ps2_host_send(PS2_RESEND); xprintf("Resend: %02X\n", ret); } */ return 1; }