Exemplo n.º 1
0
void
core_read_usb(uint8_t port)
{
  uint8_t c;
  //check for incoming USB data
  while (udi_cdc_is_rx_ready()) {
    c = udi_cdc_getc();
    if(cmd_buf_full)
      return; //still processing last command
    if (c < 0) {
      printf("read error: %d\n", c);
      return;
    } else if ((c == '\b' || c == '\x7f') && cmd_buf_idx > 0) {
      if (wemo_config.echo)
	udi_cdc_putc('\b');
      cmd_buf_idx--;
    } else if (c >= ' ' && cmd_buf_idx < CMD_BUF_SIZE-1) {
      if(wemo_config.echo)
	udi_cdc_putc(c);
      cmd_buf[cmd_buf_idx++] = c;
    } else if (c == '\n' || c == '\r') {
      cmd_buf[cmd_buf_idx] = 0; //we have a complete command
      if(wemo_config.echo)
	printf("\r\n");
      //run the command in the main loop (get out of USB interrupt ctx)
      cmd_buf_full = true;
    }
  }
}
Exemplo n.º 2
0
int comms_usb_putchar(char c, FILE *stream)
{

	if (c == '\n')
	comms_usb_putchar('\r', stream);
	udi_cdc_putc(c);
	return 0;
}
Exemplo n.º 3
0
size_t SerialCDC::write(uint8_t c)
{
	if (isConnected)
	{
		udi_cdc_putc(c);
	}
	return 1;
}
Exemplo n.º 4
0
int stdio_usb_putchar (volatile void * usart, int data)
{
	/* A negative return value should be used to indicate that data
	 * was not written, but this doesn't seem to work with GCC libc.
	 */
	if (!stdio_usb_interface_enable) {
		return 0;  // -1
	}

	return udi_cdc_putc (data) ? 0 : -1;
}
Exemplo n.º 5
0
int main (void)
{
	sysclk_init();
	ioport_init();
	
	ioport_set_pin_dir(LED_BLUE, IOPORT_DIR_OUTPUT);
	ioport_set_pin_dir(LED_GREEN, IOPORT_DIR_OUTPUT);
	ioport_set_pin_dir(LED_WHITE, IOPORT_DIR_OUTPUT);
	
	ioport_configure_pin(BUTTON_0, IOPORT_PULL_UP);
	ioport_configure_pin(BUTTON_1, IOPORT_PULL_UP);

	force_boot_loader();
	
	irq_initialize_vectors();
	cpu_irq_enable();
	udc_start();
	//board_init();

	while(1)
	{
		ioport_toggle_pin_level(LED_GREEN);
		delay_ms(100);
		ioport_set_pin_level(LED_BLUE, ioport_get_pin_level(BUTTON_0));
		ioport_set_pin_level(LED_WHITE, ioport_get_pin_level(BUTTON_1));
		
		char usb_in = udi_cdc_getc();
		char usb_out [17]=  "WHAT YOU TYPED: \r";//udi_cdc_getc();
		for (int i=0;i<16;i++)
		{
			udi_cdc_putc(usb_out[i]);
		}
		udi_cdc_putc(usb_in);
		udi_cdc_putc('\r');
	}
}
Exemplo n.º 6
0
uint8_t sio2host_tx(uint8_t *data, uint8_t length)
{
	int status;
	uint8_t len;
	len = length;
	
   while (len) {
	  status = udi_cdc_putc(*data);
	  /* Check transmission status */
	  if(status)
	   { 
	   /* Put next byte if the previous transfer is successful */
	    len--;
	    data++;
		}
   }
   return length;
}
Exemplo n.º 7
0
bool uart_poll(void) {
	if (my_flag_autorize_cdc_transfert) {
		if (exec_mode) {
			exec_mode = false;
			// process content of the buffer
			parse_line(usb_buffin, usb_buffout, sizeof(usb_buffout) - 1, true);
				
			char *ptr = usb_buffout;
			// print out the command response
			while (*ptr) {
				udi_cdc_putc(*ptr++);
			}
			// reset pointer and exec mode
			put_ptr = 0;
			return true;
		}
	}
	return false;
}
/**
 * \internal
 * \brief USART interrupt callback function
 *
 * Called by USART driver when receiving is complete.
 *
 * * \param module USART module causing the interrupt (not used)
 */
static void usart_rx_callback(struct usart_module *const module)
{
	/* Data received */
	ui_com_tx_start();

	/* Transfer UART RX fifo to CDC TX */
	if (!udi_cdc_is_tx_ready()) {
		/* Fifo full */
		udi_cdc_signal_overrun();
		ui_com_overflow();
	} else {
		udi_cdc_putc(rx_data);
	}

	ui_com_tx_stop();

	usart_read_buffer_job(&usart_module_edbg, &rx_data, 1);

	return;
}
/*! \brief Write data buffer via USB or serial port.
 *
 * This application uses a serial or USB connection to transmit sensor data.
 * This routine takes the specified input buffer and writes each byte to
 * the appropriate output device.
 *
 * \param   buffer    The address of a buffer containing the data to transmit
 * \param   num_bytes The number of bytes to transmit
 *
 * \return  Nothing.
 */
void adv_write_buf(uint8_t *buffer, int num_bytes)
{
#if UC3
#  if UC3L
	/* Use regular USART stdio output */

	/* Transmit each character */
	while (num_bytes-- > 0) {
		putchar(*buffer++);         /* write char via usart */
	}

#  else
	/* Use internal USB controller (CDC device) */

	/* Check if USB ready to transmit */
	if (!(udi_cdc_is_tx_ready())) {
		return;
	}

	/* Transmit each character */
	while (num_bytes-- > 0) {
		udi_cdc_putc(*buffer++);         /* write char via USB CDC
		                                  * device */
	}
#  endif

#elif XMEGA
	/* Transmit each character */
	while (num_bytes-- > 0) {
		putchar(*buffer++);         /* write char via usart */
	}
#endif

	/* Delay to allow all bytes to output */
	delay_ms(PKT_XMIT_DELAY);

	return;
}
Exemplo n.º 10
0
// sends a single character if usb driver is running
void usb_putc(char in) {
	if (my_flag_autorize_cdc_transfert)
		udi_cdc_putc(in);
}
Exemplo n.º 11
0
int usb_data_write_byte(Byte data)
{
	while(!udi_cdc_is_tx_ready());
	return udi_cdc_putc(data);
}
Exemplo n.º 12
0
static void usb_cdc_command_console_task(void *pvParameters)
{
	uint8_t received_char, input_index = 0, *output_string;
	static int8_t input_string[MAX_INPUT_SIZE],
			last_input_string[MAX_INPUT_SIZE];
	portBASE_TYPE returned_value;

	/* Just to remove compiler warnings. */
	(void) pvParameters;

	udc_start();

	if (udc_include_vbus_monitoring() == false) {
		/* VBUS monitoring is not available on this product.  Assume VBUS is
		present. */
		cli_vbus_event(true);
	}

	/* Obtain the address of the output buffer.  Note there is no mutual
	exclusion on this buffer as it is assumed only one command console
	interface will be used at any one time. */
	output_string = (uint8_t *) FreeRTOS_CLIGetOutputBuffer();

	for (;;) {
		/* Wait for new data. */
		xSemaphoreTake(cdc_new_data_semaphore, portMAX_DELAY);

		/* Ensure mutually exclusive access is obtained as other tasks can write
		to the CLI. */
		xSemaphoreTake(access_mutex, portMAX_DELAY);

		/* While there are input characters. */
		while (udi_cdc_is_rx_ready() == true) {
			received_char = (uint8_t) udi_cdc_getc();

			/* Echo the character. */
			udi_cdc_putc(received_char);

			if (received_char == '\r') {
				/* Transmit a line separator, just to make the output easier to
				read. */
				udi_cdc_write_buf((void *) new_line,
						strlen((char *) new_line));

				/* See if the command is empty, indicating that the last command
				is to be executed again. */
				if (input_index == 0) {
					strcpy((char *) input_string,
							(char *) last_input_string);
				}

				/* Pass the received command to the command interpreter.  The
				command interpreter is called repeatedly until it returns pdFALSE as
				it might generate more than one string. */
				do {
					/* Get the string to write to the UART from the command
					interpreter. */
					returned_value = FreeRTOS_CLIProcessCommand(
							input_string,
							(int8_t *) output_string,
							configCOMMAND_INT_MAX_OUTPUT_SIZE);

					/* Transmit the generated string. */
					udi_cdc_write_buf((void *) output_string, strlen(
							(char *) output_string));
				} while (returned_value != pdFALSE);

				/* All the strings generated by the input command have been sent.
				Clear the input	string ready to receive the next command.
				Remember the command that was just processed first in case it is
				to be processed again. */
				strcpy((char *) last_input_string,
						(char *) input_string);
				input_index = 0;
				memset(input_string, 0x00, MAX_INPUT_SIZE);

				/* Start to transmit a line separator, just to make the output
				easier to read. */
				udi_cdc_write_buf((void *) line_separator, strlen(
						(char *) line_separator));
			} else {
				if (received_char == '\n') {
					/* Ignore the character. */
				} else if (received_char == '\b') {
					/* Backspace was pressed.  Erase the last character in the
					string - if any. */
					if (input_index > 0) {
						input_index--;
						input_string[input_index]
							= '\0';
					}
				} else {
					/* A character was entered.  Add it to the string
					entered so far.  When a \n is entered the complete
					string will be passed to the command interpreter. */
					if (input_index < MAX_INPUT_SIZE) {
						input_string[input_index] = received_char;
						input_index++;
					}
				}
			}
		}

		/* Finished with the CDC port, return the mutex until more characters
		arrive. */
		xSemaphoreGive(access_mutex);
	}
}
Exemplo n.º 13
0
void usb_putchar(char a)
{
	udi_cdc_putc(a);
}