示例#1
0
STATIC mp_uint_t pyb_uart_read(mp_obj_t self_in, void *buf_in, mp_uint_t size, int *errcode) {
    pyb_uart_obj_t *self = self_in;
    byte *buf = buf_in;

    // make sure we want at least 1 char
    if (size == 0) {
        return 0;
    }

    // wait for first char to become available
    if (!uart_rx_wait(self, self->timeout)) {
        // we can either return 0 to indicate EOF (then read() method returns b'')
        // or return EAGAIN error to indicate non-blocking (then read() method returns None)
        return 0;
    }

    // read the data
    byte *orig_buf = buf;
    for (;;) {
        *buf++ = uart_rx_char(self);
        if (--size == 0 || !uart_rx_wait(self, self->timeout_char)) {
            // return number of bytes read
            return buf - orig_buf;
        }
    }
}
示例#2
0
/// \method readchar()
/// Receive a single character on the bus.
/// Return value: The character read, as an integer.  Returns -1 on timeout.
STATIC mp_obj_t pyb_uart_readchar(mp_obj_t self_in) {
    pyb_uart_obj_t *self = self_in;
    if (uart_rx_wait(self, self->timeout)) {
        return mp_obj_new_int(uart_rx_char(self));
    } else {
        // return -1 on timeout
        return MP_OBJ_NEW_SMALL_INT(-1);
    }
}
示例#3
0
int mp_hal_stdin_rx_chr(void) {
    for (;;) {
        byte c;
        if (usb_vcp_recv_byte(&c) != 0) {
            return c;
        } else if (MP_STATE_PORT(pyb_stdio_uart) != NULL && uart_rx_any(MP_STATE_PORT(pyb_stdio_uart))) {
            return uart_rx_char(MP_STATE_PORT(pyb_stdio_uart));
        }
        __WFI();
    }
}
示例#4
0
int stdin_rx_chr(void) {
    for (;;) {
#if 0
#ifdef USE_HOST_MODE
        pyb_usb_host_process();
        int c = pyb_usb_host_get_keyboard();
        if (c != 0) {
            return c;
        }
#endif
#endif

        byte c;
        if (usb_vcp_recv_byte(&c) != 0) {
            return c;
        } else if (pyb_stdio_uart != PYB_UART_NONE && uart_rx_any(pyb_stdio_uart)) {
            return uart_rx_char(pyb_stdio_uart);
        }
        __WFI();
    }
}
示例#5
0
int mp_hal_stdin_rx_chr(void) {
    for (;;) {
#if 0
#ifdef USE_HOST_MODE
        pyb_usb_host_process();
        int c = pyb_usb_host_get_keyboard();
        if (c != 0) {
            return c;
        }
#endif
#endif

        byte c;
        if (usb_vcp_recv_byte(&c) != 0) {
            return c;
        } else if (MP_STATE_PORT(pyb_stdio_uart) != NULL && uart_rx_any(MP_STATE_PORT(pyb_stdio_uart))) {
            return uart_rx_char(MP_STATE_PORT(pyb_stdio_uart));
        }
        __WFI();
    }
}
示例#6
0
void main(void)
{
  stop_watchdog();
  set_clk_8MHz();

  //interrupts_enable();

  lcd_init();
  uart_init();


  /*
   * Read a regiser (data[1]) and print register and value on the display
   * */
  unsigned char i2creceive[8];
  i2c_master_init();
  unsigned char data[1] = {0x6F};
  lcd_goto(1,0);
  lcd_print("R: ");
  lcd_print(int2HEXcharArray(*data));
  lcd_goto(2,0);
  lcd_print("V: ");
  i2c_writeByte(1,data,0x50);
  __delay_cycles(300);  // delay some time to get a better view on the signals
  unsigned char rx_byte = i2c_receiveSingleByte(0x50);
  __delay_cycles(300);
  lcd_print(int2HEXcharArray(rx_byte));


  /*
   * receive 256 register values via UART and write them to the EEPROM (incrementing address from 0x00 to 0xFF)
   * */

  ///*
  unsigned char write_byte[2];
  unsigned int write_counter = 0;

  while(write_counter < 255) {
	  lcd_goto(2,0);
	  write_byte[0] = write_counter;
	  write_byte[1] = uart_rx_char();
	  lcd_print(int2HEXcharArray(write_byte[1]));
	  i2c_writeByte(2,write_byte,0x50);
	  write_counter = write_counter + 1;
  }
  //*/


  /*
   * Read out a register value and print it on the display to verify the write process
   * */
  lcd_goto(2,0);
  lcd_print("V: ");
  i2c_writeByte(1,data,0x50);
  rx_byte = i2c_receiveSingleByte(0x50);
  __delay_cycles(300);
  lcd_print(int2HEXcharArray(rx_byte));
  __delay_cycles(300);

  for (;;)
  {

  }
}