void Adafruit_MCP23008::pullUp(uint8_t p, uint8_t d) {
  uint8_t gppu;
  
  // only 8 bits!
  if (p > 7)
    return;

  gppu = read8(MCP23008_GPPU);
  // set the pin and direction
  if (d == HIGH) {
    gppu |= 1 << p; 
  } else {
    gppu &= ~(1 << p);
  }
  // write the new GPIO
  write8(MCP23008_GPPU, gppu);
}
static int nor_write(const struct spi_flash *flash, u32 addr, size_t len,
		const void *buf)
{
	const u8 *buffer = (const u8 *)buf;

	set_sfpaddr(addr);
	while (len) {
		write8(&mt8173_nor->wdata, *buffer);
		if (mt8173_nor_execute_cmd(SFLASH_WR_TRIGGER | SFLASH_AUTOINC))
			return -1;

		if (wait_for_write_done())
			return -1;
		buffer++;
		len--;
	}
	return 0;
}
Beispiel #3
0
bool Adafruit_LSM303_Accel_Unified::begin()
{
  // Enable I2C
  Wire.begin();

  // Enable the accelerometer (100Hz)
  write8(LSM303_ADDRESS_ACCEL, LSM303_REGISTER_ACCEL_CTRL_REG1_A, 0x57);
  
  // LSM303DLHC has no WHOAMI register so read CTRL_REG1_A back to check
  // if we are connected or not
  uint8_t reg1_a = read8(LSM303_ADDRESS_ACCEL, LSM303_REGISTER_ACCEL_CTRL_REG1_A);
  if (reg1_a != 0x57)
  {
    return false;
  }  
  
  return true;
}
// allow sensor to be initialised with a specific I2c address
boolean Adafruit_SI1145::begin( uint8_t addr ) {
  boolean begun;

  Wire.begin();

  if ( !_reset ) reset();
  _reset = true;

  writeParam( 0x00, addr );
  write8( SI1145_REG_COMMAND, SI1145_BUSADDR );
  _addr = addr;

  begun = begin();

  _reset = false;

  return begun;
}
Beispiel #5
0
int proc_set_write_reg(struct file *file, const char *buffer,
		unsigned long count, void *data)
{
	struct net_device *dev = (struct net_device *)data;
	_adapter *padapter = (_adapter *)netdev_priv(dev);
	char tmp[32];
	u32 addr, val, len;

	if (count < 3)
	{
		printk("argument size is less than 3\n");
		return -EFAULT;
	}	

	if (buffer && !copy_from_user(tmp, buffer, sizeof(tmp))) {		

		int num = sscanf(tmp, "%x %x %x", &addr, &val, &len);

		if (num !=  3) {
			printk("invalid write_reg parameter!\n");
			return count;
		}

		switch(len)
		{
			case 1:
				write8(padapter, addr, (u8)val);				
				break;
			case 2:
				write16(padapter, addr, (u16)val);				
				break;
			case 4:
				write32(padapter, addr, val);				
				break;
			default:
				printk("error write length=%d", len);
				break;
		}			
		
	}
	
	return count;
	
}
Beispiel #6
0
void APDS9930::init(uint8_t _APDS9930_PDRIVE, uint8_t _APDS9930_PGAIN, uint8_t _APDS9930_AGAIN)
{
  write8(0, 0); //Disable and powerdown
  
  write8(1, APDS9930_ATIME);
  write8(2, APDS9930_PTIME);
  write8(3, APDS9930_WTIME);
  write8(0x0e, APDS9930_PPULSE);

  write8(0x0f, 0xff & ( (_APDS9930_PDRIVE << 6) | (APDS9930_PDIODE << 4) | (_APDS9930_PGAIN << 2) | (_APDS9930_AGAIN)));

  power(PON);
}
Beispiel #7
0
static void rangeley_setup_bars(void)
{
	/* Setting up Southbridge. */
	printk(BIOS_DEBUG, "Setting up static southbridge registers...");
	pci_write_config32(LPC_BDF, RCBA, (uintptr_t)DEFAULT_RCBA | RCBA_ENABLE);
	pci_write_config32(LPC_BDF, ABASE, DEFAULT_ABASE | SET_BAR_ENABLE);
	pci_write_config32(LPC_BDF, PBASE, DEFAULT_PBASE | SET_BAR_ENABLE);
	printk(BIOS_DEBUG, " done.\n");

	printk(BIOS_DEBUG, "Disabling Watchdog timer...");
	/* Disable the watchdog reboot and turn off the watchdog timer */
	write8((void *)(DEFAULT_PBASE + PMC_CFG),
	       read8((void *)(DEFAULT_PBASE + PMC_CFG)) | NO_REBOOT);	// disable reboot on timer trigger
	outw(DEFAULT_ABASE + TCO1_CNT, inw(DEFAULT_ABASE + TCO1_CNT) |
		TCO_TMR_HALT);	// disable watchdog timer

	printk(BIOS_DEBUG, " done.\n");

}
void Adafruit_MCP23008::pinMode(uint8_t p, uint8_t d) {
  uint8_t iodir;

  // only 8 bits!
  if (p > 7)
    return;

  iodir = read8(MCP23008_IODIR);

  // set the pin and direction
  if (d == INPUT) {
    iodir |= 1 << p;
  } else {
    iodir &= ~(1 << p);
  }

  // write the new IODIR
  write8(MCP23008_IODIR, iodir);
}
Beispiel #9
0
/*
 * Clock_exit
 *
 * Clean up before the application exits
 *
 * SIDE EFFECTS:
 *     Stop Timer 0 counting, set timer 0 interrupt priority level to 0.
 */
void
Clock_exit(void)
{
  uint8_t   temp8 = 0;
  uint16_t   temp16 = 0;

  /* turn off the timer interrupts */
  /* Stop the Timer 0 */
  temp8 = read8(SH7750_TSTR);
  temp8 &= ~SH7750_TSTR_STR0;
  write8(temp8, SH7750_TSTR);

  /* Lower timer interrupt priority to 0 */
  temp16 = read16(SH7750_IPRA);
  temp16 = (temp16 & ~SH7750_IPRA_TMU0) | (0 << SH7750_IPRA_TMU0_S);
  write16(temp16, SH7750_IPRA);

  /* old vector shall not be installed */
}
void Hybotics_LSM303DLHC_Mag_Unified::setMagGain(lsm303MagGain gain) {
  write8(LSM303_ADDRESS_MAG, LSM303_REGISTER_MAG_CRB_REG_M, (byte)gain);

  _magGain = gain;

  switch(gain) {
    case LSM303_MAGGAIN_1_3:
      _lsm303Mag_Gauss_LSB_XY = 1100;
      _lsm303Mag_Gauss_LSB_Z  = 980;
      break;

    case LSM303_MAGGAIN_1_9:
      _lsm303Mag_Gauss_LSB_XY = 855;
      _lsm303Mag_Gauss_LSB_Z  = 760;
      break;

    case LSM303_MAGGAIN_2_5:
      _lsm303Mag_Gauss_LSB_XY = 670;
      _lsm303Mag_Gauss_LSB_Z  = 600;
      break;

    case LSM303_MAGGAIN_4_0:
      _lsm303Mag_Gauss_LSB_XY = 450;
      _lsm303Mag_Gauss_LSB_Z  = 400;
      break;

    case LSM303_MAGGAIN_4_7:
      _lsm303Mag_Gauss_LSB_XY = 400;
      _lsm303Mag_Gauss_LSB_Z  = 255;
      break;

    case LSM303_MAGGAIN_5_6:
      _lsm303Mag_Gauss_LSB_XY = 330;
      _lsm303Mag_Gauss_LSB_Z  = 295;
      break;

    case LSM303_MAGGAIN_8_1:
      _lsm303Mag_Gauss_LSB_XY = 230;
      _lsm303Mag_Gauss_LSB_Z  = 205;
      break;
  }
}
Beispiel #11
0
/**
 * Init Servo system
 */
void Servo_init() {
	write8(PCA9685_MODE1, 0x0);

	// compute the prescale value
	uint8_t prescale = floor(PRESCALE_VALUE + 0.5);

	uint8_t oldmode = read8(PCA9685_MODE1);
	uint8_t newmode = (oldmode & 0x7F) | 0x10; // sleep
	write8(PCA9685_MODE1, newmode); // go to sleep
	write8(PCA9685_PRESCALE, prescale); // set the prescaler
	write8(PCA9685_MODE1, oldmode);
	// Delay for 5 milliseconds
	timer_sleep(TIMER_FREQUENCY_HZ / 1000 * 5);
	//delay(5);
	write8(PCA9685_MODE1, oldmode | 0xa1);
	write8(ALLLED_ON_L, 0);
	write8(ALLLED_ON_H, 0);
}
Beispiel #12
0
/*
 *  Clean up before the application exits
 */
void Clock_exit( void )
{
  uint8_t   temp8 = 0;

  /* turn off the timer interrupts */
  /* set interrupt priority to 0 */
  if( sh_set_irq_priority( CLOCK_VECTOR, 0 ) != RTEMS_SUCCESSFUL)
    rtems_fatal_error_occurred( RTEMS_UNSATISFIED);

/*
 *   temp16 = read16( ITU_TIER0) & IPRC_ITU0_IRQMASK;
 *   write16( temp16, ITU_TIER0);
 */

  /* stop counter */
  temp8 = read8( ITU_TSTR) & ITU0_STARTMASK;
  write8( temp8, ITU_TSTR);

  /* old vector shall not be installed */
}
int main(void)
{
	I2C_Initialize(I2C2,I2C_Ack_Enable,I2C_AcknowledgedAddress_7bit, 100000, I2C_DutyCycle_2, I2C_Mode_I2C, 0x00);

	setup(I2C2);

	write8(I2C2,0x20,0x0F);

	unsigned short temp = 0;
	while(1)
	{
		temp = read8(I2C2);
		if(recieve[i-1] != temp){
			recieve[i++] = temp;
			if(i == 1024){
				i = 0;
			}
		}
	}
}
Beispiel #14
0
void Adafruit_LSM9DS0::setupGyro ( lsm9ds0GyroScale_t scale )
{
  uint8_t reg = read8(GYROTYPE, LSM9DS0_REGISTER_CTRL_REG4_G);
  reg &= ~(0b00110000);
  reg |= scale;
  write8(GYROTYPE, LSM9DS0_REGISTER_CTRL_REG4_G, reg );

  switch(scale)
  {
    case LSM9DS0_GYROSCALE_245DPS:
      _gyro_dps_digit = LSM9DS0_GYRO_DPS_DIGIT_245DPS;
      break;
    case LSM9DS0_GYROSCALE_500DPS:
      _gyro_dps_digit = LSM9DS0_GYRO_DPS_DIGIT_500DPS;
      break;
    case LSM9DS0_GYROSCALE_2000DPS:
      _gyro_dps_digit = LSM9DS0_GYRO_DPS_DIGIT_2000DPS;
      break;
  }
}
Beispiel #15
0
static bool_t kmi_write(struct realview_keyboard_data_t * dat, u8_t data)
{
	s32_t timeout = 1000;

	while((read8(phys_to_virt(dat->regbase + KEYBOARD_STAT)) & KEYBOARD_STAT_TXEMPTY) == 0 && timeout--);

	if(timeout)
	{
		write8(phys_to_virt(dat->regbase + KEYBOARD_DATA), data);

		while((read8(phys_to_virt(dat->regbase + KEYBOARD_STAT)) & KEYBOARD_STAT_RXFULL) == 0);

		if( read8(phys_to_virt(dat->regbase + KEYBOARD_DATA)) == 0xfa)
			return TRUE;
		else
			return FALSE;
	}

	return FALSE;
}
Beispiel #16
0
uint32_t baro_get_pressure(void)
{

	  uint32_t pressure;

	  write8(MPL3115A2_CTRL_REG1,
		 MPL3115A2_CTRL_REG1_SBYB |
		 MPL3115A2_CTRL_REG1_OS128 |
		 MPL3115A2_CTRL_REG1_BAR);

	  uint8_t sta = 0;
	  while (! (sta & MPL3115A2_REGISTER_STATUS_PDR)) {
	    sta = read8(MPL3115A2_REGISTER_STATUS);
	    cph_millis_delay(125);
	  }




//	  Wire.beginTransmission(MPL3115A2_ADDRESS); // start transmission to device
//	  Wire.write(MPL3115A2_REGISTER_PRESSURE_MSB);
//	  Wire.endTransmission(false); // end transmission

	  bool status = writeBit(MPL3115A2_ADDRESS, MPL3115A2_REGISTER_PRESSURE_MSB, MPL3115A2_OUT_P_DELTA_MSB, true);

//	  Wire.requestFrom((uint8_t)MPL3115A2_ADDRESS, (uint8_t)3);// send data n-bytes read
//	  pressure = Wire.read(); // receive DATA
//	  pressure <<= 8;
//	  pressure |= Wire.read(); // receive DATA
//	  pressure <<= 8;
//	  pressure |= Wire.read(); // receive DATA
//	  pressure >>= 4;

	  readBits(MPL3115A2_ADDRESS, 0x01, 0x00, 3, baro_buffer, I2CDEV_DEFAULT_READ_TIMEOUT);

	  pressure = (((int32_t)baro_buffer[0]) << 8) | (((int32_t)baro_buffer[1]) << 8) | (((int32_t)baro_buffer[2]) << 4);

	  float baro = pressure;
	  baro /= 4.0;
	  return baro;
}
Beispiel #17
0
/**
 * Sendet zum Sensor ein Befehl zum Auswahl von HardwareMode.
 */
bool AS_BH1750::selectResolutionMode(uint8_t mode) {
#if BH1750_DEBUG == 1
    Serial.print("selectResolutionMode: ");
    Serial.println(mode, DEC);
#endif
  if(!isInitialized()) {
    return false;
#if BH1750_DEBUG == 1
    Serial.println("sensor not initialized");
#endif
  }

  _hardwareMode=mode;
  _valueReaded=false;

  // Prüfen, ob ein valides Modus vorliegt und im positiven Fall das gewünschte Modus aktivieren
  switch (mode) {
  case BH1750_CONTINUOUS_HIGH_RES_MODE:
  case BH1750_CONTINUOUS_HIGH_RES_MODE_2:
  case BH1750_CONTINUOUS_LOW_RES_MODE:
  case BH1750_ONE_TIME_HIGH_RES_MODE:
  case BH1750_ONE_TIME_HIGH_RES_MODE_2:
  case BH1750_ONE_TIME_LOW_RES_MODE:
    // Modus aktivieren
    if(write8(mode)) {
    // Kurze pause nötig, sonst wird das Modus nicht sicher Aktiviert
    // (z.B. liefert Sensor im AutoHigh Modus abwechselnd übersteuerte Werte, etwa so: 54612.5, 68123.4, 54612.5, 69345.3,..)
    delay(5);
      return true;
    }
    break;
  default:
    // Invalid measurement mode
#if BH1750_DEBUG == 1
    Serial.println("Invalid measurement mode");
#endif
    break;
  }

  return false;
}
Beispiel #18
0
void WritePCXHeader(FILE *f, int w, int h, int np)
{
	int i;
	write8(f, 10); write8(f, 5); write8(f, 1); write8(f, 8);
	write32(f, 0);
	write16(f, w-1); write16(f, h-1);
	write16(f, w); write16(f, h);
	for(i = 0; i < 12; i++) write32(f, 0);
	write8(f, 0);
	write8(f, np);
	write16(f, w + (w&1));
	write16(f, 1);
	write16(f, 0);
	for(i = 0; i < 14; i++) write32(f, 0);
}
Beispiel #19
0
void assembler_t::emit(instruction_e ins) {
    switch (ins) {
    case(INS_ADD) :
    case(INS_SUB) :
    case(INS_MUL) :
    case(INS_DIV) :
    case(INS_MOD) :
    case(INS_AND) :
    case(INS_OR)  :
    case(INS_NOT) :
    case(INS_LT)  :
    case(INS_GT)  :
    case(INS_LEQ) :
    case(INS_GEQ) :
    case(INS_EQ)  :
    case(INS_NOP) : write8(ins);
                    break;
    default:
        throws("unknown instruction");
    }
}
void rma1_wdt_init(void)
{
	u32 usecs = 1000 * 1000; /* 1s */
	u32 count;
	u8 tstr;

	if (callback_rebooted_by_watchdog && (read8(RWTCSRA0) & 0x10))
		callback_rebooted_by_watchdog();

	request_irq(199 + 32, rma1_wdt_ping, NULL);

	/* initializing timer */
	/*** SUB = 50MHz, TCNT_CLK = 12.5MHz */
	count = (12 * usecs) + (usecs / 2) + (usecs & 1);

	write16(TMU(0, TCR01), 0x20);
	write32(TMU(0, TCOR01), count);
	write32(TMU(0, TCNT01), count);
	tstr = read8(TMU(0,TSTR));
	write8(TMU(0, TSTR), tstr | 0x2);
}
Beispiel #21
0
bool Adafruit_LSM303_Mag_Unified::begin()
{
  // Enable I2C
  Wire.begin();
  
  // Enable the magnetometer
  write8(LSM303_ADDRESS_MAG, LSM303_REGISTER_MAG_MR_REG_M, 0x00);

  // LSM303DLHC has no WHOAMI register so read CRA_REG_M to check
  // the default value (0b00010000/0x10)
  uint8_t reg1_a = read8(LSM303_ADDRESS_MAG, LSM303_REGISTER_MAG_CRA_REG_M);
  if (reg1_a != 0x10)
  {
    return false;
  }

  // Set the gain to a known level
  setMagGain(LSM303_MAGGAIN_1_3);

  return true;
}
Beispiel #22
0
void BH1750::configure(uint8_t mode) {

    switch (mode) {
        case BH1750_CONTINUOUS_HIGH_RES_MODE:
        case BH1750_CONTINUOUS_HIGH_RES_MODE_2:
        case BH1750_CONTINUOUS_LOW_RES_MODE:
        case BH1750_ONE_TIME_HIGH_RES_MODE:
        case BH1750_ONE_TIME_HIGH_RES_MODE_2:
        case BH1750_ONE_TIME_LOW_RES_MODE:
            // apply a valid mode change
            write8(mode);
            delay(10);
            break;
        default:
            // Invalid measurement mode
            #if BH1750_DEBUG == 1
            Serial.println("Invalid measurement mode");
            #endif
            break;
    }
}
Beispiel #23
0
void testNotSmallPageAligned64RW(result_t *result, char abort, char quiet){
	int fails = 0;
	int testNr = 0;
	for(testNr=0; testNr<(SMALL_PAGE_SIZE / 8); testNr++){
		write64(S_SANDBOXW + testNr * 8, testNr, 1);
		if(read8(S_SANDBOXR + testNr * 8, testNr, 0, 1)){
			fails++;
			write8(S_SANDBOXW + testNr * 8, testNr, quiet);
			read8(S_SANDBOXR + testNr * 8, testNr, abort, quiet);
		}
		if(fails >= 5){
			printString("Ending test prematurely due to too many failures\n", quiet);
			break;
		}
	}
	result_t localResult;
	localResult.nrFailed = fails;
	localResult.nrTests = testNr + 1;

	addResults(result, &localResult);
}
Beispiel #24
0
void RTC_last_power()
{
   rtc_last_sec   = RTC_Sec_Reg;
   rtc_last_min   = RTC_Min_Reg;
   rtc_last_hour  = RTC_Hr_Reg;
   rtc_last_day   = RTC_DOM_Reg;
   rtc_last_month = RTC_Mon_Reg;
   rtc_last_year  = RTC_Yr_Reg;
   
   write8(ADDR_LAST_MONTH, rtc_last_month);
   write8(ADDR_LAST_DAY, rtc_last_day);
   write8(ADDR_LAST_YEAR, rtc_last_year);
   write8(ADDR_LAST_HOUR, rtc_last_hour);
   write8(ADDR_LAST_MIN, rtc_last_min);
   write8(ADDR_LAST_SEC, rtc_last_sec);
}
Beispiel #25
0
/**
 * Probe for supported codecs
 */
int hda_codec_detect(u8 *base)
{
	u8 reg8;

	/* Set Bit 0 to 1 to exit reset state (BAR + 0x8)[0] */
	if (set_bits(base + HDA_GCTL_REG, HDA_GCTL_CRST, HDA_GCTL_CRST) < 0)
		goto no_codec;

	/* Write back the value once reset bit is set. */
	write16(base + HDA_GCAP_REG, read16(base + HDA_GCAP_REG));

	/* Clear the "State Change Status Register" STATESTS bits
	 * for each of the "SDIN Stat Change Status Flag"
	 */
	write8(base + HDA_STATESTS_REG, 0xf);

	/* Turn off the link and poll RESET# bit until it reads back as 0 */
	if (set_bits(base + HDA_GCTL_REG, HDA_GCTL_CRST, ~HDA_GCTL_CRST) < 0)
		goto no_codec;

	/* Turn on the link and poll RESET# bit until it reads back as 1 */
	if (set_bits(base + HDA_GCTL_REG, HDA_GCTL_CRST, HDA_GCTL_CRST) < 0)
		goto no_codec;

	/* Read in Codec location (BAR + 0xe)[2..0]*/
	reg8 = read8(base + HDA_STATESTS_REG);
	reg8 &= 0x0f;
	if (!reg8)
		goto no_codec;

	return reg8;

no_codec:
	/* Codec Not found */
	/* Put HDA back in reset (BAR + 0x8) [0] */
	set_bits(base + HDA_GCTL_REG, HDA_GCTL_CRST, 0);
	printk(BIOS_DEBUG, "HDA: No codec!\n");
	return 0;
}
Beispiel #26
0
void testNotLargePageAligned2MRW(result_t *result, char abort, char quiet){
	int fails = 0;
	int testNr = 0;

	for(testNr=0; testNr<(LARGE_PAGE_SIZE / MEDIUM_PAGE_SIZE); testNr++){
//		write64(L_SANDBOXW + testNr * MEDIUM_PAGE_SIZE, testNr, 1);
//		if(read8(L_SANDBOXR + testNr * MEDIUM_PAGE_SIZE, testNr, 0, 1)){
//			fails++;
			write8(L_SANDBOXW + testNr * MEDIUM_PAGE_SIZE, testNr, quiet);
			read8(L_SANDBOXR + testNr * MEDIUM_PAGE_SIZE, testNr, abort, quiet);
//		}
		if(fails >= 5){
			printString("Ending test prematurely due to too many failures\n", quiet);
			break;
		}
	}
	result_t localResult;
	localResult.nrFailed = fails;
	localResult.nrTests = testNr + 1;

	addResults(result, &localResult);
}
Beispiel #27
0
void configure_hudson_uart(void)
{
	u8 byte;

	byte = read8((void *)(ACPI_MMIO_BASE + AOAC_BASE + FCH_AOAC_REG56 +
				CONFIG_UART_FOR_CONSOLE * sizeof(u16)));
	byte |= 1 << 3;
	write8((void *)(ACPI_MMIO_BASE + AOAC_BASE + FCH_AOAC_REG56 +
			CONFIG_UART_FOR_CONSOLE * sizeof(u16)), byte);
	byte = read8((void *)(ACPI_MMIO_BASE + AOAC_BASE + FCH_AOAC_REG62));
	byte |= 1 << 3;
	write8((void *)(ACPI_MMIO_BASE + AOAC_BASE + FCH_AOAC_REG62), byte);
	write8((void *)FCH_IOMUXx89_UART0_RTS_L_EGPIO137, 0);
	write8((void *)FCH_IOMUXx8A_UART0_TXD_EGPIO138, 0);
	write8((void *)FCH_IOMUXx8E_UART1_RTS_L_EGPIO142, 0);
	write8((void *)FCH_IOMUXx8F_UART1_TXD_EGPIO143, 0);

	udelay(2000);
	write8((void *)(0xFEDC6000 + 0x2000 * CONFIG_UART_FOR_CONSOLE + 0x88),
			0x01); /* reset UART */
}
void Adafruit_HMC5883_Unified::setMagGain(hmc5883MagGain gain)
{
  write8(HMC5883_ADDRESS_MAG, HMC5883_REGISTER_MAG_CRB_REG_M, (byte)gain);
  
  _magGain = gain;
 
  switch(gain)
  {
    case HMC5883_MAGGAIN_1_3:
      _hmc5883_Gauss_LSB_XY = 1100;
      _hmc5883_Gauss_LSB_Z  = 980;
      break;
    case HMC5883_MAGGAIN_1_9:
      _hmc5883_Gauss_LSB_XY = 855;
      _hmc5883_Gauss_LSB_Z  = 760;
      break;
    case HMC5883_MAGGAIN_2_5:
      _hmc5883_Gauss_LSB_XY = 670;
      _hmc5883_Gauss_LSB_Z  = 600;
      break;
    case HMC5883_MAGGAIN_4_0:
      _hmc5883_Gauss_LSB_XY = 450;
      _hmc5883_Gauss_LSB_Z  = 400;
      break;
    case HMC5883_MAGGAIN_4_7:
      _hmc5883_Gauss_LSB_XY = 400;
      _hmc5883_Gauss_LSB_Z  = 255;
      break;
    case HMC5883_MAGGAIN_5_6:
      _hmc5883_Gauss_LSB_XY = 330;
      _hmc5883_Gauss_LSB_Z  = 295;
      break;
    case HMC5883_MAGGAIN_8_1:
      _hmc5883_Gauss_LSB_XY = 230;
      _hmc5883_Gauss_LSB_Z  = 205;
      break;
  } 
}
static int sector_erase(int offset)
{
	if (wait_for_write_done())
		return -1;

	write8(&mt8173_nor->prgdata[5], SFLASH_OP_WREN);
	write8(&mt8173_nor->cnt, 8);
	mt8173_nor_execute_cmd(SFLASH_PRG_CMD);

	write8(&mt8173_nor->prgdata[5], SECTOR_ERASE_CMD);
	write8(&mt8173_nor->prgdata[4], get_nth_byte(offset, 2));
	write8(&mt8173_nor->prgdata[3], get_nth_byte(offset, 1));
	write8(&mt8173_nor->prgdata[2], get_nth_byte(offset, 0));
	write8(&mt8173_nor->cnt, 32);
	mt8173_nor_execute_cmd(SFLASH_PRG_CMD);

	if (wait_for_write_done())
		return -1;

	return 0;
}
Beispiel #30
0
void Adafruit_LSM303_Mag::setMagGain(lsm303MagGain gain)
{
  write8(_i2cAddress, LSM303_REGISTER_MAG_CRB_REG_M, (byte)gain);
  
  _magGain = gain;
 
  switch(gain)
  {
    case LSM303_MAGGAIN_1_3:
      _lsm303Mag_Gauss_LSB_XY = 1100;
      _lsm303Mag_Gauss_LSB_Z  = 980;
      break;
    case LSM303_MAGGAIN_1_9:
      _lsm303Mag_Gauss_LSB_XY = 855;
      _lsm303Mag_Gauss_LSB_Z  = 760;
      break;
    case LSM303_MAGGAIN_2_5:
      _lsm303Mag_Gauss_LSB_XY = 670;
      _lsm303Mag_Gauss_LSB_Z  = 600;
      break;
    case LSM303_MAGGAIN_4_0:
      _lsm303Mag_Gauss_LSB_XY = 450;
      _lsm303Mag_Gauss_LSB_Z  = 400;
      break;
    case LSM303_MAGGAIN_4_7:
      _lsm303Mag_Gauss_LSB_XY = 400;
      _lsm303Mag_Gauss_LSB_Z  = 255;
      break;
    case LSM303_MAGGAIN_5_6:
      _lsm303Mag_Gauss_LSB_XY = 330;
      _lsm303Mag_Gauss_LSB_Z  = 295;
      break;
    case LSM303_MAGGAIN_8_1:
      _lsm303Mag_Gauss_LSB_XY = 230;
      _lsm303Mag_Gauss_LSB_Z  = 205;
      break;
  } 
}