Ejemplo n.º 1
0
void jshInit() {
  jshInitDevices();
  nrf_utils_lfclk_config_and_start();

  BITFIELD_CLEAR(jshPinSoftPWM);
    
  JshUSARTInfo inf;
  jshUSARTInitInfo(&inf);
  inf.pinRX = DEFAULT_CONSOLE_RX_PIN;
  inf.pinTX = DEFAULT_CONSOLE_TX_PIN;
  inf.baudRate = DEFAULT_CONSOLE_BAUDRATE;
  jshUSARTSetup(EV_SERIAL1, &inf); // Initialize UART for communication with Espruino/terminal.
  init = 1;

  // Enable and sort out the timer
  nrf_timer_mode_set(NRF_TIMER1,NRF_TIMER_MODE_TIMER);
  nrf_timer_bit_width_set(NRF_TIMER1, NRF_TIMER_BIT_WIDTH_32);
  nrf_timer_frequency_set(NRF_TIMER1, NRF_TIMER_FREQ_1MHz); // hmm = only a few options here

  // Irq setup
  NVIC_SetPriority(TIMER1_IRQn, 3); // low - don't mess with BLE :)
  NVIC_ClearPendingIRQ(TIMER1_IRQn);
  NVIC_EnableIRQ(TIMER1_IRQn);
  nrf_timer_int_enable(NRF_TIMER1, NRF_TIMER_INT_COMPARE0_MASK );

  // Pin change
  nrf_drv_gpiote_init();
  jswrap_nrf_bluetooth_init();
}
Ejemplo n.º 2
0
void jshInit() 
{
  jshInitDevices();
  nrf_utils_lfclk_config_and_start(); // Configure and start the external crystal used by RTC.
  nrf_utils_rtc1_config_and_start(); // Configure and start RTC1 used for the system time.
    
  JshUSARTInfo inf; // Just for show, not actually used...
  jshUSARTSetup(EV_SERIAL1, &inf); // Initialize UART. jshUSARTSetup() gets called each time a UART needs initializing (and is passed baude rate etc...).
  init = 1;
}
Ejemplo n.º 3
0
// ----------------------------------------------------------------------------
// for non-blocking IO
void jshInit() {
  jshInitDevices();
  systemTimeWasHigh = false;
  systemTimeHigh = 0;
  systemTime.start();
  int i;
  for (i=0;i<MBED_PINS;i++) {
     gpio_init(&mbedPins[i], (PinName)(P0_0+i), PIN_INPUT);
  }
  for (i=0;i<USARTS;i++) {
    serial_init(&mbedSerial[i], USBTX, USBRX); // FIXME Pin
    serial_irq_handler(&mbedSerial[i], &mbedSerialIRQ, i);
    // serial_irq_set(&mbedSerial[i], RxIrq, 1); // FIXME Rx IRQ just crashes when called
  }
}
Ejemplo n.º 4
0
void jshInit() {

#ifdef USE_WIRINGPI
  if (geteuid() == 0) {
    printf("RUNNING AS SUDO - awesome. You'll get proper IRQ support\n");
    wiringPiSetup();
  } else {
    printf("NOT RUNNING AS SUDO - sorry, you'll get rubbish realtime IO. You also need to export the pins you want to use first.\n");
    wiringPiSetupSys() ;
  }
#endif

  int i;
  for (i=0;i<=EV_DEVICE_MAX;i++)
    ioDevices[i] = 0;

  jshInitDevices();
#ifndef __MINGW32__
  if (!terminal_set) {
    struct termios new_termios;

    /* take two copies - one for now, one for later */
    tcgetattr(0, &orig_termios);
    memcpy(&new_termios, &orig_termios, sizeof(new_termios));

    /* register cleanup handler, and set the new terminal mode */
    atexit(reset_terminal_mode);
    cfmakeraw(&new_termios);
    tcsetattr(0, TCSANOW, &new_termios);
    terminal_set = 1;
  }
#endif//!__MINGW32__
  for (i=0;i<JSH_PIN_COUNT;i++) {
    gpioState[i] = JSHPINSTATE_UNDEFINED;
    gpioEventFlags[i] = 0;
  }
#ifdef SYSFS_GPIO_DIR
  for (i=0;i<JSH_PIN_COUNT;i++) {
    gpioShouldWatch[i] = false;    
  }
#endif

  isInitialised = true;
  int err = pthread_create(&inputThread, NULL, &jshInputThread, NULL);
  if (err != 0)
      printf("Unable to create input thread, %s", strerror(err));
}
Ejemplo n.º 5
0
void jshInit() {
  jshInitDevices();
  nrf_utils_lfclk_config_and_start();
    
  JshUSARTInfo inf; // Just for show, not actually used...
  jshUSARTSetup(EV_SERIAL1, &inf); // Initialize UART for communication with Espruino/terminal.
  init = 1;

  // Enable and sort out the timer
  nrf_timer_mode_set(NRF_TIMER1,NRF_TIMER_MODE_TIMER);
  nrf_timer_bit_width_set(NRF_TIMER1, NRF_TIMER_BIT_WIDTH_32);
  nrf_timer_frequency_set(NRF_TIMER1, NRF_TIMER_FREQ_1MHz); // hmm = only a few options here
  // Irq setup
  NVIC_SetPriority(TIMER1_IRQn, 15); // low - don't mess with BLE :)
  NVIC_ClearPendingIRQ(TIMER1_IRQn);
  NVIC_EnableIRQ(TIMER1_IRQn);
  nrf_timer_int_enable(NRF_TIMER1, NRF_TIMER_INT_COMPARE0_MASK );

  jswrap_nrf_bluetooth_init();
}
Ejemplo n.º 6
0
/**
 * Initialize the ESP8266 hardware environment.
 *
 * TODO: we should move stuff from user_main.c here
 */
void jshInit() {
  // A call to jshInitDevices is architected as something we have to do.
  os_printf("> jshInit\n");

  // Initialize the ESP8266 GPIO subsystem.
  gpio_init();

  systemTimeInit();
  utilTimerInit();
  jshInitDevices();

  // sanity check for pin function enum to catch ordering changes
  if (JSHPINSTATE_I2C != 12 || JSHPINSTATE_GPIO_IN_PULLDOWN != 5 || JSHPINSTATE_MASK != 15) {
    jsError("JshPinState #defines have changed, please update pinStateToString()");
  }

  // Register a callback function to be called for a GPIO interrupt
  gpio_intr_handler_register(intrHandlerCB, NULL);

  ETS_GPIO_INTR_ENABLE();
  os_printf("< jshInit\n");
} // End of jshInit
Ejemplo n.º 7
0
/**
 * Initialize the ESP8266 hardware environment.
 *
 * TODO: we should move stuff from user_main.c here
 */
void jshInit() {
  // A call to jshInitDevices is architected as something we have to do.
  os_printf("> jshInit\n");

  // Initialize the ESP8266 GPIO subsystem.
  gpio_init();

  systemTimeInit();
  utilTimerInit();
  jshInitDevices();

  // sanity check for pin function enum to catch ordering changes
  if (JSHPINSTATE_I2C != 12 || JSHPINSTATE_GPIO_IN_PULLDOWN != 5 || JSHPINSTATE_MASK != 15) {
    jsError("JshPinState #defines have changed, please update pinStateToString()");
  }

  // Register a callback function to be called for a GPIO interrupt
  gpio_intr_handler_register(intrHandlerCB, NULL);

  ETS_GPIO_INTR_ENABLE();

#ifndef HARDWARE_PWM
  BITFIELD_CLEAR(jshPinSoftPWM);
#endif

  // Initialize something for each of the possible pins.
  for (int i=0; i<JSH_PIN_COUNT; i++) {
#ifdef HARDWARE_PWM
    // For each of the PWM records, flag the PWM as having been not initialized.
    g_PWMRecords[i].enabled = false;
#endif
    g_pinState[i] = 0;
  }

  os_printf("< jshInit\n");
} // End of jshInit
Ejemplo n.º 8
0
/**
 * Initialize the ESP8266 hardware environment.
 */
void jshInit() {
	// A call to jshInitDevices is architected as something we have to do.
	jshInitDevices();
} // End of jshInit
Ejemplo n.º 9
0
// ----------------------------------------------------------------------------
void jshInit() {
  jshInitDevices();
  Serial.begin(DEFAULT_BAUD_RATE);
}
Ejemplo n.º 10
0
/**
 * Initialize the ESP8266 hardware environment.
 *
 * TODO: we should move stuff from user_main.c here
 */
void jshInit() {
	// A call to jshInitDevices is architected as something we have to do.
	systemTimeInit();
	utilTimerInit();
	jshInitDevices();
} // End of jshInit