示例#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();
}
示例#2
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