Beispiel #1
0
static int init(t_hydra_console *con, t_tokenline_parsed *p)
{
	mode_config_proto_t* proto = &con->mode->proto;
	int tokens_used = 0;

	proto->dev_function = NFC_TYPEA;

	if(init_gpio(con) ==  FALSE) {
		deinit_gpio();
		return tokens_used;
	}

	if(key_sniff_thread != NULL) {
		chThdTerminate(key_sniff_thread);
		chThdWait(key_sniff_thread);
		key_sniff_thread = NULL;
	}

	key_sniff_thread = chThdCreateStatic(key_sniff_mem,
					     sizeof(key_sniff_mem), HIGHPRIO, key_sniff, NULL);

	/* Process cmdline arguments, skipping "nfc". */
	if(p != NULL) {
		tokens_used = 1 + exec(con, p, 1);
	}

	return tokens_used;
}
Beispiel #2
0
/** \brief Check if HydraNFC is detected
 *
 * \return bool: return TRUE if success or FALSE if failure
 *
 */
bool hydranfc_is_detected(void)
{
	if(init_gpio(NULL) ==  FALSE) {
		deinit_gpio();
		return FALSE;
	}
	return TRUE;
}
Beispiel #3
0
/** \brief Init HydraNFC functions
 *
 * \param con t_hydra_console*: hydra console (optional can be NULL if unused)
 * \return bool: return TRUE if success or FALSE if failure
 *
 */
bool hydranfc_init(t_hydra_console *con)
{
	if(init_gpio(con) ==  FALSE) {
		deinit_gpio();
		return FALSE;
	}

	init(con, NULL);

	return TRUE;
}
Beispiel #4
0
/** \brief DeInit/Cleanup HydraNFC functions
 *
 * \param con t_hydra_console*: hydra console (optional can be NULL if unused)
 * \return void
 *
 */
void hydranfc_cleanup(t_hydra_console *con)
{
	(void)con;

	if(key_sniff_thread != NULL) {
		chThdTerminate(key_sniff_thread);
		chThdWait(key_sniff_thread);
		key_sniff_thread = NULL;
	}

	bsp_spi_deinit(BSP_DEV_SPI2);
	extStop(&EXTD1);

	/* deinit GPIO config (reinit using hydrabus_init() */
	deinit_gpio();
}
// This method translates 2 wires (a tx and rx line) to 1 wire, by letting the
// RX line control when data should be read or written from the single line
void usb1WirePassthrough(int8_t escIndex)
{
  // Reset all GPIO
  deinit_gpio(escIndex);
  // Take control of the LEDs
  ledInitDebug();
  //delay(1000);
  disable_hardware_uart();
  init_all_gpio(escIndex);
  // reset all the pins, 1wire goes into input mode, pullup on
  reset_all_gpio(escIndex);

  // set the programmer high
  txSet(Bit_SET);

  // Wait for programmer to go from 1 -> 0 indicating incoming data
  while(rxHi());
  while(1) {
    // A new iteration on this loop starts when we have data from the programmer (read_programmer goes low)
    // Setup escIndex pin to send data, pullup is the default
    gpio_set_mode_escs(escIndex, Mode_Out_PP);
    // Write the first bit
    escSet(escIndex, Bit_RESET);
    // Echo on the programmer tx line
    txSet(Bit_RESET);

    // Wait for programmer to go 0 -> 1
    while(!rxHi());

    // Programmer is high, end of bit
    // Echo to the esc
    escSet(escIndex, Bit_SET);
    // Listen to the escIndex, input mode, pullup resistor is on
    gpio_set_mode_escs(escIndex, Mode_IPU);

    // Listen to the escIndex while there is no data from the programmer
    while (rxHi()) {
      if (escHi(escIndex)) {
        txSet(Bit_SET);
      }
      else {
        txSet(Bit_RESET);
      }
    }
  }
}