mirror of
https://github.com/RGBCube/serenity
synced 2025-05-31 12:48:10 +00:00
Kernel/Devices/HID: Propagate errors of HIDDevices properly
Some error indication was done by returning bool. This was changed to propagate the error by ErrorOr from the underlying functions. The returntype of the underlying functions was also changed to propagate the error.
This commit is contained in:
parent
83e96569ed
commit
d3ce97e8b2
8 changed files with 103 additions and 110 deletions
|
@ -137,70 +137,69 @@ MousePacket PS2MouseDevice::parse_data_packet(const RawPacket& raw_packet)
|
|||
return packet;
|
||||
}
|
||||
|
||||
u8 PS2MouseDevice::get_device_id()
|
||||
ErrorOr<u8> PS2MouseDevice::get_device_id()
|
||||
{
|
||||
if (send_command(I8042Command::GetDeviceID) != I8042Response::Acknowledge)
|
||||
return 0;
|
||||
TRY(send_command(I8042Command::GetDeviceID));
|
||||
return read_from_device();
|
||||
}
|
||||
|
||||
u8 PS2MouseDevice::read_from_device()
|
||||
ErrorOr<u8> PS2MouseDevice::read_from_device()
|
||||
{
|
||||
return m_i8042_controller->read_from_device(instrument_type());
|
||||
}
|
||||
|
||||
u8 PS2MouseDevice::send_command(u8 command)
|
||||
ErrorOr<u8> PS2MouseDevice::send_command(u8 command)
|
||||
{
|
||||
u8 response = m_i8042_controller->send_command(instrument_type(), command);
|
||||
if (response != I8042Response::Acknowledge)
|
||||
u8 response = TRY(m_i8042_controller->send_command(instrument_type(), command));
|
||||
|
||||
if (response != I8042Response::Acknowledge) {
|
||||
dbgln("PS2MouseDevice: Command {} got {} but expected ack: {}", command, response, static_cast<u8>(I8042Response::Acknowledge));
|
||||
return response;
|
||||
}
|
||||
|
||||
u8 PS2MouseDevice::send_command(u8 command, u8 data)
|
||||
{
|
||||
u8 response = m_i8042_controller->send_command(instrument_type(), command, data);
|
||||
if (response != I8042Response::Acknowledge)
|
||||
dbgln("PS2MouseDevice: Command {} got {} but expected ack: {}", command, response, static_cast<u8>(I8042Response::Acknowledge));
|
||||
return response;
|
||||
}
|
||||
|
||||
void PS2MouseDevice::set_sample_rate(u8 rate)
|
||||
{
|
||||
send_command(I8042Command::SetSampleRate, rate);
|
||||
}
|
||||
|
||||
UNMAP_AFTER_INIT RefPtr<PS2MouseDevice> PS2MouseDevice::try_to_initialize(const I8042Controller& ps2_controller)
|
||||
{
|
||||
auto mouse_device_or_error = DeviceManagement::try_create_device<PS2MouseDevice>(ps2_controller);
|
||||
// FIXME: Find a way to propagate errors
|
||||
VERIFY(!mouse_device_or_error.is_error());
|
||||
if (mouse_device_or_error.value()->initialize())
|
||||
return mouse_device_or_error.release_value();
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
UNMAP_AFTER_INIT bool PS2MouseDevice::initialize()
|
||||
{
|
||||
if (!m_i8042_controller->reset_device(instrument_type())) {
|
||||
dbgln("PS2MouseDevice: I8042 controller failed to reset device");
|
||||
return false;
|
||||
// FIXME: Is this the correct errno value for this?
|
||||
return Error::from_errno(EIO);
|
||||
}
|
||||
return response;
|
||||
}
|
||||
|
||||
u8 device_id = read_from_device();
|
||||
ErrorOr<u8> PS2MouseDevice::send_command(u8 command, u8 data)
|
||||
{
|
||||
u8 response = TRY(m_i8042_controller->send_command(instrument_type(), command, data));
|
||||
if (response != I8042Response::Acknowledge) {
|
||||
dbgln("PS2MouseDevice: Command {} got {} but expected ack: {}", command, response, static_cast<u8>(I8042Response::Acknowledge));
|
||||
// FIXME: Is this the correct errno value for this?
|
||||
return Error::from_errno(EIO);
|
||||
}
|
||||
return response;
|
||||
}
|
||||
|
||||
if (send_command(I8042Command::SetDefaults) != I8042Response::Acknowledge)
|
||||
return false;
|
||||
ErrorOr<void> PS2MouseDevice::set_sample_rate(u8 rate)
|
||||
{
|
||||
TRY(send_command(I8042Command::SetSampleRate, rate));
|
||||
return {};
|
||||
}
|
||||
|
||||
if (send_command(I8042Command::EnablePacketStreaming) != I8042Response::Acknowledge)
|
||||
return false;
|
||||
UNMAP_AFTER_INIT ErrorOr<NonnullRefPtr<PS2MouseDevice>> PS2MouseDevice::try_to_initialize(const I8042Controller& ps2_controller)
|
||||
{
|
||||
auto mouse_device = TRY(DeviceManagement::try_create_device<PS2MouseDevice>(ps2_controller));
|
||||
TRY(mouse_device->initialize());
|
||||
return mouse_device;
|
||||
}
|
||||
|
||||
UNMAP_AFTER_INIT ErrorOr<void> PS2MouseDevice::initialize()
|
||||
{
|
||||
TRY(m_i8042_controller->reset_device(instrument_type()));
|
||||
|
||||
u8 device_id = TRY(read_from_device());
|
||||
|
||||
TRY(send_command(I8042Command::SetDefaults));
|
||||
|
||||
TRY(send_command(I8042Command::EnablePacketStreaming));
|
||||
|
||||
if (device_id != PS2MOUSE_INTELLIMOUSE_ID) {
|
||||
// Send magical wheel initiation sequence.
|
||||
set_sample_rate(200);
|
||||
set_sample_rate(100);
|
||||
set_sample_rate(80);
|
||||
device_id = get_device_id();
|
||||
TRY(set_sample_rate(200));
|
||||
TRY(set_sample_rate(100));
|
||||
TRY(set_sample_rate(80));
|
||||
device_id = TRY(get_device_id());
|
||||
}
|
||||
if (device_id == PS2MOUSE_INTELLIMOUSE_ID) {
|
||||
m_has_wheel = true;
|
||||
|
@ -211,17 +210,17 @@ UNMAP_AFTER_INIT bool PS2MouseDevice::initialize()
|
|||
|
||||
if (device_id == PS2MOUSE_INTELLIMOUSE_ID) {
|
||||
// Try to enable 5 buttons as well!
|
||||
set_sample_rate(200);
|
||||
set_sample_rate(200);
|
||||
set_sample_rate(80);
|
||||
device_id = get_device_id();
|
||||
TRY(set_sample_rate(200));
|
||||
TRY(set_sample_rate(200));
|
||||
TRY(set_sample_rate(80));
|
||||
device_id = TRY(get_device_id());
|
||||
}
|
||||
|
||||
if (device_id == PS2MOUSE_INTELLIMOUSE_EXPLORER_ID) {
|
||||
m_has_five_buttons = true;
|
||||
dmesgln("PS2MouseDevice: 5 buttons enabled!");
|
||||
}
|
||||
return true;
|
||||
return {};
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue