示例#1
0
//begin public methods
void MMA845XQ::begin(bool highres, uint8_t scale)
{
  _highres = highres;
  
  _scale = scale;
  _step_factor = (_highres ? 0.0039 : 0.0156); // Base value at 2g setting
  if( _scale == 4 )
    _step_factor *= 2;
  else if (_scale == 8)
    _step_factor *= 4;
  uint8_t wai = _read_register(0x0D); // Get Who Am I from the device.
  // return value for MMA8543Q is 0x3A
  
  Wire.beginTransmission(_addr); // Reset
  Wire.write(MMA_845XQ_CTRL_REG2);
  Wire.write(MMA_845XQ_CTRL_REG2_RESET);
  Wire.endTransmission();
  delay(10); // Give it time to do the reset
  _standby();
  Wire.beginTransmission(_addr); // Set Portrait/Landscape mode
  Wire.write(MMA_845XQ_PL_CFG);
  Wire.write(0x80 | MMA_845XQ_PL_EN);
  Wire.endTransmission();
  Wire.beginTransmission(_addr);
  Wire.write(MMA_845XQ_XYZ_DATA_CFG);
  if (_scale == 4 || _scale == 8)
    Wire.write((_scale == 4) ? MMA_845XQ_4G_MODE : MMA_845XQ_8G_MODE);
  else // Default to 2g mode
    Wire.write((uint8_t)MMA_845XQ_2G_MODE);
  Wire.endTransmission();
  _active();
}
示例#2
0
static gboolean
arv_gv_device_read_register (ArvDevice *device, guint32 address, guint32 *value, GError **error)
{
	ArvGvDevice *gv_device = ARV_GV_DEVICE (device);

	return _read_register (gv_device->priv->io_data, address, value, error);
}
示例#3
0
static void *
arv_gv_device_heartbeat_thread (void *data)
{
	ArvGvDeviceHeartbeatData *thread_data = data;
	ArvGvDeviceIOData *io_data = thread_data->io_data;
	GTimer *timer;
	guint32 value;

	timer = g_timer_new ();

	do {
		g_usleep (thread_data->period_us);

		if (io_data->is_controller) {
			guint counter = 1;

			/* TODO: Instead of reading the control register, Pylon does write the heartbeat
			 * timeout value, which is interresting, as doing this we could get an error
			 * ack packet which will indicate we lost the control access. */

			g_timer_start (timer);

			while (!_read_register (io_data, ARV_GVBS_CONTROL_CHANNEL_PRIVILEGE_OFFSET, &value, NULL) &&
			       g_timer_elapsed (timer, NULL) < ARV_GV_DEVICE_HEARTBEAT_RETRY_TIMEOUT_S &&
			       !thread_data->cancel) {
				g_usleep (ARV_GV_DEVICE_HEARTBEAT_RETRY_DELAY_US);
				counter++;
			}

			if (!thread_data->cancel) {
				arv_log_device ("[GvDevice::Heartbeat] Ack value = %d", value);

				if (counter > 1)
					arv_log_device ("[GvDevice::Heartbeat] Tried %u times", counter);

				if ((value & (ARV_GVBS_CONTROL_CHANNEL_PRIVILEGE_CONTROL |
					      ARV_GVBS_CONTROL_CHANNEL_PRIVILEGE_EXCLUSIVE)) == 0) {
					arv_warning_device ("[GvDevice::Heartbeat] Control access lost");

					arv_device_emit_control_lost_signal (ARV_DEVICE (thread_data->gv_device));

					io_data->is_controller = FALSE;
				}
			} else
				io_data->is_controller = FALSE;
		}
	} while (!thread_data->cancel);

	g_timer_destroy (timer);

	return NULL;
}
示例#4
0
bool MMA845XQ::setInterrupt(uint8_t type, uint8_t pin, bool on)
{
	uint8_t current_value = _read_register(0x2D);
	
	if(on)
		current_value |= type;
	else
		current_value &= ~(type);
	
	_write_register(0x2D, current_value);
	
	uint8_t current_routing_value = _read_register(0x2E);
	
	if (pin == 1) {
		current_routing_value &= ~(type);
	}
	else if (pin == 2) {
		current_routing_value |= type;
	}
	
	_write_register(0x2E, current_routing_value);
}
示例#5
0
文件: gdb.c 项目: smaccm/camkes_debug
static void GDB_read_register(char* command) {
    seL4_Word reg;
    // Get which register we want to read
    char *register_string = strtok(command + 1, "#");
    if (register_string == NULL) {
        send_message("E00", 0);
        return;
    }
    int num_regs = sizeof(seL4_UserContext) / sizeof(seL4_Word);
    seL4_Word reg_num = strtol(register_string, NULL, 16);
    if (reg_num >= x86_INVALID_REGISTER) {
        send_message("E00", 0);
        return;
    }
    // Convert to the register order we have
    seL4_Word gdb_reg_num = x86_GDB_Register_Map[reg_num];
    /*? me.from_instance.name ?*/_read_register(badge, &reg, gdb_reg_num);
    int buf_len = sizeof(seL4_Word) * CHAR_HEX_SIZE + 1;
    char data[buf_len];
    sprintf(data, "%02x", __builtin_bswap32(reg));
    send_message(data, buf_len);
}
示例#6
0
uint8_t MMA845XQ::getPulse()
{
	_write_register(MMA_845XQ_PULSE_CFG, MMA_845XQ_PULSE_CFG_ELE);
	return (_read_register(MMA_845XQ_PULSE_SRC) & MMA_845XQ_PULSE_SRC_EA);
}
示例#7
0
uint8_t MMA845XQ::getPLStatus()
{
	return _read_register(MMA_845XQ_PL_STATUS);
}