void SysTick_Handler (void) { static uint_32 tick = 0; tick++; if (tick%100 == 0) { //uart_send_buffer(0, "BEEP\r\n", strlen("BEEP\r\n")); sprintf((char *)buf, "ADC=%d\r\n\0", adcval_filtered); uart_send_buffer(0, buf, strlen((const char *)buf)); } //pwm_systick_control(90); }
int main(int argc, char *argv[]) { static struct option long_options[] = { { "uart-port", required_argument, 0, 'p' }, { "baud-rate", required_argument, 0, 'b' }, { "closed-loop", no_argument, 0, 'c' }, { "no-reply", no_argument, 0, 'n' }, { "colors", no_argument, 0, 'j' }, { "quiet", no_argument, 0, 'q' }, { "help", no_argument, 0, 'h' }, { 0, 0, 0, 0 } }; int option; int option_index = 0; while ((option = getopt_long(argc, argv, "p:b:cnjqh", long_options, &option_index)) != -1) { switch (option) { case 0: break; case 'p': if (optarg) { option_port = optarg; } break; case 'b': if (optarg) { option_baud = optarg; } break; case 'c': option_closed_loop = 1; break; case 'n': option_no_reply = 1; break; case 'j': option_colors = 1; break; case 'q': option_quiet = 1; break; case 'h': puts("Usage: uartaccessory [options]"); puts("Options:"); puts(" -h, --help Display this information"); puts(" -p, --uart-port Set the uart port. Example: use -p /dev/ttyUSB3 or simply port number -p 3. Default is /dev/ttyUSB0"); puts(" -b, --baud-rate Set the baud rate. Example: use -b 57600. Standard values are permitted. Default is 115200"); puts(" -c, --closed-loop Enable closed loop mode where accessory TX/RX are logically coupled and ttyUSBx disabled"); puts(" -n, --no-reply Disable sending of RX data packets (reply to request)"); puts(" -j, --colors Enable colors to show TX vs RX packets"); puts(" -q, --quiet Quiet mode"); return EXIT_SUCCESS; } } accessory_device *ad = NULL; accessory_init(); int need_quit = 0; while (need_quit == 0) { puts(""); puts("Looking for accessory device... Press Q to quit"); while (1) { int key = getasynckey(); if (key == 'Q' || key == 'q') { need_quit = 1; break; } ad = accessory_get_device(); if (ad != NULL) { printf(" - Found Android device with ID=%04x:%04x now connected as ID=%04x:%04x, version %d\n", ad->vendor_id, ad->product_id, ad->aoa_vendor_id, ad->aoa_product_id, ad->aoa_version); break; } usleep(500000); } if (need_quit != 0) break; puts(""); puts("Capture and show data flow coming from Android device... Press Q to quit"); unsigned char *buffer = malloc(ACCESSORY_MODE_BUFFER_SIZE); if (buffer == NULL) return EXIT_FAILURE; if (option_closed_loop == 0) { char device_name[256]; if (option_port[0] == '/') strcpy(device_name, option_port); else { strcpy(device_name, "/dev/ttyUSB"); strcpy(&device_name[11], option_port); } int i; speed_t baud_rate = B0; int requested_baud = atoi(option_baud); for (i = 0; i < ARRAY_LEN(baud_table); i++) { if (baud_table[i].baud_rate == requested_baud) { baud_rate = baud_table[i].speed; break; } } if (baud_rate == B0) { fprintf(stderr, "Unrecognized baud rate: '%s'\n", option_baud); exit(1); } if (uart_open(device_name, baud_rate, 0) < 0) { char message[256]; snprintf(message, sizeof message, "Unable to open serial port %s", device_name); perror(message); return EXIT_FAILURE; } } while (1) { int key = getasynckey(); if (key == 'Q' || key == 'q') { need_quit = 1; break; } int cnt = accessory_receive_data(ad, buffer, ACCESSORY_MODE_BUFFER_SIZE); if (cnt > 0) { print_buffer(buffer, cnt, 0); if (option_closed_loop == 0) uart_send_buffer(buffer, cnt); else if (option_no_reply == 0) { accessory_send_data(ad, buffer, cnt); print_buffer(buffer, cnt, 1); } } else if (cnt == LIBUSB_ERROR_NO_DEVICE) { puts("AOA device disconnected !"); break; } if (option_no_reply == 0 && option_closed_loop == 0) { cnt = uart_receive_buffer_timout(buffer, ACCESSORY_MODE_BUFFER_SIZE, 0); if (cnt > 0) { accessory_send_data(ad, buffer, cnt); print_buffer(buffer, cnt, 1); } } } free(buffer); } accessory_free_device(ad); accessory_finalize(); uart_close(); return EXIT_SUCCESS; }
void uart_send_byte(uint8_t b) { while (!uart_send_complete()) {} bytebuf = b; uart_send_buffer(&bytebuf,1); }