コード例 #1
0
ファイル: main.c プロジェクト: uISP/uisp-appsources
uchar	usbFunctionSetup(uchar data[8]) {
  static uchar replyBuf[4];
  usbMsgPtr = replyBuf;
#else
extern	byte_t	usb_setup ( byte_t data[8] )
{
  byte_t *replyBuf = data;
#endif

  DEBUGF("Setup %x %x %x %x\n", data[0], data[1], data[2], data[3]);

  switch(data[1]) {

  case CMD_ECHO: // echo (for transfer reliability testing)
    replyBuf[0] = data[2];
    replyBuf[1] = data[3];
    return 2;
    break;

  case CMD_GET_FUNC:
    memcpy_P(replyBuf, &func, sizeof(func));
    return sizeof(func);
    break;

  case CMD_SET_DELAY:
    /* The delay function used delays 4 system ticks per cycle. */
    /* This gives 1/3us at 12Mhz per cycle. The delay function is */
    /* called twice per clock edge and thus four times per full cycle. */ 
    /* Thus it is called one time per edge with the full delay */ 
    /* value and one time with the half one. Resulting in */
    /* 2 * n * 1/3 + 2 * 1/2 n * 1/3 = n us. */
    clock_delay = *(unsigned short*)(data+2);
    if(!clock_delay) clock_delay = 1;
    clock_delay2 = clock_delay/2;
    if(!clock_delay2) clock_delay2 = 1;

    DEBUGF("request for delay %dus\n", clock_delay); 
    break;

  case CMD_I2C_IO:
  case CMD_I2C_IO + CMD_I2C_BEGIN:
  case CMD_I2C_IO                 + CMD_I2C_END:
  case CMD_I2C_IO + CMD_I2C_BEGIN + CMD_I2C_END:
    // these are only allowed as class transfers

    return i2c_do((struct i2c_cmd*)data);
    break;

  case CMD_GET_STATUS:
    replyBuf[0] = status;
    return 1;
    break;

  default:
    // must not happen ...
    break;
  }

  return 0;  // reply len
}
コード例 #2
0
ファイル: lpc11xx_i2c.c プロジェクト: 88kacper8/u8glib
/*

  uint8_t i2c_receive_data(i2c_struct *i2c, uint8_t adr, uint32_t cnt, uint8_t *buf, uint8_t send_stop)
  
  adr
    address of the device

  cnt
    number of bytes to receive

  buf
    pointer to buffer with the data from the i2c device

  send_stop
    0: does not send stop condition after successful data receive. Another transmit/receive
	after this transmit will generate a repeated start condition
    1:	send stop codition after successful receive of data.

  note: in the case of any errors, a stop condition is sent.

*/
uint8_t i2c_receive_data(i2c_struct *i2c, uint8_t adr, uint32_t cnt, uint8_t *buf, uint8_t send_stop)
{
  i2c->adr = adr;
  i2c->is_send_stop = send_stop;
  i2c->data_cnt = cnt;
  i2c->data_buf = buf;
  i2c->pre_data_cnt = 0;
  i2c->pre_data_buf = NULL;
  i2c_clear_error(i2c);  
  i2c->state = I2C_STATE_MR_GENERATE_START;
  return i2c_do(i2c);
}
コード例 #3
0
ファイル: lpc11xx_i2c.c プロジェクト: 88kacper8/u8glib
uint8_t i2c_send_pre_data(i2c_struct *i2c, uint8_t adr, uint32_t pre_cnt, uint8_t *pre_buf, uint32_t cnt, uint8_t *buf)
{
  i2c->adr = adr;
  i2c->is_send_stop = 1;
  i2c->pre_data_cnt = pre_cnt;
  i2c->pre_data_buf = pre_buf;
  i2c->data_cnt = cnt;
  i2c->data_buf = buf;
  
  i2c_clear_error(i2c);  
  i2c->state = I2C_STATE_MT_GENERATE_START;
  return i2c_do(i2c);
}
コード例 #4
0
/* ------------------------------------------------------------------------- */
uchar	usbFunctionSetup(uchar data[8])
{
  static uchar replyBuf[4];
  usbMsgPtr = replyBuf;
  DEBUGF("Setup %x %x %x %x\n", data[0], data[1], data[2], data[3]);

  switch(data[1]) {

  case CMD_ECHO: // echo (for transfer reliability testing)
    replyBuf[0] = data[2];
    replyBuf[1] = data[3];
    return 2;
    break;

  case CMD_GET_FUNC:
    memcpy_P(replyBuf, &func, sizeof(func));
    return sizeof(func);
    break;

  case CMD_SET_DELAY:
    /* The original device used a 12MHz clock: */
    /* --- */
    /* The delay function used delays 4 system ticks per cycle. */
    /* This gives 1/3us at 12Mhz per cycle. The delay function is */
    /* called twice per clock edge and thus four times per full cycle. */ 
    /* Thus it is called one time per edge with the full delay */ 
    /* value and one time with the half one. Resulting in */
    /* 2 * n * 1/3 + 2 * 1/2 n * 1/3 = n us. */
    /* --- */
    /* On littleWire-like devices, we run at 16.5MHz, so delay must be scaled up. */
    { 
      uint32_t delay = *(unsigned short*)(data+2);
      delay = (delay*1650UL + 600UL) / 1200UL;
      clock_delay = delay;
      if (clock_delay <= DELAY_OVERHEAD) {
	clock_delay = 1;
      } else {
	clock_delay = clock_delay - DELAY_OVERHEAD;
      }
      clock_delay2 = clock_delay/2;
      if(!clock_delay2) clock_delay2 = 1;
    }

    DEBUGF("request for delay %dus\n", clock_delay); 
    break;

  case CMD_I2C_IO:
  case CMD_I2C_IO + CMD_I2C_BEGIN:
  case CMD_I2C_IO                 + CMD_I2C_END:
  case CMD_I2C_IO + CMD_I2C_BEGIN + CMD_I2C_END:
    // these are only allowed as class transfers

    return i2c_do((struct i2c_cmd*)data);
    break;

  case CMD_GET_STATUS:
    replyBuf[0] = status;
    return 1;
    break;

  default:
    // must not happen ...
    break;
  }

  return 0;  // reply len

}
コード例 #5
0
uchar	usbFunctionSetup(uchar data[8]) {
  static uchar replyBuf[4];
  usbMsgPtr = replyBuf;
#else
extern	byte_t	usb_setup ( byte_t data[8] )
{
  byte_t *replyBuf = data;
#endif

  switch(data[1]) {

  case FUNC_GET_TYPE:
    replyBuf[0] = 6;
    return 1;
    break;
  case FUNC_START_BOOTLOADER:
    cli();
	wdt_enable(WDTO_15MS);
    while(1);
	break;
  case CMD_ECHO: // echo (for transfer reliability testing)
    replyBuf[0] = data[2];
    replyBuf[1] = data[3];
    return 2;
    break;

  case CMD_GET_FUNC:
    memcpy_P(replyBuf, &func, sizeof(func));
    return sizeof(func);
    break;

  case CMD_SET_DELAY:
    /* The delay function used delays 4 system ticks per cycle. */
    /* This gives 1/3us at 12Mhz per cycle. The delay function is */
    /* called twice per clock edge and thus four times per full cycle. */ 
    /* Thus it is called one time per edge with the full delay */ 
    /* value and one time with the half one. Resulting in */
    /* 2 * n * 1/3 + 2 * 1/2 n * 1/3 = n us. */
    clock_delay = *(unsigned short*)(data+2);
    if(!clock_delay) clock_delay = 1;
    clock_delay2 = clock_delay/2;
    if(!clock_delay2) clock_delay2 = 1;

    break;

  case CMD_I2C_IO:
  case CMD_I2C_IO + CMD_I2C_BEGIN:
  case CMD_I2C_IO                 + CMD_I2C_END:
  case CMD_I2C_IO + CMD_I2C_BEGIN + CMD_I2C_END:
    // these are only allowed as class transfers

    leds[LED_RED].counter = 10; 
    leds[LED_RED].frequency = LED_FLASH;
    return i2c_do((struct i2c_cmd*)data);
    break;

  case CMD_GET_STATUS:
    replyBuf[0] = status;
    return 1;
    break;

  default:
    // must not happen ...
    break;
  }

  leds[LED_BLUE].counter = 10; 
  leds[LED_BLUE].frequency = LED_FLASH_NEG;
  return 0;  // reply len
}