error_t lm75bConfigWrite (uint8_t configValue)
{
  if (!_lm75bInitialised)
  {
    ASSERT_STATUS(lm75bInit());
  }

  ASSERT_STATUS(lm75bWrite8(LM75B_REGISTER_CONFIGURATION, configValue));

  return ERROR_NONE;
}
error_t lm75bGetTemperature (int32_t *temp)
{
  if (!_lm75bInitialised)
  {
    ASSERT_STATUS(lm75bInit());
  }

  /* Turn device on */
  ASSERT_STATUS(lm75bConfigWrite (LM75B_CONFIG_SHUTDOWN_POWERON));

  /* Read temperature */
  ASSERT_STATUS(lm75bRead16 (LM75B_REGISTER_TEMPERATURE, temp));

  /* Shut device back down */
  ASSERT_STATUS(lm75bConfigWrite (LM75B_CONFIG_SHUTDOWN_SHUTDOWN));

  return ERROR_NONE;
}
Beispiel #3
0
void systemInit()
{
  cpuInit();
  systickInit((CFG_CPU_CCLK / 1000) * CFG_SYSTICK_DELAY_IN_MS);
  gpioInit();
  pmuInit();
  adcInit();    // Init adc pins to avoid wasting 60uA in deep sleep

  #ifdef CFG_PRINTF_UART
    // Initialise UART with the default baud rate (set in projectconfig.h)
    uartInit(CFG_UART_BAUDRATE);
  #endif

  // Switch to 3.3V if TPS780 (etc.) is being used
  #if defined CFG_VREG_ALT_PRESENT && CFG_VREG_ALT_PRESENT == 1
    gpioSetDir(CFG_VREG_ALT_PORT, CFG_VREG_ALT_PIN, gpioDirection_Output);
    gpioSetValue(CFG_VREG_ALT_PORT, CFG_VREG_ALT_PIN, 0);
    gpioSetPullup(&CFG_VREG_ALT_REG32, gpioPullupMode_Inactive);
  #endif

  // Set LED pin as output and turn LED off
  gpioSetDir(CFG_LED_PORT, CFG_LED_PIN, 1);
  gpioSetValue(CFG_LED_PORT, CFG_LED_PIN, CFG_LED_OFF);

  // Initialise the ST7565 128x64 pixel display
  #ifdef CFG_ST7565
    st7565Init();
    st7565ClearScreen();    // Clear the screen  
    st7565Backlight(1);     // Enable the backlight
  #endif

  // Initialise the SSD1306 OLED display
  #ifdef CFG_SSD1306
    ssd1306Init(SSD1306_SWITCHCAPVCC);
    ssd1306ClearScreen();   // Clear the screen  
  #endif

  // Initialise EEPROM
  #ifdef CFG_I2CEEPROM
    mcp24aaInit();
  #endif

  // Initialise Chibi
  #ifdef CFG_CHIBI
    // Write addresses to EEPROM for the first time if necessary
    // uint16_t addr_short = 0x1166;
    // uint64_t addr_ieee =  addr_short;
    // mcp24aaWriteBuffer(CFG_CHIBI_EEPROM_SHORTADDR, (uint8_t *)&addr_short, 2);
    // mcp24aaWriteBuffer(CFG_CHIBI_EEPROM_IEEEADDR, (uint8_t *)&addr_ieee, 8);
    chb_init();
  #endif

  // Setup SD Card
  #ifdef CFG_SDCARD
    // Turn off SD card by default (saves power)
    gpioSetDir(CFG_SDCARD_ENPORT, CFG_SDCARD_ENPIN, gpioDirection_Output); /* Set enable pin to output */
    gpioSetValue(CFG_SDCARD_ENPORT, CFG_SDCARD_ENPIN, 0);                  /* Disable card by setting ENPIN low */
    gpioSetPullup(&CFG_SDCARD_ENREG32, gpioPullupMode_Inactive);
  #endif

  #ifdef CFG_LM75B
    // Initialise LM75B
    lm75bInit();
    // Read temp once to make sure we are in sleep mode
    int32_t temp;
    lm75bGetTemperature(&temp);
  #endif

  #ifdef CFG_BAT
    // Turn off battery voltage divider by default
    gpioSetDir(CFG_BAT_ENPORT, CFG_BAT_ENPIN, gpioDirection_Output );   // Set voltage divider enable pin to output
    gpioSetValue(CFG_BAT_ENPORT, CFG_BAT_ENPIN, 0 );                    // Disable the voltage divider by default
    gpioSetPullup(&CFG_BAT_ENREG32, gpioPullupMode_Inactive);
  #endif

  // Start the command line interface (if requested)
  #ifdef CFG_INTERFACE
    printf("%sType '?' for a list of available commands%s", CFG_PRINTF_NEWLINE, CFG_PRINTF_NEWLINE);
    cmdInit();
  #endif
}