-
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.
Update code to use its own c++ class and CMake library
Now using a c++ class. This update contains some potentially breaking changes to any existing code you may have that uses this library. The RGBMacroLibrary has been reworked into its own class RGBMacroPad which can be seen in use in Main.cpp CMake also now sees the library as a proper library making implementation even easier. This will allow better integration into your code and much easier usage when working with the library. This library basically becomes an extension of tinyUSB and the Pimoroni libraries to create a really simple deployment of the keypad with keyboard keybinds. Changing the library to be like this makes it easy to work with for beginners as well as allowing you to easily merge this with another project. The libraries SendKeypress function is exposed in the event you wish to send keypresses/combinations yourself while using this library. I may add more examples in the future to better show the uses of the library.
- Loading branch information
Showing
11 changed files
with
349 additions
and
189 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
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,26 @@ | ||
# The MIT License (MIT) | ||
# | ||
# Copyright (c) 2022 Joshua Glass (SuperNinja_4965) | ||
# | ||
# Permission is hereby granted, free of charge, to any person obtaining a copy | ||
# of this software and associated documentation files (the "Software"), to deal | ||
# in the Software without restriction, including without limitation the rights | ||
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
# copies of the Software, and to permit persons to whom the Software is | ||
# furnished to do so, subject to the following conditions: | ||
# | ||
# The above copyright notice and this permission notice shall be included in | ||
# all copies or substantial portions of the Software. | ||
# | ||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
# THE SOFTWARE. | ||
# | ||
|
||
cmake_minimum_required(VERSION 3.5) | ||
|
||
add_subdirectory(Simple) |
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,51 @@ | ||
# The MIT License (MIT) | ||
# | ||
# Copyright (c) 2022 Joshua Glass (SuperNinja_4965) | ||
# | ||
# Permission is hereby granted, free of charge, to any person obtaining a copy | ||
# of this software and associated documentation files (the "Software"), to deal | ||
# in the Software without restriction, including without limitation the rights | ||
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
# copies of the Software, and to permit persons to whom the Software is | ||
# furnished to do so, subject to the following conditions: | ||
# | ||
# The above copyright notice and this permission notice shall be included in | ||
# all copies or substantial portions of the Software. | ||
# | ||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
# THE SOFTWARE. | ||
# | ||
|
||
cmake_minimum_required(VERSION 3.5) | ||
set(CMAKE_C_STANDARD 11) | ||
set(CMAKE_CXX_STANDARD 17) | ||
|
||
# Check to see if TinyUSB has been included in the SDK | ||
if (TARGET tinyusb_device) | ||
# Add our binary | ||
add_executable( | ||
SimpleExample | ||
Main.cpp | ||
) | ||
|
||
# Make sure TinyUSB can find tusb_config.h | ||
target_include_directories(SimpleExample PUBLIC ${CMAKE_CURRENT_LIST_DIR}) | ||
|
||
# Set the Pico program information | ||
pico_set_program_name(SimpleExample "Raspberry Pi Pico MacroPad") | ||
pico_set_program_version(SimpleExample "2023-02-1") | ||
|
||
# Pull in pico libraries that we need | ||
target_link_libraries(SimpleExample PUBLIC pico_stdlib RGBMacroPad) | ||
|
||
# create map/bin/hex file etc. | ||
pico_add_extra_outputs(SimpleExample) | ||
|
||
elseif(PICO_ON_DEVICE) | ||
message(WARNING "Not building Pico-MacroPad because TinyUSB submodule is not initialized in the SDK") | ||
endif() |
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,79 @@ | ||
/* | ||
* The MIT License (MIT) | ||
* | ||
* Copyright (c) 2022 Joshua Glass (SuperNinja_4965) | ||
* | ||
* Permission is hereby granted, free of charge, to any person obtaining a copy | ||
* of this software and associated documentation files (the "Software"), to deal | ||
* in the Software without restriction, including without limitation the rights | ||
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
* copies of the Software, and to permit persons to whom the Software is | ||
* furnished to do so, subject to the following conditions: | ||
* | ||
* The above copyright notice and this permission notice shall be included in | ||
* all copies or substantial portions of the Software. | ||
* | ||
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
* THE SOFTWARE. | ||
* | ||
*/ | ||
|
||
// Standard library includes. | ||
#include "pico/stdlib.h" | ||
// Include our Macropad Library | ||
#include "RGBMacroLibrary.hpp" | ||
|
||
//------------------------------------------------------------------------------------------------------------------------+ | ||
// Useful info: | ||
// The RGBMacroLibrary uses 2 of the RP2040's timers. | ||
// To find out what keys work you can look here: https://github.com/hathach/tinyusb/blob/master/src/class/hid/hid.h | ||
// Any keys in the REPORT_ID_KEYBOARD and REPORT_ID_CONSUMER_CONTROL devices will work. | ||
//------------------------------------------------------------------------------------------------------------------------+ | ||
|
||
RGBMacroPad MacroPad; | ||
|
||
// Code enters here. | ||
int main() { | ||
//False disables the blinking task, 300000 is the sleep timer duration in ms. | ||
MacroPad.DimLedDuration = 300000; | ||
MacroPad.UseBlinking = false; | ||
// Ready the device. | ||
MacroPad.InitializeDevice(); | ||
|
||
// Setup our keys These are just the keys I personally use. | ||
MacroPad.SetupButton(0, 0x20, 0x00, 0x20, HID_KEY_VOLUME_UP, 0, REPORT_ID_KEYBOARD); | ||
MacroPad.SetupButton(1, 0x00, 0x20, 0x00, HID_KEY_S, KEYBOARD_MODIFIER_LEFTGUI + KEYBOARD_MODIFIER_LEFTCTRL + KEYBOARD_MODIFIER_LEFTSHIFT + KEYBOARD_MODIFIER_LEFTALT, REPORT_ID_KEYBOARD); | ||
MacroPad.SetupButton(2, 0x20, 0x00, 0x20, HID_USAGE_CONSUMER_PLAY_PAUSE, 0, REPORT_ID_CONSUMER_CONTROL); | ||
MacroPad.SetupButton(3, 0x20, 0x00, 0x00, HID_KEY_DELETE, KEYBOARD_MODIFIER_LEFTCTRL + KEYBOARD_MODIFIER_LEFTALT, REPORT_ID_KEYBOARD); | ||
|
||
MacroPad.SetupButton(4, 0x20, 0x00, 0x20, HID_KEY_VOLUME_DOWN, 0, REPORT_ID_KEYBOARD); | ||
MacroPad.SetupButton(5, 0x20, 0x00, 0x00, HID_KEY_H, KEYBOARD_MODIFIER_LEFTGUI + KEYBOARD_MODIFIER_LEFTCTRL + KEYBOARD_MODIFIER_LEFTSHIFT + KEYBOARD_MODIFIER_LEFTALT, REPORT_ID_KEYBOARD); | ||
MacroPad.SetupButton(6, 0x20, 0x00, 0x20, HID_USAGE_CONSUMER_SCAN_PREVIOUS, 0, REPORT_ID_CONSUMER_CONTROL); | ||
MacroPad.SetupButton(7, 0x20, 0x00, 0x20, HID_USAGE_CONSUMER_SCAN_NEXT, 0, REPORT_ID_CONSUMER_CONTROL); | ||
|
||
MacroPad.SetupButton(8, 0x20, 0x00, 0x20, HID_KEY_MUTE, 0, REPORT_ID_KEYBOARD); | ||
MacroPad.SetupButton(9, 0x00, 0x20, 0x20, HID_KEY_A, KEYBOARD_MODIFIER_LEFTGUI + KEYBOARD_MODIFIER_LEFTCTRL + KEYBOARD_MODIFIER_LEFTSHIFT + KEYBOARD_MODIFIER_LEFTALT, REPORT_ID_KEYBOARD); | ||
MacroPad.SetupButton(10, 0x00, 0x00, 0x20, HID_KEY_D, KEYBOARD_MODIFIER_LEFTGUI + KEYBOARD_MODIFIER_LEFTCTRL + KEYBOARD_MODIFIER_LEFTSHIFT + KEYBOARD_MODIFIER_LEFTALT, REPORT_ID_KEYBOARD); | ||
MacroPad.SetupButton(11, 0x20, 0x00, 0x00, 0, 0, REPORT_ID_TINYPICO); | ||
|
||
MacroPad.SetupButton(12, 0x00, 0x00, 0x00, HID_KEY_CAPS_LOCK, 0, REPORT_ID_KEYBOARD); | ||
MacroPad.SetupButton(13, 0x00, 0x00, 0x00, HID_KEY_NUM_LOCK, 0, REPORT_ID_KEYBOARD); | ||
// Uncomment this line if you want to use scroll lock. Comment the line below if you don't want to use it. (dont forget to update the line below) | ||
//SetupButton(14, 0x00, 0x00, 0x00, HID_KEY_SCROLL_LOCK, 0, REPORT_ID_KEYBOARD); | ||
MacroPad.SetupButton(14, 0x00, 0x20, 0x00, HID_KEY_T, KEYBOARD_MODIFIER_LEFTCTRL + KEYBOARD_MODIFIER_LEFTALT, REPORT_ID_KEYBOARD); | ||
MacroPad.SetupButton(15, 0x00, 0x20, 0x20, HID_KEY_L, KEYBOARD_MODIFIER_LEFTGUI, REPORT_ID_KEYBOARD); | ||
//MacroPad.RemoveButtonSetup(ButtonNum); // Use this to remove a buttons config. | ||
|
||
while (true) | ||
{ | ||
// Run the libraries loop to handle keypresses. | ||
MacroPad.Loop(); | ||
} | ||
|
||
return 0; | ||
} |
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,56 @@ | ||
# This file can be dropped into a project to help locate the Pimoroni Pico libraries | ||
# It will also set up the required include and module search paths. | ||
|
||
if (DEFINED ENV{PIMORONI_PICO_FETCH_FROM_GIT} AND (NOT PIMORONI_PICO_FETCH_FROM_GIT)) | ||
set(PIMORONI_PICO_FETCH_FROM_GIT $ENV{PIMORONI_PICO_FETCH_FROM_GIT}) | ||
message("Using PIMORONI_PICO_FETCH_FROM_GIT from environment ('${PIMORONI_PICO_FETCH_FROM_GIT}')") | ||
endif () | ||
|
||
if (DEFINED ENV{PIMORONI_PICO_FETCH_FROM_GIT_PATH} AND (NOT PIMORONI_PICO_FETCH_FROM_GIT_PATH)) | ||
set(PIMORONI_PICO_FETCH_FROM_GIT_PATH $ENV{PIMORONI_PICO_FETCH_FROM_GIT_PATH}) | ||
message("Using PIMORONI_PICO_FETCH_FROM_GIT_PATH from environment ('${PIMORONI_PICO_FETCH_FROM_GIT_PATH}')") | ||
endif () | ||
|
||
if (NOT PIMORONI_PICO_PATH) | ||
if (PIMORONI_PICO_FETCH_FROM_GIT) | ||
include(FetchContent) | ||
set(FETCHCONTENT_BASE_DIR_SAVE ${FETCHCONTENT_BASE_DIR}) | ||
if (PIMORONI_PICO_FETCH_FROM_GIT_PATH) | ||
get_filename_component(FETCHCONTENT_BASE_DIR "${PIMORONI_PICO_FETCH_FROM_GIT_PATH}" REALPATH BASE_DIR "${CMAKE_SOURCE_DIR}") | ||
endif () | ||
FetchContent_Declare( | ||
pimoroni_pico | ||
GIT_REPOSITORY https://github.com/pimoroni/pimoroni-pico | ||
GIT_TAG main | ||
) | ||
if (NOT pimoroni_pico) | ||
message("Downloading PIMORONI_PICO SDK") | ||
FetchContent_Populate(pimoroni_pico) | ||
set(PIMORONI_PICO_PATH ${pimoroni_pico_SOURCE_DIR}) | ||
endif () | ||
set(FETCHCONTENT_BASE_DIR ${FETCHCONTENT_BASE_DIR_SAVE}) | ||
elseif(PICO_SDK_PATH AND EXISTS "${PICO_SDK_PATH}/../pimoroni-pico") | ||
set(PIMORONI_PICO_PATH ${PICO_SDK_PATH}/../pimoroni-pico) | ||
message("Defaulting PIMORONI_PICO_PATH as sibling of PICO_SDK_PATH: ${PIMORONI_PICO_PATH}") | ||
elseif(EXISTS "${CMAKE_CURRENT_BINARY_DIR}/../../pimoroni-pico/") | ||
set(PIMORONI_PICO_PATH ${CMAKE_CURRENT_BINARY_DIR}/../../pimoroni-pico/) | ||
else() | ||
message(FATAL_ERROR "Pimoroni Pico location was not specified. Please set PIMORONI_PICO_PATH.") | ||
endif() | ||
endif() | ||
|
||
get_filename_component(PIMORONI_PICO_PATH "${PIMORONI_PICO_PATH}" REALPATH BASE_DIR "${CMAKE_BINARY_DIR}") | ||
if (NOT EXISTS ${PIMORONI_PICO_PATH}) | ||
message(FATAL_ERROR "Directory '${PIMORONI_PICO_PATH}' not found") | ||
endif () | ||
|
||
if (NOT EXISTS ${PIMORONI_PICO_PATH}/pimoroni_pico_import.cmake) | ||
message(FATAL_ERROR "Directory '${PIMORONI_PICO_PATH}' does not appear to contain the Pimoroni Pico libraries") | ||
endif () | ||
|
||
message("PIMORONI_PICO_PATH is ${PIMORONI_PICO_PATH}") | ||
|
||
set(PIMORONI_PICO_PATH ${PIMORONI_PICO_PATH} CACHE PATH "Path to the Pimoroni Pico libraries" FORCE) | ||
|
||
include_directories(${PIMORONI_PICO_PATH}) | ||
list(APPEND CMAKE_MODULE_PATH ${PIMORONI_PICO_PATH}) |
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,47 @@ | ||
# The MIT License (MIT) | ||
# | ||
# Copyright (c) 2022 Joshua Glass (SuperNinja_4965) | ||
# | ||
# Permission is hereby granted, free of charge, to any person obtaining a copy | ||
# of this software and associated documentation files (the "Software"), to deal | ||
# in the Software without restriction, including without limitation the rights | ||
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
# copies of the Software, and to permit persons to whom the Software is | ||
# furnished to do so, subject to the following conditions: | ||
# | ||
# The above copyright notice and this permission notice shall be included in | ||
# all copies or substantial portions of the Software. | ||
# | ||
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN | ||
# THE SOFTWARE. | ||
# | ||
|
||
cmake_minimum_required(VERSION 3.5) | ||
set(CMAKE_C_STANDARD 11) | ||
set(CMAKE_CXX_STANDARD 17) | ||
|
||
# Check to see if TinyUSB has been included in the SDK | ||
if (TARGET tinyusb_device) | ||
# Add our library | ||
add_library(RGBMacroPad INTERFACE) | ||
|
||
target_sources(RGBMacroPad INTERFACE | ||
${CMAKE_CURRENT_LIST_DIR}/RGBMacroLibrary.cpp | ||
${CMAKE_CURRENT_LIST_DIR}/usb_descriptors.c | ||
) | ||
|
||
# Make sure TinyUSB can find tusb_config.h | ||
target_include_directories(RGBMacroPad INTERFACE ${CMAKE_CURRENT_LIST_DIR}) | ||
|
||
# Pull in pico libraries that we need | ||
target_link_libraries(RGBMacroPad INTERFACE pico_stdlib pico_rgb_keypad tinyusb_device tinyusb_board) | ||
|
||
elseif(PICO_ON_DEVICE) | ||
message(WARNING "Not building Pico-MacroPad because TinyUSB submodule is not initialized in the SDK") | ||
endif() | ||
|
Oops, something went wrong.