generated from libhal/libhal-__device__
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ Add CH9329 driver for mouse and keyboard control (#8)
* ✨ Add CH9329 driver for mouse control * bug fixes and absolute mouse demo * change button logic * add doxygen comments * add keyboard general commands * add keyboard media command * split keyboard media and acpi commands * comment out new demos in cmake * Update demo to use nunchuck buttons as kb buttons * add get info command * work in progress, more commands * more work in progress * more work in progress * take out config/parameter commands for later * change requests * more change requests * bug fixes * more change requests
- Loading branch information
1 parent
84b8883
commit 0ba945d
Showing
13 changed files
with
1,146 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
// Copyright 2024 Khalil Estell | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
#include <cstdint> | ||
|
||
#include <libhal-input/ch9329.hpp> | ||
#include <libhal-input/gamepad/nunchuck.hpp> | ||
#include <libhal-util/serial.hpp> | ||
#include <libhal-util/steady_clock.hpp> | ||
#include <libhal/i2c.hpp> | ||
|
||
#include <resource_list.hpp> | ||
|
||
void application(resource_list& p_map) | ||
{ | ||
using namespace std::chrono_literals; | ||
using namespace hal::literals; | ||
|
||
auto& clock = *p_map.clock.value(); | ||
auto& console = *p_map.console.value(); | ||
auto& uart3 = *p_map.uart3.value(); | ||
|
||
hal::input::ch9329 usb_control(uart3); | ||
uint16_t width = 3840; | ||
uint16_t height = 2160; | ||
|
||
hal::input::ch9329::mouse_absolute abs_mouse_control(width, height); | ||
|
||
hal::print(console, "Demo Application Starting...\n\n"); | ||
hal::print<32>(console, "Screen Width: %li ", width); | ||
hal::print<32>(console, "Screen Height: %li \n", height); | ||
|
||
while (true) { | ||
// top left corner | ||
abs_mouse_control.position(1, 1); | ||
usb_control.send(abs_mouse_control); | ||
hal::delay(clock, 1s); | ||
|
||
// middle screen | ||
abs_mouse_control.position(width / 2, height / 2); | ||
usb_control.send(abs_mouse_control); | ||
hal::delay(clock, 1s); | ||
|
||
// bottom right | ||
abs_mouse_control.position(width, height); | ||
usb_control.send(abs_mouse_control); | ||
hal::delay(clock, 1s); | ||
|
||
// bottom left | ||
abs_mouse_control.position(1, height); | ||
usb_control.send(abs_mouse_control); | ||
hal::delay(clock, 1s); | ||
|
||
// middle screen | ||
abs_mouse_control.position(width / 2, height / 2); | ||
usb_control.send(abs_mouse_control); | ||
hal::delay(clock, 1s); | ||
|
||
// top right | ||
abs_mouse_control.position(width, 1); | ||
usb_control.send(abs_mouse_control); | ||
hal::delay(clock, 1s); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
// Copyright 2024 Khalil Estell | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
#include <libhal-input/ch9329.hpp> | ||
#include <libhal-input/gamepad/nunchuck.hpp> | ||
#include <libhal-util/serial.hpp> | ||
#include <libhal-util/steady_clock.hpp> | ||
#include <libhal/i2c.hpp> | ||
|
||
#include <resource_list.hpp> | ||
|
||
void application(resource_list& p_map) | ||
{ | ||
using namespace std::chrono_literals; | ||
using namespace hal::literals; | ||
|
||
auto& clock = *p_map.clock.value(); | ||
auto& console = *p_map.console.value(); | ||
auto& uart3 = *p_map.uart3.value(); | ||
|
||
hal::input::ch9329 usb_control(uart3); | ||
|
||
hal::input::ch9329::keyboard_general keyboard_control; | ||
|
||
hal::print(console, "Demo Application Starting...\n\n"); | ||
|
||
while (true) { | ||
keyboard_control.press_normal_key(normal_key::a, 1); | ||
usb_control.send(keyboard_control); | ||
hal::delay(clock, 1ms); | ||
|
||
keyboard_control.release_normal_key(normal_key::a); | ||
usb_control.send(keyboard_control); | ||
hal::delay(clock, 2s); | ||
|
||
keyboard_control.press_normal_key(normal_key::back_space, 1); | ||
usb_control.send(keyboard_control); | ||
hal::delay(clock, 1ms); | ||
|
||
keyboard_control.release_normal_key(normal_key::back_space); | ||
usb_control.send(keyboard_control); | ||
hal::delay(clock, 2s); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
// Copyright 2024 Khalil Estell | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
|
||
#include <libhal-input/ch9329.hpp> | ||
#include <libhal-input/gamepad/nunchuck.hpp> | ||
#include <libhal-util/serial.hpp> | ||
#include <libhal-util/steady_clock.hpp> | ||
#include <libhal/i2c.hpp> | ||
|
||
#include <resource_list.hpp> | ||
|
||
void application(resource_list& p_map) | ||
{ | ||
using namespace std::chrono_literals; | ||
using namespace hal::literals; | ||
|
||
constexpr auto sensitivity = 16; | ||
auto& clock = *p_map.clock.value(); | ||
auto& console = *p_map.console.value(); | ||
auto& uart3 = *p_map.uart3.value(); | ||
auto& i2c = *p_map.i2c.value(); | ||
|
||
hal::input::nunchuck nunchuck(i2c); | ||
hal::input::ch9329 usb_control(uart3); | ||
hal::input::ch9329::keyboard_general kb_control; | ||
hal::input::ch9329::mouse_relative rel_mouse_control; | ||
|
||
hal::print(console, "Demo Application Starting...\n\n"); | ||
while (true) { | ||
auto data = nunchuck.read(); | ||
std::int8_t x = (data.joystick_x() - 128) / sensitivity; | ||
std::int8_t y = -(data.joystick_y() - 128) / sensitivity; | ||
rel_mouse_control.move(x, y) | ||
.left_button(data.c_button()) | ||
.right_button(data.z_button()); | ||
usb_control.send(rel_mouse_control); | ||
hal::delay(clock, 1ms); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.