#include <USBHostGiga.h>
#include <main.h>
#include <usb_host.h>
#include <usbh_cdc.h>
#include <usbh_conf.h>
#include <usbh_core.h>
#include <usbh_ctlreq.h>
#include <usbh_def.h>
#include <usbh_hid.h>
#include <usbh_hid_keybd.h>
#include <usbh_hid_mouse.h>
#include <usbh_hid_parser.h>
#include <usbh_hid_usage.h>
#include <usbh_ioreq.h>
#include <usbh_pipes.h>
#include <usbh_platform.h>
#include <Adafruit_GFX.h>
#include <Adafruit_ST7735.h>
#include <WiFiNINA.h> // Use WiFi.h for STM32 (GIGA R1)
#include <KeyboardController.h>
// ST7735 LCD Pins
#define TFT_CS 10
#define TFT_RST 9
#define TFT_DC 8
#define TFT_MOSI 15
#define TFT_SCLK 13
// Create LCD object
Adafruit_ST7735 tft = Adafruit_ST7735(TFT_CS, TFT_DC, TFT_MOSI, TFT_SCLK, TFT_RST);
// USB Keyboard
USBHostGiga usbHost;
KeyboardController keyboard(usbHost);
// WiFi credentials
String ssid = "";
String password = "";
bool enteringSSID = true;
bool enteringPassword = false;
bool wifiConnected = false;
// Browser input
String url = "";
bool enteringURL = false;
bool redraw = true;
// Keyboard Event
void keyPressed() {
char key = keyboard.getKey();
if (key >= 32 && key <= 126) { // Printable characters
if (enteringSSID) {
handleSSIDInput(key);
} else if (enteringPassword) {
handlePasswordInput(key);
} else if (enteringURL) {
handleURLInput(key);
}
redraw = true;
} else if (key == 13) { // Enter key
if (enteringSSID) {
enteringSSID = false;
enteringPassword = true;
redraw = true;
} else if (enteringPassword) {
enteringPassword = false;
connectToWiFi();
} else if (enteringURL) {
enteringURL = false;
fetchPage(url);
}
} else if (key == 8) { // Backspace
if (enteringSSID && ssid.length() > 0) {
ssid.remove(ssid.length() - 1);
redraw = true;
} else if (enteringPassword && password.length() > 0) {
password.remove(password.length() - 1);
redraw = true;
} else if (enteringURL && url.length() > 0) {
url.remove(url.length() - 1);
redraw = true;
}
}
}
// Handle SSID Input
void handleSSIDInput(char key) {
ssid += key;
}
// Handle Password Input
void handlePasswordInput(char key) {
password += key;
}
// Handle URL Input
void handleURLInput(char key) {
url += key;
}
// Connect to WiFi
void connectToWiFi() {
tft.fillScreen(ST7735_BLACK);
tft.setCursor(0, 10);
tft.print("Connecting to WiFi...");
WiFi.begin(ssid.c_str(), password.c_str());
int attempts = 0;
while (WiFi.status() != WL_CONNECTED && attempts < 10) {
delay(1000);
tft.print(".");
attempts++;
}
if (WiFi.status() == WL_CONNECTED) {
wifiConnected = true;
enteringURL = true;
tft.fillScreen(ST7735_BLACK);
tft.setCursor(0, 10);
tft.print("WiFi Connected!");
delay(2000);
redraw = true;
} else {
tft.fillScreen(ST7735_BLACK);
tft.setCursor(0, 10);
tft.print("WiFi Failed!");
delay(2000);
enteringSSID = true; // Restart WiFi input
redraw = true;
}
}
// Fetch Web Page
void fetchPage(String url) {
tft.fillScreen(ST7735_BLACK);
tft.setCursor(0, 10);
tft.print("Fetching: ");
tft.print(url);
WiFiClient client;
String host = url;
String path = "/";
int slashIndex = url.indexOf('/');
if (slashIndex != -1) {
host = url.substring(0, slashIndex);
path = url.substring(slashIndex);
}
if (client.connect(host.c_str(), 80)) {
client.println("GET " + path + " HTTP/1.1");
client.println("Host: " + host);
client.println("Connection: close");
client.println();
}
String response = "";
while (client.available()) {
response += client.readString();
}
client.stop();
tft.fillScreen(ST7735_BLACK);
tft.setCursor(0, 10);
tft.print("Page Loaded!");
Serial.println(response); // Debug print
redraw = true;
}
void setup() {
Serial.begin(115200);
// Initialize display
tft.initR(INITR_BLACKTAB);
tft.fillScreen(ST7735_BLACK);
tft.setTextColor(ST7735_WHITE);
tft.setTextSize(1);
// Initialize USB host (check GIGA R1 support)
usbHost.begin();
tft.setCursor(0, 10);
tft.print("Enter WiFi SSID:");
}
void loop() {
usbHost.Task(); // Check USB keyboard
if (redraw) {
tft.fillScreen(ST7735_BLACK);
tft.setCursor(0, 10);
if (enteringSSID) {
tft.print("SSID: " + ssid);
} else if (enteringPassword) {
tft.print("Password: ");
for (int i = 0; i < password.length(); i++) {
tft.print("*");
}
} else if (enteringURL) {
tft.print("URL: " + url);
}
redraw = false;
}
}
error massage
WARNING: library USBHost claims to run on sam architecture(s) and may be incompatible with your current board which runs on mbed_giga architecture(s).
In file included from c:\Users\Nelson\Documents\Arduino\libraries\USBHost\src/hidboot.h:24:0,
from c:\Users\Nelson\Documents\Arduino\libraries\USBHost\src/KeyboardController.h:22,
from C:\Users\Nelson\Downloads\sketch_feb26a\sketch_feb26a.ino:21:
c:\Users\Nelson\Documents\Arduino\libraries\USBHost\src/hid.h:108:0: warning: "HID_ITEM_TYPE_MAIN" redefined
#define HID_ITEM_TYPE_MAIN 0
In file included from c:\Users\Nelson\Documents\Arduino\libraries\USBHostGiga-master/usbh_hid_keybd.h:29:0,
from c:\Users\Nelson\Documents\Arduino\libraries\USBHostGiga-master/USBHostGiga.h:7,
from C:\Users\Nelson\Downloads\sketch_feb26a\sketch_feb26a.ino:1:
c:\Users\Nelson\Documents\Arduino\libraries\USBHostGiga-master/usbh_hid.h:63:0: note: this is the location of the previous definition
#define HID_ITEM_TYPE_MAIN 0x00U
In file included from c:\Users\Nelson\Documents\Arduino\libraries\USBHost\src/hidboot.h:24:0,
from c:\Users\Nelson\Documents\Arduino\libraries\USBHost\src/KeyboardController.h:22,
from C:\Users\Nelson\Downloads\sketch_feb26a\sketch_feb26a.ino:21:
c:\Users\Nelson\Documents\Arduino\libraries\USBHost\src/hid.h:109:0: warning: "HID_ITEM_TYPE_GLOBAL" redefined
#define HID_ITEM_TYPE_GLOBAL 1
In file included from c:\Users\Nelson\Documents\Arduino\libraries\USBHostGiga-master/usbh_hid_keybd.h:29:0,
from c:\Users\Nelson\Documents\Arduino\libraries\USBHostGiga-master/USBHostGiga.h:7,
from C:\Users\Nelson\Downloads\sketch_feb26a\sketch_feb26a.ino:1:
c:\Users\Nelson\Documents\Arduino\libraries\USBHostGiga-master/usbh_hid.h:64:0: note: this is the location of the previous definition
#define HID_ITEM_TYPE_GLOBAL 0x01U
In file included from c:\Users\Nelson\Documents\Arduino\libraries\USBHost\src/hidboot.h:24:0,
from c:\Users\Nelson\Documents\Arduino\libraries\USBHost\src/KeyboardController.h:22,
from C:\Users\Nelson\Downloads\sketch_feb26a\sketch_feb26a.ino:21:
c:\Users\Nelson\Documents\Arduino\libraries\USBHost\src/hid.h:110:0: warning: "HID_ITEM_TYPE_LOCAL" redefined
#define HID_ITEM_TYPE_LOCAL 2
In file included from c:\Users\Nelson\Documents\Arduino\libraries\USBHostGiga-master/usbh_hid_keybd.h:29:0,
from c:\Users\Nelson\Documents\Arduino\libraries\USBHostGiga-master/USBHostGiga.h:7,
from C:\Users\Nelson\Downloads\sketch_feb26a\sketch_feb26a.ino:1:
c:\Users\Nelson\Documents\Arduino\libraries\USBHostGiga-master/usbh_hid.h:65:0: note: this is the location of the previous definition
#define HID_ITEM_TYPE_LOCAL 0x02U
In file included from c:\Users\Nelson\Documents\Arduino\libraries\USBHost\src/hidboot.h:24:0,
from c:\Users\Nelson\Documents\Arduino\libraries\USBHost\src/KeyboardController.h:22,
from C:\Users\Nelson\Downloads\sketch_feb26a\sketch_feb26a.ino:21:
c:\Users\Nelson\Documents\Arduino\libraries\USBHost\src/hid.h:111:0: warning: "HID_ITEM_TYPE_RESERVED" redefined
#define HID_ITEM_TYPE_RESERVED 3
In file included from c:\Users\Nelson\Documents\Arduino\libraries\USBHostGiga-master/usbh_hid_keybd.h:29:0,
from c:\Users\Nelson\Documents\Arduino\libraries\USBHostGiga-master/USBHostGiga.h:7,
from C:\Users\Nelson\Downloads\sketch_feb26a\sketch_feb26a.ino:1:
c:\Users\Nelson\Documents\Arduino\libraries\USBHostGiga-master/usbh_hid.h:66:0: note: this is the location of the previous definition
#define HID_ITEM_TYPE_RESERVED 0x03U
In file included from c:\Users\Nelson\Documents\Arduino\libraries\USBHost\src/KeyboardController.h:22:0,
from C:\Users\Nelson\Downloads\sketch_feb26a\sketch_feb26a.ino:21:
c:\Users\Nelson\Documents\Arduino\libraries\USBHost\src/hidboot.h: In member function 'virtual void HIDBoot<BOOT_PROTOCOL>::EndpointXtract(uint32_t, uint32_t, uint32_t, uint32_t, const USB_ENDPOINT_DESCRIPTOR*)':
c:\Users\Nelson\Documents\Arduino\libraries\USBHost\src/hidboot.h:474:62: error: 'UOTGHS_HSTPIPCFG_PTYPE_INTRPT' was not declared in this scope
pipe = UHD_Pipe_Alloc(bAddress, epInfo[index].deviceEpNum, UOTGHS_HSTPIPCFG_PTYPE_INTRPT, UOTGHS_HSTPIPCFG_PTOKEN_IN, epInfo[index].maxPktSize, 10, UOTGHS_HSTPIPCFG_PBK_1_BANK);
^~~~~~~~~~~~~~~~~~~~~~~~~~~~~
c:\Users\Nelson\Documents\Arduino\libraries\USBHost\src/hidboot.h:474:93: error: 'UOTGHS_HSTPIPCFG_PTOKEN_IN' was not declared in this scope
pipe = UHD_Pipe_Alloc(bAddress, epInfo[index].deviceEpNum, UOTGHS_HSTPIPCFG_PTYPE_INTRPT, UOTGHS_HSTPIPCFG_PTOKEN_IN, epInfo[index].maxPktSize, 10, UOTGHS_HSTPIPCFG_PBK_1_BANK);
^~~~~~~~~~~~~~~~~~~~~~~~~~
c:\Users\Nelson\Documents\Arduino\libraries\USBHost\src/hidboot.h:474:151: error: 'UOTGHS_HSTPIPCFG_PBK_1_BANK' was not declared in this scope
pipe = UHD_Pipe_Alloc(bAddress, epInfo[index].deviceEpNum, UOTGHS_HSTPIPCFG_PTYPE_INTRPT, UOTGHS_HSTPIPCFG_PTOKEN_IN, epInfo[index].maxPktSize, 10, UOTGHS_HSTPIPCFG_PBK_1_BANK);
^~~~~~~~~~~~~~~~~~~~~~~~~~~
c:\Users\Nelson\Documents\Arduino\libraries\USBHost\src/hidboot.h:474:10: error: there are no arguments to 'UHD_Pipe_Alloc' that depend on a template parameter, so a declaration of 'UHD_Pipe_Alloc' must be available [-fpermissive]
pipe = UHD_Pipe_Alloc(bAddress, epInfo[index].deviceEpNum, UOTGHS_HSTPIPCFG_PTYPE_INTRPT, UOTGHS_HSTPIPCFG_PTOKEN_IN, epInfo[index].maxPktSize, 10, UOTGHS_HSTPIPCFG_PBK_1_BANK);
^~~~~~~~~~~~~~
c:\Users\Nelson\Documents\Arduino\libraries\USBHost\src/hidboot.h:474:10: note: (if you use '-fpermissive', G++ will accept your code, but allowing the use of an undeclared name is deprecated)
c:\Users\Nelson\Documents\Arduino\libraries\USBHost\src/hidboot.h: In member function 'virtual uint32_t HIDBoot<BOOT_PROTOCOL>::Release()':
c:\Users\Nelson\Documents\Arduino\libraries\USBHost\src/hidboot.h:500:2: error: there are no arguments to 'UHD_Pipe_Free' that depend on a template parameter, so a declaration of 'UHD_Pipe_Free' must be available [-fpermissive]
UHD_Pipe_Free(epInfo[epInterruptInIndex].hostPipeNum);
^~~~~~~~~~~~~
C:\Users\Nelson\Downloads\sketch_feb26a\sketch_feb26a.ino: At global scope:
C:\Users\Nelson\Downloads\sketch_feb26a\sketch_feb26a.ino:34:1: error: 'USBHostGiga' does not name a type; did you mean 'USBHost'?
USBHostGiga usbHost;
^~~~~~~~~~~
USBHost
C:\Users\Nelson\Downloads\sketch_feb26a\sketch_feb26a.ino:35:29: error: 'usbHost' was not declared in this scope
KeyboardController keyboard(usbHost);
^~~~~~~
C:\Users\Nelson\Downloads\sketch_feb26a\sketch_feb26a.ino:35:29: note: suggested alternative: 'USBHost'
KeyboardController keyboard(usbHost);
^~~~~~~
USBHost
C:\Users\Nelson\Downloads\sketch_feb26a\sketch_feb26a.ino: In function 'void setup()':
C:\Users\Nelson\Downloads\sketch_feb26a\sketch_feb26a.ino:181:3: error: 'usbHost' was not declared in this scope
usbHost.begin();
^~~~~~~
C:\Users\Nelson\Downloads\sketch_feb26a\sketch_feb26a.ino:181:3: note: suggested alternative: 'USBHost'
usbHost.begin();
^~~~~~~
USBHost
C:\Users\Nelson\Downloads\sketch_feb26a\sketch_feb26a.ino: In function 'void loop()':
C:\Users\Nelson\Downloads\sketch_feb26a\sketch_feb26a.ino:188:3: error: 'usbHost' was not declared in this scope
usbHost.Task(); // Check USB keyboard
^~~~~~~
C:\Users\Nelson\Downloads\sketch_feb26a\sketch_feb26a.ino:188:3: note: suggested alternative: 'USBHost'
usbHost.Task(); // Check USB keyboard
^~~~~~~
USBHost
C:\Users\Nelson\Downloads\sketch_feb26a\sketch_feb26a.ino:197:25: warning: comparison between signed and unsigned integer expressions [-Wsign-compare]
for (int i = 0; i < password.length(); i++) {
^~~~~~~~~~~~~~~~~
In file included from c:\Users\Nelson\Documents\Arduino\libraries\USBHost\src/KeyboardController.h:22:0,
from C:\Users\Nelson\Downloads\sketch_feb26a\sketch_feb26a.ino:21:
c:\Users\Nelson\Documents\Arduino\libraries\USBHost\src/hidboot.h: In instantiation of 'uint32_t HIDBoot<BOOT_PROTOCOL>::Release() [with unsigned char BOOT_PROTOCOL = 1; uint32_t = long unsigned int]':
C:\Users\Nelson\Downloads\sketch_feb26a\sketch_feb26a.ino:206:1: required from here
c:\Users\Nelson\Documents\Arduino\libraries\USBHost\src/hidboot.h:500:15: error: 'UHD_Pipe_Free' was not declared in this scope
UHD_Pipe_Free(epInfo[epInterruptInIndex].hostPipeNum);
c:\Users\Nelson\Documents\Arduino\libraries\USBHost\src/hidboot.h: In instantiation of 'void HIDBoot<BOOT_PROTOCOL>::EndpointXtract(uint32_t, uint32_t, uint32_t, uint32_t, const USB_ENDPOINT_DESCRIPTOR*) [with unsigned char BOOT_PROTOCOL = 1; uint32_t = long unsigned int]':
C:\Users\Nelson\Downloads\sketch_feb26a\sketch_feb26a.ino:206:1: required from here
c:\Users\Nelson\Documents\Arduino\libraries\USBHost\src/hidboot.h:474:178: error: 'UHD_Pipe_Alloc' was not declared in this scope
pipe = UHD_Pipe_Alloc(bAddress, epInfo[index].deviceEpNum, UOTGHS_HSTPIPCFG_PTYPE_INTRPT, UOTGHS_HSTPIPCFG_PTOKEN_IN, epInfo[index].maxPktSize, 10, UOTGHS_HSTPIPCFG_PBK_1_BANK);
^
Multiple libraries were found for "Adafruit_ST7735.h"
Used: C:\Users\Nelson\Documents\Arduino\libraries\Adafruit-ST7735-Library-master
Not used: C:\Users\Nelson\Documents\Arduino\libraries\Adafruit_ST7735_and_ST7789_Library
exit status 1
Compilation error: 'USBHostGiga' does not name a type; did you mean 'USBHost'?